mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Expand linear operation to allow use of per-channel arrays #3303
This commit is contained in:
committed by
Lovell Fuller
parent
b9261c243c
commit
74e3f73934
@@ -306,10 +306,14 @@ namespace sharp {
|
||||
/*
|
||||
* Calculate (a * in + b)
|
||||
*/
|
||||
VImage Linear(VImage image, double const a, double const b) {
|
||||
if (HasAlpha(image)) {
|
||||
VImage Linear(VImage image, std::vector<double> const a, std::vector<double> const b) {
|
||||
size_t const bands = static_cast<size_t>(image.bands());
|
||||
if (a.size() > bands) {
|
||||
throw VError("Band expansion using linear is unsupported");
|
||||
}
|
||||
if (HasAlpha(image) && a.size() != bands && (a.size() == 1 || a.size() == bands - 1 || bands - 1 == 1)) {
|
||||
// Separate alpha channel
|
||||
VImage alpha = image[image.bands() - 1];
|
||||
VImage alpha = image[bands - 1];
|
||||
return RemoveAlpha(image).linear(a, b).bandjoin(alpha);
|
||||
} else {
|
||||
return image.linear(a, b);
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace sharp {
|
||||
/*
|
||||
* Linear adjustment (a * in + b)
|
||||
*/
|
||||
VImage Linear(VImage image, double const a, double const b);
|
||||
VImage Linear(VImage image, std::vector<double> const a, std::vector<double> const b);
|
||||
|
||||
/*
|
||||
* Recomb with a Matrix of the given bands/channel size.
|
||||
|
||||
@@ -688,7 +688,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
}
|
||||
|
||||
// Linear adjustment (a * in + b)
|
||||
if (baton->linearA != 1.0 || baton->linearB != 0.0) {
|
||||
if (!baton->linearA.empty()) {
|
||||
image = sharp::Linear(image, baton->linearA, baton->linearB);
|
||||
}
|
||||
|
||||
@@ -1454,8 +1454,8 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
||||
baton->trimThreshold = sharp::AttrAsDouble(options, "trimThreshold");
|
||||
baton->gamma = sharp::AttrAsDouble(options, "gamma");
|
||||
baton->gammaOut = sharp::AttrAsDouble(options, "gammaOut");
|
||||
baton->linearA = sharp::AttrAsDouble(options, "linearA");
|
||||
baton->linearB = sharp::AttrAsDouble(options, "linearB");
|
||||
baton->linearA = sharp::AttrAsVectorOfDouble(options, "linearA");
|
||||
baton->linearB = sharp::AttrAsVectorOfDouble(options, "linearB");
|
||||
baton->greyscale = sharp::AttrAsBool(options, "greyscale");
|
||||
baton->normalise = sharp::AttrAsBool(options, "normalise");
|
||||
baton->claheWidth = sharp::AttrAsUint32(options, "claheWidth");
|
||||
|
||||
@@ -100,8 +100,8 @@ struct PipelineBaton {
|
||||
double trimThreshold;
|
||||
int trimOffsetLeft;
|
||||
int trimOffsetTop;
|
||||
double linearA;
|
||||
double linearB;
|
||||
std::vector<double> linearA;
|
||||
std::vector<double> linearB;
|
||||
double gamma;
|
||||
double gammaOut;
|
||||
bool greyscale;
|
||||
@@ -251,8 +251,8 @@ struct PipelineBaton {
|
||||
trimThreshold(0.0),
|
||||
trimOffsetLeft(0),
|
||||
trimOffsetTop(0),
|
||||
linearA(1.0),
|
||||
linearB(0.0),
|
||||
linearA{},
|
||||
linearB{},
|
||||
gamma(0.0),
|
||||
greyscale(false),
|
||||
normalise(false),
|
||||
|
||||
Reference in New Issue
Block a user