11/*
2- * Copyright (c) 1999, 2018 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 1999, 2021 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3333
3434/** PNG - Portable Network Graphics - image file reader.
3535 See <a href=http://www.ietf.org/rfc/rfc2083.txt>RFC2083</a> for details. */
36-
37- /* this is changed
38- public class PNGImageDecoder extends FilterInputStream implements Runnable
39- { */
40-
4136public class PNGImageDecoder extends ImageDecoder
4237{
4338 private static final int GRAY =0 ;
@@ -69,18 +64,11 @@ public class PNGImageDecoder extends ImageDecoder
6964 private int interlaceMethod ;
7065 private int gamma = 100000 ;
7166 private java .util .Hashtable <String , Object > properties ;
72- /* this is not needed
73- ImageConsumer target;
74- */
7567 private ColorModel cm ;
7668 private byte [] red_map , green_map , blue_map , alpha_map ;
7769 private int transparentPixel = -1 ;
7870 private byte [] transparentPixel_16 = null ; // we need 6 bytes to store 16bpp value
7971 private static ColorModel [] greyModels = new ColorModel [4 ];
80- /* this is not needed
81- PNGImageDecoder next;
82- */
83-
8472 private void property (String key ,Object value ) {
8573 if (value ==null ) return ;
8674 if (properties ==null ) properties =new java .util .Hashtable <>();
@@ -153,9 +141,6 @@ protected boolean handleChunk(int key, byte[] buf, int st, int len)
153141 compressionMethod = getByte (st +10 );
154142 filterMethod = getByte (st +11 );
155143 interlaceMethod = getByte (st +12 );
156- /* this is not needed
157- if(target!=null) target.setDimensions(width,height);
158- */
159144 break ;
160145 case PLTEChunk :
161146 { int tsize = len /3 ;
@@ -235,14 +220,7 @@ protected boolean handleChunk(int key, byte[] buf, int st, int len)
235220 public class PNGException extends IOException {
236221 PNGException (String s ) { super (s ); }
237222 }
238- /* this is changed
239- public void run() {
240- */
241223 public void produceImage () throws IOException , ImageFormatException {
242- /* this is not needed
243- ImageConsumer t = target;
244- if(t!=null) try {
245- */
246224 try {
247225 for (int i =0 ; i <signature .length ; i ++)
248226 if ((signature [i ]&0xFF )!=underlyingInputStream .read ())
@@ -310,14 +288,6 @@ public void produceImage() throws IOException, ImageFormatException {
310288 default :
311289 throw new PNGException ("invalid color type" );
312290 }
313- /* this is going to be set in the pixel store
314- t.setColorModel(cm);
315- t.setHints(interlaceMethod !=0
316- ? ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES
317- : ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES |
318- ImageConsumer.SINGLEPASS | ImageConsumer.SINGLEFRAME);
319- */
320- // code added to make it work with ImageDecoder architecture
321291 setDimensions (width , height );
322292 setColorModel (cm );
323293 int flags = (interlaceMethod !=0
@@ -326,7 +296,6 @@ public void produceImage() throws IOException, ImageFormatException {
326296 ImageConsumer .SINGLEPASS | ImageConsumer .SINGLEFRAME );
327297 setHints (flags );
328298 headerComplete ();
329- // end of adding
330299
331300 int samplesPerPixel = ((colorType &PALETTE )!=0 ? 1
332301 : ((colorType &COLOR )!=0 ? 3 : 1 )+((colorType &ALPHA )!=0 ?1 :0 ));
@@ -335,11 +304,6 @@ public void produceImage() throws IOException, ImageFormatException {
335304 int pass , passLimit ;
336305 if (interlaceMethod ==0 ) { pass = -1 ; passLimit = 0 ; }
337306 else { pass = 0 ; passLimit = 7 ; }
338- // These loops are far from being tuned. They're this way to make them easy to
339- // debug. Tuning comes later.
340- /* code changed. target not needed here
341- while(++pass<=passLimit && (t=target)!=null) {
342- */
343307 while (++pass <=passLimit ) {
344308 int row = startingRow [pass ];
345309 int rowInc = rowIncrement [pass ];
@@ -356,9 +320,6 @@ public void produceImage() throws IOException, ImageFormatException {
356320
357321 byte [] rowByteBuffer = new byte [rowByteWidth ];
358322 byte [] prevRowByteBuffer = new byte [rowByteWidth ];
359- /* code changed. target not needed here
360- while (row < height && (t=target)!=null) {
361- */
362323 while (row < height ) {
363324 int rowFilter = is .read ();
364325 for (int rowFillPos =0 ;rowFillPos <rowByteWidth ; ) {
@@ -457,27 +418,13 @@ public void produceImage() throws IOException, ImageFormatException {
457418 break ;
458419 default : throw new PNGException ("illegal type/depth" );
459420 }
460- /*visit (row, col,
461- min (bHeight, height - row),
462- min (bWidth, width - col)); */
463421 col += colInc ;
464422 }
465423 if (interlaceMethod ==0 )
466424 if (wPixels !=null ) {
467- /* code changed. target not needed here
468- t.setPixels(0,row,width,1,cm,wPixels,0,width);
469- */
470- // code added to make it work with ImageDecoder arch
471425 sendPixels (0 ,row ,width ,1 ,wPixels ,0 ,width );
472- // end of adding
473- }
474- else {
475- /* code changed. target not needed here
476- t.setPixels(0,row,width,1,cm,bPixels,0,width);
477- */
478- // code added to make it work with ImageDecoder arch
426+ } else {
479427 sendPixels (0 ,row ,width ,1 ,bPixels ,0 ,width );
480- //end of adding
481428 }
482429 row += rowInc ;
483430 rowOffset += rowInc *rowStride ;
@@ -488,20 +435,9 @@ public void produceImage() throws IOException, ImageFormatException {
488435 }
489436 if (interlaceMethod !=0 )
490437 if (wPixels !=null ) {
491- /* code changed. target not needed here
492- t.setPixels(0,0,width,height,cm,wPixels,0,width);
493- */
494- // code added to make it work with ImageDecoder arch
495438 sendPixels (0 ,0 ,width ,height ,wPixels ,0 ,width );
496- //end of adding
497- }
498- else {
499- /* code changed. target not needed here
500- t.setPixels(0,0,width,height,cm,bPixels,0,width);
501- */
502- // code added to make it work with ImageDecoder arch
439+ } else {
503440 sendPixels (0 ,0 ,width ,height ,bPixels ,0 ,width );
504- //end of adding
505441 }
506442 }
507443
@@ -511,37 +447,15 @@ public void produceImage() throws IOException, ImageFormatException {
511447 and column, using the color indicated by the pixel. Note that row
512448 and column are measured from 0,0 at the upper left corner. */
513449
514- /* code not needed, don't deal with target
515- if((t=target)!=null) {
516- if(properties!=null) t.setProperties(properties);
517- t.imageComplete(ImageConsumer.STATICIMAGEDONE);
518- */
519-
520450 imageComplete (ImageConsumer .STATICIMAGEDONE , true );
521-
522- /* code not needed }
523- is.close();
524- */
525451 } catch (IOException e ) {
526452 if (!aborted ) {
527- /* code not needed
528- if((t=target)!=null) {
529- PNGEncoder.prChunk(e.toString(),inbuf,pos,limit-pos,true);
530- */
531453 property ("error" , e );
532- /* code not needed
533- t.setProperties(properties);
534- t.imageComplete(ImageConsumer.IMAGEERROR|ImageConsumer.STATICIMAGEDONE);
535- */
536454 imageComplete (ImageConsumer .IMAGEERROR |ImageConsumer .STATICIMAGEDONE , true );
537455 throw e ;
538456 }
539457 } finally {
540458 try { close (); } catch (Throwable e ){}
541- /* code not needed
542- target = null;
543- endTurn();
544- */
545459 }
546460 }
547461
@@ -620,47 +534,22 @@ private void filterRow(byte[] rowByteBuffer, byte[] prevRow,
620534 private static final byte [] blockHeight = { 1 , 8 , 8 , 4 , 4 , 2 , 2 , 1 };
621535 private static final byte [] blockWidth = { 1 , 8 , 4 , 4 , 2 , 2 , 1 , 1 };
622536
623- //abstract public class ChunkReader extends FilterInputStream {
624- int pos , limit ;
537+ int pos , limit ;
625538 int chunkStart ;
626- int chunkKey , chunkLength , chunkCRC ;
539+ int chunkKey , chunkLength , chunkCRC ;
627540 boolean seenEOF ;
628541
629542 private static final byte [] signature = { (byte ) 137 , (byte ) 80 , (byte ) 78 ,
630543 (byte ) 71 , (byte ) 13 , (byte ) 10 , (byte ) 26 , (byte ) 10 };
631544
632- PNGFilterInputStream inputStream ;
633- InputStream underlyingInputStream ;
545+ PNGFilterInputStream inputStream ;
546+ InputStream underlyingInputStream ;
634547
635- /* code changed
636- public PNGImageDecoder(InputStream in, ImageConsumer t) throws IOException {
637- */
638548 public PNGImageDecoder (InputStreamImageSource src , InputStream input ) throws IOException {
639- // code added
640549 super (src , input );
641550 inputStream = new PNGFilterInputStream (this , input );
642551 underlyingInputStream = inputStream .underlyingInputStream ;
643- // end of adding
644- /* code changed
645- super(in);
646- target = t;
647- waitTurn();
648- new Thread(this).start();
649- */
650- }
651- /* code changed to make it work with ImageDecoder architecture
652- static int ThreadLimit = 10;
653- private static synchronized void waitTurn() {
654- try {
655- while(ThreadLimit<=0) PNGImageDecoder.class.wait(1000);
656- } catch(InterruptedException e){}
657- ThreadLimit--;
658- }
659- private static synchronized void endTurn() {
660- if(ThreadLimit<=0) PNGImageDecoder.class.notify();
661- ThreadLimit++;
662552 }
663- */
664553 byte [] inbuf = new byte [4096 ];
665554 private void fill () throws IOException {
666555 if (!seenEOF ) {
@@ -728,8 +617,6 @@ boolean getData() throws IOException {
728617 chunkLength = 0 ;
729618 return chunkLength >0 ;
730619 }
731- //abstract protected boolean handleChunk(int key, byte[] buf, int st, int len)
732- // throws IOException;
733620 private static boolean checkCRC = true ;
734621 public static boolean getCheckCRC () { return checkCRC ; }
735622 public static void setCheckCRC (boolean c ) { checkCRC = c ; }
0 commit comments