title: Fastest way to compare pixel values between two BufferedImages?
body: <p>I have a BufferedImage of type TYPE_INT_BGR.  I need to do a pixel-by-pixel comparison to another BufferedImage to compute the "distance" between the two images.  I have something that works, but is slow.  I get a pixel from the "reference" image, break it up into RGB bytes with:</p>
  
  <pre><code>    int pixel = referenceImage.getRGB(col, row);
      int red   = (pixel &gt;&gt; 16) &amp; 0xff;
      int green = (pixel &gt;&gt; 8) &amp; 0xff;
      int blue  = (pixel) &amp; 0xff;
  </code></pre>
  
  <p>I compare the r/g/b values to the corresponding pixel of the candidate image, and sum up the squares the differences.</p>
  
  <p>Is there a faster way to do this kind of comparison?  Peeking into the JRE source, I see that BufferedImage.getRGB() is actually ORing the constituent RGB values from the raster together, which is wasteful for my purposes, since I'm just breaking it down into bytes again.</p>
  
  <p>I'm going to try doing that directly, but I wonder if there is not a better way of doing this, either via a Java or 3rd party API that I might have missed.</p>