PDA

View Full Version : How to retreive red and blue component from an Image



iris_raj
07-14-2003, 09:38 PM
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

Relic
07-14-2003, 10:01 PM
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.

iris_raj
07-14-2003, 10:52 PM
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

Obli
07-15-2003, 04:06 AM
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).

GlutterFly
07-15-2003, 04:12 AM
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

07-18-2003, 03:16 AM
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.