From 53d201df26f4354fd0aae0e0884f56b2ae3eeeb2 Mon Sep 17 00:00:00 2001 From: Seth Fowler Date: Fri, 18 Sep 2015 10:54:38 -0700 Subject: [PATCH] Bug 1201796 (Part 3) - Enable downscale-during-decode for imgITools::EncodeScaledImage(). r=tn --- image/ImageFactory.cpp | 8 +++- image/imgTools.cpp | 36 +++++++++--------- image/test/unit/image1png16x16.jpg | Bin 1078 -> 1051 bytes image/test/unit/image2jpg16x16.png | Bin 948 -> 950 bytes image/test/unit/test_imgtools.js | 4 +- .../favicons/expected-favicon-big32.jpg.png | Bin 948 -> 950 bytes .../favicons/expected-favicon-big64.png.png | Bin 868 -> 979 bytes 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/image/ImageFactory.cpp b/image/ImageFactory.cpp index 037bd1996c8..fdf9edba1d3 100644 --- a/image/ImageFactory.cpp +++ b/image/ImageFactory.cpp @@ -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); } diff --git a/image/imgTools.cpp b/image/imgTools.cpp index 6a2688b3a7b..6cbe950fc37 100644 --- a/image/imgTools.cpp +++ b/image/imgTools.cpp @@ -198,26 +198,27 @@ imgTools::EncodeScaledImage(imgIContainer* aContainer, return EncodeImage(aContainer, aMimeType, aOutputOptions, aStream); } - // Use frame 0 from the image container. - RefPtr 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 frame = + aContainer->GetFrameAtSize(scaledSize, + imgIContainer::FRAME_FIRST, + imgIContainer::FLAG_HIGH_QUALITY_SCALING | + imgIContainer::FLAG_SYNC_DECODE); + NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE); RefPtr 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)); diff --git a/image/test/unit/image1png16x16.jpg b/image/test/unit/image1png16x16.jpg index 645bc114c8de46cc0a4f6afb02c190f3aea9c7a3..ea14dbedede96973213586f1754a29c774e72993 100644 GIT binary patch delta 438 zcmV;n0ZIP02%8A7Z~}jCfIkBM7koOg(0oDSKM3hs*N88yZEh~2)m}T8qJ4qi?D4qT zN!+2hIOhZk`3@fAj9xD{{>!0;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d1cc55 100644 --- a/image/test/unit/test_imgtools.js +++ b/image/test/unit/test_imgtools.js @@ -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. diff --git a/toolkit/components/places/tests/favicons/expected-favicon-big32.jpg.png b/toolkit/components/places/tests/favicons/expected-favicon-big32.jpg.png index c3a4aee616675d212178f70a97d8ce73fc1813e2..5722223c26fe0024d8c4d18f198114d5fde708bb 100644 GIT binary patch delta 928 zcmV;R17G~K2et>0B!7KLL_t(IjYZRaESv`b$MHwHgig#dMQ4m*QjIR!YPV+VqBA7K zOr@Px*`}Ql4SJVzA=u(=8Kn!Q6BWH#6R*`(=Z1N?3){uG3Z)#^bJiQtjAc@qx##)r zkK4=d-(T|m?;{|AB!OtP^6w^%D>U`$Xc`!!u4j~Q`g9nUR)7BcMXQJ;NdO3vB(Y=t z3jo9FAIO_DeAF<4;?^%T=uMPs=SXkXl9*G@SCy4KURkt7B#tH{;&$-G=mbNRdcI+VcLd>f*58%Y8|+Sz38S{mPF9HXK5 zB0Y6k+$nvJ&wpB4$s3*H{OzB}*DaB*>LD^NjDhy!tWQL8udf7g=PAO@_B#6FNR|uy zSuP5~sPv`xV^6Bel@xS#b7^=Q+2{h3W1m>M~~Y z{CFsHV@ct~vciYOlDDX>P?CE6HqkYAc{U;k;ZO?4WGbTMRSdO+BN}5F?>dcOR%J4y z@M0;)gSk&V>3G|Pl5^pFQdUoV?Ene&S_02iAo!iaF))$Pm;|P~4r4WkF?s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>WJEvCQjU21jbK%7KC z1b-$cXt@mq5Y5UNTjxc-7an}5!cA!`D7MiPvnHU>-hH1v3 zI6h8WzM5}5-MMBzm!kQvQX;XY!qW!5%$8e`j%ZU?q0diceDuL{O#f3BMVOvuY~U_+ z-(IF7Y(Ir^8HN5b%8!Onqdv!AZ!1hcmlp`|ANF3#ZPy`Xs{jB107*qoM6N<$g0t+$ Apa1{> diff --git a/toolkit/components/places/tests/favicons/expected-favicon-big64.png.png b/toolkit/components/places/tests/favicons/expected-favicon-big64.png.png index 03a01c6de84a633c5a4a73a9b0187d92f4ba9125..238973189040030ed5071fb3f9ed8c141a802211 100644 GIT binary patch delta 957 zcmV;u148`d2Ga+SB!8MoL_t(Ijct>EOwJmI1V^Q0v@d&lWZtMLqkxI zKw)0BNHAcx108b5uMk8)GDWlkq)eEN;mAn@K~N|lxs#A76ne^!1Ood3EcmAa?)!b8 z{&2EcJ%7H>-p`&to`;BtKqS#>wbryEosUb*g~ZUpwvrdpntzW{*!j1K&Uid_QAk$w ze^U5myQ}q=Yocm~77SOW@%hj5sJt@={TFu-k#>4!Q{dh*A}5FcKqfy6jz16;QADu~ zV-c;hIM>;Q(#95{X7pF#h_eoOQLGVp!PjrNQ=fSTaAeRF&eCvy$NE{xvuM zJnkjT=c$(GGUez=aOIO_?{Q({mpE|UjEoy*PP=xOg9=)BtFh8D(zXT*EnbV-xVY!2 zE8TDN)G?pM@eGAHmhLW&89jI;Rn5O=yo}RDsfeuq9)Drwt|Z zW$wMSO~C9c+>DHlj^)vY%Jdx!l+)r`i=0G`)#_dGHiF1gl>VfvW34Z%ZK|XsS zfA&pmjDIxp{br4b*-d==gu?)JZ*%_Yw`@0ln5VXU6Kux~o&-Zu5`yxtAS$mO2hY@D ztG)u(%IzTA5R_)V#psX;7+=NL&u(m|dM{b=RH_n_@48!tUSG|lJBS}7twwix0PYzz zm?-c@l6Ds)Rxg5VUgJyEDI$98zyn)QTOL(Lhkxklfd1|F%TtGy;)FpZPU-A17;Dd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