Colors: Use int16 instead of int8 to avoid (de)serialization issues
This commit is contained in:
parent
d604b7c61e
commit
23fd9ae731
12 changed files with 20 additions and 20 deletions
|
@ -81,7 +81,7 @@ type File struct {
|
|||
FileColors string `gorm:"type:VARBINARY(9);" json:"Colors" yaml:"Colors,omitempty"`
|
||||
FileLuminance string `gorm:"type:VARBINARY(9);" json:"Luminance" yaml:"Luminance,omitempty"`
|
||||
FileDiff int `json:"Diff" yaml:"Diff,omitempty"`
|
||||
FileChroma int8 `json:"Chroma" yaml:"Chroma,omitempty"`
|
||||
FileChroma int16 `json:"Chroma" yaml:"Chroma,omitempty"`
|
||||
FileSoftware string `gorm:"type:VARCHAR(64)" json:"Software" yaml:"Software,omitempty"`
|
||||
FileError string `gorm:"type:VARBINARY(512)" json:"Error" yaml:"Error,omitempty"`
|
||||
ModTime int64 `json:"ModTime" yaml:"-"`
|
||||
|
@ -167,7 +167,7 @@ type FileInfos struct {
|
|||
FileColors string
|
||||
FileLuminance string
|
||||
FileDiff int
|
||||
FileChroma int8
|
||||
FileChroma int16
|
||||
}
|
||||
|
||||
// FirstFileByHash gets a file in db from its hash
|
||||
|
|
|
@ -41,7 +41,7 @@ func (m *File) MarshalJSON() ([]byte, error) {
|
|||
Colors string `json:",omitempty"`
|
||||
Luminance string `json:",omitempty"`
|
||||
Diff int `json:",omitempty"`
|
||||
Chroma int8 `json:",omitempty"`
|
||||
Chroma int16 `json:",omitempty"`
|
||||
HDR bool `json:",omitempty"`
|
||||
Watermark bool `json:",omitempty"`
|
||||
Software string `json:",omitempty"`
|
||||
|
|
|
@ -85,7 +85,7 @@ type Photo struct {
|
|||
PhotoQuality int `gorm:"type:SMALLINT" json:"Quality" yaml:"Quality,omitempty"`
|
||||
PhotoFaces int `json:"Faces,omitempty" yaml:"Faces,omitempty"`
|
||||
PhotoResolution int `gorm:"type:SMALLINT" json:"Resolution" yaml:"-"`
|
||||
PhotoColor int8 `json:"Color" yaml:"-"`
|
||||
PhotoColor int16 `json:"Color" yaml:"-"`
|
||||
CameraID uint `gorm:"index:idx_photos_camera_lens;default:1" json:"CameraID" yaml:"-"`
|
||||
CameraSerial string `gorm:"type:VARBINARY(160);" json:"CameraSerial" yaml:"CameraSerial,omitempty"`
|
||||
CameraSrc string `gorm:"type:VARBINARY(8);" json:"CameraSrc" yaml:"-"`
|
||||
|
|
|
@ -44,7 +44,7 @@ type SearchPhotos struct {
|
|||
Dist uint `form:"dist" example:"dist:5" notes:"Distance in km in combination with lat/lng"`
|
||||
Fmin float32 `form:"fmin" notes:"F-number (min)"`
|
||||
Fmax float32 `form:"fmax" notes:"F-number (max)"`
|
||||
Chroma uint8 `form:"chroma" example:"chroma:70" notes:"Chroma (0-100)"`
|
||||
Chroma int16 `form:"chroma" example:"chroma:70" notes:"Chroma (0-100)"`
|
||||
Diff uint32 `form:"diff" notes:"Differential Perceptual Hash (000000-FFFFFF)"`
|
||||
Mono bool `form:"mono" notes:"Finds pictures with few or no colors"`
|
||||
Geo bool `form:"geo" notes:"Finds pictures with GPS location"`
|
||||
|
|
|
@ -121,7 +121,7 @@ func TestParseQueryString(t *testing.T) {
|
|||
t.Fatal("err should be nil")
|
||||
}
|
||||
|
||||
assert.Equal(t, uint8(200), form.Chroma)
|
||||
assert.Equal(t, int16(200), form.Chroma)
|
||||
assert.Equal(t, "te:st", form.Title)
|
||||
assert.Equal(t, time.Date(2018, 01, 15, 0, 0, 0, 0, time.UTC), form.After)
|
||||
assert.Equal(t, float32(33.45343), form.Lng)
|
||||
|
|
|
@ -25,7 +25,7 @@ type TestForm struct {
|
|||
Dist uint `form:"dist"`
|
||||
Fmin float32 `form:"fmin"`
|
||||
Fmax float32 `form:"fmax"`
|
||||
Chroma uint8 `form:"chroma"`
|
||||
Chroma int16 `form:"chroma"`
|
||||
Diff uint32 `form:"diff"`
|
||||
Mono bool `form:"mono"`
|
||||
Portrait bool `form:"portrait"`
|
||||
|
|
|
@ -42,7 +42,7 @@ type Photo struct {
|
|||
PhotoFaces int `json:"Faces,omitempty" select:"photos.photo_faces"`
|
||||
PhotoQuality int `json:"Quality" select:"photos.photo_quality"`
|
||||
PhotoResolution int `json:"Resolution" select:"photos.photo_resolution"`
|
||||
PhotoColor uint8 `json:"Color" select:"photos.photo_color"`
|
||||
PhotoColor int16 `json:"Color" select:"photos.photo_color"`
|
||||
PhotoScan bool `json:"Scan" select:"photos.photo_scan"`
|
||||
PhotoPanorama bool `json:"Panorama" select:"photos.photo_panorama"`
|
||||
CameraID uint `json:"CameraID" select:"photos.camera_id"` // Camera
|
||||
|
@ -90,7 +90,7 @@ type Photo struct {
|
|||
FileAspectRatio float32 `json:"-" select:"files.file_aspect_ratio"`
|
||||
FileColors string `json:"-" select:"files.file_colors"`
|
||||
FileDiff int `json:"-" select:"files.file_diff"`
|
||||
FileChroma int8 `json:"-" select:"files.file_chroma"`
|
||||
FileChroma int16 `json:"-" select:"files.file_chroma"`
|
||||
FileLuminance string `json:"-" select:"files.file_luminance"`
|
||||
Merged bool `json:"Merged" select:"-"`
|
||||
CreatedAt time.Time `json:"CreatedAt" select:"photos.created_at"`
|
||||
|
|
|
@ -3,17 +3,17 @@ package colors
|
|||
import "fmt"
|
||||
|
||||
// Chroma represents colorfulness.
|
||||
type Chroma int8
|
||||
type Chroma int16
|
||||
|
||||
// Percent returns the colourfulness in percent.
|
||||
func (c Chroma) Percent() int8 {
|
||||
func (c Chroma) Percent() int16 {
|
||||
if c > 100 {
|
||||
return 100
|
||||
} else if c < 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
return int8(c)
|
||||
return int16(c)
|
||||
}
|
||||
|
||||
// Hex returns the colourfulness in percent has hex string.
|
||||
|
|
|
@ -12,11 +12,11 @@ func TestChroma_Percent(t *testing.T) {
|
|||
|
||||
t.Run("chroma 15", func(t *testing.T) {
|
||||
perception := ColorPerception{Colors: Colors{Orange, Lime, Cyan}, MainColor: Cyan, Luminance: lMap, Chroma: 15}
|
||||
assert.Equal(t, int8(15), perception.Chroma.Percent())
|
||||
assert.Equal(t, int16(15), perception.Chroma.Percent())
|
||||
})
|
||||
t.Run("chroma 127", func(t *testing.T) {
|
||||
perception := ColorPerception{Colors: Colors{Orange, Lime, Cyan}, MainColor: Cyan, Luminance: lMap, Chroma: 127}
|
||||
assert.Equal(t, int8(100), perception.Chroma.Percent())
|
||||
assert.Equal(t, int16(100), perception.Chroma.Percent())
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ import (
|
|||
"github.com/photoprism/photoprism/pkg/txt"
|
||||
)
|
||||
|
||||
type Color int8
|
||||
type Color int16
|
||||
type Colors []Color
|
||||
|
||||
const (
|
||||
|
@ -115,8 +115,8 @@ func (c Color) Name() string {
|
|||
return Names[c]
|
||||
}
|
||||
|
||||
func (c Color) ID() int8 {
|
||||
return int8(c)
|
||||
func (c Color) ID() int16 {
|
||||
return int16(c)
|
||||
}
|
||||
|
||||
func (c Color) Hex() string {
|
||||
|
|
|
@ -28,6 +28,6 @@ func TestColors_Hex(t *testing.T) {
|
|||
assert.Equal(t, "DA0", result)
|
||||
}
|
||||
|
||||
func TestColor_Uint8(t *testing.T) {
|
||||
assert.Equal(t, int8(7), Cyan.ID())
|
||||
func TestColor_ID(t *testing.T) {
|
||||
assert.Equal(t, int16(7), Cyan.ID())
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package colors
|
|||
|
||||
import "fmt"
|
||||
|
||||
type Luminance uint8
|
||||
type Luminance int16
|
||||
|
||||
func (l Luminance) Hex() string {
|
||||
return fmt.Sprintf("%X", l)
|
||||
|
|
Loading…
Add table
Reference in a new issue