@revizly/sharp 0.33.4-revizly5 → 0.33.4-revizly6

Sign up to get free protection for your applications and to get access to all the features.
package/lib/index.d.ts CHANGED
@@ -571,11 +571,11 @@ declare namespace sharp {
571
571
 
572
572
  /**
573
573
  * Recomb the image with the specified matrix.
574
- * @param inputMatrix 3x3 Recombination matrix
574
+ * @param inputMatrix 3x3 Recombination matrix or 4x4 Recombination matrix
575
575
  * @throws {Error} Invalid parameters
576
576
  * @returns A sharp instance that can be used to chain operations
577
577
  */
578
- recomb(inputMatrix: Matrix3x3): Sharp;
578
+ recomb(inputMatrix: Matrix3x3 | Matrix4x4): Sharp;
579
579
 
580
580
  /**
581
581
  * Transforms the image using brightness, saturation, hue rotation and lightness.
@@ -1730,6 +1730,7 @@ declare namespace sharp {
1730
1730
 
1731
1731
  type Matrix2x2 = [[number, number], [number, number]];
1732
1732
  type Matrix3x3 = [[number, number, number], [number, number, number], [number, number, number]];
1733
+ type Matrix4x4 = [[number, number, number, number], [number, number, number, number], [number, number, number, number], [number, number, number, number]];
1733
1734
  }
1734
1735
 
1735
1736
  export = sharp;
package/lib/operation.js CHANGED
@@ -787,24 +787,22 @@ function linear (a, b) {
787
787
  * // With this example input, a sepia filter has been applied
788
788
  * });
789
789
  *
790
- * @param {Array<Array<number>>} inputMatrix - 3x3 Recombination matrix
790
+ * @param {Array<Array<number>>} inputMatrix - 3x3 or 4x4 Recombination matrix
791
791
  * @returns {Sharp}
792
792
  * @throws {Error} Invalid parameters
793
793
  */
794
794
  function recomb (inputMatrix) {
795
- if (!Array.isArray(inputMatrix) || inputMatrix.length !== 3 ||
796
- inputMatrix[0].length !== 3 ||
797
- inputMatrix[1].length !== 3 ||
798
- inputMatrix[2].length !== 3
799
- ) {
800
- // must pass in a kernel
801
- throw new Error('Invalid recombination matrix');
795
+ if (!Array.isArray(inputMatrix)) {
796
+ throw is.invalidParameterError('inputMatrix', 'array', inputMatrix);
797
+ }
798
+ if (inputMatrix.length !== 3 && inputMatrix.length !== 4) {
799
+ throw is.invalidParameterError('inputMatrix', '3x3 or 4x4 array', inputMatrix.length);
800
+ }
801
+ const recombMatrix = inputMatrix.flat().map(Number);
802
+ if (recombMatrix.length !== 9 && recombMatrix.length !== 16) {
803
+ throw is.invalidParameterError('inputMatrix', 'cardinality of 9 or 16', recombMatrix.length);
802
804
  }
803
- this.options.recombMatrix = [
804
- inputMatrix[0][0], inputMatrix[0][1], inputMatrix[0][2],
805
- inputMatrix[1][0], inputMatrix[1][1], inputMatrix[1][2],
806
- inputMatrix[2][0], inputMatrix[2][1], inputMatrix[2][2]
807
- ].map(Number);
805
+ this.options.recombMatrix = recombMatrix;
808
806
  return this;
809
807
  }
810
808
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@revizly/sharp",
3
3
  "description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
4
- "version": "0.33.4-revizly5",
4
+ "version": "0.33.4-revizly6",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://sharp.pixelplumbing.com",
7
7
  "contributors": [
package/src/operations.cc CHANGED
@@ -164,10 +164,10 @@ namespace sharp {
164
164
  */
165
165
  VImage Convolve(VImage image, int const width, int const height,
166
166
  double const scale, double const offset,
167
- std::unique_ptr<double[]> const &kernel_v
167
+ std::vector<double> const &kernel_v
168
168
  ) {
169
169
  VImage kernel = VImage::new_from_memory(
170
- kernel_v.get(),
170
+ static_cast<void*>(const_cast<double*>(kernel_v.data())),
171
171
  width * height * sizeof(double),
172
172
  width,
173
173
  height,
@@ -183,19 +183,21 @@ namespace sharp {
183
183
  * Recomb with a Matrix of the given bands/channel size.
184
184
  * Eg. RGB will be a 3x3 matrix.
185
185
  */
186
- VImage Recomb(VImage image, std::unique_ptr<double[]> const &matrix) {
187
- double *m = matrix.get();
186
+ VImage Recomb(VImage image, std::vector<double> const& matrix) {
187
+ double* m = const_cast<double*>(matrix.data());
188
188
  image = image.colourspace(VIPS_INTERPRETATION_sRGB);
189
- return image
190
- .recomb(image.bands() == 3
191
- ? VImage::new_from_memory(
192
- m, 9 * sizeof(double), 3, 3, 1, VIPS_FORMAT_DOUBLE
193
- )
194
- : VImage::new_matrixv(4, 4,
195
- m[0], m[1], m[2], 0.0,
196
- m[3], m[4], m[5], 0.0,
197
- m[6], m[7], m[8], 0.0,
198
- 0.0, 0.0, 0.0, 1.0));
189
+ if (matrix.size() == 9) {
190
+ return image
191
+ .recomb(image.bands() == 3
192
+ ? VImage::new_matrix(3, 3, m, 9)
193
+ : VImage::new_matrixv(4, 4,
194
+ m[0], m[1], m[2], 0.0,
195
+ m[3], m[4], m[5], 0.0,
196
+ m[6], m[7], m[8], 0.0,
197
+ 0.0, 0.0, 0.0, 1.0));
198
+ } else {
199
+ return image.recomb(VImage::new_matrix(4, 4, m, 16));
200
+ }
199
201
  }
200
202
 
201
203
  VImage Modulate(VImage image, double const brightness, double const saturation,
package/src/operations.h CHANGED
@@ -53,7 +53,7 @@ namespace sharp {
53
53
  * Convolution with a kernel.
54
54
  */
55
55
  VImage Convolve(VImage image, int const width, int const height,
56
- double const scale, double const offset, std::unique_ptr<double[]> const &kernel_v);
56
+ double const scale, double const offset, std::vector<double> const &kernel_v);
57
57
 
58
58
  /*
59
59
  * Sharpen flat and jagged areas. Use sigma of -1.0 for fast sharpen.
@@ -95,7 +95,7 @@ namespace sharp {
95
95
  * Recomb with a Matrix of the given bands/channel size.
96
96
  * Eg. RGB will be a 3x3 matrix.
97
97
  */
98
- VImage Recomb(VImage image, std::unique_ptr<double[]> const &matrix);
98
+ VImage Recomb(VImage image, std::vector<double> const &matrix);
99
99
 
100
100
  /*
101
101
  * Modulate brightness, saturation, hue and lightness
package/src/pipeline.cc CHANGED
@@ -609,7 +609,7 @@ class PipelineWorker : public Napi::AsyncWorker {
609
609
  }
610
610
 
611
611
  // Recomb
612
- if (baton->recombMatrix != NULL) {
612
+ if (!baton->recombMatrix.empty()) {
613
613
  image = sharp::Recomb(image, baton->recombMatrix);
614
614
  }
615
615
 
@@ -1606,17 +1606,18 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
1606
1606
  baton->convKernelScale = sharp::AttrAsDouble(kernel, "scale");
1607
1607
  baton->convKernelOffset = sharp::AttrAsDouble(kernel, "offset");
1608
1608
  size_t const kernelSize = static_cast<size_t>(baton->convKernelWidth * baton->convKernelHeight);
1609
- baton->convKernel = std::unique_ptr<double[]>(new double[kernelSize]);
1609
+ baton->convKernel.resize(kernelSize);
1610
1610
  Napi::Array kdata = kernel.Get("kernel").As<Napi::Array>();
1611
1611
  for (unsigned int i = 0; i < kernelSize; i++) {
1612
1612
  baton->convKernel[i] = sharp::AttrAsDouble(kdata, i);
1613
1613
  }
1614
1614
  }
1615
1615
  if (options.Has("recombMatrix")) {
1616
- baton->recombMatrix = std::unique_ptr<double[]>(new double[9]);
1617
1616
  Napi::Array recombMatrix = options.Get("recombMatrix").As<Napi::Array>();
1618
- for (unsigned int i = 0; i < 9; i++) {
1619
- baton->recombMatrix[i] = sharp::AttrAsDouble(recombMatrix, i);
1617
+ unsigned int matrixElements = recombMatrix.Length();
1618
+ baton->recombMatrix.resize(matrixElements);
1619
+ for (unsigned int i = 0; i < matrixElements; i++) {
1620
+ baton->recombMatrix[i] = sharp::AttrAsDouble(recombMatrix, i);
1620
1621
  }
1621
1622
  }
1622
1623
  baton->colourspacePipeline = sharp::AttrAsEnum<VipsInterpretation>(
package/src/pipeline.h CHANGED
@@ -197,7 +197,7 @@ struct PipelineBaton {
197
197
  std::unordered_map<std::string, std::string> withExif;
198
198
  bool withExifMerge;
199
199
  int timeoutSeconds;
200
- std::unique_ptr<double[]> convKernel;
200
+ std::vector<double> convKernel;
201
201
  int convKernelWidth;
202
202
  int convKernelHeight;
203
203
  double convKernelScale;
@@ -223,7 +223,7 @@ struct PipelineBaton {
223
223
  VipsForeignDzDepth tileDepth;
224
224
  std::string tileId;
225
225
  std::string tileBasename;
226
- std::unique_ptr<double[]> recombMatrix;
226
+ std::vector<double> recombMatrix;
227
227
 
228
228
  PipelineBaton():
229
229
  input(nullptr),