Merge pull request #306 from dacarley/negate

Add negate operation to invert all pixel values.
This commit is contained in:
Lovell Fuller
2015-11-17 20:45:09 +00:00
10 changed files with 130 additions and 0 deletions

View File

@@ -101,6 +101,7 @@ struct PipelineBaton {
std::string interpolator;
double background[4];
bool flatten;
bool negate;
double blurSigma;
int sharpenRadius;
double sharpenFlat;
@@ -140,6 +141,7 @@ struct PipelineBaton {
canvas(Canvas::CROP),
gravity(0),
flatten(false),
negate(false),
blurSigma(0.0),
sharpenRadius(0),
sharpenFlat(1.0),
@@ -454,6 +456,16 @@ class PipelineWorker : public AsyncWorker {
image = flattened;
}
// Negate the colors in the image.
if (baton->negate) {
VipsImage *negated;
if (vips_invert(image, &negated, nullptr)) {
return Error();
}
vips_object_local(hook, negated);
image = negated;
}
// Gamma encoding (darken)
if (baton->gamma >= 1 && baton->gamma <= 3 && !HasAlpha(image)) {
VipsImage *gammaEncoded;
@@ -1225,6 +1237,7 @@ NAN_METHOD(pipeline) {
baton->interpolator = *Utf8String(Get(options, New("interpolator").ToLocalChecked()).ToLocalChecked());
// Operators
baton->flatten = To<bool>(Get(options, New("flatten").ToLocalChecked()).ToLocalChecked()).FromJust();
baton->negate = To<bool>(Get(options, New("negate").ToLocalChecked()).ToLocalChecked()).FromJust();
baton->blurSigma = To<double>(Get(options, New("blurSigma").ToLocalChecked()).ToLocalChecked()).FromJust();
baton->sharpenRadius = To<int32_t>(Get(options, New("sharpenRadius").ToLocalChecked()).ToLocalChecked()).FromJust();
baton->sharpenFlat = To<double>(Get(options, New("sharpenFlat").ToLocalChecked()).ToLocalChecked()).FromJust();