Bug 922942 - Do image scaling in imgTools using azure. r=seth

This commit is contained in:
Matt Woodrow 2013-10-16 14:00:31 +13:00
parent bb090aba45
commit 71902a7d0a
6 changed files with 29 additions and 10 deletions

View File

@ -23,8 +23,11 @@
#include "Image.h"
#include "ScriptedNotificationObserver.h"
#include "imgIScriptedNotificationObserver.h"
#include "gfxPlatform.h"
using namespace mozilla;
using namespace mozilla::image;
using namespace mozilla::gfx;
/* ========== imgITools implementation ========== */
@ -144,17 +147,33 @@ NS_IMETHODIMP imgTools::EncodeScaledImage(imgIContainer *aContainer,
// Create a temporary image surface
nsRefPtr<gfxImageSurface> dest = new gfxImageSurface(gfxIntSize(aScaledWidth, aScaledHeight),
gfxImageFormatARGB32);
gfxContext ctx(dest);
if (gfxPlatform::GetPlatform()->SupportsAzureContent()) {
RefPtr<DrawTarget> dt =
gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(dest, IntSize(aScaledWidth, aScaledHeight));
RefPtr<SourceSurface> source = gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(dt, frame);
// Set scaling
gfxFloat sw = (double) aScaledWidth / frameWidth;
gfxFloat sh = (double) aScaledHeight / frameHeight;
ctx.Scale(sw, sh);
dt->DrawSurface(source,
Rect(0, 0, aScaledWidth, aScaledHeight),
Rect(0, 0, frameWidth, frameHeight),
DrawSurfaceOptions(),
DrawOptions(1.0f, OP_SOURCE));
} else {
gfxContext ctx(dest);
// Set scaling
gfxFloat sw = (double) aScaledWidth / frameWidth;
gfxFloat sh = (double) aScaledHeight / frameHeight;
ctx.Scale(sw, sh);
// Paint a scaled image
ctx.SetOperator(gfxContext::OPERATOR_SOURCE);
nsRefPtr<gfxPattern> pat = new gfxPattern(frame);
pat->SetExtend(gfxPattern::EXTEND_PAD);
ctx.SetPattern(pat);
ctx.Paint();
}
// Paint a scaled image
ctx.SetOperator(gfxContext::OPERATOR_SOURCE);
ctx.SetSource(frame);
ctx.Paint();
return EncodeImageData(dest, aMimeType, aOutputOptions, aStream);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -289,7 +289,7 @@ encodedBytes = streamToArray(istream);
refName = "image3ico32x32.png";
refFile = do_get_file(refName);
istream = getFileInputStream(refFile);
do_check_eq(istream.available(), 2281);
do_check_eq(istream.available(), 2285);
referenceBytes = streamToArray(istream);
// compare the encoder's output to the reference file.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 B

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 B

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 124 B

After

Width:  |  Height:  |  Size: 116 B