How to retreive red and blue component from an Image

Dear All,

I have two Images with file extension *.rgb, I want to retreive
red component from the first Image and blue/green component
from the second Image using OPENGL commands.Can anyone describe the method for getting the components.

Thanks in advance

Assuming you have a file loader which can load the *.rgb files (look in the GLUT examples, if not).
Load the two images,
either download them as textures and draw textured screen aligned quads or simply use glDrawPixels to draw them onto the screen,
and now the answer:
Set glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE) to let only the red component pass through the framebuffer and glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_FALSE) for green+blue.
Voila!

Actually it’s as simple to load the images and mix the components “by hand” and then draw the mixed images.

Thanks for the reply.But how to load the *.rgb images using opengl. examples in Red book doesnot show how to load rgb image.

Moreover I want to store red components and blue components in two arrays and then add these arrrays and generate new Image

Thanks

Loading this or that file is not GL’s duty.
You have to load it yourself, manipolate it as you want and then pass it to the GL.

Once you get it loaded in RAM you can draw it by using a texture (much faster) or by issuing glDraw* calls - take care to set the raster position correctly.

Of curse, if you want compose images by taking different channels from different files you can do it yourself by using arrays and stuff like that or maybe you can try that thing Relic suggested (which seems a bit weird to me but if it works then it’s ok).

Relic:“look in the GLUT examples, if not”

GLUT has atleast one way to open a file. Other libs (GLu and Glaux) have commands such as LoadBMP(“Data/Cube.bmp”)). One of these should work for you. Good luck

hi !
assuming you already loaded a bmp file, this is how to get colors channels :


store pixels data in an array

unsigned char r,g,b,a;
for (int i=0; i<Size_w*Size_h; i++)
{
r = data[(i>>2)+0]; // get red componment
g = data[(i>>2)+1]; // get green componment
b = data[(i>>2)+2]; // get bleue componment
a = data[(i>>2)+3]; // get alpha componment
}

hope this help.

Steve.