imagescript 3.8.0 → 3.8.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/dist/codecs/gif.js +21 -40
- package/dist/codecs/jpeg.js +54 -32
- package/dist/codecs/png.js +58 -6
- package/dist/codecs/vp8.js +21 -17
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/codecs/gif.js
CHANGED
|
@@ -271,17 +271,11 @@ function lzwDecode(data, minCodeSize, pixelCount) {
|
|
|
271
271
|
return output;
|
|
272
272
|
const clear = 1 << minCodeSize;
|
|
273
273
|
const eoi = clear + 1;
|
|
274
|
-
const
|
|
275
|
-
const
|
|
276
|
-
const first = new Uint8Array(4096);
|
|
277
|
-
const lengths = new Uint16Array(4096);
|
|
278
|
-
for (let i = 0; i < clear; i++) {
|
|
279
|
-
suffix[i] = first[i] = i;
|
|
280
|
-
lengths[i] = 1;
|
|
281
|
-
}
|
|
274
|
+
const positions = new Int32Array(4096);
|
|
275
|
+
const lengths = new Uint16Array(4096).fill(1, 0, clear);
|
|
282
276
|
let codeSize = minCodeSize + 1;
|
|
283
277
|
let next = eoi + 1;
|
|
284
|
-
let previous = -1;
|
|
278
|
+
let previous = -1, previousOut = 0;
|
|
285
279
|
let buffer = 0, bufferBits = 0, position = 0, out = 0;
|
|
286
280
|
while (out < pixelCount) {
|
|
287
281
|
while (bufferBits < codeSize) {
|
|
@@ -301,49 +295,36 @@ function lzwDecode(data, minCodeSize, pixelCount) {
|
|
|
301
295
|
}
|
|
302
296
|
if (code === eoi)
|
|
303
297
|
break;
|
|
304
|
-
|
|
305
|
-
if (code < next)
|
|
306
|
-
entry = code;
|
|
307
|
-
else if (code === next && previous !== -1)
|
|
308
|
-
entry = previous;
|
|
309
|
-
else
|
|
298
|
+
if (code > next || (code === next && previous === -1))
|
|
310
299
|
break;
|
|
311
300
|
if (previous === -1 && code >= clear)
|
|
312
301
|
break;
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (end === out + length) {
|
|
317
|
-
for (let i = end - 1; i >= out; i--) {
|
|
318
|
-
output[i] = suffix[c];
|
|
319
|
-
c = prefix[c];
|
|
320
|
-
}
|
|
321
|
-
}
|
|
302
|
+
const start = out;
|
|
303
|
+
if (code < clear)
|
|
304
|
+
output[out++] = code;
|
|
322
305
|
else {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
306
|
+
const kwk = code === next;
|
|
307
|
+
const from = kwk ? previousOut : positions[code];
|
|
308
|
+
const length = kwk ? lengths[previous] + 1 : lengths[code];
|
|
309
|
+
const count = Math.min(length, pixelCount - out) - (kwk ? 1 : 0);
|
|
310
|
+
if (count < 16)
|
|
311
|
+
for (let i = 0; i < count; i++)
|
|
312
|
+
output[out + i] = output[from + i];
|
|
313
|
+
else
|
|
314
|
+
output.copyWithin(out, from, from + count);
|
|
315
|
+
if (kwk && out + count < pixelCount)
|
|
316
|
+
output[out + count] = output[from];
|
|
317
|
+
out = Math.min(out + length, pixelCount);
|
|
335
318
|
}
|
|
336
|
-
out += written;
|
|
337
319
|
if (previous !== -1 && next <= MAX_CODE) {
|
|
338
|
-
|
|
339
|
-
suffix[next] = first[code === next ? previous : code];
|
|
340
|
-
first[next] = first[previous];
|
|
320
|
+
positions[next] = previousOut;
|
|
341
321
|
lengths[next] = lengths[previous] + 1;
|
|
342
322
|
next++;
|
|
343
323
|
if (next === 1 << codeSize && codeSize < 12)
|
|
344
324
|
codeSize++;
|
|
345
325
|
}
|
|
346
326
|
previous = code;
|
|
327
|
+
previousOut = start;
|
|
347
328
|
}
|
|
348
329
|
return output;
|
|
349
330
|
}
|
package/dist/codecs/jpeg.js
CHANGED
|
@@ -8,6 +8,7 @@ import { ByteWriter } from "../util/bytes.js";
|
|
|
8
8
|
import { MAX_PIXELS, checkPixels } from "../util/limits.js";
|
|
9
9
|
import { orientation as exifOrientation } from "./exif.js";
|
|
10
10
|
import { concat } from "../util/mem.js";
|
|
11
|
+
import { littleEndian } from "../util/alpha.js";
|
|
11
12
|
const ZIGZAG = Int32Array.of(0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63);
|
|
12
13
|
function clamp8(v) {
|
|
13
14
|
return v < 0 ? 0 : v > 255 ? 255 : v;
|
|
@@ -610,6 +611,9 @@ for (let i = 0; i < 256; i++) {
|
|
|
610
611
|
crG[i] = -46802 * x;
|
|
611
612
|
cbG[i] = -22554 * x + 32768;
|
|
612
613
|
}
|
|
614
|
+
const CLAMP_OFFSET = 256, CLAMP = new Uint8Array(768);
|
|
615
|
+
for (let i = 0; i < 768; i++)
|
|
616
|
+
CLAMP[i] = clamp8(i - CLAMP_OFFSET);
|
|
613
617
|
function output(frame, adobe, jfif, override) {
|
|
614
618
|
const { width, height, components } = frame;
|
|
615
619
|
const planes = components.map(component => upsample(component, frame));
|
|
@@ -633,27 +637,45 @@ function output(frame, adobe, jfif, override) {
|
|
|
633
637
|
else
|
|
634
638
|
throw new Error(`JPEG: ${count} color components are not supported`);
|
|
635
639
|
const [p0, p1, p2, p3] = planes;
|
|
640
|
+
if (transform === 'grey' || transform === 'rgb' || transform === 'ycc') {
|
|
641
|
+
const s0 = p0.samples, s1 = (p1 ?? p0).samples, s2 = (p2 ?? p0).samples;
|
|
642
|
+
const grey = transform === 'grey', ycc = transform === 'ycc';
|
|
643
|
+
const words = littleEndian ? new Uint32Array(pixels.buffer) : null;
|
|
644
|
+
for (let y = 0, o = 0; y < height; y++, o = y * width * 4) {
|
|
645
|
+
const r0 = y * p0.stride, r1 = p1 ? y * p1.stride : r0, r2 = p2 ? y * p2.stride : r0;
|
|
646
|
+
if (grey)
|
|
647
|
+
for (let x = 0; x < width; x++, o += 4) {
|
|
648
|
+
pixels[o] = pixels[o + 1] = pixels[o + 2] = s0[r0 + x];
|
|
649
|
+
pixels[o + 3] = 0xff;
|
|
650
|
+
}
|
|
651
|
+
else if (ycc && words)
|
|
652
|
+
for (let x = 0, w = o >> 2; x < width; x++, w++) {
|
|
653
|
+
const a = s0[r0 + x] + CLAMP_OFFSET, b = s1[r1 + x], c = s2[r2 + x];
|
|
654
|
+
words[w] = (CLAMP[a + crR[c]] | CLAMP[a + (cbG[b] + crG[c] >> 16)] << 8 | CLAMP[a + cbB[b]] << 16 | 0xff000000) >>> 0;
|
|
655
|
+
}
|
|
656
|
+
else if (ycc)
|
|
657
|
+
for (let x = 0; x < width; x++, o += 4) {
|
|
658
|
+
const a = s0[r0 + x] + CLAMP_OFFSET, b = s1[r1 + x], c = s2[r2 + x];
|
|
659
|
+
pixels[o] = CLAMP[a + crR[c]];
|
|
660
|
+
pixels[o + 1] = CLAMP[a + (cbG[b] + crG[c] >> 16)];
|
|
661
|
+
pixels[o + 2] = CLAMP[a + cbB[b]];
|
|
662
|
+
pixels[o + 3] = 0xff;
|
|
663
|
+
}
|
|
664
|
+
else
|
|
665
|
+
for (let x = 0; x < width; x++, o += 4) {
|
|
666
|
+
pixels[o] = s0[r0 + x];
|
|
667
|
+
pixels[o + 1] = s1[r1 + x];
|
|
668
|
+
pixels[o + 2] = s2[r2 + x];
|
|
669
|
+
pixels[o + 3] = 0xff;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return pixels;
|
|
673
|
+
}
|
|
636
674
|
for (let y = 0, o = 0; y < height; y++) {
|
|
637
|
-
const r0 = y * p0.stride, r1 =
|
|
675
|
+
const r0 = y * p0.stride, r1 = y * p1.stride, r2 = y * p2.stride, r3 = y * p3.stride;
|
|
638
676
|
for (let x = 0; x < width; x++, o += 4) {
|
|
639
677
|
pixels[o + 3] = 0xff;
|
|
640
|
-
if (transform === 'grey') {
|
|
641
|
-
pixels[o] = pixels[o + 1] = pixels[o + 2] = p0.samples[r0 + x];
|
|
642
|
-
continue;
|
|
643
|
-
}
|
|
644
678
|
const a = p0.samples[r0 + x], b = p1.samples[r1 + x], c = p2.samples[r2 + x];
|
|
645
|
-
if (transform === 'rgb') {
|
|
646
|
-
pixels[o] = a;
|
|
647
|
-
pixels[o + 1] = b;
|
|
648
|
-
pixels[o + 2] = c;
|
|
649
|
-
continue;
|
|
650
|
-
}
|
|
651
|
-
if (transform === 'ycc') {
|
|
652
|
-
pixels[o] = clamp8(a + crR[c]);
|
|
653
|
-
pixels[o + 1] = clamp8(a + (cbG[b] + crG[c] >> 16));
|
|
654
|
-
pixels[o + 2] = clamp8(a + cbB[b]);
|
|
655
|
-
continue;
|
|
656
|
-
}
|
|
657
679
|
let cyan = a, magenta = b, yellow = c, k = p3.samples[r3 + x];
|
|
658
680
|
if (transform === 'ycck') {
|
|
659
681
|
cyan = 255 - clamp8(a + crR[c]);
|
|
@@ -745,7 +767,7 @@ export function encode(pixels, width, height, quality = 90, { exif, comment } =
|
|
|
745
767
|
const blocksPerMcu = hmax * hmax + 2;
|
|
746
768
|
const count = mcusPerLine * mcusPerColumn * blocksPerMcu;
|
|
747
769
|
const coefficients = new Int16Array(count * 64);
|
|
748
|
-
const owners = new Uint8Array(count);
|
|
770
|
+
const owners = new Uint8Array(count), ends = new Uint8Array(count);
|
|
749
771
|
const block = new Float64Array(64);
|
|
750
772
|
let n = 0;
|
|
751
773
|
for (let my = 0; my < mcusPerColumn; my++)
|
|
@@ -763,12 +785,18 @@ export function encode(pixels, width, height, quality = 90, { exif, comment } =
|
|
|
763
785
|
}
|
|
764
786
|
fdct(block);
|
|
765
787
|
const o = n * 64;
|
|
766
|
-
|
|
767
|
-
|
|
788
|
+
let end = 0;
|
|
789
|
+
for (let k = 0; k < 64; k++) {
|
|
790
|
+
const i = ZIGZAG[k], value = (block[i] * d[i] + 16384.5 | 0) - 16384;
|
|
791
|
+
coefficients[o + k] = value;
|
|
792
|
+
if (value)
|
|
793
|
+
end = k;
|
|
794
|
+
}
|
|
768
795
|
owners[n] = c;
|
|
796
|
+
ends[n] = end;
|
|
769
797
|
}
|
|
770
798
|
}
|
|
771
|
-
const blocks = { coefficients, owners, count };
|
|
799
|
+
const blocks = { coefficients, owners, ends, count };
|
|
772
800
|
const frequencies = [new Int32Array(257), new Int32Array(257), new Int32Array(257), new Int32Array(257)];
|
|
773
801
|
encodeBlocks(blocks, (table, symbol) => frequencies[table][symbol]++, () => { });
|
|
774
802
|
const huffman = frequencies.map(buildOptimalTable);
|
|
@@ -809,7 +837,7 @@ export function encode(pixels, width, height, quality = 90, { exif, comment } =
|
|
|
809
837
|
writer.bytes(0xff, 0xd9);
|
|
810
838
|
return writer.finish();
|
|
811
839
|
}
|
|
812
|
-
function encodeBlocks({ coefficients, owners, count }, symbol, bits) {
|
|
840
|
+
function encodeBlocks({ coefficients, owners, ends, count }, symbol, bits) {
|
|
813
841
|
const pred = [0, 0, 0];
|
|
814
842
|
for (let n = 0; n < count; n++) {
|
|
815
843
|
const component = owners[n];
|
|
@@ -823,8 +851,8 @@ function encodeBlocks({ coefficients, owners, count }, symbol, bits) {
|
|
|
823
851
|
if (size)
|
|
824
852
|
bits(diff < 0 ? diff - 1 & (1 << size) - 1 : diff, size);
|
|
825
853
|
let run = 0;
|
|
826
|
-
for (let k = 1; k
|
|
827
|
-
const value = coefficients[o +
|
|
854
|
+
for (let k = 1, end = ends[n]; k <= end; k++) {
|
|
855
|
+
const value = coefficients[o + k];
|
|
828
856
|
if (value === 0) {
|
|
829
857
|
run++;
|
|
830
858
|
continue;
|
|
@@ -838,18 +866,12 @@ function encodeBlocks({ coefficients, owners, count }, symbol, bits) {
|
|
|
838
866
|
bits(value < 0 ? value - 1 & (1 << s) - 1 : value, s);
|
|
839
867
|
run = 0;
|
|
840
868
|
}
|
|
841
|
-
if (
|
|
869
|
+
if (ends[n] < 63)
|
|
842
870
|
symbol(acTable, 0x00);
|
|
843
871
|
}
|
|
844
872
|
}
|
|
845
873
|
function magnitude(value) {
|
|
846
|
-
|
|
847
|
-
let size = 0;
|
|
848
|
-
while (value) {
|
|
849
|
-
size++;
|
|
850
|
-
value >>= 1;
|
|
851
|
-
}
|
|
852
|
-
return size;
|
|
874
|
+
return 32 - Math.clz32(Math.abs(value));
|
|
853
875
|
}
|
|
854
876
|
function buildOptimalTable(frequencies) {
|
|
855
877
|
const freq = Int32Array.from(frequencies);
|
package/dist/codecs/png.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { crc32 } from "./crc.js";
|
|
2
2
|
import { MAX_PIXELS, checkPixels } from "../util/limits.js";
|
|
3
3
|
import { concat } from "../util/mem.js";
|
|
4
|
+
import { littleEndian } from "../util/alpha.js";
|
|
4
5
|
import { encode as utf8, decode as utf8Decode } from "../util/utf8.js";
|
|
5
6
|
import { orientation as exifOrientation, xmpOrientation } from "./exif.js";
|
|
6
7
|
import { compressAsync, decompressAsync } from "./zlib.js";
|
|
@@ -648,12 +649,15 @@ function unfilter(data, offset, height, rowBytes, bpp, inPlace = false) {
|
|
|
648
649
|
else {
|
|
649
650
|
for (let i = row; i < row + first; i++)
|
|
650
651
|
out[i] = data[src + i] + out[i - rowBytes];
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
652
|
+
if (bpp === 3 || bpp === 4)
|
|
653
|
+
paethRow(data, src, out, row, rowBytes, bpp);
|
|
654
|
+
else
|
|
655
|
+
for (let i = row + bpp; i < row + rowBytes; i++) {
|
|
656
|
+
const a = out[i - bpp], b = out[i - rowBytes], c = out[i - rowBytes - bpp];
|
|
657
|
+
const pa = Math.abs(b - c), pb = Math.abs(a - c), pc = Math.abs(a + b - 2 * c);
|
|
658
|
+
const notA = (pb - pa | pc - pa) >> 31, takeC = (pc - pb) >> 31;
|
|
659
|
+
out[i] = data[src + i] + (a ^ (a ^ b ^ (b ^ c) & takeC) & notA);
|
|
660
|
+
}
|
|
657
661
|
}
|
|
658
662
|
}
|
|
659
663
|
else
|
|
@@ -662,6 +666,47 @@ function unfilter(data, offset, height, rowBytes, bpp, inPlace = false) {
|
|
|
662
666
|
}
|
|
663
667
|
return out;
|
|
664
668
|
}
|
|
669
|
+
function paethRow(data, src, out, row, rowBytes, bpp) {
|
|
670
|
+
const up = row - rowBytes, end = row + rowBytes;
|
|
671
|
+
let a0 = out[row], a1 = out[row + 1], a2 = out[row + 2], a3 = bpp === 4 ? out[row + 3] : 0;
|
|
672
|
+
let c0 = out[up], c1 = out[up + 1], c2 = out[up + 2], c3 = bpp === 4 ? out[up + 3] : 0;
|
|
673
|
+
for (let i = row + bpp; i < end; i += bpp) {
|
|
674
|
+
let b = out[i - rowBytes], pa = Math.abs(b - c0), pb = Math.abs(a0 - c0), pc = Math.abs(a0 + b - 2 * c0);
|
|
675
|
+
let notA = (pb - pa | pc - pa) >> 31, takeC = (pc - pb) >> 31;
|
|
676
|
+
a0 = data[src + i] + (a0 ^ (a0 ^ b ^ (b ^ c0) & takeC) & notA) & 255;
|
|
677
|
+
out[i] = a0;
|
|
678
|
+
c0 = b;
|
|
679
|
+
b = out[i + 1 - rowBytes];
|
|
680
|
+
pa = Math.abs(b - c1);
|
|
681
|
+
pb = Math.abs(a1 - c1);
|
|
682
|
+
pc = Math.abs(a1 + b - 2 * c1);
|
|
683
|
+
notA = (pb - pa | pc - pa) >> 31;
|
|
684
|
+
takeC = (pc - pb) >> 31;
|
|
685
|
+
a1 = data[src + i + 1] + (a1 ^ (a1 ^ b ^ (b ^ c1) & takeC) & notA) & 255;
|
|
686
|
+
out[i + 1] = a1;
|
|
687
|
+
c1 = b;
|
|
688
|
+
b = out[i + 2 - rowBytes];
|
|
689
|
+
pa = Math.abs(b - c2);
|
|
690
|
+
pb = Math.abs(a2 - c2);
|
|
691
|
+
pc = Math.abs(a2 + b - 2 * c2);
|
|
692
|
+
notA = (pb - pa | pc - pa) >> 31;
|
|
693
|
+
takeC = (pc - pb) >> 31;
|
|
694
|
+
a2 = data[src + i + 2] + (a2 ^ (a2 ^ b ^ (b ^ c2) & takeC) & notA) & 255;
|
|
695
|
+
out[i + 2] = a2;
|
|
696
|
+
c2 = b;
|
|
697
|
+
if (bpp === 4) {
|
|
698
|
+
b = out[i + 3 - rowBytes];
|
|
699
|
+
pa = Math.abs(b - c3);
|
|
700
|
+
pb = Math.abs(a3 - c3);
|
|
701
|
+
pc = Math.abs(a3 + b - 2 * c3);
|
|
702
|
+
notA = (pb - pa | pc - pa) >> 31;
|
|
703
|
+
takeC = (pc - pb) >> 31;
|
|
704
|
+
a3 = data[src + i + 3] + (a3 ^ (a3 ^ b ^ (b ^ c3) & takeC) & notA) & 255;
|
|
705
|
+
out[i + 3] = a3;
|
|
706
|
+
c3 = b;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
665
710
|
function createConverter(colorType, depth, palette, transparency) {
|
|
666
711
|
const maxValue = (1 << depth) - 1;
|
|
667
712
|
const sample = depth === 8 ? (row, n) => row[n]
|
|
@@ -717,6 +762,13 @@ function createConverter(colorType, depth, palette, transparency) {
|
|
|
717
762
|
if (depth === 8) {
|
|
718
763
|
const [kr, kg, kb] = key || [-1, -1, -1];
|
|
719
764
|
return (pixels, rowBytes, w, h, out, place) => {
|
|
765
|
+
if (!key && place.step === 4 && littleEndian && !(out.byteOffset & 3)) {
|
|
766
|
+
const words = new Uint32Array(out.buffer, out.byteOffset, out.length >> 2);
|
|
767
|
+
for (let y = 0; y < h; y++)
|
|
768
|
+
for (let x = 0, s = y * rowBytes, o = place.row(y) >> 2; x < w; x++, s += 3, o++)
|
|
769
|
+
words[o] = (pixels[s] | pixels[s + 1] << 8 | pixels[s + 2] << 16 | 0xff000000) >>> 0;
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
720
772
|
for (let y = 0; y < h; y++) {
|
|
721
773
|
for (let x = 0, s = y * rowBytes, o = place.row(y), step = place.step; x < w; x++, s += 3, o += step) {
|
|
722
774
|
const r = pixels[s], g = pixels[s + 1], b = pixels[s + 2];
|
package/dist/codecs/vp8.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { KF_BMODE_PROBS, COEFF_UPDATE_PROBS, DEFAULT_COEFF_PROBS, DC_QLOOKUP, AC_QLOOKUP, PCAT } from "./vp8-tables.js";
|
|
2
2
|
import { MAX_PIXELS, checkPixels } from "../util/limits.js";
|
|
3
|
+
import { littleEndian } from "../util/alpha.js";
|
|
3
4
|
class BoolDecoder {
|
|
4
5
|
data;
|
|
5
6
|
pos;
|
|
@@ -661,43 +662,46 @@ function loopFilter(h, Y, U, V, ys, cs, mbw, mbh, segments, inner, bpred) {
|
|
|
661
662
|
}
|
|
662
663
|
const multHi = (v, coeff) => v * coeff >> 8;
|
|
663
664
|
const clip8 = (v) => (v & ~16383) === 0 ? v >> 6 : v < 0 ? 0 : 255;
|
|
664
|
-
function
|
|
665
|
+
function yuvToWord(y, u, v) {
|
|
665
666
|
const yy = multHi(y, 19077);
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
out[o + 2] = clip8(yy + multHi(u, 33050) - 17685);
|
|
669
|
-
out[o + 3] = 255;
|
|
667
|
+
return (clip8(yy + multHi(v, 26149) - 14234) | clip8(yy - multHi(u, 6419) - multHi(v, 13320) + 8708) << 8
|
|
668
|
+
| clip8(yy + multHi(u, 33050) - 17685) << 16 | 0xff000000) >>> 0;
|
|
670
669
|
}
|
|
671
670
|
function toRGBA(Y, U, V, ys, cs, width, height) {
|
|
672
|
-
const out = new
|
|
671
|
+
const out = new Uint32Array(width * height);
|
|
673
672
|
const yRow = (y) => (y + 1) * ys + 1;
|
|
674
673
|
const cRow = (y) => (y + 1) * cs + 1;
|
|
675
674
|
const lastChroma = (height + 1 >> 1) - 1;
|
|
676
675
|
upsamplePair(Y, U, V, yRow(0), -1, cRow(0), cRow(0), out, 0, -1, width);
|
|
677
676
|
for (let y = 1; y + 1 < height; y += 2) {
|
|
678
677
|
const k = y + 1 >> 1;
|
|
679
|
-
upsamplePair(Y, U, V, yRow(y), yRow(y + 1), cRow(k - 1), cRow(k), out, y * width
|
|
678
|
+
upsamplePair(Y, U, V, yRow(y), yRow(y + 1), cRow(k - 1), cRow(k), out, y * width, (y + 1) * width, width);
|
|
680
679
|
}
|
|
681
680
|
if (!(height & 1))
|
|
682
|
-
upsamplePair(Y, U, V, yRow(height - 1), -1, cRow(lastChroma), cRow(lastChroma), out, (height - 1) * width
|
|
683
|
-
|
|
681
|
+
upsamplePair(Y, U, V, yRow(height - 1), -1, cRow(lastChroma), cRow(lastChroma), out, (height - 1) * width, -1, width);
|
|
682
|
+
if (!littleEndian)
|
|
683
|
+
for (let i = 0; i < out.length; i++) {
|
|
684
|
+
const w = out[i];
|
|
685
|
+
out[i] = (w << 24 | (w & 0xff00) << 8 | w >>> 8 & 0xff00 | w >>> 24) >>> 0;
|
|
686
|
+
}
|
|
687
|
+
return new Uint8Array(out.buffer);
|
|
684
688
|
}
|
|
685
689
|
function upsamplePair(Y, U, V, topY, bottomY, topC, curC, out, topOut, bottomOut, width) {
|
|
686
690
|
let tlu = U[topC], tlv = V[topC], lu = U[curC], lv = V[curC];
|
|
687
|
-
|
|
691
|
+
out[topOut] = yuvToWord(Y[topY], 3 * tlu + lu + 2 >> 2, 3 * tlv + lv + 2 >> 2);
|
|
688
692
|
if (bottomY >= 0)
|
|
689
|
-
|
|
693
|
+
out[bottomOut] = yuvToWord(Y[bottomY], 3 * lu + tlu + 2 >> 2, 3 * lv + tlv + 2 >> 2);
|
|
690
694
|
const pairs = width - 1 >> 1;
|
|
691
695
|
for (let x = 1; x <= pairs; x++) {
|
|
692
696
|
const tu = U[topC + x], tv = V[topC + x], u = U[curC + x], v = V[curC + x];
|
|
693
697
|
const avgU = tlu + tu + lu + u + 8, avgV = tlv + tv + lv + v + 8;
|
|
694
698
|
const d12u = avgU + 2 * (tu + lu) >> 3, d03u = avgU + 2 * (tlu + u) >> 3;
|
|
695
699
|
const d12v = avgV + 2 * (tv + lv) >> 3, d03v = avgV + 2 * (tlv + v) >> 3;
|
|
696
|
-
|
|
697
|
-
|
|
700
|
+
out[topOut + 2 * x - 1] = yuvToWord(Y[topY + 2 * x - 1], d12u + tlu >> 1, d12v + tlv >> 1);
|
|
701
|
+
out[topOut + 2 * x] = yuvToWord(Y[topY + 2 * x], d03u + tu >> 1, d03v + tv >> 1);
|
|
698
702
|
if (bottomY >= 0) {
|
|
699
|
-
|
|
700
|
-
|
|
703
|
+
out[bottomOut + 2 * x - 1] = yuvToWord(Y[bottomY + 2 * x - 1], d03u + lu >> 1, d03v + lv >> 1);
|
|
704
|
+
out[bottomOut + 2 * x] = yuvToWord(Y[bottomY + 2 * x], d12u + u >> 1, d12v + v >> 1);
|
|
701
705
|
}
|
|
702
706
|
tlu = tu;
|
|
703
707
|
tlv = tv;
|
|
@@ -706,8 +710,8 @@ function upsamplePair(Y, U, V, topY, bottomY, topC, curC, out, topOut, bottomOut
|
|
|
706
710
|
}
|
|
707
711
|
if (!(width & 1)) {
|
|
708
712
|
const x = width - 1;
|
|
709
|
-
|
|
713
|
+
out[topOut + x] = yuvToWord(Y[topY + x], 3 * tlu + lu + 2 >> 2, 3 * tlv + lv + 2 >> 2);
|
|
710
714
|
if (bottomY >= 0)
|
|
711
|
-
|
|
715
|
+
out[bottomOut + x] = yuvToWord(Y[bottomY + x], 3 * lu + tlu + 2 >> 2, 3 * lv + tlv + 2 >> 2);
|
|
712
716
|
}
|
|
713
717
|
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '3.8.
|
|
1
|
+
export const VERSION = '3.8.1';
|