Hello All,

 

Please review the following solution in JDK11 :

 

Bug : https://bugs.openjdk.java.net/browse/JDK-6788458 

Webrev : http://cr.openjdk.java.net/~jdv/6788458/webrev.00/ 

 

Issue: When we try to read non-indexed RGB PNG image having transparent pixel 
information in tRNS chunk, ImageIO.PNGImageReader ignores the transparent pixel 
information. If we use Toolkit.getDefaultToolkit().createImage() it doesn't 
ignore the transparent pixel information.

 

Root cause:  In ImageIO.PNGImageReader() we store tRNS chunk values in 
readMetadata() -> parse_tRNS_chunk (), but we never use the tRNS R, G, B value 
to compare with decoded image information. Also in ImageIO.PNGImageReader() for 
IHDR colortype RGB we use only 3 channel destination BufferedImage. So even if 
we use the tRNS chunk value we need destination BufferedImage of 4 channels to 
represent transparency.

 

Solution: While assigning destination image in PNGImageReader.getImageTypes() 
if we know that PNG image is of type RGB and has tRNS chunk then we need to 
assign a destination image having 4 channels. After that in decodePass() we 
need to create 4 channel destination raster and while we store decoded image 
information into the destination BufferedImage we need to compare decoded R, G, 
B values with tRNS R, G, B values and store appropriate alpha channel value.

 

Also we use 4 channel destination image in case of RGB image only when tRNS 
chunk is present and ImageReadParam.destinationBands is null or 
ImageReadParam.destinationBands is equal to 4.

 

One more change is that we have optimization in PNGImageReader.readMetadata() 
where if ignoreMetadata is true and IHDR colortype is not of type 
PNG_COLOR_PALETTE, we ignore all the chunk data and just try to find first IDAT 
chunk. But if we need tRNS chunk values in case of IHDR colortype PNG_COLOR_RGB 
we need to parse tNRS chunk also. So in readMetadata() also appropriate changes 
are made.

 

Note : Initially the enhancement request was present only for 8 bit RGB PNG 
images but after making more modifications realized that we can add support for 
16 bit RGB image also by making similar incremental changes. The tRNS chunk 
value is still ignored for Gray PNG image. If we need to support PNG_COLOR_GRAY 
image with tRNS chunk(which is very rare) we can take that up in a separate bug 
as it needs different set of changes.

 

Thanks,

Jay

 

Reply via email to