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

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

Issue 290893002: [wip] Add canvas.toDataURL("image/png") compression control Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update after https://src.chromium.org/viewvc/blink?view=rev&revision=175387 Created 6 years, 6 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
Index: Source/platform/graphics/ImageBuffer.cpp
diff --git a/Source/platform/graphics/ImageBuffer.cpp b/Source/platform/graphics/ImageBuffer.cpp
index f37ac2bb71c84c90e8fe4aedfefdaf731fbd53b4..fbba10befe101257b532e3a883d45f7acc67d72f 100644
--- a/Source/platform/graphics/ImageBuffer.cpp
+++ b/Source/platform/graphics/ImageBuffer.cpp
@@ -396,7 +396,10 @@ static bool encodeImage(T& source, const String& mimeType, const double* quality
if (!WEBPImageEncoder::encode(source, compressionQuality, encodedImage))
return false;
} else {
- if (!PNGImageEncoder::encode(source, encodedImage))
+ int compressionQuality = PNGImageEncoder::DefaultCompressionQuality;
+ if (quality && *quality >= 0.0 && *quality <= 1.0)
+ compressionQuality = static_cast<int>(*quality * 100 + 0.5);
+ if (!PNGImageEncoder::encode(source, compressionQuality, encodedImage))
return false;
ASSERT(mimeType == "image/png");
}
@@ -411,6 +414,7 @@ String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con
Vector<char> encodedImage;
if (!isSurfaceValid() || !encodeImage(m_surface->bitmap(), mimeType, quality, &encodedImage))
return "data:,";
+
Vector<char> base64Data;
base64Encode(encodedImage, base64Data);
« no previous file with comments | « Source/platform/graphics/GraphicsContextRecorder.cpp ('k') | Source/platform/image-encoders/skia/PNGImageEncoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698