jimp 0.16.2-canary.984.1126.0 → 0.16.2
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/browser/lib/jimp.js +48 -7
- package/package.json +6 -6
package/browser/lib/jimp.js
CHANGED
|
@@ -20198,7 +20198,9 @@ var JpegImage = (function jpegImage() {
|
|
|
20198
20198
|
return array;
|
|
20199
20199
|
}
|
|
20200
20200
|
function prepareComponents(frame) {
|
|
20201
|
-
|
|
20201
|
+
// According to the JPEG standard, the sampling factor must be between 1 and 4
|
|
20202
|
+
// See https://github.com/libjpeg-turbo/libjpeg-turbo/blob/9abeff46d87bd201a952e276f3e4339556a403a3/libjpeg.txt#L1138-L1146
|
|
20203
|
+
var maxH = 1, maxV = 1;
|
|
20202
20204
|
var component, componentId;
|
|
20203
20205
|
for (componentId in frame.components) {
|
|
20204
20206
|
if (frame.components.hasOwnProperty(componentId)) {
|
|
@@ -20245,6 +20247,7 @@ var JpegImage = (function jpegImage() {
|
|
|
20245
20247
|
var quantizationTables = [], frames = [];
|
|
20246
20248
|
var huffmanTablesAC = [], huffmanTablesDC = [];
|
|
20247
20249
|
var fileMarker = readUint16();
|
|
20250
|
+
var malformedDataOffset = -1;
|
|
20248
20251
|
this.comments = [];
|
|
20249
20252
|
if (fileMarker != 0xFFD8) { // SOI (Start of Image)
|
|
20250
20253
|
throw new Error("SOI not found");
|
|
@@ -20366,6 +20369,11 @@ var JpegImage = (function jpegImage() {
|
|
|
20366
20369
|
var h = data[offset + 1] >> 4;
|
|
20367
20370
|
var v = data[offset + 1] & 15;
|
|
20368
20371
|
var qId = data[offset + 2];
|
|
20372
|
+
|
|
20373
|
+
if ( h <= 0 || v <= 0 ) {
|
|
20374
|
+
throw new Error('Invalid sampling factor, expected values above 0');
|
|
20375
|
+
}
|
|
20376
|
+
|
|
20369
20377
|
frame.componentsOrder.push(componentId);
|
|
20370
20378
|
frame.components[componentId] = {
|
|
20371
20379
|
h: h,
|
|
@@ -20435,7 +20443,6 @@ var JpegImage = (function jpegImage() {
|
|
|
20435
20443
|
offset--;
|
|
20436
20444
|
}
|
|
20437
20445
|
break;
|
|
20438
|
-
|
|
20439
20446
|
default:
|
|
20440
20447
|
if (data[offset - 3] == 0xFF &&
|
|
20441
20448
|
data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
|
|
@@ -20444,6 +20451,19 @@ var JpegImage = (function jpegImage() {
|
|
|
20444
20451
|
offset -= 3;
|
|
20445
20452
|
break;
|
|
20446
20453
|
}
|
|
20454
|
+
else if (fileMarker === 0xE0 || fileMarker == 0xE1) {
|
|
20455
|
+
// Recover from malformed APP1 markers popular in some phone models.
|
|
20456
|
+
// See https://github.com/eugeneware/jpeg-js/issues/82
|
|
20457
|
+
if (malformedDataOffset !== -1) {
|
|
20458
|
+
throw new Error(`first unknown JPEG marker at offset ${malformedDataOffset.toString(16)}, second unknown JPEG marker ${fileMarker.toString(16)} at offset ${(offset - 1).toString(16)}`);
|
|
20459
|
+
}
|
|
20460
|
+
malformedDataOffset = offset - 1;
|
|
20461
|
+
const nextOffset = readUint16();
|
|
20462
|
+
if (data[offset + nextOffset - 2] === 0xFF) {
|
|
20463
|
+
offset += nextOffset - 2;
|
|
20464
|
+
break;
|
|
20465
|
+
}
|
|
20466
|
+
}
|
|
20447
20467
|
throw new Error("unknown JPEG marker " + fileMarker.toString(16));
|
|
20448
20468
|
}
|
|
20449
20469
|
fileMarker = readUint16();
|
|
@@ -20732,13 +20752,19 @@ function decode(jpegData, userOpts = {}) {
|
|
|
20732
20752
|
if(decoder.comments.length > 0) {
|
|
20733
20753
|
image["comments"] = decoder.comments;
|
|
20734
20754
|
}
|
|
20735
|
-
} catch (err){
|
|
20736
|
-
if (err instanceof RangeError){
|
|
20755
|
+
} catch (err) {
|
|
20756
|
+
if (err instanceof RangeError) {
|
|
20737
20757
|
throw new Error("Could not allocate enough memory for the image. " +
|
|
20738
20758
|
"Required: " + bytesNeeded);
|
|
20739
|
-
}
|
|
20740
|
-
|
|
20759
|
+
}
|
|
20760
|
+
|
|
20761
|
+
if (err instanceof ReferenceError) {
|
|
20762
|
+
if (err.message === "Buffer is not defined") {
|
|
20763
|
+
throw new Error("Buffer is not globally defined in this environment. " +
|
|
20764
|
+
"Consider setting useTArray to true");
|
|
20765
|
+
}
|
|
20741
20766
|
}
|
|
20767
|
+
throw err;
|
|
20742
20768
|
}
|
|
20743
20769
|
|
|
20744
20770
|
decoder.copyToImageData(image, opts.formatAsRGBA);
|
|
@@ -21286,6 +21312,20 @@ function JPEGEncoder(quality) {
|
|
|
21286
21312
|
writeByte(std_ac_chrominance_values[p]);
|
|
21287
21313
|
}
|
|
21288
21314
|
}
|
|
21315
|
+
|
|
21316
|
+
function writeCOM(comments)
|
|
21317
|
+
{
|
|
21318
|
+
if (typeof comments === "undefined" || comments.constructor !== Array) return;
|
|
21319
|
+
comments.forEach(e => {
|
|
21320
|
+
if (typeof e !== "string") return;
|
|
21321
|
+
writeWord(0xFFFE); // marker
|
|
21322
|
+
var l = e.length;
|
|
21323
|
+
writeWord(l + 2); // length itself as well
|
|
21324
|
+
var i;
|
|
21325
|
+
for (i = 0; i < l; i++)
|
|
21326
|
+
writeByte(e.charCodeAt(i));
|
|
21327
|
+
});
|
|
21328
|
+
}
|
|
21289
21329
|
|
|
21290
21330
|
function writeSOS()
|
|
21291
21331
|
{
|
|
@@ -21376,6 +21416,7 @@ function JPEGEncoder(quality) {
|
|
|
21376
21416
|
// Add JPEG headers
|
|
21377
21417
|
writeWord(0xFFD8); // SOI
|
|
21378
21418
|
writeAPP0();
|
|
21419
|
+
writeCOM(image.comments);
|
|
21379
21420
|
writeAPP1(image.exifBuffer);
|
|
21380
21421
|
writeDQT();
|
|
21381
21422
|
writeSOF0(image.width,image.height);
|
|
@@ -21533,7 +21574,7 @@ function encode(imgData, qu) {
|
|
|
21533
21574
|
return {
|
|
21534
21575
|
data: data,
|
|
21535
21576
|
width: imgData.width,
|
|
21536
|
-
height: imgData.height
|
|
21577
|
+
height: imgData.height,
|
|
21537
21578
|
};
|
|
21538
21579
|
}
|
|
21539
21580
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jimp",
|
|
3
|
-
"version": "0.16.2
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"description": "An image processing library written entirely in JavaScript (i.e. zero external or native dependencies)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"license": "MIT",
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@babel/runtime": "^7.7.2",
|
|
62
|
-
"@jimp/custom": "0.16.2
|
|
63
|
-
"@jimp/plugins": "0.16.2
|
|
64
|
-
"@jimp/types": "0.16.2
|
|
62
|
+
"@jimp/custom": "^0.16.2",
|
|
63
|
+
"@jimp/plugins": "^0.16.2",
|
|
64
|
+
"@jimp/types": "^0.16.2",
|
|
65
65
|
"regenerator-runtime": "^0.13.3"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@babel/plugin-syntax-object-rest-spread": "^7.2.0",
|
|
72
72
|
"@babel/preset-env": "^7.7.1",
|
|
73
73
|
"@babel/register": "^7.7.0",
|
|
74
|
-
"@jimp/test-utils": "0.16.2
|
|
74
|
+
"@jimp/test-utils": "^0.16.2",
|
|
75
75
|
"babel-eslint": "^10.0.3",
|
|
76
76
|
"babel-plugin-add-module-exports": "^1.0.2",
|
|
77
77
|
"babel-plugin-istanbul": "^5.2.0",
|
|
@@ -116,5 +116,5 @@
|
|
|
116
116
|
"test/*.js"
|
|
117
117
|
]
|
|
118
118
|
},
|
|
119
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "e4d6af032fdabdb4b8a4368ec957dec8ea426ef4"
|
|
120
120
|
}
|