title: JPEG image with wrong colors
body: <p>I have a method that reads images, converts them (size, format) and writes them back. This always worked very well, but now I've come across some JPEG images (from a Press Agency) that obviously contain some meta-data (IPTC). When converting those images, the colors are all wrong. My first guess was, that those are CMYK images but they are not.</p>
  
  <p>The problem must come from the reading, because it doesn't matter whether I convert the image to a smaller JPEG or a PNG, it always looks the same.</p>
  
  <p>At first, I used <code>ImageIO.read()</code> to read the image. I now get the actual <code>ImageReader</code> via <code>ImageIO.getImageReadersByMIMEType()</code> and tried to tell the reader to ignore meta data by setting the <code>ignoreMetadata</code> parameter of <code>ImageReader#setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata)</code> but had no success.</p>
  
  <p>Then I created a version of the image without the metadata (using Fireworks). That image is converted correctly.</p>
  
  <p>The only difference I could find out, is, that with the not-working image the value of the reader's variable <code>colorSpaceCode</code> is <strong>2</strong>, whilest with the working image, the value is <strong>3</strong>. There's also an <code>outColorSpaceCode</code> which is <strong>2</strong> for both images.</p>
  
  <p>As the <a href="http://www.docjar.com/html/api/com/sun/imageio/plugins/jpeg/JPEGImageReader.java.html" rel="nofollow noreferrer">source comment of the reader</a> only says <em>Set by setImageData native code callback.  A modified IJG+NIFTY colorspace code</em> I'm really stuck now. So any help would be much appreciated.</p>
  
  <p>You can get original image (~3 MB) by going <a href="https://docs.google.com/leaf?id=0B91_UJs94xyTYTU4MTYxZDQtM2FlYy00OGVlLTkzMGQtYThhNzI5N2M0YmRl" rel="nofollow noreferrer">here</a> and clicking download. The left image below shows what I get from the original image, the right shows what it should look like. </p>
  
  <p><img src="https://i.stack.imgur.com/4TYAc.jpg" alt="wrong colors">
  <img src="https://i.stack.imgur.com/6vy74.jpg" alt="correct colors (after removing metadata)"></p>