LibWeb: Ensure putImageData() is unaffected by drawing state

This commit is contained in:
Tim Ledbetter 2025-10-20 14:34:30 +01:00 committed by Jelle Raaijmakers
parent 2ac4544a81
commit d3ca038b2c
Notes: github-actions[bot] 2025-10-21 07:53:34 +00:00
3 changed files with 50 additions and 1 deletions

View file

@ -600,14 +600,18 @@ WebIDL::ExceptionOr<void> CanvasRenderingContext2D::put_pixels_from_an_image_dat
// imageData data structure's bitmap, converted from imageData's colorSpace to the color space of bitmap using
// 'relative-colorimetric' rendering intent.
auto dst_rect = Gfx::FloatRect { dx + dirty_x, dy + dirty_y, dirty_width, dirty_height };
painter.save();
painter.set_transform({});
painter.draw_bitmap(
dst_rect,
Gfx::ImmutableBitmap::create(image_data.bitmap(), Gfx::AlphaType::Unpremultiplied),
Gfx::IntRect { dirty_x, dirty_y, dirty_width, dirty_height },
Gfx::ScalingMode::NearestNeighbor,
drawing_state().filter,
{},
1.0f,
Gfx::CompositingAndBlendingOperator::SourceOver);
painter.restore();
did_draw(dst_rect);
return {};

View file

@ -0,0 +1,6 @@
Harness status: OK
Found 1 tests
1 Pass
Pass putImageData() is not affected by context state

View file

@ -0,0 +1,39 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<title>Canvas test: 2d.imageData.put.unaffected</title>
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<script src="../../../../html/canvas/resources/canvas-tests.js"></script>
<link rel="stylesheet" href="../../../../html/canvas/resources/canvas-tests.css">
<body class="show_output">
<h1>2d.imageData.put.unaffected</h1>
<p class="desc">putImageData() is not affected by context state</p>
<p class="output">Actual output:</p>
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
<p class="output expectedtext">Expected output:<p><img src="../../../../images/green-100x50.png" class="output expected" id="expected" alt="">
<ul id="d"></ul>
<script>
var t = async_test("putImageData() is not affected by context state");
_addTest(function(canvas, ctx) {
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50)
var imgdata = ctx.getImageData(0, 0, 100, 50);
ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, 100, 50)
ctx.globalAlpha = 0.1;
ctx.globalCompositeOperation = 'destination-atop';
ctx.shadowColor = '#f00';
ctx.shadowBlur = 1;
ctx.translate(100, 50);
ctx.scale(0.1, 0.1);
ctx.putImageData(imgdata, 0, 0);
_assertPixelApprox(canvas, 50,25, 0,255,0,255, 2);
});
</script>