next up previous contents
Next: Image Inversion Up: Image Processing using GTK. Previous: Brightening:   Contents

Image flipping

Take the first column and swap it with the last col. Do this for the first width/2 columns then we have a flipped image.

Figure: Kathakali, Image L-R flipped, Look closely! see Fig:2
Image kathakali_pictureflip

void flip_picture(GdkPixbuf *pb) //Left to Right
{
  int ht,wt;
  int i=0,j=0;
  
  gchar *pixel;
  ht=gdk_pixbuf_get_height(pb);
  wt=gdk_pixbuf_get_width(pb);
  pixel=gdk_pixbuf_get_pixels(pb);



  for(i=0;i<ht;i++)           //half the width
    for(j=0;j<(wt/2)*3;j+=3)
      {	
	swap(pixel[i*wt*3+j+0],pixel[i*wt*3+(wt*3-j)+0]);
	swap(pixel[i*wt*3+j+1],pixel[i*wt*3+(wt*3-j)+1]);
	swap(pixel[i*wt*3+j+2],pixel[i*wt*3+(wt*3-j)+2]);
      }
  return;
}



Muthiah 2004-06-04