ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CV/CV.xs
Revision: 1.2
Committed: Mon Nov 3 00:04:22 2003 UTC (20 years, 6 months ago) by root
Branch: MAIN
Changes since 1.1: +81 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4
5 #include <gdk-pixbuf/gdk-pixbuf.h>
6
7 #include <gperl.h>
8 #include <gtk2perl.h>
9
10 MODULE = Gtk2::CV PACKAGE = Gtk2::CV::ImageWindow
11
12 PROTOTYPES: ENABLE
13
14 GdkPixbuf *
15 transpose (GdkPixbuf *pb)
16 CODE:
17 {
18 int w = gdk_pixbuf_get_width (pb);
19 int h = gdk_pixbuf_get_height (pb);
20 int bpp = gdk_pixbuf_get_has_alpha (pb) ? 4 : 3;
21 int x, y, i;
22 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
23 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
24
25 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, h, w);
26
27 dst = gdk_pixbuf_get_pixels (RETVAL);
28 dstr = gdk_pixbuf_get_rowstride (RETVAL);
29
30 for (x = 0; x < w; x++)
31 for (y = 0; y < h; y++)
32 for (i = 0; i < bpp; i++)
33 dst[y * bpp + x * dstr + i] = src[x * bpp + y * sstr + i];
34 }
35 OUTPUT:
36 RETVAL
37
38 GdkPixbuf *
39 flop (GdkPixbuf *pb)
40 CODE:
41 {
42 int w = gdk_pixbuf_get_width (pb);
43 int h = gdk_pixbuf_get_height (pb);
44 int bpp = gdk_pixbuf_get_has_alpha (pb) ? 4 : 3;
45 int x, y, i;
46 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
47 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
48
49 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, w, h);
50
51 dst = gdk_pixbuf_get_pixels (RETVAL);
52 dstr = gdk_pixbuf_get_rowstride (RETVAL);
53
54 for (x = 0; x < w; x++)
55 for (y = 0; y < h; y++)
56 for (i = 0; i < bpp; i++)
57 dst[(w - x) * bpp + y * dstr + i] = src[x *bpp + y * sstr + i];
58 }
59 OUTPUT:
60 RETVAL
61
62 MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer
63
64 GdkPixbuf *
65 p7_to_pb (int w, int h, guchar *src)
66 CODE:
67 {
68 int x, y;
69 guchar *dst, *d;
70 int dstr;
71
72 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
73 dst = gdk_pixbuf_get_pixels (RETVAL);
74 dstr = gdk_pixbuf_get_rowstride (RETVAL);
75
76 for (y = 0; y < h; y++)
77 for (d = dst + y * dstr, x = 0; x < w; x++)
78 {
79 *d++ = ((*src >> 5) & 7) * 255 / 7;
80 *d++ = ((*src >> 2) & 7) * 255 / 7;
81 *d++ = ((*src >> 0) & 3) * 255 / 3;
82
83 src++;
84 }
85 }
86 OUTPUT:
87 RETVAL
88
89
90