#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include #include #include MODULE = Gtk2::CV PACKAGE = Gtk2::CV::ImageWindow PROTOTYPES: ENABLE GdkPixbuf * transpose (GdkPixbuf *pb) CODE: { int w = gdk_pixbuf_get_width (pb); int h = gdk_pixbuf_get_height (pb); int bpp = gdk_pixbuf_get_has_alpha (pb) ? 4 : 3; int x, y, i; guchar *src = gdk_pixbuf_get_pixels (pb), *dst; int sstr = gdk_pixbuf_get_rowstride (pb), dstr; RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, h, w); dst = gdk_pixbuf_get_pixels (RETVAL); dstr = gdk_pixbuf_get_rowstride (RETVAL); for (x = 0; x < w; x++) for (y = 0; y < h; y++) for (i = 0; i < bpp; i++) dst[y * bpp + x * dstr + i] = src[x * bpp + y * sstr + i]; } OUTPUT: RETVAL GdkPixbuf * flop (GdkPixbuf *pb) CODE: { int w = gdk_pixbuf_get_width (pb); int h = gdk_pixbuf_get_height (pb); int bpp = gdk_pixbuf_get_has_alpha (pb) ? 4 : 3; int x, y, i; guchar *src = gdk_pixbuf_get_pixels (pb), *dst; int sstr = gdk_pixbuf_get_rowstride (pb), dstr; RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, w, h); dst = gdk_pixbuf_get_pixels (RETVAL); dstr = gdk_pixbuf_get_rowstride (RETVAL); for (x = 0; x < w; x++) for (y = 0; y < h; y++) for (i = 0; i < bpp; i++) dst[(w - x) * bpp + y * dstr + i] = src[x *bpp + y * sstr + i]; } OUTPUT: RETVAL MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer GdkPixbuf * p7_to_pb (int w, int h, guchar *src) CODE: { int x, y; guchar *dst, *d; int dstr; RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); dst = gdk_pixbuf_get_pixels (RETVAL); dstr = gdk_pixbuf_get_rowstride (RETVAL); for (y = 0; y < h; y++) for (d = dst + y * dstr, x = 0; x < w; x++) { *d++ = ((*src >> 5) & 7) * 255 / 7; *d++ = ((*src >> 2) & 7) * 255 / 7; *d++ = ((*src >> 0) & 3) * 255 / 3; src++; } } OUTPUT: RETVAL