fix numerical overflows in 565 blends
authorreed <reed@google.com>
Fri, 22 Aug 2014 14:27:14 +0000 (07:27 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 22 Aug 2014 14:27:14 +0000 (07:27 -0700)
BUG=skia:2797
R=mtklein@google.com

Author: reed@google.com

Review URL: https://codereview.chromium.org/474983007

bench/nanobench.cpp
src/core/SkBlitRow_D16.cpp

index 8961916..f2bf30a 100644 (file)
@@ -612,14 +612,6 @@ int nanobench_main() {
             SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface->getCanvas() : NULL;
             const char* config = targets[j]->config.name;
 
-#ifdef SK_DEBUG
-            // skia:2797  Some SKPs SkASSERT in debug mode.  Skip them for now.
-            if (0 == strcmp("565", config) && SkStrContains(bench->getName(), ".skp")) {
-                SkDebugf("Skipping 565 %s.  See skia:2797\n", bench->getName());
-                continue;
-            }
-#endif
-
             const int loops =
 #if SK_SUPPORT_GPU
                 Benchmark::kGPU_Backend == targets[j]->config.backend
index 1b2be06..e052b35 100644 (file)
@@ -74,11 +74,8 @@ static void S32A_D565_Blend(uint16_t* SK_RESTRICT dst,
             SkPMColorAssert(sc);
             if (sc) {
                 uint16_t dc = *dst;
-                unsigned dst_scale = 255 - SkMulDiv255Round(SkGetPackedA32(sc), alpha);
-                unsigned dr = SkMulS16(SkPacked32ToR16(sc), alpha) + SkMulS16(SkGetPackedR16(dc), dst_scale);
-                unsigned dg = SkMulS16(SkPacked32ToG16(sc), alpha) + SkMulS16(SkGetPackedG16(dc), dst_scale);
-                unsigned db = SkMulS16(SkPacked32ToB16(sc), alpha) + SkMulS16(SkGetPackedB16(dc), dst_scale);
-                *dst = SkPackRGB16(SkDiv255Round(dr), SkDiv255Round(dg), SkDiv255Round(db));
+                SkPMColor res = SkBlendARGB32(sc, SkPixel16ToPixel32(dc), alpha);
+                *dst = SkPixel32ToPixel16(res);
             }
             dst += 1;
         } while (--count != 0);