photoprism/pkg/colors/srgb_test.go
Michael Mayer 5be456a09f JPEG: Convert Apple "Display P3" colors to standard sRGB #1474
Other color profiles and file formats are not supported yet. Should
be easy to add though. Main difficulty will be profile name comparison:
For example "Adobe RGB (1998)" vs just "Adobe RGB".
2021-12-09 07:00:39 +01:00

61 lines
926 B
Go

package colors
import (
"image"
"image/jpeg"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func writeImage(path string, img image.Image) error {
imgFile, err := os.Create(path)
if err != nil {
return err
}
defer imgFile.Close()
opt := jpeg.Options{
Quality: 95,
}
return jpeg.Encode(imgFile, img, &opt)
}
func TestToSRGB(t *testing.T) {
t.Run("DisplayP3", func(t *testing.T) {
testFile, _ := filepath.Abs("./testdata/DisplayP3.jpg")
t.Logf("testfile: %s", testFile)
imgFile, err := os.Open(testFile)
if err != nil {
t.Fatal(err)
}
defer imgFile.Close()
img, _, err := image.Decode(imgFile)
if err != nil {
t.Fatal(err)
}
imgSRGB := ToSRGB(img, ProfileDisplayP3)
srgbFile := "./testdata/SRGB.jpg"
if err := writeImage(srgbFile, imgSRGB); err != nil {
t.Error(err)
}
assert.FileExists(t, srgbFile)
_ = os.Remove(srgbFile)
})
}