blob: 49318df8329a3fb30e2350d02abb304844ca6294 [file] [log] [blame]
Cary Clark681287e2018-03-16 11:34:15 -04001#Topic Illustrations
2
Cary Clark682c58d2018-05-16 07:07:07 -04003#Subtopic Image_Info_Color_Type_RGB_565
Cary Clark681287e2018-03-16 11:34:15 -04004#Example
5#Width 415
6#Height 250
7void draw(SkCanvas* canvas) {
8 canvas->scale(1.25f, 1.25f);
9 SkPaint paint;
10 paint.setAntiAlias(true);
11 paint.setTextSize(10);
12 paint.setTextAlign(SkPaint::kCenter_Align);
13 canvas->drawString("16-bit word", 5 + 20 * 8, 20, paint);
14 canvas->drawString("little endian byte order", 5 + 20 * 4, 85, paint);
15 canvas->drawString("(low bits)", 5 + 20 * 1.5f, 137, paint);
16 canvas->drawString("(high bits)", 5 + 20 * 6.5f, 187, paint);
17 auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
18 SkPaint p(paint);
19 p.setColor(SK_ColorRED);
20 SkScalar xPos = 15;
21 int width = n % 32 + 1;
22 int lastN = n > 32 ? 32 : 0;
23 for (; n >= lastN; --n) {
24 for (int i = 0; i <= count; ++i) {
25 int a = width - e[i];
26 if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
27 char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
28 canvas->drawString(n >= 10 ? num : &num[1], xPos, yPos - 5, p);
29 break;
30 }
31 }
32 xPos += 20;
33 }
34 p.setColor(SK_ColorBLACK);
35 for (int i = 0; i < count; ++i) {
36 canvas->drawString(s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p);
37 }
38 p.setStyle(SkPaint::kStroke_Style);
39 for (int i = 0; i <= count; ++i) {
40 canvas->drawLine(5 + e[i] * 20, yPos, 5 + e[i] * 20, yPos + 15, p);
41 }
42 for (int i = 0; i < 2; ++i) {
43 canvas->drawLine(5 + e[0] * 20, yPos + i * 15, 5 + e[count] * 20, yPos + i * 15, p);
44 }
45 };
Cary Clark682c58d2018-05-16 07:07:07 -040046 SkScalar edges[] = { 0, 5, 11, 16,
Cary Clark681287e2018-03-16 11:34:15 -040047 0, 3, 8,
48 0, 5, 8 };
49 const char* labels[] = { "red", "green", "blue" };
50 drawBoxText(&edges[0], &labels[0], 3, 15, 45);
51 drawBoxText(&edges[4], &labels[1], 2, 7, 110);
52 drawBoxText(&edges[7], &labels[0], 2, 7, 160);
53}
54##
55##
56
Cary Clark682c58d2018-05-16 07:07:07 -040057#Subtopic Image_Info_Color_Type_ARGB_4444
Cary Clark681287e2018-03-16 11:34:15 -040058#Example
59#Width 415
60#Height 250
61void draw(SkCanvas* canvas) {
62 canvas->scale(1.25f, 1.25f);
63 SkPaint paint;
64 paint.setAntiAlias(true);
65 paint.setTextSize(10);
66 paint.setTextAlign(SkPaint::kCenter_Align);
67 canvas->drawString("16-bit word", 5 + 20 * 8, 20, paint);
68 canvas->drawString("little endian byte order", 5 + 20 * 4, 85, paint);
69 auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
70 SkPaint p(paint);
71 p.setColor(SK_ColorRED);
72 SkScalar xPos = 15;
73 int width = n % 32 + 1;
74 int lastN = n > 32 ? 32 : 0;
75 for (; n >= lastN; --n) {
76 for (int i = 0; i <= count; ++i) {
77 int a = width - e[i];
78 if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
79 char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
80 canvas->drawString(n >= 10 ? num : &num[1], xPos, yPos - 5, p);
81 break;
82 }
83 }
84 xPos += 20;
85 }
86 p.setColor(SK_ColorBLACK);
87 for (int i = 0; i < count; ++i) {
88 canvas->drawString(s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p);
89 }
90 p.setStyle(SkPaint::kStroke_Style);
91 for (int i = 0; i <= count; ++i) {
92 canvas->drawLine(5 + e[i] * 20, yPos, 5 + e[i] * 20, yPos + 15, p);
93 }
94 for (int i = 0; i < 2; ++i) {
95 canvas->drawLine(5 + e[0] * 20, yPos + i * 15, 5 + e[count] * 20, yPos + i * 15, p);
96 }
97 };
98 SkScalar edges[] = { 0, 4, 8, 12, 16 };
99 const char* labels[] = { "red", "green", "blue", "alpha" };
100 drawBoxText(&edges[0], &labels[0], 4, 15, 45);
101 drawBoxText(&edges[0], &labels[2], 2, 7, 110);
102 drawBoxText(&edges[0], &labels[0], 2, 7, 160);
103}
104##
105##
106
107#Subtopic Image_Info_Color_Type_RGBA_8888
108#Example
109#Width 812
110#Height 365
111void draw(SkCanvas* canvas) {
112 canvas->scale(1.25f, 1.25f);
113 SkPaint paint;
114 paint.setAntiAlias(true);
115 paint.setTextSize(10);
116 paint.setTextAlign(SkPaint::kCenter_Align);
117 canvas->drawString("32-bit word", 5 + 20 * 16, 20, paint);
118 canvas->drawString("little endian byte order", 5 + 20 * 4, 85, paint);
119 auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
120 SkPaint p(paint);
121 p.setColor(SK_ColorRED);
122 SkScalar xPos = 15;
123 int width = n % 32 + 1;
124 int lastN = n > 32 ? 32 : 0;
125 for (; n >= lastN; --n) {
126 for (int i = 0; i <= count; ++i) {
127 int a = width - e[i];
128 if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
129 char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
130 canvas->drawString(n >= 10 ? num : &num[1], xPos, yPos - 5, p);
131 break;
132 }
133 }
134 xPos += 20;
135 }
136 p.setColor(SK_ColorBLACK);
137 for (int i = 0; i < count; ++i) {
138 canvas->drawString(s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p);
139 }
140 p.setStyle(SkPaint::kStroke_Style);
141 for (int i = 0; i <= count; ++i) {
142 canvas->drawLine(5 + e[i] * 20, yPos, 5 + e[i] * 20, yPos + 15, p);
143 }
144 for (int i = 0; i < 2; ++i) {
145 canvas->drawLine(5 + e[0] * 20, yPos + i * 15, 5 + e[count] * 20, yPos + i * 15, p);
146 }
147 };
148 SkScalar edges[] = { 0, 8, 16, 24, 32 };
149 const char* labels[] = { "alpha", "blue", "green", "red" };
150 drawBoxText(edges, &labels[0], 4, 31, 45);
151 drawBoxText(edges, &labels[3], 1, 7, 110);
152 drawBoxText(edges, &labels[2], 1, 7, 160);
153 drawBoxText(edges, &labels[1], 1, 7, 210);
154 drawBoxText(edges, &labels[0], 1, 7, 260);
155}
156##
157##
158
Cary Clark682c58d2018-05-16 07:07:07 -0400159#Subtopic Image_Info_Color_Type_RGB_888
Cary Clark681287e2018-03-16 11:34:15 -0400160#Example
161#Width 812
162#Height 365
163void draw(SkCanvas* canvas) {
164 canvas->scale(1.25f, 1.25f);
165 SkPaint paint;
166 paint.setAntiAlias(true);
167 paint.setTextSize(10);
168 paint.setTextAlign(SkPaint::kCenter_Align);
169 canvas->drawString("32-bit word", 5 + 20 * 16, 20, paint);
170 canvas->drawString("little endian byte order", 5 + 20 * 4, 85, paint);
171 auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
172 SkPaint p(paint);
173 p.setColor(SK_ColorRED);
174 SkScalar xPos = 15;
175 int width = n % 32 + 1;
176 int lastN = n > 32 ? 32 : 0;
177 for (; n >= lastN; --n) {
178 for (int i = 0; i <= count; ++i) {
179 int a = width - e[i];
180 if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
181 char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
182 canvas->drawString(n >= 10 ? num : &num[1], xPos, yPos - 5, p);
183 break;
184 }
185 }
186 xPos += 20;
187 }
188 p.setColor(SK_ColorBLACK);
189 for (int i = 0; i < count; ++i) {
190 canvas->drawString(s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p);
191 }
192 p.setStyle(SkPaint::kStroke_Style);
193 for (int i = 0; i <= count; ++i) {
194 canvas->drawLine(5 + e[i] * 20, yPos, 5 + e[i] * 20, yPos + 15, p);
195 }
196 for (int i = 0; i < 2; ++i) {
197 canvas->drawLine(5 + e[0] * 20, yPos + i * 15, 5 + e[count] * 20, yPos + i * 15, p);
198 }
199 };
200 SkScalar edges[] = { 0, 8, 16, 24, 32 };
201 const char* labels[] = { "(unused)", "blue", "green", "red" };
202 drawBoxText(edges, &labels[0], 4, 31, 45);
203 drawBoxText(edges, &labels[3], 1, 7, 110);
204 drawBoxText(edges, &labels[2], 1, 7, 160);
205 drawBoxText(edges, &labels[1], 1, 7, 210);
206 drawBoxText(edges, &labels[0], 1, 7, 260);
207}
208##
209##
210
211#Subtopic Image_Info_Color_Type_BGRA_8888
212#Example
213#Width 812
214#Height 365
215void draw(SkCanvas* canvas) {
216 canvas->scale(1.25f, 1.25f);
217 SkPaint paint;
218 paint.setAntiAlias(true);
219 paint.setTextSize(10);
220 paint.setTextAlign(SkPaint::kCenter_Align);
221 canvas->drawString("32-bit word", 5 + 20 * 16, 20, paint);
222 canvas->drawString("little endian byte order", 5 + 20 * 4, 85, paint);
223 auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
224 SkPaint p(paint);
225 p.setColor(SK_ColorRED);
226 SkScalar xPos = 15;
227 int width = n % 32 + 1;
228 int lastN = n > 32 ? 32 : 0;
229 for (; n >= lastN; --n) {
230 for (int i = 0; i <= count; ++i) {
231 int a = width - e[i];
232 if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
233 char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
234 canvas->drawString(n >= 10 ? num : &num[1], xPos, yPos - 5, p);
235 break;
236 }
237 }
238 xPos += 20;
239 }
240 p.setColor(SK_ColorBLACK);
241 for (int i = 0; i < count; ++i) {
242 canvas->drawString(s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p);
243 }
244 p.setStyle(SkPaint::kStroke_Style);
245 for (int i = 0; i <= count; ++i) {
246 canvas->drawLine(5 + e[i] * 20, yPos, 5 + e[i] * 20, yPos + 15, p);
247 }
248 for (int i = 0; i < 2; ++i) {
249 canvas->drawLine(5 + e[0] * 20, yPos + i * 15, 5 + e[count] * 20, yPos + i * 15, p);
250 }
251 };
252 SkScalar edges[] = { 0, 8, 16, 24, 32 };
253 const char* labels[] = { "alpha", "red", "green", "blue" };
254 drawBoxText(edges, &labels[0], 4, 31, 45);
255 drawBoxText(edges, &labels[3], 1, 7, 110);
256 drawBoxText(edges, &labels[2], 1, 7, 160);
257 drawBoxText(edges, &labels[1], 1, 7, 210);
258 drawBoxText(edges, &labels[0], 1, 7, 260);
259}
260##
261##
262
263#Subtopic Image_Info_Color_Type_RGBA_1010102
264#Example
265#Width 812
266#Height 380
267void draw(SkCanvas* canvas) {
268 canvas->scale(1.25f, 1.25f);
269 SkPaint paint;
270 paint.setAntiAlias(true);
271 paint.setTextSize(10);
272 paint.setTextAlign(SkPaint::kCenter_Align);
273 canvas->drawString("32-bit word", 5 + 20 * 16, 20, paint);
274 canvas->drawString("little endian byte order", 5 + 20 * 4, 85, paint);
275 canvas->drawString("(low bits)", 5 + 20 * 4, 137, paint);
276 canvas->drawString("(low bits)", 5 + 20 * 3, 187, paint);
277 canvas->drawString("(high bits)", 5 + 20 * 7, 187, paint);
278 canvas->drawString("(low bits)", 5 + 20 * 2, 237, paint);
279 canvas->drawString("(high bits)", 5 + 20 * 6, 237, paint);
280 canvas->drawString("(high bits)", 5 + 20 * 5, 287, paint);
281 auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
282 SkPaint p(paint);
283 p.setColor(SK_ColorRED);
284 SkScalar xPos = 15;
285 int width = n % 32 + 1;
286 int lastN = n > 32 ? 32 : 0;
287 for (; n >= lastN; --n) {
288 for (int i = 0; i <= count; ++i) {
289 int a = width - e[i];
290 if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
291 char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
292 canvas->drawString(n >= 10 ? num : &num[1], xPos, yPos - 5, p);
293 break;
294 }
295 }
296 xPos += 20;
297 }
298 p.setColor(SK_ColorBLACK);
299 for (int i = 0; i < count; ++i) {
300 canvas->drawString(s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p);
301 }
302 p.setStyle(SkPaint::kStroke_Style);
303 for (int i = 0; i <= count; ++i) {
304 canvas->drawLine(5 + e[i] * 20, yPos, 5 + e[i] * 20, yPos + 15, p);
305 }
306 for (int i = 0; i < 2; ++i) {
307 canvas->drawLine(5 + e[0] * 20, yPos + i * 15, 5 + e[count] * 20, yPos + i * 15, p);
308 }
309 };
310 SkScalar edges[] = { 0, 2, 12, 22, 32,
311 0, 8,
312 0, 6, 8,
313 0, 4, 8,
314 0, 2, 8
315 };
316 const char* labels[] = { "alpha", "blue", "green", "red" };
317 drawBoxText(&edges[0], &labels[0], 4, 31, 45);
318 drawBoxText(&edges[5], &labels[3], 1, 7, 110);
319 drawBoxText(&edges[7], &labels[2], 2, 7, 160);
320 drawBoxText(&edges[10], &labels[1], 2, 7, 210);
321 drawBoxText(&edges[13], &labels[0], 2, 7, 260);
322}
323##
324##
325
Cary Clark682c58d2018-05-16 07:07:07 -0400326#Subtopic Image_Info_Color_Type_RGB_101010
Cary Clark681287e2018-03-16 11:34:15 -0400327#Example
328#Width 812
329#Height 380
330void draw(SkCanvas* canvas) {
331 canvas->scale(1.25f, 1.25f);
332 SkPaint paint;
333 paint.setAntiAlias(true);
334 paint.setTextSize(10);
335 paint.setTextAlign(SkPaint::kCenter_Align);
336 canvas->drawString("32-bit word", 5 + 20 * 16, 20, paint);
337 canvas->drawString("little endian byte order", 5 + 20 * 4, 85, paint);
338 canvas->drawString("(low bits)", 5 + 20 * 4, 137, paint);
339 canvas->drawString("(low bits)", 5 + 20 * 3, 187, paint);
340 canvas->drawString("(high bits)", 5 + 20 * 7, 187, paint);
341 canvas->drawString("(low bits)", 5 + 20 * 2, 237, paint);
342 canvas->drawString("(high bits)", 5 + 20 * 6, 237, paint);
343 canvas->drawString("(high bits)", 5 + 20 * 5, 287, paint);
344 auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
345 SkPaint p(paint);
346 p.setColor(SK_ColorRED);
347 SkScalar xPos = 15;
348 int width = n % 32 + 1;
349 int lastN = n > 32 ? 32 : 0;
350 for (; n >= lastN; --n) {
351 for (int i = 0; i <= count; ++i) {
352 int a = width - e[i];
353 if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
354 char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
355 canvas->drawString(n >= 10 ? num : &num[1], xPos, yPos - 5, p);
356 break;
357 }
358 }
359 xPos += 20;
360 }
361 p.setColor(SK_ColorBLACK);
362 for (int i = 0; i < count; ++i) {
363 canvas->drawString(s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p);
364 }
365 p.setStyle(SkPaint::kStroke_Style);
366 for (int i = 0; i <= count; ++i) {
367 canvas->drawLine(5 + e[i] * 20, yPos, 5 + e[i] * 20, yPos + 15, p);
368 }
369 for (int i = 0; i < 2; ++i) {
370 canvas->drawLine(5 + e[0] * 20, yPos + i * 15, 5 + e[count] * 20, yPos + i * 15, p);
371 }
372 };
373 SkScalar edges[] = { 0, 2, 12, 22, 32,
374 0, 8,
375 0, 6, 8,
376 0, 4, 8,
377 0, 2, 8
378 };
379 const char* labels[] = { "unused", "blue", "green", "red" };
380 drawBoxText(&edges[0], &labels[0], 4, 31, 45);
381 drawBoxText(&edges[5], &labels[3], 1, 7, 110);
382 drawBoxText(&edges[7], &labels[2], 2, 7, 160);
383 drawBoxText(&edges[10], &labels[1], 2, 7, 210);
384 drawBoxText(&edges[13], &labels[0], 2, 7, 260);
385}
386##
387##
388
389#Subtopic Image_Info_Color_Type_RGBA_F16
390#Example
391#Width 812
392#Height 685
393void draw(SkCanvas* canvas) {
394 canvas->scale(1.25f, 1.25f);
395 SkPaint paint;
396 paint.setAntiAlias(true);
397 paint.setTextSize(10);
398 paint.setTextAlign(SkPaint::kCenter_Align);
399 canvas->drawString("64-bit word", 5 + 20 * 16, 20, paint);
400 canvas->drawString("little endian byte order", 5 + 20 * 4, 135, paint);
401 for (int i = 0; i < 4; ++i) {
402 canvas->drawString("(low bits)", 5 + 20 * 4, 187 + i * 100, paint);
403 canvas->drawString("(high bits)", 5 + 20 * 4, 237 + i * 100, paint);
404 }
405 auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
406 SkPaint p(paint);
407 p.setColor(SK_ColorRED);
408 SkScalar xPos = 15;
409 int width = n % 32 + 1;
410 int lastN = n > 32 ? 32 : 0;
411 for (; n >= lastN; --n) {
412 for (int i = 0; i <= count; ++i) {
413 int a = width - e[i];
414 if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
415 char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
416 canvas->drawString(n >= 10 ? num : &num[1], xPos, yPos - 5, p);
417 break;
418 }
419 }
420 xPos += 20;
421 }
422 p.setColor(SK_ColorBLACK);
423 for (int i = 0; i < count; ++i) {
424 canvas->drawString(s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p);
425 }
426 p.setStyle(SkPaint::kStroke_Style);
427 for (int i = 0; i <= count; ++i) {
428 canvas->drawLine(5 + e[i] * 20, yPos, 5 + e[i] * 20, yPos + 15, p);
429 }
430 for (int i = 0; i < 2; ++i) {
431 canvas->drawLine(5 + e[0] * 20, yPos + i * 15, 5 + e[count] * 20, yPos + i * 15, p);
432 }
433 };
434 SkScalar edges[] = { 0, 16, 32,
435 0, 8
436 };
437 const char* labels[] = { "alpha", "blue", "green", "red" };
438 drawBoxText(&edges[0], &labels[0], 2, 63, 45);
439 drawBoxText(&edges[0], &labels[2], 2, 31, 95);
440 drawBoxText(&edges[3], &labels[3], 1, 7, 160);
441 drawBoxText(&edges[3], &labels[3], 1, 7, 210);
442 drawBoxText(&edges[3], &labels[2], 1, 7, 260);
443 drawBoxText(&edges[3], &labels[2], 1, 7, 310);
444 drawBoxText(&edges[3], &labels[1], 1, 7, 360);
445 drawBoxText(&edges[3], &labels[1], 1, 7, 410);
446 drawBoxText(&edges[3], &labels[0], 1, 7, 460);
447 drawBoxText(&edges[3], &labels[0], 1, 7, 510);
448}
449##
450##
451
Cary Clark224c7002018-06-27 11:00:21 -0400452#Subtopic Image_Info_Color_Type_RGBA_F32
453#Example
454#Width 812
455#Height 685
456void draw(SkCanvas* canvas) {
457 canvas->scale(1.25f, 1.25f);
458 SkPaint paint;
459 paint.setAntiAlias(true);
460 paint.setTextSize(10);
461 paint.setTextAlign(SkPaint::kCenter_Align);
462 canvas->drawString("128-bit word", 5 + 20 * 16, 20, paint);
463 canvas->drawString("little endian byte order", 5 + 20 * 4, 135, paint);
464 for (int i = 0; i < 4; ++i) {
465 canvas->drawString("(low bits)", 5 + 10 * 4, 187 + i * 100, paint);
466 canvas->drawString("(high bits)", 105 + 10 * 4, 237 + i * 100, paint);
467 }
468 auto drawBoxText = [=](SkScalar e[], const char* s[], const char* nums[] ,
469 int count, int n, SkScalar yPos) -> void {
470 SkPaint p(paint);
471 p.setColor(SK_ColorRED);
472 SkScalar xPos = 15;
473 int stringIndex = 0;
474 for (int i = n; i >= 0; --i) {
475 if (0 == i || n == i || 32 == i || 31 == i) {
476 int x = xPos;
477 if (2 == count) {
478 x += stringIndex * 12 + (stringIndex ? 8 : 0);
479 }
480 canvas->drawString(nums[stringIndex], x, yPos - 5, p);
481 if (1 == count) {
482 canvas->drawString(nums[stringIndex], xPos + 100, yPos - 5, p);
483 }
484 ++stringIndex;
485 }
486 xPos += 9;
487 }
488 p.setColor(SK_ColorBLACK);
489 for (int i = 0; i < count; ++i) {
490 canvas->drawString(s[i], 5 + (e[i] + e[i + 1]) * 5, yPos + 10, p);
491 if (1 == count) {
492 canvas->drawString(s[i], 105 + (e[i] + e[i + 1]) * 5, yPos + 10, p);
493 }
494 }
495 p.setStyle(SkPaint::kStroke_Style);
496 for (int i = 0; i <= count; ++i) {
497 canvas->drawLine(5 + e[i] * 10, yPos, 5 + e[i] * 10, yPos + 15, p);
498 if (1 == count) {
499 canvas->drawLine(105 + e[i] * 10, yPos, 105 + e[i] * 10, yPos + 15, p);
500 }
501 }
502 for (int i = 0; i < 2; ++i) {
503 canvas->drawLine(5 + e[0] * 10, yPos + i * 15,
504 5 + e[count] * 10, yPos + i * 15, p);
505 if (1 == count) {
506 canvas->drawLine(105 + e[0] * 10, yPos + i * 15,
507 105 + e[count] * 10, yPos + i * 15, p);
508 }
509 }
510 };
511 SkScalar edges[] = { 0, 32, 64,
512 0, 8
513 };
514 const char* labels[] = { "alpha", "blue", "green", "red" };
515 const char* nums128[] = { "127", "96", "95", "64"};
516 const char* nums64[] = { "63", "32", "31", "0"};
517 const char* nums8[] = { "7", "0"};
518 drawBoxText(&edges[0], &labels[0], nums128, 2, 63, 45);
519 drawBoxText(&edges[0], &labels[2], nums64, 2, 63, 95);
520 drawBoxText(&edges[3], &labels[3], nums8, 1, 7, 160);
521 drawBoxText(&edges[3], &labels[3], nums8, 1, 7, 210);
522 drawBoxText(&edges[3], &labels[2], nums8, 1, 7, 260);
523 drawBoxText(&edges[3], &labels[2], nums8, 1, 7, 310);
524 drawBoxText(&edges[3], &labels[1], nums8, 1, 7, 360);
525 drawBoxText(&edges[3], &labels[1], nums8, 1, 7, 410);
526 drawBoxText(&edges[3], &labels[0], nums8, 1, 7, 460);
527 drawBoxText(&edges[3], &labels[0], nums8, 1, 7, 510);
528}
529##
530##
531
532#Subtopic Blend_Mode_Porter_Duff
533#Example
534#Width 480
535#Height 330
536 SkPaint srcPaint;
537 srcPaint.setAntiAlias(true);
538 SkPaint labelPaint = srcPaint;
539 labelPaint.setTextAlign(SkPaint::kCenter_Align);
540 labelPaint.setTextSize(16);
541 SkPaint dstPaint = labelPaint;
542 dstPaint.setTextSize(80);
543 dstPaint.setColor(0xFF606080);
544 dstPaint.setTypeface(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()));
545
546 SkBitmap srcBits;
547 srcBits.allocN32Pixels(80, 84);
548 SkCanvas srcCanvas(srcBits);
549 srcPaint.setColor(0xFFcc6633);
550 SkPath srcPath;
551 const SkPoint points[] = {{20, 20}, {80, 45}, {45, 80}};
552 srcPath.addPoly(points, SK_ARRAY_COUNT(points), true);
553 srcBits.eraseColor(0);
554 srcCanvas.drawPath(srcPath, srcPaint);
555
556 canvas->drawColor(0, SkBlendMode::kClear);
557 for (auto blend : { SkBlendMode::kSrc, SkBlendMode::kSrcATop, SkBlendMode::kSrcOver,
558 SkBlendMode::kSrcIn, SkBlendMode::kSrcOut,
559 SkBlendMode::kDst, SkBlendMode::kDstATop, SkBlendMode::kDstOver,
560 SkBlendMode::kDstIn, SkBlendMode::kDstOut,
561 SkBlendMode::kClear, SkBlendMode::kXor } ) {
562 canvas->drawString("&", 50, 80, dstPaint);
563 srcPaint.setBlendMode(blend);
564 canvas->drawBitmap(srcBits, 0, 0, &srcPaint);
565 canvas->drawString(SkBlendMode_Name(blend), 50, 100, labelPaint);
566 canvas->translate(80, 0);
567 if (SkBlendMode::kSrcOut == blend || SkBlendMode::kDstOut == blend) {
568 canvas->translate(-80 * 5, 100);
569 }
570 }
571##
572##
573
574#Subtopic Blend_Mode_Porter_Duff_2
575#Example
576#Width 480
577#Height 330
578 SkPaint srcPaint;
579 srcPaint.setAntiAlias(true);
580 SkPaint labelPaint = srcPaint;
581 labelPaint.setTextAlign(SkPaint::kCenter_Align);
582 labelPaint.setTextSize(16);
583 SkPaint dstPaint = labelPaint;
584 dstPaint.setTextSize(80);
585 dstPaint.setColor(0xFF606080);
586 dstPaint.setTypeface(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()));
587
588 srcPaint.setColor(0xFFcc6633);
589 SkPath srcPath;
590 const SkPoint points[] = {{20, 20}, {80, 45}, {45, 80}};
591 srcPath.addPoly(points, SK_ARRAY_COUNT(points), true);
592 canvas->drawColor(0, SkBlendMode::kClear);
593
594 SkBitmap dstBits;
595 dstBits.allocN32Pixels(80, 80);
596 SkCanvas dstCanvas(dstBits);
597 for (auto blend : { SkBlendMode::kSrc, SkBlendMode::kSrcATop, SkBlendMode::kSrcOver,
598 SkBlendMode::kSrcIn, SkBlendMode::kSrcOut,
599 SkBlendMode::kDst, SkBlendMode::kDstATop, SkBlendMode::kDstOver,
600 SkBlendMode::kDstIn, SkBlendMode::kDstOut,
601 SkBlendMode::kClear, SkBlendMode::kXor } ) {
602 canvas->drawString("&", 50, 80, dstPaint);
603 srcPaint.setBlendMode(blend);
604 canvas->drawPath(srcPath, srcPaint);
605 canvas->drawString(SkBlendMode_Name(blend), 50, 100, labelPaint);
606 canvas->translate(80, 0);
607 if (SkBlendMode::kSrcOut == blend || SkBlendMode::kDstOut == blend) {
608 canvas->translate(-80 * 5, 100);
609 }
610 }
611##
612##
613
614#Subtopic Blend_Mode_Lighten_Darken
615#Example
616#Width 480
617#Height 330
618 SkPaint srcPaint;
619 srcPaint.setAntiAlias(true);
620 SkPaint labelPaint = srcPaint;
621 labelPaint.setTextAlign(SkPaint::kCenter_Align);
622 labelPaint.setTextSize(16);
623 SkPaint dstPaint = labelPaint;
624 dstPaint.setTextSize(80);
625 dstPaint.setColor(0xFF606080);
626 dstPaint.setTypeface(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()));
627
628 srcPaint.setColor(0xFFcc6633);
629 SkPath srcPath;
630 const SkPoint points[] = {{20, 20}, {80, 45}, {45, 80}};
631 srcPath.addPoly(points, SK_ARRAY_COUNT(points), true);
632 canvas->drawColor(0, SkBlendMode::kClear);
633 for (auto blend : { SkBlendMode::kPlus, SkBlendMode::kScreen, SkBlendMode::kOverlay,
634 SkBlendMode::kDarken, SkBlendMode::kLighten, SkBlendMode::kColorDodge,
635 SkBlendMode::kColorBurn, SkBlendMode::kHardLight, SkBlendMode::kSoftLight,
636 SkBlendMode::kDifference, SkBlendMode::kExclusion, SkBlendMode::kMultiply } ) {
637 canvas->drawString("&", 50, 80, dstPaint);
638 srcPaint.setBlendMode(blend);
639 canvas->drawPath(srcPath, srcPaint);
640 canvas->drawString(SkBlendMode_Name(blend), 50, 100, labelPaint);
641 canvas->translate(90, 0);
642 if (SkBlendMode::kLighten == blend || SkBlendMode::kDifference == blend) {
643 canvas->translate(-90 * 5, 100);
644 }
645 }
646##
647##
648
649#Subtopic Blend_Mode_Color_Blends
650#Example
651#Width 480
652#Height 110
653 SkPaint srcPaint;
654 srcPaint.setAntiAlias(true);
655 SkPaint labelPaint = srcPaint;
656 labelPaint.setTextAlign(SkPaint::kCenter_Align);
657 labelPaint.setTextSize(16);
658 SkPaint dstPaint = labelPaint;
659 dstPaint.setTextSize(80);
660 dstPaint.setColor(0xFF606080);
661 dstPaint.setTypeface(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()));
662
663 srcPaint.setColor(0xFFcc6633);
664 SkPath srcPath;
665 const SkPoint points[] = {{20, 20}, {80, 45}, {45, 80}};
666 srcPath.addPoly(points, SK_ARRAY_COUNT(points), true);
667 canvas->drawColor(0, SkBlendMode::kClear);
668 for (auto blend : { SkBlendMode::kHue, SkBlendMode::kSaturation, SkBlendMode::kColor,
669 SkBlendMode::kLuminosity } ) {
670 canvas->drawString("&", 50, 80, dstPaint);
671 srcPaint.setBlendMode(blend);
672 canvas->drawPath(srcPath, srcPaint);
673 canvas->drawString(SkBlendMode_Name(blend), 50, 100, labelPaint);
674 canvas->translate(90, 0);
675 }
676##
677##
678
679#Subtopic Blend_Mode_Modulate_Blend
680#Example
681#Width 480
682#Height 110
683 SkPaint srcPaint;
684 srcPaint.setAntiAlias(true);
685 SkPaint labelPaint = srcPaint;
686 labelPaint.setTextAlign(SkPaint::kCenter_Align);
687 labelPaint.setTextSize(16);
688 SkPaint dstPaint = labelPaint;
689 dstPaint.setTextSize(80);
690 dstPaint.setColor(0xFF606080);
691 dstPaint.setTypeface(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()));
692
693 SkBitmap srcBits;
694 srcBits.allocN32Pixels(80, 84);
695 SkCanvas srcCanvas(srcBits);
696 srcPaint.setColor(0xFFcc6633);
697 SkPath srcPath;
698 const SkPoint points[] = {{20, 20}, {80, 45}, {45, 80}};
699 srcPath.addPoly(points, SK_ARRAY_COUNT(points), true);
700 srcBits.eraseColor(0);
701 srcCanvas.drawPath(srcPath, srcPaint);
702
703 canvas->drawColor(0, SkBlendMode::kClear);
704 srcPaint.setBlendMode(SkBlendMode::kModulate);
705 for (auto step: { 1, 2 } ) {
706 canvas->drawString("&", 50, 80, dstPaint);
707 if (1 == step) {
708 canvas->drawBitmap(srcBits, 0, 0, &srcPaint);
709 canvas->drawString("Bitmap", 50, 18, labelPaint);
710 } else {
711 canvas->drawPath(srcPath, srcPaint);
712 canvas->drawString("Geometry", 50, 18, labelPaint);
713 }
714 canvas->drawString(SkBlendMode_Name(SkBlendMode::kModulate), 50, 100, labelPaint);
715 canvas->translate(120, 0);
716 }
717
718##
719##
720
Cary Clark153e76d2018-08-28 11:48:28 -0400721#Subtopic Path_Arc
722#Example
723#Height 300
724#Width 600
725#Function
726###$
727#include "SkTextOnPath.h"
728struct data {
729 const char* name;
730 char super;
731 int yn[10];
732};
733
734const data dataSet[] = {
735{ "arcTo sweep", '1', {1, 3, 1, 0, 0, 0, 0, 1, 0, 0 }},
736{ "drawArc", 0, {1, -1, 1, 1, 1, 1, 1, 0, 0, 0 }},
737{ "addArc", 0, {1, 1, 1, 4, 0, 1, 1, 1, 0, 0 }},
738{ "arcTo tangents", '4', {0, 0, 0, 0, 0, 0, 0, 1, 1, 0 }},
739{ "arcTo radii", '5', {1, 0, 1, 0, 0, 0, 0, 1, 1, 0 }},
740{ "conicTo", 0, {1, 1, 0, 0, 0, 0, 0, 1, 1, 1 }}
741};
742
743#define __degree_symbol__ "\xC2" "\xB0"
744
745const char* headers[] = {
746 "Oval part",
747 "force moveTo",
748 "can draw 180" __degree_symbol__,
749 "can draw 360" __degree_symbol__,
750 "can draw greater than 360" __degree_symbol__,
751 "ignored if radius is zero",
752 "ignored if sweep is zero",
753 "requires Path",
754 "describes rotation",
755 "describes perspective",
756};
757
758const char* yna[] = {
759 "n/a",
760 "no",
761 "yes"
762};
763$$$#
764##
765void draw(SkCanvas* canvas) {
766 SkPaint lp;
767 lp.setAntiAlias(true);
768 SkPaint tp(lp);
769 SkPaint sp(tp);
770 SkPaint bp(tp);
771 bp.setFakeBoldText(true);
772 sp.setTextSize(10);
773 lp.setColor(SK_ColorGRAY);
774 canvas->translate(0, 32);
775 const int tl = 115;
776 for (unsigned col = 0; col <= SK_ARRAY_COUNT(headers); ++col) {
777 canvas->drawLine(tl + col * 35, 100, tl + col * 35, 250, lp);
778 if (0 == col) {
779 continue;
780 }
781 canvas->drawLine(tl + col * 35, 100, tl + 100 + col * 35, 0, lp);
782 SkPath path;
783 path.moveTo(tl - 3 + col * 35, 103);
784 path.lineTo(tl + 124 + col * 35, -24);
785 SkMatrix matrix;
786 matrix.setTranslate(0, -9);
787 SkDrawTextOnPath(headers[col -1], strlen(headers[col -1]), bp, path, &matrix, canvas);
788 }
789 for (unsigned row = 0; row <= SK_ARRAY_COUNT(dataSet); ++row) {
790 if (0 == row) {
791 canvas->drawLine(tl, 100, tl + 350, 100, lp);
792 } else {
793 canvas->drawLine(5, 100 + row * 25, tl + 350, 100 + row * 25, lp);
794 }
795 if (row == SK_ARRAY_COUNT(dataSet)) {
796 break;
797 }
798 canvas->drawString(dataSet[row].name, 5, 117 + row * 25, bp);
799 if (dataSet[row].super) {
800 SkScalar width = bp.measureText(dataSet[row].name, strlen(dataSet[row].name));
801 canvas->drawText(&dataSet[row].super, 1, 8 + width, 112 + row * 25, sp);
802 }
803 for (unsigned col = 0; col < SK_ARRAY_COUNT(headers); ++col) {
804 int val = dataSet[row].yn[col];
805 canvas->drawString(yna[SkTMin(2, val + 1)], tl + 5 + col * 35, 117 + row * 25, tp);
806 if (val > 1) {
807 char supe = '0' + val - 1;
808 canvas->drawText(&supe, 1, tl + 25 + col * 35, 112 + row * 25, sp);
809 }
810 }
811 }
812}
813#Example ##
814##
815
Cary Clark681287e2018-03-16 11:34:15 -0400816#Topic Illustrations ##