Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: d473ec91f732b22aa3f952dfc329ef6317252cdf
https://github.com/WebKit/WebKit/commit/d473ec91f732b22aa3f952dfc329ef6317252cdf
Author: Kimmo Kinnunen <[email protected]>
Date: 2026-02-10 (Tue, 10 Feb 2026)
Changed paths:
M LayoutTests/TestExpectations
A
LayoutTests/http/wpt/webcodecs/2d-drawImage-videoFrame-I420-BT709-expected.txt
A LayoutTests/http/wpt/webcodecs/2d-drawImage-videoFrame-I420-BT709.html
A LayoutTests/http/wpt/webcodecs/encoder-decoder-vp9-I420-expected.txt
A LayoutTests/http/wpt/webcodecs/encoder-decoder-vp9-I420.html
A LayoutTests/http/wpt/webcodecs/resources/videoframe-utilities.js
M LayoutTests/ipc/videoEncode.html
M LayoutTests/platform/mac/TestExpectations
M Source/WebCore/Sources.txt
M Source/WebCore/WebCore.xcodeproj/project.pbxproj
M Source/WebCore/platform/graphics/PlatformVideoColorPrimaries.h
A Source/WebCore/platform/graphics/PlatformVideoColorSpace.cpp
M Source/WebCore/platform/graphics/PlatformVideoColorSpace.h
M Source/WebCore/platform/graphics/PlatformVideoMatrixCoefficients.h
M Source/WebCore/platform/graphics/PlatformVideoTransferCharacteristics.h
M Source/WebCore/platform/graphics/cocoa/CMUtilities.h
M Source/WebCore/platform/graphics/cocoa/CMUtilities.mm
M Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.mm
M Source/WebCore/platform/graphics/cv/VideoFrameCV.h
M Source/WebCore/platform/graphics/cv/VideoFrameCV.mm
M Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp
M Source/WebKit/WebProcess/GPU/webrtc/SampleBufferDisplayLayer.cpp
M Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.cpp
M Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.h
M Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.serialization.in
Log Message:
-----------
I420 BT709 VideoFrame is drawn incorrectly to 2D context
https://bugs.webkit.org/show_bug.cgi?id=305048
rdar://167688407
Reviewed by Youenn Fablet.
Consider case:
const v = new VideoFrame(i420Data, { format: "I420", ... });
ctx.drawImage(v, 0, 0);
On Cocoa, the data is put to CVPixelBufferRef. Upon the draw, the I420
data is converted to RGB with VTPixelTransferSession (currently through
the VTPixelBufferConformer API).
VTPixelTransferSession expects the CVPixelBufferRef to be configured
with the color space properties. However, VideoFrameCV did not do this.
Thus the conversion is done in wrong color space and results in
incorrect pixel values, likely values for BT.601.
Fix by always ensuring that the WebKit -created CVPixelBuffers for
VideoFrames set the color space properties.
Test:
http/wpt/webcodecs/2d-drawImage-videoFrame-I420-BT709.html
Tests the bug above.
http/wpt/webcodecs/2d-drawImage-videoFrame-I420-BT709.html
FIXME:
Tests a bug that might be need to be fixed in this patch:
Create sRGB RGB image with a component that has 255 in it (say RGB 255, 255,
40). 2. Create BT709 VideoFrame out of that.
3. Encode the VideoFrame to VP9 via VideoEncoder.
4. Decode the VP9 to VideoFrame via VideoDecoder.
5. The new VideoFrame is in BT709.
6. Draw the VideoFrame and check the components.
7. The component comes out as 239. Expected is to get that 255+-4 back.
Other browsers pass the test.
Either the encode or the decode does not use the correct colorspace at some
point. BT.601 is likely used, as that can't represent RGB 255. BT709 can.
*
LayoutTests/http/wpt/webcodecs/2d-drawImage-videoFrame-I420-BT709-expected.txt:
Added.
* LayoutTests/http/wpt/webcodecs/2d-drawImage-videoFrame-I420-BT709.html: Added.
* LayoutTests/http/wpt/webcodecs/encoder-decoder-vp9-I420.html: Added.
* LayoutTests/http/wpt/webcodecs/resources/videoframe-utilities.js: Added.
(sRGBToBT709Gamma):
(sRGBImageDataToI420BT709):
(BT709ToSRGBGamma):
(I420BT709ToSRGB):
(createTestPattern):
(diffCanvas):
(async encodeDecodeVideoFrame):
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/platform/graphics/PlatformVideoColorPrimaries.h:
* Source/WebCore/platform/graphics/PlatformVideoColorSpace.cpp: Added.
(WebCore::operator<<):
* Source/WebCore/platform/graphics/PlatformVideoColorSpace.h:
* Source/WebCore/platform/graphics/PlatformVideoMatrixCoefficients.h:
* Source/WebCore/platform/graphics/PlatformVideoTransferCharacteristics.h:
* Source/WebCore/platform/graphics/cocoa/CMUtilities.h:
* Source/WebCore/platform/graphics/cocoa/CMUtilities.mm:
(WebCore::computeVideoFrameColorSpace):
* Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.mm:
(WebCore::ImageRotationSessionVT::applyRotation):
* Source/WebCore/platform/graphics/cv/VideoFrameCV.h:
(WebCore::VideoFrameCV::create): Deleted.
* Source/WebCore/platform/graphics/cv/VideoFrameCV.mm:
(WebCore::VideoFrameCV::create):
(WebCore::computeVideoFrameColorSpace): Deleted.
* Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:
(WebKit::LibWebRTCCodecs::encodeFrameInternal):
* Source/WebKit/WebProcess/GPU/webrtc/SampleBufferDisplayLayer.cpp:
(WebKit::SampleBufferDisplayLayer::enqueueBlackFrameFrom):
* Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.cpp:
(WebKit::SharedVideoFrameWriter::write):
(WebKit::SharedVideoFrameReader::read):
* Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.h:
* Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.serialization.in:
Canonical link: https://commits.webkit.org/307179@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications