cross-image 0.1.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.
Files changed (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +606 -0
  3. package/esm/mod.d.ts +33 -0
  4. package/esm/mod.d.ts.map +1 -0
  5. package/esm/mod.js +31 -0
  6. package/esm/package.json +3 -0
  7. package/esm/src/formats/ascii.d.ts +27 -0
  8. package/esm/src/formats/ascii.d.ts.map +1 -0
  9. package/esm/src/formats/ascii.js +172 -0
  10. package/esm/src/formats/bmp.d.ts +19 -0
  11. package/esm/src/formats/bmp.d.ts.map +1 -0
  12. package/esm/src/formats/bmp.js +174 -0
  13. package/esm/src/formats/gif.d.ts +40 -0
  14. package/esm/src/formats/gif.d.ts.map +1 -0
  15. package/esm/src/formats/gif.js +385 -0
  16. package/esm/src/formats/jpeg.d.ts +18 -0
  17. package/esm/src/formats/jpeg.d.ts.map +1 -0
  18. package/esm/src/formats/jpeg.js +414 -0
  19. package/esm/src/formats/png.d.ts +33 -0
  20. package/esm/src/formats/png.d.ts.map +1 -0
  21. package/esm/src/formats/png.js +544 -0
  22. package/esm/src/formats/raw.d.ts +23 -0
  23. package/esm/src/formats/raw.d.ts.map +1 -0
  24. package/esm/src/formats/raw.js +98 -0
  25. package/esm/src/formats/tiff.d.ts +58 -0
  26. package/esm/src/formats/tiff.d.ts.map +1 -0
  27. package/esm/src/formats/tiff.js +791 -0
  28. package/esm/src/formats/webp.d.ts +22 -0
  29. package/esm/src/formats/webp.d.ts.map +1 -0
  30. package/esm/src/formats/webp.js +403 -0
  31. package/esm/src/image.d.ts +124 -0
  32. package/esm/src/image.d.ts.map +1 -0
  33. package/esm/src/image.js +320 -0
  34. package/esm/src/types.d.ts +167 -0
  35. package/esm/src/types.d.ts.map +1 -0
  36. package/esm/src/types.js +1 -0
  37. package/esm/src/utils/gif_decoder.d.ts +42 -0
  38. package/esm/src/utils/gif_decoder.d.ts.map +1 -0
  39. package/esm/src/utils/gif_decoder.js +374 -0
  40. package/esm/src/utils/gif_encoder.d.ts +29 -0
  41. package/esm/src/utils/gif_encoder.d.ts.map +1 -0
  42. package/esm/src/utils/gif_encoder.js +226 -0
  43. package/esm/src/utils/jpeg_decoder.d.ts +39 -0
  44. package/esm/src/utils/jpeg_decoder.d.ts.map +1 -0
  45. package/esm/src/utils/jpeg_decoder.js +580 -0
  46. package/esm/src/utils/jpeg_encoder.d.ts +33 -0
  47. package/esm/src/utils/jpeg_encoder.d.ts.map +1 -0
  48. package/esm/src/utils/jpeg_encoder.js +1017 -0
  49. package/esm/src/utils/lzw.d.ts +43 -0
  50. package/esm/src/utils/lzw.d.ts.map +1 -0
  51. package/esm/src/utils/lzw.js +309 -0
  52. package/esm/src/utils/resize.d.ts +9 -0
  53. package/esm/src/utils/resize.d.ts.map +1 -0
  54. package/esm/src/utils/resize.js +52 -0
  55. package/esm/src/utils/tiff_lzw.d.ts +44 -0
  56. package/esm/src/utils/tiff_lzw.d.ts.map +1 -0
  57. package/esm/src/utils/tiff_lzw.js +306 -0
  58. package/esm/src/utils/webp_decoder.d.ts +39 -0
  59. package/esm/src/utils/webp_decoder.d.ts.map +1 -0
  60. package/esm/src/utils/webp_decoder.js +493 -0
  61. package/esm/src/utils/webp_encoder.d.ts +72 -0
  62. package/esm/src/utils/webp_encoder.d.ts.map +1 -0
  63. package/esm/src/utils/webp_encoder.js +627 -0
  64. package/package.json +41 -0
  65. package/script/mod.d.ts +33 -0
  66. package/script/mod.d.ts.map +1 -0
  67. package/script/mod.js +43 -0
  68. package/script/package.json +3 -0
  69. package/script/src/formats/ascii.d.ts +27 -0
  70. package/script/src/formats/ascii.d.ts.map +1 -0
  71. package/script/src/formats/ascii.js +176 -0
  72. package/script/src/formats/bmp.d.ts +19 -0
  73. package/script/src/formats/bmp.d.ts.map +1 -0
  74. package/script/src/formats/bmp.js +178 -0
  75. package/script/src/formats/gif.d.ts +40 -0
  76. package/script/src/formats/gif.d.ts.map +1 -0
  77. package/script/src/formats/gif.js +389 -0
  78. package/script/src/formats/jpeg.d.ts +18 -0
  79. package/script/src/formats/jpeg.d.ts.map +1 -0
  80. package/script/src/formats/jpeg.js +451 -0
  81. package/script/src/formats/png.d.ts +33 -0
  82. package/script/src/formats/png.d.ts.map +1 -0
  83. package/script/src/formats/png.js +548 -0
  84. package/script/src/formats/raw.d.ts +23 -0
  85. package/script/src/formats/raw.d.ts.map +1 -0
  86. package/script/src/formats/raw.js +102 -0
  87. package/script/src/formats/tiff.d.ts +58 -0
  88. package/script/src/formats/tiff.d.ts.map +1 -0
  89. package/script/src/formats/tiff.js +795 -0
  90. package/script/src/formats/webp.d.ts +22 -0
  91. package/script/src/formats/webp.d.ts.map +1 -0
  92. package/script/src/formats/webp.js +440 -0
  93. package/script/src/image.d.ts +124 -0
  94. package/script/src/image.d.ts.map +1 -0
  95. package/script/src/image.js +324 -0
  96. package/script/src/types.d.ts +167 -0
  97. package/script/src/types.d.ts.map +1 -0
  98. package/script/src/types.js +2 -0
  99. package/script/src/utils/gif_decoder.d.ts +42 -0
  100. package/script/src/utils/gif_decoder.d.ts.map +1 -0
  101. package/script/src/utils/gif_decoder.js +378 -0
  102. package/script/src/utils/gif_encoder.d.ts +29 -0
  103. package/script/src/utils/gif_encoder.d.ts.map +1 -0
  104. package/script/src/utils/gif_encoder.js +230 -0
  105. package/script/src/utils/jpeg_decoder.d.ts +39 -0
  106. package/script/src/utils/jpeg_decoder.d.ts.map +1 -0
  107. package/script/src/utils/jpeg_decoder.js +584 -0
  108. package/script/src/utils/jpeg_encoder.d.ts +33 -0
  109. package/script/src/utils/jpeg_encoder.d.ts.map +1 -0
  110. package/script/src/utils/jpeg_encoder.js +1021 -0
  111. package/script/src/utils/lzw.d.ts +43 -0
  112. package/script/src/utils/lzw.d.ts.map +1 -0
  113. package/script/src/utils/lzw.js +314 -0
  114. package/script/src/utils/resize.d.ts +9 -0
  115. package/script/src/utils/resize.d.ts.map +1 -0
  116. package/script/src/utils/resize.js +56 -0
  117. package/script/src/utils/tiff_lzw.d.ts +44 -0
  118. package/script/src/utils/tiff_lzw.d.ts.map +1 -0
  119. package/script/src/utils/tiff_lzw.js +311 -0
  120. package/script/src/utils/webp_decoder.d.ts +39 -0
  121. package/script/src/utils/webp_decoder.d.ts.map +1 -0
  122. package/script/src/utils/webp_decoder.js +497 -0
  123. package/script/src/utils/webp_encoder.d.ts +72 -0
  124. package/script/src/utils/webp_encoder.d.ts.map +1 -0
  125. package/script/src/utils/webp_encoder.js +631 -0
@@ -0,0 +1,311 @@
1
+ "use strict";
2
+ /**
3
+ * LZW compression and decompression for TIFF images
4
+ *
5
+ * TIFF LZW differs from GIF LZW in several ways:
6
+ * - Uses MSB-first bit ordering (big-endian bits)
7
+ * - Typically starts with 9-bit codes
8
+ * - Uses code 256 as clear code, code 257 as end-of-information (EOI)
9
+ * - Variable code size from 9 to 12 bits
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TIFFLZWEncoder = exports.TIFFLZWDecoder = void 0;
13
+ /**
14
+ * LZW Decompressor for TIFF images
15
+ */
16
+ class TIFFLZWDecoder {
17
+ constructor(data) {
18
+ Object.defineProperty(this, "data", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ Object.defineProperty(this, "pos", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ Object.defineProperty(this, "bitPos", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ Object.defineProperty(this, "codeSize", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ Object.defineProperty(this, "dict", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
48
+ Object.defineProperty(this, "clearCode", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: 256
53
+ });
54
+ Object.defineProperty(this, "eoiCode", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: 257
59
+ });
60
+ Object.defineProperty(this, "nextCode", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: 258
65
+ });
66
+ this.data = data;
67
+ this.pos = 0;
68
+ this.bitPos = 0;
69
+ this.codeSize = 9;
70
+ this.dict = [];
71
+ this.initDictionary();
72
+ }
73
+ initDictionary() {
74
+ this.dict = [];
75
+ // Initialize dictionary with single-byte entries (0-255)
76
+ for (let i = 0; i < 256; i++) {
77
+ this.dict[i] = new Uint8Array([i]);
78
+ }
79
+ this.nextCode = 258; // Next available code after clear and EOI
80
+ this.codeSize = 9;
81
+ }
82
+ readCode() {
83
+ if (this.pos >= this.data.length) {
84
+ return null;
85
+ }
86
+ let code = 0;
87
+ // Read bits MSB-first (TIFF bit ordering)
88
+ for (let i = 0; i < this.codeSize; i++) {
89
+ if (this.pos >= this.data.length) {
90
+ return null;
91
+ }
92
+ const byte = this.data[this.pos];
93
+ const bit = (byte >> (7 - this.bitPos)) & 1;
94
+ code = (code << 1) | bit;
95
+ this.bitPos++;
96
+ if (this.bitPos === 8) {
97
+ this.bitPos = 0;
98
+ this.pos++;
99
+ }
100
+ }
101
+ return code;
102
+ }
103
+ decompress() {
104
+ const output = [];
105
+ let prevCode = null;
106
+ while (true) {
107
+ const code = this.readCode();
108
+ if (code === null || code === this.eoiCode) {
109
+ break;
110
+ }
111
+ if (code === this.clearCode) {
112
+ this.initDictionary();
113
+ prevCode = null;
114
+ continue;
115
+ }
116
+ if (code < this.dict.length && this.dict[code]) {
117
+ const entry = this.dict[code];
118
+ output.push(...entry);
119
+ if (prevCode !== null && prevCode < this.dict.length &&
120
+ this.dict[prevCode]) {
121
+ const prevEntry = this.dict[prevCode];
122
+ const newEntry = new Uint8Array(prevEntry.length + 1);
123
+ newEntry.set(prevEntry);
124
+ newEntry[prevEntry.length] = entry[0];
125
+ if (this.nextCode < 4096) {
126
+ this.dict[this.nextCode] = newEntry;
127
+ this.nextCode++;
128
+ // Increase code size when dictionary reaches certain sizes
129
+ if (this.nextCode === 512 && this.codeSize === 9) {
130
+ this.codeSize = 10;
131
+ }
132
+ else if (this.nextCode === 1024 && this.codeSize === 10) {
133
+ this.codeSize = 11;
134
+ }
135
+ else if (this.nextCode === 2048 && this.codeSize === 11) {
136
+ this.codeSize = 12;
137
+ }
138
+ }
139
+ }
140
+ }
141
+ else if (prevCode !== null && prevCode < this.dict.length && this.dict[prevCode]) {
142
+ // Special case: code not in dictionary yet
143
+ const prevEntry = this.dict[prevCode];
144
+ const newEntry = new Uint8Array(prevEntry.length + 1);
145
+ newEntry.set(prevEntry);
146
+ newEntry[prevEntry.length] = prevEntry[0];
147
+ if (this.nextCode < 4096) {
148
+ this.dict[this.nextCode] = newEntry;
149
+ this.nextCode++;
150
+ // Increase code size when dictionary reaches certain sizes
151
+ if (this.nextCode === 512 && this.codeSize === 9) {
152
+ this.codeSize = 10;
153
+ }
154
+ else if (this.nextCode === 1024 && this.codeSize === 10) {
155
+ this.codeSize = 11;
156
+ }
157
+ else if (this.nextCode === 2048 && this.codeSize === 11) {
158
+ this.codeSize = 12;
159
+ }
160
+ }
161
+ output.push(...newEntry);
162
+ }
163
+ prevCode = code;
164
+ }
165
+ return new Uint8Array(output);
166
+ }
167
+ }
168
+ exports.TIFFLZWDecoder = TIFFLZWDecoder;
169
+ /**
170
+ * LZW Encoder for TIFF images
171
+ */
172
+ class TIFFLZWEncoder {
173
+ constructor() {
174
+ Object.defineProperty(this, "codeSize", {
175
+ enumerable: true,
176
+ configurable: true,
177
+ writable: true,
178
+ value: void 0
179
+ });
180
+ Object.defineProperty(this, "dict", {
181
+ enumerable: true,
182
+ configurable: true,
183
+ writable: true,
184
+ value: void 0
185
+ });
186
+ Object.defineProperty(this, "output", {
187
+ enumerable: true,
188
+ configurable: true,
189
+ writable: true,
190
+ value: void 0
191
+ });
192
+ Object.defineProperty(this, "bitBuffer", {
193
+ enumerable: true,
194
+ configurable: true,
195
+ writable: true,
196
+ value: void 0
197
+ });
198
+ Object.defineProperty(this, "bitCount", {
199
+ enumerable: true,
200
+ configurable: true,
201
+ writable: true,
202
+ value: void 0
203
+ });
204
+ Object.defineProperty(this, "clearCode", {
205
+ enumerable: true,
206
+ configurable: true,
207
+ writable: true,
208
+ value: 256
209
+ });
210
+ Object.defineProperty(this, "eoiCode", {
211
+ enumerable: true,
212
+ configurable: true,
213
+ writable: true,
214
+ value: 257
215
+ });
216
+ Object.defineProperty(this, "nextCode", {
217
+ enumerable: true,
218
+ configurable: true,
219
+ writable: true,
220
+ value: 258
221
+ });
222
+ this.codeSize = 9;
223
+ this.dict = new Map();
224
+ this.output = [];
225
+ this.bitBuffer = 0;
226
+ this.bitCount = 0;
227
+ this.initDictionary();
228
+ }
229
+ initDictionary() {
230
+ this.dict.clear();
231
+ // Initialize dictionary with single-byte entries
232
+ for (let i = 0; i < 256; i++) {
233
+ this.dict.set(String.fromCharCode(i), i);
234
+ }
235
+ this.nextCode = 258;
236
+ this.codeSize = 9;
237
+ }
238
+ writeCode(code) {
239
+ // Write bits MSB-first (TIFF bit ordering)
240
+ for (let i = this.codeSize - 1; i >= 0; i--) {
241
+ const bit = (code >> i) & 1;
242
+ this.bitBuffer = (this.bitBuffer << 1) | bit;
243
+ this.bitCount++;
244
+ if (this.bitCount === 8) {
245
+ this.output.push(this.bitBuffer & 0xff);
246
+ this.bitBuffer = 0;
247
+ this.bitCount = 0;
248
+ }
249
+ }
250
+ }
251
+ compress(data) {
252
+ this.initDictionary();
253
+ this.output = [];
254
+ this.bitBuffer = 0;
255
+ this.bitCount = 0;
256
+ // Write clear code
257
+ this.writeCode(this.clearCode);
258
+ let buffer = "";
259
+ for (let i = 0; i < data.length; i++) {
260
+ const k = String.fromCharCode(data[i]);
261
+ const bufferK = buffer + k;
262
+ if (this.dict.has(bufferK)) {
263
+ buffer = bufferK;
264
+ }
265
+ else {
266
+ // Output code for buffer
267
+ const code = this.dict.get(buffer);
268
+ if (code !== undefined) {
269
+ this.writeCode(code);
270
+ }
271
+ // Add new entry to dictionary
272
+ if (this.nextCode < 4096) {
273
+ this.dict.set(bufferK, this.nextCode);
274
+ this.nextCode++;
275
+ // Increase code size when needed
276
+ if (this.nextCode === 512 && this.codeSize === 9) {
277
+ this.codeSize = 10;
278
+ }
279
+ else if (this.nextCode === 1024 && this.codeSize === 10) {
280
+ this.codeSize = 11;
281
+ }
282
+ else if (this.nextCode === 2048 && this.codeSize === 11) {
283
+ this.codeSize = 12;
284
+ }
285
+ // Reset when dictionary is full
286
+ if (this.nextCode === 4096) {
287
+ this.writeCode(this.clearCode);
288
+ this.initDictionary();
289
+ }
290
+ }
291
+ buffer = k;
292
+ }
293
+ }
294
+ // Output final code
295
+ if (buffer.length > 0) {
296
+ const code = this.dict.get(buffer);
297
+ if (code !== undefined) {
298
+ this.writeCode(code);
299
+ }
300
+ }
301
+ // Write end code
302
+ this.writeCode(this.eoiCode);
303
+ // Flush remaining bits
304
+ if (this.bitCount > 0) {
305
+ this.bitBuffer <<= 8 - this.bitCount;
306
+ this.output.push(this.bitBuffer & 0xff);
307
+ }
308
+ return new Uint8Array(this.output);
309
+ }
310
+ }
311
+ exports.TIFFLZWEncoder = TIFFLZWEncoder;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * WebP VP8L (Lossless) decoder implementation
3
+ *
4
+ * This module implements a pure JavaScript decoder for WebP lossless (VP8L) format.
5
+ * It supports:
6
+ * - Huffman coding (canonical Huffman codes)
7
+ * - LZ77 backward references for compression
8
+ * - Color cache for repeated colors
9
+ * - Simple and complex Huffman code tables
10
+ *
11
+ * Current limitations:
12
+ * - Does not support transforms (predictor, color, subtract green, color indexing)
13
+ * - Does not support meta Huffman codes
14
+ * - Does not support lossy WebP (VP8) format
15
+ *
16
+ * For images with transforms or lossy compression, the decoder will fall back
17
+ * to the runtime's ImageDecoder API if available.
18
+ *
19
+ * @see https://developers.google.com/speed/webp/docs/riff_container
20
+ * @see https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification
21
+ */
22
+ export declare class WebPDecoder {
23
+ private data;
24
+ constructor(data: Uint8Array);
25
+ decode(): {
26
+ width: number;
27
+ height: number;
28
+ data: Uint8Array;
29
+ };
30
+ private decodeVP8L;
31
+ private decodeImageData;
32
+ private readHuffmanCodes;
33
+ private readHuffmanCode;
34
+ private readCodeLengths;
35
+ private buildHuffmanTable;
36
+ private getLength;
37
+ private getDistance;
38
+ }
39
+ //# sourceMappingURL=webp_decoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webp_decoder.d.ts","sourceRoot":"","sources":["../../../src/src/utils/webp_decoder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAsHH,qBAAa,WAAW;IACtB,OAAO,CAAC,IAAI,CAAa;gBAEb,IAAI,EAAE,UAAU;IAI5B,MAAM,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAA;KAAE;IAgE7D,OAAO,CAAC,UAAU;IA+BlB,OAAO,CAAC,eAAe;IAqHvB,OAAO,CAAC,gBAAgB;IAqDxB,OAAO,CAAC,eAAe;IA0CvB,OAAO,CAAC,eAAe;IAkEvB,OAAO,CAAC,iBAAiB;IA6BzB,OAAO,CAAC,SAAS;IAUjB,OAAO,CAAC,WAAW;CASpB"}