@pixagram/renderart 0.4.5 → 1.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 +1 -1
- package/README.md +171 -67
- package/dist/crt-gpu.d.ts +30 -0
- package/dist/crt-gpu.d.ts.map +1 -0
- package/dist/crt-gpu.js +282 -0
- package/dist/crt-gpu.js.map +1 -0
- package/dist/hex-gpu.d.ts +35 -0
- package/dist/hex-gpu.d.ts.map +1 -0
- package/dist/hex-gpu.js +382 -0
- package/dist/hex-gpu.js.map +1 -0
- package/dist/index.d.ts +21 -300
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -963
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +84 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/wasm-wrapper.d.ts +71 -0
- package/dist/wasm-wrapper.d.ts.map +1 -0
- package/dist/wasm-wrapper.js +76 -0
- package/dist/wasm-wrapper.js.map +1 -0
- package/dist/xbrz-gpu.d.ts +34 -0
- package/dist/xbrz-gpu.d.ts.map +1 -0
- package/dist/xbrz-gpu.js +640 -0
- package/dist/xbrz-gpu.js.map +1 -0
- package/package.json +48 -35
- package/src/crt-gpu.ts +313 -0
- package/src/hex-gpu.ts +426 -0
- package/src/index.ts +52 -0
- package/src/types.ts +90 -0
- package/src/wasm/crt.rs +181 -0
- package/src/wasm/hex.rs +324 -0
- package/src/wasm/lib.rs +285 -0
- package/src/wasm/xbrz.rs +262 -0
- package/src/wasm-wrapper.ts +195 -0
- package/src/xbrz-gpu.ts +671 -0
- package/dist/index.d.mts +0 -305
- package/dist/index.mjs +0 -948
- package/dist/index.mjs.map +0 -1
- package/pkg/LICENSE +0 -21
- package/pkg/README.md +0 -117
- package/pkg/renderart_wasm.d.ts +0 -52
- package/pkg/renderart_wasm.js +0 -5
- package/pkg/renderart_wasm_bg.js +0 -283
- package/pkg/renderart_wasm_bg.wasm +0 -0
- package/pkg/renderart_wasm_bg.wasm.d.ts +0 -24
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RenderArt WASM Module Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Provides TypeScript type definitions and helper functions
|
|
5
|
+
* for the WebAssembly module.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { CrtOptions, HexOptions, HexOrientation, ImageOutput, XbrzOptions } from './types';
|
|
9
|
+
|
|
10
|
+
/** WASM upscale result structure */
|
|
11
|
+
export interface WasmUpscaleResult {
|
|
12
|
+
/** Pointer to output data in WASM memory */
|
|
13
|
+
ptr: number;
|
|
14
|
+
/** Length of output data in bytes */
|
|
15
|
+
len: number;
|
|
16
|
+
/** Output width in pixels */
|
|
17
|
+
width: number;
|
|
18
|
+
/** Output height in pixels */
|
|
19
|
+
height: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** WASM module interface */
|
|
23
|
+
export interface RenderArtWasm {
|
|
24
|
+
/** Get WASM memory for reading output buffers */
|
|
25
|
+
get_memory(): WebAssembly.Memory;
|
|
26
|
+
|
|
27
|
+
/** CRT upscale with default config */
|
|
28
|
+
crt_upscale(data: Uint8Array, width: number, height: number, scale: number): WasmUpscaleResult;
|
|
29
|
+
|
|
30
|
+
/** CRT upscale with full config */
|
|
31
|
+
crt_upscale_config(
|
|
32
|
+
data: Uint8Array,
|
|
33
|
+
width: number,
|
|
34
|
+
height: number,
|
|
35
|
+
scale: number,
|
|
36
|
+
warp_x: number,
|
|
37
|
+
warp_y: number,
|
|
38
|
+
scan_hardness: number,
|
|
39
|
+
scan_opacity: number,
|
|
40
|
+
mask_opacity: number,
|
|
41
|
+
enable_warp: boolean,
|
|
42
|
+
enable_scanlines: boolean,
|
|
43
|
+
enable_mask: boolean,
|
|
44
|
+
): WasmUpscaleResult;
|
|
45
|
+
|
|
46
|
+
/** HEX upscale with default config */
|
|
47
|
+
hex_upscale(data: Uint8Array, width: number, height: number, scale: number): WasmUpscaleResult;
|
|
48
|
+
|
|
49
|
+
/** HEX upscale with full config */
|
|
50
|
+
hex_upscale_config(
|
|
51
|
+
data: Uint8Array,
|
|
52
|
+
width: number,
|
|
53
|
+
height: number,
|
|
54
|
+
scale: number,
|
|
55
|
+
orientation: number,
|
|
56
|
+
draw_borders: boolean,
|
|
57
|
+
border_color: number,
|
|
58
|
+
border_thickness: number,
|
|
59
|
+
background_color: number,
|
|
60
|
+
): WasmUpscaleResult;
|
|
61
|
+
|
|
62
|
+
/** Get HEX output dimensions */
|
|
63
|
+
hex_get_dimensions(width: number, height: number, scale: number, orientation: number): Uint32Array;
|
|
64
|
+
|
|
65
|
+
/** xBRZ upscale with default config */
|
|
66
|
+
xbrz_upscale(data: Uint8Array, width: number, height: number, scale: number): WasmUpscaleResult;
|
|
67
|
+
|
|
68
|
+
/** xBRZ upscale with full config */
|
|
69
|
+
xbrz_upscale_config(
|
|
70
|
+
data: Uint8Array,
|
|
71
|
+
width: number,
|
|
72
|
+
height: number,
|
|
73
|
+
scale: number,
|
|
74
|
+
luminance_weight: number,
|
|
75
|
+
equal_color_tolerance: number,
|
|
76
|
+
dominant_direction_threshold: number,
|
|
77
|
+
steep_direction_threshold: number,
|
|
78
|
+
): WasmUpscaleResult;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Helper to read WASM output into ImageOutput */
|
|
82
|
+
export function readWasmOutput(wasm: RenderArtWasm, result: WasmUpscaleResult): ImageOutput {
|
|
83
|
+
const memory = wasm.get_memory();
|
|
84
|
+
const data = new Uint8ClampedArray(memory.buffer, result.ptr, result.len);
|
|
85
|
+
|
|
86
|
+
// Copy the data to avoid issues with WASM memory growth
|
|
87
|
+
return {
|
|
88
|
+
data: new Uint8ClampedArray(data),
|
|
89
|
+
width: result.width,
|
|
90
|
+
height: result.height,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Parse color to RGBA number for WASM */
|
|
95
|
+
export function colorToRgba(color: string | number | undefined, defaultValue: number): number {
|
|
96
|
+
if (color === undefined) return defaultValue;
|
|
97
|
+
if (typeof color === 'number') return color;
|
|
98
|
+
|
|
99
|
+
if (color === 'transparent') return 0x00000000;
|
|
100
|
+
|
|
101
|
+
if (color.startsWith('#')) {
|
|
102
|
+
const hex = color.slice(1);
|
|
103
|
+
if (hex.length === 6) {
|
|
104
|
+
return (parseInt(hex, 16) << 8) | 0xFF;
|
|
105
|
+
}
|
|
106
|
+
if (hex.length === 8) {
|
|
107
|
+
return parseInt(hex, 16);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return defaultValue;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Convert HexOrientation string to number for WASM */
|
|
115
|
+
export function orientationToNumber(orientation: HexOrientation | undefined): number {
|
|
116
|
+
return orientation === 'pointy-top' ? 1 : 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* High-level WASM renderer wrapper
|
|
121
|
+
*
|
|
122
|
+
* Provides the same interface as GPU renderers but uses WASM.
|
|
123
|
+
*/
|
|
124
|
+
export class WasmRenderer {
|
|
125
|
+
private wasm: RenderArtWasm;
|
|
126
|
+
|
|
127
|
+
constructor(wasm: RenderArtWasm) {
|
|
128
|
+
this.wasm = wasm;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Render CRT effect */
|
|
132
|
+
renderCrt(input: ImageData | { data: Uint8Array; width: number; height: number }, options: CrtOptions = {}): ImageOutput {
|
|
133
|
+
const data = input instanceof ImageData ? new Uint8Array(input.data.buffer) : input.data;
|
|
134
|
+
const { width, height } = input;
|
|
135
|
+
const scale = Math.min(32, Math.max(2, options.scale ?? 3));
|
|
136
|
+
|
|
137
|
+
const result = this.wasm.crt_upscale_config(
|
|
138
|
+
data,
|
|
139
|
+
width,
|
|
140
|
+
height,
|
|
141
|
+
scale,
|
|
142
|
+
options.warpX ?? 0.015,
|
|
143
|
+
options.warpY ?? 0.02,
|
|
144
|
+
options.scanHardness ?? -4.0,
|
|
145
|
+
options.scanOpacity ?? 0.5,
|
|
146
|
+
options.maskOpacity ?? 0.3,
|
|
147
|
+
options.enableWarp !== false,
|
|
148
|
+
options.enableScanlines !== false,
|
|
149
|
+
options.enableMask !== false,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return readWasmOutput(this.wasm, result);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Render hexagonal effect */
|
|
156
|
+
renderHex(input: ImageData | { data: Uint8Array; width: number; height: number }, options: HexOptions = {}): ImageOutput {
|
|
157
|
+
const data = input instanceof ImageData ? new Uint8Array(input.data.buffer) : input.data;
|
|
158
|
+
const { width, height } = input;
|
|
159
|
+
const scale = Math.min(32, Math.max(2, options.scale ?? 16));
|
|
160
|
+
|
|
161
|
+
const result = this.wasm.hex_upscale_config(
|
|
162
|
+
data,
|
|
163
|
+
width,
|
|
164
|
+
height,
|
|
165
|
+
scale,
|
|
166
|
+
orientationToNumber(options.orientation),
|
|
167
|
+
options.drawBorders ?? false,
|
|
168
|
+
colorToRgba(options.borderColor, 0x282828FF),
|
|
169
|
+
options.borderThickness ?? 1,
|
|
170
|
+
colorToRgba(options.backgroundColor, 0x00000000),
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
return readWasmOutput(this.wasm, result);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Render xBRZ effect */
|
|
177
|
+
renderXbrz(input: ImageData | { data: Uint8Array; width: number; height: number }, options: XbrzOptions = {}): ImageOutput {
|
|
178
|
+
const data = input instanceof ImageData ? new Uint8Array(input.data.buffer) : input.data;
|
|
179
|
+
const { width, height } = input;
|
|
180
|
+
const scale = Math.min(6, Math.max(2, options.scale ?? 2));
|
|
181
|
+
|
|
182
|
+
const result = this.wasm.xbrz_upscale_config(
|
|
183
|
+
data,
|
|
184
|
+
width,
|
|
185
|
+
height,
|
|
186
|
+
scale,
|
|
187
|
+
options.luminanceWeight ?? 1.0,
|
|
188
|
+
options.equalColorTolerance ?? 30,
|
|
189
|
+
options.dominantDirectionThreshold ?? 4.4,
|
|
190
|
+
options.steepDirectionThreshold ?? 2.2,
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
return readWasmOutput(this.wasm, result);
|
|
194
|
+
}
|
|
195
|
+
}
|