Program: 33357
Project: 33357
Buggy source:
/** 
 * Retrieves RGB values from Raster. This seems to be the fastest way to get RGB values. TYPE_INT_RGB        = 1 TYPE_INT_ARGB       = 2 TYPE_INT_ARGB_PRE   = 3 TYPE_INT_BGR        = 4 TYPE_3BYTE_BGR      = 5 TYPE_4BYTE_ABGR     = 6 TYPE_4BYTE_ABGR_PRE = 7 TYPE_BYTE_GRAY      = 10 TYPE_BYTE_BINARY    = 12 TYPE_BYTE_INDEXED   = 13 TYPE_USHORT_GRAY    = 11 TYPE_USHORT_565_RGB = 8 TYPE_USHORT_555_RGB = 9 TYPE_CUSTOM         = 0.
 * @param image input BufferedImage 
 * @return integer array - default RGB color space representation
 */
public static int[] getRGB(BufferedImage image){
  int type=image.getType();
  Raster raster=image.getRaster();
  Object object=raster.getDataElements(0,0,image.getWidth(),image.getHeight(),null);
  int transferType=raster.getTransferType();
  int imageWidth=image.getWidth();
  int imageHeight=image.getHeight();
  int imageSize=imageWidth * imageHeight;
  int[] rgbs=new int[imageSize];
switch (transferType) {
case DataBuffer.TYPE_INT:
    rgbs=(int[])object;
  if (type == BufferedImage.TYPE_INT_ARGB_PRE) {
    for (int i=0; i < imageSize; i++) {
      float alpha=255.0f / ((rgbs[i] >> 24) & 0xff);
      byte red=(byte)(((rgbs[i] >> 16) & 0xff) * alpha);
      byte green=(byte)(((rgbs[i] >> 8) & 0xff) * alpha);
      byte blue=(byte)((rgbs[i] & 0xff) * alpha);
      rgbs[i]=(rgbs[i] & 0xff000000) | ((red & 0xff) << 16) | ((green & 0xff) << 8)| (blue & 0xff);
    }
  }
 else   if (type == BufferedImage.TYPE_INT_BGR) {
    for (int i=0; i < rgbs.length; i++) {
      int blue=(rgbs[i] >> 16) & 0xff;
      int green=(rgbs[i] >> 8) & 0xff;
      int red=rgbs[i] & 0xff;
      rgbs[i]=0xff000000 | (red << 16) | (green << 8)| blue;
    }
  }
 else   if (type == BufferedImage.TYPE_INT_RGB) {
    for (int i=0; i < rgbs.length; i++)     rgbs[i]=0xff000000 | rgbs[i];
  }
 else   if (type == BufferedImage.TYPE_INT_ARGB) {
    ;
  }
 else {
    System.out.println("String_Node_Str");
    return image.getRGB(0,0,imageWidth,imageHeight,rgbs,0,imageWidth);
  }
return rgbs;
case DataBuffer.TYPE_BYTE:
byte[] bpixels=(byte[])object;
if (type == BufferedImage.TYPE_BYTE_INDEXED || type == BufferedImage.TYPE_BYTE_BINARY) {
IndexColorModel indexModel=(IndexColorModel)image.getColorModel();
int mapSize=indexModel.getMapSize();
byte[] reds=new byte[mapSize];
byte[] greens=new byte[mapSize];
byte[] blues=new byte[mapSize];
byte[] alphas=new byte[mapSize];
int[] palette=new int[mapSize];
indexModel.getReds(reds);
indexModel.getGreens(greens);
indexModel.getBlues(blues);
indexModel.getAlphas(alphas);
for (int i=0; i < mapSize; i++) palette[i]=(alphas[i] & 0xff) << 24 | (reds[i] & 0xff) << 16 | (greens[i] & 0xff) << 8 | blues[i] & 0xff;
for (int i=0; i < imageSize; i++) rgbs[i]=palette[bpixels[i] & 0xff];
}
 else if (type == BufferedImage.TYPE_4BYTE_ABGR) {
for (int i=0, index=0; i < imageSize; i++) rgbs[i]=(((bpixels[index++] & 0xff) << 16) | ((bpixels[index++] & 0xff) << 8) | (bpixels[index++] & 0xff)| ((bpixels[index++] & 0xff) << 24));
}
 else if (type == BufferedImage.TYPE_3BYTE_BGR) {
for (int i=0, index=0; i < imageSize; i++) rgbs[i]=((0xff000000) | ((bpixels[index++] & 0xff) << 16) | ((bpixels[index++] & 0xff) << 8)| (bpixels[index++] & 0xff));
}
 else if (type == BufferedImage.TYPE_4BYTE_ABGR_PRE) {
for (int i=0, index=0; i < imageSize; i++, index+=4) {
float alpha=255.0f * (bpixels[index + 3] & 0xff);
byte blue=(byte)((bpixels[index + 2] & 0xff) * alpha);
byte green=(byte)((bpixels[index + 1] & 0xff) * alpha);
byte red=(byte)((bpixels[index] & 0xff) * alpha);
rgbs[i]=(bpixels[index + 3] & 0xff000000) | ((red & 0xff) << 16) | ((green & 0xff) << 8)| (blue & 0xff);
}
}
 else if (type == BufferedImage.TYPE_BYTE_GRAY) {
for (int i=0; i < imageSize; i++) rgbs[i]=(0xff000000) | ((bpixels[i] & 0xff) << 16) | ((bpixels[i] & 0xff) << 8)| (bpixels[i] & 0xff);
}
 else {
System.out.println("String_Node_Str");
return image.getRGB(0,0,imageWidth,imageHeight,rgbs,0,imageWidth);
}
return rgbs;
case DataBuffer.TYPE_USHORT:
short[] spixels=(short[])object;
if (type == BufferedImage.TYPE_USHORT_GRAY) {
for (int i=0; i < imageSize; i++) {
int gray=((spixels[i] >> 8) & 0xff);
rgbs[i]=(0xff000000) | (gray << 16) | (gray << 8)| gray;
}
}
 else if (type == BufferedImage.TYPE_USHORT_565_RGB) {
for (int i=0; i < imageSize; i++) {
int red=((spixels[i] >> 11) & 0x1f);
int green=((spixels[i] >> 5) & 0x3f);
int blue=(spixels[i] & 0x1f);
rgbs[i]=(0xff000000) | (red << 19) | (green << 10)| (blue << 3);
}
}
 else if (type == BufferedImage.TYPE_USHORT_555_RGB) {
for (int i=0; i < imageSize; i++) {
int red=((spixels[i] >>> 10) & 0x1f);
int green=((spixels[i] >>> 5) & 0x1f);
int blue=(spixels[i] & 0x1f);
rgbs[i]=(0xff000000) | (red << 19) | (green << 11)| (blue << 3);
}
}
 else {
System.out.println("String_Node_Str");
return image.getRGB(0,0,imageWidth,imageHeight,rgbs,0,imageWidth);
}
return rgbs;
default :
throw new UnsupportedOperationException("String_Node_Str" + type);
}
}

Fixed version (ground truth):
/** 
 * Retrieves RGB values from Raster. This seems to be the fastest way to get RGB values. TYPE_INT_RGB        = 1 TYPE_INT_ARGB       = 2 TYPE_INT_ARGB_PRE   = 3 TYPE_INT_BGR        = 4 TYPE_3BYTE_BGR      = 5 TYPE_4BYTE_ABGR     = 6 TYPE_4BYTE_ABGR_PRE = 7 TYPE_BYTE_GRAY      = 10 TYPE_BYTE_BINARY    = 12 TYPE_BYTE_INDEXED   = 13 TYPE_USHORT_GRAY    = 11 TYPE_USHORT_565_RGB = 8 TYPE_USHORT_555_RGB = 9 TYPE_CUSTOM         = 0.
 * @param image input BufferedImage 
 * @return integer array - default RGB color space representation
 */
public static int[] getRGB(BufferedImage image){
  int type=image.getType();
  Raster raster=image.getRaster();
  Object object=raster.getDataElements(0,0,image.getWidth(),image.getHeight(),null);
  int transferType=raster.getTransferType();
  int imageWidth=image.getWidth();
  int imageHeight=image.getHeight();
  int imageSize=imageWidth * imageHeight;
  int[] rgbs=new int[imageSize];
switch (transferType) {
case DataBuffer.TYPE_INT:
    rgbs=(int[])object;
  if (type == BufferedImage.TYPE_INT_ARGB_PRE) {
    for (int i=0; i < imageSize; i++) {
      float alpha=255.0f / ((rgbs[i] >> 24) & 0xff);
      byte red=(byte)(((rgbs[i] >> 16) & 0xff) * alpha);
      byte green=(byte)(((rgbs[i] >> 8) & 0xff) * alpha);
      byte blue=(byte)((rgbs[i] & 0xff) * alpha);
      rgbs[i]=(rgbs[i] & 0xff000000) | ((red & 0xff) << 16) | ((green & 0xff) << 8)| (blue & 0xff);
    }
  }
 else   if (type == BufferedImage.TYPE_INT_BGR) {
    for (int i=0; i < rgbs.length; i++) {
      int blue=(rgbs[i] >> 16) & 0xff;
      int green=(rgbs[i] >> 8) & 0xff;
      int red=rgbs[i] & 0xff;
      rgbs[i]=0xff000000 | (red << 16) | (green << 8)| blue;
    }
  }
 else   if (type == BufferedImage.TYPE_INT_RGB) {
    for (int i=0; i < rgbs.length; i++)     rgbs[i]=0xff000000 | rgbs[i];
  }
 else   if (type == BufferedImage.TYPE_INT_ARGB) {
    ;
  }
 else {
    System.out.println("String_Node_Str");
    return image.getRGB(0,0,imageWidth,imageHeight,rgbs,0,imageWidth);
  }
return rgbs;
case DataBuffer.TYPE_BYTE:
byte[] bpixels=(byte[])object;
if (type == BufferedImage.TYPE_BYTE_INDEXED || type == BufferedImage.TYPE_BYTE_BINARY) {
IndexColorModel indexModel=(IndexColorModel)image.getColorModel();
int mapSize=indexModel.getMapSize();
byte[] reds=new byte[mapSize];
byte[] greens=new byte[mapSize];
byte[] blues=new byte[mapSize];
byte[] alphas=new byte[mapSize];
int[] palette=new int[mapSize];
indexModel.getReds(reds);
indexModel.getGreens(greens);
indexModel.getBlues(blues);
indexModel.getAlphas(alphas);
for (int i=0; i < mapSize; i++) palette[i]=(alphas[i] & 0xff) << 24 | (reds[i] & 0xff) << 16 | (greens[i] & 0xff) << 8 | blues[i] & 0xff;
for (int i=0; i < imageSize; i++) rgbs[i]=palette[bpixels[i] & 0xff];
}
 else if (type == BufferedImage.TYPE_4BYTE_ABGR) {
for (int i=0, index=0; i < imageSize; i++) rgbs[i]=(((bpixels[index++] & 0xff) << 16) | ((bpixels[index++] & 0xff) << 8) | (bpixels[index++] & 0xff)| ((bpixels[index++] & 0xff) << 24));
}
 else if (type == BufferedImage.TYPE_3BYTE_BGR) {
for (int i=0, index=0; i < imageSize; i++) rgbs[i]=((0xff000000) | ((bpixels[index++] & 0xff) << 16) | ((bpixels[index++] & 0xff) << 8)| (bpixels[index++] & 0xff));
}
 else if (type == BufferedImage.TYPE_4BYTE_ABGR_PRE) {
for (int i=0, index=0; i < imageSize; i++, index+=4) {
float alpha=255.0f * (bpixels[index + 3] & 0xff);
byte blue=(byte)((bpixels[index + 2] & 0xff) * alpha);
byte green=(byte)((bpixels[index + 1] & 0xff) * alpha);
byte red=(byte)((bpixels[index] & 0xff) * alpha);
rgbs[i]=(bpixels[index + 3] & 0xff000000) | ((red & 0xff) << 16) | ((green & 0xff) << 8)| (blue & 0xff);
}
}
 else if (type == BufferedImage.TYPE_BYTE_GRAY) {
for (int i=0; i < imageSize; i++) rgbs[i]=(0xff000000) | ((bpixels[i] & 0xff) << 16) | ((bpixels[i] & 0xff) << 8)| (bpixels[i] & 0xff);
}
 else {
System.out.println("String_Node_Str");
return image.getRGB(0,0,imageWidth,imageHeight,rgbs,0,imageWidth);
}
return rgbs;
case DataBuffer.TYPE_USHORT:
short[] spixels=(short[])object;
if (type == BufferedImage.TYPE_USHORT_GRAY) {
for (int i=0; i < imageSize; i++) {
int gray=((spixels[i] >> 8) & 0xff);
rgbs[i]=(0xff000000) | (gray << 16) | (gray << 8)| gray;
}
}
 else if (type == BufferedImage.TYPE_USHORT_565_RGB) {
for (int i=0; i < imageSize; i++) {
int red=((spixels[i] >> 11) & 0x1f);
int green=((spixels[i] >> 5) & 0x3f);
int blue=(spixels[i] & 0x1f);
rgbs[i]=(0xff000000) | (red << 19) | (green << 10)| (blue << 3);
}
}
 else if (type == BufferedImage.TYPE_USHORT_555_RGB) {
for (int i=0; i < imageSize; i++) {
int red=((spixels[i] >>> 10) & 0x1f);
int green=((spixels[i] >>> 5) & 0x1f);
int blue=(spixels[i] & 0x1f);
rgbs[i]=(0xff000000) | (red << 19) | (green << 11)| (blue << 3);
}
}
 else {
System.out.println("String_Node_Str");
return image.getRGB(0,0,imageWidth,imageHeight,rgbs,0,imageWidth);
}
return rgbs;
default :
return image.getRGB(0,0,imageWidth,imageHeight,rgbs,0,imageWidth);
}
}