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

Unified Diff: gm/resizeimagefilter.cpp

Issue 136863006: Implement a resize image filter. This is needed for the "filterRes" feature in SVG filter effects, … (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Add registration to fix cross-process pipe tests. Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/effects.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/resizeimagefilter.cpp
diff --git a/gm/resizeimagefilter.cpp b/gm/resizeimagefilter.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..fa407c4bfadd37c98eca9d96fb022736b05a9b20
--- /dev/null
+++ b/gm/resizeimagefilter.cpp
@@ -0,0 +1,96 @@
+/*
+ * 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 "SkColor.h"
+#include "SkResizeImageFilter.h"
+
+namespace skiagm {
+
+class ResizeGM : public GM {
+public:
+ ResizeGM() {
+ this->setBGColor(0x00000000);
+ }
+
+protected:
+ virtual SkString onShortName() {
+ return SkString("resizeimagefilter");
+ }
+
+ void draw(SkCanvas* canvas,
+ const SkRect& rect,
+ const SkSize& deviceSize,
+ SkPaint::FilterLevel filterLevel) {
+ SkRect dstRect;
+ canvas->getTotalMatrix().mapRect(&dstRect, rect);
+ canvas->save();
+ SkScalar deviceScaleX = SkScalarDiv(deviceSize.width(), dstRect.width());
+ SkScalar deviceScaleY = SkScalarDiv(deviceSize.height(), dstRect.height());
+ canvas->translate(rect.x(), rect.y());
+ canvas->scale(deviceScaleX, deviceScaleY);
+ canvas->translate(-rect.x(), -rect.y());
+ SkAutoTUnref<SkImageFilter> imageFilter(
+ new SkResizeImageFilter(SkScalarInvert(deviceScaleX),
+ SkScalarInvert(deviceScaleY),
+ filterLevel));
+ SkPaint filteredPaint;
+ filteredPaint.setImageFilter(imageFilter.get());
+ canvas->saveLayer(&rect, &filteredPaint);
+ SkPaint paint;
+ paint.setColor(0xFF00FF00);
+ SkRect ovalRect = rect;
+ ovalRect.inset(SkIntToScalar(4), SkIntToScalar(4));
+ canvas->drawOval(ovalRect, paint);
+ canvas->restore(); // for saveLayer
+ canvas->restore();
+ }
+
+ virtual SkISize onISize() {
+ return make_isize(420, 100);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ canvas->clear(0x00000000);
+
+ SkRect srcRect = SkRect::MakeWH(96, 96);
+
+ SkSize deviceSize = SkSize::Make(16, 16);
+ draw(canvas,
+ srcRect,
+ deviceSize,
+ SkPaint::kNone_FilterLevel);
+
+ canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
+ draw(canvas,
+ srcRect,
+ deviceSize,
+ SkPaint::kLow_FilterLevel);
+
+ canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
+ draw(canvas,
+ srcRect,
+ deviceSize,
+ SkPaint::kMedium_FilterLevel);
+
+ canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
+ draw(canvas,
+ srcRect,
+ deviceSize,
+ SkPaint::kHigh_FilterLevel);
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new ResizeGM; }
+static GMRegistry reg(MyFactory);
+
+}
« no previous file with comments | « no previous file | gyp/effects.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698