PDA

View Full Version : inverted image



ramona
11-24-2008, 04:28 AM
Hi,
I'm using a library that allows me to render JPG images using an array of pixels. So for every pixel, I do this:

outputImage->set(x, y, 0, pixel_array[i].r);
outputImage->set(x, y, 1, pixel_array[i].g);
outputImage->set(x, y, 2, pixel_array[i].b);

However all the images are rendered inverted i.e., I have to take them to photoshop and do this image->adjustments->invert

can anyone tell me why this might be happening? What does an inverted image mean?

_NK47
11-24-2008, 05:53 AM
i dont have photoshop right here but by inverted you mean the colors where f.e white becomes black if inverted or inverted image itself? you can invert images back by reading out scanlines from top to bottom or bottom to top with a for loop.

Rosario Leonardi
11-24-2008, 06:55 AM
@NK47: Invert reverse the color (white become black and vice versa.. for each channel).

@Ramona: Your message is not very clear and don't let us to help you.
What library are you using? I suggest DevIL (or OpenIL)
How do you render the texture? Are you using some flag?

In openGL you can set a bias and a scale for the each color channel but by default they are fine
http://www.opengl.org/sdk/docs/man/xhtml/glPixelTransfer.xml

ramona
11-24-2008, 07:17 AM
Thank you for your messages. Sorry if I was unclear. I'm using someone else's library to output frames and I can not contact them. By invert I do mean going from black to white and vice versa.

on the screen I'm rendering it like this:
glTexImage2D(GL_TEXTURE_2D, 0, 3,array_width,array_height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixel_array);

and then:
glTexCoord2f(0.0, 0.0f);
glVertex3f(-0.5f, -0.5f, 0.0f); etc. etc.

Forgive my ignorance but what is a flag?

ramona
11-24-2008, 07:31 AM
PS what does this mean and how do I do it:
reading out scanlines from top to bottom or bottom to top

_NK47
11-24-2008, 08:38 AM
PS what does this mean and how do I do it:
reading out scanlines from top to bottom or bottom to top
nah thats wrong then. inverting colors can be set in ... by reading the functions documentation.
doc:
Several parameters define the encoding of pixel data in
memory and control the processing of the pixel data before
it is placed in the frame buffer. These parameters are set
with four commands: glPixelStore, glPixelTransfer,
glPixelMap, and glPixelZoom.

seems like you did something there before? otherwise i never had this in GL without explicitly inverting them myself.

_NK47
11-24-2008, 08:46 AM
if you still want to do it yourself: assume here its an RGBA image with UNSIGNED_BYTE values taking up 32bit each pixel thus 8bit per channel.
go over each pixel and subtract each color channel like this:
inverted_value = 255 - channel_value;

now you have white as black and black as white. in case of troubles upload some images of your problem.

ramona
11-25-2008, 03:10 AM
Dear NK47, Thank you so much. I did the inverted_value = 255 - channel_value and it worked.

PS I had this before, like you said:
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPixelStorei(GL_PACK_ALIGNMENT, 4);
So I wonder what I should have put instead not to get the inverted image.

Thanks again for your help

_NK47
11-25-2008, 05:29 AM
welcome.

http://www.opengl.org/resources/code/samples/advanced/advanced97/notes/node130.html