[m59] dither when converting to 4444
authorMatt Sarett <msarett@google.com>
Thu, 25 May 2017 22:53:02 +0000 (18:53 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Thu, 25 May 2017 23:22:01 +0000 (23:22 +0000)
NOTREECHECKS=true
NOTRY=true
NOPRESUBMIT=true
Bug: 720105
Change-Id: I2a3b8a56795403077151ccebed978a94f2350def

Change-Id: I2a3b8a56795403077151ccebed978a94f2350def
Reviewed-on: https://skia-review.googlesource.com/18021
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>

src/core/SkConvertPixels.cpp

index b919f5d..6106626 100644 (file)
@@ -9,6 +9,7 @@
 #include "SkColorSpaceXformPriv.h"
 #include "SkColorTable.h"
 #include "SkConvertPixels.h"
+#include "SkDither.h"
 #include "SkHalf.h"
 #include "SkImageInfoPriv.h"
 #include "SkOpts.h"
@@ -416,6 +417,25 @@ void SkConvertPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
         return;
     }
 
+    // Chrome M59 Bug Fix: Convert to 4444 with dithering.
+    // This code is unnecessary in Skia for M60, since the raster pipeline implementation
+    // will dither.
+    if (kARGB_4444_SkColorType == dstInfo.colorType() && kN32_SkColorType == srcInfo.colorType() &&
+            kUnpremul_SkAlphaType != srcInfo.alphaType()) {
+        for (int y = 0; y < srcInfo.height(); y++) {
+            DITHER_4444_SCAN(y);
+            SkPMColor16* SK_RESTRICT dstRow = (SkPMColor16*)dstPixels;
+            const SkPMColor* SK_RESTRICT srcRow = (const SkPMColor*)srcPixels;
+            for (int x = 0; x < srcInfo.width(); ++x) {
+                dstRow[x] = SkDitherARGB32To4444(srcRow[x], DITHER_VALUE(x));
+            }
+            dstPixels = (char*)dstPixels + dstRB;
+            srcPixels = (const char*)srcPixels + srcRB;
+        }
+
+        return;
+    }
+
     // Default: Use the pipeline.
     convert_with_pipeline(dstInfo, dstPixels, dstRB, srcInfo, srcPixels, srcRB, isColorAware,
                           behavior);