Index: Source/platform/graphics/ImageBuffer.cpp |
diff --git a/Source/platform/graphics/ImageBuffer.cpp b/Source/platform/graphics/ImageBuffer.cpp |
index d1f305d1b878f65dc20522116998343b0293a356..5643aef1ee66c54971952df80e4bb39c075eaba9 100644 |
--- a/Source/platform/graphics/ImageBuffer.cpp |
+++ b/Source/platform/graphics/ImageBuffer.cpp |
@@ -341,8 +341,10 @@ void ImageBuffer::putByteArray(Multiply multiplied, const unsigned char* source, |
m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); |
} |
-bool ImageDataBuffer::encodeImage(const String& mimeType, const double* quality, Vector<char>* output) const |
+bool ImageDataBuffer::encodeImage(const String& mimeType, const double* quality, Vector<char>* output, String* outputMimeType) const |
{ |
+ ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
+ |
Vector<unsigned char>* encodedImage = reinterpret_cast<Vector<unsigned char>*>(output); |
if (mimeType == "image/jpeg") { |
@@ -351,6 +353,15 @@ bool ImageDataBuffer::encodeImage(const String& mimeType, const double* quality, |
compressionQuality = static_cast<int>(*quality * 100 + 0.5); |
if (!JPEGImageEncoder::encode(*this, compressionQuality, encodedImage)) |
return false; |
+ } else if (mimeType == "image/webp.ll") { |
+ int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; |
+ if (quality && *quality >= 0.0 && *quality <= 1.0) |
+ compressionQuality = static_cast<int>(*quality * 100 + 0.5); |
+ if (!WEBPImageEncoder::encode(*this, compressionQuality, encodedImage, WEBPImageEncoder::Lossless)) |
+ return false; |
+ // webp.ll is an encoder selector: map it to the encoded image mimeType "image/webp". |
+ *outputMimeType = "image/webp"; |
+ return true; |
} else if (mimeType == "image/webp") { |
int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; |
if (quality && *quality >= 0.0 && *quality <= 1.0) |
@@ -363,18 +374,18 @@ bool ImageDataBuffer::encodeImage(const String& mimeType, const double* quality, |
ASSERT(mimeType == "image/png"); |
} |
+ *outputMimeType = mimeType; |
return true; |
} |
String ImageDataBuffer::toDataURL(const String& mimeType, const double* quality) const |
{ |
- ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
- |
Vector<char> encodedImage; |
- if (!encodeImage(mimeType, quality, &encodedImage)) |
+ String encodedMimeType; |
+ if (!encodeImage(mimeType, quality, &encodedImage, &encodedMimeType)) |
return "data:,"; |
- return "data:" + mimeType + ";base64," + base64Encode(encodedImage); |
+ return "data:" + encodedMimeType + ";base64," + base64Encode(encodedImage); |
} |
} // namespace blink |