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

Unified Diff: Source/platform/graphics/ImageBuffer.cpp

Issue 1302423004: Support lossy and lossless <canvas>.toDataURL for webp (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Patch for landing. Created 5 years, 3 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/platform/graphics/ImageBuffer.h ('k') | Source/platform/image-encoders/skia/WEBPImageEncoder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « Source/platform/graphics/ImageBuffer.h ('k') | Source/platform/image-encoders/skia/WEBPImageEncoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698