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/README.md +3 -3
- package/binding.gyp +5 -0
- package/docs/api-channel.md +16 -0
- package/docs/api-colour.md +1 -19
- package/docs/api-composite.md +2 -3
- package/docs/api-constructor.md +2 -2
- package/docs/api-input.md +6 -2
- package/docs/api-operation.md +40 -115
- package/docs/api-output.md +3 -0
- package/docs/api-resize.md +159 -109
- package/docs/api-utility.md +4 -7
- package/docs/changelog.md +87 -0
- package/docs/index.md +10 -4
- package/docs/install.md +18 -38
- package/docs/performance.md +14 -21
- package/install/dll-copy.js +3 -2
- package/install/libvips.js +55 -36
- package/lib/channel.js +18 -0
- package/lib/colour.js +34 -15
- package/lib/composite.js +2 -3
- package/lib/constructor.js +19 -41
- package/lib/input.js +7 -3
- package/lib/libvips.js +38 -6
- package/lib/operation.js +27 -118
- package/lib/output.js +22 -2
- package/lib/platform.js +4 -1
- package/lib/resize.js +308 -104
- package/lib/utility.js +5 -8
- package/package.json +20 -13
- package/src/common.cc +50 -13
- package/src/common.h +12 -10
- package/src/libvips/cplusplus/VImage.cpp +95 -95
- package/src/libvips/cplusplus/vips-operators.cpp +268 -185
- package/src/metadata.cc +15 -0
- package/src/metadata.h +3 -0
- package/src/operations.cc +27 -54
- package/src/operations.h +6 -1
- package/src/pipeline.cc +81 -89
- package/src/pipeline.h +25 -13
- package/src/stats.cc +11 -8
- package/src/stats.h +3 -1
- package/src/utilities.cc +1 -1
package/src/common.cc
CHANGED
|
@@ -37,6 +37,14 @@ namespace sharp {
|
|
|
37
37
|
std::string AttrAsStr(v8::Handle<v8::Object> obj, std::string attr) {
|
|
38
38
|
return *Nan::Utf8String(Nan::Get(obj, Nan::New(attr).ToLocalChecked()).ToLocalChecked());
|
|
39
39
|
}
|
|
40
|
+
std::vector<double> AttrAsRgba(v8::Handle<v8::Object> obj, std::string attr) {
|
|
41
|
+
v8::Local<v8::Object> background = AttrAs<v8::Object>(obj, attr);
|
|
42
|
+
std::vector<double> rgba(4);
|
|
43
|
+
for (unsigned int i = 0; i < 4; i++) {
|
|
44
|
+
rgba[i] = AttrTo<double>(background, i);
|
|
45
|
+
}
|
|
46
|
+
return rgba;
|
|
47
|
+
}
|
|
40
48
|
|
|
41
49
|
// Create an InputDescriptor instance from a v8::Object describing an input image
|
|
42
50
|
InputDescriptor* CreateInputDescriptor(
|
|
@@ -55,7 +63,7 @@ namespace sharp {
|
|
|
55
63
|
descriptor->failOnError = AttrTo<bool>(input, "failOnError");
|
|
56
64
|
// Density for vector-based input
|
|
57
65
|
if (HasAttr(input, "density")) {
|
|
58
|
-
descriptor->density = AttrTo<
|
|
66
|
+
descriptor->density = AttrTo<double>(input, "density");
|
|
59
67
|
}
|
|
60
68
|
// Raw pixel input
|
|
61
69
|
if (HasAttr(input, "rawChannels")) {
|
|
@@ -72,10 +80,7 @@ namespace sharp {
|
|
|
72
80
|
descriptor->createChannels = AttrTo<uint32_t>(input, "createChannels");
|
|
73
81
|
descriptor->createWidth = AttrTo<uint32_t>(input, "createWidth");
|
|
74
82
|
descriptor->createHeight = AttrTo<uint32_t>(input, "createHeight");
|
|
75
|
-
|
|
76
|
-
for (unsigned int i = 0; i < 4; i++) {
|
|
77
|
-
descriptor->createBackground[i] = AttrTo<double>(createBackground, i);
|
|
78
|
-
}
|
|
83
|
+
descriptor->createBackground = AttrAsRgba(input, "createBackground");
|
|
79
84
|
}
|
|
80
85
|
return descriptor;
|
|
81
86
|
}
|
|
@@ -228,7 +233,7 @@ namespace sharp {
|
|
|
228
233
|
->set("access", accessMethod)
|
|
229
234
|
->set("fail", descriptor->failOnError);
|
|
230
235
|
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
|
231
|
-
option->set("dpi",
|
|
236
|
+
option->set("dpi", descriptor->density);
|
|
232
237
|
}
|
|
233
238
|
if (imageType == ImageType::MAGICK) {
|
|
234
239
|
option->set("density", std::to_string(descriptor->density).data());
|
|
@@ -270,7 +275,7 @@ namespace sharp {
|
|
|
270
275
|
->set("access", accessMethod)
|
|
271
276
|
->set("fail", descriptor->failOnError);
|
|
272
277
|
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
|
273
|
-
option->set("dpi",
|
|
278
|
+
option->set("dpi", descriptor->density);
|
|
274
279
|
}
|
|
275
280
|
if (imageType == ImageType::MAGICK) {
|
|
276
281
|
option->set("density", std::to_string(descriptor->density).data());
|
|
@@ -355,8 +360,8 @@ namespace sharp {
|
|
|
355
360
|
/*
|
|
356
361
|
Set pixels/mm resolution based on a pixels/inch density.
|
|
357
362
|
*/
|
|
358
|
-
void SetDensity(VImage image, const
|
|
359
|
-
const double pixelsPerMm =
|
|
363
|
+
void SetDensity(VImage image, const double density) {
|
|
364
|
+
const double pixelsPerMm = density / 25.4;
|
|
360
365
|
image.set("Xres", pixelsPerMm);
|
|
361
366
|
image.set("Yres", pixelsPerMm);
|
|
362
367
|
image.set(VIPS_META_RESOLUTION_UNIT, "in");
|
|
@@ -370,10 +375,6 @@ namespace sharp {
|
|
|
370
375
|
if (image.width() > 65535 || image.height() > 65535) {
|
|
371
376
|
throw vips::VError("Processed image is too large for the JPEG format");
|
|
372
377
|
}
|
|
373
|
-
} else if (imageType == ImageType::PNG) {
|
|
374
|
-
if (image.width() > 2147483647 || image.height() > 2147483647) {
|
|
375
|
-
throw vips::VError("Processed image is too large for the PNG format");
|
|
376
|
-
}
|
|
377
378
|
} else if (imageType == ImageType::WEBP) {
|
|
378
379
|
if (image.width() > 16383 || image.height() > 16383) {
|
|
379
380
|
throw vips::VError("Processed image is too large for the WebP format");
|
|
@@ -606,4 +607,40 @@ namespace sharp {
|
|
|
606
607
|
}
|
|
607
608
|
}
|
|
608
609
|
|
|
610
|
+
/*
|
|
611
|
+
Apply the alpha channel to a given colour
|
|
612
|
+
*/
|
|
613
|
+
std::tuple<VImage, std::vector<double>> ApplyAlpha(VImage image, std::vector<double> colour) {
|
|
614
|
+
// Scale up 8-bit values to match 16-bit input image
|
|
615
|
+
double const multiplier = sharp::Is16Bit(image.interpretation()) ? 256.0 : 1.0;
|
|
616
|
+
// Create alphaColour colour
|
|
617
|
+
std::vector<double> alphaColour;
|
|
618
|
+
if (image.bands() > 2) {
|
|
619
|
+
alphaColour = {
|
|
620
|
+
multiplier * colour[0],
|
|
621
|
+
multiplier * colour[1],
|
|
622
|
+
multiplier * colour[2]
|
|
623
|
+
};
|
|
624
|
+
} else {
|
|
625
|
+
// Convert sRGB to greyscale
|
|
626
|
+
alphaColour = { multiplier * (
|
|
627
|
+
0.2126 * colour[0] +
|
|
628
|
+
0.7152 * colour[1] +
|
|
629
|
+
0.0722 * colour[2])
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
// Add alpha channel to alphaColour colour
|
|
633
|
+
if (colour[3] < 255.0 || HasAlpha(image)) {
|
|
634
|
+
alphaColour.push_back(colour[3] * multiplier);
|
|
635
|
+
}
|
|
636
|
+
// Ensure alphaColour colour uses correct colourspace
|
|
637
|
+
alphaColour = sharp::GetRgbaAsColourspace(alphaColour, image.interpretation());
|
|
638
|
+
// Add non-transparent alpha channel, if required
|
|
639
|
+
if (colour[3] < 255.0 && !HasAlpha(image)) {
|
|
640
|
+
image = image.bandjoin(
|
|
641
|
+
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier));
|
|
642
|
+
}
|
|
643
|
+
return std::make_tuple(image, alphaColour);
|
|
644
|
+
}
|
|
645
|
+
|
|
609
646
|
} // namespace sharp
|
package/src/common.h
CHANGED
|
@@ -49,7 +49,7 @@ namespace sharp {
|
|
|
49
49
|
char *buffer;
|
|
50
50
|
bool failOnError;
|
|
51
51
|
size_t bufferLength;
|
|
52
|
-
|
|
52
|
+
double density;
|
|
53
53
|
int rawChannels;
|
|
54
54
|
int rawWidth;
|
|
55
55
|
int rawHeight;
|
|
@@ -57,30 +57,27 @@ namespace sharp {
|
|
|
57
57
|
int createChannels;
|
|
58
58
|
int createWidth;
|
|
59
59
|
int createHeight;
|
|
60
|
-
double createBackground
|
|
60
|
+
std::vector<double> createBackground;
|
|
61
61
|
|
|
62
62
|
InputDescriptor():
|
|
63
63
|
buffer(nullptr),
|
|
64
64
|
failOnError(FALSE),
|
|
65
65
|
bufferLength(0),
|
|
66
|
-
density(72),
|
|
66
|
+
density(72.0),
|
|
67
67
|
rawChannels(0),
|
|
68
68
|
rawWidth(0),
|
|
69
69
|
rawHeight(0),
|
|
70
70
|
page(0),
|
|
71
71
|
createChannels(0),
|
|
72
72
|
createWidth(0),
|
|
73
|
-
createHeight(0)
|
|
74
|
-
|
|
75
|
-
createBackground[1] = 0.0;
|
|
76
|
-
createBackground[2] = 0.0;
|
|
77
|
-
createBackground[3] = 255.0;
|
|
78
|
-
}
|
|
73
|
+
createHeight(0),
|
|
74
|
+
createBackground{ 0.0, 0.0, 0.0, 255.0 } {}
|
|
79
75
|
};
|
|
80
76
|
|
|
81
77
|
// Convenience methods to access the attributes of a v8::Object
|
|
82
78
|
bool HasAttr(v8::Handle<v8::Object> obj, std::string attr);
|
|
83
79
|
std::string AttrAsStr(v8::Handle<v8::Object> obj, std::string attr);
|
|
80
|
+
std::vector<double> AttrAsRgba(v8::Handle<v8::Object> obj, std::string attr);
|
|
84
81
|
template<typename T> v8::Local<T> AttrAs(v8::Handle<v8::Object> obj, std::string attr) {
|
|
85
82
|
return Nan::Get(obj, Nan::New(attr).ToLocalChecked()).ToLocalChecked().As<T>();
|
|
86
83
|
}
|
|
@@ -186,7 +183,7 @@ namespace sharp {
|
|
|
186
183
|
/*
|
|
187
184
|
Set pixels/mm resolution based on a pixels/inch density.
|
|
188
185
|
*/
|
|
189
|
-
void SetDensity(VImage image, const
|
|
186
|
+
void SetDensity(VImage image, const double density);
|
|
190
187
|
|
|
191
188
|
/*
|
|
192
189
|
Check the proposed format supports the current dimensions.
|
|
@@ -255,6 +252,11 @@ namespace sharp {
|
|
|
255
252
|
*/
|
|
256
253
|
std::vector<double> GetRgbaAsColourspace(std::vector<double> const rgba, VipsInterpretation const interpretation);
|
|
257
254
|
|
|
255
|
+
/*
|
|
256
|
+
Apply the alpha channel to a given colour
|
|
257
|
+
*/
|
|
258
|
+
std::tuple<VImage, std::vector<double>> ApplyAlpha(VImage image, std::vector<double> colour);
|
|
259
|
+
|
|
258
260
|
} // namespace sharp
|
|
259
261
|
|
|
260
262
|
#endif // SRC_COMMON_H_
|