| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkColorMatrixFilter.h" | 10 #include "SkColorMatrixFilter.h" |
| 11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
| 12 #include "SkShader.h" | 12 #include "SkShader.h" |
| 13 | 13 |
| 14 #include "SkBlurImageFilter.h" | 14 #include "SkBlurImageFilter.h" |
| 15 #include "SkColorFilterImageFilter.h" | 15 #include "SkColorFilterImageFilter.h" |
| 16 | 16 |
| 17 #define FILTER_WIDTH SkIntToScalar(30) | 17 #define FILTER_WIDTH SkIntToScalar(30) |
| 18 #define FILTER_HEIGHT SkIntToScalar(30) | 18 #define FILTER_HEIGHT SkIntToScalar(30) |
| 19 #define MARGIN SkIntToScalar(10) | 19 #define MARGIN SkIntToScalar(10) |
| 20 | 20 |
| 21 static SkImageFilter* make_blur(float amount, SkImageFilter* input = NULL) { | 21 static SkImageFilter* make_blur(float amount, SkImageFilter* input = NULL) { |
| 22 return new SkBlurImageFilter(amount, amount, input); | 22 return new SkBlurImageFilter(amount, amount, input); |
| 23 } | 23 } |
| 24 | 24 |
| 25 static SkImageFilter* make_brightness(float amount, SkImageFilter* input = NULL)
{ | 25 static SkImageFilter* make_brightness(float amount, SkImageFilter* input = NULL)
{ |
| 26 SkScalar amount255 = SkScalarMul(SkFloatToScalar(amount), SkIntToScalar(255)
); | 26 SkScalar amount255 = SkScalarMul(amount, SkIntToScalar(255)); |
| 27 SkScalar matrix[20] = { 1, 0, 0, 0, amount255, | 27 SkScalar matrix[20] = { 1, 0, 0, 0, amount255, |
| 28 0, 1, 0, 0, amount255, | 28 0, 1, 0, 0, amount255, |
| 29 0, 0, 1, 0, amount255, | 29 0, 0, 1, 0, amount255, |
| 30 0, 0, 0, 1, 0 }; | 30 0, 0, 0, 1, 0 }; |
| 31 SkAutoTUnref<SkColorFilter> filter(new SkColorMatrixFilter(matrix)); | 31 SkAutoTUnref<SkColorFilter> filter(new SkColorMatrixFilter(matrix)); |
| 32 return SkColorFilterImageFilter::Create(filter, input); | 32 return SkColorFilterImageFilter::Create(filter, input); |
| 33 } | 33 } |
| 34 | 34 |
| 35 static SkImageFilter* make_grayscale(SkImageFilter* input = NULL) { | 35 static SkImageFilter* make_grayscale(SkImageFilter* input = NULL) { |
| 36 SkScalar matrix[20]; | 36 SkScalar matrix[20]; |
| 37 memset(matrix, 0, 20 * sizeof(SkScalar)); | 37 memset(matrix, 0, 20 * sizeof(SkScalar)); |
| 38 matrix[0] = matrix[5] = matrix[10] = SkFloatToScalar(0.2126f); | 38 matrix[0] = matrix[5] = matrix[10] = 0.2126f; |
| 39 matrix[1] = matrix[6] = matrix[11] = SkFloatToScalar(0.7152f); | 39 matrix[1] = matrix[6] = matrix[11] = 0.7152f; |
| 40 matrix[2] = matrix[7] = matrix[12] = SkFloatToScalar(0.0722f); | 40 matrix[2] = matrix[7] = matrix[12] = 0.0722f; |
| 41 matrix[18] = SkFloatToScalar(1.0f); | 41 matrix[18] = 1.0f; |
| 42 SkAutoTUnref<SkColorFilter> filter(new SkColorMatrixFilter(matrix)); | 42 SkAutoTUnref<SkColorFilter> filter(new SkColorMatrixFilter(matrix)); |
| 43 return SkColorFilterImageFilter::Create(filter, input); | 43 return SkColorFilterImageFilter::Create(filter, input); |
| 44 } | 44 } |
| 45 | 45 |
| 46 static SkImageFilter* make_mode_blue(SkImageFilter* input = NULL) { | 46 static SkImageFilter* make_mode_blue(SkImageFilter* input = NULL) { |
| 47 SkAutoTUnref<SkColorFilter> filter( | 47 SkAutoTUnref<SkColorFilter> filter( |
| 48 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); | 48 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); |
| 49 return SkColorFilterImageFilter::Create(filter, input); | 49 return SkColorFilterImageFilter::Create(filter, input); |
| 50 } | 50 } |
| 51 | 51 |
| 52 class ColorFilterImageFilterGM : public skiagm::GM { | 52 class ColorFilterImageFilterGM : public skiagm::GM { |
| 53 public: | 53 public: |
| 54 ColorFilterImageFilterGM () {} | 54 ColorFilterImageFilterGM () {} |
| 55 | 55 |
| 56 protected: | 56 protected: |
| 57 | 57 |
| 58 virtual SkString onShortName() { | 58 virtual SkString onShortName() { |
| 59 return SkString("colorfilterimagefilter"); | 59 return SkString("colorfilterimagefilter"); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void drawClippedRect(SkCanvas* canvas, const SkRect& r, const SkPaint& paint
, float outset = 0.0f) { | 62 void drawClippedRect(SkCanvas* canvas, const SkRect& r, const SkPaint& paint
, float outset = 0.0f) { |
| 63 canvas->save(); | 63 canvas->save(); |
| 64 SkRect clip(r); | 64 SkRect clip(r); |
| 65 clip.outset(SkFloatToScalar(outset), SkFloatToScalar(outset)); | 65 clip.outset(outset, outset); |
| 66 canvas->clipRect(clip); | 66 canvas->clipRect(clip); |
| 67 canvas->drawRect(r, paint); | 67 canvas->drawRect(r, paint); |
| 68 canvas->restore(); | 68 canvas->restore(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual SkISize onISize() { return SkISize::Make(400, 100); } | 71 virtual SkISize onISize() { return SkISize::Make(400, 100); } |
| 72 | 72 |
| 73 virtual void onDraw(SkCanvas* canvas) { | 73 virtual void onDraw(SkCanvas* canvas) { |
| 74 | 74 |
| 75 SkRect r = SkRect::MakeWH(FILTER_WIDTH, FILTER_HEIGHT); | 75 SkRect r = SkRect::MakeWH(FILTER_WIDTH, FILTER_HEIGHT); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 123 } |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 typedef GM INHERITED; | 126 typedef GM INHERITED; |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 ////////////////////////////////////////////////////////////////////////////// | 129 ////////////////////////////////////////////////////////////////////////////// |
| 130 | 130 |
| 131 static skiagm::GM* MyFactory(void*) { return new ColorFilterImageFilterGM; } | 131 static skiagm::GM* MyFactory(void*) { return new ColorFilterImageFilterGM; } |
| 132 static skiagm::GMRegistry reg(MyFactory); | 132 static skiagm::GMRegistry reg(MyFactory); |
| OLD | NEW |