2019-12-28 20:24:20 +01:00
|
|
|
/*
|
2020-01-12 14:00:56 +01:00
|
|
|
Package colors provides types and functions for color classification.
|
2019-12-28 20:24:20 +01:00
|
|
|
|
2022-04-13 22:17:59 +02:00
|
|
|
Copyright (c) 2018 - 2022 PhotoPrism UG. All rights reserved.
|
2020-06-23 13:44:14 +02:00
|
|
|
|
2022-08-10 16:09:21 +02:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under Version 3 of the GNU Affero General Public License (the "AGPL"):
|
|
|
|
<https://docs.photoprism.app/license/agpl>
|
2020-06-23 13:44:14 +02:00
|
|
|
|
2022-08-10 16:09:21 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
2020-06-23 13:44:14 +02:00
|
|
|
|
2022-08-10 16:09:21 +02:00
|
|
|
The AGPL is supplemented by our Trademark and Brand Guidelines,
|
|
|
|
which describe how our Brand Assets may be used:
|
|
|
|
<https://photoprism.app/trademark>
|
2020-06-23 13:44:14 +02:00
|
|
|
|
2022-04-13 22:17:59 +02:00
|
|
|
Feel free to send an email to hello@photoprism.app if you have questions,
|
2020-06-23 13:44:14 +02:00
|
|
|
want to support our work, or just want to say hello.
|
|
|
|
|
2019-12-28 20:24:20 +01:00
|
|
|
Additional information can be found in our Developer Guide:
|
2022-02-27 17:32:54 +01:00
|
|
|
<https://docs.photoprism.app/developer-guide/>
|
2019-12-28 20:24:20 +01:00
|
|
|
*/
|
|
|
|
package colors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-04-15 09:42:07 +02:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
2019-12-28 20:24:20 +01:00
|
|
|
)
|
|
|
|
|
2022-06-16 06:30:59 +02:00
|
|
|
type Color int16
|
2019-12-28 20:24:20 +01:00
|
|
|
type Colors []Color
|
|
|
|
|
|
|
|
const (
|
|
|
|
Black Color = iota
|
|
|
|
Grey
|
2020-12-17 11:47:31 +01:00
|
|
|
Brown
|
|
|
|
Gold
|
2019-12-28 20:24:20 +01:00
|
|
|
White
|
|
|
|
Purple
|
|
|
|
Blue
|
|
|
|
Cyan
|
|
|
|
Teal
|
|
|
|
Green
|
|
|
|
Lime
|
|
|
|
Yellow
|
|
|
|
Magenta
|
|
|
|
Orange
|
|
|
|
Red
|
|
|
|
Pink
|
|
|
|
)
|
|
|
|
|
|
|
|
var All = Colors{
|
2019-12-29 15:35:23 +01:00
|
|
|
Purple,
|
2019-12-28 20:24:20 +01:00
|
|
|
Magenta,
|
|
|
|
Pink,
|
2019-12-29 15:35:23 +01:00
|
|
|
Red,
|
2019-12-28 20:24:20 +01:00
|
|
|
Orange,
|
|
|
|
Gold,
|
|
|
|
Yellow,
|
|
|
|
Lime,
|
|
|
|
Green,
|
|
|
|
Teal,
|
|
|
|
Cyan,
|
|
|
|
Blue,
|
2019-12-29 15:35:23 +01:00
|
|
|
Brown,
|
2019-12-28 20:24:20 +01:00
|
|
|
White,
|
|
|
|
Grey,
|
|
|
|
Black,
|
|
|
|
}
|
|
|
|
|
|
|
|
var Names = map[Color]string{
|
2019-12-29 01:50:23 +01:00
|
|
|
Black: "black", // 0
|
2020-12-17 11:47:31 +01:00
|
|
|
Grey: "grey", // 1
|
|
|
|
Brown: "brown", // 2
|
|
|
|
Gold: "gold", // 3
|
|
|
|
White: "white", // 4
|
|
|
|
Purple: "purple", // 5
|
2019-12-28 20:24:20 +01:00
|
|
|
Blue: "blue", // 6
|
|
|
|
Cyan: "cyan", // 7
|
|
|
|
Teal: "teal", // 8
|
|
|
|
Green: "green", // 9
|
|
|
|
Lime: "lime", // A
|
|
|
|
Yellow: "yellow", // B
|
|
|
|
Magenta: "magenta", // C
|
|
|
|
Orange: "orange", // D
|
|
|
|
Red: "red", // E
|
|
|
|
Pink: "pink", // F
|
|
|
|
}
|
|
|
|
|
|
|
|
var Weights = map[Color]uint16{
|
2020-12-17 11:47:31 +01:00
|
|
|
Grey: 1,
|
2019-12-28 20:24:20 +01:00
|
|
|
Black: 2,
|
|
|
|
Brown: 2,
|
|
|
|
White: 2,
|
2020-12-17 11:47:31 +01:00
|
|
|
Blue: 3,
|
|
|
|
Green: 3,
|
2019-12-28 20:24:20 +01:00
|
|
|
Purple: 4,
|
|
|
|
Gold: 4,
|
|
|
|
Cyan: 4,
|
|
|
|
Teal: 4,
|
|
|
|
Orange: 4,
|
|
|
|
Red: 4,
|
|
|
|
Pink: 4,
|
2020-12-17 11:47:31 +01:00
|
|
|
Lime: 5,
|
|
|
|
Yellow: 5,
|
|
|
|
Magenta: 5,
|
2019-12-28 20:24:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c Color) Name() string {
|
|
|
|
return Names[c]
|
|
|
|
}
|
|
|
|
|
2022-06-16 06:30:59 +02:00
|
|
|
func (c Color) ID() int16 {
|
|
|
|
return int16(c)
|
2020-12-17 12:32:53 +01:00
|
|
|
}
|
|
|
|
|
2019-12-28 20:24:20 +01:00
|
|
|
func (c Color) Hex() string {
|
|
|
|
return fmt.Sprintf("%X", c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Colors) Hex() (result string) {
|
|
|
|
for _, indexedColor := range c {
|
|
|
|
result += indexedColor.Hex()
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Colors) List() []map[string]string {
|
|
|
|
result := make([]map[string]string, 0, len(c))
|
|
|
|
|
|
|
|
for _, c := range c {
|
2022-04-15 09:42:07 +02:00
|
|
|
result = append(result, map[string]string{"Slug": c.Name(), "Name": txt.UpperFirst(c.Name()), "Example": ColorExamples[c]})
|
2019-12-28 20:24:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|