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.
- package/LICENSE +21 -0
- package/README.md +606 -0
- package/esm/mod.d.ts +33 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +31 -0
- package/esm/package.json +3 -0
- package/esm/src/formats/ascii.d.ts +27 -0
- package/esm/src/formats/ascii.d.ts.map +1 -0
- package/esm/src/formats/ascii.js +172 -0
- package/esm/src/formats/bmp.d.ts +19 -0
- package/esm/src/formats/bmp.d.ts.map +1 -0
- package/esm/src/formats/bmp.js +174 -0
- package/esm/src/formats/gif.d.ts +40 -0
- package/esm/src/formats/gif.d.ts.map +1 -0
- package/esm/src/formats/gif.js +385 -0
- package/esm/src/formats/jpeg.d.ts +18 -0
- package/esm/src/formats/jpeg.d.ts.map +1 -0
- package/esm/src/formats/jpeg.js +414 -0
- package/esm/src/formats/png.d.ts +33 -0
- package/esm/src/formats/png.d.ts.map +1 -0
- package/esm/src/formats/png.js +544 -0
- package/esm/src/formats/raw.d.ts +23 -0
- package/esm/src/formats/raw.d.ts.map +1 -0
- package/esm/src/formats/raw.js +98 -0
- package/esm/src/formats/tiff.d.ts +58 -0
- package/esm/src/formats/tiff.d.ts.map +1 -0
- package/esm/src/formats/tiff.js +791 -0
- package/esm/src/formats/webp.d.ts +22 -0
- package/esm/src/formats/webp.d.ts.map +1 -0
- package/esm/src/formats/webp.js +403 -0
- package/esm/src/image.d.ts +124 -0
- package/esm/src/image.d.ts.map +1 -0
- package/esm/src/image.js +320 -0
- package/esm/src/types.d.ts +167 -0
- package/esm/src/types.d.ts.map +1 -0
- package/esm/src/types.js +1 -0
- package/esm/src/utils/gif_decoder.d.ts +42 -0
- package/esm/src/utils/gif_decoder.d.ts.map +1 -0
- package/esm/src/utils/gif_decoder.js +374 -0
- package/esm/src/utils/gif_encoder.d.ts +29 -0
- package/esm/src/utils/gif_encoder.d.ts.map +1 -0
- package/esm/src/utils/gif_encoder.js +226 -0
- package/esm/src/utils/jpeg_decoder.d.ts +39 -0
- package/esm/src/utils/jpeg_decoder.d.ts.map +1 -0
- package/esm/src/utils/jpeg_decoder.js +580 -0
- package/esm/src/utils/jpeg_encoder.d.ts +33 -0
- package/esm/src/utils/jpeg_encoder.d.ts.map +1 -0
- package/esm/src/utils/jpeg_encoder.js +1017 -0
- package/esm/src/utils/lzw.d.ts +43 -0
- package/esm/src/utils/lzw.d.ts.map +1 -0
- package/esm/src/utils/lzw.js +309 -0
- package/esm/src/utils/resize.d.ts +9 -0
- package/esm/src/utils/resize.d.ts.map +1 -0
- package/esm/src/utils/resize.js +52 -0
- package/esm/src/utils/tiff_lzw.d.ts +44 -0
- package/esm/src/utils/tiff_lzw.d.ts.map +1 -0
- package/esm/src/utils/tiff_lzw.js +306 -0
- package/esm/src/utils/webp_decoder.d.ts +39 -0
- package/esm/src/utils/webp_decoder.d.ts.map +1 -0
- package/esm/src/utils/webp_decoder.js +493 -0
- package/esm/src/utils/webp_encoder.d.ts +72 -0
- package/esm/src/utils/webp_encoder.d.ts.map +1 -0
- package/esm/src/utils/webp_encoder.js +627 -0
- package/package.json +41 -0
- package/script/mod.d.ts +33 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +43 -0
- package/script/package.json +3 -0
- package/script/src/formats/ascii.d.ts +27 -0
- package/script/src/formats/ascii.d.ts.map +1 -0
- package/script/src/formats/ascii.js +176 -0
- package/script/src/formats/bmp.d.ts +19 -0
- package/script/src/formats/bmp.d.ts.map +1 -0
- package/script/src/formats/bmp.js +178 -0
- package/script/src/formats/gif.d.ts +40 -0
- package/script/src/formats/gif.d.ts.map +1 -0
- package/script/src/formats/gif.js +389 -0
- package/script/src/formats/jpeg.d.ts +18 -0
- package/script/src/formats/jpeg.d.ts.map +1 -0
- package/script/src/formats/jpeg.js +451 -0
- package/script/src/formats/png.d.ts +33 -0
- package/script/src/formats/png.d.ts.map +1 -0
- package/script/src/formats/png.js +548 -0
- package/script/src/formats/raw.d.ts +23 -0
- package/script/src/formats/raw.d.ts.map +1 -0
- package/script/src/formats/raw.js +102 -0
- package/script/src/formats/tiff.d.ts +58 -0
- package/script/src/formats/tiff.d.ts.map +1 -0
- package/script/src/formats/tiff.js +795 -0
- package/script/src/formats/webp.d.ts +22 -0
- package/script/src/formats/webp.d.ts.map +1 -0
- package/script/src/formats/webp.js +440 -0
- package/script/src/image.d.ts +124 -0
- package/script/src/image.d.ts.map +1 -0
- package/script/src/image.js +324 -0
- package/script/src/types.d.ts +167 -0
- package/script/src/types.d.ts.map +1 -0
- package/script/src/types.js +2 -0
- package/script/src/utils/gif_decoder.d.ts +42 -0
- package/script/src/utils/gif_decoder.d.ts.map +1 -0
- package/script/src/utils/gif_decoder.js +378 -0
- package/script/src/utils/gif_encoder.d.ts +29 -0
- package/script/src/utils/gif_encoder.d.ts.map +1 -0
- package/script/src/utils/gif_encoder.js +230 -0
- package/script/src/utils/jpeg_decoder.d.ts +39 -0
- package/script/src/utils/jpeg_decoder.d.ts.map +1 -0
- package/script/src/utils/jpeg_decoder.js +584 -0
- package/script/src/utils/jpeg_encoder.d.ts +33 -0
- package/script/src/utils/jpeg_encoder.d.ts.map +1 -0
- package/script/src/utils/jpeg_encoder.js +1021 -0
- package/script/src/utils/lzw.d.ts +43 -0
- package/script/src/utils/lzw.d.ts.map +1 -0
- package/script/src/utils/lzw.js +314 -0
- package/script/src/utils/resize.d.ts +9 -0
- package/script/src/utils/resize.d.ts.map +1 -0
- package/script/src/utils/resize.js +56 -0
- package/script/src/utils/tiff_lzw.d.ts +44 -0
- package/script/src/utils/tiff_lzw.d.ts.map +1 -0
- package/script/src/utils/tiff_lzw.js +311 -0
- package/script/src/utils/webp_decoder.d.ts +39 -0
- package/script/src/utils/webp_decoder.d.ts.map +1 -0
- package/script/src/utils/webp_decoder.js +497 -0
- package/script/src/utils/webp_encoder.d.ts +72 -0
- package/script/src/utils/webp_encoder.d.ts.map +1 -0
- package/script/src/utils/webp_encoder.js +631 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZW (Lempel-Ziv-Welch) compression and decompression
|
|
3
|
+
* Used for GIF image encoding and decoding
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* LZW Decompressor for GIF images
|
|
7
|
+
*/
|
|
8
|
+
export declare class LZWDecoder {
|
|
9
|
+
private minCodeSize;
|
|
10
|
+
private clearCode;
|
|
11
|
+
private endCode;
|
|
12
|
+
private data;
|
|
13
|
+
private pos;
|
|
14
|
+
private bitPos;
|
|
15
|
+
private codeSize;
|
|
16
|
+
private maxCode;
|
|
17
|
+
private dict;
|
|
18
|
+
private prevCode;
|
|
19
|
+
private nextCode;
|
|
20
|
+
constructor(minCodeSize: number, data: Uint8Array);
|
|
21
|
+
private initDictionary;
|
|
22
|
+
private readCode;
|
|
23
|
+
decompress(): Uint8Array;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* LZW Encoder for GIF images
|
|
27
|
+
*/
|
|
28
|
+
export declare class LZWEncoder {
|
|
29
|
+
private minCodeSize;
|
|
30
|
+
private clearCode;
|
|
31
|
+
private endCode;
|
|
32
|
+
private codeSize;
|
|
33
|
+
private maxCode;
|
|
34
|
+
private dict;
|
|
35
|
+
private output;
|
|
36
|
+
private bitBuffer;
|
|
37
|
+
private bitCount;
|
|
38
|
+
constructor(minCodeSize: number);
|
|
39
|
+
private initDictionary;
|
|
40
|
+
private writeCode;
|
|
41
|
+
compress(data: Uint8Array): Uint8Array;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=lzw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lzw.d.ts","sourceRoot":"","sources":["../../../src/src/utils/lzw.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,IAAI,CAAe;IAC3B,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,QAAQ,CAAS;gBAEb,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU;IAejD,OAAO,CAAC,cAAc;IAetB,OAAO,CAAC,QAAQ;IAqBhB,UAAU,IAAI,UAAU;CA0DzB;AAED;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,IAAI,CAAsB;IAClC,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAS;gBAEb,WAAW,EAAE,MAAM;IAa/B,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,SAAS;IAWjB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU;CA4DvC"}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* LZW (Lempel-Ziv-Welch) compression and decompression
|
|
4
|
+
* Used for GIF image encoding and decoding
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.LZWEncoder = exports.LZWDecoder = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* LZW Decompressor for GIF images
|
|
10
|
+
*/
|
|
11
|
+
class LZWDecoder {
|
|
12
|
+
constructor(minCodeSize, data) {
|
|
13
|
+
Object.defineProperty(this, "minCodeSize", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "clearCode", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "endCode", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(this, "data", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: void 0
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "pos", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: void 0
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(this, "bitPos", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
writable: true,
|
|
47
|
+
value: void 0
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(this, "codeSize", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: void 0
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(this, "maxCode", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true,
|
|
59
|
+
value: void 0
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(this, "dict", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
writable: true,
|
|
65
|
+
value: void 0
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(this, "prevCode", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
configurable: true,
|
|
70
|
+
writable: true,
|
|
71
|
+
value: void 0
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(this, "nextCode", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
configurable: true,
|
|
76
|
+
writable: true,
|
|
77
|
+
value: void 0
|
|
78
|
+
});
|
|
79
|
+
this.minCodeSize = minCodeSize;
|
|
80
|
+
this.clearCode = 1 << minCodeSize;
|
|
81
|
+
this.endCode = this.clearCode + 1;
|
|
82
|
+
this.data = data;
|
|
83
|
+
this.pos = 0;
|
|
84
|
+
this.bitPos = 0;
|
|
85
|
+
this.codeSize = minCodeSize + 1;
|
|
86
|
+
this.maxCode = (1 << this.codeSize) - 1;
|
|
87
|
+
this.dict = [];
|
|
88
|
+
this.prevCode = null;
|
|
89
|
+
this.nextCode = this.endCode + 1;
|
|
90
|
+
this.initDictionary();
|
|
91
|
+
}
|
|
92
|
+
initDictionary() {
|
|
93
|
+
this.dict = [];
|
|
94
|
+
// Initialize dictionary with single-byte entries
|
|
95
|
+
for (let i = 0; i < this.clearCode; i++) {
|
|
96
|
+
this.dict[i] = new Uint8Array([i]);
|
|
97
|
+
}
|
|
98
|
+
// Reserve clear code and end code positions
|
|
99
|
+
this.dict[this.clearCode] = new Uint8Array(0);
|
|
100
|
+
this.dict[this.endCode] = new Uint8Array(0);
|
|
101
|
+
this.codeSize = this.minCodeSize + 1;
|
|
102
|
+
this.maxCode = (1 << this.codeSize) - 1;
|
|
103
|
+
this.prevCode = null;
|
|
104
|
+
this.nextCode = this.endCode + 1;
|
|
105
|
+
}
|
|
106
|
+
readCode() {
|
|
107
|
+
let code = 0;
|
|
108
|
+
for (let i = 0; i < this.codeSize; i++) {
|
|
109
|
+
if (this.bitPos === 0) {
|
|
110
|
+
// Need to read a new byte
|
|
111
|
+
if (this.pos >= this.data.length) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const byte = this.data[this.pos];
|
|
116
|
+
const bit = (byte >> this.bitPos) & 1;
|
|
117
|
+
code |= bit << i;
|
|
118
|
+
this.bitPos++;
|
|
119
|
+
if (this.bitPos === 8) {
|
|
120
|
+
this.bitPos = 0;
|
|
121
|
+
this.pos++;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return code;
|
|
125
|
+
}
|
|
126
|
+
decompress() {
|
|
127
|
+
const output = [];
|
|
128
|
+
while (true) {
|
|
129
|
+
// Check if we need to increase code size for this read
|
|
130
|
+
// This happens when we're about to add an entry at nextCode and it exceeds maxCode
|
|
131
|
+
if (this.prevCode !== null && this.nextCode > this.maxCode &&
|
|
132
|
+
this.codeSize < 12) {
|
|
133
|
+
this.maxCode = this.maxCode * 2 + 1;
|
|
134
|
+
this.codeSize++;
|
|
135
|
+
}
|
|
136
|
+
const code = this.readCode();
|
|
137
|
+
if (code === null || code === this.endCode) {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
if (code === this.clearCode) {
|
|
141
|
+
this.initDictionary();
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (code < this.dict.length && this.dict[code]) {
|
|
145
|
+
const entry = this.dict[code];
|
|
146
|
+
output.push(...entry);
|
|
147
|
+
if (this.prevCode !== null && this.prevCode < this.dict.length) {
|
|
148
|
+
const prevEntry = this.dict[this.prevCode];
|
|
149
|
+
if (prevEntry && this.nextCode < 4096) {
|
|
150
|
+
const newEntry = new Uint8Array(prevEntry.length + 1);
|
|
151
|
+
newEntry.set(prevEntry);
|
|
152
|
+
newEntry[prevEntry.length] = entry[0];
|
|
153
|
+
this.dict[this.nextCode] = newEntry;
|
|
154
|
+
this.nextCode++;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else if (this.prevCode !== null && this.prevCode < this.dict.length) {
|
|
159
|
+
// Special case: code not in dictionary yet
|
|
160
|
+
const prevEntry = this.dict[this.prevCode];
|
|
161
|
+
if (prevEntry && this.nextCode < 4096) {
|
|
162
|
+
const newEntry = new Uint8Array(prevEntry.length + 1);
|
|
163
|
+
newEntry.set(prevEntry);
|
|
164
|
+
newEntry[prevEntry.length] = prevEntry[0];
|
|
165
|
+
this.dict[this.nextCode] = newEntry;
|
|
166
|
+
this.nextCode++;
|
|
167
|
+
output.push(...newEntry);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
this.prevCode = code;
|
|
171
|
+
}
|
|
172
|
+
return new Uint8Array(output);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.LZWDecoder = LZWDecoder;
|
|
176
|
+
/**
|
|
177
|
+
* LZW Encoder for GIF images
|
|
178
|
+
*/
|
|
179
|
+
class LZWEncoder {
|
|
180
|
+
constructor(minCodeSize) {
|
|
181
|
+
Object.defineProperty(this, "minCodeSize", {
|
|
182
|
+
enumerable: true,
|
|
183
|
+
configurable: true,
|
|
184
|
+
writable: true,
|
|
185
|
+
value: void 0
|
|
186
|
+
});
|
|
187
|
+
Object.defineProperty(this, "clearCode", {
|
|
188
|
+
enumerable: true,
|
|
189
|
+
configurable: true,
|
|
190
|
+
writable: true,
|
|
191
|
+
value: void 0
|
|
192
|
+
});
|
|
193
|
+
Object.defineProperty(this, "endCode", {
|
|
194
|
+
enumerable: true,
|
|
195
|
+
configurable: true,
|
|
196
|
+
writable: true,
|
|
197
|
+
value: void 0
|
|
198
|
+
});
|
|
199
|
+
Object.defineProperty(this, "codeSize", {
|
|
200
|
+
enumerable: true,
|
|
201
|
+
configurable: true,
|
|
202
|
+
writable: true,
|
|
203
|
+
value: void 0
|
|
204
|
+
});
|
|
205
|
+
Object.defineProperty(this, "maxCode", {
|
|
206
|
+
enumerable: true,
|
|
207
|
+
configurable: true,
|
|
208
|
+
writable: true,
|
|
209
|
+
value: void 0
|
|
210
|
+
});
|
|
211
|
+
Object.defineProperty(this, "dict", {
|
|
212
|
+
enumerable: true,
|
|
213
|
+
configurable: true,
|
|
214
|
+
writable: true,
|
|
215
|
+
value: void 0
|
|
216
|
+
});
|
|
217
|
+
Object.defineProperty(this, "output", {
|
|
218
|
+
enumerable: true,
|
|
219
|
+
configurable: true,
|
|
220
|
+
writable: true,
|
|
221
|
+
value: void 0
|
|
222
|
+
});
|
|
223
|
+
Object.defineProperty(this, "bitBuffer", {
|
|
224
|
+
enumerable: true,
|
|
225
|
+
configurable: true,
|
|
226
|
+
writable: true,
|
|
227
|
+
value: void 0
|
|
228
|
+
});
|
|
229
|
+
Object.defineProperty(this, "bitCount", {
|
|
230
|
+
enumerable: true,
|
|
231
|
+
configurable: true,
|
|
232
|
+
writable: true,
|
|
233
|
+
value: void 0
|
|
234
|
+
});
|
|
235
|
+
this.minCodeSize = minCodeSize;
|
|
236
|
+
this.clearCode = 1 << minCodeSize;
|
|
237
|
+
this.endCode = this.clearCode + 1;
|
|
238
|
+
this.codeSize = minCodeSize + 1;
|
|
239
|
+
this.maxCode = (1 << this.codeSize) - 1;
|
|
240
|
+
this.dict = new Map();
|
|
241
|
+
this.output = [];
|
|
242
|
+
this.bitBuffer = 0;
|
|
243
|
+
this.bitCount = 0;
|
|
244
|
+
this.initDictionary();
|
|
245
|
+
}
|
|
246
|
+
initDictionary() {
|
|
247
|
+
this.dict.clear();
|
|
248
|
+
// Initialize dictionary with single-byte entries
|
|
249
|
+
for (let i = 0; i < this.clearCode; i++) {
|
|
250
|
+
this.dict.set(String.fromCharCode(i), i);
|
|
251
|
+
}
|
|
252
|
+
this.codeSize = this.minCodeSize + 1;
|
|
253
|
+
this.maxCode = (1 << this.codeSize) - 1;
|
|
254
|
+
}
|
|
255
|
+
writeCode(code) {
|
|
256
|
+
this.bitBuffer |= code << this.bitCount;
|
|
257
|
+
this.bitCount += this.codeSize;
|
|
258
|
+
while (this.bitCount >= 8) {
|
|
259
|
+
this.output.push(this.bitBuffer & 0xff);
|
|
260
|
+
this.bitBuffer >>= 8;
|
|
261
|
+
this.bitCount -= 8;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
compress(data) {
|
|
265
|
+
this.initDictionary();
|
|
266
|
+
this.output = [];
|
|
267
|
+
this.bitBuffer = 0;
|
|
268
|
+
this.bitCount = 0;
|
|
269
|
+
// Write clear code
|
|
270
|
+
this.writeCode(this.clearCode);
|
|
271
|
+
let buffer = "";
|
|
272
|
+
let nextCode = this.endCode + 1;
|
|
273
|
+
for (let i = 0; i < data.length; i++) {
|
|
274
|
+
const k = String.fromCharCode(data[i]);
|
|
275
|
+
const bufferK = buffer + k;
|
|
276
|
+
if (this.dict.has(bufferK)) {
|
|
277
|
+
buffer = bufferK;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
// Output code for buffer
|
|
281
|
+
const code = this.dict.get(buffer);
|
|
282
|
+
if (code !== undefined) {
|
|
283
|
+
this.writeCode(code);
|
|
284
|
+
}
|
|
285
|
+
// Add new entry to dictionary
|
|
286
|
+
if (nextCode < 4096) {
|
|
287
|
+
this.dict.set(bufferK, nextCode);
|
|
288
|
+
// Increase code size when needed (check BEFORE incrementing nextCode)
|
|
289
|
+
if (nextCode > this.maxCode && this.codeSize < 12) {
|
|
290
|
+
this.maxCode = this.maxCode * 2 + 1;
|
|
291
|
+
this.codeSize++;
|
|
292
|
+
}
|
|
293
|
+
nextCode++;
|
|
294
|
+
}
|
|
295
|
+
buffer = k;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
// Output final code
|
|
299
|
+
if (buffer.length > 0) {
|
|
300
|
+
const code = this.dict.get(buffer);
|
|
301
|
+
if (code !== undefined) {
|
|
302
|
+
this.writeCode(code);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// Write end code
|
|
306
|
+
this.writeCode(this.endCode);
|
|
307
|
+
// Flush remaining bits
|
|
308
|
+
if (this.bitCount > 0) {
|
|
309
|
+
this.output.push(this.bitBuffer & 0xff);
|
|
310
|
+
}
|
|
311
|
+
return new Uint8Array(this.output);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
exports.LZWEncoder = LZWEncoder;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bilinear interpolation resize
|
|
3
|
+
*/
|
|
4
|
+
export declare function resizeBilinear(src: Uint8Array, srcWidth: number, srcHeight: number, dstWidth: number, dstHeight: number): Uint8Array;
|
|
5
|
+
/**
|
|
6
|
+
* Nearest neighbor resize
|
|
7
|
+
*/
|
|
8
|
+
export declare function resizeNearest(src: Uint8Array, srcWidth: number, srcHeight: number, dstWidth: number, dstHeight: number): Uint8Array;
|
|
9
|
+
//# sourceMappingURL=resize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resize.d.ts","sourceRoot":"","sources":["../../../src/src/utils/resize.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,UAAU,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,UAAU,CAgCZ;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,UAAU,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,UAAU,CAoBZ"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resizeBilinear = resizeBilinear;
|
|
4
|
+
exports.resizeNearest = resizeNearest;
|
|
5
|
+
/**
|
|
6
|
+
* Bilinear interpolation resize
|
|
7
|
+
*/
|
|
8
|
+
function resizeBilinear(src, srcWidth, srcHeight, dstWidth, dstHeight) {
|
|
9
|
+
const dst = new Uint8Array(dstWidth * dstHeight * 4);
|
|
10
|
+
const xRatio = srcWidth / dstWidth;
|
|
11
|
+
const yRatio = srcHeight / dstHeight;
|
|
12
|
+
for (let y = 0; y < dstHeight; y++) {
|
|
13
|
+
for (let x = 0; x < dstWidth; x++) {
|
|
14
|
+
const srcX = x * xRatio;
|
|
15
|
+
const srcY = y * yRatio;
|
|
16
|
+
const x1 = Math.floor(srcX);
|
|
17
|
+
const y1 = Math.floor(srcY);
|
|
18
|
+
const x2 = Math.min(x1 + 1, srcWidth - 1);
|
|
19
|
+
const y2 = Math.min(y1 + 1, srcHeight - 1);
|
|
20
|
+
const dx = srcX - x1;
|
|
21
|
+
const dy = srcY - y1;
|
|
22
|
+
for (let c = 0; c < 4; c++) {
|
|
23
|
+
const p1 = src[(y1 * srcWidth + x1) * 4 + c];
|
|
24
|
+
const p2 = src[(y1 * srcWidth + x2) * 4 + c];
|
|
25
|
+
const p3 = src[(y2 * srcWidth + x1) * 4 + c];
|
|
26
|
+
const p4 = src[(y2 * srcWidth + x2) * 4 + c];
|
|
27
|
+
const v1 = p1 * (1 - dx) + p2 * dx;
|
|
28
|
+
const v2 = p3 * (1 - dx) + p4 * dx;
|
|
29
|
+
const v = v1 * (1 - dy) + v2 * dy;
|
|
30
|
+
dst[(y * dstWidth + x) * 4 + c] = Math.round(v);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return dst;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Nearest neighbor resize
|
|
38
|
+
*/
|
|
39
|
+
function resizeNearest(src, srcWidth, srcHeight, dstWidth, dstHeight) {
|
|
40
|
+
const dst = new Uint8Array(dstWidth * dstHeight * 4);
|
|
41
|
+
const xRatio = srcWidth / dstWidth;
|
|
42
|
+
const yRatio = srcHeight / dstHeight;
|
|
43
|
+
for (let y = 0; y < dstHeight; y++) {
|
|
44
|
+
for (let x = 0; x < dstWidth; x++) {
|
|
45
|
+
const srcX = Math.floor(x * xRatio);
|
|
46
|
+
const srcY = Math.floor(y * yRatio);
|
|
47
|
+
const srcIdx = (srcY * srcWidth + srcX) * 4;
|
|
48
|
+
const dstIdx = (y * dstWidth + x) * 4;
|
|
49
|
+
dst[dstIdx] = src[srcIdx];
|
|
50
|
+
dst[dstIdx + 1] = src[srcIdx + 1];
|
|
51
|
+
dst[dstIdx + 2] = src[srcIdx + 2];
|
|
52
|
+
dst[dstIdx + 3] = src[srcIdx + 3];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return dst;
|
|
56
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZW compression and decompression for TIFF images
|
|
3
|
+
*
|
|
4
|
+
* TIFF LZW differs from GIF LZW in several ways:
|
|
5
|
+
* - Uses MSB-first bit ordering (big-endian bits)
|
|
6
|
+
* - Typically starts with 9-bit codes
|
|
7
|
+
* - Uses code 256 as clear code, code 257 as end-of-information (EOI)
|
|
8
|
+
* - Variable code size from 9 to 12 bits
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* LZW Decompressor for TIFF images
|
|
12
|
+
*/
|
|
13
|
+
export declare class TIFFLZWDecoder {
|
|
14
|
+
private data;
|
|
15
|
+
private pos;
|
|
16
|
+
private bitPos;
|
|
17
|
+
private codeSize;
|
|
18
|
+
private dict;
|
|
19
|
+
private clearCode;
|
|
20
|
+
private eoiCode;
|
|
21
|
+
private nextCode;
|
|
22
|
+
constructor(data: Uint8Array);
|
|
23
|
+
private initDictionary;
|
|
24
|
+
private readCode;
|
|
25
|
+
decompress(): Uint8Array;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* LZW Encoder for TIFF images
|
|
29
|
+
*/
|
|
30
|
+
export declare class TIFFLZWEncoder {
|
|
31
|
+
private codeSize;
|
|
32
|
+
private dict;
|
|
33
|
+
private output;
|
|
34
|
+
private bitBuffer;
|
|
35
|
+
private bitCount;
|
|
36
|
+
private clearCode;
|
|
37
|
+
private eoiCode;
|
|
38
|
+
private nextCode;
|
|
39
|
+
constructor();
|
|
40
|
+
private initDictionary;
|
|
41
|
+
private writeCode;
|
|
42
|
+
compress(data: Uint8Array): Uint8Array;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=tiff_lzw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiff_lzw.d.ts","sourceRoot":"","sources":["../../../src/src/utils/tiff_lzw.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,IAAI,CAAe;IAC3B,OAAO,CAAC,SAAS,CAAO;IACxB,OAAO,CAAC,OAAO,CAAO;IACtB,OAAO,CAAC,QAAQ,CAAO;gBAEX,IAAI,EAAE,UAAU;IAS5B,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,QAAQ;IA2BhB,UAAU,IAAI,UAAU;CA2EzB;AAED;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,IAAI,CAAsB;IAClC,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAO;IACxB,OAAO,CAAC,OAAO,CAAO;IACtB,OAAO,CAAC,QAAQ,CAAO;;IAWvB,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,SAAS;IAejB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU;CAoEvC"}
|