3261N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A/** PNG - Portable Network Graphics - image file reader. 0N/Apublic class PNGImageDecoder extends FilterInputStream implements Runnable 0N/A /* this is not needed 0N/A ImageConsumer target; 0N/A /* this is not needed 0N/A PNGImageDecoder next; 0N/A /* this is not needed 0N/A if(target!=null) target.setDimensions(width,height); 0N/A case COLOR:
// doesn't deal with 16 bit colors properly 0N/A for (
int i =
0; i <
6; i++) {
0N/A case GRAY:
// doesn't deal with 16 bit colors properly 0N/A case GRAY|
ALPHA:
// doesn't deal with 16 bit colors properly 0N/A /* REMIND: Discarding the LSB for 16 bit depth here 0N/A * means that the all pixels which match the MSB 0N/A * will be treated as transparent. 0N/A /* this is not needed 0N/A ImageConsumer t = target; 0N/A //Figure out the color model 0N/A /* this is going to be set in the pixel store 0N/A t.setColorModel(cm); 0N/A t.setHints(interlaceMethod !=0 0N/A ? ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES 0N/A : ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES | 0N/A ImageConsumer.SINGLEPASS | ImageConsumer.SINGLEFRAME); 0N/A // code added to make it work with ImageDecoder architecture 0N/A // These loops are far from being tuned. They're this way to make them easy to 0N/A // debug. Tuning comes later. 0N/A /* code changed. target not needed here 0N/A while(++pass<=passLimit && (t=target)!=null) { 0N/A /* code changed. target not needed here 0N/A while (row < height && (t=target)!=null) { 0N/A min (bHeight, height - row), 0N/A min (bWidth, width - col)); */ 0N/A /* code changed. target not needed here 0N/A t.setPixels(0,row,width,1,cm,wPixels,0,width); 0N/A // code added to make it work with ImageDecoder arch 0N/A /* code changed. target not needed here 0N/A t.setPixels(0,row,width,1,cm,bPixels,0,width); 0N/A // code added to make it work with ImageDecoder arch 0N/A /* code changed. target not needed here 0N/A t.setPixels(0,0,width,height,cm,wPixels,0,width); 0N/A // code added to make it work with ImageDecoder arch 0N/A /* code changed. target not needed here 0N/A t.setPixels(0,0,width,height,cm,bPixels,0,width); 0N/A // code added to make it work with ImageDecoder arch 0N/A /* Here, the function "visit(row,column,height,width)" obtains the 0N/A next transmitted pixel and paints a rectangle of the specified 0N/A height and width, whose upper-left corner is at the specified row 0N/A and column, using the color indicated by the pixel. Note that row 0N/A and column are measured from 0,0 at the upper left corner. */ 0N/A /* code not needed, don't deal with target 0N/A if((t=target)!=null) { 0N/A if(properties!=null) t.setProperties(properties); 0N/A t.imageComplete(ImageConsumer.STATICIMAGEDONE); 0N/A /* code not needed } 0N/A if((t=target)!=null) { 0N/A PNGEncoder.prChunk(e.toString(),inbuf,pos,limit-pos,true); 0N/A t.setProperties(properties); 0N/A t.imageComplete(ImageConsumer.IMAGEERROR|ImageConsumer.STATICIMAGEDONE); 0N/A pa = p > a ? p - a : a - p;
0N/A pb = p > b ? p - b : b - p;
0N/A pc = p > c ? p - c : c - p;
0N/A private static final byte[]
blockWidth = {
1,
8,
4,
4,
2,
2,
1,
1 };
0N/A //abstract public class ChunkReader extends FilterInputStream { 0N/A private static final byte[]
signature = { (
byte)
137, (
byte)
80, (
byte)
78,
0N/A (
byte)
71, (
byte)
13, (
byte)
10, (
byte)
26, (
byte)
10 };
0N/A public PNGImageDecoder(InputStream in, ImageConsumer t) throws IOException { 0N/A new Thread(this).start(); 0N/A /* code changed to make it work with ImageDecoder architecture 0N/A static int ThreadLimit = 10; 0N/A private synchronized static void waitTurn() { 0N/A while(ThreadLimit<=0) PNGImageDecoder.class.wait(1000); 0N/A } catch(InterruptedException e){} 0N/A private synchronized static void endTurn() { 0N/A if(ThreadLimit<=0) PNGImageDecoder.class.notify(); 0N/A //abstract protected boolean handleChunk(int key, byte[] buf, int st, int len) 0N/A // throws IOException; 0N/A if(c<=
' '||c>
'z') c =
'?';
0N/A /* Table of CRCs of all 8-bit messages. */ 0N/A /* Make the table for a fast CRC. */ 0N/A for (
int n =
0; n <
256; n++) {
0N/A for (
int k =
0; k <
8; k++)
0N/A c =
0xedb88320 ^ (c >>>
1);
0N/A /* Update a running CRC with the bytes buf[0..len-1]--the CRC 0N/A should be initialized to all 1's, and the transmitted value 0N/A is the 1's complement of the final running CRC (see the 0N/A crc() routine below)). */ 0N/A /* Return the CRC of the bytes buf[0..len-1]. */ 0N/A// the following class are added to make it work with ImageDecoder architecture