0

I'm currently working on a program that stores RGB-info from two images to compare them.

I created two example images with paint.net. Both are 16x16 and one is BLUE and the other one is RED. I set the value in paint.net to (255, 0 ,0) in the RGB value for RED and in the blue image to (0,0,255).

As I loaded it into a ByteBuffer and looked inside it.

                // Buffer for texture data
                ByteBuffer res = BufferUtils.makeByteBufferT4(w * h);

                // Convert pixel format
                for (int y = 0; y != h; y++) {
                    for (int x = 0; x != w; x++) {
                        int pp = bi.getRGB(x, y);
                        byte a = (byte) ((pp & 0xff000000) >> 24);
                        byte r = (byte) ((pp & 0x00ff0000) >> 16);
                        byte g = (byte) ((pp & 0x0000ff00) >> 8);
                        byte b = (byte) (pp & 0x000000ff);
                        res.put((y * w + x) * 4 + 0, r);
                        res.put((y * w + x) * 4 + 1, g);
                        res.put((y * w + x) * 4 + 2, b);
                        res.put((y * w + x) * 4 + 3, a);
                    }
                }

    public static ByteBuffer makeByteBufferT4(int length){
            // As "int" in java has 4 bytes we have to multiply our length with 4 for every single int value
            ByteBuffer res = null;
            return res = ByteBuffer.allocateDirect(length * 4);
        }

Via res.get(0) I expected 1 as value, but got -1 I recognized that against my expectation it stores the value -1. I expected the value 1.

Why is this so, should'nt it store the value 1?

This is not problem that a affects my coding negatively, But more an understanding issue, I have.

BigPenguin
  • 264
  • 2
  • 17

0 Answers0