@poe-platform/safe-bash 0.1.835 → 0.1.836
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/image-ast/browser/codecs/gif-output-parts.d.ts +2 -0
- package/dist/image-ast/browser/codecs/gif-storage.d.ts +1 -1
- package/dist/image-ast/codecs/gif-output-parts.d.ts +2 -0
- package/dist/image-ast/codecs/gif-storage.d.ts +1 -1
- package/dist/image-ast/index.js +62 -1
- package/dist/safe-bash/command-chunks/{chunk-GQQUZGIZ.js → chunk-FH5VMAPS.js} +99287 -51054
- package/dist/safe-bash/command-chunks/{chunk-THJIIMGT.js → chunk-RSFKQE2U.js} +1 -1
- package/dist/safe-bash-command-ffmpeg/index.js +1 -1
- package/dist/safe-bash-command-ffprobe/index.js +2 -2
- package/dist/safe-bash-command-ffprobe/media.js +2 -2
- package/dist/safe-bash-command-imagemagick/index.js +345 -158
- package/package.json +2 -2
|
@@ -11,6 +11,8 @@ export declare class GifPalette {
|
|
|
11
11
|
private readonly colors;
|
|
12
12
|
private readonly used;
|
|
13
13
|
private readonly missing;
|
|
14
|
+
private readonly histogram;
|
|
15
|
+
private quantized?;
|
|
14
16
|
constructor();
|
|
15
17
|
add(r: number, g: number, b: number, a: number): void;
|
|
16
18
|
finish(): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ImageByteStorage, StoredRgbaImage } from "./png-storage.js";
|
|
2
2
|
import { type GifOptions } from "./gif-output-parts.js";
|
|
3
|
-
/** Multipass GIF encoding with a
|
|
3
|
+
/** Multipass GIF encoding with a source-derived palette and pull-driven owned subblocks. */
|
|
4
4
|
export declare function encodeGifFromStorage(image: StoredRgbaImage, storage: ImageByteStorage, signal: AbortSignal, options?: GifOptions): AsyncGenerator<Uint8Array<ArrayBufferLike>, void, unknown>;
|
|
@@ -11,6 +11,8 @@ export declare class GifPalette {
|
|
|
11
11
|
private readonly colors;
|
|
12
12
|
private readonly used;
|
|
13
13
|
private readonly missing;
|
|
14
|
+
private readonly histogram;
|
|
15
|
+
private quantized?;
|
|
14
16
|
constructor();
|
|
15
17
|
add(r: number, g: number, b: number, a: number): void;
|
|
16
18
|
finish(): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ImageByteStorage, StoredRgbaImage } from "./png-storage.js";
|
|
2
2
|
import { type GifOptions } from "./gif-output-parts.js";
|
|
3
|
-
/** Multipass GIF encoding with a
|
|
3
|
+
/** Multipass GIF encoding with a source-derived palette and pull-driven owned subblocks. */
|
|
4
4
|
export declare function encodeGifFromStorage(image: StoredRgbaImage, storage: ImageByteStorage, signal: AbortSignal, options?: GifOptions): AsyncGenerator<Uint8Array<ArrayBufferLike>, void, unknown>;
|
package/dist/image-ast/index.js
CHANGED
|
@@ -5394,12 +5394,66 @@ function decodeWebpImage(bytes) {
|
|
|
5394
5394
|
};
|
|
5395
5395
|
}
|
|
5396
5396
|
|
|
5397
|
+
// src/codecs/gif-quantization.ts
|
|
5398
|
+
function quantizeGif(histogram, palette) {
|
|
5399
|
+
let bins = [];
|
|
5400
|
+
for (let id = 0; id < 32768; id++) {
|
|
5401
|
+
let at = id * 4, count = histogram[at + 3];
|
|
5402
|
+
count && bins.push([
|
|
5403
|
+
histogram[at] / count,
|
|
5404
|
+
histogram[at + 1] / count,
|
|
5405
|
+
histogram[at + 2] / count,
|
|
5406
|
+
count,
|
|
5407
|
+
id
|
|
5408
|
+
]);
|
|
5409
|
+
}
|
|
5410
|
+
let box2 = (colors) => {
|
|
5411
|
+
let sum = [0, 0, 0], squares = [0, 0, 0], count = 0;
|
|
5412
|
+
for (let color of colors) {
|
|
5413
|
+
count += color[3];
|
|
5414
|
+
for (let c = 0; c < 3; c++)
|
|
5415
|
+
sum[c] += color[c] * color[3], squares[c] += color[c] ** 2 * color[3];
|
|
5416
|
+
}
|
|
5417
|
+
let variance = squares.map((value, c) => Math.max(0, value - sum[c] ** 2 / count)), axis = variance.indexOf(Math.max(...variance));
|
|
5418
|
+
return { colors, count, sum, axis, error: colors.length > 1 ? variance[axis] : 0 };
|
|
5419
|
+
}, boxes = [box2(bins)];
|
|
5420
|
+
for (; boxes.length < 254; ) {
|
|
5421
|
+
let best = 0;
|
|
5422
|
+
for (let i = 1; i < boxes.length; i++) boxes[i].error > boxes[best].error && (best = i);
|
|
5423
|
+
let current = boxes[best];
|
|
5424
|
+
if (current.error <= 0) break;
|
|
5425
|
+
current.colors.sort((a, b) => a[current.axis] - b[current.axis]);
|
|
5426
|
+
let count = 0, split = 0;
|
|
5427
|
+
do
|
|
5428
|
+
count += current.colors[split++][3];
|
|
5429
|
+
while (count < current.count / 2 && split < current.colors.length - 1);
|
|
5430
|
+
boxes[best] = box2(current.colors.slice(0, split)), boxes.push(box2(current.colors.slice(split)));
|
|
5431
|
+
}
|
|
5432
|
+
palette.fill(0, 0, 762);
|
|
5433
|
+
for (let i = 0; i < boxes.length; i++)
|
|
5434
|
+
for (let c = 0; c < 3; c++)
|
|
5435
|
+
palette[i * 3 + c] = Math.round(boxes[i].sum[c] / boxes[i].count);
|
|
5436
|
+
let indices2 = new Uint8Array(32768);
|
|
5437
|
+
for (let color of bins) {
|
|
5438
|
+
let distance = 1 / 0, nearest = 0;
|
|
5439
|
+
for (let i = 0; i <= boxes.length; i++) {
|
|
5440
|
+
let index = i === boxes.length ? 254 : i, error = 0;
|
|
5441
|
+
for (let c = 0; c < 3; c++) error += (color[c] - palette[index * 3 + c]) ** 2;
|
|
5442
|
+
error < distance && (distance = error, nearest = index);
|
|
5443
|
+
}
|
|
5444
|
+
indices2[color[4]] = nearest;
|
|
5445
|
+
}
|
|
5446
|
+
return indices2;
|
|
5447
|
+
}
|
|
5448
|
+
|
|
5397
5449
|
// src/codecs/gif-output-parts.ts
|
|
5398
5450
|
var GifPalette = class {
|
|
5399
5451
|
bytes = new Uint8Array(768);
|
|
5400
5452
|
colors = /* @__PURE__ */ new Map();
|
|
5401
5453
|
used = /* @__PURE__ */ new Set();
|
|
5402
5454
|
missing = /* @__PURE__ */ new Set();
|
|
5455
|
+
histogram = new Float64Array(32768 * 4);
|
|
5456
|
+
quantized;
|
|
5403
5457
|
constructor() {
|
|
5404
5458
|
for (let i = 0; i < 254; i++) {
|
|
5405
5459
|
let r = Math.round((i >>> 5 & 7) * 255 / 7), g = Math.round((i >>> 2 & 7) * 255 / 7), b = Math.round((i & 3) * 255 / 3);
|
|
@@ -5409,6 +5463,10 @@ var GifPalette = class {
|
|
|
5409
5463
|
}
|
|
5410
5464
|
add(r, g, b, a) {
|
|
5411
5465
|
if (a < 128) return;
|
|
5466
|
+
if (r !== 255 || g !== 255 || b !== 255) {
|
|
5467
|
+
let at = (r >>> 3 << 10 | g >>> 3 << 5 | b >>> 3) * 4;
|
|
5468
|
+
this.histogram[at] += r, this.histogram[at + 1] += g, this.histogram[at + 2] += b, this.histogram[at + 3]++;
|
|
5469
|
+
}
|
|
5412
5470
|
let key = r << 16 | g << 8 | b, existing = this.colors.get(key);
|
|
5413
5471
|
existing !== void 0 ? this.used.add(existing) : this.missing.size < 255 && this.missing.add(key);
|
|
5414
5472
|
}
|
|
@@ -5420,10 +5478,13 @@ var GifPalette = class {
|
|
|
5420
5478
|
if (probe >= 254) break;
|
|
5421
5479
|
this.used.add(probe), this.colors.set(key, probe), this.bytes.set([key >>> 16 & 255, key >>> 8 & 255, key & 255], probe * 3);
|
|
5422
5480
|
}
|
|
5423
|
-
}
|
|
5481
|
+
} else
|
|
5482
|
+
this.quantized = quantizeGif(this.histogram, this.bytes);
|
|
5424
5483
|
}
|
|
5425
5484
|
index(r, g, b, a) {
|
|
5426
5485
|
if (a < 128) return 255;
|
|
5486
|
+
if (this.quantized)
|
|
5487
|
+
return r === 255 && g === 255 && b === 255 ? 254 : this.quantized[r >>> 3 << 10 | g >>> 3 << 5 | b >>> 3];
|
|
5427
5488
|
let exact = this.colors.get(r << 16 | g << 8 | b);
|
|
5428
5489
|
if (exact !== void 0) return exact;
|
|
5429
5490
|
let value = r >>> 5 << 5 | g >>> 5 << 2 | b >>> 6;
|