REC-PNG-20031110
311 KB
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
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Portable Network Graphics (PNG) Specification (Second Edition)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="./isostyle.css" type="text/css" />
<style type="text/css">
/* remove annoying green color from definition terms */
dt {color: black}
</style>
<link rel="stylesheet" type="text/css" media="screen"
href="http://www.w3.org/StyleSheets/TR/W3C-REC" />
</head>
<body>
<div class="head">
<p><a href="http://www.w3.org/"><img height="48" width="72"
alt="W3C" src="http://www.w3.org/Icons/w3c_home" /></a></p>
<h1 id="pagetitle">Portable Network Graphics (PNG) Specification (Second Edition)</h1>
<h1>Information technology — Computer graphics and image processing — Portable Network Graphics (PNG): Functional specification. ISO/IEC 15948:2003 (E)</h1>
<!--h2 id="pagesubtitle">W3C Recommendation 1 October 1996, revised 14 October 2003</h2-->
<h2 id="pagesubtitle">W3C Recommendation 10 November 2003</h2>
<dl>
<dt>This version:</dt>
<dd><a
href="http://www.w3.org/TR/2003/REC-PNG-20031110">http://www.w3.org/TR/2003/REC-PNG-20031110</a></dd>
<dt>Latest version:</dt>
<dd><a
href="http://www.w3.org/TR/PNG">http://www.w3.org/TR/PNG</a></dd>
<dt>Previous version:</dt>
<dd><a
href="http://www.w3.org/TR/2003/PR-PNG-20030520">http://www.w3.org/TR/2003/PR-PNG-20030520</a></dd>
<dt>Editor:</dt>
<dd>David Duce, Oxford Brookes University (Second Edition)</dd>
<dt>Authors:</dt>
<dd>See <a href="#F-Relationship">author list</a></dd>
</dl>
<p>Please refer to the <a href="http://www.w3.org/2003/11/REC-PNG-20031110-errata"><strong>errata</strong></a> for this document, which may include some normative corrections.</p>
<!--p>This document is also available in these non-normative
packages: <a href="REC-SVG11-20030114.zip">zip archive of
HTML</a> (without external dependencies) and <a
href="REC-SVG11-20030114.pdf">PDF</a>.</p-->
<p>See also the <a href="http://www.w3.org/Consortium/Translation/">translations</a> of this document.</p>
<p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"> Copyright</a> © 2003 <a href="http://www.w3.org/"><acronym title="World Wide Web Consortium">W3C</acronym></a><sup>®</sup> (<a href="http://www.lcs.mit.edu/"><acronym title="Massachusetts Institute of Technology">MIT</acronym></a>, <a href="http://www.ercim.org/"><acronym title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>, <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>, <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-software">software licensing</a> rules apply.</p>
</div>
<hr title="Separator from Header" />
<h2 id="specabstract"><a id="abstract" name="abstract">Abstract</a></h2>
<p>This document describes PNG (Portable Network Graphics), an extensible file format for the lossless, portable, well-compressed storage of raster images. PNG provides a patent-free replacement for GIF and can also replace many common uses of TIFF. Indexed-color, grayscale, and truecolor images are supported, plus an optional alpha channel. Sample depths range from 1 to 16 bits.</p>
<p>PNG is designed to work well in online viewing applications, such as the World Wide Web, so it is fully streamable with a progressive display option. PNG is robust, providing both full file integrity checking and simple detection of common transmission errors. Also, PNG can store gamma and chromaticity data for improved color matching on heterogeneous platforms.</p>
<p>This specification defines an Internet Media Type image/png.</p>
<h2 id="status">Status of this document</h2>
<p><em>This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the <a href="http://www.w3.org/TR/">W3C technical reports index</a> at http://www.w3.org/TR/.</em></p>
<p>This document is the 14 October 2003 W3C
Recommendation of the PNG specification, second edition. It is also International Standard, ISO/IEC 15948:2003. The two documents have exactly identical content except for cover page and boilerplate differences as appropriate to the two organisations.</p>
<p>This International Standard is strongly based on the W3C Recommendation 'PNG Specification Version 1.0' which was reviewed by W3C members, approved as a W3C Recommendation and published in October 1996. This second edition incorporates all known errata and clarifications. </p>
<p>A complete review of the document has been done by ISO/IEC/JTC 1/SC 24 in collaboration with W3C and the PNG development group (the original authors of the PNG 1.0 Recommendation) in order to transform that Recommendation into an ISO/IEC international standard. A major design goal during this review was to avoid changes that will invalidate existing files, editors, or viewers that conform to W3C Recommendation PNG Specification Version 1.0.</p>
<p>The PNG specification enjoys a good level of <a href="http://www.libpng.org/pub/png/pngstatus.html">implementation</a> with good interoperability. At the time of this publication more than 180 <a href="http://www.libpng.org/pub/png/pngapvw.html">image viewers</a> could display PNG images and over 100 <a href="http://www.libpng.org/pub/png/pngaped.html">image editors</a> could read and write valid PNG files. Full support of PNG is required for conforming <a href="/Graphics/SVG">SVG</a> viewers; at the time of publication all eighteen <a href="/Graphics/SVG/SVG-Implementations.htm8#viewer">SVG viewers</a> had PNG support. HTML has no required image formats, but over 60 <a href="http://www.libpng.org/pub/png/pngapbr.html">HTML browsers</a> had at least basic support of PNG images.</p>
<p>Public comments on this W3C Recommendation are welcome.
Please send them to the <a href="http://lists.w3.org/Archives/Public/png-group">archived</a> list <a href="mailto:png-group@w3.org">png-group@w3.org</a> .</p>
<p>The latest information regarding <a rel="disclosure"
href="http://www.w3.org/Graphics/PNG/Disclosures">patent
disclosures</a> related to this document is available on the
Web. As of this publication, the PNG Group are not
aware of any royalty-bearing patents they believe to be
essential to PNG.</p>
<p>This document has been produced by ISO/IEC JTC1 SC24 and the PNG Group as part of the <a
href="http://www.w3.org/Graphics/Activity">Graphics
Activity</a> within the <a href="http://www.w3.org/Interaction/">W3C
Interaction Domain</a>. </p>
<!-- removed p>A list of current W3C Recommendations and
other technical documents can be found at <a
href="http://www.w3.org/TR/">http://www.w3.org/TR/</a>.
W3C publications may be updated, replaced, or obsoleted by other
documents at any time.
</p-->
<div><p><strong>Note:</strong> To provide the highest quality images, this specification uses SVG diagrams with a PNG fallback using the HTML object element. SVG-enabled browsers will see the SVG figures with selectable text, other browsers will display the raster PNG version.</p>
<p>W3C is aware that there is a <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=133567">known incompatibility</a> between the unsupported beta of Adobe SVG plugin for Linux and Mozilla versions greater than 0.9.9 due to changes in the plug-in API, causing a browser crash. Therefore, a normative <a href="./index-noobject.html">PNG-only alternative version</a> is available that does not use an object element. The two versions are otherwise identical.</p></div>
<h3 id="AvailableLanguages">Available languages</h3>
<p>The English version of this specification is the only
normative version. However, for translations in other languages
see <a
href="http://www.w3.org/Consortium/Translation/">
http://www.w3.org/Consortium/Translation/</a>.</p>
<div class="toc">
<h2><a id="minitoc" name="minitoc">Table of Contents</a></h2>
<ul class="toc">
<!--li class="tocline1"-->
<li class='Contents'><a class='Href' href='#1Scope'>1
Scope</a></li>
<li class='Contents'><a class='Href' href='#2NormRefs'>2
Normative references</a></li>
<li class='Contents'><a class='Href' href='#3Defsandabbrevs'>3
Terms, definitions, and abbreviated terms</a>
<ul>
<li class='Contents'><a class='Href' href='#3Definitions'>3.1
Definitions</a></li>
<li class='Contents'><a class='Href' href='#3Abbreviations'>3.2
Abbreviated terms</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#4Concepts'>4
Concepts</a>
<ul>
<li class='Contents'><a class='Href' href=
'#4Concepts.Sourceimage'>4.1 Images</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.ColourSpaces'>4.2 Colour spaces</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.PNGImageTransformation'>4.3 Reference image to PNG
image transformation</a>
<ul>
<li class='Contents'><a class='Href' href=
'#4Concepts.Introduction'>4.3.1 Introduction</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.Implied-alpha'>4.3.2 Alpha separation</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.Indexing'>4.3.3 Indexing</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.RGBMerging'>4.3.4 RGB merging</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.Alpha-indexing'>4.3.5 Alpha compaction</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.Scaling'>4.3.6 Sample depth scaling</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href=
'#4Concepts.PNGImage'>4.4 PNG image</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.Encoding'>4.5 Encoding the PNG image</a>
<ul>
<li class='Contents'><a class='Href' href=
'#4Concepts.EncodingIntro'>4.5.1 Introduction</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.EncodingPassAbs'>4.5.2 Pass extraction</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.EncodingScanlineAbs'>4.5.3 Scanline
serialization</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.EncodingFiltering'>4.5.4 Filtering</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.EncodingCompression'>4.5.5 Compression</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.EncodingChunking'>4.5.6 Chunking</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href=
'#4Concepts.AncillInfo'>4.6 Additional information</a></li>
<li class='Contents'><a class='Href' href='#4Concepts.Format'>4.7
PNG datastream</a>
<ul>
<li class='Contents'><a class='Href' href=
'#4Concepts.FormatChunks'>4.7.1 Chunks</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.FormatTypes'>4.7.2 Chunk types</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#4Concepts.Errors'>4.8
Error handling</a></li>
<li class='Contents'><a class='Href' href=
'#4Concepts.Registration'>4.9 Extension and registration</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#5DataRep'>5
Datastream structure</a>
<ul>
<li class='Contents'><a class='Href' href='#5Introduction'>5.1
Introduction</a></li>
<li class='Contents'><a class='Href' href=
'#5PNG-file-signature'>5.2 PNG signature</a></li>
<li class='Contents'><a class='Href' href='#5Chunk-layout'>5.3
Chunk layout</a></li>
<li class='Contents'><a class='Href' href=
'#5Chunk-naming-conventions'>5.4 Chunk naming
conventions</a></li>
<li class='Contents'><a class='Href' href='#5CRC-algorithm'>5.5
Cyclic Redundancy Code algorithm</a></li>
<li class='Contents'><a class='Href' href='#5ChunkOrdering'>5.6
Chunk ordering</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#6Transformation'>6
Reference image to PNG image transformation</a>
<ul>
<li class='Contents'><a class='Href' href='#6Colour-values'>6.1
Colour types and values</a></li>
<li class='Contents'><a class='Href' href=
'#6AlphaRepresentation'>6.2 Alpha representation</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#7Transformation'>7
Encoding the PNG image as a PNG datastream</a>
<ul>
<li class='Contents'><a class='Href' href=
'#7Integers-and-byte-order'>7.1 Integers and byte order</a></li>
<li class='Contents'><a class='Href' href='#7Scanline'>7.2
Scanlines</a></li>
<li class='Contents'><a class='Href' href='#7Filtering'>7.3
Filtering</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#8Interlace'>8
Interlacing and pass extraction</a>
<ul>
<li class='Contents'><a class='Href' href='#8InterlaceIntro'>8.1
Introduction</a></li>
<li class='Contents'><a class='Href' href=
'#8InterlaceMethods'>8.2 Interlace methods</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#9Filters'>9
Filtering</a>
<ul>
<li class='Contents'><a class='Href' href='#9FtIntro'>9.1 Filter
methods and filter types</a></li>
<li class='Contents'><a class='Href' href='#9Filter-types'>9.2
Filter types for filter method 0</a></li>
<li class='Contents'><a class='Href' href=
'#9Filter-type-3-Average'>9.3 Filter type 3: Average</a></li>
<li class='Contents'><a class='Href' href=
'#9Filter-type-4-Paeth'>9.4 Filter type 4: Paeth</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#10Compression'>10
Compression</a>
<ul>
<li class='Contents'><a class='Href' href=
'#10CompressionCM0'>10.1 Compression method 0</a></li>
<li class='Contents'><a class='Href' href=
'#10CompressionFSL'>10.2 Compression of the sequence of filtered
scanlines</a></li>
<li class='Contents'><a class='Href' href=
'#10CompressionOtherUses'>10.3 Other uses of compression</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#11Chunks'>11 Chunk
specifications</a>
<ul>
<li class='Contents'><a class='Href' href='#11Introduction'>11.1
Introduction</a></li>
<li class='Contents'><a class='Href' href=
'#11Critical-chunks'>11.2 Critical chunks</a>
<ul>
<li class='Contents'><a class='Href' href='#11CcGen'>11.2.1
General</a></li>
<li class='Contents'><a class='Href' href='#11IHDR'>11.2.2 <span
class='chunk'>IHDR</span> Image header</a></li>
<li class='Contents'><a class='Href' href='#11PLTE'>11.2.3 <span
class='chunk'>PLTE</span> Palette</a></li>
<li class='Contents'><a class='Href' href='#11IDAT'>11.2.4 <span
class='chunk'>IDAT</span> Image data</a></li>
<li class='Contents'><a class='Href' href='#11IEND'>11.2.5 <span
class='chunk'>IEND</span> Image trailer</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href=
'#11Ancillary-chunks'>11.3 Ancillary chunks</a>
<ul>
<li class='Contents'><a class='Href' href='#11AcGen'>11.3.1
General</a></li>
<li class='Contents'><a class='Href' href='#11transinfo'>11.3.2
Transparency information</a>
<ul>
<li class='Contents'><a class='Href' href='#11tRNS'>11.3.2.1
<span class='chunk'>tRNS</span> Transparency</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href=
'#11addnlcolinfo'>11.3.3 Colour space information</a>
<ul>
<li class='Contents'><a class='Href' href='#11cHRM'>11.3.3.1
<span class='chunk'>cHRM</span> Primary chromaticities and white
point</a></li>
<li class='Contents'><a class='Href' href='#11gAMA'>11.3.3.2
<span class='chunk'>gAMA</span> Image gamma</a></li>
<li class='Contents'><a class='Href' href='#11iCCP'>11.3.3.3
<span class='chunk'>iCCP</span> Embedded ICC profile</a></li>
<li class='Contents'><a class='Href' href='#11sBIT'>11.3.3.4
<span class='chunk'>sBIT</span> Significant bits</a></li>
<li class='Contents'><a class='Href' href='#11sRGB'>11.3.3.5
<span class='chunk'>sRGB</span> Standard RGB colour
space</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#11textinfo'>11.3.4
Textual information</a>
<ul>
<li class='Contents'><a class='Href' href='#11textIntro'>11.3.4.1
Introduction</a></li>
<li class='Contents'><a class='Href' href='#11keywords'>11.3.4.2
Keywords and text strings</a></li>
<li class='Contents'><a class='Href' href='#11tEXt'>11.3.4.3
<span class='chunk'>tEXt</span> Textual data</a></li>
<li class='Contents'><a class='Href' href='#11zTXt'>11.3.4.4
<span class='chunk'>zTXt</span> Compressed textual data</a></li>
<li class='Contents'><a class='Href' href='#11iTXt'>11.3.4.5
<span class='chunk'>iTXt</span> International textual
data</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#11addnlsiinfo'>11.3.5
Miscellaneous information</a>
<ul>
<li class='Contents'><a class='Href' href='#11bKGD'>11.3.5.1
<span class='chunk'>bKGD</span> Background colour</a></li>
<li class='Contents'><a class='Href' href='#11hIST'>11.3.5.2
<span class='chunk'>hIST</span> Image histogram</a></li>
<li class='Contents'><a class='Href' href='#11pHYs'>11.3.5.3
<span class='chunk'>pHYs</span> Physical pixel
dimensions</a></li>
<li class='Contents'><a class='Href' href='#11sPLT'>11.3.5.4
<span class='chunk'>sPLT</span> Suggested palette</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href=
'#11timestampinfo'>11.3.6 Time stamp information</a>
<ul>
<li class='Contents'><a class='Href' href='#11tIME'>11.3.6.1
<span class='chunk'>tIME</span> Image last-modification
time</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#12Encoders'>12 PNG
Encoders</a>
<ul>
<li class='Contents'><a class='Href' href='#12Introduction'>12.1
Introduction</a></li>
<li class='Contents'><a class='Href' href=
'#12Encoder-gamma-handling'>12.2 Encoder gamma handling</a></li>
<li class='Contents'><a class='Href' href=
'#12Encoder-colour-handling'>12.3 Encoder colour
handling</a></li>
<li class='Contents'><a class='Href' href=
'#12Alpha-channel-creation'>12.4 Alpha channel creation</a></li>
<li class='Contents'><a class='Href' href=
'#12Sample-depth-scaling'>12.5 Sample depth scaling</a></li>
<li class='Contents'><a class='Href' href=
'#12Suggested-palettes'>12.6 Suggested palettes</a></li>
<li class='Contents'><a class='Href' href='#12Interlacing'>12.7
Interlacing</a></li>
<li class='Contents'><a class='Href' href=
'#12Filter-selection'>12.8 Filter selection</a></li>
<li class='Contents'><a class='Href' href='#12Compression'>12.9
Compression</a></li>
<li class='Contents'><a class='Href' href=
'#12Text-chunk-processing'>12.10 Text chunk processing</a></li>
<li class='Contents'><a class='Href' href=
'#12Chunk-processing'>12.11 Chunking</a>
<ul>
<li class='Contents'><a class='Href' href=
'#12Use-of-private-chunks'>12.11.1 Use of private chunks</a></li>
<li class='Contents'><a class='Href' href=
'#12Private-type-and-method-codes'>12.11.2 Private type and
method codes</a></li>
<li class='Contents'><a class='Href' href='#12Ancillary'>12.11.3
Ancillary chunks</a></li>
</ul>
</li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#13Decoders'>13 PNG
decoders and viewers</a>
<ul>
<li class='Contents'><a class='Href' href='#13Introduction'>13.1
Introduction</a></li>
<li class='Contents'><a class='Href' href=
'#13Decoders.Errors'>13.2 Error handling</a></li>
<li class='Contents'><a class='Href' href=
'#13Error-checking'>13.3 Error checking</a></li>
<li class='Contents'><a class='Href' href=
'#13Security-considerations'>13.4 Security
considerations</a></li>
<li class='Contents'><a class='Href' href='#13Chunking'>13.5
Chunking</a></li>
<li class='Contents'><a class='Href' href=
'#13Pixel-dimensions'>13.6 Pixel dimensions</a></li>
<li class='Contents'><a class='Href' href=
'#13Text-chunk-processing'>13.7 Text chunk processing</a></li>
<li class='Contents'><a class='Href' href='#13Decompression'>13.8
Decompression</a></li>
<li class='Contents'><a class='Href' href='#13Filtering'>13.9
Filtering</a></li>
<li class='Contents'><a class='Href' href=
'#13Progressive-display'>13.10 Interlacing and progressive
display</a></li>
<li class='Contents'><a class='Href' href=
'#13Truecolour-image-handling'>13.11 Truecolour image
handling</a></li>
<li class='Contents'><a class='Href' href=
'#13Sample-depth-rescaling'>13.12 Sample depth rescaling</a></li>
<li class='Contents'><a class='Href' href=
'#13Decoder-gamma-handling'>13.13 Decoder gamma handling</a></li>
<li class='Contents'><a class='Href' href=
'#13Decoder-colour-handling'>13.14 Decoder colour
handling</a></li>
<li class='Contents'><a class='Href' href=
'#13Background-colour'>13.15 Background colour</a></li>
<li class='Contents'><a class='Href' href=
'#13Alpha-channel-processing'>13.16 Alpha channel
processing</a></li>
<li class='Contents'><a class='Href' href=
'#13Histogram-and-suggested-palette-usage'>13.17
Histogram and suggested palette usage</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#14EditorsExt'>14
Editors and extensions</a>
<ul>
<li class='Contents'><a class='Href' href=
'#14Additional-chunk-types'>14.1 Additional chunk types</a></li>
<li class='Contents'><a class='Href' href='#14Ordering'>14.2
Behaviour of PNG editors</a></li>
<li class='Contents'><a class='Href' href=
'#14Ordering-of-chunks'>14.3 Ordering of chunks</a>
<ul>
<li class='Contents'><a class='Href' href=
'#14Ordering-of-critical-chunks'>14.3.1 Ordering of critical
chunks</a></li>
<li class='Contents'><a class='Href' href=
'#14Ordering-of-ancillary-chunks'>14.3.2 Ordering of ancillary
chunks</a></li>
</ul>
</li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#15Conformance'>15
Conformance</a>
<ul>
<li class='Contents'><a class='Href' href='#15ConfIntro'>15.1
Introduction</a>
<ul>
<li class='Contents'><a class='Href' href=
'#15ConfObjectives'>15.1.1 Objectives</a></li>
<li class='Contents'><a class='Href' href='#15ConfScope'>15.1.2
Scope</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href=
'#15ConformanceConf'>15.2 Conformance conditions</a>
<ul>
<li class='Contents'><a class='Href' href=
'#15FileConformance'>15.2.1 Conformance of PNG
datastreams</a></li>
<li class='Contents'><a class='Href' href=
'#15ConformanceEncoder'>15.2.2 Conformance of PNG
encoders</a></li>
<li class='Contents'><a class='Href' href=
'#15ConformanceDecoder'>15.2.3 Conformance of PNG
decoders</a></li>
<li class='Contents'><a class='Href' href=
'#15ConformanceEditor'>15.2.4 Conformance of PNG editors</a></li>
</ul>
</li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#A-Conventions'>Annex
A File conventions and Internet media type</a>
<ul>
<li class='Contents'><a class='Href' href=
'#A-File-name-extension'>A.1 File name extension</a></li>
<li class='Contents'><a class='Href' href='#A-Media-type'>A.2
Internet media type</a></li>
<li class='Contents'><a class='Href' href=
'#A-Macintosh-file-layout'>A.3 Macintosh file layout</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href=
'#B-NewChunksAppendix'>Annex B Guidelines for new chunk
types</a></li>
<li class='Contents'><a class='Href' href=
'#C-GammaAppendix'>Annex C Gamma and chromaticity</a></li>
<li class='Contents'><a class='Href' href='#D-CRCAppendix'>Annex
D Sample Cyclic Redundancy Code implementation</a></li>
<li class='Contents'><a class='Href' href='#E-Resources'>Annex E
Online resources</a>
<ul>
<li class='Contents'><a class='Href' href=
'#E-Intro'>Introduction</a></li>
<li class='Contents'><a class='Href' href=
'#E-Archive-sites'>Archive sites</a></li>
<li class='Contents'><a class='Href' href=
'#E-icc-profile-specs'>ICC profile specifications</a></li>
<li class='Contents'><a class='Href' href='#E-PNG-home-page'>PNG
web site</a></li>
<li class='Contents'><a class='Href' href=
'#E-Sample-implementation'>Sample implementation and test
images</a></li>
<li class='Contents'><a class='Href' href='#E-Email'>Electronic
mail</a></li>
</ul>
</li>
<li class='Contents'><a class='Href' href='#F-Relationship'>Annex
F Relationship to W3C PNG</a>
<ul>
<li class='Contents'><a class='Href' href='#F-Editor10'>Editor
(Version 1.0)</a></li>
<li class='Contents'><a class='Href' href='#F-Editor12'>Editor
(Versions 1.1 and 1.2)</a></li>
<li class='Contents'><a class='Href' href=
'#F-ContribEditor10'>Contributing Editor (Version 1.0)</a></li>
<li class='Contents'><a class='Href' href=
'#F-ContribEditor12'>Contributing Editor (Versions 1.1 and 1.2)</a></li>
<li class='Contents'><a class='Href' href='#F-Authors'>Authors
(Versions 1.0, 1.1, and 1.2 combined)</a></li>
<li class='Contents'><a class='Href' href='#F-ChangeList'>List of
changes between W3C Recommendation PNG Specification Version 1.0
and this International Standard</a>
<ul>
<li class='Contents'><a class='Href' href=
'#F-EditorialChanges'>Editorial changes</a></li>
<li class='Contents'><a class='Href' href=
'#F-TechnicalChanges'>Technical changes</a></li>
</ul>
</li>
</ul>
</li>
<li class='Contents'><a class='Href' href=
'#G-References'>Bibliography</a></li>
</ul>
</div>
<!-- *********************************************************************
FROM HERE ON THIS FILE IS IDENTICAL TO THE ISO VERSION
with these exceptions:
- id added to any headings that did not have one, to comply with pubrules and allow indexing into the document
- URL for this document updated in Annex E and the words " [to be completed when published]" removed
************************************************************************** -->
<h1><a name="Introduction">Introduction</a></h1>
<p></p>
<p>The design goals for this International Standard were:</p>
<ol>
<li>Portability: encoding, decoding, and transmission should be
software and hardware platform independent.</li>
<li>Completeness: it should be possible to represent truecolour,
indexed-colour, and greyscale images, in each case with the
option of transparency, colour space information, and ancillary
information such as textual comments.</li>
<li>Serial encode and decode: it should be possible for
datastreams to be generated serially and read serially, allowing
the datastream format to be used for on-the-fly generation and
display of images across a serial communication channel.</li>
<li>Progressive presentation: it should be possible to transmit
datastreams so that an approximation of the whole image can be
presented initially, and progressively enhanced as the datastream
is received.</li>
<li>Robustness to transmission errors: it should be possible to
detect datastream transmission errors reliably.</li>
<li>Losslessness: filtering and compression should preserve all
information.</li>
<li>Performance: any filtering, compression, and progressive
image presentation should be aimed at efficient decoding and
presentation. Fast encoding is a less important goal than fast
decoding. Decoding speed may be achieved at the expense of
encoding speed.</li>
<li>Compression: images should be compressed effectively,
consistent with the other design goals.</li>
<li>Simplicity: developers should be able to implement the
standard easily.</li>
<li>Interchangeability: any standard-conforming PNG decoder shall
be capable of reading all conforming PNG datastreams.</li>
<li>Flexibility: future extensions and private additions should
be allowed for without compromising the interchangeability of
standard PNG datastreams.</li>
<li>Freedom from legal restrictions: no algorithms should be used
that are not freely available.</li>
</ol>
<h1><a name="1Scope">1 Scope</a></h1>
<p>This International Standard specifies a datastream and an
associated file format, Portable Network Graphics (PNG,
pronounced "ping"), for a lossless, portable, compressed
individual computer graphics image transmitted across the
Internet. Indexed-colour, greyscale, and truecolour images are
supported, with optional transparency. Sample depths range from 1
to 16 bits. PNG is fully streamable with a progressive display
option. It is robust, providing both full file integrity checking
and simple detection of common transmission errors. PNG can store
gamma and chromaticity data as well as a full ICC colour profile
for accurate colour matching on heterogenous platforms. This
Standard defines the Internet Media type "image/png". The
datastream and associated file format have value outside of the
main design goal.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="2NormRefs">2 Normative references</a></h1>
<p>The following normative documents contain provisions which,
through reference in this text, constitute provisions of this
International Standard. For dated references, subsequent
amendments to, or revisions of, any of these publications do not
apply. However, parties to agreements based on this International
Standard are encouraged to investigate the possibility of
applying the most recent editions of the normative documents
indicated below. For undated references, the latest edition of
the normative document referred to applies. Members of ISO and
IEC maintain registers of currently valid International
Standards.</p>
<p class="NormRefDef"><a name="2-ISO-639">ISO 639:1988</a>,
<i>Code for the representation of names of languages</i>.</p>
<p class="NormRefDef"><a name="2-ISO-646">ISO/IEC 646:1991</a>,
<i>International Organization for Standardization, Information
technology — ISO 7-bit coded character set for information
interchange</i>.</p>
<p class="NormRefDef"><a name="2-ISO-3309">ISO/IEC 3309:1993</a>,
<i>Information Technology — Telecommunications and
information exchange between systems — High-level data link
control (HDLC) procedures — Frame structure</i>.</p>
<p class="NormRefDef"><a name="2-ISO-8859-1">ISO/IEC
8859-1:1998</a>, <i>Information technology — 8-bit
single-byte coded graphic character sets — Part 1: Latin
alphabet No. 1</i>.<br class="xhtml" />
For convenience, here is a non-normative <a href="iso_8859-1.txt">sample text file</a>
describing the codes and associated character names.</p>
<p class="NormRefDef"><a name="2-ISO-9899">ISO/IEC
9899:1990(R1997)</a>, <i>Programming languages — C</i>.</p>
<p class="NormRefDef"><a name="2-ISO-10646-1">ISO/IEC
10646-1:1993/AMD.2</a>, <i>Information technology —
Universal Multiple-Octet Coded Character Sets (UCS) — Part
1: Architecture and Basic Multilingual Plane</i>.</p>
<p class="NormRefDef"><a name="2-IEC-61966-2-1">IEC
61966-2-1</a>, <i>Multimedia systems and equipment — Colour
measurement and management — Part 2-1: Default RGB colour
space — sRGB,</i> available at <code><a href=
"http://www.iec.ch">http://www.iec.ch/</a></code>.</p>
<p class="NormRefDef"><a name="2-CIE-15.2">CIE-15.2</a>, CIE,
"Colorimetry, Second Edition". CIE Publication 15.2-1986. ISBN
3-900-734-00-3.</p>
<p class="NormRefDef"><a name="2-ICC-1">ICC-1</a>, International
Color Consortium, "Specification ICC.1: 1998-09, File Format for
Color Profiles", 1998, available at <code><a href=
"http://www.color.org/">http://www.color.org/</a></code></p>
<p class="NormRefDef"><a name="2-ICC-1A">ICC-1A</a>,
International Color Consortium, "Specification ICC.1A: 1999-04,
Addendum 2 to ICC.1: 1998-09", 1999, available at <code><a href=
"http://www.color.org/">http://www.color.org/</a></code></p>
<p class="NormRefDef"><a name="2-RFC-1123">RFC-1123</a>, Braden,
R., Editor, "Requirements for Internet Hosts — Application
and Support", STD 3, RFC 1123, USC/Information Sciences
Institute, October 1989.<br class="xhtml" />
<code><a href=
"http://www.ietf.org/rfc/rfc1123.txt">http://www.ietf.org/rfc/rfc1123.txt</a></code></p>
<p class="NormRefDef"><a name="2-RFC-1950">RFC-1950</a>, Deutsch,
P. and Gailly, J-L., "ZLIB Compressed Data Format Specification
version 3.3", RFC 1950, Aladdin Enterprises, May 1996.<br class="xhtml" />
<code><a href=
"http://www.ietf.org/rfc/rfc1950.txt">http://www.ietf.org/rfc/rfc1950.txt</a></code></p>
<p class="NormRefDef"><a name="2-RFC-1951">RFC-1951</a>, Deutsch,
P., "DEFLATE Compressed Data Format Specification version 1.3",
RFC 1951, Aladdin Enterprises, May 1996.<br class="xhtml" />
<code><a href=
"http://www.ietf.org/rfc/rfc1951.txt">http://www.ietf.org/rfc/rfc1951.txt</a></code></p>
<p class="NormRefDef"><a name="2-RFC-2045">RFC-2045</a>, Freed,
N. and Borenstein, N. , "MIME (Multipurpose Internet Mail
Extensions) Part One: Format of Internet Message Bodies", RFC
2045, Innosoft, First Virtual, November 1996.<br class="xhtml" />
<code><a href=
"http://www.ietf.org/rfc/rfc2045.txt">http://www.ietf.org/rfc/rfc2045.txt</a></code></p>
<p class="NormRefDef"><a name="2-RFC-2048">RFC-2048</a>, Freed,
N., Klensin, J. and Postel, J., "Multipurpose Internet Mail
Extensions (MIME) Part Four: Registration Procedures", RFC 2048,
Innosoft, MCI, ISI, November 1996.<br class="xhtml" />
<code><a href=
"http://www.ietf.org/rfc/rfc2048.txt">http://www.ietf.org/rfc/rfc2048.txt</a></code></p>
<p class="NormRefDef"><a name="2-RFC-3066">RFC-3066</a>,
Alvestrand, H., "Tags for the Identification of Languages", RFC
3066, Cisco Systems, January 2001. (Obsoletes RFC 1766.)<br class="xhtml" />
<code><a href=
"http://www.ietf.org/rfc/rfc3066.txt">http://www.ietf.org/rfc/rfc3066.txt</a></code></p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="3Defsandabbrevs">3 Terms, definitions, and
abbreviated terms</a></h1>
<h2><a name="3Definitions">3.1 Definitions</a></h2>
<p>For the purposes of this International Standard the following
definitions apply.</p>
<dl>
<dt><a name="3alpha">3.1.1 alpha</a></dt>
<dd>a value representing a <a href="#3pixel"><span class=
"Definition">pixel's</span></a> degree of opacity. The more
opaque a pixel, the more it hides the background against which
the image is presented. Zero alpha represents a completely
transparent pixel, maximum alpha represents a completely opaque
pixel.</dd>
<dt><a name="3alphaCompaction">3.1.2 alpha compaction</a></dt>
<dd>an implicit representation of transparent <a href=
"#3pixel"><span class="Definition">pixels</span></a>. If every
pixel with a specific colour or <a href="#3greyscale"><span
class="Definition">greyscale</span></a> value is fully
transparent and all other pixels are fully opaque, the <a href=
"#3alpha"><span class="Definition">alpha</span></a> <a href=
"#3channel"><span class="Definition">channel</span></a> may be
represented implicitly.</dd>
<dt><a name="3alphaSeparation">3.1.3 alpha separation</a></dt>
<dd>separating an <a href="#3alpha"><span class=
"Definition">alpha</span></a> <a href="#3channel"><span class=
"Definition">channel</span></a> in which every <a href=
"#3pixel"><span class="Definition">pixel</span></a> is fully
opaque; all alpha values are the maximum value.
The fact that all pixels are fully opaque is represented implicitly.
</dd>
<dt><a name="3alphaTable">3.1.4 alpha table</a></dt>
<dd>indexed table of <a href="#3alpha"><span class=
"Definition">alpha</span></a> <a href="#3sample"><span class=
"Definition">sample</span></a> values, which in an <a href=
"#3indexedColour"><span class=
"Definition">indexed-colour</span></a> image defines the alpha
sample values of the <a href="#3referenceImage"><span class=
"Definition">reference image</span></a>. The alpha table has the
same number of entries as the <a href="#3palette"><span class=
"Definition">palette</span></a>.</dd>
<dt><a name="3ancillaryChunk">3.1.5 ancillary chunk</a></dt>
<dd>class of <a href="#3chunk"><span class=
"Definition">chunk</span></a> that provides additional
information. A <a href="#3PNGdecoder"><span class=
"Definition">PNG decoder</span></a>, without processing an
ancillary chunk, can still produce a meaningful image, though not
necessarily the best possible image.
<!-- agreed: don't need to define a bit -->
</dd>
<dt><a name="3bitDepth">3.1.6 bit depth</a></dt>
<dd>for <a href="#3indexedColour"><span class=
"Definition">indexed-colour</span></a> images, the number of bits
per <a href="#3palette"><span class=
"Definition">palette</span></a> index. For other images, the
number of bits per <a href="#3sample"><span class=
"Definition">sample</span></a> in the image. This is the value
that appears in the <a href="#11IHDR"><span class=
"chunk">IHDR</span></a> <a href="#3chunk"><span class=
"Definition">chunk</span></a>.</dd>
<dt><a name="3byte">3.1.7 byte</a></dt>
<dd>8 bits; also called an octet. The highest bit (value 128) of
a byte is numbered bit 7; the lowest bit (value 1) is numbered
bit 0.</dd>
<dt><a name="3byteOrder">3.1.8 byte order</a></dt>
<dd>ordering of <a href="#3byte"><span class=
"Definition">bytes</span></a> for multi-byte data values within a
<a href="#3PNGfile"><span class="Definition">PNG file</span></a>
or <a href="#3PNGdatastream"><span class="Definition">PNG
datastream</span></a>. PNG uses <a href=
"#3networkByteOrder"><span class="Definition">network byte
order</span></a>.</dd>
<dt><a name="3channel">3.1.9 channel</a></dt>
<dd>array of all per-<a href="#3pixel"><span class=
"Definition">pixel</span></a> information of a particular kind
within a <a href="#3referenceImage"><span class=
"Definition">reference image</span></a>. There are five kinds of
information: red, green, blue, <a href="#3greyscale"><span class=
"Definition">greyscale</span></a>, and <a href="#3alpha"><span
class="Definition">alpha</span></a>. For example the alpha
channel is the array of alpha values within a reference
image.</dd>
<dt><a name="3chromaticity">3.1.10 chromaticity (CIE)</a></dt>
<dd>pair of values <i>x,y</i> that precisely specify a colour,
except for the brightness information.</dd>
<dt><a name="3chunk">3.1.11 chunk</a></dt>
<dd>section of a <a href="#3PNGdatastream"><span class=
"Definition">PNG datastream</span></a>. Each chunk has a chunk
type. Most chunks also include data. The format and meaning of
the data within the chunk are determined by the chunk type.
Each chunk is either a
<a href="#3criticalChunk"><span class=
"Definition">critical chunk</span></a> or an <a href=
"#3ancillaryChunk"><span class=
"Definition">ancillary chunk</span></a>.
</dd>
<dt><a name="3colourType">3.1.12 colour type</a></dt>
<dd>value denoting how colour and <a href="#3alpha"><span class=
"Definition">alpha</span></a> are specified in the <a href=
"#3PNGimage"><span class="Definition">PNG image</span></a>.
Colour types are sums of the following values: 1 (<a href=
"#3palette"><span class="Definition">palette</span></a> used), 2
(<a href="#3truecolour"><span class=
"Definition">truecolour</span></a> used), 4 (alpha used). The
permitted values of colour type are 0, 2, 3, 4, and 6.</dd>
<dt><a name="3composite">3.1.13 composite (verb)</a></dt>
<dd>to form an image by merging a foreground image and a
background image, using transparency information to determine
where and to what extent the background should be visible. The
foreground image is said to be "composited against" the
background.</dd>
<dt><a name="3criticalChunk">3.1.14 critical chunk</a></dt>
<dd><a href="#3chunk"><span class="Definition">chunk</span></a>
that <!--must be understood and processed by the decoder-->
shall be understood and processed by the decoder in order to
produce a meaningful image from a <a href="#3PNGdatastream"><span
class="Definition">PNG datastream</span></a>.</dd>
<dt><a name="3datastream">3.1.15 datastream</a></dt>
<dd>sequence of <a href="#3byte"><span class=
"Definition">bytes</span></a>. This term is used rather than
"file" to describe a byte sequence that may be only a portion of
a file. It is also used to emphasize that the sequence of bytes
might be generated and consumed "on the fly", never appearing in
a stored file at all.</dd>
<dt><a name="3deflate">3.1.16 deflate</a></dt>
<dd>name of a particular compression algorithm. This algorithm is
used, in compression mode 0, in conforming <a href=
"#3PNGdatastream"><span class="Definition">PNG
datastreams</span></a>. Deflate is a member of the <a href=
"#3LZ77"><span class="Definition">LZ77</span></a> family of
compression methods. It is defined in <a href="#2-RFC-1951"><span
class="NormRef">[RFC-1951]</span></a>.</dd>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<dt><a name="3deliveredImage">3.1.17 delivered image</a></dt>
<dd>image constructed from a decoded <a href=
"#3PNGdatastream"><span class="Definition">PNG
datastream</span></a>.</dd>
<dt><a name="3filter">3.1.18 filter</a></dt>
<dd>transformation applied to an array of <a href=
"#3scanline"><span class="Definition">scanlines</span></a> with
the aim of improving their compressibility. PNG uses only
lossless (reversible) filter algorithms.</dd>
<dt><a name="3frameBuffer">3.1.19 frame buffer</a></dt>
<dd>the final digital storage area for the image shown by most
types of computer display. Software causes an image to appear on
screen by loading the image into the frame buffer.</dd>
<dt><a name="3gamma">3.1.20 gamma</a></dt>
<dd>exponent that describes approximations to certain non-linear
transfer functions encountered in image capture and reproduction.
Within this International Standard, gamma is the exponent in the
transfer function from <tt>display_output</tt> to
<tt>image_sample</tt>
<pre>
<tt>image_sample = display_output<sup>gamma</sup></tt>
</pre>
where both <tt>display_output</tt> and <tt>image_sample</tt>
are scaled to the range 0 to 1.
</dd>
<dt><a name="3greyscale">3.1.21 greyscale</a></dt>
<dd>image representation in which each <a href="#3pixel"><span
class="Definition">pixel</span></a> is defined by a single <a
href="#3sample"><span class="Definition">sample</span></a> of
colour information, representing overall <a href=
"#3luminance"><span class="Definition">luminance</span></a> (on a
scale from black to white), and optionally an <a href=
"#3alpha"><span class="Definition">alpha</span></a> sample (in
which case it is called greyscale with alpha).</dd>
<dt><a name="3imageData">3.1.22 image data</a></dt>
<dd>1-dimensional array of <a href="#3scanline"><span class=
"Definition">scanlines</span></a> within an image.</dd>
<dt><a name="3indexedColour">3.1.23 indexed-colour</a></dt>
<dd>image representation in which each <a href="#3pixel"><span
class="Definition">pixel</span></a> of the original image is
represented by a single index into a <a href="#3palette"><span
class="Definition">palette</span></a>. The selected palette entry
defines the actual colour of the pixel.</dd>
<dt><a name="3indexing">3.1.24 indexing</a></dt>
<dd>representing an image by a <a href="#3palette"><span class=
"Definition">palette</span></a>, an <a href="#3alphaTable"><span
class="Definition">alpha table</span></a>, and an array of
indices pointing to entries in the palette and alpha table.</dd>
<dt><a name="3interlacedPNGimage">3.1.25 interlaced PNG
image</a></dt>
<dd>sequence of <a href="#3reducedImage"><span class=
"Definition">reduced images</span></a> generated from the <a
href="#3PNGimage"><span class="Definition">PNG image</span></a>
by <a href="#3passExtraction"><span class="Definition">pass
extraction</span></a>.</dd>
<dt><a name="3losslessCompression">3.1.26 lossless
compression</a></dt>
<dd>method of data compression that permits reconstruction of the
original data exactly, bit-for-bit.</dd>
<dt><a name="3lossyCompression">3.1.27 lossy compression</a></dt>
<dd>method of data compression that permits reconstruction of the
original data approximately, rather than exactly.</dd>
<dt><a name="3luminance">3.1.28 luminance</a></dt>
<dd>formal definition of luminance is in <a href=
"#2-CIE-15.2"><span class="NormRef">[CIE-15.2]</span></a>.
Informally it is the perceived brightness, or <a href=
"#3greyscale"><span class="Definition">greyscale</span></a>
level, of a colour. Luminance and <a href="#3chromaticity"><span
class="Definition">chromaticity</span></a> together fully define
a perceived colour.</dd>
<dt><a name="3LZ77">3.1.29 LZ77</a></dt>
<dd>data compression algorithm described by Ziv and Lempel in
their 1977 paper <a href="#G-ZL"><span class=
"bibref">[ZL]</span></a>.</dd>
<dt><a name="3networkByteOrder">3.1.30 network byte
order</a></dt>
<dd><a href="#3byteOrder"><span class="Definition">byte
order</span></a> in which the most significant byte comes first,
then the less significant bytes in descending order of
significance (<a href="#3MSB"><span class=
"Definition">MSB</span></a> <a href="#3LSB"><span class=
"Definition">LSB</span></a> for two-byte integers, <a href=
"#3MSB"><span class="Definition">MSB</span></a> B2 B1 <a href=
"#3LSB"><span class="Definition">LSB</span></a> for four-byte
integers).</dd>
<dt><a name="3palette">3.1.31 palette</a></dt>
<dd>indexed table of three 8-bit <a href="#3sample"><span class=
"Definition">sample</span></a> values, red, green, and blue,
which with an <a href="#3indexedColour"><span class=
"Definition">indexed-colour</span></a> image defines the red,
green, and blue sample values of the <a href=
"#3referenceImage"><span class="Definition">reference
image</span></a>. In other cases, the palette may be a suggested
palette that viewers may use to present the image on
indexed-colour display hardware. <a href="#3alpha"><span class=
"Definition">Alpha</span></a> samples may be defined for palette
entries via the <a href="#3alphaTable"><span class=
"Definition">alpha table</span></a> and may be used to
reconstruct the alpha sample values of the reference image.</dd>
<dt><a name="3passExtraction">3.1.32 pass extraction</a></dt>
<dd>organizing a <a href="#3PNGimage"><span class=
"Definition">PNG image</span></a> as a sequence of <a href=
"#3reducedImage"><span class="Definition">reduced
images</span></a> to change the order of transmission and enable
progressive display.</dd>
<dt><a name="3pixel">3.1.33 pixel</a></dt>
<dd>information stored for a single grid point in an image. A
pixel consists of (or points to) a sequence of <a href="#3sample"><span class=
"Definition">samples</span></a> from all <a href=
"#3channel"><span class="Definition">channels</span></a>. The
complete image is a rectangular array of pixels.</dd>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<dt><a name="3PNGdatastream">3.1.34 PNG datastream</a></dt>
<dd>result of encoding a <a href="#3PNGimage"><span class=
"Definition">PNG image</span></a>. A PNG <a href=
"#3datastream"><span class="Definition">datastream</span></a>
consists of a <a href="#3PNGsignature"><span class=
"Definition">PNG signature</span></a> followed by a sequence of
<a href="#3chunk"><span class=
"Definition">chunks</span></a>.</dd>
<dt><a name="3PNGdecoder">3.1.35 PNG decoder</a></dt>
<dd>process or device which reconstructs the <a href=
"#3referenceImage"><span class="Definition">reference
image</span></a> from a <a href="#3PNGdatastream"><span class=
"Definition">PNG datastream</span></a> and generates a
corresponding delivered image.</dd>
<dt><a name="3PNGeditor">3.1.36 PNG editor</a></dt>
<dd>process or device which creates a modification of an existing
<a href="#3PNGdatastream"><span class="Definition">PNG
datastream</span></a>, preserving unmodified ancillary
information wherever possible, and obeying the <a href=
"#3chunk"><span class="Definition">chunk</span></a> ordering
rules, even for unknown chunk types.</dd>
<dt><a name="3PNGencoder">3.1.37 PNG encoder</a></dt>
<dd>process or device which constructs a <a href=
"#3referenceImage"><span class="Definition">reference
image</span></a> from a <a href="#3sourceImage"><span class=
"Definition">source image</span></a>, and generates a <a href=
"#3PNGdatastream"><span class="Definition">PNG
datastream</span></a> representing the reference image.</dd>
<dt><a name="3PNGfile">3.1.38 PNG file</a></dt>
<dd><a href="#3PNGdatastream"><span class="Definition">PNG
datastream</span></a> stored as a file.</dd>
<dt><a name="3PNGfourByteSignedInteger">3.1.39 PNG four-byte
signed integer</a></dt>
<dd>a four-byte signed integer limited to the range
-(2<sup>31</sup>-1) to 2<sup>31</sup>-1. The restriction is
imposed in order to accommodate languages that have difficulty
with the value -2<sup>31</sup>.</dd>
<dt><a name="3PNGfourByteUnSignedInteger">3.1.40 PNG four-byte
unsigned integer</a></dt>
<dd>a four-byte unsigned integer limited to the range 0 to
2<sup>31</sup>-1. The restriction is imposed in order to
accommodate languages that have difficulty with unsigned
four-byte values.</dd>
<dt><a name="3PNGimage">3.1.41 PNG image</a></dt>
<dd>result of transformations applied by a <a href=
"#3PNGencoder"><span class="Definition">PNG encoder</span></a> to
a <a href="#3referenceImage"><span class="Definition">reference
image</span></a>, in preparation for encoding as a <a href=
"#3PNGdatastream"><span class="Definition">PNG
datastream</span></a>, and the result of decoding a PNG
datastream.</dd>
<dt><a name="3PNGsignature">3.1.42 PNG signature</a></dt>
<dd>sequence of <a href="#3byte"><span class=
"Definition">bytes</span></a> appearing at the start of every <a
href="#3PNGdatastream"><span class="Definition">PNG
datastream</span></a>. It differentiates a PNG datastream from
other types of <a href="#3datastream"><span class=
"Definition">datastream</span></a> and allows early detection of
some transmission errors.</dd>
<dt><a name="3reducedImage">3.1.43 reduced image</a></dt>
<dd>pass of the <a href="#3interlacedPNGimage"><span class=
"Definition">interlaced PNG image</span></a> extracted from the
<a href="#3PNGimage"><span class="Definition">PNG
image</span></a> by <a href="#3passExtraction"><span class=
"Definition">pass extraction</span></a>.</dd>
<dt><a name="3referenceImage">3.1.44 reference image</a></dt>
<dd>rectangular array of rectangular <a href="#3pixel"><span
class="Definition">pixels</span></a>, each having the same number
of <a href="#3sample"><span class=
"Definition">samples</span></a>, either three (red, green, blue)
or four (red, green, blue, <a href="#3alpha"><span class=
"Definition">alpha</span></a>). Every reference image can be
represented exactly by a <a href="#3PNGdatastream"><span class=
"Definition">PNG datastream</span></a> and every PNG datastream
can be converted into a reference image. Each <a href=
"#3channel"><span class="Definition">channel</span></a> has a <a
href="#3sampleDepth"><span class="Definition">sample
depth</span></a> in the range 1 to 16. All samples in the same
channel have the same sample depth. Different channels may have
different sample depths.</dd>
<dt><a name="3RGBmerging">3.1.45 RGB merging</a></dt>
<dd>converting an image in which the red, green, and blue <a
href="#3sample"><span class="Definition">samples</span></a> for
each <a href="#3pixel"><span class="Definition">pixel</span></a>
have the same value, and the same <a href="#3sampleDepth"><span
class="Definition">sample depth</span></a>, into an image with a
single <a href="#3greyscale"><span class=
"Definition">greyscale</span></a> <a href="#3channel"><span
class="Definition">channel</span></a>.</dd>
<dt><a name="3sample">3.1.46 sample</a></dt>
<dd>intersection of a <a href="#3channel"><span class=
"Definition">channel</span></a> and a <a href="#3pixel"><span
class="Definition">pixel</span></a> in an image.</dd>
<dt><a name="3sampleDepth">3.1.47 sample depth</a></dt>
<dd>number of bits used to represent a <a href="#3sample"><span
class="Definition">sample</span></a> value. In an <a href=
"#3indexedColour"><span class=
"Definition">indexed-colour</span></a> <a href="#3PNGimage"><span
class="Definition">PNG image</span></a>, samples are stored in
the <a href="#3palette"><span class=
"Definition">palette</span></a> and thus the sample depth is
always 8 by definition of the palette. In other types of PNG
image it is the same as the <a href="#3bitDepth"><span class=
"Definition">bit depth</span></a>.</dd>
<dt><a name="3sampleDepthScaling">3.1.48 sample depth
scaling</a></dt>
<dd>mapping of a range of <a href="#3sample"><span class=
"Definition">sample</span></a> values onto the full range of a <a
href="#3sampleDepth"><span class="Definition">sample
depth</span></a> allowed in a <a href="#3PNGimage"><span class=
"Definition">PNG image</span></a>.</dd>
<dt><a name="3scanline">3.1.49 scanline</a></dt>
<dd>row of <a href="#3pixel"><span class=
"Definition">pixels</span></a> within an image or <a href=
"#3interlacedPNGimage"><span class="Definition">interlaced PNG
image</span></a>.</dd>
<dt><a name="3sourceImage">3.1.50 source image</a></dt>
<dd>image which is presented to a <a href="#3PNGencoder"><span
class="Definition">PNG encoder</span></a>.</dd>
<dt><a name="3truecolour">3.1.51 truecolour</a></dt>
<dd>image representation in which each <a href="#3pixel"><span
class="Definition">pixel</span></a> is defined by <a href=
"#3sample"><span class="Definition">samples</span></a>,
representing red, green, and blue intensities and optionally an
<a href="#3alpha"><span class="Definition">alpha</span></a>
sample (in which case it is referred to as truecolour with
alpha).</dd>
<dt><a name="3whitePoint">3.1.52 white point</a></dt>
<dd><a href="#3chromaticity"><span class=
"Definition">chromaticity</span></a> of a computer display's
nominal white value.</dd>
<dt><a name="3zlib">3.1.53 zlib</a></dt>
<dd>particular format for data that have been compressed using <a
href="#3deflate"><span class=
"Definition">deflate</span></a>-style compression. Also the name
of a library containing a sample implementation of this method.
The format is defined in <a href="#2-RFC-1950"><span class=
"NormRef">[RFC-1950]</span></a>.</dd>
</dl>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h2><a name="3Abbreviations">3.2 Abbreviated terms</a></h2>
<dl>
<dt><a name="3CRC">3.2.1 CRC</a></dt>
<dd>Cyclic Redundancy Code. A CRC is a type of check value
designed to detect most transmission errors. A decoder calculates
the CRC for the received data and checks by comparing it to the
CRC calculated by the encoder and appended to the data.
A mismatch
indicates that the data or the CRC were corrupted in
transit.</dd>
<dt><a name="3CRT">3.2.2 CRT</a></dt>
<dd>Cathode Ray Tube: a common type of computer display
hardware.</dd>
<dt><a name="3LSB">3.2.2 LSB</a></dt>
<dd>Least Significant Byte of a multi-<a href="#3byte"><span
class="Definition">byte</span></a> value.</dd>
<dt><a name="3LUT">3.2.3 LUT</a></dt>
<dd>Look Up Table. In <a href="#3frameBuffer"><span class=
"Definition">frame buffer</span></a> hardware, a LUT can be used
to map <a href="#3indexedColour"><span class=
"Definition">indexed-colour</span></a> <a href="#3pixel"><span
class="Definition">pixels</span></a> into a selected set of <a
href="#3truecolour"><span class=
"Definition">truecolour</span></a> values, or to perform <a href=
"#3gamma"><span class="Definition">gamma</span></a> correction.
In software, a LUT can often be used as a fast way of
implementing any mathematical function of a single integer
variable.</dd>
<dt><a name="3MSB">3.2.4 MSB</a></dt>
<dd>Most Significant Byte of a multi-<a href="#3byte"><span
class="Definition">byte</span></a> value.</dd>
</dl>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="4Concepts">4 Concepts</a></h1>
<h2><a name="4Concepts.Sourceimage">4.1 Images</a></h2>
<p>This International Standard specifies the PNG datastream, and
places some requirements on PNG encoders, which generate PNG
datastreams, PNG decoders, which interpret PNG datastreams, and
PNG editors, which transform one PNG datastream into another. It
does not specify the interface between an application and either
a PNG encoder, decoder, or editor. The precise form in which an
image is presented to an encoder or delivered by a decoder is not
specified. Four kinds of image are distinguished.</p>
<ol>
<li>The <i>source image</i> is the image presented to a PNG
encoder.</li>
<li>The <i>reference image</i>, which only exists conceptually,
is a rectangular array of rectangular pixels, all having the same
width and height, and all containing the same number of unsigned
integer samples, either three (red, green, blue) or four (red,
green, blue, alpha). The array of all samples of a particular
kind (red, green, blue, or alpha) is called a channel. Each
channel has a sample depth in the range 1 to 16, which is the
number of bits used by every sample in the channel. Different
channels may have different sample depths. The red, green, and
blue samples determine the intensities of the red, green, and
blue components of the pixel's colour; if they are all zero, the
pixel is black, and if they all have their maximum values
(2<sup>sampledepth</sup>-1), the pixel is white. The alpha sample
determines a pixel's degree of opacity, where zero means fully
transparent and the maximum value means fully opaque. In a
three-channel reference image all pixels are fully opaque. (It is
also possible for a four-channel reference image to have all
pixels fully opaque; the difference is that the latter has a
specific alpha sample depth, whereas the former does not.) Each
horizontal row of pixels is called a scanline. Pixels are ordered
from left to right within each scanline, and scanlines are
ordered from top to bottom. A PNG encoder may transform the source
image directly into a PNG image, but conceptually it first
transforms the source image into a reference image, then
transforms the reference image into a PNG image. Depending on the
type of source image, the transformation from the source image to
a reference image may require the loss of information. That
transformation is beyond the scope of this International
Standard. The reference image, however, can always be recovered
exactly from a PNG datastream.</li>
<li>The <i>PNG image</i> is obtained from the reference image by
a series of transformations: alpha separation, indexing, RGB
merging, alpha compaction, and sample depth scaling. Five types
of PNG image are defined (see 6.1: <a href=
"#6Colour-values"><span class="xref">Colour types and
values</span></a>). (If the PNG encoder actually transforms the
source image directly into the PNG image, and the source image
format is already similar to the PNG image format, the encoder
may be able to avoid doing some of these transformations.)
Although not all sample depths in the range 1 to 16 bits are
explicitly supported in the PNG image, the number of significant
bits in each channel of the reference image may be recorded. All
channels in the PNG image have the same sample depth. A PNG
encoder generates a PNG datastream from the PNG image. A PNG
decoder takes the PNG datastream and recreates the PNG
image.</li>
<li>The <i>delivered image</i> is constructed from the PNG image
obtained by decoding a PNG datastream. No specific format is
specified for the delivered image. A viewer presents an image to
the user as close to the appearance of the original source image
as it can achieve.</li>
</ol>
<p>The relationships between the four kinds of image are
illustrated in <a href="#figure41"><span class="figref">figure
4.1</span></a>.</p>
<p><a name="figure41">
<object data="figures/fig41.svg" type="image/svg+xml" width="640" height="290">
<img height="280" width="640" src="png-figures/fig41.png" alt="Figure 4.1: Relationships between
source, reference, PNG, and display images" />
</object>
</a></p>
<p class="Figuretitle">Figure 4.1 — Relationships between
source, reference, PNG, and display images</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<p>The relationships between samples, channels, pixels, and
sample depth are illustrated in <a href="#figure42"><span class=
"figref">figure 4.2</span></a>.</p>
<p><a name="figure42">
<object data="figures/fig42.svg" type="image/svg+xml" width="640" height="290">
<img height="290" width="640" src="png-figures/fig42.png" alt="Figure 4.2: Relationships between
sample, sample depth, pixel, and channel" />
</object>
</a></p>
<p class="Figuretitle">Figure 4.2 — Relationships between
sample, sample depth, pixel, and channel</p>
<h2><a name="4Concepts.ColourSpaces">4.2 Colour spaces</a></h2>
<p>The RGB colour space in which colour samples are situated may
be specified in one of three ways:</p>
<!-- <ol start="1"> --><ol>
<li>by an ICC profile;</li>
<li>by specifying explicitly that the colour space is sRGB when
the samples conform to this colour space;</li>
<li>by specifying the value of gamma and the 1931 CIE <i>x,y</i>
chromaticities of the red, green, and blue primaries used in the
image and the reference white point.</li>
</ol>
<p>For high-end applications the first method provides the most
flexibility and control. The second method enables one particular
colour space to be indicated. The third method enables the exact
chromaticities of the RGB data to be specified, along with the
gamma correction (the power function relating the desired display
output with the image samples) to be applied (see Annex C: <a
href="#C-GammaAppendix"><span class="xref">Gamma and
chromaticity</span></a>). It is recommended that explicit gamma
information also be provided when either the first or second
method is used, for use by PNG decoders that do not support full
ICC profiles or the sRGB colour space. Such PNG decoders can
still make sensible use of gamma information. PNG decoders are
strongly encouraged to use this information, plus information
about the display system, in order to present the image to the
viewer in a way that reproduces as closely as possible what the image's original author
saw .</p>
<p>Gamma correction is not applied to the alpha channel, if
present. Alpha samples always represent a linear fraction of full
opacity.</p>
<h2><a name="4Concepts.PNGImageTransformation">4.3 Reference
image to PNG image transformation</a></h2>
<h3><a name="4Concepts.Introduction">4.3.1 Introduction</a></h3>
<p>A number of transformations are applied to the reference image
to create the PNG image to be encoded (see <a href=
"#figure43"><span class="figref">figure 4.3</span></a>). The
transformations are applied in the following sequence, where
square brackets mean the transformation is optional:</p>
<pre>
[alpha separation]
indexing or ( [RGB merging] [alpha compaction] )
sample depth scaling
</pre>
<p>When every pixel is either fully transparent or fully opaque,
the alpha separation, alpha compaction, and indexing
transformations can cause the recovered reference image to have
an alpha sample depth different from the original reference
image, or to have no alpha channel. This has no effect on the
degree of opacity of any pixel. The two reference images are
considered equivalent, and the transformations are considered
lossless. Encoders that nevertheless wish to preserve the alpha
sample depth may elect not to perform transformations that would
alter the alpha sample depth.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<p><a name="figure43">
<object data="figures/fig43.svg" type="image/svg+xml" height="525" width="640">
<img height="525" width="640" src="png-figures/fig43.png" alt="Figure 4.3: Reference image to PNG
image transformation" />
</object>
</a></p>
<p class="Figuretitle">Figure 4.3 — Reference image to PNG
image transformation</p>
<h3><a name="4Concepts.Implied-alpha">4.3.2 Alpha
separation</a></h3>
<p>If all alpha samples in a reference image have the maximum
value, then the alpha channel may be omitted, resulting in an
equivalent image that can be encoded more compactly.</p>
<h3><a name="4Concepts.Indexing">4.3.3 Indexing</a></h3>
<p>If the number of distinct pixel values is 256 or less, and the
RGB sample depths are not greater than 8, and the alpha channel
is absent or exactly 8 bits deep or every pixel is either fully
transparent or fully opaque, then an alternative representation
called indexed-colour may be more efficient for encoding.
Each pixel is replaced by an index into a palette.
The palette is a list of entries each containing
three 8-bit samples (red, green, blue). If an alpha channel is
present, there is also a parallel table of 8-bit alpha
samples.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<p><a name="figure44">
<object height="450" width="660" data="figures/fig44.svg" type="image/svg+xml">
<img height="450" width="660" src="png-figures/fig44.png" alt="Figure 4.4: Indexed-colour
image" />
</object>
</a></p>
<p class="Figuretitle">Figure 4.4 — Indexed-colour
image</p>
<p>A suggested palette or palettes may be constructed even when
the PNG image is not indexed-colour in order to assist viewers
that are capable of displaying only a limited number of
colours.</p>
<p>For indexed-colour images, encoders can rearrange the palette
so that the table entries with the maximum alpha value are
grouped at the end. In this case the table can be encoded in a
shortened form that does not include these entries.</p>
<h3><a name="4Concepts.RGBMerging">4.3.4 RGB merging</a></h3>
<p>If the red, green, and blue channels have the same sample
depth, and for each pixel the values of the red, green, and blue
samples are equal, then these three channels may be merged into a
single greyscale channel.</p>
<h3><a name="4Concepts.Alpha-indexing">4.3.5 Alpha
compaction</a></h3>
<p>For non-indexed images, if there exists an RGB (or greyscale)
value such that all pixels with that value are fully transparent
while all other pixels are fully opaque, then the alpha channel
can be represented more compactly by merely identifying the RGB
(or greyscale) value that is transparent.</p>
<h3><a name="4Concepts.Scaling">4.3.6 Sample depth
scaling</a></h3>
<p>In the PNG image, not all sample depths are supported (see
6.1: <a href="#6Colour-values"><span class="xref">Colour types
and values</span></a>), and all channels shall have the same
sample depth. All channels of the PNG image use the smallest
allowable sample depth that is not less than any sample depth in
the reference image, and the possible sample values in the
reference image are linearly mapped into the next allowable range
for the PNG image. <a href="#figure45"><span class=
"figref">Figure 4.5</span></a> shows how samples of depth 3 might
be mapped into samples of depth 4.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<p><a name="figure45">
<object height="320" width="640" data="figures/fig45.svg" type="image/svg+xml">
<img height="320" width="640" src="png-figures/fig45.png" alt="Figure 4.5: Scaling sample
values" />
</object>
</a></p>
<p class="Figuretitle">Figure 4.5 — Scaling sample
values</p>
<p>Allowing only a few sample depths reduces the number of cases
that decoders have to cope with. Sample depth scaling is
reversible with no loss of data, because the reference image
sample depths can be recorded in the PNG datastream. In the
absence of recorded sample depths, the reference image sample
depth equals the PNG image sample depth. See 12.5: <a href=
"#12Sample-depth-scaling"><span class="xref">Sample depth
scaling</span></a> and 13.12: <a href=
"#13Sample-depth-rescaling"><span class="xref">Sample depth
rescaling</span></a>.</p>
<p><a name="figure46">
<object height="450" width="660" data="figures/fig46.svg" type="image/svg+xml">
<img height="450" width="660" src= "png-figures/fig46.png" alt="Figure 4.6: Possible PNG image
pixel types" />
</object>
</a></p>
<p class="Figuretitle">Figure 4.6 — Possible PNG image
pixel types</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h2><a name="4Concepts.PNGImage">4.4 PNG image</a></h2>
<p>The transformation of the reference image results in one of
five types of PNG image (see <a href="#figure46"><span class=
"figref">figure 4.6</span></a>) :</p>
<!-- <ol start="1"> --><ol>
<li>Truecolour with alpha: each pixel consists of four samples:
red, green, blue, and alpha.</li>
<li>Greyscale with alpha: each pixel consists of two samples:
grey and alpha.</li>
<li>Truecolour: each pixel consists of three samples: red, green,
and blue. The alpha channel may be represented by a single pixel
value. Matching pixels are fully transparent, and all others are
fully opaque. If the alpha channel is not represented in this
way, all pixels are fully opaque.</li>
<li>Greyscale: each pixel consists of a single sample: grey. The
alpha channel may be represented by a single pixel value as in
the previous case. If the alpha channel is not represented in
this way, all pixels are fully opaque.</li>
<li>Indexed-colour: each pixel consists of an index into a palette (and into an associated table of alpha values, if present).</li>
</ol>
<p>The format of each pixel depends on the PNG image type and the
bit depth. For PNG image types other than indexed-colour,
the bit depth specifies the number of bits per sample, not the
total number of bits per pixel.
For indexed-colour images, the bit depth specifies the
number of bits in each palette index, not the sample depth of the
colours in the palette or alpha table. Within the pixel the
samples appear in the following order, depending on the PNG image
type.</p>
<!-- <ol start="6"> --><ol>
<li>Truecolour with alpha: red, green, blue, alpha.</li>
<li>Greyscale with alpha: grey, alpha.</li>
<li>Truecolour: red, green, blue.</li>
<li>Greyscale: grey.</li>
<li>Indexed-colour: palette index.</li>
</ol>
<h2><a name="4Concepts.Encoding">4.5 Encoding the PNG
image</a></h2>
<h3><a name="4Concepts.EncodingIntro">4.5.1 Introduction</a></h3>
<p>A conceptual model of the process of encoding a PNG image is
given in <a href="#figure47"><span class="figref">figure
4.7</span></a>. The steps refer to the operations on the array of
pixels or indices in the PNG image. The palette and alpha table
are not encoded in this way.</p>
<!-- <ol start="1"> --><ol>
<li>Pass extraction: to allow for progressive display, the PNG
image pixels can be rearranged to form several smaller images
called reduced images or passes.</li>
<li>Scanline serialization: the image is serialized a scanline at
a time. Pixels are ordered left to right in a scanline and
scanlines are ordered top to bottom.</li>
<li>Filtering: each scanline is transformed into a filtered
scanline using one of the defined filter types to prepare the
scanline for image compression.</li>
<li>Compression: occurs on all the filtered scanlines in the
image.</li>
<li>Chunking: the compressed image is divided into conveniently
sized chunks. An error detection code is added to each
chunk.</li>
<li>Datastream construction: the chunks are inserted into the
datastream.</li>
</ol>
<h3><a name="4Concepts.EncodingPassAbs">4.5.2 Pass
extraction</a></h3>
<p>Pass extraction (see <a href="#figure48"><span class=
"figref">figure 4.8</span></a>) splits a PNG image into a
sequence of reduced images where the first image defines a coarse
view and subsequent images enhance this coarse view until the
last image completes the PNG image. The set of reduced images is
also called an interlaced PNG image. Two interlace methods are
defined in this International Standard. The first method is a
null method; pixels are stored sequentially from left to right
and scanlines from top to bottom. The second method makes
multiple scans over the image to produce a sequence of seven
reduced images. The seven passes for a sample image are
illustrated in <a href="#figure48"><span class="figref">figure
4.8</span></a>. See clause 8: <a href="#8Interlace"><span class=
"xref">Interlacing and pass extraction</span></a>.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<p><a name="figure47">
<object height="575" width="645" data="figures/fig47.svg" type="image/svg+xml">
<img height="575" width="645" src="png-figures/fig47.png" alt="Figure 4.7: Encoding the PNG
image" />
</object>
</a></p>
<p class="Figuretitle">Figure 4.7 — Encoding the PNG
image</p>
<p><a name="figure48">
<object height="450" width="645" data="figures/fig48.svg" type="image/svg+xml">
<img height="450" width="645" src="png-figures/fig48.png" alt="Figure 4.8: Pass extraction" />
</object>
</a></p>
<p class="Figuretitle">Figure 4.8 — Pass extraction</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h3><a name="4Concepts.EncodingScanlineAbs">4.5.3 Scanline
serialization</a></h3>
<p>Each row of pixels, called a scanline, is represented as a
sequence of bytes.</p>
<h3><a name="4Concepts.EncodingFiltering">4.5.4
Filtering</a></h3>
<p>PNG standardizes one filter method and several filter types
that may be used to prepare image data for compression. It
transforms the byte sequence in a scanline to an equal length
sequence of bytes preceded by a filter type byte (see <a href=
"#figure49"><span class="figref">figure 4.9</span></a> for an
example). The filter type byte defines
the specific filtering to be applied to a specific
scanline. The encoder shall use only a single filter method for
an interlaced PNG image, but may use different filter types for
each scanline in a reduced image. See clause 9: <a href=
"#9Filters"><span class="xref">Filtering</span></a>.</p>
<p><a name="figure49">
<object height="340" width="710" data="figures/fig49.svg" type="image/svg+xml">
<img height="340" width="710" src="png-figures/fig49.png" alt="Figure 4.9: Serializing and
filtering a scanline" />
</object>
</a></p>
<p class="Figuretitle">Figure 4.9 — Serializing and
filtering a scanline</p>
<h3><a name="4Concepts.EncodingCompression">4.5.5
Compression</a></h3>
<p>The sequence of filtered scanlines in the pass or passes of
the PNG image is compressed (see <a href="#figure410"><span
class="figref">figure 4.10</span></a>) by one of the defined
compression methods. The concatenated filtered scanlines form the
input to the compression stage. The output from the compression
stage is a single compressed datastream. See clause 10: <a href=
"#10Compression"><span class="xref">Compression</span></a>.</p>
<h3><a name="4Concepts.EncodingChunking">4.5.6 Chunking</a></h3>
<p>Chunking provides a convenient breakdown of the compressed
datastream into manageable chunks (see <span
class="figref"><a href="#figure410">figure 4.10</a></span>). Each chunk has its own
redundancy check. See clause 11: <a href="#11Chunks"><span class=
"xref">Chunk specifications</span></a>.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<p><a name="figure410">
<object height="450" width="700" data="figures/fig410.svg" type="image/svg+xml">
<img height="450" width="700" src="png-figures/fig410.png" alt="Figure 4.10: Compression" />
</object></a></p>
<p class="Figuretitle">Figure 4.10 — Compression</p>
<h2><a name="4Concepts.AncillInfo">4.6 Additional
information</a></h2>
<p>Ancillary information may be associated with an image.
Decoders may ignore all or some of the ancillary information. The
types of ancillary information provided are described in <a href=
"#table41"><span class="tabref">Table 4.1</span></a>.</p>
<table class="Regular" summary=
"This table lists the types of ancillary information that may be associated with an image">
<caption><a name="table41"><b>Table 4.1 — Types of
ancillary information</b></a></caption>
<tr>
<th>Type of information</th>
<th>Description</th>
</tr>
<tr>
<td class="Regular">Background colour</td>
<td class="Regular">Solid background colour to be used when presenting the image
if no better option is available.</td>
</tr>
<tr>
<td class="Regular">Gamma and chromaticity</td>
<td class="Regular">Gamma characteristic of the image with respect to the desired
output intensity, and chromaticity characteristics of the RGB
values used in the image.</td>
</tr>
<tr>
<td class="Regular">ICC profile</td>
<td class="Regular">Description of the colour space (in the form of an
International Color Consortium (ICC) profile) to which the
samples in the image conform.</td>
</tr>
<tr>
<td class="Regular">Image histogram</td>
<td class="Regular">Estimates of how frequently the image uses each palette entry.</td>
</tr>
<tr>
<td class="Regular">Physical pixel dimensions</td>
<td class="Regular">Intended pixel size and aspect ratio to be used in presenting
the PNG image.</td>
</tr>
<tr>
<td class="Regular">Significant bits</td>
<td class="Regular">The number of bits that are significant in the samples.</td>
</tr>
<tr>
<td class="Regular">sRGB colour space</td>
<td class="Regular">A rendering intent (as defined by the International Color
Consortium) and an indication that the image samples conform to
this colour space.</td>
</tr>
<tr>
<td class="Regular">Suggested palette</td>
<td class="Regular">A reduced palette that may be used when the display device is
not capable of displaying the full range of colours in the
image.</td>
</tr>
<tr>
<td class="Regular">Textual data</td>
<td class="Regular">Textual information (which may be compressed) associated with
the image.</td>
</tr>
<tr>
<td class="Regular">Time</td>
<td class="Regular">The time when the PNG image was last modified.</td>
</tr>
<tr>
<td class="Regular">Transparency</td>
<td class="Regular">Alpha information that allows the reference image to be
reconstructed when the alpha channel is not retained in the PNG
image.</td>
</tr>
</table>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h2><a name="4Concepts.Format">4.7 PNG datastream</a></h2>
<h3><a name="4Concepts.FormatChunks">4.7.1 Chunks</a></h3>
<p>The PNG datastream consists of a PNG signature (see 5.2: <a
href="#5PNG-file-signature"><span class="xref">PNG
signature</span></a>) followed by a sequence of chunks (see
clause 11: <a href="#11Chunks"><span class="xref">Chunk
specifications</span></a>). Each chunk has a chunk type which
specifies its function.</p>
<h3><a name="4Concepts.FormatTypes">4.7.2 Chunk types</a></h3>
<p>There are 18 chunk types defined in this International
Standard. Chunk types are four-byte sequences chosen so that they
correspond to readable labels when interpreted in the ISO 646.IRV:1991
character set. The first four are termed critical chunks, which
shall be understood and correctly interpreted according to the
provisions of this International Standard. These are:</p>
<!-- <ol start="1"> --><ol>
<li><a href="#11IHDR"><span class="chunk">IHDR</span></a>: image
header, which is the first chunk in a PNG datastream.</li>
<li><a href="#11PLTE"><span class="chunk">PLTE</span></a>:
palette table associated with indexed PNG images.</li>
<li><a href="#11IDAT"><span class="chunk">IDAT</span></a>: image
data chunks.</li>
<li><a href="#11IEND"><span class="chunk">IEND</span></a>: image
trailer, which is the last chunk in a PNG datastream.</li>
</ol>
<p>The remaining 14 chunk types are termed ancillary chunk types,
which encoders may generate and decoders may interpret.</p>
<!-- <ol start="5"> --><ol>
<li>Transparency information: <a href="#11tRNS"><span class=
"chunk">tRNS</span></a> (see 11.3.2: <a class='Href' href=
'#11transinfo'>Transparency information</a>).</li>
<li>Colour space information: <a href="#11cHRM"><span class=
"chunk">cHRM</span></a>, <a href="#11gAMA"><span class=
"chunk">gAMA</span></a>, <a href="#11iCCP"><span class=
"chunk">iCCP</span></a>, <a href="#11sBIT"><span class=
"chunk">sBIT</span></a>, <a href="#11sRGB"><span class=
"chunk">sRGB</span></a> (see 11.3.3: <a class='Href' href=
'#11addnlcolinfo'>Colour space information</a>).</li>
<li>Textual information: <a href="#11iTXt"><span class=
"chunk">iTXt</span></a>, <a href="#11tEXt"><span class=
"chunk">tEXt</span></a>, <a href="#11zTXt"><span class=
"chunk">zTXt</span></a> (see 11.3.4: <a class='Href' href=
'#11textinfo'>Textual information</a>).</li>
<li>Miscellaneous information: <a href="#11bKGD"><span class=
"chunk">bKGD</span></a>, <a href="#11hIST"><span class=
"chunk">hIST</span></a>, <a href="#11pHYs"><span class=
"chunk">pHYs</span></a>, <a href="#11sPLT"><span class=
"chunk">sPLT</span></a> (see 11.3.5: <a class='Href' href=
'#11addnlsiinfo'>Miscellaneous information</a>).</li>
<li>Time information: <a href="#11tIME"><span class=
"chunk">tIME</span></a> (see 11.3.6: <a class='Href' href=
'#11timestampinfo'>Time stamp information</a>).</li>
</ol>
<h2><a name="4Concepts.Errors">4.8 Error handling</a></h2>
<p>Errors in a PNG datastream fall into two general classes:</p>
<!-- <ol start="1"> --><ol>
<li>transmission errors or damage to a computer file system,
which tend to corrupt much or all of the datastream;</li>
<li>syntax errors, which appear as invalid values in chunks, or
as missing or misplaced chunks. Syntax errors can be caused not
only by encoding mistakes, but also by the use of registered or
private values, if those values are unknown to the decoder.</li>
</ol>
<p>PNG decoders should detect errors as early as possible,
recover from errors whenever possible, and fail gracefully
otherwise. The error handling philosophy is described in detail
in 13.2: <a href="#13Decoders.Errors"><span class="xref">Error
handling</span></a>.</p>
<h2><a name="4Concepts.Registration">4.9 Extension and
registration</a></h2>
<p>For some facilities in PNG, there are a number of alternatives
defined, and this International Standard allows other
alternatives to be defined by registration. According to the
rules for the designation and operation of registration
authorities in the ISO/IEC Directives, the ISO and IEC Councils
have designated the following as the registration authority:</p>
<address>The World-Wide Web Consortium Host at ERCIM</address>
<address>The Registration Authority for PNG</address>
<address>INRIA- Sophia Antipolis</address>
<address>BP 93</address>
<address>06902 Sophia Antipolis Cedex</address>
<address>FRANCE</address>
<address>Email:png-group@w3.org</address>
<p>To ensure timely processing the Registration Authority should be contacted by email.</p>
<p>The following entities may be registered:</p>
<!-- <ol start="1"> --><ol>
<li>chunk type;</li>
<li>text keyword.</li>
</ol>
<p>The following entities are reserved for future
standardization:</p>
<!-- <ol start="4"> --><ol>
<li>undefined field values less than 128;</li>
<li>filter method;</li>
<li>filter type;</li>
<li>interlace method;</li>
<li>compression method.</li>
</ol>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="5DataRep">5 Datastream structure</a></h1>
<h2><a name="5Introduction">5.1 Introduction</a></h2>
<p>This clause defines the PNG signature and the basic properties
of chunks. Individual chunk types are discussed in clause 11: <a
href="#11Chunks"><span class="xref">Chunk
specifications</span></a>.</p>
<h2><a name="5PNG-file-signature">5.2 PNG signature</a></h2>
<p>The first eight bytes of a PNG datastream always contain the
following (decimal) values:</p>
<pre>
137 80 78 71 13 10 26 10
</pre>
<p>This signature indicates that the remainder of the datastream
contains a single PNG image, consisting of a series of chunks
beginning with an <a href="#11IHDR"><span class=
"chunk">IHDR</span></a> chunk and ending with an <a href=
"#11IEND"><span class="chunk">IEND</span></a> chunk.</p>
<h2><a name="5Chunk-layout">5.3 Chunk layout</a></h2>
<p>Each chunk consists of three or four fields (see figure 5.1).
The meaning of the fields is described in
<a href="#table51"><span class="tabref">Table 5.1</span></a>.
The chunk data field may be empty.</p>
<p><a name="figure411">
<object height="160" width="480" data="figures/fig51.svg" type="image/svg+xml">
<img height="160" width="480" src="png-figures/fig51.png" alt="Figure 5.1: Chunk parts" />
</object>
</a></p>
<p class="Figuretitle">Figure 5.1 — Chunk parts</p>
<table class="Regular" summary=
"This table defines the chunk fields">
<caption><a name="table51"><b>Table 5.1 — Chunk fields</b></a></caption>
<tr>
<td class="Regular">Length</td>
<td class="Regular">A four-byte unsigned integer giving the number of bytes in
the chunk's data field. The length counts <strong>only</strong>
the data field, <strong>not</strong> itself, the chunk type, or
the CRC. Zero is a valid length. Although encoders and decoders
should treat the length as unsigned, its value shall not exceed
2<sup>31</sup>-1 bytes.</td>
</tr>
<tr>
<td class="Regular">Chunk Type</td>
<td class="Regular">A sequence of four bytes defining the chunk type. Each byte
of a chunk type is restricted to the decimal values 65 to 90 and
97 to 122. These correspond to the uppercase and lowercase ISO
646 letters (<tt>A</tt>-<tt>Z</tt> and <tt>a</tt>-<tt>z</tt>)
respectively for convenience in description and examination of
PNG datastreams. Encoders and decoders shall treat the chunk
types as fixed binary values, not character strings. For example,
it would not be correct to represent the chunk type <a href=
"#11IDAT"><span class="chunk">IDAT</span></a> by the equivalents
of those letters in the UCS 2 character set. Additional naming
conventions for chunk types are discussed in 5.4: <a href=
"#5Chunk-naming-conventions"><span class="xref">Chunk naming
conventions</span></a>.</td>
</tr>
<tr>
<td class="Regular">Chunk Data</td>
<td class="Regular">The data bytes appropriate to the chunk type, if any. This
field can be of zero length.</td>
</tr>
<tr>
<td class="Regular">CRC</td>
<td class="Regular">A four-byte CRC (Cyclic Redundancy Code) calculated on the
preceding bytes in the chunk, including the chunk type field and
chunk data fields, but <strong>not</strong> including the length
field. The CRC can be used to check for corruption of the data.
The CRC is always present, even for chunks containing no data.
See 5.5: <a href="#5CRC-algorithm"><span class="xref">Cyclic
Redundancy Code algorithm</span></a>.</td>
</tr>
</table>
<p>The chunk data length may be any number of bytes up to the
maximum; therefore, implementors cannot assume that chunks are
aligned on any boundaries larger than bytes.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h2><a name="5Chunk-naming-conventions">5.4 Chunk naming
conventions</a></h2>
<p>Chunk types are chosen to be meaningful names when the bytes
of the chunk type are interpreted as ISO 646 letters. Chunk types
are assigned so that a decoder can determine some properties of a
chunk even when the type is not recognized. These rules allow
safe, flexible extension of the PNG format, by allowing a PNG
decoder to decide what to do when it encounters an unknown chunk.
(The chunk types standardized in this International Standard are
defined in clause 11: <a href="#11Chunks"><span class=
"xref">Chunk specifications</span></a>, and the way to add
non-standard chunks is defined in clause 14: <a href=
"#14EditorsExt"><span class="xref">Editors and
extensions</span></a>.) The naming rules are normally of interest
only when the decoder does not recognize the chunk's type.</p>
<p>Four bits of the chunk type, the property bits, namely bit 5
(value 32) of each byte, are used to convey chunk properties.
This choice means that a human can read off the assigned
properties according to whether the letter corresponding to each
byte of the chunk type is uppercase (bit 5 is 0) or lowercase
(bit 5 is 1). However, decoders should test the properties of an
unknown chunk type by numerically testing the specified bits;
testing whether a character is uppercase or lowercase is
inefficient, and even incorrect if a locale-specific case
definition is used.</p>
<p>The property bits are an inherent part of the chunk type, and
hence are fixed for any chunk type. Thus, <span class=
"chunk">CHNK</span> and <span class="chunk">cHNk</span> would be
unrelated chunk types, not the same chunk with different
properties.</p>
<p>The semantics of the property bits are
defined in
<a href="#table52"><span class="tabref">Table 5.2</span></a>.
</p>
<table class="Regular" summary=
"This table defines the semantics of the property bits">
<caption><a name="table52"><b>Table 5.2 — Semantics of property bits</b></a></caption>
<tr>
<td class="Regular">Ancillary bit: first byte</td>
<td class="Regular">0 (uppercase) = critical,<br class="xhtml" />
1 (lowercase) = ancillary.</td>
<td class="Regular">Critical chunks are necessary for successful display of the
contents of the datastream, for example the image header chunk
(<a href="#11IHDR"><span class="chunk">IHDR</span></a>). A
decoder trying to extract the image, upon encountering an unknown
chunk type in which the ancillary bit is 0, shall indicate to the
user that the image contains information it cannot safely
interpret.<br class="xhtml" />
Ancillary chunks are not strictly necessary in order to
meaningfully display the contents of the datastream, for example
the time chunk (<a href="#11tIME"><span class=
"chunk">tIME</span></a>). A decoder encountering an unknown chunk
type in which the ancillary bit is 1 can safely ignore the chunk
and proceed to display the image.</td>
</tr>
<tr>
<td class="Regular">Private bit: second byte</td>
<td class="Regular">0 (uppercase) = public,<br class="xhtml" />
1 (lowercase) = private.</td>
<td class="Regular">A public chunk is one that is defined in this International
Standard or is registered in the list of PNG special-purpose
public chunk types maintained by the Registration Authority (see
4.9 <a href="#4Concepts.Registration"><span class=
"xref">Extension and registration</span></a>). Applications can
also define private (unregistered) chunk types for their own
purposes. The names of private chunks have a lowercase second
letter, while public chunks will always be assigned names with
uppercase second letters. Decoders do not need to test the
private-chunk property bit, since it has no functional
significance; it is simply an administrative convenience to
ensure that public and private chunk names will not conflict. See
clause 14: <a href="#14EditorsExt"><span class="xref">Editors and
extensions</span></a> and 12.10.2: <a href=
"#12Use-of-private-chunks"><span class="xref">Use of private
chunks</span></a>.</td>
</tr>
<tr>
<td class="Regular">Reserved bit: third byte</td>
<td class="Regular">0 (uppercase) in this version of PNG.<br class="xhtml" />
If the reserved bit is 1, the datastream does not conform to
this version of PNG.</td>
<td class="Regular">The significance of the case of the third letter of the chunk
name is reserved for possible future extension. In this
International Standard, all chunk names shall have uppercase
third letters.</td>
</tr>
<tr>
<td class="Regular">Safe-to-copy bit: fourth byte</td>
<td class="Regular">0 (uppercase) = unsafe to copy,<br class="xhtml" />
1 (lowercase) = safe to copy.</td>
<td class="Regular">This property bit is not of interest to pure decoders, but it
is needed by PNG editors. This bit defines the proper handling of
unrecognized chunks in a datastream that is being modified. Rules
for PNG editors are discussed further in 14.2: <a href=
"#14Ordering"><span class="xref">Behaviour of PNG
editors</span></a>.</td>
</tr>
</table>
<p>EXAMPLE The hypothetical chunk type "<span class=
"chunk">cHNk</span>" has the property bits:</p>
<pre>
cHNk <-- 32 bit chunk type represented in text form
||||
|||+- Safe-to-copy bit is 1 (lower case letter; bit 5 is 1)
||+-- Reserved bit is 0 (upper case letter; bit 5 is 0)
|+--- Private bit is 0 (upper case letter; bit 5 is 0)
+---- Ancillary bit is 1 (lower case letter; bit 5 is 1)
</pre>
<p>Therefore, this name represents an ancillary, public,
safe-to-copy chunk.</p>
<h2><a name="5CRC-algorithm">5.5 Cyclic Redundancy Code
algorithm</a></h2>
<p>CRC fields are calculated using standardized CRC methods with
pre and post conditioning, as defined by ISO 3309 <a href=
"#2-ISO-3309"><span class="NormRef">[ISO-3309]</span></a> and
ITU-T V.42 <a href="#G-ITU-T-V42"><span class=
"bibref">[ITU-T-V42]</span></a>. The CRC polynomial employed
is</p>
<p>x<sup>32</sup> + x<sup>26</sup> + x<sup>23</sup> +
x<sup>22</sup> + x<sup>16</sup> + x<sup>12</sup> + x<sup>11</sup>
+ x<sup>10</sup> + x<sup>8</sup> + x<sup>7</sup> + x<sup>5</sup>
+ x<sup>4</sup> + x<sup>2</sup> + x + 1</p>
<p>In PNG, the 32-bit CRC is initialized to all 1's, and then the
data from each byte is processed from the least significant bit
(1) to the most significant bit (128). After all the data bytes
are processed, the CRC is inverted (its ones complement is
taken). This value is transmitted (stored in the datastream) MSB
first. For the purpose of separating into bytes and ordering, the
least significant bit of the 32-bit CRC is defined to be the
coefficient of the <tt>x<sup>31</sup></tt> term.</p>
<p>Practical calculation of the CRC often employs a precalculated
table to accelerate the computation. See Annex D: <a href=
"#D-CRCAppendix"><span class="xref">Sample Cyclic Redundancy Code
implementation</span></a>.</p>
<h2><a name="5ChunkOrdering">5.6 Chunk ordering</a></h2>
<p>The constraints on the positioning of the individual chunks
are listed in <a href="#table53"><span class="tabref">Table
5.3</span></a> and illustrated diagrammatically in <a href=
"#figure52"><span class="figref">figure 5.2</span></a> and <a
href="#figure53"><span class="figref">figure 5.3</span></a>.
These lattice diagrams represent the constraints on positioning
imposed by this International Standard. The lines in the diagrams
define partial ordering relationships. Chunks higher up shall
appear before chunks lower down. Chunks which are horizontally
aligned and appear between two other chunk types (higher and
lower than the horizontally aligned chunks) may appear in any
order between the two higher and lower chunk types to which they
are connected. The superscript associated with the chunk type is
defined in <a href="#table54"><span class="tabref">Table
5.4</span></a>. It indicates whether the chunk is mandatory,
optional, or may appear more than once. A vertical bar between
two chunk types indicates alternatives.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<table class="Regular" summary=
"This table lists the chunk ordering rules">
<caption><a name="table53"><b>Table 5.3 — Chunk ordering
rules</b></a></caption>
<tr>
<th colspan="3">Critical chunks<br class="xhtml" />
(shall appear in this order, except <a href="#11PLTE"><span
class="chunk">PLTE</span></a> is optional)</th>
</tr>
<tr>
<th>Chunk name</th>
<th>Multiple allowed</th>
<th>Ordering constraints</th>
</tr>
<tr>
<td class="Regular"><a href="#11IHDR"><span class="chunk">IHDR</span></a> </td>
<td class="Regular">No</td>
<td class="Regular">Shall be first</td>
</tr>
<tr>
<td class="Regular"><a href="#11PLTE"><span class="chunk">PLTE</span></a> </td>
<td class="Regular">No</td>
<td class="Regular">Before first <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> </td>
</tr>
<tr>
<td class="Regular"><a href="#11IDAT"><span class="chunk">IDAT</span></a> </td>
<td class="Regular">Yes</td>
<td class="Regular">Multiple <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> chunks shall be consecutive</td>
</tr>
<tr>
<td class="Regular"><a href="#11IEND"><span class="chunk">IEND</span></a> </td>
<td class="Regular">No</td>
<td class="Regular">Shall be last</td>
</tr>
<tr>
<th colspan="3">Ancillary chunks<br class="xhtml" />
(need not appear in this order)</th>
</tr>
<tr>
<th>Chunk name</th>
<th>Multiple allowed</th>
<th>Ordering constraints</th>
</tr>
<tr>
<td class="Regular"><a href="#11cHRM"><span class="chunk">cHRM</span></a> </td>
<td class="Regular">No</td>
<td class="Regular">Before <a href="#11PLTE"><span class="chunk">PLTE</span></a>
and <a href="#11IDAT"><span class="chunk">IDAT</span></a> </td>
</tr>
<tr>
<td class="Regular"><a href="#11gAMA"><span class="chunk">gAMA</span></a> </td>
<td class="Regular">No</td>
<td class="Regular">Before <a href="#11PLTE"><span class="chunk">PLTE</span></a>
and <a href="#11IDAT"><span class="chunk">IDAT</span></a> </td>
</tr>
<tr>
<td class="Regular"><a href="#11iCCP"><span class="chunk">iCCP</span></a> </td>
<td class="Regular">No</td>
<td class="Regular">Before <a href="#11PLTE"><span class="chunk">PLTE</span></a>
and <a href="#11IDAT"><span class="chunk">IDAT</span></a>. If the
<a href="#11iCCP"><span class="chunk">iCCP</span></a> chunk is
present, the <a href="#11sRGB"><span class=
"chunk">sRGB</span></a> chunk should not be present.</td>
</tr>
<tr>
<td class="Regular"><a href="#11sBIT"><span class="chunk">sBIT</span></a> </td>
<td class="Regular">No</td>
<td class="Regular">Before <a href="#11PLTE"><span class="chunk">PLTE</span></a>
and <a href="#11IDAT"><span class="chunk">IDAT</span></a> </td>
</tr>
<tr>
<td class="Regular"><a href="#11sRGB"><span class="chunk">sRGB</span></a> </td>
<td class="Regular">No</td>
<td class="Regular">Before <a href="#11PLTE"><span class="chunk">PLTE</span></a>
and <a href="#11IDAT"><span class="chunk">IDAT</span></a>. If the
<a href="#11sRGB"><span class="chunk">sRGB</span></a> chunk is
present, the <a href="#11iCCP"><span class=
"chunk">iCCP</span></a> chunk should not be present.</td>
</tr>
<tr>
<td class="Regular"><a href="#11bKGD"><span class="chunk">bKGD</span></a> </td>
<td class="Regular">No</td>
<td class="Regular">After <a href="#11PLTE"><span class="chunk">PLTE</span></a>;
before <a href="#11IDAT"><span class="chunk">IDAT</span></a>
</td>
</tr>
<tr>
<td class="Regular"><a href="#11hIST"><span class="chunk">hIST</span></a> </td>
<td class="Regular">No</td>
<td class="Regular">After <a href="#11PLTE"><span class="chunk">PLTE</span></a>;
before <a href="#11IDAT"><span class="chunk">IDAT</span></a>
</td>
</tr>
<tr>
<td class="Regular"><a href="#11tRNS"><span class="chunk">tRNS</span></a> </td>
<td class="Regular">No</td>
<td class="Regular">After <a href="#11PLTE"><span class="chunk">PLTE</span></a>;
before <a href="#11IDAT"><span class="chunk">IDAT</span></a>
</td>
</tr>
<tr>
<td class="Regular"><a href="#11pHYs"><span class="chunk">pHYs</span></a> </td>
<td class="Regular">No</td>
<td class="Regular">Before <a href="#11IDAT"><span class="chunk">IDAT</span></a>
</td>
</tr>
<tr>
<td class="Regular"><a href="#11sPLT"><span class="chunk">sPLT</span></a> </td>
<td class="Regular">Yes</td>
<td class="Regular">Before <a href="#11IDAT"><span class="chunk">IDAT</span></a>
</td>
</tr>
<tr>
<td class="Regular"><a href="#11tIME"><span class="chunk">tIME</span></a> </td>
<td class="Regular">No</td>
<td class="Regular">None</td>
</tr>
<tr>
<td class="Regular"><a href="#11iTXt"><span class="chunk">iTXt</span></a> </td>
<td class="Regular">Yes</td>
<td class="Regular">None</td>
</tr>
<tr>
<td class="Regular"><a href="#11tEXt"><span class="chunk">tEXt</span></a> </td>
<td class="Regular">Yes</td>
<td class="Regular">None</td>
</tr>
<tr>
<td class="Regular"><a href="#11zTXt"><span class="chunk">zTXt</span></a> </td>
<td class="Regular">Yes</td>
<td class="Regular">None</td>
</tr>
</table>
<table class="Regular" summary=
"This table lists the symbols used in lattice diagrams">
<caption><a name="table54"><b>Table 5.4 — Meaning of
symbols used in lattice diagrams</b></a></caption>
<tr>
<th>Symbol</th>
<th>Meaning</th>
</tr>
<tr>
<td class="Regular">+</td>
<td class="Regular">One or more</td>
</tr>
<tr>
<td class="Regular">1</td>
<td class="Regular">Only one</td>
</tr>
<tr>
<td class="Regular">?</td>
<td class="Regular">Zero or one</td>
</tr>
<tr>
<td class="Regular">*</td>
<td class="Regular">Zero or more</td>
</tr>
<tr>
<td class="Regular">|</td>
<td class="Regular">Alternative</td>
</tr>
</table>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<p>
<object height="540" width="800" data="figures/fig52.svg" type="image/svg+xml">
<img height="540" width="800" src="png-figures/fig52.png" alt="Figure 5.2: Lattice diagram: PNG images with PLTE in datastream" />
</object>
</p>
<p class="Figuretitle"><a name="figure52">Figure 5.2 —</a>
Lattice diagram: PNG images with <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> in datastream</p>
<p>
<object height="540" width="900" data="figures/fig53.svg"
type="image/svg+xml">
<img height="540" width="900" src="png-figures/fig53.png" alt="Figure 5.3: Lattice diagram: PNG images without PLTE in datastream" />
</object>
</p>
<p class="Figuretitle"><a name="figure53">Figure 5.3 —</a>
Lattice diagram: PNG images without <a href="#11PLTE"><span
class="chunk">PLTE</span></a> in datastream</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="6Transformation">6 Reference image to PNG image
transformation</a></h1>
<h2><a name="6Colour-values">6.1 Colour types and values</a></h2>
<p>As explained in 4.4: <a href="#4Concepts.PNGImage"><span
class="xref">PNG image</span></a> there are five types of PNG
image. Corresponding to each type is a colour type, which is the
sum of the following values: 1 (palette used), 2 (truecolour
used) and 4 (alpha used). Greyscale and truecolour images may
have an explicit alpha channel. The PNG image types and
corresponding colour types are listed in <a href=
"#table6.1"><span class="tabref">Table 6.1</span></a>.</p>
<table class="Regular" summary=
"This table lists the PNG image and colour types">
<caption><a name="table6.1"><b>Table 6.1 — PNG image types
and colour types</b></a></caption>
<tr>
<th>PNG image type</th>
<th>Colour type</th>
</tr>
<tr>
<td class="Regular">Greyscale</td>
<td class="Regular">0</td>
</tr>
<tr>
<td class="Regular">Truecolour</td>
<td class="Regular">2</td>
</tr>
<tr>
<td class="Regular">Indexed-colour</td>
<td class="Regular">3</td>
</tr>
<tr>
<td class="Regular">Greyscale with alpha</td>
<td class="Regular">4</td>
</tr>
<tr>
<td class="Regular">Truecolour with alpha</td>
<td class="Regular">6</td>
</tr>
</table>
<p>The allowed bit depths and sample depths for each PNG image
type are listed in 11.2.2: <a href="#11IHDR"><span class=
"xref"><span class="chunk">IHDR</span> Image
header</span></a>.</p>
<p>Greyscale samples represent luminance if the transfer curve is
indicated (by <a href="#11gAMA"><span class=
"chunk">gAMA</span></a>, <a href="#11sRGB"><span class=
"chunk">sRGB</span></a>, or <a href="#11iCCP"><span class=
"chunk">iCCP</span></a>) or device-dependent greyscale if not.
RGB samples represent calibrated colour information if the colour
space is indicated (by <a href="#11gAMA"><span class=
"chunk">gAMA</span></a> and <a href="#11cHRM"><span class=
"chunk">cHRM</span></a>, or <a href="#11sRGB"><span class=
"chunk">sRGB</span></a>, or <a href="#11iCCP"><span class=
"chunk">iCCP</span></a>) or uncalibrated device-dependent colour
if not.</p>
<p>Sample values are not necessarily proportional to light
intensity; the <a href="#11gAMA"><span class=
"chunk">gAMA</span></a> chunk specifies the relationship between
sample values and display output intensity. Viewers are strongly
encouraged to compensate properly. See 4.2: <a href=
"#4Concepts.ColourSpaces"><span class="xref">Colour
spaces</span></a>, 13.13: <a href=
"#13Decoder-gamma-handling"><span class="xref">Decoder gamma
handling</span></a> and Annex C: <a href="#C-GammaAppendix"><span
class="xref">Gamma and chromaticity</span></a>.</p>
<h2><a name="6AlphaRepresentation">6.2 Alpha
representation</a></h2>
<p>In a PNG datastream transparency may be represented in one of
four ways, depending on the PNG image type (see 4.3.2: <a href=
"#4Concepts.Implied-alpha"><span class="xref">Alpha
separation</span></a> and 4.3.5: <a href=
"#4Concepts.Alpha-indexing"><span class="xref">Alpha
compaction</span></a>).</p>
<!-- <ol start="1"> --><ol>
<li>Truecolour with alpha, greyscale with alpha: an alpha channel
is part of the image array.</li>
<li>Truecolour, greyscale: A <a href="#11tRNS"><span class=
"chunk">tRNS</span></a> chunk contains a single pixel value
distinguishing the fully transparent pixels from the fully opaque
pixels.</li>
<li>Indexed-colour: A <a href="#11tRNS"><span class=
"chunk">tRNS</span></a> chunk contains the alpha table that
associates an alpha sample with each palette entry.</li>
<li>Truecolour, greyscale, indexed-colour: there is no <a href=
"#11tRNS"><span class="chunk">tRNS</span></a> chunk present and
all pixels are fully opaque.</li>
</ol>
<p>An alpha channel included in the image array has 8-bit or
16-bit samples, the same size as the other samples. The alpha
sample for each pixel is stored immediately following the
greyscale or RGB samples of the pixel. An alpha value of zero
represents full transparency, and a value of
2<sup>sampledepth</sup> - 1 represents full opacity. Intermediate
values indicate partially transparent pixels that can be
composited against a background image to yield the delivered
image.</p>
<p>The colour values in a pixel are not premultiplied by the
alpha value assigned to the pixel. This rule is sometimes called
"unassociated" or "non-premultiplied" alpha. (Another common
technique is to store sample values premultiplied by the alpha
value; in effect, such an image is already composited against a
black background. PNG does <strong>not</strong> use premultiplied alpha.
In consequence an image editor can take a PNG image and easily
change its transparency.) See 12.4: <a href=
"#12Alpha-channel-creation"><span class="xref">Alpha channel
creation</span></a> and 13.16: <a href=
"#13Alpha-channel-processing"><span class="xref">Alpha channel
processing</span></a>.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="7Transformation">7 Encoding the PNG image as a PNG
datastream</a></h1>
<h2><a name="7Integers-and-byte-order">7.1 Integers and byte
order</a></h2>
<p>All integers that require more than one byte shall be in
network byte order (as illustrated in <a href="#figure71"><span
class="figref">figure 7.1</span></a>): the most significant byte
comes first, then the less significant bytes in descending order
of significance (MSB LSB for two-byte integers, MSB B2 B1 LSB for
four-byte integers). The highest bit (value 128) of a byte is
numbered bit 7; the lowest bit (value 1) is numbered bit 0.
Values are unsigned unless otherwise noted. Values explicitly
noted as signed are represented in two's complement notation.</p>
<p>PNG four-byte unsigned integers are limited to the range 0 to
2<sup>31</sup>-1 to accommodate languages that have difficulty
with unsigned four-byte values. Similarly PNG four-byte signed
integers are limited to the range -(2<sup>31</sup>-1) to
2<sup>31</sup>-1 to accommodate languages that have difficulty
with the value -2<sup>31</sup>.</p>
<p>
<object height="310" width="810" data="figures/fig71.svg" type="image/svg+xml">
<img height="310" width="810" src="png-figures/fig71.png" alt="Figure 7.1: Integer representation in PNG" />
</object>
</p>
<p class="Figuretitle"><a name="figure71">Figure 7.1</a> —
Integer representation in PNG</p>
<h2><a name="7Scanline">7.2 Scanlines</a></h2>
<p>A PNG image (or pass, see clause 8: <a href=
"#8Interlace"><span class="xref">Interlacing and pass
extraction</span></a>) is a rectangular pixel array, with pixels
appearing left-to-right within each scanline, and scanlines
appearing top-to-bottom. The size of each pixel is determined by
the number of bits per pixel.</p>
<p>Pixels within a scanline are always packed into a sequence of
bytes with no wasted bits between pixels. Scanlines always begin
on byte boundaries. Permitted bit depths and colour types are
restricted so that in all cases the packing is simple and
efficient.</p>
<p>
In PNG images of colour type 0 (greyscale) each pixel is a single sample, which may have precision less than a byte (1, 2, or 4 bits). These samples are packed into bytes with the leftmost sample in the high-order bits of a byte followed by the other samples for the scanline.
</p>
<p>
In PNG images of colour type 3 (indexed-colour) each pixel is a single palette index. These indices are packed into bytes in the same way as the samples for colour type 0.</p>
<p>When there are multiple pixels per byte, some low-order bits
of the last byte of a scanline may go unused. The contents of
these unused bits are not specified.</p>
<p>PNG images that are not indexed-colour images may have sample
values with a bit depth of 16. Such sample values are in network
byte order (MSB first, LSB second). PNG permits multi-sample
pixels only with 8 and 16-bit samples, so multiple samples of a
single pixel are never packed into one byte.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h2><a name="7Filtering">7.3 Filtering</a></h2>
<p>PNG allows the scanline data to be <strong>filtered</strong> before it
is compressed. Filtering can improve the compressibility of the
data. The filter step itself results in a sequence of bytes of
the same size as the incoming sequence, but in a different
representation, preceded by a filter type byte. Filtering does
not reduce the size of the actual scanline data. All PNG filters
are strictly lossless.</p>
<p>Different filter types can be used for different scanlines,
and the filter algorithm is specified for each scanline by a
filter type byte. The filter type byte is not considered part of
the image data, but it is included in the datastream sent to the
compression step. An intelligent encoder can switch filters from
one scanline to the next. The method for choosing which filter to
employ is left to the encoder.</p>
<p>See clause 9: <a href="#9Filters"><span class=
"xref">Filtering</span></a>.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="8Interlace">8 Interlacing and pass
extraction</a></h1>
<h2><a name="8InterlaceIntro">8.1 Introduction</a></h2>
<p>Pass extraction (see <a href="#figure48"><span class=
"figref">figure 4.8</span></a>) splits a PNG image into a
sequence of reduced images (the interlaced PNG image) where the
first image defines a coarse view and subsequent images enhance
this coarse view until the last image completes the PNG image.
This allows progressive display of the interlaced PNG image by
the decoder and allows images to "fade in" when they are being
displayed on-the-fly. On average, interlacing slightly expands
the datastream size, but it can give the user a meaningful
display much more rapidly.</p>
<h2><a name="8InterlaceMethods">8.2 Interlace methods</a></h2>
<p>Two interlace methods are defined in this International
Standard, methods 0 and 1. Other values of interlace method are
reserved for future standardization (see 4.9: <a href=
"#4Concepts.Registration"><span class="xref">Extension and
registration</span></a>).</p>
<p>With interlace method 0, the null method, pixels are extracted
sequentially from left to right, and scanlines sequentially from
top to bottom. The interlaced PNG image is a single reduced
image.</p>
<p>Interlace method 1, known as Adam7, defines seven distinct
passes over the image. Each pass transmits a subset of the pixels
in the reference image. The pass in which each pixel is
transmitted (numbered from 1 to 7) is defined by replicating the
following 8-by-8 pattern over the entire image, starting at the
upper left corner:</p>
<pre>
1 6 4 6 2 6 4 6
7 7 7 7 7 7 7 7
5 6 5 6 5 6 5 6
7 7 7 7 7 7 7 7
3 6 4 6 3 6 4 6
7 7 7 7 7 7 7 7
5 6 5 6 5 6 5 6
7 7 7 7 7 7 7 7
</pre>
<p><a href="#figure48"><span class="figref">Figure 4.8</span></a>
shows the seven passes of interlace method 1. Within each pass,
the selected pixels are transmitted left to right within a
scanline, and selected scanlines sequentially from top to bottom.
For example, pass 2 contains pixels 4, 12, 20, etc. of scanlines
0, 8, 16, etc. (where scanline 0, pixel 0 is the upper left
corner). The last pass contains all of scanlines 1, 3, 5, etc.
The transmission order is defined so that all the scanlines
transmitted in a pass will have the same number of pixels; this
is necessary for proper application of some of the filters. The
interlaced PNG image consists of a sequence of seven reduced
images. For example, if the PNG image is 16 by 16 pixels, then
the third pass will be a reduced image of two scanlines, each
containing four pixels (see <a href="#figure48"><span class=
"figref">figure 4.8</span></a>).</p>
<p>Scanlines that do not completely fill an integral number of
bytes are padded as defined in 7.2: <a href="#7Scanline"><span
class="xref">Scanlines</span></a>.</p>
<p class="Note">NOTE If the reference image contains fewer than
five columns or fewer than five rows, some passes will be
empty.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="9Filters">9 Filtering</a></h1>
<h2><a name="9FtIntro">9.1 Filter methods and filter
types</a></h2>
<p>Filtering transforms the PNG image with the goal of
improving compression. PNG allows for a number of filter methods.
All the reduced
images in an interlaced image shall use a single filter method.
Only filter method 0
is defined by this International Standard. Other filter methods
are reserved for future standardization (see 4.9 <a href=
"#4Concepts.Registration"><span class="xref">Extension and
registration</span></a>).
Filter method 0 provides a set of five filter types,
and individual scanlines in each reduced image may use
different filter types.</p>
<p>PNG imposes no additional restriction on which filter types
can be applied to an interlaced PNG image. However, the filter
types are not equally effective on all types of data. See 12.8:
<a href="#12Filter-selection"><span class="xref">Filter
selection</span></a>.</p>
<p>Filtering transforms the byte sequence in a scanline to an
equal length sequence of bytes preceded by the filter type.
Filter type bytes are associated only with non-empty scanlines.
No filter type bytes are present in an empty pass. See 13.8: <a
href="#13Progressive-display"><span class="xref">Interlacing and
progressive display</span></a>.</p>
<h2><a name="9Filter-types">9.2 Filter types for filter method
0</a></h2>
<p>Filters are applied to <strong>bytes</strong>, not to pixels,
regardless of the bit depth or colour type of the image. The
filters operate on the byte sequence formed by a scanline that
has been represented as described in 7.2: <a href=
"#7Scanline"><span class="xref">Scanlines</span></a>. If the image
includes an alpha channel, the alpha data is filtered in the same
way as the image data.</p>
<p>Filters may use the original values of the following bytes to
generate the new byte value:</p>
<table class="Regular" summary=
"This table defines the variables usedin table 9.1">
<tr>
<td class="Regular"><tt>x</tt> </td>
<td class="Regular">the byte being filtered;</td>
</tr>
<tr>
<td class="Regular"><tt>a</tt> </td>
<td class="Regular">the byte corresponding to x in the pixel immediately before the pixel containing x (or the byte immediately before x, when the bit depth is less than 8);</td>
</tr>
<tr>
<td class="Regular"><tt>b</tt> </td>
<td class="Regular">the byte corresponding to x in the previous scanline;</td>
</tr>
<tr>
<td class="Regular"><tt>c</tt> </td>
<td class="Regular">the byte corresponding to b in the pixel immediately before the pixel containing b (or the byte immediately before b, when the bit depth is less than 8).</td>
</tr>
</table>
<p><a href="#9-figure91"><span class="figref">Figure
9.1</span></a> shows the relative positions of the bytes <tt>x</tt>,
<tt>a</tt>, <tt>b</tt>,
and <tt>c</tt>.</p>
<p>PNG filter method 0 defines five basic filter types as listed
in <a href="#9-table91"><span class="tabref">Table
9.1</span></a>. <tt>Orig(y)</tt> denotes the orginal (unfiltered)
value of byte <tt>y</tt>. <tt>Filt(y)</tt> denotes the value
after a filter has been applied. <tt>Recon(y)</tt> denotes the
value after the corresponding reconstruction function has been
applied. The filter function for the Paeth type
<tt>PaethPredictor</tt> is defined below.</p>
<p>Filter method 0 specifies exactly this set of five filter
types and this shall not be extended.
This ensures that decoders need not decompress the data
to determine whether it contains unsupported filter types:
it is sufficient to check the filter method in <a href="#11IHDR"><span class=
"chunk">IHDR</span></a>.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<table class="Regular" summary=
"This table lists the filter types">
<caption><a name="9-table91"><b>Table 9.1 — Filter
types</b></a></caption>
<tr>
<th>Type</th>
<th>Name</th>
<th>Filter Function</th>
<th>Reconstruction Function</th>
</tr>
<tr>
<td class="Regular" align="center">0</td>
<td class="Regular">None</td>
<td class="Regular"><tt>Filt(x) = Orig(x)</tt> </td>
<td class="Regular"><tt>Recon(x) = Filt(x)</tt> </td>
</tr>
<tr>
<td class="Regular" align="center">1</td>
<td class="Regular">Sub</td>
<td class="Regular"><tt>Filt(x) = Orig(x) - Orig(a)</tt> </td>
<td class="Regular"><tt>Recon(x) = Filt(x) + Recon(a)</tt> </td>
</tr>
<tr>
<td class="Regular" align="center">2</td>
<td class="Regular">Up</td>
<td class="Regular"><tt>Filt(x) = Orig(x) - Orig(b)</tt> </td>
<td class="Regular"><tt>Recon(x) = Filt(x) + Recon(b)</tt> </td>
</tr>
<tr>
<td class="Regular" align="center">3</td>
<td class="Regular">Average</td>
<td class="Regular"><tt>Filt(x) = Orig(x) - floor((Orig(a) + Orig(b)) /
2)</tt> </td>
<td class="Regular"><tt>Recon(x) = Filt(x) + floor((Recon(a) + Recon(b)) /
2)</tt> </td>
</tr>
<tr>
<td class="Regular" align="center">4</td>
<td class="Regular">Paeth</td>
<td class="Regular"><tt>Filt(x) = Orig(x) - PaethPredictor(Orig(a),
Orig(b), Orig(c))</tt> </td>
<td class="Regular"><tt>Recon(x) = Filt(x) + PaethPredictor(Recon(a), Recon(b),
Recon(c))</tt> </td>
</tr>
</table>
<p>For all filters, the bytes "to the left of" the first pixel in
a scanline shall be treated as being zero. For filters that refer
to the prior scanline, the entire prior scanline and bytes "to
the left of" the first pixel in the prior scanline shall be
treated as being zeroes for the first scanline of a reduced
image.</p>
<p>To reverse the effect of a filter requires the decoded values
of the prior pixel on the same scanline, the pixel immediately
above the current pixel on the prior scanline, and the pixel just
to the left of the pixel above.</p>
<p>Unsigned arithmetic modulo 256 is used, so that both the
inputs and outputs fit into bytes. Filters are applied to each
byte regardless of bit depth. The sequence of <tt>Filt</tt>
values is transmitted as the filtered scanline.</p>
<h2><a name="9Filter-type-3-Average">9.3 Filter type 3:
Average</a></h2>
<p>The sum <tt>Orig(a) + Orig(b)</tt> shall be performed without
overflow (using at least nine-bit arithmetic). <tt>floor()</tt>
indicates that the result of the division is rounded to the next
lower integer if fractional; in other words, it is an integer
division or right shift operation.</p>
<h2><a name="9Filter-type-4-Paeth">9.4 Filter type 4:
Paeth</a></h2>
<p>The Paeth filter function computes a simple linear function of
the three neighbouring pixels (left, above, upper left), then
chooses as predictor the neighbouring pixel closest to the
computed value. The algorithm used in this International Standard
is an adaptation of the technique due to Alan W. Paeth <a href=
"#G-PAETH"><span class="bibref">[PAETH]</span></a>.</p>
<p>The PaethPredictor function is defined in the code below. The
logic of the function and the locations of the bytes <tt>a</tt>,
<tt>b</tt>, <tt>c</tt>, and <tt>x</tt> are shown in <a href=
"#9-figure91"><span class="figref">figure 9.1</span></a>.
<tt>Pr</tt> is the predictor for byte <tt>x</tt>.</p>
<pre>
p = a + b - c
pa = abs(p - a)
pb = abs(p - b)
pc = abs(p - c)
if pa <= pb and pa <= pc then Pr = a
else if pb <= pc then Pr = b
else Pr = c
return Pr
</pre>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<p><a name="9-figure91">
<object height="360" width="640" data="figures/fig91.svg" type="image/svg+xml">
<img height="360" width="640" src="png-figures/fig91.png" alt="Figure 9.1: The PaethPredictor
function" />
</object>
</a></p>
<p class="Figuretitle"><b>Figure 9.1: The PaethPredictor
function</b></p>
<p>The calculations within the PaethPredictor function shall be
performed exactly, without overflow.</p>
<p><strong>The order in which the comparisons are performed is
critical and shall not be altered.</strong> The function tries to
establish in which of the three directions (vertical, horizontal,
or diagonal) the gradient of the image is smallest.</p>
<p>Exactly the same PaethPredictor function is used by both
encoder and decoder.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="10Compression">10 Compression</a></h1>
<h2><a name="10CompressionCM0">10.1 Compression method 0</a></h2>
<p>Only PNG compression method 0 is defined by this International
Standard. Other values of compression method are reserved for
future standardization (see 4.9: <a href=
"#4Concepts.Registration"><span class="xref">Extension and
registration</span></a>). PNG compression method 0 is
deflate/inflate compression with a sliding window
(which is an upper bound on the distances appearing in the
deflate stream) of at most
32768 bytes. Deflate compression is an LZ77 derivative <a href=
"#G-ZL"><span class="bibref">[ZL]</span></a>.</p>
<p>Deflate-compressed datastreams within PNG are stored in the
"zlib" format, which has the structure:</p>
<table class="Regular" summary=
"This table gives the structure of the zlib format">
<tr>
<td class="Regular">zlib compression method/flags code</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Additional flags/check bits</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Compressed data blocks</td>
<td class="Regular">n bytes</td>
</tr>
<tr>
<td class="Regular">Check value</td>
<td class="Regular">4 bytes</td>
</tr>
</table>
<p>Further details on this format are given in the zlib
specification <a href="#2-RFC-1950"><span class=
"NormRef">[RFC-1950]</span></a>.</p>
<p>For PNG compression method 0, the zlib compression
method/flags code shall specify method code 8 (deflate
compression) and an LZ77 window size of not more than 32768
bytes. The zlib compression method number is not the same as the
PNG compression method number in the <a href=
"#11IHDR"><span class="chunk">IHDR</span></a> chunk (see 11.2.2
<a href="#11IHDR"><span class="xref"><span class=
"chunk">IHDR</span> Image header</span></a>). The additional
flags shall not specify a preset dictionary.</p>
<p>If the data to be compressed contain 16384 bytes or fewer, the
PNG encoder may set the window size by rounding up to a power of
2 (256 minimum). This decreases the memory required for both
encoding and decoding, without adversely affecting the
compression ratio.</p>
<p>The compressed data within the zlib datastream are stored as a
series of blocks, each of which can represent raw (uncompressed)
data, LZ77-compressed data encoded with fixed Huffman codes, or
LZ77-compressed data encoded with custom Huffman codes. A marker
bit in the final block identifies it as the last block, allowing
the decoder to recognize the end of the compressed datastream.
Further details on the compression algorithm and the encoding are
given in the deflate specification <a href="#2-RFC-1951"><span
class="NormRef">[RFC-1951]</span></a>.</p>
<p>The check value stored at the end of the zlib datastream is
calculated on the uncompressed data represented by the
datastream. The algorithm used to calculate this is not the same
as the CRC calculation used for PNG chunk CRC field values. The
zlib check value is useful mainly as a cross-check that the
deflate and inflate algorithms are implemented correctly.
Verifying the individual PNG chunk CRCs provides confidence that
the PNG datastream has been transmitted undamaged.</p>
<h2><a name="10CompressionFSL">10.2 Compression of the sequence
of filtered scanlines</a></h2>
<p>The sequence of filtered scanlines is compressed and the
resulting data stream is split into <a href="#11IDAT"><span
class="chunk">IDAT</span></a> chunks. The concatenation of the
contents of all the <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> chunks makes up a zlib datastream. This
datastream decompresses to filtered image data.</p>
<p>It is important to emphasize that the boundaries between <a
href="#11IDAT"><span class="chunk">IDAT</span></a> chunks are
arbitrary and can fall anywhere in the zlib datastream. There is
not necessarily any correlation between <a href="#11IDAT"><span
class="chunk">IDAT</span></a> chunk boundaries and deflate block
boundaries or any other feature of the zlib data. For example, it
is entirely possible for the terminating zlib check value to be
split across <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> chunks.</p>
<p>Similarly, there is no required correlation between the
structure of the image data (i.e., scanline boundaries) and
deflate block boundaries or <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> chunk boundaries. The complete filtered
PNG image is represented by a single zlib datastream that is
stored in a number of <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> chunks.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h2><a name="10CompressionOtherUses">10.3 Other uses of
compression</a></h2>
<p>PNG also uses compression method 0 in <a href="#11iTXt"><span
class="chunk">iTXt</span></a>, <a href="#11iCCP"><span class=
"chunk">iCCP</span></a>, and <a href="#11zTXt"><span class=
"chunk">zTXt</span></a> chunks. Unlike the image data, such
datastreams are not split across chunks; each such chunk contains
an independent zlib datastream (see 10.1: <a href=
"#10CompressionCM0"><span class="xref">Compression method
0</span></a>).</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="11Chunks">11 Chunk specifications</a></h1>
<h2><a name="11Introduction">11.1 Introduction</a></h2>
<p>The PNG datastream consists of a PNG signature (see 5.2: <a
href="#5PNG-file-signature"><span class="xref">PNG
signature</span></a>) followed by a sequence of chunks. Each
chunk has a chunk type which specifies its function. This clause
defines the PNG chunk types standardized in this International
Standard. The PNG datastream structure is defined in clause 5: <a
href="#5DataRep"><span class="xref">Datastream
structure</span></a>. This also defines the order in which chunks
may appear. For details specific to encoders see 12.11: <a href=
"#12Chunk-processing"><span class="xref">Chunking</span></a>.
For details specific to decoders see 13.5: <a href=
"#13Chunking"><span class="xref">Chunking</span></a>.</p>
<h2><a name="11Critical-chunks">11.2 Critical chunks</a></h2>
<h3><a name="11CcGen">11.2.1 General</a></h3>
<p>Critical chunks are those chunks that are absolutely required
in order to successfully decode a PNG image from a PNG
datastream. Extension chunks may be defined as critical chunks
(see clause 14: <a href="#14EditorsExt"><span class=
"xref">Editors and extensions</span></a>), though this practice
is strongly discouraged.</p>
<p>A valid PNG datastream shall begin with a PNG signature,
immediately followed by an <a href="#11IHDR"><span class=
"chunk">IHDR</span></a> chunk, then one or more <a href=
"#11IDAT"><span class="chunk">IDAT</span></a> chunks, and shall
end with an <a href="#11IEND"><span class="chunk">IEND</span></a>
chunk. Only one <a href="#11IHDR"><span class=
"chunk">IHDR</span></a> chunk and one <a href="#11IEND"><span
class="chunk">IEND</span></a> chunk are allowed in a PNG
datastream.</p>
<h3><a name="11IHDR">11.2.2 <span class="chunk">IHDR</span> Image
header</a></h3>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
73 72 68 82
</pre>
<p>The <span class="chunk">IHDR</span> chunk shall be the first
chunk in the PNG datastream. It contains:</p>
<table class="Regular" summary=
"This table defines the IHDR chunk">
<tr>
<td class="Regular">Width</td>
<td class="Regular">4 bytes</td>
</tr>
<tr>
<td class="Regular">Height</td>
<td class="Regular">4 bytes</td>
</tr>
<tr>
<td class="Regular">Bit depth</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Colour type</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Compression method</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Filter method</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Interlace method</td>
<td class="Regular">1 byte</td>
</tr>
</table>
<p>Width and height give the image dimensions in pixels. They are
PNG four-byte unsigned integers. Zero is an invalid
value.</p>
<p>Bit depth is a single-byte integer giving the number of bits
per sample or per palette index (not per pixel). Valid values are
1, 2, 4, 8, and 16, although not all values are allowed for all
colour types. See 6.1: <a href="#6Colour-values"><span class=
"xref">Colour types and values</span></a>.</p>
<p>Colour type is a single-byte integer that defines the PNG
image type. Valid values are 0, 2, 3, 4, and 6.</p>
<p>Bit depth restrictions for each colour type are imposed to
simplify implementations and to prohibit combinations that do not
compress well. The allowed combinations are defined in <a href=
"#table111"><span class="tabref">Table 11.1</span></a>.</p>
<table class="Regular" summary=
"This table defines the colour types">
<caption><a name="table111"><b>Table 11.1 — Allowed
combinations of colour type and bit depth</b></a></caption>
<tr>
<th>PNG image type</th>
<th>Colour type</th>
<th>Allowed bit depths</th>
<th>Interpretation</th>
</tr>
<tr>
<td class="Regular">Greyscale</td>
<td class="Regular" align="center">0</td>
<td class="Regular">1, 2, 4, 8, 16</td>
<td class="Regular">Each pixel is a greyscale sample</td>
</tr>
<tr>
<td class="Regular">Truecolour</td>
<td class="Regular" align="center">2</td>
<td class="Regular">8, 16</td>
<td class="Regular">Each pixel is an R,G,B triple</td>
</tr>
<tr>
<td class="Regular">Indexed-colour</td>
<td class="Regular" align="center">3</td>
<td class="Regular">1, 2, 4, 8</td>
<td class="Regular">Each pixel is a palette index; a <a href="#11PLTE"><span
class="chunk">PLTE</span></a> chunk shall appear.</td>
</tr>
<tr>
<td class="Regular">Greyscale with alpha</td>
<td class="Regular" align="center">4</td>
<td class="Regular">8, 16</td>
<td class="Regular">Each pixel is a greyscale sample followed by an alpha
sample.</td>
</tr>
<tr>
<td class="Regular">Truecolour with alpha</td>
<td class="Regular" align="center">6</td>
<td class="Regular">8, 16</td>
<td class="Regular">Each pixel is an R,G,B triple followed by an alpha
sample.</td>
</tr>
</table>
<p>The sample depth is the same as the bit depth except in the
case of indexed-colour PNG images (colour type 3), in which the
sample depth is always 8 bits (see 4.4: <a href=
"#4Concepts.PNGImage"><span class="xref">PNG image</span></a>).</p>
<p>Compression method is a single-byte integer that indicates the
method used to compress the image data. Only compression method 0
(deflate/inflate compression with a sliding window of at most
32768 bytes) is defined in this International Standard. All
conforming PNG images shall be compressed with this scheme.</p>
<p>Filter method is a single-byte integer that indicates the
preprocessing method applied to the image data before
compression. Only filter method 0 (adaptive filtering with five
basic filter types) is defined in this International Standard.
See clause 9: <a href="#9Filters"><span class=
"xref">Filtering</span></a> for details.</p>
<p>Interlace method is a single-byte integer that indicates the
transmission order of the image data. Two values are defined in
this International Standard: 0 (no interlace) or 1 (Adam7
interlace). See clause 8: <a href="#8Interlace"><span class=
"xref">Interlacing and pass extraction</span></a> for
details.</p>
<h3><a name="11PLTE">11.2.3 <span class="chunk">PLTE</span>
Palette</a></h3>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
80 76 84 69
</pre>
<p>The <span class="chunk">PLTE</span> chunk contains from 1 to
256 palette entries, each a three-byte series of the form:</p>
<table class="Regular" summary=
"This table defines the PLTE palette table entries">
<tr>
<td class="Regular">Red</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Green</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Blue</td>
<td class="Regular">1 byte</td>
</tr>
</table>
<p>The number of entries is determined from the chunk length. A
chunk length not divisible by 3 is an error.</p>
<p>This chunk shall appear for colour type 3, and may appear for
colour types 2 and 6; it shall not appear for colour types 0 and
4. There shall not be more than one <span class=
"chunk">PLTE</span> chunk.</p>
<p>For colour type 3 (indexed-colour), the <span class=
"chunk">PLTE</span> chunk is required. The first entry in <span
class="chunk">PLTE</span> is referenced by pixel value 0, the
second by pixel value 1, etc. The number of palette entries shall
not exceed the range that can be represented in the image bit
depth (for example, 2<sup>4</sup> = 16 for a bit depth of 4). It
is permissible to have fewer entries than the bit depth would
allow. In that case, any out-of-range pixel value found in the
image data is an error.</p>
<p>For colour types 2 and 6 (truecolour and truecolour with
alpha), the <span class="chunk">PLTE</span> chunk is optional. If
present, it provides a suggested set of colours (from 1 to 256)
to which the truecolour image can be quantized if it cannot be
displayed directly. It is, however, recommended that the <a href=
"#11sPLT"><span class="chunk">sPLT</span></a> chunk be used for
this purpose, rather than the <span class="chunk">PLTE</span>
chunk. If neither <span class="chunk">PLTE</span> nor <a href=
"#11sPLT"><span class="chunk">sPLT</span></a> chunks are present
and the image cannot be displayed directly, quantization has to
be done by the viewing system. However, it is often preferable
for the selection of colours to be done once by the PNG encoder.
(See 12.6: <a href="#12Suggested-palettes"><span class=
"xref">Suggested palettes</span></a>.)</p>
<p>Note that the palette uses 8 bits (1 byte) per sample
regardless of the image bit depth. In particular,
the palette is 8 bits deep even when it is a suggested
quantization of a 16-bit truecolour image.</p>
<p>There is no requirement that the palette entries all be used
by the image, nor that they all be different.</p>
<h3><a name="11IDAT">11.2.4 <span class="chunk">IDAT</span> Image
data</a></h3>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
73 68 65 84
</pre>
<p>The <span class="chunk">IDAT</span> chunk contains the actual
image data which is the output stream of the compression
algorithm. See clause 9: <a href="#9Filters"><span class=
"xref">Filtering</span></a> and clause 10: <a href=
"#10Compression"><span class="xref">Compression</span></a> for
details.</p>
<p>There may be multiple <span class="chunk">IDAT</span> chunks;
if so, they shall appear consecutively with no other intervening
chunks. The compressed datastream is then the concatenation of
the contents of the data fields of all the <span class=
"chunk">IDAT</span> chunks.</p>
<h3><a name="11IEND">11.2.5 <span class="chunk">IEND</span> Image
trailer</a></h3>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
73 69 78 68
</pre>
<p>The <span class="chunk">IEND</span> chunk marks the end of the
PNG datastream. The chunk's data field is empty.</p>
<h2><a name="11Ancillary-chunks">11.3 Ancillary chunks</a></h2>
<h3><a name="11AcGen">11.3.1 General</a></h3>
<p>The ancillary chunks defined in this International Standard
are listed in the order in 4.7.2: <a href=
"#4Concepts.FormatTypes"><span class="xref">Chunk
types</span></a>. This is not the order in which they appear in a
PNG datastream. Ancillary chunks may be ignored by a decoder. For
each ancillary chunk, the actions described are under the
assumption that the decoder is not ignoring the chunk.</p>
<h3><a name="11transinfo">11.3.2 Transparency
information</a></h3>
<h4><a name="11tRNS">11.3.2.1 <span class="chunk">tRNS</span>
Transparency</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
116 82 78 83
</pre>
<p>The <span class="chunk">tRNS</span> chunk specifies either
alpha values that are associated with palette entries (for
indexed-colour images) or a single transparent colour (for
greyscale and truecolour images). The <span class=
"chunk">tRNS</span> chunk contains:
<!-- ************Page Break******************* -->
</p>
<!-- ************Page Break******************* -->
<table class="Regular" summary=
"This table defines the tRNS chunk">
<tr>
<th colspan="2">Colour type 0</th>
</tr>
<tr>
<td class="Regular">Grey sample value</td>
<td class="Regular">2 bytes</td>
</tr>
<tr>
<th colspan="2">Colour type 2</th>
</tr>
<tr>
<td class="Regular">Red sample value</td>
<td class="Regular">2 bytes</td>
</tr>
<tr>
<td class="Regular">Blue sample value</td>
<td class="Regular">2 bytes</td>
</tr>
<tr>
<td class="Regular">Green sample value</td>
<td class="Regular">2 bytes</td>
</tr>
<tr>
<th colspan="2">Colour type 3</th>
</tr>
<tr>
<td class="Regular">Alpha for palette index 0</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Alpha for palette index 1</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">...etc...</td>
<td class="Regular">1 byte</td>
</tr>
</table>
<p>For colour type 3 (indexed-colour), the <span class=
"chunk">tRNS</span> chunk contains a series of one-byte alpha
values, corresponding to entries in the <a href="#11PLTE"><span
class="chunk">PLTE</span></a> chunk. Each entry indicates that
pixels of the corresponding palette index shall be treated as
having the specified alpha value. Alpha values have the same
interpretation as in an 8-bit full alpha channel: 0 is fully
transparent, 255 is fully opaque, regardless of image bit depth.
The <span class="chunk">tRNS</span> chunk shall not contain more
alpha values than there are palette entries, but a <span class=
"chunk">tRNS</span> chunk may contain fewer values than there are
palette entries. In this case, the alpha value for all remaining
palette entries is assumed to be 255. In the common case in which
only palette index 0 need be made transparent, only a one-byte
<span class="chunk">tRNS</span> chunk is needed, and when all
palette indices are opaque, the <span class="chunk">tRNS</span>
chunk may be omitted.</p>
<p>For colour types 0 or 2, two bytes per sample are used
regardless of the image bit depth (see 7.1: <a href=
"#7Integers-and-byte-order"><span class="xref">Integers and byte
order</span></a>). Pixels of the specified grey sample value or
RGB sample values are treated as transparent (equivalent to alpha
value 0); all other pixels are to be treated as fully opaque
(alpha value 2<sup>bitdepth</sup>-1). If the image bit depth is
less than 16, the least significant bits are used and the others
are 0.</p>
<p>A <span class="chunk">tRNS</span> chunk shall not appear for
colour types 4 and 6, since a full alpha channel is already
present in those cases.</p>
<p class="Note">NOTE For 16-bit greyscale or truecolour data,
only pixels matching the entire 16-bit values in <span class=
"chunk">tRNS</span> chunks are transparent. Decoders have to
postpone any sample depth rescaling until after the pixels have
been tested for transparency.</p>
<h3><a name="11addnlcolinfo">11.3.3 Colour space
information</a></h3>
<h4><a name="11cHRM">11.3.3.1 <span class="chunk">cHRM</span>
Primary chromaticities and white point</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
99 72 82 77
</pre>
<p>The <span class="chunk">cHRM</span> chunk may be used to
specify the 1931 CIE <i>x,y</i> chromaticities of the red,
green, and blue display primaries used in the image, and the referenced
white point. See Annex C: <a href="#C-GammaAppendix"><span class=
"xref">Gamma and chromaticity</span></a> for more information.
The <a href="#11iCCP"><span class="chunk">iCCP</span></a> and <a
href="#11sRGB"><span class="chunk">sRGB</span></a> chunks provide
more sophisticated support for colour management and control.</p>
<p>The <span class="chunk">cHRM</span> chunk contains:</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<table class="Regular" summary=
"This table defines the cHRM chunk">
<tr>
<td class="Regular">White point x</td>
<td class="Regular">4 bytes</td>
</tr>
<tr>
<td class="Regular">White point y</td>
<td class="Regular">4 bytes</td>
</tr>
<tr>
<td class="Regular">Red x</td>
<td class="Regular">4 bytes</td>
</tr>
<tr>
<td class="Regular">Red y</td>
<td class="Regular">4 bytes</td>
</tr>
<tr>
<td class="Regular">Green x</td>
<td class="Regular">4 bytes</td>
</tr>
<tr>
<td class="Regular">Green y</td>
<td class="Regular">4 bytes</td>
</tr>
<tr>
<td class="Regular">Blue x</td>
<td class="Regular">4 bytes</td>
</tr>
<tr>
<td class="Regular">Blue y</td>
<td class="Regular">4 bytes</td>
</tr>
</table>
<p>Each value is encoded as a four-byte PNG unsigned integer,
representing the <i>x</i> or <i>y</i> value times 100000.</p>
<p>EXAMPLE A value of 0.3127 would be stored as the integer
31270.</p>
<p>The <span class="chunk">cHRM</span> chunk is allowed in all
PNG datastreams, although it is of little value for greyscale
images.</p>
<p>An <a href="#11sRGB"><span class="chunk">sRGB</span></a> chunk
or <a href="#11iCCP"><span class="chunk">iCCP</span></a> chunk,
when present and recognized, overrides the <span class=
"chunk">cHRM</span> chunk.</p>
<h4><a name="11gAMA">11.3.3.2 <span class="chunk">gAMA</span>
Image gamma</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
103 65 77 65
</pre>
<p>The <span class="chunk">gAMA</span> chunk specifies the
relationship between the image samples and the desired display
output intensity. Gamma is defined in 3.1.20: <a href=
"#3gamma">gamma</a>.</p>
<p>In fact specifying the desired display output intensity is
insufficient. It is also necessary to specify the viewing
conditions under which the output is desired. For <span class=
"chunk">gAMA</span> these are the reference viewing conditions of
the sRGB specification <a href="#2-IEC-61966-2-1"><span class=
"NormRef">[IEC 61966-2-1]</span></a>, which are based on ISO 3664
<a href="#G-ISO-3664"><span class="bibref">[ISO-3664]</span></a>.
Adjustment for different viewing conditions is normally handled
by a Colour Management System. If the adjustment is not
performed, the error is usually small. Applications desiring high
colour fidelity may wish to use an <a href="#11sRGB"><span class=
"chunk">sRGB</span></a> chunk or <a href="#11iCCP"><span class=
"chunk">iCCP</span></a> chunk.</p>
<p>The <span class="chunk">gAMA</span> chunk contains:</p>
<table class="Regular" summary=
"This table defines the gAMA chunk">
<tr>
<td class="Regular">Image gamma</td>
<td class="Regular">4 bytes</td>
</tr>
</table>
<p>The value is encoded as a four-byte PNG unsigned integer,
representing gamma times 100000.</p>
<p>EXAMPLE A gamma of 1/2.2 would be stored as the integer
45455.</p>
<p>See 12.2: <a href="#12Encoder-gamma-handling"><span class=
"xref">Encoder gamma handling</span></a> and 13.13: <a href=
"#13Decoder-gamma-handling"><span class="xref">Decoder gamma
handling</span></a> for more information.</p>
<p>An <a href="#11sRGB"><span class="chunk">sRGB</span></a> chunk
or <a href="#11iCCP"><span class="chunk">iCCP</span></a> chunk,
when present and recognized, overrides the <span class=
"chunk">gAMA</span> chunk.</p>
<h4><a name="11iCCP">11.3.3.3 <span class="chunk">iCCP</span>
Embedded ICC profile</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
105 67 67 80
</pre>
<p>The <span class="chunk">iCCP</span> chunk contains:</p>
<table class="Regular" summary=
"This table defines the iCCP chunk">
<tr>
<td class="Regular">Profile name</td>
<td class="Regular">1-79 bytes (character string)</td>
</tr>
<tr>
<td class="Regular">Null separator</td>
<td class="Regular">1 byte (null character)</td>
</tr>
<tr>
<td class="Regular">Compression method</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Compressed profile</td>
<td class="Regular">n bytes</td>
</tr>
</table>
<p>The profile name may be any convenient name for referring to
the profile. It is case-sensitive. Profile names shall contain
only printable Latin-1 characters and spaces (only character
codes 32-126 and 161-255 decimal are allowed). Leading, trailing,
and consecutive spaces are not permitted. The only compression
method defined in this International Standard is method 0 (zlib
datastream with deflate compression, see 10.3: <a href=
'#10CompressionOtherUses'><span class="xref">Other uses of
compression</span></a>). The compression method entry is followed
by a compressed profile that makes up the remainder of the chunk.
Decompression of this datastream yields the embedded ICC
profile.</p>
<p>If the <span class="chunk">iCCP</span> chunk is present, the
image samples conform to the colour space represented by the
embedded ICC profile as defined by the International Color
Consortium <a href="#G-ICC"><span class=
"bibref">[ICC]</span></a>. The colour space of the ICC profile
shall be an RGB colour space for colour images (PNG colour types
2, 3, and 6), or a greyscale colour space for greyscale images
(PNG colour types 0 and 4). A PNG encoder that writes the <span
class="chunk">iCCP</span> chunk is encouraged to also write <a
href="#11gAMA"><span class="chunk">gAMA</span></a> and <a href=
"#11cHRM"><span class="chunk">cHRM</span></a> chunks that
approximate the ICC profile, to provide compatibility with
applications that do not use the <span class="chunk">iCCP</span>
chunk. When the <span class="chunk">iCCP</span> chunk is present,
PNG decoders that recognize it and are capable of colour
management <a href="#G-ICC"><span class="bibref">[ICC]</span></a>
shall ignore the <a href="#11gAMA"><span class=
"chunk">gAMA</span></a> and <a href="#11cHRM"><span class=
"chunk">cHRM</span></a> chunks and use the <span class=
"chunk">iCCP</span> chunk instead and interpret it according to
<a href="#2-ICC-1"><span class="NormRef">[ICC-1]</span></a> and
<a href="#2-ICC-1A"><span class="NormRef">[ICC-1A]</span></a>.
PNG decoders that are used in an environment that is incapable of
full-fledged colour management should use the <a href=
"#11gAMA"><span class="chunk">gAMA</span></a> and <a href=
"#11cHRM"><span class="chunk">cHRM</span></a> chunks if
present.</p>
<p>A PNG datastream should contain at most one embedded profile,
whether specified explicitly with an <span class=
"chunk">iCCP</span> chunk or implicitly with an <a href=
"#11sRGB"><span class="chunk">sRGB</span></a> chunk.</p>
<h4><a name="11sBIT">11.3.3.4 <span class="chunk">sBIT</span>
Significant bits</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
115 66 73 84
</pre>
<p>To simplify decoders, PNG specifies that only certain sample
depths may be used, and further specifies that sample values
should be scaled to the full range of possible values at the
sample depth. The <a href="#11sBIT"><span class=
"chunk">sBIT</span></a> chunk defines the original number of
significant bits (which can be less than or equal to the sample
depth). This allows PNG decoders to recover the original data
losslessly even if the data had a sample depth not directly
supported by PNG.</p>
<p>The <span class="chunk">sBIT</span> chunk contains:</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<table class="Regular" summary=
"This table defines the sBIT chunk">
<tr>
<th colspan="2">Colour type 0</th>
</tr>
<tr>
<td class="Regular">significant greyscale bits</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<th colspan="2">Colour types 2 and 3</th>
</tr>
<tr>
<td class="Regular">significant red bits</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">significant green bits</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">significant blue bits</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<th colspan="2">Colour type 4</th>
</tr>
<tr>
<td class="Regular">significant greyscale bits</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">significant alpha bits</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<th colspan="2">Colour type 6</th>
</tr>
<tr>
<td class="Regular">significant red bits</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">significant green bits</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">significant blue bits</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">significant alpha bits</td>
<td class="Regular">1 byte</td>
</tr>
</table>
<p>Each depth specified in <span class="chunk">sBIT</span> shall
be greater than zero and less than or equal to the sample depth
(which is 8 for indexed-colour images, and the bit depth given in
<a href="#11IHDR"><span class="chunk">IHDR</span></a> for other
colour types).
Note that <span class="chunk">sBIT</span> does not provide a sample depth
for the alpha channel that is implied by a
<a href="#11tRNS"><span class=
"chunk">tRNS</span></a> chunk; in that case, all of the sample bits of
the alpha channel are to be treated as significant. If the <span
class="chunk">sBIT</span> chunk is not present, then all of the
sample bits of all channels are to be treated as significant.</p>
<h4><a name="11sRGB">11.3.3.5 <span class="chunk">sRGB</span>
Standard RGB colour space</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
115 82 71 66
</pre>
<p>If the <span class="chunk">sRGB</span> chunk is present, the
image samples conform to the sRGB colour space <a href=
"#2-IEC-61966-2-1"><span class="NormRef">[IEC
61966-2-1]</span></a> and should be displayed using the specified
rendering intent defined by the International Color Consortium <a
href="#2-ICC-1"><span class="NormRef">[ICC-1]</span></a> and <a
href="#2-ICC-1A"><span class="NormRef">[ICC-1A]</span></a>.</p>
<p>The <span class="chunk">sRGB</span> chunk contains:</p>
<table class="Regular" summary=
"This table defines the sRGB chunk">
<tr>
<td class="Regular">Rendering intent</td>
<td class="Regular">1 byte</td>
</tr>
</table>
<p>The following values are defined for rendering intent:</p>
<table class="Regular" summary=
"This table defines the values of rendering intent in the sRGB chunk">
<tr>
<td class="Regular">0</td>
<td class="Regular">Perceptual</td>
<td class="Regular">for images preferring good adaptation to the output device
gamut at the expense of colorimetric accuracy, such as
photographs.</td>
</tr>
<tr>
<td class="Regular">1</td>
<td class="Regular">Relative colorimetric</td>
<td class="Regular">for images requiring colour appearance matching (relative to
the output device white point), such as logos.</td>
</tr>
<tr>
<td class="Regular">2</td>
<td class="Regular">Saturation</td>
<td class="Regular">for images preferring preservation of saturation at the
expense of hue and lightness, such as charts and graphs.</td>
</tr>
<tr>
<td class="Regular">3</td>
<td class="Regular">Absolute colorimetric</td>
<td class="Regular">for images requiring preservation of absolute colorimetry,
such as previews of images destined for a different output device
(proofs).</td>
</tr>
</table>
<p>It is recommended that a PNG encoder that writes the <span
class="chunk">sRGB</span> chunk also write a <a href=
"#11gAMA"><span class="chunk">gAMA</span></a> chunk (and
optionally a <a href="#11cHRM"><span class=
"chunk">cHRM</span></a> chunk) for compatibility with decoders
that do not use the <span class="chunk">sRGB</span> chunk. Only
the following values shall be used.</p>
<table class="Regular" summary=
"This table defines the gAMA and cHRM values for sRGB">
<tr>
<th colspan="2"><a href="#11gAMA"><span class=
"chunk">gAMA</span></a> </th>
</tr>
<tr>
<td class="Regular">Gamma</td>
<td class="Regular">45455</td>
</tr>
<tr>
<th colspan="2"><a href="#11cHRM"><span class=
"chunk">cHRM</span></a> </th>
</tr>
<tr>
<td class="Regular">White point x</td>
<td class="Regular">31270</td>
</tr>
<tr>
<td class="Regular">White point y</td>
<td class="Regular">32900</td>
</tr>
<tr>
<td class="Regular">Red x</td>
<td class="Regular">64000</td>
</tr>
<tr>
<td class="Regular">Red y</td>
<td class="Regular">33000</td>
</tr>
<tr>
<td class="Regular">Green x</td>
<td class="Regular">30000</td>
</tr>
<tr>
<td class="Regular">Green y</td>
<td class="Regular">60000</td>
</tr>
<tr>
<td class="Regular">Blue x</td>
<td class="Regular">15000</td>
</tr>
<tr>
<td class="Regular">Blue y</td>
<td class="Regular">6000</td>
</tr>
</table>
<p>When the <span class="chunk">sRGB</span> chunk is present, it
is recommended that decoders that recognize it and are capable of
colour management <a href="#G-ICC"><span class=
"bibref">[ICC]</span></a> ignore the <a href="#11gAMA"><span
class="chunk">gAMA</span></a> and <a href="#11cHRM"><span class=
"chunk">cHRM</span></a> chunks and use the <span class=
"chunk">sRGB</span> chunk instead. Decoders that recognize the
<span class="chunk">sRGB</span> chunk but are not capable of
colour management <a href="#G-ICC"><span class=
"bibref">[ICC]</span></a> are recommended to ignore the <a href=
"#11gAMA"><span class="chunk">gAMA</span></a> and <a href=
"#11cHRM"><span class="chunk">cHRM</span></a> chunks, and use the
values given above as if they had appeared in <a href=
"#11gAMA"><span class="chunk">gAMA</span></a> and <a href=
"#11cHRM"><span class="chunk">cHRM</span></a> chunks.</p>
<p>It is recommended that the <span class="chunk">sRGB</span> and
<a href="#11iCCP"><span class="chunk">iCCP</span></a> chunks do
not both appear in a PNG datastream.</p>
<h3><a name="11textinfo">11.3.4 Textual information</a></h3>
<h4><a name="11textIntro">11.3.4.1 Introduction</a></h4>
<p>PNG provides the <a href="#11tEXt"><span class=
"chunk">tEXt</span></a>, <a href="#11iTXt"><span class=
"chunk">iTXt</span></a>, and <a href="#11zTXt"><span class=
"chunk">zTXt</span></a> chunks for storing text strings
associated with the image, such as an image description or
copyright notice. Keywords are used to indicate what each text
string represents. Any number of such text chunks may appear, and
more than one with the same keyword is permitted.</p>
<h4><a name="11keywords">11.3.4.2 Keywords and text
strings</a></h4>
<p>The following keywords are predefined and should be used where
appropriate.</p>
<table class="Regular" summary=
"This table defines the keywords defined for tEXt, iTXt and zTXt chunks">
<tr>
<td class="Regular">Title</td>
<td class="Regular">Short (one line) title or caption for image</td>
</tr>
<tr>
<td class="Regular">Author</td>
<td class="Regular">Name of image's creator</td>
</tr>
<tr>
<td class="Regular">Description</td>
<td class="Regular">Description of image (possibly long)</td>
</tr>
<tr>
<td class="Regular">Copyright</td>
<td class="Regular">Copyright notice</td>
</tr>
<tr>
<td class="Regular">Creation Time</td>
<td class="Regular">Time of original image creation</td>
</tr>
<tr>
<td class="Regular">Software</td>
<td class="Regular">Software used to create the image</td>
</tr>
<tr>
<td class="Regular">Disclaimer</td>
<td class="Regular">Legal disclaimer</td>
</tr>
<tr>
<td class="Regular">Warning</td>
<td class="Regular">Warning of nature of content</td>
</tr>
<tr>
<td class="Regular">Source</td>
<td class="Regular">Device used to create the image</td>
</tr>
<tr>
<td class="Regular">Comment</td>
<td class="Regular">Miscellaneous comment</td>
</tr>
</table>
<p>Other keywords may be defined for other purposes. Keywords of
general interest can be registered with the PNG Registration
Authority (see 4.9 <a href="#4Concepts.Registration"><span class=
"xref">Extension and registration</span></a>). It is also
permitted to use private unregistered keywords. (Private keywords
should be reasonably self-explanatory, in order to minimize the
chance that the same keyword is used for incompatible purposes by
different people.)</p>
<p>Keywords shall contain only printable Latin-1 <a href=
"#2-ISO-8859-1"><span class="NormRef">[ISO-8859-1]</span></a>
characters and spaces; that is, only character codes 32-126 and
161-255 decimal are allowed. To reduce the chances for human
misreading of a keyword, leading spaces, trailing spaces,
and consecutive spaces are not permitted in keywords, nor is the
non-breaking space (code 160) since it is visually
indistinguishable from an ordinary space.</p>
<p>Keywords shall be spelled exactly as registered, so that
decoders can use simple literal comparisons when looking for
particular keywords. In particular, keywords are considered
case-sensitive. Keywords are restricted to 1 to 79 bytes in
length.</p>
<p>For the Creation Time keyword, the date format defined in
section 5.2.14 of RFC 1123 is suggested, but not required <a
href="#2-RFC-1123"><span class=
"NormRef">[RFC-1123]</span></a>.</p>
<p>In the <a href="#11tEXt"><span class="chunk">tEXt</span></a>
and <a href="#11zTXt"><span class="chunk">zTXt</span></a> chunks,
the text string associated with a keyword is restricted to the
Latin-1 character set plus the linefeed character. Text strings
in <a href="#11zTXt"><span class="chunk">zTXt</span></a> are
compressed into zlib datastreams using deflate compression (see
10.3: <a href='#10CompressionOtherUses'><span class="xref">Other
uses of compression</span></a>). The <a href="#11iTXt"><span
class="chunk">iTXt</span></a> chunk can be used to convey
characters outside the Latin-1 set. It uses the UTF-8 encoding of
UCS <a href="#2-ISO-10646-1"><span class="NormRef">[ISO/IEC
10646-1]</span></a> . There is an option to compress text strings
in the <a href="#11iTXt"><span class="chunk">iTXt</span></a>
chunk.</p>
<h4><a name="11tEXt">11.3.4.3 <span class="chunk">tEXt</span>
Textual data</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
116 69 88 116
</pre>
<p>Each <span class="chunk">tEXt</span> chunk contains a keyword
and a text string, in the format:</p>
<table class="Regular" summary=
"This table defines the tEXt chunk">
<tr>
<td class="Regular">Keyword</td>
<td class="Regular">1-79 bytes (character string)</td>
</tr>
<tr>
<td class="Regular">Null separator</td>
<td class="Regular">1 byte (null character)</td>
</tr>
<tr>
<td class="Regular">Text string</td>
<td class="Regular">0 or more bytes (character string)</td>
</tr>
</table>
<p>
The keyword and text string are separated by a zero byte (null
character). Neither the keyword nor the text string may contain a
null character.
The text string is <strong>not</strong> null-terminated (the length of
the chunk defines the ending). The text string may be of any
length from zero bytes up to the maximum permissible chunk size
less the length of the keyword and null character separator.</p>
<p>The keyword indicates the type of information represented by
the text string as described in 11.3.4.2: <a href=
"#11keywords"><span class="xref">Keywords and text
strings</span></a>.</p>
<p>Text is interpreted according to the Latin-1 character set <a
href="#2-ISO-8859-1"><span class=
"NormRef">[ISO-8859-1]</span></a>. The text string may contain
any Latin-1 character. Newlines in the text string should be
represented by a single linefeed character (decimal 10).
Characters other than those defined in Latin-1 plus the linefeed
character have no defined meaning in <span class="chunk">tEXt</span> chunks.
Text containing characters outside the repertoire of ISO/IEC
8859-1 should be encoded using the <a href="#11iTXt"><span class=
"chunk">iTXt</span></a> chunk.</p>
<h4><a name="11zTXt">11.3.4.4 <span class="chunk">zTXt</span>
Compressed textual data</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
122 84 88 116
</pre>
<p>The <span class="chunk">zTXt</span> and <a href=
"#11tEXt"><span class="chunk">tEXt</span></a> chunks are
semantically equivalent, but the <span class="chunk">zTXt</span>
chunk is recommended for storing large blocks of text.</p>
<p>A <span class="chunk">zTXt</span> chunk contains:</p>
<table class="Regular" summary=
"This table defines the zTXt chunk">
<tr>
<td class="Regular">Keyword</td>
<td class="Regular">1-79 bytes (character string)</td>
</tr>
<tr>
<td class="Regular">Null separator</td>
<td class="Regular">1 byte (null character)</td>
</tr>
<tr>
<td class="Regular">Compression method</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Compressed text datastream</td>
<td class="Regular">n bytes</td>
</tr>
</table>
<p>The keyword and null character are the same as in the <a href=
"#11tEXt"><span class="chunk">tEXt</span></a> chunk (see
11.3.4.3: <a href="#11tEXt"><span class="xref"><span class=
"chunk">tEXt</span> Textual data</span></a>). The keyword is not
compressed. The compression method entry defines the compression
method used. The only value defined in this International
Standard is 0 (deflate/inflate compression). Other values are
reserved for future standardization (see 4.9 <a href=
"#4Concepts.Registration"><span class="xref">Extension and
registration</span></a>). The compression method entry is
followed by the compressed text datastream that makes up the
remainder of the chunk. For compression method 0, this datastream
is a zlib datastream with deflate compression (see 10.3: <a href=
"#10CompressionOtherUses"><span class="xref">Other uses of
compression</span></a>). Decompression of this datastream yields
Latin-1 text that is identical to the text that would be stored
in an equivalent <a href="#11tEXt"><span class=
"chunk">tEXt</span></a> chunk.</p>
<h4><a name="11iTXt">11.3.4.5 <span class="chunk">iTXt</span>
International textual data</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
105 84 88 116
</pre>
<p>An <span class="chunk">iTXt</span> chunk contains:</p>
<table class="Regular" summary=
"This table defines the iTXt chunk">
<tr>
<td class="Regular">Keyword</td>
<td class="Regular">1-79 bytes (character string)</td>
</tr>
<tr>
<td class="Regular">Null separator</td>
<td class="Regular">1 byte (null character)</td>
</tr>
<tr>
<td class="Regular">Compression flag</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Compression method</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Language tag</td>
<td class="Regular">0 or more bytes (character string)</td>
</tr>
<tr>
<td class="Regular">Null separator</td>
<td class="Regular">1 byte (null character)</td>
</tr>
<tr>
<td class="Regular">Translated keyword</td>
<td class="Regular">0 or more bytes</td>
</tr>
<tr>
<td class="Regular">Null separator</td>
<td class="Regular">1 byte (null character)</td>
</tr>
<tr>
<td class="Regular">Text</td>
<td class="Regular">0 or more bytes</td>
</tr>
</table>
<p>The keyword is described in 11.3.4.2: <a href=
"#11keywords"><span class="xref">Keywords and text
strings</span></a>.</p>
<p>The compression flag is 0 for uncompressed text, 1 for
compressed text. Only the text field may be compressed. The
compression method entry defines the compression method used. The
only compression method defined in this International Standard is
0 (zlib datastream with deflate compression, see 10.3: <a href=
'#10CompressionOtherUses'><span class="xref">Other uses of
compression</span></a>). For uncompressed text, encoders shall
set the compression method to 0, and decoders shall ignore
it.</p>
<p>The language tag defined in <a href="#2-RFC-3066"><span class=
"NormRef">[RFC-3066]</span></a>
indicates the human language used by the translated keyword and
the text. Unlike the keyword, the language tag is
case-insensitive. It is an ISO 646.IRV:1991 <a href="#2-ISO-646"><span
class="NormRef">[ISO 646]</span></a> string consisting of
hyphen-separated words of 1-8 alphanumeric characters each (for example cn,
en-uk, no-bok, x-klingon, x-KlInGoN). If the first word is two or three
letters long, it is an ISO language code <a href=
"#2-ISO-639"><span class="NormRef">[ISO-639]</span></a>. If the
language tag is empty, the language is unspecified.</p>
<p>The translated keyword and text both use the UTF-8 encoding of
UCS <a href="#2-ISO-10646-1"><span class="NormRef">[ISO/IEC
10646-1]</span></a>, and neither shall contain a zero byte (null
character). The text, unlike other textual data in this chunk, is
not null-terminated; its length is derived from the chunk
length.</p>
<p>Line breaks should not appear in the translated keyword. In
the text, a newline should be represented by a single linefeed
character (decimal 10). The remaining control characters (1-9,
11-31, 127-159) are discouraged in both the translated keyword
and text. In UTF-8 there is a difference between the characters
128-159 (which are discouraged) and the bytes 128-159 (which are
often necessary).</p>
<p>The translated keyword, if not empty, should contain a
translation of the keyword into the language indicated by the
language tag, and applications displaying the keyword should
display the translated keyword in addition.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h3><a name="11addnlsiinfo">11.3.5 Miscellaneous
information</a></h3>
<h4><a name="11bKGD">11.3.5.1 <span class="chunk">bKGD</span>
Background colour</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
98 75 71 68
</pre>
<p>The <span class="chunk">bKGD</span> chunk specifies a default
background colour to present the image against. If there is any
other preferred background, either user-specified or part of a
larger page (as in a browser), the <span class=
"chunk">bKGD</span> chunk should be ignored. The <span class=
"chunk">bKGD</span> chunk contains:</p>
<table class="Regular" summary=
"This table defines the bKGD chunk">
<tr>
<th colspan="2">Colour types 0 and 4</th>
</tr>
<tr>
<td class="Regular">Greyscale</td>
<td class="Regular">2 bytes</td>
</tr>
<tr>
<th colspan="2">Colour types 2 and 6</th>
</tr>
<tr>
<td class="Regular">Red</td>
<td class="Regular">2 bytes</td>
</tr>
<tr>
<td class="Regular">Green</td>
<td class="Regular">2 bytes</td>
</tr>
<tr>
<td class="Regular">Blue</td>
<td class="Regular">2 bytes</td>
</tr>
<tr>
<th colspan="2">Colour type 3</th>
</tr>
<tr>
<td class="Regular">Palette index</td>
<td class="Regular">1 byte</td>
</tr>
</table>
<p>For colour type 3 (indexed-colour), the value is the palette
index of the colour to be used as background.</p>
<p>For colour types 0 and 4 (greyscale, greyscale with alpha),
the value is the grey level to be used as background in the range
0 to (2<sup>bitdepth</sup>)-1. For colour types 2 and 6
(truecolour, truecolour with alpha), the values are the colour to be
used as background, given as RGB
samples in the range 0 to (2<sup>bitdepth</sup>)-1. In each case,
for consistency, two bytes per sample are used regardless of the
image bit depth. If the image bit depth is less than 16, the
least significant bits are used and the others are 0.</p>
<h4><a name="11hIST">11.3.5.2 <span class="chunk">hIST</span>
Image histogram</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
104 73 83 84
</pre>
<p>The <span class="chunk">hIST</span> chunk contains a series of
two-byte (16-bit) unsigned integers:</p>
<table class="Regular" summary=
"This table defines the hIST chunk">
<tr>
<td class="Regular">Frequency</td>
<td class="Regular">2 bytes (unsigned integer)</td>
</tr>
<tr>
<td class="Regular">...etc...</td>
<td class="Regular"> </td>
</tr>
</table>
<p>The <span class="chunk">hIST</span> chunk gives the
approximate usage frequency of each colour in the palette. A
histogram chunk can appear only when a <a href="#11PLTE"><span
class="chunk">PLTE</span></a> chunk appears. If a viewer is
unable to provide all the colours listed in the palette, the
histogram may help it decide how to choose a subset of the
colours for display.</p>
<p>There shall be exactly one
entry for each entry in the <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> chunk. Each entry is proportional to the
fraction of pixels in the image that have that palette index; the
exact scale factor is chosen by the encoder.</p>
<p>Histogram entries are approximate, with the exception that a
zero entry specifies that the corresponding palette entry is not
used at all in the image. A histogram entry shall be nonzero if
there are any pixels of that colour.</p>
<p class="Note">NOTE When the palette is a suggested quantization
of a truecolour image, the histogram is necessarily approximate,
since a decoder may map pixels to palette entries differently
than the encoder did. In this situation, zero entries should not
normally appear, because any entry might be used.</p>
<h4><a name="11pHYs">11.3.5.3 <span class="chunk">pHYs</span>
Physical pixel dimensions</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
112 72 89 115
</pre>
<p>The <span class="chunk">pHYs</span> chunk specifies the
intended pixel size or aspect ratio for display of the image. It
contains:</p>
<table class="Regular" summary=
"This table defines the pHYs chunk">
<tr>
<td class="Regular">Pixels per unit, X axis</td>
<td class="Regular">4 bytes (PNG unsigned integer)</td>
</tr>
<tr>
<td class="Regular">Pixels per unit, Y axis</td>
<td class="Regular">4 bytes (PNG unsigned integer)</td>
</tr>
<tr>
<td class="Regular">Unit specifier</td>
<td class="Regular">1 byte</td>
</tr>
</table>
<p>The following values are defined for the unit specifier:</p>
<table class="Regular" summary=
"This table defines the allowed values for the unit specifier in the pHYs chunk">
<tr>
<td class="Regular">0</td>
<td class="Regular">unit is unknown</td>
</tr>
<tr>
<td class="Regular">1</td>
<td class="Regular">unit is the metre</td>
</tr>
</table>
<p>When the unit specifier is 0, the <span class=
"chunk">pHYs</span> chunk defines pixel aspect ratio only; the
actual size of the pixels remains unspecified.</p>
<p>If the <span class="chunk">pHYs</span> chunk is not present,
pixels are assumed to be square, and the physical size of each
pixel is unspecified.</p>
<h4><a name="11sPLT">11.3.5.4 <span class="chunk">sPLT</span>
Suggested palette</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
115 80 76 84
</pre>
<p>The <span class="chunk">sPLT</span> chunk contains:</p>
<table class="Regular" summary=
"This table defines the sPLT chunk">
<tr>
<td class="Regular">Palette name</td>
<td class="Regular">1-79 bytes (character string)</td>
</tr>
<tr>
<td class="Regular">Null separator</td>
<td class="Regular">1 byte (null character)</td>
</tr>
<tr>
<td class="Regular">Sample depth</td>
<td class="Regular">1 byte</td>
</tr>
<tr>
<td class="Regular">Red</td>
<td class="Regular">1 or 2 bytes</td>
</tr>
<tr>
<td class="Regular">Green</td>
<td class="Regular">1 or 2 bytes</td>
</tr>
<tr>
<td class="Regular">Blue</td>
<td class="Regular">1 or 2 bytes</td>
</tr>
<tr>
<td class="Regular">Alpha</td>
<td class="Regular">1 or 2 bytes</td>
</tr>
<tr>
<td class="Regular">Frequency</td>
<td class="Regular">2 bytes</td>
</tr>
<tr>
<td class="Regular">...etc...</td>
<td class="Regular"> </td>
</tr>
</table>
<p>Each palette entry is six bytes or ten bytes containing five
unsigned integers (red, blue, green, alpha, and frequency).</p>
<p>There may be any number of entries. A PNG decoder determines
the number of entries from the length of the chunk remaining
after the sample depth byte. This shall be divisible by 6 if the
<span class="chunk">sPLT</span> sample depth is 8, or by 10 if
the <span class="chunk">sPLT</span> sample depth is 16. Entries
shall appear in decreasing order of frequency. There is no
requirement that the entries all be used by the image, nor that
they all be different.</p>
<p>The palette name can be any convenient name for referring to
the palette (for example "256 colour including Macintosh
default", "256 colour including Windows-3.1 default", "Optimal
512"). The palette name may aid the choice of the appropriate
suggested palette when more than one appears in a PNG
datastream.</p>
<p>The palette name is case-sensitive, and subject to the same
restrictions as the keyword parameter for the <a href=
"#11tEXt"><span class="chunk">tEXt</span></a> chunk. Palette
names shall contain only printable Latin-1 characters and spaces
(only character codes 32-126 and 161-255 decimal are allowed).
Leading, trailing, and consecutive spaces are not permitted.</p>
<p>The <span class="chunk">sPLT</span> sample depth shall be 8 or
16.</p>
<p>The red, green, blue, and alpha samples are either one or two
bytes each, depending on the <span class="chunk">sPLT</span>
sample depth, regardless of the image bit depth. The colour
samples are not premultiplied by alpha, nor are they
precomposited against any background. An alpha value of 0 means
fully transparent. An alpha value of 255 (when the <span class=
"chunk">sPLT</span> sample depth is 8) or 65535 (when the <span
class="chunk">sPLT</span> sample depth is 16) means fully opaque.
The <span class="chunk">sPLT</span> chunk may appear for any PNG
colour type. Entries in <span class="chunk">sPLT</span> use the
same gamma and chromaticity values as the PNG image, but may fall
outside the range of values used in the colour space of the PNG
image; for example, in a greyscale PNG image, each <span class=
"chunk">sPLT</span> entry would typically have equal red, green,
and blue values, but this is not required. Similarly, <span
class="chunk">sPLT</span> entries can have non-opaque alpha
values even when the PNG image does not use transparency.</p>
<p>Each frequency value is proportional to the fraction of
the pixels in the image for which that palette entry
is the closest match in RGBA space, before the image has been composited against any
background. The exact scale factor is chosen by the PNG encoder;
it is recommended that the resulting range of individual values
reasonably fills the range 0 to 65535. A PNG encoder may
artificially inflate the frequencies for colours considered to be
"important", for example the colours used in a logo or the facial
features of a portrait. Zero is a valid frequency meaning that
the colour is "least important" or that it is rarely, if ever,
used. When all the frequencies are zero, they are meaningless,
that is to say, nothing may be inferred about the actual
frequencies with which the colours appear in the PNG image.</p>
<p>Multiple <span class="chunk">sPLT</span> chunks are permitted,
but each shall have a different palette name.</p>
<h3><a name="11timestampinfo">11.3.6 Time stamp
information</a></h3>
<h4><a name="11tIME">11.3.6.1 <span class="chunk">tIME</span>
Image last-modification time</a></h4>
<p>The four-byte chunk type field contains the decimal values</p>
<pre>
116 73 77 69
</pre>
<p>The <span class="chunk">tIME</span> chunk gives the time of
the last image modification (<strong>not</strong> the time of initial
image creation). It contains:</p>
<table class="Regular" summary=
"This table defines the tIME chunk">
<tr>
<td class="Regular">Year</td>
<td class="Regular">2 bytes (complete; for example, 1995, <strong>not</strong> 95)</td>
</tr>
<tr>
<td class="Regular">Month</td>
<td class="Regular">1 byte (1-12)</td>
</tr>
<tr>
<td class="Regular">Day</td>
<td class="Regular">1 byte (1-31)</td>
</tr>
<tr>
<td class="Regular">Hour</td>
<td class="Regular">1 byte (0-23)</td>
</tr>
<tr>
<td class="Regular">Minute</td>
<td class="Regular">1 byte (0-59)</td>
</tr>
<tr>
<td class="Regular">Second</td>
<td class="Regular">1 byte (0-60) (to allow for leap seconds)</td>
</tr>
</table>
<p>Universal Time (UTC) should be specified rather than local
time.</p>
<p>The <span class="chunk">tIME</span> chunk is intended for use
as an automatically-applied time stamp that is updated whenever
the image data are changed.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="12Encoders">12 PNG Encoders</a></h1>
<h2><a name="12Introduction">12.1 Introduction</a></h2>
<p>This clause gives requirements and recommendations for encoder
behaviour. A PNG encoder shall produce a PNG datastream from a
PNG image that conforms to the format specified in the preceding
clauses. Best results will usually be achieved by following the
additional recommendations given here.</p>
<h2><a name="12Encoder-gamma-handling">12.2 Encoder gamma
handling</a></h2>
<p>See Annex C: <a href="#C-GammaAppendix"><span class=
"xref">Gamma and chromaticity</span></a> for a brief introduction
to gamma issues.</p>
<p>PNG encoders capable of full colour management <a href=
"#G-ICC"><span class="bibref">[ICC]</span></a> will perform more
sophisticated calculations than those described here and may
choose to use the <a href="#11iCCP"><span class=
"chunk">iCCP</span></a> chunk. If it is known that the image
samples conform to the sRGB specification <a href=
"#2-IEC-61966-2-1"><span class="NormRef">[IEC
61966-2-1]</span></a>, encoders are strongly encouraged to write
the <a href="#11sRGB"><span class="chunk">sRGB</span></a> chunk
without performing additional gamma handling. In both cases it is
recommended that an appropriate <a href="#11gAMA"><span class=
"chunk">gAMA</span></a> chunk be generated for use by PNG
decoders that do not recognize the <a href="#11iCCP"><span class=
"chunk">iCCP</span></a> chunk or <a href="#11sRGB"><span class=
"chunk">sRGB</span></a> chunk.</p>
<p>A PNG encoder has to determine:</p>
<!-- <ol start="1"> --><ol>
<li>what value to write in the <a href="#11gAMA"><span class=
"chunk">gAMA</span></a> chunk;</li>
<li>how to transform the provided image samples into the values
to be written in the PNG datastream.</li>
</ol>
<p>The value to write in the <a href="#11gAMA"><span class=
"chunk">gAMA</span></a> chunk is that value which causes a PNG
decoder to behave in the desired way. See 13.13: <a class='Href'
href='#13Decoder-gamma-handling'>Decoder gamma handling</a>.</p>
<p>The transform to be applied depends on the nature of the image
samples and their precision. If the samples represent light
intensity in floating-point or high precision integer form
(perhaps from a computer graphics renderer), the encoder may
perform "gamma encoding" (applying a power function with exponent
less than 1) before quantizing the data to integer values for
inclusion in the PNG datastream. This results in fewer banding
artifacts at a given sample depth, or allows smaller samples
while retaining the same visual quality. An intensity level
expressed as a floating-point value in the range 0 to 1 can be
converted to a datastream image sample by:</p>
<p><tt>integer_sample =
floor((2<sup>sampledepth</sup>-1) * intensity<sup>encoding_exponent</sup>
+ 0.5)</tt></p>
<p>If the intensity in the equation is the desired output
intensity, the encoding exponent is the gamma value to be used in
the <a href="#11gAMA"><span class="chunk">gAMA</span></a>
chunk.</p>
<p>If the intensity available to the PNG encoder is the original
scene intensity, another transformation may be needed. There is
sometimes a requirement for the displayed image to have higher
contrast than the original source image. This corresponds to an
end-to-end transfer function from original scene to display
output with an exponent greater than 1. In this case:</p>
<pre>
gamma = encoding_exponent/end_to_end_exponent
</pre>
<p>If it is not known whether the conditions under which the
original image was captured or calculated warrant such a contrast
change, it may be assumed that the display intensities are
proportional to original scene intensities, i.e. the end-to-end
exponent is 1 and hence:</p>
<pre>
gamma = encoding_exponent
</pre>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<p>If the image is being written to a datastream only, the
encoder is free to choose the encoding exponent. Choosing a value
that causes the gamma value in the <a href="#11gAMA"><span class=
"chunk">gAMA</span></a> chunk to be 1/2.2 is often a reasonable
choice because it minimizes the work for a PNG decoder displaying
on a typical video monitor.</p>
<p>Some image renderers may simultaneously write the image to a
PNG datastream and display it on-screen. The displayed pixels
should be gamma corrected for the display system and viewing
conditions in use, so that the user sees a proper representation
of the intended scene.</p>
<p>If the renderer wants to write the displayed sample values to
the PNG datastream, avoiding a separate gamma encoding step for
the datastream, the renderer should approximate the transfer
function of the display system by a power function, and write the
reciprocal of the exponent into the <a href="#11gAMA"><span
class="chunk">gAMA</span></a> chunk. This will allow a PNG
decoder to reproduce what was displayed on screen for the
originator during rendering.</p>
<p>However, it is equally reasonable for a renderer to compute
displayed pixels appropriate for the display device, and to
perform separate gamma encoding for data storage and
transmission, arranging to have a value in the <a href=
"#11gAMA"><span class="chunk">gAMA</span></a> chunk more
appropriate to the future use of the image.</p>
<p>Computer graphics renderers often do not perform gamma
encoding, instead making sample values directly proportional to
scene light intensity. If the PNG encoder receives sample values
that have already been quantized into integer values, there is no
point in doing gamma encoding on them; that would just result in
further loss of information. The encoder should just write the
sample values to the PNG datastream. This does not imply that the
<a href="#11gAMA"><span class="chunk">gAMA</span></a> chunk
should contain a gamma value of 1.0 because the desired
end-to-end transfer function from scene intensity to display
output intensity is not necessarily linear. However, the desired
gamma value is probably not far from 1.0. It may depend on
whether the scene being rendered is a daylight scene or an indoor
scene, etc.</p>
<p>When the sample values come directly from a piece of hardware,
the correct <a href="#11gAMA"><span class="chunk">gAMA</span></a>
value can, in principle, be inferred from the transfer function
of the hardware and lighting conditions of the scene. In the case
of video digitizers ("frame grabbers"), the samples are probably
in the sRGB colour space, because the sRGB specification was
designed to be compatible with modern video standards. Image
scanners are less predictable. Their output samples may be
proportional to the input light intensity since CCD sensors
themselves are linear, or the scanner hardware may have already
applied a power function designed to compensate for dot gain in
subsequent printing (an exponent of about 0.57), or the scanner
may have corrected the samples for display on a monitor. It may
be necessary to refer to the scanner's manual or to scan a
calibrated target in order to determine the characteristics of a
particular scanner. It should be remembered that gamma relates
samples to desired display output, not to scanner input.</p>
<p>Datastream format converters generally should not attempt to
convert supplied images to a different gamma. The data should be
stored in the PNG datastream without conversion, and the gamma
value should be deduced from information in the source datastream
if possible. Gamma alteration at datastream conversion time
causes re-quantization of the set of intensity levels that are
represented, introducing further roundoff error with little
benefit. It is almost always better to just copy the sample
values intact from the input to the output file.</p>
<p>If the source datastream describes the gamma characteristics
of the image, a datastream converter is strongly encouraged to
write a <a href="#11gAMA"><span class="chunk">gAMA</span></a>
chunk. Some datastream formats specify the display exponent (the
exponent of the function which maps image samples to display
output rather than the other direction). If the source file's
gamma value is greater than 1.0, it is probably a display
exponent, and the reciprocal of this value should be used for the
PNG gamma value. If the source file format records the
relationship between image samples and a quantity other than
display output, it will be more complex than this to deduce the
PNG gamma value.</p>
<p>If a PNG encoder or datastream converter knows that the image
has been displayed satisfactorily using a display system whose
transfer function can be approximated by a power function with
exponent <tt>display_exponent</tt>, the image can be marked as
having the gamma value:</p>
<pre>
gamma = 1/display_exponent
</pre>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<p>It is better to write a <a href="#11gAMA"><span class=
"chunk">gAMA</span></a> chunk with a value that is approximately
correct than to omit the chunk and force PNG decoders to guess an
approximate gamma. If a PNG encoder is unable to infer the gamma
value, it is preferable to omit the <a href="#11gAMA"><span
class="chunk">gAMA</span></a> chunk. If a guess has to be made
this should be left to the PNG decoder.</p>
<p>Gamma does not apply to alpha samples; alpha is always
represented linearly.</p>
<p>See also 13.13: <a href="#13Decoder-gamma-handling"><span
class="xref">Decoder gamma handling</span></a>.</p>
<h2><a name="12Encoder-colour-handling">12.3 Encoder colour
handling</a></h2>
<p>See Annex C: <a href="#C-GammaAppendix"><span class=
"xref">Gamma and chromaticity</span></a> for references to colour
issues.</p>
<p>PNG encoders capable of full colour management <a href=
"#G-ICC"><span class="bibref">[ICC]</span></a> will perform more
sophisticated calculations than those described here and may
choose to use the <a href="#11iCCP"><span class=
"chunk">iCCP</span></a> chunk. If it is known that the image
samples conform to the sRGB specification <a href=
"#2-IEC-61966-2-1"><span class="NormRef">[IEC
61966-2-1]</span></a>, PNG encoders are strongly encouraged to
use the <a href="#11sRGB"><span class="chunk">sRGB</span></a>
chunk.</p>
<p>If it is possible for the encoder to determine the
chromaticities of the source display primaries, or to make a
strong guess based on the origin of the image, or the hardware
running it, the encoder is strongly encouraged to output the <a
href="#11cHRM"><span class="chunk">cHRM</span></a> chunk. If this
is done, the <a href="#11gAMA"><span class=
"chunk">gAMA</span></a> chunk should also be written; decoders
can do little with a <a href="#11cHRM"><span class=
"chunk">cHRM</span></a> chunk if the <a href="#11gAMA"><span
class="chunk">gAMA</span></a> chunk is missing.</p>
<p>There are a number of recommendations and standards for
primaries and white points, some of which are linked to
particular technologies, for example the CCIR 709 standard <a
href="#G-ITU-R-BT709"><span class=
"bibref">[ITU-R-BT709]</span></a> and the SMPTE-C standard <a
href="#G-SMPTE-170M"><span class=
"bibref">[SMPTE-170M]</span></a>.</p>
<p>There are three cases that need to be considered:</p>
<ol>
<li>the encoder is part of the generation system;</li>
<li>the source image is captured by a camera or scanner;</li>
<li>the PNG datastream was generated by translation from some
other format.</li>
</ol>
<!-- deleted - comment PDG 31<p>Scanners that produce PNG datastreams as output should insert
the filter chromaticities into a <a href="#11cHRM"><span class=
"chunk">cHRM</span></a> chunk.</p>-->
<p>In the case of hand-drawn or digitally edited images, it is
necessary to determine what monitor they were viewed on when
being produced. Many image editing programs allow the type of
monitor being used to be specified. This is often because they
are working in some device-independent space internally. Such
programs have enough information to write valid <a href=
"#11cHRM"><span class="chunk">cHRM</span></a> and <a href=
"#11gAMA"><span class="chunk">gAMA</span></a> chunks, and are
strongly encouraged to do so automatically.</p>
<p>If the encoder is compiled as a portion of a computer image
renderer that performs full-spectral rendering, the monitor
values that were used to convert from the internal
device-independent colour space to RGB should be written into the
<a href="#11cHRM"><span class="chunk">cHRM</span></a> chunk. Any
colours that are outside the gamut of the chosen RGB device
should be mapped to be within the gamut; PNG does not store
out-of-gamut colours.</p>
<p>If the computer image renderer performs calculations directly
in device-dependent RGB space, a <a href="#11cHRM"><span class=
"chunk">cHRM</span></a> chunk should not be written unless the
scene description and rendering parameters have been adjusted for
a particular monitor. In that case, the data for that monitor
should be used to construct a <a href="#11cHRM"><span class=
"chunk">cHRM</span></a> chunk.</p>
<p>A few image formats store calibration information, which can
be used to fill in the <a href="#11cHRM"><span class=
"chunk">cHRM</span></a> chunk. For example, TIFF 6.0 files <a
href="#G-TIFF-6.0"><span class="bibref">[TIFF-6.0]</span></a> can
optionally store calibration information, which if present should
be used to construct the <a href="#11cHRM"><span class=
"chunk">cHRM</span></a> chunk.</p>
<p>Video created with recent video equipment probably uses the
CCIR 709 primaries and D65 white point <a href=
"#G-ITU-R-BT709"><span class="bibref">[ITU-R-BT709]</span></a>,
which are given in <a href="#12-table121"><span class=
"tabref">Table 12.1</span></a>.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<table class="Regular" summary=
"CCIR 709 primaries and D65 whitepoint">
<caption><a name="12-table121"><b>Table 12.1 — CCIR 709
primaries and D65 whitepoint</b></a></caption>
<tr>
<th> </th>
<th>R</th>
<th>G</th>
<th>B</th>
<th>White</th>
</tr>
<tr>
<td class="Regular">x</td>
<td class="Regular">0.640</td>
<td class="Regular">0.300</td>
<td class="Regular">0.150</td>
<td class="Regular">0.3127</td>
</tr>
<tr>
<td class="Regular">y</td>
<td class="Regular">0.330</td>
<td class="Regular">0.600</td>
<td class="Regular">0.060</td>
<td class="Regular">0.3290</td>
</tr>
</table>
<p>An older but still very popular video standard is SMPTE-C <a
href="#G-SMPTE-170M"><span class="bibref">[SMPTE-170M]</span></a>
given in <a href="#12-table122"><span class="tabref">Table
12.2</span></a>.</p>
<table class="Regular" summary=
"CSMPTE-C video standard">
<caption><a name="12-table122"><b>Table 12.2 — SMPTE-C
video standard</b></a></caption>
<tr>
<th> </th>
<th>R</th>
<th>G</th>
<th>B</th>
<th>White</th>
</tr>
<tr>
<td class="Regular">x</td>
<td class="Regular">0.630</td>
<td class="Regular">0.310</td>
<td class="Regular">0.155</td>
<td class="Regular">0.3127</td>
</tr>
<tr>
<td class="Regular">y</td>
<td class="Regular">0.340</td>
<td class="Regular">0.595</td>
<td class="Regular">0.070</td>
<td class="Regular">0.3290</td>
</tr>
</table>
<p>It is <strong>not</strong> recommended that datastream format
converters attempt to convert supplied images to a different RGB
colour space. The data should be stored in the PNG datastream
without conversion, and the source primary chromaticities should
be recorded if they are known. Colour space transformation at
datastream conversion time is a bad idea because of gamut
mismatches and rounding errors. As with gamma conversions, it is
better to store the data losslessly and incur at most one
conversion when the image is finally displayed.</p>
<p>See also 13.14: <a href="#13Decoder-colour-handling"><span
class="xref">Decoder colour handling</span></a>.</p>
<h2><a name="12Alpha-channel-creation">12.4 Alpha channel
creation</a></h2>
<p>The alpha channel can be regarded either as a mask that
temporarily hides transparent parts of the image, or as a means
for constructing a non-rectangular image. In the first case, the
colour values of fully transparent pixels should be preserved for
future use. In the second case, the transparent pixels carry no
useful data and are simply there to fill out the rectangular
image area required by PNG. In this case, fully transparent
pixels should all be assigned the same colour value for best
compression.</p>
<p>Image authors should keep in mind the possibility that a
decoder will not support transparency control in full (see 13.16:
<a href="#13Alpha-channel-processing"><span class="xref">Alpha
channel processing</span></a>). Hence, the colours assigned to
transparent pixels should be reasonable background colours
whenever feasible.</p>
<p>For applications that do not require a full alpha channel, or
cannot afford the price in compression efficiency, the <a href=
"#11tRNS"><span class="chunk">tRNS</span></a> transparency chunk
is also available.</p>
<p>If the image has a known background colour, this colour should
be written in the <a href="#11bKGD"><span class=
"chunk">bKGD</span></a> chunk. Even decoders that ignore
transparency may use the <a href="#11bKGD"><span class=
"chunk">bKGD</span></a> colour to fill unused screen area.</p>
<p>If the original image has premultiplied (also called
"associated") alpha data, it can be converted to PNG's
non-premultiplied format by dividing each sample value by the
corresponding alpha value, then multiplying by the maximum value
for the image bit depth, and rounding to the nearest integer. In
valid premultiplied data, the sample values never exceed their
corresponding alpha values, so the result of the division should
always be in the range 0 to 1. If the alpha value is zero, output
black (zeroes).</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h2><a name="12Sample-depth-scaling">12.5 Sample depth
scaling</a></h2>
<p>When encoding input samples that have a sample depth that
cannot be directly represented in PNG, the encoder shall scale
the samples up to a sample depth that is allowed by PNG. The most
accurate scaling method is the linear equation:</p>
<pre>
output = floor((input * MAXOUTSAMPLE / MAXINSAMPLE) + 0.5)
</pre>
<p>where the input samples range from 0 to <tt>MAXINSAMPLE</tt>
and the outputs range from 0 to <tt>MAXOUTSAMPLE</tt> (which is
2<sup>sampledepth</sup>-1).</p>
<p>A close approximation to the linear scaling method is achieved
by "left bit replication", which is shifting the valid bits to
begin in the most significant bit and repeating the most
significant bits into the open bits. This method is often faster
to compute than linear scaling.</p>
<p>EXAMPLE Assume that 5-bit samples are being scaled up to 8
bits. If the source sample value is 27 (in the range from 0-31),
then the original bits are:</p>
<pre>
4 3 2 1 0
---------
1 1 0 1 1
</pre>
<p>Left bit replication gives a value of 222:</p>
<pre>
7 6 5 4 3 2 1 0
----------------
1 1 0 1 1 1 1 0
|=======| |===|
| Leftmost Bits Repeated to Fill Open Bits
|
Original Bits
</pre>
<p>which matches the value computed by the linear equation. Left
bit replication usually gives the same value as linear scaling,
and is never off by more than one.</p>
<p>A distinctly less accurate approximation is obtained by simply
left-shifting the input value and filling the low order bits with
zeroes. This scheme cannot reproduce white exactly, since it does
not generate an all-ones maximum value; the net effect is to
darken the image slightly. This method is not recommended in
general, but it does have the effect of improving compression,
particularly when dealing with greater-than-8-bit sample depths.
Since the relative error introduced by zero-fill scaling is small
at high sample depths, some encoders may choose to use it.
Zero-fill shall <strong>not</strong> be used for alpha channel
data, however, since many decoders will treat alpha values of all
zeroes and all ones as special cases. It is important to
represent both those values exactly in the scaled data.</p>
<p>When the encoder writes an <a href="#11sBIT"><span class=
"chunk">sBIT</span></a> chunk, it is required to do the scaling
in such a way that the high-order bits of the stored samples
match the original data. That is, if the <a href="#11sBIT"><span
class="chunk">sBIT</span></a> chunk specifies a sample depth of
S, the high-order S bits of the stored data shall agree with the
original S-bit data values. This allows decoders to recover the
original data by shifting right. The added low-order bits are not
constrained. All the above scaling methods meet this
restriction.</p>
<p>When scaling up source image data, it is recommended that the
low-order bits be filled consistently for all samples; that is,
the same source value should generate the same sample value at
any pixel position. This improves compression by reducing the
number of distinct sample values. This is not a mandatory
requirement, and some encoders may choose not to follow it. For
example, an encoder might instead dither the low-order bits,
improving displayed image quality at the price of increasing file
size.</p>
<p>In some applications the original source data may have a range
that is not a power of 2. The linear scaling equation still works
for this case, although the shifting methods do not. It is
recommended that an <a href="#11sBIT"><span class=
"chunk">sBIT</span></a> chunk not be written for such images,
since <a href="#11sBIT"><span class="chunk">sBIT</span></a>
suggests that the original data range was exactly
0..2<sup>S</sup>-1.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h2><a name="12Suggested-palettes">12.6 Suggested
palettes</a></h2>
<p>Suggested palettes may appear as <a href="#11sPLT"><span
class="chunk">sPLT</span></a> chunks in any PNG datastream, or as
a <a href="#11PLTE"><span class="chunk">PLTE</span></a> chunk in
truecolour PNG datastreams. In either case, the suggested palette
is not an essential part of the image data, but it may be used to
present the image on indexed-colour display hardware. Suggested
palettes are of no interest to viewers running on truecolour
hardware.</p>
<p>When an <a href="#11sPLT"><span class="chunk">sPLT</span></a>
chunk is used to provide a suggested palette, it is recommended
that the encoder use the frequency fields to indicate the
relative importance of the palette entries, rather than leave
them all zero (meaning undefined). The frequency values are most
easily computed as "nearest neighbour" counts, that is, the
approximate usage of each RGBA palette entry if no dithering is
applied. (These counts will often be available "for free" as a
consequence of developing the suggested palette.) Because the
suggested palette includes transparency information, it should be
computed for the uncomposited image.</p>
<p>Even for indexed-colour images, <a href="#11sPLT"><span class=
"chunk">sPLT</span></a> can be used to define alternative reduced
palettes for viewers that are unable to display all the colours
present in the <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> chunk.
If the <a href="#11PLTE"><span class="chunk">PLTE</span></a>
chunk appears without the <a href="#11bKGD"><span class=
"chunk">bKGD</span></a> chunk in an image of colour type 6, the
circumstances under which the palette was computed are
unspecified.</p>
<p>An older method for including a suggested palette in a
truecolour PNG datastream uses the <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> chunk. If this method is used, the
histogram (frequencies) should appear in a separate <a href=
"#11hIST"><span class="chunk">hIST</span></a> chunk. The <a href=
"#11PLTE"><span class="chunk">PLTE</span></a> chunk does not
include transparency information. Hence for images of colour type
6 (truecolour with alpha), it is recommended that a <a href=
"#11bKGD"><span class="chunk">bKGD</span></a> chunk appear and
that the palette and histogram be computed with reference to the
image as it would appear after compositing against the specified
background colour. This definition is necessary to ensure that
useful palette entries are generated for pixels having fractional
alpha values. The resulting palette will probably be useful only
to viewers that present the image against the same background
colour. It is recommended that PNG editors delete or recompute
the palette if they alter or remove the <a href="#11bKGD"><span
class="chunk">bKGD</span></a> chunk in an image of colour type
6.</p>
<p>For images of colour type 2 (truecolour), it is recommended
that the <a href="#11PLTE"><span class="chunk">PLTE</span></a>
and <a href="#11hIST"><span class="chunk">hIST</span></a> chunks
be computed with reference to the RGB data only, ignoring any
transparent-colour specification. If the datastream uses
transparency (has a <a href="#11tRNS"><span class=
"chunk">tRNS</span></a> chunk), viewers can easily adapt the
resulting palette for use with their intended background colour
(see 13.17: <a href=
"#13Histogram-and-suggested-palette-usage"><span class="xref">
Histogram and suggested palette usage</span></a>).
</p>
<p>For providing suggested palettes,
the <a href="#11sPLT"><span class="chunk">sPLT</span></a>
chunk is more flexible than the <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> chunk in
the following ways:</p>
<!-- <ol start="1"> --><ol>
<li>With <a href="#11sPLT"><span class="chunk">sPLT</span></a>
multiple suggested palettes may be provided. A PNG decoder may
choose an appropriate palette based on name or number of
entries.</li>
<li>In a PNG datastream of colour type 6 (truecolour with alpha
channel), the <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> chunk represents a palette already
composited against the <a href="#11bKGD"><span class=
"chunk">bKGD</span></a> colour, so it is useful only for display
against that background colour. The <a href="#11sPLT"><span
class="chunk">sPLT</span></a> chunk provides an uncomposited
palette, which is useful for display against backgrounds chosen
by the PNG decoder.</li>
<li>Since the <a href="#11sPLT"><span class=
"chunk">sPLT</span></a> chunk is an ancillary chunk, a PNG editor
may add or modify suggested palettes without being forced to
discard unknown unsafe-to-copy chunks.</li>
<li>Whereas the <a href="#11sPLT"><span class=
"chunk">sPLT</span></a> chunk is allowed in PNG datastreams for
colour types 0, 3, and 4 (greyscale and indexed), the <a href=
"#11PLTE"><span class="chunk">PLTE</span></a> chunk cannot be
used to provide reduced palettes in these cases.</li>
<li>More than 256 entries may appear in the <a href=
"#11sPLT"><span class="chunk">sPLT</span></a> chunk.</li>
</ol>
<p>A PNG encoder that uses the <a href="#11sPLT"><span class=
"chunk">sPLT</span></a> chunk may choose to write a suggested
palette represented by <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> and <a href="#11hIST"><span class=
"chunk">hIST</span></a> chunks as well, for compatibility with
decoders that do not recognize the <a href="#11sPLT"><span class=
"chunk">sPLT</span></a> chunk.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h2><a name="12Interlacing">12.7 Interlacing</a></h2>
<p>This International Standard defines two interlace methods,
one of which is no interlacing. Interlacing provides a convenient
basis from which decoders can progressively display an image, as
described in 13.8: <a href="#13Progressive-display"><span class=
"xref">Interlacing and progressive display</span></a>.</p>
<h2><a name="12Filter-selection">12.8 Filter selection</a></h2>
<p>For images of colour type 3 (indexed-colour), filter type 0
(None) is usually the most effective. Colour images with 256 or
fewer colours should almost always be stored in indexed-colour
format; truecolour format is likely to be much larger.</p>
<p>Filter type 0 is also recommended for images of bit depths
less than 8. For low-bit-depth greyscale images, in rare cases,
better compression may be obtained by first expanding the image
to 8-bit representation and then applying filtering.</p>
<p>For truecolour and greyscale images, any of the five filters
may prove the most effective. If an encoder uses a fixed filter,
the Paeth filter is most likely to be the best.</p>
<p>For best compression of truecolour and greyscale images,
the recommended approach is
adaptive filtering in which a filter is
chosen for each scanline. The following simple heuristic has
performed well in early tests: compute the output scanline using
all five filters, and select the filter that gives the smallest
sum of absolute values of outputs. (Consider the output bytes as
signed differences for this test.) This method usually
outperforms any single fixed filter choice. However, it is likely
that better heuristics will be found as more experience is
gained with PNG.</p>
<p>Filtering according to these recommendations is effective in
conjunction with either of the two interlace methods defined in
this International Standard.</p>
<h2><a name="12Compression">12.9 Compression</a></h2>
<p>The encoder may divide the compressed datastream into <a href=
"#11IDAT"><span class="chunk">IDAT</span></a> chunks however it
wishes. (Multiple <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> chunks are allowed so that encoders may
work in a fixed amount of memory; typically the chunk size will
correspond to the encoder's buffer size.) A PNG datastream in
which each <a href="#11IDAT"><span class="chunk">IDAT</span></a>
chunk contains only one data byte is valid, though remarkably
wasteful of space. (Zero-length <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> chunks are also valid, though even more
wasteful.)</p>
<h2><a name="12Text-chunk-processing">12.10 Text chunk
processing</a></h2>
<p>A nonempty keyword shall be provided for each text chunk. The
generic keyword "Comment" can be used if no better description of
the text is available. If a user-supplied keyword is used,
encoders should check that it meets the restrictions on
keywords.</p>
<p>For the <a href="#11tEXt"><span class="chunk">tEXt</span></a>
and <a href="#11zTXt"><span class="chunk">zTXt</span></a> chunks,
PNG text strings are expected to use the Latin-1 character set.
Encoders should avoid storing characters that are not defined in
Latin-1, and should provide character code remapping if the local
system's character set is not Latin-1. The <a href=
"#11iTXt"><span class="chunk">iTXt</span></a> chunk provides
support for international text, represented using the UTF-8
encoding of UCS. Encoders should discourage the creation of
single lines of text longer than 79 characters, in order to
facilitate easy reading. It is recommended that text items less
than 1024 bytes in size should be output using uncompressed
text chunks. It is
recommended that the basic title and author keywords be output
using uncompressed text chunks.
Placing large text chunks after the
image data (after the <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> chunks) can speed up image display in
some situations, as the decoder will decode the image data first.
It is recommended that small text chunks, such as the image
title, appear before the <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> chunks.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h2><a name="12Chunk-processing">12.11 Chunking</a></h2>
<h3><a name="12Use-of-private-chunks">12.11.1 Use of private
chunks</a></h3>
<p>
Chunk types are classified as public or private depending on bit 5
of the second byte (the private bit), and classified as critical or
ancillary depending on bit 5 of the first byte (the ancillary bit).
See 5.4: <a href=
"#5Chunk-naming-conventions"><span class="xref">Chunk naming
conventions</span></a>.
</p>
<p>Applications can use PNG private chunks to carry information
that need not be understood by other applications. Such chunks
shall be given private chunk types,
to ensure that they can never conflict
with any future public chunk definition. However, there is no
guarantee that some other application will not use the same
private chunk type. If a private chunk type is used, it is
prudent to store additional identifying information at the
beginning of the chunk data.</p>
<p>An ancillary chunk type, not a critical chunk type, should be
used for all private chunks that store information that is not
absolutely essential to view the image. Creation of private
critical chunks is discouraged because PNG datastreams containing
such chunks are not portable. Such chunks should not be used in
publicly available software or datastreams. If private critical
chunks are essential for an application, it is recommended that
one appear near the start of the datastream, so that a standard
decoder need not read very far before discovering that it cannot
handle the datastream.</p>
<p>If other organizations need to understand a new chunk type, it
should be submitted to the Registration Authority (see 4.9: <a
href="#4Concepts.Registration"><span class="xref">Extension and
registration</span></a>). A proposed public chunk type
shall not be used in publicly available software or
datastreams until registration has been approved.</p>
<p>If an ancillary chunk contains textual information that might
be of interest to a human user, a special chunk type should not
be defined for it. Instead a <a href="#11tEXt"><span class=
"chunk">tEXt</span></a> chunk should be used and a suitable
keyword defined. The information will then be available to other
users.</p>
<p>Keywords in <a href="#11tEXt"><span class=
"chunk">tEXt</span></a> chunks should be reasonably
self-explanatory, since the aim is to let other users understand
what the chunk contains. If generally useful, new keywords should
be registered with the Registration Authority (see 4.9: <a href=
"#4Concepts.Registration"><span class="xref">Extension and
registration</span></a>). However, it is permissible to use
keywords without registering them first.</p>
<h3><a name="12Private-type-and-method-codes">12.11.2 Private
type and method codes</a></h3>
<p>This specification defines the meaning of only some of the
possible values of some fields. For example, only compression
method 0 and filter types 0 through 4 are defined in this
International Standard. Numbers greater than 127 shall be used
when inventing experimental or private definitions of values for
any of these fields. Numbers below 128 are reserved for possible
public extensions of this specification through future
standardization (see 4.9 <a href="#4Concepts.Registration"><span
class="xref">Extension and registration</span></a>). The use of
private type codes may render a datastream unreadable by standard
decoders. Such codes are strongly discouraged except for
experimental purposes, and should not appear in publicly
available software or datastreams.</p>
<h3><a name="12Ancillary">12.11.3 Ancillary chunks</a></h3>
<p>All ancillary chunks are optional, encoders need not write
them. However, encoders are encouraged to write the standard
ancillary chunks when the information is available.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="13Decoders">13 PNG decoders and viewers</a></h1>
<h2><a name="13Introduction">13.1 Introduction</a></h2>
<p>This clause gives some requirements and recommendations for PNG
decoder behaviour and viewer behaviour. A viewer presents the
decoded PNG image to the user. Since viewer and decoder behaviour
are closely connected, decoders and viewers are treated together
here. The only absolute requirement on a PNG decoder is that it
successfully reads any datastream conforming to the format
specified in the preceding chapters. However, best results will
usually be achieved by following these additional
recommendations.</p>
<p>PNG decoders shall support all valid combinations of bit
depth, colour type, compression method, filter method, and
interlace method that are explicitly defined in this
International Standard.</p>
<p>All ancillary chunks are optional; decoders may ignore them.
However, decoders are encouraged to interpret these chunks when
appropriate and feasible.</p>
<h2><a name="13Decoders.Errors">13.2 Error handling</a></h2>
<p>Errors in a PNG datastream will fall into two general classes,
transmission errors and syntax errors (see <a href=
"#4Concepts.Errors"><span class="xref">4.8 Error
handling</span></a>).</p>
<p>Examples of transmission errors are transmission in "text" or
"ascii" mode, in which byte codes 13 and/or 10 may be added,
removed, or converted throughout the datastream; unexpected
termination, in which the datastream is truncated; or a physical
error on a storage device, in which one or more blocks (typically
512 bytes each) will have garbled or random values. Some examples
of syntax errors are an invalid value for a row filter, an
invalid compression method, an invalid chunk length, the absence
of a <a href="#11PLTE"><span class="chunk">PLTE</span></a> chunk
before the first <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> chunk in an indexed image, or the
presence of multiple <a href="#11gAMA"><span class=
"chunk">gAMA</span></a> chunks. A PNG decoder should handle
errors as follows:</p>
<!-- <ol start="1"> --><ol>
<li>Detect errors as early as possible using the PNG signature
bytes and CRCs on each chunk. Decoders should verify that all
eight bytes of the PNG signature are correct. A decoder can
have additional confidence in the datastream's integrity if the
next eight bytes begin an <a href="#11IHDR"><span class=
"chunk">IHDR</span></a> chunk with the correct chunk length. A
CRC should be checked before processing the chunk data. Sometimes
this is impractical, for example when a streaming PNG decoder is
processing a large <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> chunk. In this case the CRC should be
checked when the end of the chunk is reached.</li>
<li>Recover from an error, if possible; otherwise fail
gracefully. Errors that have little or no effect on the
processing of the image may be ignored, while those that affect
critical data shall be dealt with in a manner appropriate to the
application.</li>
<li>Provide helpful messages describing errors, including
recoverable errors.</li>
</ol>
<p>Three classes of PNG chunks are relevant to this philosophy.
For the purposes of this classification, an "unknown chunk" is
either one whose type was genuinely unknown to the decoder's
author, or one that the author chose to treat as unknown, because
default handling of that chunk type would be sufficient for the
program's purposes. Other chunks are called "known chunks". Given
this definition, the three classes are as follows:</p>
<!-- <ol start="4"> --><ol>
<li>known chunks, which necessarily includes all of the critical
chunks defined in this International Standard (<a href=
"#11IHDR"><span class="chunk">IHDR</span></a>, <a href=
"#11PLTE"><span class="chunk">PLTE</span></a>, <a href=
"#11IDAT"><span class="chunk">IDAT</span></a>, <a href=
"#11IEND"><span class="chunk">IEND</span></a>)</li>
<li>unknown critical chunks (bit 5 of the first byte of the chunk
type is 0)</li>
<li>unknown ancillary chunks (bit 5 of the first byte of the
chunk type is 1)</li>
</ol>
<p>See 5.4: <a href="#5Chunk-naming-conventions"><span class=
"xref">Chunk naming conventions</span></a> for a full description
of chunk naming conventions.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<p>PNG chunk types are marked "critical" or "ancillary" according
to whether the chunks are critical for the purpose of extracting
a viewable image (as with <a href="#11IHDR"><span class=
"chunk">IHDR</span></a>, <a href="#11PLTE"><span class=
"chunk">PLTE</span></a>, and <a href="#11IDAT"><span class=
"chunk">IDAT</span></a>) or critical to understanding the
datastream structure (as with <a href="#11IEND"><span class=
"chunk">IEND</span></a>). This is a specific kind of criticality
and one that is not necessarily relevant to every conceivable
decoder. For example, a program whose sole purpose is to extract
text annotations (for example, copyright information) does not
require a viewable image. Another decoder might consider the <a
href="#11tRNS"><span class="chunk">tRNS</span></a> and <a href=
"#11gAMA"><span class="chunk">gAMA</span></a> chunks essential to
its proper execution.</p>
<p>Syntax errors always involve known chunks because syntax
errors in unknown chunks cannot be detected. The PNG decoder has
to determine whether a syntax error is fatal (unrecoverable) or
not, depending on its requirements and the situation. For
example, most decoders can ignore an invalid <a href=
"#11IEND"><span class="chunk">IEND</span></a> chunk; a
text-extraction program can ignore the absence of <a href=
"#11IDAT"><span class="chunk">IDAT</span></a>; an image viewer
cannot recover from an empty <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> chunk in an indexed image but it can
ignore an invalid <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> chunk in a truecolour image; and a
program that extracts the alpha channel can ignore an invalid <a
href="#11gAMA"><span class="chunk">gAMA</span></a> chunk, but may
consider the presence of two <a href="#11tRNS"><span class=
"chunk">tRNS</span></a> chunks to be a fatal error. Anomalous
situations other than syntax errors shall be treated as
follows:</p>
<!-- <ol start="7"> --><ol>
<li>Encountering an unknown ancillary chunk is never an error.
The chunk can simply be ignored.</li>
<li>Encountering an unknown critical chunk is a fatal condition
for any decoder trying to extract the image from the datastream.
A decoder that ignored a critical chunk could not know whether
the image it extracted was the one intended by the encoder.</li>
<li>A PNG signature mismatch, a CRC mismatch, or an unexpected
end-of-stream indicates a corrupted datastream, and may be
regarded as a fatal error. A decoder could try to salvage
something from the datastream, but the extent of the damage will
not be known.</li>
</ol>
<p>When a fatal condition occurs, the decoder should fail
immediately, signal an error to the user if appropriate, and
optionally continue displaying any image data already visible to
the user (i.e. "fail gracefully"). The application as a whole
need not terminate.</p>
<p>When a non-fatal error occurs, the decoder should signal a
warning to the user if appropriate, recover from the error, and
continue processing normally.</p>
<p>Decoders that do not compute CRCs should interpret apparent
syntax errors as indications of corruption (see also 13.3: <a
href="#13Error-checking"><span class="xref">Error
checking</span></a>).</p>
<p>Errors in compressed chunks (<a href="#11IDAT"><span class=
"chunk">IDAT</span></a>, <a href="#11zTXt"><span class=
"chunk">zTXt</span></a>, <a href="#11iTXt"><span class=
"chunk">iTXt</span></a>, <a href="#11iCCP"><span class=
"chunk">iCCP</span></a>) could lead to buffer overruns.
Implementors of deflate decompressors should guard against this
possibility.</p>
<h2><a name="13Error-checking">13.3 Error checking</a></h2>
<p>The PNG error handling philosophy is described in 13.2: <a
href="#13Decoders.Errors"><span class="xref">Error
handling</span></a>.</p>
<p>Unknown chunk types shall be handled as described in 5.4: <a
href="#5Chunk-naming-conventions"><span class="xref">Chunk naming
conventions</span></a>. An unknown chunk type is <strong>not</strong> to
be treated as an error unless it is a critical chunk.</p>
<p>The chunk type can be checked for plausibility by seeing
whether all four bytes are in the range codes 65-90 and 97-122
(decimal); note that this need be done only for unrecognized
chunk types. If the total datastream size is known (from file
system information, HTTP protocol, etc), the chunk length can be
checked for plausibility as well. If CRCs are not checked,
dropped/added data bytes or an erroneous chunk length can cause
the decoder to get out of step and misinterpret subsequent data
as a chunk header.</p>
<p>For known-length chunks, such as <a href="#11IHDR"><span
class="chunk">IHDR</span></a>, decoders should treat an
unexpected chunk length as an error. Future extensions to this
specification will not add new fields to existing chunks;
instead, new chunk types will be added to carry new
information.</p>
<p>Unexpected values in fields of known chunks (for example, an
unexpected compression method in the <a href="#11IHDR"><span
class="chunk">IHDR</span></a> chunk) shall be checked for and
treated as errors. However, it is recommended that unexpected
field values be treated as fatal errors only in <strong>critical</strong>
chunks. An unexpected value in an ancillary chunk can be handled
by ignoring the whole chunk as though it were an unknown chunk
type. (This recommendation assumes that the chunk's CRC has been
verified. In decoders that do not check CRCs, it is safer to
treat any unexpected value as indicating a corrupted
datastream.)</p>
<p>Standard PNG images shall be compressed with compression
method 0. The compression method field of the <a href="#11IHDR"><span class=
"chunk">IHDR</span></a> chunk is
provided for possible future standardization or proprietary
variants. Decoders shall check this byte and report an error if
it holds an unrecognized code. See clause 10: <a href=
"#10Compression"><span class="xref">Compression</span></a> for
details.</p>
<h2><a name="13Security-considerations">13.4 Security
considerations</a></h2>
<p>A PNG datastream is composed of a collection of explicitly
typed chunks. Chunks whose contents are defined by the
specification could actually contain anything, including
malicious code. But there is no known risk that such malicious
code could be executed on the recipient's computer as a result of
decoding the PNG image.</p>
<p>The possible security risks associated with future chunk types
cannot be specified at this time. Security issues will be
considered by the Registration Authority when evaluating chunks
proposed for registration as public chunks. There is no
additional security risk associated with unknown or unimplemented
chunk types, because such chunks will be ignored, or at most be
copied into another PNG datastream.</p>
<p>The <a href="#11iTXt"><span class="chunk">iTXt</span></a>, <a
href="#11tEXt"><span class="chunk">tEXt</span></a>, and <a href=
"#11zTXt"><span class="chunk">zTXt</span></a> chunks contain keywords
and data
that are meant to be displayed as plain text. The <a href=
"#11iCCP"><span class="chunk">iCCP</span></a> and <a href=
"#11sPLT"><span class="chunk">sPLT</span></a> chunks contain
keywords that are meant to be displayed as plain text. It is
possible that if the decoder displays such text without filtering
out control characters, especially the ESC (escape) character,
certain systems or terminals could behave in undesirable and
insecure ways. It is recommended that decoders filter out control
characters to avoid this risk; see 13.5.3: <a href=
"#13Text-chunk-processing"><span class="xref">Text chunk
processing</span></a>.</p>
<p>Every chunk begins with a length field, which makes it easier
to write decoders that are invulnerable to fraudulent chunks that
attempt to overflow buffers. The CRC at the end of every chunk
provides a robust defence against accidentally corrupted data.
The PNG signature bytes provide early detection of common file
transmission errors.</p>
<p>A decoder that fails to check CRCs could be subject to data
corruption. The only likely consequence of such corruption is
incorrectly displayed pixels within the image. Worse things might
happen if the CRC of the <a href="#11IHDR"><span class=
"chunk">IHDR</span></a> chunk is not checked and the width or
height fields are corrupted. See 13.3: <a href=
"#13Error-checking"><span class="xref">Error
checking</span></a>.</p>
<p>A poorly written decoder might be subject to buffer overflow,
because chunks can be extremely large, up to 2<sup>31</sup>-1
bytes long. But properly written decoders will handle large
chunks without difficulty.</p>
<h2><a name="13Chunking">13.5 Chunking</a></h2>
<p>Decoders shall recognize chunk types by a simple four-byte
literal comparison; it is incorrect to perform case conversion on
chunk types. A decoder encountering an unknown chunk in which the
ancillary bit is 1 may safely ignore the chunk and proceed to
display the image. A decoder trying to extract the image, upon
encountering an unknown chunk in which the ancillary bit is 0,
indicating a critical chunk, shall indicate to the user that the
image contains information it cannot safely interpret.</p>
<p>(Decoders should not flag an error if the reserved bit is set
to 1, however, as some future version of the PNG specification
could define a meaning for this bit. It is sufficient to treat a
chunk with this bit set in the same way as any other unknown
chunk type.)</p>
<h2><a name="13Pixel-dimensions">13.6 Pixel dimensions</a></h2>
<p>Non-square pixels can be represented (see 11.3.5.3: <a href=
"#11pHYs"><span class="xref"><span class="chunk">pHYs</span>
Physical pixel dimensions</span></a>), but viewers are not
required to account for them; a viewer can present any PNG
datastream as though its pixels are square.</p>
<p>Where the pixel aspect ratio of the display differs from the
aspect ratio of the physical pixel dimensions defined in the PNG
datastream, viewers are strongly encouraged to rescale images for
proper display.</p>
<p>When the <a href="#11pHYs"><span class="xref"><span class=
"chunk">pHYs</span></span></a> chunk has a unit specifier of 0
(unit is unknown), the behaviour of a decoder may depend on the
ratio of the two pixels-per-unit values, but should not depend on
their magnitudes. For example, a <a href="#11pHYs"><span class=
"xref"><span class="chunk">pHYs</span></span></a> chunk
containing <tt>(ppuX, ppuY, unit) = (2, 1, 0)</tt> is equivalent
to one containing <tt>(1000, 500, 0)</tt>; both are equally valid
indications that the image pixels are twice as tall as they are
wide.</p>
<p>One reasonable way for viewers to handle a difference between
the pixel aspect ratios of the image and the display is to expand
the image either horizontally or vertically, but not both. The
scale factors could be obtained using the following
floating-point calculations:</p>
<pre>
<tt>image_ratio = pHYs_ppuY / pHYs_ppuX
display_ratio = display_ppuY / display_ppuX
scale_factor_X = max(1.0, image_ratio/display_ratio)
scale_factor_Y = max(1.0, display_ratio/image_ratio)</tt>
</pre>
<p>Because other methods such as maintaining the image area are
also reasonable, and because ignoring the <a href="#11pHYs"><span
class="xref"><span class="chunk">pHYs</span></span></a> chunk is
permissible, authors should not assume that all viewing
applications will use this scaling method.</p>
<p>As well as making corrections for pixel aspect ratio, a viewer
may have reasons to perform additional scaling both horizontally
and vertically. For example, a viewer might want to shrink an
image that is too large to fit on the display, or to expand
images sent to a high-resolution printer so that they appear the
same size as they did on the display.</p>
<h2><a name="13Text-chunk-processing">13.7 Text chunk
processing</a></h2>
<p>If practical, PNG decoders should have a way to display to the
user all the <a href="#11iTXt"><span class=
"chunk">iTXt</span></a>, <a href="#11tEXt"><span class=
"chunk">tEXt</span></a>, and <a href="#11zTXt"><span class=
"chunk">zTXt</span></a> chunks found in the datastream. Even if
the decoder does not recognize a particular text keyword, the
user might be able to understand it.</p>
<p>When processing <a href="#11tEXt"><span class=
"chunk">tEXt</span></a> and <a href="#11zTXt"><span class=
"chunk">zTXt</span></a> chunks, decoders could encounter
characters other than those permitted. Some can be safely
displayed (e.g., TAB, FF, and CR, decimal 9, 12, and 13,
respectively), but others, especially the ESC character (decimal
27), could pose a security hazard (because unexpected actions may
be taken by display hardware or software). Decoders should not
attempt to directly display any non-Latin-1 characters (except
for newline and perhaps TAB, FF, CR) encountered in a <a href=
"#11tEXt"><span class="chunk">tEXt</span></a> or <a href=
"#11zTXt"><span class="chunk">zTXt</span></a> chunk. Instead,
they should be ignored or displayed in a visible notation such as
"<tt>\</tt>nnn". See 13.4: <a href=
"#13Security-considerations"><span class="xref">Security
considerations</span></a>.</p>
<p>Even though encoders are recommended to represent newlines as
linefeed (decimal 10), it is recommended that decoders not rely
on this; it is best to recognize all the common newline
combinations (CR, LF, and CR-LF) and display each as a single
newline. TAB can be expanded to the proper number of spaces
needed to arrive at a column multiple of 8.</p>
<p>Decoders running on systems with non-Latin-1 character set
encoding should provide character code remapping so that Latin-1
characters are displayed correctly. Some systems may not provide
all the characters defined in Latin-1. Mapping unavailable
characters to a visible notation such as "<tt>\</tt>nnn" is a
good fallback. Character codes 127-255 should be displayed only
if they are printable characters on the decoding system. Some
systems may interpret such codes as control characters; for
security, decoders running on such systems should not display
such characters literally.</p>
<p>Decoders should be prepared to display text chunks that
contain any number of printing characters between newline
characters, even though it is recommended that encoders avoid
creating lines in excess of 79 characters.</p>
<h2><a name="13Decompression">13.8 Decompression</a></h2>
<p>The compression technique used in this International Standard
does not require the entire compressed datastream to be available
before decompression can start. Display can therefore commence
before the entire decompressed datastream is available. It is
extremely unlikely that any general purpose compression methods
in future versions of this International Standard will not have
this property.</p>
<p>It is important to emphasize that <a href="#11IDAT"><span
class="chunk">IDAT</span></a> chunk boundaries have no semantic
significance and can occur at any point in the compressed
datastream. There is no required correlation between the
structure of the image data (for example, scanline boundaries) and
deflate block boundaries or <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> chunk boundaries. The complete image data
is represented by a single zlib datastream that is stored in some
number of <a href="#11IDAT"><span class="chunk">IDAT</span></a>
chunks; a decoder that assumes any more than this is incorrect.
Some encoder implementations may emit datastreams in which some
of these structures are indeed related, but decoders cannot rely
on this.</p>
<h2><a name="13Filtering">13.9 Filtering</a></h2>
<p>To reverse the effect of a filter, the decoder may need
to use the decoded values of the prior pixel on the same line,
the pixel immediately above the current pixel on the prior line,
and the pixel just to the left of the pixel above. This implies
that at least one scanline's worth of image data needs to be
stored by the decoder at all times. Even though some filter types
do not refer to the prior scanline, the decoder will always need
to store each scanline as it is decoded, since the next scanline
might use a filter type that refers to it.</p>
<h2><a name="13Progressive-display">13.10 Interlacing and
progressive display</a></h2>
<p>Decoders are required to be able to read interlaced images. If
the reference image contains fewer than five columns or fewer
than five rows, some passes will be empty. Encoders and decoders
shall handle this case correctly. In particular, filter type
bytes are associated only with nonempty scanlines; no filter type
bytes are present in an empty reduced image.</p>
<p>When receiving images over slow transmission links, viewers
can improve perceived performance by displaying interlaced images
progressively. This means that as each reduced image is received,
an approximation to the complete image is displayed based on the
data received so far. One simple yet pleasing effect can be
obtained by expanding each received pixel to fill a rectangle
covering the yet-to-be-transmitted pixel positions below and to
the right of the received pixel. This process can be described by
the following ISO C code <a href="#2-ISO-9899"><span class=
"NormRef">[ISO-9899]</span></a>:</p>
<pre>
/*
variables declared and initialized elsewhere in the code:
height, width
functions or macros defined elsewhere in the code:
visit(), min()
*/
int starting_row[7] = { 0, 0, 4, 0, 2, 0, 1 };
int starting_col[7] = { 0, 4, 0, 2, 0, 1, 0 };
int row_increment[7] = { 8, 8, 8, 4, 4, 2, 2 };
int col_increment[7] = { 8, 8, 4, 4, 2, 2, 1 };
int block_height[7] = { 8, 8, 4, 4, 2, 2, 1 };
int block_width[7] = { 8, 4, 4, 2, 2, 1, 1 };
int pass;
long row, col;
pass = 0;
while (pass < 7)
{
row = starting_row[pass];
while (row < height)
{
col = starting_col[pass];
while (col < width)
{
visit(row, col,
min(block_height[pass], height - row),
min(block_width[pass], width - col));
col = col + col_increment[pass];
}
row = row + row_increment[pass];
}
pass = pass + 1;
}
</pre>
<p>The function <tt>visit(row,column,height,width)</tt> obtains
the next transmitted pixel and paints a rectangle of the
specified height and width, whose upper-left corner is at the
specified row and column, using the colour indicated by the
pixel. Note that row and column are measured from 0,0 at the
upper left corner.</p>
<p>If the viewer is merging the received image with a background
image, it may be more convenient just to paint the received pixel
positions (the <tt>visit()</tt> function sets only the pixel at the
specified row and column, not the whole rectangle). This produces
a "fade-in" effect as the new image gradually replaces the old.
An advantage of this approach is that proper alpha or
transparency processing can be done as each pixel is replaced.
Painting a rectangle as described above will overwrite
background-image pixels that may be needed later, if the pixels
eventually received for those positions turn out to be wholly or
partially transparent. This is a problem only if the background
image is not stored anywhere offscreen.</p>
<h2><a name="13Truecolour-image-handling">13.11 Truecolour image
handling</a></h2>
<p>To achieve PNG's goal of universal interchangeability,
decoders shall accept all types of PNG image: indexed-colour,
truecolour, and greyscale. Viewers running on indexed-colour
display hardware need to be able to reduce truecolour images to
indexed-colour for viewing. This process is called "colour
quantization".</p>
<p>A simple, fast method for colour quantization is to reduce the
image to a fixed palette. Palettes with uniform colour spacing
("colour cubes") are usually used to minimize the per-pixel
computation. For photograph-like images, dithering is recommended
to avoid ugly contours in what should be smooth gradients;
however, dithering introduces graininess that can be
objectionable.</p>
<p>The quality of rendering can be improved substantially by
using a palette chosen specifically for the image, since a colour
cube usually has numerous entries that are unused in any
particular image. This approach requires more work, first in
choosing the palette, and second in mapping individual pixels to
the closest available colour. PNG allows the encoder to supply
suggested palettes, but not all encoders will do so, and the
suggested palettes may be unsuitable in any case (they may have
too many or too few colours). Therefore, high-quality viewers
will need to have a palette selection routine at hand. A large
lookup table is usually the most feasible way of mapping
individual pixels to palette entries with adequate speed.</p>
<p>Numerous implementations of colour quantization are available.
The PNG sample implementation, libpng (<a href=
"http://www.libpng.org/pub/png/libpng.html"><code>http://www.libpng.org/pub/png/libpng.html</code></a>),
includes code for the purpose.</p>
<h2><a name="13Sample-depth-rescaling">13.12 Sample depth
rescaling</a></h2>
<p>Decoders may wish to scale PNG data to a lesser sample depth
(data precision) for display. For example, 16-bit data will need
to be reduced to 8-bit depth for use on most present-day display
hardware. Reduction of 8-bit data to 5-bit depth is also
common.</p>
<p>The most accurate scaling is achieved by the linear
equation</p>
<p><tt>output = floor((input * MAXOUTSAMPLE / MAXINSAMPLE) +
0.5)</tt></p>
<p>where</p>
<p><tt>MAXINSAMPLE = (2<sup>sampledepth</sup>)-1</tt><br class="xhtml" />
<tt>MAXOUTSAMPLE = (2<sup>desired_sampledepth</sup>)-1</tt></p>
<p>A slightly less accurate conversion is achieved by simply
shifting right by <tt>(sampledepth - desired_sampledepth)</tt>
places. For example, to reduce 16-bit samples to 8-bit, the
low-order byte can be discarded. In many situations the shift
method is sufficiently accurate for display purposes, and it is
certainly much faster. (But if gamma correction is being done,
sample rescaling can be merged into the gamma correction lookup
table, as is illustrated in 13.13: <a href=
"#13Decoder-gamma-handling"><span class="xref">Decoder gamma
handling</span></a>.)</p>
<p>If the decoder needs to scale samples up (for example, if the
frame buffer has a greater sample depth than the PNG image), it
should use linear scaling or left-bit-replication as described in
12.5: <a href="#12Sample-depth-scaling"><span class="xref">Sample
depth scaling</span></a>.</p>
<p>When an <a href="#11sBIT"><span class="chunk">sBIT</span></a>
chunk is present, the reference image data can be recovered by
shifting right to the sample depth specified by <a href=
"#11sBIT"><span class="chunk">sBIT</span></a>. Note that linear
scaling will not necessarily reproduce the original data, because
the encoder is not required to have used linear scaling to scale
the data up. However, the encoder is required to have used a
method that preserves the high-order bits, so shifting always
works. This is the only case in which shifting might be said to
be more accurate than linear scaling. A decoder need not pay
attention to the <a href="#11sBIT"><span class=
"chunk">sBIT</span></a> chunk; the stored image is a valid PNG
datastream of the sample depth indicated by the <a href=
"#11IHDR"><span class="chunk">IHDR</span></a> chunk; however,
using <a href="#11sBIT"><span class="chunk">sBIT</span></a> to
recover the original samples before scaling them to suit the
display often yields a more accurate display than ignoring <a
href="#11sBIT"><span class="chunk">sBIT</span></a>.</p>
<p>When comparing pixel values to <a href="#11tRNS"><span class=
"chunk">tRNS</span></a> chunk values to detect transparent
pixels, the comparison shall be done exactly. Therefore,
transparent pixel detection shall be done before reducing sample
precision.</p>
<h2><a name="13Decoder-gamma-handling">13.13 Decoder gamma
handling</a></h2>
<p>See Annex C: <a href="#C-GammaAppendix"><span class=
"xref">Gamma and chromaticity</span></a> for a brief introduction
to gamma issues.</p>
<p>Viewers capable of full colour management <a href=
"#G-ICC"><span class="bibref">[ICC]</span></a> will perform more
sophisticated calculations than those described here.</p>
<p>For an image display program to produce correct tone
reproduction, it is necessary to take into account the
relationship between samples and display output, and the transfer
function of the display system. This can be done by
calculating:</p>
<p><tt>sample = integer_sample / (2<sup>sampledepth</sup> -
1.0)<br class="xhtml" />
display_output = sample<sup>1.0/gamma</sup><br class="xhtml" />
display_input = inverse_display_transfer(display_output)<br class="xhtml" />
framebuf_sample = floor((display_input *
MAX_FRAMEBUF_SAMPLE)+0.5)</tt></p>
<p>where <tt>integer_sample</tt> is the sample value from the
datastream, <tt>framebuf_sample</tt> is the value to write into
the frame buffer, and <tt>MAX_FRAMEBUF_SAMPLE</tt> is the maximum
value of a frame buffer sample (255 for 8-bit, 31 for 5-bit,
etc). The first line converts an integer sample into a normalized
floating point value (in the range 0.0 to 1.0), the second
converts to a value proportional to the desired display output
intensity, the third accounts for the display system's transfer
function, and the fourth converts to an integer frame buffer
sample. Zero raised to any positive power is zero.</p>
<p>A step could be inserted between the second and third to
adjust <tt>display_output</tt> to account for the difference
between the actual viewing conditions and the reference viewing
conditions. However, this adjustment requires accounting for
veiling glare, black mapping, and colour appearance models, none
of which can be well approximated by power functions. Such
calculations are not described here. If viewing conditions are
ignored, the error will usually be small.</p>
<p>The display transfer function can typically be approximated by
a power function with exponent <tt>display_exponent</tt>, in
which case the second and third lines can be merged into:</p>
<p><tt>display_input = sample<sup>1.0/(gamma *
display_exponent)</sup> =
sample<sup>decoding_exponent</sup></tt></p>
<p>so as to perform only one power calculation. For colour
images, the entire calculation is performed separately for R, G,
and B values.</p>
<p>The value of gamma can be taken directly from the <a href=
"#11gAMA"><span class="chunk">gAMA</span></a> chunk.
Alternatively, an application may wish to allow the user to
adjust the appearance of the displayed image by influencing the
value of gamma. For example, the user could manually set a
parameter <tt>user_exponent</tt> which defaults to 1.0, and the
application could set:</p>
<pre>
<tt>gamma = gamma_from_file / user_exponent
decoding_exponent = 1.0 / (gamma * display_exponent)
= user_exponent / (gamma_from_file * display_exponent)</tt>
</pre>
<p>The user would set <tt>user_exponent</tt> greater than 1 to
darken the mid-level tones, or less than 1 to lighten them.</p>
<p>A <a href=
"#11gAMA"><span class="chunk">gAMA</span></a> chunk containing zero is
meaningless but could appear by mistake.
Decoders should ignore it,
and editors may discard it and issue a warning to the user.</p>
<p>It is <strong>not</strong> necessary to perform a transcendental
mathematical computation for every pixel. Instead, a lookup table
can be computed that gives the correct output value for every
possible sample value. This requires only 256 calculations per
image (for 8-bit accuracy), not one or three calculations per
pixel. For an indexed-colour image, a one-time correction of the
palette is sufficient, unless the image uses transparency and is
being displayed against a nonuniform background.</p>
<p>If floating-point calculations are not possible, gamma
correction tables can be computed using integer arithmetic and a
precomputed table of logarithms. Example code appears in <a href=
"#G-PNG-EXTENSIONS"><span class=
"bibref">[PNG-EXTENSIONS]</span></a>.</p>
<p>When the incoming image has unknown gamma (<a href=
"#11gAMA"><span class="chunk">gAMA</span></a>, <a href=
"#11sRGB"><span class="chunk">sRGB</span></a>, and <a href=
"#11iCCP"><span class="chunk">iCCP</span></a> all absent), choose
a likely default gamma value, but allow the user to select a new
one if the result proves too dark or too light. The default gamma
may depend on other knowledge about the image, for example
whether it came from the Internet or from the local system.</p>
<p>In practice, it is often difficult to determine what value of
display exponent should be used. In systems with no built-in
gamma correction, the display exponent is determined entirely by
the CRT. A display exponent of 2.2 should be used unless detailed
calibration measurements are available for the particular CRT
used.</p>
<p>Many modern frame buffers have lookup tables that are used to
perform gamma correction, and on these systems the display
exponent value should be the exponent of the lookup table and CRT
combined. It may not be possible to find out what the lookup
table contains from within the viewer application, in which case
it may be necessary to ask the user to supply the display
system's exponent value. Unfortunately, different manufacturers
use different ways of specifying what should go into the lookup
table, so interpretation of the system "gamma" value is
system-dependent.</p>
<p>The response of real displays is actually more complex than
can be described by a single number (the display exponent). If
actual measurements of the monitor's light output as a function
of voltage input are available, the third and fourth lines of the
computation above can be replaced by a lookup in these
measurements, to find the actual frame buffer value that most
nearly gives the desired brightness.</p>
<h2><a name="13Decoder-colour-handling">13.14 Decoder colour
handling</a></h2>
<p>See Annex C: <a href="#C-GammaAppendix"><span class=
"xref">Gamma and chromaticity</span></a> for references to colour
issues.</p>
<p>In many cases, the image data in PNG datastreams will be
treated as device-dependent RGB values and displayed without
modification (except for appropriate gamma correction). This
provides the fastest display of PNG images. But unless the viewer
uses exactly the same display hardware as that used by the author
of the original image, the colours will not be exactly the same
as those seen by the original author, particularly for darker or
near-neutral colours. The <a href="#11cHRM"><span class=
"chunk">cHRM</span></a> chunk provides information that allows
closer colour matching than that provided by gamma correction
alone.</p>
<p>The <a href="#11cHRM"><span class="chunk">cHRM</span></a> data
can be used to transform the image data from RGB to XYZ and
thence into a perceptually linear colour space such as CIE LAB.
The colours can be partitioned to generate an optimal palette,
because the geometric distance between two colours in CIE LAB is
strongly related to how different those colours appear (unlike,
for example, RGB or XYZ spaces). The resulting palette of
colours, once transformed back into RGB colour space, could be
used for display or written into a <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> chunk.</p>
<p>Decoders that are part of image processing applications might
also transform image data into CIE LAB space for analysis.</p>
<p>In applications where colour fidelity is critical, such as
product design, scientific visualization, medicine, architecture,
or advertising, PNG decoders can transform the image data from
source RGB to the display RGB space of the monitor used to view
the image. This involves calculating the matrix to go from source
RGB to XYZ and the matrix to go from XYZ to display RGB, then
combining them to produce the overall transformation. The PNG
decoder is responsible for implementing gamut mapping.</p>
<p>Decoders running on platforms that have a Colour Management
System (CMS) can pass the image data, <a href="#11gAMA"><span
class="chunk">gAMA</span></a>, and <a href="#11cHRM"><span class=
"chunk">cHRM</span></a> values to the CMS for display or further
processing.</p>
<p>PNG decoders that provide colour printing facilities can use
the facilities in Level 2 PostScript to specify image data in
calibrated RGB space or in a device-independent colour space such
as XYZ. This will provide better colour fidelity than a simple
RGB to CMYK conversion. The PostScript Language Reference manual
<a href="#G-POSTSCRIPT"><span class=
"bibref">[POSTSCRIPT]</span></a> gives examples. Such decoders
are responsible for implementing gamut mapping between source RGB
(specified in the <a href="#11cHRM"><span class=
"chunk">cHRM</span></a> chunk) and the target printer. The
PostScript interpreter is then responsible for producing the
required colours.</p>
<p>PNG decoders can use the <a href="#11cHRM"><span class=
"chunk">cHRM</span></a> data to calculate an accurate greyscale
representation of a colour image. Conversion from RGB to grey is
simply a case of calculating the Y (luminance) component of XYZ,
which is a weighted sum of R, G, and B values. The weights depend
upon the monitor type, i.e. the values in the <a href=
"#11cHRM"><span class="chunk">cHRM</span></a> chunk. PNG decoders
may wish to do this for PNG datastreams with no <a href=
"#11cHRM"><span class="chunk">cHRM</span></a> chunk. In this
case, a reasonable default would be the CCIR 709 primaries <a
href="#G-ITU-R-BT709"><span class=
"bibref">[ITU-R-BT709]</span></a>. The original NTSC primaries
should <strong>not</strong> be used unless the PNG image really
was colour-balanced for such a monitor.</p>
<h2><a name="13Background-colour">13.15 Background
colour</a></h2>
<p>The background colour given by the <a href="#11bKGD"><span
class="chunk">bKGD</span></a> chunk will typically be used to
fill unused screen space around the image, as well as any
transparent pixels within the image. (Thus, <a href=
"#11bKGD"><span class="chunk">bKGD</span></a> is valid and useful
even when the image does not use transparency.) If no <a href=
"#11bKGD"><span class="chunk">bKGD</span></a> chunk is present,
the viewer will need to decide upon a suitable background colour.
When no other information is available, a medium grey such as 153
in the 8-bit sRGB colour space would be a reasonable choice.
Transparent black or white text and dark drop shadows, which are
common, would all be legible against this background.</p>
<p>Viewers that have a specific background against which to
present the image (such as web browsers) should ignore the <a
href="#11bKGD"><span class="chunk">bKGD</span></a> chunk, in
effect overriding <a href="#11bKGD"><span class=
"chunk">bKGD</span></a> with their preferred background colour or
background image.</p>
<p>The background colour given by the <a href="#11bKGD"><span
class="chunk">bKGD</span></a> chunk is not to be considered
transparent, even if it happens to match the colour given by the
<a href="#11tRNS"><span class="chunk">tRNS</span></a> chunk (or,
in the case of an indexed-colour image, refers to a palette index
that is marked as transparent by the <a href="#11tRNS"><span
class="chunk">tRNS</span></a> chunk). Otherwise one would have to
imagine something "behind the background" to composite against.
The background colour is either used as background or ignored; it
is not an intermediate layer between the PNG image and some other
background.</p>
<p>Indeed, it will be common that the <a href="#11bKGD"><span
class="chunk">bKGD</span></a> and <a href="#11tRNS"><span class=
"chunk">tRNS</span></a> chunks specify the same colour, since
then a decoder that does not implement transparency processing
will give the intended display, at least when no
partially-transparent pixels are present.</p>
<h2><a name="13Alpha-channel-processing">13.16 Alpha channel
processing</a></h2>
<p>The alpha channel can be used to composite a foreground image
against a background image. The PNG datastream defines the
foreground image and the transparency mask, but not the
background image. PNG decoders are <strong>not</strong> required to
support this most general case. It is expected that most will be
able to support compositing against a single background
colour.</p>
<p>The equation for computing a composited sample value is:</p>
<pre>
output = alpha * foreground + (1-alpha) * background
</pre>
<p>where alpha and the input and output sample values are
expressed as fractions in the range 0 to 1. This computation
should be performed with intensity samples (not gamma-encoded
samples). For colour images, the computation is done separately
for R, G, and B samples.</p>
<p>The following code illustrates the general case of compositing
a foreground image against a background image. It assumes that
the original pixel data are available for the background image,
and that output is to a frame buffer for display. Other variants
are possible; see the comments below the code. The code allows
the sample depths and gamma values of foreground image and
background image all to be different and not necessarily suited
to the display system. In practice no assumptions about equality
should be made without first checking.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<p>This code is ISO C <a href="#2-ISO-9899"><span class=
"NormRef">[ISO-9899]</span></a>, with line numbers added for
reference in the comments below.</p>
<pre>
01 int foreground[4]; /* image pixel: R, G, B, A */
02 int background[3]; /* background pixel: R, G, B */
03 int fbpix[3]; /* frame buffer pixel */
04 int fg_maxsample; /* foreground max sample */
05 int bg_maxsample; /* background max sample */
06 int fb_maxsample; /* frame buffer max sample */
07 int ialpha;
08 float alpha, compalpha;
09 float gamfg, linfg, gambg, linbg, comppix, gcvideo;
/* Get max sample values in data and frame buffer */
10 fg_maxsample = (1 << fg_sample_depth) - 1;
11 bg_maxsample = (1 << bg_sample_depth) - 1;
12 fb_maxsample = (1 << frame_buffer_sample_depth) - 1;
/*
* Get integer version of alpha.
* Check for opaque and transparent special cases;
* no compositing needed if so.
*
* We show the whole gamma decode/correct process in
* floating point, but it would more likely be done
* with lookup tables.
*/
13 ialpha = foreground[3];
14 if (ialpha == 0) {
/*
* Foreground image is transparent here.
* If the background image is already in the frame
* buffer, there is nothing to do.
*/
15 ;
16 } else if (ialpha == fg_maxsample) {
/*
* Copy foreground pixel to frame buffer.
*/
17 for (i = 0; i < 3; i++) {
18 gamfg = (float) foreground[i] / fg_maxsample;
19 linfg = pow(gamfg, 1.0 / fg_gamma);
20 comppix = linfg;
21 gcvideo = pow(comppix, 1.0 / display_exponent);
22 fbpix[i] = (int) (gcvideo * fb_maxsample + 0.5);
23 }
24 } else {
/*
* Compositing is necessary.
* Get floating-point alpha and its complement.
* Note: alpha is always linear; gamma does not
* affect it.
*/
25 alpha = (float) ialpha / fg_maxsample;
26 compalpha = 1.0 - alpha;
27 for (i = 0; i < 3; i++) {
/*
* Convert foreground and background to floating
* point, then undo gamma encoding.
*/
28 gamfg = (float) foreground[i] / fg_maxsample;
29 linfg = pow(gamfg, 1.0 / fg_gamma);
30 gambg = (float) background[i] / bg_maxsample;
</pre>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<pre>
31 linbg = pow(gambg, 1.0 / bg_gamma);
/*
* Composite.
*/
32 comppix = linfg * alpha + linbg * compalpha;
/*
* Gamma correct for display.
* Convert to integer frame buffer pixel.
*/
33 gcvideo = pow(comppix, 1.0 / display_exponent);
34 fbpix[i] = (int) (gcvideo * fb_maxsample + 0.5);
35 }
36 }
</pre>
<p>Variations:</p>
<!-- <ol start="1"> --><ol>
<li>If output is to another PNG datastream instead of a frame
buffer, lines 21, 22, 33, and 34 should be changed along the
following lines
<pre>
/*
* Gamma encode for storage in output datastream.
* Convert to integer sample value.
*/
gamout = pow(comppix, outfile_gamma);
outpix[i] = (int) (gamout * out_maxsample + 0.5);
</pre>
Also, it becomes necessary to process background pixels when
alpha is zero, rather than just skipping pixels. Thus, line 15
will need to be replaced by copies of lines 17-23, but processing
background instead of foreground pixel values.</li>
<li>If the sample depths of the output file, foreground file, and
background file are all the same, and the three gamma values also
match, then the no-compositing code in lines 14-23 reduces to
copying pixel values from the input file to the output file if
alpha is one, or copying pixel values from background to output
file if alpha is zero. Since alpha is typically either zero or
one for the vast majority of pixels in an image, this is a
significant saving. No gamma computations are needed for most
pixels.</li>
<li>When the sample depths and gamma values all match, it may
appear attractive to skip the gamma decoding and encoding (lines
28-31, 33-34) and just perform line 32 using gamma-encoded sample
values. Although this does not have too bad an effect on image
quality, the time savings are small if alpha values of zero and
one are treated as special cases as recommended here.</li>
<li>If the original pixel values of the background image are no
longer available, only processed frame buffer pixels left by
display of the background image, then lines 30 and 31 need to
extract intensity from the frame buffer pixel values using code
such as
<pre>
/*
* Convert frame buffer value into intensity sample.
*/
gcvideo = (float) fbpix[i] / fb_maxsample;
linbg = pow(gcvideo, display_exponent);
</pre>
However, some roundoff error can result, so it is better to have
the original background pixels available if at all possible.</li>
<li>Note that lines 18-22 are performing exactly the same gamma
computation that is done when no alpha channel is present. If the
no-alpha case is handled with a lookup table, the same lookup
table can be used here. Lines 28-31 and 33-34 can also be done
with (different) lookup tables.</li>
<li>Integer arithmetic can be used instead of floating point,
providing care is taken to maintain sufficient precision
throughout.</li>
</ol>
<p class="Note">NOTE In floating point, no overflow or underflow
checks are needed, because the input sample values are guaranteed
to be between 0 and 1, and compositing always yields a result
that is in between the input values (inclusive). With integer
arithmetic, some roundoff-error analysis might be needed to
guarantee no overflow or underflow.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<p>When displaying a PNG image with full alpha channel, it is
important to be able to composite the image against some
background, even if it is only black. Ignoring the alpha channel
will cause PNG images that have been converted from an
associated-alpha representation to look wrong. (Of course, if the
alpha channel is a separate transparency mask, then ignoring
alpha is a useful option: it allows the hidden parts of the image
to be recovered.)</p>
<p>Even if the decoder does not implement true compositing logic,
it is simple to deal with images that contain only zero and one
alpha values. (This is implicitly true for greyscale and
truecolour PNG datastreams that use a <a href="#11tRNS"><span
class="chunk">tRNS</span></a> chunk; for indexed-colour PNG
datastreams it is easy to check whether the <a href=
"#11tRNS"><span class="chunk">tRNS</span></a> chunk contains any
values other than 0 and 255.) In this simple case, transparent
pixels are replaced by the background colour, while others are
unchanged.</p>
<p>If a decoder contains only this much transparency capability,
it should deal with a full alpha channel by treating all nonzero
alpha values as fully opaque or by dithering. Neither approach
will yield very good results for images converted from
associated-alpha formats, but this is preferable to doing
nothing. Dithering full alpha to binary alpha is very much like
dithering greyscale to black-and-white, except that all fully
transparent and fully opaque pixels should be left unchanged by
the dither.</p>
<h2><a name="13Histogram-and-suggested-palette-usage">13.17
Histogram and suggested palette usage</a></h2>
<p>For viewers running on indexed-colour hardware attempting to
display a truecolour image, or an indexed-colour image whose
palette is too large for the frame buffer, the encoder may have
provided one or more suggested palettes in <a href=
"#11sPLT"><span class="chunk">sPLT</span></a> chunks. If one of
these is found to be suitable, based on size and perhaps name,
the PNG decoder can use that palette. Suggested palettes with a
sample depth different from what the decoder needs can be
converted using sample depth rescaling (see 13.12: <a href=
"#13Sample-depth-rescaling"><span class="xref">Sample depth
rescaling</span></a>).</p>
<p>When the background is a solid colour, the viewer should
composite the image and the suggested palette against that
colour, then quantize the resulting image to the resulting RGB
palette. When the image uses transparency and the background is
not a solid colour, no suggested palette is likely to be
useful.</p>
<p>For truecolour images, a suggested palette might also be
provided in a <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> chunk. If the image has a <a href=
"#11tRNS"><span class="chunk">tRNS</span></a> chunk and the
background is a solid colour, the viewer will need to adapt the
suggested palette for use with its desired background colour. To
do this, the palette entry closest to the <a href="#11tRNS"><span
class="chunk">tRNS</span></a> colour should be replaced with the
desired background colour; or alternatively a palette entry for
the background colour can be added, if the viewer can handle more
colours than there are <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> entries.</p>
<p>For images of colour type 6 (truecolour with alpha), any <a
href="#11PLTE"><span class="chunk">PLTE</span></a> chunk should
have been designed for display of the image against a uniform
background of the colour specified by the <a href="#11bKGD"><span
class="chunk">bKGD</span></a> chunk. Viewers should probably
ignore the palette if they intend to use a different background,
or if the <a href="#11bKGD"><span class="chunk">bKGD</span></a>
chunk is missing. Viewers can use a suggested palette for display
against a different background than it was intended for, but the
results may not be very good.</p>
<p>If the viewer presents a transparent truecolour image against
a background that is more complex than a uniform colour, it is
unlikely that the suggested palette will be optimal for the
composite image. In this case it is best to perform a truecolour
compositing step on the truecolour PNG image and background
image, then colour-quantize the resulting image.</p>
<p>In truecolour PNG datastreams, if both <a href="#11PLTE"><span
class="chunk">PLTE</span></a> and <a href="#11sPLT"><span class=
"chunk">sPLT</span></a> chunks appear, the PNG decoder may choose
from among the palettes suggested by both, bearing in mind the
different transparency semantics described above.</p>
<p>The frequencies in the <a href="#11sPLT"><span class=
"chunk">sPLT</span></a> and <a href="#11hIST"><span class=
"chunk">hIST</span></a> chunks are useful when the viewer cannot
provide as many colours as are used in the palette in the PNG
datastream. If the viewer has a shortfall of only a few colours,
it is usually adequate to drop the least-used colours from the
palette. To reduce the number of colours substantially, it is
best to choose entirely new representative colours, rather than
trying to use a subset of the existing palette. This amounts to
performing a new colour quantization step; however, the existing
palette and histogram can be used as the input data, thus
avoiding a scan of the image data in the <a href="#11IDAT"><span
class="chunk">IDAT</span></a> chunks.</p>
<p>If no suggested palette is provided, a decoder can develop its
own, at the cost of an extra pass over the image data in the <a
href="#11IDAT"><span class="chunk">IDAT</span></a> chunks.
Alternatively, a default palette (probably a colour cube) can be
used.</p>
<p>See also 12.6: <a href="#12Suggested-palettes"><span class=
"xref">Suggested palettes</span></a>.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="14EditorsExt">14 Editors and extensions</a></h1>
<h2><a name="14Additional-chunk-types">14.1 Additional chunk
types</a></h2>
<p>The provisions of this International Standard may be extended
by adding new chunk types, which may be either private or public.
Applications can use private chunk types to carry data that is
not of interest to other people's applications.</p>
<p>Decoders shall be prepared to encounter unrecognized public or
private chunk types. The chunk naming conventions (see 5.4:
<a href="#5Chunk-naming-conventions"><span class="xref">Chunk
naming conventions</span></a>) enable critical/ancillary,
public/private, and safe/unsafe to copy chunks to be
distinguished.</p>
<p>Additional public PNG chunk types are defined in the document
Register of PNG Public Chunks and Keywords <a href=
"#G-PNG-EXTENSIONS"><span class=
"bibref">[PNG-REGISTER]</span></a>. Chunks described there are
expected to be less widely supported than those defined in this
International Standard. However, application authors are
encouraged to use those chunk types whenever appropriate for
their applications. Additional chunk types can be proposed for
inclusion in that list by contacting the PNG Registration
Authority (see 4.9: <a href="#4Concepts.Registration"><span
class="xref">Extension and registration</span></a>).</p>
<p>New public chunks will be registered only if they are of use
to others and do not violate the design philosophy of PNG. Chunk
registration is not automatic, although it is the intent of the
Registration Authority that it be straightforward when a new
chunk of potentially wide application is needed. The creation of
new critical chunk types is discouraged unless absolutely
necessary.</p>
<h2><a name="14Ordering">14.2 Behaviour of PNG editors</a></h2>
<p>A "PNG editor" is defined as a program that reads a PNG
datastream, makes modifications, and writes a new PNG datastream
while preserving as much ancillary information as possible. Two
examples of PNG editors are a program that adds or modifies text
chunks, and a program that adds a suggested palette to a
truecolour PNG datastream. Ordinary image editors are not PNG
editors because they usually discard all unrecognized information
while reading in an image.</p>
<p>To allow new chunk types to be added to PNG, it is necessary
to establish rules about the ordering requirements for all chunk
types. Otherwise a PNG editor does not know what to do when it
encounters an unknown chunk.</p>
<p>EXAMPLE Consider a hypothetical new ancillary chunk type that
is safe-to-copy and is required to appear after <a href=
"#11PLTE"><span class="chunk">PLTE</span></a> if <a href=
"#11PLTE"><span class="chunk">PLTE</span></a> is present. If a
program attempts to add a <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> chunk and does not recognize the new
chunk, it may insert the <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> chunk in the wrong place, namely after
the new chunk. Such problems could be prevented by requiring PNG
editors to discard all unknown chunks, but that is a very
unattractive solution. Instead, PNG requires ancillary chunks not
to have ordering restrictions like this.</p>
<p>To prevent this type of problem while allowing for future
extension, constraints are placed on both the behaviour of PNG
editors and the allowed ordering requirements for chunks. The
safe-to-copy bit defines the proper handling of unrecognized
chunks in a datastream that is being modified.</p>
<!-- <ol start="1"> --><ol>
<li>If a chunk's safe-to-copy bit is 1, the chunk may be copied
to a modified PNG datastream whether or not the PNG editor
recognizes the chunk type, and regardless of the extent of the
datastream modifications.</li>
<li>If a chunk's safe-to-copy bit is 0, it indicates that the
chunk depends on the image data. If the program has made
<strong>any</strong> changes to <strong>critical</strong> chunks, including
addition, modification, deletion, or reordering of critical
chunks, then unrecognized unsafe chunks shall
<strong>not</strong> be copied to the output PNG datastream. (Of
course, if the program <strong>does</strong> recognize the chunk,
it can choose to output an appropriately modified version.)</li>
<li>A PNG editor is always allowed to copy all unrecognized
ancillary chunks if it has only added, deleted, modified, or
reordered <strong>ancillary</strong> chunks. This implies that it is not
permissible for ancillary chunks to depend on other ancillary
chunks.</li>
<li>PNG editors shall terminate on encountering an unrecognized
critical chunk type, because there is no way to be certain that a
valid datastream will result from modifying a datastream
containing such a chunk. (Simply discarding the chunk is not good
enough, because it might have unknown implications for the
interpretation of other chunks.) The safe/unsafe mechanism is
intended for use with ancillary chunks. The safe-to-copy bit will
always be 0 for critical chunks.</li>
</ol>
<p>The rules governing ordering of chunks are as follows.</p>
<!-- <ol start="5"> --><ol>
<li>When copying an unknown <strong>unsafe-to-copy</strong> ancillary
chunk, a PNG editor shall not move the chunk relative to any
critical chunk. It may relocate the chunk freely relative to
other ancillary chunks that occur between the same pair of
critical chunks. (This is well defined since the editor shall not
add, delete, modify, or reorder critical chunks if it is
preserving unknown unsafe-to-copy chunks.)</li>
<li>When copying an unknown <strong>safe-to-copy</strong> ancillary
chunk, a PNG editor shall not move the chunk from before <a href=
"#11IDAT"><span class="chunk">IDAT</span></a> to after <a href=
"#11IDAT"><span class="chunk">IDAT</span></a> or vice versa.
(This is well defined because <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> is always present.) Any other reordering
is permitted.</li>
<li>When copying a <strong>known</strong> ancillary chunk type, an editor
need only honour the specific chunk ordering rules that exist for
that chunk type. However, it may always choose to apply the above
general rules instead.</li>
</ol>
<p>These rules are expressed in terms of copying chunks from an
input datastream to an output datastream, but they apply in the
obvious way if a PNG datastream is modified in place.</p>
<p>See also 5.4: <a href="#5Chunk-naming-conventions"><span
class="xref">Chunk naming conventions</span></a>.</p>
<p>PNG editors that do not change the image data should not
change the <a href="#11tIME"><span class="chunk">tIME</span></a>
chunk. The Creation Time keyword in the <a href="#11tEXt"><span
class="chunk">tEXt</span></a>, <a href="#11zTXt"><span class=
"chunk">zTXt</span></a>, and <a href="#11iTXt"><span class=
"chunk">iTXt</span></a> chunks may be used for a user-supplied
time.</p>
<h2><a name="14Ordering-of-chunks">14.3 Ordering of
chunks</a></h2>
<h3><a name="14Ordering-of-critical-chunks">14.3.1 Ordering of
critical chunks</a></h3>
<p>Critical chunks may have arbitrary ordering requirements,
because PNG editors are required to terminate if they encounter
unknown critical chunks. For example <a href="#11IHDR"><span
class="chunk">IHDR</span></a> has the specific ordering rule that
it shall always appear first. A PNG editor, or indeed any
PNG-writing program, shall know and follow the ordering rules for
any critical chunk type that it can generate.</p>
<h3><a name="14Ordering-of-ancillary-chunks">14.3.2 Ordering of
ancillary chunks</a></h3>
<p>The strictest ordering rules for an ancillary chunk type
are:</p>
<!-- <ol start="1"> --><ol>
<li>Unsafe-to-copy chunks may have ordering requirements relative
to critical chunks.</li>
<li>Safe-to-copy chunks may have ordering requirements relative
to <a href="#11IDAT"><span class="chunk">IDAT</span></a>.</li>
</ol>
<p>The actual ordering rules for any particular ancillary chunk
type may be weaker. See for example the ordering rules for the
standard ancillary chunk types in 5.6: <a href=
"#5ChunkOrdering"><span class="xref">Chunk
ordering</span></a>.</p>
<p>Decoders shall not assume more about the positioning of any
ancillary chunk than is specified by the chunk ordering rules. In
particular, it is never valid to assume that a specific ancillary
chunk type occurs with any particular positioning relative to
other ancillary chunks.</p>
<p>EXAMPLE It is unsafe to assume that a particular private
ancillary chunk occurs immediately before <a href="#11IEND"><span
class="chunk">IEND</span></a>. Even if it is always written in
that position by a particular application, a PNG editor might
have inserted some other ancillary chunk after it. But it is safe
to assume that the chunk will remain somewhere between <a href=
"#11IDAT"><span class="chunk">IDAT</span></a> and <a href=
"#11IEND"><span class="chunk">IEND</span></a>.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1><a name="15Conformance">15 Conformance</a></h1>
<h2><a name="15ConfIntro">15.1 Introduction</a></h2>
<h3><a name="15ConfObjectives">15.1.1 Objectives</a></h3>
<p>This clause addresses conformance of PNG datastreams, PNG
encoders, PNG decoders, and PNG editors.</p>
<p>The primary objectives of the specifications in this clause
are:</p>
<!-- <ol start="1"> --><ol>
<li>to promote interoperability by eliminating arbitrary subsets
of, or extensions to, this International Standard;</li>
<li>to promote uniformity in the development of conformance
tests;</li>
<li>to promote consistent results across PNG encoders, decoders,
and editors;</li>
<li>to facilitate automated test generation.</li>
</ol>
<h3><a name="15ConfScope">15.1.2 Scope</a></h3>
<p>Conformance is defined for PNG datastreams and for PNG
encoders, decoders, and editors.</p>
<p>This clause addresses the PNG datastream and implementation
requirements including the range of allowable differences for PNG
encoders, PNG decoders, and PNG editors. This clause does not
directly address the environmental, performance, or resource
requirements of the encoder, decoder, or editor.</p>
<p>The scope of this clause is limited to rules for the open
interchange of PNG datastreams.</p>
<h2><a name="15ConformanceConf">15.2 Conformance conditions</a></h2>
<h3><a name="15FileConformance">15.2.1 Conformance of PNG
datastreams</a></h3>
<p>A PNG datastream conforms to this International Standard if
the following conditions are met.</p>
<ol>
<li>The PNG datastream contains a PNG signature as the first
content (see 5.2: <a href="#5PNG-file-signature"><span class=
"xref">PNG file signature</span></a>).</li>
<li>With respect to the chunk types defined in this International
Standard:
<ul>
<li>the PNG datastream contains as its first chunk, an <a href=
"#11IHDR"><span class="chunk">IHDR</span></a> chunk, immediately
following the PNG signature;</li>
<li>the PNG datastream contains as its last chunk, an <a href=
"#11IEND"><span class="chunk">IEND</span></a> chunk.</li>
</ul>
</li>
<li>No chunks or other content follow the <a href="#11IEND"><span
class="chunk">IEND</span></a> chunk.</li>
<li>All chunks contained therein match the specification of the
corresponding chunk types of this International Standard.
The PNG datastream shall obey the relationships among chunk types
defined in this International Standard.</li>
<li>The sequence of chunks in the PNG datastream obeys the
ordering relationship specified in this International
Standard.</li>
<li>All field values in the PNG datastream obey the relationships
specified in this International Standard producing the structure
specified in this International Standard.</li>
<li>No chunks appear in the PNG datastream other than those
specified in this International Standard or those defined
according to the rules for creating new chunk types as defined in
this International Standard.</li>
<li>The PNG datastream is encoded according to the rules of this
International Standard.</li>
</ol>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h3><a name="15ConformanceEncoder">15.2.2 Conformance of PNG
encoders</a></h3>
<p>A PNG encoder conforms to this International Standard if it
satisfies the following conditions.</p>
<!-- <ol start="1"> --><ol>
<li>All PNG datastreams that are generated by the PNG encoder are
conforming PNG datastreams.</li>
<li>When encoding input samples that have a sample depth that
cannot be directly represented in PNG, the encoder scales the
samples up to the next higher sample depth that is allowed by
PNG. The data are scaled in such a way that the high-order bits
match the original data.</li>
<li>Numbers greater than 127 are used when encoding experimental
or private definitions of values for any of the method or type
fields.</li>
</ol>
<h3><a name="15ConformanceDecoder">15.2.3 Conformance of PNG
decoders</a></h3>
<p>A PNG decoder conforms to this International Standard if it
satisfies the following conditions.</p>
<!-- <ol start="1"> --><ol>
<li>It is able to read any PNG datastream that conforms to this
International Standard, including both public and private chunks
whose types may not be recognized.</li>
<li>It supports all the standardized critical chunks, and all the
standardized compression, filter, and interlace methods and types
in any PNG datastream that conforms to this International
Standard.</li>
<li>Unknown chunk types are handled as described in <a href=
"#5Chunk-naming-conventions"><span class="xref">5.4 Chunk naming
conventions</span></a>. An unknown chunk type is <strong>not</strong>
treated as an error unless it is a critical chunk.</li>
<li>Unexpected values in fields of known chunks (for example, an
unexpected compression method in the <a href="#11IHDR"><span
class="chunk">IHDR</span></a> chunk) are treated as errors.</li>
<li>All types of PNG images (indexed-colour, truecolour,
greyscale, truecolour with alpha, and greyscale with alpha) are
processed. For example, decoders which are part of viewers
running on indexed-colour display hardware shall reduce
truecolour images to indexed format for viewing.</li>
<li>Encountering an unknown chunk in which the ancillary bit is 0
generates an error if the decoder is attempting to extract the
image.</li>
<li>A chunk type in which the reserved bit is set is treated as
an unknown chunk type.</li>
<li>All valid combinations of bit depth and colour type as
defined in 11.2.2: <a href="#11IHDR"><span class="xref"><span
class="chunk">IHDR</span> Image header</span></a> are
supported.</li>
<li>An error is reported if an unrecognized value is encountered
in the bit depth, colour type, compression method, filter method,
or interlace method bytes of the <a href="#11IHDR"><span class=
"chunk">IHDR</span></a> chunk.</li>
<li>When processing 16-bit greyscale or truecolour data in the <a
href="#11tRNS"><span class="chunk">tRNS</span></a> chunk, both
bytes of the sample values are evaluated to determine whether a
pixel is transparent.</li>
<li>When processing an image compressed by compression method 0,
the decoder assumes no more than that the complete image data is
represented by a single compressed datastream that is stored in
some number of <a href="#11IDAT"><span class=
"chunk">IDAT</span></a> chunks.</li>
<li>No assumptions are made concerning the positioning of any
ancillary chunk other than those that are specified by the chunk
ordering rules.</li>
</ol>
<h3><a name="15ConformanceEditor">15.2.4 Conformance of PNG
editors</a></h3>
<p>A PNG editor conforms to this International Standard if it satisfies the following conditions.</p>
<ol>
<li>It conforms to the requirements for PNG encoders.</li>
<li>It conforms to the requirements for PNG decoders.</li>
<li>It is able to encode all chunks that it decodes.</li>
<li>It preserves the ordering of the chunks presented within the
rules in 5.6: <a href="#5ChunkOrdering"><span class="xref">Chunk
ordering</span></a>.</li>
<li>It properly processes the safe-to-copy bit information and
preserves unknown chunks when the safe-to-copy rules permit
it.</li>
<li>Unless the user specifically permits lossy operations or the
editor issues a warning, it preserves all information required to
reconstruct the reference image exactly, except that the sample
depth of the alpha channel need not be preserved if it contains
only zero and maximum values. Operations such as changing the
colour type or rearranging the palette in an indexed-colour
datastream are permitted provided that the new datastream
losslessly represents the same reference image.</li>
</ol>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1 class="Annex"><a name="A-Conventions">Annex A</a></h1>
<p class="Annex">(informative)</p>
<h1 id="filemedia" class="Annex">File conventions and Internet media type</h1>
<h2><a name="A-File-name-extension">A.1 File name
extension</a></h2>
<p>On systems where file names customarily include an extension
signifying file type, the extension "<tt>.png</tt>" is
recommended for PNG files. Lower case "<tt>.png</tt>" is
preferred if file names are case-sensitive.</p>
<h2><a name="A-Media-type">A.2 Internet media type</a></h2>
<p>The internet media type "<tt>image/png</tt>" is the Internet
Media Type for PNG <a href="#2-RFC-2045"><span class=
"NormRef">[RFC-2045]</span></a>, <a href="#2-RFC-2048"><span
class="NormRef">[RFC-2048]</span></a>. It is recommended that
implementations also recognize the media type
"<tt>image/x-png</tt>".</p>
<h2><a name="A-Macintosh-file-layout">A.3 Macintosh file
layout</a></h2>
<p>In the Apple Computer Inc. Macintosh system, the following
conventions are recommended.</p>
<ol>
<li>The four-byte file type code for PNG files is
"<tt>PNGf</tt>". (This code has been registered with Apple
Computer Inc. for PNG files.) The creator code will vary
depending on the creating application.</li>
<li>The contents of the data fork is a PNG file exactly as
described in this International Standard.</li>
<li>The contents of the resource fork are unspecified. It may be
empty or may contain application-dependent resources.</li>
<li>When transferring a Macintosh PNG file to a non-Macintosh
system, only the data fork should be transferred.</li>
</ol>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1 class="Annex"><a name="B-NewChunksAppendix">Annex B</a></h1>
<p class="Annex">(informative)</p>
<h1 id="newchunks" class="Annex">Guidelines for new chunk types</h1>
<p>This International Standard allows extension through the
addition of new chunk types and new interlace, filter, and
compression methods. Such extensions might be made to the
standard either for experimental purposes or by organizations for
internal use.</p>
<p>Chunk types that are intended for general public use, or are
required for specific application domains, should be standardized
through registration (see 4.9 <a href=
"#4Concepts.Registration"><span class="xref">Extension and
registration</span></a>). The process for registration is defined
by the Registration Authority. The conventions for naming chunks
are given in 5.4: <a href="#5Chunk-naming-conventions"><span
class="xref">Chunk naming conventions</span></a>.</p>
<p>Some guidelines for defining private chunks are given
below.</p>
<!-- <ol start="1"> --><ol>
<li>Do not define new chunks that redefine the meaning of
existing chunks or change the interpretation of an existing
standardized chunk, e.g., do not add a new chunk to say that RGB
and alpha values actually mean CMYK.</li>
<li>Minimize the use of private chunks to aid portability.</li>
<li>Avoid defining chunks that depend on total datastream
contents. If such chunks have to be defined, make them critical
chunks.</li>
<li>For textual information that is representable in Latin-1
avoid defining a new chunk type. Use a <a href="#11tEXt"><span
class="chunk">tEXt</span></a> or <a href="#11zTXt"><span class=
"chunk">zTXt</span></a> chunk with a suitable keyword to identify
the type of information. For textual information that is not
representable in Latin-1 but which can be represented in UTF-8,
use an <a href="#11iTXt"><span class="chunk">iTXt</span></a>
chunk with a suitable keyword.</li>
<li>Group mutually dependent ancillary information into a single
chunk. This avoids the need to introduce chunk ordering
relationships.</li>
<li>Avoid defining private critical chunks.</li>
</ol>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1 class="Annex"><a name="C-GammaAppendix">Annex C</a></h1>
<p class="Annex">(informative)</p>
<h1 id="gammachromaticity" class="Annex">Gamma and chromaticity</h1>
<p>Gamma is a numerical parameter used to describe approximations
to certain non-linear transfer functions encountered in image
capture and reproduction. Gamma is the exponent in a power law
function. For example the function:</p>
<p><tt>intensity = (voltage +
constant)<sup>exponent</sup></tt></p>
<p>which is used to model the non-linearity of cathode ray tube
(CRT) displays. It is often assumed, as in this International
Standard, that the constant is zero.</p>
<p>For the purposes of this International Standard, it is
convenient to consider five places in a general image pipeline at
which non-linear transfer functions may occur and which may be
modelled by power laws. The characteristic exponent associated
with each is given a specific name.</p>
<table class="Regular" summary=
"This table describes characteristic exponents">
<tr>
<td class="Regular"><tt>input_exponent</tt> </td>
<td class="Regular">the exponent of the image sensor.</td>
</tr>
<tr>
<td class="Regular"><tt>encoding_exponent</tt> </td>
<td class="Regular">the exponent of any transfer function performed by the
process or device writing the datastream.</td>
</tr>
<tr>
<td class="Regular"><tt>decoding_exponent</tt> </td>
<td class="Regular">the exponent of any transfer function performed by the
software reading the image datastream.</td>
</tr>
<tr>
<td class="Regular"><tt>LUT_exponent</tt> </td>
<td class="Regular">the exponent of the transfer function applied between the
frame buffer and the display device (typically this is applied by
a Look Up Table).</td>
</tr>
<tr>
<td class="Regular"><tt>output_exponent</tt> </td>
<td class="Regular">the exponent of the display device. For a CRT, this is
typically a value close to 2.2.</td>
</tr>
</table>
<p>It is convenient to define some additional entities that
describe some composite transfer functions, or combinations of
stages.</p>
<table class="Regular" summary=
"This table characterises additional entities that are used to describe transfer functions">
<tr>
<td class="Regular"><tt>display_exponent</tt> </td>
<td class="Regular">exponent of the transfer function applied between the frame
buffer and the display surface of the display device.<br class="xhtml" />
<tt>display_exponent = LUT_exponent * output_exponent</tt> </td>
</tr>
<tr>
<td class="Regular"><tt>gamma</tt> </td>
<td class="Regular">exponent of the function mapping display output intensity to
samples in the PNG datastream.<br class="xhtml" />
<tt>gamma = 1.0 / (decoding_exponent * display_exponent)</tt>
</td>
</tr>
<tr>
<td class="Regular"><tt>end_to_end_exponent</tt> </td>
<td class="Regular">the exponent of the function mapping image sensor input
intensity to display output intensity. This is generally a value
in the range 1.0 to 1.5.</td>
</tr>
</table>
<p>The PNG <a href="#11gAMA"><span class="chunk">gAMA</span></a>
chunk is used to record the gamma value. This information may be
used by decoders together with additional information about the
display environment in order to achieve, or approximate, the
desired display output.</p>
<p>Additional information about this subject may be found in the
references <a href="#G-GAMMA-TUTORIAL"><span class=
"bibref">[GAMMA-TUTORIAL]</span></a>, <a href=
"#G-GAMMA-FAQ"><span class="bibref">[GAMMA-FAQ]</span></a>, and
<a href="#G-POYNTON"><span class="bibref">[POYNTON]</span></a>
(especially chapter 6).</p>
<p>Background information about chromaticity and colour spaces
may be found in references <a href="#G-COLOUR-TUTORIAL"><span
class="bibref">[COLOUR-TUTORIAL]</span></a>, <a href=
"#G-COLOUR-FAQ"><span class="bibref">[COLOUR-FAQ]</span></a>, <a
href="#G-HALL"><span class="bibref">[HALL]</span></a>, <a href=
"#G-KASSON"><span class="bibref">[KASSON]</span></a>, <a href=
"#G-LILLEY"><span class="bibref">[LILLEY]</span></a>, <a href=
"#G-STONE"><span class="bibref">[STONE]</span></a>, and <a href=
"#G-TRAVIS"><span class="bibref">[TRAVIS]</span></a>.</p>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1 class="Annex"><a name="D-CRCAppendix">Annex D</a></h1>
<p class="Annex">(informative)</p>
<h1 id="samplecrc" class="Annex">Sample Cyclic Redundancy Code
implementation</h1>
<p>The following sample code represents a practical
implementation of the CRC (Cyclic Redundancy Check) employed in
PNG chunks. (See also ISO 3309 <a href="#2-ISO-3309"><span class=
"NormRef">[ISO-3309]</span></a> or ITU-T V.42 <a href=
"#G-ITU-T-V42"><span class="bibref">[ITU-T-V42]</span></a> for a
formal specification.)</p>
<p>The sample code is in the ISO C <a href="#2-ISO-9899"><span
class="NormRef">[ISO-9899]</span></a> programming language. The
hints in <a href="#D-tabled1"><span class="tabref">Table
D.1</span></a> may help non-C users to read the code more
easily.</p>
<table class="Regular" summary=
"This table gives hints for reading the CRC code">
<caption><a name="D-tabled1"><b>Table D.1 — Hints for
reading ISO C code</b></a></caption>
<tr>
<td class="Regular"><tt>&</tt> </td>
<td class="Regular">Bitwise AND operator.</td>
</tr>
<tr>
<td class="Regular"><tt>^</tt> </td>
<td class="Regular">Bitwise exclusive-OR operator.</td>
</tr>
<tr>
<td class="Regular"><tt>>></tt> </td>
<td class="Regular">Bitwise right shift operator. When applied to an unsigned
quantity, as here, right shift inserts zeroes at the left.</td>
</tr>
<tr>
<td class="Regular"><tt>!</tt> </td>
<td class="Regular">Logical NOT operator.</td>
</tr>
<tr>
<td class="Regular"><tt>++</tt> </td>
<td class="Regular">"<tt>n++</tt>" increments the variable <tt>n</tt>. In "for"
loops, it is applied after the variable is tested.</td>
</tr>
<tr>
<td class="Regular"><tt>0xNNN</tt> </td>
<td class="Regular"><tt>0x</tt> introduces a hexadecimal (base 16) constant.
Suffix <tt>L</tt> indicates a long value (at least 32 bits).</td>
</tr>
</table>
<hr class="xhtml" />
<pre>
/* Table of CRCs of all 8-bit messages. */
unsigned long crc_table[256];
/* Flag: has the table been computed? Initially false. */
int crc_table_computed = 0;
/* Make the table for a fast CRC. */
void make_crc_table(void)
{
unsigned long c;
int n, k;
for (n = 0; n < 256; n++) {
c = (unsigned long) n;
for (k = 0; k < 8; k++) {
if (c & 1)
c = 0xedb88320L ^ (c >> 1);
else
c = c >> 1;
}
crc_table[n] = c;
}
crc_table_computed = 1;
}
</pre>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<pre>
/* Update a running CRC with the bytes buf[0..len-1]--the CRC
should be initialized to all 1's, and the transmitted value
is the 1's complement of the final running CRC (see the
crc() routine below). */
unsigned long update_crc(unsigned long crc, unsigned char *buf,
int len)
{
unsigned long c = crc;
int n;
if (!crc_table_computed)
make_crc_table();
for (n = 0; n < len; n++) {
c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
}
return c;
}
/* Return the CRC of the bytes buf[0..len-1]. */
unsigned long crc(unsigned char *buf, int len)
{
return update_crc(0xffffffffL, buf, len) ^ 0xffffffffL;
}
</pre>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1 class="Annex"><a name="E-Resources">Annex E</a></h1>
<p class="Annex">(informative)</p>
<h1 id="onlineresources" class="Annex">Online resources</h1>
<h2><a name="E-Intro">Introduction</a></h2>
<p>This annex gives the locations of some Internet resources for
PNG software developers. By the nature of the Internet, the list
is incomplete and subject to change.</p>
<h2><a name="E-Archive-sites">Archive sites</a></h2>
<p>This International Standard can be found at
<a href="http://www.w3.org/TR/2003/REC-PNG-20031110/index.html"
><code>http://www.w3.org/TR/2003/REC-PNG-20031110/index.html</code></a>.</p>
<h2><a name="E-icc-profile-specs">ICC profile
specifications</a></h2>
<p>ICC profile specifications are available at: <a href=
"http://www.color.org/"><code>http://www.color.org/</code></a></p>
<h2><a name="E-PNG-home-page">PNG web site</a></h2>
<p>There is a World Wide Web site for PNG at <a href=
"http://www.libpng.org/pub/png/"><code>http://www.libpng.org/pub/png/</code></a>.
This page is a central location for current information about PNG
and PNG-related tools.</p>
<p>Additional documentation and portable C code for deflate,
inflate, and an optimized implementation of the CRC algorithm are
available from the zlib web site,
<a href=
"http://www.zlib.org/"><code>http://www.zlib.org/</code></a>.</p>
<h2><a name="E-Sample-implementation">Sample implementation and
test images</a></h2>
<p>A sample implementation in portable C, <strong>libpng</strong>, is
available at <a href=
"http://www.libpng.org/pub/png/libpng.html"><code>http://www.libpng.org/pub/png/libpng.html</code></a>.
Sample viewer and encoder applications of libpng are available at
<a href=
"http://www.libpng.org/pub/png/book/sources.html"><code>http://www.libpng.org/pub/png/book/sources.html</code></a>
and are described in detail in <i>PNG: The Definitive Guide</i>
<a href="#G-ROELOFS">[ROELOFS]</a>. Test images can also be
accessed from the PNG web site.</p>
<h2><a name="E-Email">Electronic mail</a></h2>
<p>Queries concerning PNG developments may be addressed to <a href=
"mailto:png-group@w3.org"><tt>png-group@w3.org</tt></a>.
<!-- ************Page Break******************* -->
</p>
<!-- ************Page Break******************* -->
<h1 class="Annex"><a name="F-Relationship">Annex F</a></h1>
<p class="Annex">(informative)</p>
<h1 id="relationshiptofirstedition" class="Annex">Relationship to W3C PNG</h1>
<p>This International Standard is strongly based on W3C
Recommendation PNG Specification Version 1.0 <a href=
"#G-PNG-1.0">[PNG-1.0]</a> which was reviewed by W3C members,
approved as a W3C Recommendation, and published in October 1996
according to the established W3C process. Subsequent amendments
to the PNG Specification have also been incorporated into this
International Standard <a href="#G-PNG-1.0">[PNG-1.1]</a>, <a
href="#G-PNG-1.0">[PNG-1.2]</a>.</p>
<p>A complete review of the document has been done by ISO/IEC/JTC
1/SC 24 in collaboration with W3C in order to transform this
recommendation into an ISO/IEC international standard. A major
design goal during this review was to avoid changes that will
invalidate existing files, editors, or viewers that conform to
W3C Recommendation PNG Specification Version 1.0.</p>
<p>The W3C PNG Recommendation was developed with major
contribution from the following people.</p>
<h2><a name="F-Editor10">Editor (Version 1.0)</a></h2>
<p>Thomas Boutell, <span class="email">boutell @ boutell.com</span></p>
<h2><a name="F-Editor12">Editor (Versions 1.1 and 1.2)</a></h2>
<p>Glenn Randers-Pehrson, <span class="email">randeg @ alum.rpi.edu</span></p>
<h2><a name="F-ContribEditor10">Contributing Editor (Version
1.0)</a></h2>
<p>Tom Lane, <span class="email">tgl @ sss.pgh.pa.us</span></p>
<h2><a name="F-ContribEditor12">Contributing Editor (Versions 1.1
and 1.2)</a></h2>
<p>Adam M. Costello, <span class="email">png-spec.amc @ nicemice.net</span></p>
<h2><a name="F-Authors">Authors (Versions 1.0, 1.1, and 1.2
combined)</a></h2>
<p><strong>Authors' names are presented in alphabetical
order.</strong></p>
<ul>
<li><a href="http://www.alumni.caltech.edu/~madler/">Mark Adler</a>,
<span class="email">madler @ alumni.caltech.edu</span></li>
<li><a href="http://www.boutell.com/boutell/">Thomas Boutell</a>,
<span class="email">boutell @ boutell.com</span></li>
<li>John Bowler, <span class="mail">jbowler @ acm.org</span></li>
<li><a href="http://www.df.lth.se/~cb/">Christian Brunschen</a>,
<span class="email">cb @ brunschen.com</span></li>
<li><a href="http://www.nicemice.net/amc/">Adam M.
Costello</a>, <span class=
"email">png-spec.amc @ nicemice.net</span></li>
<li><a href="http://www.piclab.com/">Lee Daniel Crocker</a>,
<span class="email">lee @ piclab.com</span></li>
<li><a href=
"http://www-mddsp.enel.ucalgary.ca/People/adilger/">Andreas
Dilger</a>, <span class=
"email">adilger @ turbolabs.com</span></li>
<li><a href="http://www.fromme.com/">Oliver Fromme</a>, <span
class="email">oliver @ fromme.com</span></li>
<li><a href="http://www.teaser.fr/~jlgailly/">Jean-loup
Gailly</a>, <span class="email">jloup @ gzip.org</span></li>
<li>Chris Herborth, <span class=
"email">chrish @ pobox.com</span></li>
<li>Alex Jakulin, <span class=
"email">jakulin @ acm.org</span></li>
<li>Neal Kettler, <span class=
"email">neal @ westwood.com</span></li>
<li>Tom Lane, <span class="email">tgl @ sss.pgh.pa.us</span></li>
<li>Alexander Lehmann, <span class=
"email">lehmann @ usa.net</span></li>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<li><a href="http://www.w3.org/People/chris/">Chris Lilley</a>,
<span class="email">chris @ w3.org</span></li>
<li>Dave Martindale, <span class=
"email">davem @ cs.ubc.ca</span></li>
<li>Owen Mortensen, <span class="email">ojm @ acm.org</span></li>
<li>Keith S. Pickens, <span class=
"email">ksp @ rice.edu</span></li>
<li><a href="http://www.users.qwest.net/~lionlad/">Robert P. Poole</a>, <span class=
"email">lionlad @ qwest.net</span></li>
<li>Glenn Randers-Pehrson, <span class=
"email">randeg @ alum.rpi.edu</span></li>
<li><a href="http://pobox.com/~newt/">Greg Roelofs</a>, <span
class="email">newt @ pobox.com</span></li>
<li><a href="http://www.schaik.com/">Willem van Schaik</a>, <span
class="email">willem @ schaik.com</span></li>
<li>Guy Schalnat, <span class=
"email">gschal @ infinet.com</span></li>
<li>Paul Schmidt, <span class=
"email">pschmidt @ photodex.com</span></li>
<li>Michael Stokes, <span class=
"email">mistokes @ microsoft.com</span></li>
<li>Tim Wegner, <span class=
"email">twegner @ phoenix.net</span></li>
<li>Jeremy Wohl, <span class=
"email">jeremyw @ evantide.com</span></li>
</ul>
<h2><a name="F-ChangeList">List of changes between W3C
Recommendation PNG Specification Version 1.0 and this
International Standard</a></h2>
<h3><a name="F-EditorialChanges">Editorial changes</a></h3>
<p>The document has been reformatted according to the
requirements of ISO.</p>
<!-- <ol start="1"> --><ol>
<li>A concepts clause has been introduced.</li>
<li>Conformance for datastreams, encoders, decoders, and editors
has been defined in a conformance clause.</li>
</ol>
<h3><a name="F-TechnicalChanges">Technical changes</a></h3>
<!-- <ol start="1"> --><ol>
<li>New chunk types introduced in PNG version 1.1 and 1.2 have
been incorporated (<a href="#11iCCP"><span class=
"chunk">iCCP</span></a>, <a href="#11iTXt"><span class=
"chunk">iTXt</span></a>, <a href="#11sRGB"><span class=
"chunk">sRGB</span></a>, <a href="#11sPLT"><span class=
"chunk">sPLT</span></a>).
In the
<a href="#11iTXt"><span class=
"chunk">iTXt</span></a>
chunk, the language tag has been updated from RFC 1766 to RFC 3066.</li>
<li>In accord with version 1.1, the scope of the 31-bit limit on
chunk lengths and image dimensions has been extended to apply to
all four-byte unsigned integers. The value -2<sup>31</sup> is not
allowed in signed integers.</li>
<li>The redefinition of <a href="#11gAMA"><span class=
"chunk">gAMA</span></a> to be in terms of the desired display
output rather than the original scene, introduced in PNG version
1.1, has been incorporated.</li>
<li>The use of the <a href="#11PLTE"><span class=
"chunk">PLTE</span></a> and <a href="#11hIST"><span class=
"chunk">hIST</span></a> chunks in non-indexed-colour images has
been discouraged in favour of the <a href="#11sPLT"><span class=
"chunk">sPLT</span></a> chunk.</li>
<li>Some recommendations for PNG encoders, decoders, and editors
have been strengthened to requirements. These changes do not
affect the conformance of PNG datastreams, and do not compromise
interoperability.</li>
<li>The sample depth of channels not mentioned in the <a href=
"#11sBIT"><span class="chunk">sBIT</span></a> chunk has been
clarified.</li>
</ol>
<!-- ************Page Break******************* -->
<!-- ************Page Break******************* -->
<h1 class="Annex"><a name="G-References">Bibliography</a></h1>
<dl>
<dt><a name="G-COLOUR-FAQ">[COLOUR-FAQ]</a></dt>
<dd>Poynton, C., "Colour FAQ".<br class="xhtml" />
<a href=
"http://www.poynton.com/ColorFAQ.html">
<code>http://www.poynton.com/ColorFAQ.html</code></a></dd>
<dt><a name="G-COLOUR-TUTORIAL">[COLOUR-TUTORIAL]</a></dt>
<dd>PNG Group, "Colour tutorial".<br class="xhtml" />
<a href=
"http://www.libpng.org/pub/png/spec/1.2/PNG-ColorAppendix.html"><code>
http://www.libpng.org/pub/png/spec/1.2/PNG-ColorAppendix.html</code></a></dd>
<dt><a name="G-GAMMA-TUTORIAL">[GAMMA-TUTORIAL]</a></dt>
<dd>PNG Group, "Gamma tutorial".<br class="xhtml" />
<a href=
"http://www.libpng.org/pub/png/spec/1.2/PNG-GammaAppendix.html"><code>
http://www.libpng.org/pub/png/spec/1.2/PNG-GammaAppendix.html</code></a></dd>
<dt><a name="G-GAMMA-FAQ">[GAMMA-FAQ]</a></dt>
<dd>Poynton, C., "Gamma FAQ".<br class="xhtml" />
<a href=
"http://www.poynton.com/Poynton-color.html">
<code>http://www.poynton.com/Poynton-color.html</code></a></dd>
<dt><a name="G-HALL">[HALL]</a></dt>
<dd>Hall, Roy, <i>Illumination and Color in Computer Generated
Imagery</i>. Springer-Verlag, New York, 1989. ISBN
0-387-96774-5.</dd>
<dt><a name="G-ICC">[ICC]</a></dt>
<dd>The International Color Consortium.<br class="xhtml" />
<a href=
"http://www.color.org/"><code>http://www.color.org/</code></a></dd>
<dt><a name="G-ISO-3664">[ISO-3664]</a></dt>
<dd>ISO 3664:2000, <i>Viewing conditions — Graphic
technology and photography</i>.</dd>
<dt><a name="G-ITU-R-BT709">[ITU-R-BT709]</a></dt>
<dd>International Telecommunications Union, <i>Basic Parameter
Values for the HDTV Standard for the Studio and for International
Programme Exchange</i>, ITU-R Recommendation BT.709 (formerly CCIR
Rec. 709), 1990.</dd>
<dt><a name="G-ITU-T-V42">[ITU-T-V42]</a></dt>
<dd>International Telecommunications Union, <i>Error-correcting
Procedures for DCEs Using Asynchronous-to-Synchronous
Conversion</i>, ITU-T Recommendation V.42, 1994, Rev. 1.</dd>
<dt><a name="G-KASSON">[KASSON]</a></dt>
<dd>Kasson, J., and W. Plouffe, "An Analysis of Selected Computer
Interchange Color Spaces", <i>ACM Transactions on Graphics</i>,
vol. 11, no. 4 , pp. 373-405, 1992.</dd>
<dt><a name="G-LILLEY">[LILLEY]</a></dt>
<dd>Lilley, C., F. Lin, W.T. Hewitt, and T.L.J. Howard, <i>Colour
in Computer Graphics</i>. CVCP, Sheffield, 1993. ISBN
1-85889-022-5.<br class="xhtml" />
<!-- Also available from<br class="xhtml" />
<a href=
"http://www.man.ac.uk/MVC/training/gravigs/colour/"><code>http://www.man.ac.uk/MVC/training/gravigs/colour/</code></a>
--></dd>
<dt><a name="G-ROELOFS">[ROELOFS]</a></dt>
<dd>Roelofs, G., <i>PNG: The Definitive Guide</i>, O'Reilly &
Associates Inc, Sebastopol, CA, 1999. ISBN 1-56592-542-4.
See also <a href="http://www.libpng.org/pub/png/pngbook.html">
<code>http://www.libpng.org/pub/png/pngbook.html</code>
</a></dd>
<dt><a name="G-PAETH">[PAETH]</a></dt>
<dd>Paeth, A.W., "Image File Compression Made Easy", in
<i>Graphics Gems II</i>, James Arvo, editor. Academic Press, San
Diego, 1991. ISBN 0-12-064480-0.</dd>
<dt><a name="G-PNG-1.0">[PNG-1.0]</a></dt>
<dd>W3C Recommendation, "PNG (Portable Network Graphics)
Specification, Version 1.0", 1996. Available in several formats
from<br class="xhtml" />
<a href=
"http://www.w3.org/TR/REC-png-961001"><code>http://www.w3.org/TR/REC-png-961001</code></a>
and from<br class="xhtml" />
<a href=
"http://www.libpng.org/pub/png/spec/1.0/"><code>http://www.libpng.org/pub/png/spec/1.0/</code></a></dd>
<dt><a name="G-PNG-1.1">[PNG-1.1]</a></dt>
<dd>PNG Development Group, "PNG (Portable Network Graphics)
Specification, Version 1.1", 1999. Available
from<br class="xhtml" />
<a href=
"http://www.libpng.org/pub/png/spec/1.1/"><code>http://www.libpng.org/pub/png/spec/1.1/</code></a></dd>
<dt><a name="G-PNG-1.2">[PNG-1.2]</a></dt>
<dd>PNG Development Group, "PNG (Portable Network Graphics)
Specification, Version 1.2", 1999. Available from<br class="xhtml" />
<a href=
"http://www.libpng.org/pub/png/spec/1.2/"><code>http://www.libpng.org/pub/png/spec/1.2/</code></a></dd>
<dt><a name="G-PNG-EXTENSIONS">[PNG-REGISTER]</a></dt>
<dd>PNG Development Group, "Register of PNG Public Chunks and Keywords".
Available in several formats from:<br class="xhtml" />
<a href=
"http://www.libpng.org/pub/png/spec/register/"><code>http://www.libpng.org/pub/png/spec/register/</code></a></dd>
<dt><a name="G-POSTSCRIPT">[POSTSCRIPT]</a></dt>
<dd>Adobe Systems Incorporated, <i>PostScript Language Reference
Manual</i>, 2nd edition. Addison-Wesley, Reading, 1990. ISBN
0-201-18127-4.</dd>
<dt><a name="G-POYNTON">[POYNTON]</a></dt>
<dd>Poynton, Charles A., <i>A Technical Introduction to Digital
Video</i>. John Wiley and Sons, Inc., New York, 1996. ISBN
0-471-12253-X.</dd>
<dt><a name="G-SMPTE-170M">[SMPTE-170M]</a></dt>
<dd>Society of Motion Picture and Television Engineers,
<i>Television — Composite Analog Video Signal — NTSC
for Studio Applications</i>, SMPTE-170M, 1994.</dd>
<dt><a name="G-STONE">[STONE]</a></dt>
<dd>Stone, M.C., W.B. Cowan, and J.C. Beatty, "Color gamut
mapping and the printing of digital images", <i>ACM Transactions on
Graphics</i>, vol. 7, no. 3, pp. 249-292, 1988.</dd>
<dt><a name="G-TIFF-6.0">[TIFF-6.0]</a></dt>
<dd>TIFF<sup>TM</sup> Revision 6.0, Aldus Corporation, June
1992.</dd>
<dt><a name="G-TRAVIS">[TRAVIS]</a></dt>
<dd>Travis, David, <i>Effective Color Displays — Theory and
Practice</i>. Academic Press, London, 1991. ISBN
0-12-697690-2.</dd>
<dt><a name="G-ZL">[ZL]</a></dt>
<dd>J. Ziv and A. Lempel, "A Universal Algorithm for Sequential
Data Compression", <i>IEEE Transactions on Information
Theory</i>, vol. IT-23, no. 3, pp. 337 - 343, 1977.</dd>
</dl>
<p>Additional documentation and portable C code for deflate,
inflate, and an optimized implementation of the CRC algorithm are
available from the zlib web site,
<a href=
"http://www.zlib.org/"><code>http://www.zlib.org/</code></a>.</p>
</body>
</html>