title: Pure Java alternative to JAI ImageIO for detecting CMYK images
body: <p>first I'd like to explain the situation/requirements that lead to the question:</p>
  
  <p>In our web application we can't support CMYK images (JPEG) since IE 8 and below can't display them.
  Thus we need to detect when someone wants to upload such an image and deny it.</p>
  
  <p>Unfortunately, Java's ImageIO won't read those images or would not enable me to get the detected color space. From debugging it seems like <code>JPEGImageReader</code> internally gets the color space code 11 (which would mean <code>JCS_YCCK</code>) but I can't safely access that information.</p>
  
  <p>When querying the reader for the image types I get nothing for CMYK, so I might assume <code>no image types = unsupported image</code>. </p>
  
  <p>I converted the source CMYK image to RGB using an imaging tool in order to test whether it would then be readable (I tried to simulate the admin's steps when getting the message "No CMYK supported"). However, <code>JPEGImageReader</code> would not read that image, since it <i>assumes</i> (comment in the source!)3-component RGB color space but the image header reports 4 components (maybe RGBA or ARGB) and thus an <code>IllegalArgumentException</code> is thrown.</p>
  
  <p>Thus, ImageIO is not an option since I can't reliably get the color space of an image and I can't tell the admin why an otherwise fine image (it can be displayed by the browser) would not be accepted due to some internal error.
  <br/><br/></p>
  
  <p>This led me to try JAI ImageIO whose <code>CLibJPEGImageReader</code> does an excellent job and correctly reads all my test images.</p>
  
  <p>However, since we're deploying our application in a JBoss that might host other applications as well, we'd like to keep them as isolated as possible. AFAIK, I'd need to install JAI ImageIO to the JRE or otherwise make the native libs available in order to use them, and thus other applications might get access to them as well, which might cause side effects (at least we'd have to test a lot to ensure that's not the case).</p>
  
  <p>That's the explanation for the question, and here it comes again:
  <b>Is there any pure Java alternative to JAI ImageIO which reliably detects and possibly converts CMYK images?</b></p>
  
  <p>Thanks in advance,</p>
  
  <p>Thomas</p>