imagescript 1.3.1 → 3.1.0
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 +4 -1
- package/README.md +76 -26
- package/THIRD_PARTY_NOTICES.md +156 -0
- package/dist/animation.d.ts +55 -0
- package/dist/animation.js +167 -0
- package/dist/codecs/crc.d.ts +9 -0
- package/dist/codecs/crc.js +29 -0
- package/dist/codecs/exif.d.ts +11 -0
- package/dist/codecs/exif.js +27 -0
- package/dist/codecs/gif.d.ts +44 -0
- package/dist/codecs/gif.js +401 -0
- package/dist/codecs/jpeg.d.ts +35 -0
- package/dist/codecs/jpeg.js +980 -0
- package/dist/codecs/png.d.ts +97 -0
- package/dist/codecs/png.js +664 -0
- package/dist/codecs/quantize.d.ts +25 -0
- package/dist/codecs/quantize.js +302 -0
- package/dist/codecs/tga.d.ts +16 -0
- package/dist/codecs/tga.js +203 -0
- package/dist/codecs/tiff.d.ts +6 -0
- package/dist/codecs/tiff.js +546 -0
- package/dist/codecs/vp8-tables.d.ts +10 -0
- package/dist/codecs/vp8-tables.js +17 -0
- package/dist/codecs/vp8.d.ts +8 -0
- package/dist/codecs/vp8.js +711 -0
- package/dist/codecs/vp8l.d.ts +62 -0
- package/dist/codecs/vp8l.js +909 -0
- package/dist/codecs/webp.d.ts +67 -0
- package/dist/codecs/webp.js +280 -0
- package/dist/codecs/zlib.d.ts +22 -0
- package/dist/codecs/zlib.js +607 -0
- package/dist/frame.d.ts +57 -0
- package/dist/frame.js +65 -0
- package/dist/gif.d.ts +31 -0
- package/dist/gif.js +20 -0
- package/dist/image-type.d.ts +24 -0
- package/dist/image-type.js +64 -0
- package/dist/image.d.ts +553 -0
- package/dist/image.js +1156 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +20 -0
- package/dist/package.json +1 -0
- package/dist/render/font.d.ts +92 -0
- package/dist/render/font.js +954 -0
- package/dist/render/hinting.d.ts +110 -0
- package/dist/render/hinting.js +1236 -0
- package/dist/render/svg.d.ts +11 -0
- package/dist/render/svg.js +1717 -0
- package/dist/render/text.d.ts +63 -0
- package/dist/render/text.js +342 -0
- package/dist/text-layout.d.ts +46 -0
- package/dist/text-layout.js +35 -0
- package/dist/util/blur.d.ts +13 -0
- package/dist/util/blur.js +146 -0
- package/dist/util/mem.d.ts +10 -0
- package/dist/util/mem.js +23 -0
- package/dist/util/resample.d.ts +12 -0
- package/dist/util/resample.js +99 -0
- package/dist/util/utf8.d.ts +5 -0
- package/dist/util/utf8.js +55 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/licenses/Apache-2.0.txt +202 -0
- package/licenses/FTL.txt +169 -0
- package/licenses/README.ijg +260 -0
- package/package.json +31 -7
- package/ImageScript.d.ts +0 -954
- package/ImageScript.js +0 -1669
- package/bench/_.mjs +0 -166
- package/bench/all.mjs +0 -4
- package/bench/blur.mjs +0 -59
- package/bench/flip.mjs +0 -63
- package/bench/overlay.mjs +0 -35
- package/bench/package.json +0 -7
- package/bench/readme.md +0 -64
- package/bench/resize.mjs +0 -52
- package/codecs/LICENSE +0 -21
- package/codecs/lib.d.ts +0 -50
- package/codecs/lib.js +0 -6
- package/codecs/lib.mjs +0 -1
- package/codecs/node/bin/arm64-darwin.node +0 -0
- package/codecs/node/bin/arm64-linux.node +0 -0
- package/codecs/node/bin/x64-darwin.node +0 -0
- package/codecs/node/bin/x64-linux.node +0 -0
- package/codecs/node/bin/x64-win32.node +0 -0
- package/codecs/node/index.js +0 -3
- package/codecs/node/index.mjs +0 -6
- package/codecs/package.json +0 -14
- package/codecs/readme.md +0 -38
- package/codecs/wasm/bin/codecs.wasm +0 -0
- package/codecs/wasm/bin/simd.wasm +0 -0
- package/codecs/wasm/bundle/browser.js +0 -1
- package/codecs/wasm/index.js +0 -1
- package/codecs/wasm/index.mjs +0 -1
- package/png/README.md +0 -1
- package/png/node.js +0 -1137
- package/png/src/crc.mjs +0 -49
- package/png/src/mem.mjs +0 -24
- package/png/src/png.mjs +0 -254
- package/png/src/zlib.mjs +0 -618
- package/tsconfig.json +0 -21
- package/utils/mem.js +0 -26
- package/v2/codecs/magic.js +0 -25
- package/v2/framebuffer.d.ts +0 -67
- package/v2/framebuffer.js +0 -2352
- package/v2/framebuffer.mjs +0 -126
- package/v2/framebuffer.rs +0 -1264
- package/v2/index.d.ts +0 -84
- package/v2/index.js +0 -261
- package/v2/ops/blur.mjs +0 -303
- package/v2/ops/color.mjs +0 -277
- package/v2/ops/crop.mjs +0 -64
- package/v2/ops/fill.mjs +0 -33
- package/v2/ops/flip.mjs +0 -33
- package/v2/ops/index.mjs +0 -9
- package/v2/ops/iterator.mjs +0 -34
- package/v2/ops/overlay.mjs +0 -63
- package/v2/ops/resize.mjs +0 -166
- package/v2/ops/rotate.mjs +0 -117
- package/v2/util/mem.mjs +0 -24
- package/wasm/any/font.wasm +0 -0
- package/wasm/any/gif.wasm +0 -0
- package/wasm/any/jpeg.wasm +0 -0
- package/wasm/any/png.wasm +0 -0
- package/wasm/any/svg.wasm +0 -0
- package/wasm/any/tiff.wasm +0 -0
- package/wasm/node/font.js +0 -142
- package/wasm/node/gif.js +0 -76
- package/wasm/node/jpeg.js +0 -92
- package/wasm/node/png.js +0 -49
- package/wasm/node/svg.js +0 -56
- package/wasm/node/tiff.js +0 -47
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
import { decompressAsync } from "./zlib.js";
|
|
2
|
+
import * as jpeg from "./jpeg.js";
|
|
3
|
+
const TYPE_SIZES = { 1: 1, 2: 1, 3: 2, 4: 4, 5: 8, 6: 1, 7: 1, 8: 2, 9: 4, 10: 8, 11: 4, 12: 8, 13: 4, 16: 8, 17: 8, 18: 8 };
|
|
4
|
+
const TAGS = {
|
|
5
|
+
ImageWidth: 256,
|
|
6
|
+
ImageLength: 257,
|
|
7
|
+
BitsPerSample: 258,
|
|
8
|
+
Compression: 259,
|
|
9
|
+
Photometric: 262,
|
|
10
|
+
FillOrder: 266,
|
|
11
|
+
Orientation: 274,
|
|
12
|
+
StripOffsets: 273,
|
|
13
|
+
SamplesPerPixel: 277,
|
|
14
|
+
RowsPerStrip: 278,
|
|
15
|
+
StripByteCounts: 279,
|
|
16
|
+
PlanarConfiguration: 284,
|
|
17
|
+
Predictor: 317,
|
|
18
|
+
ColorMap: 320,
|
|
19
|
+
TileWidth: 322,
|
|
20
|
+
TileLength: 323,
|
|
21
|
+
TileOffsets: 324,
|
|
22
|
+
TileByteCounts: 325,
|
|
23
|
+
ExtraSamples: 338,
|
|
24
|
+
SampleFormat: 339,
|
|
25
|
+
JPEGTables: 347,
|
|
26
|
+
YCbCrCoefficients: 529,
|
|
27
|
+
YCbCrSubSampling: 530,
|
|
28
|
+
ReferenceBlackWhite: 532
|
|
29
|
+
};
|
|
30
|
+
const COMPRESSION_NAMES = { 2: 'CCITT RLE', 3: 'CCITT fax 3', 4: 'CCITT fax 4', 6: 'old-style JPEG', 32809: 'ThunderScan', 34676: 'SGI LogLuv', 34677: 'SGI LogL' };
|
|
31
|
+
export async function decode(data) {
|
|
32
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
33
|
+
let little;
|
|
34
|
+
if (data[0] === 0x49 && data[1] === 0x49)
|
|
35
|
+
little = true;
|
|
36
|
+
else if (data[0] === 0x4d && data[1] === 0x4d)
|
|
37
|
+
little = false;
|
|
38
|
+
else
|
|
39
|
+
throw new Error('TIFF: invalid byte order');
|
|
40
|
+
const u16 = (offset) => view.getUint16(offset, little);
|
|
41
|
+
const u32 = (offset) => view.getUint32(offset, little);
|
|
42
|
+
const u64 = (offset) => {
|
|
43
|
+
const lo = view.getUint32(offset + (little ? 0 : 4), little);
|
|
44
|
+
const hi = view.getUint32(offset + (little ? 4 : 0), little);
|
|
45
|
+
return hi * 0x100000000 + lo;
|
|
46
|
+
};
|
|
47
|
+
const version = u16(2);
|
|
48
|
+
if (version !== 42 && version !== 43)
|
|
49
|
+
throw new Error('TIFF: invalid version');
|
|
50
|
+
const big = version === 43;
|
|
51
|
+
const ifdOffset = big ? u64(8) : u32(4);
|
|
52
|
+
if (ifdOffset + 2 > data.length)
|
|
53
|
+
throw new Error('TIFF: invalid IFD offset');
|
|
54
|
+
const tags = new Map();
|
|
55
|
+
const entryCount = big ? u64(ifdOffset) : u16(ifdOffset);
|
|
56
|
+
const entrySize = big ? 20 : 12;
|
|
57
|
+
const inlineSize = big ? 8 : 4;
|
|
58
|
+
for (let i = 0; i < entryCount; i++) {
|
|
59
|
+
const entry = ifdOffset + (big ? 8 : 2) + i * entrySize;
|
|
60
|
+
if (entry + entrySize > data.length)
|
|
61
|
+
break;
|
|
62
|
+
const tag = u16(entry);
|
|
63
|
+
const type = u16(entry + 2);
|
|
64
|
+
const count = big ? u64(entry + 4) : u32(entry + 4);
|
|
65
|
+
const size = TYPE_SIZES[type];
|
|
66
|
+
if (!size)
|
|
67
|
+
continue;
|
|
68
|
+
const valueField = entry + (big ? 12 : 8);
|
|
69
|
+
const offset = size * count <= inlineSize ? valueField : big ? u64(valueField) : u32(valueField);
|
|
70
|
+
if (offset + size * count > data.length)
|
|
71
|
+
continue;
|
|
72
|
+
tags.set(tag, { type, count, offset });
|
|
73
|
+
}
|
|
74
|
+
const read = (type, offset) => {
|
|
75
|
+
switch (type) {
|
|
76
|
+
case 1:
|
|
77
|
+
case 2:
|
|
78
|
+
case 7: return data[offset];
|
|
79
|
+
case 6: return view.getInt8(offset);
|
|
80
|
+
case 3: return u16(offset);
|
|
81
|
+
case 8: return view.getInt16(offset, little);
|
|
82
|
+
case 4:
|
|
83
|
+
case 13: return u32(offset);
|
|
84
|
+
case 9: return view.getInt32(offset, little);
|
|
85
|
+
case 5: return u32(offset) / u32(offset + 4);
|
|
86
|
+
case 10: return view.getInt32(offset, little) / view.getInt32(offset + 4, little);
|
|
87
|
+
case 11: return view.getFloat32(offset, little);
|
|
88
|
+
case 12: return view.getFloat64(offset, little);
|
|
89
|
+
case 16:
|
|
90
|
+
case 18: return u64(offset);
|
|
91
|
+
case 17: return Number(view.getBigInt64(offset, little));
|
|
92
|
+
default: return 0;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
function values(tag, fallback) {
|
|
96
|
+
const entry = tags.get(tag);
|
|
97
|
+
if (!entry)
|
|
98
|
+
return fallback;
|
|
99
|
+
const result = new Array(entry.count);
|
|
100
|
+
const size = TYPE_SIZES[entry.type];
|
|
101
|
+
for (let i = 0; i < entry.count; i++)
|
|
102
|
+
result[i] = read(entry.type, entry.offset + i * size);
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
function value(tag, fallback) {
|
|
106
|
+
const v = values(tag);
|
|
107
|
+
return v && v.length ? v[0] : fallback;
|
|
108
|
+
}
|
|
109
|
+
const orientationTag = value(TAGS.Orientation, 1);
|
|
110
|
+
const orientation = orientationTag >= 1 && orientationTag <= 8 ? orientationTag : 1;
|
|
111
|
+
const width = value(TAGS.ImageWidth);
|
|
112
|
+
const height = value(TAGS.ImageLength);
|
|
113
|
+
if (!width || !height)
|
|
114
|
+
throw new Error('TIFF: invalid dimensions');
|
|
115
|
+
const samplesPerPixel = value(TAGS.SamplesPerPixel, 1);
|
|
116
|
+
const bitsPerSample = values(TAGS.BitsPerSample, [1]);
|
|
117
|
+
const bps = bitsPerSample[0];
|
|
118
|
+
if (bitsPerSample.some(b => b !== bps))
|
|
119
|
+
throw new Error('TIFF: mixed bit depths are not supported');
|
|
120
|
+
const compression = value(TAGS.Compression, 1);
|
|
121
|
+
const photometric = value(TAGS.Photometric, samplesPerPixel >= 3 ? 2 : 1);
|
|
122
|
+
const planar = value(TAGS.PlanarConfiguration, 1) === 2 && samplesPerPixel > 1;
|
|
123
|
+
const predictor = value(TAGS.Predictor, 1);
|
|
124
|
+
const sampleFormat = value(TAGS.SampleFormat, 1);
|
|
125
|
+
const fillOrder = value(TAGS.FillOrder, 1);
|
|
126
|
+
const extraSamples = values(TAGS.ExtraSamples, []);
|
|
127
|
+
if (COMPRESSION_NAMES[compression])
|
|
128
|
+
throw new Error(`TIFF: ${COMPRESSION_NAMES[compression]} compression is not supported`);
|
|
129
|
+
if (![1, 5, 7, 8, 32773, 32946].includes(compression))
|
|
130
|
+
throw new Error(`TIFF: compression ${compression} is not supported`);
|
|
131
|
+
if (![0, 1, 2, 3, 5, 6].includes(photometric))
|
|
132
|
+
throw new Error(`TIFF: photometric interpretation ${photometric} is not supported`);
|
|
133
|
+
if (sampleFormat === 3 ? bps !== 32 && bps !== 64 : bps < 1 || bps > 32)
|
|
134
|
+
throw new Error(`TIFF: ${bps}-bit samples are not supported`);
|
|
135
|
+
const colorChannels = { 0: 1, 1: 1, 2: 3, 3: 1, 5: 4, 6: 3 }[photometric];
|
|
136
|
+
if (samplesPerPixel < colorChannels)
|
|
137
|
+
throw new Error('TIFF: not enough samples per pixel');
|
|
138
|
+
const alphaType = samplesPerPixel > colorChannels ? extraSamples[0] || 0 : 0;
|
|
139
|
+
const alphaChannel = alphaType === 1 || alphaType === 2 ? colorChannels : -1;
|
|
140
|
+
const tiled = tags.has(TAGS.TileWidth) && tags.has(TAGS.TileLength);
|
|
141
|
+
const segmentWidth = tiled ? value(TAGS.TileWidth) : width;
|
|
142
|
+
const segmentHeight = tiled ? value(TAGS.TileLength) : Math.min(height, value(TAGS.RowsPerStrip, height));
|
|
143
|
+
const offsets = values(TAGS.TileOffsets) || values(TAGS.StripOffsets);
|
|
144
|
+
const byteCounts = values(TAGS.TileByteCounts) || values(TAGS.StripByteCounts);
|
|
145
|
+
if (!offsets || !segmentWidth || !segmentHeight)
|
|
146
|
+
throw new Error('TIFF: missing image data');
|
|
147
|
+
const segmentsAcross = Math.ceil(width / segmentWidth);
|
|
148
|
+
const segmentsDown = Math.ceil(height / segmentHeight);
|
|
149
|
+
const segmentsPerPlane = segmentsAcross * segmentsDown;
|
|
150
|
+
const segment = (index) => {
|
|
151
|
+
const offset = offsets[index];
|
|
152
|
+
const count = byteCounts ? byteCounts[index] : data.length - offset;
|
|
153
|
+
if (offset === undefined || offset >= data.length)
|
|
154
|
+
throw new Error('TIFF: missing image data');
|
|
155
|
+
return data.subarray(offset, Math.min(data.length, offset + count));
|
|
156
|
+
};
|
|
157
|
+
const pixels = new Uint8Array(width * height * 4);
|
|
158
|
+
if (compression === 7) {
|
|
159
|
+
const tables = tags.has(TAGS.JPEGTables) ? data.subarray(tags.get(TAGS.JPEGTables).offset, tags.get(TAGS.JPEGTables).offset + tags.get(TAGS.JPEGTables).count) : null;
|
|
160
|
+
const transform = photometric === 6 ? 'ycc' : photometric === 2 ? 'rgb' : photometric === 5 ? 'cmyk' : null;
|
|
161
|
+
for (let s = 0; s < segmentsPerPlane; s++) {
|
|
162
|
+
let stream = segment(s);
|
|
163
|
+
if (tables) {
|
|
164
|
+
const joined = new Uint8Array(tables.length - 2 + stream.length - 2);
|
|
165
|
+
joined.set(tables.subarray(0, tables.length - 2));
|
|
166
|
+
joined.set(stream.subarray(2), tables.length - 2);
|
|
167
|
+
stream = joined;
|
|
168
|
+
}
|
|
169
|
+
const decoded = jpeg.decode(stream, { transform });
|
|
170
|
+
blitRGBA(decoded.pixels, decoded.width, decoded.height, pixels, width, height, (s % segmentsAcross) * segmentWidth, (s / segmentsAcross | 0) * segmentHeight);
|
|
171
|
+
}
|
|
172
|
+
return { width, height, pixels, orientation };
|
|
173
|
+
}
|
|
174
|
+
const samplesPerRow = planar ? 1 : samplesPerPixel;
|
|
175
|
+
const planes = planar ? samplesPerPixel : 1;
|
|
176
|
+
const subsampling = photometric === 6 ? values(TAGS.YCbCrSubSampling, [2, 2]) : [1, 1];
|
|
177
|
+
const subsampled = photometric === 6 && (subsampling[0] !== 1 || subsampling[1] !== 1);
|
|
178
|
+
if (subsampled) {
|
|
179
|
+
if (tiled || planar || bps !== 8)
|
|
180
|
+
throw new Error('TIFF: subsampled YCbCr is only supported for 8-bit strips');
|
|
181
|
+
const [h, v] = subsampling;
|
|
182
|
+
const unitsPerRow = Math.ceil(width / h);
|
|
183
|
+
const unitRowBytes = unitsPerRow * (h * v + 2);
|
|
184
|
+
const units = new Uint8Array(Math.ceil(height / v) * unitRowBytes);
|
|
185
|
+
let written = 0;
|
|
186
|
+
for (let s = 0; s < segmentsPerPlane && written < units.length; s++) {
|
|
187
|
+
const expected = Math.min(units.length - written, Math.ceil(segmentHeight / v) * unitRowBytes);
|
|
188
|
+
const raw = await decompressSegment(segment(s), compression, expected);
|
|
189
|
+
units.set(raw.subarray(0, expected), written);
|
|
190
|
+
written += expected;
|
|
191
|
+
}
|
|
192
|
+
ycbcrUnitsToRGBA(units, width, height, h, v, ycbcrConversion(values), pixels);
|
|
193
|
+
return { width, height, pixels, orientation };
|
|
194
|
+
}
|
|
195
|
+
const rowBytes = Math.ceil(width * samplesPerRow * bps / 8);
|
|
196
|
+
const planeBytes = rowBytes * height;
|
|
197
|
+
const raw = new Uint8Array(planeBytes * planes);
|
|
198
|
+
const segmentRowBytes = Math.ceil(segmentWidth * samplesPerRow * bps / 8);
|
|
199
|
+
for (let plane = 0; plane < planes; plane++) {
|
|
200
|
+
for (let s = 0; s < segmentsPerPlane; s++) {
|
|
201
|
+
const sx = (s % segmentsAcross) * segmentWidth;
|
|
202
|
+
const sy = (s / segmentsAcross | 0) * segmentHeight;
|
|
203
|
+
const rows = tiled ? segmentHeight : Math.min(segmentHeight, height - sy);
|
|
204
|
+
const expected = rows * segmentRowBytes;
|
|
205
|
+
const bytes = await decompressSegment(segment(plane * segmentsPerPlane + s), compression, expected);
|
|
206
|
+
if (fillOrder === 2)
|
|
207
|
+
reverseBits(bytes);
|
|
208
|
+
if (predictor === 2)
|
|
209
|
+
undoHorizontalPredictor(bytes, segmentRowBytes, rows, samplesPerRow, bps, little);
|
|
210
|
+
else if (predictor === 3)
|
|
211
|
+
undoFloatingPointPredictor(bytes, segmentRowBytes, rows, samplesPerRow, bps);
|
|
212
|
+
const visibleRows = Math.min(rows, height - sy);
|
|
213
|
+
const startBit = sx * samplesPerRow * bps;
|
|
214
|
+
const copyBits = Math.min(segmentWidth, width - sx) * samplesPerRow * bps;
|
|
215
|
+
for (let row = 0; row < visibleRows; row++) {
|
|
216
|
+
const target = plane * planeBytes + (sy + row) * rowBytes;
|
|
217
|
+
if (startBit % 8 === 0) {
|
|
218
|
+
const start = target + startBit / 8;
|
|
219
|
+
raw.set(bytes.subarray(row * segmentRowBytes, row * segmentRowBytes + Math.ceil(copyBits / 8)).subarray(0, rowBytes - startBit / 8), start);
|
|
220
|
+
}
|
|
221
|
+
else
|
|
222
|
+
copyBitsUnaligned(bytes, row * segmentRowBytes * 8, raw, target * 8 + startBit, copyBits);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const sampleLittle = predictor === 3 ? true : little;
|
|
227
|
+
const readSample = sampleReader(raw, bps, sampleFormat, sampleLittle, sampleFormat === 3 ? floatRange(raw, bps, sampleLittle) : null);
|
|
228
|
+
const sampleAt = planar
|
|
229
|
+
? (x, y, s) => readSample(s * planeBytes + y * rowBytes, x)
|
|
230
|
+
: (x, y, s) => readSample(y * rowBytes, x * samplesPerPixel + s);
|
|
231
|
+
const colormap = photometric === 3 ? values(TAGS.ColorMap, []) : [];
|
|
232
|
+
if (photometric === 3 && colormap.length < 3 << bps)
|
|
233
|
+
throw new Error('TIFF: missing color map');
|
|
234
|
+
const ycc = photometric === 6 ? ycbcrConversion(values) : null;
|
|
235
|
+
for (let y = 0, o = 0; y < height; y++) {
|
|
236
|
+
for (let x = 0; x < width; x++, o += 4) {
|
|
237
|
+
if (photometric === 3) {
|
|
238
|
+
const index = sampleAt(x, y, 0).raw;
|
|
239
|
+
const entries = 1 << bps;
|
|
240
|
+
pixels[o] = colormap[index] >> 8;
|
|
241
|
+
pixels[o + 1] = colormap[entries + index] >> 8;
|
|
242
|
+
pixels[o + 2] = colormap[2 * entries + index] >> 8;
|
|
243
|
+
}
|
|
244
|
+
else if (photometric <= 1) {
|
|
245
|
+
const v = sampleAt(x, y, 0).value;
|
|
246
|
+
pixels[o] = pixels[o + 1] = pixels[o + 2] = photometric === 0 ? 255 - v : v;
|
|
247
|
+
}
|
|
248
|
+
else if (photometric === 2) {
|
|
249
|
+
pixels[o] = sampleAt(x, y, 0).value;
|
|
250
|
+
pixels[o + 1] = sampleAt(x, y, 1).value;
|
|
251
|
+
pixels[o + 2] = sampleAt(x, y, 2).value;
|
|
252
|
+
}
|
|
253
|
+
else if (photometric === 5) {
|
|
254
|
+
const k = sampleAt(x, y, 3).value;
|
|
255
|
+
pixels[o] = cmykToRGB(sampleAt(x, y, 0).value, k);
|
|
256
|
+
pixels[o + 1] = cmykToRGB(sampleAt(x, y, 1).value, k);
|
|
257
|
+
pixels[o + 2] = cmykToRGB(sampleAt(x, y, 2).value, k);
|
|
258
|
+
}
|
|
259
|
+
else
|
|
260
|
+
ycc(sampleAt(x, y, 0).value, sampleAt(x, y, 1).value, sampleAt(x, y, 2).value, pixels, o);
|
|
261
|
+
if (alphaChannel === -1)
|
|
262
|
+
pixels[o + 3] = 0xff;
|
|
263
|
+
else {
|
|
264
|
+
const alpha = pixels[o + 3] = sampleAt(x, y, alphaChannel).value;
|
|
265
|
+
if (alphaType === 1) {
|
|
266
|
+
for (let c = 0; c < 3; c++)
|
|
267
|
+
pixels[o + c] = alpha ? Math.min(255, Math.round(pixels[o + c] * 255 / alpha)) : 0;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return { width, height, pixels, orientation };
|
|
273
|
+
}
|
|
274
|
+
function sampleReader(raw, bps, sampleFormat, little, range) {
|
|
275
|
+
const view = new DataView(raw.buffer, raw.byteOffset, raw.byteLength);
|
|
276
|
+
const result = { raw: 0, value: 0 };
|
|
277
|
+
if (sampleFormat === 3) {
|
|
278
|
+
const [min, max] = range || [0, 1];
|
|
279
|
+
const scale = 255 / (max - min || 1);
|
|
280
|
+
return (rowOffset, n) => {
|
|
281
|
+
const v = bps === 32 ? view.getFloat32(rowOffset + n * 4, little) : view.getFloat64(rowOffset + n * 8, little);
|
|
282
|
+
result.raw = v;
|
|
283
|
+
result.value = v === v ? Math.min(255, Math.max(0, Math.round((v - min) * scale))) : 0;
|
|
284
|
+
return result;
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
const signed = sampleFormat === 2;
|
|
288
|
+
const max = 2 ** bps - 1;
|
|
289
|
+
if (bps === 8) {
|
|
290
|
+
return (rowOffset, n) => {
|
|
291
|
+
result.raw = raw[rowOffset + n];
|
|
292
|
+
result.value = signed ? result.raw ^ 0x80 : result.raw;
|
|
293
|
+
return result;
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
if (bps === 16) {
|
|
297
|
+
return (rowOffset, n) => {
|
|
298
|
+
result.raw = view.getUint16(rowOffset + n * 2, little);
|
|
299
|
+
result.value = (signed ? result.raw ^ 0x8000 : result.raw) >> 8;
|
|
300
|
+
return result;
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
if (bps === 32) {
|
|
304
|
+
return (rowOffset, n) => {
|
|
305
|
+
result.raw = view.getUint32(rowOffset + n * 4, little);
|
|
306
|
+
result.value = (signed ? (result.raw ^ 0x80000000) >>> 0 : result.raw) >>> 24;
|
|
307
|
+
return result;
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
return (rowOffset, n) => {
|
|
311
|
+
let bit = rowOffset * 8 + n * bps;
|
|
312
|
+
let v = 0;
|
|
313
|
+
for (let remaining = bps; remaining > 0;) {
|
|
314
|
+
const byte = raw[bit >> 3];
|
|
315
|
+
const available = 8 - (bit & 7);
|
|
316
|
+
const take = Math.min(available, remaining);
|
|
317
|
+
v = v * (1 << take) + (byte >> available - take & (1 << take) - 1);
|
|
318
|
+
bit += take;
|
|
319
|
+
remaining -= take;
|
|
320
|
+
}
|
|
321
|
+
if (signed)
|
|
322
|
+
v = (v + 2 ** (bps - 1)) % 2 ** bps;
|
|
323
|
+
result.raw = v;
|
|
324
|
+
result.value = bps === 1 ? v * 255 : Math.round(v * 255 / max);
|
|
325
|
+
return result;
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function floatRange(raw, bps, little) {
|
|
329
|
+
const view = new DataView(raw.buffer, raw.byteOffset, raw.byteLength);
|
|
330
|
+
const size = bps / 8;
|
|
331
|
+
let min = Infinity, max = -Infinity;
|
|
332
|
+
for (let o = 0; o + size <= raw.length; o += size) {
|
|
333
|
+
const v = size === 4 ? view.getFloat32(o, little) : view.getFloat64(o, little);
|
|
334
|
+
if (v < min)
|
|
335
|
+
min = v;
|
|
336
|
+
if (v > max)
|
|
337
|
+
max = v;
|
|
338
|
+
}
|
|
339
|
+
if (min >= 0 && max <= 1)
|
|
340
|
+
return [0, 1];
|
|
341
|
+
if (min >= 0 && max <= 255)
|
|
342
|
+
return [0, 255];
|
|
343
|
+
return [min, max];
|
|
344
|
+
}
|
|
345
|
+
async function decompressSegment(bytes, compression, expected) {
|
|
346
|
+
let out;
|
|
347
|
+
if (compression === 5)
|
|
348
|
+
out = lzw(bytes, expected);
|
|
349
|
+
else if (compression === 8 || compression === 32946)
|
|
350
|
+
out = await decompressAsync(bytes, expected);
|
|
351
|
+
else if (compression === 32773)
|
|
352
|
+
out = packBits(bytes, expected);
|
|
353
|
+
else
|
|
354
|
+
out = bytes.slice(0, expected);
|
|
355
|
+
if (out.length >= expected)
|
|
356
|
+
return out.length === expected ? out : out.slice(0, expected);
|
|
357
|
+
const padded = new Uint8Array(expected);
|
|
358
|
+
padded.set(out);
|
|
359
|
+
return padded;
|
|
360
|
+
}
|
|
361
|
+
function lzw(input, expected) {
|
|
362
|
+
const out = new Uint8Array(expected);
|
|
363
|
+
const compat = input[0] === 0 && (input[1] & 1) === 1;
|
|
364
|
+
const prefix = new Uint16Array(4096);
|
|
365
|
+
const suffix = new Uint8Array(4096);
|
|
366
|
+
const first = new Uint8Array(4096);
|
|
367
|
+
const lengths = new Uint16Array(4096);
|
|
368
|
+
for (let i = 0; i < 256; i++) {
|
|
369
|
+
suffix[i] = first[i] = i;
|
|
370
|
+
lengths[i] = 1;
|
|
371
|
+
}
|
|
372
|
+
let codeSize = 9, next = 258, previous = -1;
|
|
373
|
+
let buffer = 0, bits = 0, position = 0, written = 0;
|
|
374
|
+
while (written < expected) {
|
|
375
|
+
while (bits < codeSize) {
|
|
376
|
+
if (position >= input.length)
|
|
377
|
+
return out.subarray(0, written);
|
|
378
|
+
buffer = compat ? buffer | input[position++] << bits : (buffer << 8 | input[position++]) & 0xffffff;
|
|
379
|
+
bits += 8;
|
|
380
|
+
}
|
|
381
|
+
let code;
|
|
382
|
+
if (compat) {
|
|
383
|
+
code = buffer & (1 << codeSize) - 1;
|
|
384
|
+
buffer >>>= codeSize;
|
|
385
|
+
}
|
|
386
|
+
else
|
|
387
|
+
code = buffer >> bits - codeSize & (1 << codeSize) - 1;
|
|
388
|
+
bits -= codeSize;
|
|
389
|
+
if (code === 256) {
|
|
390
|
+
codeSize = 9;
|
|
391
|
+
next = 258;
|
|
392
|
+
previous = -1;
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
if (code === 257)
|
|
396
|
+
break;
|
|
397
|
+
let entry;
|
|
398
|
+
if (previous === -1) {
|
|
399
|
+
if (code > 255)
|
|
400
|
+
break;
|
|
401
|
+
entry = code;
|
|
402
|
+
}
|
|
403
|
+
else if (code < next)
|
|
404
|
+
entry = code;
|
|
405
|
+
else if (code === next)
|
|
406
|
+
entry = previous;
|
|
407
|
+
else
|
|
408
|
+
break;
|
|
409
|
+
const length = lengths[entry];
|
|
410
|
+
let c = entry;
|
|
411
|
+
for (let i = written + length - 1; i >= written; i--) {
|
|
412
|
+
if (i < expected)
|
|
413
|
+
out[i] = suffix[c];
|
|
414
|
+
c = prefix[c];
|
|
415
|
+
}
|
|
416
|
+
written += length;
|
|
417
|
+
if (code === next && written < expected)
|
|
418
|
+
out[written] = first[previous];
|
|
419
|
+
if (code === next)
|
|
420
|
+
written++;
|
|
421
|
+
if (previous !== -1 && next < 4096) {
|
|
422
|
+
prefix[next] = previous;
|
|
423
|
+
suffix[next] = first[code === next ? previous : code];
|
|
424
|
+
first[next] = first[previous];
|
|
425
|
+
lengths[next] = lengths[previous] + 1;
|
|
426
|
+
next++;
|
|
427
|
+
}
|
|
428
|
+
if (next + (compat ? 0 : 1) >= 1 << codeSize && codeSize < 12)
|
|
429
|
+
codeSize++;
|
|
430
|
+
previous = code;
|
|
431
|
+
}
|
|
432
|
+
return out.subarray(0, Math.min(written, expected));
|
|
433
|
+
}
|
|
434
|
+
function packBits(input, expected) {
|
|
435
|
+
const out = new Uint8Array(expected);
|
|
436
|
+
let i = 0, o = 0;
|
|
437
|
+
while (i < input.length && o < expected) {
|
|
438
|
+
const n = input[i++];
|
|
439
|
+
if (n < 128) {
|
|
440
|
+
const count = Math.min(n + 1, expected - o, input.length - i);
|
|
441
|
+
out.set(input.subarray(i, i + count), o);
|
|
442
|
+
i += n + 1;
|
|
443
|
+
o += count;
|
|
444
|
+
}
|
|
445
|
+
else if (n > 128) {
|
|
446
|
+
const count = Math.min(257 - n, expected - o);
|
|
447
|
+
out.fill(input[i++], o, o + count);
|
|
448
|
+
o += count;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return out.subarray(0, o);
|
|
452
|
+
}
|
|
453
|
+
function reverseBits(bytes) {
|
|
454
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
455
|
+
let b = bytes[i];
|
|
456
|
+
b = (b & 0xf0) >> 4 | (b & 0x0f) << 4;
|
|
457
|
+
b = (b & 0xcc) >> 2 | (b & 0x33) << 2;
|
|
458
|
+
bytes[i] = (b & 0xaa) >> 1 | (b & 0x55) << 1;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function undoHorizontalPredictor(bytes, rowBytes, rows, samplesPerPixel, bps, little) {
|
|
462
|
+
if (bps === 8) {
|
|
463
|
+
for (let r = 0; r < rows; r++)
|
|
464
|
+
for (let i = r * rowBytes + samplesPerPixel, end = (r + 1) * rowBytes; i < end; i++)
|
|
465
|
+
bytes[i] = bytes[i] + bytes[i - samplesPerPixel];
|
|
466
|
+
}
|
|
467
|
+
else if (bps === 16 || bps === 32) {
|
|
468
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
469
|
+
const size = bps / 8;
|
|
470
|
+
const get = size === 2 ? (o) => view.getUint16(o, little) : (o) => view.getUint32(o, little);
|
|
471
|
+
const set = size === 2 ? (o, v) => view.setUint16(o, v, little) : (o, v) => view.setUint32(o, v >>> 0, little);
|
|
472
|
+
const stride = samplesPerPixel * size;
|
|
473
|
+
for (let r = 0; r < rows; r++)
|
|
474
|
+
for (let o = r * rowBytes + stride, end = r * rowBytes + Math.floor(rowBytes / size) * size; o < end; o += size)
|
|
475
|
+
set(o, get(o) + get(o - stride));
|
|
476
|
+
}
|
|
477
|
+
else
|
|
478
|
+
throw new Error(`TIFF: horizontal predictor with ${bps}-bit samples is not supported`);
|
|
479
|
+
}
|
|
480
|
+
function undoFloatingPointPredictor(bytes, rowBytes, rows, samplesPerPixel, bps) {
|
|
481
|
+
const size = bps / 8;
|
|
482
|
+
const count = rowBytes / size;
|
|
483
|
+
const tmp = new Uint8Array(rowBytes);
|
|
484
|
+
for (let r = 0; r < rows; r++) {
|
|
485
|
+
const row = bytes.subarray(r * rowBytes, (r + 1) * rowBytes);
|
|
486
|
+
for (let i = samplesPerPixel; i < rowBytes; i++)
|
|
487
|
+
row[i] = row[i] + row[i - samplesPerPixel];
|
|
488
|
+
tmp.set(row);
|
|
489
|
+
for (let n = 0; n < count; n++)
|
|
490
|
+
for (let b = 0; b < size; b++)
|
|
491
|
+
row[n * size + b] = tmp[(size - b - 1) * count + n];
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function copyBitsUnaligned(src, srcBit, dst, dstBit, count) {
|
|
495
|
+
for (let i = 0; i < count; i++, srcBit++, dstBit++) {
|
|
496
|
+
const bit = src[srcBit >> 3] >> 7 - (srcBit & 7) & 1;
|
|
497
|
+
if (bit)
|
|
498
|
+
dst[dstBit >> 3] |= 0x80 >> (dstBit & 7);
|
|
499
|
+
else
|
|
500
|
+
dst[dstBit >> 3] &= ~(0x80 >> (dstBit & 7));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function blitRGBA(src, sw, sh, dst, dw, dh, x0, y0) {
|
|
504
|
+
const w = Math.min(sw, dw - x0);
|
|
505
|
+
for (let y = 0; y < sh && y0 + y < dh; y++)
|
|
506
|
+
dst.set(src.subarray(y * sw * 4, (y * sw + w) * 4), ((y0 + y) * dw + x0) * 4);
|
|
507
|
+
}
|
|
508
|
+
function ycbcrConversion(values) {
|
|
509
|
+
const [lr, lg, lb] = values(TAGS.YCbCrCoefficients, [0.299, 0.587, 0.114]);
|
|
510
|
+
const reference = values(TAGS.ReferenceBlackWhite, [0, 255, 128, 255, 128, 255]);
|
|
511
|
+
const scale = (v, black, white, center) => (v - black) * (center ? 127 : 255) / (white - black || 1);
|
|
512
|
+
return (Y, Cb, Cr, out, o) => {
|
|
513
|
+
const y = scale(Y, reference[0], reference[1], false);
|
|
514
|
+
const cb = scale(Cb, reference[2], reference[3], true);
|
|
515
|
+
const cr = scale(Cr, reference[4], reference[5], true);
|
|
516
|
+
const r = y + cr * (2 - 2 * lr);
|
|
517
|
+
const b = y + cb * (2 - 2 * lb);
|
|
518
|
+
const g = (y - lb * b - lr * r) / lg;
|
|
519
|
+
out[o] = Math.min(255, Math.max(0, Math.round(r)));
|
|
520
|
+
out[o + 1] = Math.min(255, Math.max(0, Math.round(g)));
|
|
521
|
+
out[o + 2] = Math.min(255, Math.max(0, Math.round(b)));
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
function ycbcrUnitsToRGBA(units, width, height, h, v, convert, pixels) {
|
|
525
|
+
const unitsPerRow = Math.ceil(width / h);
|
|
526
|
+
const unitSize = h * v + 2;
|
|
527
|
+
for (let uy = 0; uy < Math.ceil(height / v); uy++)
|
|
528
|
+
for (let ux = 0; ux < unitsPerRow; ux++) {
|
|
529
|
+
const u = (uy * unitsPerRow + ux) * unitSize;
|
|
530
|
+
const cb = units[u + h * v], cr = units[u + h * v + 1];
|
|
531
|
+
for (let j = 0; j < v; j++)
|
|
532
|
+
for (let i = 0; i < h; i++) {
|
|
533
|
+
const x = ux * h + i, y = uy * v + j;
|
|
534
|
+
if (x >= width || y >= height)
|
|
535
|
+
continue;
|
|
536
|
+
const o = (y * width + x) * 4;
|
|
537
|
+
convert(units[u + j * h + i], cb, cr, pixels, o);
|
|
538
|
+
pixels[o + 3] = 0xff;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
function cmykToRGB(c, k) {
|
|
543
|
+
const t = (255 - c) * k + 128;
|
|
544
|
+
const v = 255 - (c + ((t >> 8) + t >> 8));
|
|
545
|
+
return v < 0 ? 0 : v;
|
|
546
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* VP8 constant tables, extracted from RFC 6386 ("VP8 Data Format and Decoding Guide", sections 9.6, 11.5, 13.4,
|
|
3
|
+
* 13.5 and 14.1). Copyright (c) 2010, 2011 Google Inc., BSD license (see THIRD_PARTY_NOTICES.md)
|
|
4
|
+
*/
|
|
5
|
+
export declare const KF_BMODE_PROBS: Uint8Array<ArrayBuffer>;
|
|
6
|
+
export declare const COEFF_UPDATE_PROBS: Uint8Array<ArrayBuffer>;
|
|
7
|
+
export declare const DEFAULT_COEFF_PROBS: Uint8Array<ArrayBuffer>;
|
|
8
|
+
export declare const DC_QLOOKUP: Uint8Array<ArrayBuffer>;
|
|
9
|
+
export declare const AC_QLOOKUP: Int16Array<ArrayBuffer>;
|
|
10
|
+
export declare const PCAT: Uint8Array<ArrayBuffer>[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* VP8 constant tables, extracted from RFC 6386 ("VP8 Data Format and Decoding Guide", sections 9.6, 11.5, 13.4,
|
|
3
|
+
* 13.5 and 14.1). Copyright (c) 2010, 2011 Google Inc., BSD license (see THIRD_PARTY_NOTICES.md)
|
|
4
|
+
*/
|
|
5
|
+
export const KF_BMODE_PROBS = Uint8Array.of(231, 120, 48, 89, 115, 113, 120, 152, 112, 152, 179, 64, 126, 170, 118, 46, 70, 95, 175, 69, 143, 80, 85, 82, 72, 155, 103, 56, 58, 10, 171, 218, 189, 17, 13, 152, 144, 71, 10, 38, 171, 213, 144, 34, 26, 114, 26, 17, 163, 44, 195, 21, 10, 173, 121, 24, 80, 195, 26, 62, 44, 64, 85, 170, 46, 55, 19, 136, 160, 33, 206, 71, 63, 20, 8, 114, 114, 208, 12, 9, 226, 81, 40, 11, 96, 182, 84, 29, 16, 36, 134, 183, 89, 137, 98, 101, 106, 165, 148, 72, 187, 100, 130, 157, 111, 32, 75, 80, 66, 102, 167, 99, 74, 62, 40, 234, 128, 41, 53, 9, 178, 241, 141, 26, 8, 107, 104, 79, 12, 27, 217, 255, 87, 17, 7, 74, 43, 26, 146, 73, 166, 49, 23, 157, 65, 38, 105, 160, 51, 52, 31, 115, 128, 87, 68, 71, 44, 114, 51, 15, 186, 23, 47, 41, 14, 110, 182, 183, 21, 17, 194, 66, 45, 25, 102, 197, 189, 23, 18, 22, 88, 88, 147, 150, 42, 46, 45, 196, 205, 43, 97, 183, 117, 85, 38, 35, 179, 61, 39, 53, 200, 87, 26, 21, 43, 232, 171, 56, 34, 51, 104, 114, 102, 29, 93, 77, 107, 54, 32, 26, 51, 1, 81, 43, 31, 39, 28, 85, 171, 58, 165, 90, 98, 64, 34, 22, 116, 206, 23, 34, 43, 166, 73, 68, 25, 106, 22, 64, 171, 36, 225, 114, 34, 19, 21, 102, 132, 188, 16, 76, 124, 62, 18, 78, 95, 85, 57, 50, 48, 51, 193, 101, 35, 159, 215, 111, 89, 46, 111, 60, 148, 31, 172, 219, 228, 21, 18, 111, 112, 113, 77, 85, 179, 255, 38, 120, 114, 40, 42, 1, 196, 245, 209, 10, 25, 109, 100, 80, 8, 43, 154, 1, 51, 26, 71, 88, 43, 29, 140, 166, 213, 37, 43, 154, 61, 63, 30, 155, 67, 45, 68, 1, 209, 142, 78, 78, 16, 255, 128, 34, 197, 171, 41, 40, 5, 102, 211, 183, 4, 1, 221, 51, 50, 17, 168, 209, 192, 23, 25, 82, 125, 98, 42, 88, 104, 85, 117, 175, 82, 95, 84, 53, 89, 128, 100, 113, 101, 45, 75, 79, 123, 47, 51, 128, 81, 171, 1, 57, 17, 5, 71, 102, 57, 53, 41, 49, 115, 21, 2, 10, 102, 255, 166, 23, 6, 38, 33, 13, 121, 57, 73, 26, 1, 85, 41, 10, 67, 138, 77, 110, 90, 47, 114, 101, 29, 16, 10, 85, 128, 101, 196, 26, 57, 18, 10, 102, 102, 213, 34, 20, 43, 117, 20, 15, 36, 163, 128, 68, 1, 26, 138, 31, 36, 171, 27, 166, 38, 44, 229, 67, 87, 58, 169, 82, 115, 26, 59, 179, 63, 59, 90, 180, 59, 166, 93, 73, 154, 40, 40, 21, 116, 143, 209, 34, 39, 175, 57, 46, 22, 24, 128, 1, 54, 17, 37, 47, 15, 16, 183, 34, 223, 49, 45, 183, 46, 17, 33, 183, 6, 98, 15, 32, 183, 65, 32, 73, 115, 28, 128, 23, 128, 205, 40, 3, 9, 115, 51, 192, 18, 6, 223, 87, 37, 9, 115, 59, 77, 64, 21, 47, 104, 55, 44, 218, 9, 54, 53, 130, 226, 64, 90, 70, 205, 40, 41, 23, 26, 57, 54, 57, 112, 184, 5, 41, 38, 166, 213, 30, 34, 26, 133, 152, 116, 10, 32, 134, 75, 32, 12, 51, 192, 255, 160, 43, 51, 39, 19, 53, 221, 26, 114, 32, 73, 255, 31, 9, 65, 234, 2, 15, 1, 118, 73, 88, 31, 35, 67, 102, 85, 55, 186, 85, 56, 21, 23, 111, 59, 205, 45, 37, 192, 55, 38, 70, 124, 73, 102, 1, 34, 98, 102, 61, 71, 37, 34, 53, 31, 243, 192, 69, 60, 71, 38, 73, 119, 28, 222, 37, 68, 45, 128, 34, 1, 47, 11, 245, 171, 62, 17, 19, 70, 146, 85, 55, 62, 70, 75, 15, 9, 9, 64, 255, 184, 119, 16, 37, 43, 37, 154, 100, 163, 85, 160, 1, 63, 9, 92, 136, 28, 64, 32, 201, 85, 86, 6, 28, 5, 64, 255, 25, 248, 1, 56, 8, 17, 132, 137, 255, 55, 116, 128, 58, 15, 20, 82, 135, 57, 26, 121, 40, 164, 50, 31, 137, 154, 133, 25, 35, 218, 51, 103, 44, 131, 131, 123, 31, 6, 158, 86, 40, 64, 135, 148, 224, 45, 183, 128, 22, 26, 17, 131, 240, 154, 14, 1, 209, 83, 12, 13, 54, 192, 255, 68, 47, 28, 45, 16, 21, 91, 64, 222, 7, 1, 197, 56, 21, 39, 155, 60, 138, 23, 102, 213, 85, 26, 85, 85, 128, 128, 32, 146, 171, 18, 11, 7, 63, 144, 171, 4, 4, 246, 35, 27, 10, 146, 174, 171, 12, 26, 128, 190, 80, 35, 99, 180, 80, 126, 54, 45, 85, 126, 47, 87, 176, 51, 41, 20, 32, 101, 75, 128, 139, 118, 146, 116, 128, 85, 56, 41, 15, 176, 236, 85, 37, 9, 62, 146, 36, 19, 30, 171, 255, 97, 27, 20, 71, 30, 17, 119, 118, 255, 17, 18, 138, 101, 38, 60, 138, 55, 70, 43, 26, 142, 138, 45, 61, 62, 219, 1, 81, 188, 64, 32, 41, 20, 117, 151, 142, 20, 21, 163, 112, 19, 12, 61, 195, 128, 48, 4, 24);
|
|
6
|
+
export const COEFF_UPDATE_PROBS = Uint8Array.of(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 176, 246, 255, 255, 255, 255, 255, 255, 255, 255, 255, 223, 241, 252, 255, 255, 255, 255, 255, 255, 255, 255, 249, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 244, 252, 255, 255, 255, 255, 255, 255, 255, 255, 234, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 246, 254, 255, 255, 255, 255, 255, 255, 255, 255, 239, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255, 251, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 251, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 253, 255, 254, 255, 255, 255, 255, 255, 255, 250, 255, 254, 255, 254, 255, 255, 255, 255, 255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 217, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 225, 252, 241, 253, 255, 255, 254, 255, 255, 255, 255, 234, 250, 241, 250, 253, 255, 253, 254, 255, 255, 255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 223, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 238, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255, 249, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 247, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 252, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255, 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 186, 251, 250, 255, 255, 255, 255, 255, 255, 255, 255, 234, 251, 244, 254, 255, 255, 255, 255, 255, 255, 255, 251, 251, 243, 253, 254, 255, 254, 255, 255, 255, 255, 255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 236, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 251, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 248, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 250, 254, 252, 254, 255, 255, 255, 255, 255, 255, 255, 248, 254, 249, 253, 255, 255, 255, 255, 255, 255, 255, 255, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255, 246, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255, 252, 254, 251, 254, 254, 255, 255, 255, 255, 255, 255, 255, 254, 252, 255, 255, 255, 255, 255, 255, 255, 255, 248, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255, 253, 255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255, 245, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255, 253, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 251, 253, 255, 255, 255, 255, 255, 255, 255, 255, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 252, 255, 255, 255, 255, 255, 255, 255, 255, 255, 249, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255);
|
|
7
|
+
export const DEFAULT_COEFF_PROBS = Uint8Array.of(128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 253, 136, 254, 255, 228, 219, 128, 128, 128, 128, 128, 189, 129, 242, 255, 227, 213, 255, 219, 128, 128, 128, 106, 126, 227, 252, 214, 209, 255, 255, 128, 128, 128, 1, 98, 248, 255, 236, 226, 255, 255, 128, 128, 128, 181, 133, 238, 254, 221, 234, 255, 154, 128, 128, 128, 78, 134, 202, 247, 198, 180, 255, 219, 128, 128, 128, 1, 185, 249, 255, 243, 255, 128, 128, 128, 128, 128, 184, 150, 247, 255, 236, 224, 128, 128, 128, 128, 128, 77, 110, 216, 255, 236, 230, 128, 128, 128, 128, 128, 1, 101, 251, 255, 241, 255, 128, 128, 128, 128, 128, 170, 139, 241, 252, 236, 209, 255, 255, 128, 128, 128, 37, 116, 196, 243, 228, 255, 255, 255, 128, 128, 128, 1, 204, 254, 255, 245, 255, 128, 128, 128, 128, 128, 207, 160, 250, 255, 238, 128, 128, 128, 128, 128, 128, 102, 103, 231, 255, 211, 171, 128, 128, 128, 128, 128, 1, 152, 252, 255, 240, 255, 128, 128, 128, 128, 128, 177, 135, 243, 255, 234, 225, 128, 128, 128, 128, 128, 80, 129, 211, 255, 194, 224, 128, 128, 128, 128, 128, 1, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128, 246, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 198, 35, 237, 223, 193, 187, 162, 160, 145, 155, 62, 131, 45, 198, 221, 172, 176, 220, 157, 252, 221, 1, 68, 47, 146, 208, 149, 167, 221, 162, 255, 223, 128, 1, 149, 241, 255, 221, 224, 255, 255, 128, 128, 128, 184, 141, 234, 253, 222, 220, 255, 199, 128, 128, 128, 81, 99, 181, 242, 176, 190, 249, 202, 255, 255, 128, 1, 129, 232, 253, 214, 197, 242, 196, 255, 255, 128, 99, 121, 210, 250, 201, 198, 255, 202, 128, 128, 128, 23, 91, 163, 242, 170, 187, 247, 210, 255, 255, 128, 1, 200, 246, 255, 234, 255, 128, 128, 128, 128, 128, 109, 178, 241, 255, 231, 245, 255, 255, 128, 128, 128, 44, 130, 201, 253, 205, 192, 255, 255, 128, 128, 128, 1, 132, 239, 251, 219, 209, 255, 165, 128, 128, 128, 94, 136, 225, 251, 218, 190, 255, 255, 128, 128, 128, 22, 100, 174, 245, 186, 161, 255, 199, 128, 128, 128, 1, 182, 249, 255, 232, 235, 128, 128, 128, 128, 128, 124, 143, 241, 255, 227, 234, 128, 128, 128, 128, 128, 35, 77, 181, 251, 193, 211, 255, 205, 128, 128, 128, 1, 157, 247, 255, 236, 231, 255, 255, 128, 128, 128, 121, 141, 235, 255, 225, 227, 255, 255, 128, 128, 128, 45, 99, 188, 251, 195, 217, 255, 224, 128, 128, 128, 1, 1, 251, 255, 213, 255, 128, 128, 128, 128, 128, 203, 1, 248, 255, 255, 128, 128, 128, 128, 128, 128, 137, 1, 177, 255, 224, 255, 128, 128, 128, 128, 128, 253, 9, 248, 251, 207, 208, 255, 192, 128, 128, 128, 175, 13, 224, 243, 193, 185, 249, 198, 255, 255, 128, 73, 17, 171, 221, 161, 179, 236, 167, 255, 234, 128, 1, 95, 247, 253, 212, 183, 255, 255, 128, 128, 128, 239, 90, 244, 250, 211, 209, 255, 255, 128, 128, 128, 155, 77, 195, 248, 188, 195, 255, 255, 128, 128, 128, 1, 24, 239, 251, 218, 219, 255, 205, 128, 128, 128, 201, 51, 219, 255, 196, 186, 128, 128, 128, 128, 128, 69, 46, 190, 239, 201, 218, 255, 228, 128, 128, 128, 1, 191, 251, 255, 255, 128, 128, 128, 128, 128, 128, 223, 165, 249, 255, 213, 255, 128, 128, 128, 128, 128, 141, 124, 248, 255, 255, 128, 128, 128, 128, 128, 128, 1, 16, 248, 255, 255, 128, 128, 128, 128, 128, 128, 190, 36, 230, 255, 236, 255, 128, 128, 128, 128, 128, 149, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128, 1, 226, 255, 128, 128, 128, 128, 128, 128, 128, 128, 247, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128, 240, 128, 255, 128, 128, 128, 128, 128, 128, 128, 128, 1, 134, 252, 255, 255, 128, 128, 128, 128, 128, 128, 213, 62, 250, 255, 255, 128, 128, 128, 128, 128, 128, 55, 93, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 202, 24, 213, 235, 186, 191, 220, 160, 240, 175, 255, 126, 38, 182, 232, 169, 184, 228, 174, 255, 187, 128, 61, 46, 138, 219, 151, 178, 240, 170, 255, 216, 128, 1, 112, 230, 250, 199, 191, 247, 159, 255, 255, 128, 166, 109, 228, 252, 211, 215, 255, 174, 128, 128, 128, 39, 77, 162, 232, 172, 180, 245, 178, 255, 255, 128, 1, 52, 220, 246, 198, 199, 249, 220, 255, 255, 128, 124, 74, 191, 243, 183, 193, 250, 221, 255, 255, 128, 24, 71, 130, 219, 154, 170, 243, 182, 255, 255, 128, 1, 182, 225, 249, 219, 240, 255, 224, 128, 128, 128, 149, 150, 226, 252, 216, 205, 255, 171, 128, 128, 128, 28, 108, 170, 242, 183, 194, 254, 223, 255, 255, 128, 1, 81, 230, 252, 204, 203, 255, 192, 128, 128, 128, 123, 102, 209, 247, 188, 196, 255, 233, 128, 128, 128, 20, 95, 153, 243, 164, 173, 255, 203, 128, 128, 128, 1, 222, 248, 255, 216, 213, 128, 128, 128, 128, 128, 168, 175, 246, 252, 235, 205, 255, 255, 128, 128, 128, 47, 116, 215, 255, 211, 212, 255, 255, 128, 128, 128, 1, 121, 236, 253, 212, 214, 255, 255, 128, 128, 128, 141, 84, 213, 252, 201, 202, 255, 219, 128, 128, 128, 42, 80, 160, 240, 162, 185, 255, 205, 128, 128, 128, 1, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128, 244, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128, 238, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128);
|
|
8
|
+
export const DC_QLOOKUP = Uint8Array.of(4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 17, 18, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 91, 93, 95, 96, 98, 100, 101, 102, 104, 106, 108, 110, 112, 114, 116, 118, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 143, 145, 148, 151, 154, 157);
|
|
9
|
+
export const AC_QLOOKUP = Int16Array.of(4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 149, 152, 155, 158, 161, 164, 167, 170, 173, 177, 181, 185, 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 229, 234, 239, 245, 249, 254, 259, 264, 269, 274, 279, 284);
|
|
10
|
+
export const PCAT = [
|
|
11
|
+
Uint8Array.of(159),
|
|
12
|
+
Uint8Array.of(165, 145),
|
|
13
|
+
Uint8Array.of(173, 148, 140),
|
|
14
|
+
Uint8Array.of(176, 155, 140, 135),
|
|
15
|
+
Uint8Array.of(180, 157, 141, 134, 130),
|
|
16
|
+
Uint8Array.of(254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129)
|
|
17
|
+
];
|