Add autodetection of image orientation from EXIF information

https://bugs.webkit.org/show_bug.cgi?id=19688
<rdar://problem/4126979> and <rdar://problem/11091578>

Original patch by David Carson and Eric Seidel.

Reviewed by Simon Fraser.

Add support for respecting EXIF image orientation, enabled by default for ImageDocuments.
The setting shouldRespectImageOrientation causes orientation to take effect for any image included via <img>.

Test: fast/images/exif-orientation.html, fast/images/exif-orientation-css.html

File list truncated because it's very long.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@113486 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b29ed18e
2012-04-06 Tim Horton <timothy_horton@apple.com>
Add autodetection of image orientation from EXIF information
https://bugs.webkit.org/show_bug.cgi?id=19688
<rdar://problem/4126979> and <rdar://problem/11091578>
Original patch by David Carson and Eric Seidel.
Reviewed by Simon Fraser.
Add a test ensuring that images in <img> respect their embedded EXIF orientation when the setting is enabled.
Add a test ensuring that images used via CSS's content property do not respect their embedded EXIF orientation.
* fast/images/exif-orientation.html: Added.
* fast/images/exif-orientation-css.html: Added.
* fast/images/resources/exif-orientation-1-ul.jpg: Added.
* fast/images/resources/exif-orientation-2-ur.jpg: Added.
* fast/images/resources/exif-orientation-3-lr.jpg: Added.
* fast/images/resources/exif-orientation-4-lol.jpg: Added.
* fast/images/resources/exif-orientation-5-lu.jpg: Added.
* fast/images/resources/exif-orientation-6-ru.jpg: Added.
* fast/images/resources/exif-orientation-7-rl.jpg: Added.
* fast/images/resources/exif-orientation-8-llo.jpg: Added.
* fast/images/resources/exif-orientation-9-u.jpg: Added.
* platform/mac/fast/images/exif-orientation-expected.png: Added.
* platform/mac/fast/images/exif-orientation-expected.txt: Added.
* platform/mac/fast/images/exif-orientation-css-expected.png: Added.
* platform/mac/fast/images/exif-orientation-css-expected.txt: Added.
2012-04-06 Joshua Bell <jsbell@chromium.org>
IndexedDB: Race condition in layout test logging from window and worker
<html>
<head>
<script>
if (window.layoutTestController) {
layoutTestController.overridePreference('WebKitShouldRespectImageOrientation', 1);
layoutTestController.dumpAsText(1);
}
function log(str) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(str));
var console = document.getElementById("console");
console.appendChild(li);
}
function imageSize(el) {
var computedStyle = window.getComputedStyle(el);
return computedStyle.width + " by " + computedStyle.height;
}
function load() {
for(var i = 1; i <= 13; i++)
log("img" + i + " size = " + imageSize(document.getElementById("img" + i)))
}
</script>
<style>
div.image { display: inline-block; border: 1px solid black; }
div.container { display: inline-block; margin-right: 20px; margin-bottom: 10px; width: 100px; vertical-align: top; }
img { width: 100px; height: 100px; background-repeat: no-repeat; }
</style>
</head>
<body onload="load()">
<b>None of the images should be rotated. This test is only valid when run with layoutTestController (or with WebKitShouldRespectImageOrientation manually set to true).</b><br><br>
<div class="container"><div class="image" id="img1" style="content: url(resources/exif-orientation-1-ul.jpg)"></div><br>Normal</div>
<div class="container"><div class="image" id="img2" style="content: url(resources/exif-orientation-2-ur.jpg)"></div><br>Flipped horizontally</div>
<div class="container"><div class="image" id="img3" style="content: url(resources/exif-orientation-3-lr.jpg)"></div><br>Rotated 180&deg;</div>
<div class="container"><div class="image" id="img4" style="content: url(resources/exif-orientation-4-lol.jpg)"></div><br>Flipped vertically</div>
<br>
<div class="container"><div class="image" id="img5" style="content: url(resources/exif-orientation-5-lu.jpg)"></div><br>Rotated 90&deg; CCW and flipped vertically</div>
<div class="container"><div class="image" id="img6" style="content: url(resources/exif-orientation-6-ru.jpg)"></div><br>Rotated 90&deg; CCW</div>
<div class="container"><div class="image" id="img7" style="content: url(resources/exif-orientation-7-rl.jpg)"></div><br>Rotated 90&deg; CW and flipped vertically</div>
<div class="container"><div class="image" id="img8" style="content: url(resources/exif-orientation-8-llo.jpg)"></div><br>Rotated 90&deg; CW</div>
<br>
<div class="container"><img id="img9" style="background-image: url(resources/exif-orientation-5-lu.jpg)"></img><br>Rotated 90&deg; CCW and flipped vertically</div>
<div class="container"><img id="img10" style="background-image: url(resources/exif-orientation-6-ru.jpg)"></img><br>Rotated 90&deg; CCW</div>
<div class="container"><img id="img11" style="background-image: url(resources/exif-orientation-7-rl.jpg)"></img><br>Rotated 90&deg; CW and flipped vertically</div>
<div class="container"><img id="img12" style="background-image: url(resources/exif-orientation-8-llo.jpg)"></img><br>Rotated 90&deg; CW</div>
<br>
<div class="container"><div class="image" id="img13" style="content: url(resources/exif-orientation-9-u.jpg)"></div><br>Undefined (invalid value)</div>
<br>
<ul id="console"></ul>
</body>
</html>
<html>
<head>
<script>
if (window.layoutTestController) {
layoutTestController.overridePreference('WebKitShouldRespectImageOrientation', 1);
layoutTestController.dumpAsText(1);
}
function log(str) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(str));
var console = document.getElementById("console");
console.appendChild(li);
}
function imageSize(el) {
var computedStyle = window.getComputedStyle(el);
return computedStyle.width + " by " + computedStyle.height;
}
function load() {
for(var i = 1; i <= 9; i++)
log("img" + i + " size = " + imageSize(document.getElementById("img" + i)))
}
</script>
<style>
img { border: 1px solid black; }
div { display: inline-block; margin-right: 20px; margin-bottom: 10px; width: 100px; vertical-align: top; }
</style>
</head>
<body onload="load()">
<b>The images should be rotated respecting their EXIF orientation. This test can only be run with layoutTestController (or by manually setting WebKitShouldRespectImageOrientation to true).</b><br><br>
<div><img id="img1" src="resources/exif-orientation-1-ul.jpg"><br>Normal</div>
<div><img id="img2" src="resources/exif-orientation-2-ur.jpg"><br>Flipped horizontally</div>
<div><img id="img3" src="resources/exif-orientation-3-lr.jpg"><br>Rotated 180&deg;</div>
<div><img id="img4" src="resources/exif-orientation-4-lol.jpg"><br>Flipped vertically</div>
<br>
<div><img id="img5" src="resources/exif-orientation-5-lu.jpg"><br>Rotated 90&deg; CCW and flipped vertically</div>
<div><img id="img6" src="resources/exif-orientation-6-ru.jpg"><br>Rotated 90&deg; CCW</div>
<div><img id="img7" src="resources/exif-orientation-7-rl.jpg"><br>Rotated 90&deg; CW and flipped vertically </div>
<div><img id="img8" src="resources/exif-orientation-8-llo.jpg"><br>Rotated 90&deg; CW</div>
<br>
<div><img id="img9" src="resources/exif-orientation-9-u.jpg"><br>Undefined (invalid value)</div>
<br>
<ul id="console"></ul>
</body>
</html>
......@@ -3865,3 +3865,7 @@ BUGWK83183 MAC : svg/as-image/animated-svg-as-image-no-fixed-intrinsic-size.html
BUGWK83185 MAC DEBUG : fast/writing-mode/relative-positioning-percentages.html = CRASH
BUGWK83219 LION : fonts/cursive.html = PASS IMAGE+TEXT
BUGWK83324 WIN DEBUG : fast/js/cross-global-object-inline-global-var.html = PASS TEXT
// EXIF orientation support has not yet been implemented for this platform
BUGWK19688 SKIP : fast/images/exif-orientation.html = FAIL
BUGWK19688 SKIP : fast/images/exif-orientation-css.html = FAIL
......@@ -1002,6 +1002,11 @@ editing/pasteboard/drag-files-to-editable-element.html
# http://webkit.org/b/79604
fast/mutation/database-callback-delivery.html
# EXIF orientation support has not yet been implemented for this platform
# http://webkit.org/b/19688
fast/images/exif-orientation.html
fast/images/exif-orientation-css.html
# --------------------------------
# Tests which are expected to fail
# --------------------------------
......
......@@ -422,6 +422,11 @@ batterystatus
#Network Information API support not yet. http://webkit.org/b/73528
networkinformation
# EXIF orientation support has not yet been implemented for this platform
# http://webkit.org/b/19688
fast/images/exif-orientation.html
fast/images/exif-orientation-css.html
###############################################################################
# TESTS FAILING
###############################################################################
......
None of the images should be rotated. This test is only valid when run with layoutTestController (or with WebKitShouldRespectImageOrientation manually set to true).
Normal
Flipped horizontally
Rotated 180°
Flipped vertically
Rotated 90° CCW and flipped vertically
Rotated 90° CCW
Rotated 90° CW and flipped vertically
Rotated 90° CW
Rotated 90° CCW and flipped vertically
Rotated 90° CCW
Rotated 90° CW and flipped vertically
Rotated 90° CW
Undefined (invalid value)
img1 size = 100px by 50px
img2 size = 100px by 50px
img3 size = 100px by 50px
img4 size = 100px by 50px
img5 size = 100px by 50px
img6 size = 100px by 50px
img7 size = 100px by 50px
img8 size = 100px by 50px
img9 size = 100px by 100px
img10 size = 100px by 100px
img11 size = 100px by 100px
img12 size = 100px by 100px
img13 size = 100px by 50px
The images should be rotated respecting their EXIF orientation. This test can only be run with layoutTestController (or by manually setting WebKitShouldRespectImageOrientation to true).
Normal
Flipped horizontally
Rotated 180°
Flipped vertically
Rotated 90° CCW and flipped vertically
Rotated 90° CCW
Rotated 90° CW and flipped vertically
Rotated 90° CW
Undefined (invalid value)
img1 size = 100px by 50px
img2 size = 100px by 50px
img3 size = 100px by 50px
img4 size = 100px by 50px
img5 size = 50px by 100px
img6 size = 50px by 100px
img7 size = 50px by 100px
img8 size = 50px by 100px
img9 size = 100px by 50px
......@@ -396,6 +396,11 @@ batterystatus
# Network Information API is not supported yet. http://webkit.org/b/73528
networkinformation
# EXIF orientation support has not yet been implemented for this platform
# http://webkit.org/b/19688
fast/images/exif-orientation.html
fast/images/exif-orientation-css.html
# =========================================================================== #
# Drag and Drop Support in DRT. #
# =========================================================================== #
......
......@@ -1146,6 +1146,7 @@ SET(WebCore_SOURCES
platform/graphics/GraphicsTypes.cpp
platform/graphics/Image.cpp
platform/graphics/ImageBuffer.cpp
platform/graphics/ImageOrientation.cpp
platform/graphics/IntRect.cpp
platform/graphics/Path.cpp
platform/graphics/PathTraversalState.cpp
......
2012-04-06 Tim Horton <timothy_horton@apple.com>
Add autodetection of image orientation from EXIF information
https://bugs.webkit.org/show_bug.cgi?id=19688
<rdar://problem/4126979> and <rdar://problem/11091578>
Original patch by David Carson and Eric Seidel.
Reviewed by Simon Fraser.
Add support for respecting EXIF image orientation, enabled by default for ImageDocuments.
The setting shouldRespectImageOrientation causes orientation to take effect for any image included via <img>.
Test: fast/images/exif-orientation.html, fast/images/exif-orientation-css.html
* WebCore.xcodeproj/project.pbxproj: Add ImageOrientation.{cpp, h}
* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::imageForRenderer): Plumb setting down from RenderObject into Image.
(WebCore::CachedImage::imageSizeForRenderer):
* page/Settings.h:
(WebCore::Settings::setShouldRespectImageOrientation):
(WebCore::Settings::shouldRespectImageOrientation):
(Settings):
* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::cacheFrame):
(WebCore::BitmapImage::size):
(WebCore::BitmapImage::sizeRespectingOrientation):
(WebCore):
(WebCore::BitmapImage::ensureFrameIsCached):
(WebCore::BitmapImage::frameAtIndex):
(WebCore::BitmapImage::frameIsCompleteAtIndex):
(WebCore::BitmapImage::frameDurationAtIndex):
(WebCore::BitmapImage::frameHasAlphaAtIndex):
(WebCore::BitmapImage::frameOrientationAtIndex):
* platform/graphics/BitmapImage.h:
(WebCore::FrameData::FrameData):
(FrameData):
(BitmapImage):
* platform/graphics/GraphicsContext.h:
(GraphicsContext):
* platform/graphics/ImageOrientation.cpp: Added.
(WebCore):
(WebCore::ImageOrientation::transformFromDefault):
* platform/graphics/ImageOrientation.h: Added.
(WebCore):
(ImageOrientation):
(WebCore::ImageOrientation::ImageOrientation):
(WebCore::ImageOrientation::usesWidthAsHeight):
(WebCore::ImageOrientation::fromEXIFValue):
(WebCore::ImageOrientation::operator==):
(WebCore::ImageOrientation::operator!=):
* platform/graphics/ImageSource.cpp:
(WebCore::ImageSource::orientationAtIndex):
(WebCore):
* platform/graphics/ImageSource.h:
(WebCore):
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::drawNativeImage): Transform the image while drawing if its orientation requires it.
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::draw):
* platform/graphics/cg/ImageCG.cpp:
(WebCore::FrameData::clear):
(WebCore::BitmapImage::BitmapImage):
(WebCore::BitmapImage::draw):
* platform/graphics/cg/ImageSourceCG.cpp:
(WebCore::imageSourceOptions): Don't use SkipMetaData on Lion/Snow Leopard, as it prevents us from retrieving orientation data.
(WebCore::ImageSource::frameSizeAtIndex): Adjust the image's size based on its orientation.
(WebCore):
(WebCore::ImageSource::orientationAtIndex):
(WebCore::ImageSource::size):
* platform/graphics/mac/DragImageMac.mm:
(createDragImageFromImage): Create scaled copy of image for drag image if we're respecting orientation and it is non-default.
* rendering/RenderObject.h:
(RenderObject):
(WebCore::RenderObject::shouldRespectImageOrientation):
2012-04-06 Levi Weintraub <leviw@chromium.org>
Correct LayoutUnit usgae in RenderThemeQt and RenderThemeQStyle
......@@ -3238,6 +3238,8 @@ webcore_sources += \
Source/WebCore/platform/graphics/Image.cpp \
Source/WebCore/platform/graphics/Image.h \
Source/WebCore/platform/graphics/ImageObserver.h \
Source/WebCore/platform/graphics/ImageOrientation.cpp \
Source/WebCore/platform/graphics/ImageOrientation.h \
Source/WebCore/platform/graphics/ImageSource.cpp \
Source/WebCore/platform/graphics/ImageSource.h \
Source/WebCore/platform/graphics/IntPoint.h \
......
......@@ -1093,6 +1093,7 @@ SOURCES += \
platform/graphics/GraphicsTypes.cpp \
platform/graphics/Image.cpp \
platform/graphics/ImageBuffer.cpp \
platform/graphics/ImageOrientation.cpp \
platform/graphics/ImageSource.cpp \
platform/graphics/IntRect.cpp \
platform/graphics/Path.cpp \
......@@ -2224,6 +2225,7 @@ HEADERS += \
platform/graphics/GraphicsTypes.h \
platform/graphics/GraphicsTypes3D.h \
platform/graphics/Image.h \
platform/graphics/ImageOrientation.h \
platform/graphics/ImageSource.h \
platform/graphics/IntPoint.h \
platform/graphics/IntPointHash.h \
......
......@@ -446,7 +446,7 @@ __ZN7WebCore15GraphicsContext8fillPathERKNS_4PathE
__ZN7WebCore15GraphicsContext8fillRectERKNS_9FloatRectE
__ZN7WebCore15GraphicsContext8fillRectERKNS_9FloatRectERKNS_5ColorENS_10ColorSpaceE
__ZN7WebCore15GraphicsContext9clearRectERKNS_9FloatRectE
__ZN7WebCore15GraphicsContext9drawImageEPNS_5ImageENS_10ColorSpaceERKNS_8IntPointENS_17CompositeOperatorE
__ZN7WebCore15GraphicsContext9drawImageEPNS_5ImageENS_10ColorSpaceERKNS_8IntPointENS_17CompositeOperatorENS_27RespectImageOrientationEnumE
__ZN7WebCore15GraphicsContext9setShadowERKNS_9FloatSizeEfRKNS_5ColorENS_10ColorSpaceE
__ZN7WebCore15GraphicsContext9translateEff
__ZN7WebCore15GraphicsContextC1EP9CGContext
......
......@@ -373,6 +373,7 @@
'platform/graphics/ImageBuffer.h',
'platform/graphics/ImageBufferData.h',
'platform/graphics/ImageObserver.h',
'platform/graphics/ImageOrientation.h',
'platform/graphics/ImageSource.h',
'platform/graphics/IntPoint.h',
'platform/graphics/IntPointHash.h',
......@@ -3372,6 +3373,7 @@
'platform/graphics/GraphicsTypes.cpp',
'platform/graphics/Image.cpp',
'platform/graphics/ImageBuffer.cpp',
'platform/graphics/ImageOrientation.cpp',
'platform/graphics/ImageSource.cpp',
'platform/graphics/IntRect.cpp',
'platform/graphics/MediaPlayer.cpp',
......
......@@ -28656,6 +28656,14 @@
RelativePath="..\platform\graphics\ImageObserver.h"
>
</File>
<File
RelativePath="..\platform\graphics\ImageOrientation.cpp"
>
</File>
<File
RelativePath="..\platform\graphics\ImageOrientation.h"
>
</File>
<File
RelativePath="..\platform\graphics\ImageSource.cpp"
>
......@@ -757,6 +757,8 @@
2D481F02146B5C5500AA7834 /* CrossfadeGeneratedImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D2FC0551460CD6F00263633 /* CrossfadeGeneratedImage.h */; };
2D481F03146B5C6500AA7834 /* GeneratorGeneratedImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D2FC0561460CD6F00263633 /* GeneratorGeneratedImage.cpp */; };
2D481F04146B5C6B00AA7834 /* GeneratorGeneratedImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D2FC0571460CD6F00263633 /* GeneratorGeneratedImage.h */; };
2D5A592F152525230036EE51 /* ImageOrientation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8748D7412CC3F89001FBA41 /* ImageOrientation.cpp */; };
2D5A5931152525D00036EE51 /* ImageOrientation.h in Headers */ = {isa = PBXBuildFile; fileRef = A8748D6612CC3763001FBA41 /* ImageOrientation.h */; settings = {ATTRIBUTES = (Private, ); }; };
2D8FEBDC143E3EF70072502B /* CSSCrossfadeValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D8FEBDA143E3EF70072502B /* CSSCrossfadeValue.cpp */; };
2D8FEBDD143E3EF70072502B /* CSSCrossfadeValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D8FEBDB143E3EF70072502B /* CSSCrossfadeValue.h */; };
2D9066060BE141D400956998 /* LayoutState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D9066040BE141D400956998 /* LayoutState.cpp */; };
......@@ -11024,6 +11026,8 @@
A871DFE00A15376B00B12A68 /* RenderWidget.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RenderWidget.h; sourceTree = "<group>"; };
A871DFE10A15376B00B12A68 /* RenderWidget.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RenderWidget.cpp; sourceTree = "<group>"; };
A8748BDF12CBF2DC001FBA41 /* HashTools.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HashTools.h; sourceTree = "<group>"; };
A8748D6612CC3763001FBA41 /* ImageOrientation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageOrientation.h; sourceTree = "<group>"; };
A8748D7412CC3F89001FBA41 /* ImageOrientation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageOrientation.cpp; sourceTree = "<group>"; };
A883DF250F3D045D00F19BF6 /* VisibleSelection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VisibleSelection.cpp; sourceTree = "<group>"; };
A883DF260F3D045D00F19BF6 /* VisibleSelection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VisibleSelection.h; sourceTree = "<group>"; };
A886CDC214FBBAA300D279F4 /* WorkerContextWebSocket.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = WorkerContextWebSocket.idl; path = Modules/websockets/WorkerContextWebSocket.idl; sourceTree = "<group>"; };
......@@ -19362,6 +19366,8 @@
501BAAA813950E2C00F7ACEB /* WindRule.h */,
379919941200DDF400EA041C /* WOFFFileFormat.cpp */,
379919951200DDF400EA041C /* WOFFFileFormat.h */,
A8748D6612CC3763001FBA41 /* ImageOrientation.h */,
A8748D7412CC3F89001FBA41 /* ImageOrientation.cpp */,
);
path = graphics;
sourceTree = "<group>";
......@@ -21581,6 +21587,7 @@
49E912AD0EFAC906009D0CAF /* AnimationList.h in Headers */,
0F580FAF149800D400FB5BD8 /* AnimationUtilities.h in Headers */,
93309DD7099E64920056E581 /* AppendNodeCommand.h in Headers */,
2D5A5931152525D00036EE51 /* ImageOrientation.h in Headers */,
1A8F6BBD0DB55CDC001DB794 /* ApplicationCache.h in Headers */,
1A8F6BBF0DB55CDC001DB794 /* ApplicationCacheGroup.h in Headers */,
24F54EAD101FE914000AE741 /* ApplicationCacheHost.h in Headers */,
......@@ -25083,6 +25090,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2D5A592F152525230036EE51 /* ImageOrientation.cpp in Sources */,
97BC69DA1505F076001B74AC /* AbstractDatabase.cpp in Sources */,
41E1B1D00FF5986900576B3B /* AbstractWorker.cpp in Sources */,
0F29C16E1300C2E2002D794E /* AccessibilityAllInOne.cpp in Sources */,
......@@ -331,7 +331,7 @@ void HTMLCanvasElement::paint(GraphicsContext* context, const LayoutRect& r, boo
ImageBuffer* imageBuffer = buffer();
if (imageBuffer) {
if (m_presentedImage)
context->drawImage(m_presentedImage.get(), ColorSpaceDeviceRGB, pixelSnappedIntRect(r), CompositeSourceOver, useLowQualityScale);
context->drawImage(m_presentedImage.get(), ColorSpaceDeviceRGB, pixelSnappedIntRect(r), CompositeSourceOver, DoNotRespectImageOrientation, useLowQualityScale);
else
context->drawImageBuffer(imageBuffer, ColorSpaceDeviceRGB, pixelSnappedIntRect(r), CompositeSourceOver, useLowQualityScale);
}
......
......@@ -241,7 +241,12 @@ IntSize CachedImage::imageSizeForRenderer(const RenderObject* renderer, float mu
if (!m_image)
return IntSize();
IntSize imageSize = m_image->size();
IntSize imageSize;
if (m_image->isBitmapImage() && (renderer && renderer->shouldRespectImageOrientation() == RespectImageOrientation))
imageSize = static_cast<BitmapImage*>(m_image.get())->sizeRespectingOrientation();
else
imageSize = m_image->size();
#if ENABLE(SVG)
if (m_image->isSVGImage()) {
......@@ -251,8 +256,6 @@ IntSize CachedImage::imageSizeForRenderer(const RenderObject* renderer, float mu
imageSize.setHeight(sizeAndZoom.size.height() / sizeAndZoom.zoom);
}
}
#else
UNUSED_PARAM(renderer);
#endif
if (multiplier == 1.0f)
......
......@@ -51,6 +51,7 @@
#include "HitTestRequest.h"
#include "HitTestResult.h"
#include "Image.h"
#include "ImageOrientation.h"
#include "MoveSelectionCommand.h"
#include "Node.h"
#include "Page.h"
......@@ -851,7 +852,7 @@ void DragController::doImageDrag(Element* element, const IntPoint& dragOrigin, c
Image* image = getImage(element);
if (image && image->size().height() * image->size().width() <= MaxOriginalImageArea
&& (dragImage = createDragImageFromImage(image))) {
&& (dragImage = createDragImageFromImage(image, element->renderer() ? element->renderer()->shouldRespectImageOrientation() : DoNotRespectImageOrientation))) {
IntSize originalSize = rect.size();
origin = rect.location();
......
......@@ -1087,7 +1087,7 @@ DragImageRef Frame::nodeImage(Node* node)
m_view->paintContents(buffer->context(), paintingRect);
RefPtr<Image> image = buffer->copyImage();
return createDragImageFromImage(image.get());
return createDragImageFromImage(image.get(), renderer->shouldRespectImageOrientation());
}
DragImageRef Frame::dragImageForSelection()
......
......@@ -549,6 +549,9 @@ namespace WebCore {
void setThreadedAnimationEnabled(bool enabled) { m_threadedAnimationEnabled = enabled; }
bool threadedAnimationEnabled() const { return m_threadedAnimationEnabled; }
void setShouldRespectImageOrientation(bool enabled) { m_shouldRespectImageOrientation = enabled; }
bool shouldRespectImageOrientation() const { return m_shouldRespectImageOrientation; }
private:
Settings(Page*);
......@@ -703,6 +706,7 @@ namespace WebCore {
bool m_touchEventEmulationEnabled : 1;
#endif
bool m_threadedAnimationEnabled : 1;
bool m_shouldRespectImageOrientation : 1;
Timer<Settings> m_loadsImagesAutomaticallyTimer;
void loadsImagesAutomaticallyTimerFired(Timer<Settings>*);
......
......@@ -26,6 +26,7 @@
#ifndef DragImage_h
#define DragImage_h
#include "ImageOrientation.h"
#include "IntSize.h"
#include "FloatSize.h"
#include <wtf/Forward.h>
......@@ -81,7 +82,7 @@ namespace WebCore {
DragImageRef scaleDragImage(DragImageRef, FloatSize scale);
DragImageRef dissolveDragImageToFraction(DragImageRef image, float delta);
DragImageRef createDragImageFromImage(Image*);
DragImageRef createDragImageFromImage(Image*, RespectImageOrientationEnum = DoNotRespectImageOrientation);
DragImageRef createDragImageForSelection(Frame*);
DragImageRef createDragImageIconForCachedImage(CachedImage*);
DragImageRef createDragImageForLink(KURL&, const String& label, Frame*);
......
......@@ -26,7 +26,7 @@
namespace WebCore {
void* createDragImageFromImage(Image*)
void* createDragImageFromImage(Image*, RespectImageOrientationEnum)
{
notImplemented();
return 0;
......
......@@ -98,7 +98,7 @@ DragImageRef dissolveDragImageToFraction(DragImageRef image, float delta)
return dissolvedImage;
}
DragImageRef createDragImageFromImage(Image* image)
DragImageRef createDragImageFromImage(Image* image, RespectImageOrientationEnum)
{
if (!image)
return 0;
......
......@@ -92,7 +92,7 @@ DragImageRef dissolveDragImageToFraction(DragImageRef image, float fraction)
return image;
}
DragImageRef createDragImageFromImage(Image* image)
DragImageRef createDragImageFromImage(Image* image, RespectImageOrientationEnum)
{
if (!image)
return 0;
......
......@@ -50,7 +50,7 @@ DragImageRef dissolveDragImageToFraction(DragImageRef image, float)
return image;
}
DragImageRef createDragImageFromImage(Image*)
DragImageRef createDragImageFromImage(Image*, RespectImageOrientationEnum)
{
notImplemented();
return 0;
......
......@@ -139,6 +139,7 @@ void BitmapImage::cacheFrame(size_t index)
if (numFrames == 1 && m_frames[index].m_frame)
checkForSolidColor();
m_frames[index].m_orientation = m_source.orientationAtIndex(index);
m_frames[index].m_haveMetadata = true;
m_frames[index].m_isComplete = m_source.frameIsCompleteAtIndex(index);
if (repetitionCount(false) != cAnimationNone)
......@@ -182,12 +183,24 @@ IntSize BitmapImage::size() const
{
if (m_sizeAvailable && !m_haveSize) {
m_size = m_source.size();
m_sizeRespectingOrientation = m_source.size(RespectImageOrientation);
m_haveSize = true;
didDecodeProperties();
}
return m_size;
}
IntSize BitmapImage::sizeRespectingOrientation() const
{
if (m_sizeAvailable && !m_haveSize) {
m_size = m_source.size();
m_sizeRespectingOrientation = m_source.size(RespectImageOrientation);
m_haveSize = true;
didDecodeProperties();
}
return m_sizeRespectingOrientation;
}
IntSize BitmapImage::currentFrameSize() const
{
if (!m_currentFrame || m_hasUniformFrameSize)
......@@ -268,36 +281,34 @@ bool BitmapImage::isSizeAvailable()
return m_sizeAvailable;
}
NativeImagePtr BitmapImage::frameAtIndex(size_t index)
bool BitmapImage::ensureFrameIsCached(size_t index)
{
if (index >= frameCount())
return 0;
return false;
if (index >= m_frames.size() || !m_frames[index].m_frame)
cacheFrame(index);
return true;
}
NativeImagePtr BitmapImage::frameAtIndex(size_t index)
{
if (!ensureFrameIsCached(index))
return 0;