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

Side by Side Diff: gm/tablecolorfilter.cpp

Issue 971653002: Revert of add compose-colorfilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | include/core/SkColorFilter.h » ('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 2011 Google Inc. 2 * Copyright 2011 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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorFilterImageFilter.h" 10 #include "SkColorFilterImageFilter.h"
11 #include "SkGradientShader.h" 11 #include "SkGradientShader.h"
12 #include "SkTableColorFilter.h" 12 #include "SkTableColorFilter.h"
13 13
14 static SkShader* make_shader0(int w, int h) {
15 SkPoint pts[] = { {0, 0}, {SkIntToScalar(w), SkIntToScalar(h)} };
16 SkColor colors[] = {
17 SK_ColorBLACK, SK_ColorGREEN, SK_ColorCYAN,
18 SK_ColorRED, 0, SK_ColorBLUE, SK_ColorWHITE
19 };
20 return SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COUNT(colo rs),
21 SkShader::kClamp_TileMode);
22 }
23 static void make_bm0(SkBitmap* bm) { 14 static void make_bm0(SkBitmap* bm) {
24 int W = 120; 15 int W = 120;
25 int H = 120; 16 int H = 120;
26 bm->allocN32Pixels(W, H); 17 bm->allocN32Pixels(W, H);
27 bm->eraseColor(SK_ColorTRANSPARENT); 18 bm->eraseColor(SK_ColorTRANSPARENT);
28 19
29 SkCanvas canvas(*bm); 20 SkCanvas canvas(*bm);
30 SkPaint paint; 21 SkPaint paint;
31 paint.setShader(make_shader0(W, H))->unref(); 22 SkPoint pts[] = { {0, 0}, {SkIntToScalar(W), SkIntToScalar(H)} };
23 SkColor colors[] = {
24 SK_ColorBLACK, SK_ColorGREEN, SK_ColorCYAN,
25 SK_ColorRED, 0, SK_ColorBLUE, SK_ColorWHITE
26 };
27 SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COU NT(colors),
28 SkShader::kClamp_TileMode);
29 paint.setShader(s)->unref();
32 canvas.drawPaint(paint); 30 canvas.drawPaint(paint);
33 } 31 }
34 static SkShader* make_shader1(int w, int h) {
35 SkScalar cx = SkIntToScalar(w)/2;
36 SkScalar cy = SkIntToScalar(h)/2;
37 SkColor colors[] = {
38 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
39 };
40 return SkGradientShader::CreateRadial(SkPoint::Make(cx, cy), cx, colors, NUL L,
41 SK_ARRAY_COUNT(colors), SkShader::kCla mp_TileMode);
42 }
43 static void make_bm1(SkBitmap* bm) { 32 static void make_bm1(SkBitmap* bm) {
44 int W = 120; 33 int W = 120;
45 int H = 120; 34 int H = 120;
46 SkScalar cx = SkIntToScalar(W)/2;
47 SkScalar cy = SkIntToScalar(H)/2;
48 bm->allocN32Pixels(W, H); 35 bm->allocN32Pixels(W, H);
49 bm->eraseColor(SK_ColorTRANSPARENT); 36 bm->eraseColor(SK_ColorTRANSPARENT);
50 37
51 SkCanvas canvas(*bm); 38 SkCanvas canvas(*bm);
52 SkPaint paint; 39 SkPaint paint;
53 paint.setShader(make_shader1(W, H))->unref(); 40 SkScalar cx = SkIntToScalar(W)/2;
41 SkScalar cy = SkIntToScalar(H)/2;
42 SkColor colors[] = {
43 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
44 };
45 SkShader* s = SkGradientShader::CreateRadial(SkPoint::Make(SkIntToScalar(W)/ 2,
46 SkIntToScalar(H)/ 2),
47 SkIntToScalar(W)/2, colors, NUL L, SK_ARRAY_COUNT(colors),
48 SkShader::kClamp_TileMode);
49 paint.setShader(s)->unref();
54 paint.setAntiAlias(true); 50 paint.setAntiAlias(true);
55 canvas.drawCircle(cx, cy, cx, paint); 51 canvas.drawCircle(cx, cy, cx, paint);
56 } 52 }
57 53
58 static void make_table0(uint8_t table[]) { 54 static void make_table0(uint8_t table[]) {
59 for (int i = 0; i < 256; ++i) { 55 for (int i = 0; i < 256; ++i) {
60 int n = i >> 5; 56 int n = i >> 5;
61 table[i] = (n << 5) | (n << 2) | (n >> 1); 57 table[i] = (n << 5) | (n << 2) | (n >> 1);
62 } 58 }
63 } 59 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 } 177 }
182 178
183 // Move down one line to the beginning of the block for next bitmap 179 // Move down one line to the beginning of the block for next bitmap
184 y += yOffset; 180 y += yOffset;
185 } 181 }
186 } 182 }
187 183
188 private: 184 private:
189 typedef GM INHERITED; 185 typedef GM INHERITED;
190 }; 186 };
191 DEF_GM( return new TableColorFilterGM; )
192 187
193 ////////////////////////////////////////////////////////////////////////////// 188 //////////////////////////////////////////////////////////////////////////////
194 189
195 class ComposeColorFilterGM : public skiagm::GM { 190 static skiagm::GM* MyFactory(void*) { return new TableColorFilterGM; }
196 public: 191 static skiagm::GMRegistry reg(MyFactory);
197 ComposeColorFilterGM() {}
198
199 protected:
200 virtual SkString onShortName() {
201 return SkString("composecolorfilter");
202 }
203
204 virtual SkISize onISize() {
205 return SkISize::Make(730, 730);
206 }
207
208 virtual void onDraw(SkCanvas* canvas) {
209 SkBitmap bm;
210 make_bm1(&bm);
211
212 canvas->drawColor(0xFFDDDDDD);
213
214 SkColor colors[] = { SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW };
215 SkXfermode::Mode modes[] = {
216 SkXfermode::kOverlay_Mode,
217 SkXfermode::kDarken_Mode,
218 SkXfermode::kColorBurn_Mode,
219 SkXfermode::kExclusion_Mode,
220 };
221
222 const int MODES = SK_ARRAY_COUNT(modes) * SK_ARRAY_COUNT(colors);
223 SkAutoTUnref<SkColorFilter> filters[MODES];
224 int index = 0;
225 for (size_t i = 0; i < SK_ARRAY_COUNT(modes); ++i) {
226 for (size_t j = 0; j < SK_ARRAY_COUNT(colors); ++j) {
227 filters[index++].reset(SkColorFilter::CreateModeFilter(colors[j] , modes[i]));
228 }
229 }
230
231 SkPaint paint;
232 paint.setShader(make_shader1(50, 50))->unref();
233 SkRect r = SkRect::MakeWH(50, 50);
234 const SkScalar spacer = 10;
235
236 canvas->translate(spacer, spacer);
237
238 for (size_t y = 0; y < MODES; ++y) {
239 canvas->save();
240 for (size_t x = 0; x < MODES; ++x) {
241 SkAutoTUnref<SkColorFilter> compose(SkColorFilter::CreateCompose Filter(filters[y],
242 filters[x]));
243 paint.setColorFilter(compose);
244 canvas->drawRect(r, paint);
245 canvas->translate(r.width() + spacer, 0);
246 }
247 canvas->restore();
248 canvas->translate(0, r.height() + spacer);
249 }
250 }
251
252 private:
253 typedef GM INHERITED;
254 };
255 DEF_GM( return new ComposeColorFilterGM; )
256
OLDNEW
« no previous file with comments | « no previous file | include/core/SkColorFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698