Bug 1201796 (Part 3) - Enable downscale-during-decode for imgITools::EncodeScaledImage(). r=tn

This commit is contained in:
Seth Fowler 2015-09-18 10:54:38 -07:00
parent 070157c0f4
commit 53d201df26
7 changed files with 28 additions and 20 deletions

View File

@ -142,7 +142,13 @@ ImageFactory::CreateAnonymousImage(const nsCString& aMimeType)
newTracker->SetImage(newImage);
newImage->SetProgressTracker(newTracker);
rv = newImage->Init(aMimeType.get(), Image::INIT_FLAG_SYNC_LOAD);
uint32_t imageFlags = Image::INIT_FLAG_SYNC_LOAD;
if (gfxPrefs::ImageDownscaleDuringDecodeEnabled() &&
ShouldDownscaleDuringDecode(aMimeType)) {
imageFlags |= Image::INIT_FLAG_DOWNSCALE_DURING_DECODE;
}
rv = newImage->Init(aMimeType.get(), imageFlags);
if (NS_FAILED(rv)) {
return BadImage("RasterImage::Init failed", newImage);
}

View File

@ -198,26 +198,27 @@ imgTools::EncodeScaledImage(imgIContainer* aContainer,
return EncodeImage(aContainer, aMimeType, aOutputOptions, aStream);
}
// Use frame 0 from the image container.
RefPtr<SourceSurface> frame =
aContainer->GetFrame(imgIContainer::FRAME_FIRST,
imgIContainer::FLAG_SYNC_DECODE);
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
int32_t frameWidth = frame->GetSize().width;
int32_t frameHeight = frame->GetSize().height;
// Retrieve the image's size.
int32_t imageWidth = 0;
int32_t imageHeight = 0;
aContainer->GetWidth(&imageWidth);
aContainer->GetHeight(&imageHeight);
// If the given width or height is zero we'll replace it with the image's
// original dimensions.
if (aScaledWidth == 0) {
aScaledWidth = frameWidth;
} else if (aScaledHeight == 0) {
aScaledHeight = frameHeight;
}
IntSize scaledSize(aScaledWidth == 0 ? imageWidth : aScaledWidth,
aScaledHeight == 0 ? imageHeight : aScaledHeight);
// Use frame 0 from the image container.
RefPtr<SourceSurface> frame =
aContainer->GetFrameAtSize(scaledSize,
imgIContainer::FRAME_FIRST,
imgIContainer::FLAG_HIGH_QUALITY_SCALING |
imgIContainer::FLAG_SYNC_DECODE);
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
RefPtr<DataSourceSurface> dataSurface =
Factory::CreateDataSourceSurface(IntSize(aScaledWidth, aScaledHeight),
SurfaceFormat::B8G8R8A8);
Factory::CreateDataSourceSurface(scaledSize, SurfaceFormat::B8G8R8A8);
if (NS_WARN_IF(!dataSurface)) {
return NS_ERROR_FAILURE;
}
@ -238,9 +239,10 @@ imgTools::EncodeScaledImage(imgIContainer* aContainer,
return NS_ERROR_OUT_OF_MEMORY;
}
IntSize frameSize = frame->GetSize();
dt->DrawSurface(frame,
Rect(0, 0, aScaledWidth, aScaledHeight),
Rect(0, 0, frameWidth, frameHeight),
Rect(0, 0, scaledSize.width, scaledSize.height),
Rect(0, 0, frameSize.width, frameSize.height),
DrawSurfaceOptions(),
DrawOptions(1.0f, CompositionOp::OP_SOURCE));

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 948 B

After

Width:  |  Height:  |  Size: 950 B

View File

@ -169,7 +169,7 @@ var encodedBytes = streamToArray(istream);
var refName = "image1png16x16.jpg";
var refFile = do_get_file(refName);
istream = getFileInputStream(refFile);
do_check_eq(istream.available(), 1078);
do_check_eq(istream.available(), 1051);
var referenceBytes = streamToArray(istream);
// compare the encoder's output to the reference file.
@ -228,7 +228,7 @@ encodedBytes = streamToArray(istream);
refName = isWindows ? "image2jpg16x16-win.png" : "image2jpg16x16.png";
refFile = do_get_file(refName);
istream = getFileInputStream(refFile);
do_check_eq(istream.available(), 948);
do_check_eq(istream.available(), 950);
referenceBytes = streamToArray(istream);
// compare the encoder's output to the reference file.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 948 B

After

Width:  |  Height:  |  Size: 950 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 868 B

After

Width:  |  Height:  |  Size: 979 B