Making all the three pixels take up the value of their average values gives a gray scale effect. This however is very rudimentary, method of grey scaling. The image looks very ugly so I'm not putting it up. ;-)!
average=(pixel.red+pixel.green+pixel.blue)/3;
pixel.red =average;
pixel.green =average;
pixel.blue =average;
#include<gtk/gtk.h>
void colorgrey_picture(GdkPixbuf *pb)
{
int ht,wt;
int i=0,j=0;
int rowstride=0;
int bpp=0;
double avg=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
{
//find avg of the pixel to grey it.
avg+=pixel[i*rowstride + j+0]+pixel[i*rowstride + j+1]+pixel[i*rowstride + j+2];
avg/=3.00;
avg=((int)(avg))%256;
pixel[i*rowstride + j+0]=(int)avg;
pixel[i*rowstride + j+1]=(int)avg;
pixel[i*rowstride + j+2]=(int)avg;
}
return;
}
% <!-- provide link here-->
% complete working example with glue code in example_colorgrey.c