Bug 1207958 - Fix heuristic for choosing which ICO sub-image to render - r=tn, a=sylvestre
authorEdwin Flores <eflores@mozilla.com>
Wed, 20 Jan 2016 11:00:12 +0000
changeset 310888 2308a996a554986a6a94faed1da6f34219c5df48
parent 310887 07f847a16bf17ded6ae5fc32bb263f0d30e46149
child 310889 01b93573f9d466514485a3188bc666bb621d09bb
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn, sylvestre
bugs1207958
milestone45.0a2
Bug 1207958 - Fix heuristic for choosing which ICO sub-image to render - r=tn, a=sylvestre
image/decoders/nsICODecoder.cpp
--- a/image/decoders/nsICODecoder.cpp
+++ b/image/decoders/nsICODecoder.cpp
@@ -230,18 +230,18 @@ nsICODecoder::ReadDirEntry(const char* a
     // Calculate the delta between this resource's size and the desired size, so
     // we can see if it is better than our current-best option.  In the case of
     // several equally-good resources, we use the last one. "Better" in this
     // case is determined by |delta|, a measure of the difference in size
     // between the entry we've found and the downscaler's target size. We will
     // choose the smallest resource that is >= the target size (i.e. we assume
     // it's better to downscale a larger icon than to upscale a smaller one).
     IntSize desiredSize = mDownscaler->TargetSize();
-    int32_t delta = entrySize.width - desiredSize.width +
-                    entrySize.height - desiredSize.height;
+    int32_t delta = std::min(entrySize.width - desiredSize.width,
+                             entrySize.height - desiredSize.height);
     if (e.mBitCount >= mBestResourceColorDepth &&
         ((mBestResourceDelta < 0 && delta >= mBestResourceDelta) ||
          (delta >= 0 && delta <= mBestResourceDelta))) {
       mBestResourceDelta = delta;
       mBestResourceColorDepth = e.mBitCount;
       mDirEntry = e;
     }
   }