inverted image

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?

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.

@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

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?

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

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.

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