aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/imageblur2.cpp
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2014-08-11 13:55:34 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-11 13:55:34 -0700
commit5acfea789d39106dbc706c6ee85cd8f027fce3ed (patch)
treeceec0b44a8cace23a13cdce08e1ffd27437a73ea /gm/imageblur2.cpp
parenta10555a354cf294bde217044472d33c3161df249 (diff)
2D kernel initial wiring for Guassian
BUG=skia: R=senorblanco@chromium.org, bsalomon@chromium.org, bsalomon@google.com Author: joshualitt@chromium.org Review URL: https://codereview.chromium.org/418223009
Diffstat (limited to 'gm/imageblur2.cpp')
-rw-r--r--gm/imageblur2.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/gm/imageblur2.cpp b/gm/imageblur2.cpp
new file mode 100644
index 0000000000..b7c9f9d9c8
--- /dev/null
+++ b/gm/imageblur2.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2011 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 "SkBlurImageFilter.h"
+#include "SkRandom.h"
+
+// TODO deprecate imageblur
+
+#define WIDTH 500
+#define HEIGHT 500
+
+static const float kBlurSigmas[] = {
+ 0.0, 0.3f, 0.5f, 2.0f, 32.0f, 80.0f };
+
+const char* kTestStrings[] = {
+ "The quick`~",
+ "brown fox[]",
+ "jumped over",
+ "the lazy@#$",
+ "dog.{}!%^&",
+ "*()+=-\\'\"/",
+};
+
+namespace skiagm {
+
+class BlurImageFilter : public GM {
+public:
+ BlurImageFilter() {
+ this->setBGColor(0xFFFFFFFF);
+ fName.printf("imageblur2");
+ }
+
+protected:
+ virtual uint32_t onGetFlags() const SK_OVERRIDE {
+ return kSkipTiled_Flag;
+ }
+
+ virtual SkString onShortName() {
+ return fName;
+ }
+
+ virtual SkISize onISize() {
+ return SkISize::Make(WIDTH, HEIGHT);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ const int sigmaCount = SK_ARRAY_COUNT(kBlurSigmas);
+ const int testStringCount = SK_ARRAY_COUNT(kTestStrings);
+ SkScalar dx = WIDTH / sigmaCount;
+ SkScalar dy = HEIGHT / sigmaCount;
+ const SkScalar textSize = 12;
+
+ for (int x = 0; x < sigmaCount; x++) {
+ SkScalar sigmaX = kBlurSigmas[x];
+ for (int y = 0; y < sigmaCount; y++) {
+ SkScalar sigmaY = kBlurSigmas[y];
+
+ SkPaint paint;
+ paint.setImageFilter(SkBlurImageFilter::Create(sigmaX, sigmaY))->unref();
+ canvas->saveLayer(NULL, &paint);
+
+ SkRandom rand;
+ SkPaint textPaint;
+ textPaint.setAntiAlias(false);
+ textPaint.setColor(rand.nextBits(24) | 0xFF000000);
+ textPaint.setTextSize(textSize);
+
+ for (int i = 0; i < testStringCount; i++) {
+ canvas->drawText(kTestStrings[i],
+ strlen(kTestStrings[i]),
+ SkIntToScalar(x * dx),
+ SkIntToScalar(y * dy + textSize * i + textSize),
+ textPaint);
+ }
+ canvas->restore();
+ }
+ }
+ }
+
+private:
+ SkString fName;
+
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new BlurImageFilter; }
+static GMRegistry reg(MyFactory);
+
+}