diff --git a/image/public/imgITools.idl b/image/public/imgITools.idl index 1447c290081d..d10d760c1f14 100644 --- a/image/public/imgITools.idl +++ b/image/public/imgITools.idl @@ -41,7 +41,7 @@ interface nsIInputStream; interface imgIContainer; -[scriptable, uuid(c395d8f1-c616-4a1b-adfd-747b4b1b2cbe)] +[scriptable, uuid(1f19a2ce-cf5c-4a6b-8ba7-63785b45053f)] interface imgITools : nsISupports { /** @@ -74,9 +74,12 @@ interface imgITools : nsISupports * An image container. * @param aMimeType * Type of encoded image desired (eg "image/png"). + * @param outputOptions + * Encoder-specific output options. */ nsIInputStream encodeImage(in imgIContainer aContainer, - in ACString aMimeType); + in ACString aMimeType, + [optional] in AString outputOptions); /** * encodeScaledImage @@ -90,9 +93,12 @@ interface imgITools : nsISupports * Type of encoded image desired (eg "image/png"). * @param aWidth, aHeight * The size (in pixels) desired for the resulting image. + * @param outputOptions + * Encoder-specific output options. */ nsIInputStream encodeScaledImage(in imgIContainer aContainer, in ACString aMimeType, in long aWidth, - in long aHeight); + in long aHeight, + [optional] in AString outputOptions); }; diff --git a/image/src/imgTools.cpp b/image/src/imgTools.cpp index bcdc0937b6ce..47a89ddf153e 100644 --- a/image/src/imgTools.cpp +++ b/image/src/imgTools.cpp @@ -131,16 +131,22 @@ NS_IMETHODIMP imgTools::DecodeImageData(nsIInputStream* aInStr, NS_IMETHODIMP imgTools::EncodeImage(imgIContainer *aContainer, const nsACString& aMimeType, + const nsAString& aOutputOptions, nsIInputStream **aStream) { - return EncodeScaledImage(aContainer, aMimeType, 0, 0, aStream); + return EncodeScaledImage(aContainer, + aMimeType, + 0, + 0, + aOutputOptions, + aStream); } - NS_IMETHODIMP imgTools::EncodeScaledImage(imgIContainer *aContainer, const nsACString& aMimeType, PRInt32 aScaledWidth, PRInt32 aScaledHeight, + const nsAString& aOutputOptions, nsIInputStream **aStream) { nsresult rv; @@ -215,9 +221,13 @@ NS_IMETHODIMP imgTools::EncodeScaledImage(imgIContainer *aContainer, } // Encode the bitmap - rv = encoder->InitFromData(bitmapData, bitmapDataLength, - aScaledWidth, aScaledHeight, strideSize, - imgIEncoder::INPUT_FORMAT_HOSTARGB, EmptyString()); + rv = encoder->InitFromData(bitmapData, + bitmapDataLength, + aScaledWidth, + aScaledHeight, + strideSize, + imgIEncoder::INPUT_FORMAT_HOSTARGB, + aOutputOptions); NS_ENSURE_SUCCESS(rv, rv); diff --git a/image/test/unit/image4gif16x16bmp24bpp.ico b/image/test/unit/image4gif16x16bmp24bpp.ico new file mode 100644 index 000000000000..890c81c27233 Binary files /dev/null and b/image/test/unit/image4gif16x16bmp24bpp.ico differ diff --git a/image/test/unit/image4gif16x16bmp32bpp.ico b/image/test/unit/image4gif16x16bmp32bpp.ico new file mode 100644 index 000000000000..f8a9eb8adc29 Binary files /dev/null and b/image/test/unit/image4gif16x16bmp32bpp.ico differ diff --git a/image/test/unit/image4gif32x32bmp24bpp.ico b/image/test/unit/image4gif32x32bmp24bpp.ico new file mode 100644 index 000000000000..28092818dc28 Binary files /dev/null and b/image/test/unit/image4gif32x32bmp24bpp.ico differ diff --git a/image/test/unit/image4gif32x32bmp32bpp.ico b/image/test/unit/image4gif32x32bmp32bpp.ico new file mode 100644 index 000000000000..0e2d28c82a4b Binary files /dev/null and b/image/test/unit/image4gif32x32bmp32bpp.ico differ diff --git a/image/test/unit/test_imgtools.js b/image/test/unit/test_imgtools.js index f66682b9811e..f827ea6c9828 100644 --- a/image/test/unit/test_imgtools.js +++ b/image/test/unit/test_imgtools.js @@ -342,6 +342,94 @@ container = outParam.value; do_check_eq(container.width, 32); do_check_eq(container.height, 32); +/* ========== 11 ========== */ +testnum++; +testdesc = "test encoding an unscaled ICO with format options " + + "(format=bmp;bpp=32)"; + +// we'll reuse the container from the previous test +istream = imgTools.encodeImage(container, + "image/vnd.microsoft.icon", + "format=bmp;bpp=32"); +encodedBytes = streamToArray(istream); + +// Get bytes for exected result +refName = "image4gif32x32bmp32bpp.ico"; +refFile = do_get_file(refName); +istream = getFileInputStream(refFile); +do_check_eq(istream.available(), 4286); +referenceBytes = streamToArray(istream); + +// compare the encoder's output to the reference file. +compareArrays(encodedBytes, referenceBytes); + +/* ========== 12 ========== */ +testnum++; +testdesc = "test encoding a scaled ICO with format options " + + "(format=bmp;bpp=32)"; + +// we'll reuse the container from the previous test +istream = imgTools.encodeScaledImage(container, + "image/vnd.microsoft.icon", + 16, + 16, + "format=bmp;bpp=32"); +encodedBytes = streamToArray(istream); + +// Get bytes for exected result +refName = "image4gif16x16bmp32bpp.ico"; +refFile = do_get_file(refName); +istream = getFileInputStream(refFile); +do_check_eq(istream.available(), 1150); +referenceBytes = streamToArray(istream); + +// compare the encoder's output to the reference file. +compareArrays(encodedBytes, referenceBytes); + +/* ========== 13 ========== */ +testnum++; +testdesc = "test encoding an unscaled ICO with format options " + + "(format=bmp;bpp=24)"; + +// we'll reuse the container from the previous test +istream = imgTools.encodeImage(container, + "image/vnd.microsoft.icon", + "format=bmp;bpp=24"); +encodedBytes = streamToArray(istream); + +// Get bytes for exected result +refName = "image4gif32x32bmp24bpp.ico"; +refFile = do_get_file(refName); +istream = getFileInputStream(refFile); +do_check_eq(istream.available(), 3262); +referenceBytes = streamToArray(istream); + +// compare the encoder's output to the reference file. +compareArrays(encodedBytes, referenceBytes); + +/* ========== 14 ========== */ +testnum++; +testdesc = "test encoding a scaled ICO with format options " + + "(format=bmp;bpp=24)"; + +// we'll reuse the container from the previous test +istream = imgTools.encodeScaledImage(container, + "image/vnd.microsoft.icon", + 16, + 16, + "format=bmp;bpp=24"); +encodedBytes = streamToArray(istream); + +// Get bytes for exected result +refName = "image4gif16x16bmp24bpp.ico"; +refFile = do_get_file(refName); +istream = getFileInputStream(refFile); +do_check_eq(istream.available(), 894); +referenceBytes = streamToArray(istream); + +// compare the encoder's output to the reference file. +compareArrays(encodedBytes, referenceBytes); + /* ========== bug 363986 ========== */ testnum = 363986; diff --git a/widget/src/windows/JumpListBuilder.cpp b/widget/src/windows/JumpListBuilder.cpp index 0572fff20232..b49f380dcc24 100644 --- a/widget/src/windows/JumpListBuilder.cpp +++ b/widget/src/windows/JumpListBuilder.cpp @@ -637,6 +637,7 @@ NS_IMETHODIMP AsyncWriteIconToDisk::Run() rv = imgtool->EncodeScaledImage(container, mMimeTypeOfInputData, systemIconWidth, systemIconHeight, + EmptyString(), getter_AddRefs(iconStream)); NS_ENSURE_SUCCESS(rv, rv);