Yeah, that’s true. I tried using getPixels() to grab the RGB values, but the problem is that it writes out the interlaced RGB value, and I need the seperate R, G and B values. How can I do that?
[quote author=“pshoeg”]Thanks, dude!
That’s awesome. It works like a charm!
The images that I load are 16 bit, and thus the values printed should also be 16 bit RGB values. Is that possible?[/quote]
hmm…
check out this code (copied from the wiki)
ofTexture* invert_color_image(ofImage* im) {
int bytes_per_pixel = im->bpp / 8;
if (im->type != OF_IMAGE_COLOR || bytes_per_pixel != 3)
// This function only works on RGB images.
return NULL;
int w = im->width;
int h = im->height;
// (t) will hold the result of the processing that we do on (im).
ofTexture* t = new ofTexture();
t->allocate(w, h, GL_RGB);
unsigned char* im_pixels = im->getPixels(); // These are the pixel data of im,
unsigned char* p = new unsigned char[w*h*bytes_per_pixel]; // and here's where we keep our processed pixel data.
for (int i = 0; i < w*h; i++) {
int base = i * bytes_per_pixel;
// Assuming the pixels come in RGB order, here we grab the intensity
// (a value in the range [0,255]) of each color channel of the image.
unsigned char r = im_pixels[base + 0];
unsigned char g = im_pixels[base + 1];
unsigned char b = im_pixels[base + 2];
p[base + 0] = 255 - r; // Invert R.
p[base + 1] = 255 - g; // Invert G.
p[base + 2] = 255 - b; // Invert B.
}
t->loadData(p, w, h, GL_RGB); // This copies our processed pixel data into a texture that can be displayed.
delete [] p; // Because loadData performed a copy, we no longer need to store the processed pixel data.
return t;
}