imagescript 1.3.0 → 3.0.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 +64 -26
- package/THIRD_PARTY_NOTICES.md +74 -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 +44 -0
- package/dist/codecs/png.js +442 -0
- package/dist/codecs/quantize.d.ts +25 -0
- package/dist/codecs/quantize.js +302 -0
- package/dist/codecs/tiff.d.ts +6 -0
- package/dist/codecs/tiff.js +546 -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 +44 -0
- package/dist/gif.js +93 -0
- package/dist/image-type.d.ts +20 -0
- package/dist/image-type.js +49 -0
- package/dist/image.d.ts +521 -0
- package/dist/image.js +1118 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +13 -0
- package/dist/package.json +1 -0
- package/dist/render/font.d.ts +63 -0
- package/dist/render/font.js +857 -0
- package/dist/render/svg.d.ts +11 -0
- package/dist/render/svg.js +1717 -0
- package/dist/render/text.d.ts +61 -0
- package/dist/render/text.js +317 -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/README.ijg +260 -0
- package/package.json +31 -7
- package/ImageScript.d.ts +0 -235
- 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/tests/gif.js +0 -0
- package/codecs/tests/jpeg.js +0 -0
- package/codecs/tests/png.js +0 -0
- package/codecs/tests/results/gif/1024.nis.gif +0 -0
- package/codecs/tests/results/gif/1024.skyra.gif +0 -0
- package/codecs/tests/results/gif/256.nis.gif +0 -0
- package/codecs/tests/results/gif/256.skyra.gif +0 -0
- package/codecs/tests/results/jpeg/256.jpegjs.jpeg +0 -0
- package/codecs/tests/results/jpeg/256.nis.jpeg +0 -0
- package/codecs/tests/results/jpeg/256.sharp.jpeg +0 -0
- package/codecs/tests/results/jpeg/512.jpegjs.jpeg +0 -0
- package/codecs/tests/results/jpeg/512.nis.jpeg +0 -0
- package/codecs/tests/results/jpeg/512.sharp.jpeg +0 -0
- package/codecs/tests/results/jpeg/64.jpegjs.jpeg +0 -0
- package/codecs/tests/results/jpeg/64.nis.jpeg +0 -0
- package/codecs/tests/results/jpeg/64.sharp.jpeg +0 -0
- package/codecs/tests/results/png/256.jis.png +0 -0
- package/codecs/tests/results/png/256.nis.png +0 -0
- package/codecs/tests/results/png/256.sharp.png +0 -0
- package/codecs/tests/results/png/256.upng.png +0 -0
- package/codecs/tests/results/png/512.jis.png +0 -0
- package/codecs/tests/results/png/512.nis.png +0 -0
- package/codecs/tests/results/png/512.sharp.png +0 -0
- package/codecs/tests/results/png/512.upng.png +0 -0
- package/codecs/tests/results/png/64.jis.png +0 -0
- package/codecs/tests/results/png/64.nis.png +0 -0
- package/codecs/tests/results/png/64.sharp.png +0 -0
- package/codecs/tests/results/png/64.upng.png +0 -0
- package/codecs/tests/webp.js +0 -0
- 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
package/v2/index.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Color } from './framebuffer';
|
|
2
|
-
import type framebuffer from './framebuffer';
|
|
3
|
-
|
|
4
|
-
export { Color };
|
|
5
|
-
export function load(buffer: BufferSource): Image | Animation;
|
|
6
|
-
|
|
7
|
-
type svg_options = {
|
|
8
|
-
/** image fit options */
|
|
9
|
-
fit?: svg_fit_zoom | svg_fit_width | svg_fit_height,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type png_options = {
|
|
13
|
-
compression?: 'fast' | 'best' | 'default',
|
|
14
|
-
filter?: 'up' | 'sub' | 'none' | 'paeth' | 'average',
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type svg_fit_zoom = {
|
|
18
|
-
/** zoom by factor */
|
|
19
|
-
zoom: number,
|
|
20
|
-
width?: undefined,
|
|
21
|
-
height?: undefined,
|
|
22
|
-
};
|
|
23
|
-
type svg_fit_width = {
|
|
24
|
-
/** scale to width */
|
|
25
|
-
width: number,
|
|
26
|
-
zoom?: undefined,
|
|
27
|
-
height?: undefined,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
type svg_fit_height = {
|
|
31
|
-
/** scale to height */
|
|
32
|
-
height: number,
|
|
33
|
-
zoom?: undefined,
|
|
34
|
-
width?: undefined,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export class Frame {
|
|
38
|
-
image: Image;
|
|
39
|
-
timestamp: number;
|
|
40
|
-
dispose: 'any' | 'keep' | 'previous' | 'background';
|
|
41
|
-
|
|
42
|
-
constructor(width: number, height: number, buffer?: Image | BufferSource);
|
|
43
|
-
static from(framebuffer: { width: number, height: number, u8?: BufferSource, timestamp?: number, buffer?: BufferSource, dispose: 'any' | 'keep' | 'previous' | 'background' }): Frame;
|
|
44
|
-
|
|
45
|
-
clone(): this;
|
|
46
|
-
get width(): number;
|
|
47
|
-
get height(): number;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// @ts-ignore
|
|
51
|
-
export class Image extends framebuffer {
|
|
52
|
-
clone(): this;
|
|
53
|
-
static from(framebuffer: { width: number, height: number, u8?: BufferSource, buffer?: BufferSource }): Image;
|
|
54
|
-
|
|
55
|
-
encode(format: 'png', options?: png_options): Promise<Uint8Array>;
|
|
56
|
-
encode(format: 'png', options: png_options & { sync: true }): Uint8Array;
|
|
57
|
-
encode(format: 'jpeg', options?: { quality?: number }): Promise<Uint8Array>;
|
|
58
|
-
encode(format: 'webp', options?: { quality?: number }): Promise<Uint8Array>;
|
|
59
|
-
encode(format: 'jpeg', options: { quality?: number } & { sync: true }): Uint8Array;
|
|
60
|
-
encode(format: 'webp', options: { quality?: number } & { sync: true }): Uint8Array;
|
|
61
|
-
|
|
62
|
-
static decode(format: 'png', buffer: BufferSource): Promise<Image>;
|
|
63
|
-
static decode(format: 'jpeg', buffer: BufferSource): Promise<Image>;
|
|
64
|
-
static decode(format: 'tiff', buffer: BufferSource): Promise<Image>;
|
|
65
|
-
static decode(format: 'auto', buffer: string | BufferSource, options?: any): Promise<Image>;
|
|
66
|
-
static decode(format: 'svg', buffer: string | BufferSource, options?: svg_options): Promise<Image>;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export class Animation {
|
|
70
|
-
repeat: number;
|
|
71
|
-
readonly width: number;
|
|
72
|
-
readonly height: number;
|
|
73
|
-
readonly frames: Frame[];
|
|
74
|
-
|
|
75
|
-
constructor(width: number, height: number);
|
|
76
|
-
static decode(format: 'gif', buffer: BufferSource, options?: {}): Promise<Animation>;
|
|
77
|
-
static decode(format: 'auto', buffer: BufferSource, options?: any): Promise<Animation>;
|
|
78
|
-
|
|
79
|
-
clear(): void;
|
|
80
|
-
add(frame: Frame): void;
|
|
81
|
-
[Symbol.iterator]: Generator<Frame, Frame>;
|
|
82
|
-
resize(type: 'cubic' | 'linear' | 'nearest', width: number, height: number): void;
|
|
83
|
-
encode(format: 'gif', options?: { repeat?: number, comment?: string, application?: string }): Promise<Uint8Array>;
|
|
84
|
-
}
|
package/v2/index.js
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
const mem = require('../utils/mem.js');
|
|
2
|
-
const png = require('../png/node.js');
|
|
3
|
-
const magic = require('./codecs/magic.js');
|
|
4
|
-
const codecs = require('../codecs/node/index.js');
|
|
5
|
-
const { Color, default: framebuffer } = require('./framebuffer.js');
|
|
6
|
-
|
|
7
|
-
const wasm = {
|
|
8
|
-
svg: require('../wasm/node/svg.js'),
|
|
9
|
-
gif: require('../wasm/node/gif.js'),
|
|
10
|
-
jpeg: require('../wasm/node/jpeg.js'),
|
|
11
|
-
tiff: require('../wasm/node/tiff.js'),
|
|
12
|
-
// font: require('../wasm/node/font.js'),
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// todo: verbose range errors
|
|
16
|
-
|
|
17
|
-
const animation_formats = ['gif'];
|
|
18
|
-
const image_formats = ['png', 'jpeg', 'tiff'];
|
|
19
|
-
const all_formats = ['png', 'gif', 'jpeg', 'tiff'];
|
|
20
|
-
|
|
21
|
-
async function load(buffer) {
|
|
22
|
-
const u8 = mem.view(buffer);
|
|
23
|
-
if (0 === u8.length) throw new RangeError('empty buffer');
|
|
24
|
-
|
|
25
|
-
const meta = magic.buffer(u8);
|
|
26
|
-
if (!meta) throw new RangeError('unknown file format');
|
|
27
|
-
if ('image' !== meta.type) throw new RangeError('unsupported file type');
|
|
28
|
-
if (!all_formats.includes(meta.format)) throw new RangeError('unsupported image format');
|
|
29
|
-
|
|
30
|
-
if ('gif' === meta.format) return Animation.decode('gif', u8);
|
|
31
|
-
return Image.from('png' === meta.format ? png.decode(u8) : (await wasm[meta.format].init()).load(u8));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
class Frame {
|
|
35
|
-
timestamp = 0;
|
|
36
|
-
dispose = 'any';
|
|
37
|
-
|
|
38
|
-
constructor(width, height, buffer) {
|
|
39
|
-
this.image = buffer instanceof Image ? buffer : new Image(width | 0, height | 0, buffer);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get width() { return this.image.width; }
|
|
43
|
-
get height() { return this.image.height; }
|
|
44
|
-
|
|
45
|
-
clone() {
|
|
46
|
-
const frame = new Frame(this.width, this.height, this.image.clone());
|
|
47
|
-
|
|
48
|
-
frame.dispose = this.dispose;
|
|
49
|
-
frame.timestamp = this.timestamp;
|
|
50
|
-
|
|
51
|
-
return frame;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static from(framebuffer) {
|
|
55
|
-
const frame = new Frame(framebuffer.width, framebuffer.height, framebuffer.u8 || framebuffer.buffer);
|
|
56
|
-
|
|
57
|
-
frame.dispose = framebuffer.dispose || 'any';
|
|
58
|
-
frame.timestamp = framebuffer.timestamp || 0;
|
|
59
|
-
|
|
60
|
-
return frame;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
class Image extends framebuffer {
|
|
65
|
-
constructor(width, height, buffer) {
|
|
66
|
-
super(width, height, buffer || new Uint8Array(4 * width * height));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
encode(format, options = {}) {
|
|
70
|
-
const method = options.sync ? 'encode' : 'encode_async';
|
|
71
|
-
if ('png' === format) return codecs.png[method](this.u8, { ...options, width: this.width, height: this.height });
|
|
72
|
-
if ('jpeg' === format) return codecs.jpeg[method](this.u8, { ...options, width: this.width, height: this.height });
|
|
73
|
-
if ('webp' === format) return codecs.webp[method](this.u8, { ...options, width: this.width, height: this.height });
|
|
74
|
-
|
|
75
|
-
throw new RangeError('invalid image format');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
static async decode(format, buffer, options = {}) {
|
|
79
|
-
buffer = mem.view('string' === typeof buffer ? Buffer.from(buffer) : buffer);
|
|
80
|
-
|
|
81
|
-
if ('auto' === format) {
|
|
82
|
-
const meta = magic.buffer(buffer);
|
|
83
|
-
if (!meta) throw new RangeError('unknown file format');
|
|
84
|
-
if ('image' !== meta.type) throw new RangeError('unsupported file type');
|
|
85
|
-
if (!image_formats.includes(meta.format)) throw new RangeError('unsupported image format');
|
|
86
|
-
|
|
87
|
-
format = meta.format;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
let frame;
|
|
91
|
-
if ('svg' === format) frame = (await wasm.svg.init()).load(buffer, options.fit ?? null);
|
|
92
|
-
|
|
93
|
-
else if (format in wasm) frame = (await wasm[format].init()).load(buffer);
|
|
94
|
-
|
|
95
|
-
if (!frame) throw new RangeError('invalid image format');
|
|
96
|
-
return new Image(frame.width, frame.height, frame.buffer);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
class Animation {
|
|
101
|
-
width = 0;
|
|
102
|
-
height = 0;
|
|
103
|
-
frames = [];
|
|
104
|
-
repeat = Infinity;
|
|
105
|
-
|
|
106
|
-
constructor(width, height) {
|
|
107
|
-
this.width = width | 0;
|
|
108
|
-
this.height = height | 0;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
clear() { this.frames.length = 0; }
|
|
112
|
-
[Symbol.iterator]() { return this.frames.values(); }
|
|
113
|
-
|
|
114
|
-
add(frame) {
|
|
115
|
-
if (this.width !== frame.width) throw new RangeError('invalid frame width');
|
|
116
|
-
else if (this.height !== frame.height) throw new RangeError('invalid frame height');
|
|
117
|
-
|
|
118
|
-
this.frames.push(frame);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
resize(type, width, height) {
|
|
122
|
-
this.width = width | 0;
|
|
123
|
-
this.height = height | 0;
|
|
124
|
-
for (const frame of this) frame.image.resize(type, this.width, this.height);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async encode(format, options = {}) {
|
|
128
|
-
if ('gif' === format) {
|
|
129
|
-
const quality = options.quality ?? 95;
|
|
130
|
-
const encoder = new codecs.gif.encoder(this.width, this.height);
|
|
131
|
-
|
|
132
|
-
let prev = { timestamp: 0 };
|
|
133
|
-
for (const frame of this.frames) {
|
|
134
|
-
encoder.add(frame.image.u8, {
|
|
135
|
-
x: 0,
|
|
136
|
-
y: 0,
|
|
137
|
-
quality,
|
|
138
|
-
width: frame.width,
|
|
139
|
-
speed: options.speed,
|
|
140
|
-
height: frame.height,
|
|
141
|
-
colors: options.colors,
|
|
142
|
-
dispose: frame.dispose,
|
|
143
|
-
delay: ((frame.timestamp - prev.timestamp) / 10) | 0,
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
prev = frame;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const repeat = options.repeat ?? this.repeat;
|
|
150
|
-
return encoder.finish({ ...options, repeat: Infinity === repeat ? null : repeat });
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
throw new RangeError('invalid animation format');
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
static async decode(format, buffer, options = {}) {
|
|
157
|
-
buffer = mem.view(buffer);
|
|
158
|
-
|
|
159
|
-
if ('auto' === format) {
|
|
160
|
-
const meta = magic.buffer(buffer);
|
|
161
|
-
if (!meta) throw new RangeError('unknown file format');
|
|
162
|
-
if ('image' !== meta.type) throw new RangeError('unsupported file type');
|
|
163
|
-
if (!animation_formats.includes(meta.format)) throw new RangeError('unsupported animation format');
|
|
164
|
-
|
|
165
|
-
format = meta.format;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if ('gif' === format) {
|
|
169
|
-
const decoder = new (await wasm.gif.init()).Decoder(buffer);
|
|
170
|
-
|
|
171
|
-
const gwidth = decoder.width | 0;
|
|
172
|
-
const gheight = decoder.height | 0;
|
|
173
|
-
const animation = new Animation(gwidth, gheight);
|
|
174
|
-
const u32 = new Uint32Array(decoder.width * decoder.height);
|
|
175
|
-
const u8 = new Uint8Array(u32.buffer, u32.byteOffset, u32.byteLength);
|
|
176
|
-
|
|
177
|
-
let prev = { timestamp: 0 };
|
|
178
|
-
const frames = animation.frames;
|
|
179
|
-
for (const frame of decoder.frames()) {
|
|
180
|
-
let offset8 = 0 | 0;
|
|
181
|
-
let offset32 = 0 | 0;
|
|
182
|
-
const fx = frame.x | 0;
|
|
183
|
-
const fy = frame.y | 0;
|
|
184
|
-
const f8 = frame.buffer;
|
|
185
|
-
const mode = frame.dispose;
|
|
186
|
-
const width = frame.width | 0;
|
|
187
|
-
const height = frame.height | 0;
|
|
188
|
-
const f = frames[frames.push(new Frame(gwidth, gheight)) - 1];
|
|
189
|
-
const f32 = new Uint32Array(f8.buffer, f8.byteOffset, width * height);
|
|
190
|
-
|
|
191
|
-
const t8 = f.image.u8;
|
|
192
|
-
f.dispose = 'background';
|
|
193
|
-
const t32 = new Uint32Array(t8.buffer);
|
|
194
|
-
f.timestamp = prev.timestamp + 10 * frame.delay;
|
|
195
|
-
|
|
196
|
-
prev = f;
|
|
197
|
-
t8.set(u8);
|
|
198
|
-
|
|
199
|
-
if (2 === mode) {
|
|
200
|
-
for (let y = 0 | 0; y < height; y++) {
|
|
201
|
-
const y_offset = fx + gwidth * (y + fy) | 0;
|
|
202
|
-
|
|
203
|
-
for (let x = 0 | 0; x < width; x++) {
|
|
204
|
-
const x_offset = x + y_offset;
|
|
205
|
-
|
|
206
|
-
if (0 === f8[3 + offset8])
|
|
207
|
-
t32[x_offset] = u32[x_offset];
|
|
208
|
-
else t32[x_offset] = f32[offset32];
|
|
209
|
-
|
|
210
|
-
offset32++;
|
|
211
|
-
offset8 += 4;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
else if (3 === mode) {
|
|
217
|
-
for (let y = 0 | 0; y < height; y++) {
|
|
218
|
-
const y_offset = fx + gwidth * (y + fy) | 0;
|
|
219
|
-
|
|
220
|
-
for (let x = 0 | 0; x < width; x++) {
|
|
221
|
-
const x_offset = x + y_offset;
|
|
222
|
-
|
|
223
|
-
if (0 === f8[3 + offset8])
|
|
224
|
-
t32[x_offset] = u32[x_offset];
|
|
225
|
-
else t32[x_offset] = f32[offset32];
|
|
226
|
-
|
|
227
|
-
offset32++;
|
|
228
|
-
offset8 += 4;
|
|
229
|
-
u32[x_offset] = 0;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
else if (0 === mode || 1 === mode) {
|
|
235
|
-
t8.set(u8)
|
|
236
|
-
for (let y = 0 | 0; y < height; y++) {
|
|
237
|
-
const y_offset = fx + gwidth * (y + fy) | 0;
|
|
238
|
-
|
|
239
|
-
for (let x = 0 | 0; x < width; x++) {
|
|
240
|
-
const x_offset = x + y_offset;
|
|
241
|
-
|
|
242
|
-
if (0 === f8[3 + offset8])
|
|
243
|
-
t32[x_offset] = u32[x_offset];
|
|
244
|
-
else t32[x_offset] = f32[offset32];
|
|
245
|
-
|
|
246
|
-
offset32++;
|
|
247
|
-
offset8 += 4;
|
|
248
|
-
u32[x_offset] = t32[x_offset];
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return animation;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
throw new RangeError('invalid animation format');
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
module.exports = { load, Image, Frame, Color, Animation };
|
package/v2/ops/blur.mjs
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
export function cubic(framebuffer) {
|
|
2
|
-
const width = framebuffer.width;
|
|
3
|
-
const height = framebuffer.height;
|
|
4
|
-
framebuffer.resize('cubic', Math.max(1, .008 * width), Math.max(1, .008 * height));
|
|
5
|
-
|
|
6
|
-
framebuffer.resize('cubic', width, height);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function box(radius, framebuffer) {
|
|
10
|
-
if (!radius) return;
|
|
11
|
-
const u8 = framebuffer.u8;
|
|
12
|
-
const width = framebuffer.width;
|
|
13
|
-
const height = framebuffer.height;
|
|
14
|
-
const old = framebuffer.u8.slice();
|
|
15
|
-
bb(u8, old, width, height, radius);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function gaussian(radius, framebuffer) {
|
|
19
|
-
if (0 >= radius) return;
|
|
20
|
-
const a = Math.exp(.726 ** 2) / radius;
|
|
21
|
-
|
|
22
|
-
const g1 = Math.exp(-a);
|
|
23
|
-
const g2 = Math.exp(a * -2);
|
|
24
|
-
const old = framebuffer.u8.slice();
|
|
25
|
-
const k = ((1 - g1) ** 2) / (1 - g2 + 2 * a * g1);
|
|
26
|
-
|
|
27
|
-
const b2 = -g2;
|
|
28
|
-
const b1 = 2 * g1;
|
|
29
|
-
const a3 = -k * g2;
|
|
30
|
-
const a1 = k * g1 * (a - 1);
|
|
31
|
-
const a2 = k * g1 * (a + 1);
|
|
32
|
-
const lc = (k + a1) / (1 - b1 - b2);
|
|
33
|
-
const width = framebuffer.width | 0;
|
|
34
|
-
const rc = (a2 + a3) / (1 - b1 - b2);
|
|
35
|
-
const height = framebuffer.height | 0;
|
|
36
|
-
const tmp = new Float32Array(4 * Math.max(width, height));
|
|
37
|
-
gc(old, framebuffer.u8, tmp, width, height, k, a1, a2, a3, b1, b2, lc, rc);
|
|
38
|
-
gc(framebuffer.u8, old, tmp, height, width, k, a1, a2, a3, b1, b2, lc, rc);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function bb(u8, old, width, height, radius) {
|
|
42
|
-
const divisor = 1 / (1 + radius + radius);
|
|
43
|
-
bbt(u8, old, width, height, radius, divisor);
|
|
44
|
-
bbh(u8, old, width, height, radius, divisor);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function bbh(u8, old, width, height, radius, divisor) {
|
|
48
|
-
for (var y = 0; y < height; y++) {
|
|
49
|
-
let y_offset = y * width;
|
|
50
|
-
|
|
51
|
-
let li = y_offset;
|
|
52
|
-
let ri = radius + y_offset;
|
|
53
|
-
const fv_offset = 4 * y_offset;
|
|
54
|
-
const lv_offset = 4 * (width - 1 + y_offset);
|
|
55
|
-
|
|
56
|
-
const rfv = old[fv_offset];
|
|
57
|
-
const gfv = old[1 + fv_offset];
|
|
58
|
-
const bfv = old[2 + fv_offset];
|
|
59
|
-
const afv = old[3 + fv_offset];
|
|
60
|
-
|
|
61
|
-
const rlv = old[lv_offset];
|
|
62
|
-
const glv = old[1 + lv_offset];
|
|
63
|
-
const blv = old[2 + lv_offset];
|
|
64
|
-
const alv = old[3 + lv_offset];
|
|
65
|
-
|
|
66
|
-
let r = rfv * (1 + radius);
|
|
67
|
-
let g = gfv * (1 + radius);
|
|
68
|
-
let b = bfv * (1 + radius);
|
|
69
|
-
let a = afv * (1 + radius);
|
|
70
|
-
|
|
71
|
-
for (let x = 0; x < radius; x++) {
|
|
72
|
-
const offset = 4 * (x + y_offset);
|
|
73
|
-
|
|
74
|
-
r += old[offset];
|
|
75
|
-
g += old[1 + offset];
|
|
76
|
-
b += old[2 + offset];
|
|
77
|
-
a += old[3 + offset];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
for (let x = 0; x <= radius; x++) {
|
|
81
|
-
let offset = 4 * ri++;
|
|
82
|
-
r += old[offset] - rfv;
|
|
83
|
-
g += old[1 + offset] - gfv;
|
|
84
|
-
b += old[2 + offset] - bfv;
|
|
85
|
-
a += old[3 + offset] - afv;
|
|
86
|
-
|
|
87
|
-
offset = 4 * y_offset++;
|
|
88
|
-
u8[offset] = Math.round(r * divisor);
|
|
89
|
-
u8[1 + offset] = Math.round(g * divisor);
|
|
90
|
-
u8[2 + offset] = Math.round(b * divisor);
|
|
91
|
-
u8[3 + offset] = Math.round(a * divisor);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
for (let x = 1 + radius; x < (width - radius); x++) {
|
|
95
|
-
let offset = 4 * ri++;
|
|
96
|
-
const roffset = 4 * li++;
|
|
97
|
-
r += old[offset] - old[roffset];
|
|
98
|
-
g += old[1 + offset] - old[1 + roffset];
|
|
99
|
-
b += old[2 + offset] - old[2 + roffset];
|
|
100
|
-
a += old[3 + offset] - old[3 + roffset];
|
|
101
|
-
// todo: how far is roffset
|
|
102
|
-
|
|
103
|
-
offset = 4 * y_offset++;
|
|
104
|
-
u8[offset] = Math.round(r * divisor);
|
|
105
|
-
u8[1 + offset] = Math.round(g * divisor);
|
|
106
|
-
u8[2 + offset] = Math.round(b * divisor);
|
|
107
|
-
u8[3 + offset] = Math.round(a * divisor);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
for (let x = width - radius; x < width; x++) {
|
|
111
|
-
let offset = 4 * li++;
|
|
112
|
-
r += rlv - old[offset];
|
|
113
|
-
g += glv - old[1 + offset];
|
|
114
|
-
b += blv - old[2 + offset];
|
|
115
|
-
a += alv - old[3 + offset];
|
|
116
|
-
|
|
117
|
-
offset = 4 * y_offset++;
|
|
118
|
-
u8[offset] = Math.round(r * divisor);
|
|
119
|
-
u8[1 + offset] = Math.round(g * divisor);
|
|
120
|
-
u8[2 + offset] = Math.round(b * divisor);
|
|
121
|
-
u8[3 + offset] = Math.round(a * divisor);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function bbt(u8, old, width, height, radius, divisor) {
|
|
127
|
-
for (var x = 0; x < width; x++) {
|
|
128
|
-
let ti = x;
|
|
129
|
-
let li = ti;
|
|
130
|
-
const fv_offset = 4 * ti;
|
|
131
|
-
let ri = ti + width * radius;
|
|
132
|
-
const lv_offset = 4 * (ti + width * (height - 1));
|
|
133
|
-
|
|
134
|
-
const rfv = old[fv_offset];
|
|
135
|
-
const gfv = old[1 + fv_offset];
|
|
136
|
-
const bfv = old[2 + fv_offset];
|
|
137
|
-
const afv = old[3 + fv_offset];
|
|
138
|
-
|
|
139
|
-
const rlv = old[lv_offset];
|
|
140
|
-
const glv = old[1 + lv_offset];
|
|
141
|
-
const blv = old[2 + lv_offset];
|
|
142
|
-
const alv = old[3 + lv_offset];
|
|
143
|
-
|
|
144
|
-
let r = rfv * (1 + radius);
|
|
145
|
-
let g = gfv * (1 + radius);
|
|
146
|
-
let b = bfv * (1 + radius);
|
|
147
|
-
let a = afv * (1 + radius);
|
|
148
|
-
|
|
149
|
-
for (let y = 0; y < radius; y++) {
|
|
150
|
-
const offset = 4 * (ti + y * width);
|
|
151
|
-
|
|
152
|
-
r += old[offset];
|
|
153
|
-
g += old[1 + offset];
|
|
154
|
-
b += old[2 + offset];
|
|
155
|
-
a += old[3 + offset];
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
for (let y = 0; y <= radius; y++) {
|
|
159
|
-
let offset = 4 * ri;
|
|
160
|
-
r += old[offset] - rfv;
|
|
161
|
-
g += old[1 + offset] - gfv;
|
|
162
|
-
b += old[2 + offset] - bfv;
|
|
163
|
-
a += old[3 + offset] - afv;
|
|
164
|
-
|
|
165
|
-
offset = 4 * ti;
|
|
166
|
-
u8[offset] = Math.round(r * divisor);
|
|
167
|
-
u8[1 + offset] = Math.round(g * divisor);
|
|
168
|
-
u8[2 + offset] = Math.round(b * divisor);
|
|
169
|
-
u8[3 + offset] = Math.round(a * divisor);
|
|
170
|
-
|
|
171
|
-
ri += width;
|
|
172
|
-
ti += width;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
for (let y = 1 + radius; y < (height - radius); y++) {
|
|
176
|
-
let offset = 4 * ri;
|
|
177
|
-
const xoffset = 4 * li;
|
|
178
|
-
r += old[offset] - old[xoffset];
|
|
179
|
-
g += old[1 + offset] - old[1 + xoffset];
|
|
180
|
-
b += old[2 + offset] - old[2 + xoffset];
|
|
181
|
-
a += old[3 + offset] - old[3 + xoffset];
|
|
182
|
-
// todo: how far is xoffset
|
|
183
|
-
|
|
184
|
-
offset = 4 * ti;
|
|
185
|
-
u8[offset] = Math.round(r * divisor);
|
|
186
|
-
u8[1 + offset] = Math.round(g * divisor);
|
|
187
|
-
u8[2 + offset] = Math.round(b * divisor);
|
|
188
|
-
u8[3 + offset] = Math.round(a * divisor);
|
|
189
|
-
|
|
190
|
-
li += width;
|
|
191
|
-
ri += width;
|
|
192
|
-
ti += width;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
for (let y = height - radius; y < height; y++) {
|
|
196
|
-
let offset = 4 * li;
|
|
197
|
-
r += rlv - old[offset];
|
|
198
|
-
g += glv - old[1 + offset];
|
|
199
|
-
b += blv - old[2 + offset];
|
|
200
|
-
a += alv - old[3 + offset];
|
|
201
|
-
|
|
202
|
-
offset = 4 * ti;
|
|
203
|
-
u8[offset] = Math.round(r * divisor);
|
|
204
|
-
u8[1 + offset] = Math.round(g * divisor);
|
|
205
|
-
u8[2 + offset] = Math.round(b * divisor);
|
|
206
|
-
u8[3 + offset] = Math.round(a * divisor);
|
|
207
|
-
|
|
208
|
-
li += width;
|
|
209
|
-
ti += width;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function gc(u8, old, tmp, width, height, k, a1, a2, a3, b1, b2, lc, rc) {
|
|
215
|
-
const width4 = width * 4;
|
|
216
|
-
const height4 = height * 4;
|
|
217
|
-
const hw1 = height * (width - 1);
|
|
218
|
-
|
|
219
|
-
for (let y = 0; y < height; y++) {
|
|
220
|
-
let toffset = 0 | 0;
|
|
221
|
-
let ooffset = (y * width4) | 0;
|
|
222
|
-
let offset = (4 * (y + hw1)) | 0;
|
|
223
|
-
|
|
224
|
-
let por = old[ooffset];
|
|
225
|
-
let pog = old[1 + ooffset];
|
|
226
|
-
let pob = old[2 + ooffset];
|
|
227
|
-
let poa = old[3 + ooffset];
|
|
228
|
-
|
|
229
|
-
let pur = lc * por;
|
|
230
|
-
let pug = lc * pog;
|
|
231
|
-
let pub = lc * pob;
|
|
232
|
-
let pua = lc * poa;
|
|
233
|
-
|
|
234
|
-
let ppur = pur;
|
|
235
|
-
let ppug = pug;
|
|
236
|
-
let ppub = pub;
|
|
237
|
-
let ppua = pua;
|
|
238
|
-
|
|
239
|
-
for (let x = 0; x < width; x++) {
|
|
240
|
-
const cor = old[ooffset++];
|
|
241
|
-
const cog = old[ooffset++];
|
|
242
|
-
const cob = old[ooffset++];
|
|
243
|
-
const coa = old[ooffset++];
|
|
244
|
-
|
|
245
|
-
const cur = k * cor + a1 * por + b1 * pur + b2 * ppur;
|
|
246
|
-
const cug = k * cog + a1 * pog + b1 * pug + b2 * ppug;
|
|
247
|
-
const cub = k * cob + a1 * pob + b1 * pub + b2 * ppub;
|
|
248
|
-
const cua = k * coa + a1 * poa + b1 * pua + b2 * ppua;
|
|
249
|
-
|
|
250
|
-
ppur = pur; pur = cur; por = cor;
|
|
251
|
-
ppug = pug; pug = cug; pog = cog;
|
|
252
|
-
ppub = pub; pub = cub; pob = cob;
|
|
253
|
-
ppua = pua; pua = cua; poa = coa;
|
|
254
|
-
|
|
255
|
-
tmp[toffset++] = pur;
|
|
256
|
-
tmp[toffset++] = pug;
|
|
257
|
-
tmp[toffset++] = pub;
|
|
258
|
-
tmp[toffset++] = pua;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
ooffset -= 4;
|
|
262
|
-
toffset -= 4;
|
|
263
|
-
ppur = rc * (por = old[ooffset]);
|
|
264
|
-
ppug = rc * (pog = old[1 + ooffset]);
|
|
265
|
-
ppub = rc * (pob = old[2 + ooffset]);
|
|
266
|
-
ppua = rc * (poa = old[3 + ooffset]);
|
|
267
|
-
|
|
268
|
-
pur = ppur;
|
|
269
|
-
pug = ppug;
|
|
270
|
-
pub = ppub;
|
|
271
|
-
pua = ppua;
|
|
272
|
-
let cor = por;
|
|
273
|
-
let cog = pog;
|
|
274
|
-
let cob = pob;
|
|
275
|
-
let coa = poa;
|
|
276
|
-
|
|
277
|
-
for (let x = width - 1; 0 <= x; x--) {
|
|
278
|
-
const cur = a2 * cor + a3 * por + b1 * pur + b2 * ppur;
|
|
279
|
-
const cug = a2 * cog + a3 * pog + b1 * pug + b2 * ppug;
|
|
280
|
-
const cub = a2 * cob + a3 * pob + b1 * pub + b2 * ppub;
|
|
281
|
-
const cua = a2 * coa + a3 * poa + b1 * pua + b2 * ppua;
|
|
282
|
-
|
|
283
|
-
ppur = pur; pur = cur; por = cor;
|
|
284
|
-
ppug = pug; pug = cug; pog = cog;
|
|
285
|
-
ppub = pub; pub = cub; pob = cob;
|
|
286
|
-
ppua = pua; pua = cua; poa = coa;
|
|
287
|
-
|
|
288
|
-
cor = old[ooffset];
|
|
289
|
-
cog = old[1 + ooffset];
|
|
290
|
-
cob = old[2 + ooffset];
|
|
291
|
-
coa = old[3 + ooffset];
|
|
292
|
-
|
|
293
|
-
u8[offset] = pur + tmp[toffset];
|
|
294
|
-
u8[1 + offset] = pug + tmp[1 + toffset];
|
|
295
|
-
u8[2 + offset] = pub + tmp[2 + toffset];
|
|
296
|
-
u8[3 + offset] = pua + tmp[3 + toffset];
|
|
297
|
-
|
|
298
|
-
ooffset -= 4;
|
|
299
|
-
toffset -= 4;
|
|
300
|
-
offset -= height4;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|