* <p/>
* does not unmange the image for all (A)RGN and (A)BGR and gray imaged
*/
public static void setBGRPixels(byte[] bgrPixels, BufferedImage img, int x, int y, int w, int h) {
int imageType = img.getType();
WritableRaster raster = img.getRaster();
//int ttype= raster.getTransferType();
if (imageType == BufferedImage.TYPE_3BYTE_BGR ||
imageType == BufferedImage.TYPE_4BYTE_ABGR ||
imageType == BufferedImage.TYPE_4BYTE_ABGR_PRE ||
imageType == BufferedImage.TYPE_BYTE_GRAY) {
raster.setDataElements(x, y, w, h, bgrPixels);
} else {
int[] pixels;
if (imageType == BufferedImage.TYPE_INT_BGR) {
pixels = bytes2int(bgrPixels, 2, 1, 0); // bgr --> bgr
} else if (imageType == BufferedImage.TYPE_INT_ARGB ||
imageType == BufferedImage.TYPE_INT_ARGB_PRE) {
pixels = bytes2int(bgrPixels, 3, 0, 1, 2); // abgr --> argb
} else {
pixels = bytes2int(bgrPixels, 0, 1, 2); // bgr --> rgb
}
if (w == 0 || h == 0) {
return;
} else if (pixels.length < w * h) {
throw new IllegalArgumentException("pixels array must have a length" + " >= w*h");
}
if (imageType == BufferedImage.TYPE_INT_ARGB ||
imageType == BufferedImage.TYPE_INT_RGB ||
imageType == BufferedImage.TYPE_INT_ARGB_PRE ||
imageType == BufferedImage.TYPE_INT_BGR) {
raster.setDataElements(x, y, w, h, pixels);
} else {
// Unmanages the image
img.setRGB(x, y, w, h, pixels, 0, w);
}
}