<?xml version="1.0" encoding="GBK"?>
<?xml-stylesheet href="http://www.sharera.com//styles/rss.css" type="text/css"?>
<rss version="2.0">
 
 <channel>
  <title>果冻</title>
  <link>http://pudding.sharera.com/</link>
  <description>果冻日志</description>
  <language>zh-CN</language> 
  <docs>http://pudding.sharera.com/rss/rss20.xml</docs>
  <pubDate></pubDate>
  <managingEditor>chendz0526@126.com(pudding)</managingEditor>
      <item>
   <title>李嘉诚授逆市投资三铁律：PE低盈利强高派息</title>
   <description><![CDATA[<p style="TEXT-INDENT: 2em">长江实业(集团)有限公司(0001.HK)及其子公司和记黄埔(0013.HK)的年报记者会向来是最&ldquo;严格&rdquo;的记者会之一，若非提前登记，绝对无法进入会场。</p>
<p style="TEXT-INDENT: 2em">当然，长和系的记者会，也以气氛非常活跃闻名，这可能与主席李嘉诚的健谈不无关系。</p>
<p style="TEXT-INDENT: 2em">3月27日，李嘉诚携长子、长和系副主席李泽钜、和黄董事总经理霍建宁出席记者会。相比于情绪高昂、表情丰富的父亲李嘉诚来说，李泽钜向来显得拘谨，讲话声音比较低沉，这让李嘉诚不得不屡次提醒李泽鉅讲话&ldquo;大声一点&rdquo;。</p>
<p style="TEXT-INDENT: 2em">席间，李嘉诚坦言做主席很辛苦，&ldquo;幸亏有一帮好伙计。&rdquo;他的核心管理层均在台下列席记者会。</p>
<p style="TEXT-INDENT: 2em"><clk></clk>除了对长和系去年业绩的兴趣之外，李家家长李嘉诚与两个<nobr oncontextmenu="return false;" onmousemove="kwM(3);" id="clickeyekey3" onmouseover="kwE(event,3, this);" style="COLOR: #6600ff; BORDER-BOTTOM: #6600ff 1px dotted; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick="return kwC(event,3)" onmouseout="kwL(event, this);" target="_1">儿子</nobr>李泽钜和李泽楷的关系，以及李嘉诚退休去向等，向来是外界关注的热点。最近，业界传闻李嘉诚对次子李泽楷可能即将到来的婚讯不甚满意，也不可避免地在业绩会上被一再提及。</p>
<p style="TEXT-INDENT: 2em"><clk></clk>当然，李嘉诚对这些家事均不置可否，或一笑带过，但却坦言，尽管矛盾在所难免，但与两个儿子关系不错，而且最近没有退休打算，如果真有这么一天的话，他将全心全意打理自己的慈善<nobr oncontextmenu="return false;" onmousemove="kwM(4);" id="clickeyekey4" onmouseover="kwE(event,4, this);" style="COLOR: #6600ff; BORDER-BOTTOM: #6600ff 1px dotted; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick="return kwC(event,4)" onmouseout="kwL(event, this);" target="_1">基金</nobr>，&ldquo;绝不会偷懒&rdquo;。</p>
<p style="TEXT-INDENT: 2em">去年，长实为股东带来盈利276.78亿港元，和黄收益总额更高达3087.75亿港元，其中股东应占盈利306亿港元，换言之，长和系股东总体应占盈利高达582.78亿港元。</p>
<p style="TEXT-INDENT: 2em"><strong>买股要量力</strong></p>
<p style="TEXT-INDENT: 2em"><clk></clk>《21世纪》：现在<nobr oncontextmenu="return false;" onmousemove="kwM(6);" id="clickeyekey6" onmouseover="kwE(event,6, this);" style="COLOR: #6600ff; BORDER-BOTTOM: #6600ff 1px dotted; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick="return kwC(event,6)" onmouseout="kwL(event, this);" target="_1">美国</nobr>经济影响全球市场状况不佳，内地股市也有泡沫，你怎么看内地股市的情况？港股最近也没方向，你怎么看？</p>
<p style="TEXT-INDENT: 2em">李嘉诚：我觉得，美国的经济问题，不是一朝一日能解决的，带来的麻烦也很多。</p>
<p style="TEXT-INDENT: 2em">另外，我觉得投资者买股票最重要的是要看PE。我记得1989年，日本的股票，最高到了差不多38000点，很多股票的PE高到不合理，我一股都没买，直到现在，日本的股市还没有恢复到原来价格的三分之一，所以这个情形，最关键是要看PE是不是高到离谱，要小心。</p>
<p style="TEXT-INDENT: 2em">至于港股现在是不是已经到了合理的水平，我不敢这么说，今天的恒生指数跟去年同期相比，我相信还要高出15%。至于内地的股市，我觉得投资者最重要的是，量力而为，要买PE不太高的、赚钱能力强、有能力提高派息水平的公司。</p>
<p style="TEXT-INDENT: 2em">《21世纪》：美国次按问题造成全球经济环境不稳定，对香港有什么影响？</p>
<p style="TEXT-INDENT: 2em"><clk></clk>李嘉诚：过去10年，美国的GDP每年有3%的增长，今年可能降到2.9%，第二季度甚至可能出现负增长。美国平均<nobr oncontextmenu="return false;" onmousemove="kwM(11);" id="clickeyekey11" onmouseover="kwE(event,11, this);" style="COLOR: #6600ff; BORDER-BOTTOM: #6600ff 1px dotted; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick="return kwC(event,11)" onmouseout="kwL(event, this);" target="_1">购买</nobr>力占GDP大概70%，如果当地消费下跌一至两成,对当地经济会构成一定影响, 所以美国的问题影响是很大的，因为一定会影响美国人的购买能力。但对于香港,<nobr oncontextmenu="return false;" onmousemove="kwM(1);" id="clickeyekey1" onmouseover="kwE(event,1, this);" style="COLOR: #6600ff; BORDER-BOTTOM: #6600ff 1px dotted; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick="return kwC(event,1)" onmouseout="kwL(event, this);" target="_1">目前</nobr>香港对美国的直接出口比重很低,所以应该对经济影响不大。</p>
<p style="TEXT-INDENT: 2em">《21世纪》：你怎么看待内地宏调对楼市和股市的影响？</p>
<p style="TEXT-INDENT: 2em">李嘉诚：现在内地的宏观调控，今年来看，对股市也好，楼市也好，肯定会有不同程度的影响，但长远来看是好的，对经济健康都有利。</p>
<p style="TEXT-INDENT: 2em">《21世纪》：现在香港有些发展商降价卖房，你是否看淡香港楼市升势？</p>
<p style="TEXT-INDENT: 2em"><clk></clk>李嘉诚：我举个最简单的例子，我旗下的楼盘&ldquo;首都&rdquo;，一天内卖掉2000多套,<nobr oncontextmenu="return false;" onmousemove="kwM(10);" id="clickeyekey10" onmouseover="kwE(event,10, this);" style="COLOR: #6600ff; BORDER-BOTTOM: #6600ff 1px dotted; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick="return kwC(event,10)" onmouseout="kwL(event, this);" target="_1">超过</nobr>100亿港元，即便几次加价，也都能卖完，证明购买力不俗。</p>
<p style="TEXT-INDENT: 2em">现在香港是负利率，有利于楼价。美国的楼价有回落，但美国的楼市情况跟香港完全不同，一方面，香港政府是最大的业主，政府拿地出来勾地，如果地供应平衡，楼价难以下跌，而且从供求关系来看，香港的需求不少。</p>
<p style="TEXT-INDENT: 2em">我们的货尾也都卖完了。另外，发展商将货尾减价销售属于正常现象，因为货尾位置一般比较差。</p>
<p style="TEXT-INDENT: 2em"><strong>长和控制权不会注入基金</strong></p>
<p style="TEXT-INDENT: 2em">《21世纪》：很多投资者都很关心集团管理层的稳定性，你与两个儿子的感情如何？</p>
<p style="TEXT-INDENT: 2em">李嘉诚：两个都是我儿子，感情很好，当然矛盾有，批评也有，但都是在所难免。</p>
<p style="TEXT-INDENT: 2em">对我自己来说，没想过退休，但如果有一日我退休的话，我会全力打理我的基金，全职的，不会偷懒，当然如果做得到的话。但是，长实的控制权不会注入到这个基金当中。</p>
<p style="TEXT-INDENT: 2em"><clk></clk>《21世纪》：你曾经说过要把<nobr oncontextmenu="return false;" onmousemove="kwM(5);" id="clickeyekey5" onmouseover="kwE(event,5, this);" style="COLOR: #6600ff; BORDER-BOTTOM: #6600ff 1px dotted; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick="return kwC(event,5)" onmouseout="kwL(event, this);" target="_1">海外</nobr>业务慢慢交给二儿子李泽楷打理，现在怎么样？</p>
<p style="TEXT-INDENT: 2em">李泽楷：个人来说，我海外是有投资的，但不需要跟公众交代的。</p>
<p style="TEXT-INDENT: 2em"><clk></clk>《21世纪》：今年的慈善捐款哪里会多点？国内和香港，还是海外？今年的捐助<nobr oncontextmenu="return false;" onmousemove="kwM(9);" id="clickeyekey9" onmouseover="kwE(event,9, this);" style="COLOR: #6600ff; BORDER-BOTTOM: #6600ff 1px dotted; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick="return kwC(event,9)" onmouseout="kwL(event, this);" target="_1">计划</nobr>怎样？</p>
<p style="TEXT-INDENT: 2em">李嘉诚：我有一个原则，每一年捐的钱应该80%以上要用在香港和内地，其它地方不应该超过20%。</p>
<p style="TEXT-INDENT: 2em">不算公司捐助在内，我个人已经捐过了88亿港元，大部分是在内地和香港，但是很多都没有公布，我在内地捐助的建筑，没有一个用我的名字命名的，连对汕头大学的捐款也都没有用自己的名字命名，所以很多人都不知道我捐钱，估计我在内地的捐助对外公布的不超过1/4。</p>
<p style="TEXT-INDENT: 2em"><clk></clk>今年的话，有空就会主动去想怎么捐钱，未来捐款只会增加不会减少，因为基金会的资金有回报，有<nobr oncontextmenu="return false;" onmousemove="kwM(0);" id="clickeyekey0" onmouseover="kwE(event,0, this);" style="COLOR: #6600ff; BORDER-BOTTOM: #6600ff 1px dotted; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick="return kwC(event,0)" onmouseout="kwL(event, this);" target="_1">资源</nobr>继续捐款。</p>
<p style="TEXT-INDENT: 2em"><strong>无计划售资产</strong></p>
<p style="TEXT-INDENT: 2em">《21世纪》：去年集团业绩这么好，部分原因是出售和电国际印度流动电讯业务取得的特殊收益358.2亿港元，今年是否会继续卖资产以保持盈利增长？</p>
<p style="TEXT-INDENT: 2em">李嘉诚：我不能说绝对不会，我只能告诉你，现在我没有这个计划。</p>
<p style="TEXT-INDENT: 2em">当然，如果有人给很好的条件，也不是绝对不可能，我要看哪里有好的项目、好价格、好公司、好股东，才能作决定，但我不能预测未来怎样，因为法律不允许。我现在很有信心能把我们的业务做得好，未来如果对股东有利，我们也会视情况而定。</p>
<p style="TEXT-INDENT: 2em">《21世纪》：传闻你有对Facebook进行股权投资？</p>
<p style="TEXT-INDENT: 2em">李嘉诚：有的。我以个人名义对Facebook的投资超过1亿美元，因为Facebook业务做得好,有高速增长,而且日后在和黄的手机网络中可以使用Facebook的服务，至于今后会否增持，任何事情都是有可能的。</p>
<p style="TEXT-INDENT: 2em">《21世纪》：目前香港货柜码头是不是面临内地压力？</p>
<p style="TEXT-INDENT: 2em">李嘉诚：码头来看，因为出口很多都是在内地，原材料和工厂也都设在内地，货运肯定是内地方便。我保守估计，四年后，香港可能连第三的地位都难保。</p>
<p style="TEXT-INDENT: 2em"><clk></clk>现在上海、<nobr oncontextmenu="return false;" onmousemove="kwM(12);" id="clickeyekey12" onmouseover="kwE(event,12, this);" style="COLOR: #6600ff; BORDER-BOTTOM: #6600ff 1px dotted; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick="return kwC(event,12)" onmouseout="kwL(event, this);" target="_1">新加坡</nobr>、深圳，都很方便，深圳现在的运量为2000万标准箱，香港是2400万箱，按照深圳的增速，很快就可以超过香港。</p>
<p style="TEXT-INDENT: 2em">很多人希望港珠澳大桥修好之后，香港可以多点货过来，但往来香港的费用、过大桥的费用，都很高，为什么要来香港呢？所以，我对现在的生意已经很满意。</p>]]></description>
   <link>http://pudding.sharera.com/blog/BlogTopic/54771.htm</link>
   <comments>http://pudding.sharera.com/blog/BlogTopic/54771.htm</comments>
   <guid>http://pudding.sharera.com/blog/BlogTopic/54771.htm</guid>
      <author>chendz0526@126.com</author>
   <source url="http://pudding.sharera.com/rss/rss20.xml">果冻</source>
  </item>
    <item>
   <title>新一届领导人</title>
   <description><![CDATA[<table cellspacing="0" cellpadding="0" width="531" border="0">
    <tbody>
        <tr>
            <td width="270">
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0312/13/46RDCU2V00012JLG.html" target="_blank"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/200803141035150dfc6.jpg" width="67" /></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 250px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/13/46RDCU2V00012JLG.html" target="_blank"><font color="#ffffff">中华人民共和国主席、军事委员会主席 胡锦涛</font></a></div>
            </td>
            <td width="206">
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0312/15/46RKAVOL00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/2008031410353854e83.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/15/46RKAVOL00012JLG.html" target="_blank"><font color="#ffffff">副主席 习近平</font></a></div>
            </td>
            <td width="120">
            <div style="BACKGROUND: #ffc600; MARGIN: 0px auto; WIDTH: 120px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/15/46RKAVOL00012JLG.html" target="_blank"><font color="#ffffff"></font></a></div>
            </td>
        </tr>
    </tbody>
</table>
<div class="blank20"><font color="#ffffff"></font></div>
<table cellspacing="0" cellpadding="0" width="694" border="0">
    <tbody>
        <tr>
            <td width="177">
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0312/13/46RDFEQ600012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/2008031410342511375.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 170px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/13/46RDFEQ600012JLG.html" target="_blank"><font color="#ffffff">全国人大常委会委员长 吴邦国</font></a><a style="COLOR: #fff" href="http://news.163.com/08/0312/15/46RK7OPF00012JLG.html" target="_blank"></a></div>
            </td>
            <td width="305">
            <div style="BACKGROUND: #ffc600; MARGIN: 0px auto; WIDTH: 280px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/13/46RDCU2V00012JLG.html"><font color="#ffffff"></font></a></div>
            </td>
            <td width="172">
            <div style="BACKGROUND: #ffc600; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/15/46RKAVOL00012JLG.html"><font color="#ffffff"></font></a></div>
            </td>
        </tr>
    </tbody>
</table>
<div class="blank20"><font color="#ffffff"></font></div>
<table cellspacing="0" cellpadding="0" width="720" border="0">
    <tbody>
        <tr>
            <td style="WIDTH: 60px">
            <div style="BACKGROUND: #ffc600; MARGIN: 0px auto; WIDTH: 180px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/13/46RDFEQ600012JLG.html" target="_blank"><font color="#ffffff"></font></a><a style="COLOR: #fff" href="http://news.163.com/08/0312/15/46RK7OPF00012JLG.html" target="_blank"></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0315/11/472QKEG50001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/15/200803151122363b442.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0315/11/472QKEG50001124J.html" target="_blank"><font color="#ffffff">副委员长 王兆国</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0315/11/472QNUMT00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/15/200803151122549ec3d.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0315/11/472QNUMT00012JLG.html" target="_blank"><font color="#ffffff">路甬祥</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0315/11/472QPCQQ00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/15/20080315112313ed931.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0315/11/472QPCQQ00012JLG.html" target="_blank"><font color="#ffffff">乌云其木格</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0315/11/472QR1NP00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/15/2008031511233057b75.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0315/11/472QR1NP00012JLG.html" target="_blank"><font color="#ffffff">韩启德</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0315/11/472QU48300012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/15/20080315112347607ed.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0315/11/472QU48300012JLG.html" target="_blank"><font color="#ffffff">华建敏</font></a></div>
            </td>
        </tr>
    </tbody>
</table>
<div class="blank20"><font color="#ffffff"></font></div>
<table cellspacing="0" cellpadding="0" width="720" border="0">
    <tbody>
        <tr>
            <td style="WIDTH: 190px">&nbsp;</td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0315/11/472R016S00012JLG.html" target="_blank"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/15/200803151124064a0cb.jpg" width="67" /></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0315/11/472R016S00012JLG.html" target="_blank"><font color="#ffffff">副委员长 陈至立</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0315/11/472R1NFP00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/15/200803151124431bc60.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0315/11/472R1NFP00012JLG.html" target="_blank"><font color="#ffffff">周铁农</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0315/11/472QNT2C0001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/15/20080315112503aa5f5.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 90px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0315/11/472QNT2C0001124J.html" target="_blank"><font color="#ffffff">李建国</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0315/11/472QNA4J00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/15/200803151125195bab9.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 120px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0315/11/472QNA4J00012JLG.html" target="_blank"><font color="#ffffff">司马义&middot;铁力瓦尔地</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0315/11/472QSJQP00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/15/20080315112536320f9.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0315/11/472QSJQP00012JLG.html" target="_blank"><font color="#ffffff">蒋树声</font></a></div>
            </td>
        </tr>
    </tbody>
</table>
<div class="blank20"><font color="#ffffff"></font></div>
<table cellspacing="0" cellpadding="0" width="720" border="0">
    <tbody>
        <tr>
            <td style="WIDTH: 190px">&nbsp;</td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/07/1220/18/4066G1JT000120GU.html" target="_blank"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/15/200803151125514e017.jpg" width="67" /></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/07/1220/18/4066G1JT000120GU.html" target="_blank"><font color="#ffffff">副委员长 陈昌智</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0315/11/472R3TLJ00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/15/20080315112611ea796.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0315/11/472R3TLJ00012JLG.html" target="_blank"><font color="#ffffff">严隽琪</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0315/11/472R636B00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/15/2008031511262603e7a.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 90px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0315/11/472R636B00012JLG.html" target="_blank"><font color="#ffffff">桑国卫</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #ffc600; MARGIN: 0px auto; WIDTH: 140px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UDH2HB0001124J.html" target="_blank"><font color="#ffffff"></font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #ffc600; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UDJNT60001124J.html" target="_blank"><font color="#ffffff"></font></a></div>
            </td>
        </tr>
    </tbody>
</table>
<div class="blank20"><font color="#ffffff"></font></div>
<table cellspacing="0" cellpadding="0" width="694" border="0">
    <tbody>
        <tr>
            <td width="177">
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0315/11/472QNT2C0001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/15/20080315110755cc421.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 170px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0315/11/472QNT2C0001124J.html" target="_blank"><font color="#ffffff">全国人大常委会秘书长 李建国</font></a></div>
            </td>
            <td width="305">
            <div style="BACKGROUND: #ffc600; MARGIN: 0px auto; WIDTH: 280px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/13/46RDCU2V00012JLG.html"><font color="#ffffff"></font></a></div>
            </td>
            <td width="172">
            <div style="BACKGROUND: #ffc600; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/15/46RKAVOL00012JLG.html"><font color="#ffffff"></font></a></div>
            </td>
        </tr>
    </tbody>
</table>
<div class="blank20"><font color="#ffffff"></font></div>
<table cellspacing="0" cellpadding="0" width="694" border="0">
    <tbody>
        <tr>
            <td width="177">
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0312/15/46RK7OPF00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/20080314140330653e6.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 150px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/15/46RK7OPF00012JLG.html" target="_blank"><font color="#ffffff">全国政协主席 贾庆林</font></a></div>
            </td>
            <td width="305">
            <div style="BACKGROUND: #ffc600; MARGIN: 0px auto; WIDTH: 280px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/13/46RDCU2V00012JLG.html"><font color="#ffffff"></font></a></div>
            </td>
            <td width="172">
            <div style="BACKGROUND: #ffc600; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/15/46RKAVOL00012JLG.html"><font color="#ffffff"></font></a></div>
            </td>
        </tr>
    </tbody>
</table>
<div class="blank20"><font color="#ffffff"></font></div>
<table cellspacing="0" cellpadding="0" width="720" border="0">
    <tbody>
        <tr>
            <td style="WIDTH: 190px">
            <div style="BACKGROUND: #ffc600; MARGIN: 0px auto; WIDTH: 150px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><font color="#ffffff"></font></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0228/20/45QJU9500001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/2008031417070664590.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0228/20/45QJU9500001124J.html" target="_blank"><font color="#ffffff">副主席 王刚 </font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/13/46TVKBFP0001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/20080314172927e2710.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/13/46TVKBFP0001124J.html" target="_blank"><font color="#ffffff">廖晖</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/13/46TVCOAQ00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/2008031417242127076.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/13/46TVCOAQ00012JLG.html" target="_blank"><font color="#ffffff">杜青林</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UD8BV70001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/20080314173256334b6.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UD8BV70001124J.html" target="_blank"><font color="#ffffff">阿沛&middot;阿旺晋美</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UDC2VL0001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/2008031417343867464.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UDC2VL0001124J.html" target="_blank"><font color="#ffffff">帕巴拉&middot;格列朗杰</font></a></div>
            </td>
        </tr>
    </tbody>
</table>
<div class="blank20"><font color="#ffffff"></font></div>
<table cellspacing="0" cellpadding="0" width="720" border="0">
    <tbody>
        <tr>
            <td style="WIDTH: 190px">&nbsp;</td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UDF4G30001124J.html" target="_blank"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/20080314174205054da.jpg" width="67" /></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UDF4G30001124J.html" target="_blank"><font color="#ffffff">副主席 马万祺</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/14/46U06JRG0001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/20080314174405b2ee1.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/14/46U06JRG0001124J.html" target="_blank"><font color="#ffffff">白立忱</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/13/46TVDGPJ0001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/200803141746125ac14.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 90px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/13/46TVDGPJ0001124J.html" target="_blank"><font color="#ffffff">陈奎元</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UDH2HB0001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/2008031417494625012.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 140px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UDH2HB0001124J.html" target="_blank"><font color="#ffffff">阿不来提&middot;阿不都热西提</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UDJNT60001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/20080314184423a1bda.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UDJNT60001124J.html" target="_blank"><font color="#ffffff">李兆焯</font></a></div>
            </td>
        </tr>
    </tbody>
</table>
<div class="blank20"><font color="#ffffff"></font></div>
<table cellspacing="0" cellpadding="0" width="720" border="0">
    <tbody>
        <tr>
            <td style="WIDTH: 190px">&nbsp;</td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UD4H230001124J.html" target="_blank"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/200803141849039491e.jpg" width="67" /></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UD4H230001124J.html" target="_blank"><font color="#ffffff">副主席 黄孟复</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UD5QGU0001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/20080314185135cc809.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UD5QGU0001124J.html" target="_blank"><font color="#ffffff">董建华</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UD7HBO0001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/2008031418540942fa4.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UD7HBO0001124J.html" target="_blank"><font color="#ffffff">张梅颖</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UD9JN70001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/200803141856309ecf3.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UD9JN70001124J.html" target="_blank"><font color="#ffffff">张榕明</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/13/46TVLQTF00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/200803141858285be05.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/13/46TVLQTF00012JLG.html" target="_blank"><font color="#ffffff">钱运录</font></a></div>
            </td>
        </tr>
    </tbody>
</table>
<div class="blank20"><font color="#ffffff"></font></div>
<table cellspacing="0" cellpadding="0" width="720" border="0">
    <tbody>
        <tr>
            <td style="WIDTH: 190px"><font color="#ffffff"></font></td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/13/46TV9DSE00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/2008031419011844631.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/13/46TV9DSE00012JLG.html" target="_blank"><font color="#ffffff">副主席 孙家正</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UDE6M90001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/20080314190300befed.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UDE6M90001124J.html" target="_blank"><font color="#ffffff">李金华</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/13/46TVKBTQ00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/200803141905310beb3.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/13/46TVKBTQ00012JLG.html" target="_blank"><font color="#ffffff">郑万通</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/13/46TVF7M20001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/200803141907500c611.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/13/46TVF7M20001124J.html" target="_blank"><font color="#ffffff">邓朴方</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/18/46UDNR880001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/200803141910131a614.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/18/46UDNR880001124J.html" target="_blank"><font color="#ffffff">万钢</font></a></div>
            </td>
        </tr>
    </tbody>
</table>
<div class="blank20"><font color="#ffffff"></font></div>
<table cellspacing="0" cellpadding="0" width="720" border="0">
    <tbody>
        <tr>
            <td style="WIDTH: 190px">&nbsp;</td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UDHJIM0001124J.html" target="_blank"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/20080314191211b4bb3.jpg" width="67" /></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UDHJIM0001124J.html" target="_blank"><font color="#ffffff">副主席 林文漪</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UDFPNI0001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/20080314191340dab1b.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UDFPNI0001124J.html" target="_blank"><font color="#ffffff">厉无畏</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UDC64F0001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/20080314191608d60cc.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UDC64F0001124J.html" target="_blank"><font color="#ffffff">罗富和</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UD9KAM0001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/200803141917555e388.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UD9KAM0001124J.html" target="_blank"><font color="#ffffff">陈宗兴</font></a></div>
            </td>
            <td>
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/17/46UD6G2K0001124J.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg21.163.com/cnews/2008/3/14/20080314191949e3e17.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/17/46UD6G2K0001124J.html" target="_blank"><font color="#ffffff">王志珍</font></a></div>
            </td>
        </tr>
    </tbody>
</table>
<div class="blank20"><font color="#ffffff"></font></div>
<table cellspacing="0" cellpadding="0" width="694" border="0">
    <tbody>
        <tr>
            <td width="177">
            <div style="BACKGROUND: #fff; MARGIN: 9px auto; WIDTH: 77px; HEIGHT: 96px"><a href="http://news.163.com/08/0313/13/46TVLQTF00012JLG.html" target="_blank"><font color="#ffffff"><img style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; MARGIN: 4px 0px 0px; BORDER-LEFT: #ccc 1px solid; BORDER-BOTTOM: #ccc 1px solid" height="86" alt="图片" src="http://cimg20.163.com/cnews/2008/3/14/200803141858285be05.jpg" width="67" /></font></a></div>
            <div style="BACKGROUND: #db0000; MARGIN: 0px auto; WIDTH: 170px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0313/13/46TVLQTF00012JLG.html" target="_blank"><font color="#ffffff">全国政协秘书长 钱运录</font></a><a style="COLOR: #fff" href="http://news.163.com/08/0312/15/46RKAVOL00012JLG.html"></a></div>
            </td>
            <td width="305">
            <div style="BACKGROUND: #ffc600; MARGIN: 0px auto; WIDTH: 280px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/13/46RDCU2V00012JLG.html"></a></div>
            </td>
            <td width="172">
            <div style="BACKGROUND: #ffc600; MARGIN: 0px auto; WIDTH: 100px; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center"><a style="COLOR: #fff" href="http://news.163.com/08/0312/15/46RKAVOL00012JLG.html"></a></div>
            </td>
        </tr>
    </tbody>
</table>]]></description>
   <link>http://pudding.sharera.com/blog/BlogTopic/54255.htm</link>
   <comments>http://pudding.sharera.com/blog/BlogTopic/54255.htm</comments>
   <guid>http://pudding.sharera.com/blog/BlogTopic/54255.htm</guid>
      <author>chendz0526@126.com</author>
   <source url="http://pudding.sharera.com/rss/rss20.xml">果冻</source>
  </item>
    <item>
   <title>Simple jpeg encoder</title>
   <description><![CDATA[<pre><span class="c">// Version 1.0a</span>
<span class="c">// Copyright (C) 1998, James R. Weeks anｄ BioElectroMech.</span>
<span class="c">// Visit BioElectroMech at www.obrador.com.  Email James@obrador.com.</span>

<span class="c">// See license.txt (included below - search for LICENSE.TXT) for details</span>
<span class="c">// about the allowed used of this software.</span>
<span class="c">// This software is based in part on the work of the Independent JPEG Group.</span>
<span class="c">// See IJGreadme.txt (included below - search for IJGREADME.TXT)</span>
<span class="c">// for details about the Independent JPEG Group's license.</span>

<span class="c">// This encoder is inspired by the Java Jpeg encoder by Florian Raemy,</span>
<span class="c">// studwww.eurecom.fr/~raemy.</span>
<span class="c">// It borrows a great deal of code anｄ structure from the Independent</span>
<span class="c">// Jpeg Group's Jpeg 6a library, Copyright Thomas G. Lane.</span>
<span class="c">// See license.txt for details.</span>

<span class="k">package</span> <a class="r" title="Search for references of 'net'" href=>net</a>.<a class="r" title="Search for references of 'sourceforge'" href=>sourceforge</a>.<a class="r" title="Search for references of 'processdash'" href=>processdash</a>.<a class="r" title="Search for references of 'ui'" href=>ui</a>.<a class="r" title="Search for references of 'lib'" href=>lib</a>;

<span class="c">//import java.applet.Applet;</span>
<span class="k">import</span> <a class="r" title="Search for references of 'java'" href=>java</a>.<a class="r" title="Search for references of 'awt'" href=>awt</a>.*;
<span class="k">import</span> <a class="r" title="Search for references of 'java'" href=>java</a>.<a class="r" title="Search for references of 'awt'" href=>awt</a>.<a class="r" title="Search for references of 'image'" href=>image</a>.*;
<span class="k">import</span> <a class="r" title="Search for references of 'java'" href=>java</a>.<a class="r" title="Search for references of 'io'" href=>io</a>.*;
<span class="k">import</span> <a class="r" title="Search for references of 'java'" href=>java</a>.<a class="r" title="Search for references of 'util'" href=>util</a>.*;

<span class="c">/*
* JpegEncoder - The JPEG main program which performs a jpeg compression of
* an image.
*/</span>

<span class="k">public</span> <span class="k">class</span> <a class="r" title="Search for references of 'JpegEncoder'" href=>JpegEncoder</a> <span class="k">extends</span> <a class="r" title="Search for references of 'Frame'" href=>Frame</a>
{
    <span class="c">//Thread runner;</span>
    <a class="r" title="Search for references of 'BufferedOutputStream'" href=>BufferedOutputStream</a> <a class="r" title="Search for references of 'outStream'" href=>outStream</a>;
    <span class="c">//Image image;</span>
    <a class="r" title="Search for references of 'JpegInfo'" href=>JpegInfo</a> <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>;
    <a class="r" title="Search for references of 'Huffman'" href=>Huffman</a> <a class="r" title="Search for references of 'Huf'" href=>Huf</a>;
    <a class="r" title="Search for references of 'DCT'" href=>DCT</a> <a class="r" title="Search for references of 'dct'" href=>dct</a>;
    <span class="k">int</span> <a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>, <a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>;
    <span class="k">int</span> <a class="r" title="Search for references of 'Quality'" href=>Quality</a>;
    <span class="c">//int code;</span>
    <span class="k">public</span> <span class="k">static</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'jpegNaturalOrder'" href=>jpegNaturalOrder</a> = {
          0,  1,  8, 16,  9,  2,  3, 10,
         17, 24, 32, 25, 18, 11,  4,  5,
         12, 19, 26, 33, 40, 48, 41, 34,
         27, 20, 13,  6,  7, 14, 21, 28,
         35, 42, 49, 56, 57, 50, 43, 36,
         29, 22, 15, 23, 30, 37, 44, 51,
         58, 59, 52, 45, 38, 31, 39, 46,
         53, 60, 61, 54, 47, 55, 62, 63,
        };

    <span class="k">public</span> <a class="r" title="Search for references of 'JpegEncoder'" href=>JpegEncoder</a>(<a class="r" title="Search for references of 'Image'" href=>Image</a> <a class="r" title="Search for references of 'image'" href=>image</a>, <span class="k">int</span> <a class="r" title="Search for references of 'quality'" href=>quality</a>, <a class="r" title="Search for references of 'OutputStream'" href=>OutputStream</a> <a class="r" title="Search for references of 'out'" href=>out</a>)
    {
                <a class="r" title="Search for references of 'MediaTracker'" href=>MediaTracker</a> <a class="r" title="Search for references of 'tracker'" href=>tracker</a> = <span class="k">new</span> <a class="r" title="Search for references of 'MediaTracker'" href=>MediaTracker</a>(<span class="k">this</span>);
                <a class="r" title="Search for references of 'tracker'" href=>tracker</a>.<a class="r" title="Search for references of 'addImage'" href=>addImage</a>(<a class="r" title="Search for references of 'image'" href=>image</a>, 0);
                <span class="k">try</span> {
                        <a class="r" title="Search for references of 'tracker'" href=>tracker</a>.<a class="r" title="Search for references of 'waitForID'" href=>waitForID</a>(0);
                }
                <span class="k">catch</span> (<a class="r" title="Search for references of 'InterruptedException'" href=>InterruptedException</a> <a class="r" title="Search for references of 'e'" href=>e</a>) {
<span class="c">// Got to do something?</span>
                }
        <span class="c">/*
        * Quality of the image.
        * 0 to 100 anｄ from bad image quality, high compression to good
        * image quality low compression
        */</span>
        <a class="r" title="Search for references of 'Quality'" href=>Quality</a>=<a class="r" title="Search for references of 'quality'" href=>quality</a>;

        <span class="c">/*
        * Getting picture information
        * It takes the Width, Height anｄ RGB scans of the image. 
        */</span>
        <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a> = <span class="k">new</span> <a class="r" title="Search for references of 'JpegInfo'" href=>JpegInfo</a>(<a class="r" title="Search for references of 'image'" href=>image</a>);

        <a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>=<a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>;
        <a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>=<a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>;
        <a class="r" title="Search for references of 'outStream'" href=>outStream</a> = <span class="k">new</span> <a class="r" title="Search for references of 'BufferedOutputStream'" href=>BufferedOutputStream</a>(<a class="r" title="Search for references of 'out'" href=>out</a>);
        <a class="r" title="Search for references of 'dct'" href=>dct</a> = <span class="k">new</span> <a class="r" title="Search for references of 'DCT'" href=>DCT</a>(<a class="r" title="Search for references of 'Quality'" href=>Quality</a>);
        <a class="r" title="Search for references of 'Huf'" href=>Huf</a>=<span class="k">new</span> <a class="r" title="Search for references of 'Huffman'" href=>Huffman</a>(<a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>,<a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>);
    }

    <span class="k">public</span> <span class="k">void</span> <a class="r" title="Search for references of 'setQuality'" href=>setQuality</a>(<span class="k">int</span> <a class="r" title="Search for references of 'quality'" href=>quality</a>) {
        <a class="r" title="Search for references of 'dct'" href=>dct</a> = <span class="k">new</span> <a class="r" title="Search for references of 'DCT'" href=>DCT</a>(<a class="r" title="Search for references of 'quality'" href=>quality</a>);
    }

    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'getQuality'" href=>getQuality</a>() {
        <span class="k">return</span> <a class="r" title="Search for references of 'Quality'" href=>Quality</a>;
    }

    <span class="k">public</span> <span class="k">void</span> <a class="r" title="Search for references of 'Compress'" href=>Compress</a>() {
        <a class="r" title="Search for references of 'WriteHeaders'" href=>WriteHeaders</a>(<a class="r" title="Search for references of 'outStream'" href=>outStream</a>);
        <a class="r" title="Search for references of 'WriteCompressedData'" href=>WriteCompressedData</a>(<a class="r" title="Search for references of 'outStream'" href=>outStream</a>);
        <a class="r" title="Search for references of 'WriteEOI'" href=>WriteEOI</a>(<a class="r" title="Search for references of 'outStream'" href=>outStream</a>);
        <span class="k">try</span> {
                <a class="r" title="Search for references of 'outStream'" href=>outStream</a>.<a class="r" title="Search for references of 'flush'" href=>flush</a>();
        } <span class="k">catch</span> (<a class="r" title="Search for references of 'IOException'" href=>IOException</a> <a class="r" title="Search for references of 'e'" href=>e</a>) {
                <a class="r" title="Search for references of 'System'" href=>System</a>.<a class="r" title="Search for references of 'out'" href=>out</a>.<a class="r" title="Search for references of 'println'" href=>println</a>(<span class="str">&quot;IO Error: &quot;</span> + <a class="r" title="Search for references of 'e'" href=>e</a>.<a class="r" title="Search for references of 'getMessage'" href=>getMessage</a>());
        }
    }

    <span class="k">public</span> <span class="k">void</span> <a class="r" title="Search for references of 'WriteCompressedData'" href=>WriteCompressedData</a>(<a class="r" title="Search for references of 'BufferedOutputStream'" href=>BufferedOutputStream</a> <a class="r" title="Search for references of 'outStream'" href=>outStream</a>) {
        <span class="k">int</span> <a class="r" title="Search for references of 'offset'" href=>offset</a>, <a class="r" title="Search for references of 'i'" href=>i</a>, <a class="r" title="Search for references of 'j'" href=>j</a>, <a class="r" title="Search for references of 'r'" href=>r</a>, <a class="r" title="Search for references of 'c'" href=>c</a>,<a class="r" title="Search for references of 'a'" href=>a</a> ,<a class="r" title="Search for references of 'b'" href=>b</a>, <a class="r" title="Search for references of 'temp'" href=>temp</a> = 0;
        <span class="k">int</span> <a class="r" title="Search for references of 'comp'" href=>comp</a>, <a class="r" title="Search for references of 'xpos'" href=>xpos</a>, <a class="r" title="Search for references of 'ypos'" href=>ypos</a>, <a class="r" title="Search for references of 'xblockoffset'" href=>xblockoffset</a>, <a class="r" title="Search for references of 'yblockoffset'" href=>yblockoffset</a>;
        <span class="k">float</span> <a class="r" title="Search for references of 'inputArray'" href=>inputArray</a>[][];
        <span class="k">float</span> <a class="r" title="Search for references of 'dctArray1'" href=>dctArray1</a>[][] = <span class="k">new</span> <span class="k">float</span>[8][8];
        <span class="k">double</span> <a class="r" title="Search for references of 'dctArray2'" href=>dctArray2</a>[][] = <span class="k">new</span> <span class="k">double</span>[8][8];
        <span class="k">int</span> <a class="r" title="Search for references of 'dctArray3'" href=>dctArray3</a>[] = <span class="k">new</span> <span class="k">int</span>[8*8];

        <span class="c">/*
         * This method controls the compression of the image.
         * Starting at the upper left of the image, it compresses 8x8 blocks
         * of data until the entire image has been compressed.
         */</span>

        <span class="k">int</span> <a class="r" title="Search for references of 'lastDCvalue'" href=>lastDCvalue</a>[] = <span class="k">new</span> <span class="k">int</span>[<a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'NumberOfComponents'" href=>NumberOfComponents</a>];
        <span class="k">int</span> <a class="r" title="Search for references of 'zeroArray'" href=>zeroArray</a>[] = <span class="k">new</span> <span class="k">int</span>[64]; <span class="c">// initialized to hold all zeros</span>
        <span class="k">int</span> <a class="r" title="Search for references of 'Width'" href=>Width</a> = 0, <a class="r" title="Search for references of 'Height'" href=>Height</a> = 0;
        <span class="k">int</span> <a class="r" title="Search for references of 'nothing'" href=>nothing</a> = 0, <a class="r" title="Search for references of 'not'" href=>not</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'MinBlockWidth'" href=>MinBlockWidth</a>, <a class="r" title="Search for references of 'MinBlockHeight'" href=>MinBlockHeight</a>;
<span class="c">// This initial setting of MinBlockWidth anｄ MinBlockHeight is done to</span>
<span class="c">// ensure they start with values larger than will actually be the case.</span>
        <a class="r" title="Search for references of 'MinBlockWidth'" href=>MinBlockWidth</a> = ((<a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>%8 != 0) ? (<span class="k">int</span>) (<a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'floor'" href=>floor</a>((<span class="k">double</span>) <a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>/8.0) + 1)*8 : <a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>);
        <a class="r" title="Search for references of 'MinBlockHeight'" href=>MinBlockHeight</a> = ((<a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>%8 != 0) ? (<span class="k">int</span>) (<a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'floor'" href=>floor</a>((<span class="k">double</span>) <a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>/8.0) + 1)*8: <a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>);
        <span class="k">for</span> (<a class="r" title="Search for references of 'comp'" href=>comp</a> = 0; <a class="r" title="Search for references of 'comp'" href=>comp</a> &lt; <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'NumberOfComponents'" href=>NumberOfComponents</a>; <a class="r" title="Search for references of 'comp'" href=>comp</a>++) {
                <a class="r" title="Search for references of 'MinBlockWidth'" href=>MinBlockWidth</a> = <a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'min'" href=>min</a>(<a class="r" title="Search for references of 'MinBlockWidth'" href=>MinBlockWidth</a>, <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'BlockWidth'" href=>BlockWidth</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>]);
                <a class="r" title="Search for references of 'MinBlockHeight'" href=>MinBlockHeight</a> = <a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'min'" href=>min</a>(<a class="r" title="Search for references of 'MinBlockHeight'" href=>MinBlockHeight</a>, <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'BlockHeight'" href=>BlockHeight</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>]);
        }
        <a class="r" title="Search for references of 'xpos'" href=>xpos</a> = 0;
        <span class="k">for</span> (<a class="r" title="Search for references of 'r'" href=>r</a> = 0; <a class="r" title="Search for references of 'r'" href=>r</a> &lt; <a class="r" title="Search for references of 'MinBlockHeight'" href=>MinBlockHeight</a>; <a class="r" title="Search for references of 'r'" href=>r</a>++) {
           <span class="k">for</span> (<a class="r" title="Search for references of 'c'" href=>c</a> = 0; <a class="r" title="Search for references of 'c'" href=>c</a> &lt; <a class="r" title="Search for references of 'MinBlockWidth'" href=>MinBlockWidth</a>; <a class="r" title="Search for references of 'c'" href=>c</a>++) {
               <a class="r" title="Search for references of 'xpos'" href=>xpos</a> = <a class="r" title="Search for references of 'c'" href=>c</a>*8;
               <a class="r" title="Search for references of 'ypos'" href=>ypos</a> = <a class="r" title="Search for references of 'r'" href=>r</a>*8;
               <span class="k">for</span> (<a class="r" title="Search for references of 'comp'" href=>comp</a> = 0; <a class="r" title="Search for references of 'comp'" href=>comp</a> &lt; <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'NumberOfComponents'" href=>NumberOfComponents</a>; <a class="r" title="Search for references of 'comp'" href=>comp</a>++) {
                  <a class="r" title="Search for references of 'Width'" href=>Width</a> = <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'BlockWidth'" href=>BlockWidth</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>];
                  <a class="r" title="Search for references of 'Height'" href=>Height</a> = <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'BlockHeight'" href=>BlockHeight</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>];
                  <a class="r" title="Search for references of 'inputArray'" href=>inputArray</a> = (<span class="k">float</span>[][]) <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'Components'" href=>Components</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>];

                  <span class="k">for</span>(<a class="r" title="Search for references of 'i'" href=>i</a> = 0; <a class="r" title="Search for references of 'i'" href=>i</a> &lt; <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'VsampFactor'" href=>VsampFactor</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>]; <a class="r" title="Search for references of 'i'" href=>i</a>++) {
                     <span class="k">for</span>(<a class="r" title="Search for references of 'j'" href=>j</a> = 0; <a class="r" title="Search for references of 'j'" href=>j</a> &lt; <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'HsampFactor'" href=>HsampFactor</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>]; <a class="r" title="Search for references of 'j'" href=>j</a>++) {
                        <a class="r" title="Search for references of 'xblockoffset'" href=>xblockoffset</a> = <a class="r" title="Search for references of 'j'" href=>j</a> * 8;
                        <a class="r" title="Search for references of 'yblockoffset'" href=>yblockoffset</a> = <a class="r" title="Search for references of 'i'" href=>i</a> * 8;
                        <span class="k">for</span> (<a class="r" title="Search for references of 'a'" href=>a</a> = 0; <a class="r" title="Search for references of 'a'" href=>a</a> &lt; 8; <a class="r" title="Search for references of 'a'" href=>a</a>++) {
                           <span class="k">for</span> (<a class="r" title="Search for references of 'b'" href=>b</a> = 0; <a class="r" title="Search for references of 'b'" href=>b</a> &lt; 8; <a class="r" title="Search for references of 'b'" href=>b</a>++) {

<span class="c">// I believe this is where the dirty line at the bottom of the image is</span>
<span class="c">// coming from.  I need to do a check here to make sure I'm not reading past</span>
<span class="c">// image data.</span>
<span class="c">// This seems to not be a big issue right now. (04/04/98)</span>

                              <a class="r" title="Search for references of 'dctArray1'" href=>dctArray1</a>[<a class="r" title="Search for references of 'a'" href=>a</a>][<a class="r" title="Search for references of 'b'" href=>b</a>] = <a class="r" title="Search for references of 'inputArray'" href=>inputArray</a>[<a class="r" title="Search for references of 'ypos'" href=>ypos</a> + <a class="r" title="Search for references of 'yblockoffset'" href=>yblockoffset</a> + <a class="r" title="Search for references of 'a'" href=>a</a>][<a class="r" title="Search for references of 'xpos'" href=>xpos</a> + <a class="r" title="Search for references of 'xblockoffset'" href=>xblockoffset</a> + <a class="r" title="Search for references of 'b'" href=>b</a>];
                           }
                        }
<span class="c">// The following code commented out because on some images this technique</span>
<span class="c">// results in poor right anｄ bottom borders.</span>
<span class="c">//                        if ((!JpegObj.lastColumnIsDummy[comp] || c &lt; Width - 1) &amp;&amp; (!JpegObj.lastRowIsDummy[comp] || r &lt; Height - 1)) {</span>
                           <a class="r" title="Search for references of 'dctArray2'" href=>dctArray2</a> = <a class="r" title="Search for references of 'dct'" href=>dct</a>.<a class="r" title="Search for references of 'forwardDCT'" href=>forwardDCT</a>(<a class="r" title="Search for references of 'dctArray1'" href=>dctArray1</a>);
                           <a class="r" title="Search for references of 'dctArray3'" href=>dctArray3</a> = <a class="r" title="Search for references of 'dct'" href=>dct</a>.<a class="r" title="Search for references of 'quantizeBlock'" href=>quantizeBlock</a>(<a class="r" title="Search for references of 'dctArray2'" href=>dctArray2</a>, <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'QtableNumber'" href=>QtableNumber</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>]);
<span class="c">//                        }</span>
<span class="c">//                        else {</span>
<span class="c">//                           zeroArray[0] = dctArray3[0];</span>
<span class="c">//                           zeroArray[0] = lastDCvalue[comp];</span>
<span class="c">//                           dctArray3 = zeroArray;</span>
<span class="c">//                        }</span>
                        <a class="r" title="Search for references of 'Huf'" href=>Huf</a>.<a class="r" title="Search for references of 'HuffmanBlockEncoder'" href=>HuffmanBlockEncoder</a>(<a class="r" title="Search for references of 'outStream'" href=>outStream</a>, <a class="r" title="Search for references of 'dctArray3'" href=>dctArray3</a>, <a class="r" title="Search for references of 'lastDCvalue'" href=>lastDCvalue</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>], <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'DCtableNumber'" href=>DCtableNumber</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>], <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'ACtableNumber'" href=>ACtableNumber</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>]);
                        <a class="r" title="Search for references of 'lastDCvalue'" href=>lastDCvalue</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>] = <a class="r" title="Search for references of 'dctArray3'" href=>dctArray3</a>[0];
                     }
                  }
               }
            }
        }
        <a class="r" title="Search for references of 'Huf'" href=>Huf</a>.<a class="r" title="Search for references of 'flushBuffer'" href=>flushBuffer</a>(<a class="r" title="Search for references of 'outStream'" href=>outStream</a>);
    }

    <span class="k">public</span> <span class="k">void</span> <a class="r" title="Search for references of 'WriteEOI'" href=>WriteEOI</a>(<a class="r" title="Search for references of 'BufferedOutputStream'" href=>BufferedOutputStream</a> <a class="r" title="Search for references of 'out'" href=>out</a>) {
        <span class="k">byte</span>[] <a class="r" title="Search for references of 'EOI'" href=>EOI</a> = {(<span class="k">byte</span>) 0xFF, (<span class="k">byte</span>) 0xD9};
        <a class="r" title="Search for references of 'WriteMarker'" href=>WriteMarker</a>(<a class="r" title="Search for references of 'EOI'" href=>EOI</a>, <a class="r" title="Search for references of 'out'" href=>out</a>);
    }

    <span class="k">public</span> <span class="k">void</span> <a class="r" title="Search for references of 'WriteHeaders'" href=>WriteHeaders</a>(<a class="r" title="Search for references of 'BufferedOutputStream'" href=>BufferedOutputStream</a> <a class="r" title="Search for references of 'out'" href=>out</a>) {
        <span class="k">int</span> <a class="r" title="Search for references of 'i'" href=>i</a>, <a class="r" title="Search for references of 'j'" href=>j</a>, <a class="r" title="Search for references of 'index'" href=>index</a>, <a class="r" title="Search for references of 'offset'" href=>offset</a>, <a class="r" title="Search for references of 'length'" href=>length</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'tempArray'" href=>tempArray</a>[];

<span class="c">// the SOI marker</span>
        <span class="k">byte</span>[] <a class="r" title="Search for references of 'SOI'" href=>SOI</a> = {(<span class="k">byte</span>) 0xFF, (<span class="k">byte</span>) 0xD8};
        <a class="r" title="Search for references of 'WriteMarker'" href=>WriteMarker</a>(<a class="r" title="Search for references of 'SOI'" href=>SOI</a>, <a class="r" title="Search for references of 'out'" href=>out</a>);

<span class="c">// The order of the following headers is quiet inconsequential.</span>
<span class="c">// the JFIF header</span>
        <span class="k">byte</span> <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[] = <span class="k">new</span> <span class="k">byte</span>[18];
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[0] = (<span class="k">byte</span>) 0xff;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[1] = (<span class="k">byte</span>) 0xe0;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[2] = (<span class="k">byte</span>) 0x00;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[3] = (<span class="k">byte</span>) 0x10;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[4] = (<span class="k">byte</span>) 0x4a;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[5] = (<span class="k">byte</span>) 0x46;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[6] = (<span class="k">byte</span>) 0x49;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[7] = (<span class="k">byte</span>) 0x46;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[8] = (<span class="k">byte</span>) 0x00;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[9] = (<span class="k">byte</span>) 0x01;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[10] = (<span class="k">byte</span>) 0x00;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[11] = (<span class="k">byte</span>) 0x00;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[12] = (<span class="k">byte</span>) 0x00;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[13] = (<span class="k">byte</span>) 0x01;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[14] = (<span class="k">byte</span>) 0x00;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[15] = (<span class="k">byte</span>) 0x01;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[16] = (<span class="k">byte</span>) 0x00;
        <a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>[17] = (<span class="k">byte</span>) 0x00;
        <a class="r" title="Search for references of 'WriteArray'" href=>WriteArray</a>(<a class="r" title="Search for references of 'JFIF'" href=>JFIF</a>, <a class="r" title="Search for references of 'out'" href=>out</a>);

<span class="c">// Comment Header</span>
        <a class="r" title="Search for references of 'String'" href=>String</a> <a class="r" title="Search for references of 'comment'" href=>comment</a> = <span class="k">new</span> <a class="r" title="Search for references of 'String'" href=>String</a>();
        <a class="r" title="Search for references of 'comment'" href=>comment</a> = <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'getComment'" href=>getComment</a>();
        <a class="r" title="Search for references of 'length'" href=>length</a> = <a class="r" title="Search for references of 'comment'" href=>comment</a>.<a class="r" title="Search for references of 'length'" href=>length</a>();
        <span class="k">byte</span> <a class="r" title="Search for references of 'COM'" href=>COM</a>[] = <span class="k">new</span> <span class="k">byte</span>[<a class="r" title="Search for references of 'length'" href=>length</a> + 4];
        <a class="r" title="Search for references of 'COM'" href=>COM</a>[0] = (<span class="k">byte</span>) 0xFF;
        <a class="r" title="Search for references of 'COM'" href=>COM</a>[1] = (<span class="k">byte</span>) 0xFE;
        <a class="r" title="Search for references of 'COM'" href=>COM</a>[2] = (<span class="k">byte</span>) ((<a class="r" title="Search for references of 'length'" href=>length</a> &gt;&gt; 8) &amp; 0xFF);
        <a class="r" title="Search for references of 'COM'" href=>COM</a>[3] = (<span class="k">byte</span>) (<a class="r" title="Search for references of 'length'" href=>length</a> &amp; 0xFF);
        <a class="r" title="Search for references of 'java'" href=>java</a>.<a class="r" title="Search for references of 'lang'" href=>lang</a>.<a class="r" title="Search for references of 'System'" href=>System</a>.<a class="r" title="Search for references of 'arraycopy'" href=>arraycopy</a>(<a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'Comment'" href=>Comment</a>.<a class="r" title="Search for references of 'getBytes'" href=>getBytes</a>(), 0, <a class="r" title="Search for references of 'COM'" href=>COM</a>, 4, <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'Comment'" href=>Comment</a>.<a class="r" title="Search for references of 'length'" href=>length</a>());
        <a class="r" title="Search for references of 'WriteArray'" href=>WriteArray</a>(<a class="r" title="Search for references of 'COM'" href=>COM</a>, <a class="r" title="Search for references of 'out'" href=>out</a>);

<span class="c">// The DQT header</span>
<span class="c">// 0 is the luminance index anｄ 1 is the chrominance index</span>
        <span class="k">byte</span> <a class="r" title="Search for references of 'DQT'" href=>DQT</a>[] = <span class="k">new</span> <span class="k">byte</span>[134];
        <a class="r" title="Search for references of 'DQT'" href=>DQT</a>[0] = (<span class="k">byte</span>) 0xFF;
        <a class="r" title="Search for references of 'DQT'" href=>DQT</a>[1] = (<span class="k">byte</span>) 0xDB;
        <a class="r" title="Search for references of 'DQT'" href=>DQT</a>[2] = (<span class="k">byte</span>) 0x00;
        <a class="r" title="Search for references of 'DQT'" href=>DQT</a>[3] = (<span class="k">byte</span>) 0x84;
        <a class="r" title="Search for references of 'offset'" href=>offset</a> = 4;
        <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 0; <a class="r" title="Search for references of 'i'" href=>i</a> &lt; 2; <a class="r" title="Search for references of 'i'" href=>i</a>++) {
                <a class="r" title="Search for references of 'DQT'" href=>DQT</a>[<a class="r" title="Search for references of 'offset'" href=>offset</a>++] = (<span class="k">byte</span>) ((0 &lt;&lt; 4) + <a class="r" title="Search for references of 'i'" href=>i</a>);
                <a class="r" title="Search for references of 'tempArray'" href=>tempArray</a> = (<span class="k">int</span>[]) <a class="r" title="Search for references of 'dct'" href=>dct</a>.<a class="r" title="Search for references of 'quantum'" href=>quantum</a>[<a class="r" title="Search for references of 'i'" href=>i</a>];
                <span class="k">for</span> (<a class="r" title="Search for references of 'j'" href=>j</a> = 0; <a class="r" title="Search for references of 'j'" href=>j</a> &lt; 64; <a class="r" title="Search for references of 'j'" href=>j</a>++) {
                        <a class="r" title="Search for references of 'DQT'" href=>DQT</a>[<a class="r" title="Search for references of 'offset'" href=>offset</a>++] = (<span class="k">byte</span>) <a class="r" title="Search for references of 'tempArray'" href=>tempArray</a>[<a class="r" title="Search for references of 'jpegNaturalOrder'" href=>jpegNaturalOrder</a>[<a class="r" title="Search for references of 'j'" href=>j</a>]];
                }
        }
        <a class="r" title="Search for references of 'WriteArray'" href=>WriteArray</a>(<a class="r" title="Search for references of 'DQT'" href=>DQT</a>, <a class="r" title="Search for references of 'out'" href=>out</a>);

<span class="c">// Start of Frame Header</span>
        <span class="k">byte</span> <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[] = <span class="k">new</span> <span class="k">byte</span>[19];
        <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[0] = (<span class="k">byte</span>) 0xFF;
        <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[1] = (<span class="k">byte</span>) 0xC0;
        <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[2] = (<span class="k">byte</span>) 0x00;
        <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[3] = (<span class="k">byte</span>) 17;
        <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[4] = (<span class="k">byte</span>) <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'Precision'" href=>Precision</a>;
        <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[5] = (<span class="k">byte</span>) ((<a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a> &gt;&gt; 8) &amp; 0xFF);
        <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[6] = (<span class="k">byte</span>) ((<a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>) &amp; 0xFF);
        <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[7] = (<span class="k">byte</span>) ((<a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a> &gt;&gt; 8) &amp; 0xFF);
        <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[8] = (<span class="k">byte</span>) ((<a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>) &amp; 0xFF);
        <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[9] = (<span class="k">byte</span>) <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'NumberOfComponents'" href=>NumberOfComponents</a>;
        <a class="r" title="Search for references of 'index'" href=>index</a> = 10;
        <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 0; <a class="r" title="Search for references of 'i'" href=>i</a> &lt; <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[9]; <a class="r" title="Search for references of 'i'" href=>i</a>++) {
                <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[<a class="r" title="Search for references of 'index'" href=>index</a>++] = (<span class="k">byte</span>) <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'CompID'" href=>CompID</a>[<a class="r" title="Search for references of 'i'" href=>i</a>];
                <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[<a class="r" title="Search for references of 'index'" href=>index</a>++] = (<span class="k">byte</span>) ((<a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'HsampFactor'" href=>HsampFactor</a>[<a class="r" title="Search for references of 'i'" href=>i</a>] &lt;&lt; 4) + <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'VsampFactor'" href=>VsampFactor</a>[<a class="r" title="Search for references of 'i'" href=>i</a>]);
                <a class="r" title="Search for references of 'SOF'" href=>SOF</a>[<a class="r" title="Search for references of 'index'" href=>index</a>++] = (<span class="k">byte</span>) <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'QtableNumber'" href=>QtableNumber</a>[<a class="r" title="Search for references of 'i'" href=>i</a>];
        }
        <a class="r" title="Search for references of 'WriteArray'" href=>WriteArray</a>(<a class="r" title="Search for references of 'SOF'" href=>SOF</a>, <a class="r" title="Search for references of 'out'" href=>out</a>);

<span class="c">// The DHT Header</span>
        <span class="k">byte</span> <a class="r" title="Search for references of 'DHT1'" href=>DHT1</a>[], <a class="r" title="Search for references of 'DHT2'" href=>DHT2</a>[], <a class="r" title="Search for references of 'DHT3'" href=>DHT3</a>[], <a class="r" title="Search for references of 'DHT4'" href=>DHT4</a>[];
        <span class="k">int</span> <a class="r" title="Search for references of 'bytes'" href=>bytes</a>, <a class="r" title="Search for references of 'temp'" href=>temp</a>, <a class="r" title="Search for references of 'oldindex'" href=>oldindex</a>, <a class="r" title="Search for references of 'intermediateindex'" href=>intermediateindex</a>;
        <a class="r" title="Search for references of 'length'" href=>length</a> = 2;
        <a class="r" title="Search for references of 'index'" href=>index</a> = 4;
        <a class="r" title="Search for references of 'oldindex'" href=>oldindex</a> = 4;
        <a class="r" title="Search for references of 'DHT1'" href=>DHT1</a> = <span class="k">new</span> <span class="k">byte</span>[17];
        <a class="r" title="Search for references of 'DHT4'" href=>DHT4</a> = <span class="k">new</span> <span class="k">byte</span>[4];
        <a class="r" title="Search for references of 'DHT4'" href=>DHT4</a>[0] = (<span class="k">byte</span>) 0xFF;
        <a class="r" title="Search for references of 'DHT4'" href=>DHT4</a>[1] = (<span class="k">byte</span>) 0xC4;
        <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 0; <a class="r" title="Search for references of 'i'" href=>i</a> &lt; 4; <a class="r" title="Search for references of 'i'" href=>i</a>++ ) {
                <a class="r" title="Search for references of 'bytes'" href=>bytes</a> = 0;
                <a class="r" title="Search for references of 'DHT1'" href=>DHT1</a>[<a class="r" title="Search for references of 'index'" href=>index</a>++ - <a class="r" title="Search for references of 'oldindex'" href=>oldindex</a>] = (<span class="k">byte</span>) ((<span class="k">int</span>[]) <a class="r" title="Search for references of 'Huf'" href=>Huf</a>.<a class="r" title="Search for references of 'bits'" href=>bits</a>.<a class="r" title="Search for references of 'elementAt'" href=>elementAt</a>(<a class="r" title="Search for references of 'i'" href=>i</a>))[0];
                <span class="k">for</span> (<a class="r" title="Search for references of 'j'" href=>j</a> = 1; <a class="r" title="Search for references of 'j'" href=>j</a> &lt; 17; <a class="r" title="Search for references of 'j'" href=>j</a>++) {
                        <a class="r" title="Search for references of 'temp'" href=>temp</a> = ((<span class="k">int</span>[]) <a class="r" title="Search for references of 'Huf'" href=>Huf</a>.<a class="r" title="Search for references of 'bits'" href=>bits</a>.<a class="r" title="Search for references of 'elementAt'" href=>elementAt</a>(<a class="r" title="Search for references of 'i'" href=>i</a>))[<a class="r" title="Search for references of 'j'" href=>j</a>];
                        <a class="r" title="Search for references of 'DHT1'" href=>DHT1</a>[<a class="r" title="Search for references of 'index'" href=>index</a>++ - <a class="r" title="Search for references of 'oldindex'" href=>oldindex</a>] =(<span class="k">byte</span>) <a class="r" title="Search for references of 'temp'" href=>temp</a>;
                        <a class="r" title="Search for references of 'bytes'" href=>bytes</a> += <a class="r" title="Search for references of 'temp'" href=>temp</a>;
                }
                <a class="r" title="Search for references of 'intermediateindex'" href=>intermediateindex</a> = <a class="r" title="Search for references of 'index'" href=>index</a>;
                <a class="r" title="Search for references of 'DHT2'" href=>DHT2</a> = <span class="k">new</span> <span class="k">byte</span>[<a class="r" title="Search for references of 'bytes'" href=>bytes</a>];
                <span class="k">for</span> (<a class="r" title="Search for references of 'j'" href=>j</a> = 0; <a class="r" title="Search for references of 'j'" href=>j</a> &lt; <a class="r" title="Search for references of 'bytes'" href=>bytes</a>; <a class="r" title="Search for references of 'j'" href=>j</a>++) {
                        <a class="r" title="Search for references of 'DHT2'" href=>DHT2</a>[<a class="r" title="Search for references of 'index'" href=>index</a>++ - <a class="r" title="Search for references of 'intermediateindex'" href=>intermediateindex</a>] = (<span class="k">byte</span>) ((<span class="k">int</span>[]) <a class="r" title="Search for references of 'Huf'" href=>Huf</a>.<a class="r" title="Search for references of 'val'" href=>val</a>.<a class="r" title="Search for references of 'elementAt'" href=>elementAt</a>(<a class="r" title="Search for references of 'i'" href=>i</a>))[<a class="r" title="Search for references of 'j'" href=>j</a>];
                }
                <a class="r" title="Search for references of 'DHT3'" href=>DHT3</a> = <span class="k">new</span> <span class="k">byte</span>[<a class="r" title="Search for references of 'index'" href=>index</a>];
                <a class="r" title="Search for references of 'java'" href=>java</a>.<a class="r" title="Search for references of 'lang'" href=>lang</a>.<a class="r" title="Search for references of 'System'" href=>System</a>.<a class="r" title="Search for references of 'arraycopy'" href=>arraycopy</a>(<a class="r" title="Search for references of 'DHT4'" href=>DHT4</a>, 0, <a class="r" title="Search for references of 'DHT3'" href=>DHT3</a>, 0, <a class="r" title="Search for references of 'oldindex'" href=>oldindex</a>);
                <a class="r" title="Search for references of 'java'" href=>java</a>.<a class="r" title="Search for references of 'lang'" href=>lang</a>.<a class="r" title="Search for references of 'System'" href=>System</a>.<a class="r" title="Search for references of 'arraycopy'" href=>arraycopy</a>(<a class="r" title="Search for references of 'DHT1'" href=>DHT1</a>, 0, <a class="r" title="Search for references of 'DHT3'" href=>DHT3</a>, <a class="r" title="Search for references of 'oldindex'" href=>oldindex</a>, 17);
                <a class="r" title="Search for references of 'java'" href=>java</a>.<a class="r" title="Search for references of 'lang'" href=>lang</a>.<a class="r" title="Search for references of 'System'" href=>System</a>.<a class="r" title="Search for references of 'arraycopy'" href=>arraycopy</a>(<a class="r" title="Search for references of 'DHT2'" href=>DHT2</a>, 0, <a class="r" title="Search for references of 'DHT3'" href=>DHT3</a>, <a class="r" title="Search for references of 'oldindex'" href=>oldindex</a> + 17, <a class="r" title="Search for references of 'bytes'" href=>bytes</a>);
                <a class="r" title="Search for references of 'DHT4'" href=>DHT4</a> = <a class="r" title="Search for references of 'DHT3'" href=>DHT3</a>;
                <a class="r" title="Search for references of 'oldindex'" href=>oldindex</a> = <a class="r" title="Search for references of 'index'" href=>index</a>;
        }
        <a class="r" title="Search for references of 'DHT4'" href=>DHT4</a>[2] = (<span class="k">byte</span>) (((<a class="r" title="Search for references of 'index'" href=>index</a> - 2) &gt;&gt; 8)&amp; 0xFF);
        <a class="r" title="Search for references of 'DHT4'" href=>DHT4</a>[3] = (<span class="k">byte</span>) ((<a class="r" title="Search for references of 'index'" href=>index</a> -2) &amp; 0xFF);
        <a class="r" title="Search for references of 'WriteArray'" href=>WriteArray</a>(<a class="r" title="Search for references of 'DHT4'" href=>DHT4</a>, <a class="r" title="Search for references of 'out'" href=>out</a>);


<span class="c">// Start of Scan Header</span>
        <span class="k">byte</span> <a class="r" title="Search for references of 'SOS'" href=>SOS</a>[] = <span class="k">new</span> <span class="k">byte</span>[14];
        <a class="r" title="Search for references of 'SOS'" href=>SOS</a>[0] = (<span class="k">byte</span>) 0xFF;
        <a class="r" title="Search for references of 'SOS'" href=>SOS</a>[1] = (<span class="k">byte</span>) 0xDA;
        <a class="r" title="Search for references of 'SOS'" href=>SOS</a>[2] = (<span class="k">byte</span>) 0x00;
        <a class="r" title="Search for references of 'SOS'" href=>SOS</a>[3] = (<span class="k">byte</span>) 12;
        <a class="r" title="Search for references of 'SOS'" href=>SOS</a>[4] = (<span class="k">byte</span>) <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'NumberOfComponents'" href=>NumberOfComponents</a>;
        <a class="r" title="Search for references of 'index'" href=>index</a> = 5;
        <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 0; <a class="r" title="Search for references of 'i'" href=>i</a> &lt; <a class="r" title="Search for references of 'SOS'" href=>SOS</a>[4]; <a class="r" title="Search for references of 'i'" href=>i</a>++) {
                <a class="r" title="Search for references of 'SOS'" href=>SOS</a>[<a class="r" title="Search for references of 'index'" href=>index</a>++] = (<span class="k">byte</span>) <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'CompID'" href=>CompID</a>[<a class="r" title="Search for references of 'i'" href=>i</a>];
                <a class="r" title="Search for references of 'SOS'" href=>SOS</a>[<a class="r" title="Search for references of 'index'" href=>index</a>++] = (<span class="k">byte</span>) ((<a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'DCtableNumber'" href=>DCtableNumber</a>[<a class="r" title="Search for references of 'i'" href=>i</a>] &lt;&lt; 4) + <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'ACtableNumber'" href=>ACtableNumber</a>[<a class="r" title="Search for references of 'i'" href=>i</a>]);
        }
        <a class="r" title="Search for references of 'SOS'" href=>SOS</a>[<a class="r" title="Search for references of 'index'" href=>index</a>++] = (<span class="k">byte</span>) <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'Ss'" href=>Ss</a>;
        <a class="r" title="Search for references of 'SOS'" href=>SOS</a>[<a class="r" title="Search for references of 'index'" href=>index</a>++] = (<span class="k">byte</span>) <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'Se'" href=>Se</a>;
        <a class="r" title="Search for references of 'SOS'" href=>SOS</a>[<a class="r" title="Search for references of 'index'" href=>index</a>++] = (<span class="k">byte</span>) ((<a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'Ah'" href=>Ah</a> &lt;&lt; 4) + <a class="r" title="Search for references of 'JpegObj'" href=>JpegObj</a>.<a class="r" title="Search for references of 'Al'" href=>Al</a>);
        <a class="r" title="Search for references of 'WriteArray'" href=>WriteArray</a>(<a class="r" title="Search for references of 'SOS'" href=>SOS</a>, <a class="r" title="Search for references of 'out'" href=>out</a>);

    }

    <span class="k">void</span> <a class="r" title="Search for references of 'WriteMarker'" href=>WriteMarker</a>(<span class="k">byte</span>[] <a class="r" title="Search for references of 'data'" href=>data</a>, <a class="r" title="Search for references of 'BufferedOutputStream'" href=>BufferedOutputStream</a> <a class="r" title="Search for references of 'out'" href=>out</a>) {
        <span class="k">try</span> {
                <a class="r" title="Search for references of 'out'" href=>out</a>.<a class="r" title="Search for references of 'write'" href=>write</a>(<a class="r" title="Search for references of 'data'" href=>data</a>, 0, 2);
        } <span class="k">catch</span> (<a class="r" title="Search for references of 'IOException'" href=>IOException</a> <a class="r" title="Search for references of 'e'" href=>e</a>) {
                <a class="r" title="Search for references of 'System'" href=>System</a>.<a class="r" title="Search for references of 'out'" href=>out</a>.<a class="r" title="Search for references of 'println'" href=>println</a>(<span class="str">&quot;IO Error: &quot;</span> + <a class="r" title="Search for references of 'e'" href=>e</a>.<a class="r" title="Search for references of 'getMessage'" href=>getMessage</a>());
        }
    }
        
    <span class="k">void</span> <a class="r" title="Search for references of 'WriteArray'" href=>WriteArray</a>(<span class="k">byte</span>[] <a class="r" title="Search for references of 'data'" href=>data</a>, <a class="r" title="Search for references of 'BufferedOutputStream'" href=>BufferedOutputStream</a> <a class="r" title="Search for references of 'out'" href=>out</a>) {
        <span class="k">int</span> <a class="r" title="Search for references of 'i'" href=>i</a>, <a class="r" title="Search for references of 'length'" href=>length</a>;
        <span class="k">try</span> {
                <a class="r" title="Search for references of 'length'" href=>length</a> = (((<span class="k">int</span>) (<a class="r" title="Search for references of 'data'" href=>data</a>[2] &amp; 0xFF)) &lt;&lt; 8) + (<span class="k">int</span>) (<a class="r" title="Search for references of 'data'" href=>data</a>[3] &amp; 0xFF) + 2;
                <a class="r" title="Search for references of 'out'" href=>out</a>.<a class="r" title="Search for references of 'write'" href=>write</a>(<a class="r" title="Search for references of 'data'" href=>data</a>, 0, <a class="r" title="Search for references of 'length'" href=>length</a>);
        } <span class="k">catch</span> (<a class="r" title="Search for references of 'IOException'" href=>IOException</a> <a class="r" title="Search for references of 'e'" href=>e</a>) {
                <a class="r" title="Search for references of 'System'" href=>System</a>.<a class="r" title="Search for references of 'out'" href=>out</a>.<a class="r" title="Search for references of 'println'" href=>println</a>(<span class="str">&quot;IO Error: &quot;</span> + <a class="r" title="Search for references of 'e'" href=>e</a>.<a class="r" title="Search for references of 'getMessage'" href=>getMessage</a>());
        }
    }

<span class="c">// This class incorporates quality scaling as implemented in the JPEG-6a</span>
<span class="c">// library.</span>

 <span class="c">/*
 * DCT - A Java implementation of the Discreet Cosine Transform
 */</span>

<span class="k">class</span> <a class="r" title="Search for references of 'DCT'" href=>DCT</a>
{
    <span class="c">/**
     * DCT Block Size - default 8
     */</span>
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'N'" href=>N</a>        = 8;

    <span class="c">/**
     * Image Quality (0-100) - default 80 (good image / good compression)
     */</span>
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'QUALITY'" href=>QUALITY</a> = 80;

    <span class="k">public</span> <a class="r" title="Search for references of 'Object'" href=>Object</a> <a class="r" title="Search for references of 'quantum'" href=>quantum</a>[] = <span class="k">new</span> <a class="r" title="Search for references of 'Object'" href=>Object</a>[2];
    <span class="k">public</span> <a class="r" title="Search for references of 'Object'" href=>Object</a> <a class="r" title="Search for references of 'Divisors'" href=>Divisors</a>[] = <span class="k">new</span> <a class="r" title="Search for references of 'Object'" href=>Object</a>[2];

    <span class="c">/**
     * Quantitization Matrix for luminace.
     */</span>
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[]     = <span class="k">new</span> <span class="k">int</span>[<a class="r" title="Search for references of 'N'" href=>N</a>*<a class="r" title="Search for references of 'N'" href=>N</a>];
    <span class="k">public</span> <span class="k">double</span> <a class="r" title="Search for references of 'DivisorsLuminance'" href=>DivisorsLuminance</a>[] = <span class="k">new</span> <span class="k">double</span>[<a class="r" title="Search for references of 'N'" href=>N</a>*<a class="r" title="Search for references of 'N'" href=>N</a>];

    <span class="c">/**
     * Quantitization Matrix for chrominance.
     */</span>
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[]     = <span class="k">new</span> <span class="k">int</span>[<a class="r" title="Search for references of 'N'" href=>N</a>*<a class="r" title="Search for references of 'N'" href=>N</a>];
    <span class="k">public</span> <span class="k">double</span> <a class="r" title="Search for references of 'DivisorsChrominance'" href=>DivisorsChrominance</a>[] = <span class="k">new</span> <span class="k">double</span>[<a class="r" title="Search for references of 'N'" href=>N</a>*<a class="r" title="Search for references of 'N'" href=>N</a>];

    <span class="c">/**
     * Constructs a new DCT object. Initializes the cosine transform matrix
     * these are used when computing the DCT anｄ it's inverse. This also
     * initializes the run length counters anｄ the ZigZag sequence. Note that
     * the image quality can be worse than 25 however the image will be
     * extemely pixelated, usually to a block size of N.
     *
     * @param QUALITY The quality of the image (0 worst - 100 best)
     *
     */</span>
    <span class="k">public</span> <a class="r" title="Search for references of 'DCT'" href=>DCT</a>(<span class="k">int</span> <a class="r" title="Search for references of 'QUALITY'" href=>QUALITY</a>)
    {
        <a class="r" title="Search for references of 'initMatrix'" href=>initMatrix</a>(<a class="r" title="Search for references of 'QUALITY'" href=>QUALITY</a>);
    }
                        

    <span class="c">/*
     * This method sets up the quantization matrix for luminance and
     * chrominance using the Quality parameter.
     */</span>
    <span class="k">private</span> <span class="k">void</span> <a class="r" title="Search for references of 'initMatrix'" href=>initMatrix</a>(<span class="k">int</span> <a class="r" title="Search for references of 'quality'" href=>quality</a>)
    {
        <span class="k">double</span>[] <a class="r" title="Search for references of 'AANscaleFactor'" href=>AANscaleFactor</a> = { 1.0, 1.387039845, 1.306562965, 1.175875602,
                                    1.0, 0.785694958, 0.541196100, 0.275899379};
        <span class="k">int</span> <a class="r" title="Search for references of 'i'" href=>i</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'j'" href=>j</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'index'" href=>index</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'Quality'" href=>Quality</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'temp'" href=>temp</a>;

<span class="c">// converting quality setting to that specified in the jpeg_quality_scaling</span>
<span class="c">// method in the IJG Jpeg-6a C libraries</span>

        <a class="r" title="Search for references of 'Quality'" href=>Quality</a> = <a class="r" title="Search for references of 'quality'" href=>quality</a>;
        <span class="k">if</span> (<a class="r" title="Search for references of 'Quality'" href=>Quality</a> &lt;= 0)
                <a class="r" title="Search for references of 'Quality'" href=>Quality</a> = 1;
        <span class="k">if</span> (<a class="r" title="Search for references of 'Quality'" href=>Quality</a> &gt; 100)
                <a class="r" title="Search for references of 'Quality'" href=>Quality</a> = 100;
        <span class="k">if</span> (<a class="r" title="Search for references of 'Quality'" href=>Quality</a> &lt; 50)
                <a class="r" title="Search for references of 'Quality'" href=>Quality</a> = 5000 / <a class="r" title="Search for references of 'Quality'" href=>Quality</a>;
        <span class="k">else</span>
                <a class="r" title="Search for references of 'Quality'" href=>Quality</a> = 200 - <a class="r" title="Search for references of 'Quality'" href=>Quality</a> * 2;

<span class="c">// Creating the luminance matrix</span>

        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[0]=16;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[1]=11;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[2]=10;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[3]=16;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[4]=24;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[5]=40;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[6]=51;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[7]=61;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[8]=12;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[9]=12;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[10]=14;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[11]=19;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[12]=26;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[13]=58;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[14]=60;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[15]=55;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[16]=14;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[17]=13;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[18]=16;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[19]=24;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[20]=40;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[21]=57;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[22]=69;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[23]=56;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[24]=14;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[25]=17;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[26]=22;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[27]=29;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[28]=51;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[29]=87;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[30]=80;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[31]=62;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[32]=18;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[33]=22;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[34]=37;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[35]=56;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[36]=68;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[37]=109;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[38]=103;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[39]=77;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[40]=24;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[41]=35;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[42]=55;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[43]=64;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[44]=81;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[45]=104;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[46]=113;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[47]=92;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[48]=49;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[49]=64;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[50]=78;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[51]=87;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[52]=103;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[53]=121;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[54]=120;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[55]=101;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[56]=72;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[57]=92;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[58]=95;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[59]=98;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[60]=112;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[61]=100;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[62]=103;
        <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[63]=99;

        <span class="k">for</span> (<a class="r" title="Search for references of 'j'" href=>j</a> = 0; <a class="r" title="Search for references of 'j'" href=>j</a> &lt; 64; <a class="r" title="Search for references of 'j'" href=>j</a>++)
        {
                <a class="r" title="Search for references of 'temp'" href=>temp</a> = (<a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[<a class="r" title="Search for references of 'j'" href=>j</a>] * <a class="r" title="Search for references of 'Quality'" href=>Quality</a> + 50) / 100;
                <span class="k">if</span> ( <a class="r" title="Search for references of 'temp'" href=>temp</a> &lt;= 0) <a class="r" title="Search for references of 'temp'" href=>temp</a> = 1;
                <span class="k">if</span> (<a class="r" title="Search for references of 'temp'" href=>temp</a> &gt; 255) <a class="r" title="Search for references of 'temp'" href=>temp</a> = 255;
                <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[<a class="r" title="Search for references of 'j'" href=>j</a>] = <a class="r" title="Search for references of 'temp'" href=>temp</a>;
        }
        <a class="r" title="Search for references of 'index'" href=>index</a> = 0;
        <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 0; <a class="r" title="Search for references of 'i'" href=>i</a> &lt; 8; <a class="r" title="Search for references of 'i'" href=>i</a>++) {
                <span class="k">for</span> (<a class="r" title="Search for references of 'j'" href=>j</a> = 0; <a class="r" title="Search for references of 'j'" href=>j</a> &lt; 8; <a class="r" title="Search for references of 'j'" href=>j</a>++) {
<span class="c">// The divisors for the LL&amp;M method (the slow integer method used in</span>
<span class="c">// jpeg 6a library).  This method is currently (04/04/98) incompletely</span>
<span class="c">// implemented.</span>
<span class="c">//                        DivisorsLuminance[index] = ((double) quantum_luminance[index]) &lt;&lt; 3;</span>
<span class="c">// The divisors for the AAN method (the float method used in jpeg 6a library.</span>
                        <a class="r" title="Search for references of 'DivisorsLuminance'" href=>DivisorsLuminance</a>[<a class="r" title="Search for references of 'index'" href=>index</a>] = (<span class="k">double</span>) ((<span class="k">double</span>)1.0/((<span class="k">double</span>) <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>[<a class="r" title="Search for references of 'index'" href=>index</a>] * <a class="r" title="Search for references of 'AANscaleFactor'" href=>AANscaleFactor</a>[<a class="r" title="Search for references of 'i'" href=>i</a>] * <a class="r" title="Search for references of 'AANscaleFactor'" href=>AANscaleFactor</a>[<a class="r" title="Search for references of 'j'" href=>j</a>] * (<span class="k">double</span>) 8.0));
                        <a class="r" title="Search for references of 'index'" href=>index</a>++;
                }
        }


<span class="c">// Creating the chrominance matrix</span>

        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[0]=17;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[1]=18;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[2]=24;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[3]=47;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[4]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[5]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[6]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[7]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[8]=18;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[9]=21;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[10]=26;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[11]=66;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[12]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[13]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[14]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[15]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[16]=24;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[17]=26;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[18]=56;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[19]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[20]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[21]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[22]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[23]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[24]=47;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[25]=66;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[26]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[27]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[28]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[29]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[30]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[31]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[32]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[33]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[34]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[35]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[36]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[37]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[38]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[39]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[40]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[41]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[42]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[43]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[44]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[45]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[46]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[47]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[48]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[49]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[50]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[51]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[52]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[53]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[54]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[55]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[56]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[57]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[58]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[59]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[60]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[61]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[62]=99;
        <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[63]=99;

        <span class="k">for</span> (<a class="r" title="Search for references of 'j'" href=>j</a> = 0; <a class="r" title="Search for references of 'j'" href=>j</a> &lt; 64; <a class="r" title="Search for references of 'j'" href=>j</a>++)
        {
                <a class="r" title="Search for references of 'temp'" href=>temp</a> = (<a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[<a class="r" title="Search for references of 'j'" href=>j</a>] * <a class="r" title="Search for references of 'Quality'" href=>Quality</a> + 50) / 100;
                <span class="k">if</span> ( <a class="r" title="Search for references of 'temp'" href=>temp</a> &lt;= 0) <a class="r" title="Search for references of 'temp'" href=>temp</a> = 1;
                <span class="k">if</span> (<a class="r" title="Search for references of 'temp'" href=>temp</a> &gt;= 255) <a class="r" title="Search for references of 'temp'" href=>temp</a> = 255;
                <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[<a class="r" title="Search for references of 'j'" href=>j</a>] = <a class="r" title="Search for references of 'temp'" href=>temp</a>;
        }
        <a class="r" title="Search for references of 'index'" href=>index</a> = 0;
        <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 0; <a class="r" title="Search for references of 'i'" href=>i</a> &lt; 8; <a class="r" title="Search for references of 'i'" href=>i</a>++) {
                <span class="k">for</span> (<a class="r" title="Search for references of 'j'" href=>j</a> = 0; <a class="r" title="Search for references of 'j'" href=>j</a> &lt; 8; <a class="r" title="Search for references of 'j'" href=>j</a>++) {
<span class="c">// The divisors for the LL&amp;M method (the slow integer method used in</span>
<span class="c">// jpeg 6a library).  This method is currently (04/04/98) incompletely</span>
<span class="c">// implemented.</span>
<span class="c">//                        DivisorsChrominance[index] = ((double) quantum_chrominance[index]) &lt;&lt; 3;</span>
<span class="c">// The divisors for the AAN method (the float method used in jpeg 6a library.</span>
                        <a class="r" title="Search for references of 'DivisorsChrominance'" href=>DivisorsChrominance</a>[<a class="r" title="Search for references of 'index'" href=>index</a>] = (<span class="k">double</span>) ((<span class="k">double</span>)1.0/((<span class="k">double</span>) <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>[<a class="r" title="Search for references of 'index'" href=>index</a>] * <a class="r" title="Search for references of 'AANscaleFactor'" href=>AANscaleFactor</a>[<a class="r" title="Search for references of 'i'" href=>i</a>] * <a class="r" title="Search for references of 'AANscaleFactor'" href=>AANscaleFactor</a>[<a class="r" title="Search for references of 'j'" href=>j</a>] * (<span class="k">double</span>)8.0));
                        <a class="r" title="Search for references of 'index'" href=>index</a>++;
                }
        }

<span class="c">// quantum anｄ Divisors are objects used to hold the appropriate matices</span>

        <a class="r" title="Search for references of 'quantum'" href=>quantum</a>[0] = <a class="r" title="Search for references of 'quantum_luminance'" href=>quantum_luminance</a>;
        <a class="r" title="Search for references of 'Divisors'" href=>Divisors</a>[0] = <a class="r" title="Search for references of 'DivisorsLuminance'" href=>DivisorsLuminance</a>;
        <a class="r" title="Search for references of 'quantum'" href=>quantum</a>[1] = <a class="r" title="Search for references of 'quantum_chrominance'" href=>quantum_chrominance</a>;
        <a class="r" title="Search for references of 'Divisors'" href=>Divisors</a>[1] = <a class="r" title="Search for references of 'DivisorsChrominance'" href=>DivisorsChrominance</a>;


    }

    <span class="c">/*
     * This method preforms forward DCT on a block of image data using
     * the literal method specified for a 2-D Discrete Cosine Transform.
     * It is included as a curiosity anｄ can give you an idea of the
     * difference in the compression result (the resulting image quality)
     * by comparing its output to the output of the AAN method below.
     * It is ridiculously inefficient.
     */</span>

<span class="c">// For now the final output is unusable.  The associated quantization step</span>
<span class="c">// needs some tweaking.  If you get this part working, please let me know.</span>

    <span class="k">public</span> <span class="k">double</span>[][] <a class="r" title="Search for references of 'forwardDCTExtreme'" href=>forwardDCTExtreme</a>(<span class="k">float</span> <a class="r" title="Search for references of 'input'" href=>input</a>[][])
    {
        <span class="k">double</span> <a class="r" title="Search for references of 'output'" href=>output</a>[][] = <span class="k">new</span> <span class="k">double</span>[<a class="r" title="Search for references of 'N'" href=>N</a>][<a class="r" title="Search for references of 'N'" href=>N</a>];
        <span class="k">double</span> <a class="r" title="Search for references of 'tmp0'" href=>tmp0</a>, <a class="r" title="Search for references of 'tmp1'" href=>tmp1</a>, <a class="r" title="Search for references of 'tmp2'" href=>tmp2</a>, <a class="r" title="Search for references of 'tmp3'" href=>tmp3</a>, <a class="r" title="Search for references of 'tmp4'" href=>tmp4</a>, <a class="r" title="Search for references of 'tmp5'" href=>tmp5</a>, <a class="r" title="Search for references of 'tmp6'" href=>tmp6</a>, <a class="r" title="Search for references of 'tmp7'" href=>tmp7</a>;
        <span class="k">double</span> <a class="r" title="Search for references of 'tmp10'" href=>tmp10</a>, <a class="r" title="Search for references of 'tmp11'" href=>tmp11</a>, <a class="r" title="Search for references of 'tmp12'" href=>tmp12</a>, <a class="r" title="Search for references of 'tmp13'" href=>tmp13</a>;
        <span class="k">double</span> <a class="r" title="Search for references of 'z1'" href=>z1</a>, <a class="r" title="Search for references of 'z2'" href=>z2</a>, <a class="r" title="Search for references of 'z3'" href=>z3</a>, <a class="r" title="Search for references of 'z4'" href=>z4</a>, <a class="r" title="Search for references of 'z5'" href=>z5</a>, <a class="r" title="Search for references of 'z11'" href=>z11</a>, <a class="r" title="Search for references of 'z13'" href=>z13</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'i'" href=>i</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'j'" href=>j</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'v'" href=>v</a>, <a class="r" title="Search for references of 'u'" href=>u</a>, <a class="r" title="Search for references of 'x'" href=>x</a>, <a class="r" title="Search for references of 'y'" href=>y</a>;
        <span class="k">for</span> (<a class="r" title="Search for references of 'v'" href=>v</a> = 0; <a class="r" title="Search for references of 'v'" href=>v</a> &lt; 8; <a class="r" title="Search for references of 'v'" href=>v</a>++) {
                <span class="k">for</span> (<a class="r" title="Search for references of 'u'" href=>u</a> = 0; <a class="r" title="Search for references of 'u'" href=>u</a> &lt; 8; <a class="r" title="Search for references of 'u'" href=>u</a>++) {
                        <span class="k">for</span> (<a class="r" title="Search for references of 'x'" href=>x</a> = 0; <a class="r" title="Search for references of 'x'" href=>x</a> &lt; 8; <a class="r" title="Search for references of 'x'" href=>x</a>++) {
                                <span class="k">for</span> (<a class="r" title="Search for references of 'y'" href=>y</a> = 0; <a class="r" title="Search for references of 'y'" href=>y</a> &lt; 8; <a class="r" title="Search for references of 'y'" href=>y</a>++) {
                                        <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'v'" href=>v</a>][<a class="r" title="Search for references of 'u'" href=>u</a>] += ((<span class="k">double</span>)<a class="r" title="Search for references of 'input'" href=>input</a>[<a class="r" title="Search for references of 'x'" href=>x</a>][<a class="r" title="Search for references of 'y'" href=>y</a>])*<a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'cos'" href=>cos</a>(((<span class="k">double</span>)(2*<a class="r" title="Search for references of 'x'" href=>x</a> + 1)*(<span class="k">double</span>)<a class="r" title="Search for references of 'u'" href=>u</a>*<a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'PI'" href=>PI</a>)/(<span class="k">double</span>)16)*<a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'cos'" href=>cos</a>(((<span class="k">double</span>)(2*<a class="r" title="Search for references of 'y'" href=>y</a> + 1)*(<span class="k">double</span>)<a class="r" title="Search for references of 'v'" href=>v</a>*<a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'PI'" href=>PI</a>)/(<span class="k">double</span>)16);
                                }
                        }
                        <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'v'" href=>v</a>][<a class="r" title="Search for references of 'u'" href=>u</a>] *= (<span class="k">double</span>)(0.25)*((<a class="r" title="Search for references of 'u'" href=>u</a> == 0) ? ((<span class="k">double</span>)1.0/<a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'sqrt'" href=>sqrt</a>(2)) : (<span class="k">double</span>) 1.0)*((<a class="r" title="Search for references of 'v'" href=>v</a> == 0) ? ((<span class="k">double</span>)1.0/<a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'sqrt'" href=>sqrt</a>(2)) : (<span class="k">double</span>) 1.0);
                }
        }
        <span class="k">return</span> <a class="r" title="Search for references of 'output'" href=>output</a>;
    }
                                                                

    <span class="c">/*
     * This method preforms a DCT on a block of image data using the AAN
     * method as implemented in the IJG Jpeg-6a library.
     */</span>
    <span class="k">public</span> <span class="k">double</span>[][] <a class="r" title="Search for references of 'forwardDCT'" href=>forwardDCT</a>(<span class="k">float</span> <a class="r" title="Search for references of 'input'" href=>input</a>[][])
    {
        <span class="k">double</span> <a class="r" title="Search for references of 'output'" href=>output</a>[][] = <span class="k">new</span> <span class="k">double</span>[<a class="r" title="Search for references of 'N'" href=>N</a>][<a class="r" title="Search for references of 'N'" href=>N</a>];
        <span class="k">double</span> <a class="r" title="Search for references of 'tmp0'" href=>tmp0</a>, <a class="r" title="Search for references of 'tmp1'" href=>tmp1</a>, <a class="r" title="Search for references of 'tmp2'" href=>tmp2</a>, <a class="r" title="Search for references of 'tmp3'" href=>tmp3</a>, <a class="r" title="Search for references of 'tmp4'" href=>tmp4</a>, <a class="r" title="Search for references of 'tmp5'" href=>tmp5</a>, <a class="r" title="Search for references of 'tmp6'" href=>tmp6</a>, <a class="r" title="Search for references of 'tmp7'" href=>tmp7</a>;
        <span class="k">double</span> <a class="r" title="Search for references of 'tmp10'" href=>tmp10</a>, <a class="r" title="Search for references of 'tmp11'" href=>tmp11</a>, <a class="r" title="Search for references of 'tmp12'" href=>tmp12</a>, <a class="r" title="Search for references of 'tmp13'" href=>tmp13</a>;
        <span class="k">double</span> <a class="r" title="Search for references of 'z1'" href=>z1</a>, <a class="r" title="Search for references of 'z2'" href=>z2</a>, <a class="r" title="Search for references of 'z3'" href=>z3</a>, <a class="r" title="Search for references of 'z4'" href=>z4</a>, <a class="r" title="Search for references of 'z5'" href=>z5</a>, <a class="r" title="Search for references of 'z11'" href=>z11</a>, <a class="r" title="Search for references of 'z13'" href=>z13</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'i'" href=>i</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'j'" href=>j</a>;

<span class="c">// Subtracts 128 from the input values</span>
        <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 0; <a class="r" title="Search for references of 'i'" href=>i</a> &lt; 8; <a class="r" title="Search for references of 'i'" href=>i</a>++) {
                <span class="k">for</span>(<a class="r" title="Search for references of 'j'" href=>j</a> = 0; <a class="r" title="Search for references of 'j'" href=>j</a> &lt; 8; <a class="r" title="Search for references of 'j'" href=>j</a>++) {
                        <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][<a class="r" title="Search for references of 'j'" href=>j</a>] = ((<span class="k">double</span>)<a class="r" title="Search for references of 'input'" href=>input</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][<a class="r" title="Search for references of 'j'" href=>j</a>] - (<span class="k">double</span>)128.0);
<span class="c">//                        input[i][j] -= 128;</span>

                }
        }

        <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 0; <a class="r" title="Search for references of 'i'" href=>i</a> &lt; 8; <a class="r" title="Search for references of 'i'" href=>i</a>++) {
                <a class="r" title="Search for references of 'tmp0'" href=>tmp0</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][0] + <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][7];
                <a class="r" title="Search for references of 'tmp7'" href=>tmp7</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][0] - <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][7];
                <a class="r" title="Search for references of 'tmp1'" href=>tmp1</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][1] + <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][6];
                <a class="r" title="Search for references of 'tmp6'" href=>tmp6</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][1] - <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][6];
                <a class="r" title="Search for references of 'tmp2'" href=>tmp2</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][2] + <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][5];
                <a class="r" title="Search for references of 'tmp5'" href=>tmp5</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][2] - <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][5];
                <a class="r" title="Search for references of 'tmp3'" href=>tmp3</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][3] + <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][4];
                <a class="r" title="Search for references of 'tmp4'" href=>tmp4</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][3] - <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][4];

                <a class="r" title="Search for references of 'tmp10'" href=>tmp10</a> = <a class="r" title="Search for references of 'tmp0'" href=>tmp0</a> + <a class="r" title="Search for references of 'tmp3'" href=>tmp3</a>;
                <a class="r" title="Search for references of 'tmp13'" href=>tmp13</a> = <a class="r" title="Search for references of 'tmp0'" href=>tmp0</a> - <a class="r" title="Search for references of 'tmp3'" href=>tmp3</a>;
                <a class="r" title="Search for references of 'tmp11'" href=>tmp11</a> = <a class="r" title="Search for references of 'tmp1'" href=>tmp1</a> + <a class="r" title="Search for references of 'tmp2'" href=>tmp2</a>;
                <a class="r" title="Search for references of 'tmp12'" href=>tmp12</a> = <a class="r" title="Search for references of 'tmp1'" href=>tmp1</a> - <a class="r" title="Search for references of 'tmp2'" href=>tmp2</a>;

                <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][0] = <a class="r" title="Search for references of 'tmp10'" href=>tmp10</a> + <a class="r" title="Search for references of 'tmp11'" href=>tmp11</a>;
                <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][4] = <a class="r" title="Search for references of 'tmp10'" href=>tmp10</a> - <a class="r" title="Search for references of 'tmp11'" href=>tmp11</a>;

                <a class="r" title="Search for references of 'z1'" href=>z1</a> = (<a class="r" title="Search for references of 'tmp12'" href=>tmp12</a> + <a class="r" title="Search for references of 'tmp13'" href=>tmp13</a>) * (<span class="k">double</span>) 0.707106781;
                <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][2] = <a class="r" title="Search for references of 'tmp13'" href=>tmp13</a> + <a class="r" title="Search for references of 'z1'" href=>z1</a>;
                <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][6] = <a class="r" title="Search for references of 'tmp13'" href=>tmp13</a> - <a class="r" title="Search for references of 'z1'" href=>z1</a>;

                <a class="r" title="Search for references of 'tmp10'" href=>tmp10</a> = <a class="r" title="Search for references of 'tmp4'" href=>tmp4</a> + <a class="r" title="Search for references of 'tmp5'" href=>tmp5</a>;
                <a class="r" title="Search for references of 'tmp11'" href=>tmp11</a> = <a class="r" title="Search for references of 'tmp5'" href=>tmp5</a> + <a class="r" title="Search for references of 'tmp6'" href=>tmp6</a>;
                <a class="r" title="Search for references of 'tmp12'" href=>tmp12</a> = <a class="r" title="Search for references of 'tmp6'" href=>tmp6</a> + <a class="r" title="Search for references of 'tmp7'" href=>tmp7</a>;

                <a class="r" title="Search for references of 'z5'" href=>z5</a> = (<a class="r" title="Search for references of 'tmp10'" href=>tmp10</a> - <a class="r" title="Search for references of 'tmp12'" href=>tmp12</a>) * (<span class="k">double</span>) 0.382683433;
                <a class="r" title="Search for references of 'z2'" href=>z2</a> = ((<span class="k">double</span>) 0.541196100) * <a class="r" title="Search for references of 'tmp10'" href=>tmp10</a> + <a class="r" title="Search for references of 'z5'" href=>z5</a>;
                <a class="r" title="Search for references of 'z4'" href=>z4</a> = ((<span class="k">double</span>) 1.306562965) * <a class="r" title="Search for references of 'tmp12'" href=>tmp12</a> + <a class="r" title="Search for references of 'z5'" href=>z5</a>;
                <a class="r" title="Search for references of 'z3'" href=>z3</a> = <a class="r" title="Search for references of 'tmp11'" href=>tmp11</a> * ((<span class="k">double</span>) 0.707106781);

                <a class="r" title="Search for references of 'z11'" href=>z11</a> = <a class="r" title="Search for references of 'tmp7'" href=>tmp7</a> + <a class="r" title="Search for references of 'z3'" href=>z3</a>;
                <a class="r" title="Search for references of 'z13'" href=>z13</a> = <a class="r" title="Search for references of 'tmp7'" href=>tmp7</a> - <a class="r" title="Search for references of 'z3'" href=>z3</a>;

                <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][5] = <a class="r" title="Search for references of 'z13'" href=>z13</a> + <a class="r" title="Search for references of 'z2'" href=>z2</a>;
                <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][3] = <a class="r" title="Search for references of 'z13'" href=>z13</a> - <a class="r" title="Search for references of 'z2'" href=>z2</a>;
                <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][1] = <a class="r" title="Search for references of 'z11'" href=>z11</a> + <a class="r" title="Search for references of 'z4'" href=>z4</a>;
                <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][7] = <a class="r" title="Search for references of 'z11'" href=>z11</a> - <a class="r" title="Search for references of 'z4'" href=>z4</a>;
        }

        <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 0; <a class="r" title="Search for references of 'i'" href=>i</a> &lt; 8; <a class="r" title="Search for references of 'i'" href=>i</a>++) {
                <a class="r" title="Search for references of 'tmp0'" href=>tmp0</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[0][<a class="r" title="Search for references of 'i'" href=>i</a>] + <a class="r" title="Search for references of 'output'" href=>output</a>[7][<a class="r" title="Search for references of 'i'" href=>i</a>];
                <a class="r" title="Search for references of 'tmp7'" href=>tmp7</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[0][<a class="r" title="Search for references of 'i'" href=>i</a>] - <a class="r" title="Search for references of 'output'" href=>output</a>[7][<a class="r" title="Search for references of 'i'" href=>i</a>];
                <a class="r" title="Search for references of 'tmp1'" href=>tmp1</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[1][<a class="r" title="Search for references of 'i'" href=>i</a>] + <a class="r" title="Search for references of 'output'" href=>output</a>[6][<a class="r" title="Search for references of 'i'" href=>i</a>];
                <a class="r" title="Search for references of 'tmp6'" href=>tmp6</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[1][<a class="r" title="Search for references of 'i'" href=>i</a>] - <a class="r" title="Search for references of 'output'" href=>output</a>[6][<a class="r" title="Search for references of 'i'" href=>i</a>];
                <a class="r" title="Search for references of 'tmp2'" href=>tmp2</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[2][<a class="r" title="Search for references of 'i'" href=>i</a>] + <a class="r" title="Search for references of 'output'" href=>output</a>[5][<a class="r" title="Search for references of 'i'" href=>i</a>];
                <a class="r" title="Search for references of 'tmp5'" href=>tmp5</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[2][<a class="r" title="Search for references of 'i'" href=>i</a>] - <a class="r" title="Search for references of 'output'" href=>output</a>[5][<a class="r" title="Search for references of 'i'" href=>i</a>];
                <a class="r" title="Search for references of 'tmp3'" href=>tmp3</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[3][<a class="r" title="Search for references of 'i'" href=>i</a>] + <a class="r" title="Search for references of 'output'" href=>output</a>[4][<a class="r" title="Search for references of 'i'" href=>i</a>];
                <a class="r" title="Search for references of 'tmp4'" href=>tmp4</a> = <a class="r" title="Search for references of 'output'" href=>output</a>[3][<a class="r" title="Search for references of 'i'" href=>i</a>] - <a class="r" title="Search for references of 'output'" href=>output</a>[4][<a class="r" title="Search for references of 'i'" href=>i</a>];

                <a class="r" title="Search for references of 'tmp10'" href=>tmp10</a> = <a class="r" title="Search for references of 'tmp0'" href=>tmp0</a> + <a class="r" title="Search for references of 'tmp3'" href=>tmp3</a>;
                <a class="r" title="Search for references of 'tmp13'" href=>tmp13</a> = <a class="r" title="Search for references of 'tmp0'" href=>tmp0</a> - <a class="r" title="Search for references of 'tmp3'" href=>tmp3</a>;
                <a class="r" title="Search for references of 'tmp11'" href=>tmp11</a> = <a class="r" title="Search for references of 'tmp1'" href=>tmp1</a> + <a class="r" title="Search for references of 'tmp2'" href=>tmp2</a>;
                <a class="r" title="Search for references of 'tmp12'" href=>tmp12</a> = <a class="r" title="Search for references of 'tmp1'" href=>tmp1</a> - <a class="r" title="Search for references of 'tmp2'" href=>tmp2</a>;

                <a class="r" title="Search for references of 'output'" href=>output</a>[0][<a class="r" title="Search for references of 'i'" href=>i</a>] = <a class="r" title="Search for references of 'tmp10'" href=>tmp10</a> + <a class="r" title="Search for references of 'tmp11'" href=>tmp11</a>;
                <a class="r" title="Search for references of 'output'" href=>output</a>[4][<a class="r" title="Search for references of 'i'" href=>i</a>] = <a class="r" title="Search for references of 'tmp10'" href=>tmp10</a> - <a class="r" title="Search for references of 'tmp11'" href=>tmp11</a>;

                <a class="r" title="Search for references of 'z1'" href=>z1</a> = (<a class="r" title="Search for references of 'tmp12'" href=>tmp12</a> + <a class="r" title="Search for references of 'tmp13'" href=>tmp13</a>) * (<span class="k">double</span>) 0.707106781;
                <a class="r" title="Search for references of 'output'" href=>output</a>[2][<a class="r" title="Search for references of 'i'" href=>i</a>] = <a class="r" title="Search for references of 'tmp13'" href=>tmp13</a> + <a class="r" title="Search for references of 'z1'" href=>z1</a>;
                <a class="r" title="Search for references of 'output'" href=>output</a>[6][<a class="r" title="Search for references of 'i'" href=>i</a>] = <a class="r" title="Search for references of 'tmp13'" href=>tmp13</a> - <a class="r" title="Search for references of 'z1'" href=>z1</a>;

                <a class="r" title="Search for references of 'tmp10'" href=>tmp10</a> = <a class="r" title="Search for references of 'tmp4'" href=>tmp4</a> + <a class="r" title="Search for references of 'tmp5'" href=>tmp5</a>;
                <a class="r" title="Search for references of 'tmp11'" href=>tmp11</a> = <a class="r" title="Search for references of 'tmp5'" href=>tmp5</a> + <a class="r" title="Search for references of 'tmp6'" href=>tmp6</a>;
                <a class="r" title="Search for references of 'tmp12'" href=>tmp12</a> = <a class="r" title="Search for references of 'tmp6'" href=>tmp6</a> + <a class="r" title="Search for references of 'tmp7'" href=>tmp7</a>;

                <a class="r" title="Search for references of 'z5'" href=>z5</a> = (<a class="r" title="Search for references of 'tmp10'" href=>tmp10</a> - <a class="r" title="Search for references of 'tmp12'" href=>tmp12</a>) * (<span class="k">double</span>) 0.382683433;
                <a class="r" title="Search for references of 'z2'" href=>z2</a> = ((<span class="k">double</span>) 0.541196100) * <a class="r" title="Search for references of 'tmp10'" href=>tmp10</a> + <a class="r" title="Search for references of 'z5'" href=>z5</a>;
                <a class="r" title="Search for references of 'z4'" href=>z4</a> = ((<span class="k">double</span>) 1.306562965) * <a class="r" title="Search for references of 'tmp12'" href=>tmp12</a> + <a class="r" title="Search for references of 'z5'" href=>z5</a>;
                <a class="r" title="Search for references of 'z3'" href=>z3</a> = <a class="r" title="Search for references of 'tmp11'" href=>tmp11</a> * ((<span class="k">double</span>) 0.707106781);

                <a class="r" title="Search for references of 'z11'" href=>z11</a> = <a class="r" title="Search for references of 'tmp7'" href=>tmp7</a> + <a class="r" title="Search for references of 'z3'" href=>z3</a>;
                <a class="r" title="Search for references of 'z13'" href=>z13</a> = <a class="r" title="Search for references of 'tmp7'" href=>tmp7</a> - <a class="r" title="Search for references of 'z3'" href=>z3</a>;

                <a class="r" title="Search for references of 'output'" href=>output</a>[5][<a class="r" title="Search for references of 'i'" href=>i</a>] = <a class="r" title="Search for references of 'z13'" href=>z13</a> + <a class="r" title="Search for references of 'z2'" href=>z2</a>;
                <a class="r" title="Search for references of 'output'" href=>output</a>[3][<a class="r" title="Search for references of 'i'" href=>i</a>] = <a class="r" title="Search for references of 'z13'" href=>z13</a> - <a class="r" title="Search for references of 'z2'" href=>z2</a>;
                <a class="r" title="Search for references of 'output'" href=>output</a>[1][<a class="r" title="Search for references of 'i'" href=>i</a>] = <a class="r" title="Search for references of 'z11'" href=>z11</a> + <a class="r" title="Search for references of 'z4'" href=>z4</a>;
                <a class="r" title="Search for references of 'output'" href=>output</a>[7][<a class="r" title="Search for references of 'i'" href=>i</a>] = <a class="r" title="Search for references of 'z11'" href=>z11</a> - <a class="r" title="Search for references of 'z4'" href=>z4</a>;
        }

        <span class="k">return</span> <a class="r" title="Search for references of 'output'" href=>output</a>;
    }

    <span class="c">/*
    * This method quantitizes data anｄ rounds it to the nearest integer.
    */</span>
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'quantizeBlock'" href=>quantizeBlock</a>(<span class="k">double</span> <a class="r" title="Search for references of 'inputData'" href=>inputData</a>[][], <span class="k">int</span> <a class="r" title="Search for references of 'code'" href=>code</a>)
    {
        <span class="k">int</span> <a class="r" title="Search for references of 'outputData'" href=>outputData</a>[] = <span class="k">new</span> <span class="k">int</span>[<a class="r" title="Search for references of 'N'" href=>N</a>*<a class="r" title="Search for references of 'N'" href=>N</a>];
        <span class="k">int</span> <a class="r" title="Search for references of 'i'" href=>i</a>, <a class="r" title="Search for references of 'j'" href=>j</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'index'" href=>index</a>;
        <a class="r" title="Search for references of 'index'" href=>index</a> = 0;
        <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 0; <a class="r" title="Search for references of 'i'" href=>i</a> &lt; 8; <a class="r" title="Search for references of 'i'" href=>i</a>++) {
                <span class="k">for</span> (<a class="r" title="Search for references of 'j'" href=>j</a> = 0; <a class="r" title="Search for references of 'j'" href=>j</a> &lt; 8; <a class="r" title="Search for references of 'j'" href=>j</a>++) {
<span class="c">// The second line results in significantly better compression.</span>
                        <a class="r" title="Search for references of 'outputData'" href=>outputData</a>[<a class="r" title="Search for references of 'index'" href=>index</a>] = (<span class="k">int</span>)(<a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'round'" href=>round</a>(<a class="r" title="Search for references of 'inputData'" href=>inputData</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][<a class="r" title="Search for references of 'j'" href=>j</a>] * (((<span class="k">double</span>[]) (<a class="r" title="Search for references of 'Divisors'" href=>Divisors</a>[<a class="r" title="Search for references of 'code'" href=>code</a>]))[<a class="r" title="Search for references of 'index'" href=>index</a>])));
<span class="c">//                        outputData[index] = (int)(((inputData[i][j] * (((double[]) (Divisors[code]))[index])) + 16384.5) -16384);</span>
                        <a class="r" title="Search for references of 'index'" href=>index</a>++;
                }
        }

        <span class="k">return</span> <a class="r" title="Search for references of 'outputData'" href=>outputData</a>;
    }

    <span class="c">/*
    * This is the method for quantizing a block DCT'ed with forwardDCTExtreme
    * This method quantitizes data anｄ rounds it to the nearest integer.
    */</span>
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'quantizeBlockExtreme'" href=>quantizeBlockExtreme</a>(<span class="k">double</span> <a class="r" title="Search for references of 'inputData'" href=>inputData</a>[][], <span class="k">int</span> <a class="r" title="Search for references of 'code'" href=>code</a>)
    {
        <span class="k">int</span> <a class="r" title="Search for references of 'outputData'" href=>outputData</a>[] = <span class="k">new</span> <span class="k">int</span>[<a class="r" title="Search for references of 'N'" href=>N</a>*<a class="r" title="Search for references of 'N'" href=>N</a>];
        <span class="k">int</span> <a class="r" title="Search for references of 'i'" href=>i</a>, <a class="r" title="Search for references of 'j'" href=>j</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'index'" href=>index</a>;
        <a class="r" title="Search for references of 'index'" href=>index</a> = 0;
        <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 0; <a class="r" title="Search for references of 'i'" href=>i</a> &lt; 8; <a class="r" title="Search for references of 'i'" href=>i</a>++) {
                <span class="k">for</span> (<a class="r" title="Search for references of 'j'" href=>j</a> = 0; <a class="r" title="Search for references of 'j'" href=>j</a> &lt; 8; <a class="r" title="Search for references of 'j'" href=>j</a>++) {
                        <a class="r" title="Search for references of 'outputData'" href=>outputData</a>[<a class="r" title="Search for references of 'index'" href=>index</a>] = (<span class="k">int</span>)(<a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'round'" href=>round</a>(<a class="r" title="Search for references of 'inputData'" href=>inputData</a>[<a class="r" title="Search for references of 'i'" href=>i</a>][<a class="r" title="Search for references of 'j'" href=>j</a>] / (<span class="k">double</span>)(((<span class="k">int</span>[]) (<a class="r" title="Search for references of 'quantum'" href=>quantum</a>[<a class="r" title="Search for references of 'code'" href=>code</a>]))[<a class="r" title="Search for references of 'index'" href=>index</a>])));
                        <a class="r" title="Search for references of 'index'" href=>index</a>++;
                }
        }

        <span class="k">return</span> <a class="r" title="Search for references of 'outputData'" href=>outputData</a>;
    }
}

<span class="c">// This class was modified by James R. Weeks on 3/27/98.</span>
<span class="c">// It now incorporates Huffman table derivation as in the C jpeg library</span>
<span class="c">// from the IJG, Jpeg-6a.</span>

<span class="k">class</span> <a class="r" title="Search for references of 'Huffman'" href=>Huffman</a>
{
    <span class="k">int</span> <a class="r" title="Search for references of 'bufferPutBits'" href=>bufferPutBits</a>, <a class="r" title="Search for references of 'bufferPutBuffer'" href=>bufferPutBuffer</a>;    
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'ImageHeight'" href=>ImageHeight</a>;
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'ImageWidth'" href=>ImageWidth</a>;
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'DC_matrix0'" href=>DC_matrix0</a>[][];
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'AC_matrix0'" href=>AC_matrix0</a>[][];
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'DC_matrix1'" href=>DC_matrix1</a>[][];
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'AC_matrix1'" href=>AC_matrix1</a>[][];
    <span class="k">public</span> <a class="r" title="Search for references of 'Object'" href=>Object</a> <a class="r" title="Search for references of 'DC_matrix'" href=>DC_matrix</a>[];
    <span class="k">public</span> <a class="r" title="Search for references of 'Object'" href=>Object</a> <a class="r" title="Search for references of 'AC_matrix'" href=>AC_matrix</a>[];
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'code'" href=>code</a>;
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'NumOfDCTables'" href=>NumOfDCTables</a>;
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'NumOfACTables'" href=>NumOfACTables</a>;
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'bitsDCluminance'" href=>bitsDCluminance</a> = { 0x00, 0, 1, 5, 1, 1,1,1,1,1,0,0,0,0,0,0,0};
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'valDCluminance'" href=>valDCluminance</a> = { 0,1,2,3,4,5,6,7,8,9,10,11 };
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'bitsDCchrominance'" href=>bitsDCchrominance</a> = { 0x01,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0 };
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'valDCchrominance'" href=>valDCchrominance</a> = { 0,1,2,3,4,5,6,7,8,9,10,11 };
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'bitsACluminance'" href=>bitsACluminance</a> = {0x10,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d };
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'valACluminance'" href=>valACluminance</a> =
        { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
          0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
          0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
          0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
          0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
          0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
          0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
          0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
          0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
          0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
          0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
          0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
          0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
          0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
          0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
          0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
          0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
          0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
          0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
          0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
          0xf9, 0xfa };
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'bitsACchrominance'" href=>bitsACchrominance</a> = { 0x11,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77 };;
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'valACchrominance'" href=>valACchrominance</a> = 
        { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
          0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
          0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
          0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
          0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
          0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
          0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 
          0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 
          0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 
          0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 
          0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 
          0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 
          0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 
          0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 
          0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 
          0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 
          0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 
          0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 
          0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 
          0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
          0xf9, 0xfa };
    <span class="k">public</span> <a class="r" title="Search for references of 'Vector'" href=>Vector</a> <a class="r" title="Search for references of 'bits'" href=>bits</a>;
    <span class="k">public</span> <a class="r" title="Search for references of 'Vector'" href=>Vector</a> <a class="r" title="Search for references of 'val'" href=>val</a>;

    <span class="c">/*
    * The Huffman class constructor
    */</span>
        <span class="k">public</span> <a class="r" title="Search for references of 'Huffman'" href=>Huffman</a>(<span class="k">int</span> <a class="r" title="Search for references of 'Width'" href=>Width</a>,<span class="k">int</span> <a class="r" title="Search for references of 'Height'" href=>Height</a>)
	{

            <a class="r" title="Search for references of 'bits'" href=>bits</a> = <span class="k">new</span> <a class="r" title="Search for references of 'Vector'" href=>Vector</a>();
            <a class="r" title="Search for references of 'bits'" href=>bits</a>.<a class="r" title="Search for references of 'addElement'" href=>addElement</a>(<a class="r" title="Search for references of 'bitsDCluminance'" href=>bitsDCluminance</a>);
            <a class="r" title="Search for references of 'bits'" href=>bits</a>.<a class="r" title="Search for references of 'addElement'" href=>addElement</a>(<a class="r" title="Search for references of 'bitsACluminance'" href=>bitsACluminance</a>);
            <a class="r" title="Search for references of 'bits'" href=>bits</a>.<a class="r" title="Search for references of 'addElement'" href=>addElement</a>(<a class="r" title="Search for references of 'bitsDCchrominance'" href=>bitsDCchrominance</a>);
            <a class="r" title="Search for references of 'bits'" href=>bits</a>.<a class="r" title="Search for references of 'addElement'" href=>addElement</a>(<a class="r" title="Search for references of 'bitsACchrominance'" href=>bitsACchrominance</a>);
            <a class="r" title="Search for references of 'val'" href=>val</a> = <span class="k">new</span> <a class="r" title="Search for references of 'Vector'" href=>Vector</a>();
            <a class="r" title="Search for references of 'val'" href=>val</a>.<a class="r" title="Search for references of 'addElement'" href=>addElement</a>(<a class="r" title="Search for references of 'valDCluminance'" href=>valDCluminance</a>);
            <a class="r" title="Search for references of 'val'" href=>val</a>.<a class="r" title="Search for references of 'addElement'" href=>addElement</a>(<a class="r" title="Search for references of 'valACluminance'" href=>valACluminance</a>);
            <a class="r" title="Search for references of 'val'" href=>val</a>.<a class="r" title="Search for references of 'addElement'" href=>addElement</a>(<a class="r" title="Search for references of 'valDCchrominance'" href=>valDCchrominance</a>);
            <a class="r" title="Search for references of 'val'" href=>val</a>.<a class="r" title="Search for references of 'addElement'" href=>addElement</a>(<a class="r" title="Search for references of 'valACchrominance'" href=>valACchrominance</a>);
            <a class="r" title="Search for references of 'initHuf'" href=>initHuf</a>();
	    <span class="c">//code=code;</span>
            <a class="r" title="Search for references of 'ImageWidth'" href=>ImageWidth</a>=<a class="r" title="Search for references of 'Width'" href=>Width</a>;
            <a class="r" title="Search for references of 'ImageHeight'" href=>ImageHeight</a>=<a class="r" title="Search for references of 'Height'" href=>Height</a>;

	}

   <span class="c">/**
   * HuffmanBlockEncoder run length encodes anｄ Huffman encodes the quantized
   * data.
   **/</span>

        <span class="k">public</span> <span class="k">void</span> <a class="r" title="Search for references of 'HuffmanBlockEncoder'" href=>HuffmanBlockEncoder</a>(<a class="r" title="Search for references of 'BufferedOutputStream'" href=>BufferedOutputStream</a> <a class="r" title="Search for references of 'outStream'" href=>outStream</a>, <span class="k">int</span> <a class="r" title="Search for references of 'zigzag'" href=>zigzag</a>[], <span class="k">int</span> <a class="r" title="Search for references of 'prec'" href=>prec</a>, <span class="k">int</span> <a class="r" title="Search for references of 'DCcode'" href=>DCcode</a>, <span class="k">int</span> <a class="r" title="Search for references of 'ACcode'" href=>ACcode</a>)
	{
        <span class="k">int</span> <a class="r" title="Search for references of 'temp'" href=>temp</a>, <a class="r" title="Search for references of 'temp2'" href=>temp2</a>, <a class="r" title="Search for references of 'nbits'" href=>nbits</a>, <a class="r" title="Search for references of 'k'" href=>k</a>, <a class="r" title="Search for references of 'r'" href=>r</a>, <a class="r" title="Search for references of 'i'" href=>i</a>;

        <a class="r" title="Search for references of 'NumOfDCTables'" href=>NumOfDCTables</a> = 2;
        <a class="r" title="Search for references of 'NumOfACTables'" href=>NumOfACTables</a> = 2;

<span class="c">// The DC portion</span>

        <a class="r" title="Search for references of 'temp'" href=>temp</a> = <a class="r" title="Search for references of 'temp2'" href=>temp2</a> = <a class="r" title="Search for references of 'zigzag'" href=>zigzag</a>[0] - <a class="r" title="Search for references of 'prec'" href=>prec</a>;
        <span class="k">if</span>(<a class="r" title="Search for references of 'temp'" href=>temp</a> &lt; 0) {
                <a class="r" title="Search for references of 'temp'" href=>temp</a> = -<a class="r" title="Search for references of 'temp'" href=>temp</a>;
                <a class="r" title="Search for references of 'temp2'" href=>temp2</a>--;
        }
        <a class="r" title="Search for references of 'nbits'" href=>nbits</a> = 0;
        <span class="k">while</span> (<a class="r" title="Search for references of 'temp'" href=>temp</a> != 0) {
                <a class="r" title="Search for references of 'nbits'" href=>nbits</a>++;
                <a class="r" title="Search for references of 'temp'" href=>temp</a> &gt;&gt;= 1;
        }
<span class="c">//        if (nbits &gt; 11) nbits = 11;</span>
        <a class="r" title="Search for references of 'bufferIt'" href=>bufferIt</a>(<a class="r" title="Search for references of 'outStream'" href=>outStream</a>, ((<span class="k">int</span>[][])<a class="r" title="Search for references of 'DC_matrix'" href=>DC_matrix</a>[<a class="r" title="Search for references of 'DCcode'" href=>DCcode</a>])[<a class="r" title="Search for references of 'nbits'" href=>nbits</a>][0], ((<span class="k">int</span>[][])<a class="r" title="Search for references of 'DC_matrix'" href=>DC_matrix</a>[<a class="r" title="Search for references of 'DCcode'" href=>DCcode</a>])[<a class="r" title="Search for references of 'nbits'" href=>nbits</a>][1]);
        <span class="c">// The arguments in bufferIt are code anｄ size.</span>
        <span class="k">if</span> (<a class="r" title="Search for references of 'nbits'" href=>nbits</a> != 0) {
                <a class="r" title="Search for references of 'bufferIt'" href=>bufferIt</a>(<a class="r" title="Search for references of 'outStream'" href=>outStream</a>, <a class="r" title="Search for references of 'temp2'" href=>temp2</a>, <a class="r" title="Search for references of 'nbits'" href=>nbits</a>);
        }

<span class="c">// The AC portion</span>

        <a class="r" title="Search for references of 'r'" href=>r</a> = 0;

        <span class="k">for</span> (<a class="r" title="Search for references of 'k'" href=>k</a> = 1; <a class="r" title="Search for references of 'k'" href=>k</a> &lt; 64; <a class="r" title="Search for references of 'k'" href=>k</a>++) {
                <span class="k">if</span> ((<a class="r" title="Search for references of 'temp'" href=>temp</a> = <a class="r" title="Search for references of 'zigzag'" href=>zigzag</a>[<a class="r" title="Search for references of 'jpegNaturalOrder'" href=>jpegNaturalOrder</a>[<a class="r" title="Search for references of 'k'" href=>k</a>]]) == 0) {
                        <a class="r" title="Search for references of 'r'" href=>r</a>++;
                }
                <span class="k">else</span> {
                        <span class="k">while</span> (<a class="r" title="Search for references of 'r'" href=>r</a> &gt; 15) {
                                <a class="r" title="Search for references of 'bufferIt'" href=>bufferIt</a>(<a class="r" title="Search for references of 'outStream'" href=>outStream</a>, ((<span class="k">int</span>[][])<a class="r" title="Search for references of 'AC_matrix'" href=>AC_matrix</a>[<a class="r" title="Search for references of 'ACcode'" href=>ACcode</a>])[0xF0][0], ((<span class="k">int</span>[][])<a class="r" title="Search for references of 'AC_matrix'" href=>AC_matrix</a>[<a class="r" title="Search for references of 'ACcode'" href=>ACcode</a>])[0xF0][1]);
                                <a class="r" title="Search for references of 'r'" href=>r</a> -= 16;
                        }
                        <a class="r" title="Search for references of 'temp2'" href=>temp2</a> = <a class="r" title="Search for references of 'temp'" href=>temp</a>;
                        <span class="k">if</span> (<a class="r" title="Search for references of 'temp'" href=>temp</a> &lt; 0) {
                                <a class="r" title="Search for references of 'temp'" href=>temp</a> = -<a class="r" title="Search for references of 'temp'" href=>temp</a>;
                                <a class="r" title="Search for references of 'temp2'" href=>temp2</a>--;
                        }
                        <a class="r" title="Search for references of 'nbits'" href=>nbits</a> = 1;
                        <span class="k">while</span> ((<a class="r" title="Search for references of 'temp'" href=>temp</a> &gt;&gt;= 1) != 0) {
                                <a class="r" title="Search for references of 'nbits'" href=>nbits</a>++;
                        }
                        <a class="r" title="Search for references of 'i'" href=>i</a> = (<a class="r" title="Search for references of 'r'" href=>r</a> &lt;&lt; 4) + <a class="r" title="Search for references of 'nbits'" href=>nbits</a>;
                        <a class="r" title="Search for references of 'bufferIt'" href=>bufferIt</a>(<a class="r" title="Search for references of 'outStream'" href=>outStream</a>, ((<span class="k">int</span>[][])<a class="r" title="Search for references of 'AC_matrix'" href=>AC_matrix</a>[<a class="r" title="Search for references of 'ACcode'" href=>ACcode</a>])[<a class="r" title="Search for references of 'i'" href=>i</a>][0], ((<span class="k">int</span>[][])<a class="r" title="Search for references of 'AC_matrix'" href=>AC_matrix</a>[<a class="r" title="Search for references of 'ACcode'" href=>ACcode</a>])[<a class="r" title="Search for references of 'i'" href=>i</a>][1]);
                        <a class="r" title="Search for references of 'bufferIt'" href=>bufferIt</a>(<a class="r" title="Search for references of 'outStream'" href=>outStream</a>, <a class="r" title="Search for references of 'temp2'" href=>temp2</a>, <a class="r" title="Search for references of 'nbits'" href=>nbits</a>);

                        <a class="r" title="Search for references of 'r'" href=>r</a> = 0;
                }
        }

        <span class="k">if</span> (<a class="r" title="Search for references of 'r'" href=>r</a> &gt; 0) {
                <a class="r" title="Search for references of 'bufferIt'" href=>bufferIt</a>(<a class="r" title="Search for references of 'outStream'" href=>outStream</a>, ((<span class="k">int</span>[][])<a class="r" title="Search for references of 'AC_matrix'" href=>AC_matrix</a>[<a class="r" title="Search for references of 'ACcode'" href=>ACcode</a>])[0][0], ((<span class="k">int</span>[][])<a class="r" title="Search for references of 'AC_matrix'" href=>AC_matrix</a>[<a class="r" title="Search for references of 'ACcode'" href=>ACcode</a>])[0][1]);
        }

	}

<span class="c">// Uses an integer long (32 bits) buffer to store the Huffman encoded bits</span>
<span class="c">// anｄ sends them to outStream by the byte.</span>

        <span class="k">void</span> <a class="r" title="Search for references of 'bufferIt'" href=>bufferIt</a>(<a class="r" title="Search for references of 'BufferedOutputStream'" href=>BufferedOutputStream</a> <a class="r" title="Search for references of 'outStream'" href=>outStream</a>, <span class="k">int</span> <a class="r" title="Search for references of 'code'" href=>code</a>,<span class="k">int</span> <a class="r" title="Search for references of 'size'" href=>size</a>)
	{
        <span class="k">int</span> <a class="r" title="Search for references of 'PutBuffer'" href=>PutBuffer</a> = <a class="r" title="Search for references of 'code'" href=>code</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'PutBits'" href=>PutBits</a> = <a class="r" title="Search for references of 'bufferPutBits'" href=>bufferPutBits</a>;

        <a class="r" title="Search for references of 'PutBuffer'" href=>PutBuffer</a> &amp;= (1 &lt;&lt; <a class="r" title="Search for references of 'size'" href=>size</a>) - 1;
        <a class="r" title="Search for references of 'PutBits'" href=>PutBits</a> += <a class="r" title="Search for references of 'size'" href=>size</a>;
        <a class="r" title="Search for references of 'PutBuffer'" href=>PutBuffer</a> &lt;&lt;= 24 - <a class="r" title="Search for references of 'PutBits'" href=>PutBits</a>;
        <a class="r" title="Search for references of 'PutBuffer'" href=>PutBuffer</a> |= <a class="r" title="Search for references of 'bufferPutBuffer'" href=>bufferPutBuffer</a>;

        <span class="k">while</span>(<a class="r" title="Search for references of 'PutBits'" href=>PutBits</a> &gt;= 8) {
                <span class="k">int</span> <a class="r" title="Search for references of 'c'" href=>c</a> = ((<a class="r" title="Search for references of 'PutBuffer'" href=>PutBuffer</a> &gt;&gt; 16) &amp; 0xFF);
                <span class="k">try</span>
                {
                        <a class="r" title="Search for references of 'outStream'" href=>outStream</a>.<a class="r" title="Search for references of 'write'" href=>write</a>(<a class="r" title="Search for references of 'c'" href=>c</a>);
                }
                <span class="k">catch</span> (<a class="r" title="Search for references of 'IOException'" href=>IOException</a> <a class="r" title="Search for references of 'e'" href=>e</a>) {
                        <a class="r" title="Search for references of 'System'" href=>System</a>.<a class="r" title="Search for references of 'out'" href=>out</a>.<a class="r" title="Search for references of 'println'" href=>println</a>(<span class="str">&quot;IO Error: &quot;</span> + <a class="r" title="Search for references of 'e'" href=>e</a>.<a class="r" title="Search for references of 'getMessage'" href=>getMessage</a>());
                }
                <span class="k">if</span> (<a class="r" title="Search for references of 'c'" href=>c</a> == 0xFF) {
                        <span class="k">try</span>
                        {
                                <a class="r" title="Search for references of 'outStream'" href=>outStream</a>.<a class="r" title="Search for references of 'write'" href=>write</a>(0);
                        }
                        <span class="k">catch</span> (<a class="r" title="Search for references of 'IOException'" href=>IOException</a> <a class="r" title="Search for references of 'e'" href=>e</a>) {
                                <a class="r" title="Search for references of 'System'" href=>System</a>.<a class="r" title="Search for references of 'out'" href=>out</a>.<a class="r" title="Search for references of 'println'" href=>println</a>(<span class="str">&quot;IO Error: &quot;</span> + <a class="r" title="Search for references of 'e'" href=>e</a>.<a class="r" title="Search for references of 'getMessage'" href=>getMessage</a>());
                        }
                }
                <a class="r" title="Search for references of 'PutBuffer'" href=>PutBuffer</a> &lt;&lt;= 8;
                <a class="r" title="Search for references of 'PutBits'" href=>PutBits</a> -= 8;
        }
        <a class="r" title="Search for references of 'bufferPutBuffer'" href=>bufferPutBuffer</a> = <a class="r" title="Search for references of 'PutBuffer'" href=>PutBuffer</a>;
        <a class="r" title="Search for references of 'bufferPutBits'" href=>bufferPutBits</a> = <a class="r" title="Search for references of 'PutBits'" href=>PutBits</a>;

        }

        <span class="k">void</span> <a class="r" title="Search for references of 'flushBuffer'" href=>flushBuffer</a>(<a class="r" title="Search for references of 'BufferedOutputStream'" href=>BufferedOutputStream</a> <a class="r" title="Search for references of 'outStream'" href=>outStream</a>) {
                <span class="k">int</span> <a class="r" title="Search for references of 'PutBuffer'" href=>PutBuffer</a> = <a class="r" title="Search for references of 'bufferPutBuffer'" href=>bufferPutBuffer</a>;
                <span class="k">int</span> <a class="r" title="Search for references of 'PutBits'" href=>PutBits</a> = <a class="r" title="Search for references of 'bufferPutBits'" href=>bufferPutBits</a>;
                <span class="k">while</span> (<a class="r" title="Search for references of 'PutBits'" href=>PutBits</a> &gt;= 8) {
                        <span class="k">int</span> <a class="r" title="Search for references of 'c'" href=>c</a> = ((<a class="r" title="Search for references of 'PutBuffer'" href=>PutBuffer</a> &gt;&gt; 16) &amp; 0xFF);
                        <span class="k">try</span>
                        {
                                <a class="r" title="Search for references of 'outStream'" href=>outStream</a>.<a class="r" title="Search for references of 'write'" href=>write</a>(<a class="r" title="Search for references of 'c'" href=>c</a>);
                        }
                        <span class="k">catch</span> (<a class="r" title="Search for references of 'IOException'" href=>IOException</a> <a class="r" title="Search for references of 'e'" href=>e</a>) {
                                <a class="r" title="Search for references of 'System'" href=>System</a>.<a class="r" title="Search for references of 'out'" href=>out</a>.<a class="r" title="Search for references of 'println'" href=>println</a>(<span class="str">&quot;IO Error: &quot;</span> + <a class="r" title="Search for references of 'e'" href=>e</a>.<a class="r" title="Search for references of 'getMessage'" href=>getMessage</a>());
                        }
                        <span class="k">if</span> (<a class="r" title="Search for references of 'c'" href=>c</a> == 0xFF) {
                                <span class="k">try</span> {
                                        <a class="r" title="Search for references of 'outStream'" href=>outStream</a>.<a class="r" title="Search for references of 'write'" href=>write</a>(0);
                                }
                                <span class="k">catch</span> (<a class="r" title="Search for references of 'IOException'" href=>IOException</a> <a class="r" title="Search for references of 'e'" href=>e</a>) {
                                        <a class="r" title="Search for references of 'System'" href=>System</a>.<a class="r" title="Search for references of 'out'" href=>out</a>.<a class="r" title="Search for references of 'println'" href=>println</a>(<span class="str">&quot;IO Error: &quot;</span> + <a class="r" title="Search for references of 'e'" href=>e</a>.<a class="r" title="Search for references of 'getMessage'" href=>getMessage</a>());
                                }
                        }
                        <a class="r" title="Search for references of 'PutBuffer'" href=>PutBuffer</a> &lt;&lt;= 8;
                        <a class="r" title="Search for references of 'PutBits'" href=>PutBits</a> -= 8;
                }
                <span class="k">if</span> (<a class="r" title="Search for references of 'PutBits'" href=>PutBits</a> &gt; 0) {
                        <span class="k">int</span> <a class="r" title="Search for references of 'c'" href=>c</a> = ((<a class="r" title="Search for references of 'PutBuffer'" href=>PutBuffer</a> &gt;&gt; 16) &amp; 0xFF);
                        <span class="k">try</span>
                        {
                                <a class="r" title="Search for references of 'outStream'" href=>outStream</a>.<a class="r" title="Search for references of 'write'" href=>write</a>(<a class="r" title="Search for references of 'c'" href=>c</a>);
                        }
                        <span class="k">catch</span> (<a class="r" title="Search for references of 'IOException'" href=>IOException</a> <a class="r" title="Search for references of 'e'" href=>e</a>) {
                                <a class="r" title="Search for references of 'System'" href=>System</a>.<a class="r" title="Search for references of 'out'" href=>out</a>.<a class="r" title="Search for references of 'println'" href=>println</a>(<span class="str">&quot;IO Error: &quot;</span> + <a class="r" title="Search for references of 'e'" href=>e</a>.<a class="r" title="Search for references of 'getMessage'" href=>getMessage</a>());
                        }
                }
        }

    <span class="c">/*
    * Initialisation of the Huffman codes for Luminance anｄ Chrominance.
    * This code results in the same tables created in the IJG Jpeg-6a
    * library.
    */</span>

    <span class="k">public</span> <span class="k">void</span> <a class="r" title="Search for references of 'initHuf'" href=>initHuf</a>()
    {
        <a class="r" title="Search for references of 'DC_matrix0'" href=>DC_matrix0</a>=<span class="k">new</span> <span class="k">int</span>[12][2];
        <a class="r" title="Search for references of 'DC_matrix1'" href=>DC_matrix1</a>=<span class="k">new</span> <span class="k">int</span>[12][2];
        <a class="r" title="Search for references of 'AC_matrix0'" href=>AC_matrix0</a>=<span class="k">new</span> <span class="k">int</span>[255][2];
        <a class="r" title="Search for references of 'AC_matrix1'" href=>AC_matrix1</a>=<span class="k">new</span> <span class="k">int</span>[255][2];
        <a class="r" title="Search for references of 'DC_matrix'" href=>DC_matrix</a> = <span class="k">new</span> <a class="r" title="Search for references of 'Object'" href=>Object</a>[2];
        <a class="r" title="Search for references of 'AC_matrix'" href=>AC_matrix</a> = <span class="k">new</span> <a class="r" title="Search for references of 'Object'" href=>Object</a>[2];
        <span class="k">int</span> <a class="r" title="Search for references of 'p'" href=>p</a>, <a class="r" title="Search for references of 'l'" href=>l</a>, <a class="r" title="Search for references of 'i'" href=>i</a>, <a class="r" title="Search for references of 'lastp'" href=>lastp</a>, <a class="r" title="Search for references of 'si'" href=>si</a>, <a class="r" title="Search for references of 'code'" href=>code</a>;
        <span class="k">int</span>[] <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a> = <span class="k">new</span> <span class="k">int</span>[257];
        <span class="k">int</span>[] <a class="r" title="Search for references of 'huffcode'" href=>huffcode</a>= <span class="k">new</span> <span class="k">int</span>[257];

        <span class="c">/*
        * init of the DC values for the chrominance
        * [][0] is the code   [][1] is the number of bit
        */</span>

        <a class="r" title="Search for references of 'p'" href=>p</a> = 0;
        <span class="k">for</span> (<a class="r" title="Search for references of 'l'" href=>l</a> = 1; <a class="r" title="Search for references of 'l'" href=>l</a> &lt;= 16; <a class="r" title="Search for references of 'l'" href=>l</a>++)
        {
                <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 1; <a class="r" title="Search for references of 'i'" href=>i</a> &lt;= <a class="r" title="Search for references of 'bitsDCchrominance'" href=>bitsDCchrominance</a>[<a class="r" title="Search for references of 'l'" href=>l</a>]; <a class="r" title="Search for references of 'i'" href=>i</a>++)
                {
                        <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>++] = <a class="r" title="Search for references of 'l'" href=>l</a>;
                }
        }
        <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>] = 0;
        <a class="r" title="Search for references of 'lastp'" href=>lastp</a> = <a class="r" title="Search for references of 'p'" href=>p</a>;

        <a class="r" title="Search for references of 'code'" href=>code</a> = 0;
        <a class="r" title="Search for references of 'si'" href=>si</a> = <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[0];
        <a class="r" title="Search for references of 'p'" href=>p</a> = 0;
        <span class="k">while</span>(<a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>] != 0)
        {
                <span class="k">while</span>(<a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>] == <a class="r" title="Search for references of 'si'" href=>si</a>)
                {
                        <a class="r" title="Search for references of 'huffcode'" href=>huffcode</a>[<a class="r" title="Search for references of 'p'" href=>p</a>++] = <a class="r" title="Search for references of 'code'" href=>code</a>;
                        <a class="r" title="Search for references of 'code'" href=>code</a>++;
                }
                <a class="r" title="Search for references of 'code'" href=>code</a> &lt;&lt;= 1;
                <a class="r" title="Search for references of 'si'" href=>si</a>++;
        }

        <span class="k">for</span> (<a class="r" title="Search for references of 'p'" href=>p</a> = 0; <a class="r" title="Search for references of 'p'" href=>p</a> &lt; <a class="r" title="Search for references of 'lastp'" href=>lastp</a>; <a class="r" title="Search for references of 'p'" href=>p</a>++)
        {
                <a class="r" title="Search for references of 'DC_matrix1'" href=>DC_matrix1</a>[<a class="r" title="Search for references of 'valDCchrominance'" href=>valDCchrominance</a>[<a class="r" title="Search for references of 'p'" href=>p</a>]][0] = <a class="r" title="Search for references of 'huffcode'" href=>huffcode</a>[<a class="r" title="Search for references of 'p'" href=>p</a>];
                <a class="r" title="Search for references of 'DC_matrix1'" href=>DC_matrix1</a>[<a class="r" title="Search for references of 'valDCchrominance'" href=>valDCchrominance</a>[<a class="r" title="Search for references of 'p'" href=>p</a>]][1] = <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>];
        }

        <span class="c">/*
        * Init of the AC hufmann code for the chrominance
        * matrix [][][0] is the code &amp; matrix[][][1] is the number of bit needed
        */</span>

        <a class="r" title="Search for references of 'p'" href=>p</a> = 0;
        <span class="k">for</span> (<a class="r" title="Search for references of 'l'" href=>l</a> = 1; <a class="r" title="Search for references of 'l'" href=>l</a> &lt;= 16; <a class="r" title="Search for references of 'l'" href=>l</a>++)
        {
                <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 1; <a class="r" title="Search for references of 'i'" href=>i</a> &lt;= <a class="r" title="Search for references of 'bitsACchrominance'" href=>bitsACchrominance</a>[<a class="r" title="Search for references of 'l'" href=>l</a>]; <a class="r" title="Search for references of 'i'" href=>i</a>++)
                {
                        <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>++] = <a class="r" title="Search for references of 'l'" href=>l</a>;
                }
        }
        <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>] = 0;
        <a class="r" title="Search for references of 'lastp'" href=>lastp</a> = <a class="r" title="Search for references of 'p'" href=>p</a>;

        <a class="r" title="Search for references of 'code'" href=>code</a> = 0;
        <a class="r" title="Search for references of 'si'" href=>si</a> = <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[0];
        <a class="r" title="Search for references of 'p'" href=>p</a> = 0;
        <span class="k">while</span>(<a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>] != 0)
        {
                <span class="k">while</span>(<a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>] == <a class="r" title="Search for references of 'si'" href=>si</a>)
                {
                        <a class="r" title="Search for references of 'huffcode'" href=>huffcode</a>[<a class="r" title="Search for references of 'p'" href=>p</a>++] = <a class="r" title="Search for references of 'code'" href=>code</a>;
                        <a class="r" title="Search for references of 'code'" href=>code</a>++;
                }
                <a class="r" title="Search for references of 'code'" href=>code</a> &lt;&lt;= 1;
                <a class="r" title="Search for references of 'si'" href=>si</a>++;
        }

        <span class="k">for</span> (<a class="r" title="Search for references of 'p'" href=>p</a> = 0; <a class="r" title="Search for references of 'p'" href=>p</a> &lt; <a class="r" title="Search for references of 'lastp'" href=>lastp</a>; <a class="r" title="Search for references of 'p'" href=>p</a>++)
        {
                <a class="r" title="Search for references of 'AC_matrix1'" href=>AC_matrix1</a>[<a class="r" title="Search for references of 'valACchrominance'" href=>valACchrominance</a>[<a class="r" title="Search for references of 'p'" href=>p</a>]][0] = <a class="r" title="Search for references of 'huffcode'" href=>huffcode</a>[<a class="r" title="Search for references of 'p'" href=>p</a>];
                <a class="r" title="Search for references of 'AC_matrix1'" href=>AC_matrix1</a>[<a class="r" title="Search for references of 'valACchrominance'" href=>valACchrominance</a>[<a class="r" title="Search for references of 'p'" href=>p</a>]][1] = <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>];
        }

        <span class="c">/*
        * init of the DC values for the luminance
        * [][0] is the code   [][1] is the number of bit
        */</span>
        <a class="r" title="Search for references of 'p'" href=>p</a> = 0;
        <span class="k">for</span> (<a class="r" title="Search for references of 'l'" href=>l</a> = 1; <a class="r" title="Search for references of 'l'" href=>l</a> &lt;= 16; <a class="r" title="Search for references of 'l'" href=>l</a>++)
        {
                <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 1; <a class="r" title="Search for references of 'i'" href=>i</a> &lt;= <a class="r" title="Search for references of 'bitsDCluminance'" href=>bitsDCluminance</a>[<a class="r" title="Search for references of 'l'" href=>l</a>]; <a class="r" title="Search for references of 'i'" href=>i</a>++)
                {
                        <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>++] = <a class="r" title="Search for references of 'l'" href=>l</a>;
                }
        }
        <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>] = 0;
        <a class="r" title="Search for references of 'lastp'" href=>lastp</a> = <a class="r" title="Search for references of 'p'" href=>p</a>;

        <a class="r" title="Search for references of 'code'" href=>code</a> = 0;
        <a class="r" title="Search for references of 'si'" href=>si</a> = <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[0];
        <a class="r" title="Search for references of 'p'" href=>p</a> = 0;
        <span class="k">while</span>(<a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>] != 0)
        {
                <span class="k">while</span>(<a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>] == <a class="r" title="Search for references of 'si'" href=>si</a>)
                {
                        <a class="r" title="Search for references of 'huffcode'" href=>huffcode</a>[<a class="r" title="Search for references of 'p'" href=>p</a>++] = <a class="r" title="Search for references of 'code'" href=>code</a>;
                        <a class="r" title="Search for references of 'code'" href=>code</a>++;
                }
                <a class="r" title="Search for references of 'code'" href=>code</a> &lt;&lt;= 1;
                <a class="r" title="Search for references of 'si'" href=>si</a>++;
        }

        <span class="k">for</span> (<a class="r" title="Search for references of 'p'" href=>p</a> = 0; <a class="r" title="Search for references of 'p'" href=>p</a> &lt; <a class="r" title="Search for references of 'lastp'" href=>lastp</a>; <a class="r" title="Search for references of 'p'" href=>p</a>++)
        {
                <a class="r" title="Search for references of 'DC_matrix0'" href=>DC_matrix0</a>[<a class="r" title="Search for references of 'valDCluminance'" href=>valDCluminance</a>[<a class="r" title="Search for references of 'p'" href=>p</a>]][0] = <a class="r" title="Search for references of 'huffcode'" href=>huffcode</a>[<a class="r" title="Search for references of 'p'" href=>p</a>];
                <a class="r" title="Search for references of 'DC_matrix0'" href=>DC_matrix0</a>[<a class="r" title="Search for references of 'valDCluminance'" href=>valDCluminance</a>[<a class="r" title="Search for references of 'p'" href=>p</a>]][1] = <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>];
        }

        <span class="c">/*
        * Init of the AC hufmann code for luminance
        * matrix [][][0] is the code &amp; matrix[][][1] is the number of bit
        */</span>

        <a class="r" title="Search for references of 'p'" href=>p</a> = 0;
        <span class="k">for</span> (<a class="r" title="Search for references of 'l'" href=>l</a> = 1; <a class="r" title="Search for references of 'l'" href=>l</a> &lt;= 16; <a class="r" title="Search for references of 'l'" href=>l</a>++)
        {
                <span class="k">for</span> (<a class="r" title="Search for references of 'i'" href=>i</a> = 1; <a class="r" title="Search for references of 'i'" href=>i</a> &lt;= <a class="r" title="Search for references of 'bitsACluminance'" href=>bitsACluminance</a>[<a class="r" title="Search for references of 'l'" href=>l</a>]; <a class="r" title="Search for references of 'i'" href=>i</a>++)
                {
                        <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>++] = <a class="r" title="Search for references of 'l'" href=>l</a>;
                }
        }
        <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>] = 0;
        <a class="r" title="Search for references of 'lastp'" href=>lastp</a> = <a class="r" title="Search for references of 'p'" href=>p</a>;

        <a class="r" title="Search for references of 'code'" href=>code</a> = 0;
        <a class="r" title="Search for references of 'si'" href=>si</a> = <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[0];
        <a class="r" title="Search for references of 'p'" href=>p</a> = 0;
        <span class="k">while</span>(<a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>] != 0)
        {
                <span class="k">while</span>(<a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'p'" href=>p</a>] == <a class="r" title="Search for references of 'si'" href=>si</a>)
                {
                        <a class="r" title="Search for references of 'huffcode'" href=>huffcode</a>[<a class="r" title="Search for references of 'p'" href=>p</a>++] = <a class="r" title="Search for references of 'code'" href=>code</a>;
                        <a class="r" title="Search for references of 'code'" href=>code</a>++;
                }
                <a class="r" title="Search for references of 'code'" href=>code</a> &lt;&lt;= 1;
                <a class="r" title="Search for references of 'si'" href=>si</a>++;
        }
        <span class="k">for</span> (<span class="k">int</span> <a class="r" title="Search for references of 'q'" href=>q</a> = 0; <a class="r" title="Search for references of 'q'" href=>q</a> &lt; <a class="r" title="Search for references of 'lastp'" href=>lastp</a>; <a class="r" title="Search for references of 'q'" href=>q</a>++)
        {
                <a class="r" title="Search for references of 'AC_matrix0'" href=>AC_matrix0</a>[<a class="r" title="Search for references of 'valACluminance'" href=>valACluminance</a>[<a class="r" title="Search for references of 'q'" href=>q</a>]][0] = <a class="r" title="Search for references of 'huffcode'" href=>huffcode</a>[<a class="r" title="Search for references of 'q'" href=>q</a>];
                <a class="r" title="Search for references of 'AC_matrix0'" href=>AC_matrix0</a>[<a class="r" title="Search for references of 'valACluminance'" href=>valACluminance</a>[<a class="r" title="Search for references of 'q'" href=>q</a>]][1] = <a class="r" title="Search for references of 'huffsize'" href=>huffsize</a>[<a class="r" title="Search for references of 'q'" href=>q</a>];
        } 

        <a class="r" title="Search for references of 'DC_matrix'" href=>DC_matrix</a>[0] = <a class="r" title="Search for references of 'DC_matrix0'" href=>DC_matrix0</a>;
        <a class="r" title="Search for references of 'DC_matrix'" href=>DC_matrix</a>[1] = <a class="r" title="Search for references of 'DC_matrix1'" href=>DC_matrix1</a>;
        <a class="r" title="Search for references of 'AC_matrix'" href=>AC_matrix</a>[0] = <a class="r" title="Search for references of 'AC_matrix0'" href=>AC_matrix0</a>;
        <a class="r" title="Search for references of 'AC_matrix'" href=>AC_matrix</a>[1] = <a class="r" title="Search for references of 'AC_matrix1'" href=>AC_matrix1</a>;
    }

}

<span class="c">/*
 * JpegInfo - Given an image, sets default information about it anｄ divides
 * it into its constituant components, downsizing those that need to be.
 */</span>

<span class="k">class</span> <a class="r" title="Search for references of 'JpegInfo'" href=>JpegInfo</a>
{
    <a class="r" title="Search for references of 'String'" href=>String</a> <a class="r" title="Search for references of 'Comment'" href=>Comment</a>;
    <span class="k">public</span> <a class="r" title="Search for references of 'Image'" href=>Image</a> <a class="r" title="Search for references of 'imageobj'" href=>imageobj</a>;
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>;
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>;
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'BlockWidth'" href=>BlockWidth</a>[];
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'BlockHeight'" href=>BlockHeight</a>[];

<span class="c">// the following are set as the default</span>
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'Precision'" href=>Precision</a> = 8;
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'NumberOfComponents'" href=>NumberOfComponents</a> = 3;
    <span class="k">public</span> <a class="r" title="Search for references of 'Object'" href=>Object</a> <a class="r" title="Search for references of 'Components'" href=>Components</a>[];
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'CompID'" href=>CompID</a> = {1, 2, 3};
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'HsampFactor'" href=>HsampFactor</a> = {1, 1, 1};
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'VsampFactor'" href=>VsampFactor</a> = {1, 1, 1};
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'QtableNumber'" href=>QtableNumber</a> = {0, 1, 1};
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'DCtableNumber'" href=>DCtableNumber</a> = {0, 1, 1};
    <span class="k">public</span> <span class="k">int</span>[] <a class="r" title="Search for references of 'ACtableNumber'" href=>ACtableNumber</a> = {0, 1, 1};
    <span class="k">public</span> <span class="k">boolean</span>[] <a class="r" title="Search for references of 'lastColumnIsDummy'" href=>lastColumnIsDummy</a> = {<span class="k">false</span>, <span class="k">false</span>, <span class="k">false</span>};
    <span class="k">public</span> <span class="k">boolean</span>[] <a class="r" title="Search for references of 'lastRowIsDummy'" href=>lastRowIsDummy</a> = {<span class="k">false</span>, <span class="k">false</span>, <span class="k">false</span>};
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'Ss'" href=>Ss</a> = 0;
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'Se'" href=>Se</a> = 63;
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'Ah'" href=>Ah</a> = 0;
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'Al'" href=>Al</a> = 0;
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'compWidth'" href=>compWidth</a>[], <a class="r" title="Search for references of 'compHeight'" href=>compHeight</a>[];
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'MaxHsampFactor'" href=>MaxHsampFactor</a>;
    <span class="k">public</span> <span class="k">int</span> <a class="r" title="Search for references of 'MaxVsampFactor'" href=>MaxVsampFactor</a>;


    <span class="k">public</span> <a class="r" title="Search for references of 'JpegInfo'" href=>JpegInfo</a>(<a class="r" title="Search for references of 'Image'" href=>Image</a> <a class="r" title="Search for references of 'image'" href=>image</a>)
    {
        <a class="r" title="Search for references of 'Components'" href=>Components</a> = <span class="k">new</span> <a class="r" title="Search for references of 'Object'" href=>Object</a>[<a class="r" title="Search for references of 'NumberOfComponents'" href=>NumberOfComponents</a>];
        <a class="r" title="Search for references of 'compWidth'" href=>compWidth</a> = <span class="k">new</span> <span class="k">int</span>[<a class="r" title="Search for references of 'NumberOfComponents'" href=>NumberOfComponents</a>];
        <a class="r" title="Search for references of 'compHeight'" href=>compHeight</a> = <span class="k">new</span> <span class="k">int</span>[<a class="r" title="Search for references of 'NumberOfComponents'" href=>NumberOfComponents</a>];
        <a class="r" title="Search for references of 'BlockWidth'" href=>BlockWidth</a> = <span class="k">new</span> <span class="k">int</span>[<a class="r" title="Search for references of 'NumberOfComponents'" href=>NumberOfComponents</a>];
        <a class="r" title="Search for references of 'BlockHeight'" href=>BlockHeight</a> = <span class="k">new</span> <span class="k">int</span>[<a class="r" title="Search for references of 'NumberOfComponents'" href=>NumberOfComponents</a>];
        <a class="r" title="Search for references of 'imageobj'" href=>imageobj</a> = <a class="r" title="Search for references of 'image'" href=>image</a>;
        <a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a> = <a class="r" title="Search for references of 'image'" href=>image</a>.<a class="r" title="Search for references of 'getWidth'" href=>getWidth</a>(<span class="k">null</span>);
        <a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a> = <a class="r" title="Search for references of 'image'" href=>image</a>.<a class="r" title="Search for references of 'getHeight'" href=>getHeight</a>(<span class="k">null</span>);
        <a class="r" title="Search for references of 'Comment'" href=>Comment</a> = <span class="str">&quot;JPEG Encoder Copyright 1998, James R. Weeks anｄ BioElectroMech.  &quot;</span>;
        <a class="r" title="Search for references of 'getYCCArray'" href=>getYCCArray</a>();
    }

    <span class="k">public</span> <span class="k">void</span> <a class="r" title="Search for references of 'setComment'" href=>setComment</a>(<a class="r" title="Search for references of 'String'" href=>String</a> <a class="r" title="Search for references of 'comment'" href=>comment</a>) {
        <a class="r" title="Search for references of 'Comment'" href=>Comment</a>.<a class="r" title="Search for references of 'concat'" href=>concat</a>(<a class="r" title="Search for references of 'comment'" href=>comment</a>);
    }

    <span class="k">public</span> <a class="r" title="Search for references of 'String'" href=>String</a> <a class="r" title="Search for references of 'getComment'" href=>getComment</a>() {
        <span class="k">return</span> <a class="r" title="Search for references of 'Comment'" href=>Comment</a>;
    }

    <span class="c">/*
     * This method creates anｄ fills three arrays, Y, Cb, anｄ Cr using the
     * input image.
     */</span>

    <span class="k">private</span> <span class="k">void</span> <a class="r" title="Search for references of 'getYCCArray'" href=>getYCCArray</a>()
    {
        <span class="k">int</span> <a class="r" title="Search for references of 'values'" href=>values</a>[] = <span class="k">new</span> <span class="k">int</span>[<a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a> * <a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>];
        <span class="k">int</span> <a class="r" title="Search for references of 'r'" href=>r</a>, <a class="r" title="Search for references of 'g'" href=>g</a>, <a class="r" title="Search for references of 'b'" href=>b</a>, <a class="r" title="Search for references of 'y'" href=>y</a>, <a class="r" title="Search for references of 'x'" href=>x</a>;
<span class="c">// In order to minimize the chance that grabPixels will throw an exception</span>
<span class="c">// it may be necessary to grab some pixels every few scanlines anｄ process</span>
<span class="c">// those before going for more.  The time expense may be prohibitive.</span>
<span class="c">// However, for a situation where memory overhead is a concern, this may be</span>
<span class="c">// the only choice.</span>
    	<a class="r" title="Search for references of 'PixelGrabber'" href=>PixelGrabber</a> <a class="r" title="Search for references of 'grabber'" href=>grabber</a> = <span class="k">new</span> <a class="r" title="Search for references of 'PixelGrabber'" href=>PixelGrabber</a>(<a class="r" title="Search for references of 'imageobj'" href=>imageobj</a>.<a class="r" title="Search for references of 'getSource'" href=>getSource</a>(), 0, 0, <a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>, <a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>, <a class="r" title="Search for references of 'values'" href=>values</a>, 0, <a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>);
        <a class="r" title="Search for references of 'MaxHsampFactor'" href=>MaxHsampFactor</a> = 1;
        <a class="r" title="Search for references of 'MaxVsampFactor'" href=>MaxVsampFactor</a> = 1;
        <span class="k">for</span> (<a class="r" title="Search for references of 'y'" href=>y</a> = 0; <a class="r" title="Search for references of 'y'" href=>y</a> &lt; <a class="r" title="Search for references of 'NumberOfComponents'" href=>NumberOfComponents</a>; <a class="r" title="Search for references of 'y'" href=>y</a>++) {
                <a class="r" title="Search for references of 'MaxHsampFactor'" href=>MaxHsampFactor</a> = <a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'max'" href=>max</a>(<a class="r" title="Search for references of 'MaxHsampFactor'" href=>MaxHsampFactor</a>, <a class="r" title="Search for references of 'HsampFactor'" href=>HsampFactor</a>[<a class="r" title="Search for references of 'y'" href=>y</a>]);
                <a class="r" title="Search for references of 'MaxVsampFactor'" href=>MaxVsampFactor</a> = <a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'max'" href=>max</a>(<a class="r" title="Search for references of 'MaxVsampFactor'" href=>MaxVsampFactor</a>, <a class="r" title="Search for references of 'VsampFactor'" href=>VsampFactor</a>[<a class="r" title="Search for references of 'y'" href=>y</a>]);
        }
        <span class="k">for</span> (<a class="r" title="Search for references of 'y'" href=>y</a> = 0; <a class="r" title="Search for references of 'y'" href=>y</a> &lt; <a class="r" title="Search for references of 'NumberOfComponents'" href=>NumberOfComponents</a>; <a class="r" title="Search for references of 'y'" href=>y</a>++) {
                <a class="r" title="Search for references of 'compWidth'" href=>compWidth</a>[<a class="r" title="Search for references of 'y'" href=>y</a>] = (((<a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>%8 != 0) ? ((<span class="k">int</span>) <a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'ceil'" href=>ceil</a>((<span class="k">double</span>) <a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>/8.0))*8 : <a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>)/<a class="r" title="Search for references of 'MaxHsampFactor'" href=>MaxHsampFactor</a>)*<a class="r" title="Search for references of 'HsampFactor'" href=>HsampFactor</a>[<a class="r" title="Search for references of 'y'" href=>y</a>];
                <span class="k">if</span> (<a class="r" title="Search for references of 'compWidth'" href=>compWidth</a>[<a class="r" title="Search for references of 'y'" href=>y</a>] != ((<a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>/<a class="r" title="Search for references of 'MaxHsampFactor'" href=>MaxHsampFactor</a>)*<a class="r" title="Search for references of 'HsampFactor'" href=>HsampFactor</a>[<a class="r" title="Search for references of 'y'" href=>y</a>])) {
                        <a class="r" title="Search for references of 'lastColumnIsDummy'" href=>lastColumnIsDummy</a>[<a class="r" title="Search for references of 'y'" href=>y</a>] = <span class="k">true</span>;
                }
                <span class="c">// results in a multiple of 8 for compWidth</span>
                <span class="c">// this will make the rest of the program fail for the unlikely</span>
                <span class="c">// event that someone tries to compress an 16 x 16 pixel image</span>
                <span class="c">// which would of course be worse than pointless</span>
                <a class="r" title="Search for references of 'BlockWidth'" href=>BlockWidth</a>[<a class="r" title="Search for references of 'y'" href=>y</a>] = (<span class="k">int</span>) <a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'ceil'" href=>ceil</a>((<span class="k">double</span>) <a class="r" title="Search for references of 'compWidth'" href=>compWidth</a>[<a class="r" title="Search for references of 'y'" href=>y</a>]/8.0);
                <a class="r" title="Search for references of 'compHeight'" href=>compHeight</a>[<a class="r" title="Search for references of 'y'" href=>y</a>] = (((<a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>%8 != 0) ? ((<span class="k">int</span>) <a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'ceil'" href=>ceil</a>((<span class="k">double</span>) <a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>/8.0))*8: <a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>)/<a class="r" title="Search for references of 'MaxVsampFactor'" href=>MaxVsampFactor</a>)*<a class="r" title="Search for references of 'VsampFactor'" href=>VsampFactor</a>[<a class="r" title="Search for references of 'y'" href=>y</a>];
                <span class="k">if</span> (<a class="r" title="Search for references of 'compHeight'" href=>compHeight</a>[<a class="r" title="Search for references of 'y'" href=>y</a>] != ((<a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>/<a class="r" title="Search for references of 'MaxVsampFactor'" href=>MaxVsampFactor</a>)*<a class="r" title="Search for references of 'VsampFactor'" href=>VsampFactor</a>[<a class="r" title="Search for references of 'y'" href=>y</a>])) {
                        <a class="r" title="Search for references of 'lastRowIsDummy'" href=>lastRowIsDummy</a>[<a class="r" title="Search for references of 'y'" href=>y</a>] = <span class="k">true</span>;
                }
                <a class="r" title="Search for references of 'BlockHeight'" href=>BlockHeight</a>[<a class="r" title="Search for references of 'y'" href=>y</a>] = (<span class="k">int</span>) <a class="r" title="Search for references of 'Math'" href=>Math</a>.<a class="r" title="Search for references of 'ceil'" href=>ceil</a>((<span class="k">double</span>) <a class="r" title="Search for references of 'compHeight'" href=>compHeight</a>[<a class="r" title="Search for references of 'y'" href=>y</a>]/8.0);
        }
        <span class="k">try</span>
    	{
    	    <span class="k">if</span>(<a class="r" title="Search for references of 'grabber'" href=>grabber</a>.<a class="r" title="Search for references of 'grabPixels'" href=>grabPixels</a>() != <span class="k">true</span>)
    	    {
    		    <span class="k">try</span>
    		    {
    		        <span class="k">throw</span> <span class="k">new</span> <a class="r" title="Search for references of 'AWTException'" href=>AWTException</a>(<span class="str">&quot;Grabber returned false: &quot;</span> + <a class="r" title="Search for references of 'grabber'" href=>grabber</a>.<a class="r" title="Search for references of 'status'" href=>status</a>());
    		    }
    		    <span class="k">catch</span> (<a class="r" title="Search for references of 'Exception'" href=>Exception</a> <a class="r" title="Search for references of 'e'" href=>e</a>) {};
            }
    	}
    	<span class="k">catch</span> (<a class="r" title="Search for references of 'InterruptedException'" href=>InterruptedException</a> <a class="r" title="Search for references of 'e'" href=>e</a>) {};
        <span class="k">float</span> <a class="r" title="Search for references of 'Y'" href=>Y</a>[][] = <span class="k">new</span> <span class="k">float</span>[<a class="r" title="Search for references of 'compHeight'" href=>compHeight</a>[0]][<a class="r" title="Search for references of 'compWidth'" href=>compWidth</a>[0]];
        <span class="k">float</span> <a class="r" title="Search for references of 'Cr1'" href=>Cr1</a>[][] = <span class="k">new</span> <span class="k">float</span>[<a class="r" title="Search for references of 'compHeight'" href=>compHeight</a>[0]][<a class="r" title="Search for references of 'compWidth'" href=>compWidth</a>[0]];
        <span class="k">float</span> <a class="r" title="Search for references of 'Cb1'" href=>Cb1</a>[][] = <span class="k">new</span> <span class="k">float</span>[<a class="r" title="Search for references of 'compHeight'" href=>compHeight</a>[0]][<a class="r" title="Search for references of 'compWidth'" href=>compWidth</a>[0]];
        <span class="k">float</span> <a class="r" title="Search for references of 'Cb2'" href=>Cb2</a>[][] = <span class="k">new</span> <span class="k">float</span>[<a class="r" title="Search for references of 'compHeight'" href=>compHeight</a>[1]][<a class="r" title="Search for references of 'compWidth'" href=>compWidth</a>[1]];
        <span class="k">float</span> <a class="r" title="Search for references of 'Cr2'" href=>Cr2</a>[][] = <span class="k">new</span> <span class="k">float</span>[<a class="r" title="Search for references of 'compHeight'" href=>compHeight</a>[2]][<a class="r" title="Search for references of 'compWidth'" href=>compWidth</a>[2]];
        <span class="k">int</span> <a class="r" title="Search for references of 'index'" href=>index</a> = 0;
        <span class="k">for</span> (<a class="r" title="Search for references of 'y'" href=>y</a> = 0; <a class="r" title="Search for references of 'y'" href=>y</a> &lt; <a class="r" title="Search for references of 'imageHeight'" href=>imageHeight</a>; ++<a class="r" title="Search for references of 'y'" href=>y</a>)
    	{
            <span class="k">for</span> (<a class="r" title="Search for references of 'x'" href=>x</a> = 0; <a class="r" title="Search for references of 'x'" href=>x</a> &lt; <a class="r" title="Search for references of 'imageWidth'" href=>imageWidth</a>; ++<a class="r" title="Search for references of 'x'" href=>x</a>)
    	    {
                <a class="r" title="Search for references of 'r'" href=>r</a> = ((<a class="r" title="Search for references of 'values'" href=>values</a>[<a class="r" title="Search for references of 'index'" href=>index</a>] &gt;&gt; 16) &amp; 0xff);
                <a class="r" title="Search for references of 'g'" href=>g</a> = ((<a class="r" title="Search for references of 'values'" href=>values</a>[<a class="r" title="Search for references of 'index'" href=>index</a>] &gt;&gt; 8) &amp; 0xff);
                <a class="r" title="Search for references of 'b'" href=>b</a> = (<a class="r" title="Search for references of 'values'" href=>values</a>[<a class="r" title="Search for references of 'index'" href=>index</a>] &amp; 0xff);

<span class="c">// The following three lines are a more correct color conversion but</span>
<span class="c">// the current conversion technique is sufficient anｄ results in a higher</span>
<span class="c">// compression rate.</span>
<span class="c">//                Y[y][x] = 16 + (float)(0.8588*(0.299 * (float)r + 0.587 * (float)g + 0.114 * (float)b ));</span>
<span class="c">//                Cb1[y][x] = 128 + (float)(0.8784*(-0.16874 * (float)r - 0.33126 * (float)g + 0.5 * (float)b));</span>
<span class="c">//                Cr1[y][x] = 128 + (float)(0.8784*(0.5 * (float)r - 0.41869 * (float)g - 0.08131 * (float)b));</span>
                <a class="r" title="Search for references of 'Y'" href=>Y</a>[<a class="r" title="Search for references of 'y'" href=>y</a>][<a class="r" title="Search for references of 'x'" href=>x</a>] = (<span class="k">float</span>)((0.299 * (<span class="k">float</span>)<a class="r" title="Search for references of 'r'" href=>r</a> + 0.587 * (<span class="k">float</span>)<a class="r" title="Search for references of 'g'" href=>g</a> + 0.114 * (<span class="k">float</span>)<a class="r" title="Search for references of 'b'" href=>b</a>));
                <a class="r" title="Search for references of 'Cb1'" href=>Cb1</a>[<a class="r" title="Search for references of 'y'" href=>y</a>][<a class="r" title="Search for references of 'x'" href=>x</a>] = 128 + (<span class="k">float</span>)((-0.16874 * (<span class="k">float</span>)<a class="r" title="Search for references of 'r'" href=>r</a> - 0.33126 * (<span class="k">float</span>)<a class="r" title="Search for references of 'g'" href=>g</a> + 0.5 * (<span class="k">float</span>)<a class="r" title="Search for references of 'b'" href=>b</a>));
                <a class="r" title="Search for references of 'Cr1'" href=>Cr1</a>[<a class="r" title="Search for references of 'y'" href=>y</a>][<a class="r" title="Search for references of 'x'" href=>x</a>] = 128 + (<span class="k">float</span>)((0.5 * (<span class="k">float</span>)<a class="r" title="Search for references of 'r'" href=>r</a> - 0.41869 * (<span class="k">float</span>)<a class="r" title="Search for references of 'g'" href=>g</a> - 0.08131 * (<span class="k">float</span>)<a class="r" title="Search for references of 'b'" href=>b</a>));
                <a class="r" title="Search for references of 'index'" href=>index</a>++;
    	    }
    	}

<span class="c">// Need a way to set the H anｄ V sample factors before allowing downsampling.</span>
<span class="c">// For now (04/04/98) downsampling must be hard coded.</span>
<span class="c">// Until a better downsampler is implemented, this will not be done.</span>
<span class="c">// Downsampling is currently supported.  The downsampling method here</span>
<span class="c">// is a simple box filter.</span>

        <a class="r" title="Search for references of 'Components'" href=>Components</a>[0] = <a class="r" title="Search for references of 'Y'" href=>Y</a>;
<span class="c">//        Cb2 = DownSample(Cb1, 1);</span>
        <a class="r" title="Search for references of 'Components'" href=>Components</a>[1] = <a class="r" title="Search for references of 'Cb1'" href=>Cb1</a>;
<span class="c">//        Cr2 = DownSample(Cr1, 2);</span>
        <a class="r" title="Search for references of 'Components'" href=>Components</a>[2] = <a class="r" title="Search for references of 'Cr1'" href=>Cr1</a>;
    }

    <span class="k">float</span>[][] <a class="r" title="Search for references of 'DownSample'" href=>DownSample</a>(<span class="k">float</span>[][] <a class="r" title="Search for references of 'C'" href=>C</a>, <span class="k">int</span> <a class="r" title="Search for references of 'comp'" href=>comp</a>)
    {
        <span class="k">int</span> <a class="r" title="Search for references of 'inrow'" href=>inrow</a>, <a class="r" title="Search for references of 'incol'" href=>incol</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'outrow'" href=>outrow</a>, <a class="r" title="Search for references of 'outcol'" href=>outcol</a>;
        <span class="k">float</span> <a class="r" title="Search for references of 'output'" href=>output</a>[][];
        <span class="k">int</span> <a class="r" title="Search for references of 'temp'" href=>temp</a>;
        <span class="k">int</span> <a class="r" title="Search for references of 'bias'" href=>bias</a>;
        <a class="r" title="Search for references of 'inrow'" href=>inrow</a> = 0;
        <a class="r" title="Search for references of 'incol'" href=>incol</a> = 0;
        <a class="r" title="Search for references of 'output'" href=>output</a> = <span class="k">new</span> <span class="k">float</span>[<a class="r" title="Search for references of 'compHeight'" href=>compHeight</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>]][<a class="r" title="Search for references of 'compWidth'" href=>compWidth</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>]];
        <span class="k">for</span> (<a class="r" title="Search for references of 'outrow'" href=>outrow</a> = 0; <a class="r" title="Search for references of 'outrow'" href=>outrow</a> &lt; <a class="r" title="Search for references of 'compHeight'" href=>compHeight</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>]; <a class="r" title="Search for references of 'outrow'" href=>outrow</a>++) {
                <a class="r" title="Search for references of 'bias'" href=>bias</a> = 1;
                <span class="k">for</span> (<a class="r" title="Search for references of 'outcol'" href=>outcol</a> = 0; <a class="r" title="Search for references of 'outcol'" href=>outcol</a> &lt; <a class="r" title="Search for references of 'compWidth'" href=>compWidth</a>[<a class="r" title="Search for references of 'comp'" href=>comp</a>]; <a class="r" title="Search for references of 'outcol'" href=>outcol</a>++) {
                        <a class="r" title="Search for references of 'output'" href=>output</a>[<a class="r" title="Search for references of 'outrow'" href=>outrow</a>][<a class="r" title="Search for references of 'outcol'" href=>outcol</a>] = (<a class="r" title="Search for references of 'C'" href=>C</a>[<a class="r" title="Search for references of 'inrow'" href=>inrow</a>][<a class="r" title="Search for references of 'incol'" href=>incol</a>++] + <a class="r" title="Search for references of 'C'" href=>C</a>[<a class="r" title="Search for references of 'inrow'" href=>inrow</a>++][<a class="r" title="Search for references of 'incol'" href=>incol</a>--] + <a class="r" title="Search for references of 'C'" href=>C</a>[<a class="r" title="Search for references of 'inrow'" href=>inrow</a>][<a class="r" title="Search for references of 'incol'" href=>incol</a>++] + <a class="r" title="Search for references of 'C'" href=>C</a>[<a class="r" title="Search for references of 'inrow'" href=>inrow</a>--][<a class="r" title="Search for references of 'incol'" href=>incol</a>++] + (<span class="k">float</span>)<a class="r" title="Search for references of 'bias'" href=>bias</a>)/(<span class="k">float</span>)4.0;
                        <a class="r" title="Search for references of 'bias'" href=>bias</a> ^= 3;
                }
                <a class="r" title="Search for references of 'inrow'" href=>inrow</a> += 2;
                <a class="r" title="Search for references of 'incol'" href=>incol</a> = 0;
        }
        <span class="k">return</span> <a class="r" title="Search for references of 'output'" href=>output</a>;
    }
}

<span class="c">/* LICENSE.TXT **************************************************************
The JpegEncoder anｄ its associated classes are Copyright (c) 1998,
James R. Weeks anｄ BioElectroMech.  This software is based in part on
the work of the Independent JPEG Group.

Redistribution anｄ use in source anｄ binary forms, with oｒ without
modification, are permitted provided that the following conditions are
met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions, all files included with the source
code, anｄ the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions anｄ the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR anｄ CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS oｒ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY anｄ FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR oｒ CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS oｒ SERVICES; LOSS OF USE, DATA, oｒ PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED anｄ ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, oｒ TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
****************************************************************************/</span>

<span class="c">/* IJGREADME.TXT ************************************************************
The Independent JPEG Group's JPEG software
==========================================

README for release 6a of 7-Feb-96
=================================

This distribution contains the sixth public release of the Independent JPEG
Group's free JPEG software.  You are welcome to redistribute this software and
to use it for any purpose, subject to the conditions under LEGAL ISSUES, below.

Serious users of this software (particularly those incorporating it into
larger programs) should contact IJG at jpeg-info@uunet.uu.net to be added to
our electronic mailing list.  Mailing list members are notified of updates
and have a chance to participate in technical discussions, etc.

This software is the work of Tom Lane, Philip Gladstone, Luis Ortiz, Jim
Boucher, Lee Crocker, Julian Minguillon, George Phillips, Davide Rossi,
Ge' Weijers, anｄ other members of the Independent JPEG Group.

IJG is not affiliated with the official ISO JPEG standards committee.


DOCUMENTATION ROADMAP
=====================

This file contains the following sections:

OVERVIEW            General description of JPEG anｄ the IJG software.
LEGAL ISSUES        Copyright, lack of warranty, terms of distribution.
REFERENCES          Where to learn more about JPEG.
ARCHIVE LOCATIONS   Where to find newer versions of this software.
RELATED SOFTWARE    Other stuff you should get.
FILE FORMAT WARS    Software *not* to get.
TO DO               Plans for future IJG releases.

Other documentation files in the distribution are:

User documentation:
  install.doc       How to configure anｄ install the IJG software.
  usage.doc         Usage instructions for cjpeg, djpeg, jpegtran,
                    rdjpgcom, anｄ wrjpgcom.
  *.1               Unix-style man pages for programs (same info as usage.doc).
  wizard.doc        Advanced usage instructions for JPEG wizards only.
  change.log        Version-to-version change highlights.
Programmer anｄ internal documentation:
  libjpeg.doc       How to use the JPEG library in your own programs.
  example.c         Sample code for calling the JPEG library.
  structure.doc     Overview of the JPEG library's internal structure.
  filelist.doc      Road map of IJG files.
  coderules.doc     Coding style rules --- please read if you contribute code.

Please read at least the files install.doc anｄ usage.doc.  Useful information
can also be found in the JPEG FAQ (Frequently Asked Questions) article.  See
ARCHIVE LOCATIONS below to find out where to obtain the FAQ article.

If you want to understand how the JPEG code works, we suggest reading one or
more of the REFERENCES, then looking at the documentation files (in roughly
the order listed) before diving into the code.


OVERVIEW
========

This package contains C software to implement JPEG image compression and
decompression.  JPEG (pronounced &quot;jay-peg&quot;) is a standardized compression
method for full-color anｄ gray-scale images.  JPEG is intended for compressing
&quot;real-world&quot; scenes; line drawings, cartoons anｄ other non-realistic images
are not its strong suit.  JPEG is lossy, meaning that the output image is not
exactly identical to the input image.  Hence you must not use JPEG if you
have to have identical output bits.  However, on typical photographic images,
very good compression levels can be obtained with no visible change, and
remarkably high compression levels are possible if you can tolerate a
low-quality image.  For more details, see the references, oｒ just experiment
with various compression settings.

This software implements JPEG baseline, extended-sequential, anｄ progressive
compression processes.  Provision is made for supporting all variants of these
processes, although some uncommon parameter settings aren't implemented yet.
For legal reasons, we are not distributing code for the arithmetic-coding
variants of JPEG; see LEGAL ISSUES.  We have made no provision for supporting
the hierarchical oｒ lossless processes defined in the standard.

We provide a set of library routines for reading anｄ writing JPEG image files,
plus two sample applications &quot;cjpeg&quot; anｄ &quot;djpeg&quot;, which use the library to
perform conversion between JPEG anｄ some other popular image file formats.
The library is intended to be reused in other applications.

In order to support file conversion anｄ viewing software, we have included
considerable functionality beyond the bare JPEG coding/decoding capability;
for example, the color quantization modules are not strictly part of JPEG
decoding, but they are essential for output to colormapped file formats or
colormapped displays.  These extra functions can be compiled out of the
library if not required for a particular application.  We have also included
&quot;jpegtran&quot;, a utility for lossless transcoding between different JPEG
processes, anｄ &quot;rdjpgcom&quot; anｄ &quot;wrjpgcom&quot;, two simple applications for
inserting anｄ extracting textual comments in JFIF files.

The emphasis in designing this software has been on achieving portability and
flexibility, while also making it fast enough to be useful.  In particular,
the software is not intended to be read as a tutorial on JPEG.  (See the
REFERENCES section for introductory material.)  Rather, it is intended to
be reliable, portable, industrial-strength code.  We do not claim to have
achieved that goal in every aspect of the software, but we strive for it.

We welcome the use of this software as a component of commercial products.
No royalty is required, but we do ask for an acknowledgement in product
documentation, as described under LEGAL ISSUES.


LEGAL ISSUES
============

In plain English:

1. We don't promise that this software works.  (But if you find any bugs,
   please let us know!)
2. You can use this software for whatever you want.  You don't have to pay us.
3. You may not pretend that you wrote this software.  If you use it in a
   program, you must acknowledge somewhere in your documentation that
   you've used the IJG code.

In legalese:

The authors make NO WARRANTY oｒ representation, either express oｒ implied,
with respect to this software, its quality, accuracy, merchantability, or
fitness for a particular purpose.  This software is provided &quot;AS IS&quot;, anｄ you,
its user, assume the entire risk as to its quality anｄ accuracy.

This software is copyright (C) 1991-1996, Thomas G. Lane.
All Rights Reserved except as specified below.

Permission is hereby granted to use, copy, modify, anｄ distribute this
software (or portions thereof) for any purpose, without fee, subject to these
conditions:
(1) If any part of the source code for this software is distributed, then this
README file must be included, with this copyright anｄ no-warranty notice
unaltered; anｄ any additions, deletions, oｒ changes to the original files
must be clearly indicated in accompanying documentation.
(2) If only executable code is distributed, then the accompanying
documentation must state that &quot;this software is based in part on the work of
the Independent JPEG Group&quot;.
(3) Permission for use of this software is granted only if the user accepts
full responsibility for any undesirable consequences; the authors accept
NO LIABILITY for damages of any kind.

These conditions apply to any software derived from oｒ based on the IJG code,
not just to the unmodified library.  If you use our work, you ought to
acknowledge us.

Permission is NOT granted for the use of any IJG author's name oｒ company name
in advertising oｒ publicity relating to this software oｒ products derived from
it.  This software may be referred to only as &quot;the Independent JPEG Group's
software&quot;.

We specifically permit anｄ encourage the use of this software as the basis of
commercial products, provided that all warranty oｒ liability claims are
assumed by the product vendor.


ansi2knr.c is included in this distribution by permission of L. Peter Deutsch,
sole proprietor of its copyright holder, Aladdin Enterprises of Menlo Park, CA.
ansi2knr.c is NOT covered by the above copyright anｄ conditions, but instead
by the usual distribution terms of the Free Software Foundation; principally,
that you must include source code if you redistribute it.  (See the file
ansi2knr.c for full details.)  However, since ansi2knr.c is not needed as part
of any program generated from the IJG code, this does not limit you more than
the foregoing paragraphs do.

The configuration script &quot;configure&quot; was produced with GNU Autoconf.  It
is copyright by the Free Software Foundation but is freely distributable.

It appears that the arithmetic coding option of the JPEG spec is covered by
patents owned by IBM, AT&amp;T, anｄ Mitsubishi.  Hence arithmetic coding cannot
legally be used without obtaining one oｒ more licenses.  For this reason,
support for arithmetic coding has been removed from the free JPEG software.
(Since arithmetic coding provides only a marginal gain over the unpatented
Huffman mode, it is unlikely that very many implementations will support it.)
So far as we are aware, there are no patent restrictions on the remaining
code.

WARNING: Unisys has begun to enforce their patent on LZW compression against
GIF encoders anｄ decoders.  You will need a license from Unisys to use the
included rdgif.c oｒ wrgif.c files in a commercial oｒ shareware application.
At this time, Unisys is not enforcing their patent against freeware, so
distribution of this package remains legal.  However, we intend to remove
GIF support from the IJG package as soon as a suitable replacement format
becomes reasonably popular.

We are required to state that
    &quot;The Graphics Interchange Format(c) is the Copyright property of
    CompuServe Incorporated.  GIF(sm) is a Service Mark property of
    CompuServe Incorporated.&quot;


REFERENCES
==========

We highly recommend reading one oｒ more of these references before trying to
understand the innards of the JPEG software.

The best short technical introduction to the JPEG compression algorithm is
	Wallace, Gregory K.  &quot;The JPEG Still Picture Compression Standard&quot;,
	Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
(Adjacent articles in that issue discuss MPEG motion picture compression,
applications of JPEG, anｄ related topics.)  If you don't have the CACM issue
handy, a PostScript file containing a revised version of Wallace's article
is available at ftp.uu.net, graphics/jpeg/wallace.ps.gz.  The file (actually
a preprint for an article that appeared in IEEE Trans. Consumer Electronics)
omits the sample images that appeared in CACM, but it includes corrections
and some added material.  Note: the Wallace article is copyright ACM and
IEEE, anｄ it may not be used for commercial purposes.

A somewhat less technical, more leisurely introduction to JPEG can be found in
&quot;The Data Compression Book&quot; by Mark Nelson, published by M&amp;T Books (Redwood
City, CA), 1991, ISBN 1-55851-216-0.  This book provides good explanations and
example C code for a multitude of compression methods including JPEG.  It is
an excellent source if you are comfortable reading C code but don't know much
about data compression in general.  The book's JPEG sample code is far from
industrial-strength, but when you are ready to look at a full implementation,
you've got one here...

The best full description of JPEG is the textbook &quot;JPEG Still Image Data
Compression Standard&quot; by William B. Pennebaker anｄ Joan L. Mitchell, published
by Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1.  Price US$59.95, 638 pp.
The book includes the complete text of the ISO JPEG standards (DIS 10918-1
and draft DIS 10918-2).  This is by far the most complete exposition of JPEG
in existence, anｄ we highly recommend it.

The JPEG standard itself is not available electronically; you must order a
paper copy through ISO oｒ ITU.  (Unless you feel a need to own a certified
official copy, we recommend buying the Pennebaker anｄ Mitchell book instead;
it's much cheaper anｄ includes a great deal of useful explanatory material.)
In the USA, copies of the standard may be ordered from ANSI Sales at (212)
642-4900, oｒ from Global Engineering Documents at (800) 854-7179.  (ANSI
doesn't take credit card orders, but Global does.)  It's not cheap: as of
1992, ANSI was charging $95 for Part 1 anｄ $47 for Part 2, plus 7%
shipping/handling.  The standard is divided into two parts, Part 1 being the
actual specification, while Part 2 covers compliance testing methods.  Part 1
is titled &quot;Digital Compression anｄ Coding of Continuous-tone Still Images,
Part 1: Requirements anｄ guidelines&quot; anｄ has document numbers ISO/IEC IS
10918-1, ITU-T T.81.  Part 2 is titled &quot;Digital Compression anｄ Coding of
Continuous-tone Still Images, Part 2: Compliance testing&quot; anｄ has document
numbers ISO/IEC IS 10918-2, ITU-T T.83.

Extensions to the original JPEG standard are defined in JPEG Part 3, a new ISO
document.  Part 3 is undergoing ISO balloting anｄ is expected to be approved
by the end of 1995; it will have document numbers ISO/IEC IS 10918-3, ITU-T
T.84.  IJG currently does not support any Part 3 extensions.

The JPEG standard does not specify all details of an interchangeable file
format.  For the omitted details we follow the &quot;JFIF&quot; conventions, revision
1.02.  A copy of the JFIF spec is available from:
	Literature Department
	C-Cube Microsystems, Inc.
	1778 McCarthy Blvd.
	Milpitas, CA 95035
	phone (408) 944-6300,  fax (408) 944-6314
A PostScript version of this document is available at ftp.uu.net, file
graphics/jpeg/jfif.ps.gz.  It can also be obtained by e-mail from the C-Cube
mail server, netlib@c3.pla.ca.us.  Send the message &quot;send jfif_ps from jpeg&quot;
to the server to obtain the JFIF document; send the message &quot;help&quot; if you have
trouble.

The TIFF 6.0 file format specification can be obtained by FTP from sgi.com
(192.48.153.1), file graphics/tiff/TIFF6.ps.Z; oｒ you can order a printed
copy from Aldus Corp. at (206) 628-6593.  The JPEG incorporation scheme
found in the TIFF 6.0 spec of 3-June-92 has a number of serious problems.
IJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6).
Instead, we recommend the JPEG design proposed by TIFF Technical Note #2
(Compression tag 7).  Copies of this Note can be obtained from sgi.com or
from ftp.uu.net:/graphics/jpeg/.  It is expected that the next revision of
the TIFF spec will replace the 6.0 JPEG design with the Note's design.
Although IJG's own code does not support TIFF/JPEG, the free libtiff library
uses our library to implement TIFF/JPEG per the Note.  libtiff is available
from sgi.com:/graphics/tiff/.


ARCHIVE LOCATIONS
=================

The &quot;official&quot; archive site for this software is ftp.uu.net (Internet
address 192.48.96.9).  The most recent released version can always be found
there in directory graphics/jpeg.  This particular version will be archived
as graphics/jpeg/jpegsrc.v6a.tar.gz.  If you are on the Internet, you
can retrieve files from ftp.uu.net by standard anonymous FTP.  If you don't
have FTP access, UUNET's archives are also available via UUCP; contact
help@uunet.uu.net for information on retrieving files that way.

Numerous Internet sites maintain copies of the UUNET files.  However, only
ftp.uu.net is guaranteed to have the latest official version.

You can also obtain this software in DOS-compatible &quot;zip&quot; archive format from
the SimTel archives (ftp.coast.net:/SimTel/msdos/graphics/), oｒ on CompuServe
in the Graphics Support forum (GO CIS:GRAPHSUP), library 12 &quot;JPEG Tools&quot;.
Again, these versions may sometimes lag behind the ftp.uu.net release.

The JPEG FAQ (Frequently Asked Questions) article is a useful source of
general information about JPEG.  It is updated constantly anｄ therefore is
not included in this distribution.  The FAQ is posted every two weeks to
Usenet newsgroups comp.graphics.misc, news.answers, anｄ other groups.
You can always obtain the latest version from the news.answers archive at
rtfm.mit.edu.  By FTP, fetch /pub/usenet/news.answers/jpeg-faq/part1 and
.../part2.  If you don't have FTP, send e-mail to mail-server@rtfm.mit.edu
with body
	send usenet/news.answers/jpeg-faq/part1
	send usenet/news.answers/jpeg-faq/part2


RELATED SOFTWARE
================

Numerous viewing anｄ image manipulation programs now support JPEG.  (Quite a
few of them use this library to do so.)  The JPEG FAQ described above lists
some of the more popular free anｄ shareware viewers, anｄ tells where to
obtain them on Internet.

If you are on a Unix machine, we highly recommend Jef Poskanzer's free
PBMPLUS image software, which provides many useful operations on PPM-format
image files.  In particular, it can convert PPM images to anｄ from a wide
range of other formats.  You can obtain this package by FTP from ftp.x.org
(contrib/pbmplus*.tar.Z) oｒ ftp.ee.lbl.gov (pbmplus*.tar.Z).  There is also
a newer updatｅ of this package called NETPBM, available from
wuarchive.wustl.edu under directory /graphics/graphics/packages/NetPBM/.
Unfortunately PBMPLUS/NETPBM is not nearly as portable as the IJG software
is; you are likely to have difficulty making it work on any non-Unix machine.

A different free JPEG implementation, written by the PVRG group at Stanford,
is available from havefun.stanford.edu in directory pub/jpeg.  This program
is designed for research anｄ experimentation rather than production use;
it is slower, harder to use, anｄ less portable than the IJG code, but it
is easier to read anｄ modify.  Also, the PVRG code supports lossless JPEG,
which we do not.


FILE FORMAT WARS
================

Some JPEG programs produce files that are not compatible with our library.
The root of the problem is that the ISO JPEG committee failed to specify a
concrete file format.  Some vendors &quot;filled in the blanks&quot; on their own,
creating proprietary formats that no one else could read.  (For example, none
of the early commercial JPEG implementations for the Macintosh were able to
exchange compressed files.)

The file format we have adopted is called JFIF (see REFERENCES).  This format
has been agreed to by a number of major commercial JPEG vendors, anｄ it has
become the de facto standard.  JFIF is a minimal oｒ &quot;low end&quot; representation.
We recommend the use of TIFF/JPEG (TIFF revision 6.0 as modified by TIFF
Technical Note #2) for &quot;high end&quot; applications that need to record a lot of
additional data about an image.  TIFF/JPEG is fairly new anｄ not yet widely
supported, unfortunately.

The upcoming JPEG Part 3 standard defines a file format called SPIFF.
SPIFF is interoperable with JFIF, in the sense that most JFIF decoders should
be able to read the most common variant of SPIFF.  SPIFF has some technical
advantages over JFIF, but its major claim to fame is simply that it is an
official standard rather than an informal one.  At this point it is unclear
whether SPIFF will supersede JFIF oｒ whether JFIF will remain the de-facto
standard.  IJG intends to support SPIFF once the standard is frozen, but we
have not decided whether it should become our default output format oｒ not.
(In any case, our decoder will remain capable of reading JFIF indefinitely.)

Various proprietary file formats incorporating JPEG compression also exist.
We have little oｒ no sympathy for the existence of these formats.  Indeed,
one of the original reasons for developing this free software was to help
force convergence on common, open format standards for JPEG files.  Don't
use a proprietary file format!


TO DO
=====

In future versions, we are considering supporting some of the upcoming JPEG
Part 3 extensions --- principally, variable quantization anｄ the SPIFF file
format.

Tuning the software for better behavior at low quality/high compression
settings is also of interest.  The current method for scaling the
quantization tables is known not to be very good at low Q values.

As always, speeding things up is high on our priority list.

Please send bug reports, offers of help, etc. to jpeg-info@uunet.uu.net.
****************************************************************************/</span>
}
</pre>]]></description>
   <link>http://pudding.sharera.com/blog/BlogTopic/53965.htm</link>
   <comments>http://pudding.sharera.com/blog/BlogTopic/53965.htm</comments>
   <guid>http://pudding.sharera.com/blog/BlogTopic/53965.htm</guid>
      <author>chendz0526@126.com</author>
   <source url="http://pudding.sharera.com/rss/rss20.xml">果冻</source>
  </item>
    <item>
   <title>PNG file format decoder</title>
   <description><![CDATA[<br />
<font face="新宋体"><font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.awt.Graphics;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.awt.Insets;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.awt.image.BufferedImage;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.awt.image.ColorModel;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.awt.image.DataBuffer;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.awt.image.DataBufferByte;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.awt.image.IndexColorModel;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.awt.image.Raster;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.awt.image.WritableRaster;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.io.ByteArrayInputStream;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.io.ByteArrayOutputStream;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.io.DataInputStream;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.io.EOFException;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.io.IOException;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.io.InputStream;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.io.UnsupportedEncodingException;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.util.zip.CRC32;</font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">java.util.zip.InflaterInputStream;</font><br />
<font color="#ffffff"></font><br />
<font color="#7f0055"><strong>import&nbsp;</strong></font><font color="#000000">javax.swing.JFrame;</font><br />
<font color="#ffffff"></font><br />
<font color="#7f0055"><strong>public&nbsp;class&nbsp;</strong></font><font color="#000000">PNGDecoder&nbsp;</font><font color="#000000">{</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;static&nbsp;</strong></font><font color="#7f0055"><strong>void&nbsp;</strong></font><font color="#000000">main</font><font color="#000000">(</font><font color="#000000">String</font><font color="#000000">[]&nbsp;</font><font color="#000000">args</font><font color="#000000">)&nbsp;</font><font color="#7f0055"><strong>throws&nbsp;</strong></font><font color="#000000">Exception&nbsp;</font><font color="#000000">{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">String&nbsp;name&nbsp;=&nbsp;</font><font color="#2a00ff">&quot;logo.png&quot;</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>if&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">args.length&nbsp;&gt;&nbsp;</font><font color="#990000">0</font><font color="#000000">)</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">name&nbsp;=&nbsp;args</font><font color="#000000">[</font><font color="#990000">0</font><font color="#000000">]</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">InputStream&nbsp;in&nbsp;=&nbsp;PNGDecoder.</font><font color="#7f0055"><strong>class</strong></font><font color="#000000">.getResourceAsStream</font><font color="#000000">(</font><font color="#000000">name</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>final&nbsp;</strong></font><font color="#000000">BufferedImage&nbsp;image&nbsp;=&nbsp;PNGDecoder.decode</font><font color="#000000">(</font><font color="#000000">in</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">in.close</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">JFrame&nbsp;f&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#000000">JFrame</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#7f0055"><strong>void&nbsp;</strong></font><font color="#000000">paint</font><font color="#000000">(</font><font color="#000000">Graphics&nbsp;g</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">Insets&nbsp;insets&nbsp;=&nbsp;getInsets</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">g.drawImage</font><font color="#000000">(</font><font color="#000000">image,&nbsp;insets.left,&nbsp;insets.top,&nbsp;</font><font color="#7f0055"><strong>null</strong></font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">f.setVisible</font><font color="#000000">(</font><font color="#7f0055"><strong>true</strong></font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">Insets&nbsp;insets&nbsp;=&nbsp;f.getInsets</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">f.setSize</font><font color="#000000">(</font><font color="#000000">image.getWidth</font><font color="#000000">()&nbsp;</font><font color="#000000">+&nbsp;insets.left&nbsp;+&nbsp;insets.right,&nbsp;image</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">.getHeight</font><font color="#000000">()</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">+&nbsp;insets.top&nbsp;+&nbsp;insets.bottom</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;static&nbsp;</strong></font><font color="#000000">BufferedImage&nbsp;decode</font><font color="#000000">(</font><font color="#000000">InputStream&nbsp;in</font><font color="#000000">)&nbsp;</font><font color="#7f0055"><strong>throws&nbsp;</strong></font><font color="#000000">IOException&nbsp;</font><font color="#000000">{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">DataInputStream&nbsp;dataIn&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#000000">DataInputStream</font><font color="#000000">(</font><font color="#000000">in</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">readSignature</font><font color="#000000">(</font><font color="#000000">dataIn</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">PNGData&nbsp;chunks&nbsp;=&nbsp;readChunks</font><font color="#000000">(</font><font color="#000000">dataIn</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>long&nbsp;</strong></font><font color="#000000">widthLong&nbsp;=&nbsp;chunks.getWidth</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>long&nbsp;</strong></font><font color="#000000">heightLong&nbsp;=&nbsp;chunks.getHeight</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>if&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">widthLong&nbsp;&gt;&nbsp;Integer.MAX_VALUE&nbsp;||&nbsp;heightLong&nbsp;&gt;&nbsp;Integer.MAX_VALUE</font><font color="#000000">)</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>throw&nbsp;new&nbsp;</strong></font><font color="#000000">IOException</font><font color="#000000">(</font><font color="#2a00ff">&quot;That&nbsp;image&nbsp;is&nbsp;too&nbsp;wide&nbsp;or&nbsp;tall.&quot;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">width&nbsp;=&nbsp;</font><font color="#000000">(</font><font color="#7f0055"><strong>int</strong></font><font color="#000000">)&nbsp;</font><font color="#000000">widthLong;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">height&nbsp;=&nbsp;</font><font color="#000000">(</font><font color="#7f0055"><strong>int</strong></font><font color="#000000">)&nbsp;</font><font color="#000000">heightLong;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">ColorModel&nbsp;cm&nbsp;=&nbsp;chunks.getColorModel</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">WritableRaster&nbsp;raster&nbsp;=&nbsp;chunks.getRaster</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">BufferedImage&nbsp;image&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#000000">BufferedImage</font><font color="#000000">(</font><font color="#000000">cm,&nbsp;raster,&nbsp;false,&nbsp;</font><font color="#7f0055"><strong>null</strong></font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">image;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>protected&nbsp;static&nbsp;</strong></font><font color="#7f0055"><strong>void&nbsp;</strong></font><font color="#000000">readSignature</font><font color="#000000">(</font><font color="#000000">DataInputStream&nbsp;in</font><font color="#000000">)&nbsp;</font><font color="#7f0055"><strong>throws&nbsp;</strong></font><font color="#000000">IOException&nbsp;</font><font color="#000000">{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>long&nbsp;</strong></font><font color="#000000">signature&nbsp;=&nbsp;in.readLong</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>if&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">signature&nbsp;!=&nbsp;</font><font color="#990000">0x89504e470d0a1a0aL</font><font color="#000000">)</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>throw&nbsp;new&nbsp;</strong></font><font color="#000000">IOException</font><font color="#000000">(</font><font color="#2a00ff">&quot;PNG&nbsp;signature&nbsp;not&nbsp;found!&quot;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>protected&nbsp;static&nbsp;</strong></font><font color="#000000">PNGData&nbsp;readChunks</font><font color="#000000">(</font><font color="#000000">DataInputStream&nbsp;in</font><font color="#000000">)&nbsp;</font><font color="#7f0055"><strong>throws&nbsp;</strong></font><font color="#000000">IOException&nbsp;</font><font color="#000000">{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">PNGData&nbsp;chunks&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#000000">PNGData</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>boolean&nbsp;</strong></font><font color="#000000">trucking&nbsp;=&nbsp;</font><font color="#7f0055"><strong>true</strong></font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>while&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">trucking</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>try&nbsp;</strong></font><font color="#000000">{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//&nbsp;Read&nbsp;the&nbsp;length.</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">length&nbsp;=&nbsp;in.readInt</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>if&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">length&nbsp;&lt;&nbsp;</font><font color="#990000">0</font><font color="#000000">)</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>throw&nbsp;new&nbsp;</strong></font><font color="#000000">IOException</font><font color="#000000">(</font><font color="#2a00ff">&quot;Sorry,&nbsp;that&nbsp;file&nbsp;is&nbsp;too&nbsp;long.&quot;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//&nbsp;Read&nbsp;the&nbsp;type.</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">typeBytes&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[</font><font color="#990000">4</font><font color="#000000">]</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">in.readFully</font><font color="#000000">(</font><font color="#000000">typeBytes</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//&nbsp;Read&nbsp;the&nbsp;data.</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">data&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[</font><font color="#000000">length</font><font color="#000000">]</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">in.readFully</font><font color="#000000">(</font><font color="#000000">data</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//&nbsp;Read&nbsp;the&nbsp;CRC.</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>long&nbsp;</strong></font><font color="#000000">crc&nbsp;=&nbsp;in.readInt</font><font color="#000000">()&nbsp;</font><font color="#000000">&amp;&nbsp;</font><font color="#990000">0x00000000ffffffffL</font><font color="#000000">;&nbsp;</font><font color="#3f7f5f">//&nbsp;Make&nbsp;it</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//&nbsp;unsigned.</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>if&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">verifyCRC</font><font color="#000000">(</font><font color="#000000">typeBytes,&nbsp;data,&nbsp;crc</font><font color="#000000">)&nbsp;</font><font color="#000000">==&nbsp;</font><font color="#7f0055"><strong>false</strong></font><font color="#000000">)</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>throw&nbsp;new&nbsp;</strong></font><font color="#000000">IOException</font><font color="#000000">(</font><font color="#2a00ff">&quot;That&nbsp;file&nbsp;appears&nbsp;to&nbsp;be&nbsp;corrupted.&quot;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">PNGChunk&nbsp;chunk&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#000000">PNGChunk</font><font color="#000000">(</font><font color="#000000">typeBytes,&nbsp;data</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">chunks.add</font><font color="#000000">(</font><font color="#000000">chunk</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}&nbsp;</font><font color="#7f0055"><strong>catch&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">EOFException&nbsp;eofe</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">trucking&nbsp;=&nbsp;</font><font color="#7f0055"><strong>false</strong></font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">chunks;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>protected&nbsp;static&nbsp;</strong></font><font color="#7f0055"><strong>boolean&nbsp;</strong></font><font color="#000000">verifyCRC</font><font color="#000000">(</font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">typeBytes,&nbsp;</font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">data,&nbsp;</font><font color="#7f0055"><strong>long&nbsp;</strong></font><font color="#000000">crc</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">CRC32&nbsp;crc32&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#000000">CRC32</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">crc32.</font><font color="#7f0055"><strong>update</strong></font><font color="#000000">(</font><font color="#000000">typeBytes</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">crc32.</font><font color="#7f0055"><strong>update</strong></font><font color="#000000">(</font><font color="#000000">data</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>long&nbsp;</strong></font><font color="#000000">calculated&nbsp;=&nbsp;crc32.getValue</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">calculated&nbsp;==&nbsp;crc</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#7f0055"><strong>class&nbsp;</strong></font><font color="#000000">PNGData&nbsp;</font><font color="#000000">{</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>private&nbsp;</strong></font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">mNumberOfChunks;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>private&nbsp;</strong></font><font color="#000000">PNGChunk</font><font color="#000000">[]&nbsp;</font><font color="#000000">mChunks;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#000000">PNGData</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">mNumberOfChunks&nbsp;=&nbsp;</font><font color="#990000">0</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">mChunks&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#000000">PNGChunk</font><font color="#000000">[</font><font color="#990000">10</font><font color="#000000">]</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#7f0055"><strong>void&nbsp;</strong></font><font color="#000000">add</font><font color="#000000">(</font><font color="#000000">PNGChunk&nbsp;chunk</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">mChunks</font><font color="#000000">[</font><font color="#000000">mNumberOfChunks++</font><font color="#000000">]&nbsp;</font><font color="#000000">=&nbsp;chunk;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>if&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">mNumberOfChunks&nbsp;&gt;=&nbsp;mChunks.length</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">PNGChunk</font><font color="#000000">[]&nbsp;</font><font color="#000000">largerArray&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#000000">PNGChunk</font><font color="#000000">[</font><font color="#000000">mChunks.length&nbsp;+&nbsp;</font><font color="#990000">10</font><font color="#000000">]</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">System.arraycopy</font><font color="#000000">(</font><font color="#000000">mChunks,&nbsp;</font><font color="#990000">0</font><font color="#000000">,&nbsp;largerArray,&nbsp;</font><font color="#990000">0</font><font color="#000000">,&nbsp;mChunks.length</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">mChunks&nbsp;=&nbsp;largerArray;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#7f0055"><strong>long&nbsp;</strong></font><font color="#000000">getWidth</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">getChunk</font><font color="#000000">(</font><font color="#2a00ff">&quot;IHDR&quot;</font><font color="#000000">)</font><font color="#000000">.getUnsignedInt</font><font color="#000000">(</font><font color="#990000">0</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#7f0055"><strong>long&nbsp;</strong></font><font color="#000000">getHeight</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">getChunk</font><font color="#000000">(</font><font color="#2a00ff">&quot;IHDR&quot;</font><font color="#000000">)</font><font color="#000000">.getUnsignedInt</font><font color="#000000">(</font><font color="#990000">4</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#7f0055"><strong>short&nbsp;</strong></font><font color="#000000">getBitsPerPixel</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">getChunk</font><font color="#000000">(</font><font color="#2a00ff">&quot;IHDR&quot;</font><font color="#000000">)</font><font color="#000000">.getUnsignedByte</font><font color="#000000">(</font><font color="#990000">8</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#7f0055"><strong>short&nbsp;</strong></font><font color="#000000">getColorType</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">getChunk</font><font color="#000000">(</font><font color="#2a00ff">&quot;IHDR&quot;</font><font color="#000000">)</font><font color="#000000">.getUnsignedByte</font><font color="#000000">(</font><font color="#990000">9</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#7f0055"><strong>short&nbsp;</strong></font><font color="#000000">getCompression</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">getChunk</font><font color="#000000">(</font><font color="#2a00ff">&quot;IHDR&quot;</font><font color="#000000">)</font><font color="#000000">.getUnsignedByte</font><font color="#000000">(</font><font color="#990000">10</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#7f0055"><strong>short&nbsp;</strong></font><font color="#000000">getFilter</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">getChunk</font><font color="#000000">(</font><font color="#2a00ff">&quot;IHDR&quot;</font><font color="#000000">)</font><font color="#000000">.getUnsignedByte</font><font color="#000000">(</font><font color="#990000">11</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#7f0055"><strong>short&nbsp;</strong></font><font color="#000000">getInterlace</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">getChunk</font><font color="#000000">(</font><font color="#2a00ff">&quot;IHDR&quot;</font><font color="#000000">)</font><font color="#000000">.getUnsignedByte</font><font color="#000000">(</font><font color="#990000">12</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#000000">ColorModel&nbsp;getColorModel</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>short&nbsp;</strong></font><font color="#000000">colorType&nbsp;=&nbsp;getColorType</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">bitsPerPixel&nbsp;=&nbsp;getBitsPerPixel</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>if&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">colorType&nbsp;==&nbsp;</font><font color="#990000">3</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">paletteData&nbsp;=&nbsp;getChunk</font><font color="#000000">(</font><font color="#2a00ff">&quot;PLTE&quot;</font><font color="#000000">)</font><font color="#000000">.getData</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">paletteLength&nbsp;=&nbsp;paletteData.length&nbsp;/&nbsp;</font><font color="#990000">3</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;new&nbsp;</strong></font><font color="#000000">IndexColorModel</font><font color="#000000">(</font><font color="#000000">bitsPerPixel,&nbsp;paletteLength,</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">paletteData,&nbsp;</font><font color="#990000">0</font><font color="#000000">,&nbsp;</font><font color="#7f0055"><strong>false</strong></font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#2a00ff">&quot;Unsupported&nbsp;color&nbsp;type:&nbsp;&quot;&nbsp;</font><font color="#000000">+&nbsp;colorType</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;null</strong></font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#000000">WritableRaster&nbsp;getRaster</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">width&nbsp;=&nbsp;</font><font color="#000000">(</font><font color="#7f0055"><strong>int</strong></font><font color="#000000">)&nbsp;</font><font color="#000000">getWidth</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">height&nbsp;=&nbsp;</font><font color="#000000">(</font><font color="#7f0055"><strong>int</strong></font><font color="#000000">)&nbsp;</font><font color="#000000">getHeight</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">bitsPerPixel&nbsp;=&nbsp;getBitsPerPixel</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>short&nbsp;</strong></font><font color="#000000">colorType&nbsp;=&nbsp;getColorType</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>if&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">colorType&nbsp;==&nbsp;</font><font color="#990000">3</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">imageData&nbsp;=&nbsp;getImageData</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">DataBuffer&nbsp;db&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#000000">DataBufferByte</font><font color="#000000">(</font><font color="#000000">imageData,&nbsp;imageData.length</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">WritableRaster&nbsp;raster&nbsp;=&nbsp;Raster.createPackedRaster</font><font color="#000000">(</font><font color="#000000">db,&nbsp;width,</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">height,&nbsp;bitsPerPixel,&nbsp;</font><font color="#7f0055"><strong>null</strong></font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">raster;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}&nbsp;</font><font color="#7f0055"><strong>else</strong></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#2a00ff">&quot;Unsupported&nbsp;color&nbsp;type!&quot;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;null</strong></font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">getImageData</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>try&nbsp;</strong></font><font color="#000000">{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">ByteArrayOutputStream&nbsp;out&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#000000">ByteArrayOutputStream</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//&nbsp;Write&nbsp;all&nbsp;the&nbsp;IDAT&nbsp;data&nbsp;into&nbsp;the&nbsp;array.</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>for&nbsp;</strong></font><font color="#000000">(</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">i&nbsp;=&nbsp;</font><font color="#990000">0</font><font color="#000000">;&nbsp;i&nbsp;&lt;&nbsp;mNumberOfChunks;&nbsp;i++</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">PNGChunk&nbsp;chunk&nbsp;=&nbsp;mChunks</font><font color="#000000">[</font><font color="#000000">i</font><font color="#000000">]</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>if&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">chunk.getTypeString</font><font color="#000000">()</font><font color="#000000">.equals</font><font color="#000000">(</font><font color="#2a00ff">&quot;IDAT&quot;</font><font color="#000000">))&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">out.write</font><font color="#000000">(</font><font color="#000000">chunk.getData</font><font color="#000000">())</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">out.flush</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//&nbsp;Now&nbsp;deflate&nbsp;the&nbsp;data.</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">InflaterInputStream&nbsp;in&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#000000">InflaterInputStream</font><font color="#000000">(</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#000000">ByteArrayInputStream</font><font color="#000000">(</font><font color="#000000">out.toByteArray</font><font color="#000000">()))</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">ByteArrayOutputStream&nbsp;inflatedOut&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#000000">ByteArrayOutputStream</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">readLength;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">block&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[</font><font color="#990000">8192</font><font color="#000000">]</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>while&nbsp;</strong></font><font color="#000000">((</font><font color="#000000">readLength&nbsp;=&nbsp;in.read</font><font color="#000000">(</font><font color="#000000">block</font><font color="#000000">))&nbsp;</font><font color="#000000">!=&nbsp;-</font><font color="#990000">1</font><font color="#000000">)</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">inflatedOut.write</font><font color="#000000">(</font><font color="#000000">block,&nbsp;</font><font color="#990000">0</font><font color="#000000">,&nbsp;readLength</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">inflatedOut.flush</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">imageData&nbsp;=&nbsp;inflatedOut.toByteArray</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//&nbsp;Compute&nbsp;the&nbsp;real&nbsp;length.</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">width&nbsp;=&nbsp;</font><font color="#000000">(</font><font color="#7f0055"><strong>int</strong></font><font color="#000000">)&nbsp;</font><font color="#000000">getWidth</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">height&nbsp;=&nbsp;</font><font color="#000000">(</font><font color="#7f0055"><strong>int</strong></font><font color="#000000">)&nbsp;</font><font color="#000000">getHeight</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">bitsPerPixel&nbsp;=&nbsp;getBitsPerPixel</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">length&nbsp;=&nbsp;width&nbsp;*&nbsp;height&nbsp;*&nbsp;bitsPerPixel&nbsp;/&nbsp;</font><font color="#990000">8</font><font color="#000000">;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">prunedData&nbsp;=&nbsp;</font><font color="#7f0055"><strong>new&nbsp;</strong></font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[</font><font color="#000000">length</font><font color="#000000">]</font><font color="#000000">;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#3f7f5f">//&nbsp;We&nbsp;can&nbsp;only&nbsp;deal&nbsp;with&nbsp;non-interlaced&nbsp;images.</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>if&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">getInterlace</font><font color="#000000">()&nbsp;</font><font color="#000000">==&nbsp;</font><font color="#990000">0</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">index&nbsp;=&nbsp;</font><font color="#990000">0</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>for&nbsp;</strong></font><font color="#000000">(</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">i&nbsp;=&nbsp;</font><font color="#990000">0</font><font color="#000000">;&nbsp;i&nbsp;&lt;&nbsp;length;&nbsp;i++</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>if&nbsp;</strong></font><font color="#000000">((</font><font color="#000000">i&nbsp;*&nbsp;</font><font color="#990000">8&nbsp;</font><font color="#000000">/&nbsp;bitsPerPixel</font><font color="#000000">)&nbsp;</font><font color="#000000">%&nbsp;width&nbsp;==&nbsp;</font><font color="#990000">0</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">index++;&nbsp;</font><font color="#3f7f5f">//&nbsp;Skip&nbsp;the&nbsp;filter&nbsp;byte.</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">prunedData</font><font color="#000000">[</font><font color="#000000">i</font><font color="#000000">]&nbsp;</font><font color="#000000">=&nbsp;imageData</font><font color="#000000">[</font><font color="#000000">index++</font><font color="#000000">]</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}&nbsp;</font><font color="#7f0055"><strong>else</strong></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#2a00ff">&quot;Couldn't&nbsp;undo&nbsp;interlacing.&quot;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">prunedData;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}&nbsp;</font><font color="#7f0055"><strong>catch&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">IOException&nbsp;ioe</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;null</strong></font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#000000">PNGChunk&nbsp;getChunk</font><font color="#000000">(</font><font color="#000000">String&nbsp;type</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>for&nbsp;</strong></font><font color="#000000">(</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">i&nbsp;=&nbsp;</font><font color="#990000">0</font><font color="#000000">;&nbsp;i&nbsp;&lt;&nbsp;mNumberOfChunks;&nbsp;i++</font><font color="#000000">)</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>if&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">mChunks</font><font color="#000000">[</font><font color="#000000">i</font><font color="#000000">]</font><font color="#000000">.getTypeString</font><font color="#000000">()</font><font color="#000000">.equals</font><font color="#000000">(</font><font color="#000000">type</font><font color="#000000">))</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">mChunks</font><font color="#000000">[</font><font color="#000000">i</font><font color="#000000">]</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;null</strong></font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#7f0055"><strong>class&nbsp;</strong></font><font color="#000000">PNGChunk&nbsp;</font><font color="#000000">{</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>private&nbsp;</strong></font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">mType;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>private&nbsp;</strong></font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">mData;</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#000000">PNGChunk</font><font color="#000000">(</font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">type,&nbsp;</font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">data</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">mType&nbsp;=&nbsp;type;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">mData&nbsp;=&nbsp;data;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#000000">String&nbsp;getTypeString</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>try&nbsp;</strong></font><font color="#000000">{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;new&nbsp;</strong></font><font color="#000000">String</font><font color="#000000">(</font><font color="#000000">mType,&nbsp;</font><font color="#2a00ff">&quot;UTF8&quot;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}&nbsp;</font><font color="#7f0055"><strong>catch&nbsp;</strong></font><font color="#000000">(</font><font color="#000000">UnsupportedEncodingException&nbsp;uee</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#2a00ff">&quot;&quot;</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#7f0055"><strong>byte</strong></font><font color="#000000">[]&nbsp;</font><font color="#000000">getData</font><font color="#000000">()&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">mData;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#7f0055"><strong>long&nbsp;</strong></font><font color="#000000">getUnsignedInt</font><font color="#000000">(</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">offset</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>long&nbsp;</strong></font><font color="#000000">value&nbsp;=&nbsp;</font><font color="#990000">0</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>for&nbsp;</strong></font><font color="#000000">(</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">i&nbsp;=&nbsp;</font><font color="#990000">0</font><font color="#000000">;&nbsp;i&nbsp;&lt;&nbsp;</font><font color="#990000">4</font><font color="#000000">;&nbsp;i++</font><font color="#000000">)</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">value&nbsp;+=&nbsp;</font><font color="#000000">(</font><font color="#000000">mData</font><font color="#000000">[</font><font color="#000000">offset&nbsp;+&nbsp;i</font><font color="#000000">]&nbsp;</font><font color="#000000">&amp;&nbsp;</font><font color="#990000">0xff</font><font color="#000000">)&nbsp;</font><font color="#000000">&lt;&lt;&nbsp;</font><font color="#000000">((</font><font color="#990000">3&nbsp;</font><font color="#000000">-&nbsp;i</font><font color="#000000">)&nbsp;</font><font color="#000000">*&nbsp;</font><font color="#990000">8</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">value;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><strong>public&nbsp;</strong></font><font color="#7f0055"><strong>short&nbsp;</strong></font><font color="#000000">getUnsignedByte</font><font color="#000000">(</font><font color="#7f0055"><strong>int&nbsp;</strong></font><font color="#000000">offset</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><strong>return&nbsp;</strong></font><font color="#000000">(</font><font color="#7f0055"><strong>short</strong></font><font color="#000000">)&nbsp;(</font><font color="#000000">mData</font><font color="#000000">[</font><font color="#000000">offset</font><font color="#000000">]&nbsp;</font><font color="#000000">&amp;&nbsp;</font><font color="#990000">0x00ff</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font><br />
<font color="#000000">}</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></font>]]></description>
   <link>http://pudding.sharera.com/blog/BlogTopic/53964.htm</link>
   <comments>http://pudding.sharera.com/blog/BlogTopic/53964.htm</comments>
   <guid>http://pudding.sharera.com/blog/BlogTopic/53964.htm</guid>
      <author>chendz0526@126.com</author>
   <source url="http://pudding.sharera.com/rss/rss20.xml">果冻</source>
  </item>
    <item>
   <title>J2ME Bitmap encoder</title>
   <description><![CDATA[<ol>
    <li><span><span class="comment">/* </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;*&nbsp;Copyright&nbsp;ThinkTank&nbsp;Mathematics&nbsp;Limited&nbsp;2007 </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;* </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;*&nbsp;This&nbsp;file&nbsp;is&nbsp;free&nbsp;software:&nbsp;you&nbsp;can&nbsp;redistribute&nbsp;it&nbsp;and/or&nbsp;modify&nbsp;it&nbsp;under&nbsp;the&nbsp;terms&nbsp;of </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;*&nbsp;the&nbsp;GNU&nbsp;Lesser&nbsp;General&nbsp;Public&nbsp;License&nbsp;as&nbsp;published&nbsp;by&nbsp;the&nbsp;Free&nbsp;Software&nbsp;Foundation,&nbsp;either </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;*&nbsp;version&nbsp;3&nbsp;of&nbsp;the&nbsp;License,&nbsp;or&nbsp;(at&nbsp;your&nbsp;option)&nbsp;any&nbsp;later&nbsp;version. </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;* </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;*&nbsp;This&nbsp;file&nbsp;is&nbsp;distributed&nbsp;in&nbsp;the&nbsp;hope&nbsp;that&nbsp;it&nbsp;will&nbsp;be&nbsp;useful,&nbsp;but&nbsp;WITHOUT&nbsp;ANY&nbsp;WARRANTY; </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;*&nbsp;without&nbsp;even&nbsp;the&nbsp;implied&nbsp;warranty&nbsp;of&nbsp;MERCHANTABILITY&nbsp;or&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;*&nbsp;PURPOSE.&nbsp;See&nbsp;the&nbsp;GNU&nbsp;Lesser&nbsp;General&nbsp;Public&nbsp;License&nbsp;for&nbsp;more&nbsp;details. </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;* </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;*&nbsp;You&nbsp;should&nbsp;have&nbsp;received&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;GNU&nbsp;Lesser&nbsp;General&nbsp;Public&nbsp;License&nbsp;along&nbsp;with&nbsp;this&nbsp;file. </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;*&nbsp;If&nbsp;not,&nbsp;see&nbsp;&lt;http://www.gnu.org/licenses/&gt;. </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;*/</span><span>&nbsp;&nbsp;</span></span></li>
    <li><span></span><span class="keyword">package</span><span>&nbsp;thinktank.&lt;SPAN&nbsp;</span><span class="keyword">class</span><span>=hilite1&gt;j2me&lt;/SPAN&gt;; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp; &nbsp;&nbsp;</span></li>
    <li><span></span><span class="keyword">import</span><span>&nbsp;java.io.ByteArrayOutputStream; &nbsp;&nbsp;</span></li>
    <li><span></span><span class="keyword">import</span><span>&nbsp;java.io.DataOutputStream; &nbsp;&nbsp;</span></li>
    <li><span></span><span class="keyword">import</span><span>&nbsp;java.io.IOException; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp; &nbsp;&nbsp;</span></li>
    <li><span></span><span class="keyword">import</span><span>&nbsp;javax.microedition.lcdui.Image; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp; &nbsp;&nbsp;</span></li>
    <li><span></span><span class="comment">/** </span>&nbsp;</li>
    <li><span><span class="comment">&nbsp;*&nbsp;@author&nbsp;Samuel&nbsp;Halliday,&nbsp;ThinkTank&nbsp;Mathematics&nbsp;Limited </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;*/</span><span>&nbsp;&nbsp;</span></span></li>
    <li><span></span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">final</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;BMPGenerator&nbsp;{ &nbsp;&nbsp;</span></li>
    <li><span>&nbsp; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">/** </span>&nbsp;</li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;image </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@throws&nbsp;IOException </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@see&nbsp;{@link&nbsp;#encodeBMP(int[],&nbsp;int,&nbsp;int)} </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span>&nbsp;&nbsp;</span></span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">static</span><span>&nbsp;</span><span class="keyword">byte</span><span>[]&nbsp;encodeBMP(Image&nbsp;image)&nbsp;</span><span class="keyword">throws</span><span>&nbsp;IOException&nbsp;{ &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;width&nbsp;=&nbsp;image.getWidth(); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;height&nbsp;=&nbsp;image.getHeight(); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>[]&nbsp;rgb&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;</span><span class="keyword">int</span><span>[height&nbsp;*&nbsp;width]; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image.getRGB(rgb,&nbsp;</span><span class="number"><font color="#c00000">0</font></span><span>,&nbsp;width,&nbsp;</span><span class="number"><font color="#c00000">0</font></span><span>,&nbsp;</span><span class="number"><font color="#c00000">0</font></span><span>,&nbsp;width,&nbsp;height); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">return</span><span>&nbsp;encodeBMP(rgb,&nbsp;width,&nbsp;height); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span></li>
    <li><span>&nbsp; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">/** </span>&nbsp;</li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;A&nbsp;self-contained&nbsp;BMP&nbsp;generator,&nbsp;which&nbsp;takes&nbsp;a&nbsp;byte&nbsp;array&nbsp;(without&nbsp;any&nbsp;unusual </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;offsets)&nbsp;extracted&nbsp;from&nbsp;an&nbsp;{@link&nbsp;Image}.&nbsp;The&nbsp;target&nbsp;platform&nbsp;is&nbsp;&lt;SPAN&nbsp;class=hilite1&gt;J2ME&lt;/SPAN&gt;.&nbsp;You&nbsp;may </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;wish&nbsp;to&nbsp;use&nbsp;the&nbsp;convenience&nbsp;method&nbsp;{@link&nbsp;#encodeBMP(Image)}&nbsp;instead&nbsp;of&nbsp;this. </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&lt;p&gt; </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;A&nbsp;BMP&nbsp;file&nbsp;consists&nbsp;of&nbsp;4&nbsp;parts:- </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&lt;ul&gt; </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&lt;li&gt;header&lt;/li&gt; </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&lt;li&gt;information&nbsp;header&lt;/li&gt; </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&lt;li&gt;optional&nbsp;palette&lt;/li&gt; </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&lt;li&gt;image&nbsp;data&lt;/li&gt; </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&lt;/ul&gt; </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;At&nbsp;this&nbsp;time&nbsp;only&nbsp;24&nbsp;bit&nbsp;uncompressed&nbsp;BMPs&nbsp;with&nbsp;Windows&nbsp;V3&nbsp;headers&nbsp;can&nbsp;be&nbsp;created. </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Future&nbsp;releases&nbsp;may&nbsp;become&nbsp;much&nbsp;more&nbsp;space-efficient,&nbsp;but&nbsp;will&nbsp;most&nbsp;likely&nbsp;be </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;ditched&nbsp;in&nbsp;favour&nbsp;of&nbsp;a&nbsp;&lt;SPAN&nbsp;class=hilite2&gt;PNG&lt;/SPAN&gt;&nbsp;generator. </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp; </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;rgb </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;width </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;height </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@throws&nbsp;IOException </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@see&nbsp;http://en.wikipedia.org/wiki/Windows_bitmap </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span>&nbsp;&nbsp;</span></span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">static</span><span>&nbsp;</span><span class="keyword">byte</span><span>[]&nbsp;encodeBMP(</span><span class="keyword">int</span><span>[]&nbsp;rgb,&nbsp;</span><span class="keyword">int</span><span>&nbsp;width,&nbsp;</span><span class="keyword">int</span><span>&nbsp;height) &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">throws</span><span>&nbsp;IOException&nbsp;{ &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;pad&nbsp;=&nbsp;(</span><span class="number"><font color="#c00000">4</font></span><span>&nbsp;-&nbsp;(width&nbsp;%&nbsp;</span><span class="number"><font color="#c00000">4</font></span><span>))&nbsp;%&nbsp;</span><span class="number"><font color="#c00000">4</font></span><span>; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;BMP&nbsp;file&nbsp;in&nbsp;bytes </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;size&nbsp;=&nbsp;</span><span class="number"><font color="#c00000">14</font></span><span>&nbsp;+&nbsp;</span><span class="number"><font color="#c00000">40</font></span><span>&nbsp;+&nbsp;height&nbsp;*&nbsp;(pad&nbsp;+&nbsp;width&nbsp;*&nbsp;</span><span class="number"><font color="#c00000">3</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ByteArrayOutputStream&nbsp;bytes&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;ByteArrayOutputStream(size); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataOutputStream&nbsp;stream&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;DataOutputStream(bytes); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;HEADER </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;the&nbsp;magic&nbsp;number&nbsp;used&nbsp;to&nbsp;identify&nbsp;the&nbsp;BMP&nbsp;file:&nbsp;0x42&nbsp;0x4D </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeByte(</span><span class="number"><font color="#c00000">0x42</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeByte(</span><span class="number"><font color="#c00000">0x4D</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeInt(swapEndian(size)); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;reserved </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeInt(</span><span class="number"><font color="#c00000">0</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;the&nbsp;offset,&nbsp;i.e.&nbsp;starting&nbsp;address&nbsp;of&nbsp;the&nbsp;bitmap&nbsp;data </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeInt(swapEndian(</span><span class="number"><font color="#c00000">14</font></span><span>&nbsp;+&nbsp;</span><span class="number"><font color="#c00000">40</font></span><span>)); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;INFORMATION&nbsp;HEADER&nbsp;(Windows&nbsp;V3&nbsp;header) </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;the&nbsp;size&nbsp;of&nbsp;this&nbsp;header&nbsp;(40&nbsp;bytes) </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeInt(swapEndian(</span><span class="number"><font color="#c00000">40</font></span><span>)); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;the&nbsp;bitmap&nbsp;width&nbsp;in&nbsp;pixels&nbsp;(signed&nbsp;integer). </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeInt(swapEndian(width)); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;the&nbsp;bitmap&nbsp;height&nbsp;in&nbsp;pixels&nbsp;(signed&nbsp;integer). </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeInt(swapEndian(height)); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;the&nbsp;number&nbsp;of&nbsp;colour&nbsp;planes&nbsp;being&nbsp;used.&nbsp;Must&nbsp;be&nbsp;set&nbsp;to&nbsp;1. </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeShort(swapEndian((</span><span class="keyword">short</span><span>)&nbsp;</span><span class="number"><font color="#c00000">1</font></span><span>)); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;the&nbsp;number&nbsp;of&nbsp;bits&nbsp;per&nbsp;pixel,&nbsp;which&nbsp;is&nbsp;the&nbsp;colour&nbsp;depth&nbsp;of&nbsp;the&nbsp;image. </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeShort(swapEndian((</span><span class="keyword">short</span><span>)&nbsp;</span><span class="number"><font color="#c00000">24</font></span><span>)); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;the&nbsp;compression&nbsp;method&nbsp;being&nbsp;used. </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeInt(</span><span class="number"><font color="#c00000">0</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;image&nbsp;size.&nbsp;The&nbsp;size&nbsp;of&nbsp;the&nbsp;raw&nbsp;bitmap&nbsp;data.&nbsp;0&nbsp;is&nbsp;valid&nbsp;for&nbsp;uncompressed. </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeInt(</span><span class="number"><font color="#c00000">0</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;the&nbsp;horizontal&nbsp;resolution&nbsp;of&nbsp;the&nbsp;image.&nbsp;(pixel&nbsp;per&nbsp;meter,&nbsp;signed&nbsp;integer) </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeInt(</span><span class="number"><font color="#c00000">0</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;the&nbsp;vertical&nbsp;resolution&nbsp;of&nbsp;the&nbsp;image.&nbsp;(pixel&nbsp;per&nbsp;meter,&nbsp;signed&nbsp;integer) </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeInt(</span><span class="number"><font color="#c00000">0</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;the&nbsp;number&nbsp;of&nbsp;colours&nbsp;in&nbsp;the&nbsp;colour&nbsp;palette,&nbsp;or&nbsp;0&nbsp;to&nbsp;default&nbsp;to&nbsp;2n. </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeInt(</span><span class="number"><font color="#c00000">0</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;the&nbsp;number&nbsp;of&nbsp;important&nbsp;colours&nbsp;used,&nbsp;or&nbsp;0&nbsp;when&nbsp;every&nbsp;colour&nbsp;is&nbsp;important; </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;generally&nbsp;ignored. </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeInt(</span><span class="number"><font color="#c00000">0</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;PALETTE </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;none&nbsp;for&nbsp;24&nbsp;bit&nbsp;depth </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;IMAGE&nbsp;DATA </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;starting&nbsp;in&nbsp;the&nbsp;bottom&nbsp;left,&nbsp;working&nbsp;right&nbsp;and&nbsp;then&nbsp;up </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;a&nbsp;series&nbsp;of&nbsp;3&nbsp;bytes&nbsp;per&nbsp;pixel&nbsp;in&nbsp;the&nbsp;order&nbsp;B&nbsp;G&nbsp;R. </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">for</span><span>&nbsp;(</span><span class="keyword">int</span><span>&nbsp;j&nbsp;=&nbsp;height&nbsp;-&nbsp;</span><span class="number"><font color="#c00000">1</font></span><span>;&nbsp;j&nbsp;&gt;=&nbsp;</span><span class="number"><font color="#c00000">0</font></span><span>;&nbsp;j--)&nbsp;{ &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">for</span><span>&nbsp;(</span><span class="keyword">int</span><span>&nbsp;i&nbsp;=&nbsp;</span><span class="number"><font color="#c00000">0</font></span><span>;&nbsp;i&nbsp;&lt;&nbsp;width;&nbsp;i++)&nbsp;{ &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;val&nbsp;=&nbsp;rgb[i&nbsp;+&nbsp;width&nbsp;*&nbsp;j]; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeByte(val&nbsp;&amp;&nbsp;</span><span class="number"><font color="#c00000">0x000000FF</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeByte((val&nbsp;&gt;&gt;&gt;&nbsp;</span><span class="number"><font color="#c00000">8</font></span><span>&nbsp;)&nbsp;&amp;&nbsp;</span><span class="number"><font color="#c00000">0x000000FF</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeByte((val&nbsp;&gt;&gt;&gt;&nbsp;</span><span class="number"><font color="#c00000">16</font></span><span>)&nbsp;&amp;&nbsp;</span><span class="number"><font color="#c00000">0x000000FF</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;number&nbsp;of&nbsp;bytes&nbsp;in&nbsp;each&nbsp;row&nbsp;must&nbsp;be&nbsp;padded&nbsp;to&nbsp;multiple&nbsp;of&nbsp;4 </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">for</span><span>&nbsp;(</span><span class="keyword">int</span><span>&nbsp;i&nbsp;=&nbsp;</span><span class="number"><font color="#c00000">0</font></span><span>;&nbsp;i&nbsp;&lt;&nbsp;pad;&nbsp;i++)&nbsp;{ &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream.writeByte(</span><span class="number"><font color="#c00000">0</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">byte</span><span>[]&nbsp;out&nbsp;=&nbsp;bytes.toByteArray(); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bytes.close(); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;quick&nbsp;consistency&nbsp;check </span><span>&nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">if</span><span>&nbsp;(out.length&nbsp;!=&nbsp;size) &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">throw</span><span>&nbsp;</span><span class="keyword">new</span><span>&nbsp;RuntimeException(</span><span class="string">&quot;bad&nbsp;math&quot;</span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">return</span><span>&nbsp;out; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span></li>
    <li><span>&nbsp; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">/** </span>&nbsp;</li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Swap&nbsp;the&nbsp;Endian-ness&nbsp;of&nbsp;a&nbsp;32&nbsp;bit&nbsp;integer. </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp; </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;value </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span>&nbsp;&nbsp;</span></span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">private</span><span>&nbsp;</span><span class="keyword">static</span><span>&nbsp;</span><span class="keyword">int</span><span>&nbsp;swapEndian(</span><span class="keyword">int</span><span>&nbsp;value)&nbsp;{ &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;b1&nbsp;=&nbsp;value&nbsp;&amp;&nbsp;</span><span class="number"><font color="#c00000">0xff</font></span><span>; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;b2&nbsp;=&nbsp;(value&nbsp;&gt;&gt;&nbsp;</span><span class="number"><font color="#c00000">8</font></span><span>&nbsp;)&nbsp;&amp;&nbsp;</span><span class="number"><font color="#c00000">0xff</font></span><span>; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;b3&nbsp;=&nbsp;(value&nbsp;&gt;&gt;&nbsp;</span><span class="number"><font color="#c00000">16</font></span><span>)&nbsp;&amp;&nbsp;</span><span class="number"><font color="#c00000">0xff</font></span><span>; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;b4&nbsp;=&nbsp;(value&nbsp;&gt;&gt;&nbsp;</span><span class="number"><font color="#c00000">24</font></span><span>)&nbsp;&amp;&nbsp;</span><span class="number"><font color="#c00000">0xff</font></span><span>; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">return</span><span>&nbsp;b1&nbsp;&lt;&lt;&nbsp;</span><span class="number"><font color="#c00000">24</font></span><span>&nbsp;|&nbsp;b2&nbsp;&lt;&lt;&nbsp;</span><span class="number"><font color="#c00000">16</font></span><span>&nbsp;|&nbsp;b3&nbsp;&lt;&lt;&nbsp;</span><span class="number"><font color="#c00000">8</font></span><span>&nbsp;|&nbsp;b4&nbsp;&lt;&lt;&nbsp;</span><span class="number"><font color="#c00000">0</font></span><span>; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span></li>
    <li><span>&nbsp; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">/** </span>&nbsp;</li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Swap&nbsp;the&nbsp;Endian-ness&nbsp;of&nbsp;a&nbsp;16&nbsp;bit&nbsp;integer. </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp; </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;value </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return </span>&nbsp;</span></li>
    <li><span><span class="comment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span>&nbsp;&nbsp;</span></span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">private</span><span>&nbsp;</span><span class="keyword">static</span><span>&nbsp;</span><span class="keyword">short</span><span>&nbsp;swapEndian(</span><span class="keyword">short</span><span>&nbsp;value)&nbsp;{ &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;b1&nbsp;=&nbsp;value&nbsp;&amp;&nbsp;</span><span class="number"><font color="#c00000">0xff</font></span><span>; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;b2&nbsp;=&nbsp;(value&nbsp;&gt;&gt;&nbsp;</span><span class="number"><font color="#c00000">8</font></span><span>&nbsp;)&nbsp;&amp;&nbsp;</span><span class="number"><font color="#c00000">0xff</font></span><span>; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp; &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">return</span><span>&nbsp;(</span><span class="keyword">short</span><span>)&nbsp;(b1&nbsp;&lt;&lt;&nbsp;</span><span class="number"><font color="#c00000">8</font></span><span>&nbsp;|&nbsp;b2&nbsp;&lt;&lt;&nbsp;</span><span class="number"><font color="#c00000">0</font></span><span>); &nbsp;&nbsp;</span></li>
    <li><span>&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span></li>
    <li><span>&nbsp; &nbsp;&nbsp;</span></li>
    <li><span>}&nbsp;&nbsp;</span></li>
</ol>
<p><span></span></p>
<p><span></span></p>
<p><span></span></p>
<p><span></span></p>
<p><span><span class="hilite1">J2ME</span> is bare-bones anｄ I recently realised that it doesn&rsquo;t have any image encoders. Sure, you can create Image objects&hellip; but there is no way to persist them to disc oｒ to send them over the network in a recognised format. <br />
<br />
With the goal of creating a low-memory <span class="hilite2">PNG</span> encoder based on TinyLine GZIPInputStream, I wrote an uncompressed BMP encoder as a gentle introduction. I am posting it here (under the LGPL) incase it helps somebody out&hellip; I got tripped up by some file format details (including Endianness) so you don&rsquo;t need to go through it. <br />
<br />
Unfortunately, you won&rsquo;t be able to load BMPs anｄ display them without writing your own <span class="hilite3">decoder</span>! (<span class="hilite1">J2ME</span> only supports <span class="hilite2">PNG</span>)&hellip; but at least it allows you to communicate images with the outside world. <br />
<br />
One of the biggest problems with <span class="hilite1">J2ME</span> is that there aren&rsquo;t any great open source libraries out there. That&rsquo;s one of Java&rsquo;s greatest strengths. I intend to post a few of my <span class="hilite1">J2ME</span> utility classes here as I write them. I&rsquo;m currently working on a hobby project which I intend to release here, anｄ if it goes according to plan, I intend to reveal some bluetooth convenience classes. </span></p>]]></description>
   <link>http://pudding.sharera.com/blog/BlogTopic/53953.htm</link>
   <comments>http://pudding.sharera.com/blog/BlogTopic/53953.htm</comments>
   <guid>http://pudding.sharera.com/blog/BlogTopic/53953.htm</guid>
      <author>chendz0526@126.com</author>
   <source url="http://pudding.sharera.com/rss/rss20.xml">果冻</source>
  </item>
    <item>
   <title>详细的PNG文件格式</title>
   <description><![CDATA[参考]详细的PNG文件格式
<div class="t_msgfont" id="postmessage_10840">
<h2 align="right"><a href="http://www.w3.org/"><img height="48" alt="W3C:" src="http://www.w3.org/pub/WWW/Icons/WWW/w3c_home" width="72" align="left" border="0" /></a> REC-png.html</h2>
<h1>PNG (Portable Network Graphics) Specification</h1>
<h1>Version 1.0</h1>
<h3 align="center">W3C Recommendation <em>01-October-1996</em></h3>
<p>For list of authors, see <a href="http://www.j2megame.cn/viewthread.php?tid=3292#Credits"><font color="#800080">Credits (Chapter 19)</font></a>. </p>
<hr />
<h2>Status of this document</h2>
<p>This document has been reviewed by W3C members anｄ other interested parties anｄ has been endorsed by the Director as a W3C Recommendation. It is a stable document anｄ may be used as reference material oｒ cited as a normative reference from another document. W3C's role in making the Recommendation is to draw attention to the specification anｄ to promote its widespread deployment. This enhances the functionality anｄ interoperability of the Web. </p>
<p>A list of current W3C Recommendations anｄ other technical documents can be found at <a href="http://www.w3.org/pub/WWW/TR/"><font color="#0000ff">http://www.w3.org/pub/WWW/TR/</font></a>. </p>
<p>The Consortium staff have encouraged the development of PNG, as have Compuserve, Inc. Most of the work has been done by the PNG Development Group, <tt><font face="新宋体">png-[email]group@w3.org[/email]</font></tt>. The Consortium does not currently have plans to work on any future versions of PNG, though were the necessity to arise, anｄ were an activity in that area to receive the support of Members, the Consortium could in principle support some future activity.</p>
<hr />
<h2>Abstract</h2>
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 anｄ can also replace many common uses of TIFF. Indexed-color, grayscale, anｄ truecolor images are supported, plus an optional alpha channel. Sample depths range from 1 to 16 bits.
<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 anｄ simple detection of common transmission errors. Also, PNG can store gamma anｄ chromaticity data for improved color matching on heterogeneous platforms. </p>
<p>This specification defines a proposed Internet Media Type <tt><font face="新宋体">image/png</font></tt>. </p>
<hr />
<h2>Table of Contents</h2>
<ul>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Introduction"><font color="#800080">1. Introduction</font></a> </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#DataRep"><font color="#800080">2. Data Representation</font></a>
    <ul>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Integers-and-byte-order"><font color="#800080">2.1. Integers anｄ byte order</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Color-values"><font color="#800080">2.2. Color values</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Image-layout"><font color="#800080">2.3. Image layout</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Alpha-channel"><font color="#800080">2.4. Alpha channel</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Filtering"><font color="#800080">2.5. Filtering</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Interlaced-data-order"><font color="#800080">2.6. Interlaced data order</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Gamma-correction"><font color="#800080">2.7. Gamma correction</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Text-strings"><font color="#800080">2.8. Text strings</font></a> </li>
    </ul>
    </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Structure"><font color="#800080">3. File Structure</font></a>
    <ul>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#PNG-file-signature"><font color="#800080">3.1. PNG file signature</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Chunk-layout"><font color="#800080">3.2. Chunk layout</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Chunk-naming-conventions"><font color="#800080">3.3. Chunk naming conventions</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#CRC-algorithm"><font color="#800080">3.4. CRC algorithm</font></a> </li>
    </ul>
    </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Chunks"><font color="#800080">4. Chunk Specifications</font></a>
    <ul>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.Critical-chunks"><font color="#800080">4.1. Critical chunks</font></a>
        <ul>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.IHDR"><font color="#800080">4.1.1. <tt><font face="新宋体">IHDR </font></tt>Image header</font></a> </li>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.PLTE"><font color="#800080">4.1.2. <tt><font face="新宋体">PLTE </font></tt>Palette</font></a> </li>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.IDAT"><font color="#800080">4.1.3. <tt><font face="新宋体">IDAT </font></tt>Image data</font></a> </li>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.IEND"><font color="#800080">4.1.4. <tt><font face="新宋体">IEND </font></tt>Image trailer</font></a> </li>
        </ul>
        </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.Ancillary-chunks"><font color="#800080">4.2. Ancillary chunks</font></a>
        <ul>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.bKGD"><font color="#800080">4.2.1. <tt><font face="新宋体">bKGD </font></tt>Background color</font></a> </li>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.cHRM"><font color="#800080">4.2.2. <tt><font face="新宋体">cHRM </font></tt>Primary chromaticities anｄ white point</font></a> </li>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.gAMA"><font color="#800080">4.2.3. <tt><font face="新宋体">gAMA </font></tt>Image gamma</font></a> </li>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.hIST"><font color="#800080">4.2.4. <tt><font face="新宋体">hIST </font></tt>Image histogram</font></a> </li>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.pHYs"><font color="#800080">4.2.5. <tt><font face="新宋体">pHYs </font></tt>Physical pixel dimensions</font></a> </li>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.sBIT"><font color="#800080">4.2.6. <tt><font face="新宋体">sBIT </font></tt>Significant bits</font></a> </li>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.tEXt"><font color="#800080">4.2.7. <tt><font face="新宋体">tEXt </font></tt>Textual data</font></a> </li>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.tIME"><font color="#800080">4.2.8. <tt><font face="新宋体">tIME </font></tt>Image last-modification time</font></a> </li>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.tRNS"><font color="#800080">4.2.9. <tt><font face="新宋体">tRNS </font></tt>Transparency</font></a> </li>
            <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.zTXt"><font color="#800080">4.2.10. <tt><font face="新宋体">zTXt </font></tt>Compressed textual data</font></a> </li>
        </ul>
        </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.Summary-of-standard-chunks"><font color="#800080">4.3. Summary of standard chunks</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.Additional-chunk-types"><font color="#800080">4.4. Additional chunk types</font></a> </li>
    </ul>
    </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Compression"><font color="#800080">5. Deflate/Inflate Compression</font></a> </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Filters"><font color="#800080">6. Filter Algorithms</font></a>
    <ul>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Filter-types"><font color="#800080">6.1. Filter types</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Filter-type-0-None"><font color="#800080">6.2. Filter type 0: None</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Filter-type-1-Sub"><font color="#800080">6.3. Filter type 1: Sub</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Filter-type-2-Up"><font color="#800080">6.4. Filter type 2: Up</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Filter-type-3-Average"><font color="#800080">6.5. Filter type 3: Average</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Filter-type-4-Paeth"><font color="#800080">6.6. Filter type 4: Paeth</font></a> </li>
    </ul>
    </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Ordering"><font color="#800080">7. Chunk Ordering Rules</font></a>
    <ul>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Behavior-of-PNG-editors"><font color="#800080">7.1. Behavior of PNG editors</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Ordering-of-ancillary-chunks"><font color="#800080">7.2. Ordering of ancillary chunks</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Ordering-of-critical-chunks"><font color="#800080">7.3. Ordering of critical chunks</font></a> </li>
    </ul>
    </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Misc"><font color="#800080">8. Miscellaneous Topics</font></a>
    <ul>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#File-name-extension"><font color="#800080">8.1. File name extension</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Media-type"><font color="#800080">8.2. Internet media type</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Macintosh-file-layout"><font color="#800080">8.3. Macintosh file layout</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Multiple-image-extension"><font color="#800080">8.4. Multiple-image extension</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Security-considerations"><font color="#800080">8.5. Security considerations</font></a> </li>
    </ul>
    </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Encoders"><font color="#800080">9. Recommendations for Encoders</font></a>
    <ul>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Sample-depth-scaling"><font color="#800080">9.1. Sample depth scaling</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Encoder-gamma-handling"><font color="#800080">9.2. Encoder gamma handling</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Encoder-color-handling"><font color="#800080">9.3. Encoder color handling</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Alpha-channel-creation"><font color="#800080">9.4. Alpha channel creation</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Suggested-palettes"><font color="#800080">9.5. Suggested palettes</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Filter-selection"><font color="#800080">9.6. Filter selection</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Text-chunk-processing"><font color="#800080">9.7. Text chunk processing</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Use-of-private-chunks"><font color="#800080">9.8. Use of private chunks</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Private-type-and-method-codes"><font color="#800080">9.9. Private type anｄ method codes</font></a> </li>
    </ul>
    </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Decoders"><font color="#800080">10. Recommendations for Decoders</font></a>
    <ul>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Error-checking"><font color="#800080">10.1. Error checking</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Pixel-dimensions"><font color="#800080">10.2. Pixel dimensions</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Truecolor-image-handling"><font color="#800080">10.3. Truecolor image handling</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Sample-depth-rescaling"><font color="#800080">10.4. Sample depth rescaling</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Decoder-gamma-handling"><font color="#800080">10.5. Decoder gamma handling</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Decoder-color-handling"><font color="#800080">10.6. Decoder color handling</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Background-color"><font color="#800080">10.7. Background color</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Alpha-channel-processing"><font color="#800080">10.8. Alpha channel processing</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Progressive-display"><font color="#800080">10.9. Progressive display</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Suggested-palette-and-histogram-usage"><font color="#800080">10.10. Suggested-palette anｄ histogram usage</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Text-chunk-processing"><font color="#800080">10.11. Text chunk processing</font></a> </li>
    </ul>
    </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Glossary"><font color="#800080">11. Glossary</font></a> </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Rationale"><font color="#800080">12. Appendix: Rationale</font></a>
    <ul>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Why-a-new-file-format"><font color="#800080">12.1. Why a new file format?</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Why-these-features"><font color="#800080">12.2. Why these features?</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Why-not-these-features"><font color="#800080">12.3. Why not these features?</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Why-not-use-format-X"><font color="#800080">12.4. Why not use format X?</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Byte-order"><font color="#800080">12.5. Byte order</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Interlacing"><font color="#800080">12.6. Interlacing</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Why-gamma"><font color="#800080">12.7. Why gamma?</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Non-premultiplied-alpha"><font color="#800080">12.8. Non-premultiplied alpha</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Filtering"><font color="#800080">12.9. Filtering</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Text-strings"><font color="#800080">12.10. Text strings</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.PNG-file-signature"><font color="#800080">12.11. PNG file signature</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Chunk-layout"><font color="#800080">12.12. Chunk layout</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Chunk-naming-conventions"><font color="#800080">12.13. Chunk naming conventions</font></a> </li>
        <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Palette-histograms"><font color="#800080">12.14. Palette histograms</font></a> </li>
    </ul>
    </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#GammaAppendix"><font color="#800080">13. Appendix: Gamma Tutorial</font></a> </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#ColorAppendix"><font color="#800080">14. Appendix: Color Tutorial</font></a> </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#CRCAppendix"><font color="#800080">15. Appendix: Sample CRC Code</font></a> </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Resources"><font color="#800080">16. Appendix: Online Resources</font></a> </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#History"><font color="#800080">17. Appendix: Revision History</font></a> </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#References"><font color="#800080">18. References</font></a> </li>
    <li><a href="http://www.j2megame.cn/viewthread.php?tid=3292#Credits"><font color="#800080">19. Credits</font></a> </li>
</ul>
<h2><a name="Introduction"><font color="#000000">1. Introduction</font></a></h2>
The PNG format provides a portable, legally unencumbered, well-compressed, well-specified standard for lossless bitmapped image files.
<p>Although the initial motivation for developing PNG was to replace GIF, the design provides some useful new features not available in GIF, with minimal cost to developers. </p>
<p>GIF features retained in PNG include: </p>
<ul>
    <li>Indexed-color images of up to 256 colors. </li>
    <li>Streamability: files can be read anｄ written serially, thus allowing the file format to be used as a communications protocol for on-the-fly generation anｄ display of images. </li>
    <li>Progressive display: a suitably prepared image file can be displayed as it is received over a communications link, yielding a low-resolution image very quickly followed by gradual improvement of detail. </li>
    <li>Transparency: portions of the image can be marked as transparent, creating the effect of a non-rectangular image. </li>
    <li>Ancillary information: textual comments anｄ other data can be stored within the image file. </li>
    <li>Complete hardware anｄ platform independence. </li>
    <li>Effective, 100% lossless compression. </li>
</ul>
Important new features of PNG, not available in GIF, include:
<ul>
    <li>Truecolor images of up to 48 bits per pixel. </li>
    <li>Grayscale images of up to 16 bits per pixel. </li>
    <li>Full alpha channel (general transparency masks). </li>
    <li>Image gamma information, which supports automatic display of images with correct brightness/contrast regardless of the machines used to originate anｄ display the image. </li>
    <li>Reliable, straightforward detection of file corruption. </li>
    <li>Faster initial presentation in progressive display mode. </li>
</ul>
PNG is designed to be:
<ul>
    <li>Simple anｄ portable: developers should be able to implement PNG easily. </li>
    <li>Legally unencumbered: to the best knowledge of the PNG authors, no algorithms under legal challenge are used. (Some considerable effort has been spent to verify this.) </li>
    <li>Well compressed: both indexed-color anｄ truecolor images are compressed as effectively as in any other widely used lossless format, anｄ in most cases more effectively. </li>
    <li>Interchangeable: any standard-conforming PNG decoder must read all conforming PNG files. </li>
    <li>Flexible: the format allows for future extensions anｄ private add-ons, without compromising interchangeability of basic PNG. </li>
    <li>Robust: the design supports full file integrity checking as well as simple, quick detection of common transmission errors. </li>
</ul>
<p>The main part of this specification gives the definition of the file format anｄ recommendations for encoder anｄ decoder behavior. An appendix gives the rationale for many design decisions. Although the rationale is not part of the formal specification, reading it can help implementors understand the design. Cross-references in the main text point to relevant parts of the rationale. Additional appendixes, also not part of the formal specification, provide tutorials on gamma anｄ color theory as well as other supporting material. </p>
<p>In this specification, the word &quot;must&quot; indicates a mandatory requirement, while &quot;should&quot; indicates recommended behavior. </p>
<p>See Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Why-a-new-file-format"><font color="#800080">Why a new file format? (Section 12.1)</font></a>, <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Why-these-features"><font color="#800080">Why these features? (Section 12.2)</font></a>, <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Why-not-these-features"><font color="#800080">Why not these features? (Section 12.3)</font></a>, <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Why-not-use-format-X"><font color="#800080">Why not use format X? (Section 12.4)</font></a>. </p>
<h3>Pronunciation</h3>
PNG is pronounced &quot;ping&quot;.
<h2><a name="DataRep"><font color="#000000">2. Data Representation</font></a></h2>
This chapter discusses basic data representations used in PNG files, as well as the expected representation of the image data.
<h3><a name="DR.Integers-and-byte-order"><font color="#000000">2.1. Integers anｄ byte order</font></a></h3>
All integers that require more than one byte must be in network byte order: the most significant byte comes first, then the less significant bytes in descending order of significance (MSB LSB for two-byte integers, B3 B2 B1 B0 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>See Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Byte-order"><font color="#800080">Byte order (Section 12.5)</font></a>. </p>
<h3><a name="DR.Color-values"><font color="#000000">2.2. Color values</font></a></h3>
Colors can be represented by either grayscale oｒ RGB (red, green, blue) sample data. Grayscale data represents luminance; RGB data represents calibrated color information (if the <tt><font face="新宋体">cHRM</font></tt> chunk is present) oｒ uncalibrated device-dependent color (if <tt><font face="新宋体">cHRM</font></tt> is absent). All color values range from zero (representing black) to most intense at the maximum value for the sample depth. Note that the maximum value at a given sample depth is (2^sampledepth)-1, not 2^sampledepth.
<p>Sample values are not necessarily linear; the <tt><font face="新宋体">gAMA</font></tt> chunk specifies the gamma characteristic of the source device, anｄ viewers are strongly encouraged to compensate properly. See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Gamma-correction"><font color="#800080">Gamma correction (Section 2.7)</font></a>. </p>
<p>Source data with a precision not directly supported in PNG (for example, 5 bit/sample truecolor) must be scaled up to the next higher supported bit depth. This scaling is reversible with no loss of data, anｄ it reduces the number of cases that decoders have to cope with. See Recommendations for Encoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Sample-depth-scaling"><font color="#800080">Sample depth scaling (Section 9.1)</font></a> anｄ Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Sample-depth-rescaling"><font color="#800080">Sample depth rescaling (Section 10.4)</font></a>. </p>
<h3><a name="DR.Image-layout"><font color="#000000">2.3. Image layout</font></a></h3>
Conceptually, a PNG image is a rectangular pixel array, with pixels appearing left-to-right within each scanline, anｄ scanlines appearing top-to-bottom. (For progressive display purposes, the data may actually be transmitted in a different order; see <a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Interlaced-data-order"><font color="#800080">Interlaced data order, Section 2.6</font></a>.) The size of each pixel is determined by the <em>bit depth</em>, which is the number of bits per sample in the image data.
<p>Three types of pixel are supported: </p>
<ul>
    <li>An <em>indexed-color</em> pixel is represented by a single sample that is an index into a supplied palette. The image bit depth determines the maximum number of palette entries, but not the color precision within the palette. </li>
    <li>A <em>grayscale</em> pixel is represented by a single sample that is a grayscale level, where zero is black anｄ the largest value for the bit depth is white. </li>
    <li>A <em>truecolor</em> pixel is represented by three samples: red (zero = black, max = red) appears first, then green (zero = black, max = green), then blue (zero = black, max = blue). The bit depth specifies the size of each sample, not the total pixel size. </li>
</ul>
<p>Optionally, grayscale anｄ truecolor pixels can also include an alpha sample, as described in the next section. </p>
<p>Pixels are always packed into scanlines with no wasted bits between pixels. Pixels smaller than a byte never cross byte boundaries; they are packed into bytes with the leftmost pixel in the high-order bits of a byte, the rightmost in the low-order bits. Permitted bit depths anｄ pixel types are restricted so that in all cases the packing is simple anｄ efficient. </p>
<p>PNG permits multi-sample pixels only with 8- anｄ 16-bit samples, so multiple samples of a single pixel are never packed into one byte. 16-bit samples are stored in network byte order (MSB first). </p>
<p>Scanlines always begin on byte boundaries. When pixels have fewer than 8 bits anｄ the scanline width is not evenly divisible by the number of pixels per byte, the low-order bits in the last byte of each scanline are wasted. The contents of these wasted bits are unspecified. </p>
<p>An additional &quot;filter type&quot; byte is added to the beginning of every scanline (see <a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Filtering"><font color="#800080">Filtering, Section 2.5</font></a>). The filter type byte is not considered part of the image data, but it is included in the datastream sent to the compression step. </p>
<h3><a name="DR.Alpha-channel"><font color="#000000">2.4. Alpha channel</font></a></h3>
An alpha channel, representing transparency information on a per-pixel basis, can be included in grayscale anｄ truecolor PNG images.
<p>An alpha value of zero represents full transparency, anｄ a value of (2^bitdepth)-1 represents a fully opaque pixel. Intermediate values indicate partially transparent pixels that can be combined with a background image to yield a composite image. (Thus, alpha is really the degree of opacity of the pixel. But most people refer to alpha as providing transparency information, not opacity information, anｄ we continue that custom here.) </p>
<p>Alpha channels can be included with images that have either 8 oｒ 16 bits per sample, but not with images that have fewer than 8 bits per sample. Alpha samples are represented with the same bit depth used for the image samples. The alpha sample for each pixel is stored immediately following the grayscale oｒ RGB samples of the pixel. </p>
<p>The color values stored for a pixel are not affected by the alpha value assigned to the pixel. This rule is sometimes called &quot;unassociated&quot; oｒ &quot;non-premultiplied&quot; alpha. (Another common technique is to store sample values premultiplied by the alpha fraction; in effect, such an image is already composited against a black background. PNG does <em>not</em> use premultiplied alpha.) </p>
<p>Transparency control is also possible without the storage cost of a full alpha channel. In an indexed-color image, an alpha value can be defined for each palette entry. In grayscale anｄ truecolor images, a single pixel value can be identified as being &quot;transparent&quot;. These techniques are controlled by the <tt><font face="新宋体">tRNS</font></tt> ancillary chunk type. </p>
<p>If no alpha channel nor <tt><font face="新宋体">tRNS</font></tt> chunk is present, all pixels in the image are to be treated as fully opaque. </p>
<p>Viewers can support transparency control partially, oｒ not at all. </p>
<p>See Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Non-premultiplied-alpha"><font color="#800080">Non-premultiplied alpha (Section 12.8)</font></a>, Recommendations for Encoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Alpha-channel-creation"><font color="#800080">Alpha channel creation (Section 9.4)</font></a>, anｄ Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Alpha-channel-processing"><font color="#800080">Alpha channel processing (Section 10.8)</font></a>. </p>
<h3><a name="DR.Filtering"><font color="#000000">2.5. Filtering</font></a></h3>
PNG allows the image data to be <em>filtered</em> before it is compressed. Filtering can improve the compressibility of the data. The filter step itself does not reduce the size of the data. All PNG filters are strictly lossless.
<p>PNG defines several different filter algorithms, including &quot;None&quot; which indicates no filtering. The filter algorithm is specified for each scanline by a filter type byte that precedes the filtered scanline in the precompression datastream. An intelligent encoder can switch filters from one scanline to the next. The method for choosing which filter to employ is up to the encoder. </p>
<p>See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#Filters"><font color="#800080">Filter Algorithms (Chapter 6)</font></a> anｄ Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Filtering"><font color="#800080">Filtering (Section 12.9)</font></a>. </p>
<h3><a name="DR.Interlaced-data-order"><font color="#000000">2.6. Interlaced data order</font></a></h3>
A PNG image can be stored in interlaced order to allow progressive display. The purpose of this feature is to allow images to &quot;fade in&quot; when they are being displayed on-the-fly. Interlacing slightly expands the file size on average, but it gives the user a meaningful display much more rapidly. Note that decoders are required to be able to read interlaced images, whether oｒ not they actually perform progressive display.
<p>With interlace method 0, pixels are stored sequentially from left to right, anｄ scanlines sequentially from top to bottom (no interlacing). </p>
<p>Interlace method 1, known as Adam7 after its author, Adam M. Costello, consists of seven distinct passes over the image. Each pass transmits a subset of the pixels in the image. The pass in which each pixel is transmitted 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>
Within each pass, the selected pixels are transmitted left to right within a scanline, anｄ selected scanlines sequentially from top to bottom. For example, pass 2 contains pixels 4, 12, 20, etc. of scanlines 0, 8, 16, etc. (numbering from 0,0 at the upper left corner). The last pass contains the entirety of scanlines 1, 3, 5, etc.
<p><strong>The data within each pass is laid out as though it were a complete image of the appropriate dimensions.</strong> For example, if the complete image is 16 by 16 pixels, then pass 3 will contain two scanlines, each containing four pixels. When pixels have fewer than 8 bits, each such scanline is padded as needed to fill an integral number of bytes (see <a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Image-layout"><font color="#800080">Image layout, Section 2.3</font></a>). Filtering is done on this reduced image in the usual way, anｄ a filter type byte is transmitted before each of its scanlines (see <a href="http://www.j2megame.cn/viewthread.php?tid=3292#Filters"><font color="#800080">Filter Algorithms, Chapter 6</font></a>). Notice that 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. </p>
<p><strong>Caution:</strong> If the image contains fewer than five columns oｒ fewer than five rows, some passes will be entirely empty. Encoders anｄ decoders must handle this case correctly. In particular, filter type bytes are only associated with nonempty scanlines; no filter type bytes are present in an empty pass. </p>
<p>See Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Interlacing"><font color="#800080">Interlacing (Section 12.6)</font></a> anｄ Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Progressive-display"><font color="#800080">Progressive display (Section 10.9)</font></a>. </p>
<h3><a name="DR.Gamma-correction"><font color="#000000">2.7. Gamma correction</font></a></h3>
PNG images can specify, via the <tt><font face="新宋体">gAMA</font></tt> chunk, the gamma characteristic of the image with respect to the original scene. Display programs are strongly encouraged to use this information, plus information about the display device they are using anｄ room lighting, to present the image to the viewer in a way that reproduces what the image's original author saw as closely as possible. See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#GammaAppendix"><font color="#800080">Gamma Tutorial (Chapter 13)</font></a> if you aren't already familiar with gamma issues.
<p>Gamma correction is not applied to the alpha channel, if any. Alpha samples always represent a linear fraction of full opacity. </p>
<p>For high-precision applications, the exact chromaticity of the RGB data in a PNG image can be specified via the <tt><font face="新宋体">cHRM</font></tt> chunk, allowing more accurate color matching than gamma correction alone will provide. See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#ColorAppendix"><font color="#800080">Color Tutorial (Chapter 14)</font></a> if you aren't already familiar with color representation issues. </p>
<p>See Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Why-gamma"><font color="#800080">Why gamma? (Section 12.7)</font></a>, Recommendations for Encoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Encoder-gamma-handling"><font color="#800080">Encoder gamma handling (Section 9.2)</font></a>, anｄ Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Decoder-gamma-handling"><font color="#800080">Decoder gamma handling (Section 10.5)</font></a>. </p>
<h3><a name="DR.Text-strings"><font color="#000000">2.8. Text strings</font></a></h3>
A PNG file can store text associated with the image, such as an image description oｒ copyright notice. Keywords are used to indicate what each text string represents.
<p>ISO 8859-1 (Latin-1) is the character set recommended for use in text strings <a href="ftp://ftp.uu.net/graphics/png/documents/"><font color="#0000ff">[ISO-8859]</font></a>. This character set is a superset of 7-bit ASCII. </p>
<p>Character codes not defined in Latin-1 should not be used, because they have no platform-independent meaning. If a non-Latin-1 code does appear in a PNG text string, its interpretation will vary across platforms anｄ decoders. Some systems might not even be able to display all the characters in Latin-1, but most modern systems can. </p>
<p>Provision is also made for the storage of compressed text. </p>
<p>See Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Text-strings"><font color="#800080">Text strings (Section 12.10)</font></a>. </p>
<h2><a name="Structure"><font color="#000000">3. File Structure</font></a></h2>
A PNG file consists of a PNG <em>signature</em> followed by a series of <em>chunks</em>. This chapter defines the signature anｄ the basic properties of chunks. Individual chunk types are discussed in the next chapter.
<h3><a name="PNG-file-signature"><font color="#000000">3.1. PNG file signature</font></a></h3>
The first eight bytes of a PNG file always contain the following (decimal) values:
<pre>   137 80 78 71 13 10 26 10
</pre>
This signature indicates that the remainder of the file contains a single PNG image, consisting of a series of chunks beginning with an <tt><font face="新宋体">IHDR</font></tt> chunk anｄ ending with an <tt><font face="新宋体">IEND</font></tt> chunk.
<p>See Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.PNG-file-signature"><font color="#800080">PNG file signature (Section 12.11)</font></a>. </p>
<h3><a name="Chunk-layout"><font color="#000000">3.2. Chunk layout</font></a></h3>
Each chunk consists of four parts: <dl><dt>Length </dt><dd>A 4-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 code, oｒ the CRC. Zero is a valid length. Although encoders anｄ decoders should treat the length as unsigned, its value must not exceed (2^31)-1 bytes. </dd><dt>Chunk Type </dt><dd>A 4-byte chunk type code. For convenience in description anｄ in examining PNG files, type codes are restricted to consist of uppercase anｄ lowercase ASCII letters (<tt><font face="新宋体">A</font></tt>-<tt><font face="新宋体">Z</font></tt> anｄ <tt><font face="新宋体">a</font></tt>-<tt><font face="新宋体">z</font></tt>, oｒ 65-90 anｄ 97-122 decimal). However, encoders anｄ decoders must treat the codes as fixed binary values, not character strings. For example, it would not be correct to represent the type code <tt><font face="新宋体">IDAT</font></tt> by the EBCDIC equivalents of those letters. Additional naming conventions for chunk types are discussed in the next section. </dd><dt>Chunk Data </dt><dd>The data bytes appropriate to the chunk type, if any. This field can be of zero length. </dd><dt>CRC </dt><dd>A 4-byte CRC (Cyclic Redundancy Check) calculated on the preceding bytes in the chunk, including the chunk type code anｄ chunk data fields, but <strong>not</strong> including the length field. The CRC is always present, even for chunks containing no data. See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#CRC-algorithm"><font color="#800080">CRC algorithm (Section 3.4)</font></a>. </dd></dl>
<p>The chunk data length can be any number of bytes up to the maximum; therefore, implementors cannot assume that chunks are aligned on any boundaries larger than bytes. </p>
<p>Chunks can appear in any order, subject to the restrictions placed on each chunk type. (One notable restriction is that <tt><font face="新宋体">IHDR</font></tt> must appear first anｄ <tt><font face="新宋体">IEND</font></tt> must appear last; thus the <tt><font face="新宋体">IEND</font></tt> chunk serves as an end-of-file marker.) Multiple chunks of the same type can appear, but only if specifically permitted for that type. </p>
<p>See Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Chunk-layout"><font color="#800080">Chunk layout (Section 12.12)</font></a>. </p>
<h3><a name="Chunk-naming-conventions"><font color="#000000">3.3. Chunk naming conventions</font></a></h3>
Chunk type codes are assigned so that a decoder can determine some properties of a chunk even when it does not recognize the type code. These rules are intended to allow safe, flexible extension of the PNG format, by allowing a decoder to decide what to do when it encounters an unknown chunk. The naming rules are not normally of interest when the decoder does recognize the chunk's type.
<p>Four bits of the type code, 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 each letter of the type code is uppercase (bit 5 is 0) oｒ lowercase (bit 5 is 1). However, decoders should test the properties of an unknown chunk by numerically testing the specified bits; testing whether a character is uppercase oｒ lowercase is inefficient, anｄ even incorrect if a locale-specific case definition is used. </p>
<p>It is worth noting that the property bits are an inherent part of the chunk name, anｄ hence are fixed for any chunk type. Thus, <tt><font face="新宋体">TEXT</font></tt> anｄ <tt><font face="新宋体">Text</font></tt> would be unrelated chunk type codes, not the same chunk with different properties. Decoders must recognize type codes by a simple four-byte literal comparison; it is incorrect to perform case conversion on type codes. </p>
<p>The semantics of the property bits are: </p>
<dl><dt>Ancillary bit: bit 5 of first byte </dt><dd>0 (uppercase) = critical, 1 (lowercase) = ancillary.
<p>Chunks that are not strictly necessary in order to meaningfully display the contents of the file are known as &quot;ancillary&quot; chunks. A decoder encountering an unknown chunk in which the ancillary bit is 1 can safely ignore the chunk anｄ proceed to display the image. The time chunk (<tt><font face="新宋体">tIME</font></tt>) is an example of an ancillary chunk. </p>
<p>Chunks that are necessary for successful display of the file's contents are called &quot;critical&quot; chunks. A decoder encountering an unknown chunk in which the ancillary bit is 0 must indicate to the user that the image contains information it cannot safely interpret. The image header chunk (<tt><font face="新宋体">IHDR</font></tt>) is an example of a critical chunk. </p>
<p>&nbsp;</p>
</dd><dt>Private bit: bit 5 of second byte </dt><dd>0 (uppercase) = public, 1 (lowercase) = private.
<p>A public chunk is one that is part of the PNG specification oｒ is registered in the list of PNG special-purpose public chunk types. Applications can also define private (unregistered) chunks for their own purposes. The names of private chunks must have a lowercase second letter, while public chunks will always be assigned names with uppercase second letters. Note that 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 anｄ private chunk names will not conflict. See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.Additional-chunk-types"><font color="#800080">Additional chunk types (Section 4.4)</font></a> anｄ Recommendations for Encoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Use-of-private-chunks"><font color="#800080">Use of private chunks (Section 9.8)</font></a>. </p>
<p>&nbsp;</p>
</dd><dt>Reserved bit: bit 5 of third byte </dt><dd>Must be 0 (uppercase) in files conforming to this version of PNG.
<p>The significance of the case of the third letter of the chunk name is reserved for possible future expansion. At the present time all chunk names must have uppercase third letters. (Decoders should not complain about a lowercase third letter, however, as some future version of the PNG specification could define a meaning for this bit. It is sufficient to treat a chunk with a lowercase third letter in the same way as any other unknown chunk type.) </p>
<p>&nbsp;</p>
</dd><dt>Safe-to-copy bit: bit 5 of fourth byte </dt><dd>0 (uppercase) = unsafe to copy, 1 (lowercase) = safe to copy.
<p>This property bit is not of interest to pure decoders, but it is needed by PNG editors (programs that modify PNG files). This bit defines the proper handling of unrecognized chunks in a file that is being modified. </p>
<p>If a chunk's safe-to-copy bit is 1, the chunk may be copied to a modified PNG file whether oｒ not the software recognizes the chunk type, anｄ regardless of the extent of the file modifications. </p>
<p>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 <em>any</em> changes to <em>critical</em> chunks, including addition, modification, deletion, oｒ reordering of critical chunks, then unrecognized unsafe chunks must <strong>not</strong> be copied to the output PNG file. (Of course, if the program <strong>does</strong> recognize the chunk, it can choose to output an appropriately modified version.) </p>
<p>A PNG editor is always allowed to copy all unrecognized chunks if it has only added, deleted, modified, oｒ reordered <em>ancillary</em> chunks. This implies that it is not permissible for ancillary chunks to depend on other ancillary chunks. </p>
<p>PNG editors that do not recognize a <em>critical</em> chunk must report an error anｄ refuse to process that PNG file at all. The safe/unsafe mechanism is intended for use with ancillary chunks. The safe-to-copy bit will always be 0 for critical chunks. </p>
<p>Rules for PNG editors are discussed further in <a href="http://www.j2megame.cn/viewthread.php?tid=3292#Ordering"><font color="#800080">Chunk Ordering Rules (Chapter 7)</font></a>. </p>
</dd></dl>
<p>For example, the hypothetical chunk type name &quot;<tt><font face="新宋体">bLOb</font></tt>&quot; has the property bits: </p>
<pre>   bLOb  &lt;－－ 32 bit chunk type code 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>
Therefore, this name represents an ancillary, public, safe-to-copy chunk.
<p>See Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Chunk-naming-conventions"><font color="#800080">Chunk naming conventions (Section 12.13)</font></a>. </p>
<h3><a name="CRC-algorithm"><font color="#000000">3.4. CRC algorithm</font></a></h3>
Chunk CRCs are calculated using standard CRC methods with pre anｄ post conditioning, as defined by ISO 3309 [ISO-3309] oｒ ITU-T V.42 [ITU-V42]. The CRC polynomial employed is
<pre>   x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1
</pre>
The 32-bit CRC register is initialized to all 1's, anｄ 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 register is inverted (its ones complement is taken). This value is transmitted (stored in the file) MSB first. For the purpose of separating into bytes anｄ ordering, the least significant bit of the 32-bit CRC is defined to be the coefficient of the <tt><font face="新宋体">x^31</font></tt> term.
<p>Practical calculation of the CRC always employs a precalculated table to greatly accelerate the computation. See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#CRCAppendix"><font color="#800080">Sample CRC Code (Chapter 15)</font></a>. </p>
<h2><a name="Chunks"><font color="#000000">4. Chunk Specifications</font></a></h2>
This chapter defines the standard types of PNG chunks.
<h3><a name="C.Critical-chunks"><font color="#000000">4.1. Critical chunks</font></a></h3>
All implementations must understand anｄ successfully render the standard critical chunks. A valid PNG image must contain an <tt><font face="新宋体">IHDR</font></tt> chunk, one oｒ more <tt><font face="新宋体">IDAT</font></tt> chunks, anｄ an <tt><font face="新宋体">IEND</font></tt> chunk.
<h4><a name="C.IHDR"><font color="#000000">4.1.1. <tt><font face="新宋体">IHDR </font></tt>Image header</font></a></h4>
The <tt><font face="新宋体">IHDR</font></tt> chunk must appear FIRST. It contains:
<pre>   Width:              4 bytes
   Height:             4 bytes
   Bit depth:          1 byte
   Color type:         1 byte
   Compression method: 1 byte
   Filter method:      1 byte
   Interlace method:   1 byte
</pre>
Width anｄ height give the image dimensions in pixels. They are 4-byte integers. Zero is an invalid value. The maximum for each is (2^31)-1 in order to accommodate languages that have difficulty with unsigned 4-byte values.
<p>Bit depth is a single-byte integer giving the number of bits per sample oｒ per palette index (not per pixel). Valid values are 1, 2, 4, 8, anｄ 16, although not all values are allowed for all color types. </p>
<p>Color type is a single-byte integer that describes the interpretation of the image data. Color type codes represent sums of the following values: 1 (palette used), 2 (color used), anｄ 4 (alpha channel used). Valid values are 0, 2, 3, 4, anｄ 6. </p>
<p>Bit depth restrictions for each color type are imposed to simplify implementations anｄ to prohibit combinations that do not compress well. Decoders must support all legal combinations of bit depth anｄ color type. The allowed combinations are: </p>
<pre>   Color    Allowed    Interpretation
   Type    Bit Depths
   
   0       1,2,4,8,16  Each pixel is a grayscale sample.
   
   2       8,16        Each pixel is an R,G,B triple.
   
   3       1,2,4,8     Each pixel is a palette index;
                       a PLTE chunk must appear.
   
   4       8,16        Each pixel is a grayscale sample,
                       followed by an alpha sample.
   
   6       8,16        Each pixel is an R,G,B triple,
                       followed by an alpha sample.
</pre>
The sample depth is the same as the bit depth except in the case of color type 3, in which the sample depth is always 8 bits.
<p>Compression method is a single-byte integer that indicates the method used to compress the image data. At present, only compression method 0 (deflate/inflate compression with a 32K sliding window) is defined. All standard PNG images must be compressed with this scheme. The compression method field is provided for possible future expansion oｒ proprietary variants. Decoders must check this byte anｄ report an error if it holds an unrecognized code. See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#Compression"><font color="#800080">Deflate/Inflate Compression (Chapter 5)</font></a> for details. </p>
<p>Filter method is a single-byte integer that indicates the preprocessing method applied to the image data before compression. At present, only filter method 0 (adaptive filtering with five basic filter types) is defined. As with the compression method field, decoders must check this byte anｄ report an error if it holds an unrecognized code. See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#Filters"><font color="#800080">Filter Algorithms (Chapter 6)</font></a> for details. </p>
<p>Interlace method is a single-byte integer that indicates the transmission order of the image data. Two values are currently defined: 0 (no interlace) oｒ 1 (Adam7 interlace). See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Interlaced-data-order"><font color="#800080">Interlaced data order (Section 2.6)</font></a> for details. </p>
<h4><a name="C.PLTE"><font color="#000000">4.1.2. <tt><font face="新宋体">PLTE </font></tt>Palette</font></a></h4>
The <tt><font face="新宋体">PLTE</font></tt> chunk contains from 1 to 256 palette entries, each a three-byte series of the form:
<pre>   Red:   1 byte (0 = black, 255 = red)
   Green: 1 byte (0 = black, 255 = green)
   Blue:  1 byte (0 = black, 255 = blue)
</pre>
The number of entries is determined from the chunk length. A chunk length not divisible by 3 is an error.
<p>This chunk must appear for color type 3, anｄ can appear for color types 2 anｄ 6; it must not appear for color types 0 anｄ 4. If this chunk does appear, it must precede the first <tt><font face="新宋体">IDAT</font></tt> chunk. There must not be more than one <tt><font face="新宋体">PLTE</font></tt> chunk. </p>
<p>For color type 3 (indexed color), the <tt><font face="新宋体">PLTE</font></tt> chunk is required. The first entry in <tt><font face="新宋体">PLTE</font></tt> is referenced by pixel value 0, the second by pixel value 1, etc. The number of palette entries must not exceed the range that can be represented in the image bit depth (for example, 2^4 = 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 color types 2 anｄ 6 (truecolor anｄ truecolor with alpha), the <tt><font face="新宋体">PLTE</font></tt> chunk is optional. If present, it provides a suggested set of from 1 to 256 colors to which the truecolor image can be quantized if the viewer cannot display truecolor directly. If <tt><font face="新宋体">PLTE</font></tt> is not present, such a viewer will need to selecｔ colors on its own, but it is often preferable for this to be done once by the encoder. (See Recommendations for Encoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Suggested-palettes"><font color="#800080">Suggested palettes, Section 9.5</font></a>.) </p>
<p>Note that the palette uses 8 bits (1 byte) per sample regardless of the image bit depth specification. In particular, the palette is 8 bits deep even when it is a suggested quantization of a 16-bit truecolor image. </p>
<p>There is no requirement that the palette entries all be used by the image, nor that they all be different. </p>
<h4><a name="C.IDAT"><font color="#000000">4.1.3. <tt><font face="新宋体">IDAT </font></tt>Image data</font></a></h4>
The <tt><font face="新宋体">IDAT</font></tt> chunk contains the actual image data. To create this data:
<ol>
    <li>Begin with image scanlines represented as described in <a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Image-layout"><font color="#800080">Image layout (Section 2.3)</font></a>; the layout anｄ total size of this raw data are determined by the fields of <tt><font face="新宋体">IHDR</font></tt>. </li>
    <li>Filter the image data according to the filtering method specified by the <tt><font face="新宋体">IHDR</font></tt> chunk. (Note that with filter method 0, the only one currently defined, this implies prepending a filter type byte to each scanline.) </li>
    <li>Compress the filtered data using the compression method specified by the <tt><font face="新宋体">IHDR</font></tt> chunk. </li>
</ol>
The <tt><font face="新宋体">IDAT</font></tt> chunk contains the output datastream of the compression algorithm.
<p>To read the image data, reverse this process. </p>
<p>There can be multiple <tt><font face="新宋体">IDAT</font></tt> chunks; if so, they must appear consecutively with no other intervening chunks. The compressed datastream is then the concatenation of the contents of all the <tt><font face="新宋体">IDAT</font></tt> chunks. The encoder can divide the compressed datastream into <tt><font face="新宋体">IDAT</font></tt> chunks however it wishes. (Multiple <tt><font face="新宋体">IDAT</font></tt> chunks are allowed so that encoders can work in a fixed amount of memory; typically the chunk size will correspond to the encoder's buffer size.) It is important to emphasize that <tt><font face="新宋体">IDAT</font></tt> chunk boundaries have no semantic significance anｄ can occur at any point in the compressed datastream. A PNG file in which each <tt><font face="新宋体">IDAT</font></tt> chunk contains only one data byte is legal, though remarkably wasteful of space. (For that matter, zero-length <tt><font face="新宋体">IDAT</font></tt> chunks are legal, though even more wasteful.) </p>
<p>See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#Filters"><font color="#800080">Filter Algorithms (Chapter 6)</font></a> anｄ <a href="http://www.j2megame.cn/viewthread.php?tid=3292#Compression"><font color="#800080">Deflate/Inflate Compression (Chapter 5)</font></a> for details. </p>
<h4><a name="C.IEND"><font color="#000000">4.1.4. <tt><font face="新宋体">IEND </font></tt>Image trailer</font></a></h4>
The <tt><font face="新宋体">IEND</font></tt> chunk must appear LAST. It marks the end of the PNG datastream. The chunk's data field is empty.
<h3><a name="C.Ancillary-chunks"><font color="#000000">4.2. Ancillary chunks</font></a></h3>
All ancillary chunks are optional, in the sense that encoders need not write them anｄ decoders can ignore them. However, encoders are encouraged to write the standard ancillary chunks when the information is available, anｄ decoders are encouraged to interpret these chunks when appropriate anｄ feasible.
<p>The standard ancillary chunks are listed in alphabetical order. This is not necessarily the order in which they would appear in a file. </p>
<h4><a name="C.bKGD"><font color="#000000">4.2.1. <tt><font face="新宋体">bKGD </font></tt>Background color</font></a></h4>
The <tt><font face="新宋体">bKGD</font></tt> chunk specifies a default background color to present the image against. Note that viewers are not bound to honor this chunk; a viewer can choose to use a different background.
<p>For color type 3 (indexed color), the <tt><font face="新宋体">bKGD</font></tt> chunk contains: </p>
<pre>   Palette index:  1 byte
</pre>
The value is the palette index of the color to be used as background.
<p>For color types 0 anｄ 4 (grayscale, with oｒ without alpha), <tt><font face="新宋体">bKGD</font></tt> contains: </p>
<pre>   Gray:  2 bytes, range 0 .. (2^bitdepth)-1
</pre>
(For consistency, 2 bytes are used regardless of the image bit depth.) The value is the gray level to be used as background.
<p>For color types 2 anｄ 6 (truecolor, with oｒ without alpha), <tt><font face="新宋体">bKGD</font></tt> contains: </p>
<pre>   Red:   2 bytes, range 0 .. (2^bitdepth)-1
   Green: 2 bytes, range 0 .. (2^bitdepth)-1
   Blue:  2 bytes, range 0 .. (2^bitdepth)-1
</pre>
(For consistency, 2 bytes per sample are used regardless of the image bit depth.) This is the RGB color to be used as background.
<p>When present, the <tt><font face="新宋体">bKGD</font></tt> chunk must precede the first <tt><font face="新宋体">IDAT</font></tt> chunk, anｄ must follow the <tt><font face="新宋体">PLTE</font></tt> chunk, if any. </p>
<p>See Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Background-color"><font color="#800080">Background color (Section 10.7)</font></a>. </p>
<h4><a name="C.cHRM"><font color="#000000">4.2.2. <tt><font face="新宋体">cHRM </font></tt>Primary chromaticities anｄ white point</font></a></h4>
Applications that need device-independent specification of colors in a PNG file can use the <tt><font face="新宋体">cHRM</font></tt> chunk to specify the 1931 CIE <em>x,y</em> chromaticities of the red, green, anｄ blue primaries used in the image, anｄ the referenced white point. See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#ColorAppendix"><font color="#800080">Color Tutorial (Chapter 14)</font></a> for more information.
<p>The <tt><font face="新宋体">cHRM</font></tt> chunk contains: </p>
<pre>   White Point x: 4 bytes
   White Point y: 4 bytes
   Red x:         4 bytes
   Red y:         4 bytes
   Green x:       4 bytes
   Green y:       4 bytes
   Blue x:        4 bytes
   Blue y:        4 bytes
</pre>
Each value is encoded as a 4-byte unsigned integer, representing the <em>x</em> oｒ <em>y</em> value times 100000. For example, a value of 0.3127 would be stored as the integer 31270.
<p><tt><font face="新宋体">cHRM</font></tt> is allowed in all PNG files, although it is of little value for grayscale images. </p>
<p>If the encoder does not know the chromaticity values, it should not write a <tt><font face="新宋体">cHRM</font></tt> chunk; the absence of a <tt><font face="新宋体">cHRM</font></tt> chunk indicates that the image's primary colors are device-dependent. </p>
<p>If the <tt><font face="新宋体">cHRM</font></tt> chunk appears, it must precede the first <tt><font face="新宋体">IDAT</font></tt> chunk, anｄ it must also precede the <tt><font face="新宋体">PLTE</font></tt> chunk if present. </p>
<p>See Recommendations for Encoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Encoder-color-handling"><font color="#800080">Encoder color handling (Section 9.3)</font></a>, anｄ Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Decoder-color-handling"><font color="#800080">Decoder color handling (Section 10.6)</font></a>. </p>
<h4><a name="C.gAMA"><font color="#000000">4.2.3. <tt><font face="新宋体">gAMA </font></tt>Image gamma</font></a></h4>
The <tt><font face="新宋体">gAMA</font></tt> chunk specifies the gamma of the camera (or simulated camera) that produced the image, anｄ thus the gamma of the image with respect to the original scene. More precisely, the <tt><font face="新宋体">gAMA</font></tt> chunk encodes the file_gamma value, as defined in <a href="http://www.j2megame.cn/viewthread.php?tid=3292#GammaAppendix"><font color="#800080">Gamma Tutorial (Chapter 13)</font></a>.
<p>The <tt><font face="新宋体">gAMA</font></tt> chunk contains: </p>
<pre>   Image gamma: 4 bytes
</pre>
The value is encoded as a 4-byte unsigned integer, representing gamma times 100000. For example, a gamma of 0.45 would be stored as the integer 45000.
<p>If the encoder does not know the image's gamma value, it should not write a <tt><font face="新宋体">gAMA</font></tt> chunk; the absence of a <tt><font face="新宋体">gAMA</font></tt> chunk indicates that the gamma is unknown. </p>
<p>If the <tt><font face="新宋体">gAMA</font></tt> chunk appears, it must precede the first <tt><font face="新宋体">IDAT</font></tt> chunk, anｄ it must also precede the <tt><font face="新宋体">PLTE</font></tt> chunk if present. </p>
<p>See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Gamma-correction"><font color="#800080">Gamma correction (Section 2.7)</font></a>, Recommendations for Encoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Encoder-gamma-handling"><font color="#800080">Encoder gamma handling (Section 9.2)</font></a>, anｄ Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Decoder-gamma-handling"><font color="#800080">Decoder gamma handling (Section 10.5)</font></a>. </p>
<h4><a name="C.hIST"><font color="#000000">4.2.4. <tt><font face="新宋体">hIST </font></tt>Image histogram</font></a></h4>
The <tt><font face="新宋体">hIST</font></tt> chunk gives the approximate usage frequency of each color in the color palette. A histogram chunk can appear only when a palette chunk appears. If a viewer is unable to provide all the colors listed in the palette, the histogram may help it decide how to choose a subset of the colors for display.
<p>The <tt><font face="新宋体">hIST</font></tt> chunk contains a series of 2-byte (16 bit) unsigned integers. There must be exactly one entry for each entry in the <tt><font face="新宋体">PLTE</font></tt> 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. It is required that a histogram entry be nonzero if there are any pixels of that color. </p>
<p>When the palette is a suggested quantization of a truecolor 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 appear. </p>
<p>The <tt><font face="新宋体">hIST</font></tt> chunk, if it appears, must follow the <tt><font face="新宋体">PLTE</font></tt> chunk, anｄ must precede the first <tt><font face="新宋体">IDAT</font></tt> chunk. </p>
<p>See Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Palette-histograms"><font color="#800080">Palette histograms (Section 12.14)</font></a>, anｄ Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Suggested-palette-and-histogram-usage"><font color="#800080">Suggested-palette anｄ histogram usage (Section 10.10)</font></a>. </p>
<h4><a name="C.pHYs"><font color="#000000">4.2.5. <tt><font face="新宋体">pHYs </font></tt>Physical pixel dimensions</font></a></h4>
The <tt><font face="新宋体">pHYs</font></tt> chunk specifies the intended pixel size oｒ aspect ratio for display of the image. It contains:
<pre>   Pixels per unit, X axis: 4 bytes (unsigned integer)
   Pixels per unit, Y axis: 4 bytes (unsigned integer)
   Unit specifier:          1 byte
</pre>
The following values are legal for the unit specifier:
<pre>   0: unit is unknown
   1: unit is the meter
</pre>
When the unit specifier is 0, the <tt><font face="新宋体">pHYs</font></tt> chunk defines pixel aspect ratio only; the actual size of the pixels remains unspecified.
<p>Conversion note: one inch is equal to exactly 0.0254 meters. </p>
<p>If this ancillary chunk is not present, pixels are assumed to be square, anｄ the physical size of each pixel is unknown. </p>
<p>If present, this chunk must precede the first <tt><font face="新宋体">IDAT</font></tt> chunk. </p>
<p>See Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Pixel-dimensions"><font color="#800080">Pixel dimensions (Section 10.2)</font></a>. </p>
<h4><a name="C.sBIT"><font color="#000000">4.2.6. <tt><font face="新宋体">sBIT </font></tt>Significant bits</font></a></h4>
To simplify decoders, PNG specifies that only certain sample depths can be used, anｄ further specifies that sample values should be scaled to the full range of possible values at the sample depth. However, the <tt><font face="新宋体">sBIT</font></tt> chunk is provided in order to store the original number of significant bits. This allows decoders to recover the original data losslessly even if the data had a sample depth not directly supported by PNG. We recommend that an encoder emit an <tt><font face="新宋体">sBIT</font></tt> chunk if it has converted the data from a lower sample depth.
<p>For color type 0 (grayscale), the <tt><font face="新宋体">sBIT</font></tt> chunk contains a single byte, indicating the number of bits that were significant in the source data. </p>
<p>For color type 2 (truecolor), the <tt><font face="新宋体">sBIT</font></tt> chunk contains three bytes, indicating the number of bits that were significant in the source data for the red, green, anｄ blue channels, respectively. </p>
<p>For color type 3 (indexed color), the <tt><font face="新宋体">sBIT</font></tt> chunk contains three bytes, indicating the number of bits that were significant in the source data for the red, green, anｄ blue components of the palette entries, respectively. </p>
<p>For color type 4 (grayscale with alpha channel), the <tt><font face="新宋体">sBIT</font></tt> chunk contains two bytes, indicating the number of bits that were significant in the source grayscale data anｄ the source alpha data, respectively. </p>
<p>For color type 6 (truecolor with alpha channel), the <tt><font face="新宋体">sBIT</font></tt> chunk contains four bytes, indicating the number of bits that were significant in the source data for the red, green, blue anｄ alpha channels, respectively. </p>
<p>Each depth specified in <tt><font face="新宋体">sBIT</font></tt> must be greater than zero anｄ less than oｒ equal to the sample depth (which is 8 for indexed-color images, anｄ the bit depth given in <tt><font face="新宋体">IHDR</font></tt> for other color types). </p>
<p>A decoder need not pay attention to <tt><font face="新宋体">sBIT</font></tt>: the stored image is a valid PNG file of the sample depth indicated by <tt><font face="新宋体">IHDR</font></tt>. However, if the decoder wishes to recover the original data at its original precision, this can be done by right-shifting the stored samples (the stored palette entries, for an indexed-color image). The encoder must scale the data in such a way that the high-order bits match the original data. </p>
<p>If the <tt><font face="新宋体">sBIT</font></tt> chunk appears, it must precede the first <tt><font face="新宋体">IDAT</font></tt> chunk, anｄ it must also precede the <tt><font face="新宋体">PLTE</font></tt> chunk if present. </p>
<p>See Recommendations for Encoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Sample-depth-scaling"><font color="#800080">Sample depth scaling (Section 9.1)</font></a> anｄ Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Sample-depth-rescaling"><font color="#800080">Sample depth rescaling (Section 10.4)</font></a>. </p>
<h4><a name="C.tEXt"><font color="#000000">4.2.7. <tt><font face="新宋体">tEXt </font></tt>Textual data</font></a></h4>
Textual information that the encoder wishes to record with the image can be stored in <tt><font face="新宋体">tEXt</font></tt> chunks. Each <tt><font face="新宋体">tEXt</font></tt> chunk contains a keyword anｄ a text string, in the format:
<pre>   Keyword:        1-79 bytes (character string)
   Null separator: 1 byte
   Text:           n bytes (character string)
</pre>
The keyword anｄ text string are separated by a zero byte (null character). Neither the keyword nor the text string can contain a null character. Note that the text string is <em>not</em> null-terminated (the length of the chunk is sufficient information to locate the ending). The keyword must be at least one character anｄ less than 80 characters long. The text string can be of any length from zero bytes up to the maximum permissible chunk size less the length of the keyword anｄ separator.
<p>Any number of <tt><font face="新宋体">tEXt</font></tt> chunks can appear, anｄ more than one with the same keyword is permissible. </p>
<p>The keyword indicates the type of information represented by the text string. The following keywords are predefined anｄ should be used where appropriate: </p>
<pre>   Title            Short (one line) title oｒ caption for image
   Author           Name of image's creator
   Description      Description of image (possibly long)
   Copyright        Copyright notice
   Creation Time    Time of original image creation
   Software         Software used to create the image
   Disclaimer       Legal disclaimer
   Warning          Warning of nature of content
   Source           Device used to create the image
   Comment          Miscellaneous comment; conversion from
                    GIF comment
</pre>
For the Creation Time keyword, the date format defined in section 5.2.14 of RFC 1123 is suggested, but not required <a href="ftp://ds.internic.net/rfc/rfc1123.txt"><font color="#0000ff">[RFC-1123]</font></a>. Decoders should allow for free-format text associated with this oｒ any other keyword.
<p>Other keywords may be invented for other purposes. Keywords of general interest can be registered with the maintainers of the PNG specification. However, 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 will be used for incompatible purposes by different people.) </p>
<p>Both keyword anｄ text are interpreted according to the ISO 8859-1 (Latin-1) character set <a href="ftp://ftp.uu.net/graphics/png/documents/"><font color="#0000ff">[ISO-8859]</font></a>. The text string can contain any Latin-1 character. Newlines in the text string should be represented by a single linefeed character (decimal 10); use of other control characters in the text is discouraged. </p>
<p>Keywords must contain only printable Latin-1 characters anｄ spaces; that is, only character codes 32-126 anｄ 161-255 decimal are allowed. To reduce the chances for human misreading of a keyword, leading anｄ trailing spaces are forbidden, as are consecutive spaces. Note also that the non-breaking space (code 160) is not permitted in keywords, since it is visually indistinguishable from an ordinary space. </p>
<p>Keywords must 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. </p>
<p>See Recommendations for Encoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Text-chunk-processing"><font color="#800080">Text chunk processing (Section 9.7)</font></a> anｄ Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Text-chunk-processing"><font color="#800080">Text chunk processing (Section 10.11)</font></a>. </p>
<h4><a name="C.tIME"><font color="#000000">4.2.8. <tt><font face="新宋体">tIME </font></tt>Image last-modification time</font></a></h4>
The <tt><font face="新宋体">tIME</font></tt> chunk gives the time of the last image modification (<em>not</em> the time of initial image creation). It contains:
<pre>   Year:   2 bytes (complete; for example, 1995, <em>not</em> 95)
   Month:  1 byte (1-12)
   Day:    1 byte (1-31)
   Hour:   1 byte (0-23)
   Minute: 1 byte (0-59)
   Second: 1 byte (0-60)    (yes, 60, for leap seconds; not 61,
                             a common error)
</pre>
Universal Time (UTC, also called GMT) should be specified rather than local time.
<p>The <tt><font face="新宋体">tIME</font></tt> chunk is intended for use as an automatically-applied time stamp that is updated whenever the image data is changed. It is recommended that <tt><font face="新宋体">tIME</font></tt> not be changed by PNG editors that do not change the image data. See also the Creation Time <tt><font face="新宋体">tEXt</font></tt> keyword, which can be used for a user-supplied time. </p>
<h4><a name="C.tRNS"><font color="#000000">4.2.9. <tt><font face="新宋体">tRNS </font></tt>Transparency</font></a></h4>
The <tt><font face="新宋体">tRNS</font></tt> chunk specifies that the image uses simple transparency: either alpha values associated with palette entries (for indexed-color images) oｒ a single transparent color (for grayscale anｄ truecolor images). Although simple transparency is not as elegant as the full alpha channel, it requires less storage space anｄ is sufficient for many common cases.
<p>For color type 3 (indexed color), the <tt><font face="新宋体">tRNS</font></tt> chunk contains a series of one-byte alpha values, corresponding to entries in the <tt><font face="新宋体">PLTE</font></tt> chunk: </p>
<pre>   Alpha for palette index 0:  1 byte
   Alpha for palette index 1:  1 byte
   ... etc ...
</pre>
Each entry indicates that pixels of the corresponding palette index must 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 <tt><font face="新宋体">tRNS</font></tt> chunk must not contain more alpha values than there are palette entries, but <tt><font face="新宋体">tRNS</font></tt> <em>can contain fewer values than there are palette entries</em>. 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 <tt><font face="新宋体">tRNS</font></tt> chunk is needed.
<p>For color type 0 (grayscale), the <tt><font face="新宋体">tRNS</font></tt> chunk contains a single gray level value, stored in the format: </p>
<pre>   Gray:  2 bytes, range 0 .. (2^bitdepth)-1
</pre>
(For consistency, 2 bytes are used regardless of the image bit depth.) Pixels of the specified gray level are to be treated as transparent (equivalent to alpha value 0); all other pixels are to be treated as fully opaque (alpha value (2^bitdepth)-1).
<p>For color type 2 (truecolor), the <tt><font face="新宋体">tRNS</font></tt> chunk contains a single RGB color value, stored in the format: </p>
<pre>   Red:   2 bytes, range 0 .. (2^bitdepth)-1
   Green: 2 bytes, range 0 .. (2^bitdepth)-1
   Blue:  2 bytes, range 0 .. (2^bitdepth)-1
</pre>
(For consistency, 2 bytes per sample are used regardless of the image bit depth.) Pixels of the specified color value are to be treated as transparent (equivalent to alpha value 0); all other pixels are to be treated as fully opaque (alpha value (2^bitdepth)-1).
<p><tt><font face="新宋体">tRNS</font></tt> is prohibited for color types 4 anｄ 6, since a full alpha channel is already present in those cases. </p>
<p>Note: when dealing with 16-bit grayscale oｒ truecolor data, it is important to compare both bytes of the sample values to determine whether a pixel is transparent. Although decoders may drop the low-order byte of the samples for display, this must not occur until after the data has been tested for transparency. For example, if the grayscale level 0x0001 is specified to be transparent, it would be incorrect to compare only the high-order byte anｄ decide that 0x0002 is also transparent. </p>
<p>When present, the <tt><font face="新宋体">tRNS</font></tt> chunk must precede the first <tt><font face="新宋体">IDAT</font></tt> chunk, anｄ must follow the <tt><font face="新宋体">PLTE</font></tt> chunk, if any. </p>
<h4><a name="C.zTXt"><font color="#000000">4.2.10. <tt><font face="新宋体">zTXt </font></tt>Compressed textual data</font></a></h4>
The <tt><font face="新宋体">zTXt</font></tt> chunk contains textual data, just as <tt><font face="新宋体">tEXt</font></tt> does; however, <tt><font face="新宋体">zTXt</font></tt> takes advantage of compression. <tt><font face="新宋体">zTXt</font></tt> anｄ <tt><font face="新宋体">tEXt</font></tt> chunks are semantically equivalent, but <tt><font face="新宋体">zTXt</font></tt> is recommended for storing large blocks of text.
<p>A <tt><font face="新宋体">zTXt</font></tt> chunk contains: </p>
<pre>   Keyword:            1-79 bytes (character string)
   Null separator:     1 byte
   Compression method: 1 byte
   Compressed text:    n bytes
</pre>
The keyword anｄ null separator are exactly the same as in the <tt><font face="新宋体">tEXt</font></tt> chunk. Note that the keyword is not compressed. The compression method byte identifies the compression method used in this <tt><font face="新宋体">zTXt</font></tt> chunk. The only value presently defined for it is 0 (deflate/inflate compression). The compression method byte is followed by a compressed datastream that makes up the remainder of the chunk. For compression method 0, this datastream adheres to the zlib datastream format (see <a href="http://www.j2megame.cn/viewthread.php?tid=3292#Compression"><font color="#800080">Deflate/Inflate Compression, Chapter 5</font></a>). Decompression of this datastream yields Latin-1 text that is identical to the text that would be stored in an equivalent <tt><font face="新宋体">tEXt</font></tt> chunk.
<p>Any number of <tt><font face="新宋体">zTXt</font></tt> anｄ <tt><font face="新宋体">tEXt</font></tt> chunks can appear in the same file. See the preceding definition of the <tt><font face="新宋体">tEXt</font></tt> chunk for the predefined keywords anｄ the recommended format of the text. </p>
<p>See Recommendations for Encoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Text-chunk-processing"><font color="#800080">Text chunk processing (Section 9.7)</font></a>, anｄ Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Text-chunk-processing"><font color="#800080">Text chunk processing (Section 10.11)</font></a>. </p>
<h3><a name="C.Summary-of-standard-chunks"><font color="#000000">4.3. Summary of standard chunks</font></a></h3>
This table summarizes some properties of the standard chunk types.
<pre>   Critical chunks (must appear in this order, except PLTE
                    is optional):
   
           Name  Multiple  Ordering constraints
                   OK?
   
           IHDR    No      Must be first
           PLTE    No      Before IDAT
           IDAT    Yes     Multiple IDATs must be consecutive
           IEND    No      Must be last
   
   Ancillary chunks (need not appear in this order):
   
           Name  Multiple  Ordering constraints
                   OK?
   
           cHRM    No      Before PLTE anｄ IDAT
           gAMA    No      Before PLTE anｄ IDAT
           sBIT    No      Before PLTE anｄ IDAT
           bKGD    No      After PLTE; before IDAT
           hIST    No      After PLTE; before IDAT
           tRNS    No      After PLTE; before IDAT
           pHYs    No      Before IDAT
           tIME    No      None
           tEXt    Yes     None
           zTXt    Yes     None
</pre>
<p>Standard keywords for <tt><font face="新宋体">tEXt</font></tt> anｄ <tt><font face="新宋体">zTXt</font></tt> chunks: </p>
<pre>   Title            Short (one line) title oｒ caption for image
   Author           Name of image's creator
   Description      Description of image (possibly long)
   Copyright        Copyright notice
   Creation Time    Time of original image creation
   Software         Software used to create the image
   Disclaimer       Legal disclaimer
   Warning          Warning of nature of content
   Source           Device used to create the image
   Comment          Miscellaneous comment; conversion from
                    GIF comment
</pre>
<h3><a name="C.Additional-chunk-types"><font color="#000000">4.4. Additional chunk types</font></a></h3>
Additional public PNG chunk types are defined in the document &quot;PNG Special-Purpose Public Chunks&quot; <a href="ftp://ftp.uu.net/graphics/png/documents/pngextensions.html"><font color="#0000ff">[PNG-EXTENSIONS]</font></a>. Chunks described there are expected to be less widely supported than those defined in this specification. 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 specification maintainers at <a href="mailto:png-[email]info@uunet.uu.net[/email]"><tt><font face="新宋体" color="#0000ff">png-[email]info@uunet.uu.net[/email]</font></tt></a> oｒ at <a href="mailto:png-[email]group@w3.org[/email]"><tt><font face="新宋体" color="#0000ff">png-[email]group@w3.org[/email]</font></tt></a>.
<p>New public chunks will only be registered if they are of use to others anｄ do not violate the design philosophy of PNG. Chunk registration is not automatic, although it is the intent of the authors that it be straightforward when a new chunk of potentially wide application is needed. Note that the creation of new critical chunk types is discouraged unless absolutely necessary. </p>
<p>Applications can also use private chunk types to carry data that is not of interest to other applications. See Recommendations for Encoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Use-of-private-chunks"><font color="#800080">Use of private chunks (Section 9.8)</font></a>. </p>
<p>Decoders must be prepared to encounter unrecognized public oｒ private chunk type codes. Unrecognized chunk types must be handled as described in <a href="http://www.j2megame.cn/viewthread.php?tid=3292#Chunk-naming-conventions"><font color="#800080">Chunk naming conventions (Section 3.3)</font></a>. </p>
<h2><a name="Compression"><font color="#000000">5. Deflate/Inflate Compression</font></a></h2>
PNG compression method 0 (the only compression method presently defined for PNG) specifies deflate/inflate compression with a 32K sliding window. Deflate compression is an LZ77 derivative used in zip, gzip, pkzip anｄ related programs. Extensive research has been done supporting its patent-free status. Portable C implementations are freely available.
<p>Deflate-compressed datastreams within PNG are stored in the &quot;zlib&quot; format, which has the structure: </p>
<pre>   Compression method/flags code: 1 byte
   Additional flags/check bits:   1 byte
   Compressed data blocks:        n bytes
   Check value:                   4 bytes
</pre>
Further details on this format are given in the zlib specification <a href="ftp://ds.internic.net/rfc/rfc1950.txt"><font color="#0000ff">[RFC-1950]</font></a>.
<p>For PNG compression method 0, the zlib compression method/flags code must specify method code 8 (&quot;deflate&quot; compression) anｄ an LZ77 window size of not more than 32K. Note that the zlib compression method number is not the same as the PNG compression method number. The additional flags must not specify a preset dictionary. </p>
<p>The compressed data within the zlib datastream is stored as a series of blocks, each of which can represent raw (uncompressed) data, LZ77-compressed data encoded with fixed Huffman codes, oｒ 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 anｄ the encoding are given in the deflate specification <a href="ftp://ds.internic.net/rfc/rfc1951.txt"><font color="#0000ff">[RFC-1951]</font></a>. </p>
<p>The check value stored at the end of the zlib datastream is calculated on the uncompressed data represented by the datastream. Note that the algorithm used is not the same as the CRC calculation used for PNG chunk check values. The zlib check value is useful mainly as a cross-check that the deflate anｄ inflate algorithms are implemented correctly. Verifying the chunk CRCs provides adequate confidence that the PNG file has been transmitted undamaged. </p>
<p>In a PNG file, the concatenation of the contents of all the <tt><font face="新宋体">IDAT</font></tt> chunks makes up a zlib datastream as specified above. This datastream decompresses to filtered image data as described elsewhere in this document. </p>
<p>It is important to emphasize that the boundaries between <tt><font face="新宋体">IDAT</font></tt> chunks are arbitrary anｄ can fall anywhere in the zlib datastream. There is not necessarily any correlation between <tt><font face="新宋体">IDAT</font></tt> chunk boundaries anｄ deflate block boundaries oｒ any other feature of the zlib data. For example, it is entirely possible for the terminating zlib check value to be split across <tt><font face="新宋体">IDAT</font></tt> chunks. </p>
<p>In the same vein, there is no required correlation between the structure of the image data (i.e., scanline boundaries) anｄ deflate block boundaries oｒ <tt><font face="新宋体">IDAT</font></tt> chunk boundaries. The complete image data is represented by a single zlib datastream that is stored in some number of <tt><font face="新宋体">IDAT</font></tt> chunks; a decoder that assumes any more than this is incorrect. (Of course, some encoder implementations may emit files in which some of these structures are indeed related. But decoders cannot rely on this.) </p>
<p>PNG also uses zlib datastreams in <tt><font face="新宋体">zTXt</font></tt> chunks. In a <tt><font face="新宋体">zTXt</font></tt> chunk, the remainder of the chunk following the compression method byte is a zlib datastream as specified above. This datastream decompresses to the user-readable text described by the chunk's keyword. Unlike the image data, such datastreams are not split across chunks; each <tt><font face="新宋体">zTXt</font></tt> chunk contains an independent zlib datastream. </p>
<p>Additional documentation anｄ portable C code for deflate anｄ inflate are available from the Info-ZIP archives at <a href="ftp://ftp.uu.net/pub/archiving/zip/"><code><font face="新宋体" color="#0000ff">&lt;URL:[url]ftp://ftp.uu.net/pub/archiving/zip/&gt;[/url];</font></code></a>. </p>
<h2><a name="Filters"><font color="#000000">6. Filter Algorithms</font></a></h2>
This chapter describes the filter algorithms that can be applied before compression. The purpose of these filters is to prepare the image data for optimum compression.
<h3><a name="Filter-types"><font color="#000000">6.1. Filter types</font></a></h3>
PNG filter method 0 defines five basic filter types:
<pre>   Type    Name
   
   0       None
   1       Sub
   2       Up
   3       Average
   4       Paeth
</pre>
(Note that filter method 0 in <tt><font face="新宋体">IHDR</font></tt> specifies exactly this set of five filter types. If the set of filter types is ever extended, a different filter method number will be assigned to the extended set, so that decoders need not decompress the data to discover that it contains unsupported filter types.)
<p>The encoder can choose which of these filter algorithms to apply on a scanline-by-scanline basis. In the image data sent to the compression step, each scanline is preceded by a filter type byte that specifies the filter algorithm used for that scanline. </p>
<p>Filtering algorithms are applied to <strong>bytes</strong>, not to pixels, regardless of the bit depth oｒ color type of the image. The filtering algorithms work on the byte sequence formed by a scanline that has been represented as described in <a href="http://www.j2megame.cn/viewthread.php?tid=3292#DR.Image-layout"><font color="#800080">Image layout (Section 2.3)</font></a>. If the image includes an alpha channel, the alpha data is filtered in the same way as the image data. </p>
<p>When the image is interlaced, each pass of the interlace pattern is treated as an independent image for filtering purposes. The filters work on the byte sequences formed by the pixels actually transmitted during a pass, anｄ the &quot;previous scanline&quot; is the one previously transmitted in the same pass, not the one adjacent in the complete image. Note that the subimage transmitted in any one pass is always rectangular, but is of smaller width and/or height than the complete image. Filtering is not applied when this subimage is empty. </p>
<p>For all filters, the bytes &quot;to the left of&quot; the first pixel in a scanline must be treated as being zero. For filters that refer to the prior scanline, the entire prior scanline must be treated as being zeroes for the first scanline of an image (or of a pass of an interlaced image). </p>
<p>To reverse the effect of a filter, the decoder must use the decoded values of the prior pixel on the same line, the pixel immediately above the current pixel on the prior line, anｄ the pixel just to the left of the pixel above. This implies that at least one scanline's worth of image data will have 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 that refers to it. </p>
<p>PNG imposes no restriction on which filter types can be applied to an image. However, the filters are not equally effective on all types of data. See Recommendations for Encoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#E.Filter-selection"><font color="#800080">Filter selection (Section 9.6)</font></a>. </p>
<p>See also Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Filtering"><font color="#800080">Filtering (Section 12.9)</font></a>. </p>
<h3><a name="Filter-type-0-None"><font color="#000000">6.2. Filter type 0: None</font></a></h3>
With the None filter, the scanline is transmitted unmodified; it is only necessary to inserｔ a filter type byte before the data.
<h3><a name="Filter-type-1-Sub"><font color="#000000">6.3. Filter type 1: Sub</font></a></h3>
The Sub filter transmits the difference between each byte anｄ the value of the corresponding byte of the prior pixel.
<p>To compute the Sub filter, apply the following formula to each byte of the scanline: </p>
<pre>   Sub(x) = Raw(x) - Raw(x-bpp)
</pre>
where <tt><font face="新宋体">x</font></tt> ranges from zero to the number of bytes representing the scanline minus one, <tt><font face="新宋体">Raw(x)</font></tt> refers to the raw data byte at that byte position in the scanline, anｄ <tt><font face="新宋体">bpp</font></tt> is defined as the number of bytes per complete pixel, rounding up to one. For example, for color type 2 with a bit depth of 16, bpp is equal to 6 (three samples, two bytes per sample); for color type 0 with a bit depth of 2, bpp is equal to 1 (rounding up); for color type 4 with a bit depth of 16, bpp is equal to 4 (two-byte grayscale sample, plus two-byte alpha sample).
<p>Note this computation is done for each <strong>byte</strong>, regardless of bit depth. In a 16-bit image, each MSB is predicted from the preceding MSB anｄ each LSB from the preceding LSB, because of the way that <tt><font face="新宋体">bpp</font></tt> is defined. </p>
<p>Unsigned arithmetic modulo 256 is used, so that both the inputs anｄ outputs fit into bytes. The sequence of <tt><font face="新宋体">Sub</font></tt> values is transmitted as the filtered scanline. </p>
<p>For all x &lt; 0, assume Raw(x) = 0. </p>
<p>To reverse the effect of the Sub filter after decompression, output the following value: </p>
<pre>   Sub(x) + Raw(x-bpp)
</pre>
(computed mod 256), where <tt><font face="新宋体">Raw</font></tt> refers to the bytes already decoded.
<h3><a name="Filter-type-2-Up"><font color="#000000">6.4. Filter type 2: Up</font></a></h3>
The Up filter is just like the Sub filter except that the pixel immediately above the current pixel, rather than just to its left, is used as the predictor.
<p>To compute the Up filter, apply the following formula to each byte of the scanline: </p>
<pre>   Up(x) = Raw(x) - Prior(x)
</pre>
where <tt><font face="新宋体">x</font></tt> ranges from zero to the number of bytes representing the scanline minus one, <tt><font face="新宋体">Raw(x)</font></tt> refers to the raw data byte at that byte position in the scanline, anｄ <tt><font face="新宋体">Prior(x)</font></tt> refers to the unfiltered bytes of the prior scanline.
<p>Note this is done for each <strong>byte</strong>, regardless of bit depth. Unsigned arithmetic modulo 256 is used, so that both the inputs anｄ outputs fit into bytes. The sequence of <tt><font face="新宋体">Up</font></tt> values is transmitted as the filtered scanline. </p>
<p>On the first scanline of an image (or of a pass of an interlaced image), assume Prior(x) = 0 for all x. </p>
<p>To reverse the effect of the Up filter after decompression, output the following value: </p>
<pre>   Up(x) + Prior(x)
</pre>
(computed mod 256), where <tt><font face="新宋体">Prior</font></tt> refers to the decoded bytes of the prior scanline.
<h3><a name="Filter-type-3-Average"><font color="#000000">6.5. Filter type 3: Average</font></a></h3>
The Average filter uses the average of the two neighboring pixels (left anｄ above) to predict the value of a pixel.
<p>To compute the Average filter, apply the following formula to each byte of the scanline: </p>
<pre>   Average(x) = Raw(x) - floor((Raw(x-bpp)+Prior(x))/2)
</pre>
where <tt><font face="新宋体">x</font></tt> ranges from zero to the number of bytes representing the scanline minus one, <tt><font face="新宋体">Raw(x)</font></tt> refers to the raw data byte at that byte position in the scanline, <tt><font face="新宋体">Prior(x)</font></tt> refers to the unfiltered bytes of the prior scanline, anｄ <tt><font face="新宋体">bpp</font></tt> is defined as for the Sub filter.
<p>Note this is done for each <strong>byte</strong>, regardless of bit depth. The sequence of <tt><font face="新宋体">Average</font></tt> values is transmitted as the filtered scanline. </p>
<p>The subtraction of the predicted value from the raw byte must be done modulo 256, so that both the inputs anｄ outputs fit into bytes. However, the sum <tt><font face="新宋体">Raw(x-bpp)+Prior(x)</font></tt> must be formed without overflow (using at least nine-bit arithmetic). <tt><font face="新宋体">floor()</font></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 oｒ right shift operation. </p>
<p>For all x &lt; 0, assume Raw(x) = 0. On the first scanline of an image (or of a pass of an interlaced image), assume Prior(x) = 0 for all x. </p>
<p>To reverse the effect of the Average filter after decompression, output the following value: </p>
<pre>   Average(x) + floor((Raw(x-bpp)+Prior(x))/2)
</pre>
where the result is computed mod 256, but the prediction is calculated in the same way as for encoding. <tt><font face="新宋体">Raw</font></tt> refers to the bytes already decoded, anｄ <tt><font face="新宋体">Prior</font></tt> refers to the decoded bytes of the prior scanline.
<h3><a name="Filter-type-4-Paeth"><font color="#000000">6.6. Filter type 4: Paeth</font></a></h3>
The Paeth filter computes a simple linear function of the three neighboring pixels (left, above, upper left), then chooses as predictor the neighboring pixel closest to the computed value. This technique is due to Alan W. Paeth [PAETH].
<p>To compute the Paeth filter, apply the following formula to each byte of the scanline: </p>
<pre>   Paeth(x) = Raw(x) - PaethPredictor(Raw(x-bpp), Prior(x),
                                      Prior(x-bpp))
</pre>
where <tt><font face="新宋体">x</font></tt> ranges from zero to the number of bytes representing the scanline minus one, <tt><font face="新宋体">Raw(x)</font></tt> refers to the raw data byte at that byte position in the scanline, <tt><font face="新宋体">Prior(x)</font></tt> refers to the unfiltered bytes of the prior scanline, anｄ <tt><font face="新宋体">bpp</font></tt> is defined as for the Sub filter.
<p>Note this is done for each <strong>byte</strong>, regardless of bit depth. Unsigned arithmetic modulo 256 is used, so that both the inputs anｄ outputs fit into bytes. The sequence of <tt><font face="新宋体">Paeth</font></tt> values is transmitted as the filtered scanline. </p>
<p>The PaethPredictor function is defined by the following pseudocode: </p>
<pre>   function PaethPredictor (a, b, c)
   begin
        ; a = left, b = above, c = upper left
        p := a + b - c        ; initial estimate
        pa := abs(p - a)      ; distances to a, b, c
        pb := abs(p - b)
        pc := abs(p - c)
        ; return nearest of a,b,c,
        ; breaking ties in order a,b,c.
        if pa &lt;= pb anｄ pa &lt;= pc then return a
        else if pb &lt;= pc then return b
        else return c
   end
</pre>
The calculations within the PaethPredictor function must be performed exactly, without overflow. Arithmetic modulo 256 is to be used only for the final step of subtracting the function result from the target byte value.
<p><strong>Note that the order in which ties are broken is critical anｄ must not be altered.</strong> The tie break order is: pixel to the left, pixel above, pixel to the upper left. (This order differs from that given in Paeth's article.) </p>
<p>For all x &lt; 0, assume Raw(x) = 0 anｄ Prior(x) = 0. On the first scanline of an image (or of a pass of an interlaced image), assume Prior(x) = 0 for all x. </p>
<p>To reverse the effect of the Paeth filter after decompression, output the following value: </p>
<pre>   Paeth(x) + PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp))
</pre>
(computed mod 256), where <tt><font face="新宋体">Raw</font></tt> anｄ <tt><font face="新宋体">Prior</font></tt> refer to bytes already decoded. Exactly the same PaethPredictor function is used by both encoder anｄ decoder.
<h2><a name="Ordering"><font color="#000000">7. Chunk Ordering Rules</font></a></h2>
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 editing program cannot know what to do when it encounters an unknown chunk.
<p>We define a &quot;PNG editor&quot; as a program that modifies a PNG file anｄ wishes to preserve as much as possible of the ancillary information in the file. Two examples of PNG editors are a program that adds oｒ modifies text chunks, anｄ a program that adds a suggested palette to a truecolor PNG file. Ordinary image editors are not PNG editors in this sense, because they usually discard all unrecognized information while reading in an image. (Note: we strongly encourage programs handling PNG files to preserve ancillary information whenever possible.) </p>
<p>As an example of possible problems, consider a hypothetical new ancillary chunk type that is safe-to-copy anｄ is required to appear after <tt><font face="新宋体">PLTE</font></tt> if <tt><font face="新宋体">PLTE</font></tt> is present. If our program to add a suggested <tt><font face="新宋体">PLTE</font></tt> does not recognize this new chunk, it may inserｔ <tt><font face="新宋体">PLTE</font></tt> in the wrong place, namely after the new chunk. We could prevent such problems 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, we put some constraints on both the behavior of PNG editors anｄ the allowed ordering requirements for chunks. </p>
<h3><a name="Behavior-of-PNG-editors"><font color="#000000">7.1. Behavior of PNG editors</font></a></h3>
The rules for PNG editors are:
<ul>
    <li>When copying an unknown unsafe-to-copy ancillary chunk, a PNG editor must not move the chunk relative to any critical chunk. It can 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 must not add, delete, modify, oｒ reorder critical chunks if it is preserving unknown unsafe-to-copy chunks.) </li>
    <li>When copying an unknown safe-to-copy ancillary chunk, a PNG editor must not move the chunk from before <tt><font face="新宋体">IDAT</font></tt> to after <tt><font face="新宋体">IDAT</font></tt> oｒ vice versa. (This is well defined because <tt><font face="新宋体">IDAT</font></tt> is always present.) Any other reordering is permitted. </li>
    <li>When copying a <em>known</em> ancillary chunk type, an editor need only honor the specific chunk ordering rules that exist for that chunk type. However, it can always choose to apply the above general rules instead. </li>
    <li>PNG editors must give up on encountering an unknown critical chunk type, because there is no way to be certain that a valid file will result from modifying a file containing such a chunk. (Note that simply discarding the chunk is not good enough, because it might have unknown implications for the interpretation of other chunks.) </li>
</ul>
These rules are expressed in terms of copying chunks from an input file to an output file, but they apply in the obvious way if a PNG file is modified in place.
<p>See also <a href="http://www.j2megame.cn/viewthread.php?tid=3292#Chunk-naming-conventions"><font color="#800080">Chunk naming conventions (Section 3.3)</font></a>. </p>
<h3><a name="Ordering-of-ancillary-chunks"><font color="#000000">7.2. Ordering of ancillary chunks</font></a></h3>
The ordering rules for an ancillary chunk type cannot be any stricter than this:
<ul>
    <li>Unsafe-to-copy chunks can have ordering requirements relative to critical chunks. </li>
    <li>Safe-to-copy chunks can have ordering requirements relative to <tt><font face="新宋体">IDAT</font></tt>. </li>
</ul>
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 (<a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.Summary-of-standard-chunks"><font color="#800080">Summary of standard chunks, Section 4.3</font></a>).
<p><strong>Decoders must not assume more about the positioning of any ancillary chunk than is specified by the chunk ordering rules.</strong> In particular, it is never valid to assume that a specific ancillary chunk type occurs with any particular positioning relative to other ancillary chunks. (For example, it is unsafe to assume that your private ancillary chunk occurs immediately before <tt><font face="新宋体">IEND</font></tt>. Even if your application always writes it there, a PNG editor might have inserted some other ancillary chunk after it. But you can safely assume that your chunk will remain somewhere between <tt><font face="新宋体">IDAT</font></tt> anｄ <tt><font face="新宋体">IEND</font></tt>.) </p>
<h3><a name="Ordering-of-critical-chunks"><font color="#000000">7.3. Ordering of critical chunks</font></a></h3>
Critical chunks can have arbitrary ordering requirements, because PNG editors are required to give up if they encounter unknown critical chunks. For example, <tt><font face="新宋体">IHDR</font></tt> has the special ordering rule that it must always appear first. A PNG editor, oｒ indeed any PNG-writing program, must know anｄ follow the ordering rules for any critical chunk type that it can emit.
<h2><a name="Misc"><font color="#000000">8. Miscellaneous Topics</font></a></h2>
<h3><a name="File-name-extension"><font color="#000000">8.1. File name extension</font></a></h3>
On systems where file names customarily include an extension signifying file type, the extension &quot;<tt><font face="新宋体">.png</font></tt>&quot; is recommended for PNG files. Lower case &quot;<tt><font face="新宋体">.png</font></tt>&quot; is preferred if file names are case-sensitive.
<h3><a name="Media-type"><font color="#000000">8.2. Internet media type</font></a></h3>
The PNG authors intend to register &quot;<tt><font face="新宋体">image/png</font></tt>&quot; as the Internet Media Type for PNG [<a href="ftp://ds.internic.net/rfc/rfc1521.txt"><font color="#0000ff">RFC-1521</font></a>, <a href="ftp://ds.internic.net/rfc/rfc1590.txt"><font color="#0000ff">RFC-1590</font></a>]. At the date of this document, the media type registration process had not been completed. It is recommended that implementations also recognize the interim media type &quot;<tt><font face="新宋体">image/x-png</font></tt>&quot;.
<h3><a name="Macintosh-file-layout"><font color="#000000">8.3. Macintosh file layout</font></a></h3>
In the Apple Macintosh system, the following conventions are recommended:
<ul>
    <li>The four-byte file type code for PNG files is &quot;<tt><font face="新宋体">PNGf</font></tt>&quot;. (This code has been registered with Apple for PNG files.) The creator code will vary depending on the creating application. </li>
    <li>The contents of the data fork must be a PNG file exactly as described in the rest of this specification. </li>
    <li>The contents of the resource fork are unspecified. It may be empty oｒ 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>
</ul>
<h3><a name="Multiple-image-extension"><font color="#000000">8.4. Multiple-image extension</font></a></h3>
PNG itself is strictly a single-image format. However, it may be necessary to store multiple images within one file; for example, this is needed to convert some GIF files. In the future, a multiple-image format based on PNG may be defined. Such a format will be considered a separate file format anｄ will have a different signature. PNG-supporting applications may oｒ may not choose to support the multiple-image format.
<p>See Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.Why-not-these-features"><font color="#800080">Why not these features? (Section 12.3)</font></a>. </p>
<h3><a name="Security-considerations"><font color="#000000">8.5. Security considerations</font></a></h3>
A PNG file oｒ datastream is composed of a collection of explicitly typed &quot;chunks&quot;. 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>The possible security risks associated with future chunk types cannot be specified at this time. Security issues will be considered when evaluating chunks proposed for registration as public chunks. There is no additional security risk associated with unknown oｒ unimplemented chunk types, because such chunks will be ignored, oｒ at most be copied into another PNG file. </p>
<p>The <tt><font face="新宋体">tEXt</font></tt> anｄ <tt><font face="新宋体">zTXt</font></tt> chunks contain data that is 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 oｒ terminals could behave in undesirable anｄ insecure ways. We recommend that decoders filter out control characters to avoid this risk; see Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Text-chunk-processing"><font color="#800080">Text chunk processing (Section 10.11)</font></a>. </p>
<p>Because every chunk's length is available at its beginning, anｄ because every chunk has a CRC trailer, there is a very robust defense against corrupted data anｄ against fraudulent chunks that attempt to overflow the decoder's buffers. Also, 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 <tt><font face="新宋体">IHDR</font></tt> chunk is not checked anｄ the width oｒ height fields are corrupted. See Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Error-checking"><font color="#800080">Error checking (Section 10.1)</font></a>. </p>
<p>A poorly written decoder might be subject to buffer overflow, because chunks can be extremely large, up to (2^31)-1 bytes long. But properly written decoders will handle large chunks without difficulty. </p>
<h2><a name="Encoders"><font color="#000000">9. Recommendations for Encoders</font></a></h2>
This chapter gives some recommendations for encoder behavior. The only absolute requirement on a PNG encoder is that it produce files that conform to the format specified in the preceding chapters. However, best results will usually be achieved by following these recommendations.
<h3><a name="E.Sample-depth-scaling"><font color="#000000">9.1. Sample depth scaling</font></a></h3>
When encoding input samples that have a sample depth that cannot be directly represented in PNG, the encoder must scale the samples up to a sample depth that is allowed by PNG. The most accurate scaling method is the linear equation
<pre>   output = ROUND(input * MAXOUTSAMPLE / MAXINSAMPLE)
</pre>
where the input samples range from 0 to MAXINSAMPLE anｄ the outputs range from 0 to MAXOUTSAMPLE (which is (2^sampledepth)-1).
<p>A close approximation to the linear scaling method can be achieved by &quot;left bit replication&quot;, which is shifting the valid bits to begin in the most significant bit anｄ repeating the most significant bits into the open bits. This method is often faster to compute than linear scaling. As an 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>
Left bit replication gives a value of 222:
<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>
which matches the value computed by the linear equation. Left bit replication usually gives the same value as linear scaling, anｄ is never off by more than one.
<p>A distinctly less accurate approximation is obtained by simply left-shifting the input value anｄ 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-eight-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 must <strong>not</strong> be used for alpha channel data, however, since many decoders will special-case alpha values of all zeroes anｄ all ones. It is important to represent both those values exactly in the scaled data. </p>
<p>When the encoder writes an <tt><font face="新宋体">sBIT</font></tt> 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 <tt><font face="新宋体">sBIT</font></tt> chunk specifies a sample depth of S, the high-order S bits of the stored data must 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. Note that all the above scaling methods meet this restriction. </p>
<p>When scaling up source 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. However, this is not a requirement, anｄ 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 <tt><font face="新宋体">sBIT</font></tt> chunk not be written for such images, since <tt><font face="新宋体">sBIT</font></tt> suggests that the original data range was exactly 0..2^S-1. </p>
<h3><a name="E.Encoder-gamma-handling"><font color="#000000">9.2. Encoder gamma handling</font></a></h3>
See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#GammaAppendix"><font color="#800080">Gamma Tutorial (Chapter 13)</font></a> if you aren't already familiar with gamma issues.
<p>Proper handling of gamma encoding anｄ the <tt><font face="新宋体">gAMA</font></tt> chunk in an encoder depends on the prior history of the sample values anｄ on whether these values have already been quantized to integers. </p>
<p>If the encoder has access to sample intensity values in floating-point oｒ high-precision integer form (perhaps from a computer image renderer), then it is recommended that the encoder perform its own gamma encoding <em>before</em> quantizing the data to integer values for storage in the file. Applying gamma encoding at this stage results in images with fewer banding artifacts at a given sample depth, oｒ allows smaller samples while retaining the same visual quality. </p>
<p>A linear intensity level, expressed as a floating-point value in the range 0 to 1, can be converted to a gamma-encoded sample value by </p>
<pre>   sample = ROUND((intensity ^ encoder_gamma) * MAXSAMPLE)
</pre>
The file_gamma value to be written in the PNG <tt><font face="新宋体">gAMA</font></tt> chunk is the same as encoder_gamma in this equation, since we are assuming the initial intensity value is linear (in effect, camera_gamma is 1.0).
<p>If the image is being written to a file only, the encoder_gamma value can be selected somewhat arbitrarily. Values of 0.45 oｒ 0.5 are generally good choices because they are common in video systems, anｄ so most PNG decoders should do a good job displaying such images. </p>
<p>Some image renderers may simultaneously write the image to a PNG file anｄ display it on-screen. The displayed pixels should be gamma corrected for the display system anｄ viewing conditions in use, so that the user sees a proper representation of the intended scene. An appropriate gamma correction value is </p>
<pre>   screen_gc = viewing_gamma / display_gamma
</pre>
If the renderer wants to write the same gamma-corrected sample values to the PNG file, avoiding a separate gamma-encoding step for file output, then this screen_gc value should be written in the <tt><font face="新宋体">gAMA</font></tt> chunk. This will allow a PNG decoder to reproduce what the file's originator saw on screen during rendering (provided the decoder properly supports arbitrary values in a <tt><font face="新宋体">gAMA</font></tt> chunk).
<p>However, it is equally reasonable for a renderer to apply gamma correction for screen display using a gamma appropriate to the viewing conditions, anｄ to separately gamma-encode the sample values for file storage using a standard value of gamma such as 0.5. In fact, this is preferable, since some PNG decoders may not accurately display images with unusual <tt><font face="新宋体">gAMA</font></tt> values. </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 linear-light 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 file. This &quot;linear&quot; sample encoding is equivalent to gamma encoding with a gamma of 1.0, so graphics programs that produce linear samples should always emit a <tt><font face="新宋体">gAMA</font></tt> chunk specifying a gamma of 1.0. </p>
<p>When the sample values come directly from a piece of hardware, the correct <tt><font face="新宋体">gAMA</font></tt> value is determined by the gamma characteristic of the hardware. In the case of video digitizers (&quot;frame grabbers&quot;), <tt><font face="新宋体">gAMA</font></tt> should be 0.45 oｒ 0.5 for NTSC (possibly less for PAL oｒ SECAM) since video camera transfer functions are standardized. Image scanners are less predictable. Their output samples may be linear (gamma 1.0) since CCD sensors themselves are linear, oｒ the scanner hardware may have already applied gamma correction designed to compensate for dot gain in subsequent printing (gamma of about 0.57), oｒ the scanner may have corrected the samples for display on a CRT (gamma of 0.4-0.5). You will need to refer to the scanner's manual, oｒ even scan a calibrated gray wedge, to determine what a particular scanner does. </p>
<p>File format converters generally should not attempt to convert supplied images to a different gamma. Store the data in the PNG file without conversion, anｄ record the source gamma if it is known. Gamma alteration at file conversion time causes re-quantization of the set of intensity levels that are represented, introducing further roundoff error with little benefit. It's almost always better to just copy the sample values intact from the input to the output file. </p>
<p>In some cases, the supplied image may be in an image format (e.g., TIFF) that can describe the gamma characteristic of the image. In such cases, a file format converter is strongly encouraged to write a PNG <tt><font face="新宋体">gAMA</font></tt> chunk that corresponds to the known gamma of the source image. Note that some file formats specify the gamma of the display system, not the camera. If the input file's gamma value is greater than 1.0, it is almost certainly a display system gamma, anｄ you should use its reciprocal for the PNG <tt><font face="新宋体">gAMA</font></tt>. </p>
<p>If the encoder oｒ file format converter does not know how an image was originally created, but does know that the image has been displayed satisfactorily on a display with gamma display_gamma under lighting conditions where a particular viewing_gamma is appropriate, then the image can be marked as having the file_gamma: </p>
<pre>   file_gamma = viewing_gamma / display_gamma
</pre>
This will allow viewers of the PNG file to see the same image that the person running the file format converter saw. Although this may not be precisely the correct value of the image gamma, it's better to write a <tt><font face="新宋体">gAMA</font></tt> chunk with an approximately right value than to omit the chunk anｄ force PNG decoders to guess at an appropriate gamma.
<p>On the other hand, if the image file is being converted as part of a &quot;bulk&quot; conversion, with no one looking at each image, then it is better to omit the <tt><font face="新宋体">gAMA</font></tt> chunk entirely. If the image gamma has to be guessed at, leave it to the decoder to do the guessing. </p>
<p>Gamma does not apply to alpha samples; alpha is always represented linearly. </p>
<p>See also Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Decoder-gamma-handling"><font color="#800080">Decoder gamma handling (Section 10.5)</font></a>. </p>
<h3><a name="E.Encoder-color-handling"><font color="#000000">9.3. Encoder color handling</font></a></h3>
See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#ColorAppendix"><font color="#800080">Color Tutorial (Chapter 14)</font></a> if you aren't already familiar with color issues.
<p>If it is possible for the encoder to determine the chromaticities of the source display primaries, oｒ to make a strong guess based on the origin of the image oｒ the hardware running it, then the encoder is strongly encouraged to output the <tt><font face="新宋体">cHRM</font></tt> chunk. If it does so, the <tt><font face="新宋体">gAMA</font></tt> chunk should also be written; decoders can do little with <tt><font face="新宋体">cHRM</font></tt> if <tt><font face="新宋体">gAMA</font></tt> is missing. </p>
<p>Video created with recent video equipment probably uses the CCIR 709 primaries anｄ D65 white point [ITU-BT709], which are: </p>
<pre>            R           G           B         White
   x      0.640       0.300       0.150       0.3127
   y      0.330       0.600       0.060       0.3290
</pre>
An older but still very popular video standard is SMPTE-C [SMPTE-170M]:
<pre>            R           G           B         White
   x      0.630       0.310       0.155       0.3127
   y      0.340       0.595       0.070       0.3290
</pre>
The original NTSC color primaries have not been used in decades. Although you may still find the NTSC numbers listed in standards documents, you won't find any images that actually use them.
<p>Scanners that produce PNG files as output should inserｔ the filter chromaticities into a <tt><font face="新宋体">cHRM</font></tt> chunk anｄ the camera_gamma into a <tt><font face="新宋体">gAMA</font></tt> chunk. </p>
<p>In the case of hand-drawn oｒ digitally edited images, you have to determine what monitor they were viewed on when being produced. Many image editing programs allow you to specify what type of monitor you are using. This is often because they are working in some device-independent space internally. Such programs have enough information to write valid <tt><font face="新宋体">cHRM</font></tt> anｄ <tt><font face="新宋体">gAMA</font></tt> chunks, anｄ should 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 color space to RGB should be written into the <tt><font face="新宋体">cHRM</font></tt> chunk. Any colors that are outside the gamut of the chosen RGB device should be clipped oｒ otherwise constrained to be within the gamut; PNG does not store out of gamut colors. </p>
<p>If the computer image renderer performs calculations directly in device-dependent RGB space, a <tt><font face="新宋体">cHRM</font></tt> chunk should not be written unless the scene description anｄ rendering parameters have been adjusted to look good on a particular monitor. In that case, the data for that monitor (if known) should be used to construct a <tt><font face="新宋体">cHRM</font></tt> chunk. </p>
<p>There are often cases where an image's exact origins are unknown, particularly if it began life in some other format. A few image formats store calibration information, which can be used to fill in the <tt><font face="新宋体">cHRM</font></tt> chunk. For example, all PhotoCD images use the CCIR 709 primaries anｄ D65 whitepoint, so these values can be written into the <tt><font face="新宋体">cHRM</font></tt> chunk when converting a PhotoCD file. PhotoCD also uses the SMPTE-170M transfer function, which is closely approximated by a <tt><font face="新宋体">gAMA</font></tt> of 0.5. (PhotoCD can store colors outside the RGB gamut, so the image data will require gamut mapping before writing to PNG format.) TIFF 6.0 files can optionally store calibration information, which if present should be used to construct the <tt><font face="新宋体">cHRM</font></tt> chunk. GIF anｄ most other formats do not store any calibration information. </p>
<p>It is <strong>not</strong> recommended that file format converters attempt to convert supplied images to a different RGB color space. Store the data in the PNG file without conversion, anｄ record the source primary chromaticities if they are known. Color space transformation at file conversion time is a bad idea because of gamut mismatches anｄ rounding errors. As with gamma conversions, it's better to store the data losslessly anｄ incur at most one conversion when the image is finally displayed. </p>
<p>See also Recommendations for Decoders: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Decoder-color-handling"><font color="#800080">Decoder color handling (Section 10.6)</font></a>. </p>
<h3><a name="E.Alpha-channel-creation"><font color="#000000">9.4. Alpha channel creation</font></a></h3>
The alpha channel can be regarded either as a mask that temporarily hides transparent parts of the image, oｒ as a means for constructing a non-rectangular image. In the first case, the color values of fully transparent pixels should be preserved for future use. In the second case, the transparent pixels carry no useful data anｄ 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 color value for best compression.
<p>Image authors should keep in mind the possibility that a decoder will ignore transparency control. Hence, the colors assigned to transparent pixels should be reasonable background colors whenever feasible. </p>
<p>For applications that do not require a full alpha channel, oｒ cannot afford the price in compression efficiency, the <tt><font face="新宋体">tRNS</font></tt> transparency chunk is also available. </p>
<p>If the image has a known background color, this color should be written in the <tt><font face="新宋体">bKGD</font></tt> chunk. Even decoders that ignore transparency may use the <tt><font face="新宋体">bKGD</font></tt> color to fill unused screen area. </p>
<p>If the original image has premultiplied (also called &quot;associated&quot;) alpha data, convert it 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, anｄ 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>
<h3><a name="E.Suggested-palettes"><font color="#000000">9.5. Suggested palettes</font></a></h3>
A <tt><font face="新宋体">PLTE</font></tt> chunk can appear in truecolor PNG files. In such files, the chunk is not an essential part of the image data, but simply represents a suggested palette that viewers may use to present the image on indexed-color display hardware. A suggested palette is of no interest to viewers running on truecolor hardware.
<p>If an encoder chooses to provide a suggested palette, it is recommended that a <tt><font face="新宋体">hIST</font></tt> chunk also be written to indicate the relative importance of the palette entries. The histogram values are most easily computed as &quot;nearest neighbor&quot; counts, that is, the approximate usage of each palette entry if no dithering is applied. (These counts will often be available for free as a consequence of developing the suggested palette.) </p>
<p>For images of color type 2 (truecolor without alpha channel), it is recommended that the palette anｄ histogram be computed with reference to the RGB data only, ignoring any transparent-color specification. If the file uses transparency (has a <tt><font face="新宋体">tRNS</font></tt> chunk), viewers can easily adapt the resulting palette for use with their intended background color. They need only replace the palette entry closest to the <tt><font face="新宋体">tRNS</font></tt> color with their background color (which may oｒ may not match the file's <tt><font face="新宋体">bKGD</font></tt> color, if any). </p>
<p>For images of color type 6 (truecolor with alpha channel), it is recommended that a <tt><font face="新宋体">bKGD</font></tt> chunk appear anｄ that the palette anｄ histogram be computed with reference to the image as it would appear after compositing against the specified background color. This definition is necessary to ensure that useful palette entries are generated for pixels having fractional alpha values. The resulting palette will probably only be useful to viewers that present the image against the same background color. It is recommended that PNG editors deletｅ oｒ recompute the palette if they alter oｒ remove the <tt><font face="新宋体">bKGD</font></tt> chunk in an image of color type 6. If <tt><font face="新宋体">PLTE</font></tt> appears without <tt><font face="新宋体">bKGD</font></tt> in an image of color type 6, the circumstances under which the palette was computed are unspecified. </p>
<h3><a name="E.Filter-selection"><font color="#000000">9.6. Filter selection</font></a></h3>
For images of color type 3 (indexed color), filter type 0 (None) is usually the most effective. Note that color images with 256 oｒ fewer colors should almost always be stored in indexed color format; truecolor format is likely to be much larger.
<p>Filter type 0 is also recommended for images of bit depths less than 8. For low-bit-depth grayscale images, it may be a net win to expand the image to 8-bit representation anｄ apply filtering, but this is rare. </p>
<p>For truecolor anｄ grayscale 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 truecolor anｄ grayscale images, we recommend an adaptive filtering approach 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, anｄ selecｔ 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 much better heuristics will be found as more experience is gained with PNG. </p>
<p>Filtering according to these recommendations is effective on interlaced as well as noninterlaced images. </p>
<h3><a name="E.Text-chunk-processing"><font color="#000000">9.7. Text chunk processing</font></a></h3>
A nonempty keyword <em>must</em> be provided for each text chunk. The generic keyword &quot;Comment&quot; can be used if no better description of the text is available. If a user-supplied keyword is used, be sure to check that it meets the restrictions on keywords.
<p>PNG text strings are expected to use the Latin-1 character set. Encoders should avoid storing characters that are not defined in Latin-1, anｄ should provide character code remapping if the local system's character set is not Latin-1. </p>
<p>Encoders should discourage the creation of single lines of text longer than 79 characters, in order to facilitate easy reading. </p>
<p>It is recommended that text items less than 1K (1024 bytes) in size should be output using uncompressed <tt><font face="新宋体">tEXt</font></tt> chunks. In particular, it is recommended that the basic title anｄ author keywords should always be output using uncompressed <tt><font face="新宋体">tEXt</font></tt> chunks. Lengthy disclaimers, on the other hand, are ideal candidates for <tt><font face="新宋体">zTXt</font></tt>. </p>
<p>Placing large <tt><font face="新宋体">tEXt</font></tt> anｄ <tt><font face="新宋体">zTXt</font></tt> chunks after the image data (after <tt><font face="新宋体">IDAT</font></tt>) can speed up image display in some situations, since the decoder won't have to read over the text to get to the image data. But it is recommended that small text chunks, such as the image title, appear before <tt><font face="新宋体">IDAT</font></tt>. </p>
<h3><a name="E.Use-of-private-chunks"><font color="#000000">9.8. Use of private chunks</font></a></h3>
Applications can use PNG private chunks to carry information that need not be understood by other applications. Such chunks must be given names with lowercase second letters, to ensure that they can never conflict with any future public chunk definition. Note, however, that there is no guarantee that some other application will not use the same private chunk name. If you use a private chunk type, it is prudent to store additional identifying information at the beginning of the chunk data.
<p>Use an ancillary chunk type (lowercase first letter), not a critical chunk type, for all private chunks that store information that is not absolutely essential to view the image. Creation of private critical chunks is discouraged because they render PNG files unportable. Such chunks should not be used in publicly available software oｒ files. If private critical chunks are essential for your application, it is recommended that one appear near the start of the file, so that a standard decoder need not read very far before discovering that it cannot handle the file. </p>
<p>If you want others outside your organization to understand a chunk type that you invent, contact the maintainers of the PNG specification to submit a proposed chunk name anｄ definition for addition to the list of special-purpose public chunks (see <a href="http://www.j2megame.cn/viewthread.php?tid=3292#C.Additional-chunk-types"><font color="#800080">Additional chunk types, Section 4.4</font></a>). Note that a proposed public chunk name (with uppercase second letter) must not be used in publicly available software oｒ files until registration has been approved. </p>
<p>If an ancillary chunk contains textual information that might be of interest to a human user, you should <strong>not</strong> create a special chunk type for it. Instead use a <tt><font face="新宋体">tEXt</font></tt> chunk anｄ define a suitable keyword. That way, the information will be available to users not using your software. </p>
<p>Keywords in <tt><font face="新宋体">tEXt</font></tt> chunks should be reasonably self-explanatory, since the idea is to let other users figure out what the chunk contains. If of general usefulness, new keywords can be registered with the maintainers of the PNG specification. But it is permissible to use keywords without registering them first. </p>
<h3><a name="E.Private-type-and-method-codes"><font color="#000000">9.9. Private type anｄ method codes</font></a></h3>
This specification defines the meaning of only some of the possible values of some fields. For example, only compression method 0 anｄ filter types 0 through 4 are defined. Numbers greater than 127 must be used when inventing experimental oｒ private definitions of values for any of these fields. Numbers below 128 are reserved for possible future public extensions of this specification. Note that use of private type codes may render a file unreadable by standard decoders. Such codes are strongly discouraged except for experimental purposes, anｄ should not appear in publicly available software oｒ files.
<h2><a name="Decoders"><font color="#000000">10. Recommendations for Decoders</font></a></h2>
This chapter gives some recommendations for decoder behavior. The only absolute requirement on a PNG decoder is that it successfully read any file conforming to the format specified in the preceding chapters. However, best results will usually be achieved by following these recommendations.
<h3><a name="D.Error-checking"><font color="#000000">10.1. Error checking</font></a></h3>
To ensure early detection of common file-transfer problems, decoders should verify that all eight bytes of the PNG file signature are correct. (See Rationale: <a href="http://www.j2megame.cn/viewthread.php?tid=3292#R.PNG-file-signature"><font color="#800080">PNG file signature, Section 12.11</font></a>.) A decoder can have additional confidence in the file's integrity if the next eight bytes are an <tt><font face="新宋体">IHDR</font></tt> chunk header with the correct chunk length.
<p>Unknown chunk types must be handled as described in <a href="http://www.j2megame.cn/viewthread.php?tid=3292#Chunk-naming-conventions"><font color="#800080">Chunk naming conventions (Section 3.3)</font></a>. An unknown chunk type is <em>not</em> to be treated as an error unless it is a critical chunk. </p>
<p>It is strongly recommended that decoders should verify the CRC on each chunk. </p>
<p>In some situations it is desirable to check chunk headers (length anｄ type code) before reading the chunk data anｄ CRC. The chunk type can be checked for plausibility by seeing whether all four bytes are ASCII letters (codes 65-90 anｄ 97-122); note that this need only be done for unrecognized type codes. If the total file size is known (from file system information, HTTP protocol, etc), the chunk length can be checked for plausibility as well. </p>
<p>If CRCs are not checked, dropped/added data bytes oｒ an erroneous chunk length can cause the decoder to get out of step anｄ misinterpret subsequent data as a chunk header. Verifying that the chunk type contains letters is an inexpensive way of providing early error detection in this situation. </p>
<p>For known-length chunks such as <tt><font face="新宋体">IHDR</font></tt>, 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 <tt><font face="新宋体">IHDR</font></tt> chunk) must be checked for anｄ treated as errors. However, it is recommended that unexpected field values be treated as fatal errors only in <em>critical</em> 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 file.) </p>
<h3><a name="D.Pixel-dimensions"><font color="#000000">10.2. Pixel dimensions</font></a></h3>
Non-square pixels can be represented (see the <tt><font face="新宋体">pHYs</font></tt> chunk), but viewers are not required to account for them; a viewer can present any PNG file as though its pixels are square.
<p>Conversely, viewers running on display hardware with non-square pixels are strongly encouraged to rescale images for proper display. </p>
<h3><a name="D.Truecolor-image-handling"><font color="#000000">10.3. Truecolor image handling</font></a></h3>
To achieve PNG's goal of universal interchangeability, decoders are required to accept all types of PNG image: indexed-color, truecolor, anｄ grayscale. Viewers running on indexed-color display hardware need to be able to reduce truecolor images to indexed format for viewing. This process is usually called &quot;color quantization&quot;.
<p>A simple, fast way of doing this is to reduce the image to a fixed palette. Palettes with uniform color spacing (&quot;color cubes&quot;) 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 color cube usually has numerous entries that are unused in any particular image. This approach requires more work, first in choosing the palette, anｄ second in mapping individual pixels to the closest available color. PNG allows the encoder to supply a suggested palette in a <tt><font face="新宋体">PLTE</font></tt> chunk, but not all encoders will do so, anｄ the suggested palette may be unsuitable in any case (it may have too many oｒ too few colors). High-quality viewers will therefore 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 color quantization are available. The PNG reference implementation, <a href="ftp://ftp.uu.net/graphics/png/src/"><font color="#0000ff">libpng</font></a>, includes code for the purpose. </p>
<h3><a name="D.Sample-depth-rescaling"><font color="#000000">10.4. Sample depth rescaling</font></a></h3>
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>The most accurate scaling is achieved by the linear equation </p>
<pre>   output = ROUND(input * MAXOUTSAMPLE / MAXINSAMPLE)
</pre>
where
<pre>   MAXINSAMPLE = (2^sampledepth)-1
   MAXOUTSAMPLE = (2^desired_sampledepth)-1
</pre>
A slightly less accurate conversion is achieved by simply shifting right by <tt><font face="新宋体">sampledepth-desired_sampledepth</font></tt> places. For example, to reduce 16-bit samples to 8-bit, one need only discard the low-order byte. In many situations the shift method is sufficiently accurate for display purposes, anｄ 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 <a href="http://www.j2megame.cn/viewthread.php?tid=3292#D.Decoder-gamma-handling"><font color="#800080">Decoder gamma handling, Section 10.5</font></a>.)
<p>When an <tt><font face="新宋体">sBIT</font></tt> chunk is present, the original pre-PNG data can be recovered by shifting right to the sample depth specified by <tt><font face="新宋体">sBIT</font></tt>. 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. </p>
<p>When comparing pixel values to <tt><font face="新宋体">tRNS</font></tt> chunk values to detect transparent pixels, it is necessary to do the comparison exactly. Therefore, transparent pixel detection must be done before reducing sample precision. </p>
<h3><a name="D.Decoder-gamma-handling"><font color="#000000">10.5. Decoder gamma handling</font></a></h3>
See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#GammaAppendix"><font color="#800080">Gamma Tutorial (Chapter 13)</font></a> if you aren't already familiar with gamma issues.
<p>To produce correct tone reproduction, a good image display program should take into account the gammas of the image file anｄ the display device, as well as the viewing_gamma appropriate to the lighting conditions near the display. This can be done by calculating </p>
<pre>   gbright = insample / MAXINSAMPLE
   bright = gbright ^ (1.0 / file_gamma)
   vbright = bright ^ viewing_gamma
   gcvideo = vbright ^ (1.0 / display_gamma)
   fbval = ROUND(gcvideo * MAXFBVAL)
</pre>
where <tt><font face="新宋体">MAXINSAMPLE</font></tt> is the maximum sample value in the file (255 for 8-bit, 65535 for 16-bit, etc), <tt><font face="新宋体">MAXFBVAL</font></tt> is the maximum value of a frame buffer sample (255 for 8-bit, 31 for 5-bit, etc), <tt><font face="新宋体">insample</font></tt> is the value of the sample in the PNG file, anｄ <tt><font face="新宋体">fbval</font></tt> is the value to write into the frame buffer. The first line converts from integer samples into a normalized 0 to 1 floating point value, the second undoes the gamma encoding of the image file to produce a linear intensity value, the third adjusts for the viewing conditions, the fourth corrects for the display system's gamma value, anｄ the fifth converts to an integer frame buffer sample. In practice, the second through fourth lines can be merged into
<pre>   gcvideo = gbright^(viewing_gamma / (file_gamma*display_gamma))
</pre>
so as to perform only one power calculation. For color images, the entire calculation is performed separately for R, G, anｄ B values.
<p>It is <em>not</em> necessary to perform transcendental math for every pixel. Instead, compute a lookup table that gives the correct output value for every possible sample value. This requires only 256 calculations per image (for 8-bit accuracy), not one oｒ three calculations per pixel. For an indexed-color image, a one-time correction of the palette is sufficient, unless the image uses transparency anｄ is being displayed against a nonuniform background. </p>
<p>In some cases even the cost of computing a gamma lookup table may be a concern. In these cases, viewers are encouraged to have precomputed gamma correction tables for file_gamma values of 1.0 anｄ 0.5 with some reasonable choice of viewing_gamma anｄ display_gamma, anｄ to use the table closest to the gamma indicated in the file. This will produce acceptable results for the majority of real files. </p>
<p>When the incoming image has unknown gamma (no <tt><font face="新宋体">gAMA</font></tt> chunk), choose a likely default file_gamma value, but allow the user to selecｔ a new one if the result proves too dark oｒ too light. </p>
<p>In practice, it is often difficult to determine what value of display_gamma should be used. In systems with no built-in gamma correction, the display_gamma is determined entirely by the CRT. Assuming a CRT_gamma of 2.5 is recommended, unless you have detailed calibration measurements of this particular CRT available. </p>
<p>However, many modern frame buffers have lookup tables that are used to perform gamma correction, anｄ on these systems the display_gamma value should be the gamma of the lookup table anｄ CRT combined. You may not be able to find out what the lookup table contains from within an image viewer application, so you may have to ask the user what the system's gamma value is. 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. <a href="http://www.j2megame.cn/viewthread.php?tid=3292#GammaAppendix"><font color="#800080">Gamma Tutorial (Chapter 13)</font></a> gives some examples. </p>
<p>The response of real displays is actually more complex than can be described by a single number (display_gamma). If actual measurements of the monitor's light output as a function of voltage input are available, the fourth anｄ fifth 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>
<p>The value of viewing_gamma depends on lighting conditions; see <a href="http://www.j2megame.cn/viewthread.php?tid=3292#GammaAppendix"><font color="#800080">Gamma Tutorial (Chapter 13)</font></a> for more detail. Ideally, a viewer would allow the user to specify viewing_gamma, either directly numerically, oｒ via selecting from &quot;bright surround&quot;, &quot;dim surround&quot;, anｄ &quot;dark surround&quot; conditions. Viewers that don't want to do this should just assume a value for viewing_gamma of 1.0, since most computer displays live in brightly-lit rooms. </p>
<p>When viewing images that are digitized from video, oｒ that are destined to become video frames, the user might want to set the viewing_gamma to about 1.25 regardless of the actual level of room lighting. This value of viewing_gamma is &quot;built into&quot; NTSC video practice, anｄ displaying an image with that viewing_gamma allows the user to see what a TV set would show under the current room lighting conditions. (This is not the same thing as trying to obtain the most accurate rendition of the content of the scene, which would require adjusting viewing_gamma to correspond to the room lighting level.) This is another reason viewers might want to allow users to adjust viewing_gamma directly. </p>
<h3><a name="D.Decoder-color-handling"><font color="#000000">10.6. Decoder color handling</font></a></h3>
See <a href="http://www.j2megame.cn/viewthread.php?tid=3292#ColorAppendix"><font color="#800080">Color Tutorial (Chapter 14)</font></a> if you aren't already familiar with color issues.
<p>In many cases, decoders will treat image data in PNG files as device-dependent RGB data anｄ display it 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 the original image author used, the colors will not be exactly the same as the original author saw, particularly for darker oｒ near-neutral colors. The <tt><font face="新宋体">cHRM</font></tt> chunk provides information that allows closer color matching than that provided by gamma correction alone. </p>
<p>Decoders can use the <tt><font face="新宋体">cHRM</font></tt> data to transform the image data from RGB to XYZ anｄ thence into a perceptually linear color space such as CIE LAB. They can then partition the colors to generate an optimal palette, because the geometric distance between two colors in CIE LAB is strongly related to how different those colors appear (unlike, for example, RGB oｒ XYZ spaces). The resulting palette of colors, once transformed back into RGB color space, could be used for display oｒ written into a <tt><font face="新宋体">PLTE</font></tt> 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 color fidelity is critical, such as product design, scientific visualization, medicine, architecture, oｒ advertising, 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 anｄ the matrix to go from XYZ to display_RGB, then combining them to produce the overall transformation. The decoder is responsible for implementing gamut mapping. </p>
<p>Decoders running on platforms that have a Color Management System (CMS) can pass the image data, <tt><font face="新宋体">gAMA</font></tt> anｄ <tt><font face="新宋体">cHRM</font></tt> values to the CMS for display oｒ further processing. </p>
<p>Decoders that provide color printing facilities can use the facilities in Level 2 PostScript to specify image data in calibrated RGB space oｒ in a device-independent color space such as XYZ. This will provide better color fidelity than a simple RGB to CMYK conversion. The PostScript Language Reference manual gives examples of this process [POSTSCRIPT]. Such decoders are responsible for implementing gamut mapping between source_RGB (specified in the <tt><font face="新宋体">cHRM</font></tt> chunk) anｄ the target printer. The PostScript interpreter is then responsible for producing the required colors. </p>
<p>Decoders can use the <tt><font face="新宋体">cHRM</font></tt> data to calculate an accurate grayscale representation of a color image. Conversion from RGB to gray is simply a case of calculating the Y (luminance) component of XYZ, which is a weighted sum of the R G anｄ B values. The weights depend on the monitor type, i.e., the values in the <tt><font face="新宋体">cHRM</font></tt> chunk. Decoders may wish to do this for PNG files with no <tt><font face="新宋体">cHRM</font></tt> chunk. In that case, a reasonable default would be the CCIR 709 primaries [ITU-BT709]. Do <em>not</em> use the original NTSC primaries, unless you really do have an image color-balanced for such a monitor. Few monitors ever used the NTSC primaries, so such images are probably nonexistent these days. </p>
<h3><a name="D.Background-color"><font color="#000000">10.7. Background color</font></a></h3>
The background color given by <tt><font face="新宋体">bKGD</font></tt> will typically be used to fill unused screen space around the image, as well as any transparent pixels within the image. (Thus, <tt><font face="新宋体">bKGD</font></tt> is valid anｄ useful even when the image does not use transparency.) If no <tt><font face="新宋体">bKGD</font></tt> chunk is present, the viewer will need to make its own decision about a suitable background color.
<p>Viewers that have a specific background against which to present the image (such as Web browsers) should ignore the <tt><font face="新宋体">bKGD</font></tt> chunk, in effect overriding <tt><font face="新宋体">bKGD</font></tt> with their preferred background color oｒ background image. </p>
<p>The background color given by <tt><font face="新宋体">bKGD</font></tt> is not to be considered transparent, even if it happens to match the color given by <tt><font face="新宋体">tRNS</font></tt> (or, in the case of an indexed-color image, refers to a palette index that is marked as transparent by <tt><font face="新宋体">tRNS</font></tt>). Otherwise one would have to imagine something &quot;behind the background&quot; to composite against. The background color is either used as background oｒ ignored; it is not an intermediate layer between the PNG image anｄ some other background. </p>
<p>Indeed, it will be common that <tt><font face="新宋体">bKGD</font></tt> anｄ <tt><font face="新宋体">tRNS</font></tt> specify the same color, 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>
<h3><a name="D.Alpha-channel-processing"><font color="#000000">10.8. Alpha channel processing</font></a></h3>
In the most general case, the alpha channel can be used to composite a foreground image against a background image; the PNG file defines the foreground image anｄ the transparency mask, but not the background image. Decoders are <em>not</em> required to support this most general case. It is expected that most will be able to support compositing against a single background color, however.
<p>The equation for computing a composited sample value is </p>
<pre>   output = alpha * foreground + (1-alpha) * background
</pre>
where alpha anｄ the input anｄ output sample values are expressed as fractions in the range 0 to 1. This computation should be performed with linear (non-gamma-encoded) sample values. For color images, the computation is done separately for R, G, anｄ B samples.
<p>The following code illustrates the general case of compositing a foreground image over a background image. It assumes that you have the original pixel data available for the background image, anｄ 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 anｄ gamma values of foreground image, background image, anｄ frame buffer/CRT all to be different. Don't assume they are the same without checking. </p>
<p>This code is standard C, 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 anｄ frame buffer */
   10  fg_maxsample = (1 &lt;&lt; fg_sample_depth) - 1;
   11  bg_maxsample = (1 &lt;&lt; bg_sample_depth) - 1;
   12  fb_maxsample = (1 &lt;&lt; frame_buffer_sample_depth) - 1;
       /*
        * Get integer version of alpha.
        * Check for opaque anｄ 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 &lt; 3; i++) {
   18          gamfg = (float) foreground[i] / fg_maxsample;
   19          linfg = pow(gamfg, 1.0/fg_gamma);
   20          comppix = linfg;
   21          gcvideo = pow(comppix,viewing_gamma/display_gamma);
   22          fbpix[i] = (int) (gcvideo * fb_maxsample + 0.5);
   23      }
   24  } else {
           /*
            * Compositing is necessary.
            * Get floating-point alpha anｄ 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 &lt; 3; i++) {
               /*
                * Convert foreground anｄ background to floating
                * point, then linearize (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;
   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,viewing_gamma/display_gamma);
   34          fbpix[i] = (int) (gcvideo * fb_maxsample + 0.5);
   35      }
   36  }
</pre>
Variations:
<ol>
    <li>If output is to another PNG image file instead of a frame buffer, lines 21, 22, 33, anｄ 34 should be changed to be something like
    <pre>   /*
    * Gamma encode for storage in output file.
    * 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, anｄ background file are all the same, anｄ the three gamma values also match, then the no-compositing code in lines 14-23 reduces to nothing more than copying pixel values from the input file to the output file if alpha is one, oｒ copying pixel values from background to output file if alpha is zero. Since alpha is typically either zero oｒ one for the vast majority of pixels in an image, this is a great savings. No gamma computations are needed for most pixels. </li>
    <li>When the sample depths anｄ gamma values all match, it may appear attractive to skip the gamma decoding anｄ encoding (lines 28-31, 33-34) anｄ just perform line 32 using gamma-encoded sample values. Although this doesn't hurt image quality too badly, the time savings are small if alpha values of zero anｄ one are special-cased 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 anｄ 31 need to extract intensity from the frame buffer pixel values using code like
    <pre>   /*
    * Decode frame buffer value back into linear space.
    */
   gcvideo = (float) fbpix[i] / fb_maxsample;
   linbg = pow(gcvideo, display_gamma / viewing_gamma);
</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. So, if you handle the no-alpha case with a lookup table, you can use the same lookup table here. Lines 28-31 anｄ 33-34 can also be done with (different) lookup tables. </li>
    <li>Of course, everything here can be done in integer arithmetic. Just be careful to maintain sufficient precision all the way through. </li>
</ol>
<p>Note: in floating point, no overflow oｒ underflow checks are needed, because the input sample values are guaranteed to be between 0 anｄ 1, anｄ 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 oｒ underflow. </p>
<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's 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 author does not wish to implement true compositing logic, it is simple to deal with images that contain only zero anｄ one alpha values. (This is implicitly true for grayscale anｄ truecolor PNG files that use a <tt><font face="新宋体">tRNS</font></tt> chunk; for indexed-color PNG files, it is easy to check whether <tt><font face="新宋体">tRNS</font></tt> contains any values other than 0 anｄ 255.) In this simple case, transparent pixels are replaced by the background color, while others are unchanged. 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; that is, do not replace partially transparent pixels by the background. This approach will not yield very good results for images converted from associated-alpha formats, but it's better than doing nothing. </p>
<h3><a name="D.Progressive-display"><font color="#000000">10.9. Progressive display</font></a></h3>
When receiving images over slow transmission links, decoders can improve perceived performance by displaying interlaced images progressively. This means that as each pass 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 anｄ to the right of the received pixel. This process can be described by the following pseudocode:
<pre>   Starting_Row [1..7] =  { 0, 0, 4, 0, 2, 0, 1 }
   Starting_Col [1..7] =  { 0, 4, 0, 2, 0, 1, 0 }
   Row_Increment [1..7] = { 8, 8, 8, 4, 4, 2, 2 }
   Col_Increment [1..7] = { 8, 8, 4, 4, 2, 2, 1 }
   Block_Height [1..7] =  { 8, 8, 4, 4, 2, 2, 1 }
   Block_Width [1..7] =   { 8, 4, 4, 2, 2, 1, 1 }
   
   pass := 1
   while pass &lt;= 7
   begin
       row := Starting_Row[pass]
   
       while row &lt; height
       begin
           col := Starting_Col[pass]
   
           while col &lt; width
           begin
               visit (row, col,
                      min (Block_Height[pass], height - row),
                      min (Block_Width[pass], width - col))
               col := col + Col_Increment[pass]
           end
           row := row + Row_Increment[pass]
       end
   
       pass := pass + 1
   end
</pre>
Here, the function &quot;visit(row,column,height,width)&quot; obtains the next transmitted pixel anｄ paints a rectangle of the specified height anｄ width, whose upper-left corner is at the specified row anｄ column, using the color indicated by the pixel. Note that row anｄ column are measured from 0,0 at the upper left corner.
<p>If the decoder is merging the received image with a background image, it may be more convenient just to paint the received pixel positions; that is, the &quot;visit()&quot; function sets only the pixel at the specified row anｄ column, not the whole rectangle. This produces a &quot;fade-in&quot; effect as the new image gradually replaces the old. An advantage of this approach is that proper alpha oｒ 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 oｒ partially transparent. Of course, this is only a problem if the background image is not stored anywhere offscreen. </p>
<h3><a name="D.Suggested-palette-and-histogram-usage"><font color="#000000">10.10. Suggested-palette anｄ histogram usage</font></a></h3>
In truecolor PNG files, the encoder may have provided a suggested <tt><font face="新宋体">PLTE</font></tt> chunk for use by viewers running on indexed-color hardware.
<p>If the image has a <tt><font face="新宋体">tRNS</font></tt> chunk, the viewer will need to adapt the suggested palette for use with its desired background color. To do this, replace the palette entry closest to the <tt><font face="新宋体">tRNS</font></tt> color with the desired background color; oｒ just add a palette entry for the background color, if the viewer can handle more colors than there are <tt><font face="新宋体">PLTE</font></tt> entries. </p>
<p>For images of color type 6 (truecolor with alpha channel), any suggested palette should have been designed for display of the image against a uniform background of the color specified by <tt><font face="新宋体">bKGD</font></tt>. Viewers should probably ignore the palette if they intend to use a different background, oｒ if the <tt><font fa