Hello Guest

BumpMap Inversion Problem

  • 4 Replies
  • 8147 Views
BumpMap Inversion Problem
« on: June 17, 2006, 14:16:49 »
Hey,
I'm trying to load a bumpmap image and invert it by subtracting a byte's value from 255.
The image data is stored in a ByteBuffer. When I try to access the bytes I get some strange results. For example -103. I think there should only be values from 0 to 255 ?
Are they unsigned bytes? What am I doing wrong?

Thank you very much...
and sorry for my bad English {grin}


Code: [Select]

        ByteBuffer imageData = null;
        IntBuffer tmp = BufferUtils.createIntBuffer(1);

        IL.ilGenImages(tmp);
        IL.ilBindImage(tmp.get(0));

        IL.ilLoadImage(path);

        IL.ilConvertImage(IL.IL_RGB, IL.IL_BYTE);

        imageData = IL.ilGetData();

        System.out.println(imageData.get(0));  // Output:  -103


        /* create texture in opengl....*/
        GL11.glGenTextures(tmp);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, tmp.get(0));
        .....

BumpMap Inversion Problem
« Reply #1 on: June 18, 2006, 20:37:27 »
A byte in Java ranges from -128 to +127. So a Java byte is not unsigned but signed. To get values above 127, you'll have to cast the byte to a type which can hold larger numbers, such as a short. However just casting it will make it stay negative, so you'll have to make some "addition", like this:

Code: [Select]

byte b = (byte)203; // turns into -53

// convert to short
short s = b<0?(short)(256 - (-b)):b; // s now contains 203


edit. Should probably say that I'm not the most experienced programmer in Java, so there might be a nicer/better way to do this.

*

Offline spasi

  • *****
  • 2169
    • WebHotelier
BumpMap Inversion Problem
« Reply #2 on: June 19, 2006, 08:41:36 »
This one is faster:

Code: [Select]
int ub = b & 0xFF

BumpMap Inversion Problem
« Reply #3 on: June 19, 2006, 17:46:21 »
I need the pixel's color values. These range from 0 (no intensity) to 255 (full intensity).
So does -128 (byte) stand for 0 and 127 (byte) for 255 ?

Thanks

BumpMap Inversion Problem
« Reply #4 on: June 20, 2006, 02:18:47 »
No, -128 is 255, -127 is 254 and -1 is 128.