From 32bad1b68a5dab9fc3f3f74a63ee731faf8a9c68 Mon Sep 17 00:00:00 2001 From: Timothy Nikkel Date: Wed, 19 Jan 2022 09:50:33 +0000 Subject: [PATCH] Bug 1750475. Allow quality parameter to be passed through the webp encoder from canvas data url encoding functions. r=lsalzman The necessary code was already there, just needed to allow it through. Differential Revision: https://phabricator.services.mozilla.com/D136092 --- dom/canvas/CanvasRenderingContextHelper.cpp | 5 +- .../test/test_toDataURL_parameters.html | 71 +++++++++++-------- image/imgIEncoder.idl | 7 ++ 3 files changed, 50 insertions(+), 33 deletions(-) diff --git a/dom/canvas/CanvasRenderingContextHelper.cpp b/dom/canvas/CanvasRenderingContextHelper.cpp index 7c48103501d2..94c48616ba09 100644 --- a/dom/canvas/CanvasRenderingContextHelper.cpp +++ b/dom/canvas/CanvasRenderingContextHelper.cpp @@ -261,8 +261,9 @@ nsresult CanvasRenderingContextHelper::UpdateContext( nsresult CanvasRenderingContextHelper::ParseParams( JSContext* aCx, const nsAString& aType, const JS::Value& aEncoderOptions, nsAString& outParams, bool* const outUsingCustomParseOptions) { - // Quality parameter is only valid for the image/jpeg MIME type - if (aType.EqualsLiteral("image/jpeg")) { + // Quality parameter is only valid for the image/jpeg and image/webp MIME + // types. + if (aType.EqualsLiteral("image/jpeg") || aType.EqualsLiteral("image/webp")) { if (aEncoderOptions.isNumber()) { double quality = aEncoderOptions.toNumber(); // Quality must be between 0.0 and 1.0, inclusive diff --git a/dom/canvas/test/test_toDataURL_parameters.html b/dom/canvas/test/test_toDataURL_parameters.html index 2cc8b0bb7f2c..b288e4d329ea 100644 --- a/dom/canvas/test/test_toDataURL_parameters.html +++ b/dom/canvas/test/test_toDataURL_parameters.html @@ -4,13 +4,13 @@

-This test covers the JPEG quality parameter. If (when) the HTML5 spec changes the +This test covers the JPEG and webp quality parameter. If (when) the HTML5 spec changes the allowed parameters for ToDataURL, new tests should go here.

FAIL (fallback content)

diff --git a/image/imgIEncoder.idl b/image/imgIEncoder.idl index 11bdf4af6fe4..0e38a08bebbc 100644 --- a/image/imgIEncoder.idl +++ b/image/imgIEncoder.idl @@ -64,6 +64,13 @@ interface imgIEncoder : nsIAsyncInputStream // quality=# -- default: "92" // Quality of compression, 0-100 (worst-best). // Quality >= 90 prevents down-sampling of the color channels. + // + // + // WEBP: + // ----- + // + // quality=# -- default: "92" + // Quality of compression, 0-100 (worst-best). // Possible values for input format (note that not all image formats