Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Unified Diff: Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp

Issue 10860057: Merge 125869 - Source/WebCore: libwebp-0.2.0: handle alpha channel if present (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1229/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp
===================================================================
--- Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp (revision 126107)
+++ Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp (working copy)
@@ -37,12 +37,18 @@
#include "TraceEvent.h"
#endif
+// backward emulation for earlier versions than 0.1.99
+#if (WEBP_DECODER_ABI_VERSION < 0x0163)
+#define MODE_rgbA MODE_RGBA
+#define MODE_bgrA MODE_BGRA
+#endif
+
#if CPU(BIG_ENDIAN) || CPU(MIDDLE_ENDIAN)
-inline WEBP_CSP_MODE outputMode() { return MODE_RGBA; }
+inline WEBP_CSP_MODE outputMode(bool hasAlpha) { return hasAlpha ? MODE_rgbA : MODE_RGBA; }
#elif USE(SKIA) && SK_B32_SHIFT
-inline WEBP_CSP_MODE outputMode() { return MODE_RGBA; }
+inline WEBP_CSP_MODE outputMode(bool hasAlpha) { return hasAlpha ? MODE_rgbA : MODE_RGBA; }
#else // LITTLE_ENDIAN, output BGRA pixels.
-inline WEBP_CSP_MODE outputMode() { return MODE_BGRA; }
+inline WEBP_CSP_MODE outputMode(bool hasAlpha) { return hasAlpha ? MODE_bgrA : MODE_BGRA; }
#endif
namespace WebCore {
@@ -51,6 +57,7 @@
ImageSource::GammaAndColorProfileOption gammaAndColorProfileOption)
: ImageDecoder(alphaOption, gammaAndColorProfileOption)
, m_decoder(0)
+ , m_hasAlpha(false)
{
}
@@ -101,8 +108,19 @@
if (dataSize < imageHeaderSize)
return false;
int width, height;
+#if (WEBP_DECODER_ABI_VERSION >= 0x0163)
+ WebPBitstreamFeatures features;
+ if (WebPGetFeatures(dataBytes, dataSize, &features) != VP8_STATUS_OK)
+ return setFailed();
+ width = features.width;
+ height = features.height;
+ m_hasAlpha = features.has_alpha;
+#else
+ // Earlier version won't be able to display WebP files with alpha.
if (!WebPGetInfo(dataBytes, dataSize, &width, &height))
return setFailed();
+ m_hasAlpha = false;
+#endif
if (!setSize(width, height))
return setFailed();
}
@@ -119,7 +137,7 @@
if (!buffer.setSize(size().width(), size().height()))
return setFailed();
buffer.setStatus(ImageFrame::FramePartial);
- buffer.setHasAlpha(false); // FIXME: webp does not support alpha yet.
+ buffer.setHasAlpha(m_hasAlpha);
buffer.setOriginalFrameRect(IntRect(IntPoint(), size()));
}
@@ -127,7 +145,7 @@
int rowStride = size().width() * sizeof(ImageFrame::PixelData);
uint8_t* output = reinterpret_cast<uint8_t*>(buffer.getAddr(0, 0));
int outputSize = size().height() * rowStride;
- m_decoder = WebPINewRGB(outputMode(), output, outputSize, rowStride);
+ m_decoder = WebPINewRGB(outputMode(m_hasAlpha), output, outputSize, rowStride);
if (!m_decoder)
return setFailed();
}
« no previous file with comments | « Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698