Fix tint op by ensuring LAB and allowing negative values #1235

Add test cases for more tint colours and input interpretations
This commit is contained in:
Lovell Fuller
2018-05-23 20:51:47 +01:00
parent b1a9bf10a2
commit 54a71fc142
9 changed files with 55 additions and 9 deletions

View File

@@ -161,13 +161,14 @@ namespace sharp {
if (typeBeforeTint == VIPS_INTERPRETATION_RGB) {
typeBeforeTint = VIPS_INTERPRETATION_sRGB;
}
// Create 2 band image with every pixel set to the tint chroma
std::vector<double> chromaPixel {a, b};
VImage chroma = image.new_from_image(chromaPixel);
// Extract luminance
VImage luminance = image.colourspace(VIPS_INTERPRETATION_LAB)[0];
// Create the tinted version by combining the L from the original and the chroma from the tint
VImage tinted = luminance.bandjoin(chroma).colourspace(typeBeforeTint);
std::vector<double> chroma {a, b};
VImage tinted = luminance
.bandjoin(chroma)
.copy(VImage::option()->set("interpretation", VIPS_INTERPRETATION_LAB))
.colourspace(typeBeforeTint);
// Attach original alpha channel, if any
if (HasAlpha(image)) {
// Extract original alpha channel

View File

@@ -683,7 +683,7 @@ class PipelineWorker : public Nan::AsyncWorker {
}
// Tint the image
if (baton->tintA > 0 || baton->tintB > 0) {
if (baton->tintA < 128.0 || baton->tintB < 128.0) {
image = sharp::Tint(image, baton->tintA, baton->tintB);
}

View File

@@ -157,8 +157,8 @@ struct PipelineBaton {
cropOffsetLeft(0),
cropOffsetTop(0),
premultiplied(false),
tintA(0.0),
tintB(0.0),
tintA(128.0),
tintB(128.0),
flatten(false),
negate(false),
blurSigma(0.0),