summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/image-decoders
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/image-decoders')
-rw-r--r--WebCore/platform/image-decoders/ImageDecoder.cpp18
-rw-r--r--WebCore/platform/image-decoders/ImageDecoder.h8
-rw-r--r--WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp4
-rw-r--r--WebCore/platform/image-decoders/bmp/BMPImageDecoder.h2
-rw-r--r--WebCore/platform/image-decoders/cg/ImageDecoderCG.cpp9
-rw-r--r--WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp4
-rw-r--r--WebCore/platform/image-decoders/gif/GIFImageDecoder.h2
-rw-r--r--WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp6
-rw-r--r--WebCore/platform/image-decoders/ico/ICOImageDecoder.h2
-rw-r--r--WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp4
-rw-r--r--WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h2
-rw-r--r--WebCore/platform/image-decoders/png/PNGImageDecoder.cpp15
-rw-r--r--WebCore/platform/image-decoders/png/PNGImageDecoder.h2
-rw-r--r--WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp4
-rw-r--r--WebCore/platform/image-decoders/webp/WEBPImageDecoder.h2
15 files changed, 47 insertions, 37 deletions
diff --git a/WebCore/platform/image-decoders/ImageDecoder.cpp b/WebCore/platform/image-decoders/ImageDecoder.cpp
index 43ff33b..a9d5131 100644
--- a/WebCore/platform/image-decoders/ImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/ImageDecoder.cpp
@@ -53,11 +53,15 @@ 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.
ImageDecoder* ImageDecoder::create(const SharedBuffer& data, bool premultiplyAlpha)
+=======
+ImageDecoder* ImageDecoder::create(const SharedBuffer& data, bool premultiplyAlpha, bool ignoreGammaAndColorProfile)
+>>>>>>> webkit.org at r72274
{
// We need at least 4 bytes to figure out what kind of image we're dealing
// with.
@@ -69,15 +73,15 @@ ImageDecoder* ImageDecoder::create(const SharedBuffer& data, bool premultiplyAlp
// GIFs begin with GIF8(7 or 9).
if (strncmp(contents, "GIF8", 4) == 0)
- return new GIFImageDecoder(premultiplyAlpha);
+ return new GIFImageDecoder(premultiplyAlpha, ignoreGammaAndColorProfile);
// Test for PNG.
if (!memcmp(contents, "\x89\x50\x4E\x47", 4))
- return new PNGImageDecoder(premultiplyAlpha);
+ return new PNGImageDecoder(premultiplyAlpha, ignoreGammaAndColorProfile);
// JPEG
if (!memcmp(contents, "\xFF\xD8\xFF", 3))
- return new JPEGImageDecoder(premultiplyAlpha);
+ return new JPEGImageDecoder(premultiplyAlpha, ignoreGammaAndColorProfile);
#if USE(WEBP)
if (!memcmp(contents, "RIFF", 4)) {
@@ -87,19 +91,19 @@ ImageDecoder* ImageDecoder::create(const SharedBuffer& data, bool premultiplyAlp
unsigned length = copyFromSharedBuffer(header, webpExtraMarker, data, webpExtraMarkeroffset);
if (length >= webpExtraMarker) {
if (!memcmp(header, "WEBPVP", webpExtraMarker))
- return new WEBPImageDecoder(premultiplyAlpha);
+ return new WEBPImageDecoder(premultiplyAlpha, ignoreGammaAndColorProfile);
}
}
#endif
// BMP
if (strncmp(contents, "BM", 2) == 0)
- return new BMPImageDecoder(premultiplyAlpha);
+ return new BMPImageDecoder(premultiplyAlpha, ignoreGammaAndColorProfile);
// 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))
- return new ICOImageDecoder(premultiplyAlpha);
+ return new ICOImageDecoder(premultiplyAlpha, ignoreGammaAndColorProfile);
// Give up. We don't know what the heck this is.
return 0;
@@ -148,7 +152,7 @@ void RGBA32Buffer::zeroFill()
m_hasAlpha = true;
}
-#if !PLATFORM(CF)
+#if !PLATFORM(CG)
void RGBA32Buffer::copyReferenceToBitmapData(const RGBA32Buffer& other)
{
diff --git a/WebCore/platform/image-decoders/ImageDecoder.h b/WebCore/platform/image-decoders/ImageDecoder.h
index 81d6dbb..4b593f9 100644
--- a/WebCore/platform/image-decoders/ImageDecoder.h
+++ b/WebCore/platform/image-decoders/ImageDecoder.h
@@ -151,7 +151,7 @@ namespace WebCore {
#endif
private:
-#if PLATFORM(CF)
+#if PLATFORM(CG)
typedef RetainPtr<CFMutableDataRef> NativeBackingStore;
#else
typedef Vector<PixelData> NativeBackingStore;
@@ -233,9 +233,10 @@ namespace WebCore {
// m_maxNumPixels. (Not supported by all image decoders yet)
class ImageDecoder : public Noncopyable {
public:
- ImageDecoder(bool premultiplyAlpha)
+ ImageDecoder(bool premultiplyAlpha, bool ignoreGammaAndColorProfile)
: m_scaled(false)
, m_premultiplyAlpha(premultiplyAlpha)
+ , m_ignoreGammaAndColorProfile(ignoreGammaAndColorProfile)
, m_sizeAvailable(false)
, m_maxNumPixels(-1)
, m_isAllDataReceived(false)
@@ -248,7 +249,7 @@ namespace WebCore {
// Factory function to create an ImageDecoder. Ports that subclass
// ImageDecoder can provide their own implementation of this to avoid
// needing to write a dedicated setData() implementation.
- static ImageDecoder* create(const SharedBuffer& data, bool premultiplyAlpha);
+ static ImageDecoder* create(const SharedBuffer& data, bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
// The the filename extension usually associated with an undecoded image
// of this type.
@@ -364,6 +365,7 @@ namespace WebCore {
Vector<int> m_scaledColumns;
Vector<int> m_scaledRows;
bool m_premultiplyAlpha;
+ bool m_ignoreGammaAndColorProfile;
private:
// Some code paths compute the size of the image as "width * height * 4"
diff --git a/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp b/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp
index 1c117a8..219a1e2 100644
--- a/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp
@@ -40,8 +40,8 @@ namespace WebCore {
// don't pack).
static const size_t sizeOfFileHeader = 14;
-BMPImageDecoder::BMPImageDecoder(bool premultiplyAlpha)
- : ImageDecoder(premultiplyAlpha)
+BMPImageDecoder::BMPImageDecoder(bool premultiplyAlpha, bool ignoreGammaAndColorProfile)
+ : ImageDecoder(premultiplyAlpha, ignoreGammaAndColorProfile)
, m_decodedOffset(0)
{
}
diff --git a/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h b/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h
index 3996bf9..695fab4 100644
--- a/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h
+++ b/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h
@@ -39,7 +39,7 @@ namespace WebCore {
// This class decodes the BMP image format.
class BMPImageDecoder : public ImageDecoder {
public:
- BMPImageDecoder(bool premultiplyAlpha);
+ BMPImageDecoder(bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
// ImageDecoder
virtual String filenameExtension() const { return "bmp"; }
diff --git a/WebCore/platform/image-decoders/cg/ImageDecoderCG.cpp b/WebCore/platform/image-decoders/cg/ImageDecoderCG.cpp
index 0f4dbc8..32e94e0 100644
--- a/WebCore/platform/image-decoders/cg/ImageDecoderCG.cpp
+++ b/WebCore/platform/image-decoders/cg/ImageDecoderCG.cpp
@@ -60,8 +60,13 @@ bool RGBA32Buffer::copyBitmapData(const RGBA32Buffer& other)
bool RGBA32Buffer::setSize(int newWidth, int newHeight)
{
- m_backingStore.adoptCF(CFDataCreateMutable(kCFAllocatorDefault, 0));
- CFDataSetLength(m_backingStore.get(), newWidth * newHeight * sizeof(PixelData));
+ ASSERT(!m_backingStore);
+ size_t backingStoreSize = newWidth * newHeight * sizeof(PixelData);
+ CFMutableDataRef backingStoreRef = CFDataCreateMutable(kCFAllocatorDefault, backingStoreSize);
+ if (!backingStoreRef)
+ return false;
+ m_backingStore.adoptCF(backingStoreRef);
+ CFDataSetLength(backingStoreRef, backingStoreSize);
m_bytes = reinterpret_cast<PixelData*>(CFDataGetMutableBytePtr(m_backingStore.get()));
m_size = IntSize(newWidth, newHeight);
diff --git a/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp b/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp
index 18cd903..dfdf35e 100644
--- a/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp
@@ -29,8 +29,8 @@
namespace WebCore {
-GIFImageDecoder::GIFImageDecoder(bool premultiplyAlpha)
- : ImageDecoder(premultiplyAlpha)
+GIFImageDecoder::GIFImageDecoder(bool premultiplyAlpha, bool ignoreGammaAndColorProfile)
+ : ImageDecoder(premultiplyAlpha, ignoreGammaAndColorProfile)
, m_alreadyScannedThisDataForFrameCount(true)
, m_repetitionCount(cAnimationLoopOnce)
, m_readOffset(0)
diff --git a/WebCore/platform/image-decoders/gif/GIFImageDecoder.h b/WebCore/platform/image-decoders/gif/GIFImageDecoder.h
index b011e1e..5b4ca10 100644
--- a/WebCore/platform/image-decoders/gif/GIFImageDecoder.h
+++ b/WebCore/platform/image-decoders/gif/GIFImageDecoder.h
@@ -36,7 +36,7 @@ namespace WebCore {
// This class decodes the GIF image format.
class GIFImageDecoder : public ImageDecoder {
public:
- GIFImageDecoder(bool premultiplyAlpha);
+ GIFImageDecoder(bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
virtual ~GIFImageDecoder();
enum GIFQuery { GIFFullQuery, GIFSizeQuery, GIFFrameCountQuery };
diff --git a/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp b/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp
index 453efd2..b07cf92 100644
--- a/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp
@@ -44,8 +44,8 @@ namespace WebCore {
static const size_t sizeOfDirectory = 6;
static const size_t sizeOfDirEntry = 16;
-ICOImageDecoder::ICOImageDecoder(bool premultiplyAlpha)
- : ImageDecoder(premultiplyAlpha)
+ICOImageDecoder::ICOImageDecoder(bool premultiplyAlpha, bool ignoreGammaAndColorProfile)
+ : ImageDecoder(premultiplyAlpha, ignoreGammaAndColorProfile)
, m_decodedOffset(0)
{
}
@@ -201,7 +201,7 @@ bool ICOImageDecoder::decodeAtIndex(size_t index)
}
if (!m_pngDecoders[index]) {
- m_pngDecoders[index].set(new PNGImageDecoder(m_premultiplyAlpha));
+ m_pngDecoders[index].set(new PNGImageDecoder(m_premultiplyAlpha, m_ignoreGammaAndColorProfile));
setDataForPNGDecoderAtIndex(index);
}
// Fail if the size the PNGImageDecoder calculated does not match the size
diff --git a/WebCore/platform/image-decoders/ico/ICOImageDecoder.h b/WebCore/platform/image-decoders/ico/ICOImageDecoder.h
index e2ee9e3..dc631f4 100644
--- a/WebCore/platform/image-decoders/ico/ICOImageDecoder.h
+++ b/WebCore/platform/image-decoders/ico/ICOImageDecoder.h
@@ -40,7 +40,7 @@ namespace WebCore {
// This class decodes the ICO and CUR image formats.
class ICOImageDecoder : public ImageDecoder {
public:
- ICOImageDecoder(bool premultiplyAlpha);
+ ICOImageDecoder(bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
virtual ~ICOImageDecoder();
// ImageDecoder
diff --git a/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp b/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
index da35739..d1de2ca 100644
--- a/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
@@ -392,8 +392,8 @@ void term_source(j_decompress_ptr jd)
src->decoder->decoder()->jpegComplete();
}
-JPEGImageDecoder::JPEGImageDecoder(bool premultiplyAlpha)
- : ImageDecoder(premultiplyAlpha)
+JPEGImageDecoder::JPEGImageDecoder(bool premultiplyAlpha, bool ignoreGammaAndColorProfile)
+ : ImageDecoder(premultiplyAlpha, ignoreGammaAndColorProfile)
{
}
diff --git a/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h b/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h
index e942b01..a60b387 100644
--- a/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h
+++ b/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h
@@ -37,7 +37,7 @@ namespace WebCore {
// This class decodes the JPEG image format.
class JPEGImageDecoder : public ImageDecoder {
public:
- JPEGImageDecoder(bool premultiplyAlpha);
+ JPEGImageDecoder(bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
virtual ~JPEGImageDecoder();
// ImageDecoder
diff --git a/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp b/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp
index e4f7a0c..8b81896 100644
--- a/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp
@@ -169,8 +169,8 @@ private:
unsigned m_currentBufferSize;
};
-PNGImageDecoder::PNGImageDecoder(bool premultiplyAlpha)
- : ImageDecoder(premultiplyAlpha)
+PNGImageDecoder::PNGImageDecoder(bool premultiplyAlpha, bool ignoreGammaAndColorProfile)
+ : ImageDecoder(premultiplyAlpha, ignoreGammaAndColorProfile)
, m_doNothingOnFailure(false)
{
}
@@ -296,7 +296,7 @@ void PNGImageDecoder::headerAvailable()
// Deal with gamma and keep it under our control.
double gamma;
- if (png_get_gAMA(png, info, &gamma)) {
+ if (!m_ignoreGammaAndColorProfile && png_get_gAMA(png, info, &gamma)) {
if ((gamma <= 0.0) || (gamma > cMaxGamma)) {
gamma = cInverseGamma;
png_set_gAMA(png, info, gamma);
@@ -395,16 +395,15 @@ void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex,
// Check that the row is within the image bounds. LibPNG may supply an extra row.
if (destY < 0 || destY >= scaledSize().height())
return;
- bool sawAlpha = buffer.hasAlpha();
+ bool nonTrivialAlpha = false;
for (int x = 0; x < width; ++x) {
png_bytep pixel = row + (m_scaled ? m_scaledColumns[x] : x) * colorChannels;
unsigned alpha = hasAlpha ? pixel[3] : 255;
buffer.setRGBA(x, destY, pixel[0], pixel[1], pixel[2], alpha);
- if (!sawAlpha && alpha < 255) {
- sawAlpha = true;
- buffer.setHasAlpha(true);
- }
+ nonTrivialAlpha |= alpha < 255;
}
+ if (nonTrivialAlpha && !buffer.hasAlpha())
+ buffer.setHasAlpha(nonTrivialAlpha);
}
void PNGImageDecoder::pngComplete()
diff --git a/WebCore/platform/image-decoders/png/PNGImageDecoder.h b/WebCore/platform/image-decoders/png/PNGImageDecoder.h
index 763b88f..68b0c1f 100644
--- a/WebCore/platform/image-decoders/png/PNGImageDecoder.h
+++ b/WebCore/platform/image-decoders/png/PNGImageDecoder.h
@@ -36,7 +36,7 @@ namespace WebCore {
// This class decodes the PNG image format.
class PNGImageDecoder : public ImageDecoder {
public:
- PNGImageDecoder(bool premultiplyAlpha);
+ PNGImageDecoder(bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
virtual ~PNGImageDecoder();
// ImageDecoder
diff --git a/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp b/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp
index 2275fc7..0fc0bd5 100644
--- a/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp
+++ b/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp
@@ -35,8 +35,8 @@
namespace WebCore {
-WEBPImageDecoder::WEBPImageDecoder(bool premultiplyAlpha)
- : ImageDecoder(premultiplyAlpha)
+WEBPImageDecoder::WEBPImageDecoder(bool premultiplyAlpha, bool ignoreGammaAndColorProfile)
+ : ImageDecoder(premultiplyAlpha, ignoreGammaAndColorProfile)
{
}
diff --git a/WebCore/platform/image-decoders/webp/WEBPImageDecoder.h b/WebCore/platform/image-decoders/webp/WEBPImageDecoder.h
index 266c0ff..57b1dae 100644
--- a/WebCore/platform/image-decoders/webp/WEBPImageDecoder.h
+++ b/WebCore/platform/image-decoders/webp/WEBPImageDecoder.h
@@ -37,7 +37,7 @@ namespace WebCore {
class WEBPImageDecoder : public ImageDecoder {
public:
- WEBPImageDecoder(bool premultiplyAlpha);
+ WEBPImageDecoder(bool premultiplyAlpha, bool ignoreGammaAndColorProfile);
virtual ~WEBPImageDecoder();
virtual String filenameExtension() const { return "vp8"; }
virtual bool isSizeAvailable();