aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/SkBitmap_Reference.bmh
blob: 5bf8e1b2e4c8e28802fcc229dab1f8492eea7b5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
#Topic Bitmap
#Alias Bitmaps ##
#Alias Bitmap_Reference ##

#Class SkBitmap

Bitmap describes a two-dimensional raster pixel array. Bitmap is built on
Image_Info, containing integer width and height, Color_Type and Alpha_Type
describing the pixel format, and Color_Space describing the range of colors.
Bitmap points to Pixel_Ref, which describes the physical array of pixels.
Image_Info bounds may be located anywhere fully inside Pixel_Ref bounds.

Bitmap can be drawn using Canvas. Bitmap can be a drawing destination for Canvas
draw member functions. Bitmap flexibility as a pixel container limits some
optimizations available to the target platform.

If pixel array is primarily read-only, use Image for better performance.
If pixel array is primarily written to, use Surface for better performance.

Declaring SkBitmap const prevents altering Image_Info: the Bitmap height, width,
and so on cannot change. It does not affect Pixel_Ref: a caller may write its
pixels. Declaring SkBitmap const affects Bitmap configuration, not its contents.

Bitmap is not thread safe. Each thread must have its own copy of Bitmap fields,
although threads may share the underlying pixel array.

#Subtopic Row_Bytes
#Line # interval from one row to the next ##
Bitmap pixels may be contiguous, or may have a gap at the end of each row.
Row_Bytes is the interval from one row to the next. Row_Bytes may be specified;
sometimes passing zero will compute the Row_Bytes from the row width and the
number of bytes in a pixel. Row_Bytes may be larger than the row requires. This
is useful to position one or more Bitmaps within a shared pixel array.
##

#Subtopic Overview
    #Populate
##

#Subtopic Related_Function
#Populate
##

#Subtopic Constant
#Populate
##

#Subtopic Class
#Populate
##

#Subtopic Constructor
#Populate
##

#Subtopic Operator
#Populate
##

#Subtopic Member_Function
#Populate
##

# ------------------------------------------------------------------------------

#Class Allocator
#Line # abstract subclass of HeapAllocator ##
#Code
    class Allocator : public SkRefCnt {
    public:
        virtual bool allocPixelRef(SkBitmap* bitmap) = 0;
    };
##

Abstract subclass of HeapAllocator.

# ------------------------------------------------------------------------------

#Method virtual bool allocPixelRef(SkBitmap* bitmap) = 0

Allocates the pixel memory for the bitmap, given its dimensions and
Color_Type. Returns true on success, where success means either setPixels
or setPixelRef was called.

#Param bitmap  Bitmap containing Image_Info as input, and Pixel_Ref as output ##

#Return  true if Pixel_Ref was allocated ##

#NoExample
##

#SeeAlso HeapAllocator

##

#Class Allocator ##

# ------------------------------------------------------------------------------

#Class HeapAllocator
#Line # allocates pixel memory from heap ##

#Code
    class HeapAllocator : public Allocator {
    public:
        bool allocPixelRef(SkBitmap* bitmap) override;
    };
##

Subclass of SkBitmap::Allocator that returns a Pixel_Ref that allocates its pixel
memory from the heap. This is the default SkBitmap::Allocator invoked by
allocPixels.

# ------------------------------------------------------------------------------

#Method bool allocPixelRef(SkBitmap* bitmap) override
#Line # allocates pixel memory ##
Allocates the pixel memory for the bitmap, given its dimensions and
Color_Type. Returns true on success, where success means either setPixels
or setPixelRef was called.

#Param bitmap  Bitmap containing Image_Info as input, and Pixel_Ref as output ##

#Return  true if pixels are allocated ##

#Example
    SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType));
    SkDebugf("pixel address = %p\n", bitmap.getPixels());
    SkBitmap::HeapAllocator stdalloc;
    if (!stdalloc.allocPixelRef(&bitmap)) {
        SkDebugf("pixel allocation failed\n");
    } else {
        SkDebugf("pixel address = %p\n", bitmap.getPixels());
    }
#StdOut
#Volatile
pixel address = (nil)
pixel address = 0x560ddd0ac670
##
##

#SeeAlso SkBitmap::Allocator tryAllocPixels

##

#Class HeapAllocator ##

# ------------------------------------------------------------------------------

#Method SkBitmap()

#Line # constructs with default values ##
Creates an empty Bitmap without pixels, with kUnknown_SkColorType,
kUnknown_SkAlphaType, and with a width and height of zero. Pixel_Ref origin is
set to (0, 0). Bitmap is not volatile.

Use setInfo to associate SkColorType, SkAlphaType, width, and height
after Bitmap has been created.

#Return  empty Bitmap ##

#Example
void draw(SkCanvas* canvas) {
    const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
    const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
                            "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
    SkBitmap bitmap;
    for (int i = 0; i < 2; ++i) {
       SkDebugf("width: %2d  height: %2d", bitmap.width(), bitmap.height());
       SkDebugf("  color: k%s_SkColorType", colors[bitmap.colorType()]);
       SkDebugf("  alpha: k%s_SkAlphaType\n", alphas[bitmap.alphaType()]);
       bitmap.setInfo(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
                      0);
    }
}
#StdOut
width:  0  height:  0  color: kUnknown_SkColorType  alpha: kUnknown_SkAlphaType
width: 25  height: 35  color: kRGBA_8888_SkColorType  alpha: kOpaque_SkAlphaType
##
##

#SeeAlso setInfo

##

# ------------------------------------------------------------------------------

#Method SkBitmap(const SkBitmap& src)

#Line # shares ownership of pixels ##
Copies settings from src to returned Bitmap. Shares pixels if src has pixels
allocated, so both bitmaps reference the same pixels.

#Param src  Bitmap to copy Image_Info, and share Pixel_Ref ##

#Return  copy of src ##

#Example
void draw(SkCanvas* canvas) {
    SkBitmap original;
    if (original.tryAllocPixels(
            SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
        SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false");
        SkBitmap copy(original);
        SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false");
        SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
    }
}
#StdOut
original has pixels before copy: true
original has pixels after copy: true
copy has pixels: true
##
##

#SeeAlso setInfo setPixelRef setPixels swap

##

# ------------------------------------------------------------------------------

#Method SkBitmap(SkBitmap&& src)

#Line # takes ownership of pixels ##
Copies settings from src to returned Bitmap. Moves ownership of src pixels to
Bitmap.

#Param src  Bitmap to copy Image_Info, and reassign Pixel_Ref ##

#Return  copy of src ##

#Example
void draw(SkCanvas* canvas) {
    SkBitmap original;
    if (original.tryAllocPixels(
            SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
        SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false");
        SkBitmap copy(std::move(original));
        SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false");
        SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
    }
}
#StdOut
original has pixels before move: true
original has pixels after move: false
copy has pixels: true
##
##

#SeeAlso setInfo setPixelRef setPixels swap

##

# ------------------------------------------------------------------------------

#Method ~SkBitmap()

#Line # releases ownership of pixels ##
Decrements Pixel_Ref reference count, if Pixel_Ref is not nullptr.

#NoExample
##

#SeeAlso Pixel_Ref

##

# ------------------------------------------------------------------------------

#Method SkBitmap& operator=(const SkBitmap& src)

#Line # shares ownership of pixels ##
Copies settings from src to returned Bitmap. Shares pixels if src has pixels
allocated, so both bitmaps reference the same pixels.

#Param src  Bitmap to copy Image_Info, and share Pixel_Ref ##

#Return  copy of src ##

#Example
void draw(SkCanvas* canvas) {
    SkBitmap original;
    if (original.tryAllocPixels(
            SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
        SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false");
        SkBitmap copy = original;
        SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false");
        SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
    }
}
#StdOut
original has pixels before copy: true
original has pixels after copy: true
copy has pixels: true
##
##

#SeeAlso setInfo setPixelRef setPixels swap

##

# ------------------------------------------------------------------------------

#Method SkBitmap& operator=(SkBitmap&& src)

#Line # takes ownership of pixels ##
Copies settings from src to returned Bitmap. Moves ownership of src pixels to
Bitmap.

#Param src  Bitmap to copy Image_Info, and reassign Pixel_Ref ##

#Return  copy of src ##

#Example
void draw(SkCanvas* canvas) {
    SkBitmap original;
    if (original.tryAllocPixels(
            SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
        SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false");
        SkBitmap copy = std::move(original);
        SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false");
        SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
    }
}
#StdOut
original has pixels before move: true
original has pixels after move: false
copy has pixels: true
##
##

#SeeAlso setInfo setPixelRef setPixels swap

##

# ------------------------------------------------------------------------------

#Method void swap(SkBitmap& other)
#In Utility
#Line # exchanges Bitmap pair ##
Swaps the fields of the two bitmaps.

#Param other  Bitmap exchanged with original ##

#Example
void draw(SkCanvas* canvas) {
    auto debugster = [](const char* prefix, const SkBitmap& b) -> void {
        const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
        const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
                                "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
        SkDebugf("%s width:%d height:%d colorType:k%s_SkColorType alphaType:k%s_SkAlphaType\n",
                 prefix, b.width(), b.height(), colors[b.colorType()], alphas[b.alphaType()]);
    };
    SkBitmap one, two;
    if (!one.tryAllocPixels(
            SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
        return;
    }
    if (!two.tryAllocPixels(
            SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType))) {
        return;
    }
    for (int index = 0; index < 2; ++index) {
       debugster("one", one);
       debugster("two", two);
       one.swap(two);
    }
}
#StdOut
one width:1 height:1 colorType:kRGBA_8888_SkColorType alphaType:kOpaque_SkAlphaType
two width:2 height:2 colorType:kBGRA_8888_SkColorType alphaType:kPremul_SkAlphaType
one width:2 height:2 colorType:kBGRA_8888_SkColorType alphaType:kPremul_SkAlphaType
two width:1 height:1 colorType:kRGBA_8888_SkColorType alphaType:kOpaque_SkAlphaType
##
##

#SeeAlso SkBitmap(SkBitmap&& src) operator=(SkBitmap&& src)

##

# ------------------------------------------------------------------------------
#Subtopic Property
#Populate
#Line # metrics and attributes ##
##

#Method const SkPixmap& pixmap() const
#In Property
#Line # returns Pixmap ##
Returns a constant reference to the Pixmap holding the Bitmap pixel
address, row bytes, and Image_Info.

#Return reference to Pixmap describing this Bitmap ##

#Example
    SkBitmap bitmap;
    bitmap.allocPixels(SkImageInfo::MakeN32Premul(10, 11));
    SkCanvas offscreen(bitmap);
    offscreen.clear(SK_ColorWHITE);
    SkPaint paint;
    offscreen.drawString("&", 0, 10, paint);
    const SkPixmap& pixmap = bitmap.pixmap();
    if (pixmap.addr()) {
        SkPMColor pmWhite = *pixmap.addr32(0, 0);
        for (int y = 0; y < pixmap.height(); ++y) {
            for (int x = 0; x < pixmap.width(); ++x) {
                SkDebugf("%c", *pixmap.addr32(x, y) == pmWhite ? '-' : 'x');
            }
            SkDebugf("\n");
        }
    }
    #StdOut
----------
---xx-----
--x--x----
--x-------
--xx------
--x-x---x-
-x---x--x-
-x----xx--
-xx---x---
--xxxx-xx-
----------
    #StdOut ##

##

#SeeAlso peekPixels installPixels readPixels writePixels

##

# ------------------------------------------------------------------------------

#Method const SkImageInfo& info() const
#In Property
#Line # returns Image_Info ##
Returns width, height, Alpha_Type, Color_Type, and Color_Space.

#Return reference to Image_Info  ##

#Example
#Image 4
void draw(SkCanvas* canvas) {
    // SkBitmap source;  // pre-populated with soccer ball by fiddle.skia.org
    const SkImageInfo& info = source.info();
    const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
    const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
                            "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
    SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(),
                colors[info.colorType()], alphas[info.alphaType()]);
#StdOut
width: 56 height: 56 color: BGRA_8888 alpha: Opaque
##
}
##

#SeeAlso Image_Info

##

# ------------------------------------------------------------------------------

#Method int width() const
#In Property
#Line # returns pixel column count ##
Returns pixel count in each row. Should be equal or less than:

#Formula
rowBytes() / info().bytesPerPixel()
##
.

May be less than pixelRef().width(). Will not exceed pixelRef().width() less
pixelRefOrigin().fX.

#Return  pixel width in Image_Info ##

#Example
    SkImageInfo info = SkImageInfo::MakeA8(16, 32);
    SkBitmap bitmap;
    bitmap.setInfo(info);
    SkDebugf("bitmap width: %d  info width: %d\n", bitmap.width(), info.width());
#StdOut
bitmap width: 16  info width: 16
##
##

#SeeAlso height() SkPixelRef::width() SkImageInfo::width()

##

# ------------------------------------------------------------------------------

#Method int height() const
#In Property
#Line # returns pixel row count ##
Returns pixel row count.

Maybe be less than pixelRef().height(). Will not exceed pixelRef().height() less
pixelRefOrigin().fY.

#Return pixel height in Image_Info ##

#Example
    SkImageInfo info = SkImageInfo::MakeA8(16, 32);
    SkBitmap bitmap;
    bitmap.setInfo(info);
    SkDebugf("bitmap height: %d  info height: %d\n", bitmap.height(), info.height());
#StdOut
bitmap height: 32  info height: 32
##
##

#SeeAlso width() SkPixelRef::height() SkImageInfo::height()

##

# ------------------------------------------------------------------------------

#Method SkColorType colorType() const
#In Property
#Line # returns Image_Info Color_Type ##
Returns Color_Type, one of: #list_of_color_types#.

#Return  Color_Type in Image_Info ##

#Example
    const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
                            "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
    SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::MakeA8(16, 32));
    SkDebugf("color type: k" "%s" "_SkColorType\n", colors[bitmap.colorType()]);
#StdOut
color type: kAlpha_8_SkColorType
##
##

#SeeAlso alphaType() SkImageInfo::colorType

##

# ------------------------------------------------------------------------------

#Method SkAlphaType alphaType() const
#In Property
#Line # returns Image_Info Alpha_Type ##
Returns Alpha_Type, one of: #list_of_alpha_types#.

#Return  Alpha_Type in Image_Info ##

#Example
    const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
    SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
    SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]);
#StdOut
alpha type: kPremul_SkAlphaType
##
##

#SeeAlso colorType() SkImageInfo::alphaType

##

# ------------------------------------------------------------------------------

#Method SkColorSpace* colorSpace() const
#In Property
#Line # returns Image_Info Color_Space ##
Returns Color_Space, the range of colors, associated with Image_Info. The
reference count of Color_Space is unchanged. The returned Color_Space is
immutable.

#Return Color_Space in Image_Info, or nullptr ##

#Example
#Description
SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
##
    SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
            SkColorSpace::MakeSRGBLinear()));
    SkColorSpace* colorSpace = bitmap.colorSpace();
    SkDebugf("gammaCloseToSRGB: %s  gammaIsLinear: %s  isSRGB: %s\n",
            colorSpace->gammaCloseToSRGB() ? "true" : "false",
            colorSpace->gammaIsLinear() ? "true" : "false",
            colorSpace->isSRGB() ? "true" : "false");
#StdOut
gammaCloseToSRGB: false  gammaIsLinear: true  isSRGB: false
##
##

#SeeAlso Color_Space SkImageInfo::colorSpace

##

# ------------------------------------------------------------------------------

#Method sk_sp<SkColorSpace> refColorSpace() const
#In Property
#Line # returns Image_Info Color_Space ##
Returns smart pointer to Color_Space, the range of colors, associated with
Image_Info. The smart pointer tracks the number of objects sharing this
Color_Space reference so the memory is released when the owners destruct.

The returned Color_Space is immutable.

#Return Color_Space in Image_Info wrapped in a smart pointer ##

#Example
    SkBitmap bitmap1, bitmap2;
    bitmap1.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
            SkColorSpace::MakeSRGBLinear()));
    bitmap2.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
            bitmap1.refColorSpace()));
    SkColorSpace* colorSpace = bitmap2.colorSpace();
    SkDebugf("gammaCloseToSRGB: %s  gammaIsLinear: %s  isSRGB: %s\n",
            colorSpace->gammaCloseToSRGB() ? "true" : "false",
            colorSpace->gammaIsLinear() ? "true" : "false",
            colorSpace->isSRGB() ? "true" : "false");
#StdOut
gammaCloseToSRGB: false  gammaIsLinear: true  isSRGB: false
##
##

#SeeAlso Color_Space SkImageInfo::colorSpace

##

# ------------------------------------------------------------------------------

#Method int bytesPerPixel() const
#In Property
#Line # returns number of bytes in pixel based on Color_Type ##
Returns number of bytes per pixel required by Color_Type.
Returns zero if colorType( is kUnknown_SkColorType.

#Return  bytes in pixel ##

#Example
    const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
                            "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
    SkImageInfo info = SkImageInfo::MakeA8(1, 1);
    SkBitmap bitmap;
    for (SkColorType colorType : { #list_of_color_types#
                                 } ) {
        bitmap.setInfo(info.makeColorType(colorType));
        SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n",
                colors[colorType], 13 - strlen(colors[colorType]), " ",
                bitmap.bytesPerPixel());
    }
#StdOut
color: kUnknown_SkColorType      bytesPerPixel: 0
color: kAlpha_8_SkColorType      bytesPerPixel: 1
color: kRGB_565_SkColorType      bytesPerPixel: 2
color: kARGB_4444_SkColorType    bytesPerPixel: 2
color: kRGBA_8888_SkColorType    bytesPerPixel: 4
color: kRGB_888x_SkColorType     bytesPerPixel: 4
color: kBGRA_8888_SkColorType    bytesPerPixel: 4
color: kRGBA_1010102_SkColorType bytesPerPixel: 4
color: kRGB_101010x_SkColorType  bytesPerPixel: 4
color: kGray_8_SkColorType       bytesPerPixel: 1
color: kRGBA_F16_SkColorType     bytesPerPixel: 8
##
##

#SeeAlso rowBytes rowBytesAsPixels width shiftPerPixel SkImageInfo::bytesPerPixel

##

# ------------------------------------------------------------------------------

#Method int rowBytesAsPixels() const
#In Property
#Line # returns interval between rows in pixels ##
Returns number of pixels that fit on row. Should be greater than or equal to
width().

#Return  maximum pixels per row ##

#Example
    SkBitmap bitmap;
    for (int rowBytes : { 4, 5, 6, 7, 8} ) {
        bitmap.setInfo(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), rowBytes);
        SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, bitmap.rowBytesAsPixels());
    }
#StdOut
rowBytes: 4 rowBytesAsPixels: 1
rowBytes: 5 rowBytesAsPixels: 1
rowBytes: 6 rowBytesAsPixels: 1
rowBytes: 7 rowBytesAsPixels: 1
rowBytes: 8 rowBytesAsPixels: 2
##
##

#SeeAlso rowBytes shiftPerPixel width bytesPerPixel

##

# ------------------------------------------------------------------------------

#Method int shiftPerPixel() const
#In Property
#Line # returns bit shift from pixels to bytes ##
Returns bit shift converting row bytes to row pixels.
Returns zero for kUnknown_SkColorType.

#Return one of: 0, 1, 2, 3; left shift to convert pixels to bytes ##

#Example
    const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
                            "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
    SkImageInfo info = SkImageInfo::MakeA8(1, 1);
    SkBitmap bitmap;
    for (SkColorType colorType : { #list_of_color_types#
                                 } ) {
        bitmap.setInfo(info.makeColorType(colorType));
        SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n",
                colors[colorType], 14 - strlen(colors[colorType]), " ",
                bitmap.shiftPerPixel());
    }
#StdOut
color: kUnknown_SkColorType       shiftPerPixel: 0
color: kAlpha_8_SkColorType       shiftPerPixel: 0
color: kRGB_565_SkColorType       shiftPerPixel: 1
color: kARGB_4444_SkColorType     shiftPerPixel: 1
color: kRGBA_8888_SkColorType     shiftPerPixel: 2
color: kRGB_888x_SkColorType      shiftPerPixel: 2
color: kBGRA_8888_SkColorType     shiftPerPixel: 2
color: kRGBA_1010102_SkColorType  shiftPerPixel: 2
color: kRGB_101010x_SkColorType   shiftPerPixel: 2
color: kGray_8_SkColorType        shiftPerPixel: 0
color: kRGBA_F16_SkColorType      shiftPerPixel: 3
##
##

#SeeAlso rowBytes rowBytesAsPixels width bytesPerPixel

##

# ------------------------------------------------------------------------------

#Method bool empty() const
#In Property
#Line # returns true if Image_Info has zero width() or height() ##
Returns true if either width() or height() are zero.

Does not check if Pixel_Ref is nullptr; call drawsNothing to check width(),
height(), and Pixel_Ref.

#Return  true if dimensions do not enclose area ##

#Example
    SkBitmap bitmap;
    for (int width : { 0, 2 } ) {
        for (int height : { 0, 2 } ) {
             bitmap.setInfo(SkImageInfo::MakeA8(width, height));
             SkDebugf("width: %d height: %d empty: %s\n", width, height,
                      bitmap.empty() ? "true" : "false");
        }
    }
#StdOut
width: 0 height: 0 empty: true
width: 0 height: 2 empty: true
width: 2 height: 0 empty: true
width: 2 height: 2 empty: false
##
##

#SeeAlso height() width() drawsNothing

##

# ------------------------------------------------------------------------------

#Method bool isNull() const
#In Property
#Line # returns true if Pixel_Ref is nullptr ##
Returns true if Pixel_Ref is nullptr.

Does not check if width() or height() are zero; call drawsNothing to check
width(), height(), and Pixel_Ref.

#Return  true if no Pixel_Ref is associated ##

#Example
    SkBitmap bitmap;
    SkDebugf("empty bitmap does %shave pixels\n", bitmap.isNull() ? "not " : "");
    bitmap.setInfo(SkImageInfo::MakeA8(8, 8));
    SkDebugf("bitmap with dimensions does %shave pixels\n", bitmap.isNull() ? "not " : "");
    bitmap.allocPixels();
    SkDebugf("allocated bitmap does %shave pixels\n", bitmap.isNull() ? "not " : "");
#StdOut
empty bitmap does not have pixels
bitmap with dimensions does not have pixels
allocated bitmap does have pixels
##
##

#SeeAlso empty() drawsNothing pixelRef

##

# ------------------------------------------------------------------------------

#Method bool drawsNothing() const
#In Property
#Line # returns true if no width(), no height(), or no Pixel_Ref ##
Returns true if width() or height() are zero, or if Pixel_Ref is nullptr.
If true, Bitmap has no effect when drawn or drawn into.

#Return  true if drawing has no effect ##

#Example
    SkBitmap bitmap;
    for (int w : { 0, 8 } ) {
        for (bool allocate : { false, true} ) {
            bitmap.setInfo(SkImageInfo::MakeA8(w, 8));
            allocate ? bitmap.allocPixels() : (void) 0 ;
            SkDebugf("empty:%s isNull:%s drawsNothing:%s\n", bitmap.empty() ? "true " : "false",
                     bitmap.isNull() ? "true " : "false", bitmap.drawsNothing() ? "true" : "false");
        }
    }
#StdOut
empty:true  isNull:true  drawsNothing:true
empty:true  isNull:false drawsNothing:true
empty:false isNull:true  drawsNothing:true
empty:false isNull:false drawsNothing:false
##
##

#SeeAlso empty() isNull pixelRef

##

# ------------------------------------------------------------------------------

#Method size_t rowBytes() const
#In Property
#Line # returns interval between rows in bytes ##
Returns row bytes, the interval from one pixel row to the next. Row bytes
is at least as large as
#Formula
width() * info().bytesPerPixel()
##
.

Returns zero if colorType is kUnknown_SkColorType, or if row bytes supplied to
setInfo is not large enough to hold a row of pixels.

#Return  byte length of pixel row ##

#Example
   SkBitmap bitmap;
   for (int rowBytes : { 2, 8 } ) {
       bool result = bitmap.setInfo(SkImageInfo::MakeA8(4, 4), rowBytes);
       SkDebugf("setInfo returned:%s rowBytes:%d\n", result ? "true " : "false", bitmap.rowBytes());
    }
#StdOut
setInfo returned:false rowBytes:0
setInfo returned:true  rowBytes:8
##
##

#SeeAlso info() setInfo SkImageInfo::minRowBytes

##

# ------------------------------------------------------------------------------

#Method bool setAlphaType(SkAlphaType alphaType)
#In Set
#Line # sets Alpha_Type of shared pixels ##
Sets Alpha_Type, if alphaType is compatible with Color_Type.
Returns true unless alphaType is kUnknown_SkAlphaType and current Alpha_Type
is not kUnknown_SkAlphaType.

Returns true if Color_Type is kUnknown_SkColorType. alphaType is ignored, and
Alpha_Type remains kUnknown_SkAlphaType.

Returns true if Color_Type is kRGB_565_SkColorType or kGray_8_SkColorType.
alphaType is ignored, and Alpha_Type remains kOpaque_SkAlphaType.

If Color_Type is kARGB_4444_SkColorType, kRGBA_8888_SkColorType,
kBGRA_8888_SkColorType, or kRGBA_F16_SkColorType: returns true unless
alphaType is kUnknown_SkAlphaType and Alpha_Type is not kUnknown_SkAlphaType.
If Alpha_Type is kUnknown_SkAlphaType, alphaType is ignored.

If Color_Type is kAlpha_8_SkColorType, returns true unless
alphaType is kUnknown_SkAlphaType and Alpha_Type is not kUnknown_SkAlphaType.
If Alpha_Type is kUnknown_SkAlphaType, alphaType is ignored. If alphaType is
kUnpremul_SkAlphaType, it is treated as kPremul_SkAlphaType.

This changes Alpha_Type in Pixel_Ref; all bitmaps sharing Pixel_Ref
are affected.

#Param alphaType  one of: #list_of_alpha_types#
##

#Return  true if Alpha_Type is set ##

#Example
void draw(SkCanvas* canvas) {
    const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
                             "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
    const char* alphas[] = {"Unknown ", "Opaque  ", "Premul  ", "Unpremul"};
    SkBitmap bitmap;
    SkAlphaType alphaTypes[] = { #list_of_alpha_types#
                               };
    SkDebugf("%88s", "Canonical    Unknown           Opaque            Premul            Unpremul\n");
    for (SkColorType colorType : { #list_of_color_types#
                                 } ) {
        for (SkAlphaType canonicalAlphaType : alphaTypes) {
            SkColorTypeValidateAlphaType(colorType, kUnknown_SkAlphaType, &canonicalAlphaType );
            SkDebugf("%10s %10s ", colors[(int) colorType], alphas[(int) canonicalAlphaType ]);
            for (SkAlphaType alphaType : alphaTypes) {
                bitmap.setInfo(SkImageInfo::Make(4, 4, colorType, canonicalAlphaType));
                bool result = bitmap.setAlphaType(alphaType);
                SkDebugf("%s %s    ", result ? "true " : "false", alphas[(int) bitmap.alphaType()]);
            }
            SkDebugf("\n");
        }
    }
}
##

#SeeAlso Alpha_Type Color_Type Image_Info setInfo

##

# ------------------------------------------------------------------------------

#Method void* getPixels() const
#In Property
#Line # returns address of pixels ##
Returns pixel address, the base address corresponding to the pixel origin.

#Return  pixel address ##

#Example
    SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::MakeN32(4, 4, kPremul_SkAlphaType));
    bitmap.allocPixels();
    bitmap.eraseColor(0x00000000);
    void* baseAddr = bitmap.getPixels();
    *(SkPMColor*)baseAddr = 0xFFFFFFFF;
    SkDebugf("bitmap.getColor(0, 1) %c= 0x00000000\n",
              bitmap.getColor(0, 1)  == 0x00000000 ? '=' : '!');
    SkDebugf("bitmap.getColor(0, 0) %c= 0xFFFFFFFF\n",
              bitmap.getColor(0, 0)  == 0xFFFFFFFF ? '=' : '!');
#StdOut
bitmap.getColor(0, 1) == 0x00000000
bitmap.getColor(0, 0) == 0xFFFFFFFF
##
##

#SeeAlso isNull drawsNothing

##

# ------------------------------------------------------------------------------

#Method size_t computeByteSize() const
#In Utility
#Line # returns size required for pixels ##
Returns minimum memory required for pixel storage.
Does not include unused memory on last row when rowBytesAsPixels exceeds width().
Returns zero if result does not fit in size_t.
Returns zero if height() or width() is 0.
Returns height() times rowBytes if colorType is kUnknown_SkColorType.

#Return size in bytes of image buffer ##

#Example
    SkBitmap bitmap;
    for (int width : { 1, 1000, 1000000 } ) {
        for (int height: { 1, 1000, 1000000 } ) {
            SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
            bitmap.setInfo(imageInfo, width * 5);
            SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height,
                     bitmap.computeByteSize());
        }
    }
#StdOut
width:       1 height:       1 computeByteSize:             4
width:       1 height:    1000 computeByteSize:          4999
width:       1 height: 1000000 computeByteSize:       4999999
width:    1000 height:       1 computeByteSize:          4000
width:    1000 height:    1000 computeByteSize:       4999000
width:    1000 height: 1000000 computeByteSize:    4999999000
width: 1000000 height:       1 computeByteSize:       4000000
width: 1000000 height:    1000 computeByteSize:    4999000000
width: 1000000 height: 1000000 computeByteSize: 4999999000000
##
##

#SeeAlso SkImageInfo::computeByteSize

##

# ------------------------------------------------------------------------------

#Method bool isImmutable() const
#In Property
#Line # returns true if pixels will not change ##
Returns true if pixels can not change.

Most immutable Bitmap checks trigger an assert only on debug builds.

#Return  true if pixels are immutable ##

#Example
    SkBitmap original;
    SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
    if (original.tryAllocPixels(info)) {
        original.setImmutable();
        SkBitmap copy;
        original.extractSubset(&copy, {5, 10, 15, 20});
        SkDebugf("original is " "%s" "immutable\n", original.isImmutable() ? "" : "not ");
        SkDebugf("copy is " "%s" "immutable\n", copy.isImmutable() ? "" : "not ");
    }
#StdOut
original is immutable
copy is immutable
##
##

#SeeAlso setImmutable SkPixelRef::isImmutable SkImage

##

# ------------------------------------------------------------------------------

#Method void setImmutable()
#In Set
#Line # marks that pixels will not change ##
Sets internal flag to mark Bitmap as immutable. Once set, pixels can not change.
Any other bitmap sharing the same Pixel_Ref are also marked as immutable.
Once Pixel_Ref is marked immutable, the setting cannot be cleared.

Writing to immutable Bitmap pixels triggers an assert on debug builds.

#Example
#Description
Triggers assert if SK_DEBUG is true, runs fine otherwise.
##
    SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::MakeN32(4, 4, kPremul_SkAlphaType));
    bitmap.allocPixels();
    SkCanvas offscreen(bitmap);
    SkDebugf("draw white\n");
    offscreen.clear(SK_ColorWHITE);
    bitmap.setImmutable();
    SkDebugf("draw black\n");
    offscreen.clear(SK_ColorBLACK);
##

#SeeAlso isImmutable SkPixelRef::setImmutable SkImage

##

# ------------------------------------------------------------------------------

#Method bool isOpaque() const
#In Property
#Line # returns true if Image_Info describes opaque pixels ##

Returns true if Alpha_Type is set to hint that all pixels are opaque; their
Color_Alpha value is implicitly or explicitly 1.0. If true, and all pixels are
not opaque, Skia may draw incorrectly.

Does not check if Color_Type allows Alpha, or if any pixel value has
transparency.

#Return  true if Image_Info Alpha_Type is kOpaque_SkAlphaType ##

#Example
#Description
    isOpaque ignores whether all pixels are opaque or not.
##
    const int height = 2;
    const int width = 2;
    SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType));
    for (int index = 0; index < 2; ++index) {
        bitmap.allocPixels();
        bitmap.eraseColor(0x00000000);
        SkDebugf("isOpaque: %s\n", bitmap.isOpaque() ? "true" : "false");
        bitmap.eraseColor(0xFFFFFFFF);
        SkDebugf("isOpaque: %s\n", bitmap.isOpaque() ? "true" : "false");
        bitmap.setInfo(bitmap.info().makeAlphaType(kOpaque_SkAlphaType));
    }
#StdOut
isOpaque: false
isOpaque: false
isOpaque: true
isOpaque: true
##
##

#SeeAlso ComputeIsOpaque SkImageInfo::isOpaque

##

# ------------------------------------------------------------------------------

#Method bool isVolatile() const
#In Property
#Line # returns true if pixels should not be cached ##
Provides a hint to caller that pixels should not be cached. Only true if
setIsVolatile has been called to mark as volatile.

Volatile state is not shared by other bitmaps sharing the same Pixel_Ref.

#Return  true if marked volatile ##

#Example
    SkBitmap original;
    SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
    if (original.tryAllocPixels(info)) {
        original.setIsVolatile(true);
        SkBitmap copy;
        original.extractSubset(&copy, {5, 10, 15, 20});
        SkDebugf("original is " "%s" "volatile\n", original.isVolatile() ? "" : "not ");
        SkDebugf("copy is " "%s" "volatile\n", copy.isImmutable() ? "" : "not ");
    }
#StdOut
original is volatile
copy is not volatile
##
##

#SeeAlso setIsVolatile

##

# ------------------------------------------------------------------------------

#Method void setIsVolatile(bool isVolatile)
#In Set
#Line # marks if pixels should not be cached ##
Sets if pixels should be read from Pixel_Ref on every access. Bitmaps are not
volatile by default; a GPU back end may upload pixel values expecting them to be
accessed repeatedly. Marking temporary Bitmaps as volatile provides a hint to
Device that the Bitmap pixels should not be cached. This can
improve performance by avoiding overhead and reducing resource
consumption on Device.

#Param isVolatile  true if backing pixels are temporary ##

#Example
#Height 20
    SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType));
    bitmap.allocPixels();
    bitmap.eraseColor(SK_ColorRED);
    canvas->scale(16, 16);
    canvas->drawBitmap(bitmap, 0, 0);
    *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorBLUE);
    canvas->drawBitmap(bitmap, 2, 0);
    bitmap.setIsVolatile(true);
    *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorGREEN);
    canvas->drawBitmap(bitmap, 4, 0);
##

#SeeAlso isVolatile

##

# ------------------------------------------------------------------------------

#Method void reset()
#In Constructor
#Line # sets to default values, releases pixel ownership ##
Resets to its initial state; all fields are set to zero, as if Bitmap had
been initialized by SkBitmap().

Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to
kUnknown_SkColorType; and SkAlphaType to kUnknown_SkAlphaType.

If Pixel_Ref is allocated, its reference count is decreased by one, releasing
its memory if Bitmap is the sole owner.

#Example
    SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType));
    bitmap.allocPixels();
    SkDebugf("width:%d height:%d isNull:%s\n", bitmap.width(), bitmap.height(),
             bitmap.isNull() ? "true" : "false");
    bitmap.reset();
    SkDebugf("width:%d height:%d isNull:%s\n", bitmap.width(), bitmap.height(),
             bitmap.isNull() ? "true" : "false");
#StdOut
width:1 height:1 isNull:false
width:0 height:0 isNull:true
##
##

#SeeAlso SkBitmap() SkAlphaType SkColorType

##

# ------------------------------------------------------------------------------

#Method static bool ComputeIsOpaque(const SkBitmap& bm)
#In Utility
#Line # returns true if all pixels are opaque ##
Returns true if all pixels are opaque. Color_Type determines how pixels
are encoded, and whether pixel describes Alpha. Returns true for Color_Types
without alpha in each pixel; for other Color_Types, returns true if all
pixels have alpha values equivalent to 1.0 or greater.

For Color_Types kRGB_565_SkColorType or kGray_8_SkColorType: always
returns true. For Color_Types kAlpha_8_SkColorType, kBGRA_8888_SkColorType,
kRGBA_8888_SkColorType: returns true if all pixel Alpha values are 255.
For Color_Type kARGB_4444_SkColorType: returns true if all pixel Alpha values are 15.
For kRGBA_F16_SkColorType: returns true if all pixel Alpha values are 1.0 or
greater.

Returns false for kUnknown_SkColorType.

#Param bm  Bitmap to check ##

#Return true if all pixels have opaque values or Color_Type is opaque ##

#Example
    SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::Make(2, 2, kN32_SkColorType, kPremul_SkAlphaType));
    for (int index = 0; index < 2; ++index) {
        bitmap.allocPixels();
        bitmap.eraseColor(0x00000000);
        SkDebugf("computeIsOpaque: %s\n", SkBitmap::ComputeIsOpaque(bitmap) ? "true" : "false");
        bitmap.eraseColor(0xFFFFFFFF);
        SkDebugf("computeIsOpaque: %s\n", SkBitmap::ComputeIsOpaque(bitmap) ? "true" : "false");
        bitmap.setInfo(bitmap.info().makeAlphaType(kOpaque_SkAlphaType));
    }
#StdOut
computeIsOpaque: false
computeIsOpaque: true
computeIsOpaque: false
computeIsOpaque: true
##
##

#SeeAlso isOpaque Color_Type Alpha

##

# ------------------------------------------------------------------------------

#Method void getBounds(SkRect* bounds) const
#In Property
#Line # returns width() and height() as Rectangle ##
Returns Rect { 0, 0, width(), height() }.

#Param bounds container for floating point rectangle ##

#Example
#Height 160
#Image 3
    SkRect bounds;
    source.getBounds(&bounds);
    bounds.offset(100, 100);
    SkPaint paint;
    paint.setColor(SK_ColorGRAY);
    canvas->scale(.25f, .25f);
    canvas->drawRect(bounds, paint);
    canvas->drawBitmap(source, 40, 40);
##

#SeeAlso bounds()

##

# ------------------------------------------------------------------------------

#Method void getBounds(SkIRect* bounds) const

Returns IRect { 0, 0, width(), height() }.

#Param bounds container for integral rectangle ##

#Example
#Image 3
    SkIRect bounds;
    source.getBounds(&bounds);
    bounds.inset(100, 100);
    SkBitmap bitmap;
    source.extractSubset(&bitmap, bounds);
    canvas->scale(.5f, .5f);
    canvas->drawBitmap(bitmap, 10, 10);
##

#SeeAlso bounds()

##

# ------------------------------------------------------------------------------

#Method SkIRect bounds() const
#In Property
#Line # returns width() and height() as Rectangle ##
Returns IRect { 0, 0, width(), height() }.

#Return  integral rectangle from origin to width() and height() ##

#Example
#Height 64
#Image 4
    canvas->scale(.5f, .5f);
    SkIRect bounds = source.bounds();
    for (int x : { 0, bounds.width() } ) {
        for (int y : { 0, bounds.height() } ) {
            canvas->drawBitmap(source, x, y);
        }
    }
##

#SeeAlso getBounds

##

# ------------------------------------------------------------------------------

#Method SkISize dimensions() const
#In Property
#Line # returns width() and height() ##
Returns ISize { width(), height() }.

#Return integral size of width() and height() ##

#Example
    SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::MakeN32(33, 55, kOpaque_SkAlphaType));
    SkISize dimensions = bitmap.dimensions();
    SkRect bounds;
    bitmap.getBounds(&bounds);
    SkRect dimensionsAsBounds = SkRect::Make(dimensions);
    SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!');
##

#SeeAlso height() width()

##

# ------------------------------------------------------------------------------

#Method SkIRect getSubset() const
#In Property
#Line # returns bounds offset by origin ##
Returns the bounds of this bitmap, offset by its Pixel_Ref origin.

#Return bounds within Pixel_Ref bounds ##

#Example
#Image 3
    SkIRect bounds;
    source.getBounds(&bounds);
    bounds.inset(100, 100);
    SkBitmap subset;
    source.extractSubset(&subset, bounds);
    SkIRect r = source.getSubset();
    SkDebugf("source: %d, %d, %d, %d\n", r.fLeft, r.fTop, r.fRight, r.fBottom);
    r = subset.getSubset();
    SkDebugf("subset: %d, %d, %d, %d\n", r.fLeft, r.fTop, r.fRight, r.fBottom);
#StdOut
source: 0, 0, 512, 512
subset: 100, 100, 412, 412
##
##

#SeeAlso extractSubset getBounds

##

# ------------------------------------------------------------------------------

#Method bool setInfo(const SkImageInfo& imageInfo, size_t rowBytes = 0)
#In Set
#Line # sets height, width, Color_Type, and so on, releasing pixels ##
Sets width, height, Alpha_Type, Color_Type, Color_Space, and optional
rowBytes. Frees pixels, and returns true if successful.

imageInfo.alphaType may be altered to a value permitted by imageInfo.colorSpace.
If imageInfo.colorType is kUnknown_SkColorType, imageInfo.alphaType is
set to kUnknown_SkAlphaType.
If imageInfo.colorType is kAlpha_8_SkColorType and imageInfo.alphaType is
kUnpremul_SkAlphaType, imageInfo.alphaType is replaced by kPremul_SkAlphaType.
If imageInfo.colorType is kRGB_565_SkColorType or kGray_8_SkColorType,
imageInfo.alphaType is set to kOpaque_SkAlphaType.
If imageInfo.colorType is kARGB_4444_SkColorType, kRGBA_8888_SkColorType,
kBGRA_8888_SkColorType, or kRGBA_F16_SkColorType: imageInfo.alphaType remains
unchanged.

rowBytes must equal or exceed imageInfo.minRowBytes. If imageInfo.colorSpace is
kUnknown_SkColorType, rowBytes is ignored and treated as zero; for all other
Color_Space values, rowBytes of zero is treated as imageInfo.minRowBytes.

Calls reset() and returns false if:
#List
# rowBytes exceeds 31 bits ##
# imageInfo.width() is negative ##
# imageInfo.height() is negative ##
# rowBytes is positive and less than imageInfo.width() times imageInfo.bytesPerPixel ##
##

#Param imageInfo  contains width, height, Alpha_Type, Color_Type, Color_Space ##
#Param rowBytes   imageInfo.minRowBytes or larger; or zero ##

#Return  true if Image_Info set successfully ##

#Example
#Height 96
###^
SkBitmap bitmap;
bitmap.setInfo(SkImageInfo::MakeN32(44, 16, kOpaque_SkAlphaType));
bitmap.allocPixels();
bitmap.eraseColor(SK_ColorGREEN);
SkCanvas offscreen(bitmap);
SkPaint paint;
offscreen.drawString("!@#$%", 0, 12, paint);
canvas->scale(6, 6);
canvas->drawBitmap(bitmap, 0, 0);
^^^#
##

#SeeAlso Alpha_Type Color_Type Color_Space height rowBytes width

##

# ------------------------------------------------------------------------------

#Enum AllocFlags
#Line # zero pixel memory ##
#Code
    enum AllocFlags {
        kZeroPixels_AllocFlag = 1 << 0,
    };
##

AllocFlags provides the option to zero pixel memory when allocated.

#Const kZeroPixels_AllocFlag 1
#Line # zero pixel memory ##
    Instructs tryAllocPixelsFlags and allocPixelsFlags to zero pixel memory.
##

#NoExample
##

#SeeAlso tryAllocPixelsFlags allocPixelsFlags erase() eraseColor

##

# ------------------------------------------------------------------------------
#Subtopic Allocate
#Populate
#Line # allocates storage for pixels ##
##

#Method bool SK_WARN_UNUSED_RESULT tryAllocPixelsFlags(const SkImageInfo& info, uint32_t flags)
#In Allocate
#Line # allocates pixels from Image_Info with options if possible ##
Sets Image_Info to info following the rules in setInfo and allocates pixel
memory. If flags is kZeroPixels_AllocFlag, memory is zeroed.

Returns false and calls reset() if Image_Info could not be set, or memory could
not be allocated, or memory could not optionally be zeroed.

On most platforms, allocating pixel memory may succeed even though there is
not sufficient memory to hold pixels; allocation does not take place
until the pixels are written to. The actual behavior depends on the platform
implementation of malloc(), if flags is zero, and calloc(), if flags is
kZeroPixels_AllocFlag.

flags set to kZeroPixels_AllocFlag offers equal or better performance than
subsequently calling eraseColor with SK_ColorTRANSPARENT.

#Param info  contains width, height, Alpha_Type, Color_Type, Color_Space ##
#Param flags  kZeroPixels_AllocFlag, or zero ##

#Return  true if pixels allocation is successful ##

#Example
    SkBitmap bitmap;
    if (!bitmap.tryAllocPixelsFlags(SkImageInfo::MakeN32(10000, 10000, kOpaque_SkAlphaType),
                                    SkBitmap::kZeroPixels_AllocFlag)) {
        SkDebugf("bitmap allocation failed!\n");
    } else {
        SkDebugf("bitmap allocation succeeded!\n");
    }
#StdOut
bitmap allocation succeeded!
##
##

#SeeAlso allocPixelsFlags tryAllocPixels SkMallocPixelRef::MakeZeroed

##

# ------------------------------------------------------------------------------

#Method void allocPixelsFlags(const SkImageInfo& info, uint32_t flags)
#In Allocate
#Line # allocates pixels from Image_Info with options, or aborts ##
Sets Image_Info to info following the rules in setInfo and allocates pixel
memory. If flags is kZeroPixels_AllocFlag, memory is zeroed.

Aborts execution if Image_Info could not be set, or memory could
not be allocated, or memory could not optionally
be zeroed. Abort steps may be provided by the user at compile time by defining
SK_ABORT.

On most platforms, allocating pixel memory may succeed even though there is
not sufficient memory to hold pixels; allocation does not take place
until the pixels are written to. The actual behavior depends on the platform
implementation of malloc(), if flags is zero, and calloc(), if flags is
kZeroPixels_AllocFlag.

flags set to kZeroPixels_AllocFlag offers equal or better performance than
subsequently calling eraseColor with SK_ColorTRANSPARENT.

#Param info  contains width, height, Alpha_Type, Color_Type, Color_Space ##
#Param flags  kZeroPixels_AllocFlag, or zero ##

#Example
#Height 128
#Description
Text is drawn on a transparent background; drawing the bitmap a second time
lets the first draw show through.
##
###^
SkBitmap bitmap;
bitmap.allocPixelsFlags(SkImageInfo::MakeN32(44, 16, kPremul_SkAlphaType),
                        SkBitmap::kZeroPixels_AllocFlag);
SkCanvas offscreen(bitmap);
SkPaint paint;
offscreen.drawString("!@#$%", 0, 12, paint);
canvas->scale(6, 6);
canvas->drawBitmap(bitmap, 0, 0);
canvas->drawBitmap(bitmap, 8, 8);
^^^#
##

#SeeAlso tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeZeroed

##

# ------------------------------------------------------------------------------

#Method bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info, size_t rowBytes)
#In Allocate
#Line # allocates pixels from Image_Info if possible ##
#ToDo  am I ever conflicted about setInfo rules. It needs to be able to be replicated
       if, for instance, I generate one-page-per-method HTML-style documentation
       I'm not so sure it makes sense to put the indirection in for .h either unless
       my mantra is that .h should abbreviate full documentation. And, what to do
       for generated markdown? At least there the rules are a click away, although
       a pop-down in place would be way better. Hmmm.
##

Sets Image_Info to info following the rules in setInfo and allocates pixel
memory. rowBytes must equal or exceed info.width() times info.bytesPerPixel(),
or equal zero. Pass in zero for rowBytes to compute the minimum valid value.

Returns false and calls reset() if Image_Info could not be set, or memory could
not be allocated.

On most platforms, allocating pixel memory may succeed even though there is
not sufficient memory to hold pixels; allocation does not take place
until the pixels are written to. The actual behavior depends on the platform
implementation of malloc().

#Param info  contains width, height, Alpha_Type, Color_Type, Color_Space ##
#Param rowBytes  size of pixel row or larger; may be zero  ##

#Return  true if pixel storage is allocated ##

#Example
#Image 3
SkBitmap bitmap;
SkImageInfo info = SkImageInfo::Make(64, 256, kGray_8_SkColorType, kOpaque_SkAlphaType);
if (bitmap.tryAllocPixels(info, 0)) {
    SkCanvas offscreen(bitmap);
    offscreen.scale(.5f, .5f);
    for (int x : { 0, 64, 128, 192 } ) {
        offscreen.drawBitmap(source, -x, 0);
        canvas->drawBitmap(bitmap, x, 0);
    }
}
##

#SeeAlso tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeAllocate

##

# ------------------------------------------------------------------------------

#Method void allocPixels(const SkImageInfo& info, size_t rowBytes)
#In Allocate
#Line # allocates pixels from Image_Info, or aborts ##
Sets Image_Info to info following the rules in setInfo and allocates pixel
memory. rowBytes must equal or exceed info.width() times info.bytesPerPixel(),
or equal zero. Pass in zero for rowBytes to compute the minimum valid value.

Aborts execution if Image_Info could not be set, or memory could
not be allocated. Abort steps may be provided by
the user at compile time by defining SK_ABORT.

On most platforms, allocating pixel memory may succeed even though there is
not sufficient memory to hold pixels; allocation does not take place
until the pixels are written to. The actual behavior depends on the platform
implementation of malloc().

#Param info  contains width, height, Alpha_Type, Color_Type, Color_Space ##
#Param rowBytes  size of pixel row or larger; may be zero  ##

#Example
#Image 3
SkBitmap bitmap;
SkImageInfo info = SkImageInfo::Make(256, 64, kGray_8_SkColorType, kOpaque_SkAlphaType);
bitmap.allocPixels(info, info.width() * info.bytesPerPixel() + 64);
SkCanvas offscreen(bitmap);
offscreen.scale(.5f, .5f);
for (int y : { 0, 64, 128, 192 } ) {
    offscreen.drawBitmap(source, 0, -y);
    canvas->drawBitmap(bitmap, 0, y);
}
##

#SeeAlso tryAllocPixels allocPixelsFlags SkMallocPixelRef::MakeAllocate

##

# ------------------------------------------------------------------------------

#Method bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info)

Sets Image_Info to info following the rules in setInfo and allocates pixel
memory.

Returns false and calls reset() if Image_Info could not be set, or memory could
not be allocated.

On most platforms, allocating pixel memory may succeed even though there is
not sufficient memory to hold pixels; allocation does not take place
until the pixels are written to. The actual behavior depends on the platform
implementation of malloc().

#Param info  contains width, height, Alpha_Type, Color_Type, Color_Space ##

#Return  true if pixel storage is allocated ##

#Example
#Image 3
SkBitmap bitmap;
if (bitmap.tryAllocPixels(SkImageInfo::Make(64, 64, kGray_8_SkColorType, kOpaque_SkAlphaType))) {
    SkCanvas offscreen(bitmap);
    offscreen.scale(.25f, .5f);
    for (int y : { 0, 64, 128, 192 } ) {
        offscreen.drawBitmap(source, -y, -y);
        canvas->drawBitmap(bitmap, y, y);
    }
}
##

#SeeAlso tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeAllocate

##

# ------------------------------------------------------------------------------

#Method void allocPixels(const SkImageInfo& info)

Sets Image_Info to info following the rules in setInfo and allocates pixel
memory.

Aborts execution if Image_Info could not be set, or memory could
not be allocated. Abort steps may be provided by
the user at compile time by defining SK_ABORT.

On most platforms, allocating pixel memory may succeed even though there is
not sufficient memory to hold pixels; allocation does not take place
until the pixels are written to. The actual behavior depends on the platform
implementation of malloc().

#Param info  contains width, height, Alpha_Type, Color_Type, Color_Space ##

#Example
#Image 4
SkBitmap bitmap;
bitmap.allocPixels(SkImageInfo::Make(64, 64, kGray_8_SkColorType, kOpaque_SkAlphaType));
SkCanvas offscreen(bitmap);
offscreen.scale(.5f, .5f);
for (int y : { 0, 64, 128, 192 } ) {
    offscreen.drawBitmap(source, -y, -y);
    canvas->drawBitmap(bitmap, y, y);
}
##

#SeeAlso tryAllocPixels allocPixelsFlags SkMallocPixelRef::MakeAllocate

##

# ------------------------------------------------------------------------------

#Method bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isOpaque = false)
#In Allocate
#Line # allocates compatible ARGB pixels if possible ##
Sets Image_Info to width, height, and Native_Color_Type; and allocates
pixel memory. If isOpaque is true, sets Image_Info to kOpaque_SkAlphaType;
otherwise, sets to kPremul_SkAlphaType.

Calls reset() and returns false if width exceeds 29 bits or is negative,
or height is negative.

Returns false if allocation fails.

Use to create Bitmap that matches SkPMColor, the native pixel arrangement on
the platform. Bitmap drawn to output device skips converting its pixel format.

#Param width  pixel column count; must be zero or greater ##
#Param height  pixel row count; must be zero or greater ##
#Param isOpaque  true if pixels do not have transparency ##

#Return  true if pixel storage is allocated ##

#Example
#Height 160
    SkBitmap bitmap;
    if (bitmap.tryAllocN32Pixels(80, 80)) {
        bitmap.eraseColor(SK_ColorTRANSPARENT);
        bitmap.erase(0x7f3f7fff, SkIRect::MakeWH(50, 30));
        bitmap.erase(0x3f7fff3f, SkIRect::MakeXYWH(20, 10, 50, 30));
        bitmap.erase(0x5fff3f7f, SkIRect::MakeXYWH(40, 20, 50, 30));
        canvas->drawBitmap(bitmap, 0, 0);
        for (int x : { 0, 30, 60, 90 } ) {
            canvas->drawBitmap(bitmap, x, 70);
        }
    }
##

#SeeAlso tryAllocPixels allocN32Pixels SkMallocPixelRef::MakeAllocate

##

# ------------------------------------------------------------------------------

#Method void allocN32Pixels(int width, int height, bool isOpaque = false)
#In Allocate
#Line # allocates compatible ARGB pixels, or aborts ##
Sets Image_Info to width, height, and the Native_Color_Type; and allocates
pixel memory. If isOpaque is true, sets Image_Info to kPremul_SkAlphaType;
otherwise, sets to kOpaque_SkAlphaType.

Aborts if width exceeds 29 bits or is negative, or height is negative, or
allocation fails. Abort steps may be provided by the user at compile time by
defining SK_ABORT.

Use to create Bitmap that matches SkPMColor, the native pixel arrangement on
the platform. Bitmap drawn to output device skips converting its pixel format.

#Param width  pixel column count; must be zero or greater ##
#Param height  pixel row count; must be zero or greater ##
#Param isOpaque  true if pixels do not have transparency ##

#Example
    SkRandom random;
    SkBitmap bitmap;
    bitmap.allocN32Pixels(64, 64);
    bitmap.eraseColor(SK_ColorTRANSPARENT);
    for (int y = 0; y < 256; y += 64) {
        for (int x = 0; x < 256; x += 64) {
            SkColor color = random.nextU();
            uint32_t w = random.nextRangeU(4, 32);
            uint32_t cx = random.nextRangeU(0, 64 - w);
            uint32_t h = random.nextRangeU(4, 32);
            uint32_t cy = random.nextRangeU(0, 64 - h);
            bitmap.erase(color, SkIRect::MakeXYWH(cx, cy, w, h));
            canvas->drawBitmap(bitmap, x, y);
        }
    }
##

#SeeAlso allocPixels tryAllocN32Pixels SkMallocPixelRef::MakeAllocate

##

# ------------------------------------------------------------------------------

#Method bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
                       void (*releaseProc)(void* addr, void* context), void* context)
#In Allocate
#Line # creates Pixel_Ref, with optional release function ##

Sets Image_Info to info following the rules in setInfo, and creates Pixel_Ref
containing pixels and rowBytes. releaseProc, if not nullptr, is called
immediately on failure or when pixels are no longer referenced. context may be
nullptr.

If Image_Info could not be set, or rowBytes is less than info.minRowBytes:
calls releaseProc if present, calls reset(), and returns false.

Otherwise, if pixels equals nullptr: sets Image_Info, calls releaseProc if
present, returns true.

If Image_Info is set, pixels is not nullptr, and releaseProc is not nullptr:
when pixels are no longer referenced, calls releaseProc with pixels and context
as parameters.

#Param info  contains width, height, Alpha_Type, Color_Type, Color_Space ##
#Param pixels   address or pixel storage; may be nullptr ##
#Param rowBytes  size of pixel row or larger ##
#Param releaseProc  function called when pixels can be deleted; may be nullptr ##
#Param context   caller state passed to releaseProc; may be nullptr ##

#Return  true if Image_Info is set to info ##

#Example
#Description
releaseProc is called immediately because rowBytes is too small for Pixel_Ref.
##
#Function
static void releaseProc(void* addr, void* ) {
    SkDebugf("releaseProc called\n");
    delete[] (uint32_t*) addr;
}

##

void draw(SkCanvas* canvas) {
   SkBitmap bitmap;
   void* pixels = new uint32_t[8 * 8];
   SkImageInfo info = SkImageInfo::MakeN32(8, 8, kOpaque_SkAlphaType);
   SkDebugf("before installPixels\n");
   bool installed = bitmap.installPixels(info, pixels, 16, releaseProc, nullptr);
   SkDebugf("install " "%s" "successful\n", installed ? "" : "not ");
}
#StdOut
before installPixels
releaseProc called
install not successful
##
##

#SeeAlso allocPixels

##

# ------------------------------------------------------------------------------

#Method bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes)

Sets Image_Info to info following the rules in setInfo, and creates Pixel_Ref
containing pixels and rowBytes.

If Image_Info could not be set, or rowBytes is less than info.minRowBytes:
calls reset(), and returns false.

Otherwise, if pixels equals nullptr: sets Image_Info, returns true.

Caller must ensure that pixels are valid for the lifetime of Bitmap and Pixel_Ref.

#Param info  contains width, height, Alpha_Type, Color_Type, Color_Space ##
#Param pixels  address or pixel storage; may be nullptr ##
#Param rowBytes  size of pixel row or larger ##

#Return  true if Image_Info is set to info ##

#Example
#Bug 7079
#Description
GPU does not support kUnpremul_SkAlphaType, does not assert that it does not.
##
void draw(SkCanvas* canvas) {
   SkRandom random;
   SkBitmap bitmap;
   const int width = 8;
   const int height = 8;
   uint32_t pixels[width * height];
   for (unsigned x = 0; x < width * height; ++x) {
       pixels[x] = random.nextU();
   }
   SkImageInfo info = SkImageInfo::MakeN32(width, height, kUnpremul_SkAlphaType);
   if (bitmap.installPixels(info, pixels, info.minRowBytes())) {
       canvas->scale(32, 32);
       canvas->drawBitmap(bitmap, 0, 0);
   }
}
##

#SeeAlso allocPixels

##

# ------------------------------------------------------------------------------

#Method bool installPixels(const SkPixmap& pixmap)

Sets Image_Info to pixmap.info() following the rules in setInfo, and creates
Pixel_Ref containing pixmap.addr() and pixmap.rowBytes.

If Image_Info could not be set, or pixmap.rowBytes is less than
SkImageInfo::minRowBytes: calls reset(), and returns false.

Otherwise, if pixmap.addr() equals nullptr: sets Image_Info, returns true.

Caller must ensure that pixmap is valid for the lifetime of Bitmap and Pixel_Ref.

#Param pixmap  Image_Info, pixel address, and rowBytes ##

#Return  true if Image_Info was set to pixmap.info() ##

#Example
#Description
Draw a five by five bitmap, and draw it again with a center white pixel.
##
#Height 64
    uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
                            { 0xAC, 0xA8, 0x89, 0x47, 0x87 },
                            { 0x4B, 0x25, 0x25, 0x25, 0x46 },
                            { 0x90, 0x81, 0x25, 0x41, 0x33 },
                            { 0x75, 0x55, 0x44, 0x20, 0x00 }};
    SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType);
    SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
    SkBitmap bitmap;
    bitmap.installPixels(pixmap);
    canvas->scale(10, 10);
    canvas->drawBitmap(bitmap, 0, 0);
    *pixmap.writable_addr8(2, 2) = 0xFF;
    bitmap.installPixels(pixmap);
    canvas->drawBitmap(bitmap, 10, 0);
##

#SeeAlso allocPixels

##

# ------------------------------------------------------------------------------

#Method bool installMaskPixels(const SkMask& mask)
#Deprecated soon
##

# ------------------------------------------------------------------------------
#Subtopic Pixels
#Populate
#Line # read and write pixel values ##
##

#Method void setPixels(void* pixels)
#In Pixels
#Line # sets Pixel_Ref without an offset ##
Replaces Pixel_Ref with pixels, preserving Image_Info and rowBytes.
Sets Pixel_Ref origin to (0, 0).

If pixels is nullptr, or if info().colorType equals kUnknown_SkColorType;
release reference to Pixel_Ref, and set Pixel_Ref to nullptr.

Caller is responsible for handling ownership pixel memory for the lifetime
of Bitmap and Pixel_Ref.

#Param pixels  address of pixel storage, managed by caller ##

#Example
#Height 50
    uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 };
    uint8_t set2[5] = { 0xAC, 0xA8, 0x89, 0x47, 0x87 };
    SkBitmap bitmap;
    bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5);
    canvas->scale(10, 50);
    canvas->drawBitmap(bitmap, 0, 0);
    bitmap.setPixels(set2);
    canvas->drawBitmap(bitmap, 10, 0);
##

#SeeAlso installPixels allocPixels

##

# ------------------------------------------------------------------------------

#Method bool SK_WARN_UNUSED_RESULT tryAllocPixels()
#In Allocate
Allocates pixel memory with HeapAllocator, and replaces existing Pixel_Ref.
The allocation size is determined by Image_Info width, height, and Color_Type.

Returns false if info().colorType is kUnknown_SkColorType, or allocation fails.

#Return  true if the allocation succeeds
##

#Example
#Height 50
#Description
Bitmap hosts and draws gray values in set1. tryAllocPixels replaces Pixel_Ref
and erases it to black, but does not alter set1. setPixels replaces black
Pixel_Ref with set1.
##
    uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 };
    SkBitmap bitmap;
    bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5);
    canvas->scale(10, 50);
    canvas->drawBitmap(bitmap, 0, 0);
    if (bitmap.tryAllocPixels()) {
        bitmap.eraseColor(SK_ColorBLACK);
        canvas->drawBitmap(bitmap, 8, 0);
        bitmap.setPixels(set1);
        canvas->drawBitmap(bitmap, 16, 0);
    }
##

#SeeAlso allocPixels installPixels setPixels

##

# ------------------------------------------------------------------------------

#Method void allocPixels()
#In Allocate
Allocates pixel memory with HeapAllocator, and replaces existing Pixel_Ref.
The allocation size is determined by Image_Info width, height, and Color_Type.

Aborts if info().colorType is kUnknown_SkColorType, or allocation fails.
Abort steps may be provided by the user at compile
time by defining SK_ABORT.

#Example
#Height 50
#Description
Bitmap hosts and draws gray values in set1. allocPixels replaces Pixel_Ref
and erases it to black, but does not alter set1. setPixels replaces black
Pixel_Ref with set2.
##
    uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 };
    uint8_t set2[5] = { 0xAC, 0xA8, 0x89, 0x47, 0x87 };
    SkBitmap bitmap;
    bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5);
    canvas->scale(10, 50);
    canvas->drawBitmap(bitmap, 0, 0);
    bitmap.allocPixels();
    bitmap.eraseColor(SK_ColorBLACK);
    canvas->drawBitmap(bitmap, 8, 0);
    bitmap.setPixels(set2);
    canvas->drawBitmap(bitmap, 16, 0);
##

#SeeAlso tryAllocPixels installPixels setPixels

##

# ------------------------------------------------------------------------------

#Method bool SK_WARN_UNUSED_RESULT tryAllocPixels(Allocator* allocator)

Allocates pixel memory with allocator, and replaces existing Pixel_Ref.
The allocation size is determined by Image_Info width, height, and Color_Type.
If allocator is nullptr, use HeapAllocator instead.

Returns false if Allocator::allocPixelRef return false.

#Param allocator  instance of SkBitmap::Allocator instantiation ##

#Return  true if custom allocator reports success
##

#Example
#Height 100
#Description
HeapAllocator limits the maximum size of Bitmap to two gigabytes. Using
a custom allocator, this limitation may be relaxed. This example can be
modified to allocate an eight gigabyte Bitmap on a 64-bit platform with
sufficient memory.
##
#Function
class LargePixelRef : public SkPixelRef {
public:
    LargePixelRef(const SkImageInfo& info, char* storage, size_t rowBytes)
        : SkPixelRef(info.width(), info.height(), storage, rowBytes) {
    }

    ~LargePixelRef() override {
        delete[] (char* ) this->pixels();
    }
};

class LargeAllocator : public SkBitmap::Allocator {
public:
    bool allocPixelRef(SkBitmap* bitmap) override {
        const SkImageInfo& info = bitmap->info();
        uint64_t rowBytes = info.minRowBytes64();
        uint64_t size = info.height() * rowBytes;
        char* addr = new char[size];
        if (nullptr == addr) {
            return false;
        }
        sk_sp<SkPixelRef> pr = sk_sp<SkPixelRef>(new LargePixelRef(info, addr, rowBytes));
        if (!pr) {
            return false;
        }
        bitmap->setPixelRef(std::move(pr), 0, 0);
        return true;
    }
};

##

void draw(SkCanvas* canvas) {
   LargeAllocator largeAllocator;
   SkBitmap bitmap;
   int width = 100; // make this 20000
   int height = 100; // and this 100000 to allocate 8 gigs on a 64-bit platform
   bitmap.setInfo(SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType));
   if (bitmap.tryAllocPixels(&largeAllocator)) {
       bitmap.eraseColor(0xff55aa33);
       canvas->drawBitmap(bitmap, 0, 0);
   }
}

##

#SeeAlso allocPixels Allocator Pixel_Ref

##

# ------------------------------------------------------------------------------

#Method void allocPixels(Allocator* allocator)

Allocates pixel memory with allocator, and replaces existing Pixel_Ref.
The allocation size is determined by Image_Info width, height, and Color_Type.
If allocator is nullptr, use HeapAllocator instead.

Aborts if Allocator::allocPixelRef return false. Abort steps may be provided by
the user at compile time by defining SK_ABORT.

#Param allocator  instance of SkBitmap::Allocator instantiation ##

#Example
#Height 32
#Function
class TinyAllocator : public SkBitmap::Allocator {
public:
    bool allocPixelRef(SkBitmap* bitmap) override {
        const SkImageInfo& info = bitmap->info();
        if (info.height() * info.minRowBytes() > sizeof(storage)) {
            return false;
        }
        sk_sp<SkPixelRef> pr = sk_sp<SkPixelRef>(
                new SkPixelRef(info.width(), info.height(), storage, info.minRowBytes()));
        bitmap->setPixelRef(std::move(pr), 0, 0);
        return true;
    }

    char storage[16];
};

##

void draw(SkCanvas* canvas) {
   TinyAllocator tinyAllocator;
   SkBitmap bitmap;
   bitmap.setInfo(SkImageInfo::MakeN32(2, 2, kOpaque_SkAlphaType));
   if (bitmap.tryAllocPixels(&tinyAllocator)) {
       bitmap.eraseColor(0xff55aa33);
       bitmap.erase(0xffaa3355, SkIRect::MakeXYWH(1, 1, 1, 1));
       canvas->scale(16, 16);
       canvas->drawBitmap(bitmap, 0, 0);
   }
}
##

#SeeAlso allocPixels Allocator Pixel_Ref

##

# ------------------------------------------------------------------------------

#Method SkPixelRef* pixelRef() const
#In Property
#Line # returns Pixel_Ref, or nullptr ##
Returns Pixel_Ref, which contains: pixel base address; its dimensions; and
rowBytes, the interval from one row to the next. Does not change Pixel_Ref
reference count. Pixel_Ref may be shared by multiple bitmaps.
If Pixel_Ref has not been set, returns nullptr.

#Return  Pixel_Ref, or nullptr ##

#Example
#Image 3
   SkBitmap subset;
   source.extractSubset(&subset, SkIRect::MakeXYWH(32, 64, 128, 256));
   SkDebugf("src ref %c= sub ref\n", source.pixelRef() == subset.pixelRef() ? '=' : '!');
   SkDebugf("src pixels %c= sub pixels\n", source.getPixels() == subset.getPixels() ? '=' : '!');
   SkDebugf("src addr %c= sub addr\n", source.getAddr(32, 64) == subset.getAddr(0, 0) ? '=' : '!');
##

#SeeAlso getPixels getAddr

##

# ------------------------------------------------------------------------------

#Method SkIPoint pixelRefOrigin() const
#In Property
#Line # returns offset within Pixel_Ref ##
Returns origin of pixels within Pixel_Ref. Bitmap bounds is always contained
by Pixel_Ref bounds, which may be the same size or larger. Multiple Bitmaps
can share the same Pixel_Ref, where each Bitmap has different bounds.

The returned origin added to Bitmap dimensions equals or is smaller than the
Pixel_Ref dimensions.

Returns (0, 0) if Pixel_Ref is nullptr.

#Return  pixel origin within Pixel_Ref ##

#Example
#Image 3
   SkBitmap subset;
   source.extractSubset(&subset, SkIRect::MakeXYWH(32, 64, 128, 256));
   SkIPoint sourceOrigin = source.pixelRefOrigin();
   SkIPoint subsetOrigin = subset.pixelRefOrigin();
   SkDebugf("source origin: %d, %d\n", sourceOrigin.fX, sourceOrigin.fY);
   SkDebugf("subset origin: %d, %d\n", subsetOrigin.fX, subsetOrigin.fY);
#StdOut
source origin: 0, 0
subset origin: 32, 64
##
##

#SeeAlso SkPixelRef getSubset setPixelRef

##

# ------------------------------------------------------------------------------
#Subtopic Set
#Line # updates values and attributes ##
#Populate
##

#Method void setPixelRef(sk_sp<SkPixelRef> pixelRef, int dx, int dy)
#In Set
#Line # sets Pixel_Ref and offset ##
Replaces pixelRef and origin in Bitmap.  dx and dy specify the offset
within the Pixel_Ref pixels for the top-left corner of the bitmap.

Asserts in debug builds if dx or dy are out of range. Pins dx and dy
to legal range in release builds.

The caller is responsible for ensuring that the pixels match the
Color_Type and Alpha_Type in Image_Info.

#Param pixelRef  Pixel_Ref describing pixel address and rowBytes ##
#Param dx   column offset in Pixel_Ref for bitmap origin ##
#Param dy   row offset in Pixel_Ref for bitmap origin ##

#Example
#Height 140
#Image 5
#Description
Treating 32-bit data as 8-bit data is unlikely to produce useful results.
##
    SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::Make(source.width() - 5, source.height() - 5,
                   kGray_8_SkColorType, kOpaque_SkAlphaType), source.rowBytes());
    bitmap.setPixelRef(sk_ref_sp(source.pixelRef()), 5, 5);
    canvas->drawBitmap(bitmap, 10, 10);
##

#SeeAlso setInfo

##

# ------------------------------------------------------------------------------

#Method bool readyToDraw() const
#In Utility
#Line # returns true if address of pixels is not nullptr ##
Returns true if Bitmap is can be drawn.

#Return  true if getPixels() is not nullptr ##

#Example
#Image 5
#Height 160
    if (source.readyToDraw()) {
        canvas->drawBitmap(source, 10, 10);
    }
##

#SeeAlso getPixels drawsNothing

##

# ------------------------------------------------------------------------------

#Method uint32_t getGenerationID() const
#In Utility
#Line # returns unique ID ##
Returns a unique value corresponding to the pixels in Pixel_Ref.
Returns a different value after notifyPixelsChanged has been called.
Returns zero if Pixel_Ref is nullptr.

Determines if pixels have changed since last examined.

#Return unique value for pixels in Pixel_Ref ##

#Example
    SkBitmap bitmap;
    SkDebugf("empty id %u\n", bitmap.getGenerationID());
    bitmap.allocPixels(SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType));
    SkDebugf("alloc id %u\n", bitmap.getGenerationID());
    bitmap.eraseColor(SK_ColorRED);
    SkDebugf("erase id %u\n", bitmap.getGenerationID());
#StdOut
#Volatile
empty id 0
alloc id 4
erase id 6
##
##

#SeeAlso notifyPixelsChanged Pixel_Ref

##

# ------------------------------------------------------------------------------

#Method void notifyPixelsChanged() const
#In Pixels
#Line # marks pixels as changed, altering the unique ID ##
Marks that pixels in Pixel_Ref have changed. Subsequent calls to
getGenerationID() return a different value.

#Example
#Height 20
    SkBitmap bitmap;
    bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType));
    bitmap.allocPixels();
    bitmap.eraseColor(SK_ColorRED);
    canvas->scale(16, 16);
    canvas->drawBitmap(bitmap, 0, 0);
    *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorBLUE);
    canvas->drawBitmap(bitmap, 2, 0);
    bitmap.notifyPixelsChanged();
    *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorGREEN);
    canvas->drawBitmap(bitmap, 4, 0);
##

#SeeAlso getGenerationID isVolatile Pixel_Ref

##

# ------------------------------------------------------------------------------
#Subtopic Draw
#Populate
#Line # sets pixels to Color ##
##

#Method void eraseColor(SkColor c) const
#In Draw
#Line # writes Color to pixels ##
Replaces pixel values with c. All pixels contained by bounds() are affected.
If the colorType is kGray_8_SkColorType or k565_SkColorType, then Color_Alpha
is ignored; RGB is treated as opaque. If colorType is kAlpha_8_SkColorType,
then RGB is ignored.

#Param c  Unpremultiplied Color ##

#Example
#Height 20
    SkBitmap bitmap;
    bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kOpaque_SkAlphaType));
    bitmap.eraseColor(SK_ColorRED);
    canvas->scale(16, 16);
    canvas->drawBitmap(bitmap, 0, 0);
##

#SeeAlso eraseARGB erase

##

# ------------------------------------------------------------------------------

#Method void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const
#In Draw
#Line # writes Color to pixels ##
Replaces pixel values with Unpremultiplied Color built from a, r, g, and b.
All pixels contained by bounds() are affected.
If the colorType is kGray_8_SkColorType or k565_SkColorType, then a
is ignored; r, g, and b are treated as opaque. If colorType is kAlpha_8_SkColorType,
then r, g, and b are ignored.

#Param a    amount of Color_Alpha, from fully transparent (0) to fully opaque (255) ##
#Param r    amount of red, from no red (0) to full red (255) ##
#Param g    amount of green, from no green (0) to full green (255) ##
#Param b    amount of blue, from no blue (0) to full blue (255) ##

#Example
#Height 80
    SkBitmap bitmap;
    bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType));
    bitmap.eraseARGB(0x7f, 0xff, 0x7f, 0x3f);
    canvas->scale(50, 50);
    canvas->drawBitmap(bitmap, 0, 0);
    canvas->drawBitmap(bitmap, .5f, .5f);
##

#SeeAlso eraseColor erase

##

# ------------------------------------------------------------------------------

#Method void eraseRGB(U8CPU r, U8CPU g, U8CPU b) const
#Deprecated
##

# ------------------------------------------------------------------------------

#Method void erase(SkColor c, const SkIRect& area) const
#In Draw
#Line # writes Color to rectangle of pixels ##
Replaces pixel values inside area with c. If area does not intersect bounds(),
call has no effect.

If the colorType is kGray_8_SkColorType or k565_SkColorType, then Color_Alpha
is ignored; RGB is treated as opaque. If colorType is kAlpha_8_SkColorType,
then RGB is ignored.

#Param c  Unpremultiplied Color ##
#Param area  rectangle to fill ##

#Example
#Height 70
    SkBitmap bitmap;
    bitmap.allocPixels(SkImageInfo::MakeN32(2, 2, kPremul_SkAlphaType));
    bitmap.erase(0x7fff7f3f, SkIRect::MakeWH(1, 1));
    bitmap.erase(0x7f7f3fff, SkIRect::MakeXYWH(0, 1, 1, 1));
    bitmap.erase(0x7f3fff7f, SkIRect::MakeXYWH(1, 0, 1, 1));
    bitmap.erase(0x7f1fbf5f, SkIRect::MakeXYWH(1, 1, 1, 1));
    canvas->scale(25, 25);
    canvas->drawBitmap(bitmap, 0, 0);
    canvas->drawBitmap(bitmap, .5f, .5f);

##

#SeeAlso eraseColor eraseARGB eraseRGB SkCanvas::drawRect

##

# ------------------------------------------------------------------------------

#Method void eraseArea(const SkIRect& area, SkColor c) const
#Deprecated
##

# ------------------------------------------------------------------------------

#Method SkColor getColor(int x, int y) const
#In Property
#In Pixels
#Line # returns one pixel as Unpremultiplied Color ##
Returns pixel at (x, y) as Unpremultiplied Color.
Returns black with Alpha if Color_Type is kAlpha_8_SkColorType.

Input is not validated: out of bounds values of x or y trigger an assert() if
built with SK_DEBUG defined; and returns undefined values or may crash if
SK_RELEASE is defined. Fails if Color_Type is kUnknown_SkColorType or
pixel address is nullptr.

Color_Space in Image_Info is ignored. Some Color precision may be lost in the
conversion to Unpremultiplied Color; original pixel data may have additional
precision.

#Param x  column index, zero or greater, and less than width() ##
#Param y  row index, zero or greater, and less than height() ##

#Return  pixel converted to Unpremultiplied Color ##

#Example
    const int w = 4;
    const int h = 4;
    SkColor colors[][w] = {
        { 0x00000000, 0x2a0e002a, 0x55380055, 0x7f7f007f },
        { 0x2a000e2a, 0x551c1c55, 0x7f542a7f, 0xaaaa38aa },
        { 0x55003855, 0x7f2a547f, 0xaa7171aa, 0xd4d48dd4 },
        { 0x7f007f7f, 0xaa38aaaa, 0xd48dd4d4, 0xffffffff }
    };
    SkDebugf("Premultiplied:\n");
    for (int y = 0; y < h; ++y) {
        SkDebugf("(0, %d) ", y);
        for (int x = 0; x < w; ++x) {
            SkDebugf("0x%08x%c", colors[y][x], x == w - 1 ? '\n' : ' ');
        }
    }
    SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), colors, w * 4);
    SkBitmap bitmap;
    bitmap.installPixels(pixmap);
    SkDebugf("Unpremultiplied:\n");
    for (int y = 0; y < h; ++y) {
        SkDebugf("(0, %d) ", y);
        for (int x = 0; x < w; ++x) {
            SkDebugf("0x%08x%c", bitmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
        }
    }
#StdOut
Premultiplied:
(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
Unpremultiplied:
(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
##
##

#SeeAlso getAddr readPixels

##

# ------------------------------------------------------------------------------

#Method void* getAddr(int x, int y) const
#In Property
#Line # returns readable pixel address as void pointer ##
Returns pixel address at (x, y).

Input is not validated: out of bounds values of x or y, or kUnknown_SkColorType,
trigger an assert() if built with SK_DEBUG defined. Returns nullptr if
Color_Type is kUnknown_SkColorType, or Pixel_Ref is nullptr.

Performs a lookup of pixel size; for better performance, call
one of: getAddr8, getAddr16, or getAddr32.

#Param x  column index, zero or greater, and less than width() ##
#Param y  row index, zero or greater, and less than height() ##

#Return  generic pointer to pixel ##

#Example
#Image 3
    char* row0 = (char* ) source.getAddr(0, 0);
    char* row1 = (char* ) source.getAddr(0, 1);
    SkDebugf("addr interval %c= rowBytes\n",
             (size_t) (row1 - row0) == source.rowBytes() ? '=' : '!');
#StdOut
addr interval == rowBytes
##
##

#SeeAlso getAddr8 getAddr16 getAddr32 readPixels SkPixmap::addr

##

# ------------------------------------------------------------------------------

#Method inline uint32_t* getAddr32(int x, int y) const
#In Property
#Line # returns readable pixel address as 32-bit pointer ##
Returns address at (x, y).

Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
#List
# Pixel_Ref is nullptr ##
# bytesPerPixel() is not four ##
# x is negative, or not less than width() ##
# y is negative, or not less than height() ##
##

#Param x  column index, zero or greater, and less than width() ##
#Param y  row index, zero or greater, and less than height() ##

#Return  unsigned 32-bit pointer to pixel at (x, y) ##

#Example
#Image 3
    uint32_t* row0 = source.getAddr32(0, 0);
    uint32_t* row1 = source.getAddr32(0, 1);
    size_t interval = (row1 - row0) * source.bytesPerPixel();
    SkDebugf("addr interval %c= rowBytes\n", interval == source.rowBytes() ? '=' : '!');
#StdOut
addr interval == rowBytes
##
##

#SeeAlso getAddr8 getAddr16 getAddr readPixels SkPixmap::addr32

##

# ------------------------------------------------------------------------------

#Method inline uint16_t* getAddr16(int x, int y) const
#In Property
#Line # returns readable pixel address as 16-bit pointer ##
Returns address at (x, y).

Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
#List
# Pixel_Ref is nullptr ##
# bytesPerPixel() is not two ##
# x is negative, or not less than width() ##
# y is negative, or not less than height() ##
##

#Param x  column index, zero or greater, and less than width() ##
#Param y  row index, zero or greater, and less than height() ##

#Return  unsigned 16-bit pointer to pixel at (x, y)##

#Example
#Image 3
    SkBitmap bitmap16;
    SkImageInfo dstInfo = SkImageInfo::Make(source.width(), source.height(), kARGB_4444_SkColorType,
                     kPremul_SkAlphaType);
    bitmap16.allocPixels(dstInfo);
    if (source.readPixels(dstInfo, bitmap16.getPixels(), bitmap16.rowBytes(), 0, 0)) {
        uint16_t* row0 = bitmap16.getAddr16(0, 0);
        uint16_t* row1 = bitmap16.getAddr16(0, 1);
        size_t interval = (row1 - row0) * bitmap16.bytesPerPixel();
        SkDebugf("addr interval %c= rowBytes\n", interval == bitmap16.rowBytes() ? '=' : '!');
    }
#StdOut
addr interval == rowBytes
##
##

#SeeAlso getAddr8 getAddr getAddr32 readPixels SkPixmap::addr16

##

# ------------------------------------------------------------------------------

#Method inline uint8_t* getAddr8(int x, int y) const
#In Property
#Line # returns readable pixel address as 8-bit pointer ##
Returns address at (x, y).

Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
#List
# Pixel_Ref is nullptr ##
# bytesPerPixel() is not one ##
# x is negative, or not less than width() ##
# y is negative, or not less than height() ##
##

#Param x  column index, zero or greater, and less than width() ##
#Param y  row index, zero or greater, and less than height() ##

#Return unsigned 8-bit pointer to pixel at (x, y) ##

#Example
   SkBitmap bitmap;
   const int width = 8;
   const int height = 8;
   uint8_t pixels[height][width];
   SkImageInfo info = SkImageInfo::Make(width, height, kGray_8_SkColorType, kOpaque_SkAlphaType);
   if (bitmap.installPixels(info, pixels, info.minRowBytes())) {
       SkDebugf("&pixels[4][2] %c= bitmap.getAddr8(2, 4)\n",
                 &pixels[4][2]  == bitmap.getAddr8(2, 4) ? '=' : '!');
   }
#StdOut
&pixels[4][2] == bitmap.getAddr8(2, 4)
##
##

#SeeAlso getAddr getAddr16 getAddr32 readPixels SkPixmap::addr8

##

# ------------------------------------------------------------------------------

#Method bool extractSubset(SkBitmap* dst, const SkIRect& subset) const
#In Constructor
#Line # creates Bitmap, sharing pixels if possible ##
Shares Pixel_Ref with dst. Pixels are not copied; Bitmap and dst point
to the same pixels; dst bounds() are set to the intersection of subset
and the original bounds().

subset may be larger than bounds(). Any area outside of bounds() is ignored.

Any contents of dst are discarded. isVolatile setting is copied to dst.
dst is set to colorType, alphaType, and colorSpace.

Return false if:
#List
# dst is nullptr ##
# Pixel_Ref is nullptr ##
# subset does not intersect bounds() ##
##

#Param dst  Bitmap set to subset ##
#Param subset  rectangle of pixels to reference ##

#Return  true if dst is replaced by subset
##

#Example
#Image 3
    SkIRect bounds, s;
    source.getBounds(&bounds);
    SkDebugf("bounds: %d, %d, %d, %d\n", bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
    SkBitmap subset;
    for (int left: { -100, 0, 100, 1000 } ) {
         for (int right: { 0, 100, 1000 } ) {
             SkIRect b = SkIRect::MakeLTRB(left, 100, right, 200);
             bool success = source.extractSubset(&subset, b);
             SkDebugf("subset: %4d, %4d, %4d, %4d  ", b.fLeft, b.fTop, b.fRight, b.fBottom);
             SkDebugf("success; %s", success ? "true" : "false");
             if (success) {
                 subset.getBounds(&s);
                 SkDebugf("  subset: %d, %d, %d, %d", s.fLeft, s.fTop, s.fRight, s.fBottom);
             }
             SkDebugf("\n");
         }
    }
#StdOut
bounds: 0, 0, 512, 512
subset: -100,  100,    0,  200  success; false
subset: -100,  100,  100,  200  success; true  subset: 0, 0, 100, 100
subset: -100,  100, 1000,  200  success; true  subset: 0, 0, 512, 100
subset:    0,  100,    0,  200  success; false
subset:    0,  100,  100,  200  success; true  subset: 0, 0, 100, 100
subset:    0,  100, 1000,  200  success; true  subset: 0, 0, 512, 100
subset:  100,  100,    0,  200  success; false
subset:  100,  100,  100,  200  success; false
subset:  100,  100, 1000,  200  success; true  subset: 0, 0, 412, 100
subset: 1000,  100,    0,  200  success; false
subset: 1000,  100,  100,  200  success; false
subset: 1000,  100, 1000,  200  success; false
##
##

#SeeAlso readPixels writePixels SkCanvas::drawBitmap

##

# ------------------------------------------------------------------------------

#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
                    int srcX, int srcY) const
#In Pixels
#Line # copies and converts pixels ##

Copies a Rect of pixels from Bitmap to dstPixels. Copy starts at (srcX, srcY),
and does not exceed Bitmap (width(), height()).

dstInfo specifies width, height, Color_Type, Alpha_Type, and Color_Space of
destination. dstRowBytes specifics the gap from one destination row to the next.
Returns true if pixels are copied. Returns false if:
#List
# dstInfo.addr() equals nullptr ##
# dstRowBytes is less than dstInfo.minRowBytes ##
# Pixel_Ref is nullptr ##
##

Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match.
If Bitmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match.
If Bitmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must
match. If Bitmap colorSpace is nullptr, dstInfo.colorSpace must match. Returns
false if pixel conversion is not possible.

srcX and srcY may be negative to copy only top or left of source. Returns
false if width() or height() is zero or negative.
Returns false if
#Formula
abs(srcX) >= Bitmap width()
##
, or if
#Formula
abs(srcY) >= Bitmap height()
##
.

#Param dstInfo  destination width, height, Color_Type, Alpha_Type, Color_Space ##
#Param dstPixels  destination pixel storage ##
#Param dstRowBytes  destination row length ##
#Param srcX  column index whose absolute value is less than width() ##
#Param srcY  row index whose absolute value is less than height() ##

#Return  true if pixels are copied to dstPixels ##

#Example
#Height 128
#Description
Transferring the gradient from 8 bits per component to 4 bits per component
creates visible banding.
##
    const int width = 256;
    const int height = 64;
    SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
    SkColor  gradColors[] = { 0xFFAA3300, 0x7F881122 };
    SkPoint  gradPoints[] = { { 0, 0 }, { 256, 0 } };
    SkPaint paint;
    paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
                    SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
    SkBitmap bitmap;
    bitmap.allocPixels(srcInfo);
    SkCanvas srcCanvas(bitmap);
    srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
    canvas->drawBitmap(bitmap, 0, 0);
    SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
    std::vector<int16_t> dstPixels;
    dstPixels.resize(height * width);
    bitmap.readPixels(dstInfo, &dstPixels.front(), width * 2, 0, 0);
    SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
    bitmap.installPixels(dstPixmap);
    canvas->drawBitmap(bitmap, 0, 64);
##

#SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels

##

# ------------------------------------------------------------------------------

#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const

Copies a Rect of pixels from Bitmap to dst. Copy starts at (srcX, srcY), and
does not exceed Bitmap (width(), height()).

dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
and row bytes of destination. dst.rowBytes specifics the gap from one destination
row to the next. Returns true if pixels are copied. Returns false if:
#List
# dst pixel storage equals nullptr ##
# dst.rowBytes is less than SkImageInfo::minRowBytes ##
# Pixel_Ref is nullptr ##
##

Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
If Bitmap colorType is kGray_8_SkColorType, dst Color_Space must match.
If Bitmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
match. If Bitmap colorSpace is nullptr, dst Color_Space must match. Returns
false if pixel conversion is not possible.

srcX and srcY may be negative to copy only top or left of source. Returns
false if width() or height() is zero or negative.
Returns false if
#Formula
abs(srcX) >= Bitmap width()
##
, or if
#Formula
abs(srcY) >= Bitmap height()
##
.

#Param dst  destination Pixmap: Image_Info, pixels, row bytes ##
#Param srcX  column index whose absolute value is less than width() ##
#Param srcY  row index whose absolute value is less than height() ##

#Return  true if pixels are copied to dst ##

#Example
#Image 3
    std::vector<int32_t> srcPixels;
    srcPixels.resize(source.height() * source.rowBytes());
    for (int y = 0; y < 4; ++y) {
        for (int x = 0; x < 4; ++x) {
            SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width() / 4, source.height() / 4),
                    &srcPixels.front() + x * source.height() * source.width() / 4 +
                    y * source.width() / 4, source.rowBytes());
            source.readPixels(pixmap, x * source.width() / 4, y * source.height() / 4);
        }
    }
    canvas->scale(.5f, .5f);
    SkBitmap bitmap;
    bitmap.installPixels(SkImageInfo::MakeN32Premul(source.width(), source.height()),
                             &srcPixels.front(), source.rowBytes());
    canvas->drawBitmap(bitmap, 0, 0);
##

#SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels

##

# ------------------------------------------------------------------------------

#Method bool readPixels(const SkPixmap& dst) const

Copies a Rect of pixels from Bitmap to dst. Copy starts at (0, 0), and
does not exceed Bitmap (width(), height()).

dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
and row bytes of destination. dst.rowBytes specifics the gap from one destination
row to the next. Returns true if pixels are copied. Returns false if:
#List
# dst pixel storage equals nullptr ##
# dst.rowBytes is less than SkImageInfo::minRowBytes ##
# Pixel_Ref is nullptr ##
##

Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
If Bitmap colorType is kGray_8_SkColorType, dst Color_Space must match.
If Bitmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
match. If Bitmap colorSpace is nullptr, dst Color_Space must match. Returns
false if pixel conversion is not possible.

#Param dst  destination Pixmap: Image_Info, pixels, row bytes ##

#Return  true if pixels are copied to dst ##

#Example
#Height 128
#Image 3
    std::vector<int32_t> srcPixels;
    srcPixels.resize(source.height() * source.width() * 8);
    for (int i = 0;  i < 2; ++i) {
    SkPixmap pixmap(SkImageInfo::Make(source.width() * 2, source.height(),
                    i ? kRGBA_8888_SkColorType : kBGRA_8888_SkColorType, kPremul_SkAlphaType),
                    &srcPixels.front() + i * source.width(), source.rowBytes() * 2);
        source.readPixels(pixmap);
    }
    canvas->scale(.25f, .25f);
    SkBitmap bitmap;
    bitmap.installPixels(SkImageInfo::MakeN32Premul(source.width() * 2, source.height()),
                         &srcPixels.front(), source.rowBytes() * 2);
    canvas->drawBitmap(bitmap, 0, 0);
##

#SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels

##

# ------------------------------------------------------------------------------

#Method bool writePixels(const SkPixmap& src, int dstX, int dstY)
#In Pixels
#Line # copies and converts pixels ##
Copies a Rect of pixels from src. Copy starts at (dstX, dstY), and does not exceed
(src.width(), src.height()).

src specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
and row bytes of source. src.rowBytes specifics the gap from one source
row to the next. Returns true if pixels are copied. Returns false if:
#List
# src pixel storage equals nullptr ##
# src.rowBytes is less than SkImageInfo::minRowBytes ##
# Pixel_Ref is nullptr ##
##

Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color_Type must match.
If Bitmap colorType is kGray_8_SkColorType, src Color_Space must match.
If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha_Type must
match. If Bitmap colorSpace is nullptr, src Color_Space must match. Returns
false if pixel conversion is not possible.

dstX and dstY may be negative to copy only top or left of source. Returns
false if width() or height() is zero or negative.
Returns false if
#Formula
abs(dstX) >= Bitmap width()
##
, or if
#Formula
abs(dstY) >= Bitmap height()
##
.

#Param src  source Pixmap: Image_Info, pixels, row bytes ##
#Param dstX  column index whose absolute value is less than width() ##
#Param dstY  row index whose absolute value is less than height() ##

#Return  true if src pixels are copied to Bitmap ##

#Example
#Image 3
    std::vector<int32_t> srcPixels;
    int width = image->width();
    int height = image->height();
    srcPixels.resize(height * width  * 4);
    SkPixmap pixmap(SkImageInfo::MakeN32Premul(width, height), (const void*) &srcPixels.front(),
                    width * 4);
    image->readPixels(pixmap, 0, 0);
    canvas->scale(.5f, .5f);
    width /= 4;
    height /= 4;
    for (int y = 0; y < 4; ++y) {
        for (int x = 0; x < 4; ++x) {
            SkBitmap bitmap;
            bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height));
            bitmap.writePixels(pixmap, -y * width, -x * height);
            canvas->drawBitmap(bitmap, x * width, y * height);
        }
    }
##

#SeeAlso readPixels

##

# ------------------------------------------------------------------------------

#Method bool writePixels(const SkPixmap& src)

Copies a Rect of pixels from src. Copy starts at (0, 0), and does not exceed
(src.width(), src.height()).

src specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
and row bytes of source. src.rowBytes specifics the gap from one source
row to the next. Returns true if pixels are copied. Returns false if:
#List
# src pixel storage equals nullptr ##
# src.rowBytes is less than SkImageInfo::minRowBytes ##
# Pixel_Ref is nullptr ##
##

Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color_Type must match.
If Bitmap colorType is kGray_8_SkColorType, src Color_Space must match.
If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha_Type must
match. If Bitmap colorSpace is nullptr, src Color_Space must match. Returns
false if pixel conversion is not possible.

#Param src  source Pixmap: Image_Info, pixels, row bytes ##

#Return  true if src pixels are copied to Bitmap ##

#Example
#Height 80
    SkBitmap bitmap;
    bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2));
    bitmap.eraseColor(SK_ColorGREEN);
    SkPMColor color = 0xFF5599BB;
    SkPixmap src(SkImageInfo::MakeN32Premul(1, 1), &color, 4);
    bitmap.writePixels(src);
    canvas->scale(40, 40);
    canvas->drawBitmap(bitmap, 0, 0);
##

#SeeAlso readPixels

##

# ------------------------------------------------------------------------------

#Method bool hasHardwareMipMap() const
#In Property
#Line # returns Mip_Map support present; Android only ##

For use by Android framework only.

#Return  true if setHasHardwareMipMap has been called with true ##

#NoExample
##

#SeeAlso setHasHardwareMipMap

##

# ------------------------------------------------------------------------------

#Method void setHasHardwareMipMap(bool hasHardwareMipMap)
#In Set
#Line # sets Mip_Map support present; Android only ##

For use by Android framework only.

#Param hasHardwareMipMap  sets state ##

#NoExample
##

#SeeAlso hasHardwareMipMap

##

# ------------------------------------------------------------------------------

#Method bool extractAlpha(SkBitmap* dst) const
#In Constructor
#Line # creates Bitmap containing Alpha of pixels ##
Sets dst to Alpha described by pixels. Returns false if dst cannot be written to
or dst pixels cannot be allocated.

Uses HeapAllocator to reserve memory for dst Pixel_Ref.

#Param dst  holds Pixel_Ref to fill with alpha layer ##

#Return  true if Alpha layer was constructed in dst Pixel_Ref ##

#Example
#Height 100
    SkBitmap alpha, bitmap;
    bitmap.allocN32Pixels(100, 100);
    SkCanvas offscreen(bitmap);
    offscreen.clear(0);
    SkPaint paint;
    paint.setAntiAlias(true);
    paint.setColor(SK_ColorBLUE);
    paint.setStyle(SkPaint::kStroke_Style);
    paint.setStrokeWidth(20);
    offscreen.drawCircle(50, 50, 39, paint);
    offscreen.flush();
    bitmap.extractAlpha(&alpha);
    paint.setColor(SK_ColorRED);
    canvas->drawBitmap(bitmap, 0, 0, &paint);
    canvas->drawBitmap(alpha, 100, 0, &paint);
##

#SeeAlso extractSubset

##

# ------------------------------------------------------------------------------

#Method bool extractAlpha(SkBitmap* dst, const SkPaint* paint,
                      SkIPoint* offset) const

Sets dst to Alpha described by pixels. Returns false if dst cannot be written to
or dst pixels cannot be allocated.

If paint is not nullptr and contains Mask_Filter, SkMaskFilter
generates Mask_Alpha from Bitmap. Uses HeapAllocator to reserve memory for dst
Pixel_Ref. Sets offset to top-left position for dst for alignment with Bitmap;
(0, 0) unless SkMaskFilter generates mask.

#Param dst  holds Pixel_Ref to fill with alpha layer ##
#Param paint  holds optional Mask_Filter; may be nullptr ##
#Param offset  top-left position for dst; may be nullptr ##

#Return  true if Alpha layer was constructed in dst Pixel_Ref ##

#Bug 7103
#Example
#Height 160
    auto radiusToSigma = [](SkScalar radius) -> SkScalar {
         static const SkScalar kBLUR_SIGMA_SCALE = 0.57735f;
         return radius > 0 ? kBLUR_SIGMA_SCALE * radius + 0.5f : 0.0f;
    };
    SkBitmap alpha, bitmap;
    bitmap.allocN32Pixels(100, 100);
    SkCanvas offscreen(bitmap);
    offscreen.clear(0);
    SkPaint paint;
    paint.setAntiAlias(true);
    paint.setColor(SK_ColorBLUE);
    paint.setStyle(SkPaint::kStroke_Style);
    paint.setStrokeWidth(20);
    offscreen.drawCircle(50, 50, 39, paint);
    offscreen.flush();
    paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, radiusToSigma(25)));
    SkIPoint offset;
    bitmap.extractAlpha(&alpha, &paint, &offset);
    paint.setColor(SK_ColorRED);
    canvas->drawBitmap(bitmap, 0, -offset.fY, &paint);
    canvas->drawBitmap(alpha, 100 + offset.fX, 0, &paint);
##

#SeeAlso extractSubset

##

# ------------------------------------------------------------------------------

#Method bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator,
                      SkIPoint* offset) const

Sets dst to Alpha described by pixels. Returns false if dst cannot be written to
or dst pixels cannot be allocated.

If paint is not nullptr and contains Mask_Filter, SkMaskFilter
generates Mask_Alpha from Bitmap. allocator may reference a custom allocation
class or be set to nullptr to use HeapAllocator. Sets offset to top-left
position for dst for alignment with Bitmap; (0, 0) unless SkMaskFilter generates
mask.

#Param dst  holds Pixel_Ref to fill with alpha layer ##
#Param paint  holds optional Mask_Filter; may be nullptr ##
#Param allocator   function to reserve memory for Pixel_Ref; may be nullptr ##
#Param offset  top-left position for dst; may be nullptr ##

#Return  true if Alpha layer was constructed in dst Pixel_Ref ##

#Bug 7104
#Example
#Height 128
    SkBitmap alpha, bitmap;
    bitmap.allocN32Pixels(100, 100);
    SkCanvas offscreen(bitmap);
    offscreen.clear(0);
    SkPaint paint;
    paint.setAntiAlias(true);
    paint.setColor(SK_ColorBLUE);
    paint.setStyle(SkPaint::kStroke_Style);
    paint.setStrokeWidth(20);
    offscreen.drawCircle(50, 50, 39, paint);
    offscreen.flush();
    paint.setMaskFilter(SkMaskFilter::MakeBlur(kOuter_SkBlurStyle, 3));
    SkIPoint offset;
    bitmap.extractAlpha(&alpha, &paint, nullptr, &offset);
    paint.setColor(SK_ColorRED);
    canvas->drawBitmap(bitmap, 0, -offset.fY, &paint);
    canvas->drawBitmap(alpha, 100 + offset.fX, 0, &paint);
##

#SeeAlso extractSubset

##

# ------------------------------------------------------------------------------

#Method bool peekPixels(SkPixmap* pixmap) const
#In Pixels
#Line # returns Pixmap if possible ##
Copies Bitmap pixel address, row bytes, and Image_Info to pixmap, if address
is available, and returns true. If pixel address is not available, return
false and leave pixmap unchanged.

pixmap contents become invalid on any future change to Bitmap.

#Param pixmap  storage for pixel state if pixels are readable; otherwise, ignored ##

#Return true if Bitmap has direct access to pixels ##

#Example
    SkBitmap bitmap;
    bitmap.allocPixels(SkImageInfo::MakeN32Premul(6, 11));
    SkCanvas offscreen(bitmap);
    offscreen.clear(SK_ColorWHITE);
    SkPaint paint;
    offscreen.drawString("?", 0, 10, paint);
    SkPixmap pixmap;
    if (bitmap.peekPixels(&pixmap)) {
        const SkPMColor* pixels = pixmap.addr32();
        SkPMColor pmWhite = pixels[0];
        for (int y = 0; y < bitmap.height(); ++y) {
            for (int x = 0; x < bitmap.width(); ++x) {
                SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
            }
            SkDebugf("\n");
        }
    }
    #StdOut
------
-xxx--
x---x-
----x-
---x--
--x---
--x---
------
--x---
--x---
------
    #StdOut ##
##

#SeeAlso pixmap() installPixels readPixels writePixels

##

# ------------------------------------------------------------------------------
#Subtopic Utility
#Populate
#Line # rarely called management functions ##
##

#Method void validate() const;
#In Utility
#Line # asserts if Bitmap is invalid (debug only) ##
Asserts if internal values are illegal or inconsistent. Only available if
SK_DEBUG is defined at compile time.

#NoExample
##

#SeeAlso SkImageInfo::validate

##

# ------------------------------------------------------------------------------

#Class SkBitmap ##

#Topic Bitmap ##