Index: gm/arithimagefilter.cpp |
diff --git a/gm/blend.cpp b/gm/arithimagefilter.cpp |
similarity index 55% |
copy from gm/blend.cpp |
copy to gm/arithimagefilter.cpp |
index 452eb4945cb91f464eca7b10efa64e20b2f9770b..5ae074550b9f8687a3ffddd9a9062489a11cee2b 100644 |
--- a/gm/blend.cpp |
+++ b/gm/arithimagefilter.cpp |
@@ -1,25 +1,29 @@ |
/* |
- * Copyright 2012 Google Inc. |
+ * Copyright 2013 Google Inc. |
* |
* Use of this source code is governed by a BSD-style license that can be |
* found in the LICENSE file. |
*/ |
#include "gm.h" |
-#include "SkBlendImageFilter.h" |
+#include "SkArithmeticImageFilter.h" |
#include "SkBitmapSource.h" |
+#define WIDTH 500 |
+#define HEIGHT 300 |
+#define MARGIN 12 |
+ |
namespace skiagm { |
-class ImageBlendGM : public GM { |
+class ArithmeticImageFilterGM : public GM { |
public: |
- ImageBlendGM() : fInitialized(false) { |
+ ArithmeticImageFilterGM() : fInitialized(false) { |
this->setBGColor(0xFF000000); |
} |
protected: |
virtual SkString onShortName() { |
- return SkString("blend"); |
+ return SkString("arithimagefilter"); |
} |
void make_bitmap() { |
@@ -60,14 +64,14 @@ protected: |
} |
virtual SkISize onISize() { |
- return make_isize(500, 100); |
+ return make_isize(WIDTH, HEIGHT); |
} |
- void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x) { |
+ void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint, SkScalar x, SkScalar y) { |
canvas->save(); |
- canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), 0, |
- SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); |
- canvas->drawBitmap(fBitmap, SkIntToScalar(x), 0, &paint); |
+ canvas->clipRect(SkRect::MakeXYWH(x, y, |
+ SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); |
+ canvas->drawBitmap(bitmap, x, y, &paint); |
canvas->restore(); |
} |
@@ -79,19 +83,36 @@ protected: |
} |
canvas->clear(0x00000000); |
SkPaint paint; |
- SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fCheckerboard))); |
- paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kNormal_Mode, background)))->unref(); |
- drawClippedBitmap(canvas, paint, 0); |
- paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kMultiply_Mode, background)))->unref(); |
- drawClippedBitmap(canvas, paint, 100); |
- paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kScreen_Mode, background)))->unref(); |
- drawClippedBitmap(canvas, paint, 200); |
- paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kDarken_Mode, background)))->unref(); |
- drawClippedBitmap(canvas, paint, 300); |
- paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter::kLighten_Mode, background)))->unref(); |
- drawClippedBitmap(canvas, paint, 400); |
- } |
+ const SkScalar one = SK_Scalar1; |
+ static const SkScalar kValues[] = { |
+ 0, 0, 0, 0, |
+ 0, 0, 0, one, |
+ 0, one, 0, 0, |
+ 0, 0, one, 0, |
+ 0, one, one, 0, |
+ 0, one, -one, 0, |
+ 0, one/2, one/2, 0, |
+ 0, one/2, one/2, one/4, |
+ 0, one/2, one/2, -one/4, |
+ one/4, one/2, one/2, 0, |
+ -one/4, one/2, one/2, 0, |
+ }; |
+ |
+ int x = 0, y = 0; |
+ const SkScalar* kEnd = kValues + SK_ARRAY_COUNT(kValues); |
+ for (const SkScalar* k = kValues; k < kEnd; k += 4) { |
+ SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fCheckerboard))); |
+ SkAutoTUnref<SkImageFilter> arith(SkNEW_ARGS(SkArithmeticImageFilter, (k[0], k[1], k[2], k[3], background))); |
+ paint.setImageFilter(arith); |
+ drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScalar(y)); |
+ x += fBitmap.width() + MARGIN; |
+ if (x + fBitmap.width() > WIDTH) { |
+ x = 0; |
+ y += fBitmap.height() + MARGIN; |
+ } |
+ } |
+ } |
private: |
typedef GM INHERITED; |
SkBitmap fBitmap, fCheckerboard; |
@@ -100,7 +121,7 @@ private: |
////////////////////////////////////////////////////////////////////////////// |
-static GM* MyFactory(void*) { return new ImageBlendGM; } |
+static GM* MyFactory(void*) { return new ArithmeticImageFilterGM; } |
static GMRegistry reg(MyFactory); |
} |