Skip to content

Commit f1571c4

Browse files
tcl3gmta
authored andcommitted
LibWeb: Ensure drawImage() always uses the first image frame
1 parent 2c78fd5 commit f1571c4

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,14 @@ WebIDL::ExceptionOr<void> CanvasRenderingContext2D::draw_image_internal(CanvasIm
136136

137137
auto bitmap = image.visit(
138138
[](GC::Root<HTMLImageElement> const& source) -> RefPtr<Gfx::ImmutableBitmap> {
139-
return source->immutable_bitmap();
139+
auto width = source->intrinsic_width().value_or({}).to_int();
140+
auto height = source->intrinsic_height().value_or({}).to_int();
141+
return source->default_image_bitmap_sized({ width, height });
140142
},
141143
[](GC::Root<SVG::SVGImageElement> const& source) -> RefPtr<Gfx::ImmutableBitmap> {
142-
return source->current_image_bitmap();
144+
auto width = source->intrinsic_width().value_or({}).to_int();
145+
auto height = source->intrinsic_height().value_or({}).to_int();
146+
return source->default_image_bitmap_sized({ width, height });
143147
},
144148
[](GC::Root<OffscreenCanvas> const& source) -> RefPtr<Gfx::ImmutableBitmap> { return Gfx::ImmutableBitmap::create(*source->bitmap()); },
145149
[](GC::Root<HTMLCanvasElement> const& source) -> RefPtr<Gfx::ImmutableBitmap> {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Harness status: OK
2+
3+
Found 1 tests
4+
5+
1 Pass
6+
Pass drawImage() of an animated GIF draws the first frame
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
4+
<title>Canvas test: 2d.drawImage.animated.gif</title>
5+
<script src="../../../../resources/testharness.js"></script>
6+
<script src="../../../../resources/testharnessreport.js"></script>
7+
<script src="../../../../html/canvas/resources/canvas-tests.js"></script>
8+
<link rel="stylesheet" href="../../../../html/canvas/resources/canvas-tests.css">
9+
<body class="show_output">
10+
11+
<h1>2d.drawImage.animated.gif</h1>
12+
<p class="desc">drawImage() of an animated GIF draws the first frame</p>
13+
14+
15+
<p class="output">Actual output:</p>
16+
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
17+
<p class="output expectedtext">Expected output:<p><img src="../../../../images/green-100x50.png" class="output expected" id="expected" alt="">
18+
<ul id="d"></ul>
19+
<script>
20+
var t = async_test("drawImage() of an animated GIF draws the first frame");
21+
_addTest(function(canvas, ctx) {
22+
23+
deferTest();
24+
step_timeout(t.step_func_done(function () {
25+
ctx.drawImage(document.getElementById('anim-gr.gif'), 0, 0);
26+
_assertPixelApprox(canvas, 50,25, 0,255,0,255, 2);
27+
}), 500);
28+
29+
});
30+
</script>
31+
<img src="../../../../images/anim-gr.gif" id="anim-gr.gif" class="resource">
32+
241 Bytes
Loading

0 commit comments

Comments
 (0)