Bug 1904471 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

In [videoFrame-copyTo-rgb.any.js](https://searchfox.org/mozilla-central/rev/64ddb621a0d3905fc2e3df475517d4163d377b22/testing/web-platform/tests/webcodecs/videoFrame-copyTo-rgb.any.js), the test requires to convert the underlying image data into `Display-P3`, but Gecko currently has no implementation for this. The conversion should adapt the image to match the Display-P3 color space parameters as defined in the CSS Color: https://drafts.csswg.org/css-color-4/#predefined-display-p3

Some open-source libraries such as [Skia](https://skia.org/) or [Little-CMS](https://www.littlecms.com/) might help us to handle this task efficiently.
In [videoFrame-copyTo-rgb.any.js](https://searchfox.org/mozilla-central/rev/64ddb621a0d3905fc2e3df475517d4163d377b22/testing/web-platform/tests/webcodecs/videoFrame-copyTo-rgb.any.js), the test requires to convert the underlying image data into `Display-P3`, but Gecko currently has no implementation for this. The conversion should adapt the image to match the Display-P3 color space parameters as defined in the CSS Color: https://drafts.csswg.org/css-color-4/#predefined-display-p3

In bug 1902115, only srgb conversion was resolved. The conversion to `display-p3`  should be done here. There was a visual [test page](https://bug1902115.bmoattachments.org/attachment.cgi?id=9410049) I used during implementing bug 1902115. The online demo is [here](https://chunminchang.github.io/playground/webcodecs/videoFrame-copyTo-rgb.html), which might be updated from times to times.
Investigate how to do display-p3 color conversion for [videoFrame-copyTo-rgb.any.js](https://searchfox.org/mozilla-central/rev/64ddb621a0d3905fc2e3df475517d4163d377b22/testing/web-platform/tests/webcodecs/videoFrame-copyTo-rgb.any.js)

In bug 1902115, only srgb conversion was resolved. The conversion to `display-p3`  should be done here. There was a visual [test page](https://bug1902115.bmoattachments.org/attachment.cgi?id=9410049) I used during implementing bug 1902115. The online demo is [here](https://chunminchang.github.io/playground/webcodecs/videoFrame-copyTo-rgb.html), which might be updated from times to times.
Investigate how to do display-p3 color conversion for [videoFrame-copyTo-rgb.any.js](https://searchfox.org/mozilla-central/rev/64ddb621a0d3905fc2e3df475517d4163d377b22/testing/web-platform/tests/webcodecs/videoFrame-copyTo-rgb.any.js)

There was a visual [test page](https://bug1902115.bmoattachments.org/attachment.cgi?id=9410049) I used during implementing bug 1902115. The online demo is [here](https://chunminchang.github.io/playground/webcodecs/videoFrame-copyTo-rgb.html), which might be updated from times to times.
Investigate how to properly convert color for `display-p3` in [videoFrame-copyTo-rgb.any.js](https://searchfox.org/mozilla-central/rev/64ddb621a0d3905fc2e3df475517d4163d377b22/testing/web-platform/tests/webcodecs/videoFrame-copyTo-rgb.any.js). The R, G, B ,A values converted in Gecko implemented in bug 1902115 is different from the values in Chrome.

This is a visual [test page](https://bug1902115.bmoattachments.org/attachment.cgi?id=9410049) that can help us to compare the values. The online demo is [here](https://chunminchang.github.io/playground/webcodecs/videoFrame-copyTo-rgb.html), which might be updated from times to times.
Investigate how to properly convert color for `display-p3` in [videoFrame-copyTo-rgb.any.js](https://searchfox.org/mozilla-central/rev/64ddb621a0d3905fc2e3df475517d4163d377b22/testing/web-platform/tests/webcodecs/videoFrame-copyTo-rgb.any.js). The R, G, B ,A values converted in Gecko implemented in bug 1902115 is different from the values in Chrome. The conversion can probably be implemented via [skia](https://skia.org/)'s APIs.

This is a visual [test page](https://bug1902115.bmoattachments.org/attachment.cgi?id=9410049) that can help to compare the values between Firefox and Chrome. The online demo is [here](https://chunminchang.github.io/playground/webcodecs/videoFrame-copyTo-rgb.html), which might be updated from times to times.

-------------------------------

update: Here is an example of the conversion. I'll try this and submit the patch if it works.

```cpp
void ConvertSRGBBufferToDisplayP3(uint8_t* srcBuffer, int width, int height, uint8_t* dstBuffer) {
    // Define the source image info with sRGB color space
    auto srcColorSpace = SkColorSpace::MakeSRGB();
    SkImageInfo srcInfo = SkImageInfo::Make(width, height, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, srcColorSpace);

    // Create a SkBitmap from the source buffer
    SkBitmap srcBitmap;
    srcBitmap.installPixels(srcInfo, srcBuffer, width * 4);

    // Define the target color space (Display-P3)
    auto dstColorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDisplayP3);

    // Create a destination SkBitmap with Display-P3 color space
    SkBitmap dstBitmap;
    dstBitmap.allocPixels(srcInfo.makeColorSpace(dstColorSpace));

    // Copy and convert the source bitmap to the destination bitmap
    srcBitmap.readPixels(dstBitmap.pixmap());

    // Extract the pixel data from dstBitmap if needed
    memcpy(dstBuffer, dstBitmap.getPixels(), width * height * 4);
}
```
Investigate how to properly convert color for `display-p3` in [videoFrame-copyTo-rgb.any.js](https://searchfox.org/mozilla-central/rev/64ddb621a0d3905fc2e3df475517d4163d377b22/testing/web-platform/tests/webcodecs/videoFrame-copyTo-rgb.any.js). The R, G, B ,A values converted in Gecko implemented in bug 1902115 is different from the values in Chrome. The conversion can probably be implemented via [skia](https://skia.org/)'s APIs.

This is a visual [test page](https://bug1902115.bmoattachments.org/attachment.cgi?id=9410049) that can help to compare the values between Firefox and Chrome. The online demo is [here](https://chunminchang.github.io/playground/webcodecs/videoFrame-copyTo-rgb.html), which might be updated from times to times.

-------------------------------

update: Here is an example of the conversion. I'll try this and submit the patch if it works.

```cpp
void ConvertSRGBBufferToDisplayP3(uint8_t* srcBuffer, int width, int height, uint8_t* dstBuffer) {
    auto srcColorSpace = SkColorSpace::MakeSRGB();
    SkImageInfo srcInfo = SkImageInfo::Make(width, height, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, srcColorSpace);

    SkBitmap srcBitmap;
    srcBitmap.installPixels(srcInfo, srcBuffer, width * 4);

    auto dstColorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDisplayP3);

    SkBitmap dstBitmap;
    dstBitmap.allocPixels(srcInfo.makeColorSpace(dstColorSpace));

    srcBitmap.readPixels(dstBitmap.pixmap());

    memcpy(dstBuffer, dstBitmap.getPixels(), width * height * 4);
}
```

Back to Bug 1904471 Comment 0