mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-24 08:12:38 +02:00
Fix processing of CMYK without embedded profile
This commit is contained in:
parent
5307b46ed2
commit
070346d155
20066
cmyk_profile.go
Normal file
20066
cmyk_profile.go
Normal file
File diff suppressed because it is too large
Load Diff
28
process.go
28
process.go
@ -275,27 +275,31 @@ func processImage(data []byte, imgtype imageType, po processingOptions, t *timer
|
||||
}
|
||||
}
|
||||
|
||||
have_premultiplied := false
|
||||
premultiplied := false
|
||||
var bandFormat C.VipsBandFormat
|
||||
|
||||
if vipsImageHasAlpha(img) {
|
||||
if bandFormat, err = vipsPremultiply(&img); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
have_premultiplied = true
|
||||
premultiplied = true
|
||||
}
|
||||
|
||||
if err = vipsResize(&img, scale); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if have_premultiplied {
|
||||
if premultiplied {
|
||||
if err = vipsUnpremultiply(&img, bandFormat); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err = vipsImportColourProfile(&img); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = vipsFixColourspace(&img); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -463,6 +467,24 @@ func vipsSmartCrop(img **C.struct__VipsImage, width, height int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func vipsImportColourProfile(img **C.struct__VipsImage) error {
|
||||
var tmp *C.struct__VipsImage
|
||||
|
||||
if C.vips_need_icc_import(*img) > 0 {
|
||||
profile, err := cmykProfilePath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if C.vips_icc_import_go(*img, &tmp, C.CString(profile)) != 0 {
|
||||
return vipsError()
|
||||
}
|
||||
C.swap_and_clear(img, tmp)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func vipsFixColourspace(img **C.struct__VipsImage) error {
|
||||
var tmp *C.struct__VipsImage
|
||||
|
||||
|
10
vips.h
10
vips.h
@ -153,6 +153,16 @@ vips_resize_go(VipsImage *in, VipsImage **out, double scale) {
|
||||
return vips_resize(in, out, scale, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
vips_need_icc_import(VipsImage *in) {
|
||||
return in->Type == VIPS_INTERPRETATION_CMYK;
|
||||
}
|
||||
|
||||
int
|
||||
vips_icc_import_go(VipsImage *in, VipsImage **out, char *profile) {
|
||||
return vips_icc_import(in, out, "input_profile", "cmyk.icm", "embedded", TRUE, "pcs", VIPS_PCS_XYZ, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
vips_colourspace_go(VipsImage *in, VipsImage **out, VipsInterpretation cs) {
|
||||
return vips_colourspace(in, out, cs, NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user