This file is indexed.

/usr/share/doc/png-definitive-guide/html/chapter11.html is in png-definitive-guide 20060430-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>PNG Options and Extensions (PNG: The Definitive Guide)</TITLE>
<!-- META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1" -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">

<!-- http://www.w3.org/TR/REC-CSS2/box.html -->
<STYLE TYPE="text/css">
  P { margin-bottom: 0em }
  UL {
    margin-bottom: 0em;
    margin-top: 0em;
    list-style: disc;
  }
  LI {
    padding: 0px 0px 0px 0px;
    margin: 0px 0px 0px 0px;
  }
</STYLE>

<LINK REV="made" HREF="http://pobox.com/~newt/greg_contact.html">
<!--  Copyright (c) 1999 O'Reilly and Associates.  -->
<!--  Copyright (c) 2002-2006 Greg Roelofs.  -->
</HEAD>

<body bgcolor="#ffffff" text="#000000">


<hr> <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -->

<a href="chapter10.html"><img width=24 height=13 border=0 align="left"
 src="images/prev.png" alt="&lt;-"></a>

<a href="chapter12.html"><img width=24 height=13 border=0 align="right"
 src="images/next.png" alt="-&gt;"></a>

<div align="center">
  <a href="chapter10.html"><font size="-1" color="#000000"
   ><b>PREVIOUS</b></font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
     href="toc.html"><font size="-1" color="#000000"
   ><b>CONTENTS</b></font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
     href="chapter12.html"><font size="-1" color="#000000"
   ><b>NEXT</b></font></a>
</div>

<hr> <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -->


<h1 class="chapter">Chapter 11. PNG Options and Extensions</h1>

<div class="htmltoc"><h4 class="tochead">Contents:</h4><p>
<a href="#png.ch11.div.1">11.1. Background Color (bKGD)</a><br />
<a href="#png.ch11.div.2">11.2. Timestamp (tIME)</a><br />
<a href="#png.ch11.div.3">11.3. Latin-1 Text Annotations (tEXt, zTXt)</a><br />
<a href="#png.ch11.div.4">11.4. International Text Annotations (iTXt)</a><br />
<a href="#png.ch11.div.5">11.5. Histogram (hIST)</a><br />
<a href="#png.ch11.div.6">11.6. Suggested Palette (sPLT)</a><br />
<a href="#png.ch11.div.7">11.7. Significant Bits (sBIT)</a><br />
<a href="#png.ch11.div.8">11.8. Physical Pixel Dimensions (pHYs)</a><br />
<a href="#png.ch11.div.9">11.9. Physical Scale (sCAL)</a><br />
<a href="#png.ch11.div.10">11.10. Image Offset (oFFs)</a><br />
<a href="#png.ch11.div.11">11.11. Pixel Calibration (pCAL)</a><br />
<a href="#png.ch11.div.12">11.12. Fractal Parameters (fRAc)</a><br />
<a href="#png.ch11.div.13">11.13. GIF Conversion Info (gIFg, gIFx)</a><br />
<a href="#png.ch11.div.14">11.14. GIF Plain Text (gIFt)</a><br />
<a href="#png.ch11.div.15">11.15. Other Chunks</a><br />
</p></div>


<p>In addition to the core chunk types described thus far, the Portable Network
Graphics format supports a whole host of optional chunks for various purposes,
from text annotations to conversion information. These are described
in the following sections,
very roughly in order of importance to the average user.</p>


<div class="refentry">
<a name="png.ch11.div.1" />
<h2 class="sect1"><i>Background Color (bKGD)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; PNG Specification
   <li>Location: &nbsp; After PLTE, before first IDAT
   <li>Multiple: &nbsp; no
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->

<p>
<a name="INDEX-821" />
<a name="INDEX-822" />
<a name="INDEX-823" />
In some applications, notably web browsers, there is a natural background
surrounding all images,  against which images can be composited with transparency
information. But standalone image viewers typically have no preferred
background color or pattern and usually default to black, which may not be
appropriate for some images. PNG therefore supports the concept of a preferred
background color that can be used if nothing better is available.</p>


<p>The bKGD chunk is used for this purpose. Just as with the
transparency chunk, tRNS (see <a href="chapter08.html">Chapter 8, "PNG Basics"</a>), the format
of bKGD depends on the image type. For palette-based images it
contains a single byte, whose value is the palette index of the color
to be used for the background. For grayscale images, with or without
alpha, the chunk contains a 2-byte, unscaled gray value, just as
with tRNS--that is, the maximum allowed value is 2<sup class="superscript"><em class="emphasis">bit depth</em></sup>-1,
even though it is stored as a 16-bit integer. And for truecolor images, the
background chunk is exactly analogous to the grayscale version except that it
contains three 16-bit, unscaled values representing the red, green, and blue
components of the background color. There is no requirement in any of the
three cases that the background color be present in the actual image data.</p>


<p>Note that colored backgrounds are not supported in grayscale images; while
this is certainly a restriction, it appears not to be a particularly serious
one, to judge by the lack of public comment to date. Note also that the
background color should always be considered fully opaque, even if it happens
to match a color marked by the tRNS chunk as partly or fully transparent.</p>


</div>


<div class="refentry">
<a name="png.ch11.div.2" />
<h2 class="sect1"><i>Timestamp (tIME)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; PNG Specification
   <li>Location: &nbsp; anywhere<a href="#FOOTNOTE-85">[85]</a>
   <li>Multiple: &nbsp; no
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->

<blockquote class="footnote">
<a name="FOOTNOTE-85" /><p>[85] Chunks with no explicit restrictions (``anywhere'') are nonetheless
implicitly constrained to come after the PNG signature and IHDR chunk,
before the IEND chunk, and not to fall between multiple IDAT chunks.</p>
</blockquote>

<p>
<a name="INDEX-824" />		<!-- .XX "timestamp" -->
<a name="INDEX-825" />		<!-- .XX "modification time" -->
<a name="INDEX-826" />		<!-- .XX "tIME chunk" -->
<!-- <a name="INDEX-827" />	GRR DUPLICATE INDEX (see below) -->
The timestamp chunk provides a way for the author (or image-editing software)
to record the time and date the image was last modified. The chunk contains
7 bytes of data, shown in
<a href="#png.ch11.tbl.1">Table 11-1</a>.
</p>


<a name="png.ch11.tbl.1" />
<div class="table" align="center">

<p>
<table width="502" border="0">
  <tr>
    <td>
      <b class="emphasis-bold">Table 11-1.</b>
      <i>tIME Chunk</i>
    </td>
  </tr>
</table>
</p>

<p>
<table width="502" border="1">

<tr>
<td><b class="emphasis-bold">Field</b></td>
<td><b class="emphasis-bold">Length and Valid Range
<?x-space 2p?><?x-space 2p?></b></td>
</tr>

<tr>
<td>Year</td>
<td>2 bytes (0-65,535)</td>
</tr>

<tr>
<td>Month</td>
<td>1 byte (1-12)</td>
</tr>

<tr>
<td>Day</td>
<td>1 byte (1-31)</td>
</tr>

<tr>
<td>Hour</td>
<td>1 byte (0-23)</td>
</tr>

<tr>
<td>Minute</td>
<td>1 byte (0-59)</td>
</tr>

<tr>
<td>Second</td>
<td>1 byte (0-60)</td>
</tr>

<?x-space 5p?>
</table>
</p>
</div>


<p><a name="INDEX-827" />
As this book is being written before the Third Millennium begins, the first
thing to notice is that PNG is not merely Y2K-compliant, but also Y2038,
Y10K, and pretty much everything else on up through
Y65K.<a href="#FOOTNOTE-86">[86]</a>
In addition, note that the seconds field is permitted to vary between
0 and 60; this allows for leap seconds, of which there have been
roughly two dozen since 1972. (There has never been more than one
leap second in any given minute, however.)
</p>

<blockquote class="footnote">
<a name="FOOTNOTE-86" /><p>[86] Presumably humanity will have come up with another image format or
two by then.</p>
</blockquote>


<p>On a less technical level, why does tIME store the modification time rather
than creation time? On the face of it, creation time would seem like a more
useful piece of information, and indeed, it is explicitly supported in PNG
via the text chunks described later. But whereas modification time is a
well-defined quantity--even a computer program can determine whether the
image data has been modified--creation time is ambiguous. If a scanned
photograph of the Mona Lisa is converted to PNG format, is its creation time
the time of image conversion, the time of the original scan, the time the
photograph was taken, or even the time the painting was created? The case
becomes even muddier if an artist creates a digital work partly based on the
scanned image. So creation time is supported via one or more text chunks,
which can also describe in precisely what sense the image was created.</p>

</div>


<div class="refentry">
<a name="png.ch11.div.3" />
<h2 class="sect1"><i>Latin-1 Text Annotations (tEXt, zTXt)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; PNG Specification
   <li>Location: &nbsp; anywhere
   <li>Multiple: &nbsp; yes
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->

<p>
<a name="INDEX-828" />
<a name="INDEX-829" />
<a name="INDEX-830" />
<a name="INDEX-831" />
That brings us to PNG's original text chunks, which are perhaps its most
popular nonessential chunks. Regardless of how many words a picture is
worth, it is often useful or necessary to add a few more in order to record
pertinent information like title and author, store requisite legal
notices such as a copyright or disclaimer, or merely to transfer text
from one image to another.</p>


<p>PNG supports two types of Latin-1-based text chunks, uncompressed
(tEXt) and compressed (zTXt). There is also a new Unicode-based chunk
(iTXt) that I'll discuss next. For the first two, the format is
basically the same: an uncompressed keyword or key phrase, a null
(zero) byte, and the actual text. In zTXt the text is compressed; the
first byte after the null indicates the compression method, for which
only deflate is currently defined (method zero). The remainder is the
compressed stream, which for method zero must be in zlib 1.x format,
just as for image data. (The zlib 1.x format is described by revision
3.3 of the zlib specification, which is available from
<a href="http://www.zlib.org/zlib_docs.html">http://www.zlib.org/zlib_docs.html</a>/.)
<a name="INDEX-832" />
</p>


<p>Both keyword and raw text should be encoded with the Latin-1 (ISO/IEC 8859-1)
character set; neither may contain null bytes. Since the keyword is intended
to be recognizable by both humans
and computer programs, additional restrictions are placed on it: it may not
contain leading, trailing, or consecutive spaces, and it is restricted to
characters in the range 32-126 and 161-255 (which, in particular, rules
out both control characters and the nonbreaking space, decimal value 160).
The only other restriction on the main text of the chunk is that newlines
should be in Unix format, i.e., represented by a single line-feed character
(decimal value 10).</p>


<p>I mentioned in <a href="chapter07.html">Chapter 7, "History of the Portable Network Graphics Format"</a>, that the Unicode UTF-8 character set was one of the
items in the design of PNG that was voted down. In retrospect this was,
perhaps, a lamentable decision; it was finally addressed early in 1999
<a name="INDEX-833" />
<a name="INDEX-834" />
<a name="INDEX-835" />
<a name="INDEX-836" />with the iTXt chunk. But at the time, UTF-8 was very new and had not been
extensively tested in the field. In particular, it had little or no
operating-system support and no support in standard programming libraries,
either for encoding and decoding or for the translation and display of UTF-8
characters in the native character set(s) of existing systems. Since PNG's
design goals included both the use of well-tested technologies and the
avoidance of undue burdens on developers of PNG applications, support for
UTF-8 was dropped in favor of the more familiar Latin-1 character set.</p>


<p>The following list summarizes all of the keywords that are either
included in the specification itself or officially registered as extensions
to the spec:</p>


<dl>
<dt><b><em class="emphasis">Author</em></b></dt><dd><p><a name="INDEX-837" />The name of the author of the image. If the original image were a painting or
other nonelectronic medium, both the original artist and the person who
scanned the image might be listed.</p></dd>



<dt><b><em class="emphasis">Title</em></b></dt><dd><p><a name="INDEX-838" />A one-line title or caption. Longer captions should generally
use the Description keyword, but see the end of this section for an unofficial alternative.</p></dd>



<dt><b><em class="emphasis">Description</em></b></dt><dd><p><a name="INDEX-839" />A longer description of or caption for the image, perhaps including details
about the tools and settings used; the name, age, and/or location of the
subject matter; or the mood the artist was trying to convey. See also the
Software and Source keywords.</p></dd>



<dt><b><em class="emphasis">Creation Time</em></b></dt><dd><p><a name="INDEX-840" />The time the image was created, in whatever sense is most appropriate.
The recommended format is that prescribed by Internet RFC 822 (Section 5), as
amended by RFC 1123 (Section 5.2.14); specifically:
</p></dd>

</dl>


<blockquote><pre class="code">day month year hour:minute timezone</pre></blockquote>


<p>where <b class="emphasis-bold">day</b> is either one or two digits; <b class="emphasis-bold">month</b> is a three-letter
English abbreviation such as <b class="emphasis-bold">Jun</b>; <b class="emphasis-bold">year</b> is two or four digits
(though the latter is strongly recommended); <b class="emphasis-bold">hour</b> and <b class="emphasis-bold">minute</b>
are two digits each; and <b class="emphasis-bold">timezone</b> is either a three-letter abbreviation
(e.g., PST for Pacific Standard Time), or a one-letter U.S. military designation,
or a four-digit number with a leading positive or negative sign indicating the
hour:minute offset from Coordinated Universal Time (e.g., -0800 for Pacific
Standard Time, which is eight hours and zero minutes earlier than UTC). In
addition, the entire string may optionally be preceded by a <b class="emphasis-bold">weekday</b>
field, where <b class="emphasis-bold">weekday</b> is a three-letter English abbreviation (e.g.,
<b class="emphasis-bold">Fri</b>). A colon and two-digit <b class="emphasis-bold">seconds</b> field may also be
appended to the time (that is, <b class="emphasis-bold">hour:minute:second</b>). Note that this
is merely a recommendation; strings such as ``circa 1492'' are allowed, as is
explanatory text following an RFC-style date string.</p>


<dl>
<dt><b><em class="emphasis">Copyright</em></b></dt><dd><p><a name="INDEX-841" />The legal copyright notice for the image. For example, ``Copyright 1999
by Greg Roelofs. This image may be freely used and distributed provided that
it is not modified in any way and that this notice remains intact.''</p></dd>



<dt><b><em class="emphasis">Disclaimer</em></b></dt><dd><p><a name="INDEX-842" />
<a name="INDEX-843" />A legal disclaimer notice for the image. This might include a company's
standard boilerplate on all copyrighted works; in particular, it might be
lengthy enough to store in a compressed (zTXt) chunk, while the copyright
notice remains uncompressed.</p></dd>



<dt><b><em class="emphasis">Warning</em></b></dt><dd><p><a name="INDEX-844" />A warning about the content or effects of the image. For example, certain
types of popular material may not be suitable for minors, or a random-dot
stereogram (``Magic Eye'' 3D image) may induce headaches in some people.</p></dd>



<dt><b><em class="emphasis">Software</em></b></dt><dd><p><a name="INDEX-845" />The name and possibly the version of the software used to create the image. This
is most often generated automatically, but it need not be. More than one
software application may be listed.</p></dd>



<dt><b><em class="emphasis">Source</em></b></dt><dd><p><a name="INDEX-846" />Information about the device used to generate the image, such as a digital
camera or a scanner.</p></dd>



<dt><b><em class="emphasis">Comment</em></b></dt><dd><p><a name="INDEX-847" />A miscellaneous comment, often converted from a GIF comment (which lacks
keywords).</p></dd>

</dl>


<p>In addition to these official keywords, one of the technical
reviewers of this book and I have been known to make use of a few unofficial
<a name="INDEX-848" />keywords. The <B>Caption</B> keyword is used to provide a brief description
of an image that is more specifically tailored for use as a
publishable caption than the generic Description keyword; it is
also generally lengthier than is appropriate for the Title keyword.
<a name="INDEX-849" />The <B>E-mail</B> keyword stores the email address of the author in standard
Internet format (RFC 822, Section 6, as amended by RFC 1123, Sections
5.2.15 through 5.2.19); for example,
<em class="emphasis">roelofs@pobox.com</em>&nbsp;.  And
<a name="INDEX-850" />the <B>URL</B> keyword is for a standard WWW Uniform Resource Locator (RFC
2068, Section 3.2); for example,
<a href="http://www.oreilly.com/">http://www.oreilly.com/</a>&nbsp;. If
the URL is reasonably self-explanatory, it is recommended that the
chunk consist of the single URL and nothing else, but this is not a
requirement. Multiple URLs should be separated by newline characters.
Note that spaces and other white space (tabs, newlines, and so forth)
are considered unsafe by the URL standard and therefore must be
escaped within a conforming URL. For example, a space character must
be encoded as <b class="emphasis-bold">%20</b>.  This allows easy parsing
of optional explanatory text after a URL:
<?x-need 10?>the URL ends when the first white space
(space, tab, or newline) is encountered.
</p>

</div>


<div class="refentry">
<a name="png.ch11.div.4" />
<h2 class="sect1"><i>International Text Annotations (iTXt)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; PNG Extensions&nbsp;<a href="#FOOTNOTE-87">[87]</a>
   <li>Location: &nbsp; anywhere
   <li>Multiple: &nbsp; yes
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->

<blockquote class="footnote">
<a name="FOOTNOTE-87" /><p>[87] As this book went to press, the iTXt chunk had
just been approved for
inclusion in the core PNG specification, but it was temporarily placed in
the PNG extensions document pending completion and approval of extensive
ISO-related changes to the core spec. (Note that these changes are almost
entirely of an organizational or editorial nature; the technical content of
the specification is expected to change only minimally from version
1.1.). Version 1.2 of the PNG specification is expected around mid-1999 or
later. In the meantime, iTXt can be found in version 1.1.1 (and possibly
later versions) of the extensions document, which is available electronically
from <a href="http://www.libpng.org/pub/png/pngdocs.html">http://www.libpng.org/pub/png/pngdocs.html</a>.
</p>
</blockquote>


<p>
<a name="INDEX-851" />
<a name="INDEX-852" />
<a name="INDEX-853" />
<a name="INDEX-854" />
<a name="INDEX-855" />
I previously noted that, as of early 1999, PNG was in the midst of
joint ISO/IEC standardization. One of the technical issues in the
first Committee Draft vote was the lack of support for non-Western
languages, specifically in the text chunks. In fact, the PNG
Development Group had already discussed a more general text chunk in
mid-1998, but its vote was deferred until there was external interest
in it. The ISO comments from Japan and the United States clearly fell
into the category of external interest, however, so the iTXt was
voted on and approved as part of the PNG specification in early
February 1999.</p>


<p>The layout of iTXt is a generalization of tEXt and zTXt, as shown in
<a href="#png.ch11.tbl.2">Table 11-2</a>.
</p>


<a name="png.ch11.tbl.2" />
<div class="table" align="center">

<p>
<table width="502" border="0">
  <tr>
    <td>
      <b class="emphasis-bold">Table 11-2.</b>
      <i>iTXt Chunk</i>
    </td>
  </tr>
</table>
</p>

<p>
<table width="502" border="1">

<tr>
<td><b class="emphasis-bold">Field</b></td>
<td><b class="emphasis-bold">Length and Valid Range
<?x-space 2p?><?x-space 2p?></b></td>
</tr>


<tr>
<td>Keyword</td>
<td>1-79 bytes (Latin-1 text)</td>
</tr>


<tr>
<td>Null separator</td>
<td>1 byte (0)</td>
</tr>


<tr>
<td>Compression flag</td>
<td>1 byte (0, 1)</td>
</tr>


<tr>
<td>Compression method</td>
<td>1 byte (0)</td>
</tr>


<tr>
<td>Language tag</td>
<td><em class="emphasis">k</em> bytes (ASCII text)</td>
</tr>


<tr>
<td>Null separator</td>
<td>1 byte (0)</td>
</tr>


<tr>
<td>Translated keyword</td>
<td><em class="emphasis">m</em> bytes (Unicode UTF-8 text)</td>
</tr>


<tr>
<td>Null separator</td>
<td>1 byte (0)</td>
</tr>


<tr>
<td>Text</td>
<td><em class="emphasis">n</em> bytes (Unicode UTF-8 text)</td>
</tr>


<?x-space 5p?>
</table>
</p>
</div>


<p>The first field is a keyword, with exactly the same restrictions and officially
registered values (Author, Description, and so on) as the tEXt and zTXt chunks.
Latin-1 (ISO/IEC 8859-1) was chosen so that existing PNG source code could
be used without modification to parse and optionally recognize the keyword.</p>


<p>The keyword is followed by a null separator byte and two compression-related
bytes. The first indicates whether the main text is compressed (if its value
is 1) or not (if it's 0). If the text is compressed, the next byte
indicates its compression method, which currently must be zero for the
zlib-encoded deflate algorithm. The two bytes could have been combined,
but for historical reasons relating to the method byte in IHDR, the split
approach was favored.</p>


<p>After the compression bytes is an optional <em class="emphasis">case-insensitive</em> field
indicating the (human) language used in the remaining two text fields. This
is necessary not only to render Unicode text properly but also to allow
decoders to distinguish between multiple iTXt chunks, which may consist of
the same text in different languages--but possibly identical keywords.
Unlike both the keyword and the main text, the language tag is plain ASCII
text (specifically, the ``invariant'' ASCII subset of ISO 646, which is itself
a subset of both Latin-1 and Unicode UTF-8) conforming to Internet Standard
RFC 1766. It consists of hyphen-separated ``words'' of between one and eight
characters each, where the first word is either a two-letter ISO language code
(ISO 639), the letter <em class="emphasis">i</em> for tags registered by the Internet Assigned
Numbers Authority (IANA)<a href="#FOOTNOTE-88">[88]</a>
or the letter <em class="emphasis">x</em> for private tags.
The second ``word'' is interpreted as an ISO 3166 country code if it is
exactly two characters long or as an IANA-registered code if it is between
three and eight characters. Subsequent ``words'' may be anything, as long
as they conform to the general rules. Examples of language tags include
<tt>cn</tt> (Chinese),
<tt>en-US</tt> (American English),
<tt>no-bok</tt> (Norwegian
<!-- <em class="emphasis">bokm<img src="images/U00E5.png" alt="[a-with-circle]" />l</em> or ``book language''), -->
<em class="emphasis">bokm&aring;l</em> or ``book language''),
<tt>i-navajo</tt> (Navajo), and
<tt>x-klingon</tt> (Klingon, from the fictional
Star Trek universe).




</p><blockquote class="footnote">

<a name="FOOTNOTE-88" /><p>[88] As this is written, indications are that IANA will eventually be replaced
by ICANN, the Internet Corporation for Assigned Names and Numbers. This
transition may not occur until 2000, however.</p>
</blockquote>


<p>A null separator byte terminates the language tag, which is followed by an
optional translation of the keyword into the given language. The translated
keyword is represented in the UTF-8 encoding of the Unicode character set,
which is described in the International Standard ISO/IEC 10646-1, in Internet
RFC 2279, and in the Unicode Consortium's reference, <em class="emphasis">The Unicode
Standard</em>. Like the primary keyword, it should not contain any newline
characters, and it is also followed by a null byte.






</p>


<p>The remaining chunk data is the main UTF-8 text, either zlib-compressed or
not, according to the compression flag. Since its length can be determined
from the chunk length, it is not null-terminated. As with the other
two text chunks, newlines should be represented by single line-feed characters
(decimal 10), and all other control characters (1-9, 11-31, and
127-159) are discouraged. Note, however, that UTF-8 <em class="emphasis">encodings</em> may
contain any of the bytes between 128 and 159; what is discouraged is the set
of Unicode characters whose four-byte <em class="emphasis">integer values</em> are 128-159.</p>


<p><a name="INDEX-856" />
<a name="INDEX-857" />That last point is confusing, so perhaps a quick primer on Unicode is in order.
The Unicode <em class="emphasis">character set</em> is a mapping between graphic characters (or
glyphs) and integers. The simplest representation is called UCS-4 and consists
of 4-byte integers, potentially allowing more than two billion characters
to be defined. On top of that are a number of possible transformations or
<em class="emphasis">encodings</em> of the character set; UTF-8 is one of the more popular ones,
encoding 4-byte UCS-4 characters into anywhere from 1 to 8 bytes.
All Unicode characters below 128 are encoded as single bytes in UTF-8, and
because Unicode characters 1-127 are identical to US-ASCII characters
1-127, the Unicode character set (and UTF-8 in particular) may be thought
of as a very large superset of 7-bit ASCII.</p>


<p><a name="INDEX-858" />Multibyte UTF-8 encodings, on the other hand, are composed entirely of byte
values between 128 and 253--which means that bytes 1-9, 11-31, and 127
will never be found in valid UTF-8-encoded text except when representing the
<em class="emphasis">characters</em> 1-9, 11-31, and 127. So about half of the control
characters that are discouraged in iTXt can be detected simply by checking
for those single bytes. The remaining half, characters 128-159, are all
encoded with 2-byte sequences that happen to begin with byte value 194:
194 128 through 194 159. The fact that character 128 is discouraged in
iTXt's UTF-8 text fields therefore means that the 2-byte encoding 194 128
is discouraged, but the 2-byte encoding 195 128 (&Agrave; or ``Latin capital
letter A with grave accent'') is completely acceptable.


</p>

</div>


<div class="refentry">
<a name="png.ch11.div.5" />
<h2 class="sect1"><i>Histogram (hIST)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; PNG Specification
   <li>Location: &nbsp; after PLTE, before first IDAT
   <li>Multiple: &nbsp; no
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->

<p>
<a name="INDEX-859" />
<a name="INDEX-860" />
A histogram is nothing more than a frequency-of-occurrence table, and the
PNG hIST chunk gives the approximate frequencies of occurrence for pixels
of various colors. This information is typically used to decide which
colors are the most important if the system is not capable of displaying
all of them. Rather than force the decoder to count pixels every time the
image is displayed, the histogram places the burden on the encoder, which
performs the task only once.</p>


<p>
<a name="INDEX-861" />
PNG's hIST implementation is tied to the PLTE chunk; if there is no palette,
hIST is not allowed. This and one or two other limitations were later
recognized and addressed by the sPLT chunk, which we'll discuss next; it is
generally favored over hIST, but the latter is smaller, and either may be
used.
The histogram must contain exactly as many entries as PLTE contains,
and each entry is a 16-bit unsigned integer. Since such integers can
only represent numbers in the range 0-65,535 and there may be
millions of pixels of a given color, the histogram entries often must
be scaled and are therefore inexact. The sole exception is the value
zero; it is guaranteed to mean that there are <em class="emphasis">no</em> pixels of the
corresponding color. A nonzero count that would otherwise be scaled
and rounded to zero must instead be rounded up to one.</p>


<p>
<a name="INDEX-862" />
<a name="INDEX-863" />
Truecolor images that include a PLTE chunk as a suggested quantization
are a special case. The histogram counts are dependent on the
algorithm used by the encoder for quantizing the pixels; if the
decoder happens to use a different algorithm, its counts would be
different, too. The upshot is that the histogram is particularly
approximate in this case. Because truecolor images
typically have far more colors than palette entries, the palette
entries that do appear should always represent at least one
pixel; thus there should be no zero counts in the histogram.


<?x-space -4p?></p>

</div>


<div class="refentry">
<a name="png.ch11.div.6" />
<h2 class="sect1"><i>Suggested Palette (sPLT)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; PNG Specification
   <li>Location: &nbsp; before first IDAT
   <li>Multiple: &nbsp; yes
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->

<p>
<a name="INDEX-864" />
<a name="INDEX-865" />
The suggested-palette chunk, sPLT, grew out of an acknowledgment of
some limitations in PNG's PLTE, tRNS, and hIST chunks. I have already
noted that PLTE is allowed only in palette, RGB, and RGBA images and
that hIST is allowed only in images with PLTE; I also noted that tRNS
is disallowed in images with alpha channels, which rules out the use
of PLTE plus tRNS as a suggested gray/alpha or RGBA palette. sPLT
eliminates these restrictions by merging all three of the older chunks
into a general-purpose, suggested-RGBA-palette-plus-histogram
chunk. In addition, sPLT may contain any number of entries (as long as
it doesn't exceed the maximum chunk-size limit of two gigabytes); its
entries may have either 8-bit or 16-bit sample depths; and multiple
sPLT chunks encoding different suggested quantizations are allowed. A
palette-based image may even have an sPLT chunk, perhaps representing
a reduced palette for a particular web browser. The format of sPLT, given in
<a href="#png.ch11.tbl.3">Table 11-3</a>, is straightforward.

</p>


<a name="png.ch11.tbl.3" />
<div class="table" align="center">

<p>
<table width="502" border="0">
  <tr>
    <td>
      <b class="emphasis-bold">Table 11-3.</b>
      <i>sPLT Chunk</i>
    </td>
  </tr>
</table>
</p>

<p>
<table width="502" border="1">

<tr>
<td><b class="emphasis-bold">Field</b></td>
<td><b class="emphasis-bold">Length and Valid Range</b></td>
</tr>

<tr>
<td>Palette name</td>
<td>1-79 bytes (Latin-1 text)</td>
</tr>

<tr>
<td>Null separator</td>
<td>1 byte</td>
</tr>

<tr>
<td>Sample depth</td>
<td>1 byte (8 or 16)</td>
</tr>

<tr>
<td>Red value #1</td>
<td>1 byte (0-255) or 2 bytes (0-65,535)</td>
</tr>

<tr>
<td>Green value #1</td>
<td>1 byte (0-255) or 2 bytes (0-65,535)</td>
</tr>

<tr>
<td>Blue value #1</td>
<td>1 byte (0-255) or 2 bytes (0-65,535)</td>
</tr>

<tr>
<td>Alpha value #1</td>
<td>1 byte (0-255) or 2 bytes (0-65,535)</td>
</tr>

<tr>
<td>Relative frequency #1</td>
<td>2 bytes (0-65,535)</td>
</tr>

<tr>
<td> ...</td>
<td> ...</td>
</tr>

<?x-space 5p?>
</table>
</p>
</div>


<?x-space -2p?><p>
The number of sPLT entries is implicitly given by the size of the chunk and
the sample depth; in the more common case of 8-bit samples, it is obtained
by dividing the chunk size, less the length of the palette name and the two
subsequent bytes, by six. Entries are required to appear in decreasing
order of frequency, but there is no requirement that all of them be different
nor that all of them be used by the image. Furthermore, opaque images may
include nonopaque sPLT entries, grayscale images may include colored
entries, and the sample depth of sPLT is independent of that of the image.</p>


<p><a name="INDEX-866" />
Unlike the suggested practice for PLTE in RGBA images, the red, green, and
blue values in sPLT are neither premultiplied by the alpha values nor
precomposited against a background color. An encoder would still have to
inspect every pixel if it wanted to compute an optimal palette for display
of an RGBA image against a patterned background, but sPLT would enable a
statistical approach based on the background image's own histogram in
that case. And for solid backgrounds, sPLT provides the means to build
an optimal palette regardless of the choice of background color.</p>


<p><a name="INDEX-867" />
As with the hIST chunk, frequency values are scaled to the range 0-65,535
and therefore are likely to be approximate. Inflating ``important'' colors
based on the image's subject matter is allowed in sPLT, too. But whereas hIST
requires a 0 frequency to correspond exactly to 0 pixels, sPLT allows
the 0 value to represent infrequently used or unimportant colors. If all
of the frequency values are 0, however, the histogram is undefined.</p>


<p>Note that multiple sPLT chunks are required to have different palette names.</p>

</div>


<div class="refentry">
<a name="png.ch11.div.7" />
<h2 class="sect1"><i>Significant Bits (sBIT)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; PNG Specification
   <li>Location: &nbsp; before PLTE and first IDAT
   <li>Multiple: &nbsp; no
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->


<p>
<a name="INDEX-868" />
<a name="INDEX-869" />
The significant-bits chunk is used to indicate the nature of the source
data in cases in which storing it in PNG form required a conversion. For
example, gray pixels in medical images are often 12 bits deep, but PNG
requires them to be scaled up to 16 bits for portability. Scaling the pixels
does not alter the fact that they contain only 12 bits of real information,
and the sBIT chunk stores this fact in a PNG file.</p>


<p>As with several other PNG chunks, the format of sBIT depends on the image
type. Grayscale images are the simplest; sBIT then contains a single byte
indicating the number of significant bits in the source data--in the
preceding example, 12. For grayscale images with an alpha channel, sBIT contains
2 bytes, one for the gray channel and one for alpha; RGB images require
3  bytes, and RGBA images require 4. Palette-based images are treated
like RGB except that the sBIT information refers to the palette entries, and
the palette's effective sample depth is always 8, regardless of how many
bits are used to index the palette. Note that the number of significant bits
for any given channel must be greater than zero and less than or equal to the
sample depth.</p>


<p>Ordinary PNG decoders need not worry about sBIT, but those that wish to
recover the original image data can do so by right-shifting each image
sample to leave only the number of bits indicated by sBIT. This implies
that the scaling procedure used by the PNG encoder must not change the original
bits; it can only append low-order bits to each sample.</p>

</div>


<div class="refentry">
<a name="png.ch11.div.8" />
<h2 class="sect1"><i>Physical Pixel Dimensions (pHYs)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; PNG Specification
   <li>Location: &nbsp; before first IDAT
   <li>Multiple: &nbsp; no
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->

<p>
<a name="INDEX-870" />
<a name="INDEX-871" />
<a name="INDEX-872" />
The pHYs chunk encodes the absolute or relative dimensions of pixels.
For example, an image scanned at 600 dots per inch has pixels with known,
absolute sizes--namely, one six-hundredth of an inch in both
<em class="emphasis">x</em> and <em class="emphasis">y</em>
directions. Alternatively, an image created on a 1280&nbsp;&times; 1024 display
will have nonsquare pixels, and the relative dimensions of each pixel,
<a name="INDEX-873" />also referred to as the <em class="emphasis">aspect ratio</em>, may be stored so the image
can be displayed as it was intended to be seen.
</p>


<p>The layout of the chunk is shown in
<a href="#png.ch11.tbl.4">Table 11-4</a>.
</p>


<a name="png.ch11.tbl.4" />
<div class="table" align="center">

<p>
<table width="502" border="0">
  <tr>
    <td>
      <b class="emphasis-bold">Table 11-4.</b>
      <i>pHYs Chunk</i>
    </td>
  </tr>
</table>
</p>

<p>
<table width="502" border="1">

<tr>
<td><b class="emphasis-bold">Field</b></td>
<td><b class="emphasis-bold">Length and Valid Range
<?x-space 2p?><?x-space 2p?></b></td>
</tr>


<tr>
<td>Pixels per unit, <em class="emphasis">x</em> axis</td>
<td>4 bytes (0-2,147,483,647)</td>
</tr>


<tr>
<td>Pixels per unit, <em class="emphasis">y</em> axis</td>
<td>4 bytes (0-2,147,483,647)</td>
</tr>


<tr>
<td>Unit specifier</td>
<td>1 byte (0, 1)</td>
</tr>


<?x-space 5p?>
</table>
</p>
</div>


<p>If the unit specifier byte is 1, the units are meters; if it is 0, the
units are unspecified, and only the relative dimensions are known. Currently,
no other values are valid. Note that the format of the chunk precludes
pixel sizes greater than one meter, which should not be a significant
hardship for most applications, but it allows pixels as small as 4.7
<!-- <img src="images/U00C5.png" alt="[A-with-circle]" />ngstroms, -->
&Aring;ngstroms,
which is roughly the size of a single atom.</p>


<p>For the previous scanning example, 600 dpi is equal to 23,622.05
pixels per meter, so both the <em class="emphasis">x</em> and <em class="emphasis">y</em> values would be
23,622, and the unit specifier would be 1. The second example is
slightly trickier. First, it is necessary to know that practically
all current computer displays have a physical aspect ratio of 4:3,<a href="#FOOTNOTE-89">[89]</a>
which means the viewable portion of the display (the glass) is three-quarters as high as it is wide. Thus, the horizontal pixels-per-unit in the
case of a 1280&nbsp;&times; 1024 display is proportional to (1280/4) or 320, while the
vertical pixels-per-unit is proportional to (1024/3) or 341.333333. Because
we don't have an absolute scale, we are free to multiply these values by a
common factor; doing so will preserve some of the precision that would otherwise
be lost due to truncation of the decimal part of the second value (the .3333
part). One choice would be a power of 10, such as 1,000; then the stored
values would be 320,000 and 341,333, respectively. But in this case, we can
do better: we know that the fractional part is simply one-third, so multiplying
both values by 3 will preserve the aspect ratio exactly. Thus the chunk would
contain the values (3&nbsp;&times; 1280/4) or 960, (3&nbsp;&times; 1024/3) or 1,024, and 0 for
the unit specifier. Values of 15, 16, and 0 would work equally well.


</p><blockquote class="footnote">


<a name="FOOTNOTE-89" /><p>[89] This will change with the convergence of computers and high-definition
TV. Displays for the latter have a 16:9 aspect ratio, which apparently is
the geometric mean of standard television and computer displays (4:3) and
of modern, panoramic films (typically 2.35:1, but it varies).</p>


</blockquote>


<p><a name="INDEX-874" />A decoder that encounters a pHYs chunk with different values for the <em class="emphasis">x</em> and <em class="emphasis">y</em>
axes has several options. The simplest and least correct approach is to ignore
the chunk; most current viewers do this. A better approach is to interpolate
the pixels in one of the dimensions; this gives the correct overall appearance
but introduces noticeable artifacts--for the preceding example, it involves
either duplicating every 15th column stretching the image horizontally,
or deleting every 16th row shrinking the image vertically. The best
approach is to resample the image, a procedure that amounts to converting the
image to a continuous (or analog) representation and then overlaying the
desired pixel grid on that. This is, by far, the most expensive approach
in terms of CPU usage, but the results are excellent.</p>

</div>


<div class="refentry">
<a name="png.ch11.div.9" />
<h2 class="sect1"><i>Physical Scale (sCAL)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; officially registered (PNG Extensions)
   <li>Location: &nbsp; before first IDAT
   <li>Multiple: &nbsp; no
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->

<p>
<a name="INDEX-875" />
<a name="INDEX-876" />
PNG's sCAL chunk is similar to pHYs, except that instead of measuring the
size of the image pixels relative to each other or to an original, physical
image, sCAL measures their size relative to the actual subject matter of the
image. For example, an astronomical image may span a certain number of radians
in each direction, or an aerial photograph of Earth may cover a given number of
kilometers.</p>


<p><a href="#png.ch11.tbl.5">Table 11-5</a> shows the format of sCAL; it is quite simple.
</p>


<a name="png.ch11.tbl.5" />
<div class="table" align="center">

<p>
<table width="502" border="0">
  <tr>
    <td>
      <b class="emphasis-bold">Table 11-5.</b>
      <i>sCAL Chunk</i>
    </td>
  </tr>
</table>
</p>

<p>
<table width="502" border="1">

<tr>
<td><b class="emphasis-bold">Field</b></td>
<td><b class="emphasis-bold">Length and Valid Range
<?x-space 2p?><?x-space 2p?></b></td>
</tr>

<tr>
<td>Unit specifier</td>
<td>1 byte (1, 2)</td>
</tr>

<tr>
<td>Units per pixel, <em class="emphasis">x</em> axis</td>
<td><em class="emphasis">m</em> bytes (positive floating-point)</td>
</tr>

<tr>
<td>Null separator</td>
<td>1 byte (0)</td>
</tr>

<tr>
<td>Units per pixel, <em class="emphasis">y</em> axis</td>
<td><em class="emphasis">n</em> bytes (positive floating-point)</td>
</tr>

<?x-space 5p?>
</table>
</p>
</div>


<p>Two units are defined: meters (unit specifier = 1) and radians (unit
specifier = 2). The size of a pixel in the given units, both
horizontally and vertically, is given by a pair of positive
floating-point numbers encoded as ASCII strings and separated by a
null byte. The most general form of a floating-point string includes
an optional leading sign (<b class="emphasis-bold">+</b> or <b class="emphasis-bold">-</b>), zero or more
decimal digits (0-9, the ``integer part''), an optional decimal
point followed by zero or more decimal digits (the ``fractional
part''), and an optional <b class="emphasis-bold">e</b> or <b class="emphasis-bold">E</b> followed by an
optional sign and one or more digits (the ``exponent part''). Either
the integer part or the fractional part must contain at least one
digit, but everything else may be omitted. Thus, <b class="emphasis-bold">1</b> and
<b class="emphasis-bold">.1</b> are valid floating-point numbers, as is
<b class="emphasis-bold">+123.4567e-089</b>. Note that the exponent is interpreted as a
power of 10 (10<sup class="superscript">-89</sup> in the third
example) to be multiplied by the integer and fractional parts; this is the
computer version of what is sometimes referred to as <em class="emphasis">scientific notation</em>.
</p>

</div>


<div class="refentry">
<a name="png.ch11.div.10" />
<h2 class="sect1"><i>Image Offset (oFFs)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; officially registered (PNG Extensions)
   <li>Location: &nbsp; before first IDAT
   <li>Multiple: &nbsp; no
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->

<p>
<a name="INDEX-877" />
<a name="INDEX-878" />
For images that are available separately but envisioned as part of a greater
whole, the image-offset chunk, oFFs, can be used to specify the absolute
positioning of each. The most common example is positioning on a printed
page, especially in conjunction with the pHYs chunk.</p>


<p>The layout of the chunk is given in
<a href="#png.ch11.tbl.6">Table 11-6</a>.
</p>


<a name="png.ch11.tbl.6" />
<div class="table" align="center">

<p>
<table width="502" border="0">
  <tr>
    <td>
      <b class="emphasis-bold">Table 11-6.</b>
      <i>oFFs Chunk</i>
    </td>
  </tr>
</table>
</p>

<p>
<table width="502" border="1">

<tr>
<td><b class="emphasis-bold">Field</b></td>
<td><b class="emphasis-bold">Length and Valid Range
<?x-space 2p?><?x-space 2p?></b></td>
</tr>

<tr>
<td>Image position, <em class="emphasis">x</em> axis</td>
<td>4 bytes (-2,147,483,647 to +2,147,483,647)</td>
</tr>

<tr>
<td>Image position, <em class="emphasis">y</em> axis</td>
<td>4 bytes (-2,147,483,647 to +2,147,483,647)</td>
</tr>

<tr>
<td>Unit specifier</td>
<td>1 byte (0, 1)</td>
</tr>

<?x-space 5p?>
</table>
</p>
</div>


<p>Valid units are either pixels (unit specifier = 0) or microns<a href="#FOOTNOTE-90">[90]</a>
(unit specifier = 1). The image position is measured from the top and left
edges of the page (whether real or virtual); an image that is intended
to be partly cut off may have negative offsets.
</p>

<blockquote class="footnote">
<a name="FOOTNOTE-90" /><p>[90] Microns are more properly known as micrometers
<!-- (<img src="images/U03BC.png" alt="[mu]" />m); -->
(&#956;m);
there are one million of them in a meter, or 25,400 in an inch.</p>
</blockquote>

</div>


<div class="refentry">
<a name="png.ch11.div.11" />
<h2 class="sect1"><i>Pixel Calibration (pCAL)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; officially registered (PNG Extensions)
   <li>Location: &nbsp; after PLTE, before first IDAT
   <li>Multiple: &nbsp; no
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->

<p>
<a name="INDEX-879" />
<a name="INDEX-880" />
The pCAL chunk is currently the only registered scientific-visualization
extension to PNG, though it was moved into the regular PNG Extensions document
as part of the general PNG spec revision process in October 1998. It is also
the most mathematical of any approved chunk. Its purpose is to efficiently
encode the relevant conversions between the integer samples in a PNG file
and the physical quantity being represented by the image. Two conversions
are represented: a linear conversion between the PNG samples and the
original samples and a more general conversion from the original samples
to the physical values they represent. The first mapping is often the
identity mapping (i.e., the original samples are equal to the PNG samples),
but it need not be.</p>


<p>The layout of the pCAL chunk is presented in
<a href="#png.ch11.tbl.7">Table 11-7</a>.
</p>


<a name="png.ch11.tbl.7" />
<div class="table" align="center">

<p>
<table width="502" border="0">
  <tr>
    <td>
      <b class="emphasis-bold">Table 11-7.</b>
      <i>pCAL Chunk</i>
    </td>
  </tr>
</table>
</p>

<p>
<table width="502" border="1">

<tr>
<td><b class="emphasis-bold">Field</b></td>
<td><b class="emphasis-bold">Length and Valid Range</b></td>
</tr>

<tr>
<td>Calibration name</td>
<td>1-79 bytes (Latin-1 text)</td>
</tr>

<tr>
<td>Null separator</td>
<td>1 byte</td>
</tr>

<tr>
<td>Original zero, X<sub class="subscript">0</sub></td>
<td>4 bytes (signed integer)</td>
</tr>

<tr>
<td>Original maximum, X<sub class="subscript">1</sub></td>
<td>4 bytes (signed integer)</td>
</tr>

<tr>
<td>Equation type</td>
<td>1 byte</td>
</tr>

<tr>
<td>Number of parameters, N</td>
<td>1 byte</td>
</tr>

<tr>
<td>Unit name</td>
<td><em class="emphasis">n</em> bytes (Latin-1 text)</td>
</tr>

<tr>
<td>Null separator</td>
<td>1 byte</td>
</tr>

<tr>
<td>Parameter 0, P<sub class="subscript">0</sub></td>
<td><em class="emphasis">p</em><sub class="subscript">0</sub> bytes (ASCII floating-point text)</td>
</tr>

<tr>
<td>Null separator</td>
<td>1 byte</td>
</tr>

<tr>
<td> ...</td>
<td> ...</td>
</tr>

<tr>
<td>Parameter <em class="emphasis">L</em>, P<sub class="subscript">L</sub></td>
<td><em class="emphasis">p</em><sub class="subscript">L</sub> bytes (ASCII floating-point text)</td>
</tr>

<tr>
<td colspan="2">(Note: <em class="emphasis">L</em> = N-1)</td>
<td />
</tr>

<?x-space 5p?>
</table>
</p>
</div>


<p>The unit name is a label, such as <b class="emphasis-bold">kg/(m^3)</b> or <b class="emphasis-bold">Mpc</b>, that
applies to the
physical quantity represented by the image samples. Dimensionless data may
either include a descriptive string (e.g., ``fractal iteration count'') or
leave the unit field a null string. There are no restrictions on the length
of the unit name.</p>


<p>The X<sub class="subscript">0</sub> and X<sub class="subscript">1</sub> parameters encode the linear conversion.
For an 8-bit sample depth, the PNG samples range from 0 to 255; more generally,
they range from 0 to M, where M = 2<sup class="superscript"><em class="emphasis">bit depth</em></sup> - 1. Most often,
X<sub class="subscript">0</sub> will equal 0 and X<sub class="subscript">1</sub> will
equal M, indicating that the PNG samples are the same as the original samples.
But this need not be the case, and either of X<sub class="subscript">0</sub> or X<sub class="subscript">1</sub> may
be positive or negative; the only restriction is that they may not be equal to
each other. The conversion is done using integer arithmetic, according to the
following equation:</p>


<blockquote>
<pre class="code">
original_sample = (PNG_sample * (X<sub class="subscript">1</sub>-X<sub class="subscript">0</sub>) + M/2) / M + X<sub class="subscript">0</sub>
</pre>
</blockquote>

<p>The inverse mapping is:</p>


<blockquote>
<pre class="code">
PNG_sample = ((original_sample - X<sub class="subscript">0</sub>) * M + (X<sub class="subscript">1</sub>-X<sub class="subscript">0</sub>)/2) / (X<sub class="subscript">1</sub>-X<sub class="subscript">0</sub>)
</pre>
</blockquote>

<p>Note that integer arithmetic here means that fractional values are rounded
toward minus infinity, not toward zero; there's no difference for positive
values, but for negative values, there is. Also keep in mind that the PNG
samples are limited to the range [0,M] regardless of what the inverse mapping
might give.</p>


<p>The more general conversion, between original samples and actual physical
values, can be represented by one of four possible equation types: linear
(type 0), exponential (type 1), exponential with arbitrary base (type 2),
or hyperbolic sinusoidal (type 3). The number of parameters required by each
is 2, 3, 3, and 4, respectively, and the parameters are stored in the same
ASCII floating-point format as described for the sCAL chunk earlier. The
equations use floating-point arithmetic, not integer, and are given by:</p>

<blockquote>
<pre class="code">
[0]   physical_value = P<sub class="subscript">0</sub> + P<sub class="subscript">1</sub> * original_sample/(X<sub class="subscript">1</sub>-X<sub class="subscript">0</sub>)

[1]   physical_value = P<sub class="subscript">0</sub> + P<sub class="subscript">1</sub> * e<sup class="superscript">P<sub class="subscript">2</sub> * original_sample/(X<sub class="subscript">1</sub>-X<sub class="subscript">0</sub>)</sup>

[2]   physical_value = P<sub class="subscript">0</sub> + P<sub class="subscript">1</sub> * P<sub class="subscript">2</sub><sup class="superscript">original_sample/(X<sub class="subscript">1</sub>-X<sub class="subscript">0</sub>)</sup>

[3]   physical_value = P<sub class="subscript">0</sub> + P<sub class="subscript">1</sub> * sinh(P<sub class="subscript">2</sub>*(original_sample - P<sub class="subscript">3</sub>)/(X<sub class="subscript">1</sub>-X<sub class="subscript">0</sub>))
</pre>
</blockquote>

<p>Equation types 1 and 2 are equivalent in the sense that the same types of
functions can be represented by either one; both are defined for convenience.
For RGB or RGBA image types, the equations are applied to each of the color
sample values independently, while for palette images, the equations are
applied to the color sample values in the palette, not to the index values.
<?x-need 10?></p>


<p>Equation type 3 may seem odd, but it allows floating-point data to be
reduced to integer data in such a way that the resolution of the
integer data is roughly proportional to the magnitude of the original
floating-point data. That is, for 32-bit original data and 16-bit PNG
samples, the resolution near zero is around
10<sup class="superscript">-33</sup>, and near
<!--
<u>+</u>10<sup class="superscript">31</sup>
 -->
&#177;10<sup class="superscript">31</sup>
it is around 10<sup class="superscript">28</sup>.


To put it another way, the resolution everywhere is about 0.4% (or 1/256) of
the magnitude.</p>

</div>


<div class="refentry">
<a name="png.ch11.div.12" />
<h2 class="sect1"><i>Fractal Parameters (fRAc)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; officially registered (PNG Extensions)
   <li>Location: &nbsp; anywhere
   <li>Multiple: &nbsp; yes
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->

<p><a name="INDEX-881" />The fRAc chunk is unique in that it was officially registered as a PNG
extension in 1995 but, as of early 1999, still had not actually been specified.
Intended to store parameters pertaining to the generation of fractal images,
the chunk is clearly useful only to a very specialized set of programs. As
a result, its design was left in the hands of experts--specifically, the
authors of Fractint, which is one of the most general fractal programs ever
written and probably the most popular. But for technical reasons relating
to Fractint's 16-bit origins, PNG support was not added as planned, so
design of the fRAc chunk was deferred pending a rewrite of the program as a
32-bit application.
</p>

</div>


<div class="refentry">
<a name="png.ch11.div.13" />
<h2 class="sect1"><i>GIF Conversion Info (gIFg, gIFx)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; officially registered (PNG Extensions)
   <li>Location: &nbsp; anywhere
   <li>Multiple: &nbsp; yes
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->

<p>
<a name="INDEX-882" />
<a name="INDEX-883" />
Since PNG originated as an intended replacement for GIF, one requirement for
the new format was to be able to store all possible GIF information in one
form or another. Part of that requirement is addressed by chunks we've
already described. Within GIF's Logical Screen Descriptor (the global
header that immediately follows the GIF signature bytes), the Pixel Aspect
Ratio, Color Resolution, and Background Color Index fields map to pHYs, sBIT,
and bKGD, respectively. Note that Background Color Index only applies if
there is a Global Color Table, however. Within the Image Descriptor, the
Image Left Position and Image Top Position fields map to oFFs. And within
the Graphic Control Extension, the Transparent Color Index maps to tRNS.
This is summarized in
<a href="#png.ch11.tbl.8">Table 11-8</a>.
</p>


<a name="png.ch11.tbl.8" />
<div class="table" align="center">

<p>
<table width="502" border="0">
  <tr>
    <td>
      <b class="emphasis-bold">Table 11-8.</b>
      <i>Correspondence Between GIF Fields and Standard PNG Chunks</i>
    </td>
  </tr>
</table>
</p>

<p>
<table width="502" border="1">

<tr>
<td><b class="emphasis-bold">GIF Block</b></td>
<td><b class="emphasis-bold">GIF Variable Name</b></td>
<td><b class="emphasis-bold">PNG Chunk
<?x-space 2p?><?x-space 2p?></b></td>
</tr>


<tr>
<td rowspan=3>Logical Screen Descriptor</td>
<td>Pixel Aspect Ratio</td>
<td>pHYs</td>
</tr>


<tr>
<td>Color Resolution</td>
<td>sBIT</td>
</tr>


<tr>
<td>Background Color Index</td>
<td>bKGD</td>
</tr>


<?x-space 2p?><?x-space 2p?><tr>
<td rowspan=2>Image Descriptor</td>
<td>Image Left Position</td>
<td>oFFs</td>
</tr>


<tr>
<td>Image Top Position</td>
<td>oFFs</td>
</tr>


<?x-space 2p?><?x-space 2p?><tr>
<td>Graphic Control Extension</td>
<td>Transparent Color Index</td>
<td>tRNS</td>
</tr>


<?x-space 5p?>
</table>
</p>
</div>

















<p>The remainder of the requirement that PNG be able to store all GIF information
is addressed by two of PNG's three GIF extension chunks. Both correspond
directly to GIF89a extensions: the Graphic Control Extension (gIFg) and the
Application Extension (gIFx). The third chunk, gIFt, turns out to be an
unintended special case; it is discussed separately later.</p>


<p><a name="INDEX-884" />GIF's Graphic Control Extension is most commonly used to indicate
transparency, for which it corresponds most closely to PNG's tRNS
chunk. But it is also used in multi-image GIFs to provide timing and
compositing information. Although this is more properly the realm of
MNG, PNG's multi-image cousin (which I'll discuss in <a href="chapter12.html">Chapter 12, "Multiple-Image Network Graphics"</a>, PNG
also supports the conversion of a multi-image GIF into several
single-image PNGs. The gIFg chunk is used to encode the
nontransparency information in the GIF extension block so that
lossless conversion back to an animated GIF is possible.














</p>


<p>The gIFg chunk, shown in
<a href="#png.ch11.tbl.9">Table 11-9</a>, contains only three fields.
</p>


<a name="png.ch11.tbl.9" />
<div class="table" align="center">

<p>
<table width="502" border="0">
  <tr>
    <td>
      <b class="emphasis-bold">Table 11-9.</b>
      <i>gIFg Chunk</i>
    </td>
  </tr>
</table>
</p>

<p>
<table width="502" border="1">

<tr>
<td><b class="emphasis-bold">Field</b></td>
<td><b class="emphasis-bold">Length and Valid Range
<?x-space 2p?><?x-space 2p?></b></td>
</tr>


<tr>
<td>Disposal method</td>
<td>1 byte (0-3)</td>
</tr>


<tr>
<td>User input</td>
<td>1 byte (0, 1)</td>
</tr>


<tr>
<td>Delay time</td>
<td>2 bytes (0-65,535)</td>
</tr>


<?x-space 5p?>
</table>
</p>
</div>


<p>The interpretation and value of each field are identical to those in part 23
of the GIF89a Specification, with the exception that the 2-byte delay time
<a name="INDEX-885" />
<a name="INDEX-886" />is stored in big-endian order (most significant byte first) in gIFg, whereas
GIF integers are stored in little-endian format. PNG decoders may treat the
delay time (measured in hundredths of a second) as the maximum amount of time
to display the image before going on to the next one, if any, but it is likely
that most decoders will ignore the chunk entirely.


</p>


<p><a name="INDEX-887" />GIF's Application Extension is simply a way for an application to include its
own information in the image; it corresponds exactly to a private chunk in a
PNG image. The format is given in
<a href="#png.ch11.tbl.10">Table 11-10</a>.
</p>


<a name="png.ch11.tbl.10" />
<div class="table" align="center">

<p>
<table width="502" border="0">
  <tr>
    <td>
      <b class="emphasis-bold">Table 11-10.</b>
      <i>gIFx Chunk</i>
    </td>
  </tr>
</table>
</p>

<p>
<table width="502" border="1">

<tr>
<td><b class="emphasis-bold">Field</b></td>
<td><b class="emphasis-bold">Length and Valid Range
<?x-space 2p?><?x-space 2p?></b></td>
</tr>


<tr>
<td>Application identifier</td>
<td>8 bytes (printable ASCII characters)</td>
</tr>


<tr>
<td>Authentication code</td>
<td>3 bytes</td>
</tr>


<tr>
<td>Application data</td>
<td><em class="emphasis">n</em> bytes</td>
</tr>


<?x-space 5p?>
</table>
</p>
</div>


<p>The contents of gIFx are a direct transcription of the GIF data, with the sole
exception that any GIF sub-blocks are deblocked into a flat stream.</p>

</div>


<div class="refentry">
<a name="png.ch11.div.14" />
<h2 class="sect1"><i>GIF Plain Text (gIFt)</i></h2>
<ul type="disc">
   <li>Status: &nbsp; officially deprecated (PNG Extensions)
   <li>Location: &nbsp; anywhere
   <li>Multiple: &nbsp; yes
</ul>
<!--
<h4 class="refsect1">Description</h4>
 -->

<p>
<a name="INDEX-888" />
<a name="INDEX-889" />
<a name="INDEX-890" />
GIF's Plain Text Extension is a way to define an image composed entirely of
text without actually storing the text as a bitmapped image. It defines a
rectangular grid of character cells into which text characters of the
specified foreground and background colors are placed, starting from the
upper left and proceeding left to right and top to bottom; the decoder
chooses the font that is the closest match to the specified size.</p>


<p>A casual reading of the GIF specification might suggest that the Plain Text
Extension defines a method for cheaply overlaying fixed-width text on top
of ordinary pixel data--and, indeed, that was probably the primary
motivation behind the extension. But a more careful inspection reveals that
the Plain Text Extension is treated as a separate subimage within the GIF
stream, on equal terms with any block of bitmap data. It may, in fact, be
the <em class="emphasis">only</em> graphic rendering block within the stream. And since PNG
images are required to include bitmap data (i.e., IDAT chunks), allowing
GIF Plain Text information to be included is perilously close to sanctioning
multi-image PNGs. Largely because of this, the gIFt chunk was officially
deprecated in October 1998. It is still allowed for backward compatibility
(the horses have already left the barn, so to speak), but the current
recommendation is that all decoders ignore the chunk and that encoders not
write it in the first place. In fact, it is quite possible that no encoder
or decoder ever did support gIFt; the Plain Text Extension was rarely used
even in GIF's heyday, and even gif2png
(see <a href="chapter05.html">Chapter 5, "Applications: Image Converters"</a>) never supported it.</p>


<p>In any case, the format of the gIFt chunk is as shown in
<a href="#png.ch11.tbl.11">Table 11-11</a>.
</p>


<a name="png.ch11.tbl.11" />
<div class="table" align="center">

<p>
<table width="502" border="0">
  <tr>
    <td>
      <b class="emphasis-bold">Table 11-11.</b>
      <i>gIFt Chunk</i>
    </td>
  </tr>
</table>
</p>

<p>
<table width="502" border="1">

<tr>
<td><b class="emphasis-bold">Field</b></td>
<td><b class="emphasis-bold">Length and Valid Range
<?x-space 2p?><?x-space 2p?></b></td>
</tr>


<tr>
<td>Text grid left position, pixels</td>
<td>4 bytes (0-2,147,483,647)</td>
</tr>


<tr>
<td>Text grid top position, pixels</td>
<td>4 bytes (0-2,147,483,647)</td>
</tr>


<tr>
<td>Text grid width, pixels</td>
<td>4 bytes (0-2,147,483,647)</td>
</tr>


<tr>
<td>Text grid height, pixels</td>
<td>4 bytes (0-2,147,483,647)</td>
</tr>


<tr>
<td>Character cell width, pixels</td>
<td>1 byte (0-255)</td>
</tr>


<tr>
<td>Character cell height, pixels</td>
<td>1 byte (0-255)</td>
</tr>


<tr>
<td>Text foreground color</td>
<td>3 bytes (R, G, B samples, 0-255 each)</td>
</tr>


<tr>
<td>Text background color</td>
<td>3 bytes (R, G, B samples, 0-255 each)</td>
</tr>


<tr>
<td>Plain text data</td>
<td><em class="emphasis">n</em> bytes</td>
</tr>


<?x-space 5p?>
</table>
</p>
</div>





<p>There are several differences from the GIF data structure. The actual text
in the GIF block is divided into sub-blocks of between 1 and 255 bytes;
the PNG plain text data is a single stream. In addition to the reversed order
for integer values (big-endian in PNG), gIFt's width and height fields for
the grid are 4 bytes each, twice as big as in GIF. The position fields are
also twice as wide, which makes little
sense from a preserve-the-GIF-data standpoint, but apparently was chosen for
consistency with PNG's image-offset chunk. Both the Plain Text Extension
and oFFs give positions relative to a logical page, not relative to the main
image; thus, in the presence of oFFs data, the gIFt positions should be adjusted
accordingly. Note that this may not be possible if the PNG image
uses microns in the oFFs chunk and has no pHYs chunk--in that case, there
is no conversion information between pixels (the only unit defined for gIFt)
and microns.</p>


<p><a name="INDEX-891" />Possibly the biggest difference, however, is that the Plain Text Extension
is affected by the Graphic Control Extension, which means it implicitly
includes transparency and timing effects. PNG's gIFt chunk does not include
any transparency information, so effectively there is no way to float the
gIFt text over the main image by giving it a transparent background color.
This limitation appears to have been an oversight in the design of the PNG
chunk and was another reason for its official deprecation. On the other
hand, if the gIFt chunk appears before the first IDAT chunk, a hypothetical
gIFt-aware PNG decoder might assume that the text amounts to a background
image and render the pixel data on top of it, applying any transparency
effects the main image possesses.</p>

</div>


<div class="refentry">
<a name="png.ch11.div.15" />
<h2 class="sect1"><i>Other Chunks</i></h2>
<!--
<h4 class="refsect1">Description</h4>
 -->

<p>Several other chunks were proposed but never approved as official extensions,
mainly due to the perceived lack of need for them.
<a name="INDEX-892" />The alignment chunk (aLIG, had it been approved) would have provided centering
and baseline information about an image so that it could be aligned more cleanly
with surrounding text; this would have been most useful for images
<a name="INDEX-893" />with transparent edges. The fingerprint chunk (fING) would have provided a
16-byte MD5 fingerprint of the raw image data, a type of cryptographic
signature that could be used to test whether two images were identical.
Neither aLIG nor fING was ever put up for a vote, and both proposals have long
since expired.</p>


<p><a name="INDEX-894" />There were also three proposed scientific-visualization chunks, all of which
were rejected in formal voting. The false-color chunk (fALS) would have
provided false-color information for grayscale images, such as might be used
to highlight a tumor in a medical scan or a shock front in a hydrodynamic
<a name="INDEX-895" />
<a name="INDEX-896" />
<a name="INDEX-897" />simulation. The calibration chunks (xSCL and ySCL, but also known as xCAL
and yCAL in later proposals) were similar to sCAL in providing information
about the physical characteristics of an image subject but would have allowed
offsets and different units along the two axes; they thus would have provided
full calibration data, not just scaling information.</p>


<p>Note that any of these chunks may be resurrected in the future, as PNG becomes
more widely used and as the needs of various PNG-using communities evolve.

</p>

</div>

<PRE>























</PRE>


<hr> <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -->

<a href="chapter10.html"><img width=24 height=13 border=0 align="left"
 src="images/prev.png" alt="&lt;-"></a>

<a href="chapter12.html"><img width=24 height=13 border=0 align="right"
 src="images/next.png" alt="-&gt;"></a>

<div align="center">
  <a href="chapter10.html"><font size="-1" color="#000000"
   ><b>PREVIOUS</b></font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
     href="toc.html"><font size="-1" color="#000000"
   ><b>CONTENTS</b></font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
     href="chapter12.html"><font size="-1" color="#000000"
   ><b>NEXT</b></font></a>
</div>

<hr> <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -->



</body></html>