mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
committed by
Lovell Fuller
parent
18afcf5f90
commit
b494b2e872
@@ -185,6 +185,21 @@ namespace sharp {
|
||||
0.0, 0.0, 0.0, 1.0));
|
||||
}
|
||||
|
||||
VImage Modulate(VImage image, double const brightness, double const saturation, int const hue) {
|
||||
if (HasAlpha(image)) {
|
||||
// Separate alpha channel
|
||||
VImage alpha = image[image.bands() - 1];
|
||||
return RemoveAlpha(image)
|
||||
.colourspace(VIPS_INTERPRETATION_LCH)
|
||||
.linear({brightness, saturation, 1}, {0, 0, static_cast<double>(hue)})
|
||||
.bandjoin(alpha);
|
||||
} else {
|
||||
return image
|
||||
.colourspace(VIPS_INTERPRETATION_LCH)
|
||||
.linear({brightness, saturation, 1}, {0, 0, static_cast<double>(hue)});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Sharpen flat and jagged areas. Use sigma of -1.0 for fast sharpen.
|
||||
*/
|
||||
|
||||
@@ -97,6 +97,11 @@ namespace sharp {
|
||||
*/
|
||||
VImage Recomb(VImage image, std::unique_ptr<double[]> const &matrix);
|
||||
|
||||
/*
|
||||
* Modulate brightness, saturation and hue
|
||||
*/
|
||||
VImage Modulate(VImage image, double const brightness, double const saturation, int const hue);
|
||||
|
||||
} // namespace sharp
|
||||
|
||||
#endif // SRC_OPERATIONS_H_
|
||||
|
||||
@@ -349,6 +349,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
||||
bool const shouldSharpen = baton->sharpenSigma != 0.0;
|
||||
bool const shouldApplyMedian = baton->medianSize > 0;
|
||||
bool const shouldComposite = !baton->composite.empty();
|
||||
bool const shouldModulate = baton->brightness != 1.0 || baton->saturation != 1.0 || baton->hue != 0.0;
|
||||
|
||||
if (shouldComposite && !HasAlpha(image)) {
|
||||
image = sharp::EnsureAlpha(image);
|
||||
@@ -528,6 +529,10 @@ class PipelineWorker : public Nan::AsyncWorker {
|
||||
image = sharp::Recomb(image, baton->recombMatrix);
|
||||
}
|
||||
|
||||
if (shouldModulate) {
|
||||
image = sharp::Modulate(image, baton->brightness, baton->saturation, baton->hue);
|
||||
}
|
||||
|
||||
// Sharpen
|
||||
if (shouldSharpen) {
|
||||
image = sharp::Sharpen(image, baton->sharpenSigma, baton->sharpenFlat, baton->sharpenJagged);
|
||||
@@ -1210,6 +1215,9 @@ NAN_METHOD(pipeline) {
|
||||
baton->flattenBackground = AttrAsRgba(options, "flattenBackground");
|
||||
baton->negate = AttrTo<bool>(options, "negate");
|
||||
baton->blurSigma = AttrTo<double>(options, "blurSigma");
|
||||
baton->brightness = AttrTo<double>(options, "brightness");
|
||||
baton->saturation = AttrTo<double>(options, "saturation");
|
||||
baton->hue = AttrTo<int32_t>(options, "hue");
|
||||
baton->medianSize = AttrTo<uint32_t>(options, "medianSize");
|
||||
baton->sharpenSigma = AttrTo<double>(options, "sharpenSigma");
|
||||
baton->sharpenFlat = AttrTo<double>(options, "sharpenFlat");
|
||||
|
||||
@@ -87,6 +87,9 @@ struct PipelineBaton {
|
||||
std::vector<double> flattenBackground;
|
||||
bool negate;
|
||||
double blurSigma;
|
||||
double brightness;
|
||||
double saturation;
|
||||
int hue;
|
||||
int medianSize;
|
||||
double sharpenSigma;
|
||||
double sharpenFlat;
|
||||
@@ -189,6 +192,9 @@ struct PipelineBaton {
|
||||
flattenBackground{ 0.0, 0.0, 0.0 },
|
||||
negate(false),
|
||||
blurSigma(0.0),
|
||||
brightness(1.0),
|
||||
saturation(1.0),
|
||||
hue(0.0),
|
||||
medianSize(0),
|
||||
sharpenSigma(0.0),
|
||||
sharpenFlat(1.0),
|
||||
|
||||
Reference in New Issue
Block a user