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

Side by Side Diff: gm/imageresizetiled.cpp

Issue 168283006: Fix CTM application in SkResizeImagefilter; implement bounds traversals. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Simplify imageresizetiled GM a tad (layerBounds are useless) Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gm/imagefiltersscaled.cpp ('k') | gyp/gmslides.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkBlurImageFilter.h" 9 #include "SkResizeImageFilter.h"
10 #include "SkRandom.h" 10 #include "SkRandom.h"
11 11
12 #define WIDTH 640 12 #define WIDTH 640
13 #define HEIGHT 480 13 #define HEIGHT 480
14 14
15 #define RESIZE_FACTOR SkIntToScalar(2)
16
15 namespace skiagm { 17 namespace skiagm {
16 18
17 class ImageBlurTiledGM : public GM { 19 class ImageResizeTiledGM : public GM {
18 public: 20 public:
19 ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY) 21 ImageResizeTiledGM() {
20 : fSigmaX(sigmaX), fSigmaY(sigmaY) {
21 } 22 }
22 23
23 protected: 24 protected:
24 virtual SkString onShortName() { 25 virtual SkString onShortName() SK_OVERRIDE {
25 return SkString("imageblurtiled"); 26 return SkString("imageresizetiled");
26 } 27 }
27 28
28 virtual SkISize onISize() { 29 virtual SkISize onISize() SK_OVERRIDE {
29 return make_isize(WIDTH, HEIGHT); 30 return make_isize(WIDTH, HEIGHT);
30 } 31 }
31 32
32 virtual void onDraw(SkCanvas* canvas) { 33 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
33 SkPaint paint; 34 SkPaint paint;
34 paint.setImageFilter(new SkBlurImageFilter(fSigmaX, fSigmaY))->unref(); 35 SkAutoTUnref<SkImageFilter> imageFilter(
35 const SkScalar tile_size = SkIntToScalar(128); 36 new SkResizeImageFilter(RESIZE_FACTOR, RESIZE_FACTOR, SkPaint::kNone _FilterLevel));
37 paint.setImageFilter(imageFilter.get());
38 const SkScalar tile_size = SkIntToScalar(100);
36 SkRect bounds; 39 SkRect bounds;
37 canvas->getClipBounds(&bounds); 40 canvas->getClipBounds(&bounds);
38 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tile_size) { 41 for (SkScalar y = 0; y < HEIGHT; y += tile_size) {
39 for (SkScalar x = bounds.left(); x < bounds.right(); x += tile_size) { 42 for (SkScalar x = 0; x < WIDTH; x += tile_size) {
40 canvas->save(); 43 canvas->save();
41 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size)); 44 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size));
45 canvas->scale(SkScalarInvert(RESIZE_FACTOR),
46 SkScalarInvert(RESIZE_FACTOR));
42 canvas->saveLayer(NULL, &paint); 47 canvas->saveLayer(NULL, &paint);
43 const char* str[] = { 48 const char* str[] = {
44 "The quick", 49 "The quick",
45 "brown fox", 50 "brown fox",
46 "jumped over", 51 "jumped over",
47 "the lazy dog.", 52 "the lazy dog.",
48 }; 53 };
49 SkPaint textPaint; 54 SkPaint textPaint;
50 textPaint.setAntiAlias(true); 55 textPaint.setAntiAlias(true);
51 textPaint.setTextSize(SkIntToScalar(100)); 56 textPaint.setTextSize(SkIntToScalar(100));
52 int posY = 0; 57 int posY = 0;
53 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) { 58 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) {
54 posY += 100; 59 posY += 100;
55 canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0), 60 canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0),
56 SkIntToScalar(posY), textPaint); 61 SkIntToScalar(posY), textPaint);
57 } 62 }
58 canvas->restore(); 63 canvas->restore();
59 canvas->restore(); 64 canvas->restore();
60 } 65 }
61 } 66 }
62 } 67 }
63 68
64 private: 69 private:
65 SkScalar fSigmaX;
66 SkScalar fSigmaY;
67
68 typedef GM INHERITED; 70 typedef GM INHERITED;
69 }; 71 };
70 72
71 ////////////////////////////////////////////////////////////////////////////// 73 //////////////////////////////////////////////////////////////////////////////
72 74
73 static GM* MyFactory1(void*) { return new ImageBlurTiledGM(3.0f, 3.0f); } 75 DEF_GM(return new ImageResizeTiledGM(); )
74 static GMRegistry reg1(MyFactory1);
75 76
76 } 77 }
OLDNEW
« no previous file with comments | « gm/imagefiltersscaled.cpp ('k') | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698