bare-jpeg 1.1.2 → 1.1.4
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/binding.c +33 -2
- package/package.json +1 -1
- package/prebuilds/android-arm/bare-jpeg.bare +0 -0
- package/prebuilds/android-arm64/bare-jpeg.bare +0 -0
- package/prebuilds/android-ia32/bare-jpeg.bare +0 -0
- package/prebuilds/android-x64/bare-jpeg.bare +0 -0
- package/prebuilds/darwin-arm64/bare-jpeg.bare +0 -0
- package/prebuilds/darwin-x64/bare-jpeg.bare +0 -0
- package/prebuilds/ios-arm64/bare-jpeg.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-jpeg.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-jpeg.bare +0 -0
- package/prebuilds/linux-arm64/bare-jpeg.bare +0 -0
- package/prebuilds/linux-x64/bare-jpeg.bare +0 -0
- package/prebuilds/win32-arm64/bare-jpeg.bare +0 -0
- package/prebuilds/win32-x64/bare-jpeg.bare +0 -0
package/binding.c
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
#include <stdlib.h>
|
|
7
7
|
#include <string.h>
|
|
8
8
|
|
|
9
|
+
#define BARE_JPEG_MAX_PIXELS (1ull << 28)
|
|
10
|
+
|
|
9
11
|
typedef struct {
|
|
10
12
|
struct jpeg_error_mgr handle;
|
|
11
13
|
jmp_buf jump;
|
|
@@ -71,12 +73,32 @@ bare_jpeg_decode(js_env_t *env, js_callback_info_t *info) {
|
|
|
71
73
|
|
|
72
74
|
if (jpeg_read_header(&decoder, true) != JPEG_HEADER_OK) goto err;
|
|
73
75
|
|
|
76
|
+
if (decoder.out_color_space == JCS_GRAYSCALE) decoder.out_color_space = JCS_RGB;
|
|
77
|
+
|
|
74
78
|
jpeg_start_decompress(&decoder);
|
|
75
79
|
|
|
76
80
|
JDIMENSION width = decoder.output_width;
|
|
77
81
|
JDIMENSION height = decoder.output_height;
|
|
78
82
|
JDIMENSION channels = decoder.output_components;
|
|
79
83
|
|
|
84
|
+
if (channels < 3) {
|
|
85
|
+
jpeg_destroy_decompress(&decoder);
|
|
86
|
+
|
|
87
|
+
err = js_throw_error(env, NULL, "Unsupported JPEG color space");
|
|
88
|
+
assert(err == 0);
|
|
89
|
+
|
|
90
|
+
return NULL;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if ((uint64_t) width * height > BARE_JPEG_MAX_PIXELS) {
|
|
94
|
+
jpeg_destroy_decompress(&decoder);
|
|
95
|
+
|
|
96
|
+
err = js_throw_error(env, NULL, "JPEG dimensions exceed maximum");
|
|
97
|
+
assert(err == 0);
|
|
98
|
+
|
|
99
|
+
return NULL;
|
|
100
|
+
}
|
|
101
|
+
|
|
80
102
|
js_value_t *result;
|
|
81
103
|
err = js_create_object(env, &result);
|
|
82
104
|
assert(err == 0);
|
|
@@ -100,7 +122,12 @@ bare_jpeg_decode(js_env_t *env, js_callback_info_t *info) {
|
|
|
100
122
|
|
|
101
123
|
uint8_t *data;
|
|
102
124
|
err = js_create_unsafe_arraybuffer(env, len, (void **) &data, &buffer);
|
|
103
|
-
|
|
125
|
+
|
|
126
|
+
if (err < 0) {
|
|
127
|
+
jpeg_destroy_decompress(&decoder);
|
|
128
|
+
|
|
129
|
+
return NULL;
|
|
130
|
+
}
|
|
104
131
|
|
|
105
132
|
err = js_set_named_property(env, result, "data", buffer);
|
|
106
133
|
assert(err == 0);
|
|
@@ -176,6 +203,7 @@ bare_jpeg_encode(js_env_t *env, js_callback_info_t *info) {
|
|
|
176
203
|
|
|
177
204
|
uint8_t *jpeg = NULL;
|
|
178
205
|
unsigned long len = 0;
|
|
206
|
+
uint8_t *dst = NULL;
|
|
179
207
|
jpeg_mem_dest(&encoder, &jpeg, &len);
|
|
180
208
|
|
|
181
209
|
encoder.image_width = width;
|
|
@@ -194,6 +222,9 @@ bare_jpeg_encode(js_env_t *env, js_callback_info_t *info) {
|
|
|
194
222
|
err = js_throw_error(env, NULL, error.message);
|
|
195
223
|
assert(err == 0);
|
|
196
224
|
|
|
225
|
+
free(jpeg);
|
|
226
|
+
free(dst);
|
|
227
|
+
|
|
197
228
|
jpeg_destroy_compress(&encoder);
|
|
198
229
|
|
|
199
230
|
return NULL;
|
|
@@ -201,7 +232,7 @@ bare_jpeg_encode(js_env_t *env, js_callback_info_t *info) {
|
|
|
201
232
|
|
|
202
233
|
jpeg_start_compress(&encoder, true);
|
|
203
234
|
|
|
204
|
-
|
|
235
|
+
dst = malloc((size_t) width * 3);
|
|
205
236
|
|
|
206
237
|
while (encoder.next_scanline < encoder.image_height) {
|
|
207
238
|
const uint8_t *src = data + (size_t) encoder.next_scanline * width * 4;
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|