summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVivin Paliath <vivin.paliath@gmail.com>2015-10-24 17:36:27 -0700
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-12-14 13:54:50 +0000
commit7f70d2b795976c1ddbe9c2866012f91b7e0eafd0 (patch)
treea82294e56c96c186d773705992e8391cf5808aa2
parentc255643360af6b7067ab97687f3724418eee2dd6 (diff)
downloadqtwebkit-7f70d2b795976c1ddbe9c2866012f91b7e0eafd0.tar.gz
Quality in toDataURL only applies to JPEGs now
Prior to the fix, quality would default to 100 irrespective of the image type, if an explicit quality-argument was not provided, or if the quality was outside the valid range. In the case where toDataURL is called without any arguments, the image type defaults to "image/png" and quality eventually defaults to 100. However, quality in the context of a PNG applies to the quality of compression and not the quality of the image. Since PNG is a lossless format, compression only affects the size of the image and not its quality. This resulted in PNG images of a large size, with no compression at all. The same behavior could be observed when toDataURL is called with the image type explicitly set to "image/png", without a quality argument. The expected behavior is only observed if toDataURL is called with the image type set to "image/png" and the quality set to 0, since this provides the highest level of compression. According to section 4.12.4.4 of the HTML5 spec, the quality argument should only apply to images of type "image/jpeg", and if quality is not provided, the user-agent should use a default value. This means that the spec was being violated, since the quality was set to 100 regardless of the image type. The fix was to consider the quality argument (along with the associated sanity-checks) only if the image type is "jpeg"; otherwise quality is set to -1. This change results in PNG images being encoded to properly-sized base64 strings. [ChangeLog][WebKit][Behavior Change] The quality parameter in canvas.toDataURL only applies to JPEG images now, in accordance with section 4.12.4.4 of the HTML5 spec. Change-Id: Ie87a32ec368e70e7736d4d2e684e2528ce37f745 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
-rw-r--r--Source/WebCore/platform/graphics/qt/ImageBufferQt.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/Source/WebCore/platform/graphics/qt/ImageBufferQt.cpp b/Source/WebCore/platform/graphics/qt/ImageBufferQt.cpp
index f8a929c3f..a796284c5 100644
--- a/Source/WebCore/platform/graphics/qt/ImageBufferQt.cpp
+++ b/Source/WebCore/platform/graphics/qt/ImageBufferQt.cpp
@@ -196,9 +196,12 @@ void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, c
static bool encodeImage(const QPixmap& pixmap, const String& format, const double* quality, QByteArray& data)
{
- int compressionQuality = 100;
- if (quality && *quality >= 0.0 && *quality <= 1.0)
- compressionQuality = static_cast<int>(*quality * 100 + 0.5);
+ int compressionQuality = -1;
+ if (format == "jpeg" || format == "webp") {
+ compressionQuality = 100;
+ if (quality && *quality >= 0.0 && *quality <= 1.0)
+ compressionQuality = static_cast<int>(*quality * 100 + 0.5);
+ }
QBuffer buffer(&data);
buffer.open(QBuffer::WriteOnly);