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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 1556553002: Implement an SkPaint-based image filter (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: More randomness for paths and for rasterizer's paint Created 4 years, 11 months 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
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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapDevice.h" 9 #include "SkBitmapDevice.h"
10 #include "SkBlurImageFilter.h" 10 #include "SkBlurImageFilter.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkColorFilterImageFilter.h" 12 #include "SkColorFilterImageFilter.h"
13 #include "SkColorMatrixFilter.h" 13 #include "SkColorMatrixFilter.h"
14 #include "SkComposeImageFilter.h" 14 #include "SkComposeImageFilter.h"
15 #include "SkDisplacementMapEffect.h" 15 #include "SkDisplacementMapEffect.h"
16 #include "SkDropShadowImageFilter.h" 16 #include "SkDropShadowImageFilter.h"
17 #include "SkFlattenableSerialization.h" 17 #include "SkFlattenableSerialization.h"
18 #include "SkGradientShader.h" 18 #include "SkGradientShader.h"
19 #include "SkImage.h" 19 #include "SkImage.h"
20 #include "SkImageSource.h" 20 #include "SkImageSource.h"
21 #include "SkLightingImageFilter.h" 21 #include "SkLightingImageFilter.h"
22 #include "SkMatrixConvolutionImageFilter.h" 22 #include "SkMatrixConvolutionImageFilter.h"
23 #include "SkMergeImageFilter.h" 23 #include "SkMergeImageFilter.h"
24 #include "SkMorphologyImageFilter.h" 24 #include "SkMorphologyImageFilter.h"
25 #include "SkOffsetImageFilter.h" 25 #include "SkOffsetImageFilter.h"
26 #include "SkPaintImageFilter.h"
26 #include "SkPerlinNoiseShader.h" 27 #include "SkPerlinNoiseShader.h"
27 #include "SkPicture.h" 28 #include "SkPicture.h"
28 #include "SkPictureImageFilter.h" 29 #include "SkPictureImageFilter.h"
29 #include "SkPictureRecorder.h" 30 #include "SkPictureRecorder.h"
30 #include "SkPoint3.h" 31 #include "SkPoint3.h"
31 #include "SkReadBuffer.h" 32 #include "SkReadBuffer.h"
32 #include "SkRect.h" 33 #include "SkRect.h"
33 #include "SkRectShaderImageFilter.h"
34 #include "SkSurface.h" 34 #include "SkSurface.h"
35 #include "SkTableColorFilter.h" 35 #include "SkTableColorFilter.h"
36 #include "SkTileImageFilter.h" 36 #include "SkTileImageFilter.h"
37 #include "SkXfermodeImageFilter.h" 37 #include "SkXfermodeImageFilter.h"
38 #include "Test.h" 38 #include "Test.h"
39 39
40 #if SK_SUPPORT_GPU 40 #if SK_SUPPORT_GPU
41 #include "GrContext.h" 41 #include "GrContext.h"
42 #include "SkGpuDevice.h" 42 #include "SkGpuDevice.h"
43 #endif 43 #endif
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 SkRTreeFactory factory; 432 SkRTreeFactory factory;
433 SkPictureRecorder recorder; 433 SkPictureRecorder recorder;
434 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0); 434 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0);
435 435
436 SkPaint greenPaint; 436 SkPaint greenPaint;
437 greenPaint.setColor(SK_ColorGREEN); 437 greenPaint.setColor(SK_ColorGREEN);
438 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 30, 20)), g reenPaint); 438 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 30, 20)), g reenPaint);
439 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 439 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
440 SkAutoTUnref<SkImageFilter> pictureFilter(SkPictureImageFilter::Create(pictu re.get())); 440 SkAutoTUnref<SkImageFilter> pictureFilter(SkPictureImageFilter::Create(pictu re.get()));
441 SkAutoTUnref<SkShader> shader(SkPerlinNoiseShader::CreateTurbulence(SK_Scala r1, SK_Scalar1, 1, 0)); 441 SkAutoTUnref<SkShader> shader(SkPerlinNoiseShader::CreateTurbulence(SK_Scala r1, SK_Scalar1, 1, 0));
442 SkPaint noisePaint;
443 noisePaint.setShader(shader);
442 444
443 SkAutoTUnref<SkImageFilter> rectShaderFilter(SkRectShaderImageFilter::Create (shader.get())); 445 SkAutoTUnref<SkImageFilter> paintFilter(SkPaintImageFilter::Create(noisePain t));
444 446
445 SkAutoTUnref<SkShader> greenColorShader(SkShader::CreateColorShader(SK_Color GREEN));
446 SkImageFilter::CropRect leftSideCropRect(SkRect::MakeXYWH(0, 0, 32, 64)); 447 SkImageFilter::CropRect leftSideCropRect(SkRect::MakeXYWH(0, 0, 32, 64));
447 SkAutoTUnref<SkImageFilter> rectShaderFilterLeft(SkRectShaderImageFilter::Cr eate(greenColorShader.get(), &leftSideCropRect)); 448 SkAutoTUnref<SkImageFilter> paintFilterLeft(SkPaintImageFilter::Create(green Paint, &leftSideCropRect));
448 SkImageFilter::CropRect rightSideCropRect(SkRect::MakeXYWH(32, 0, 32, 64)); 449 SkImageFilter::CropRect rightSideCropRect(SkRect::MakeXYWH(32, 0, 32, 64));
449 SkAutoTUnref<SkImageFilter> rectShaderFilterRight(SkRectShaderImageFilter::C reate(greenColorShader.get(), &rightSideCropRect)); 450 SkAutoTUnref<SkImageFilter> paintFilterRight(SkPaintImageFilter::Create(gree nPaint, &rightSideCropRect));
450 451
451 struct { 452 struct {
452 const char* fName; 453 const char* fName;
453 SkImageFilter* fFilter; 454 SkImageFilter* fFilter;
454 } filters[] = { 455 } filters[] = {
455 { "color filter", SkColorFilterImageFilter::Create(cf.get()) }, 456 { "color filter", SkColorFilterImageFilter::Create(cf.get()) },
456 { "displacement map", SkDisplacementMapEffect::Create( 457 { "displacement map", SkDisplacementMapEffect::Create(
457 SkDisplacementMapEffect::kR_ChannelSelectorType, 458 SkDisplacementMapEffect::kR_ChannelSelectorType,
458 SkDisplacementMapEffect::kB_ChannelSelectorType, 459 SkDisplacementMapEffect::kB_ChannelSelectorType,
459 20.0f, gradientSource.get()) }, 460 20.0f, gradientSource.get()) },
460 { "blur", SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1) }, 461 { "blur", SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1) },
461 { "drop shadow", SkDropShadowImageFilter::Create( 462 { "drop shadow", SkDropShadowImageFilter::Create(
462 SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN, 463 SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN,
463 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode) }, 464 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode) },
464 { "diffuse lighting", SkLightingImageFilter::CreatePointLitDiffuse( 465 { "diffuse lighting", SkLightingImageFilter::CreatePointLitDiffuse(
465 location, SK_ColorGREEN, 0, 0) }, 466 location, SK_ColorGREEN, 0, 0) },
466 { "specular lighting", 467 { "specular lighting",
467 SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGR EEN, 0, 0, 0) }, 468 SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGR EEN, 0, 0, 0) },
468 { "matrix convolution", 469 { "matrix convolution",
469 SkMatrixConvolutionImageFilter::Create( 470 SkMatrixConvolutionImageFilter::Create(
470 kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1), 471 kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1),
471 SkMatrixConvolutionImageFilter::kRepeat_TileMode, false) }, 472 SkMatrixConvolutionImageFilter::kRepeat_TileMode, false) },
472 { "merge", SkMergeImageFilter::Create(nullptr, nullptr, SkXfermode::kSrc Over_Mode) }, 473 { "merge", SkMergeImageFilter::Create(nullptr, nullptr, SkXfermode::kSrc Over_Mode) },
473 { "merge with disjoint inputs", SkMergeImageFilter::Create( 474 { "merge with disjoint inputs", SkMergeImageFilter::Create(
474 rectShaderFilterLeft, rectShaderFilterRight, SkXfermode::kSrcOver_ Mode) }, 475 paintFilterLeft, paintFilterRight, SkXfermode::kSrcOver_Mode) },
475 { "offset", SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1) }, 476 { "offset", SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1) },
476 { "dilate", SkDilateImageFilter::Create(3, 2) }, 477 { "dilate", SkDilateImageFilter::Create(3, 2) },
477 { "erode", SkErodeImageFilter::Create(2, 3) }, 478 { "erode", SkErodeImageFilter::Create(2, 3) },
478 { "tile", SkTileImageFilter::Create(SkRect::MakeXYWH(0, 0, 50, 50), 479 { "tile", SkTileImageFilter::Create(SkRect::MakeXYWH(0, 0, 50, 50),
479 SkRect::MakeXYWH(0, 0, 100, 100), nu llptr) }, 480 SkRect::MakeXYWH(0, 0, 100, 100), nu llptr) },
480 { "matrix", SkImageFilter::CreateMatrixFilter(matrix, kLow_SkFilterQuali ty) }, 481 { "matrix", SkImageFilter::CreateMatrixFilter(matrix, kLow_SkFilterQuali ty) },
481 { "blur and offset", SkOffsetImageFilter::Create(five, five, blur.get()) }, 482 { "blur and offset", SkOffsetImageFilter::Create(five, five, blur.get()) },
482 { "picture and blur", SkBlurImageFilter::Create(five, five, pictureFilte r.get()) }, 483 { "picture and blur", SkBlurImageFilter::Create(five, five, pictureFilte r.get()) },
483 { "rect shader and blur", SkBlurImageFilter::Create(five, five, rectShad erFilter.get()) }, 484 { "paint and blur", SkBlurImageFilter::Create(five, five, paintFilter.ge t()) },
484 }; 485 };
485 486
486 SkBitmap untiledResult, tiledResult; 487 SkBitmap untiledResult, tiledResult;
487 const int width = 64, height = 64; 488 const int width = 64, height = 64;
488 untiledResult.allocN32Pixels(width, height); 489 untiledResult.allocN32Pixels(width, height);
489 tiledResult.allocN32Pixels(width, height); 490 tiledResult.allocN32Pixels(width, height);
490 SkCanvas tiledCanvas(tiledResult); 491 SkCanvas tiledCanvas(tiledResult);
491 SkCanvas untiledCanvas(untiledResult); 492 SkCanvas untiledCanvas(untiledResult);
492 int tileSize = 8; 493 int tileSize = 8;
493 494
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 SkSurface::kNo_Budgeted , 1313 SkSurface::kNo_Budgeted ,
1313 SkImageInfo::MakeN32Pre mul(1, 1), 1314 SkImageInfo::MakeN32Pre mul(1, 1),
1314 0, 1315 0,
1315 &props, 1316 &props,
1316 SkGpuDevice::kUninit_In itContents)); 1317 SkGpuDevice::kUninit_In itContents));
1317 SkImageFilter::DeviceProxy proxy(device); 1318 SkImageFilter::DeviceProxy proxy(device);
1318 1319
1319 test_negative_blur_sigma(&proxy, reporter); 1320 test_negative_blur_sigma(&proxy, reporter);
1320 } 1321 }
1321 #endif 1322 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698