Commit 551d6254 authored by mitz@apple.com's avatar mitz@apple.com
Browse files

2008-08-14 Dan Bernstein <mitz@apple.com>

        Reviewed by Brady Eidson.

        - fix <rdar://problem/5993323> REGRESSION (r34210): Apple.com favicon appears stretched/clipped

        * platform/graphics/BitmapImage.cpp: 
        (WebCore::BitmapImage::BitmapImage): Added initialization of
        m_hasUniformFrameSize.
        (WebCore::BitmapImage::cacheFrame): Added code to get the size of the
        cached frame for use in decoded size computation and for setting
        m_hasUniformFrameSize.
        (WebCore::BitmapImage::currentFrameSize): Added.
        (WebCore::BitmapImage::dataChanged): Added code to reset
        m_hasUniformFrameSize.
        * platform/graphics/BitmapImage.h: Added currentFrameSize() and
        m_hasUniformFrameSize.
        * platform/graphics/ImageSource.h: Added frameSizeAtIndex().
        * platform/graphics/cg/ImageCG.cpp:
        (WebCore::BitmapImage::draw): Changed to use currentFrameSize(). This
        fixes the bug, which resulted from assuming that the frame being drawn 
        was the same size as the first frame.
        * platform/graphics/cg/ImageSourceCG.cpp:
        (WebCore::ImageSource::frameSizeAtIndex): Renamed size() to this and
        changed to get the size of the frame at the given index.
        (WebCore::ImageSource::size): Added. Returns frameSizeAtIndex(0).



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@35761 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 50954e56
2008-08-14 Dan Bernstein <mitz@apple.com>
Reviewed by Brady Eidson.
- fix <rdar://problem/5993323> REGRESSION (r34210): Apple.com favicon appears stretched/clipped
* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::BitmapImage): Added initialization of
m_hasUniformFrameSize.
(WebCore::BitmapImage::cacheFrame): Added code to get the size of the
cached frame for use in decoded size computation and for setting
m_hasUniformFrameSize.
(WebCore::BitmapImage::currentFrameSize): Added.
(WebCore::BitmapImage::dataChanged): Added code to reset
m_hasUniformFrameSize.
* platform/graphics/BitmapImage.h: Added currentFrameSize() and
m_hasUniformFrameSize.
* platform/graphics/ImageSource.h: Added frameSizeAtIndex().
* platform/graphics/cg/ImageCG.cpp:
(WebCore::BitmapImage::draw): Changed to use currentFrameSize(). This
fixes the bug, which resulted from assuming that the frame being drawn
was the same size as the first frame.
* platform/graphics/cg/ImageSourceCG.cpp:
(WebCore::ImageSource::frameSizeAtIndex): Renamed size() to this and
changed to get the size of the frame at the given index.
(WebCore::ImageSource::size): Added. Returns frameSizeAtIndex(0).
2008-08-13 Simon Fraser <simon.fraser@apple.com>
Reviewed by Eric Seidel
......
......@@ -54,6 +54,7 @@ BitmapImage::BitmapImage(ImageObserver* observer)
, m_allDataReceived(false)
, m_haveSize(false)
, m_sizeAvailable(false)
, m_hasUniformFrameSize(true)
, m_decodedSize(0)
, m_haveFrameCount(false)
, m_frameCount(0)
......@@ -125,8 +126,16 @@ void BitmapImage::cacheFrame(size_t index)
if (shouldAnimate())
m_frames[index].m_duration = m_source.frameDurationAtIndex(index);
m_frames[index].m_hasAlpha = m_source.frameHasAlphaAtIndex(index);
int sizeChange = m_frames[index].m_frame ? m_size.width() * m_size.height() * 4 : 0;
int sizeChange;
if (index) {
IntSize frameSize = m_source.frameSizeAtIndex(index);
if (frameSize != m_size)
m_hasUniformFrameSize = false;
sizeChange = m_frames[index].m_frame ? frameSize.width() * frameSize.height() * 4 : 0;
} else
sizeChange = m_frames[index].m_frame ? m_size.width() * m_size.height() * 4 : 0;
if (sizeChange) {
m_decodedSize += sizeChange;
if (imageObserver())
......@@ -143,6 +152,13 @@ IntSize BitmapImage::size() const
return m_size;
}
IntSize BitmapImage::currentFrameSize() const
{
if (!m_currentFrame || m_hasUniformFrameSize)
return size();
return m_source.frameSizeAtIndex(m_currentFrame);
}
bool BitmapImage::dataChanged(bool allDataReceived)
{
destroyDecodedData(true);
......@@ -154,6 +170,8 @@ bool BitmapImage::dataChanged(bool allDataReceived)
// Clear the frame count.
m_haveFrameCount = false;
m_hasUniformFrameSize = true;
// Image properties will not be available until the first frame of the file
// reaches kCGImageStatusIncomplete.
return isSizeAvailable();
......
......@@ -104,6 +104,7 @@ public:
virtual bool isBitmapImage() const { return true; }
virtual IntSize size() const;
IntSize currentFrameSize() const;
virtual bool dataChanged(bool allDataReceived);
......@@ -204,6 +205,8 @@ protected:
mutable bool m_haveSize; // Whether or not our |m_size| member variable has the final overall image size yet.
bool m_sizeAvailable; // Whether or not we can obtain the size of the first image frame yet from ImageIO.
mutable bool m_hasUniformFrameSize;
unsigned m_decodedSize; // The current size of all decoded frames.
mutable bool m_haveFrameCount;
......
......@@ -84,7 +84,8 @@ public:
bool isSizeAvailable();
IntSize size() const;
IntSize frameSizeAtIndex(size_t) const;
int repetitionCount();
size_t frameCount() const;
......
......@@ -150,7 +150,7 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& destRect, const F
// If the source rect is a subportion of the image, then we compute an inflated destination rect that will hold the entire image
// and then set a clip to the portion that we want to display.
FloatRect adjustedDestRect = destRect;
FloatSize selfSize = size();
FloatSize selfSize = currentFrameSize();
if (srcRect.size() != selfSize) {
CGInterpolationQuality interpolationQuality = CGContextGetInterpolationQuality(context);
// When the image is scaled using high-quality interpolation, we create a temporary CGImage
......@@ -169,7 +169,7 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& destRect, const F
float yScale = srcRect.height() / destRect.height();
adjustedDestRect.setLocation(FloatPoint(destRect.x() - srcRect.x() / xScale, destRect.y() - srcRect.y() / yScale));
adjustedDestRect.setSize(FloatSize(size().width() / xScale, size().height() / yScale));
adjustedDestRect.setSize(FloatSize(selfSize.width() / xScale, selfSize.height() / yScale));
CGContextClipToRect(context, destRect);
}
......
......@@ -108,10 +108,10 @@ bool ImageSource::isSizeAvailable()
return result;
}
IntSize ImageSource::size() const
IntSize ImageSource::frameSizeAtIndex(size_t index) const
{
IntSize result;
CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions());
CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions());
if (properties) {
int w = 0, h = 0;
CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(properties, kCGImagePropertyPixelWidth);
......@@ -120,12 +120,17 @@ IntSize ImageSource::size() const
num = (CFNumberRef)CFDictionaryGetValue(properties, kCGImagePropertyPixelHeight);
if (num)
CFNumberGetValue(num, kCFNumberIntType, &h);
result = IntSize(w, h);
result = IntSize(w, h);
CFRelease(properties);
}
return result;
}
IntSize ImageSource::size() const
{
return frameSizeAtIndex(0);
}
int ImageSource::repetitionCount()
{
int result = cAnimationLoopOnce; // No property means loop once.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment