Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: gm/spritebitmap.cpp

Issue 1498243002: clarify diff manually, showing black where they differ (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkBlurImageFilter.h" 10 #include "SkBlurImageFilter.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 private: 221 private:
222 typedef GM INHERITED; 222 typedef GM INHERITED;
223 }; 223 };
224 DEF_GM( return new ApplyFilterGM; ) 224 DEF_GM( return new ApplyFilterGM; )
225 225
226 ////////////////////// 226 //////////////////////
227 227
228 #include "SkDisplacementMapEffect.h" 228 #include "SkDisplacementMapEffect.h"
229 #include "SkMatrixConvolutionImageFilter.h" 229 #include "SkMatrixConvolutionImageFilter.h"
230 230
231 static SkPMColor max_component(SkPMColor a, SkPMColor b) {
232 int dr = SkAbs32(SkGetPackedR32(a) - SkGetPackedR32(b));
233 int dg = SkAbs32(SkGetPackedG32(a) - SkGetPackedG32(b));
234 int db = SkAbs32(SkGetPackedB32(a) - SkGetPackedB32(b));
235 int d = SkTMax(dr, SkTMax(dg, db));
236 d = 0xFF - d;
237 return SkPackARGB32(0xFF, d, d, d);
238 }
239
240 static SkImage* compute_diff(SkImage* a, SkImage* b) {
241 SkASSERT(a->width() == b->width() && a->height() == b->height());
242 const SkImageInfo info = SkImageInfo::MakeN32Premul(a->width(), a->height()) ;
243 SkBitmap bma, bmb, bmdiff;
244 bma.allocPixels(info);
245 bmb.allocPixels(info);
246 bmdiff.allocPixels(info);
247
248 a->readPixels(info, bma.getPixels(), bma.rowBytes(), 0, 0);
249 b->readPixels(info, bmb.getPixels(), bmb.rowBytes(), 0, 0);
250 for (int y = 0; y < info.height(); ++y) {
251 for (int x = 0; x < info.width(); ++x) {
252 *bmdiff.getAddr32(x, y) = max_component(*bma.getAddr32(x, y), *bmb.g etAddr32(x, y));
253 }
254 }
255 bmdiff.setImmutable(); // avoid the copy
256 return SkImage::NewFromBitmap(bmdiff);
257 }
258
231 static SkImage* make_native_red_oval(SkCanvas* rootCanvas) { 259 static SkImage* make_native_red_oval(SkCanvas* rootCanvas) {
232 SkImageInfo info = SkImageInfo::MakeN32Premul(160, 90); 260 SkImageInfo info = SkImageInfo::MakeN32Premul(160, 90);
233 SkAutoTUnref<SkSurface> surface(rootCanvas->newSurface(info)); 261 SkAutoTUnref<SkSurface> surface(rootCanvas->newSurface(info));
234 if (!surface) { 262 if (!surface) {
235 surface.reset(SkSurface::NewRaster(info)); 263 surface.reset(SkSurface::NewRaster(info));
236 } 264 }
237 265
238 SkPaint paint; 266 SkPaint paint;
239 paint.setAntiAlias(true); 267 paint.setAntiAlias(true);
240 paint.setColor(SK_ColorRED); 268 paint.setColor(SK_ColorRED);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 canvas->drawImage(snap0, 0, 0); 350 canvas->drawImage(snap0, 0, 0);
323 351
324 SkAutoTUnref<SkImage> snap1(snapshot(canvas, info, [&](SkCanvas* c) { 352 SkAutoTUnref<SkImage> snap1(snapshot(canvas, info, [&](SkCanvas* c) {
325 SkBitmap bm; 353 SkBitmap bm;
326 image1->asLegacyBitmap(&bm, SkImage::kRO_LegacyBitmapMode); 354 image1->asLegacyBitmap(&bm, SkImage::kRO_LegacyBitmapMode);
327 c->drawSprite(bm, 0, 0, &paint); 355 c->drawSprite(bm, 0, 0, &paint);
328 })); 356 }));
329 canvas->drawImage(snap1, dx, 0); 357 canvas->drawImage(snap1, dx, 0);
330 358
331 SkAutoTUnref<SkImage> diff(snapshot(canvas, info, [&](SkCanvas* c) { 359 SkAutoTUnref<SkImage> diff(snapshot(canvas, info, [&](SkCanvas* c) {
332 c->drawImage(snap0, 0, 0); 360 SkAutoTUnref<SkImage> diff(compute_diff(snap0, snap1));
333 SkPaint p; 361 c->drawImage(diff, 0, 0);
334 p.setXfermodeMode(SkXfermode::kDifference_Mode);
335 c->drawImage(snap1, 0, 0, &p);
336 })); 362 }));
337 canvas->drawImage(diff, 2*dx, 0); 363 canvas->drawImage(diff, 2*dx, 0);
338 364
339 canvas->translate(0, dy); 365 canvas->translate(0, dy);
340 } 366 }
341 } 367 }
342 368
343 private: 369 private:
344 typedef GM INHERITED; 370 typedef GM INHERITED;
345 }; 371 };
346 DEF_GM( return new DrawWithFilterGM; ) 372 DEF_GM( return new DrawWithFilterGM; )
347 373
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698