sharp 0.20.5 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/pipeline.h CHANGED
@@ -61,18 +61,18 @@ struct PipelineBaton {
61
61
  int height;
62
62
  int channels;
63
63
  Canvas canvas;
64
- int crop;
65
- int embed;
64
+ int position;
65
+ std::vector<double> resizeBackground;
66
66
  bool hasCropOffset;
67
67
  int cropOffsetLeft;
68
68
  int cropOffsetTop;
69
69
  bool premultiplied;
70
70
  std::string kernel;
71
71
  bool fastShrinkOnLoad;
72
- double background[4];
73
72
  double tintA;
74
73
  double tintB;
75
74
  bool flatten;
75
+ std::vector<double> flattenBackground;
76
76
  bool negate;
77
77
  double blurSigma;
78
78
  int medianSize;
@@ -81,7 +81,9 @@ struct PipelineBaton {
81
81
  double sharpenJagged;
82
82
  int threshold;
83
83
  bool thresholdGrayscale;
84
- int trimTolerance;
84
+ double trimThreshold;
85
+ int trimOffsetLeft;
86
+ int trimOffsetTop;
85
87
  double linearA;
86
88
  double linearB;
87
89
  double gamma;
@@ -89,6 +91,8 @@ struct PipelineBaton {
89
91
  bool normalise;
90
92
  bool useExifOrientation;
91
93
  int angle;
94
+ double rotationAngle;
95
+ std::vector<double> rotationBackground;
92
96
  bool rotateBeforePreExtract;
93
97
  bool flip;
94
98
  bool flop;
@@ -96,12 +100,14 @@ struct PipelineBaton {
96
100
  int extendBottom;
97
101
  int extendLeft;
98
102
  int extendRight;
103
+ std::vector<double> extendBackground;
99
104
  bool withoutEnlargement;
100
105
  VipsAccess accessMethod;
101
106
  int jpegQuality;
102
107
  bool jpegProgressive;
103
108
  std::string jpegChromaSubsampling;
104
109
  bool jpegTrellisQuantisation;
110
+ int jpegQuantisationTable;
105
111
  bool jpegOvershootDeringing;
106
112
  bool jpegOptimiseScans;
107
113
  bool jpegOptimiseCoding;
@@ -130,6 +136,7 @@ struct PipelineBaton {
130
136
  VipsOperationBoolean booleanOp;
131
137
  VipsOperationBoolean bandBoolOp;
132
138
  int extractChannel;
139
+ bool removeAlpha;
133
140
  VipsInterpretation colourspace;
134
141
  int tileSize;
135
142
  int tileOverlap;
@@ -137,6 +144,7 @@ struct PipelineBaton {
137
144
  VipsForeignDzLayout tileLayout;
138
145
  std::string tileFormat;
139
146
  int tileAngle;
147
+ VipsForeignDzDepth tileDepth;
140
148
 
141
149
  PipelineBaton():
142
150
  input(nullptr),
@@ -152,8 +160,8 @@ struct PipelineBaton {
152
160
  topOffsetPost(-1),
153
161
  channels(0),
154
162
  canvas(Canvas::CROP),
155
- crop(0),
156
- embed(0),
163
+ position(0),
164
+ resizeBackground{ 0.0, 0.0, 0.0, 255.0 },
157
165
  hasCropOffset(false),
158
166
  cropOffsetLeft(0),
159
167
  cropOffsetTop(0),
@@ -161,6 +169,7 @@ struct PipelineBaton {
161
169
  tintA(128.0),
162
170
  tintB(128.0),
163
171
  flatten(false),
172
+ flattenBackground{ 0.0, 0.0, 0.0 },
164
173
  negate(false),
165
174
  blurSigma(0.0),
166
175
  medianSize(0),
@@ -169,7 +178,9 @@ struct PipelineBaton {
169
178
  sharpenJagged(2.0),
170
179
  threshold(0),
171
180
  thresholdGrayscale(true),
172
- trimTolerance(0),
181
+ trimThreshold(0.0),
182
+ trimOffsetLeft(0),
183
+ trimOffsetTop(0),
173
184
  linearA(1.0),
174
185
  linearB(0.0),
175
186
  gamma(0.0),
@@ -177,17 +188,21 @@ struct PipelineBaton {
177
188
  normalise(false),
178
189
  useExifOrientation(false),
179
190
  angle(0),
191
+ rotationAngle(0.0),
192
+ rotationBackground{ 0.0, 0.0, 0.0, 255.0 },
180
193
  flip(false),
181
194
  flop(false),
182
195
  extendTop(0),
183
196
  extendBottom(0),
184
197
  extendLeft(0),
185
198
  extendRight(0),
199
+ extendBackground{ 0.0, 0.0, 0.0, 255.0 },
186
200
  withoutEnlargement(false),
187
201
  jpegQuality(80),
188
202
  jpegProgressive(false),
189
203
  jpegChromaSubsampling("4:2:0"),
190
204
  jpegTrellisQuantisation(false),
205
+ jpegQuantisationTable(0),
191
206
  jpegOvershootDeringing(false),
192
207
  jpegOptimiseScans(false),
193
208
  jpegOptimiseCoding(true),
@@ -211,17 +226,14 @@ struct PipelineBaton {
211
226
  booleanOp(VIPS_OPERATION_BOOLEAN_LAST),
212
227
  bandBoolOp(VIPS_OPERATION_BOOLEAN_LAST),
213
228
  extractChannel(-1),
229
+ removeAlpha(false),
214
230
  colourspace(VIPS_INTERPRETATION_LAST),
215
231
  tileSize(256),
216
232
  tileOverlap(0),
217
233
  tileContainer(VIPS_FOREIGN_DZ_CONTAINER_FS),
218
234
  tileLayout(VIPS_FOREIGN_DZ_LAYOUT_DZ),
219
- tileAngle(0){
220
- background[0] = 0.0;
221
- background[1] = 0.0;
222
- background[2] = 0.0;
223
- background[3] = 255.0;
224
- }
235
+ tileAngle(0),
236
+ tileDepth(VIPS_FOREIGN_DZ_DEPTH_LAST) {}
225
237
  };
226
238
 
227
239
  #endif // SRC_PIPELINE_H_
package/src/stats.cc CHANGED
@@ -59,7 +59,6 @@ class StatsWorker : public Nan::AsyncWorker {
59
59
  using sharp::MaximumImageAlpha;
60
60
 
61
61
  vips::VImage image;
62
- vips::VImage stats;
63
62
  sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
64
63
 
65
64
  try {
@@ -69,9 +68,8 @@ class StatsWorker : public Nan::AsyncWorker {
69
68
  }
70
69
  if (imageType != sharp::ImageType::UNKNOWN) {
71
70
  try {
72
- stats = image.stats();
73
- int bands = image.bands();
74
- double const max = MaximumImageAlpha(image.interpretation());
71
+ vips::VImage stats = image.stats();
72
+ int const bands = image.bands();
75
73
  for (int b = 1; b <= bands; b++) {
76
74
  ChannelStats cStats(static_cast<int>(stats.getpoint(STAT_MIN_INDEX, b).front()),
77
75
  static_cast<int>(stats.getpoint(STAT_MAX_INDEX, b).front()),
@@ -83,11 +81,15 @@ class StatsWorker : public Nan::AsyncWorker {
83
81
  static_cast<int>(stats.getpoint(STAT_MAXY_INDEX, b).front()));
84
82
  baton->channelStats.push_back(cStats);
85
83
  }
86
-
87
- // alpha layer is there and the last band i.e. alpha has its max value greater than 0)
88
- if (sharp::HasAlpha(image) && stats.getpoint(STAT_MIN_INDEX, bands).front() != max) {
89
- baton->isOpaque = false;
84
+ // Image is not opaque when alpha layer is present and contains a non-mamixa value
85
+ if (sharp::HasAlpha(image)) {
86
+ double const minAlpha = static_cast<double>(stats.getpoint(STAT_MIN_INDEX, bands).front());
87
+ if (minAlpha != MaximumImageAlpha(image.interpretation())) {
88
+ baton->isOpaque = false;
89
+ }
90
90
  }
91
+ // Estimate entropy via histogram of greyscale value frequency
92
+ baton->entropy = std::abs(image.colourspace(VIPS_INTERPRETATION_B_W)[0].hist_find().hist_entropy());
91
93
  } catch (vips::VError const &err) {
92
94
  (baton->err).append(err.what());
93
95
  }
@@ -130,6 +132,7 @@ class StatsWorker : public Nan::AsyncWorker {
130
132
 
131
133
  Set(info, New("channels").ToLocalChecked(), channels);
132
134
  Set(info, New("isOpaque").ToLocalChecked(), New<v8::Boolean>(baton->isOpaque));
135
+ Set(info, New("entropy").ToLocalChecked(), New<v8::Number>(baton->entropy));
133
136
  argv[1] = info;
134
137
  }
135
138
 
package/src/stats.h CHANGED
@@ -51,12 +51,14 @@ struct StatsBaton {
51
51
  // Output
52
52
  std::vector<ChannelStats> channelStats;
53
53
  bool isOpaque;
54
+ double entropy;
54
55
 
55
56
  std::string err;
56
57
 
57
58
  StatsBaton():
58
59
  input(nullptr),
59
- isOpaque(true)
60
+ isOpaque(true),
61
+ entropy(0.0)
60
62
  {}
61
63
  };
62
64
 
package/src/utilities.cc CHANGED
@@ -259,7 +259,7 @@ NAN_METHOD(_maxColourDistance) {
259
259
  }
260
260
  // Calculate colour distance
261
261
  maxColourDistance = image1.dE00(image2).max();
262
- } catch (VError err) {
262
+ } catch (VError const &err) {
263
263
  return ThrowError(err.what());
264
264
  }
265
265