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

Side by Side Diff: gm/imagefiltersscaled.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/imagefiltersclipped.cpp ('k') | gm/imageresizetiled.cpp » ('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 "SkColor.h" 9 #include "SkColor.h"
10 #include "SkBitmapSource.h" 10 #include "SkBitmapSource.h"
11 #include "SkBlurImageFilter.h" 11 #include "SkBlurImageFilter.h"
12 #include "SkDisplacementMapEffect.h" 12 #include "SkDisplacementMapEffect.h"
13 #include "SkDropShadowImageFilter.h" 13 #include "SkDropShadowImageFilter.h"
14 #include "SkGradientShader.h" 14 #include "SkGradientShader.h"
15 #include "SkMorphologyImageFilter.h" 15 #include "SkMorphologyImageFilter.h"
16 #include "SkOffsetImageFilter.h" 16 #include "SkOffsetImageFilter.h"
17 #include "SkResizeImageFilter.h"
17 #include "SkScalar.h" 18 #include "SkScalar.h"
18 19
20 #define RESIZE_FACTOR SkIntToScalar(4)
21
19 namespace skiagm { 22 namespace skiagm {
20 23
21 class ImageFiltersScaledGM : public GM { 24 class ImageFiltersScaledGM : public GM {
22 public: 25 public:
23 ImageFiltersScaledGM() : fInitialized(false) { 26 ImageFiltersScaledGM() : fInitialized(false) {
24 this->setBGColor(0x00000000); 27 this->setBGColor(0x00000000);
25 } 28 }
26 29
27 protected: 30 protected:
28 virtual SkString onShortName() { 31 virtual SkString onShortName() {
29 return SkString("imagefiltersscaled"); 32 return SkString("imagefiltersscaled");
30 } 33 }
31 34
32 virtual SkISize onISize() { 35 virtual SkISize onISize() {
33 return make_isize(860, 500); 36 return make_isize(1020, 500);
34 } 37 }
35 38
36 void make_checkerboard() { 39 void make_checkerboard() {
37 fCheckerboard.allocN32Pixels(64, 64); 40 fCheckerboard.allocN32Pixels(64, 64);
38 SkCanvas canvas(fCheckerboard); 41 SkCanvas canvas(fCheckerboard);
39 canvas.clear(0x00000000); 42 canvas.clear(0x00000000);
40 SkPaint darkPaint; 43 SkPaint darkPaint;
41 darkPaint.setColor(0xFF404040); 44 darkPaint.setColor(0xFF404040);
42 SkPaint lightPaint; 45 SkPaint lightPaint;
43 lightPaint.setColor(0xFFA0A0A0); 46 lightPaint.setColor(0xFFA0A0A0);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 new SkDropShadowImageFilter(SkIntToScalar(5), SkIntToScalar(10), SkI ntToScalar(3), 92 new SkDropShadowImageFilter(SkIntToScalar(5), SkIntToScalar(10), SkI ntToScalar(3),
90 SK_ColorYELLOW), 93 SK_ColorYELLOW),
91 new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelec torType, 94 new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelec torType,
92 SkDisplacementMapEffect::kR_ChannelSelec torType, 95 SkDisplacementMapEffect::kR_ChannelSelec torType,
93 SkIntToScalar(12), 96 SkIntToScalar(12),
94 gradient.get(), 97 gradient.get(),
95 checkerboard.get()), 98 checkerboard.get()),
96 new SkDilateImageFilter(1, 1, checkerboard.get()), 99 new SkDilateImageFilter(1, 1, checkerboard.get()),
97 new SkErodeImageFilter(1, 1, checkerboard.get()), 100 new SkErodeImageFilter(1, 1, checkerboard.get()),
98 new SkOffsetImageFilter(SkIntToScalar(32), 0), 101 new SkOffsetImageFilter(SkIntToScalar(32), 0),
102 new SkResizeImageFilter(RESIZE_FACTOR, RESIZE_FACTOR, SkPaint::kNone _FilterLevel),
99 }; 103 };
100 104
101 SkVector scales[] = { 105 SkVector scales[] = {
102 SkVector::Make(SkScalarInvert(2), SkScalarInvert(2)), 106 SkVector::Make(SkScalarInvert(2), SkScalarInvert(2)),
103 SkVector::Make(SkIntToScalar(1), SkIntToScalar(1)), 107 SkVector::Make(SkIntToScalar(1), SkIntToScalar(1)),
104 SkVector::Make(SkIntToScalar(1), SkIntToScalar(2)), 108 SkVector::Make(SkIntToScalar(1), SkIntToScalar(2)),
105 SkVector::Make(SkIntToScalar(2), SkIntToScalar(1)), 109 SkVector::Make(SkIntToScalar(2), SkIntToScalar(1)),
106 SkVector::Make(SkIntToScalar(2), SkIntToScalar(2)), 110 SkVector::Make(SkIntToScalar(2), SkIntToScalar(2)),
107 }; 111 };
108 112
109 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); 113 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
110 SkScalar margin = SkIntToScalar(16); 114 SkScalar margin = SkIntToScalar(16);
111 SkRect bounds = r; 115 SkRect bounds = r;
112 bounds.outset(margin, margin); 116 bounds.outset(margin, margin);
113 117
114 for (size_t j = 0; j < SK_ARRAY_COUNT(scales); ++j) { 118 for (size_t j = 0; j < SK_ARRAY_COUNT(scales); ++j) {
115 canvas->save(); 119 canvas->save();
116 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { 120 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
117 SkPaint paint; 121 SkPaint paint;
118 paint.setColor(SK_ColorBLUE); 122 paint.setColor(SK_ColorBLUE);
119 paint.setImageFilter(filters[i]); 123 paint.setImageFilter(filters[i]);
120 paint.setAntiAlias(true); 124 paint.setAntiAlias(true);
121 canvas->save(); 125 canvas->save();
122 canvas->scale(scales[j].fX, scales[j].fY); 126 canvas->scale(scales[j].fX, scales[j].fY);
123 if (5 == i) { 127 if (5 == i) {
124 canvas->translate(SkIntToScalar(-32), 0); 128 canvas->translate(SkIntToScalar(-32), 0);
129 } else if (6 == i) {
130 canvas->scale(SkScalarInvert(RESIZE_FACTOR),
131 SkScalarInvert(RESIZE_FACTOR));
125 } 132 }
126 canvas->drawCircle(r.centerX(), r.centerY(), 133 canvas->drawCircle(r.centerX(), r.centerY(),
127 SkScalarDiv(r.width()*2, SkIntToScalar(5)), p aint); 134 SkScalarDiv(r.width()*2, SkIntToScalar(5)), p aint);
128 canvas->restore(); 135 canvas->restore();
129 canvas->translate(r.width() * scales[j].fX + margin, 0); 136 canvas->translate(r.width() * scales[j].fX + margin, 0);
130 } 137 }
131 canvas->restore(); 138 canvas->restore();
132 canvas->translate(0, r.height() * scales[j].fY + margin); 139 canvas->translate(0, r.height() * scales[j].fY + margin);
133 } 140 }
134 141
135 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { 142 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
136 filters[i]->unref(); 143 filters[i]->unref();
137 } 144 }
138 } 145 }
139 146
140 private: 147 private:
141 bool fInitialized; 148 bool fInitialized;
142 SkBitmap fCheckerboard; 149 SkBitmap fCheckerboard;
143 SkBitmap fGradientCircle; 150 SkBitmap fGradientCircle;
144 typedef GM INHERITED; 151 typedef GM INHERITED;
145 }; 152 };
146 153
147 ////////////////////////////////////////////////////////////////////////////// 154 //////////////////////////////////////////////////////////////////////////////
148 155
149 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; } 156 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; }
150 static GMRegistry reg(MyFactory); 157 static GMRegistry reg(MyFactory);
151 158
152 } 159 }
OLDNEW
« no previous file with comments | « gm/imagefiltersclipped.cpp ('k') | gm/imageresizetiled.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698