diff options
author | reed <reed@google.com> | 2015-12-04 12:44:24 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-04 12:44:24 -0800 |
commit | 95f53fbc5ddf14ddb1e51c7ebced2b80fb069f81 (patch) | |
tree | 107b0119489a7dd84e6ab3d2701451af3340128a | |
parent | 5123eb760fcb1684394b73c2fc6bfad270b29baf (diff) |
clarify diff manually, showing black where they differ
BUG=skia:
TBR=robertphilips@google.com
Review URL: https://codereview.chromium.org/1498243002
-rw-r--r-- | gm/spritebitmap.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/gm/spritebitmap.cpp b/gm/spritebitmap.cpp index b11763b5f9..b199371e89 100644 --- a/gm/spritebitmap.cpp +++ b/gm/spritebitmap.cpp @@ -228,6 +228,34 @@ DEF_GM( return new ApplyFilterGM; ) #include "SkDisplacementMapEffect.h" #include "SkMatrixConvolutionImageFilter.h" +static SkPMColor max_component(SkPMColor a, SkPMColor b) { + int dr = SkAbs32(SkGetPackedR32(a) - SkGetPackedR32(b)); + int dg = SkAbs32(SkGetPackedG32(a) - SkGetPackedG32(b)); + int db = SkAbs32(SkGetPackedB32(a) - SkGetPackedB32(b)); + int d = SkTMax(dr, SkTMax(dg, db)); + d = 0xFF - d; + return SkPackARGB32(0xFF, d, d, d); +} + +static SkImage* compute_diff(SkImage* a, SkImage* b) { + SkASSERT(a->width() == b->width() && a->height() == b->height()); + const SkImageInfo info = SkImageInfo::MakeN32Premul(a->width(), a->height()); + SkBitmap bma, bmb, bmdiff; + bma.allocPixels(info); + bmb.allocPixels(info); + bmdiff.allocPixels(info); + + a->readPixels(info, bma.getPixels(), bma.rowBytes(), 0, 0); + b->readPixels(info, bmb.getPixels(), bmb.rowBytes(), 0, 0); + for (int y = 0; y < info.height(); ++y) { + for (int x = 0; x < info.width(); ++x) { + *bmdiff.getAddr32(x, y) = max_component(*bma.getAddr32(x, y), *bmb.getAddr32(x, y)); + } + } + bmdiff.setImmutable(); // avoid the copy + return SkImage::NewFromBitmap(bmdiff); +} + static SkImage* make_native_red_oval(SkCanvas* rootCanvas) { SkImageInfo info = SkImageInfo::MakeN32Premul(160, 90); SkAutoTUnref<SkSurface> surface(rootCanvas->newSurface(info)); @@ -329,10 +357,8 @@ protected: canvas->drawImage(snap1, dx, 0); SkAutoTUnref<SkImage> diff(snapshot(canvas, info, [&](SkCanvas* c) { - c->drawImage(snap0, 0, 0); - SkPaint p; - p.setXfermodeMode(SkXfermode::kDifference_Mode); - c->drawImage(snap1, 0, 0, &p); + SkAutoTUnref<SkImage> diff(compute_diff(snap0, snap1)); + c->drawImage(diff, 0, 0); })); canvas->drawImage(diff, 2*dx, 0); |