aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-18 17:29:15 +0000
committerGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-18 17:29:15 +0000
commit744820e6576ec255c9454a561f21e2ef94e891ba (patch)
tree733e468c3e74ab469de1cdd8d7c617e6ac16f2b3 /gm
parentca98b3106f82384034f810c1333ac10a583c2aa9 (diff)
Implement a bicubic resampling image filter, with raster and GPU backends.
In order to get this to work on the GPU side, I had to modify the width and height of the drawn texture in drawSprite() and drawDevice() to use the filtered texture's dimensions, instead of the source texture. (This wasn't a problem before since all other image filters produce results the same dimensions as their input texture.) For now, this implementation only does axis-aligned scaling (same as the Lanczos-3 implementation in Chrome). It's also done for correctness and clarity, not speed, so there are lots of opportunities for speedups. Review URL: https://codereview.appspot.com/7033049 git-svn-id: http://skia.googlecode.com/svn/trunk@7275 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm')
-rw-r--r--gm/bicubicfilter.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/gm/bicubicfilter.cpp b/gm/bicubicfilter.cpp
new file mode 100644
index 0000000000..c3f80df118
--- /dev/null
+++ b/gm/bicubicfilter.cpp
@@ -0,0 +1,84 @@
+/*
+ * 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 "SkBicubicImageFilter.h"
+
+namespace skiagm {
+
+class BicubicGM : public GM {
+public:
+ BicubicGM() : fInitialized(false) {
+ this->setBGColor(0x00000000);
+ }
+
+protected:
+ virtual SkString onShortName() {
+ return SkString("bicubicfilter");
+ }
+
+ void make_checkerboard(int width, int height) {
+ SkASSERT(width % 2 == 0);
+ SkASSERT(height % 2 == 0);
+ fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ fCheckerboard.allocPixels();
+ SkAutoLockPixels lock(fCheckerboard);
+ for (int y = 0; y < height; y += 2) {
+ SkPMColor* s = fCheckerboard.getAddr32(0, y);
+ for (int x = 0; x < width; x += 2) {
+ *s++ = 0xFFFFFFFF;
+ *s++ = 0xFF000000;
+ }
+ s = fCheckerboard.getAddr32(0, y + 1);
+ for (int x = 0; x < width; x += 2) {
+ *s++ = 0xFF000000;
+ *s++ = 0xFFFFFFFF;
+ }
+ }
+ }
+
+ virtual SkISize onISize() {
+ return make_isize(400, 300);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ if (!fInitialized) {
+ make_checkerboard(4, 4);
+ fInitialized = true;
+ }
+ SkScalar sk32 = SkIntToScalar(32);
+ canvas->clear(0x00000000);
+ SkPaint bilinearPaint, bicubicPaint;
+ SkSize scale = SkSize::Make(sk32, sk32);
+ canvas->save();
+ canvas->scale(sk32, sk32);
+ bilinearPaint.setFilterBitmap(true);
+ canvas->drawBitmap(fCheckerboard, 0, 0, &bilinearPaint);
+ canvas->restore();
+ SkAutoTUnref<SkImageFilter> bicubic(SkBicubicImageFilter::CreateMitchell(scale));
+ bicubicPaint.setImageFilter(bicubic);
+ SkRect srcBounds;
+ fCheckerboard.getBounds(&srcBounds);
+ canvas->translate(SkIntToScalar(140), 0);
+ canvas->saveLayer(&srcBounds, &bicubicPaint);
+ canvas->drawBitmap(fCheckerboard, 0, 0);
+ canvas->restore();
+ }
+
+private:
+ typedef GM INHERITED;
+ SkBitmap fCheckerboard;
+ bool fInitialized;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new BicubicGM; }
+static GMRegistry reg(MyFactory);
+
+}