haikuwebkit/LayoutTests/fast/images/exif-orientation-canvas.html

127 lines
4.0 KiB
HTML
Raw Permalink Normal View History

Source/WebCore: EXIF orientation should be respected when rendering images https://bugs.webkit.org/show_bug.cgi?id=201123 Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2019-08-31 Reviewed by Simon Fraser. -- Image::size() will return the rendered size based on the image orientation. If image orientation is FromImage, ImageSource will query the actual image orientation from the ImageDecoder. The low level APIs might transpose the size just before calling the system API to draw the image. -- RenderElement::imageOrientation() will return ImageOrientation::FromImage for all images and for all ports till the CSS image-orientation specs is finalized. -- The default of ImagePaintingOptions argument of GraphicsContext::drawImage() will be changed to { ImageOrientation::FromImage }. -- Image element: RenderImage::paintIntoRect() will pass imageOrientation() which returns ImageOrientation::FromImage to GraphicsContext::drawImage(). -- CSS background image: RenderBoxModelObject::paintFillLayerExtended will pass ImageOrientation::FromImage by default to GraphicsContext::drawTiledImage(). -- Images on canvas: CanvasRenderingContext2DBase::drawImage() will pass ImageOrientation::FromImage by default to GraphicsContext::drawImage(). -- SVG images: RenderSVGImage::paintForeground() calls GraphicsContext::drawImage() with the default ImagePaintingOptions which is now { ImageOrientation::FromImage }. -- SVG feImage filters: FEImage::platformApplySoftware() calls GraphicsContext::drawImage() with the default ImagePaintingOptions which is now { ImageOrientation::FromImage }. -- ImageDocument: RenderElement::imageOrientation() returns FromImage always and for all ports. Tests: fast/images/exif-orientation-background.html fast/images/exif-orientation-canvas.html fast/images/exif-orientation-content.html fast/images/exif-orientation-element-object-fit.html fast/images/exif-orientation-element.html fast/images/exif-orientation-image-object.html fast/images/exif-orientation-svg-feimage.html fast/images/exif-orientation-svg-image.html * html/canvas/CanvasRenderingContext2DBase.cpp: (WebCore::CanvasRenderingContext2DBase::drawImage): * loader/cache/CachedImage.cpp: (WebCore::CachedImage::imageSizeForRenderer const): * platform/graphics/BitmapImage.h: * platform/graphics/CrossfadeGeneratedImage.h: * platform/graphics/GeneratedImage.h: * platform/graphics/GraphicsContext.h: (WebCore::GraphicsContext::drawImage): * platform/graphics/Image.h: * platform/graphics/ImageFrame.h: (WebCore::ImageFrame::sizeRespectingOrientation const): Deleted. * platform/graphics/ImageSource.cpp: (WebCore::ImageSource::ImageSource): (WebCore::ImageSource::orientation): (WebCore::ImageSource::size): (WebCore::ImageSource::sizeRespectingOrientation): Deleted. * platform/graphics/ImageSource.h: * platform/graphics/cg/PDFDocumentImage.cpp: (WebCore::PDFDocumentImage::size const): * platform/graphics/cg/PDFDocumentImage.h: * platform/mac/DragImageMac.mm: (WebCore::createDragImageFromImage): * rendering/RenderBoxModelObject.cpp: (WebCore::RenderBoxModelObject::paintFillLayerExtended): * rendering/RenderElement.cpp: (WebCore::RenderElement::imageOrientation const): * rendering/RenderImage.cpp: (WebCore::RenderImage::paintIntoRect): * svg/graphics/SVGImage.h: * svg/graphics/SVGImageForContainer.cpp: (WebCore::SVGImageForContainer::size const): * svg/graphics/SVGImageForContainer.h: LayoutTests: EXIF orientation should be respected when rendering images https://bugs.webkit.org/show_bug.cgi?id=201123 Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2019-08-31 Reviewed by Simon Fraser. Existing tests are made ref-tests. New tests were added to cover more cases for drawing images. * fast/images/exif-orientation-background-expected.html: Added. * fast/images/exif-orientation-background.html: Added. * fast/images/exif-orientation-canvas-expected.html: Added. * fast/images/exif-orientation-canvas.html: Added. * fast/images/exif-orientation-composited-expected.html: Added. * fast/images/exif-orientation-composited-expected.txt: Removed. * fast/images/exif-orientation-composited.html: * fast/images/exif-orientation-content-expected.html: Added. * fast/images/exif-orientation-content.html: Added. * fast/images/exif-orientation-css-expected.txt: Removed. * fast/images/exif-orientation-css.html: Removed. * fast/images/exif-orientation-element-expected.html: Added. * fast/images/exif-orientation-element-object-fit-expected.html: Added. * fast/images/exif-orientation-element-object-fit.html: Added. * fast/images/exif-orientation-element.html: Added. * fast/images/exif-orientation-expected.txt: Removed. * fast/images/exif-orientation-image-document-expected.html: Added. * fast/images/exif-orientation-image-document-expected.txt: Removed. * fast/images/exif-orientation-image-document.html: * fast/images/exif-orientation-image-object-expected.html: Added. * fast/images/exif-orientation-image-object.html: Added. * fast/images/exif-orientation-svg-feimage-expected.html: Added. * fast/images/exif-orientation-svg-feimage.html: Added. * fast/images/exif-orientation-svg-image-expected.html: Added. * fast/images/exif-orientation-svg-image.html: Added. * fast/images/exif-orientation.html: Removed. * platform/gtk/TestExpectations: * platform/mac/fast/images/exif-orientation-composited-expected.png: Removed. * platform/win/TestExpectations: Canonical link: https://commits.webkit.org/215033@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249364 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-09-01 00:47:39 +00:00
<!DOCTYPE html>
<style>
div.container {
display: inline-block;
margin-right: 20px;
margin-bottom: 10px;
width: 100px;
vertical-align: top;
}
div.horizontal {
width: 102px;
Source/WebCore: EXIF orientation should be respected when rendering images https://bugs.webkit.org/show_bug.cgi?id=201123 Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2019-08-31 Reviewed by Simon Fraser. -- Image::size() will return the rendered size based on the image orientation. If image orientation is FromImage, ImageSource will query the actual image orientation from the ImageDecoder. The low level APIs might transpose the size just before calling the system API to draw the image. -- RenderElement::imageOrientation() will return ImageOrientation::FromImage for all images and for all ports till the CSS image-orientation specs is finalized. -- The default of ImagePaintingOptions argument of GraphicsContext::drawImage() will be changed to { ImageOrientation::FromImage }. -- Image element: RenderImage::paintIntoRect() will pass imageOrientation() which returns ImageOrientation::FromImage to GraphicsContext::drawImage(). -- CSS background image: RenderBoxModelObject::paintFillLayerExtended will pass ImageOrientation::FromImage by default to GraphicsContext::drawTiledImage(). -- Images on canvas: CanvasRenderingContext2DBase::drawImage() will pass ImageOrientation::FromImage by default to GraphicsContext::drawImage(). -- SVG images: RenderSVGImage::paintForeground() calls GraphicsContext::drawImage() with the default ImagePaintingOptions which is now { ImageOrientation::FromImage }. -- SVG feImage filters: FEImage::platformApplySoftware() calls GraphicsContext::drawImage() with the default ImagePaintingOptions which is now { ImageOrientation::FromImage }. -- ImageDocument: RenderElement::imageOrientation() returns FromImage always and for all ports. Tests: fast/images/exif-orientation-background.html fast/images/exif-orientation-canvas.html fast/images/exif-orientation-content.html fast/images/exif-orientation-element-object-fit.html fast/images/exif-orientation-element.html fast/images/exif-orientation-image-object.html fast/images/exif-orientation-svg-feimage.html fast/images/exif-orientation-svg-image.html * html/canvas/CanvasRenderingContext2DBase.cpp: (WebCore::CanvasRenderingContext2DBase::drawImage): * loader/cache/CachedImage.cpp: (WebCore::CachedImage::imageSizeForRenderer const): * platform/graphics/BitmapImage.h: * platform/graphics/CrossfadeGeneratedImage.h: * platform/graphics/GeneratedImage.h: * platform/graphics/GraphicsContext.h: (WebCore::GraphicsContext::drawImage): * platform/graphics/Image.h: * platform/graphics/ImageFrame.h: (WebCore::ImageFrame::sizeRespectingOrientation const): Deleted. * platform/graphics/ImageSource.cpp: (WebCore::ImageSource::ImageSource): (WebCore::ImageSource::orientation): (WebCore::ImageSource::size): (WebCore::ImageSource::sizeRespectingOrientation): Deleted. * platform/graphics/ImageSource.h: * platform/graphics/cg/PDFDocumentImage.cpp: (WebCore::PDFDocumentImage::size const): * platform/graphics/cg/PDFDocumentImage.h: * platform/mac/DragImageMac.mm: (WebCore::createDragImageFromImage): * rendering/RenderBoxModelObject.cpp: (WebCore::RenderBoxModelObject::paintFillLayerExtended): * rendering/RenderElement.cpp: (WebCore::RenderElement::imageOrientation const): * rendering/RenderImage.cpp: (WebCore::RenderImage::paintIntoRect): * svg/graphics/SVGImage.h: * svg/graphics/SVGImageForContainer.cpp: (WebCore::SVGImageForContainer::size const): * svg/graphics/SVGImageForContainer.h: LayoutTests: EXIF orientation should be respected when rendering images https://bugs.webkit.org/show_bug.cgi?id=201123 Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2019-08-31 Reviewed by Simon Fraser. Existing tests are made ref-tests. New tests were added to cover more cases for drawing images. * fast/images/exif-orientation-background-expected.html: Added. * fast/images/exif-orientation-background.html: Added. * fast/images/exif-orientation-canvas-expected.html: Added. * fast/images/exif-orientation-canvas.html: Added. * fast/images/exif-orientation-composited-expected.html: Added. * fast/images/exif-orientation-composited-expected.txt: Removed. * fast/images/exif-orientation-composited.html: * fast/images/exif-orientation-content-expected.html: Added. * fast/images/exif-orientation-content.html: Added. * fast/images/exif-orientation-css-expected.txt: Removed. * fast/images/exif-orientation-css.html: Removed. * fast/images/exif-orientation-element-expected.html: Added. * fast/images/exif-orientation-element-object-fit-expected.html: Added. * fast/images/exif-orientation-element-object-fit.html: Added. * fast/images/exif-orientation-element.html: Added. * fast/images/exif-orientation-expected.txt: Removed. * fast/images/exif-orientation-image-document-expected.html: Added. * fast/images/exif-orientation-image-document-expected.txt: Removed. * fast/images/exif-orientation-image-document.html: * fast/images/exif-orientation-image-object-expected.html: Added. * fast/images/exif-orientation-image-object.html: Added. * fast/images/exif-orientation-svg-feimage-expected.html: Added. * fast/images/exif-orientation-svg-feimage.html: Added. * fast/images/exif-orientation-svg-image-expected.html: Added. * fast/images/exif-orientation-svg-image.html: Added. * fast/images/exif-orientation.html: Removed. * platform/gtk/TestExpectations: * platform/mac/fast/images/exif-orientation-composited-expected.png: Removed. * platform/win/TestExpectations: Canonical link: https://commits.webkit.org/215033@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249364 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-09-01 00:47:39 +00:00
height: 52px;
}
div.vertical {
width: 52px;
height: 102px;
}
canvas {
border: 1px solid black;
}
canvas.horizontal {
width: 100px;
height: 50px;
}
canvas.vertical {
width: 50px;
height: 100px;
}
</style>
<body>
<b>CanvasRenderingContext2D.drawImage() should rotate the images respecting their EXIF orientation.</b>
<br>
<br>
<div class ="container">
<div class ="horizontal">
<canvas class="horizontal" id="canvas1"></canvas>
</div>
<br>Normal
</div>
<div class ="container">
<div class ="horizontal">
<canvas class="horizontal" id="canvas2"></canvas>
</div>
<br>Flipped horizontally
</div>
<div class ="container">
<div class ="horizontal">
<canvas class="horizontal" id="canvas3"></canvas>
</div>
<br>Rotated 180&deg;
</div>
<div class ="container">
<div class ="horizontal">
<canvas class="horizontal" id="canvas4"></canvas>
</div>
<br>Flipped vertically
</div>
<br>
<div class ="container">
<div class ="vertical">
<canvas class="vertical" id="canvas5"></canvas>
</div>
<br>Rotated 90&deg; CCW and flipped vertically
</div>
<div class ="container">
<div class ="vertical">
<canvas class="vertical" id="canvas6"></canvas>
</div>
<br>Rotated 90&deg; CCW
</div>
<div class ="container">
<div class ="vertical">
<canvas class="vertical" id="canvas7"></canvas>
</div>
<br>Rotated 90&deg; CW and flipped vertically
</div>
<div class ="container">
<div class ="vertical">
<canvas class="vertical" id="canvas8"></canvas>
</div>
<br>Rotated 90&deg; CW
</div>
<br>
<div class ="container">
<div class ="horizontal">
<canvas class="horizontal" id="canvas9"></canvas>
</div>
<br>Undefined (invalid value)
</div>
<script>
if (window.testRunner)
window.testRunner.waitUntilDone();
window.onload = function() {
var names = [
{ resource: "resources/exif-orientation-1-ul.jpg", id : "canvas1" },
{ resource: "resources/exif-orientation-2-ur.jpg", id : "canvas2" },
{ resource: "resources/exif-orientation-3-lr.jpg", id : "canvas3" },
{ resource: "resources/exif-orientation-4-lol.jpg", id : "canvas4" },
{ resource: "resources/exif-orientation-5-lu.jpg", id : "canvas5" },
{ resource: "resources/exif-orientation-6-ru.jpg", id : "canvas6" },
{ resource: "resources/exif-orientation-7-rl.jpg", id : "canvas7" },
{ resource: "resources/exif-orientation-8-llo.jpg", id : "canvas8" },
{ resource: "resources/exif-orientation-9-u.jpg", id : "canvas9" }
];
var drawCount = 0;
names.forEach(function(name) {
var image = new Image;
image.src = name.resource;
image.decode().then(() => {
let canvas = document.getElementById(name.id);
canvas.width = image.width;
canvas.height = image.height;
let context = canvas.getContext("2d");
context.drawImage(image, 0, 0, canvas.width, canvas.height);
if (++drawCount == names.length) {
if (window.testRunner)
window.testRunner.notifyDone();
}
});
});
}
</script>
</body>