1#Topic Illustrations
2
3#Subtopic Image_Info_Color_Type_BGR_565
4#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    };
46    SkScalar edges[] = { 0, 5, 11, 16,
47                         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
57#Subtopic Image_Info_Color_Type_ABGR_4444
58#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
159#Subtopic Image_Info_Color_Type_RGB_888x
160#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
326#Subtopic Image_Info_Color_Type_RGB_101010x
327#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
452#Topic Illustrations ##
453