title: Convert DCI-P3 Colorspace to sRGB Using Java ImageIO or Imagemagick
body: <p>I'm attempting to do image processing on a screenshot from a iPhone-X, but I'm running into trouble with the red channel not falling into an expected range.  The problems are due to the color space of the image bring in DCI-P3 while most of our algorithms were written for the standard sRGB color space of the older iPhones and Android we own.</p>
  
  <p>The area of the screenshot giving us issues has RGB values of r=59, g=125, b=236 when in the DCI-P3 color space.  We expect the red channel to be less then 30 and sure enough converting the image via Photoshop's "Edit->Convert To Profile" option results in the specific pixel having a red value of 22.</p>
  
  <p>We're doing this image processing on a Jax-RS webservice so my first attempt at solving the problem was using javax.imageio.ImageIO and friends.  Unfortunately, the typical recommendation to covert the image's color space using the below didn't work (red values are still too high):</p>
  
  <pre><code>BufferedImage screenshotCopy = new BufferedImage(screenshot.getWidth(), screenshot.getHeight(), BufferedImage.TYPE_INT_ARGB);
  Graphics2D g2d = screenshotCopy.createGraphics();
  g2d.drawImage(screenshot, 0, 0, null);
  g2d.dispose();
  </code></pre>
  
  <p>I've also tried to use Imagemagick, but being new to the tool I've only had some success.  Imagemagick can use color spaces for conversion, but when I attempted it the red channel was even higher 70+.</p>
  
  <pre><code>magick convert IMG_0812.PNG -profile ~/Desktop/srgb.icc IMG_0812_converted.PNG
  </code></pre>
  
  <p>Could someone help me properly convert these color spaces using ImageIO (preferred) or ImageMagick that produces a resulting image similar to Photoshop's "Edit->Convert To Profile" tool?</p>