jassub 2.3.2 → 2.4.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/README.md +3 -3
- package/dist/worker/renderers/2d-renderer.d.ts +16 -0
- package/dist/worker/renderers/2d-renderer.js +71 -0
- package/dist/worker/renderers/2d-renderer.js.map +1 -0
- package/dist/worker/renderers/webgl1-renderer.d.ts +38 -0
- package/dist/worker/renderers/webgl1-renderer.js +363 -0
- package/dist/worker/renderers/webgl1-renderer.js.map +1 -0
- package/dist/worker/renderers/webgl2-renderer.d.ts +32 -0
- package/dist/worker/renderers/webgl2-renderer.js +361 -0
- package/dist/worker/renderers/webgl2-renderer.js.map +1 -0
- package/dist/worker/renderers/webgpu-renderer.d.ts +50 -0
- package/dist/worker/renderers/webgpu-renderer.js +404 -0
- package/dist/worker/renderers/webgpu-renderer.js.map +1 -0
- package/dist/worker/util.d.ts +23 -0
- package/dist/worker/util.js +57 -0
- package/dist/worker/util.js.map +1 -1
- package/dist/worker/worker.d.ts +4 -2
- package/dist/worker/worker.js +21 -7
- package/dist/worker/worker.js.map +1 -1
- package/package.json +1 -1
- package/src/worker/renderers/2d-renderer.ts +81 -0
- package/src/worker/renderers/webgl1-renderer.ts +445 -0
- package/src/worker/{webgl-renderer.ts → renderers/webgl2-renderer.ts} +2 -65
- package/src/worker/{webgpu-renderer.ts → renderers/webgpu-renderer.ts} +1 -1
- package/src/worker/util.ts +64 -0
- package/src/worker/worker.ts +17 -5
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
// WARN:
|
|
2
|
+
// This has been deprecated as WebGL is simply faster
|
|
3
|
+
// Know how to optimise this to beat WebGL? submit a PR!
|
|
4
|
+
const IDENTITY_MATRIX = new Float32Array([
|
|
5
|
+
1, 0, 0, 0,
|
|
6
|
+
0, 1, 0, 0,
|
|
7
|
+
0, 0, 1, 0
|
|
8
|
+
]);
|
|
9
|
+
// Color matrix conversion map - mat3x3 pre-padded for WGSL (each column padded to vec4f)
|
|
10
|
+
// Each matrix converts FROM the key color space TO the nested key color space
|
|
11
|
+
export const colorMatrixConversionMap = {
|
|
12
|
+
BT601: {
|
|
13
|
+
BT709: new Float32Array([
|
|
14
|
+
1.0863, 0.0965, -0.0141, 0,
|
|
15
|
+
-0.0723, 0.8451, -0.0277, 0,
|
|
16
|
+
-0.014, 0.0584, 1.0418, 0
|
|
17
|
+
]),
|
|
18
|
+
BT601: IDENTITY_MATRIX
|
|
19
|
+
},
|
|
20
|
+
BT709: {
|
|
21
|
+
BT601: new Float32Array([
|
|
22
|
+
0.9137, -0.1049, 0.0096, 0,
|
|
23
|
+
0.0784, 1.1722, 0.0322, 0,
|
|
24
|
+
0.0079, -0.0671, 0.9582, 0
|
|
25
|
+
]),
|
|
26
|
+
BT709: IDENTITY_MATRIX
|
|
27
|
+
},
|
|
28
|
+
FCC: {
|
|
29
|
+
BT709: new Float32Array([
|
|
30
|
+
1.0873, 0.0974, -0.0127, 0,
|
|
31
|
+
-0.0736, 0.8494, -0.0251, 0,
|
|
32
|
+
-0.0137, 0.0531, 1.0378, 0
|
|
33
|
+
]),
|
|
34
|
+
BT601: new Float32Array([
|
|
35
|
+
1.001, 0.0009, 0.0013, 0,
|
|
36
|
+
-0.0008, 1.005, 0.0027, 0,
|
|
37
|
+
-0.0002, -0.006, 0.996, 0
|
|
38
|
+
])
|
|
39
|
+
},
|
|
40
|
+
SMPTE240M: {
|
|
41
|
+
BT709: new Float32Array([
|
|
42
|
+
0.9993, -0.0004, -0.0034, 0,
|
|
43
|
+
0.0006, 0.9812, -0.0114, 0,
|
|
44
|
+
0.0001, 0.0192, 1.0148, 0
|
|
45
|
+
]),
|
|
46
|
+
BT601: new Float32Array([
|
|
47
|
+
0.913, -0.1051, 0.0063, 0,
|
|
48
|
+
0.0774, 1.1508, 0.0207, 0,
|
|
49
|
+
0.0096, -0.0456, 0.973, 0
|
|
50
|
+
])
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
// WGSL Vertex Shader
|
|
54
|
+
const VERTEX_SHADER = /* wgsl */ `
|
|
55
|
+
struct VertexOutput {
|
|
56
|
+
@builtin(position) position: vec4f,
|
|
57
|
+
@location(0) @interpolate(flat) destXY: vec2f, // destination top-left (flat, no interpolation)
|
|
58
|
+
@location(1) @interpolate(flat) color: vec4f,
|
|
59
|
+
@location(2) @interpolate(flat) texSize: vec2f,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
struct Uniforms {
|
|
63
|
+
resolution: vec2f,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
struct ImageData {
|
|
67
|
+
destRect: vec4f, // x, y, w, h
|
|
68
|
+
srcInfo: vec4f, // texW, texH, stride, 0
|
|
69
|
+
color: vec4f, // RGBA
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@group(0) @binding(0) var<uniform> uniforms: Uniforms;
|
|
73
|
+
@group(0) @binding(1) var<storage, read> imageData: ImageData;
|
|
74
|
+
|
|
75
|
+
// Quad vertices (two triangles)
|
|
76
|
+
const QUAD_POSITIONS = array<vec2f, 6>(
|
|
77
|
+
vec2f(0.0, 0.0),
|
|
78
|
+
vec2f(1.0, 0.0),
|
|
79
|
+
vec2f(0.0, 1.0),
|
|
80
|
+
vec2f(1.0, 0.0),
|
|
81
|
+
vec2f(1.0, 1.0),
|
|
82
|
+
vec2f(0.0, 1.0)
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
@vertex
|
|
86
|
+
fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {
|
|
87
|
+
var output: VertexOutput;
|
|
88
|
+
|
|
89
|
+
let quadPos = QUAD_POSITIONS[vertexIndex];
|
|
90
|
+
let wh = imageData.destRect.zw;
|
|
91
|
+
|
|
92
|
+
// Calculate pixel position
|
|
93
|
+
let pixelPos = imageData.destRect.xy + quadPos * wh;
|
|
94
|
+
|
|
95
|
+
// Convert to clip space (-1 to 1)
|
|
96
|
+
var clipPos = (pixelPos / uniforms.resolution) * 2.0 - 1.0;
|
|
97
|
+
clipPos.y = -clipPos.y; // Flip Y for canvas coordinates
|
|
98
|
+
|
|
99
|
+
output.position = vec4f(clipPos, 0.0, 1.0);
|
|
100
|
+
output.destXY = imageData.destRect.xy;
|
|
101
|
+
output.color = imageData.color;
|
|
102
|
+
output.texSize = imageData.srcInfo.xy;
|
|
103
|
+
|
|
104
|
+
return output;
|
|
105
|
+
}
|
|
106
|
+
`;
|
|
107
|
+
// WGSL Fragment Shader - use textureLoad with integer coords for pixel-perfect sampling
|
|
108
|
+
const FRAGMENT_SHADER = /* wgsl */ `
|
|
109
|
+
@group(0) @binding(3) var tex: texture_2d<f32>;
|
|
110
|
+
@group(0) @binding(4) var<uniform> colorMatrix: mat3x3f;
|
|
111
|
+
|
|
112
|
+
struct FragmentInput {
|
|
113
|
+
@builtin(position) fragCoord: vec4f,
|
|
114
|
+
@location(0) @interpolate(flat) destXY: vec2f,
|
|
115
|
+
@location(1) @interpolate(flat) color: vec4f,
|
|
116
|
+
@location(2) @interpolate(flat) texSize: vec2f,
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@fragment
|
|
120
|
+
fn fragmentMain(input: FragmentInput) -> @location(0) vec4f {
|
|
121
|
+
// Calculate integer texel coordinates from fragment position
|
|
122
|
+
// fragCoord.xy is the pixel center (e.g., 0.5, 1.5, 2.5...)
|
|
123
|
+
let texCoord = vec2i(floor(input.fragCoord.xy - input.destXY));
|
|
124
|
+
|
|
125
|
+
// Bounds check (should not be needed but prevents any out-of-bounds access)
|
|
126
|
+
let texSizeI = vec2i(input.texSize);
|
|
127
|
+
if (texCoord.x < 0 || texCoord.y < 0 || texCoord.x >= texSizeI.x || texCoord.y >= texSizeI.y) {
|
|
128
|
+
return vec4f(0.0);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Load texel directly using integer coordinates - no interpolation, no precision issues
|
|
132
|
+
let mask = textureLoad(tex, texCoord, 0).r;
|
|
133
|
+
|
|
134
|
+
// Apply color matrix conversion (identity if no conversion needed)
|
|
135
|
+
let correctedColor = colorMatrix * input.color.rgb;
|
|
136
|
+
|
|
137
|
+
// libass color alpha: 0 = opaque, 255 = transparent (inverted)
|
|
138
|
+
let colorAlpha = 1.0 - input.color.a;
|
|
139
|
+
|
|
140
|
+
// Final alpha = colorAlpha * mask (like libass: alpha * mask)
|
|
141
|
+
let a = colorAlpha * mask;
|
|
142
|
+
|
|
143
|
+
// Premultiplied alpha output
|
|
144
|
+
return vec4f(correctedColor * a, a);
|
|
145
|
+
}
|
|
146
|
+
`;
|
|
147
|
+
export class WebGPURenderer {
|
|
148
|
+
device = null;
|
|
149
|
+
context = null;
|
|
150
|
+
pipeline = null;
|
|
151
|
+
bindGroupLayout = null;
|
|
152
|
+
// Uniform buffer
|
|
153
|
+
uniformBuffer = null;
|
|
154
|
+
// Color matrix buffer (mat3x3f = 48 bytes with padding)
|
|
155
|
+
colorMatrixBuffer = null;
|
|
156
|
+
// Image data buffers (created on-demand, one per image)
|
|
157
|
+
imageDataBuffers = [];
|
|
158
|
+
// Textures created on-demand (no fixed limit)
|
|
159
|
+
textures = [];
|
|
160
|
+
pendingDestroyTextures = [];
|
|
161
|
+
// eslint-disable-next-line no-undef
|
|
162
|
+
format = 'bgra8unorm';
|
|
163
|
+
constructor(device) {
|
|
164
|
+
this.device = device;
|
|
165
|
+
this.format = navigator.gpu.getPreferredCanvasFormat();
|
|
166
|
+
// Create shader modules
|
|
167
|
+
const vertexModule = this.device.createShaderModule({
|
|
168
|
+
code: VERTEX_SHADER
|
|
169
|
+
});
|
|
170
|
+
const fragmentModule = this.device.createShaderModule({
|
|
171
|
+
code: FRAGMENT_SHADER
|
|
172
|
+
});
|
|
173
|
+
// Create uniform buffer
|
|
174
|
+
this.uniformBuffer = this.device.createBuffer({
|
|
175
|
+
size: 16, // vec2f resolution + padding
|
|
176
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
177
|
+
});
|
|
178
|
+
// Create color matrix buffer (mat3x3f requires 48 bytes: 3 vec3f padded to vec4f each)
|
|
179
|
+
this.colorMatrixBuffer = this.device.createBuffer({
|
|
180
|
+
size: 48, // 3 x vec4f (each column is vec3f padded to 16 bytes)
|
|
181
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
182
|
+
});
|
|
183
|
+
// Initialize with identity matrix
|
|
184
|
+
this.device.queue.writeBuffer(this.colorMatrixBuffer, 0, IDENTITY_MATRIX);
|
|
185
|
+
// Create bind group layout (no sampler needed - using textureLoad for pixel-perfect sampling)
|
|
186
|
+
this.bindGroupLayout = this.device.createBindGroupLayout({
|
|
187
|
+
entries: [
|
|
188
|
+
{
|
|
189
|
+
binding: 0,
|
|
190
|
+
visibility: GPUShaderStage.VERTEX,
|
|
191
|
+
buffer: { type: 'uniform' }
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
binding: 1,
|
|
195
|
+
visibility: GPUShaderStage.VERTEX,
|
|
196
|
+
buffer: { type: 'read-only-storage' }
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
binding: 3,
|
|
200
|
+
visibility: GPUShaderStage.FRAGMENT,
|
|
201
|
+
texture: { sampleType: 'unfilterable-float' } // textureLoad requires unfilterable
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
binding: 4,
|
|
205
|
+
visibility: GPUShaderStage.FRAGMENT,
|
|
206
|
+
buffer: { type: 'uniform' }
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
});
|
|
210
|
+
// Create pipeline layout
|
|
211
|
+
const pipelineLayout = this.device.createPipelineLayout({
|
|
212
|
+
bindGroupLayouts: [this.bindGroupLayout]
|
|
213
|
+
});
|
|
214
|
+
// Create render pipeline
|
|
215
|
+
this.pipeline = this.device.createRenderPipeline({
|
|
216
|
+
layout: pipelineLayout,
|
|
217
|
+
vertex: {
|
|
218
|
+
module: vertexModule,
|
|
219
|
+
entryPoint: 'vertexMain'
|
|
220
|
+
},
|
|
221
|
+
fragment: {
|
|
222
|
+
module: fragmentModule,
|
|
223
|
+
entryPoint: 'fragmentMain',
|
|
224
|
+
targets: [
|
|
225
|
+
{
|
|
226
|
+
format: this.format,
|
|
227
|
+
blend: {
|
|
228
|
+
color: {
|
|
229
|
+
srcFactor: 'one',
|
|
230
|
+
dstFactor: 'one-minus-src-alpha',
|
|
231
|
+
operation: 'add'
|
|
232
|
+
},
|
|
233
|
+
alpha: {
|
|
234
|
+
srcFactor: 'one',
|
|
235
|
+
dstFactor: 'one-minus-src-alpha',
|
|
236
|
+
operation: 'add'
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
]
|
|
241
|
+
},
|
|
242
|
+
primitive: {
|
|
243
|
+
topology: 'triangle-list'
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
setCanvas(canvas, width, height) {
|
|
248
|
+
if (!this.device)
|
|
249
|
+
return;
|
|
250
|
+
// WebGPU doesn't allow 0-sized textures/swapchains
|
|
251
|
+
if (width <= 0 || height <= 0)
|
|
252
|
+
return;
|
|
253
|
+
canvas.width = width;
|
|
254
|
+
canvas.height = height;
|
|
255
|
+
if (!this.context) {
|
|
256
|
+
// Get canvas context
|
|
257
|
+
this.context = canvas.getContext('webgpu');
|
|
258
|
+
if (!this.context) {
|
|
259
|
+
throw new Error('Could not get WebGPU context');
|
|
260
|
+
}
|
|
261
|
+
this.context.configure({
|
|
262
|
+
device: this.device,
|
|
263
|
+
format: this.format,
|
|
264
|
+
alphaMode: 'premultiplied'
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
// Update uniform buffer with resolution
|
|
268
|
+
this.device.queue.writeBuffer(this.uniformBuffer, 0, new Float32Array([width, height]));
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Set the color matrix for color space conversion.
|
|
272
|
+
* Pass null or undefined to use identity (no conversion).
|
|
273
|
+
* Matrix should be a pre-padded Float32Array with 12 values (3 columns × 4 floats each).
|
|
274
|
+
*/
|
|
275
|
+
setColorMatrix(subtitleColorSpace, videoColorSpace) {
|
|
276
|
+
if (!this.device)
|
|
277
|
+
return;
|
|
278
|
+
const colorMatrix = (subtitleColorSpace && videoColorSpace && colorMatrixConversionMap[subtitleColorSpace]?.[videoColorSpace]) ?? IDENTITY_MATRIX;
|
|
279
|
+
this.device.queue.writeBuffer(this.colorMatrixBuffer, 0, colorMatrix);
|
|
280
|
+
}
|
|
281
|
+
createTextureInfo(width, height) {
|
|
282
|
+
const texture = this.device.createTexture({
|
|
283
|
+
size: [width, height],
|
|
284
|
+
format: 'r8unorm',
|
|
285
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST
|
|
286
|
+
});
|
|
287
|
+
return {
|
|
288
|
+
texture,
|
|
289
|
+
view: texture.createView(),
|
|
290
|
+
width,
|
|
291
|
+
height
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
render(images, heap) {
|
|
295
|
+
if (!this.device || !this.context || !this.pipeline)
|
|
296
|
+
return;
|
|
297
|
+
// getCurrentTexture fails if canvas has 0 dimensions
|
|
298
|
+
const currentTexture = this.context.getCurrentTexture();
|
|
299
|
+
if (currentTexture.width === 0 || currentTexture.height === 0)
|
|
300
|
+
return;
|
|
301
|
+
const commandEncoder = this.device.createCommandEncoder();
|
|
302
|
+
const textureView = currentTexture.createView();
|
|
303
|
+
// Begin render pass
|
|
304
|
+
const renderPass = commandEncoder.beginRenderPass({
|
|
305
|
+
colorAttachments: [
|
|
306
|
+
{
|
|
307
|
+
view: textureView,
|
|
308
|
+
clearValue: { r: 0, g: 0, b: 0, a: 0 },
|
|
309
|
+
loadOp: 'clear',
|
|
310
|
+
storeOp: 'store'
|
|
311
|
+
}
|
|
312
|
+
]
|
|
313
|
+
});
|
|
314
|
+
renderPass.setPipeline(this.pipeline);
|
|
315
|
+
// Grow arrays if needed
|
|
316
|
+
while (this.textures.length < images.length) {
|
|
317
|
+
this.textures.push(this.createTextureInfo(64, 64));
|
|
318
|
+
}
|
|
319
|
+
while (this.imageDataBuffers.length < images.length) {
|
|
320
|
+
this.imageDataBuffers.push(this.device.createBuffer({
|
|
321
|
+
size: 48, // 3 x vec4f
|
|
322
|
+
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
|
|
323
|
+
}));
|
|
324
|
+
}
|
|
325
|
+
// Render each image
|
|
326
|
+
for (let i = 0, texIndex = -1; i < images.length; i++) {
|
|
327
|
+
const img = images[i];
|
|
328
|
+
// Skip images with invalid dimensions (WebGPU doesn't allow 0-sized textures)
|
|
329
|
+
if (img.w <= 0 || img.h <= 0)
|
|
330
|
+
continue;
|
|
331
|
+
let texInfo = this.textures[++texIndex];
|
|
332
|
+
// Recreate texture if size changed (use actual w, not stride)
|
|
333
|
+
if (texInfo.width !== img.w || texInfo.height !== img.h) {
|
|
334
|
+
// Defer destruction until after submit to avoid destroying textures still in use
|
|
335
|
+
this.pendingDestroyTextures.push(texInfo.texture);
|
|
336
|
+
texInfo = this.createTextureInfo(img.w, img.h);
|
|
337
|
+
this.textures[texIndex] = texInfo;
|
|
338
|
+
}
|
|
339
|
+
// Upload bitmap data using bytesPerRow to handle stride
|
|
340
|
+
// Only need stride * (h-1) + w bytes per ASS spec
|
|
341
|
+
// this... didnt work, is the used alternative bad?
|
|
342
|
+
// const dataSize = img.stride * (img.h - 1) + img.w
|
|
343
|
+
// const bitmapData = heap.subarray(img.bitmap, img.bitmap + dataSize)
|
|
344
|
+
// this.device.queue.writeTexture(
|
|
345
|
+
// { texture: texInfo.texture },
|
|
346
|
+
// bitmapData as unknown as ArrayBuffer,
|
|
347
|
+
// { bytesPerRow: img.stride }, // Source rows are stride bytes apart
|
|
348
|
+
// { width: img.w, height: img.h } // But we only copy w pixels per row
|
|
349
|
+
// )
|
|
350
|
+
this.device.queue.writeTexture({ texture: texInfo.texture }, heap.buffer, { bytesPerRow: img.stride, offset: img.bitmap }, // Source rows are stride bytes apart
|
|
351
|
+
{ width: img.w, height: img.h } // But we only copy w pixels per row
|
|
352
|
+
);
|
|
353
|
+
// Update image data buffer
|
|
354
|
+
const imageData = new Float32Array([
|
|
355
|
+
// destRect
|
|
356
|
+
img.dst_x, img.dst_y, img.w, img.h,
|
|
357
|
+
// srcInfo
|
|
358
|
+
img.w, img.h, img.stride, 0,
|
|
359
|
+
// color (RGBA from 0xRRGGBBAA)
|
|
360
|
+
((img.color >>> 24) & 0xFF) / 255,
|
|
361
|
+
((img.color >>> 16) & 0xFF) / 255,
|
|
362
|
+
((img.color >>> 8) & 0xFF) / 255,
|
|
363
|
+
(img.color & 0xFF) / 255
|
|
364
|
+
]);
|
|
365
|
+
const imageBuffer = this.imageDataBuffers[texIndex];
|
|
366
|
+
this.device.queue.writeBuffer(imageBuffer, 0, imageData);
|
|
367
|
+
// Create bind group for this image (no sampler - using textureLoad)
|
|
368
|
+
const bindGroup = this.device.createBindGroup({
|
|
369
|
+
layout: this.bindGroupLayout,
|
|
370
|
+
entries: [
|
|
371
|
+
{ binding: 0, resource: { buffer: this.uniformBuffer } },
|
|
372
|
+
{ binding: 1, resource: { buffer: imageBuffer } },
|
|
373
|
+
{ binding: 3, resource: texInfo.view },
|
|
374
|
+
{ binding: 4, resource: { buffer: this.colorMatrixBuffer } }
|
|
375
|
+
]
|
|
376
|
+
});
|
|
377
|
+
renderPass.setBindGroup(0, bindGroup);
|
|
378
|
+
renderPass.draw(6); // 6 vertices for quad
|
|
379
|
+
}
|
|
380
|
+
renderPass.end();
|
|
381
|
+
this.device.queue.submit([commandEncoder.finish()]);
|
|
382
|
+
// Now safe to destroy old textures
|
|
383
|
+
for (const tex of this.pendingDestroyTextures) {
|
|
384
|
+
tex.destroy();
|
|
385
|
+
}
|
|
386
|
+
this.pendingDestroyTextures = [];
|
|
387
|
+
}
|
|
388
|
+
destroy() {
|
|
389
|
+
for (const tex of this.textures) {
|
|
390
|
+
tex.texture.destroy();
|
|
391
|
+
}
|
|
392
|
+
this.textures = [];
|
|
393
|
+
this.uniformBuffer?.destroy();
|
|
394
|
+
this.colorMatrixBuffer?.destroy();
|
|
395
|
+
for (const buf of this.imageDataBuffers) {
|
|
396
|
+
buf.destroy();
|
|
397
|
+
}
|
|
398
|
+
this.imageDataBuffers = [];
|
|
399
|
+
this.device?.destroy();
|
|
400
|
+
this.device = null;
|
|
401
|
+
this.context = null;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
//# sourceMappingURL=webgpu-renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webgpu-renderer.js","sourceRoot":"","sources":["../../../src/worker/renderers/webgpu-renderer.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,qDAAqD;AACrD,wDAAwD;AAIxD,MAAM,eAAe,GAAG,IAAI,YAAY,CAAC;IACvC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACV,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACV,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;CACX,CAAC,CAAA;AAEF,yFAAyF;AACzF,8EAA8E;AAC9E,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,KAAK,EAAE;QACL,KAAK,EAAE,IAAI,YAAY,CAAC;YACtB,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC;YAC1B,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC;YAC3B,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;SAC1B,CAAC;QACF,KAAK,EAAE,eAAe;KACvB;IACD,KAAK,EAAE;QACL,KAAK,EAAE,IAAI,YAAY,CAAC;YACtB,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;YAC1B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;YACzB,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;SAC3B,CAAC;QACF,KAAK,EAAE,eAAe;KACvB;IACD,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IAAI,CAAC,QAAQ,EAAE,CAAC;YAChC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;QACvB,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAA;QAElB,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,CAAA;QAC7B,IAAI,CAAC,iBAAiB,EAAE,OAAO,EAAE,CAAA;QACjC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACxC,GAAG,CAAC,OAAO,EAAE,CAAA;QACf,CAAC;QACD,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAA;QAE1B,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QAClB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;IACrB,CAAC;CACF"}
|
package/dist/worker/util.d.ts
CHANGED
|
@@ -9,3 +9,26 @@ export declare const LIBASS_YCBCR_MAP: readonly [null, "BT601", null, "BT601", "
|
|
|
9
9
|
export declare function _applyKeys<T extends (ASSEvent | ASSStyle)>(input: T, output: T): void;
|
|
10
10
|
export declare const _fetch: typeof fetch;
|
|
11
11
|
export declare function fetchtext(url: string): Promise<string>;
|
|
12
|
+
export declare const THREAD_COUNT: number;
|
|
13
|
+
export declare const SUPPORTS_GROWTH: boolean;
|
|
14
|
+
export declare const SHOULD_REFERENCE_MEMORY: boolean;
|
|
15
|
+
export declare const IDENTITY_MATRIX: Float32Array<ArrayBuffer>;
|
|
16
|
+
export declare const colorMatrixConversionMap: {
|
|
17
|
+
readonly BT601: {
|
|
18
|
+
readonly BT709: Float32Array<ArrayBuffer>;
|
|
19
|
+
readonly BT601: Float32Array<ArrayBuffer>;
|
|
20
|
+
};
|
|
21
|
+
readonly BT709: {
|
|
22
|
+
readonly BT601: Float32Array<ArrayBuffer>;
|
|
23
|
+
readonly BT709: Float32Array<ArrayBuffer>;
|
|
24
|
+
};
|
|
25
|
+
readonly FCC: {
|
|
26
|
+
readonly BT709: Float32Array<ArrayBuffer>;
|
|
27
|
+
readonly BT601: Float32Array<ArrayBuffer>;
|
|
28
|
+
};
|
|
29
|
+
readonly SMPTE240M: {
|
|
30
|
+
readonly BT709: Float32Array<ArrayBuffer>;
|
|
31
|
+
readonly BT601: Float32Array<ArrayBuffer>;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export type ColorSpace = keyof typeof colorMatrixConversionMap;
|
package/dist/worker/util.js
CHANGED
|
@@ -27,4 +27,61 @@ export async function fetchtext(url) {
|
|
|
27
27
|
const res = await _fetch(url);
|
|
28
28
|
return await res.text();
|
|
29
29
|
}
|
|
30
|
+
export const THREAD_COUNT = !IS_FIREFOX && self.crossOriginIsolated ? Math.min(Math.max(1, navigator.hardwareConcurrency - 2), 8) : 1;
|
|
31
|
+
// @ts-expect-error new experimental API
|
|
32
|
+
export const SUPPORTS_GROWTH = !!WebAssembly.Memory.prototype.toResizableBuffer;
|
|
33
|
+
// HACK: 3 memory hacks to support here:
|
|
34
|
+
// 1. Chrome WASM Growable memory which can use a reference to the buffer to fix visual artifacts, which happen both with multithreading or without [fastest]
|
|
35
|
+
// 2. Chrome WASM non-growable, but mult-threaded only memory which needs to re-create the HEAPU8 on growth because of race conditions [medium]
|
|
36
|
+
// 3. Firefox non-growable memory which needs a copy of the data into a non-resizable buffer and can't use a reference [fastest single threaded, but only on Firefox, on Chrome this is slowest]
|
|
37
|
+
export const SHOULD_REFERENCE_MEMORY = !IS_FIREFOX && (SUPPORTS_GROWTH || THREAD_COUNT > 1);
|
|
38
|
+
export const IDENTITY_MATRIX = new Float32Array([
|
|
39
|
+
1, 0, 0,
|
|
40
|
+
0, 1, 0,
|
|
41
|
+
0, 0, 1
|
|
42
|
+
]);
|
|
43
|
+
// Color matrix conversion map - mat3x3 for WebGL2
|
|
44
|
+
// Each matrix converts FROM the key color space TO the nested key color space
|
|
45
|
+
export const colorMatrixConversionMap = {
|
|
46
|
+
BT601: {
|
|
47
|
+
BT709: new Float32Array([
|
|
48
|
+
1.0863, 0.0965, -0.01411,
|
|
49
|
+
-0.0723, 0.8451, -0.0277,
|
|
50
|
+
-0.0141, 0.0584, 1.0418
|
|
51
|
+
]),
|
|
52
|
+
BT601: IDENTITY_MATRIX
|
|
53
|
+
},
|
|
54
|
+
BT709: {
|
|
55
|
+
BT601: new Float32Array([
|
|
56
|
+
0.9137, 0.0784, 0.0079,
|
|
57
|
+
-0.1049, 1.1722, -0.0671,
|
|
58
|
+
0.0096, 0.0322, 0.9582
|
|
59
|
+
]),
|
|
60
|
+
BT709: IDENTITY_MATRIX
|
|
61
|
+
},
|
|
62
|
+
FCC: {
|
|
63
|
+
BT709: new Float32Array([
|
|
64
|
+
1.0873, -0.0736, -0.0137,
|
|
65
|
+
0.0974, 0.8494, 0.0531,
|
|
66
|
+
-0.0127, -0.0251, 1.0378
|
|
67
|
+
]),
|
|
68
|
+
BT601: new Float32Array([
|
|
69
|
+
1.001, -0.0008, -0.0002,
|
|
70
|
+
0.0009, 1.005, -0.006,
|
|
71
|
+
0.0013, 0.0027, 0.996
|
|
72
|
+
])
|
|
73
|
+
},
|
|
74
|
+
SMPTE240M: {
|
|
75
|
+
BT709: new Float32Array([
|
|
76
|
+
0.9993, 0.0006, 0.0001,
|
|
77
|
+
-0.0004, 0.9812, 0.0192,
|
|
78
|
+
-0.0034, -0.0114, 1.0148
|
|
79
|
+
]),
|
|
80
|
+
BT601: new Float32Array([
|
|
81
|
+
0.913, 0.0774, 0.0096,
|
|
82
|
+
-0.1051, 1.1508, -0.0456,
|
|
83
|
+
0.0063, 0.0207, 0.973
|
|
84
|
+
])
|
|
85
|
+
}
|
|
86
|
+
};
|
|
30
87
|
//# sourceMappingURL=util.js.map
|
package/dist/worker/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/worker/util.ts"],"names":[],"mappings":"AAOA,mGAAmG;AACnG,MAAM,CAAC,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AM,EAAE,KAAK,EAAE,CAAC,KAAK;YACrB,MAAM,EAAE,MAAM,EAAE,KAAK;SACtB,CAAC;KACH;IACD,SAAS,EAAE;QACT,KAAK,EAAE,IAAI,YAAY,CAAC;YACtB,MAAM,EAAE,MAAM,EAAE,MAAM;YACtB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM;YACvB,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM;SACzB,CAAC;QACF,KAAK,EAAE,IAAI,YAAY,CAAC;YACtB,KAAK,EAAE,MAAM,EAAE,MAAM;YACrB,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM;YACxB,MAAM,EAAE,MAAM,EAAE,KAAK;SACtB,CAAC;KACH;CACO,CAAA"}
|
package/dist/worker/worker.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { finalizer } from 'abslink';
|
|
2
|
+
import { Canvas2DRenderer } from './renderers/2d-renderer.ts';
|
|
3
|
+
import { WebGL1Renderer } from './renderers/webgl1-renderer.ts';
|
|
4
|
+
import { WebGL2Renderer } from './renderers/webgl2-renderer.ts';
|
|
2
5
|
import { type ASSEvent, type ASSStyle, type WeightValue } from './util.ts';
|
|
3
|
-
import { WebGL2Renderer } from './webgl-renderer.ts';
|
|
4
6
|
import type { JASSUB } from '../wasm/types.d.ts';
|
|
5
7
|
interface opts {
|
|
6
8
|
wasmUrl: string;
|
|
@@ -22,7 +24,7 @@ export declare class ASSRenderer {
|
|
|
22
24
|
_subtitleColorSpace?: 'BT601' | 'BT709' | 'SMPTE240M' | 'FCC' | null;
|
|
23
25
|
_videoColorSpace?: 'BT709' | 'BT601';
|
|
24
26
|
_malloc: (size: number) => number;
|
|
25
|
-
_gpurender: WebGL2Renderer;
|
|
27
|
+
_gpurender: WebGL2Renderer | WebGL1Renderer | Canvas2DRenderer;
|
|
26
28
|
debug: boolean;
|
|
27
29
|
_ready: Promise<void>;
|
|
28
30
|
constructor(data: opts, getFont: (font: string, weight: WeightValue) => Promise<Uint8Array<ArrayBuffer> | undefined>);
|
package/dist/worker/worker.js
CHANGED
|
@@ -3,15 +3,17 @@ import { finalizer } from 'abslink';
|
|
|
3
3
|
import { expose } from 'abslink/w3c';
|
|
4
4
|
import { queryRemoteFonts } from 'lfa-ponyfill';
|
|
5
5
|
import WASM from '../wasm/jassub-worker.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { Canvas2DRenderer } from "./renderers/2d-renderer.js";
|
|
7
|
+
import { WebGL1Renderer } from "./renderers/webgl1-renderer.js";
|
|
8
|
+
import { WebGL2Renderer } from "./renderers/webgl2-renderer.js";
|
|
9
|
+
import { _applyKeys, _fetch, fetchtext, LIBASS_YCBCR_MAP, THREAD_COUNT, WEIGHT_MAP } from "./util.js";
|
|
8
10
|
export class ASSRenderer {
|
|
9
11
|
_offCanvas;
|
|
10
12
|
_wasm;
|
|
11
13
|
_subtitleColorSpace;
|
|
12
14
|
_videoColorSpace;
|
|
13
15
|
_malloc;
|
|
14
|
-
_gpurender
|
|
16
|
+
_gpurender;
|
|
15
17
|
debug = false;
|
|
16
18
|
_ready;
|
|
17
19
|
constructor(data, getFont) {
|
|
@@ -25,7 +27,7 @@ export class ASSRenderer {
|
|
|
25
27
|
const _fetch = globalThis.fetch;
|
|
26
28
|
globalThis.fetch = _ => _fetch(data.wasmUrl);
|
|
27
29
|
// TODO: abslink doesnt support transferables yet
|
|
28
|
-
const handleMessage =
|
|
30
|
+
const handleMessage = ({ data }) => {
|
|
29
31
|
if (data.name === 'offscreenCanvas') {
|
|
30
32
|
// await this._ready // needed for webGPU
|
|
31
33
|
this._offCanvas = data.ctrl;
|
|
@@ -37,13 +39,25 @@ export class ASSRenderer {
|
|
|
37
39
|
// const devicePromise = navigator.gpu?.requestAdapter({
|
|
38
40
|
// powerPreference: 'high-performance'
|
|
39
41
|
// }).then(adapter => adapter?.requestDevice())
|
|
42
|
+
try {
|
|
43
|
+
const testCanvas = new OffscreenCanvas(1, 1);
|
|
44
|
+
if (testCanvas.getContext('webgl2')) {
|
|
45
|
+
this._gpurender = new WebGL2Renderer();
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this._gpurender = testCanvas.getContext('webgl') ? new WebGL1Renderer() : new Canvas2DRenderer();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
this._gpurender = new Canvas2DRenderer();
|
|
53
|
+
}
|
|
40
54
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
41
55
|
this._ready = WASM({ __url: data.wasmUrl, __out: (log) => this._log(log) }).then(async ({ _malloc, JASSUB }) => {
|
|
42
56
|
this._malloc = _malloc;
|
|
43
57
|
this._wasm = new JASSUB(data.width, data.height, this._defaultFont);
|
|
44
58
|
// Firefox seems to have issues with multithreading in workers
|
|
45
59
|
// a worker inside a worker does not recieve messages properly
|
|
46
|
-
this._wasm.setThreads(
|
|
60
|
+
this._wasm.setThreads(THREAD_COUNT);
|
|
47
61
|
this._loadInitialFonts(data.fonts);
|
|
48
62
|
this._wasm.createTrackMem(data.subContent ?? await fetchtext(data.subUrl));
|
|
49
63
|
this._subtitleColorSpace = LIBASS_YCBCR_MAP[this._wasm.trackColorSpace];
|
|
@@ -125,7 +139,7 @@ export class ASSRenderer {
|
|
|
125
139
|
async _log(log) {
|
|
126
140
|
console.debug(log);
|
|
127
141
|
const match = log.match(/JASSUB: fontselect:[^(]+: \(([^,]+), (\d{1,4}), \d\)/);
|
|
128
|
-
if (match && !await this._findAvailableFont(match[1].trim().toLowerCase(), WEIGHT_MAP[parseInt(match[2]
|
|
142
|
+
if (match && !await this._findAvailableFont(match[1].trim().toLowerCase(), WEIGHT_MAP[Math.ceil(parseInt(match[2]) / 100) - 1])) {
|
|
129
143
|
await this._findAvailableFont(this._defaultFont);
|
|
130
144
|
}
|
|
131
145
|
}
|
|
@@ -179,7 +193,7 @@ export class ASSRenderer {
|
|
|
179
193
|
return;
|
|
180
194
|
this._checkedFonts.add(key);
|
|
181
195
|
try {
|
|
182
|
-
const font = this._availableFonts[key] ?? this._availableFonts[fontName] ?? await this._queryLocalFont(fontName, weight) ?? await this._queryRemoteFont([
|
|
196
|
+
const font = this._availableFonts[key] ?? this._availableFonts[fontName] ?? await this._queryLocalFont(fontName, weight) ?? await this._queryRemoteFont([key, fontName]);
|
|
183
197
|
if (font)
|
|
184
198
|
return await this.addFonts([font]);
|
|
185
199
|
}
|