@depup/sharp 0.34.5-depup.0 → 0.35.4-depup.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/README.md +16 -109
- package/changes.json +5 -0
- package/{lib/channel.js → dist/channel.cjs} +1 -1
- package/dist/channel.mjs +177 -0
- package/{lib/colour.js → dist/colour.cjs} +11 -7
- package/dist/colour.mjs +199 -0
- package/{lib/composite.js → dist/composite.cjs} +8 -7
- package/dist/composite.mjs +213 -0
- package/{lib/constructor.js → dist/constructor.cjs} +42 -30
- package/dist/constructor.mjs +511 -0
- package/dist/index.cjs +25 -0
- package/dist/index.d.cts +1999 -0
- package/dist/index.d.mts +2046 -0
- package/dist/index.mjs +25 -0
- package/{lib/input.js → dist/input.cjs} +47 -37
- package/dist/input.mjs +819 -0
- package/{lib/is.js → dist/is.cjs} +1 -1
- package/dist/is.mjs +143 -0
- package/{lib/libvips.js → dist/libvips.cjs} +35 -30
- package/dist/libvips.mjs +212 -0
- package/{lib/operation.js → dist/operation.cjs} +37 -51
- package/dist/operation.mjs +1002 -0
- package/{lib/output.js → dist/output.cjs} +166 -47
- package/dist/output.mjs +1785 -0
- package/{lib/resize.js → dist/resize.cjs} +54 -32
- package/dist/resize.mjs +617 -0
- package/dist/sharp.cjs +174 -0
- package/dist/sharp.mjs +174 -0
- package/{lib/utility.js → dist/utility.cjs} +18 -8
- package/dist/utility.mjs +301 -0
- package/install/build.js +3 -3
- package/lib/index.d.ts +111 -83
- package/package.json +95 -54
- package/src/binding.gyp +19 -14
- package/src/common.cc +77 -21
- package/src/common.h +23 -4
- package/src/metadata.cc +66 -8
- package/src/metadata.h +6 -1
- package/src/operations.cc +25 -8
- package/src/operations.h +1 -1
- package/src/pipeline.cc +203 -69
- package/src/pipeline.h +15 -1
- package/src/stats.cc +6 -6
- package/src/utilities.cc +7 -6
- package/install/check.js +0 -14
- package/lib/index.js +0 -16
- package/lib/sharp.js +0 -121
package/src/metadata.cc
CHANGED
|
@@ -31,7 +31,7 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|
|
31
31
|
sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
|
|
32
32
|
try {
|
|
33
33
|
std::tie(image, imageType) = OpenInput(baton->input);
|
|
34
|
-
} catch (
|
|
34
|
+
} catch (std::runtime_error const &err) {
|
|
35
35
|
(baton->err).append(err.what());
|
|
36
36
|
}
|
|
37
37
|
if (imageType != sharp::ImageType::UNKNOWN) {
|
|
@@ -141,8 +141,60 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|
|
141
141
|
memcpy(baton->tifftagPhotoshop, tifftagPhotoshop, tifftagPhotoshopLength);
|
|
142
142
|
baton->tifftagPhotoshopLength = tifftagPhotoshopLength;
|
|
143
143
|
}
|
|
144
|
+
// Gain Map
|
|
145
|
+
if (image.get_typeof("gainmap-data") == VIPS_TYPE_BLOB) {
|
|
146
|
+
size_t gainMapLength;
|
|
147
|
+
void const *gainMap = image.get_blob("gainmap-data", &gainMapLength);
|
|
148
|
+
baton->gainMap = static_cast<char *>(g_malloc(gainMapLength));
|
|
149
|
+
memcpy(baton->gainMap, gainMap, gainMapLength);
|
|
150
|
+
baton->gainMapLength = gainMapLength;
|
|
151
|
+
}
|
|
144
152
|
// PNG comments
|
|
145
153
|
vips_image_map(image.get_image(), readPNGComment, &baton->comments);
|
|
154
|
+
// Media type
|
|
155
|
+
std::string mediaType;
|
|
156
|
+
switch (imageType) {
|
|
157
|
+
case sharp::ImageType::JPEG:
|
|
158
|
+
case sharp::ImageType::PNG:
|
|
159
|
+
case sharp::ImageType::WEBP:
|
|
160
|
+
case sharp::ImageType::JP2:
|
|
161
|
+
case sharp::ImageType::TIFF:
|
|
162
|
+
case sharp::ImageType::GIF:
|
|
163
|
+
case sharp::ImageType::FITS:
|
|
164
|
+
case sharp::ImageType::JXL:
|
|
165
|
+
baton->mediaType = "image/" + baton->format;
|
|
166
|
+
break;
|
|
167
|
+
case sharp::ImageType::SVG:
|
|
168
|
+
baton->mediaType = "image/svg+xml";
|
|
169
|
+
break;
|
|
170
|
+
case sharp::ImageType::HEIF:
|
|
171
|
+
if (baton->compression == "av1") {
|
|
172
|
+
baton->mediaType = "image/avif";
|
|
173
|
+
} else if (baton->compression == "hevc") {
|
|
174
|
+
baton->mediaType = "image/heic";
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
case sharp::ImageType::PDF:
|
|
178
|
+
baton->mediaType = "application/pdf";
|
|
179
|
+
break;
|
|
180
|
+
case sharp::ImageType::OPENSLIDE:
|
|
181
|
+
baton->mediaType = "image/tiff";
|
|
182
|
+
break;
|
|
183
|
+
case sharp::ImageType::PPM:
|
|
184
|
+
baton->mediaType = "image/x-portable-pixmap";
|
|
185
|
+
break;
|
|
186
|
+
case sharp::ImageType::EXR:
|
|
187
|
+
baton->mediaType = "image/x-exr";
|
|
188
|
+
break;
|
|
189
|
+
case sharp::ImageType::RAD:
|
|
190
|
+
baton->mediaType = "image/vnd.radiance";
|
|
191
|
+
break;
|
|
192
|
+
case sharp::ImageType::UHDR:
|
|
193
|
+
baton->mediaType = "image/jpeg";
|
|
194
|
+
break;
|
|
195
|
+
default:
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
146
198
|
}
|
|
147
199
|
|
|
148
200
|
// Clean up
|
|
@@ -157,13 +209,16 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|
|
157
209
|
// Handle warnings
|
|
158
210
|
std::string warning = sharp::VipsWarningPop();
|
|
159
211
|
while (!warning.empty()) {
|
|
160
|
-
debuglog.
|
|
212
|
+
debuglog.SHARP_CALLBACK_FN_NAME(Receiver().Value(), { Napi::String::New(env, warning) });
|
|
161
213
|
warning = sharp::VipsWarningPop();
|
|
162
214
|
}
|
|
163
215
|
|
|
164
216
|
if (baton->err.empty()) {
|
|
165
217
|
Napi::Object info = Napi::Object::New(env);
|
|
166
218
|
info.Set("format", baton->format);
|
|
219
|
+
if (!baton->mediaType.empty()) {
|
|
220
|
+
info.Set("mediaType", baton->mediaType);
|
|
221
|
+
}
|
|
167
222
|
if (baton->input->bufferLength > 0) {
|
|
168
223
|
info.Set("size", baton->input->bufferLength);
|
|
169
224
|
}
|
|
@@ -182,10 +237,6 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|
|
182
237
|
info.Set("isPalette", baton->isPalette);
|
|
183
238
|
if (baton->bitsPerSample > 0) {
|
|
184
239
|
info.Set("bitsPerSample", baton->bitsPerSample);
|
|
185
|
-
if (baton->isPalette) {
|
|
186
|
-
// Deprecated, remove with libvips 8.17.0
|
|
187
|
-
info.Set("paletteBitDepth", baton->bitsPerSample);
|
|
188
|
-
}
|
|
189
240
|
}
|
|
190
241
|
if (baton->pages > 0) {
|
|
191
242
|
info.Set("pages", baton->pages);
|
|
@@ -276,6 +327,12 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|
|
276
327
|
Napi::Buffer<char>::NewOrCopy(env, baton->tifftagPhotoshop,
|
|
277
328
|
baton->tifftagPhotoshopLength, sharp::FreeCallback));
|
|
278
329
|
}
|
|
330
|
+
if (baton->gainMapLength > 0) {
|
|
331
|
+
Napi::Object gainMap = Napi::Object::New(env);
|
|
332
|
+
info.Set("gainMap", gainMap);
|
|
333
|
+
gainMap.Set("image",
|
|
334
|
+
Napi::Buffer<char>::NewOrCopy(env, baton->gainMap, baton->gainMapLength, sharp::FreeCallback));
|
|
335
|
+
}
|
|
279
336
|
if (baton->comments.size() > 0) {
|
|
280
337
|
int i = 0;
|
|
281
338
|
Napi::Array comments = Napi::Array::New(env, baton->comments.size());
|
|
@@ -287,9 +344,10 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|
|
287
344
|
}
|
|
288
345
|
info.Set("comments", comments);
|
|
289
346
|
}
|
|
290
|
-
Callback().
|
|
347
|
+
Callback().SHARP_CALLBACK_FN_NAME(Receiver().Value(), { env.Null(), info });
|
|
291
348
|
} else {
|
|
292
|
-
Callback().
|
|
349
|
+
Callback().SHARP_CALLBACK_FN_NAME(Receiver().Value(),
|
|
350
|
+
{ Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() });
|
|
293
351
|
}
|
|
294
352
|
|
|
295
353
|
delete baton->input;
|
package/src/metadata.h
CHANGED
|
@@ -19,6 +19,7 @@ struct MetadataBaton {
|
|
|
19
19
|
sharp::InputDescriptor *input;
|
|
20
20
|
// Output
|
|
21
21
|
std::string format;
|
|
22
|
+
std::string mediaType;
|
|
22
23
|
int width;
|
|
23
24
|
int height;
|
|
24
25
|
std::string space;
|
|
@@ -53,6 +54,8 @@ struct MetadataBaton {
|
|
|
53
54
|
size_t xmpLength;
|
|
54
55
|
char *tifftagPhotoshop;
|
|
55
56
|
size_t tifftagPhotoshopLength;
|
|
57
|
+
char *gainMap;
|
|
58
|
+
size_t gainMapLength;
|
|
56
59
|
MetadataComments comments;
|
|
57
60
|
std::string err;
|
|
58
61
|
|
|
@@ -82,7 +85,9 @@ struct MetadataBaton {
|
|
|
82
85
|
xmp(nullptr),
|
|
83
86
|
xmpLength(0),
|
|
84
87
|
tifftagPhotoshop(nullptr),
|
|
85
|
-
tifftagPhotoshopLength(0)
|
|
88
|
+
tifftagPhotoshopLength(0),
|
|
89
|
+
gainMap(nullptr),
|
|
90
|
+
gainMapLength(0) {}
|
|
86
91
|
};
|
|
87
92
|
|
|
88
93
|
Napi::Value metadata(const Napi::CallbackInfo& info);
|
package/src/operations.cc
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
#include "./operations.h"
|
|
15
15
|
|
|
16
16
|
using vips::VImage;
|
|
17
|
-
using vips::VError;
|
|
18
17
|
|
|
19
18
|
namespace sharp {
|
|
20
19
|
/*
|
|
@@ -285,9 +284,9 @@ namespace sharp {
|
|
|
285
284
|
/*
|
|
286
285
|
Trim an image
|
|
287
286
|
*/
|
|
288
|
-
VImage Trim(VImage image, std::vector<double> background, double threshold, bool const lineArt) {
|
|
287
|
+
VImage Trim(VImage image, std::vector<double> background, double threshold, bool const lineArt, int const margin) {
|
|
289
288
|
if (image.width() < 3 && image.height() < 3) {
|
|
290
|
-
throw
|
|
289
|
+
throw std::runtime_error("Image to trim must be at least 3x3 pixels");
|
|
291
290
|
}
|
|
292
291
|
if (background.size() == 0) {
|
|
293
292
|
// Top-left pixel provides the default background colour if none is given
|
|
@@ -320,18 +319,36 @@ namespace sharp {
|
|
|
320
319
|
if (widthA > 0 && heightA > 0) {
|
|
321
320
|
if (width > 0 && height > 0) {
|
|
322
321
|
// Combined bounding box (B)
|
|
323
|
-
int
|
|
324
|
-
int
|
|
325
|
-
int
|
|
326
|
-
int
|
|
322
|
+
int leftB = std::min(left, leftA);
|
|
323
|
+
int topB = std::min(top, topA);
|
|
324
|
+
int widthB = std::max(left + width, leftA + widthA) - leftB;
|
|
325
|
+
int heightB = std::max(top + height, topA + heightA) - topB;
|
|
326
|
+
if (margin > 0) {
|
|
327
|
+
leftB = std::max(0, leftB - margin);
|
|
328
|
+
topB = std::max(0, topB - margin);
|
|
329
|
+
widthB = std::min(image.width() - leftB, widthB + 2 * margin);
|
|
330
|
+
heightB = std::min(image.height() - topB, heightB + 2 * margin);
|
|
331
|
+
}
|
|
327
332
|
return image.extract_area(leftB, topB, widthB, heightB);
|
|
328
333
|
} else {
|
|
329
334
|
// Use alpha only
|
|
335
|
+
if (margin > 0) {
|
|
336
|
+
leftA = std::max(0, leftA - margin);
|
|
337
|
+
topA = std::max(0, topA - margin);
|
|
338
|
+
widthA = std::min(image.width() - leftA, widthA + 2 * margin);
|
|
339
|
+
heightA = std::min(image.height() - topA, heightA + 2 * margin);
|
|
340
|
+
}
|
|
330
341
|
return image.extract_area(leftA, topA, widthA, heightA);
|
|
331
342
|
}
|
|
332
343
|
}
|
|
333
344
|
}
|
|
334
345
|
if (width > 0 && height > 0) {
|
|
346
|
+
if (margin > 0) {
|
|
347
|
+
left = std::max(0, left - margin);
|
|
348
|
+
top = std::max(0, top - margin);
|
|
349
|
+
width = std::min(image.width() - left, width + 2 * margin);
|
|
350
|
+
height = std::min(image.height() - top, height + 2 * margin);
|
|
351
|
+
}
|
|
335
352
|
return image.extract_area(left, top, width, height);
|
|
336
353
|
}
|
|
337
354
|
return image;
|
|
@@ -343,7 +360,7 @@ namespace sharp {
|
|
|
343
360
|
VImage Linear(VImage image, std::vector<double> const a, std::vector<double> const b) {
|
|
344
361
|
size_t const bands = static_cast<size_t>(image.bands());
|
|
345
362
|
if (a.size() > bands) {
|
|
346
|
-
throw
|
|
363
|
+
throw std::runtime_error("Band expansion using linear is unsupported");
|
|
347
364
|
}
|
|
348
365
|
bool const uchar = !Is16Bit(image.interpretation());
|
|
349
366
|
if (image.has_alpha() && a.size() != bands && (a.size() == 1 || a.size() == bands - 1 || bands - 1 == 1)) {
|
package/src/operations.h
CHANGED
|
@@ -82,7 +82,7 @@ namespace sharp {
|
|
|
82
82
|
/*
|
|
83
83
|
Trim an image
|
|
84
84
|
*/
|
|
85
|
-
VImage Trim(VImage image, std::vector<double> background, double threshold, bool const lineArt);
|
|
85
|
+
VImage Trim(VImage image, std::vector<double> background, double threshold, bool const lineArt, int const margin);
|
|
86
86
|
|
|
87
87
|
/*
|
|
88
88
|
* Linear adjustment (a * in + b)
|