Move color, luminance and saturation to files table

This commit is contained in:
Michael Mayer 2019-04-29 21:54:36 +02:00
parent b079882354
commit a82696f067
3 changed files with 28 additions and 26 deletions

View file

@ -11,6 +11,7 @@ type File struct {
PhotoID uint
FilePrimary bool
FileMissing bool
FileDuplicate bool
FileName string `gorm:"type:varchar(512);index"` // max 3072 bytes / 4 bytes for utf8mb4 = 768 chars
FileType string `gorm:"type:varchar(32)"`
FileMime string `gorm:"type:varchar(64)"`
@ -18,8 +19,10 @@ type File struct {
FileHeight int
FileOrientation int
FileAspectRatio float64
FileMainColor string
FileColors string
FileLuminance string
FileSaturation uint
FileHash string `gorm:"type:varchar(128);unique_index"`
FilePerceptualHash string
FileNotes string `gorm:"type:text;"`
FileNotes string `gorm:"type:text"`
}

View file

@ -93,14 +93,6 @@ func (i *Indexer) indexMediaFile(mediaFile *MediaFile) string {
photo.PhotoArtist = exifData.Artist
}
// PhotoColors
photoColors, photoColor, luminance, saturation, _ := jpeg.Colors()
photo.PhotoColor = photoColor.Name()
photo.PhotoColors = photoColors.Hex()
photo.PhotoLuminance = luminance.Hex()
photo.PhotoSaturation = saturation.Uint()
// Tags (TensorFlow)
tags = i.getImageTags(jpeg)
}
@ -164,18 +156,17 @@ func (i *Indexer) indexMediaFile(mediaFile *MediaFile) string {
i.db.Create(&photo)
} else if time.Now().Sub(photo.UpdatedAt).Minutes() > 10 { // If updated more than 10 minutes ago
if jpeg, err := mediaFile.GetJpeg(); err == nil {
// PhotoColors
photoColors, photoColor, luminance, saturation, _ := jpeg.Colors()
photo.PhotoColor = photoColor.Name()
photo.PhotoColors = photoColors.Hex()
photo.PhotoLuminance = luminance.Hex()
photo.PhotoSaturation = saturation.Uint()
photo.Camera = models.NewCamera(mediaFile.GetCameraModel(), mediaFile.GetCameraMake()).FirstOrCreate(i.db)
photo.Lens = models.NewLens(mediaFile.GetLensModel(), mediaFile.GetLensMake()).FirstOrCreate(i.db)
photo.PhotoFocalLength = mediaFile.GetFocalLength()
photo.PhotoAperture = mediaFile.GetAperture()
// Geo Location
if exifData, err := jpeg.GetExifData(); err == nil {
photo.PhotoLat = exifData.Lat
photo.PhotoLong = exifData.Long
photo.PhotoArtist = exifData.Artist
}
}
if photo.LocationID == 0 {
@ -209,12 +200,17 @@ func (i *Indexer) indexMediaFile(mediaFile *MediaFile) string {
file.FileOrientation = mediaFile.GetOrientation()
// Perceptual Hash
if file.FilePerceptualHash == "" && mediaFile.IsJpeg() {
if perceptualHash, err := mediaFile.GetPerceptualHash(); err == nil {
file.FilePerceptualHash = perceptualHash
}
if mediaFile.IsJpeg() {
// PhotoColors
c, mc, l, s, _ := mediaFile.Colors()
file.FileMainColor = mc.Name()
file.FileColors = c.Hex()
file.FileLuminance = l.Hex()
file.FileSaturation = s.Uint()
}
if mediaFile.GetWidth() > 0 && mediaFile.GetHeight() > 0 {
file.FileWidth = mediaFile.GetWidth()
file.FileHeight = mediaFile.GetHeight()

View file

@ -99,11 +99,14 @@ func (s *Search) Photos(form forms.PhotoSearchForm) ([]PhotoSearchResult, error)
q := s.db.NewScope(nil).DB()
q = q.Table("photos").
Select(`SQL_CALC_FOUND_ROWS photos.*,
files.id AS file_id, files.file_primary, files.file_missing, files.file_name, files.file_hash, files.file_perceptual_hash, files.file_type, files.file_mime, files.file_width, files.file_height, files.file_aspect_ratio, files.file_orientation,
files.id AS file_id, files.file_primary, files.file_missing, files.file_name, files.file_hash,
files.file_type, files.file_mime, files.file_width, files.file_height, files.file_aspect_ratio,
files.file_orientation, files.file_main_color, files.file_colors, files.file_luminance, files.file_saturation,
cameras.camera_make, cameras.camera_model,
lenses.lens_make, lenses.lens_model,
countries.country_name,
locations.loc_display_name, locations.loc_name, locations.loc_city, locations.loc_postcode, locations.loc_county, locations.loc_state, locations.loc_country, locations.loc_country_code, locations.loc_category, locations.loc_type,
locations.loc_display_name, locations.loc_name, locations.loc_city, locations.loc_postcode, locations.loc_county,
locations.loc_state, locations.loc_country, locations.loc_country_code, locations.loc_category, locations.loc_type,
GROUP_CONCAT(tags.tag_label) AS tags`).
Joins("JOIN files ON files.photo_id = photos.id AND files.file_primary AND files.deleted_at IS NULL").
Joins("JOIN cameras ON cameras.id = photos.camera_id").
@ -117,7 +120,7 @@ func (s *Search) Photos(form forms.PhotoSearchForm) ([]PhotoSearchResult, error)
if form.Query != "" {
likeString := "%" + strings.ToLower(form.Query) + "%"
q = q.Where("tags.tag_label LIKE ? OR LOWER(photo_title) LIKE ? OR LOWER(photo_color) LIKE ?", likeString, likeString, likeString)
q = q.Where("tags.tag_label LIKE ? OR LOWER(photo_title) LIKE ? OR LOWER(files.file_main_color) LIKE ?", likeString, likeString, likeString)
}
if form.CameraID > 0 {