I'm making a lighting system right now, and the last part I have to do is to invert the alpha channel on the final light map. My previous code that used to work was
DataBufferByte buf = (DataBufferByte)lightmap.getRaster().getDataBuffer();
byte[] values = buf.getData();
for(int i = 0; i < values.length; i += 4) values[i] = (byte)(values[i] ^ 0xff);
But this code threw this "java.lang.ClassCastException: java.awt.image.DataBufferInt cannot be cast to java.awt.image.DataBufferByte" on the first line. So, I changed it to
DataBufferInt buf = (DataBufferInt)lightmap.getRaster().getDataBuffer();
int[] values = buf.getData();
for(int i = 0; i < values.length; i += 4) values[i] = (int)(values[i] ^ 0xff);
but this doesn't actually invert the alpha, but seems to invert the color between the hue and black? I know that this works
for(int i = 0; i < lightmap.getWidth(); i++) {
for(int j = 0; j < lightmap.getHeight(); j++) {
lightmap.setRGB(i,j,(lightmap.getRGB(i, j) ^ 0xFF000000));
}
}
But testing this, it brings my framerate down to 15 fps.
So I guess my question is this: Either how can I fix this, or is there a fast way to invert the alpha values of a bufferedimage?