JDK-8057666 : Error in JPG Colorspace detection while reading using ImageIO
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 8u20
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-09-04
  • Updated: 2015-11-24
  • Resolved: 2015-11-24
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

Also seen with 

java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux localhost.localdomain 3.15.7-200.fc20.x86_64 #1 SMP Mon Jul 28 18:50:26 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Also seen on ubuntu 14.04

A DESCRIPTION OF THE PROBLEM :
When trying to read a JPG and just write it back to another file, the colors of the image are all screwed up. From browsing on the internet, Its basically whats mentioned here 

http://stackoverflow.com/questions/13072312/jpeg-image-color-gets-drastically-changed-after-just-imageio-read-and-imageio

The sample Image I tried with is here - http://img1.junaroad.com/uiproducts/34199/pri-1384240030.jpg

I am uploading the same original image as well as the wrong saved image on imgur in case the original link goes missing. Here is the imgur album - http://imgur.com/a/barYY

There is a chance imgur is resampling the image, so use the original URL i gave. If thats not working you can ping me on my email and i can provide newer source image

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
            BufferedImage originalImage;
            try {
                originalImage = ImageIO.read(inputFileInputStream); // simple FileInputStream to the image file
                
                
                if (originalImage == null) {
                    throw new Exception("error");
                }
               
                try {
                    

            FileOutputStream output = new FileOutputStream("/outputPath/outputimage");
            ImageWriter jpgWriter = ImageIO.getImageWritersByFormatName("jpeg").next();
            ImageWriteParam iwp = jpgWriter.getDefaultWriteParam();
            iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            iwp.setCompressionQuality(0.95f);
            ImageOutputStream imageOutput = ImageIO.createImageOutputStream(output);
            jpgWriter.setOutput(imageOutput);
            jpgWriter.write(null, new IIOImage(originalimage, null, null), iwp);
            jpgWriter.dispose();
            imageOutput.flush();



                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                
                
                
            } catch (FileNotFoundException ex) {
                throw new ImageNotFoundException(ex.getMessage());
            }

ACTUAL -
http://imgur.com/a/barYY

The image with red background is the wrong result

REPRODUCIBILITY :
This bug can be reproduced always.


Comments
This is duplicate of JDK-8041501. Fix for JDK-8041501 is already verified and it solves issue faced in this bug also.
24-11-2015

This is duplicate of JDK-8041501.
23-11-2015

Is this a duplicate of JDK-8041501 ?
12-11-2015

There's a number of similar bugs but I think the first of these below is the closest to this problem : https://bugs.openjdk.java.net/browse/JDK-6444933 https://bugs.openjdk.java.net/browse/JDK-6785440 https://bugs.openjdk.java.net/browse/JDK-8054568 https://bugs.openjdk.java.net/browse/JDK-8041501 https://bugs.openjdk.java.net/browse/JDK-8041459
09-09-2014