GL_RGB

Hey all,

I’ve been tinkering with the videoGrabber example app. In the testApp.cpp file there’s the line:

  
videoTexture.loadData(videoInverted, 320,240, GL_RGB);  

Could somebody perhaps explain how the GL_RGB part works and how I might go about just manipulating just one of the RGB channels?

I’d be really grateful,

Thanks,

Jon

Hi -

GL_RGB is the constant for opengl which specifies the data type of pixels in the image.

We are telling opengl what to expect from our data (videoInverted)

GL_RGB = 24 bits, interlaced : RGBRGBRGB
GL_RGBA = 32 bits, interlaced: RGBARGBARGBA
GL_LUMINANCE = 8 bits, grayscale: LLLLLLL

if you wanted to alter the data, you can do that with the actual unsigned chars in videoInverted.

For example:
videoInverted[0] refers to the Red value of pixel 0,
videoInverted[1] refers to the Green value of pixel 0,
videoInverted[2] refers to the Blue value of pixel 0,
videoInverted[3] refers to the Red value of pixel 1…

let me know if that helps, or if you want an example of playing with those values –

take care,
zach

some more examples would be really nice.

i am interested in:
-taking 2 pixel arrays (video1,video2) and using another
pixel array (grayscale) to control the blending of the
videos according the gray value.

-how to mix GL_RGB, GL_RGBA, GL_LUMINANCE pixel arrays.

-chromakey example

-how to create contrast, brightness

-how to make color correction (change hue, saturation and value of a pixel array)

i do not know how complicated this is, but it is over the horizon for me
to figure it out myself but i could use color correction and contrast/brightness
in my current project.

dan

ok - I’m gonna move this thread to advanced, because this kind of low-level pixel stuff seems like an advanced topic.

here’s an example of mixing two RGB arrays into a third RGB array using grayscale as a value. I’m gonna assume 320x240…

  
  
... (in h file)....  
unsigned char * video0;  
unsigned char * video1;  
unsigned char * mask;  
unsigned char * videoMix;  
  
... (in setup()).....  
video0 = new unsigned char[320*240*3];  
video1 = new unsigned char[320*240*3];  
mask = new unsigned char[320*240];  
videoMix = new unsigned char[320*240*3];  
// let's put some data in, ok  
  
for (int i = 0; i < 320*240*3; i++){  
video0[i] = (int)(ofRandomuf()*255);  // random RGB noise  
}  
  
for (int i = 0; i < 320*240*3; i++){  
 if (i % 3 == 0) video1[i] = 255; // red for every third pixel (% 3)  
 else  video1[i] = 0; // red  
}  
  
for (int i = 0; i < 320; i++){  
for (int j = 0; j < 240; j++){  
mask[j*320 + i] = j; // a gradient, from 0-240, top to bottom  
}  
}  
  
// now, let's mix video0 and video1 with mask:  
// remember, mask is 1/3 the size of the RGB arrays...!  
for (int i = 0; i < 320*240*3; i++){   // for every color  pixel   
   int maskPixelPos = i / 3;  
   int maskValue = mask[maskPixelPos];     
   float maskPct = (float)maskValue  / 255.0f; //convert mask to a pct  
   videoMix[i] = (int)((maskPct) * video0[i]  + (1 - maskPct) * video1[i]);  
}  
  
  

ok - this code was written very early in the morning and I didn’t test it yet, but it should give a general impression of how to mix the two arrays using a third… some tricky stuff to pay attention to:

i % 3 <---------- using % to get every third pixel
j*320 + i <------------- y*w + x to get the pixel position

for people new to working with image data at a low level, this might be foreign. but I swear it will become second nature !!

hope that helps!
zach

1 Like

zach, you’re great!!

this example contains a lot of useful information, i am
very happy to digg into the code now :slight_smile:

thank you very much,
daniel

Thanks for that Zach,

Thats really helpful stuff. I’m still completely blown away by how cool this project is! I’m finding new things everyday. Thanks again,

Take care,

Jon