mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-03-22 20:21:28 +02:00
Better work with ICC profiles; Usage of vips 8.8 bbuilt-in cmyk profile
This commit is contained in:
parent
e93daf979a
commit
eb60f0567c
41
process.go
41
process.go
@ -873,17 +873,42 @@ func vipsSharpen(img **C.VipsImage, sigma float32) error {
|
||||
func vipsImportColourProfile(img **C.VipsImage, evenSRGB bool) error {
|
||||
var tmp *C.VipsImage
|
||||
|
||||
if C.vips_need_icc_import(*img) > 0 && (evenSRGB || C.vips_icc_is_srgb_iec61966(*img) == 0) {
|
||||
profile, err := cmykProfilePath()
|
||||
if err != nil {
|
||||
return err
|
||||
if (*img).Coding != C.VIPS_CODING_NONE {
|
||||
return nil
|
||||
}
|
||||
|
||||
if (*img).BandFmt != C.VIPS_FORMAT_UCHAR && (*img).BandFmt != C.VIPS_FORMAT_USHORT {
|
||||
return nil
|
||||
}
|
||||
|
||||
profile := (*C.char)(nil)
|
||||
|
||||
if (*img).Type == C.VIPS_INTERPRETATION_sRGB {
|
||||
// No embedded profile for sRGB, ignore
|
||||
if C.vips_has_embedded_icc(*img) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if C.vips_icc_import_go(*img, &tmp, cachedCString(profile)) == 0 {
|
||||
C.swap_and_clear(img, tmp)
|
||||
} else {
|
||||
logWarning("Can't import ICC profile: %s", vipsError())
|
||||
// Don't import sRGB IEC61966 2.1 unless evenSRGB
|
||||
if !evenSRGB && C.vips_icc_is_srgb_iec61966(*img) != 0 {
|
||||
return nil
|
||||
}
|
||||
} else if (*img).Type == C.VIPS_INTERPRETATION_CMYK && C.vips_has_embedded_icc(*img) == 0 {
|
||||
if C.vips_support_builtin_icc() != 0 {
|
||||
profile = cachedCString("cmyk")
|
||||
} else {
|
||||
p, err := cmykProfilePath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
profile = cachedCString(p)
|
||||
}
|
||||
}
|
||||
|
||||
if C.vips_icc_import_go(*img, &tmp, profile) == 0 {
|
||||
C.swap_and_clear(img, tmp)
|
||||
} else {
|
||||
logWarning("Can't import ICC profile: %s", vipsError())
|
||||
}
|
||||
|
||||
return nil
|
||||
|
24
vips.c
24
vips.c
@ -19,8 +19,17 @@
|
||||
#define VIPS_SUPPORT_PNG_QUANTIZATION \
|
||||
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 7))
|
||||
|
||||
#define VIPS_SUPPORT_BUILTIN_ICC \
|
||||
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 8))
|
||||
|
||||
#define EXIF_ORIENTATION "exif-ifd0-Orientation"
|
||||
|
||||
#if (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 8))
|
||||
#define VIPS_BLOB_DATA_TYPE const void *
|
||||
#else
|
||||
#define VIPS_BLOB_DATA_TYPE void *
|
||||
#endif
|
||||
|
||||
int
|
||||
vips_initialize() {
|
||||
return vips_init("imgproxy");
|
||||
@ -218,7 +227,7 @@ vips_resize_with_premultiply(VipsImage *in, VipsImage **out, double scale) {
|
||||
|
||||
int
|
||||
vips_icc_is_srgb_iec61966(VipsImage *in) {
|
||||
void *data;
|
||||
VIPS_BLOB_DATA_TYPE data;
|
||||
size_t data_len;
|
||||
|
||||
// 1998-12-01
|
||||
@ -242,12 +251,13 @@ vips_icc_is_srgb_iec61966(VipsImage *in) {
|
||||
}
|
||||
|
||||
int
|
||||
vips_need_icc_import(VipsImage *in) {
|
||||
return (vips_image_get_typeof(in, VIPS_META_ICC_NAME) ||
|
||||
in->Type == VIPS_INTERPRETATION_CMYK) &&
|
||||
in->Coding == VIPS_CODING_NONE &&
|
||||
(in->BandFmt == VIPS_FORMAT_UCHAR ||
|
||||
in->BandFmt == VIPS_FORMAT_USHORT);
|
||||
vips_has_embedded_icc(VipsImage *in) {
|
||||
return vips_image_get_typeof(in, VIPS_META_ICC_NAME) != 0;
|
||||
}
|
||||
|
||||
int
|
||||
vips_support_builtin_icc() {
|
||||
return VIPS_SUPPORT_BUILTIN_ICC;
|
||||
}
|
||||
|
||||
int
|
||||
|
3
vips.h
3
vips.h
@ -48,7 +48,8 @@ int vips_resize_go(VipsImage *in, VipsImage **out, double scale);
|
||||
int vips_resize_with_premultiply(VipsImage *in, VipsImage **out, double scale);
|
||||
|
||||
int vips_icc_is_srgb_iec61966(VipsImage *in);
|
||||
int vips_need_icc_import(VipsImage *in);
|
||||
int vips_has_embedded_icc(VipsImage *in);
|
||||
int vips_support_builtin_icc();
|
||||
int vips_icc_import_go(VipsImage *in, VipsImage **out, char *profile);
|
||||
int vips_colourspace_go(VipsImage *in, VipsImage **out, VipsInterpretation cs);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user