Bug 922942 - Do image scaling in imgTools using azure. r=seth
@ -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);
|
||||
}
|
||||
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
@ -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.
|
||||
|
Before Width: | Height: | Size: 245 B After Width: | Height: | Size: 221 B |
Before Width: | Height: | Size: 131 B After Width: | Height: | Size: 122 B |
Before Width: | Height: | Size: 124 B After Width: | Height: | Size: 116 B |