@woosh/meep-engine 2.138.13 → 2.138.16
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/samples/terrain/from_image_2.js +2 -10
- package/src/engine/asset/loaders/image/ImageDecoderWorker.js +1 -1
- package/src/engine/asset/loaders/image/ImageRGBADataLoader.d.ts.map +1 -1
- package/src/engine/asset/loaders/image/ImageRGBADataLoader.js +6 -1
- package/src/engine/asset/loaders/image/png/PNGReader.d.ts +1 -99
- package/src/engine/asset/loaders/image/png/PNGReader.d.ts.map +1 -1
- package/src/engine/asset/loaders/image/png/PNGReader.js +31 -420
- package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.d.ts +12 -0
- package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.js +53 -0
- package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.d.ts +10 -0
- package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.js +42 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.d.ts +18 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.js +59 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.d.ts +17 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.js +55 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterPaeth.d.ts +17 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterPaeth.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterPaeth.js +74 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.d.ts +15 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.js +34 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.d.ts +16 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.js +46 -0
- package/src/engine/asset/loaders/image/png/inflate.d.ts +7 -0
- package/src/engine/asset/loaders/image/png/inflate.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/inflate.js +20 -0
- package/src/engine/ecs/terrain/ecs/Terrain.js +1 -1
- package/src/engine/ecs/terrain/ecs/splat/SplatMapping.d.ts.map +1 -1
- package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +32 -9
- package/src/engine/graphics/impostors/octahedral/prototypeBaker.js +202 -8
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.d.ts +10 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.d.ts.map +1 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.js +418 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.d.ts +14 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.d.ts.map +1 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.js +757 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.d.ts +13 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.d.ts.map +1 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.js +380 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.d.ts +6 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.d.ts.map +1 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.js +406 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.d.ts.map +1 -1
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.js +8 -1
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.d.ts +14 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.d.ts.map +1 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.js +356 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderWireframeV0.d.ts.map +1 -1
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderWireframeV0.js +4 -1
- package/src/engine/graphics/shaders/TerrainShader.js +2 -2
- package/src/engine/intelligence/mcts/MonteCarlo.d.ts +35 -4
- package/src/engine/intelligence/mcts/MonteCarlo.d.ts.map +1 -1
- package/src/engine/intelligence/mcts/MonteCarlo.js +101 -31
- package/src/engine/intelligence/mcts/StateNode.d.ts +47 -24
- package/src/engine/intelligence/mcts/StateNode.d.ts.map +1 -1
- package/src/engine/intelligence/mcts/StateNode.js +364 -316
|
@@ -7,30 +7,18 @@ import { BinaryBuffer } from "../../../../../core/binary/BinaryBuffer.js";
|
|
|
7
7
|
import { EndianType } from "../../../../../core/binary/EndianType.js";
|
|
8
8
|
import { platform_compute_endianness } from "../../../../../core/binary/platform_compute_endianness.js";
|
|
9
9
|
import { isArrayEqualStrict } from "../../../../../core/collection/array/isArrayEqualStrict.js";
|
|
10
|
+
import { png_chunk_decode_iTXt } from "./chunk/png_chunk_decode_iTXt.js";
|
|
11
|
+
import { png_chunk_decode_zTXt } from "./chunk/png_chunk_decode_zTXt.js";
|
|
10
12
|
import { crc32 } from "./crc32.js";
|
|
13
|
+
import { png_filter_unFilterAverage } from "./filter/png_filter_unFilterAverage.js";
|
|
14
|
+
import { png_filter_unFilterNone } from "./filter/png_filter_unFilterNone.js";
|
|
15
|
+
import { png_filter_unFilterPaeth } from "./filter/png_filter_unFilterPaeth.js";
|
|
16
|
+
import { png_filter_unFilterSub } from "./filter/png_filter_unFilterSub.js";
|
|
17
|
+
import { png_filter_unFilterUp } from "./filter/png_filter_unFilterUp.js";
|
|
11
18
|
|
|
12
19
|
import { PNG } from './PNG.js';
|
|
13
20
|
import { PNG_HEADER_BYTES } from "./PNG_HEADER_BYTES.js";
|
|
14
21
|
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* @param {Uint8Array} encoded_chunk
|
|
18
|
-
* @returns {ArrayBuffer}
|
|
19
|
-
*/
|
|
20
|
-
function inflate(encoded_chunk) {
|
|
21
|
-
const inflator = new zlib.Inflate();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
inflator.push(encoded_chunk);
|
|
25
|
-
|
|
26
|
-
if (inflator.err) {
|
|
27
|
-
throw new Error(inflator.err);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return inflator.result.buffer;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
22
|
/**
|
|
35
23
|
*
|
|
36
24
|
* @param {Uint8Array} buffer
|
|
@@ -221,10 +209,10 @@ PNGReader.prototype.decodeChunk = function () {
|
|
|
221
209
|
this.decodetIME(chunk);
|
|
222
210
|
break;
|
|
223
211
|
case 'zTXt':
|
|
224
|
-
|
|
212
|
+
png_chunk_decode_zTXt(chunk);
|
|
225
213
|
break;
|
|
226
214
|
case 'iTXt':
|
|
227
|
-
|
|
215
|
+
png_chunk_decode_iTXt(chunk);
|
|
228
216
|
break;
|
|
229
217
|
default:
|
|
230
218
|
// skip unknown block
|
|
@@ -265,89 +253,6 @@ PNGReader.prototype.decodetIME = function (chunk) {
|
|
|
265
253
|
const second = readUInt8(chunk, 6);
|
|
266
254
|
}
|
|
267
255
|
|
|
268
|
-
/**
|
|
269
|
-
* International textual data
|
|
270
|
-
* @see https://www.w3.org/TR/2003/REC-PNG-20031110/
|
|
271
|
-
* @param {Uint8Array} chunk
|
|
272
|
-
*/
|
|
273
|
-
PNGReader.prototype.decodeiTXt = function (chunk) {
|
|
274
|
-
const buffer = BinaryBuffer.fromArrayBuffer(chunk.buffer);
|
|
275
|
-
const keyword = buffer.readASCIICharacters(79, true);
|
|
276
|
-
const compression_flag = buffer.readUint8();
|
|
277
|
-
const compression_method = buffer.readUint8();
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const language_tag = buffer.readASCIICharacters(Infinity, true);
|
|
281
|
-
const translated_keyword = buffer.readASCIICharacters(Infinity, true);
|
|
282
|
-
|
|
283
|
-
const remaining_bytes = buffer.data.length - buffer.position;
|
|
284
|
-
|
|
285
|
-
let text;
|
|
286
|
-
|
|
287
|
-
if (compression_flag === 0) {
|
|
288
|
-
text = buffer.readASCIICharacters(remaining_bytes);
|
|
289
|
-
} else if (compression_flag === 1) {
|
|
290
|
-
|
|
291
|
-
if(compression_method !== 0){
|
|
292
|
-
throw new Error('only compression_method 0 is supported');
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const decoded = inflate(new Uint8Array(buffer.data, buffer.position, remaining_bytes));
|
|
296
|
-
|
|
297
|
-
buffer.fromArrayBuffer(decoded);
|
|
298
|
-
|
|
299
|
-
text = buffer.readASCIICharacters(decoded.byteLength);
|
|
300
|
-
} else {
|
|
301
|
-
throw new Error(`Invalid compression flag value '${compression_flag}'`);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
return {
|
|
305
|
-
keyword,
|
|
306
|
-
language_tag,
|
|
307
|
-
translated_keyword,
|
|
308
|
-
text
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Compressed textual data
|
|
315
|
-
* @see https://www.w3.org/TR/2003/REC-PNG-20031110/#11zTXt
|
|
316
|
-
* @param {Uint8Array} chunk
|
|
317
|
-
*/
|
|
318
|
-
PNGReader.prototype.decodezTXt = function (chunk) {
|
|
319
|
-
const buffer = BinaryBuffer.fromArrayBuffer(chunk.buffer);
|
|
320
|
-
|
|
321
|
-
const keyword = buffer.readASCIICharacters(79, true);
|
|
322
|
-
|
|
323
|
-
const compression_method = buffer.readUint8();
|
|
324
|
-
|
|
325
|
-
let value;
|
|
326
|
-
|
|
327
|
-
if (compression_method === 0) {
|
|
328
|
-
// deflate method
|
|
329
|
-
|
|
330
|
-
if(compression_method !== 0){
|
|
331
|
-
throw new Error('only compression_method 0 is supported');
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const encoded_chunk = new Uint8Array(chunk.buffer, buffer.position);
|
|
335
|
-
|
|
336
|
-
const decompressed_data = inflate(encoded_chunk);
|
|
337
|
-
|
|
338
|
-
buffer.fromArrayBuffer(decompressed_data);
|
|
339
|
-
|
|
340
|
-
value = buffer.readASCIICharacters(decompressed_data.length);
|
|
341
|
-
} else {
|
|
342
|
-
throw new Error(`Unsupported compression method '${compression_method}'`);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
return {
|
|
346
|
-
keyword: keyword,
|
|
347
|
-
text: value
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
256
|
/**
|
|
352
257
|
* https://www.w3.org/TR/PNG/#11tEXt
|
|
353
258
|
* @param {Uint8Array} chunk
|
|
@@ -473,6 +378,18 @@ PNGReader.prototype.decodePixels = function () {
|
|
|
473
378
|
} else {
|
|
474
379
|
this.png.pixels = this.interlaceAdam7(decompressed_data);
|
|
475
380
|
}
|
|
381
|
+
|
|
382
|
+
// PNG stores 16-bit samples big-endian. Rewrite the buffer to platform-endian
|
|
383
|
+
// here so that downstream consumers can view it as Uint16Array without further
|
|
384
|
+
// byte swapping.
|
|
385
|
+
if (png.bitDepth === 16 && platform_compute_endianness() === EndianType.LittleEndian) {
|
|
386
|
+
const pixels = this.png.pixels;
|
|
387
|
+
for (let i = 0; i < pixels.length; i += 2) {
|
|
388
|
+
const hi = pixels[i];
|
|
389
|
+
pixels[i] = pixels[i + 1];
|
|
390
|
+
pixels[i + 1] = hi;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
476
393
|
};
|
|
477
394
|
|
|
478
395
|
// Different interlace methods
|
|
@@ -513,7 +430,7 @@ PNGReader.prototype.interlaceNone = function (data) {
|
|
|
513
430
|
data,
|
|
514
431
|
scanline_address,
|
|
515
432
|
pixels,
|
|
516
|
-
|
|
433
|
+
Math.max(1, Math.ceil(bytes_per_pixel)),
|
|
517
434
|
offset,
|
|
518
435
|
offset - color_bytes_per_row,
|
|
519
436
|
color_bytes_per_row
|
|
@@ -536,8 +453,7 @@ PNGReader.prototype.interlaceAdam7 = function (data) {
|
|
|
536
453
|
|
|
537
454
|
const png = this.png;
|
|
538
455
|
|
|
539
|
-
const
|
|
540
|
-
const bytes_per_pixel = png.colors * depth / 8;
|
|
456
|
+
const bytes_per_pixel = png.colors * png.bitDepth / 8;
|
|
541
457
|
|
|
542
458
|
const pixels = new Uint8Array(bytes_per_pixel * png.width * png.height);
|
|
543
459
|
|
|
@@ -619,27 +535,7 @@ PNGReader.prototype.interlaceAdam7 = function (data) {
|
|
|
619
535
|
}
|
|
620
536
|
}
|
|
621
537
|
|
|
622
|
-
|
|
623
|
-
return ((val & 0xff) << 8) | ((val >> 8) & 0xff);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
if (depth === 16) {
|
|
627
|
-
const uint16Data = new Uint16Array(pixels.buffer);
|
|
628
|
-
|
|
629
|
-
const osIsLittleEndian = platform_compute_endianness() === EndianType.LittleEndian;
|
|
630
|
-
|
|
631
|
-
if (osIsLittleEndian) {
|
|
632
|
-
for (let k = 0; k < uint16Data.length; k++) {
|
|
633
|
-
// PNG is always big endian. Swap the bytes.
|
|
634
|
-
uint16Data[k] = swap16(uint16Data[k]);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
return uint16Data;
|
|
639
|
-
} else {
|
|
640
|
-
return pixels;
|
|
641
|
-
}
|
|
642
|
-
|
|
538
|
+
return pixels;
|
|
643
539
|
};
|
|
644
540
|
|
|
645
541
|
// Unfiltering
|
|
@@ -675,40 +571,37 @@ PNGReader.prototype.unFilter = function (
|
|
|
675
571
|
|
|
676
572
|
switch (filter_type) {
|
|
677
573
|
case 0:
|
|
678
|
-
|
|
574
|
+
png_filter_unFilterNone(
|
|
679
575
|
data,
|
|
680
576
|
scanline_address,
|
|
681
577
|
output,
|
|
682
|
-
bytes_per_pixel,
|
|
683
578
|
output_offset,
|
|
684
|
-
|
|
685
|
-
|
|
579
|
+
length,
|
|
580
|
+
this.png.bitDepth
|
|
686
581
|
);
|
|
687
582
|
break;
|
|
688
583
|
case 1:
|
|
689
|
-
|
|
584
|
+
png_filter_unFilterSub(
|
|
690
585
|
data,
|
|
691
586
|
scanline_address,
|
|
692
587
|
output,
|
|
693
588
|
bytes_per_pixel,
|
|
694
589
|
output_offset,
|
|
695
|
-
output_offset_previous,
|
|
696
590
|
length
|
|
697
591
|
);
|
|
698
592
|
break;
|
|
699
593
|
case 2:
|
|
700
|
-
|
|
594
|
+
png_filter_unFilterUp(
|
|
701
595
|
data,
|
|
702
596
|
scanline_address,
|
|
703
597
|
output,
|
|
704
|
-
bytes_per_pixel,
|
|
705
598
|
output_offset,
|
|
706
599
|
output_offset_previous,
|
|
707
600
|
length
|
|
708
601
|
);
|
|
709
602
|
break;
|
|
710
603
|
case 3:
|
|
711
|
-
|
|
604
|
+
png_filter_unFilterAverage(
|
|
712
605
|
data,
|
|
713
606
|
scanline_address,
|
|
714
607
|
output,
|
|
@@ -719,7 +612,7 @@ PNGReader.prototype.unFilter = function (
|
|
|
719
612
|
);
|
|
720
613
|
break;
|
|
721
614
|
case 4:
|
|
722
|
-
|
|
615
|
+
png_filter_unFilterPaeth(
|
|
723
616
|
data,
|
|
724
617
|
scanline_address,
|
|
725
618
|
output,
|
|
@@ -734,288 +627,6 @@ PNGReader.prototype.unFilter = function (
|
|
|
734
627
|
}
|
|
735
628
|
}
|
|
736
629
|
|
|
737
|
-
/**
|
|
738
|
-
* With the None filter, the scanline is transmitted unmodified; it is only necessary to insert a filter type byte before the data.
|
|
739
|
-
*
|
|
740
|
-
* @param {Uint8Array} data
|
|
741
|
-
* @param {number} scanline_address
|
|
742
|
-
* @param {Uint8Array} output
|
|
743
|
-
* @param {number} bytes_per_pixel
|
|
744
|
-
* @param {number} output_offset
|
|
745
|
-
* @param {number} output_offset_previous
|
|
746
|
-
* @param {number} length
|
|
747
|
-
*
|
|
748
|
-
* @see https://www.w3.org/TR/PNG-Filters.html
|
|
749
|
-
*/
|
|
750
|
-
PNGReader.prototype.unFilterNone = function (
|
|
751
|
-
data,
|
|
752
|
-
scanline_address,
|
|
753
|
-
output,
|
|
754
|
-
bytes_per_pixel,
|
|
755
|
-
output_offset,
|
|
756
|
-
output_offset_previous,
|
|
757
|
-
length
|
|
758
|
-
) {
|
|
759
|
-
|
|
760
|
-
const png = this.png;
|
|
761
|
-
const depth = png.bitDepth;
|
|
762
|
-
|
|
763
|
-
if (depth === 1) {
|
|
764
|
-
for (let x = 0; x < length; x++) {
|
|
765
|
-
const q = x >>> 4;
|
|
766
|
-
const datum = data[q + scanline_address];
|
|
767
|
-
const shift = ((x) & 0x7);
|
|
768
|
-
const out_value = (datum >>> shift) & 0x1;
|
|
769
|
-
output[output_offset + x] = out_value;
|
|
770
|
-
}
|
|
771
|
-
} else if (depth === 2) {
|
|
772
|
-
for (let x = 0; x < length; x++) {
|
|
773
|
-
const q = x >>> 2;
|
|
774
|
-
const datum = data[q + scanline_address];
|
|
775
|
-
const shift = ((~x) & 0x3) << 1;
|
|
776
|
-
const out_value = (datum >>> shift) & 0x3;
|
|
777
|
-
output[output_offset + x] = out_value;
|
|
778
|
-
}
|
|
779
|
-
} else if (depth === 4) {
|
|
780
|
-
for (let x = 0; x < length; x++) {
|
|
781
|
-
const q = x >>> 1;
|
|
782
|
-
const datum = data[q + scanline_address];
|
|
783
|
-
const shift = ((~x) & 0x1) << 2;
|
|
784
|
-
const out_value = (datum >>> shift) & 0xF;
|
|
785
|
-
output[output_offset + x] = out_value;
|
|
786
|
-
}
|
|
787
|
-
} else if (depth === 8) {
|
|
788
|
-
for (let x = 0; x < length; x++) {
|
|
789
|
-
// straight copy
|
|
790
|
-
output[output_offset + x] = data[x + scanline_address];
|
|
791
|
-
}
|
|
792
|
-
} else {
|
|
793
|
-
throw new Error(`unsupported bit depth ${depth}`)
|
|
794
|
-
}
|
|
795
|
-
};
|
|
796
|
-
|
|
797
|
-
/**
|
|
798
|
-
* The `Sub` filter transmits the difference between each byte and the value
|
|
799
|
-
* of the corresponding byte of the prior pixel.
|
|
800
|
-
* `Sub(x) = Raw(x) + Raw(x - bpp)`
|
|
801
|
-
*
|
|
802
|
-
* @param {Uint8Array} scanline raw data
|
|
803
|
-
* @param {number} scanline_offset
|
|
804
|
-
* @param {Uint8Array} pixels processed output
|
|
805
|
-
* @param {number} bpp bytes-per-pixel
|
|
806
|
-
* @param {number} offset
|
|
807
|
-
* @param {number} output_offset_previous
|
|
808
|
-
* @param {number} length
|
|
809
|
-
* @see https://www.w3.org/TR/PNG-Filters.html
|
|
810
|
-
*/
|
|
811
|
-
PNGReader.prototype.unFilterSub = function (
|
|
812
|
-
scanline,
|
|
813
|
-
scanline_offset,
|
|
814
|
-
pixels,
|
|
815
|
-
bpp,
|
|
816
|
-
offset,
|
|
817
|
-
output_offset_previous,
|
|
818
|
-
length
|
|
819
|
-
) {
|
|
820
|
-
|
|
821
|
-
let i = 0;
|
|
822
|
-
|
|
823
|
-
for (; i < bpp; i++) {
|
|
824
|
-
pixels[offset + i] = scanline[i + scanline_offset];
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
for (; i < length; i++) {
|
|
828
|
-
// Raw(x) + Raw(x - bpp)
|
|
829
|
-
const of_i = offset + i;
|
|
830
|
-
pixels[of_i] = (scanline[i + scanline_offset] + pixels[of_i - bpp]) & 0xFF;
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
};
|
|
834
|
-
|
|
835
|
-
/**
|
|
836
|
-
* The `Up` filter is just like the Sub() filter except that the pixel
|
|
837
|
-
* immediately above the current pixel, rather than just to its left, is used
|
|
838
|
-
* as the predictor.
|
|
839
|
-
* `Up(x) = Raw(x) + Prior(x)`
|
|
840
|
-
*
|
|
841
|
-
* @param {Uint8Array} scanline raw data
|
|
842
|
-
* @param {number} scanline_offset
|
|
843
|
-
* @param {Uint8Array} pixels processed output
|
|
844
|
-
* @param {number} bpp bytes-per-pixel
|
|
845
|
-
* @param {number} offset
|
|
846
|
-
* @param {number} output_offset_previous
|
|
847
|
-
* @param {number} length
|
|
848
|
-
* @see https://www.w3.org/TR/PNG-Filters.html
|
|
849
|
-
*/
|
|
850
|
-
PNGReader.prototype.unFilterUp = function (
|
|
851
|
-
scanline,
|
|
852
|
-
scanline_offset,
|
|
853
|
-
pixels,
|
|
854
|
-
bpp,
|
|
855
|
-
offset,
|
|
856
|
-
output_offset_previous,
|
|
857
|
-
length
|
|
858
|
-
) {
|
|
859
|
-
let i = 0, byte, prev;
|
|
860
|
-
|
|
861
|
-
// Prior(x) is 0 for all x on the first scanline
|
|
862
|
-
if (output_offset_previous < 0) {
|
|
863
|
-
|
|
864
|
-
for (; i < length; i++) {
|
|
865
|
-
pixels[offset + i] = scanline[i + scanline_offset];
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
} else {
|
|
869
|
-
|
|
870
|
-
for (; i < length; i++) {
|
|
871
|
-
|
|
872
|
-
// Raw(x)
|
|
873
|
-
byte = scanline[i + scanline_offset];
|
|
874
|
-
|
|
875
|
-
// Prior(x)
|
|
876
|
-
prev = pixels[output_offset_previous + i];
|
|
877
|
-
|
|
878
|
-
pixels[offset + i] = (byte + prev) & 0xFF;
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
}
|
|
882
|
-
};
|
|
883
|
-
|
|
884
|
-
/**
|
|
885
|
-
* The `Average` filter uses the average of the two neighboring pixels (left
|
|
886
|
-
* and above) to predict the value of a pixel.
|
|
887
|
-
*
|
|
888
|
-
* `Average(x) = Raw(x) + floor((Raw(x-bpp)+Prior(x))/2)`
|
|
889
|
-
*
|
|
890
|
-
* @param {Uint8Array} scanline raw data
|
|
891
|
-
* @param {number} scanline_offset
|
|
892
|
-
* @param {Uint8Array} pixels processed output
|
|
893
|
-
* @param {number} bpp bytes-per-pixel
|
|
894
|
-
* @param {number} offset
|
|
895
|
-
* @param {number} output_offset_previous
|
|
896
|
-
* @param {number} length
|
|
897
|
-
*
|
|
898
|
-
* @see https://www.w3.org/TR/PNG-Filters.html
|
|
899
|
-
*/
|
|
900
|
-
PNGReader.prototype.unFilterAverage = function (
|
|
901
|
-
scanline,
|
|
902
|
-
scanline_offset,
|
|
903
|
-
pixels,
|
|
904
|
-
bpp,
|
|
905
|
-
offset,
|
|
906
|
-
output_offset_previous,
|
|
907
|
-
length
|
|
908
|
-
) {
|
|
909
|
-
let i = 0, byte, prev, prior;
|
|
910
|
-
|
|
911
|
-
if (output_offset_previous < 0) {
|
|
912
|
-
|
|
913
|
-
// Prior(x) == 0 && Raw(x - bpp) == 0
|
|
914
|
-
for (; i < bpp; i++) {
|
|
915
|
-
pixels[offset + i] = scanline[i + scanline_offset];
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
// Prior(x) == 0 && Raw(x - bpp) != 0 (right shift, prevent doubles)
|
|
919
|
-
for (; i < length; i++) {
|
|
920
|
-
const of_i = offset + i;
|
|
921
|
-
pixels[of_i] = (scanline[i + scanline_offset] + (pixels[of_i - bpp] >> 1)) & 0xFF;
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
} else {
|
|
925
|
-
|
|
926
|
-
// Prior(x) != 0 && Raw(x - bpp) == 0
|
|
927
|
-
for (; i < bpp; i++) {
|
|
928
|
-
pixels[offset + i] = (scanline[i + scanline_offset] + (pixels[output_offset_previous + i] >> 1)) & 0xFF;
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
// Prior(x) != 0 && Raw(x - bpp) != 0
|
|
932
|
-
for (; i < length; i++) {
|
|
933
|
-
byte = scanline[i + scanline_offset];
|
|
934
|
-
|
|
935
|
-
prev = pixels[offset + i - bpp];
|
|
936
|
-
prior = pixels[output_offset_previous + i];
|
|
937
|
-
|
|
938
|
-
pixels[offset + i] = (byte + (prev + prior >> 1)) & 0xFF;
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
}
|
|
942
|
-
};
|
|
943
|
-
|
|
944
|
-
/**
|
|
945
|
-
* The `Paeth` filter computes a simple linear function of the three neighboring pixels (left, above, upper left), then chooses as predictor the neighboring pixel closest to the computed value.
|
|
946
|
-
*
|
|
947
|
-
* This technique is due to Alan W. Paeth.
|
|
948
|
-
*
|
|
949
|
-
* @param {Uint8Array} scanline raw data
|
|
950
|
-
* @param {number} scanline_offset
|
|
951
|
-
* @param {Uint8Array} pixels processed output
|
|
952
|
-
* @param {number} bpp bytes-per-pixel
|
|
953
|
-
* @param {number} offset
|
|
954
|
-
* @param {number} output_offset_previous
|
|
955
|
-
* @param {number} length
|
|
956
|
-
*
|
|
957
|
-
* @see https://www.w3.org/TR/PNG-Filters.html
|
|
958
|
-
*/
|
|
959
|
-
PNGReader.prototype.unFilterPaeth = function (
|
|
960
|
-
scanline,
|
|
961
|
-
scanline_offset,
|
|
962
|
-
pixels,
|
|
963
|
-
bpp,
|
|
964
|
-
offset,
|
|
965
|
-
output_offset_previous,
|
|
966
|
-
length
|
|
967
|
-
) {
|
|
968
|
-
let i = 0, raw, a, b, c, p, pa, pb, pc, pr;
|
|
969
|
-
|
|
970
|
-
if (output_offset_previous < 0) {
|
|
971
|
-
|
|
972
|
-
// Prior(x) == 0 && Raw(x - bpp) == 0
|
|
973
|
-
for (; i < bpp; i++) {
|
|
974
|
-
pixels[offset + i] = scanline[i + scanline_offset];
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
// Prior(x) == 0 && Raw(x - bpp) != 0
|
|
978
|
-
// paethPredictor(x, 0, 0) is always x
|
|
979
|
-
for (; i < length; i++) {
|
|
980
|
-
pixels[offset + i] = (scanline[i + scanline_offset] + pixels[offset + i - bpp]) & 0xFF;
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
} else {
|
|
984
|
-
|
|
985
|
-
// Prior(x) != 0 && Raw(x - bpp) == 0
|
|
986
|
-
// paethPredictor(x, 0, 0) is always x
|
|
987
|
-
for (; i < bpp; i++) {
|
|
988
|
-
pixels[offset + i] = (scanline[i + scanline_offset] + pixels[output_offset_previous + i]) & 0xFF;
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
// Prior(x) != 0 && Raw(x - bpp) != 0
|
|
992
|
-
for (; i < length; i++) {
|
|
993
|
-
raw = scanline[i + scanline_offset];
|
|
994
|
-
|
|
995
|
-
c = pixels[output_offset_previous + i - bpp];
|
|
996
|
-
b = pixels[output_offset_previous + i];
|
|
997
|
-
a = pixels[offset + i - bpp];
|
|
998
|
-
|
|
999
|
-
p = a + b - c;
|
|
1000
|
-
|
|
1001
|
-
pa = Math.abs(p - a);
|
|
1002
|
-
pb = Math.abs(p - b);
|
|
1003
|
-
pc = Math.abs(p - c);
|
|
1004
|
-
|
|
1005
|
-
if (pa <= pb && pa <= pc) {
|
|
1006
|
-
pr = a;
|
|
1007
|
-
} else if (pb <= pc) {
|
|
1008
|
-
pr = b;
|
|
1009
|
-
} else {
|
|
1010
|
-
pr = c;
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
pixels[offset + i] = (raw + pr) & 0xFF;
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
}
|
|
1017
|
-
};
|
|
1018
|
-
|
|
1019
630
|
/**
|
|
1020
631
|
* Parse the PNG file
|
|
1021
632
|
* @returns {PNG}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* International textual data
|
|
3
|
+
* @see https://www.w3.org/TR/2003/REC-PNG-20031110/
|
|
4
|
+
* @param {Uint8Array} chunk
|
|
5
|
+
*/
|
|
6
|
+
export function png_chunk_decode_iTXt(chunk: Uint8Array): {
|
|
7
|
+
keyword: string;
|
|
8
|
+
language_tag: string;
|
|
9
|
+
translated_keyword: string;
|
|
10
|
+
text: string;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=png_chunk_decode_iTXt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"png_chunk_decode_iTXt.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.js"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,6CAFW,UAAU;;;;;EA8CpB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BinaryBuffer } from "../../../../../../core/binary/BinaryBuffer.js";
|
|
2
|
+
import { inflate } from "../inflate.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* International textual data
|
|
6
|
+
* @see https://www.w3.org/TR/2003/REC-PNG-20031110/
|
|
7
|
+
* @param {Uint8Array} chunk
|
|
8
|
+
*/
|
|
9
|
+
export function png_chunk_decode_iTXt(chunk) {
|
|
10
|
+
const chunk_size = chunk.byteLength;
|
|
11
|
+
const chunk_buffer = chunk.buffer;
|
|
12
|
+
const chunk_byte_offset = chunk.byteOffset;
|
|
13
|
+
const chunk_byte_end = chunk_byte_offset + chunk_size;
|
|
14
|
+
|
|
15
|
+
const buffer = BinaryBuffer.fromArrayBuffer(chunk_buffer);
|
|
16
|
+
buffer.position = chunk_byte_offset;
|
|
17
|
+
|
|
18
|
+
const keyword = buffer.readASCIICharacters(79, true);
|
|
19
|
+
const compression_flag = buffer.readUint8();
|
|
20
|
+
const compression_method = buffer.readUint8();
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const language_tag = buffer.readASCIICharacters(Number.MAX_SAFE_INTEGER, true);
|
|
24
|
+
const translated_keyword = buffer.readASCIICharacters(Number.MAX_SAFE_INTEGER, true);
|
|
25
|
+
|
|
26
|
+
const remaining_bytes = chunk_byte_end - buffer.position;
|
|
27
|
+
|
|
28
|
+
let text;
|
|
29
|
+
|
|
30
|
+
if (compression_flag === 0) {
|
|
31
|
+
text = buffer.readASCIICharacters(remaining_bytes);
|
|
32
|
+
} else if (compression_flag === 1) {
|
|
33
|
+
|
|
34
|
+
if (compression_method !== 0) {
|
|
35
|
+
throw new Error('only compression_method 0 is supported');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const decoded = inflate(new Uint8Array(buffer.data, buffer.position, remaining_bytes));
|
|
39
|
+
|
|
40
|
+
buffer.fromArrayBuffer(decoded);
|
|
41
|
+
|
|
42
|
+
text = buffer.readASCIICharacters(decoded.byteLength);
|
|
43
|
+
} else {
|
|
44
|
+
throw new Error(`Invalid compression flag value '${compression_flag}'`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
keyword,
|
|
49
|
+
language_tag,
|
|
50
|
+
translated_keyword,
|
|
51
|
+
text
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compressed textual data
|
|
3
|
+
* @see https://www.w3.org/TR/2003/REC-PNG-20031110/#11zTXt
|
|
4
|
+
* @param {Uint8Array} chunk
|
|
5
|
+
*/
|
|
6
|
+
export function png_chunk_decode_zTXt(chunk: Uint8Array): {
|
|
7
|
+
keyword: string;
|
|
8
|
+
text: string;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=png_chunk_decode_zTXt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"png_chunk_decode_zTXt.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.js"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,6CAFW,UAAU;;;EAmCpB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BinaryBuffer } from "../../../../../../core/binary/BinaryBuffer.js";
|
|
2
|
+
import { inflate } from "../inflate.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Compressed textual data
|
|
6
|
+
* @see https://www.w3.org/TR/2003/REC-PNG-20031110/#11zTXt
|
|
7
|
+
* @param {Uint8Array} chunk
|
|
8
|
+
*/
|
|
9
|
+
export function png_chunk_decode_zTXt(chunk) {
|
|
10
|
+
const chunk_size = chunk.byteLength;
|
|
11
|
+
const chunk_buffer = chunk.buffer;
|
|
12
|
+
const chunk_byte_offset = chunk.byteOffset;
|
|
13
|
+
|
|
14
|
+
const buffer = BinaryBuffer.fromArrayBuffer(chunk_buffer);
|
|
15
|
+
buffer.position = chunk_byte_offset;
|
|
16
|
+
|
|
17
|
+
const keyword = buffer.readASCIICharacters(79, true);
|
|
18
|
+
|
|
19
|
+
const compression_method = buffer.readUint8();
|
|
20
|
+
|
|
21
|
+
let value;
|
|
22
|
+
|
|
23
|
+
if (compression_method === 0) {
|
|
24
|
+
// deflate method
|
|
25
|
+
|
|
26
|
+
const local_offset = buffer.position - chunk_byte_offset;
|
|
27
|
+
const encoded_chunk = new Uint8Array(chunk_buffer, buffer.position, chunk_size - local_offset);
|
|
28
|
+
|
|
29
|
+
const decompressed_data = inflate(encoded_chunk);
|
|
30
|
+
|
|
31
|
+
buffer.fromArrayBuffer(decompressed_data);
|
|
32
|
+
|
|
33
|
+
value = buffer.readASCIICharacters(decompressed_data.byteLength);
|
|
34
|
+
} else {
|
|
35
|
+
throw new Error(`Unsupported compression method '${compression_method}'`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
keyword: keyword,
|
|
40
|
+
text: value
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `Average` filter uses the average of the two neighboring pixels (left
|
|
3
|
+
* and above) to predict the value of a pixel.
|
|
4
|
+
*
|
|
5
|
+
* `Average(x) = Raw(x) + floor((Raw(x-bpp)+Prior(x))/2)`
|
|
6
|
+
*
|
|
7
|
+
* @param {Uint8Array} scanline raw data
|
|
8
|
+
* @param {number} scanline_offset
|
|
9
|
+
* @param {Uint8Array} pixels processed output
|
|
10
|
+
* @param {number} bpp bytes-per-pixel
|
|
11
|
+
* @param {number} offset
|
|
12
|
+
* @param {number} output_offset_previous pass a negative value when there is no previous scanline
|
|
13
|
+
* @param {number} length
|
|
14
|
+
*
|
|
15
|
+
* @see https://www.w3.org/TR/PNG-Filters.html
|
|
16
|
+
*/
|
|
17
|
+
export function png_filter_unFilterAverage(scanline: Uint8Array, scanline_offset: number, pixels: Uint8Array, bpp: number, offset: number, output_offset_previous: number, length: number): void;
|
|
18
|
+
//# sourceMappingURL=png_filter_unFilterAverage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"png_filter_unFilterAverage.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,qDAVW,UAAU,mBACV,MAAM,UACN,UAAU,OACV,MAAM,UACN,MAAM,0BACN,MAAM,UACN,MAAM,QA8ChB"}
|