Skip to content

Commit

Permalink
Merge pull request #231 from wix-incubator/optimize-icc-16bit-fix
Browse files Browse the repository at this point in the history
Fix OptimizeICCProfile for 16-bit images
  • Loading branch information
tonimelisma authored Dec 12, 2021
2 parents 85b8e44 + d0c679d commit 69fb618
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/png-alpha-64bit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion vips/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,12 @@ func (r *ImageRef) OptimizeICCProfile() error {

embedded := r.HasICCProfile() && (inputProfile == "")

out, err := vipsICCTransform(r.image, r.optimizedIccProfile, inputProfile, IntentPerceptual, 0, embedded)
depth := 16
if r.BandFormat() == BandFormatUchar || r.BandFormat() == BandFormatChar || r.BandFormat() == BandFormatNotSet {
depth = 8
}

out, err := vipsICCTransform(r.image, r.optimizedIccProfile, inputProfile, IntentPerceptual, depth, embedded)
if err != nil {
govipsLog("govips", LogLevelError, fmt.Sprintf("failed to do icc transform: %v", err.Error()))
return err
Expand Down
15 changes: 15 additions & 0 deletions vips/image_golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ import (
"github.com/stretchr/testify/require"
)

func TestImage_PNG_64bit_OptimizeICCProfile(t *testing.T) {
goldenTest(t, resources+"png-alpha-64bit.png",
func(img *ImageRef) error {
return img.OptimizeICCProfile()
},
nil,
exportPng(NewPngExportParams()))
}

func TestImage_Resize_Downscale(t *testing.T) {
goldenTest(t, resources+"jpg-24bit.jpg",
func(img *ImageRef) error {
Expand Down Expand Up @@ -746,6 +755,12 @@ func exportJpeg(exportParams *JpegExportParams) func(img *ImageRef) ([]byte, *Im
}
}

func exportPng(exportParams *PngExportParams) func(img *ImageRef) ([]byte, *ImageMetadata, error) {
return func(img *ImageRef) ([]byte, *ImageMetadata, error) {
return img.ExportPng(exportParams)
}
}

func goldenTest(
t *testing.T,
path string,
Expand Down

0 comments on commit 69fb618

Please sign in to comment.