BumpMap Inversion Problem

Started by xindon, June 17, 2006, 14:16:49

Previous topic - Next topic

xindon

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}


       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));
        .....

ggp83

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:

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.

spasi

This one is faster:

int ub = b & 0xFF

xindon

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

ggp83

No, -128 is 255, -127 is 254 and -1 is 128.