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

Side by Side Diff: gm/tablecolorfilter.cpp

Issue 969673002: 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') | include/core/SkColorFilter.h » ('J')
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 }
14 static void make_bm0(SkBitmap* bm) { 23 static void make_bm0(SkBitmap* bm) {
15 int W = 120; 24 int W = 120;
16 int H = 120; 25 int H = 120;
17 bm->allocN32Pixels(W, H); 26 bm->allocN32Pixels(W, H);
18 bm->eraseColor(SK_ColorTRANSPARENT); 27 bm->eraseColor(SK_ColorTRANSPARENT);
19 28
20 SkCanvas canvas(*bm); 29 SkCanvas canvas(*bm);
21 SkPaint paint; 30 SkPaint paint;
22 SkPoint pts[] = { {0, 0}, {SkIntToScalar(W), SkIntToScalar(H)} }; 31 paint.setShader(make_shader0(W, H))->unref();
32 canvas.drawPaint(paint);
33 }
34 static SkShader* make_shader1(int w, int h) {
35 SkScalar cx = SkIntToScalar(w)/2;
36 SkScalar cy = SkIntToScalar(h)/2;
23 SkColor colors[] = { 37 SkColor colors[] = {
24 SK_ColorBLACK, SK_ColorGREEN, SK_ColorCYAN, 38 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
25 SK_ColorRED, 0, SK_ColorBLUE, SK_ColorWHITE
26 }; 39 };
27 SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COU NT(colors), 40 return SkGradientShader::CreateRadial(SkPoint::Make(cx, cy), cx, colors, NUL L,
28 SkShader::kClamp_TileMode); 41 SK_ARRAY_COUNT(colors), SkShader::kCla mp_TileMode);
29 paint.setShader(s)->unref();
30 canvas.drawPaint(paint);
31 } 42 }
32 static void make_bm1(SkBitmap* bm) { 43 static void make_bm1(SkBitmap* bm) {
33 int W = 120; 44 int W = 120;
34 int H = 120; 45 int H = 120;
46 SkScalar cx = SkIntToScalar(W)/2;
47 SkScalar cy = SkIntToScalar(H)/2;
35 bm->allocN32Pixels(W, H); 48 bm->allocN32Pixels(W, H);
36 bm->eraseColor(SK_ColorTRANSPARENT); 49 bm->eraseColor(SK_ColorTRANSPARENT);
37 50
38 SkCanvas canvas(*bm); 51 SkCanvas canvas(*bm);
39 SkPaint paint; 52 SkPaint paint;
40 SkScalar cx = SkIntToScalar(W)/2; 53 paint.setShader(make_shader1(W, H))->unref();
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();
50 paint.setAntiAlias(true); 54 paint.setAntiAlias(true);
51 canvas.drawCircle(cx, cy, cx, paint); 55 canvas.drawCircle(cx, cy, cx, paint);
52 } 56 }
53 57
54 static void make_table0(uint8_t table[]) { 58 static void make_table0(uint8_t table[]) {
55 for (int i = 0; i < 256; ++i) { 59 for (int i = 0; i < 256; ++i) {
56 int n = i >> 5; 60 int n = i >> 5;
57 table[i] = (n << 5) | (n << 2) | (n >> 1); 61 table[i] = (n << 5) | (n << 2) | (n >> 1);
58 } 62 }
59 } 63 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 181 }
178 182
179 // Move down one line to the beginning of the block for next bitmap 183 // Move down one line to the beginning of the block for next bitmap
180 y += yOffset; 184 y += yOffset;
181 } 185 }
182 } 186 }
183 187
184 private: 188 private:
185 typedef GM INHERITED; 189 typedef GM INHERITED;
186 }; 190 };
191 DEF_GM( return new TableColorFilterGM; )
187 192
188 ////////////////////////////////////////////////////////////////////////////// 193 //////////////////////////////////////////////////////////////////////////////
189 194
190 static skiagm::GM* MyFactory(void*) { return new TableColorFilterGM; } 195 class ComposeColorFilterGM : public skiagm::GM {
191 static skiagm::GMRegistry reg(MyFactory); 196 public:
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') | include/core/SkColorFilter.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698