@browser-mc/webcodecs-color 0.0.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/README.md +73 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +305 -0
- package/dist/index.js.map +1 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @browser-mc/webcodecs-color
|
|
2
|
+
|
|
3
|
+
Experiments for inspecting and resizing non-sRGB `VideoFrame`s.
|
|
4
|
+
|
|
5
|
+
## Inspect A Frame
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import {
|
|
9
|
+
classifyFrameColor,
|
|
10
|
+
decodeImageToVideoFrame,
|
|
11
|
+
inspectFrame,
|
|
12
|
+
} from '@browser-mc/webcodecs-color';
|
|
13
|
+
|
|
14
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
15
|
+
const frame = await decodeImageToVideoFrame(bytes, 'image/avif', {
|
|
16
|
+
colorSpaceConversion: 'none',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
console.log(inspectFrame(frame));
|
|
20
|
+
console.log(classifyFrameColor(frame));
|
|
21
|
+
|
|
22
|
+
frame.close();
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Canvas-Free Raw Resize
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { resizeFrameRaw } from '@browser-mc/webcodecs-color';
|
|
29
|
+
|
|
30
|
+
const resized = await resizeFrameRaw(frame, {
|
|
31
|
+
width: 1024,
|
|
32
|
+
height: 682,
|
|
33
|
+
algorithm: 'bilinear',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
console.log(resized.inspection);
|
|
37
|
+
resized.frame.close();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`resizeFrameRaw` uses `VideoFrame.copyTo()` and creates a new `VideoFrame` from resized planar data. It copies only the source `visibleRect`, so coded padding rows/columns are not fed into the resize. It does not use `HTMLCanvasElement`, `OffscreenCanvas`, WebGL, or WebGPU.
|
|
41
|
+
|
|
42
|
+
### Why Not WebGPU?
|
|
43
|
+
|
|
44
|
+
This package intentionally keeps the raw resize path on CPU for now. A WebGPU compute path still needs `VideoFrame.copyTo()` to get planar bytes, then CPU-side packing/unpacking, GPU upload, compute dispatch, readback, and finally `new VideoFrame(buffer, init)`. For still images and short animation frames, that transfer/readback cost can easily dominate the resize itself.
|
|
45
|
+
|
|
46
|
+
WebGPU may become useful if the pipeline can keep frames on the GPU for several operations in a row, or if browsers expose a practical zero-copy `VideoFrame` to writable planar output path. Until then, the CPU planar path is simpler, easier to test, and preserves WebCodecs color metadata without pretending to be a full HDR color-management pipeline.
|
|
47
|
+
|
|
48
|
+
## Comparison Helpers
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { convertFrameToCanvasSdr, copyFrameToRgba, resizeFrameWithCanvas } from '@browser-mc/webcodecs-color';
|
|
52
|
+
|
|
53
|
+
const rgba = await copyFrameToRgba(frame, { colorSpace: 'display-p3' });
|
|
54
|
+
const canvasResized = resizeFrameWithCanvas(frame, { width: 1024, height: 682 });
|
|
55
|
+
const canvasSdr = convertFrameToCanvasSdr(frame);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`convertFrameToCanvasSdr` draws through an sRGB `OffscreenCanvas` path and returns an RGBA `VideoFrame` marked as BT.709 SDR. It is a practical browser conversion helper, not a dedicated HDR tone-mapping engine.
|
|
59
|
+
|
|
60
|
+
## Supported Raw Resize Formats
|
|
61
|
+
|
|
62
|
+
- `NV12`, `I420`, `I422`, `I444`
|
|
63
|
+
- Chromium 10-bit formats observed via WebCodecs: `I420P10`, `I422P10`, `I444P10`
|
|
64
|
+
|
|
65
|
+
## Commands
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
pnpm --filter @browser-mc/webcodecs-color build
|
|
69
|
+
pnpm --filter @browser-mc/webcodecs-color typecheck
|
|
70
|
+
pnpm --filter @browser-mc/webcodecs-color test:electron
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`test:electron` uses `hdrrec2020.avif`. Current result keeps `I444P10` and `bt2020` metadata through raw resize.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export type FrameColorInspection = {
|
|
2
|
+
format: VideoPixelFormat | null;
|
|
3
|
+
codedWidth: number;
|
|
4
|
+
codedHeight: number;
|
|
5
|
+
displayWidth: number;
|
|
6
|
+
displayHeight: number;
|
|
7
|
+
visibleRect: {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
} | null;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
duration: number | null;
|
|
15
|
+
colorSpace: {
|
|
16
|
+
primaries: string | null;
|
|
17
|
+
transfer: string | null;
|
|
18
|
+
matrix: string | null;
|
|
19
|
+
fullRange: boolean | null;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export type FrameColorClassification = {
|
|
23
|
+
isSimpleSdr: boolean;
|
|
24
|
+
isWideGamut: boolean;
|
|
25
|
+
isHdrLike: boolean;
|
|
26
|
+
canvasColorSpace: PredefinedColorSpace;
|
|
27
|
+
recommendedPath: 'canvas-sdr' | 'canvas-display-p3' | 'raw-hdr';
|
|
28
|
+
notes: string[];
|
|
29
|
+
};
|
|
30
|
+
export type RgbaCopyResult = {
|
|
31
|
+
data: Uint8Array;
|
|
32
|
+
layout: PlaneLayout[];
|
|
33
|
+
colorSpace: PredefinedColorSpace;
|
|
34
|
+
format: 'RGBA' | 'BGRA';
|
|
35
|
+
width: number;
|
|
36
|
+
height: number;
|
|
37
|
+
};
|
|
38
|
+
export type ResizeCanvasOptions = {
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
colorSpace?: PredefinedColorSpace;
|
|
42
|
+
imageSmoothingQuality?: ImageSmoothingQuality;
|
|
43
|
+
};
|
|
44
|
+
export type ResizeCanvasResult = {
|
|
45
|
+
frame: VideoFrame;
|
|
46
|
+
inspection: FrameColorInspection;
|
|
47
|
+
colorSpace: PredefinedColorSpace;
|
|
48
|
+
};
|
|
49
|
+
export type CanvasSdrResult = {
|
|
50
|
+
frame: VideoFrame;
|
|
51
|
+
inspection: FrameColorInspection;
|
|
52
|
+
colorSpace: PredefinedColorSpace;
|
|
53
|
+
};
|
|
54
|
+
export type ResizeRawOptions = {
|
|
55
|
+
width: number;
|
|
56
|
+
height: number;
|
|
57
|
+
algorithm?: 'nearest' | 'bilinear';
|
|
58
|
+
};
|
|
59
|
+
export type ResizeRawResult = {
|
|
60
|
+
frame: VideoFrame;
|
|
61
|
+
inspection: FrameColorInspection;
|
|
62
|
+
format: string;
|
|
63
|
+
layout: PlaneLayout[];
|
|
64
|
+
byteLength: number;
|
|
65
|
+
algorithm: 'nearest' | 'bilinear';
|
|
66
|
+
};
|
|
67
|
+
export declare function decodeImageToVideoFrame(data: Uint8Array, type: string, options?: {
|
|
68
|
+
colorSpaceConversion?: ColorSpaceConversion;
|
|
69
|
+
desiredWidth?: number;
|
|
70
|
+
desiredHeight?: number;
|
|
71
|
+
}): Promise<VideoFrame>;
|
|
72
|
+
export declare function inspectFrame(frame: VideoFrame): FrameColorInspection;
|
|
73
|
+
export declare function classifyFrameColor(frameOrInspection: VideoFrame | FrameColorInspection): FrameColorClassification;
|
|
74
|
+
export declare function copyFrameToRgba(frame: VideoFrame, options?: {
|
|
75
|
+
colorSpace?: PredefinedColorSpace;
|
|
76
|
+
format?: 'RGBA' | 'BGRA';
|
|
77
|
+
}): Promise<RgbaCopyResult>;
|
|
78
|
+
export declare function resizeFrameWithCanvas(frame: VideoFrame, options: ResizeCanvasOptions): ResizeCanvasResult;
|
|
79
|
+
export declare function convertFrameToCanvasSdr(frame: VideoFrame): CanvasSdrResult;
|
|
80
|
+
export declare function resizeFrameRaw(frame: VideoFrame, options: ResizeRawOptions): Promise<ResizeRawResult>;
|
|
81
|
+
export declare function sdrVideoColorSpaceInit(): VideoColorSpaceInit;
|
|
82
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE;QACX,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,GAAG,IAAI,CAAC;IACT,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE;QACV,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QACtB,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;KAC3B,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,gBAAgB,EAAE,oBAAoB,CAAC;IACvC,eAAe,EAAE,YAAY,GAAG,mBAAmB,GAAG,SAAS,CAAC;IAChE,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,UAAU,EAAE,oBAAoB,CAAC;IACjC,MAAM,EAA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EAAE,UAAU,GAAG,oBAAoB,CAyBpE;AAED,wBAAgB,kBAAkB,CAAC,iBAAiB,EAAE,UAAU,GAAG,oBAAoB,GAAG,wBAAwB,CA2BjH;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,GAAE;IAChE,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACrB,GAAG,OAAO,CAAC,cAAc,CAAC,CAc/B;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,mBAAmB,GAAG,kBAAkB,CAgBzG;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,UAAU,GAAG,eAAe,CAwB1E;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAwD3G;AAwJD,wBAAgB,sBAAsB,IAAI,mBAAmB,CAO5D"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { copyArrayBuffer } from '@browser-mc/binary';
|
|
2
|
+
export async function decodeImageToVideoFrame(data, type, options = {}) {
|
|
3
|
+
if (typeof ImageDecoder === 'undefined')
|
|
4
|
+
throw new Error('ImageDecoder API is not available in this environment');
|
|
5
|
+
const decoder = new ImageDecoder({
|
|
6
|
+
data: copyArrayBuffer(data),
|
|
7
|
+
type,
|
|
8
|
+
colorSpaceConversion: options.colorSpaceConversion ?? 'none',
|
|
9
|
+
desiredWidth: options.desiredWidth,
|
|
10
|
+
desiredHeight: options.desiredHeight,
|
|
11
|
+
});
|
|
12
|
+
try {
|
|
13
|
+
const result = await decoder.decode({ frameIndex: 0, completeFramesOnly: true });
|
|
14
|
+
return result.image;
|
|
15
|
+
}
|
|
16
|
+
finally {
|
|
17
|
+
decoder.close();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function inspectFrame(frame) {
|
|
21
|
+
const colorSpace = frame.colorSpace;
|
|
22
|
+
return {
|
|
23
|
+
format: frame.format,
|
|
24
|
+
codedWidth: frame.codedWidth,
|
|
25
|
+
codedHeight: frame.codedHeight,
|
|
26
|
+
displayWidth: frame.displayWidth,
|
|
27
|
+
displayHeight: frame.displayHeight,
|
|
28
|
+
visibleRect: frame.visibleRect
|
|
29
|
+
? {
|
|
30
|
+
x: frame.visibleRect.x,
|
|
31
|
+
y: frame.visibleRect.y,
|
|
32
|
+
width: frame.visibleRect.width,
|
|
33
|
+
height: frame.visibleRect.height,
|
|
34
|
+
}
|
|
35
|
+
: null,
|
|
36
|
+
timestamp: frame.timestamp,
|
|
37
|
+
duration: frame.duration ?? null,
|
|
38
|
+
colorSpace: {
|
|
39
|
+
primaries: colorSpace.primaries,
|
|
40
|
+
transfer: colorSpace.transfer,
|
|
41
|
+
matrix: colorSpace.matrix,
|
|
42
|
+
fullRange: colorSpace.fullRange,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function classifyFrameColor(frameOrInspection) {
|
|
47
|
+
const inspection = frameOrInspection instanceof VideoFrame ? inspectFrame(frameOrInspection) : frameOrInspection;
|
|
48
|
+
const { primaries, transfer } = inspection.colorSpace;
|
|
49
|
+
const isBt709OrUnknown = primaries === 'bt709' || primaries === null;
|
|
50
|
+
const isDisplayP3Like = primaries === 'smpte432';
|
|
51
|
+
const isBt2020 = primaries === 'bt2020';
|
|
52
|
+
const isHdrTransfer = transfer === 'pq' || transfer === 'hlg';
|
|
53
|
+
const isHdrLike = isBt2020 || isHdrTransfer;
|
|
54
|
+
const isWideGamut = isDisplayP3Like || isBt2020;
|
|
55
|
+
const isSimpleSdr = isBt709OrUnknown && !isHdrTransfer;
|
|
56
|
+
const canvasColorSpace = isWideGamut ? 'display-p3' : 'srgb';
|
|
57
|
+
const recommendedPath = isHdrLike
|
|
58
|
+
? 'raw-hdr'
|
|
59
|
+
: (isWideGamut ? 'canvas-display-p3' : 'canvas-sdr');
|
|
60
|
+
const notes = [];
|
|
61
|
+
if (isHdrLike) {
|
|
62
|
+
notes.push('BT.2020/PQ/HLG-like frames should not be treated as lossless Canvas 2D round-trips.');
|
|
63
|
+
}
|
|
64
|
+
if (isWideGamut && !isHdrLike) {
|
|
65
|
+
notes.push('Display P3 Canvas 2D is a practical SDR wide-gamut path.');
|
|
66
|
+
}
|
|
67
|
+
if (isSimpleSdr) {
|
|
68
|
+
notes.push('sRGB/BT.709 SDR can usually use Canvas 2D safely for resize-style operations.');
|
|
69
|
+
}
|
|
70
|
+
return { isSimpleSdr, isWideGamut, isHdrLike, canvasColorSpace, recommendedPath, notes };
|
|
71
|
+
}
|
|
72
|
+
export async function copyFrameToRgba(frame, options = {}) {
|
|
73
|
+
const colorSpace = options.colorSpace ?? classifyFrameColor(frame).canvasColorSpace;
|
|
74
|
+
const format = options.format ?? 'RGBA';
|
|
75
|
+
const allocation = frame.allocationSize({ format, colorSpace });
|
|
76
|
+
const data = new Uint8Array(allocation);
|
|
77
|
+
const layout = await frame.copyTo(data, { format, colorSpace });
|
|
78
|
+
return {
|
|
79
|
+
data,
|
|
80
|
+
layout,
|
|
81
|
+
colorSpace,
|
|
82
|
+
format,
|
|
83
|
+
width: frame.displayWidth,
|
|
84
|
+
height: frame.displayHeight,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export function resizeFrameWithCanvas(frame, options) {
|
|
88
|
+
const colorSpace = options.colorSpace ?? classifyFrameColor(frame).canvasColorSpace;
|
|
89
|
+
const canvas = new OffscreenCanvas(options.width, options.height);
|
|
90
|
+
const context = canvas.getContext('2d', { colorSpace });
|
|
91
|
+
if (!context)
|
|
92
|
+
throw new Error('Could not create 2D canvas context');
|
|
93
|
+
context.imageSmoothingEnabled = true;
|
|
94
|
+
context.imageSmoothingQuality = options.imageSmoothingQuality ?? 'high';
|
|
95
|
+
context.drawImage(frame, 0, 0, options.width, options.height);
|
|
96
|
+
const init = { timestamp: frame.timestamp };
|
|
97
|
+
if (frame.duration !== null)
|
|
98
|
+
init.duration = frame.duration;
|
|
99
|
+
const resized = new VideoFrame(canvas, init);
|
|
100
|
+
return {
|
|
101
|
+
frame: resized,
|
|
102
|
+
inspection: inspectFrame(resized),
|
|
103
|
+
colorSpace,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export function convertFrameToCanvasSdr(frame) {
|
|
107
|
+
const canvas = new OffscreenCanvas(frame.displayWidth, frame.displayHeight);
|
|
108
|
+
const context = canvas.getContext('2d', { colorSpace: 'srgb' });
|
|
109
|
+
if (!context)
|
|
110
|
+
throw new Error('Could not create 2D canvas context');
|
|
111
|
+
context.drawImage(frame, 0, 0);
|
|
112
|
+
const image = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
113
|
+
const init = {
|
|
114
|
+
format: 'RGBA',
|
|
115
|
+
codedWidth: canvas.width,
|
|
116
|
+
codedHeight: canvas.height,
|
|
117
|
+
displayWidth: canvas.width,
|
|
118
|
+
displayHeight: canvas.height,
|
|
119
|
+
timestamp: frame.timestamp,
|
|
120
|
+
layout: [{ offset: 0, stride: canvas.width * 4 }],
|
|
121
|
+
colorSpace: sdrVideoColorSpaceInit(),
|
|
122
|
+
};
|
|
123
|
+
if (frame.duration !== null)
|
|
124
|
+
init.duration = frame.duration;
|
|
125
|
+
const converted = new VideoFrame(image.data, init);
|
|
126
|
+
return {
|
|
127
|
+
frame: converted,
|
|
128
|
+
inspection: inspectFrame(converted),
|
|
129
|
+
colorSpace: 'srgb',
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export async function resizeFrameRaw(frame, options) {
|
|
133
|
+
const format = frame.format;
|
|
134
|
+
if (!format)
|
|
135
|
+
throw new Error('Cannot raw-resize a VideoFrame with unknown format');
|
|
136
|
+
const descriptor = describePlanarFormat(format);
|
|
137
|
+
if (!descriptor)
|
|
138
|
+
throw new Error(`Raw resize does not support VideoFrame format ${format}`);
|
|
139
|
+
const sourceRect = visibleRectForCopy(frame);
|
|
140
|
+
const source = new Uint8Array(frame.allocationSize({ rect: sourceRect }));
|
|
141
|
+
const sourceLayout = await frame.copyTo(source, { rect: sourceRect });
|
|
142
|
+
const destinationLayout = makeDestinationLayout(descriptor, options.width, options.height);
|
|
143
|
+
const destination = new Uint8Array(allocationFromLayout(destinationLayout, descriptor, options.width, options.height));
|
|
144
|
+
const algorithm = options.algorithm ?? 'bilinear';
|
|
145
|
+
for (let planeIndex = 0; planeIndex < descriptor.planes.length; planeIndex++) {
|
|
146
|
+
const plane = descriptor.planes[planeIndex];
|
|
147
|
+
const srcWidth = planeDimension(sourceRect.width, plane.subsampleX);
|
|
148
|
+
const srcHeight = planeDimension(sourceRect.height, plane.subsampleY);
|
|
149
|
+
const dstWidth = planeDimension(options.width, plane.subsampleX);
|
|
150
|
+
const dstHeight = planeDimension(options.height, plane.subsampleY);
|
|
151
|
+
resizePlane({
|
|
152
|
+
source,
|
|
153
|
+
destination,
|
|
154
|
+
sourceLayout: sourceLayout[planeIndex],
|
|
155
|
+
destinationLayout: destinationLayout[planeIndex],
|
|
156
|
+
sourceWidth: srcWidth,
|
|
157
|
+
sourceHeight: srcHeight,
|
|
158
|
+
destinationWidth: dstWidth,
|
|
159
|
+
destinationHeight: dstHeight,
|
|
160
|
+
bytesPerSample: descriptor.bytesPerSample,
|
|
161
|
+
samplesPerPixel: plane.samplesPerPixel ?? 1,
|
|
162
|
+
algorithm,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
const init = {
|
|
166
|
+
format: format,
|
|
167
|
+
codedWidth: options.width,
|
|
168
|
+
codedHeight: options.height,
|
|
169
|
+
displayWidth: options.width,
|
|
170
|
+
displayHeight: options.height,
|
|
171
|
+
timestamp: frame.timestamp,
|
|
172
|
+
layout: destinationLayout,
|
|
173
|
+
colorSpace: videoColorSpaceInit(frame),
|
|
174
|
+
};
|
|
175
|
+
if (frame.duration !== null)
|
|
176
|
+
init.duration = frame.duration;
|
|
177
|
+
const resized = new VideoFrame(destination, init);
|
|
178
|
+
return {
|
|
179
|
+
frame: resized,
|
|
180
|
+
inspection: inspectFrame(resized),
|
|
181
|
+
format,
|
|
182
|
+
layout: destinationLayout,
|
|
183
|
+
byteLength: destination.byteLength,
|
|
184
|
+
algorithm,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function describePlanarFormat(format) {
|
|
188
|
+
switch (format) {
|
|
189
|
+
case 'NV12':
|
|
190
|
+
return { bytesPerSample: 1, planes: [{ subsampleX: 1, subsampleY: 1 }, { subsampleX: 2, subsampleY: 2, samplesPerPixel: 2 }] };
|
|
191
|
+
case 'I420':
|
|
192
|
+
return { bytesPerSample: 1, planes: [{ subsampleX: 1, subsampleY: 1 }, { subsampleX: 2, subsampleY: 2 }, { subsampleX: 2, subsampleY: 2 }] };
|
|
193
|
+
case 'I422':
|
|
194
|
+
return { bytesPerSample: 1, planes: [{ subsampleX: 1, subsampleY: 1 }, { subsampleX: 2, subsampleY: 1 }, { subsampleX: 2, subsampleY: 1 }] };
|
|
195
|
+
case 'I444':
|
|
196
|
+
return { bytesPerSample: 1, planes: [{ subsampleX: 1, subsampleY: 1 }, { subsampleX: 1, subsampleY: 1 }, { subsampleX: 1, subsampleY: 1 }] };
|
|
197
|
+
case 'I420P10':
|
|
198
|
+
return { bytesPerSample: 2, planes: [{ subsampleX: 1, subsampleY: 1 }, { subsampleX: 2, subsampleY: 2 }, { subsampleX: 2, subsampleY: 2 }] };
|
|
199
|
+
case 'I422P10':
|
|
200
|
+
return { bytesPerSample: 2, planes: [{ subsampleX: 1, subsampleY: 1 }, { subsampleX: 2, subsampleY: 1 }, { subsampleX: 2, subsampleY: 1 }] };
|
|
201
|
+
case 'I444P10':
|
|
202
|
+
return { bytesPerSample: 2, planes: [{ subsampleX: 1, subsampleY: 1 }, { subsampleX: 1, subsampleY: 1 }, { subsampleX: 1, subsampleY: 1 }] };
|
|
203
|
+
default:
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function visibleRectForCopy(frame) {
|
|
208
|
+
const rect = frame.visibleRect;
|
|
209
|
+
return {
|
|
210
|
+
x: rect?.x ?? 0,
|
|
211
|
+
y: rect?.y ?? 0,
|
|
212
|
+
width: rect?.width ?? frame.codedWidth,
|
|
213
|
+
height: rect?.height ?? frame.codedHeight,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function makeDestinationLayout(descriptor, width, height) {
|
|
217
|
+
let offset = 0;
|
|
218
|
+
return descriptor.planes.map((plane) => {
|
|
219
|
+
const planeWidth = planeDimension(width, plane.subsampleX);
|
|
220
|
+
const planeHeight = planeDimension(height, plane.subsampleY);
|
|
221
|
+
const stride = planeWidth * (plane.samplesPerPixel ?? 1) * descriptor.bytesPerSample;
|
|
222
|
+
const layout = { offset, stride };
|
|
223
|
+
offset += stride * planeHeight;
|
|
224
|
+
return layout;
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function allocationFromLayout(layout, descriptor, width, height) {
|
|
228
|
+
const lastPlane = descriptor.planes.length - 1;
|
|
229
|
+
const planeHeight = planeDimension(height, descriptor.planes[lastPlane].subsampleY);
|
|
230
|
+
return layout[lastPlane].offset + layout[lastPlane].stride * planeHeight;
|
|
231
|
+
}
|
|
232
|
+
function planeDimension(size, subsample) {
|
|
233
|
+
return Math.ceil(size / subsample);
|
|
234
|
+
}
|
|
235
|
+
function resizePlane(options) {
|
|
236
|
+
for (let y = 0; y < options.destinationHeight; y++) {
|
|
237
|
+
const sourceY = mapPixelCenter(y, options.destinationHeight, options.sourceHeight);
|
|
238
|
+
for (let x = 0; x < options.destinationWidth; x++) {
|
|
239
|
+
const sourceX = mapPixelCenter(x, options.destinationWidth, options.sourceWidth);
|
|
240
|
+
const value = options.algorithm === 'nearest'
|
|
241
|
+
? sampleNearest(options, sourceX, sourceY, 0)
|
|
242
|
+
: sampleBilinear(options, sourceX, sourceY, 0);
|
|
243
|
+
writeSample(options.destination, options.destinationLayout, x, y, options.bytesPerSample, options.samplesPerPixel, 0, value);
|
|
244
|
+
if (options.samplesPerPixel === 2) {
|
|
245
|
+
const secondValue = options.algorithm === 'nearest'
|
|
246
|
+
? sampleNearest(options, sourceX, sourceY, 1)
|
|
247
|
+
: sampleBilinear(options, sourceX, sourceY, 1);
|
|
248
|
+
writeSample(options.destination, options.destinationLayout, x, y, options.bytesPerSample, options.samplesPerPixel, 1, secondValue);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function mapPixelCenter(position, destinationSize, sourceSize) {
|
|
254
|
+
return (position + 0.5) * sourceSize / destinationSize - 0.5;
|
|
255
|
+
}
|
|
256
|
+
function sampleNearest(options, x, y, component) {
|
|
257
|
+
return readSample(options.source, options.sourceLayout, clamp(Math.round(x), 0, options.sourceWidth - 1), clamp(Math.round(y), 0, options.sourceHeight - 1), options.bytesPerSample, options.samplesPerPixel, component);
|
|
258
|
+
}
|
|
259
|
+
function sampleBilinear(options, x, y, component) {
|
|
260
|
+
const x0 = clamp(Math.floor(x), 0, options.sourceWidth - 1);
|
|
261
|
+
const y0 = clamp(Math.floor(y), 0, options.sourceHeight - 1);
|
|
262
|
+
const x1 = clamp(x0 + 1, 0, options.sourceWidth - 1);
|
|
263
|
+
const y1 = clamp(y0 + 1, 0, options.sourceHeight - 1);
|
|
264
|
+
const tx = clamp(x - x0, 0, 1);
|
|
265
|
+
const ty = clamp(y - y0, 0, 1);
|
|
266
|
+
const a = readSample(options.source, options.sourceLayout, x0, y0, options.bytesPerSample, options.samplesPerPixel, component);
|
|
267
|
+
const b = readSample(options.source, options.sourceLayout, x1, y0, options.bytesPerSample, options.samplesPerPixel, component);
|
|
268
|
+
const c = readSample(options.source, options.sourceLayout, x0, y1, options.bytesPerSample, options.samplesPerPixel, component);
|
|
269
|
+
const d = readSample(options.source, options.sourceLayout, x1, y1, options.bytesPerSample, options.samplesPerPixel, component);
|
|
270
|
+
return Math.round(a * (1 - tx) * (1 - ty)
|
|
271
|
+
+ b * tx * (1 - ty)
|
|
272
|
+
+ c * (1 - tx) * ty
|
|
273
|
+
+ d * tx * ty);
|
|
274
|
+
}
|
|
275
|
+
function readSample(data, layout, x, y, bytesPerSample, samplesPerPixel, component) {
|
|
276
|
+
const offset = layout.offset + y * layout.stride + (x * samplesPerPixel + component) * bytesPerSample;
|
|
277
|
+
return bytesPerSample === 1 ? data[offset] : data[offset] | (data[offset + 1] << 8);
|
|
278
|
+
}
|
|
279
|
+
function writeSample(data, layout, x, y, bytesPerSample, samplesPerPixel, component, value) {
|
|
280
|
+
const offset = layout.offset + y * layout.stride + (x * samplesPerPixel + component) * bytesPerSample;
|
|
281
|
+
data[offset] = value;
|
|
282
|
+
if (bytesPerSample === 2)
|
|
283
|
+
data[offset + 1] = value >> 8;
|
|
284
|
+
}
|
|
285
|
+
function clamp(value, min, max) {
|
|
286
|
+
return Math.min(max, Math.max(min, value));
|
|
287
|
+
}
|
|
288
|
+
function videoColorSpaceInit(frame) {
|
|
289
|
+
const colorSpace = frame.colorSpace;
|
|
290
|
+
return {
|
|
291
|
+
primaries: colorSpace.primaries,
|
|
292
|
+
transfer: colorSpace.transfer,
|
|
293
|
+
matrix: colorSpace.matrix,
|
|
294
|
+
fullRange: colorSpace.fullRange,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
export function sdrVideoColorSpaceInit() {
|
|
298
|
+
return {
|
|
299
|
+
primaries: 'bt709',
|
|
300
|
+
transfer: 'bt709',
|
|
301
|
+
matrix: 'bt709',
|
|
302
|
+
fullRange: false,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AA4ErD,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,IAAgB,EAAE,IAAY,EAAE,UAI1E,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CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,KAAK,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IACpD,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAiB;IAC5C,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;IACpC,OAAO;QACL,SAAS,EAAE,UAAU,CAAC,SAAuC;QAC7D,QAAQ,EAAE,UAAU,CAAC,QAA+C;QACpE,MAAM,EAAE,UAAU,CAAC,MAAwC;QAC3D,SAAS,EAAE,UAAU,CAAC,SAAS;KAChC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO;QACL,SAAS,EAAE,OAAO;QAClB,QAAQ,EAAE,OAAO;QACjB,MAAM,EAAE,OAAO;QACf,SAAS,EAAE,KAAK;KACjB,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@browser-mc/webcodecs-color",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@browser-mc/binary": "^0.0.1"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"prebuild": "pnpm --filter @browser-mc/binary build",
|
|
25
|
+
"build": "tsc -p tsconfig.json",
|
|
26
|
+
"pretypecheck": "pnpm --filter @browser-mc/binary build",
|
|
27
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
28
|
+
"test": "pnpm build",
|
|
29
|
+
"test:electron": "pnpm build && env -u ELECTRON_RUN_AS_NODE xvfb-run -a node test/electron-smoke.mjs"
|
|
30
|
+
}
|
|
31
|
+
}
|