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

Side by Side Diff: gm/bitmapfilters.cpp

Issue 1142123003: add GM to test extractAlpha (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 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 | no next file » | 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 "sk_tool_utils.h" 9 #include "sk_tool_utils.h"
10 10
11 namespace skiagm {
12
13 static void make_bm(SkBitmap* bm) { 11 static void make_bm(SkBitmap* bm) {
14 const SkColor colors[4] = { 12 const SkColor colors[4] = {
15 SK_ColorRED, SK_ColorGREEN, 13 SK_ColorRED, SK_ColorGREEN,
16 SK_ColorBLUE, SK_ColorWHITE 14 SK_ColorBLUE, SK_ColorWHITE
17 }; 15 };
18 SkPMColor colorsPM[4]; 16 SkPMColor colorsPM[4];
19 for (size_t i = 0; i < SK_ARRAY_COUNT(colors); ++i) { 17 for (size_t i = 0; i < SK_ARRAY_COUNT(colors); ++i) {
20 colorsPM[i] = SkPreMultiplyColor(colors[i]); 18 colorsPM[i] = SkPreMultiplyColor(colors[i]);
21 } 19 }
22 SkColorTable* ctable = new SkColorTable(colorsPM, 4); 20 SkColorTable* ctable = new SkColorTable(colorsPM, 4);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 61
64 canvas->scale(SkIntToScalar(scale), SkIntToScalar(scale)); 62 canvas->scale(SkIntToScalar(scale), SkIntToScalar(scale));
65 63
66 x += draw_set(canvas, bm, 0, &paint); 64 x += draw_set(canvas, bm, 0, &paint);
67 paint.reset(); 65 paint.reset();
68 paint.setAlpha(0x80); 66 paint.setAlpha(0x80);
69 draw_set(canvas, bm, x, &paint); 67 draw_set(canvas, bm, x, &paint);
70 return x * scale / 3; 68 return x * scale / 3;
71 } 69 }
72 70
73 class FilterGM : public GM { 71 class FilterGM : public skiagm::GM {
74 bool fOnce; 72 void onOnceBeforeDraw() override {
75 void init() {
76 if (fOnce) {
77 return;
78 }
79 fOnce = true;
80 make_bm(&fBM8); 73 make_bm(&fBM8);
81 fBM8.copyTo(&fBM4444, kARGB_4444_SkColorType); 74 fBM8.copyTo(&fBM4444, kARGB_4444_SkColorType);
82 fBM8.copyTo(&fBM16, kRGB_565_SkColorType); 75 fBM8.copyTo(&fBM16, kRGB_565_SkColorType);
83 fBM8.copyTo(&fBM32, kN32_SkColorType); 76 fBM8.copyTo(&fBM32, kN32_SkColorType);
84 } 77 }
78
85 public: 79 public:
86 SkBitmap fBM8, fBM4444, fBM16, fBM32; 80 SkBitmap fBM8, fBM4444, fBM16, fBM32;
87 81
88 FilterGM() : fOnce(false) { 82 FilterGM() {
89 this->setBGColor(0xFFDDDDDD); 83 this->setBGColor(0xFFDDDDDD);
90 } 84 }
91 85
92 protected: 86 protected:
93 virtual SkString onShortName() { 87 SkString onShortName() override {
94 return SkString("bitmapfilters"); 88 return SkString("bitmapfilters");
95 } 89 }
96 90
97 virtual SkISize onISize() { 91 SkISize onISize() override {
98 return SkISize::Make(540, 330); 92 return SkISize::Make(540, 330);
99 } 93 }
100 94
101 virtual void onDraw(SkCanvas* canvas) { 95 void onDraw(SkCanvas* canvas) override {
102 this->init();
103
104 SkScalar x = SkIntToScalar(10); 96 SkScalar x = SkIntToScalar(10);
105 SkScalar y = SkIntToScalar(10); 97 SkScalar y = SkIntToScalar(10);
106 98
107 canvas->translate(x, y); 99 canvas->translate(x, y);
108 y = draw_row(canvas, fBM8); 100 y = draw_row(canvas, fBM8);
109 canvas->translate(0, y); 101 canvas->translate(0, y);
110 y = draw_row(canvas, fBM4444); 102 y = draw_row(canvas, fBM4444);
111 canvas->translate(0, y); 103 canvas->translate(0, y);
112 y = draw_row(canvas, fBM16); 104 y = draw_row(canvas, fBM16);
113 canvas->translate(0, y); 105 canvas->translate(0, y);
114 draw_row(canvas, fBM32); 106 draw_row(canvas, fBM32);
115 } 107 }
116 108
117 private: 109 private:
118 typedef GM INHERITED; 110 typedef skiagm::GM INHERITED;
119 }; 111 };
112 DEF_GM( return new FilterGM; )
120 113
121 ////////////////////////////////////////////////////////////////////////////// 114 //////////////////////////////////////////////////////////////////////////////
122 115
123 static GM* MyFactory(void*) { return new FilterGM; } 116 class TestExtractAlphaGM : public skiagm::GM {
124 static GMRegistry reg(MyFactory); 117 void onOnceBeforeDraw() override {
118 // Make a bitmap with per-pixels alpha (stroked circle)
119 fBitmap.allocN32Pixels(100, 100);
120 SkCanvas canvas(fBitmap);
121 canvas.clear(0);
125 122
126 } 123 SkPaint paint;
124 paint.setAntiAlias(true);
125 paint.setColor(SK_ColorBLUE);
126 paint.setStyle(SkPaint::kStroke_Style);
127 paint.setStrokeWidth(20);
128
129 canvas.drawCircle(50, 50, 39, paint);
130 canvas.flush();
131
132 fBitmap.extractAlpha(&fAlpha);
133 }
134
135 public:
136 SkBitmap fBitmap, fAlpha;
137
138 protected:
139 SkString onShortName() override {
140 return SkString("extractalpha");
141 }
142
143 SkISize onISize() override {
144 return SkISize::Make(540, 330);
145 }
146
147 void onDraw(SkCanvas* canvas) override {
148 SkPaint paint;
149 paint.setAntiAlias(true);
150 paint.setFilterQuality(kLow_SkFilterQuality);
151 paint.setColor(SK_ColorRED);
152
153 canvas->drawBitmap(fBitmap, 10, 10, &paint); // should stay blue (ign ore paint's color)
154 canvas->drawBitmap(fAlpha, 120, 10, &paint); // should draw red
155 }
156
157 private:
158 typedef skiagm::GM INHERITED;
159 };
160 DEF_GM( return new TestExtractAlphaGM; )
161
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698