1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-02-07 11:36:25 +02:00

Improved ICC profiles handling

This commit is contained in:
DarthSim 2021-12-07 14:21:51 +06:00
parent f60f8fff8a
commit cf884f860c
8 changed files with 17 additions and 25 deletions

View File

@ -1,6 +1,9 @@
# Changelog # Changelog
## [Unreleased] ## [Unreleased]
### Change
- Improved ICC profiles handling.
### Fix ### Fix
- (pro) Fix parsing metadata of extended sequential JPEGs. - (pro) Fix parsing metadata of extended sequential JPEGs.

View File

@ -31,10 +31,6 @@ func exportColorProfile(pctx *pipelineContext, img *vips.Image, po *options.Proc
} }
} }
if err := img.RgbColourspace(); err != nil {
return err
}
if !keepProfile { if !keepProfile {
return img.RemoveColourProfile() return img.RemoveColourProfile()
} }

View File

@ -7,14 +7,6 @@ import (
) )
func finalize(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error { func finalize(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
if err := img.RgbColourspace(); err != nil {
return err
}
if err := img.CastUchar(); err != nil {
return err
}
if po.StripMetadata { if po.StripMetadata {
if err := img.Strip(); err != nil { if err := img.Strip(); err != nil {
return err return err

View File

@ -14,7 +14,7 @@ func importColorProfile(pctx *pipelineContext, img *vips.Image, po *options.Proc
convertToLinear := config.UseLinearColorspace && (pctx.wscale != 1 || pctx.hscale != 1) convertToLinear := config.UseLinearColorspace && (pctx.wscale != 1 || pctx.hscale != 1)
if convertToLinear { if convertToLinear || img.IsCMYK() {
if err := img.ImportColourProfile(); err != nil { if err := img.ImportColourProfile(); err != nil {
return err return err
} }

View File

@ -27,12 +27,12 @@ var mainPipeline = pipeline{
rotateAndFlip, rotateAndFlip,
crop, crop,
fixWebpSize, fixWebpSize,
exportColorProfile,
applyFilters, applyFilters,
extend, extend,
padding, padding,
flatten, flatten,
watermark, watermark,
exportColorProfile,
finalize, finalize,
} }

View File

@ -16,7 +16,6 @@ var watermarkPipeline = pipeline{
importColorProfile, importColorProfile,
scale, scale,
rotateAndFlip, rotateAndFlip,
exportColorProfile,
finalize, finalize,
} }

View File

@ -293,22 +293,22 @@ vips_has_embedded_icc(VipsImage *in) {
int int
vips_icc_import_go(VipsImage *in, VipsImage **out) { vips_icc_import_go(VipsImage *in, VipsImage **out) {
return vips_icc_import(in, out, "embedded", TRUE, "pcs", VIPS_PCS_XYZ, NULL); return vips_icc_import(in, out, "embedded", TRUE, "pcs", VIPS_PCS_LAB, NULL);
} }
int int
vips_icc_export_go(VipsImage *in, VipsImage **out) { vips_icc_export_go(VipsImage *in, VipsImage **out) {
return vips_icc_export(in, out, NULL); return vips_icc_export(in, out, "pcs", VIPS_PCS_LAB, NULL);
} }
int int
vips_icc_export_srgb(VipsImage *in, VipsImage **out) { vips_icc_export_srgb(VipsImage *in, VipsImage **out) {
return vips_icc_export(in, out, "output_profile", "sRGB", NULL); return vips_icc_export(in, out, "output_profile", "sRGB", "pcs", VIPS_PCS_LAB, NULL);
} }
int int
vips_icc_transform_go(VipsImage *in, VipsImage **out) { vips_icc_transform_go(VipsImage *in, VipsImage **out) {
return vips_icc_transform(in, out, "sRGB", "embedded", TRUE, "pcs", VIPS_PCS_XYZ, NULL); return vips_icc_transform(in, out, "sRGB", "embedded", TRUE, "pcs", VIPS_PCS_LAB, NULL);
} }
int int
@ -456,15 +456,13 @@ vips_replicate_go(VipsImage *in, VipsImage **out, int width, int height) {
int int
vips_embed_go(VipsImage *in, VipsImage **out, int x, int y, int width, int height) { vips_embed_go(VipsImage *in, VipsImage **out, int x, int y, int width, int height) {
VipsImage *base = vips_image_new(); VipsImage *tmp;
VipsImage **t = (VipsImage **) vips_object_local_array(VIPS_OBJECT(base), 2);
int ret = int ret =
vips_colourspace(in, &t[0], VIPS_INTERPRETATION_sRGB, NULL) || vips_ensure_alpha(in, &tmp) ||
vips_ensure_alpha(t[0], &t[1]) || vips_embed(tmp, out, x, y, width, height, "extend", VIPS_EXTEND_BLACK, NULL);
vips_embed(t[1], out, x, y, width, height, "extend", VIPS_EXTEND_BLACK, NULL);
clear_image(&base); clear_image(&tmp);
return ret; return ret;
} }

View File

@ -573,6 +573,10 @@ func (img *Image) Sharpen(sigma float32) error {
return nil return nil
} }
func (img *Image) IsCMYK() bool {
return C.vips_image_guess_interpretation(img.VipsImage) == C.VIPS_INTERPRETATION_CMYK
}
func (img *Image) ImportColourProfile() error { func (img *Image) ImportColourProfile() error {
var tmp *C.VipsImage var tmp *C.VipsImage