mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add support to recomb operation for 4x4 matrices
This commit is contained in:
@@ -183,19 +183,21 @@ namespace sharp {
|
||||
* Recomb with a Matrix of the given bands/channel size.
|
||||
* Eg. RGB will be a 3x3 matrix.
|
||||
*/
|
||||
VImage Recomb(VImage image, std::unique_ptr<double[]> const &matrix) {
|
||||
double *m = matrix.get();
|
||||
VImage Recomb(VImage image, std::vector<double> const& matrix) {
|
||||
double* m = const_cast<double*>(matrix.data());
|
||||
image = image.colourspace(VIPS_INTERPRETATION_sRGB);
|
||||
return image
|
||||
.recomb(image.bands() == 3
|
||||
? VImage::new_from_memory(
|
||||
m, 9 * sizeof(double), 3, 3, 1, VIPS_FORMAT_DOUBLE
|
||||
)
|
||||
: VImage::new_matrixv(4, 4,
|
||||
m[0], m[1], m[2], 0.0,
|
||||
m[3], m[4], m[5], 0.0,
|
||||
m[6], m[7], m[8], 0.0,
|
||||
0.0, 0.0, 0.0, 1.0));
|
||||
if (matrix.size() == 9) {
|
||||
return image
|
||||
.recomb(image.bands() == 3
|
||||
? VImage::new_matrix(3, 3, m, 9)
|
||||
: VImage::new_matrixv(4, 4,
|
||||
m[0], m[1], m[2], 0.0,
|
||||
m[3], m[4], m[5], 0.0,
|
||||
m[6], m[7], m[8], 0.0,
|
||||
0.0, 0.0, 0.0, 1.0));
|
||||
} else {
|
||||
return image.recomb(VImage::new_matrix(4, 4, m, 16));
|
||||
}
|
||||
}
|
||||
|
||||
VImage Modulate(VImage image, double const brightness, double const saturation,
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace sharp {
|
||||
* Recomb with a Matrix of the given bands/channel size.
|
||||
* Eg. RGB will be a 3x3 matrix.
|
||||
*/
|
||||
VImage Recomb(VImage image, std::unique_ptr<double[]> const &matrix);
|
||||
VImage Recomb(VImage image, std::vector<double> const &matrix);
|
||||
|
||||
/*
|
||||
* Modulate brightness, saturation, hue and lightness
|
||||
|
||||
@@ -609,7 +609,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
}
|
||||
|
||||
// Recomb
|
||||
if (baton->recombMatrix != NULL) {
|
||||
if (!baton->recombMatrix.empty()) {
|
||||
image = sharp::Recomb(image, baton->recombMatrix);
|
||||
}
|
||||
|
||||
@@ -1613,10 +1613,11 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
||||
}
|
||||
}
|
||||
if (options.Has("recombMatrix")) {
|
||||
baton->recombMatrix = std::unique_ptr<double[]>(new double[9]);
|
||||
Napi::Array recombMatrix = options.Get("recombMatrix").As<Napi::Array>();
|
||||
for (unsigned int i = 0; i < 9; i++) {
|
||||
baton->recombMatrix[i] = sharp::AttrAsDouble(recombMatrix, i);
|
||||
unsigned int matrixElements = recombMatrix.Length();
|
||||
baton->recombMatrix.resize(matrixElements);
|
||||
for (unsigned int i = 0; i < matrixElements; i++) {
|
||||
baton->recombMatrix[i] = sharp::AttrAsDouble(recombMatrix, i);
|
||||
}
|
||||
}
|
||||
baton->colourspacePipeline = sharp::AttrAsEnum<VipsInterpretation>(
|
||||
|
||||
@@ -223,7 +223,7 @@ struct PipelineBaton {
|
||||
VipsForeignDzDepth tileDepth;
|
||||
std::string tileId;
|
||||
std::string tileBasename;
|
||||
std::unique_ptr<double[]> recombMatrix;
|
||||
std::vector<double> recombMatrix;
|
||||
|
||||
PipelineBaton():
|
||||
input(nullptr),
|
||||
|
||||
Reference in New Issue
Block a user