Back to index

gcompris  8.2.2
Functions
pixbuf_util.c File Reference
#include "pixbuf_util.h"

Go to the source code of this file.

Functions

GdkPixbuf * pixbuf_copy_mirror (GdkPixbuf *src, gint mirror, gint flip)

Function Documentation

GdkPixbuf* pixbuf_copy_mirror ( GdkPixbuf *  src,
gint  mirror,
gint  flip 
)

Definition at line 21 of file pixbuf_util.c.

{
       GdkPixbuf *dest;
       gint has_alpha;
       gint w, h, srs;
       gint drs;
       guchar *s_pix;
        guchar *d_pix;
       guchar *sp;
        guchar *dp;
       gint i, j;
       gint a;

       if (!src) return NULL;

       w = gdk_pixbuf_get_width(src);
       h = gdk_pixbuf_get_height(src);
       has_alpha = gdk_pixbuf_get_has_alpha(src);
       srs = gdk_pixbuf_get_rowstride(src);
       s_pix = gdk_pixbuf_get_pixels(src);

       dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8, w, h);
       drs = gdk_pixbuf_get_rowstride(dest);
       d_pix = gdk_pixbuf_get_pixels(dest);

       a = has_alpha ? 4 : 3;

       for (i = 0; i < h; i++)
              {
              sp = s_pix + (i * srs);
              if (flip)
                     {
                     dp = d_pix + ((h - i - 1) * drs);
                     }
              else
                     {
                     dp = d_pix + (i * drs);
                     }
              if (mirror)
                     {
                     dp += (w - 1) * a;
                     for (j = 0; j < w; j++)
                            {
                            *(dp++) = *(sp++);   /* r */
                            *(dp++) = *(sp++);   /* g */
                            *(dp++) = *(sp++);   /* b */
                            if (has_alpha) *(dp) = *(sp++);    /* a */
                            dp -= (a + 3);
                            }
                     }
              else
                     {
                     for (j = 0; j < w; j++)
                            {
                            *(dp++) = *(sp++);   /* r */
                            *(dp++) = *(sp++);   /* g */
                            *(dp++) = *(sp++);   /* b */
                            if (has_alpha) *(dp++) = *(sp++);  /* a */
                            }
                     }
              }

       return dest;
}

Here is the caller graph for this function: