/** * Method to change bands order only on the BufferedImage. * * @param bufferedImage * @return new bufferedImage */ public Image invertRGB(BufferedImage bufferedImage, String bands) { ColorModel colorModel = bufferedImage.getColorModel(); if (colorModel instanceof DirectColorModel) { DirectColorModel directColorModel = (DirectColorModel) colorModel; int red = directColorModel.getRedMask(); int blue = directColorModel.getBlueMask(); int green = directColorModel.getGreenMask(); int alpha = directColorModel.getAlphaMask(); int[] components = new int[3]; String bds = bands.toLowerCase(); components[0] = getComponent(bds.charAt(0), red, green, blue); components[1] = getComponent(bds.charAt(1), red, green, blue); components[2] = getComponent(bds.charAt(2), red, green, blue); directColorModel = new DirectColorModel(32, components[0], components[1], components[2], alpha); ColorProcessor colorProcessor = new ColorProcessor(bufferedImage); colorProcessor.setColorModel(directColorModel); return colorProcessor.createImage(); } return bufferedImage; }
private void writeDirectColorModel(DataOutput out, DirectColorModel colorModel) throws IOException { out.writeInt(colorModel.getPixelSize()); out.writeInt(colorModel.getRedMask()); out.writeInt(colorModel.getGreenMask()); out.writeInt(colorModel.getBlueMask()); out.writeInt(colorModel.getAlphaMask()); }
public static boolean isFilterableDCM(ColorModel cm) { if (cm instanceof DirectColorModel) { DirectColorModel dcm = (DirectColorModel) cm; return (isMaskOK(dcm.getAlphaMask(), true) && isMaskOK(dcm.getRedMask(), false) && isMaskOK(dcm.getGreenMask(), false) && isMaskOK(dcm.getBlueMask(), false)); } return false; }
private static boolean isBgrColorModel(ColorModel cm) { if (cm instanceof DirectColorModel && cm.getTransferType() == DataBuffer.TYPE_INT) { DirectColorModel directCM = (DirectColorModel) cm; return directCM.getRedMask() == 0x000000FF && directCM.getGreenMask() == 0x0000FF00 && directCM.getBlueMask() == 0x00FF0000 && (directCM.getNumComponents() == 3 || directCM.getAlphaMask() == 0xFF000000); } return false; }