Following similar precept we can do color masking by removing the effect of that particular colour. I will show you the masking for red as the masking for other colours is obvious.
pixel.red =0x00; //mask red. pixel.green |=0; //no change. pixel.blue |=0; //no change.
The routine below modifies the image removing the said
component [color takes values of either [r/R] or [g/G] or [b/B]]
and processes it.[ see
] . This code yielded figures
like this.
#include<gtk/gtk.h>
void colormask_picture(GdkPixbuf *pb,gchar color)
{
int ht,wt;
int i=0,j=0;
int rowstride=0;
int bpp=0;
gchar *pixel;
if(gdk_pixbuf_get_bits_per_sample(pb)!=8) //we handle only 24 bit images.
return; //look at 3 bytes per pixel.
bpp=3; //getting attributes of height,
ht=gdk_pixbuf_get_height(pb); //width, and bpp.Also get pointer
wt=gdk_pixbuf_get_width(pb); //to pixels.
pixel=gdk_pixbuf_get_pixels(pb);
rowstride=wt*bpp;
for(i=0;i<ht;i++) //iterate over the height of image.
for(j=0;j<rowstride;j+=bpp) //read every pixel in the row.skip
//bpp bytes
{
//access pixel[i][j] as
// pixel[i*rowstride + j]
//access red,green and blue as
switch(color)
{
case 'r':
case 'R':
pixel[i*rowstride + j+0]=0x00;//mask red;
break;
case 'g':
case 'G':
pixel[i*rowstride + j+1]=0x00;//mask green
break;
case 'b':
case 'B':
pixel[i*rowstride + j+2]=0x00;//mask blue;
default:
pixel[i*rowstride + j+2]=0x00;//mask blue;
}
}
return;
}
% <!-- provide link here-->
% complete working example with glue code in example_colormask.c