Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 7 additions & 120 deletions src/java.desktop/share/classes/sun/awt/image/PNGImageDecoder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright year in other files might be updated as well.

* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -33,11 +33,6 @@

/** PNG - Portable Network Graphics - image file reader.
See <a href=http://www.ietf.org/rfc/rfc2083.txt>RFC2083</a> for details. */

/* this is changed
public class PNGImageDecoder extends FilterInputStream implements Runnable
{ */

public class PNGImageDecoder extends ImageDecoder
{
private static final int GRAY=0;
Expand Down Expand Up @@ -69,18 +64,11 @@ public class PNGImageDecoder extends ImageDecoder
private int interlaceMethod;
private int gamma = 100000;
private java.util.Hashtable<String, Object> properties;
/* this is not needed
ImageConsumer target;
*/
private ColorModel cm;
private byte[] red_map, green_map, blue_map, alpha_map;
private int transparentPixel = -1;
private byte[] transparentPixel_16 = null; // we need 6 bytes to store 16bpp value
private static ColorModel[] greyModels = new ColorModel[4];
/* this is not needed
PNGImageDecoder next;
*/

private void property(String key,Object value) {
if(value==null) return;
if(properties==null) properties=new java.util.Hashtable<>();
Expand Down Expand Up @@ -153,9 +141,6 @@ protected boolean handleChunk(int key, byte[] buf, int st, int len)
compressionMethod = getByte(st+10);
filterMethod = getByte(st+11);
interlaceMethod = getByte(st+12);
/* this is not needed
if(target!=null) target.setDimensions(width,height);
*/
break;
case PLTEChunk:
{ int tsize = len/3;
Expand Down Expand Up @@ -235,14 +220,7 @@ protected boolean handleChunk(int key, byte[] buf, int st, int len)
public class PNGException extends IOException {
PNGException(String s) { super(s); }
}
/* this is changed
public void run() {
*/
public void produceImage() throws IOException, ImageFormatException {
/* this is not needed
ImageConsumer t = target;
if(t!=null) try {
*/
try {
for(int i=0; i<signature.length; i++)
if((signature[i]&0xFF)!=underlyingInputStream.read())
Expand Down Expand Up @@ -310,14 +288,6 @@ public void produceImage() throws IOException, ImageFormatException {
default:
throw new PNGException("invalid color type");
}
/* this is going to be set in the pixel store
t.setColorModel(cm);
t.setHints(interlaceMethod !=0
? ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES
: ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES |
ImageConsumer.SINGLEPASS | ImageConsumer.SINGLEFRAME);
*/
// code added to make it work with ImageDecoder architecture
setDimensions(width, height);
setColorModel(cm);
int flags = (interlaceMethod !=0
Expand All @@ -326,7 +296,6 @@ public void produceImage() throws IOException, ImageFormatException {
ImageConsumer.SINGLEPASS | ImageConsumer.SINGLEFRAME);
setHints(flags);
headerComplete();
// end of adding

int samplesPerPixel = ((colorType&PALETTE)!=0 ? 1
: ((colorType&COLOR)!=0 ? 3 : 1)+((colorType&ALPHA)!=0?1:0));
Expand All @@ -335,11 +304,6 @@ public void produceImage() throws IOException, ImageFormatException {
int pass, passLimit;
if(interlaceMethod==0) { pass = -1; passLimit = 0; }
else { pass = 0; passLimit = 7; }
// These loops are far from being tuned. They're this way to make them easy to
// debug. Tuning comes later.
/* code changed. target not needed here
while(++pass<=passLimit && (t=target)!=null) {
*/
while(++pass<=passLimit) {
int row = startingRow[pass];
int rowInc = rowIncrement[pass];
Expand All @@ -356,9 +320,6 @@ public void produceImage() throws IOException, ImageFormatException {

byte[] rowByteBuffer = new byte[rowByteWidth];
byte[] prevRowByteBuffer = new byte[rowByteWidth];
/* code changed. target not needed here
while (row < height && (t=target)!=null) {
*/
while (row < height) {
int rowFilter = is.read();
for (int rowFillPos=0;rowFillPos<rowByteWidth; ) {
Expand Down Expand Up @@ -457,27 +418,13 @@ public void produceImage() throws IOException, ImageFormatException {
break;
default: throw new PNGException("illegal type/depth");
}
/*visit (row, col,
min (bHeight, height - row),
min (bWidth, width - col)); */
col += colInc;
}
if(interlaceMethod==0)
if(wPixels!=null) {
/* code changed. target not needed here
t.setPixels(0,row,width,1,cm,wPixels,0,width);
*/
// code added to make it work with ImageDecoder arch
sendPixels(0,row,width,1,wPixels,0,width);
// end of adding
}
else {
/* code changed. target not needed here
t.setPixels(0,row,width,1,cm,bPixels,0,width);
*/
// code added to make it work with ImageDecoder arch
} else {
sendPixels(0,row,width,1,bPixels,0,width);
//end of adding
}
row += rowInc;
rowOffset += rowInc*rowStride;
Expand All @@ -488,20 +435,9 @@ public void produceImage() throws IOException, ImageFormatException {
}
if(interlaceMethod!=0)
if(wPixels!=null) {
/* code changed. target not needed here
t.setPixels(0,0,width,height,cm,wPixels,0,width);
*/
// code added to make it work with ImageDecoder arch
sendPixels(0,0,width,height,wPixels,0,width);
//end of adding
}
else {
/* code changed. target not needed here
t.setPixels(0,0,width,height,cm,bPixels,0,width);
*/
// code added to make it work with ImageDecoder arch
} else {
sendPixels(0,0,width,height,bPixels,0,width);
//end of adding
}
}

Expand All @@ -511,37 +447,15 @@ public void produceImage() throws IOException, ImageFormatException {
and column, using the color indicated by the pixel. Note that row
and column are measured from 0,0 at the upper left corner. */

/* code not needed, don't deal with target
if((t=target)!=null) {
if(properties!=null) t.setProperties(properties);
t.imageComplete(ImageConsumer.STATICIMAGEDONE);
*/

imageComplete(ImageConsumer.STATICIMAGEDONE, true);

/* code not needed }
is.close();
*/
} catch(IOException e) {
if(!aborted) {
/* code not needed
if((t=target)!=null) {
PNGEncoder.prChunk(e.toString(),inbuf,pos,limit-pos,true);
*/
property("error", e);
/* code not needed
t.setProperties(properties);
t.imageComplete(ImageConsumer.IMAGEERROR|ImageConsumer.STATICIMAGEDONE);
*/
imageComplete(ImageConsumer.IMAGEERROR|ImageConsumer.STATICIMAGEDONE, true);
throw e;
}
} finally {
try { close(); } catch(Throwable e){}
/* code not needed
target = null;
endTurn();
*/
}
}

Expand Down Expand Up @@ -620,47 +534,22 @@ private void filterRow(byte[] rowByteBuffer, byte[] prevRow,
private static final byte[] blockHeight = { 1, 8, 8, 4, 4, 2, 2, 1 };
private static final byte[] blockWidth = { 1, 8, 4, 4, 2, 2, 1, 1 };

//public abstract class ChunkReader extends FilterInputStream {
int pos, limit;
int pos, limit;
int chunkStart;
int chunkKey, chunkLength, chunkCRC;
int chunkKey, chunkLength, chunkCRC;
boolean seenEOF;

private static final byte[] signature = { (byte) 137, (byte) 80, (byte) 78,
(byte) 71, (byte) 13, (byte) 10, (byte) 26, (byte) 10 };

PNGFilterInputStream inputStream;
InputStream underlyingInputStream;
PNGFilterInputStream inputStream;
InputStream underlyingInputStream;

/* code changed
public PNGImageDecoder(InputStream in, ImageConsumer t) throws IOException {
*/
public PNGImageDecoder(InputStreamImageSource src, InputStream input) throws IOException {
// code added
super(src, input);
inputStream = new PNGFilterInputStream(this, input);
underlyingInputStream = inputStream.underlyingInputStream;
// end of adding
/* code changed
super(in);
target = t;
waitTurn();
new Thread(this).start();
*/
}
/* code changed to make it work with ImageDecoder architecture
static int ThreadLimit = 10;
private static synchronized void waitTurn() {
try {
while(ThreadLimit<=0) PNGImageDecoder.class.wait(1000);
} catch(InterruptedException e){}
ThreadLimit--;
}
private static synchronized void endTurn() {
if(ThreadLimit<=0) PNGImageDecoder.class.notify();
ThreadLimit++;
}
*/
byte[] inbuf = new byte[4096];
private void fill() throws IOException {
if(!seenEOF) {
Expand Down Expand Up @@ -728,8 +617,6 @@ boolean getData() throws IOException {
chunkLength = 0;
return chunkLength>0;
}
//protected abstract boolean handleChunk(int key, byte[] buf, int st, int len)
// throws IOException;
private static boolean checkCRC = true;
public static boolean getCheckCRC() { return checkCRC; }
public static void setCheckCRC(boolean c) { checkCRC = c; }
Expand Down