blob: c3f80df1183125a042d7cbf954ec40046fbdd805 [file] [log] [blame]
senorblanco@chromium.org3f2d45a2013-01-18 20:48:20 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkColor.h"
10#include "SkBicubicImageFilter.h"
11
12namespace skiagm {
13
14class BicubicGM : public GM {
15public:
16 BicubicGM() : fInitialized(false) {
17 this->setBGColor(0x00000000);
18 }
19
20protected:
21 virtual SkString onShortName() {
22 return SkString("bicubicfilter");
23 }
24
25 void make_checkerboard(int width, int height) {
26 SkASSERT(width % 2 == 0);
27 SkASSERT(height % 2 == 0);
28 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, width, height);
29 fCheckerboard.allocPixels();
30 SkAutoLockPixels lock(fCheckerboard);
31 for (int y = 0; y < height; y += 2) {
32 SkPMColor* s = fCheckerboard.getAddr32(0, y);
33 for (int x = 0; x < width; x += 2) {
34 *s++ = 0xFFFFFFFF;
35 *s++ = 0xFF000000;
36 }
37 s = fCheckerboard.getAddr32(0, y + 1);
38 for (int x = 0; x < width; x += 2) {
39 *s++ = 0xFF000000;
40 *s++ = 0xFFFFFFFF;
41 }
42 }
43 }
44
45 virtual SkISize onISize() {
46 return make_isize(400, 300);
47 }
48
49 virtual void onDraw(SkCanvas* canvas) {
50 if (!fInitialized) {
51 make_checkerboard(4, 4);
52 fInitialized = true;
53 }
54 SkScalar sk32 = SkIntToScalar(32);
55 canvas->clear(0x00000000);
56 SkPaint bilinearPaint, bicubicPaint;
57 SkSize scale = SkSize::Make(sk32, sk32);
58 canvas->save();
59 canvas->scale(sk32, sk32);
60 bilinearPaint.setFilterBitmap(true);
61 canvas->drawBitmap(fCheckerboard, 0, 0, &bilinearPaint);
62 canvas->restore();
63 SkAutoTUnref<SkImageFilter> bicubic(SkBicubicImageFilter::CreateMitchell(scale));
64 bicubicPaint.setImageFilter(bicubic);
65 SkRect srcBounds;
66 fCheckerboard.getBounds(&srcBounds);
67 canvas->translate(SkIntToScalar(140), 0);
68 canvas->saveLayer(&srcBounds, &bicubicPaint);
69 canvas->drawBitmap(fCheckerboard, 0, 0);
70 canvas->restore();
71 }
72
73private:
74 typedef GM INHERITED;
75 SkBitmap fCheckerboard;
76 bool fInitialized;
77};
78
79//////////////////////////////////////////////////////////////////////////////
80
81static GM* MyFactory(void*) { return new BicubicGM; }
82static GMRegistry reg(MyFactory);
83
84}