@hiroosy/baileys-lite 0.3.2 → 0.3.3
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 +1 -1
- package/package.json +1 -1
- package/src/foundation/ai-rich.js +1 -19
- package/src/foundation/image-thumb.js +5 -106
- package/src/socket/messages-send.js +17 -0
- package/src/utils/media.js +3 -3
- package/src/vendor/jpeg-js/decoder.js +0 -1091
- package/src/vendor/jpeg-js/encoder.js +0 -739
- package/src/vendor/pngjs/LICENSE +0 -20
- package/src/vendor/pngjs/bitmapper.js +0 -251
- package/src/vendor/pngjs/bitpacker.js +0 -159
- package/src/vendor/pngjs/constants.js +0 -30
- package/src/vendor/pngjs/crc.js +0 -41
- package/src/vendor/pngjs/filter-pack.js +0 -173
- package/src/vendor/pngjs/filter-parse-sync.js +0 -21
- package/src/vendor/pngjs/filter-parse.js +0 -175
- package/src/vendor/pngjs/format-normaliser.js +0 -95
- package/src/vendor/pngjs/interlace.js +0 -84
- package/src/vendor/pngjs/packer-sync.js +0 -54
- package/src/vendor/pngjs/packer.js +0 -130
- package/src/vendor/pngjs/paeth-predictor.js +0 -16
- package/src/vendor/pngjs/parser-sync.js +0 -113
- package/src/vendor/pngjs/parser.js +0 -275
- package/src/vendor/pngjs/png-sync.js +0 -12
- package/src/vendor/pngjs/sync-inflate.js +0 -165
- package/src/vendor/pngjs/sync-reader.js +0 -47
package/src/vendor/pngjs/LICENSE
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
pngjs original work Copyright (c) 2015 Luke Page & Original Contributors
|
|
2
|
-
pngjs derived work Copyright (c) 2012 Kuba Niegowski
|
|
3
|
-
|
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
in the Software without restriction, including without limitation the rights
|
|
7
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
furnished to do so, subject to the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be included in
|
|
12
|
-
all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
-
THE SOFTWARE.
|
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import * as interlaceUtils from './interlace.js'
|
|
4
|
-
|
|
5
|
-
let pixelBppMapper = [
|
|
6
|
-
|
|
7
|
-
function () {},
|
|
8
|
-
|
|
9
|
-
function (pxData, data, pxPos, rawPos) {
|
|
10
|
-
if (rawPos === data.length) {
|
|
11
|
-
throw new Error("Ran out of data");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let pixel = data[rawPos];
|
|
15
|
-
pxData[pxPos] = pixel;
|
|
16
|
-
pxData[pxPos + 1] = pixel;
|
|
17
|
-
pxData[pxPos + 2] = pixel;
|
|
18
|
-
pxData[pxPos + 3] = 0xff;
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
function (pxData, data, pxPos, rawPos) {
|
|
22
|
-
if (rawPos + 1 >= data.length) {
|
|
23
|
-
throw new Error("Ran out of data");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let pixel = data[rawPos];
|
|
27
|
-
pxData[pxPos] = pixel;
|
|
28
|
-
pxData[pxPos + 1] = pixel;
|
|
29
|
-
pxData[pxPos + 2] = pixel;
|
|
30
|
-
pxData[pxPos + 3] = data[rawPos + 1];
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
function (pxData, data, pxPos, rawPos) {
|
|
34
|
-
if (rawPos + 2 >= data.length) {
|
|
35
|
-
throw new Error("Ran out of data");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
pxData[pxPos] = data[rawPos];
|
|
39
|
-
pxData[pxPos + 1] = data[rawPos + 1];
|
|
40
|
-
pxData[pxPos + 2] = data[rawPos + 2];
|
|
41
|
-
pxData[pxPos + 3] = 0xff;
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
function (pxData, data, pxPos, rawPos) {
|
|
45
|
-
if (rawPos + 3 >= data.length) {
|
|
46
|
-
throw new Error("Ran out of data");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
pxData[pxPos] = data[rawPos];
|
|
50
|
-
pxData[pxPos + 1] = data[rawPos + 1];
|
|
51
|
-
pxData[pxPos + 2] = data[rawPos + 2];
|
|
52
|
-
pxData[pxPos + 3] = data[rawPos + 3];
|
|
53
|
-
},
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
let pixelBppCustomMapper = [
|
|
57
|
-
|
|
58
|
-
function () {},
|
|
59
|
-
|
|
60
|
-
function (pxData, pixelData, pxPos, maxBit) {
|
|
61
|
-
let pixel = pixelData[0];
|
|
62
|
-
pxData[pxPos] = pixel;
|
|
63
|
-
pxData[pxPos + 1] = pixel;
|
|
64
|
-
pxData[pxPos + 2] = pixel;
|
|
65
|
-
pxData[pxPos + 3] = maxBit;
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
function (pxData, pixelData, pxPos) {
|
|
69
|
-
let pixel = pixelData[0];
|
|
70
|
-
pxData[pxPos] = pixel;
|
|
71
|
-
pxData[pxPos + 1] = pixel;
|
|
72
|
-
pxData[pxPos + 2] = pixel;
|
|
73
|
-
pxData[pxPos + 3] = pixelData[1];
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
function (pxData, pixelData, pxPos, maxBit) {
|
|
77
|
-
pxData[pxPos] = pixelData[0];
|
|
78
|
-
pxData[pxPos + 1] = pixelData[1];
|
|
79
|
-
pxData[pxPos + 2] = pixelData[2];
|
|
80
|
-
pxData[pxPos + 3] = maxBit;
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
function (pxData, pixelData, pxPos) {
|
|
84
|
-
pxData[pxPos] = pixelData[0];
|
|
85
|
-
pxData[pxPos + 1] = pixelData[1];
|
|
86
|
-
pxData[pxPos + 2] = pixelData[2];
|
|
87
|
-
pxData[pxPos + 3] = pixelData[3];
|
|
88
|
-
},
|
|
89
|
-
];
|
|
90
|
-
|
|
91
|
-
function bitRetriever(data, depth) {
|
|
92
|
-
let leftOver = [];
|
|
93
|
-
let i = 0;
|
|
94
|
-
|
|
95
|
-
function split() {
|
|
96
|
-
if (i === data.length) {
|
|
97
|
-
throw new Error("Ran out of data");
|
|
98
|
-
}
|
|
99
|
-
let byte = data[i];
|
|
100
|
-
i++;
|
|
101
|
-
let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
|
|
102
|
-
switch (depth) {
|
|
103
|
-
default:
|
|
104
|
-
throw new Error("unrecognised depth");
|
|
105
|
-
case 16:
|
|
106
|
-
byte2 = data[i];
|
|
107
|
-
i++;
|
|
108
|
-
leftOver.push((byte << 8) + byte2);
|
|
109
|
-
break;
|
|
110
|
-
case 4:
|
|
111
|
-
byte2 = byte & 0x0f;
|
|
112
|
-
byte1 = byte >> 4;
|
|
113
|
-
leftOver.push(byte1, byte2);
|
|
114
|
-
break;
|
|
115
|
-
case 2:
|
|
116
|
-
byte4 = byte & 3;
|
|
117
|
-
byte3 = (byte >> 2) & 3;
|
|
118
|
-
byte2 = (byte >> 4) & 3;
|
|
119
|
-
byte1 = (byte >> 6) & 3;
|
|
120
|
-
leftOver.push(byte1, byte2, byte3, byte4);
|
|
121
|
-
break;
|
|
122
|
-
case 1:
|
|
123
|
-
byte8 = byte & 1;
|
|
124
|
-
byte7 = (byte >> 1) & 1;
|
|
125
|
-
byte6 = (byte >> 2) & 1;
|
|
126
|
-
byte5 = (byte >> 3) & 1;
|
|
127
|
-
byte4 = (byte >> 4) & 1;
|
|
128
|
-
byte3 = (byte >> 5) & 1;
|
|
129
|
-
byte2 = (byte >> 6) & 1;
|
|
130
|
-
byte1 = (byte >> 7) & 1;
|
|
131
|
-
leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return {
|
|
137
|
-
get: function (count) {
|
|
138
|
-
while (leftOver.length < count) {
|
|
139
|
-
split();
|
|
140
|
-
}
|
|
141
|
-
let returner = leftOver.slice(0, count);
|
|
142
|
-
leftOver = leftOver.slice(count);
|
|
143
|
-
return returner;
|
|
144
|
-
},
|
|
145
|
-
resetAfterLine: function () {
|
|
146
|
-
leftOver.length = 0;
|
|
147
|
-
},
|
|
148
|
-
end: function () {
|
|
149
|
-
if (i !== data.length) {
|
|
150
|
-
throw new Error("extra data found");
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
|
|
157
|
-
|
|
158
|
-
let imageWidth = image.width;
|
|
159
|
-
let imageHeight = image.height;
|
|
160
|
-
let imagePass = image.index;
|
|
161
|
-
for (let y = 0; y < imageHeight; y++) {
|
|
162
|
-
for (let x = 0; x < imageWidth; x++) {
|
|
163
|
-
let pxPos = getPxPos(x, y, imagePass);
|
|
164
|
-
pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
|
|
165
|
-
rawPos += bpp;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return rawPos;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
|
|
172
|
-
|
|
173
|
-
let imageWidth = image.width;
|
|
174
|
-
let imageHeight = image.height;
|
|
175
|
-
let imagePass = image.index;
|
|
176
|
-
for (let y = 0; y < imageHeight; y++) {
|
|
177
|
-
for (let x = 0; x < imageWidth; x++) {
|
|
178
|
-
let pixelData = bits.get(bpp);
|
|
179
|
-
let pxPos = getPxPos(x, y, imagePass);
|
|
180
|
-
pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
|
|
181
|
-
}
|
|
182
|
-
bits.resetAfterLine();
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export const dataToBitMap = function (data, bitmapInfo) {
|
|
187
|
-
let width = bitmapInfo.width;
|
|
188
|
-
let height = bitmapInfo.height;
|
|
189
|
-
let depth = bitmapInfo.depth;
|
|
190
|
-
let bpp = bitmapInfo.bpp;
|
|
191
|
-
let interlace = bitmapInfo.interlace;
|
|
192
|
-
let bits;
|
|
193
|
-
|
|
194
|
-
if (depth !== 8) {
|
|
195
|
-
bits = bitRetriever(data, depth);
|
|
196
|
-
}
|
|
197
|
-
let pxData;
|
|
198
|
-
if (depth <= 8) {
|
|
199
|
-
pxData = Buffer.alloc(width * height * 4);
|
|
200
|
-
} else {
|
|
201
|
-
pxData = new Uint16Array(width * height * 4);
|
|
202
|
-
}
|
|
203
|
-
let maxBit = Math.pow(2, depth) - 1;
|
|
204
|
-
let rawPos = 0;
|
|
205
|
-
let images;
|
|
206
|
-
let getPxPos;
|
|
207
|
-
|
|
208
|
-
if (interlace) {
|
|
209
|
-
images = interlaceUtils.getImagePasses(width, height);
|
|
210
|
-
getPxPos = interlaceUtils.getInterlaceIterator(width, height);
|
|
211
|
-
} else {
|
|
212
|
-
let nonInterlacedPxPos = 0;
|
|
213
|
-
getPxPos = function () {
|
|
214
|
-
let returner = nonInterlacedPxPos;
|
|
215
|
-
nonInterlacedPxPos += 4;
|
|
216
|
-
return returner;
|
|
217
|
-
};
|
|
218
|
-
images = [{ width: width, height: height }];
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
for (let imageIndex = 0; imageIndex < images.length; imageIndex++) {
|
|
222
|
-
if (depth === 8) {
|
|
223
|
-
rawPos = mapImage8Bit(
|
|
224
|
-
images[imageIndex],
|
|
225
|
-
pxData,
|
|
226
|
-
getPxPos,
|
|
227
|
-
bpp,
|
|
228
|
-
data,
|
|
229
|
-
rawPos
|
|
230
|
-
);
|
|
231
|
-
} else {
|
|
232
|
-
mapImageCustomBit(
|
|
233
|
-
images[imageIndex],
|
|
234
|
-
pxData,
|
|
235
|
-
getPxPos,
|
|
236
|
-
bpp,
|
|
237
|
-
bits,
|
|
238
|
-
maxBit
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (depth === 8) {
|
|
243
|
-
if (rawPos !== data.length) {
|
|
244
|
-
throw new Error("extra data found");
|
|
245
|
-
}
|
|
246
|
-
} else {
|
|
247
|
-
bits.end();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return pxData;
|
|
251
|
-
};
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import constants from './constants.js'
|
|
4
|
-
|
|
5
|
-
const bitPacker = function (dataIn, width, height, options) {
|
|
6
|
-
let outHasAlpha =
|
|
7
|
-
[constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(
|
|
8
|
-
options.colorType
|
|
9
|
-
) !== -1;
|
|
10
|
-
if (options.colorType === options.inputColorType) {
|
|
11
|
-
let bigEndian = (function () {
|
|
12
|
-
let buffer = new ArrayBuffer(2);
|
|
13
|
-
new DataView(buffer).setInt16(0, 256, true );
|
|
14
|
-
|
|
15
|
-
return new Int16Array(buffer)[0] !== 256;
|
|
16
|
-
})();
|
|
17
|
-
|
|
18
|
-
if (options.bitDepth === 8 || (options.bitDepth === 16 && bigEndian)) {
|
|
19
|
-
return dataIn;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
|
|
24
|
-
|
|
25
|
-
let maxValue = 255;
|
|
26
|
-
let inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
|
|
27
|
-
if (inBpp === 4 && !options.inputHasAlpha) {
|
|
28
|
-
inBpp = 3;
|
|
29
|
-
}
|
|
30
|
-
let outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
|
|
31
|
-
if (options.bitDepth === 16) {
|
|
32
|
-
maxValue = 65535;
|
|
33
|
-
outBpp *= 2;
|
|
34
|
-
}
|
|
35
|
-
let outData = Buffer.alloc(width * height * outBpp);
|
|
36
|
-
|
|
37
|
-
let inIndex = 0;
|
|
38
|
-
let outIndex = 0;
|
|
39
|
-
|
|
40
|
-
let bgColor = options.bgColor || {};
|
|
41
|
-
if (bgColor.red === undefined) {
|
|
42
|
-
bgColor.red = maxValue;
|
|
43
|
-
}
|
|
44
|
-
if (bgColor.green === undefined) {
|
|
45
|
-
bgColor.green = maxValue;
|
|
46
|
-
}
|
|
47
|
-
if (bgColor.blue === undefined) {
|
|
48
|
-
bgColor.blue = maxValue;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function getRGBA() {
|
|
52
|
-
let red;
|
|
53
|
-
let green;
|
|
54
|
-
let blue;
|
|
55
|
-
let alpha = maxValue;
|
|
56
|
-
switch (options.inputColorType) {
|
|
57
|
-
case constants.COLORTYPE_COLOR_ALPHA:
|
|
58
|
-
alpha = data[inIndex + 3];
|
|
59
|
-
red = data[inIndex];
|
|
60
|
-
green = data[inIndex + 1];
|
|
61
|
-
blue = data[inIndex + 2];
|
|
62
|
-
break;
|
|
63
|
-
case constants.COLORTYPE_COLOR:
|
|
64
|
-
red = data[inIndex];
|
|
65
|
-
green = data[inIndex + 1];
|
|
66
|
-
blue = data[inIndex + 2];
|
|
67
|
-
break;
|
|
68
|
-
case constants.COLORTYPE_ALPHA:
|
|
69
|
-
alpha = data[inIndex + 1];
|
|
70
|
-
red = data[inIndex];
|
|
71
|
-
green = red;
|
|
72
|
-
blue = red;
|
|
73
|
-
break;
|
|
74
|
-
case constants.COLORTYPE_GRAYSCALE:
|
|
75
|
-
red = data[inIndex];
|
|
76
|
-
green = red;
|
|
77
|
-
blue = red;
|
|
78
|
-
break;
|
|
79
|
-
default:
|
|
80
|
-
throw new Error(
|
|
81
|
-
"input color type:" +
|
|
82
|
-
options.inputColorType +
|
|
83
|
-
" is not supported at present"
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (options.inputHasAlpha) {
|
|
88
|
-
if (!outHasAlpha) {
|
|
89
|
-
alpha /= maxValue;
|
|
90
|
-
red = Math.min(
|
|
91
|
-
Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0),
|
|
92
|
-
maxValue
|
|
93
|
-
);
|
|
94
|
-
green = Math.min(
|
|
95
|
-
Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0),
|
|
96
|
-
maxValue
|
|
97
|
-
);
|
|
98
|
-
blue = Math.min(
|
|
99
|
-
Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0),
|
|
100
|
-
maxValue
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return { red: red, green: green, blue: blue, alpha: alpha };
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
for (let y = 0; y < height; y++) {
|
|
108
|
-
for (let x = 0; x < width; x++) {
|
|
109
|
-
let rgba = getRGBA(data, inIndex);
|
|
110
|
-
|
|
111
|
-
switch (options.colorType) {
|
|
112
|
-
case constants.COLORTYPE_COLOR_ALPHA:
|
|
113
|
-
case constants.COLORTYPE_COLOR:
|
|
114
|
-
if (options.bitDepth === 8) {
|
|
115
|
-
outData[outIndex] = rgba.red;
|
|
116
|
-
outData[outIndex + 1] = rgba.green;
|
|
117
|
-
outData[outIndex + 2] = rgba.blue;
|
|
118
|
-
if (outHasAlpha) {
|
|
119
|
-
outData[outIndex + 3] = rgba.alpha;
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
outData.writeUInt16BE(rgba.red, outIndex);
|
|
123
|
-
outData.writeUInt16BE(rgba.green, outIndex + 2);
|
|
124
|
-
outData.writeUInt16BE(rgba.blue, outIndex + 4);
|
|
125
|
-
if (outHasAlpha) {
|
|
126
|
-
outData.writeUInt16BE(rgba.alpha, outIndex + 6);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
break;
|
|
130
|
-
case constants.COLORTYPE_ALPHA:
|
|
131
|
-
case constants.COLORTYPE_GRAYSCALE: {
|
|
132
|
-
|
|
133
|
-
let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
|
|
134
|
-
if (options.bitDepth === 8) {
|
|
135
|
-
outData[outIndex] = grayscale;
|
|
136
|
-
if (outHasAlpha) {
|
|
137
|
-
outData[outIndex + 1] = rgba.alpha;
|
|
138
|
-
}
|
|
139
|
-
} else {
|
|
140
|
-
outData.writeUInt16BE(grayscale, outIndex);
|
|
141
|
-
if (outHasAlpha) {
|
|
142
|
-
outData.writeUInt16BE(rgba.alpha, outIndex + 2);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
default:
|
|
148
|
-
throw new Error("unrecognised color Type " + options.colorType);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
inIndex += inBpp;
|
|
152
|
-
outIndex += outBpp;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return outData;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export default bitPacker;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
PNG_SIGNATURE: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a],
|
|
5
|
-
|
|
6
|
-
TYPE_IHDR: 0x49484452,
|
|
7
|
-
TYPE_IEND: 0x49454e44,
|
|
8
|
-
TYPE_IDAT: 0x49444154,
|
|
9
|
-
TYPE_PLTE: 0x504c5445,
|
|
10
|
-
TYPE_tRNS: 0x74524e53,
|
|
11
|
-
TYPE_gAMA: 0x67414d41,
|
|
12
|
-
|
|
13
|
-
COLORTYPE_GRAYSCALE: 0,
|
|
14
|
-
COLORTYPE_PALETTE: 1,
|
|
15
|
-
COLORTYPE_COLOR: 2,
|
|
16
|
-
COLORTYPE_ALPHA: 4,
|
|
17
|
-
|
|
18
|
-
COLORTYPE_PALETTE_COLOR: 3,
|
|
19
|
-
COLORTYPE_COLOR_ALPHA: 6,
|
|
20
|
-
|
|
21
|
-
COLORTYPE_TO_BPP_MAP: {
|
|
22
|
-
0: 1,
|
|
23
|
-
2: 3,
|
|
24
|
-
3: 1,
|
|
25
|
-
4: 2,
|
|
26
|
-
6: 4,
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
GAMMA_DIVISION: 100000,
|
|
30
|
-
};
|
package/src/vendor/pngjs/crc.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
let crcTable = [];
|
|
4
|
-
|
|
5
|
-
(function () {
|
|
6
|
-
for (let i = 0; i < 256; i++) {
|
|
7
|
-
let currentCrc = i;
|
|
8
|
-
for (let j = 0; j < 8; j++) {
|
|
9
|
-
if (currentCrc & 1) {
|
|
10
|
-
currentCrc = 0xedb88320 ^ (currentCrc >>> 1);
|
|
11
|
-
} else {
|
|
12
|
-
currentCrc = currentCrc >>> 1;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
crcTable[i] = currentCrc;
|
|
16
|
-
}
|
|
17
|
-
})();
|
|
18
|
-
|
|
19
|
-
let CrcCalculator = function () {
|
|
20
|
-
this._crc = -1;
|
|
21
|
-
};
|
|
22
|
-
export default CrcCalculator;
|
|
23
|
-
|
|
24
|
-
CrcCalculator.prototype.write = function (data) {
|
|
25
|
-
for (let i = 0; i < data.length; i++) {
|
|
26
|
-
this._crc = crcTable[(this._crc ^ data[i]) & 0xff] ^ (this._crc >>> 8);
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
CrcCalculator.prototype.crc32 = function () {
|
|
32
|
-
return this._crc ^ -1;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
CrcCalculator.crc32 = function (buf) {
|
|
36
|
-
let crc = -1;
|
|
37
|
-
for (let i = 0; i < buf.length; i++) {
|
|
38
|
-
crc = crcTable[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);
|
|
39
|
-
}
|
|
40
|
-
return crc ^ -1;
|
|
41
|
-
};
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import paethPredictor from './paeth-predictor.js'
|
|
4
|
-
|
|
5
|
-
function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
6
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
7
|
-
rawData[rawPos + x] = pxData[pxPos + x];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function filterSumNone(pxData, pxPos, byteWidth) {
|
|
12
|
-
let sum = 0;
|
|
13
|
-
let length = pxPos + byteWidth;
|
|
14
|
-
|
|
15
|
-
for (let i = pxPos; i < length; i++) {
|
|
16
|
-
sum += Math.abs(pxData[i]);
|
|
17
|
-
}
|
|
18
|
-
return sum;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
22
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
23
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
24
|
-
let val = pxData[pxPos + x] - left;
|
|
25
|
-
|
|
26
|
-
rawData[rawPos + x] = val;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function filterSumSub(pxData, pxPos, byteWidth, bpp) {
|
|
31
|
-
let sum = 0;
|
|
32
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
33
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
34
|
-
let val = pxData[pxPos + x] - left;
|
|
35
|
-
|
|
36
|
-
sum += Math.abs(val);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return sum;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
43
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
44
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
45
|
-
let val = pxData[pxPos + x] - up;
|
|
46
|
-
|
|
47
|
-
rawData[rawPos + x] = val;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function filterSumUp(pxData, pxPos, byteWidth) {
|
|
52
|
-
let sum = 0;
|
|
53
|
-
let length = pxPos + byteWidth;
|
|
54
|
-
for (let x = pxPos; x < length; x++) {
|
|
55
|
-
let up = pxPos > 0 ? pxData[x - byteWidth] : 0;
|
|
56
|
-
let val = pxData[x] - up;
|
|
57
|
-
|
|
58
|
-
sum += Math.abs(val);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return sum;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
65
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
66
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
67
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
68
|
-
let val = pxData[pxPos + x] - ((left + up) >> 1);
|
|
69
|
-
|
|
70
|
-
rawData[rawPos + x] = val;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
|
|
75
|
-
let sum = 0;
|
|
76
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
77
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
78
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
79
|
-
let val = pxData[pxPos + x] - ((left + up) >> 1);
|
|
80
|
-
|
|
81
|
-
sum += Math.abs(val);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return sum;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
88
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
89
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
90
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
91
|
-
let upleft =
|
|
92
|
-
pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
|
|
93
|
-
let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
|
|
94
|
-
|
|
95
|
-
rawData[rawPos + x] = val;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
|
|
100
|
-
let sum = 0;
|
|
101
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
102
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
103
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
104
|
-
let upleft =
|
|
105
|
-
pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
|
|
106
|
-
let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
|
|
107
|
-
|
|
108
|
-
sum += Math.abs(val);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return sum;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
let filters = {
|
|
115
|
-
0: filterNone,
|
|
116
|
-
1: filterSub,
|
|
117
|
-
2: filterUp,
|
|
118
|
-
3: filterAvg,
|
|
119
|
-
4: filterPaeth,
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
let filterSums = {
|
|
123
|
-
0: filterSumNone,
|
|
124
|
-
1: filterSumSub,
|
|
125
|
-
2: filterSumUp,
|
|
126
|
-
3: filterSumAvg,
|
|
127
|
-
4: filterSumPaeth,
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const filterData = function (pxData, width, height, options, bpp) {
|
|
131
|
-
let filterTypes;
|
|
132
|
-
if (!("filterType" in options) || options.filterType === -1) {
|
|
133
|
-
filterTypes = [0, 1, 2, 3, 4];
|
|
134
|
-
} else if (typeof options.filterType === "number") {
|
|
135
|
-
filterTypes = [options.filterType];
|
|
136
|
-
} else {
|
|
137
|
-
throw new Error("unrecognised filter types");
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (options.bitDepth === 16) {
|
|
141
|
-
bpp *= 2;
|
|
142
|
-
}
|
|
143
|
-
let byteWidth = width * bpp;
|
|
144
|
-
let rawPos = 0;
|
|
145
|
-
let pxPos = 0;
|
|
146
|
-
let rawData = Buffer.alloc((byteWidth + 1) * height);
|
|
147
|
-
|
|
148
|
-
let sel = filterTypes[0];
|
|
149
|
-
|
|
150
|
-
for (let y = 0; y < height; y++) {
|
|
151
|
-
if (filterTypes.length > 1) {
|
|
152
|
-
|
|
153
|
-
let min = Infinity;
|
|
154
|
-
|
|
155
|
-
for (let i = 0; i < filterTypes.length; i++) {
|
|
156
|
-
let sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
|
|
157
|
-
if (sum < min) {
|
|
158
|
-
sel = filterTypes[i];
|
|
159
|
-
min = sum;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
rawData[rawPos] = sel;
|
|
165
|
-
rawPos++;
|
|
166
|
-
filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
|
|
167
|
-
rawPos += byteWidth;
|
|
168
|
-
pxPos += byteWidth;
|
|
169
|
-
}
|
|
170
|
-
return rawData;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
export default filterData;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import SyncReader from './sync-reader.js'
|
|
4
|
-
import Filter from './filter-parse.js'
|
|
5
|
-
|
|
6
|
-
export const process = function (inBuffer, bitmapInfo) {
|
|
7
|
-
let outBuffers = [];
|
|
8
|
-
let reader = new SyncReader(inBuffer);
|
|
9
|
-
let filter = new Filter(bitmapInfo, {
|
|
10
|
-
read: reader.read.bind(reader),
|
|
11
|
-
write: function (bufferPart) {
|
|
12
|
-
outBuffers.push(bufferPart);
|
|
13
|
-
},
|
|
14
|
-
complete: function () {},
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
filter.start();
|
|
18
|
-
reader.process();
|
|
19
|
-
|
|
20
|
-
return Buffer.concat(outBuffers);
|
|
21
|
-
};
|