summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/image-decoders
diff options
context:
space:
mode:
authorFeng Qian <fqian@google.com>2009-06-17 12:12:20 -0700
committerFeng Qian <fqian@google.com>2009-06-17 12:12:20 -0700
commit5f1ab04193ad0130ca8204aadaceae083aca9881 (patch)
tree5a92cd389e2cfe7fb67197ce14b38469462379f8 /WebCore/platform/image-decoders
parent194315e5a908cc8ed67d597010544803eef1ac59 (diff)
downloadexternal_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.zip
external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.gz
external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.bz2
Get WebKit r44544.
Diffstat (limited to 'WebCore/platform/image-decoders')
-rw-r--r--WebCore/platform/image-decoders/ImageDecoder.h269
-rw-r--r--WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp6
-rw-r--r--WebCore/platform/image-decoders/bmp/BMPImageDecoder.h25
-rw-r--r--WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp92
-rw-r--r--WebCore/platform/image-decoders/gif/GIFImageDecoder.h87
-rw-r--r--WebCore/platform/image-decoders/gif/GIFImageReader.cpp4
-rw-r--r--WebCore/platform/image-decoders/gif/GIFImageReader.h7
-rw-r--r--WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp6
-rw-r--r--WebCore/platform/image-decoders/ico/ICOImageDecoder.h25
-rw-r--r--WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp27
-rw-r--r--WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h59
-rw-r--r--WebCore/platform/image-decoders/png/PNGImageDecoder.cpp38
-rw-r--r--WebCore/platform/image-decoders/png/PNGImageDecoder.h51
-rw-r--r--WebCore/platform/image-decoders/skia/GIFImageDecoder.cpp4
-rw-r--r--WebCore/platform/image-decoders/skia/GIFImageReader.h10
-rw-r--r--WebCore/platform/image-decoders/skia/ImageDecoder.h93
-rw-r--r--WebCore/platform/image-decoders/skia/JPEGImageDecoder.cpp4
-rw-r--r--WebCore/platform/image-decoders/skia/PNGImageDecoder.cpp17
-rw-r--r--WebCore/platform/image-decoders/skia/XBMImageDecoder.h1
-rw-r--r--WebCore/platform/image-decoders/xbm/XBMImageDecoder.cpp6
-rw-r--r--WebCore/platform/image-decoders/xbm/XBMImageDecoder.h25
21 files changed, 396 insertions, 460 deletions
diff --git a/WebCore/platform/image-decoders/ImageDecoder.h b/WebCore/platform/image-decoders/ImageDecoder.h
index 17756ac..ca27b37 100644
--- a/WebCore/platform/image-decoders/ImageDecoder.h
+++ b/WebCore/platform/image-decoders/ImageDecoder.h
@@ -23,8 +23,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef IMAGE_DECODER_H_
-#define IMAGE_DECODER_H_
+#ifndef ImageDecoder_h
+#define ImageDecoder_h
#include "IntRect.h"
#include "ImageSource.h"
@@ -34,136 +34,145 @@
namespace WebCore {
-typedef Vector<unsigned> RGBA32Array;
-
-// The RGBA32Buffer object represents the decoded image data in RGBA32 format. This buffer is what all
-// decoders write a single frame into. Frames are then instantiated for drawing by being handed this buffer.
-class RGBA32Buffer
-{
-public:
- enum FrameStatus { FrameEmpty, FramePartial, FrameComplete };
- enum FrameDisposalMethod {
- // If you change the numeric values of these, make sure you audit all
- // users, as some users may cast raw values to/from these constants.
- DisposeNotSpecified = 0, // Leave frame in framebuffer
- DisposeKeep = 1, // Leave frame in framebuffer
- DisposeOverwriteBgcolor = 2, // Clear frame to transparent
- DisposeOverwritePrevious = 3, // Clear frame to previous framebuffer contents
- };
+ typedef Vector<unsigned> RGBA32Array;
+
+ // The RGBA32Buffer object represents the decoded image data in RGBA32 format. This buffer is what all
+ // decoders write a single frame into. Frames are then instantiated for drawing by being handed this buffer.
+ class RGBA32Buffer {
+ public:
+ enum FrameStatus { FrameEmpty, FramePartial, FrameComplete };
+
+ enum FrameDisposalMethod {
+ // If you change the numeric values of these, make sure you audit all
+ // users, as some users may cast raw values to/from these constants.
+ DisposeNotSpecified, // Leave frame in framebuffer
+ DisposeKeep, // Leave frame in framebuffer
+ DisposeOverwriteBgcolor, // Clear frame to transparent
+ DisposeOverwritePrevious, // Clear frame to previous framebuffer contents
+ };
+
+ RGBA32Buffer()
+ : m_height(0)
+ , m_status(FrameEmpty)
+ , m_duration(0)
+ , m_disposalMethod(DisposeNotSpecified)
+ , m_hasAlpha(false)
+ {
+ }
+
+ void clear() {
+ m_bytes.clear();
+ m_status = FrameEmpty;
+ // NOTE: Do not reset other members here; clearFrameBufferCache() calls
+ // this to free the bitmap data, but other functions like
+ // initFrameBuffer() and frameComplete() may still need to read other
+ // metadata out of this frame later.
+ }
- RGBA32Buffer() : m_height(0), m_status(FrameEmpty), m_duration(0),
- m_disposalMethod(DisposeNotSpecified), m_hasAlpha(false)
- {}
-
- void clear() {
- m_bytes.clear();
- m_status = FrameEmpty;
- // NOTE: Do not reset other members here; clearFrameBufferCache() calls
- // this to free the bitmap data, but other functions like
- // initFrameBuffer() and frameComplete() may still need to read other
- // metadata out of this frame later.
- }
-
- const RGBA32Array& bytes() const { return m_bytes; }
- RGBA32Array& bytes() { return m_bytes; }
- const IntRect& rect() const { return m_rect; }
- unsigned height() const { return m_height; }
- FrameStatus status() const { return m_status; }
- unsigned duration() const { return m_duration; }
- FrameDisposalMethod disposalMethod() const { return m_disposalMethod; }
- bool hasAlpha() const { return m_hasAlpha; }
-
- void setRect(const IntRect& r) { m_rect = r; }
- void ensureHeight(unsigned rowIndex) { if (rowIndex > m_height) m_height = rowIndex; }
- void setStatus(FrameStatus s) { m_status = s; }
- void setDuration(unsigned duration) { m_duration = duration; }
- void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; }
- void setHasAlpha(bool alpha) { m_hasAlpha = alpha; }
-
- static void setRGBA(unsigned& pos, unsigned r, unsigned g, unsigned b, unsigned a)
- {
- // We store this data pre-multiplied.
- if (a == 0)
- pos = 0;
- else {
- if (a < 255) {
- float alphaPercent = a / 255.0f;
- r = static_cast<unsigned>(r * alphaPercent);
- g = static_cast<unsigned>(g * alphaPercent);
- b = static_cast<unsigned>(b * alphaPercent);
+ const RGBA32Array& bytes() const { return m_bytes; }
+ RGBA32Array& bytes() { return m_bytes; }
+ const IntRect& rect() const { return m_rect; }
+ unsigned height() const { return m_height; }
+ FrameStatus status() const { return m_status; }
+ unsigned duration() const { return m_duration; }
+ FrameDisposalMethod disposalMethod() const { return m_disposalMethod; }
+ bool hasAlpha() const { return m_hasAlpha; }
+
+ void setRect(const IntRect& r) { m_rect = r; }
+ void ensureHeight(unsigned rowIndex) { if (rowIndex > m_height) m_height = rowIndex; }
+ void setStatus(FrameStatus s) { m_status = s; }
+ void setDuration(unsigned duration) { m_duration = duration; }
+ void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; }
+ void setHasAlpha(bool alpha) { m_hasAlpha = alpha; }
+
+ static void setRGBA(unsigned& pos, unsigned r, unsigned g, unsigned b, unsigned a)
+ {
+ // We store this data pre-multiplied.
+ if (a == 0)
+ pos = 0;
+ else {
+ if (a < 255) {
+ float alphaPercent = a / 255.0f;
+ r = static_cast<unsigned>(r * alphaPercent);
+ g = static_cast<unsigned>(g * alphaPercent);
+ b = static_cast<unsigned>(b * alphaPercent);
+ }
+ pos = (a << 24 | r << 16 | g << 8 | b);
}
- pos = (a << 24 | r << 16 | g << 8 | b);
}
- }
-
-private:
- RGBA32Array m_bytes;
- IntRect m_rect; // The rect of the original specified frame within the overall buffer.
- // This will always just be the entire buffer except for GIF frames
- // whose original rect was smaller than the overall image size.
- unsigned m_height; // The height (the number of rows we've fully decoded).
- FrameStatus m_status; // Whether or not this frame is completely finished decoding.
- unsigned m_duration; // The animation delay.
- FrameDisposalMethod m_disposalMethod; // What to do with this frame's data when initializing the next frame.
- bool m_hasAlpha; // Whether or not any of the pixels in the buffer have transparency.
-};
-
-// The ImageDecoder class represents a base class for specific image format decoders
-// (e.g., GIF, JPG, PNG, ICO) to derive from. All decoders decode into RGBA32 format
-// and the base class manages the RGBA32 frame cache.
-class ImageDecoder
-{
-public:
- ImageDecoder() :m_sizeAvailable(false), m_failed(false) {}
- virtual ~ImageDecoder() {}
-
- // The the filename extension usually associated with an undecoded image of this type.
- virtual String filenameExtension() const = 0;
-
- // All specific decoder plugins must do something with the data they are given.
- virtual void setData(SharedBuffer* data, bool allDataReceived) { m_data = data; }
-
- // Whether or not the size information has been decoded yet.
- virtual bool isSizeAvailable() const = 0;
-
- // Requests the size.
- virtual IntSize size() const { return m_size; }
-
- // The total number of frames for the image. Classes that support multiple frames
- // will scan the image data for the answer if they need to (without necessarily
- // decoding all of the individual frames).
- virtual int frameCount() { return 1; }
-
- // The number of repetitions to perform for an animation loop.
- virtual int repetitionCount() const { return cAnimationNone; }
-
- // Called to obtain the RGBA32Buffer full of decoded data for rendering. The
- // decoder plugin will decode as much of the frame as it can before handing
- // back the buffer.
- virtual RGBA32Buffer* frameBufferAtIndex(size_t index) = 0;
-
- // Whether or not the underlying image format even supports alpha transparency.
- virtual bool supportsAlpha() const { return true; }
-
- bool failed() const { return m_failed; }
- void setFailed() { m_failed = true; }
-
- // Wipe out frames in the frame buffer cache before |clearBeforeFrame|,
- // assuming this can be done without breaking decoding. Different decoders
- // place different restrictions on what frames are safe to destroy, so this
- // is left to them to implement.
- // For convenience's sake, we provide a default (empty) implementation,
- // since in practice only GIFs will ever use this.
- virtual void clearFrameBufferCache(size_t clearBeforeFrame) { }
-
-protected:
- RefPtr<SharedBuffer> m_data; // The encoded data.
- Vector<RGBA32Buffer> m_frameBufferCache;
- bool m_sizeAvailable;
- mutable bool m_failed;
- IntSize m_size;
-};
-
-}
+
+ private:
+ RGBA32Array m_bytes;
+ IntRect m_rect; // The rect of the original specified frame within the overall buffer.
+ // This will always just be the entire buffer except for GIF frames
+ // whose original rect was smaller than the overall image size.
+ unsigned m_height; // The height (the number of rows we've fully decoded).
+ FrameStatus m_status; // Whether or not this frame is completely finished decoding.
+ unsigned m_duration; // The animation delay.
+ FrameDisposalMethod m_disposalMethod; // What to do with this frame's data when initializing the next frame.
+ bool m_hasAlpha; // Whether or not any of the pixels in the buffer have transparency.
+ };
+
+ // The ImageDecoder class represents a base class for specific image format decoders
+ // (e.g., GIF, JPG, PNG, ICO) to derive from. All decoders decode into RGBA32 format
+ // and the base class manages the RGBA32 frame cache.
+ class ImageDecoder {
+ public:
+ ImageDecoder()
+ : m_sizeAvailable(false)
+ , m_failed(false)
+ {
+ }
+
+ virtual ~ImageDecoder() {}
+
+ // The the filename extension usually associated with an undecoded image of this type.
+ virtual String filenameExtension() const = 0;
+
+ // All specific decoder plugins must do something with the data they are given.
+ virtual void setData(SharedBuffer* data, bool allDataReceived) { m_data = data; }
+
+ // Whether or not the size information has been decoded yet.
+ virtual bool isSizeAvailable() const = 0;
+
+ // Requests the size.
+ virtual IntSize size() const { return m_size; }
+
+ // The total number of frames for the image. Classes that support multiple frames
+ // will scan the image data for the answer if they need to (without necessarily
+ // decoding all of the individual frames).
+ virtual int frameCount() { return 1; }
+
+ // The number of repetitions to perform for an animation loop.
+ virtual int repetitionCount() const { return cAnimationNone; }
+
+ // Called to obtain the RGBA32Buffer full of decoded data for rendering. The
+ // decoder plugin will decode as much of the frame as it can before handing
+ // back the buffer.
+ virtual RGBA32Buffer* frameBufferAtIndex(size_t index) = 0;
+
+ // Whether or not the underlying image format even supports alpha transparency.
+ virtual bool supportsAlpha() const { return true; }
+
+ bool failed() const { return m_failed; }
+ void setFailed() { m_failed = true; }
+
+ // Wipe out frames in the frame buffer cache before |clearBeforeFrame|,
+ // assuming this can be done without breaking decoding. Different decoders
+ // place different restrictions on what frames are safe to destroy, so this
+ // is left to them to implement.
+ // For convenience's sake, we provide a default (empty) implementation,
+ // since in practice only GIFs will ever use this.
+ virtual void clearFrameBufferCache(size_t clearBeforeFrame) { }
+
+ protected:
+ RefPtr<SharedBuffer> m_data; // The encoded data.
+ Vector<RGBA32Buffer> m_frameBufferCache;
+ bool m_sizeAvailable;
+ mutable bool m_failed;
+ IntSize m_size;
+ };
+
+} // namespace WebCore
#endif
diff --git a/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp b/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp
index cfc141c..3b90bdc 100644
--- a/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp
@@ -26,8 +26,6 @@
#include "config.h"
#include "BMPImageDecoder.h"
-#if PLATFORM(CAIRO) || PLATFORM(QT) || PLATFORM(WX)
-
namespace WebCore
{
@@ -41,6 +39,4 @@ RGBA32Buffer* BMPImageDecoder::frameBufferAtIndex(size_t index)
return 0;
}
-}
-
-#endif // PLATFORM(CAIRO)
+} // namespace WebCore
diff --git a/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h b/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h
index d850cc7..a2d4b25 100644
--- a/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h
+++ b/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h
@@ -23,27 +23,26 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef BMP_DECODER_H_
-#define BMP_DECODER_H_
+#ifndef BMPImageDecoder_h
+#define BMPImageDecoder_h
#include "ImageDecoder.h"
namespace WebCore {
-class BMPImageReader;
+ class BMPImageReader;
-// This class decodes the BMP image format.
-class BMPImageDecoder : public ImageDecoder
-{
-public:
- virtual String filenameExtension() const { return "bmp"; }
+ // This class decodes the BMP image format.
+ class BMPImageDecoder : public ImageDecoder {
+ public:
+ virtual String filenameExtension() const { return "bmp"; }
- // Whether or not the size information has been decoded yet.
- virtual bool isSizeAvailable() const;
+ // Whether or not the size information has been decoded yet.
+ virtual bool isSizeAvailable() const;
- virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
-};
+ virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
+ };
-}
+} // namespace WebCore
#endif
diff --git a/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp b/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp
index 5b4b675..62d8b5b 100644
--- a/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp
@@ -27,17 +27,14 @@
#include "GIFImageDecoder.h"
#include "GIFImageReader.h"
-#if PLATFORM(CAIRO) || PLATFORM(QT) || PLATFORM(WX)
-
namespace WebCore {
-class GIFImageDecoderPrivate
-{
+class GIFImageDecoderPrivate {
public:
GIFImageDecoderPrivate(GIFImageDecoder* decoder = 0)
: m_reader(decoder)
+ , m_readOffset(0)
{
- m_readOffset = 0;
}
~GIFImageDecoderPrivate()
@@ -45,11 +42,11 @@ public:
m_reader.close();
}
- bool decode(const Vector<char>& data,
+ bool decode(SharedBuffer* data,
GIFImageDecoder::GIFQuery query = GIFImageDecoder::GIFFullQuery,
unsigned int haltFrame = -1)
{
- return m_reader.read((const unsigned char*)data.data() + m_readOffset, data.size() - m_readOffset,
+ return m_reader.read((const unsigned char*)data->data() + m_readOffset, data->size() - m_readOffset,
query,
haltFrame);
}
@@ -61,7 +58,8 @@ public:
bool isTransparent() const { return m_reader.frame_reader->is_transparent; }
- void getColorMap(unsigned char*& map, unsigned& size) const {
+ void getColorMap(unsigned char*& map, unsigned& size) const
+ {
if (m_reader.frame_reader->is_local_colormap_defined) {
map = m_reader.frame_reader->local_colormap;
size = (unsigned)m_reader.frame_reader->local_colormap_size;
@@ -86,8 +84,11 @@ private:
};
GIFImageDecoder::GIFImageDecoder()
-: m_frameCountValid(true), m_repetitionCount(cAnimationLoopOnce), m_reader(0)
-{}
+ : m_frameCountValid(true)
+ , m_repetitionCount(cAnimationLoopOnce)
+ , m_reader(0)
+{
+}
GIFImageDecoder::~GIFImageDecoder()
{
@@ -139,7 +140,10 @@ int GIFImageDecoder::frameCount()
// state, but for now we just crawl all the data. Note that this is no worse than what
// ImageIO does on Mac right now (it also crawls all the data again).
GIFImageDecoderPrivate reader;
- reader.decode(m_data->buffer(), GIFFrameCountQuery);
+ // This function may fail, but we want to keep any partial data it may
+ // have decoded, so don't mark it is invalid. If there is an overflow
+ // or some serious error, m_failed will have gotten set for us.
+ reader.decode(m_data.get(), GIFFrameCountQuery);
m_frameCountValid = true;
m_frameBufferCache.resize(reader.frameCount());
}
@@ -173,13 +177,12 @@ int GIFImageDecoder::repetitionCount() const
RGBA32Buffer* GIFImageDecoder::frameBufferAtIndex(size_t index)
{
- if (index >= frameCount())
+ if (index >= static_cast<size_t>(frameCount()))
return 0;
RGBA32Buffer& frame = m_frameBufferCache[index];
if (frame.status() != RGBA32Buffer::FrameComplete && m_reader)
- // Decode this frame.
- decode(GIFFullQuery, index+1);
+ decode(GIFFullQuery, index + 1); // Decode this frame.
return &frame;
}
@@ -239,7 +242,7 @@ void GIFImageDecoder::decode(GIFQuery query, unsigned haltAtFrame) const
if (m_failed)
return;
- m_failed = !m_reader->decode(m_data->buffer(), query, haltAtFrame);
+ m_failed = !m_reader->decode(m_data.get(), query, haltAtFrame);
if (m_failed) {
delete m_reader;
@@ -266,10 +269,10 @@ void GIFImageDecoder::initFrameBuffer(unsigned frameIndex)
m_reader->frameWidth(), m_reader->frameHeight());
// Make sure the frameRect doesn't extend past the bottom-right of the buffer.
- if (frameRect.right() > m_size.width())
- frameRect.setWidth(m_size.width() - m_reader->frameXOffset());
- if (frameRect.bottom() > m_size.height())
- frameRect.setHeight(m_size.height() - m_reader->frameYOffset());
+ if (frameRect.right() > size().width())
+ frameRect.setWidth(size().width() - m_reader->frameXOffset());
+ if (frameRect.bottom() > size().height())
+ frameRect.setHeight(size().height() - m_reader->frameYOffset());
RGBA32Buffer* const buffer = &m_frameBufferCache[frameIndex];
buffer->setRect(frameRect);
@@ -287,14 +290,14 @@ void GIFImageDecoder::initFrameBuffer(unsigned frameIndex)
// first frame specifies this method, it will get treated like
// DisposeOverwriteBgcolor below and reset to a completely empty image.)
const RGBA32Buffer* prevBuffer = &m_frameBufferCache[--frameIndex];
- ASSERT(prevBuffer->status() == RGBA32Buffer::FrameComplete);
RGBA32Buffer::FrameDisposalMethod prevMethod =
prevBuffer->disposalMethod();
- while ((frameIndex > 0) &&
- (prevMethod == RGBA32Buffer::DisposeOverwritePrevious)) {
+ while ((frameIndex > 0)
+ && (prevMethod == RGBA32Buffer::DisposeOverwritePrevious)) {
prevBuffer = &m_frameBufferCache[--frameIndex];
prevMethod = prevBuffer->disposalMethod();
}
+ ASSERT(prevBuffer->status() == RGBA32Buffer::FrameComplete);
if ((prevMethod == RGBA32Buffer::DisposeNotSpecified) ||
(prevMethod == RGBA32Buffer::DisposeKeep)) {
@@ -305,8 +308,8 @@ void GIFImageDecoder::initFrameBuffer(unsigned frameIndex)
// We want to clear the previous frame to transparent, without
// affecting pixels in the image outside of the frame.
const IntRect& prevRect = prevBuffer->rect();
- if ((frameIndex == 0) ||
- prevRect.contains(IntRect(IntPoint(0, 0), m_size))) {
+ if ((frameIndex == 0)
+ || prevRect.contains(IntRect(IntPoint(0, 0), size()))) {
// Clearing the first frame, or a frame the size of the whole
// image, results in a completely empty image.
prepEmptyFrameBuffer(buffer);
@@ -321,7 +324,7 @@ void GIFImageDecoder::initFrameBuffer(unsigned frameIndex)
buffer->setRGBA(*(currentRow + x), 0, 0, 0, 0);
}
if ((prevRect.width() > 0) && (prevRect.height() > 0))
- buffer->setHasAlpha(true);
+ buffer->setHasAlpha(true);
}
}
}
@@ -335,7 +338,7 @@ void GIFImageDecoder::initFrameBuffer(unsigned frameIndex)
void GIFImageDecoder::prepEmptyFrameBuffer(RGBA32Buffer* buffer) const
{
- buffer->bytes().resize(m_size.width() * m_size.height());
+ buffer->bytes().resize(size().width() * size().height());
buffer->bytes().fill(0);
buffer->setHasAlpha(true);
}
@@ -353,8 +356,8 @@ void GIFImageDecoder::haveDecodedRow(unsigned frameIndex,
initFrameBuffer(frameIndex);
// Do nothing for bogus data.
- if (rowBuffer == 0 || static_cast<int>(m_reader->frameYOffset() + rowNumber) >= m_size.height())
- return;
+ if (rowBuffer == 0 || static_cast<int>(m_reader->frameYOffset() + rowNumber) >= size().height())
+ return;
unsigned colorMapSize;
unsigned char* colorMap;
@@ -369,12 +372,12 @@ void GIFImageDecoder::haveDecodedRow(unsigned frameIndex,
// within the overall image. The rows we are decoding are within this
// sub-rectangle. This means that if the GIF frame's sub-rectangle is (x,y,w,h) then row 0 is really row
// y, and each row goes from x to x+w.
- unsigned dstPos = (m_reader->frameYOffset() + rowNumber) * m_size.width() + m_reader->frameXOffset();
+ unsigned dstPos = (m_reader->frameYOffset() + rowNumber) * size().width() + m_reader->frameXOffset();
unsigned* dst = buffer.bytes().data() + dstPos;
- unsigned* dstEnd = dst + m_size.width() - m_reader->frameXOffset();
+ unsigned* dstEnd = dst + size().width() - m_reader->frameXOffset();
unsigned* currDst = dst;
unsigned char* currentRowByte = rowBuffer;
-
+
while (currentRowByte != rowEnd && currDst < dstEnd) {
if ((!m_reader->isTransparent() || *currentRowByte != m_reader->transparentPixel()) && *currentRowByte < colorMapSize) {
unsigned colorIndex = *currentRowByte * 3;
@@ -401,14 +404,14 @@ void GIFImageDecoder::haveDecodedRow(unsigned frameIndex,
if (repeatCount > 1) {
// Copy the row |repeatCount|-1 times.
unsigned num = currDst - dst;
- unsigned size = num * sizeof(unsigned);
- unsigned width = m_size.width();
- unsigned* end = buffer.bytes().data() + width * m_size.height();
+ unsigned data_size = num * sizeof(unsigned);
+ unsigned width = size().width();
+ unsigned* end = buffer.bytes().data() + width * size().height();
currDst = dst + width;
for (unsigned i = 1; i < repeatCount; i++) {
if (currDst + num > end) // Protect against a buffer overrun from a bogus repeatCount.
break;
- memcpy(currDst, dst, size);
+ memcpy(currDst, dst, data_size);
currDst += width;
}
}
@@ -434,9 +437,9 @@ void GIFImageDecoder::frameComplete(unsigned frameIndex, unsigned frameDuration,
if (!m_currentBufferSawAlpha) {
// The whole frame was non-transparent, so it's possible that the entire
// resulting buffer was non-transparent, and we can setHasAlpha(false).
- if (buffer.rect().contains(IntRect(IntPoint(0, 0), m_size))) {
+ if (buffer.rect().contains(IntRect(IntPoint(0, 0), size())))
buffer.setHasAlpha(false);
- } else if (frameIndex > 0) {
+ else if (frameIndex > 0) {
// Tricky case. This frame does not have alpha only if everywhere
// outside its rect doesn't have alpha. To know whether this is
// true, we check the start state of the frame -- if it doesn't have
@@ -446,9 +449,8 @@ void GIFImageDecoder::frameComplete(unsigned frameIndex, unsigned frameDuration,
// don't affect the start state of this frame) the same way we do in
// initFrameBuffer().
const RGBA32Buffer* prevBuffer = &m_frameBufferCache[--frameIndex];
- while ((frameIndex > 0) &&
- (prevBuffer->disposalMethod() ==
- RGBA32Buffer::DisposeOverwritePrevious))
+ while ((frameIndex > 0)
+ && (prevBuffer->disposalMethod() == RGBA32Buffer::DisposeOverwritePrevious))
prevBuffer = &m_frameBufferCache[--frameIndex];
// Now, if we're at a DisposeNotSpecified or DisposeKeep frame, then
@@ -459,10 +461,8 @@ void GIFImageDecoder::frameComplete(unsigned frameIndex, unsigned frameDuration,
// The only remaining case is a DisposeOverwriteBgcolor frame. If
// it had no alpha, and its rect is contained in the current frame's
// rect, we know the current frame has no alpha.
- if ((prevBuffer->disposalMethod() ==
- RGBA32Buffer::DisposeOverwriteBgcolor) &&
- !prevBuffer->hasAlpha() &&
- buffer.rect().contains(prevBuffer->rect()))
+ if ((prevBuffer->disposalMethod() == RGBA32Buffer::DisposeOverwriteBgcolor)
+ && !prevBuffer->hasAlpha() && buffer.rect().contains(prevBuffer->rect()))
buffer.setHasAlpha(false);
}
}
@@ -476,6 +476,4 @@ void GIFImageDecoder::gifComplete()
m_reader = 0;
}
-}
-
-#endif // PLATFORM(CAIRO)
+} // namespace WebCore
diff --git a/WebCore/platform/image-decoders/gif/GIFImageDecoder.h b/WebCore/platform/image-decoders/gif/GIFImageDecoder.h
index 02b43a2..abb55a4 100644
--- a/WebCore/platform/image-decoders/gif/GIFImageDecoder.h
+++ b/WebCore/platform/image-decoders/gif/GIFImageDecoder.h
@@ -23,70 +23,69 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef GIF_DECODER_H_
-#define GIF_DECODER_H_
+#ifndef GIFImageDecoder_h
+#define GIFImageDecoder_h
#include "ImageDecoder.h"
namespace WebCore {
-class GIFImageDecoderPrivate;
+ class GIFImageDecoderPrivate;
-// This class decodes the GIF image format.
-class GIFImageDecoder : public ImageDecoder
-{
-public:
- GIFImageDecoder();
- ~GIFImageDecoder();
+ // This class decodes the GIF image format.
+ class GIFImageDecoder : public ImageDecoder {
+ public:
+ GIFImageDecoder();
+ ~GIFImageDecoder();
- virtual String filenameExtension() const { return "gif"; }
+ virtual String filenameExtension() const { return "gif"; }
- // Take the data and store it.
- virtual void setData(SharedBuffer* data, bool allDataReceived);
+ // Take the data and store it.
+ virtual void setData(SharedBuffer* data, bool allDataReceived);
- // Whether or not the size information has been decoded yet.
- virtual bool isSizeAvailable() const;
+ // Whether or not the size information has been decoded yet.
+ virtual bool isSizeAvailable() const;
- // The total number of frames for the image. Will scan the image data for the answer
- // (without necessarily decoding all of the individual frames).
- virtual int frameCount();
+ // The total number of frames for the image. Will scan the image data for the answer
+ // (without necessarily decoding all of the individual frames).
+ virtual int frameCount();
- // The number of repetitions to perform for an animation loop.
- virtual int repetitionCount() const;
+ // The number of repetitions to perform for an animation loop.
+ virtual int repetitionCount() const;
- virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
+ virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
- virtual void clearFrameBufferCache(size_t clearBeforeFrame);
+ virtual void clearFrameBufferCache(size_t clearBeforeFrame);
- virtual unsigned frameDurationAtIndex(size_t index) { return 0; }
+ virtual unsigned frameDurationAtIndex(size_t index) { return 0; }
- enum GIFQuery { GIFFullQuery, GIFSizeQuery, GIFFrameCountQuery };
+ enum GIFQuery { GIFFullQuery, GIFSizeQuery, GIFFrameCountQuery };
- void decode(GIFQuery query, unsigned haltAtFrame) const;
+ void decode(GIFQuery, unsigned haltAtFrame) const;
- // Callbacks from the GIF reader.
- void sizeNowAvailable(unsigned width, unsigned height);
- void decodingHalted(unsigned bytesLeft);
- void haveDecodedRow(unsigned frameIndex, unsigned char* rowBuffer, unsigned char* rowEnd, unsigned rowNumber,
- unsigned repeatCount, bool writeTransparentPixels);
- void frameComplete(unsigned frameIndex, unsigned frameDuration, RGBA32Buffer::FrameDisposalMethod disposalMethod);
- void gifComplete();
+ // Callbacks from the GIF reader.
+ void sizeNowAvailable(unsigned width, unsigned height);
+ void decodingHalted(unsigned bytesLeft);
+ void haveDecodedRow(unsigned frameIndex, unsigned char* rowBuffer, unsigned char* rowEnd, unsigned rowNumber,
+ unsigned repeatCount, bool writeTransparentPixels);
+ void frameComplete(unsigned frameIndex, unsigned frameDuration, RGBA32Buffer::FrameDisposalMethod disposalMethod);
+ void gifComplete();
-private:
- // Called to initialize the frame buffer with the given index, based on the
- // previous frame's disposal method.
- void initFrameBuffer(unsigned frameIndex);
+ private:
+ // Called to initialize the frame buffer with the given index, based on the
+ // previous frame's disposal method.
+ void initFrameBuffer(unsigned frameIndex);
- // A helper for initFrameBuffer(), this sets the size of the buffer, and
- // fills it with transparent pixels.
- void prepEmptyFrameBuffer(RGBA32Buffer* buffer) const;
+ // A helper for initFrameBuffer(), this sets the size of the buffer, and
+ // fills it with transparent pixels.
+ void prepEmptyFrameBuffer(RGBA32Buffer*) const;
- bool m_frameCountValid;
- bool m_currentBufferSawAlpha;
- mutable int m_repetitionCount;
- mutable GIFImageDecoderPrivate* m_reader;
-};
+ bool m_frameCountValid;
+ bool m_currentBufferSawAlpha;
+ mutable int m_repetitionCount;
+ mutable GIFImageDecoderPrivate* m_reader;
+ };
-}
+} // namespace WebCore
#endif
diff --git a/WebCore/platform/image-decoders/gif/GIFImageReader.cpp b/WebCore/platform/image-decoders/gif/GIFImageReader.cpp
index 04347af..95ab40d 100644
--- a/WebCore/platform/image-decoders/gif/GIFImageReader.cpp
+++ b/WebCore/platform/image-decoders/gif/GIFImageReader.cpp
@@ -78,8 +78,6 @@ mailing address.
#include <string.h>
#include "GIFImageDecoder.h"
-#if PLATFORM(CAIRO) || PLATFORM(QT) || PLATFORM(WX)
-
using WebCore::GIFImageDecoder;
// Define the Mozilla macro setup so that we can leave the macros alone.
@@ -939,5 +937,3 @@ bool GIFImageReader::read(const unsigned char *buf, unsigned len,
clientptr->decodingHalted(0);
return true;
}
-
-#endif // PLATFORM(CAIRO)
diff --git a/WebCore/platform/image-decoders/gif/GIFImageReader.h b/WebCore/platform/image-decoders/gif/GIFImageReader.h
index 855e6be..f0d127f 100644
--- a/WebCore/platform/image-decoders/gif/GIFImageReader.h
+++ b/WebCore/platform/image-decoders/gif/GIFImageReader.h
@@ -35,8 +35,8 @@
*
* ***** END LICENSE BLOCK ***** */
-#ifndef _GIF_H_
-#define _GIF_H_
+#ifndef GIFImageReader_h
+#define GIFImageReader_h
// Define ourselves as the clientPtr. Mozilla just hacked their C++ callback class into this old C decoder,
// so we will too.
@@ -168,7 +168,7 @@ struct GIFImageReader {
unsigned screen_width; /* Logical screen width & height */
unsigned screen_height;
int global_colormap_size; /* Size of global colormap array. */
- int images_decoded; /* Counts completed frames for animated GIFs */
+ unsigned images_decoded; /* Counts completed frames for animated GIFs */
int images_count; /* Counted all frames seen so far (including incomplete frames) */
int loop_count; /* Netscape specific extension block to control
the number of animation loops a GIF renders. */
@@ -213,4 +213,3 @@ private:
};
#endif
-
diff --git a/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp b/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp
index 019340d..5b1a88f 100644
--- a/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp
@@ -26,8 +26,6 @@
#include "config.h"
#include "ICOImageDecoder.h"
-#if PLATFORM(CAIRO) || PLATFORM(QT) || PLATFORM(WX)
-
namespace WebCore
{
@@ -41,6 +39,4 @@ RGBA32Buffer* ICOImageDecoder::frameBufferAtIndex(size_t index)
return 0;
}
-}
-
-#endif // PLATFORM(CAIRO)
+} // namespace WebCore
diff --git a/WebCore/platform/image-decoders/ico/ICOImageDecoder.h b/WebCore/platform/image-decoders/ico/ICOImageDecoder.h
index a4f3dbd..56a74c3 100644
--- a/WebCore/platform/image-decoders/ico/ICOImageDecoder.h
+++ b/WebCore/platform/image-decoders/ico/ICOImageDecoder.h
@@ -23,27 +23,26 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef ICO_DECODER_H_
-#define ICO_DECODER_H_
+#ifndef ICOImageDecoder_h
+#define ICOImageDecoder_h
#include "ImageDecoder.h"
namespace WebCore {
-class ICOImageReader;
+ class ICOImageReader;
-// This class decodes the ICO and CUR image formats.
-class ICOImageDecoder : public ImageDecoder
-{
-public:
- virtual String filenameExtension() const { return "ico"; }
+ // This class decodes the ICO and CUR image formats.
+ class ICOImageDecoder : public ImageDecoder {
+ public:
+ virtual String filenameExtension() const { return "ico"; }
- // Whether or not the size information has been decoded yet.
- virtual bool isSizeAvailable() const;
+ // Whether or not the size information has been decoded yet.
+ virtual bool isSizeAvailable() const;
- virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
-};
+ virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
+ };
-}
+} // namespace WebCore
#endif
diff --git a/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp b/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
index 44e0e4c..38d90bd 100644
--- a/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
@@ -40,30 +40,13 @@
#include <assert.h>
#include <stdio.h>
-#if PLATFORM(CAIRO) || PLATFORM(QT) || PLATFORM(WX)
-
-#if COMPILER(MSVC)
-// Remove warnings from warning level 4.
-#pragma warning(disable : 4611) // warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable
-
-// if ADDRESS_TAG_BIT is dfined, INT32 has been declared as a typedef in the PlatformSDK (BaseTsd.h),
-// so we need to stop jpeglib.h from trying to #define it
-// see here for more info: http://www.cygwin.com/ml/cygwin/2004-07/msg01051.html
-# if defined(ADDRESS_TAG_BIT) && !defined(XMD_H)
-# define XMD_H
-# define VTK_JPEG_XMD_H
-# endif
-#endif // COMPILER(MSVC)
-
extern "C" {
#include "jpeglib.h"
}
#if COMPILER(MSVC)
-# if defined(VTK_JPEG_XMD_H)
-# undef VTK_JPEG_XMD_H
-# undef XMD_H
-# endif
+// Remove warnings from warning level 4.
+#pragma warning(disable : 4611) // warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable
#endif // COMPILER(MSVC)
#include <setjmp.h>
@@ -482,7 +465,7 @@ bool JPEGImageDecoder::outputScanlines()
if (buffer.status() == RGBA32Buffer::FrameEmpty) {
// Let's resize our buffer now to the correct width/height.
RGBA32Array& bytes = buffer.bytes();
- bytes.resize(m_size.width() * m_size.height());
+ bytes.resize(size().width() * size().height());
// Update our status to be partially complete.
buffer.setStatus(RGBA32Buffer::FramePartial);
@@ -503,7 +486,7 @@ bool JPEGImageDecoder::outputScanlines()
if (jpeg_read_scanlines(info, samples, 1) != 1)
return false;
JSAMPLE *j1 = samples[0];
- for (unsigned i = 0; i < info->output_width; ++i) {
+ for (unsigned x = 0; x < info->output_width; ++x) {
unsigned r = *j1++;
unsigned g = *j1++;
unsigned b = *j1++;
@@ -527,5 +510,3 @@ void JPEGImageDecoder::jpegComplete()
}
}
-
-#endif // PLATFORM(CAIRO)
diff --git a/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h b/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h
index b4d7b2a..c01bb5e 100644
--- a/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h
+++ b/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h
@@ -23,52 +23,51 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef JPEG_DECODER_H_
-#define JPEG_DECODER_H_
+#ifndef JPEGImageDecoder_h
+#define JPEGImageDecoder_h
#include "ImageDecoder.h"
namespace WebCore {
-class JPEGImageReader;
+ class JPEGImageReader;
-// This class decodes the JPEG image format.
-class JPEGImageDecoder : public ImageDecoder
-{
-public:
- JPEGImageDecoder();
- ~JPEGImageDecoder();
+ // This class decodes the JPEG image format.
+ class JPEGImageDecoder : public ImageDecoder {
+ public:
+ JPEGImageDecoder();
+ ~JPEGImageDecoder();
- virtual String filenameExtension() const { return "jpg"; }
+ virtual String filenameExtension() const { return "jpg"; }
- // Take the data and store it.
- virtual void setData(SharedBuffer* data, bool allDataReceived);
+ // Take the data and store it.
+ virtual void setData(SharedBuffer* data, bool allDataReceived);
- // Whether or not the size information has been decoded yet.
- virtual bool isSizeAvailable() const;
+ // Whether or not the size information has been decoded yet.
+ virtual bool isSizeAvailable() const;
- virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
-
- virtual bool supportsAlpha() const { return false; }
+ virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
+
+ virtual bool supportsAlpha() const { return false; }
- void decode(bool sizeOnly = false) const;
+ void decode(bool sizeOnly = false) const;
- JPEGImageReader* reader() { return m_reader; }
+ JPEGImageReader* reader() { return m_reader; }
- void setSize(int width, int height) {
- if (!m_sizeAvailable) {
- m_sizeAvailable = true;
- m_size = IntSize(width, height);
+ void setSize(int width, int height) {
+ if (!m_sizeAvailable) {
+ m_sizeAvailable = true;
+ m_size = IntSize(width, height);
+ }
}
- }
- bool outputScanlines();
- void jpegComplete();
+ bool outputScanlines();
+ void jpegComplete();
-private:
- mutable JPEGImageReader* m_reader;
-};
+ private:
+ mutable JPEGImageReader* m_reader;
+ };
-}
+} // namespace WebCore
#endif
diff --git a/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp b/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp
index 17143b1..dead8ca 100644
--- a/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp
@@ -40,12 +40,10 @@
#include "png.h"
#include "assert.h"
-#if PLATFORM(CAIRO) || PLATFORM(QT) || PLATFORM(WX)
-
#if COMPILER(MSVC)
// Remove warnings from warning level 4.
#pragma warning(disable : 4611) // warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable
-#endif
+#endif // COMPILER(MSVC)
namespace WebCore {
@@ -55,7 +53,7 @@ const double cDefaultGamma = 2.2;
const double cInverseGamma = 0.45455;
// Protect against large PNGs. See Mozilla's bug #251381 for more info.
-const long cMaxPNGSize = 1000000L;
+const unsigned long cMaxPNGSize = 1000000UL;
// Called if the decoding of the image fails.
static void PNGAPI decodingFailed(png_structp png_ptr, png_const_charp error_msg);
@@ -78,9 +76,12 @@ class PNGImageReader
{
public:
PNGImageReader(PNGImageDecoder* decoder)
- : m_readOffset(0), m_decodingSizeOnly(false), m_interlaceBuffer(0), m_hasAlpha(0)
+ : m_readOffset(0)
+ , m_decodingSizeOnly(false)
+ , m_interlaceBuffer(0)
+ , m_hasAlpha(0)
{
- m_png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, decodingFailed, decodingWarning);
+ m_png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, decodingFailed, decodingWarning);
m_info = png_create_info_struct(m_png);
png_set_progressive_read_fn(m_png, decoder, headerAvailable, rowAvailable, pngComplete);
}
@@ -92,8 +93,9 @@ public:
void close() {
if (m_png && m_info)
- png_destroy_read_struct(&m_png, &m_info, 0);
+ png_destroy_read_struct(&m_png, &m_info, 0); // Will zero the pointers.
delete []m_interlaceBuffer;
+ m_interlaceBuffer = 0;
m_readOffset = 0;
}
@@ -139,7 +141,7 @@ private:
};
PNGImageDecoder::PNGImageDecoder()
-: m_reader(0)
+ : m_reader(0)
{
m_frameBufferCache.resize(1);
}
@@ -224,6 +226,10 @@ void headerAvailable(png_structp png, png_infop info)
static_cast<PNGImageDecoder*>(png_get_progressive_ptr(png))->headerAvailable();
}
+void PNGImageDecoder::decodingFailed() {
+ m_failed = true;
+}
+
void PNGImageDecoder::headerAvailable()
{
png_structp png = reader()->pngPtr();
@@ -312,16 +318,16 @@ void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex,
if (buffer.status() == RGBA32Buffer::FrameEmpty) {
// Let's resize our buffer now to the correct width/height.
RGBA32Array& bytes = buffer.bytes();
- bytes.resize(m_size.width() * m_size.height());
+ bytes.resize(size().width() * size().height());
// Update our status to be partially complete.
buffer.setStatus(RGBA32Buffer::FramePartial);
// For PNGs, the frame always fills the entire image.
- buffer.setRect(IntRect(0, 0, m_size.width(), m_size.height()));
+ buffer.setRect(IntRect(0, 0, size().width(), size().height()));
if (reader()->pngPtr()->interlaced)
- reader()->createInterlaceBuffer((reader()->hasAlpha() ? 4 : 3) * m_size.width() * m_size.height());
+ reader()->createInterlaceBuffer((reader()->hasAlpha() ? 4 : 3) * size().width() * size().height());
}
if (rowBuffer == 0)
@@ -361,17 +367,17 @@ void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex,
png_bytep row;
png_bytep interlaceBuffer = reader()->interlaceBuffer();
if (interlaceBuffer) {
- row = interlaceBuffer + (rowIndex * colorChannels * m_size.width());
+ row = interlaceBuffer + (rowIndex * colorChannels * size().width());
png_progressive_combine_row(png, row, rowBuffer);
}
else
row = rowBuffer;
// Copy the data into our buffer.
- int width = m_size.width();
+ int width = size().width();
unsigned* dst = buffer.bytes().data() + rowIndex * width;
bool sawAlpha = false;
- for (int i = 0; i < width; i++) {
+ for (int x = 0; x < width; x++) {
unsigned red = *row++;
unsigned green = *row++;
unsigned blue = *row++;
@@ -398,6 +404,4 @@ void PNGImageDecoder::pngComplete()
buffer.setStatus(RGBA32Buffer::FrameComplete);
}
-}
-
-#endif // PLATFORM(CAIRO)
+} // namespace WebCore
diff --git a/WebCore/platform/image-decoders/png/PNGImageDecoder.h b/WebCore/platform/image-decoders/png/PNGImageDecoder.h
index 8c73785..c5264fd 100644
--- a/WebCore/platform/image-decoders/png/PNGImageDecoder.h
+++ b/WebCore/platform/image-decoders/png/PNGImageDecoder.h
@@ -23,46 +23,45 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef PNG_DECODER_H_
-#define PNG_DECODER_H_
+#ifndef PNGImageDecoder_h
+#define PNGImageDecoder_h
#include "ImageDecoder.h"
namespace WebCore {
-class PNGImageReader;
+ class PNGImageReader;
-// This class decodes the PNG image format.
-class PNGImageDecoder : public ImageDecoder
-{
-public:
- PNGImageDecoder();
- ~PNGImageDecoder();
+ // This class decodes the PNG image format.
+ class PNGImageDecoder : public ImageDecoder {
+ public:
+ PNGImageDecoder();
+ ~PNGImageDecoder();
- virtual String filenameExtension() const { return "png"; }
+ virtual String filenameExtension() const { return "png"; }
- // Take the data and store it.
- virtual void setData(SharedBuffer* data, bool allDataReceived);
+ // Take the data and store it.
+ virtual void setData(SharedBuffer* data, bool allDataReceived);
- // Whether or not the size information has been decoded yet.
- virtual bool isSizeAvailable() const;
+ // Whether or not the size information has been decoded yet.
+ virtual bool isSizeAvailable() const;
- virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
+ virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
- void decode(bool sizeOnly = false) const;
+ void decode(bool sizeOnly = false) const;
- PNGImageReader* reader() { return m_reader; }
+ PNGImageReader* reader() { return m_reader; }
- // Callbacks from libpng
- void decodingFailed() { m_failed = true; }
- void headerAvailable();
- void rowAvailable(unsigned char* rowBuffer, unsigned rowIndex, int interlacePass);
- void pngComplete();
+ // Callbacks from libpng
+ void decodingFailed();
+ void headerAvailable();
+ void rowAvailable(unsigned char* rowBuffer, unsigned rowIndex, int interlacePass);
+ void pngComplete();
-private:
- mutable PNGImageReader* m_reader;
-};
+ private:
+ mutable PNGImageReader* m_reader;
+ };
-}
+} // namespace WebCore
#endif
diff --git a/WebCore/platform/image-decoders/skia/GIFImageDecoder.cpp b/WebCore/platform/image-decoders/skia/GIFImageDecoder.cpp
index 2d77943..c03452a 100644
--- a/WebCore/platform/image-decoders/skia/GIFImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/skia/GIFImageDecoder.cpp
@@ -126,7 +126,7 @@ bool GIFImageDecoder::isSizeAvailable() const
decode(GIFSizeQuery, 0);
}
- return !m_failed && ImageDecoder::isSizeAvailable();
+ return ImageDecoder::isSizeAvailable();
}
// The total number of frames for the image. Will scan the image data for the answer
@@ -183,7 +183,7 @@ RGBA32Buffer* GIFImageDecoder::frameBufferAtIndex(size_t index)
RGBA32Buffer& frame = m_frameBufferCache[index];
if (frame.status() != RGBA32Buffer::FrameComplete && m_reader)
- decode(GIFFullQuery, index+1); // Decode this frame.
+ decode(GIFFullQuery, index + 1); // Decode this frame.
return &frame;
}
diff --git a/WebCore/platform/image-decoders/skia/GIFImageReader.h b/WebCore/platform/image-decoders/skia/GIFImageReader.h
index aa3d717..f0d127f 100644
--- a/WebCore/platform/image-decoders/skia/GIFImageReader.h
+++ b/WebCore/platform/image-decoders/skia/GIFImageReader.h
@@ -167,11 +167,11 @@ struct GIFImageReader {
int version; /* Either 89 for GIF89 or 87 for GIF87 */
unsigned screen_width; /* Logical screen width & height */
unsigned screen_height;
- int global_colormap_size; /* Size of global colormap array. */
- unsigned int images_decoded; /* Counts completed frames for animated GIFs */
- int images_count; /* Counted all frames seen so far (including incomplete frames) */
- int loop_count; /* Netscape specific extension block to control
- the number of animation loops a GIF renders. */
+ int global_colormap_size; /* Size of global colormap array. */
+ unsigned images_decoded; /* Counts completed frames for animated GIFs */
+ int images_count; /* Counted all frames seen so far (including incomplete frames) */
+ int loop_count; /* Netscape specific extension block to control
+ the number of animation loops a GIF renders. */
// Not really global, but convenient to locate here.
int count; /* Remaining # bytes in sub-block */
diff --git a/WebCore/platform/image-decoders/skia/ImageDecoder.h b/WebCore/platform/image-decoders/skia/ImageDecoder.h
index cddb69b..c198420 100644
--- a/WebCore/platform/image-decoders/skia/ImageDecoder.h
+++ b/WebCore/platform/image-decoders/skia/ImageDecoder.h
@@ -33,8 +33,6 @@
#include "PlatformString.h"
#include "SharedBuffer.h"
#include <wtf/Assertions.h>
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
@@ -45,37 +43,8 @@
namespace WebCore {
- class RefCountedNativeImageSkia : public RefCounted<RefCountedNativeImageSkia> {
- public:
- static PassRefPtr<RefCountedNativeImageSkia> create()
- {
- return adoptRef(new RefCountedNativeImageSkia);
- }
-
- const NativeImageSkia& bitmap() const { return m_bitmap; }
- NativeImageSkia& bitmap() { return m_bitmap; }
-
- private:
- RefCountedNativeImageSkia() {}
- NativeImageSkia m_bitmap;
- };
-
- // The RGBA32Buffer object represents the decoded image data in RGBA32 format.
- // This buffer is what all decoders write a single frame into. Frames are then
- // instantiated for drawing by being handed this buffer.
- //
- // The image data of an RGBA32Buffer is kept in an SkBitmapRef, a refcounting
- // container for an SkBitmap. In all normal cases, the refcount should be
- // exactly one. The exception happens when resizing the vector<RGBA32Buffer> in
- // ImageDecoder::m_frameBufferCache, which copies all the buffers to the new
- // vector, thus transiently incrementing the refcount to two.
- //
- // The choice to use an SkBitmapRef instead of an SkBitmap is not because of
- // performance concerns -- SkBitmap refcounts its internal data anyway. Rather,
- // we need the aforementioned vector resize to preserve the exact underlying
- // SkBitmap object, since we may have already given its address to
- // BitmapImage::m_frames. Using an SkBitmap would mean that after ImageDecoder
- // resizes its vector, BitmapImage would be holding a pointer to garbage.
+ // The RGBA32Buffer object represents the decoded image data in RGBA32 format. This buffer is what all
+ // decoders write a single frame into. Frames are then instantiated for drawing by being handed this buffer.
class RGBA32Buffer {
public:
enum FrameStatus { FrameEmpty, FramePartial, FrameComplete };
@@ -94,14 +63,12 @@ namespace WebCore {
, m_duration(0)
, m_disposalMethod(DisposeNotSpecified)
{
- m_bitmapRef = RefCountedNativeImageSkia::create();
}
// This constructor doesn't create a new copy of the image data, it only
// increases the ref count of the existing bitmap.
RGBA32Buffer(const RGBA32Buffer& other)
{
- m_bitmapRef = RefCountedNativeImageSkia::create();
operator=(other);
}
@@ -120,18 +87,20 @@ namespace WebCore {
if (this == &other)
return *this;
- m_bitmapRef = other.m_bitmapRef;
+ m_bitmap = other.m_bitmap;
+ // Keep the pixels locked since we will be writing directly into the
+ // bitmap throughout this object's lifetime.
+ m_bitmap.lockPixels();
setRect(other.rect());
setStatus(other.status());
setDuration(other.duration());
setDisposalMethod(other.disposalMethod());
- setHasAlpha(other.hasAlpha());
return *this;
}
void clear()
{
- m_bitmapRef = RefCountedNativeImageSkia::create();
+ m_bitmap.reset();
m_status = FrameEmpty;
// NOTE: Do not reset other members here; clearFrameBufferCache()
// calls this to free the bitmap data, but other functions like
@@ -146,21 +115,13 @@ namespace WebCore {
if (this == &other)
return;
- m_bitmapRef = RefCountedNativeImageSkia::create();
- SkBitmap& bmp = bitmap();
- const SkBitmap& otherBmp = other.bitmap();
- bmp.setConfig(SkBitmap::kARGB_8888_Config, other.width(),
- other.height(), otherBmp.rowBytes());
- bmp.allocPixels();
- if (width() > 0 && height() > 0) {
- memcpy(bmp.getAddr32(0, 0),
- otherBmp.getAddr32(0, 0),
- otherBmp.rowBytes() * height());
- }
+ m_bitmap.reset();
+ const NativeImageSkia& otherBitmap = other.bitmap();
+ otherBitmap.copyTo(&m_bitmap, otherBitmap.config());
}
- NativeImageSkia& bitmap() { return m_bitmapRef->bitmap(); }
- const NativeImageSkia& bitmap() const { return m_bitmapRef->bitmap(); }
+ NativeImageSkia& bitmap() { return m_bitmap; }
+ const NativeImageSkia& bitmap() const { return m_bitmap; }
// Must be called before any pixels are written. Will return true on
// success, false if the memory allocation fails.
@@ -168,37 +129,36 @@ namespace WebCore {
{
// This function should only be called once, it will leak memory
// otherwise.
- SkBitmap& bmp = bitmap();
- ASSERT(bmp.width() == 0 && bmp.height() == 0);
- bmp.setConfig(SkBitmap::kARGB_8888_Config, width, height);
- if (!bmp.allocPixels())
+ ASSERT(m_bitmap.width() == 0 && m_bitmap.height() == 0);
+ m_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ if (!m_bitmap.allocPixels())
return false; // Allocation failure, maybe the bitmap was too big.
// Clear the image.
- bmp.eraseARGB(0, 0, 0, 0);
+ m_bitmap.eraseARGB(0, 0, 0, 0);
return true;
}
- int width() const { return bitmap().width(); }
- int height() const { return bitmap().height(); }
+ int width() const { return m_bitmap.width(); }
+ int height() const { return m_bitmap.height(); }
const IntRect& rect() const { return m_rect; }
FrameStatus status() const { return m_status; }
unsigned duration() const { return m_duration; }
FrameDisposalMethod disposalMethod() const { return m_disposalMethod; }
- bool hasAlpha() const { return !bitmap().isOpaque(); }
+ bool hasAlpha() const { return !m_bitmap.isOpaque(); }
void setRect(const IntRect& r) { m_rect = r; }
void setStatus(FrameStatus s)
{
if (s == FrameComplete)
- m_bitmapRef->bitmap().setDataComplete(); // Tell the bitmap it's done.
+ m_bitmap.setDataComplete(); // Tell the bitmap it's done.
m_status = s;
}
void setDuration(unsigned duration) { m_duration = duration; }
void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; }
- void setHasAlpha(bool alpha) { bitmap().setIsOpaque(!alpha); }
+ void setHasAlpha(bool alpha) { m_bitmap.setIsOpaque(!alpha); }
static void setRGBA(uint32_t* dest, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
@@ -223,11 +183,11 @@ namespace WebCore {
void setRGBA(int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
- setRGBA(bitmap().getAddr32(x, y), r, g, b, a);
+ setRGBA(m_bitmap.getAddr32(x, y), r, g, b, a);
}
private:
- RefPtr<RefCountedNativeImageSkia> m_bitmapRef;
+ NativeImageSkia m_bitmap;
IntRect m_rect; // The rect of the original specified frame within the overall buffer.
// This will always just be the entire buffer except for GIF frames
// whose original rect was smaller than the overall image size.
@@ -241,7 +201,12 @@ namespace WebCore {
// and the base class manages the RGBA32 frame cache.
class ImageDecoder {
public:
- ImageDecoder() : m_failed(false), m_sizeAvailable(false) {}
+ ImageDecoder()
+ : m_failed(false)
+ , m_sizeAvailable(false)
+ {
+ }
+
virtual ~ImageDecoder() {}
// The the filename extension usually associated with an undecoded image of this type.
diff --git a/WebCore/platform/image-decoders/skia/JPEGImageDecoder.cpp b/WebCore/platform/image-decoders/skia/JPEGImageDecoder.cpp
index 98f622e..ab74012 100644
--- a/WebCore/platform/image-decoders/skia/JPEGImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/skia/JPEGImageDecoder.cpp
@@ -99,7 +99,7 @@ public:
/* Allocate and initialize JPEG decompression object */
jpeg_create_decompress(&m_info);
- decoder_source_mgr* src = NULL;
+ decoder_source_mgr* src = 0;
if (!m_info.src) {
src = (decoder_source_mgr*)fastCalloc(sizeof(decoder_source_mgr), 1);
if (!src) {
@@ -421,7 +421,7 @@ bool JPEGImageDecoder::isSizeAvailable() const
decode(true);
}
- return !m_failed && ImageDecoder::isSizeAvailable();
+ return ImageDecoder::isSizeAvailable();
}
RGBA32Buffer* JPEGImageDecoder::frameBufferAtIndex(size_t index)
diff --git a/WebCore/platform/image-decoders/skia/PNGImageDecoder.cpp b/WebCore/platform/image-decoders/skia/PNGImageDecoder.cpp
index ec1ebbe..ad12b86 100644
--- a/WebCore/platform/image-decoders/skia/PNGImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/skia/PNGImageDecoder.cpp
@@ -72,9 +72,12 @@ class PNGImageReader
{
public:
PNGImageReader(PNGImageDecoder* decoder)
- : m_readOffset(0), m_decodingSizeOnly(false), m_interlaceBuffer(0), m_hasAlpha(0)
+ : m_readOffset(0)
+ , m_decodingSizeOnly(false)
+ , m_interlaceBuffer(0)
+ , m_hasAlpha(0)
{
- m_png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, decodingFailed, decodingWarning);
+ m_png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, decodingFailed, decodingWarning);
m_info = png_create_info_struct(m_png);
png_set_progressive_read_fn(m_png, decoder, headerAvailable, rowAvailable, pngComplete);
}
@@ -134,8 +137,9 @@ private:
};
PNGImageDecoder::PNGImageDecoder()
-: m_reader(0)
-{}
+ : m_reader(0)
+{
+}
PNGImageDecoder::~PNGImageDecoder()
{
@@ -169,7 +173,7 @@ bool PNGImageDecoder::isSizeAvailable() const
decode(true);
}
- return !m_failed && ImageDecoder::isSizeAvailable();
+ return ImageDecoder::isSizeAvailable();
}
RGBA32Buffer* PNGImageDecoder::frameBufferAtIndex(size_t index)
@@ -305,8 +309,7 @@ void PNGImageDecoder::headerAvailable()
void rowAvailable(png_structp png, png_bytep rowBuffer,
png_uint_32 rowIndex, int interlacePass)
{
- static_cast<PNGImageDecoder*>(png_get_progressive_ptr(png))->rowAvailable(
- rowBuffer, rowIndex, interlacePass);
+ static_cast<PNGImageDecoder*>(png_get_progressive_ptr(png))->rowAvailable(rowBuffer, rowIndex, interlacePass);
}
void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex, int interlacePass)
diff --git a/WebCore/platform/image-decoders/skia/XBMImageDecoder.h b/WebCore/platform/image-decoders/skia/XBMImageDecoder.h
index 44c6be2..cdcf8e6 100644
--- a/WebCore/platform/image-decoders/skia/XBMImageDecoder.h
+++ b/WebCore/platform/image-decoders/skia/XBMImageDecoder.h
@@ -31,7 +31,6 @@
#ifndef XBMImageDecoder_h
#define XBMImageDecoder_h
-#include "config.h"
#include <string>
#include "ImageDecoder.h"
diff --git a/WebCore/platform/image-decoders/xbm/XBMImageDecoder.cpp b/WebCore/platform/image-decoders/xbm/XBMImageDecoder.cpp
index 30c5589..3e8ae57 100644
--- a/WebCore/platform/image-decoders/xbm/XBMImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/xbm/XBMImageDecoder.cpp
@@ -26,8 +26,6 @@
#include "config.h"
#include "XBMImageDecoder.h"
-#if PLATFORM(CAIRO) || PLATFORM(QT) || PLATFORM(WX)
-
namespace WebCore
{
@@ -41,6 +39,4 @@ RGBA32Buffer* XBMImageDecoder::frameBufferAtIndex(size_t index)
return 0;
}
-}
-
-#endif // PLATFORM(CAIRO)
+} // namespace WebCore
diff --git a/WebCore/platform/image-decoders/xbm/XBMImageDecoder.h b/WebCore/platform/image-decoders/xbm/XBMImageDecoder.h
index dc6d8d4..80cfb3f 100644
--- a/WebCore/platform/image-decoders/xbm/XBMImageDecoder.h
+++ b/WebCore/platform/image-decoders/xbm/XBMImageDecoder.h
@@ -23,27 +23,26 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef XBM_DECODER_H_
-#define XBM_DECODER_H_
+#ifndef XBMImageDecoder_h
+#define XBMImageDecoder_h
#include "ImageDecoder.h"
namespace WebCore {
-class XBMImageReader;
+ class XBMImageReader;
-// This class decodes the XBM image format.
-class XBMImageDecoder : public ImageDecoder
-{
-public:
- virtual String filenameExtension() const { return "xbm"; }
+ // This class decodes the XBM image format.
+ class XBMImageDecoder : public ImageDecoder {
+ public:
+ virtual String filenameExtension() const { return "xbm"; }
- // Whether or not the size information has been decoded yet.
- virtual bool isSizeAvailable() const;
+ // Whether or not the size information has been decoded yet.
+ virtual bool isSizeAvailable() const;
- virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
-};
+ virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
+ };
-}
+} // namespace WebCore
#endif