I'm storing an image in a Java ByteBuffer object. I'm fetching each coordinate with a basic offset function like this:
public static int offset(int x, int y, int z, int width, int height) {
return (z * height + y) * width + x;
}
And you can get the colors like so:
int r = imageBuffer.get(offset + 0) & 0xFF; //0xFF is the hexadecimal way of writing 255, turns this byte into an unsigned byte
int g = imageBuffer.get(offset + 1) & 0xFF;
int b = imageBuffer.get(offset + 2) & 0xFF;
int a = imageBuffer.get(offset + 3) & 0xFF;
I want to flip the image in the ByteBuffer horizontally/vertically, but most of my searches turn up queries on flip(). I was wondering if this is even possible with just the ByteBuffer, or if I'm going to have to come up with a more complex solution? It needs to still be a ByteBuffer by the ending of my processing.
Here is the information I have available:
private ByteBuffer imageBuffer;
private int imageWidth, imageHeight;
Any help is appreciated! Thank you for your time!