Bug 704558 - Added encoder options in encodeImage and encodeScaledImage. r=bbondy

This commit is contained in:
Tim Abraldes 2011-12-16 19:43:10 -05:00
Родитель 0173a656f9
Коммит ea7e685f84
8 изменённых файлов: 113 добавлений и 8 удалений

Просмотреть файл

@ -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);
};

Просмотреть файл

@ -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);

Двоичные данные
image/test/unit/image4gif16x16bmp24bpp.ico Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 894 B

Двоичные данные
image/test/unit/image4gif16x16bmp32bpp.ico Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.1 KiB

Двоичные данные
image/test/unit/image4gif32x32bmp24bpp.ico Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.2 KiB

Двоичные данные
image/test/unit/image4gif32x32bmp32bpp.ico Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 4.2 KiB

Просмотреть файл

@ -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;

Просмотреть файл

@ -637,6 +637,7 @@ NS_IMETHODIMP AsyncWriteIconToDisk::Run()
rv = imgtool->EncodeScaledImage(container, mMimeTypeOfInputData,
systemIconWidth,
systemIconHeight,
EmptyString(),
getter_AddRefs(iconStream));
NS_ENSURE_SUCCESS(rv, rv);