summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/image-decoders/ImageDecoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/platform/image-decoders/ImageDecoder.cpp')
-rw-r--r--Source/WebCore/platform/image-decoders/ImageDecoder.cpp94
1 files changed, 60 insertions, 34 deletions
diff --git a/Source/WebCore/platform/image-decoders/ImageDecoder.cpp b/Source/WebCore/platform/image-decoders/ImageDecoder.cpp
index 17208b5..2aae205 100644
--- a/Source/WebCore/platform/image-decoders/ImageDecoder.cpp
+++ b/Source/WebCore/platform/image-decoders/ImageDecoder.cpp
@@ -38,7 +38,9 @@ using namespace std;
namespace WebCore {
-static unsigned copyFromSharedBuffer(char* buffer, unsigned bufferLength, const SharedBuffer& sharedBuffer, unsigned offset)
+namespace {
+
+unsigned copyFromSharedBuffer(char* buffer, unsigned bufferLength, const SharedBuffer& sharedBuffer, unsigned offset)
{
unsigned bytesExtracted = 0;
const char* moreData;
@@ -53,55 +55,80 @@ static unsigned copyFromSharedBuffer(char* buffer, unsigned bufferLength, const
return bytesExtracted;
}
+<<<<<<< HEAD
#if !OS(ANDROID)
// This method requires BMPImageDecoder, PNGImageDecoder, ICOImageDecoder and
// JPEGDecoder, which aren't used on Android, and which don't all compile.
// TODO: Find a better fix.
+=======
+bool matchesGIFSignature(char* contents)
+{
+ return !memcmp(contents, "GIF8", 4);
+}
+
+bool matchesPNGSignature(char* contents)
+{
+ return !memcmp(contents, "\x89\x50\x4E\x47", 4);
+}
+
+bool matchesJPEGSignature(char* contents)
+{
+ return !memcmp(contents, "\xFF\xD8\xFF", 3);
+}
+
+#if USE(WEBP)
+bool matchesWebPSignature(char* contents)
+{
+ return !memcmp(contents, "RIFF", 4) && !memcmp(contents + 8, "WEBPVP", 6);
+}
+#endif
+
+bool matchesBMPSignature(char* contents)
+{
+ return !memcmp(contents, "BM", 2);
+}
+
+bool matchesICOSignature(char* contents)
+{
+ return !memcmp(contents, "\x00\x00\x01\x00", 4);
+}
+
+bool matchesCURSignature(char* contents)
+{
+ return !memcmp(contents, "\x00\x00\x02\x00", 4);
+}
+
+}
+
+>>>>>>> webkit.org at r78450
ImageDecoder* ImageDecoder::create(const SharedBuffer& data, ImageSource::AlphaOption alphaOption, ImageSource::GammaAndColorProfileOption gammaAndColorProfileOption)
{
- // We need at least 4 bytes to figure out what kind of image we're dealing
- // with.
- static const unsigned maxMarkerLength = 4;
- char contents[maxMarkerLength];
- unsigned length = copyFromSharedBuffer(contents, maxMarkerLength, data, 0);
- if (length < maxMarkerLength)
+ static const unsigned lengthOfLongestSignature = 14; // To wit: "RIFF????WEBPVP"
+ char contents[lengthOfLongestSignature];
+ unsigned length = copyFromSharedBuffer(contents, lengthOfLongestSignature, data, 0);
+ if (length < lengthOfLongestSignature)
return 0;
- // GIFs begin with GIF8(7 or 9).
- if (strncmp(contents, "GIF8", 4) == 0)
+ if (matchesGIFSignature(contents))
return new GIFImageDecoder(alphaOption, gammaAndColorProfileOption);
- // Test for PNG.
- if (!memcmp(contents, "\x89\x50\x4E\x47", 4))
+ if (matchesPNGSignature(contents))
return new PNGImageDecoder(alphaOption, gammaAndColorProfileOption);
- // JPEG
- if (!memcmp(contents, "\xFF\xD8\xFF", 3))
+ if (matchesJPEGSignature(contents))
return new JPEGImageDecoder(alphaOption, gammaAndColorProfileOption);
#if USE(WEBP)
- if (!memcmp(contents, "RIFF", 4)) {
- static const unsigned webpExtraMarker = 6;
- static const unsigned webpExtraMarkeroffset = 8;
- char header[webpExtraMarker];
- unsigned length = copyFromSharedBuffer(header, webpExtraMarker, data, webpExtraMarkeroffset);
- if (length >= webpExtraMarker) {
- if (!memcmp(header, "WEBPVP", webpExtraMarker))
- return new WEBPImageDecoder(alphaOption, gammaAndColorProfileOption);
- }
- }
+ if (matchesWebPSignature(contents))
+ return new WEBPImageDecoder(alphaOption, gammaAndColorProfileOption);
#endif
- // BMP
- if (strncmp(contents, "BM", 2) == 0)
+ if (matchesBMPSignature(contents))
return new BMPImageDecoder(alphaOption, gammaAndColorProfileOption);
- // ICOs always begin with a 2-byte 0 followed by a 2-byte 1.
- // CURs begin with 2-byte 0 followed by 2-byte 2.
- if (!memcmp(contents, "\x00\x00\x01\x00", 4) || !memcmp(contents, "\x00\x00\x02\x00", 4))
+ if (matchesICOSignature(contents) || matchesCURSignature(contents))
return new ICOImageDecoder(alphaOption, gammaAndColorProfileOption);
- // Give up. We don't know what the heck this is.
return 0;
}
#endif // !OS(ANDROID)
@@ -123,7 +150,7 @@ ImageFrame& ImageFrame::operator=(const ImageFrame& other)
return *this;
copyReferenceToBitmapData(other);
- setRect(other.rect());
+ setOriginalFrameRect(other.originalFrameRect());
setStatus(other.status());
setDuration(other.duration());
setDisposalMethod(other.disposalMethod());
@@ -131,7 +158,7 @@ ImageFrame& ImageFrame::operator=(const ImageFrame& other)
return *this;
}
-void ImageFrame::clear()
+void ImageFrame::clearPixelData()
{
m_backingStore.clear();
m_bytes = 0;
@@ -142,7 +169,7 @@ void ImageFrame::clear()
// later.
}
-void ImageFrame::zeroFill()
+void ImageFrame::zeroFillPixelData()
{
memset(m_bytes, 0, m_size.width() * m_size.height() * sizeof(PixelData));
m_hasAlpha = true;
@@ -176,8 +203,7 @@ bool ImageFrame::setSize(int newWidth, int newHeight)
m_bytes = m_backingStore.data();
m_size = IntSize(newWidth, newHeight);
- // Zero the image.
- zeroFill();
+ zeroFillPixelData();
return true;
}