@woosh/meep-engine 2.126.75 → 2.127.1
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/build/bundle-worker-image-decoder.js +1 -1
- package/package.json +1 -1
- package/src/core/binary/platform_compute_endianness.d.ts.map +1 -1
- package/src/core/binary/platform_compute_endianness.js +5 -1
- package/src/core/color/hunt/xyz_to_hpe.d.ts +7 -0
- package/src/core/color/hunt/xyz_to_hpe.d.ts.map +1 -0
- package/src/core/color/hunt/xyz_to_hpe.js +15 -0
- package/src/core/color/xyz/rgb_to_xyz.d.ts +2 -0
- package/src/core/color/xyz/rgb_to_xyz.d.ts.map +1 -1
- package/src/core/color/xyz/rgb_to_xyz.js +2 -0
- package/src/core/color/xyz/xyz_to_rgb.d.ts +2 -0
- package/src/core/color/xyz/xyz_to_rgb.d.ts.map +1 -1
- package/src/core/color/xyz/xyz_to_rgb.js +2 -0
- package/src/core/math/idct_1d.d.ts +14 -0
- package/src/core/math/idct_1d.d.ts.map +1 -0
- package/src/core/math/idct_1d.js +69 -0
- package/src/core/math/idct_2d.d.ts +11 -0
- package/src/core/math/idct_2d.d.ts.map +1 -0
- package/src/core/math/idct_2d.js +22 -0
- package/src/core/model/DebouncedObservedBoolean.d.ts +1 -1
- package/src/core/model/DebouncedObservedBoolean.d.ts.map +1 -1
- package/src/core/model/object/objectKeyByValue.d.ts.map +1 -1
- package/src/core/model/object/objectKeyByValue.js +4 -0
- package/src/engine/asset/Asset.d.ts.map +1 -1
- package/src/engine/asset/Asset.js +2 -5
- package/src/engine/asset/AssetTransformer.js +1 -1
- package/src/engine/asset/loaders/image/codec/NativeImageDecoder.d.ts +20 -1
- package/src/engine/asset/loaders/image/codec/NativeImageDecoder.d.ts.map +1 -1
- package/src/engine/asset/loaders/image/codec/NativeImageDecoder.js +56 -13
- package/src/engine/asset/loaders/image/jpeg/JpegFrame.d.ts +42 -0
- package/src/engine/asset/loaders/image/jpeg/JpegFrame.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/jpeg/JpegFrame.js +45 -0
- package/src/engine/asset/loaders/image/jpeg/JpegFrameComponent.d.ts +42 -0
- package/src/engine/asset/loaders/image/jpeg/JpegFrameComponent.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/jpeg/JpegFrameComponent.js +48 -0
- package/src/engine/asset/loaders/image/jpeg/JpegImage.d.ts +60 -0
- package/src/engine/asset/loaders/image/jpeg/JpegImage.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/jpeg/JpegImage.js +624 -0
- package/src/engine/asset/loaders/image/jpeg/NOTES.md +3 -0
- package/src/engine/asset/loaders/image/jpeg/buildComponentData.d.ts +7 -0
- package/src/engine/asset/loaders/image/jpeg/buildComponentData.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/jpeg/buildComponentData.js +59 -0
- package/src/engine/asset/loaders/image/jpeg/buildHuffmanTable.d.ts +8 -0
- package/src/engine/asset/loaders/image/jpeg/buildHuffmanTable.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/jpeg/buildHuffmanTable.js +46 -0
- package/src/engine/asset/loaders/image/jpeg/decodeScan.d.ts +17 -0
- package/src/engine/asset/loaders/image/jpeg/decodeScan.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/jpeg/decodeScan.js +351 -0
- package/src/engine/asset/loaders/image/jpeg/idct8x8_fixed.d.ts +23 -0
- package/src/engine/asset/loaders/image/jpeg/idct8x8_fixed.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/jpeg/idct8x8_fixed.js +214 -0
- package/src/engine/asset/loaders/image/jpeg/idct8x8_float.d.ts +9 -0
- package/src/engine/asset/loaders/image/jpeg/idct8x8_float.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/jpeg/idct8x8_float.js +32 -0
- package/src/engine/asset/loaders/image/jpeg/jpeg_decode.d.ts +13 -0
- package/src/engine/asset/loaders/image/jpeg/jpeg_decode.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/jpeg/jpeg_decode.js +41 -0
- package/src/engine/asset/loaders/image/png/PNG.d.ts +18 -11
- package/src/engine/asset/loaders/image/png/PNG.d.ts.map +1 -1
- package/src/engine/asset/loaders/image/png/PNG.js +17 -22
- package/src/engine/asset/loaders/image/png/PNGReader.d.ts +71 -10
- package/src/engine/asset/loaders/image/png/PNGReader.d.ts.map +1 -1
- package/src/engine/asset/loaders/image/png/PNGReader.js +422 -101
- package/src/engine/ecs/EntityComponentDataset.d.ts.map +1 -1
- package/src/engine/ecs/EntityComponentDataset.js +2 -1
- package/src/engine/graphics/geometry/AttributeSpec.d.ts.map +1 -1
- package/src/engine/graphics/geometry/AttributeSpec.js +2 -1
- package/src/engine/graphics/render/frame_graph/RenderGraph.d.ts +50 -7
- package/src/engine/graphics/render/frame_graph/RenderGraph.d.ts.map +1 -1
- package/src/engine/graphics/render/frame_graph/RenderGraph.js +108 -8
- package/src/engine/graphics/render/frame_graph/RenderPassBuilder.d.ts +44 -0
- package/src/engine/graphics/render/frame_graph/RenderPassBuilder.d.ts.map +1 -0
- package/src/engine/graphics/render/frame_graph/{RenderGraphBuilder.js → RenderPassBuilder.js} +25 -6
- package/src/engine/graphics/render/frame_graph/RenderPassNode.d.ts +1 -0
- package/src/engine/graphics/render/frame_graph/RenderPassNode.d.ts.map +1 -1
- package/src/engine/graphics/render/frame_graph/RenderPassNode.js +1 -0
- package/src/engine/graphics/render/frame_graph/ResourceEntry.d.ts +8 -0
- package/src/engine/graphics/render/frame_graph/ResourceEntry.d.ts.map +1 -1
- package/src/engine/graphics/render/frame_graph/ResourceEntry.js +8 -0
- package/src/engine/graphics/texture/sampler/downloadSamplerAsPNG.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/downloadSamplerAsPNG.js +6 -1
- package/src/engine/graphics/texture/sampler/sampler2d_compute_texel_value_conversion_scale_to_uint8.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/sampler2d_compute_texel_value_conversion_scale_to_uint8.js +7 -2
- package/src/engine/graphics/texture/sampler/sampler2d_to_html_canvas.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/sampler2d_to_html_canvas.js +12 -1
- package/src/engine/logging/elastic/ElasticSearchLogger.d.ts +1 -1
- package/src/engine/logging/elastic/ElasticSearchLogger.d.ts.map +1 -1
- package/src/engine/graphics/render/frame_graph/RenderGraphBuilder.d.ts +0 -33
- package/src/engine/graphics/render/frame_graph/RenderGraphBuilder.d.ts.map +0 -1
- package/src/engine/graphics/render/frame_graph/RenderPass.d.ts +0 -50
- package/src/engine/graphics/render/frame_graph/RenderPass.d.ts.map +0 -1
- package/src/engine/graphics/render/frame_graph/RenderPass.js +0 -74
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { idct8x8_float } from "./idct8x8_float.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {JpegFrameComponent} component
|
|
6
|
+
* @return {Uint8Array[]} lines
|
|
7
|
+
*/
|
|
8
|
+
export function buildComponentData(component) {
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @type {Uint8Array[]}
|
|
12
|
+
*/
|
|
13
|
+
const lines = [];
|
|
14
|
+
|
|
15
|
+
const blocks_per_line = component.blocksPerLine;
|
|
16
|
+
const blocks_per_column = component.blocksPerColumn;
|
|
17
|
+
const samples_per_line = blocks_per_line << 3;
|
|
18
|
+
|
|
19
|
+
// Only 1 used per invocation of this function and garbage collected after invocation, so no need to account for its memory footprint.
|
|
20
|
+
const r = new Uint8Array(64);
|
|
21
|
+
|
|
22
|
+
let i, j;
|
|
23
|
+
for (let block_row = 0; block_row < blocks_per_column; block_row++) {
|
|
24
|
+
const scan_line = block_row << 3;
|
|
25
|
+
|
|
26
|
+
// align memory
|
|
27
|
+
const lines_buffer = new ArrayBuffer(samples_per_line * 8);
|
|
28
|
+
|
|
29
|
+
for (i = 0; i < 8; i++) {
|
|
30
|
+
const line = new Uint8Array(lines_buffer, i * samples_per_line, samples_per_line);
|
|
31
|
+
|
|
32
|
+
lines.push(line);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
for (let block_col = 0; block_col < blocks_per_line; block_col++) {
|
|
36
|
+
|
|
37
|
+
idct8x8_float(
|
|
38
|
+
component.quantizationTable,
|
|
39
|
+
component.blocks[block_row][block_col],
|
|
40
|
+
r,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
let offset = 0;
|
|
44
|
+
let sample = block_col << 3;
|
|
45
|
+
|
|
46
|
+
for (j = 0; j < 8; j++) {
|
|
47
|
+
|
|
48
|
+
const line = lines[scan_line + j];
|
|
49
|
+
|
|
50
|
+
for (i = 0; i < 8; i++) {
|
|
51
|
+
line[sample + i] = r[offset++];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return lines;
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildHuffmanTable.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/asset/loaders/image/jpeg/buildHuffmanTable.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,+CAJW,UAAU,UACV,UAAU,GACT,EAAE,CAyCb"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {Uint8Array} codeLengths
|
|
4
|
+
* @param {Uint8Array} values
|
|
5
|
+
* @return {[]}
|
|
6
|
+
*/
|
|
7
|
+
export function buildHuffmanTable(codeLengths, values) {
|
|
8
|
+
let k = 0;
|
|
9
|
+
const code = [];
|
|
10
|
+
let i, j, length = 16;
|
|
11
|
+
|
|
12
|
+
while (length > 0 && !codeLengths[length - 1]) {
|
|
13
|
+
length--;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
code.push({ children: [], index: 0 });
|
|
17
|
+
let p = code[0], q;
|
|
18
|
+
for (i = 0; i < length; i++) {
|
|
19
|
+
|
|
20
|
+
for (j = 0; j < codeLengths[i]; j++) {
|
|
21
|
+
p = code.pop();
|
|
22
|
+
p.children[p.index] = values[k];
|
|
23
|
+
while (p.index > 0) {
|
|
24
|
+
if (code.length === 0)
|
|
25
|
+
throw new Error('Could not recreate Huffman Table');
|
|
26
|
+
p = code.pop();
|
|
27
|
+
}
|
|
28
|
+
p.index++;
|
|
29
|
+
code.push(p);
|
|
30
|
+
while (code.length <= i) {
|
|
31
|
+
code.push(q = { children: [], index: 0 });
|
|
32
|
+
p.children[p.index] = q.children;
|
|
33
|
+
p = q;
|
|
34
|
+
}
|
|
35
|
+
k++;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (i + 1 < length) {
|
|
39
|
+
// p here points to last code
|
|
40
|
+
code.push(q = { children: [], index: 0 });
|
|
41
|
+
p.children[p.index] = q.children;
|
|
42
|
+
p = q;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return code[0].children;
|
|
46
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {Uint8Array} data
|
|
4
|
+
* @param {number} offset
|
|
5
|
+
* @param {JpegFrame} frame
|
|
6
|
+
* @param {JpegFrameComponent[]} components
|
|
7
|
+
* @param {number} resetInterval
|
|
8
|
+
* @param {number} spectralStart
|
|
9
|
+
* @param {number} spectralEnd
|
|
10
|
+
* @param {number} successivePrev
|
|
11
|
+
* @param {number} successive
|
|
12
|
+
* @param {boolean} [tolerantDecoding]
|
|
13
|
+
* @return {number}
|
|
14
|
+
*/
|
|
15
|
+
export function decodeScan(data: Uint8Array, offset: number, frame: JpegFrame, components: JpegFrameComponent[], resetInterval: number, spectralStart: number, spectralEnd: number, successivePrev: number, successive: number, tolerantDecoding?: boolean): number;
|
|
16
|
+
export const dctZigZag: Int32Array;
|
|
17
|
+
//# sourceMappingURL=decodeScan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeScan.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/asset/loaders/image/jpeg/decodeScan.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;GAaG;AACH,iCAZW,UAAU,UACV,MAAM,gCAEN,oBAAoB,iBACpB,MAAM,iBACN,MAAM,eACN,MAAM,kBACN,MAAM,cACN,MAAM,qBACN,OAAO,GACN,MAAM,CAgUjB;AA9VD,mCAgBG"}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
export const dctZigZag = new Int32Array([
|
|
2
|
+
0,
|
|
3
|
+
1, 8,
|
|
4
|
+
16, 9, 2,
|
|
5
|
+
3, 10, 17, 24,
|
|
6
|
+
32, 25, 18, 11, 4,
|
|
7
|
+
5, 12, 19, 26, 33, 40,
|
|
8
|
+
48, 41, 34, 27, 20, 13, 6,
|
|
9
|
+
7, 14, 21, 28, 35, 42, 49, 56,
|
|
10
|
+
57, 50, 43, 36, 29, 22, 15,
|
|
11
|
+
23, 30, 37, 44, 51, 58,
|
|
12
|
+
59, 52, 45, 38, 31,
|
|
13
|
+
39, 46, 53, 60,
|
|
14
|
+
61, 54, 47,
|
|
15
|
+
55, 62,
|
|
16
|
+
63
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param {Uint8Array} data
|
|
22
|
+
* @param {number} offset
|
|
23
|
+
* @param {JpegFrame} frame
|
|
24
|
+
* @param {JpegFrameComponent[]} components
|
|
25
|
+
* @param {number} resetInterval
|
|
26
|
+
* @param {number} spectralStart
|
|
27
|
+
* @param {number} spectralEnd
|
|
28
|
+
* @param {number} successivePrev
|
|
29
|
+
* @param {number} successive
|
|
30
|
+
* @param {boolean} [tolerantDecoding]
|
|
31
|
+
* @return {number}
|
|
32
|
+
*/
|
|
33
|
+
export function decodeScan(
|
|
34
|
+
data,
|
|
35
|
+
offset,
|
|
36
|
+
frame,
|
|
37
|
+
components,
|
|
38
|
+
resetInterval,
|
|
39
|
+
spectralStart,
|
|
40
|
+
spectralEnd,
|
|
41
|
+
successivePrev,
|
|
42
|
+
successive,
|
|
43
|
+
tolerantDecoding = false
|
|
44
|
+
) {
|
|
45
|
+
const mcusPerLine = frame.mcusPerLine;
|
|
46
|
+
const progressive = frame.progressive;
|
|
47
|
+
|
|
48
|
+
const startOffset = offset;
|
|
49
|
+
let bitsData = 0, bitsCount = 0;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @return {number}
|
|
54
|
+
*/
|
|
55
|
+
function readBit() {
|
|
56
|
+
|
|
57
|
+
if (bitsCount > 0) {
|
|
58
|
+
bitsCount--;
|
|
59
|
+
return (bitsData >> bitsCount) & 1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
bitsData = data[offset++];
|
|
63
|
+
|
|
64
|
+
if (bitsData === 0xFF) {
|
|
65
|
+
const nextByte = data[offset++];
|
|
66
|
+
|
|
67
|
+
if (nextByte) {
|
|
68
|
+
throw new Error("unexpected marker: " + ((bitsData << 8) | nextByte).toString(16));
|
|
69
|
+
}
|
|
70
|
+
// unstuff 0
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
bitsCount = 7;
|
|
74
|
+
|
|
75
|
+
return bitsData >>> 7;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function decodeHuffman(tree) {
|
|
79
|
+
let node = tree, bit;
|
|
80
|
+
while ((bit = readBit()) !== null) {
|
|
81
|
+
node = node[bit];
|
|
82
|
+
if (typeof node === 'number')
|
|
83
|
+
return node;
|
|
84
|
+
if (typeof node !== 'object')
|
|
85
|
+
throw new Error("invalid huffman sequence");
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function receive(length) {
|
|
91
|
+
let n = 0;
|
|
92
|
+
while (length > 0) {
|
|
93
|
+
const bit = readBit();
|
|
94
|
+
if (bit === null) return;
|
|
95
|
+
n = (n << 1) | bit;
|
|
96
|
+
length--;
|
|
97
|
+
}
|
|
98
|
+
return n;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function receiveAndExtend(length) {
|
|
102
|
+
const n = receive(length);
|
|
103
|
+
if (n >= 1 << (length - 1))
|
|
104
|
+
return n;
|
|
105
|
+
return n + (-1 << length) + 1;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
*
|
|
110
|
+
* @param {JpegFrameComponent} component
|
|
111
|
+
* @param {number[]} zz
|
|
112
|
+
*/
|
|
113
|
+
function decodeBaseline(component, zz) {
|
|
114
|
+
const t = decodeHuffman(component.huffmanTableDC);
|
|
115
|
+
const diff = t === 0 ? 0 : receiveAndExtend(t);
|
|
116
|
+
zz[0] = (component.pred += diff);
|
|
117
|
+
let k = 1;
|
|
118
|
+
while (k < 64) {
|
|
119
|
+
const rs = decodeHuffman(component.huffmanTableAC);
|
|
120
|
+
const s = rs & 15, r = rs >> 4;
|
|
121
|
+
if (s === 0) {
|
|
122
|
+
if (r < 15)
|
|
123
|
+
break;
|
|
124
|
+
k += 16;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
k += r;
|
|
128
|
+
const z = dctZigZag[k];
|
|
129
|
+
zz[z] = receiveAndExtend(s);
|
|
130
|
+
k++;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function decodeDCFirst(component, zz) {
|
|
135
|
+
const t = decodeHuffman(component.huffmanTableDC);
|
|
136
|
+
const diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
|
|
137
|
+
zz[0] = (component.pred += diff);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function decodeDCSuccessive(component, zz) {
|
|
141
|
+
zz[0] |= readBit() << successive;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let eobrun = 0;
|
|
145
|
+
|
|
146
|
+
function decodeACFirst(component, zz) {
|
|
147
|
+
if (eobrun > 0) {
|
|
148
|
+
eobrun--;
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
let k = spectralStart;
|
|
152
|
+
while (k <= spectralEnd) {
|
|
153
|
+
const rs = decodeHuffman(component.huffmanTableAC);
|
|
154
|
+
const s = rs & 15, r = rs >> 4;
|
|
155
|
+
if (s === 0) {
|
|
156
|
+
if (r < 15) {
|
|
157
|
+
eobrun = receive(r) + (1 << r) - 1;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
k += 16;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
k += r;
|
|
164
|
+
const z = dctZigZag[k];
|
|
165
|
+
zz[z] = receiveAndExtend(s) * (1 << successive);
|
|
166
|
+
k++;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
let successiveACState = 0, successiveACNextValue;
|
|
171
|
+
|
|
172
|
+
function decodeACSuccessive(component, zz) {
|
|
173
|
+
let k = spectralStart, r = 0;
|
|
174
|
+
while (k <= spectralEnd) {
|
|
175
|
+
const z = dctZigZag[k];
|
|
176
|
+
const direction = zz[z] < 0 ? -1 : 1;
|
|
177
|
+
switch (successiveACState) {
|
|
178
|
+
case 0: // initial state
|
|
179
|
+
const rs = decodeHuffman(component.huffmanTableAC);
|
|
180
|
+
let s = rs & 15;
|
|
181
|
+
r = rs >> 4;
|
|
182
|
+
|
|
183
|
+
if (s === 0) {
|
|
184
|
+
if (r < 15) {
|
|
185
|
+
eobrun = receive(r) + (1 << r);
|
|
186
|
+
successiveACState = 4;
|
|
187
|
+
} else {
|
|
188
|
+
r = 16;
|
|
189
|
+
successiveACState = 1;
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
if (s !== 1)
|
|
193
|
+
throw new Error("invalid ACn encoding");
|
|
194
|
+
successiveACNextValue = receiveAndExtend(s);
|
|
195
|
+
successiveACState = r ? 2 : 3;
|
|
196
|
+
}
|
|
197
|
+
continue;
|
|
198
|
+
case 1: // skipping r zero items
|
|
199
|
+
case 2:
|
|
200
|
+
if (zz[z])
|
|
201
|
+
zz[z] += (readBit() << successive) * direction;
|
|
202
|
+
else {
|
|
203
|
+
r--;
|
|
204
|
+
if (r === 0)
|
|
205
|
+
successiveACState = successiveACState === 2 ? 3 : 0;
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
case 3: // set value for a zero item
|
|
209
|
+
if (zz[z])
|
|
210
|
+
zz[z] += (readBit() << successive) * direction;
|
|
211
|
+
else {
|
|
212
|
+
zz[z] = successiveACNextValue << successive;
|
|
213
|
+
successiveACState = 0;
|
|
214
|
+
}
|
|
215
|
+
break;
|
|
216
|
+
case 4: // eob
|
|
217
|
+
if (zz[z])
|
|
218
|
+
zz[z] += (readBit() << successive) * direction;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
k++;
|
|
222
|
+
}
|
|
223
|
+
if (successiveACState === 4) {
|
|
224
|
+
eobrun--;
|
|
225
|
+
if (eobrun === 0)
|
|
226
|
+
successiveACState = 0;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
*
|
|
232
|
+
* @param {JpegFrameComponent} component
|
|
233
|
+
* @param {function} decode
|
|
234
|
+
* @param {number} mcu
|
|
235
|
+
* @param {number} row
|
|
236
|
+
* @param {number} col
|
|
237
|
+
*/
|
|
238
|
+
function decodeMcu(component, decode, mcu, row, col) {
|
|
239
|
+
const mcuRow = (mcu / mcusPerLine) | 0;
|
|
240
|
+
const mcuCol = mcu % mcusPerLine;
|
|
241
|
+
const blockRow = mcuRow * component.v + row;
|
|
242
|
+
const blockCol = mcuCol * component.h + col;
|
|
243
|
+
|
|
244
|
+
if (component.blocks[blockRow] === undefined && tolerantDecoding) {
|
|
245
|
+
// If the block is missing and we're in tolerant mode, just skip it.
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
decode(component, component.blocks[blockRow][blockCol]);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
*
|
|
254
|
+
* @param {JpegFrameComponent} component
|
|
255
|
+
* @param {function} decode
|
|
256
|
+
* @param {number} mcu
|
|
257
|
+
*/
|
|
258
|
+
function decodeBlock(component, decode, mcu) {
|
|
259
|
+
const blockRow = (mcu / component.blocksPerLine) | 0;
|
|
260
|
+
const blockCol = mcu % component.blocksPerLine;
|
|
261
|
+
|
|
262
|
+
if (component.blocks[blockRow] === undefined && tolerantDecoding) {
|
|
263
|
+
// If the block is missing and we're in tolerant mode, just skip it.
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
decode(component, component.blocks[blockRow][blockCol]);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const componentsLength = components.length;
|
|
271
|
+
let component, i, j, k, n;
|
|
272
|
+
let decodeFn;
|
|
273
|
+
if (progressive) {
|
|
274
|
+
if (spectralStart === 0)
|
|
275
|
+
decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
|
|
276
|
+
else
|
|
277
|
+
decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
|
|
278
|
+
} else {
|
|
279
|
+
decodeFn = decodeBaseline;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
let mcu = 0, marker;
|
|
283
|
+
let mcuExpected;
|
|
284
|
+
if (componentsLength === 1) {
|
|
285
|
+
mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
|
|
286
|
+
} else {
|
|
287
|
+
mcuExpected = mcusPerLine * frame.mcusPerColumn;
|
|
288
|
+
}
|
|
289
|
+
if (!resetInterval) {
|
|
290
|
+
resetInterval = mcuExpected;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
let h, v;
|
|
294
|
+
while (mcu < mcuExpected) {
|
|
295
|
+
// reset interval stuff
|
|
296
|
+
for (i = 0; i < componentsLength; i++)
|
|
297
|
+
components[i].pred = 0;
|
|
298
|
+
eobrun = 0;
|
|
299
|
+
|
|
300
|
+
if (componentsLength === 1) {
|
|
301
|
+
component = components[0];
|
|
302
|
+
for (n = 0; n < resetInterval; n++) {
|
|
303
|
+
decodeBlock(component, decodeFn, mcu);
|
|
304
|
+
mcu++;
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
for (n = 0; n < resetInterval; n++) {
|
|
308
|
+
for (i = 0; i < componentsLength; i++) {
|
|
309
|
+
component = components[i];
|
|
310
|
+
h = component.h;
|
|
311
|
+
v = component.v;
|
|
312
|
+
for (j = 0; j < v; j++) {
|
|
313
|
+
for (k = 0; k < h; k++) {
|
|
314
|
+
decodeMcu(component, decodeFn, mcu, j, k);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
mcu++;
|
|
319
|
+
|
|
320
|
+
// If we've reached our expected MCU's, stop decoding
|
|
321
|
+
if (mcu === mcuExpected) break;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (mcu === mcuExpected) {
|
|
326
|
+
// Skip trailing bytes at the end of the scan - until we reach the next marker
|
|
327
|
+
do {
|
|
328
|
+
if (data[offset] === 0xFF) {
|
|
329
|
+
if (data[offset + 1] !== 0x00) {
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
offset += 1;
|
|
334
|
+
} while (offset < data.length - 2);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// find marker
|
|
338
|
+
bitsCount = 0;
|
|
339
|
+
marker = (data[offset] << 8) | data[offset + 1];
|
|
340
|
+
if (marker < 0xFF00) {
|
|
341
|
+
throw new Error("marker was not found");
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
|
|
345
|
+
offset += 2;
|
|
346
|
+
} else
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return offset - startOffset;
|
|
351
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode 8x8 block quantized DCT coefficients and inverse DCT transform.
|
|
3
|
+
* This is a fixed-point implementation of the IDCT algorithm.
|
|
4
|
+
*
|
|
5
|
+
* This IDCT algorithm is taken from:
|
|
6
|
+
* Y. A. Reznik, A. T. Hinds, L. Yu, Z. Ni, and C-X. Zhang,
|
|
7
|
+
* "Efficient fixed-point approximations of the 8x8 inverse discrete
|
|
8
|
+
* cosine transform" (invited paper), Proc. SPIE Vol. 6696, Sep. 24, 2007.
|
|
9
|
+
*
|
|
10
|
+
* which is based on:
|
|
11
|
+
* Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
|
|
12
|
+
* "Practical Fast 1-D DCT Algorithms with 11 Multiplications",
|
|
13
|
+
* IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
|
|
14
|
+
* 988-991.
|
|
15
|
+
*
|
|
16
|
+
* The stage numbers mentioned in the comments refer to Figure 1 in the Loeffler paper.
|
|
17
|
+
*
|
|
18
|
+
* @param {Int32Array} qt quantization table
|
|
19
|
+
* @param {Int32Array} zz zigzag-ordered coefficients
|
|
20
|
+
* @param {Uint8Array|Uint8ClampedArray} dataOut
|
|
21
|
+
*/
|
|
22
|
+
export function idct8x8_fixed(qt: Int32Array, zz: Int32Array, dataOut: Uint8Array | Uint8ClampedArray): void;
|
|
23
|
+
//# sourceMappingURL=idct8x8_fixed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idct8x8_fixed.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/asset/loaders/image/jpeg/idct8x8_fixed.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,kCAJW,UAAU,MACV,UAAU,WACV,UAAU,GAAC,iBAAiB,QAkLtC"}
|