Skip to content

Commit 33f79ae

Browse files
committed
Rewritten "Convert to RGB frame" algo
1 parent 83a92e4 commit 33f79ae

File tree

1 file changed

+28
-38
lines changed

1 file changed

+28
-38
lines changed

index.src.html

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3771,15 +3771,11 @@
37713771
{{RGBA}}, {{RGBX}}, {{BGRA}}, {{BGRX}} then:
37723772
1. Let |newOptions| be the result of running the <a>Clone Configuration</a>
37733773
algorithm with |options|.
3774-
2. Assign `undefined` to |newOptions|.{{VideoFrameCopyToOptions/format}}
3775-
and |newOptions|.{{VideoFrameCopyToOptions/rect}}.
3776-
3. Let |rect| be `undefined`.
3777-
4. If |options|.{{VideoFrameCopyToOptions/rect}} [=map/exists=], assign the
3778-
value of |options|.{{VideoFrameCopyToOptions/rect}} to |rect|.
3779-
5. Otherwise, assign the value of {{VideoFrame/visibleRect}} to |rect|.
3780-
6. Let |rgbFrame| be the result of running the [=VideoFrame/Convert to RGB frame=]
3781-
algorithm with |options|.{{VideoFrameCopyToOptions/format}}, |rect|, and `options.colorSpace`.
3782-
7. Return the result of calling {{VideoFrame/copyTo()}} on |rgbFrame| with
3774+
2. Assign `undefined` to |newOptions|.{{VideoFrameCopyToOptions/format}}.
3775+
3. Let |rgbFrame| be the result of running the [=VideoFrame/Convert to RGB frame=]
3776+
algorithm with [=this=], |options|.{{VideoFrameCopyToOptions/format}},
3777+
and |options|.{{VideoFrameCopyToOptions/colorSpace}}.
3778+
4. Return the result of calling {{VideoFrame/copyTo()}} on |rgbFrame| with
37833779
|destination| and |newOptions|.
37843780
7. Otherwise, if |options|.{{VideoFrameCopyToOptions/format}} is not `undefined` or `null`
37853781
throw a {{NotSupportedError}} {{DOMException}}.
@@ -4209,35 +4205,29 @@
42094205
[=combined buffer layout/allocationSize=].
42104206
9. Return |combinedLayout|.
42114207

4212-
: <dfn for=VideoFrame>Convert to RGB frame</dfn> (with |format|, |rect| and |colorSpace|)
4213-
:: 1. Let |canvas| be a new {{OffscreenCanvas}} constructed with
4214-
|rect|.|width| and |rect|.|height|.
4215-
2. Let |canvasSettings| be a new {{CanvasRenderingContext2DSettings}} with
4216-
{{CanvasRenderingContext2DSettings/colorSpace}} set to |colorSpace|.
4217-
3. Let |context| be the result of calling {{OffscreenCanvas/getContext()}}
4218-
on |canvas| with `"2d"` and |canvasSettings|.
4219-
3. Call {{CanvasDrawImage/drawImage()}} on |context| with
4220-
`rect.x`, `rect.y`, `rect.width`, `rect.height`, `0`, `0`, `rect.width`,
4221-
`rect.height`.
4222-
4. Let |imageData| be the result of calling {{CanvasImageData/getImageData()}} with
4223-
`0`, `0`, |rect.width|, |rect.height|.
4224-
5. If |format| is equal to {{BGRA}} or {{BGRX}}:
4225-
1. Let |pixelIndex| be `0`.
4226-
2. While |pixelIndex| is less than `rect.width` multiplied by `rect.height`:
4227-
1. Swap elements in |imageData|.{{ImageData/data}} at indexes `4 * pixelIndex`
4228-
and `4 * pixelIndex + 2`.
4229-
2. Increment |pixelIndex| by `1`.
4230-
6. Let |init| be a new {{VideoFrameBufferInit}} constructed with
4231-
{{VideoFrameBufferInit/format}} = |format|,
4232-
{{VideoFrameBufferInit/codedWidth}} = `rect.width`,
4233-
{{VideoFrameBufferInit/codedHeight}} = `rect.height`.
4234-
7. Let |convertedFrame| be a new {{VideoFrame}} constructed with
4235-
|imageData|.{{ImageData/data}} and |init|.
4236-
8. Return |convertedFrame|.
4237-
4238-
NOTE: User Agents don't have to execute the exact steps of this algorithm
4239-
(e.g. create an {{OffscreenCanvas}}) as long as the {{VideoFrame}} returned by
4240-
the algorithm is equal to the {{VideoFrame}} created via these steps.
4208+
: <dfn for=VideoFrame>Convert to RGB frame</dfn> (with |frame|, |format| and |colorSpace|)
4209+
:: 1. If |format| is not equal to one {{RGBA}}, {{RGBX}}, {{BGRA}}, {{BGRX}},
4210+
throw a {{NotSupportedError}}
4211+
1. Let |convertedFrame| be a new {{VideoFrame}}, constructed as follows:
4212+
1. Assign `false` to {{platform object/[[Detached]]}}.
4213+
2. Assign |format| to {{VideoFrame/[[format]]}}.
4214+
3. Let |width| be |frame|'s {{VideoFrame/[[visible width]]}}.
4215+
4. Let |height| be |frame|'s {{VideoFrame/[[visible height]]}}.
4216+
5. Assign |width|, |height|, 0, 0, |width|, |height|, |width|, and
4217+
|height| to {{VideoFrame/[[coded width]]}},
4218+
{{VideoFrame/[[coded height]]}}, {{VideoFrame/[[visible left]]}},
4219+
{{VideoFrame/[[visible top]]}}, {{VideoFrame/[[visible width]]}},
4220+
and {{VideoFrame/[[visible height]]}} respectively.
4221+
6. Assign |frame|'s {{VideoFrame/[[duration]]}} and |frame|'s
4222+
{{VideoFrame/[[timestamp]]}} to {{VideoFrame/[[duration]]}} and
4223+
{{VideoFrame/[[timestamp]]}} respectively.
4224+
7. Assign |colorSpace| to {{VideoFrame/[[color space]]}}.
4225+
8. Let |resource| be a new [=media resource=] containing the result of
4226+
conversion of [=media resource=] referenced by |frame|'s
4227+
{{VideoFrame/[[resource reference]]}} into a color space and pixel
4228+
format specified by |colorSpace| and |format| respectively.
4229+
9. Assign the reference to |resource| to {{VideoFrame/[[resource reference]]}}
4230+
2. Return |convertedFrame|.
42414231

42424232
: <dfn for=VideoFrame>Copy VideoFrame metadata</dfn> (with |metadata|)
42434233
:: 1. Let |metadataCopySerialized| be [$StructuredSerialize$](|metadata|).

0 commit comments

Comments
 (0)