|
@@ -353,6 +353,13 @@ WebIDL::ExceptionOr<JS::GCPtr<ImageData>> CanvasRenderingContext2D::get_image_da
|
|
|
|
|
|
// 5. Let the source rectangle be the rectangle whose corners are the four points (sx, sy), (sx+sw, sy), (sx+sw, sy+sh), (sx, sy+sh).
|
|
|
auto source_rect = Gfx::Rect { x, y, abs_width, abs_height };
|
|
|
+
|
|
|
+ // NOTE: The spec doesn't seem to define this behavior, but MDN does and the WPT tests
|
|
|
+ // assume it works this way.
|
|
|
+ // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getImageData#sw
|
|
|
+ if (width < 0 || height < 0) {
|
|
|
+ source_rect = source_rect.translated(min(width, 0), min(height, 0));
|
|
|
+ }
|
|
|
auto source_rect_intersected = source_rect.intersected(bitmap.rect());
|
|
|
|
|
|
// 6. Set the pixel values of imageData to be the pixels of this's output bitmap in the area specified by the source rectangle in the bitmap's coordinate space units, converted from this's color space to imageData's colorSpace using 'relative-colorimetric' rendering intent.
|