OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |