I’m using IntBuffer to manipulate pixels of a Bitmap, but the value in the buffer should be AABBGGRR, while the color constants are AARRGGBB. I know I can use Color.argb, Color.a, … to invert, but I think it’s not perfect.
I need to manipulate a very large number of pixels, so I need an algorithm that can perform this operator in short time. I think of this Bit Expression, but it’s not correct:
0xFFFFFFFF ^ pSourceColor
If there’s no better one, maybe I will use bit-shift operators (that performs Color.a, …) instead of calling the functions to reduce the time.
EDIT:
This is my current function to convert, though I think there shoul be a better algorithm (less operators) to perform it:
private int getBufferedColor(final int pSourceColor) {
return
((pSourceColor >> 24) << 24) | // Alpha
((pSourceColor >> 16) & 0xFF) | // Red -> Blue
((pSourceColor >> 8) & 0xFF) << 8 | // Green
((pSourceColor) & 0xFF) << 16; // Blue -> Red
}
Since A and G are in place, you can probably do a little better by masking off the B and R and then adding them back. Haven’t tested it but ought to be 95% right: