Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
createImageBitmap using ImageData doesn't respect the premultiply flag.
https://bugs.webkit.org/show_bug.cgi?id=237082
<rdar://89382358>

Reviewed by Brent Fulgham.

This path used the flag to premultiply the incoming data, but didn't mark the resulting ImageBitmap as wanting premultiplied data.
When uploading a WebGL texture we'd check for the flag, and unpremultiply again since it wasn't there.

* LayoutTests/webgl/2.0.0/resources/webgl_test_files/js/tests/tex-image-and-sub-image-2d-with-image-bitmap-from-image-data.js:
(init):
(generateTest):
* Source/WebCore/html/ImageBitmap.cpp:
(WebCore::ImageBitmap::createPromise):

Canonical link: https://commits.webkit.org/263137@main
  • Loading branch information
mattwoodrow authored and Brent Fulgham committed Apr 19, 2023
1 parent 55036f7 commit aa1ea27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Expand Up @@ -51,12 +51,12 @@ function generateTest(internalFormat, pixelFormat, pixelType, prologue, resource

var imageData = new ImageData(new Uint8ClampedArray(
[255, 0, 0, 255,
255, 0, 0, 0,
255, 0, 0, 128,
0, 255, 0, 255,
0, 255, 0, 0]),
0, 255, 0, 128]),
2, 2);

runImageBitmapTest(imageData, 0, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, false)
runImageBitmapTest(imageData, 0.5, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, false)
.then(() => {
finishTest();
});
Expand Down
16 changes: 12 additions & 4 deletions Source/WebCore/html/ImageBitmap.cpp
Expand Up @@ -866,9 +866,12 @@ void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext,
auto alphaPremultiplication = alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha);
if (sourceRectangle.returnValue().location().isZero() && sourceRectangle.returnValue().size() == imageData->size() && sourceRectangle.returnValue().size() == outputSize && options.orientation == ImageBitmapOptions::Orientation::None) {
bitmapData->putPixelBuffer(imageData->pixelBuffer(), sourceRectangle.releaseReturnValue(), { }, alphaPremultiplication);

auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData)));
// The result is implicitly origin-clean, and alpha premultiplication has already been handled.

OptionSet<SerializationState> serializationState = SerializationState::OriginClean;
if (alphaPremultiplication == AlphaPremultiplication::Premultiplied)
serializationState.add(SerializationState::PremultiplyAlpha);

auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState));
promise.resolve(WTFMove(imageBitmap));
return;
}
Expand All @@ -885,7 +888,12 @@ void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext,
bitmapData->context().drawImageBuffer(*tempBitmapData, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), options.resolvedImageOrientation(ImageOrientation::Orientation::None) });

// 6.4.1. Resolve p with ImageBitmap.
auto imageBitmap = create({ WTFMove(bitmapData) });
OptionSet<SerializationState> serializationState = SerializationState::OriginClean;
if (alphaPremultiplication == AlphaPremultiplication::Premultiplied)
serializationState.add(SerializationState::PremultiplyAlpha);

auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState));

// The result is implicitly origin-clean, and alpha premultiplication has already been handled.
promise.resolve(WTFMove(imageBitmap));
}
Expand Down

0 comments on commit aa1ea27

Please sign in to comment.