mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Skip normalise operation for images with one colour
It didn't play nicely with premultiplication
This commit is contained in:
@@ -128,11 +128,6 @@ int Composite(VipsObject *context, VipsImage *srcPremultiplied, VipsImage *dstPr
|
||||
int Premultiply(VipsObject *context, VipsImage *image, VipsImage **out) {
|
||||
VipsImage *imagePremultiplied;
|
||||
|
||||
// Trivial case: Copy images without alpha channel:
|
||||
if (!HasAlpha(image)) {
|
||||
return vips_image_write(image, *out);
|
||||
}
|
||||
|
||||
#if (VIPS_MAJOR_VERSION >= 9 || (VIPS_MAJOR_VERSION >= 8 && VIPS_MINOR_VERSION >= 1))
|
||||
|
||||
if (vips_premultiply(image, &imagePremultiplied, NULL))
|
||||
@@ -140,9 +135,6 @@ int Premultiply(VipsObject *context, VipsImage *image, VipsImage **out) {
|
||||
|
||||
#else
|
||||
|
||||
if (image->Bands != 4)
|
||||
return -1;
|
||||
|
||||
VipsImage *imageRGB;
|
||||
if (vips_extract_band(image, &imageRGB, 0, "n", NUM_COLOR_BANDS, NULL))
|
||||
return -1;
|
||||
@@ -181,11 +173,6 @@ int Premultiply(VipsObject *context, VipsImage *image, VipsImage **out) {
|
||||
int Unpremultiply(VipsObject *context, VipsImage *image, VipsImage **out) {
|
||||
VipsImage *imageUnpremultiplied;
|
||||
|
||||
// Trivial case: Copy images without alpha channel:
|
||||
if (!HasAlpha(image)) {
|
||||
return vips_image_write(image, *out);
|
||||
}
|
||||
|
||||
#if (VIPS_MAJOR_VERSION >= 9 || (VIPS_MAJOR_VERSION >= 8 && VIPS_MINOR_VERSION >= 1))
|
||||
|
||||
if (vips_unpremultiply(image, &imageUnpremultiplied, NULL))
|
||||
@@ -193,9 +180,6 @@ int Unpremultiply(VipsObject *context, VipsImage *image, VipsImage **out) {
|
||||
|
||||
#else
|
||||
|
||||
if (image->Bands != 4)
|
||||
return -1;
|
||||
|
||||
VipsImage *imageRGBPremultipliedTransformed;
|
||||
if (vips_extract_band(image, &imageRGBPremultipliedTransformed, 0, "n", NUM_COLOR_BANDS, NULL))
|
||||
return -1;
|
||||
@@ -219,7 +203,6 @@ int Unpremultiply(VipsObject *context, VipsImage *image, VipsImage **out) {
|
||||
if (vips_bandjoin2(imageRGBUnpremultipliedTransformed, imageAlphaTransformed, &imageUnpremultiplied, NULL))
|
||||
return -1;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
// Return a reference to the unpremultiplied output image:
|
||||
|
||||
@@ -763,17 +763,10 @@ class ResizeWorker : public NanAsyncWorker {
|
||||
return Error();
|
||||
}
|
||||
vips_object_local(hook, stats);
|
||||
|
||||
double min = *VIPS_MATRIX(stats, 0, 0);
|
||||
double max = *VIPS_MATRIX(stats, 1, 0);
|
||||
|
||||
VipsImage *normalized;
|
||||
if (min == max) {
|
||||
// Range of zero: create black image
|
||||
if (vips_black(&normalized, image->Xsize, image->Ysize, "bands", 1, NULL )) {
|
||||
return Error();
|
||||
}
|
||||
vips_object_local(hook, normalized);
|
||||
} else {
|
||||
if (min != max) {
|
||||
double f = 100.0 / (max - min);
|
||||
double a = -(min * f);
|
||||
|
||||
@@ -788,27 +781,29 @@ class ResizeWorker : public NanAsyncWorker {
|
||||
return Error();
|
||||
}
|
||||
vips_object_local(hook, normalizedLab);
|
||||
|
||||
VipsImage *normalized;
|
||||
if (vips_colourspace(normalizedLab, &normalized, typeBeforeNormalize, NULL)) {
|
||||
return Error();
|
||||
}
|
||||
vips_object_local(hook, normalized);
|
||||
}
|
||||
|
||||
if (HasAlpha(image)) {
|
||||
VipsImage *alpha;
|
||||
if (vips_extract_band(image, &alpha, image->Bands - 1, "n", 1, NULL)) {
|
||||
return Error();
|
||||
}
|
||||
vips_object_local(hook, alpha);
|
||||
if (HasAlpha(image)) {
|
||||
VipsImage *alpha;
|
||||
if (vips_extract_band(image, &alpha, image->Bands - 1, "n", 1, NULL)) {
|
||||
return Error();
|
||||
}
|
||||
vips_object_local(hook, alpha);
|
||||
|
||||
VipsImage *normalizedAlpha;
|
||||
if (vips_bandjoin2(normalized, alpha, &normalizedAlpha, NULL)) {
|
||||
return Error();
|
||||
VipsImage *normalizedAlpha;
|
||||
if (vips_bandjoin2(normalized, alpha, &normalizedAlpha, NULL)) {
|
||||
return Error();
|
||||
}
|
||||
vips_object_local(hook, normalizedAlpha);
|
||||
image = normalizedAlpha;
|
||||
} else {
|
||||
image = normalized;
|
||||
}
|
||||
vips_object_local(hook, normalizedAlpha);
|
||||
image = normalizedAlpha;
|
||||
} else {
|
||||
image = normalized;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user