ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CV/CV.xs
(Generate patch)

Comparing CV/CV.xs (file contents):
Revision 1.26 by root, Sun Aug 21 02:18:30 2005 UTC vs.
Revision 1.32 by root, Wed Feb 15 08:36:55 2006 UTC

2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5#include <string.h> 5#include <string.h>
6#include <setjmp.h> 6#include <setjmp.h>
7
8#include <magic.h>
7 9
8#include <jpeglib.h> 10#include <jpeglib.h>
9#include <glib.h> 11#include <glib.h>
10#include <gtk/gtk.h> 12#include <gtk/gtk.h>
11#include <gdk-pixbuf/gdk-pixbuf.h> 13#include <gdk-pixbuf/gdk-pixbuf.h>
126 128
127MODULE = Gtk2::CV PACKAGE = Gtk2::CV 129MODULE = Gtk2::CV PACKAGE = Gtk2::CV
128 130
129PROTOTYPES: ENABLE 131PROTOTYPES: ENABLE
130 132
133# missing function in perl. really :)
134int
135common_prefix_length (a, b)
136 unsigned char *a = (unsigned char *)SvPVutf8_nolen ($arg);
137 unsigned char *b = (unsigned char *)SvPVutf8_nolen ($arg);
138 CODE:
139 RETVAL = 0;
140
141 while (*a == *b && *a)
142 {
143 RETVAL += (*a & 0xc0) != 0x80;
144 a++, b++;
145 }
146
147 OUTPUT:
148 RETVAL
149
150const char *
151magic (const char *path)
152 CODE:
153{
154 static magic_t cookie;
155
156 if (!cookie)
157 {
158 cookie = magic_open (MAGIC_NONE);
159
160 if (cookie)
161 magic_load (cookie, 0);
162 else
163 XSRETURN_UNDEF;
164 }
165
166 RETVAL = magic_file (cookie, path);
167}
168 OUTPUT:
169 RETVAL
170
171const char *
172magic_mime (const char *path)
173 CODE:
174{
175 static magic_t cookie;
176
177 if (!cookie)
178 {
179 cookie = magic_open (MAGIC_MIME);
180
181 if (cookie)
182 magic_load (cookie, 0);
183 else
184 XSRETURN_UNDEF;
185 }
186
187 RETVAL = magic_file (cookie, path);
188}
189 OUTPUT:
190 RETVAL
191
131# missing in Gtk2 perl module 192# missing in Gtk2 perl module
132 193
133gboolean 194gboolean
134gdk_net_wm_supports (GdkAtom property) 195gdk_net_wm_supports (GdkAtom property)
135 CODE: 196 CODE:
145dealpha_expose (GdkPixbuf *pb) 206dealpha_expose (GdkPixbuf *pb)
146 CODE: 207 CODE:
147{ 208{
148 int w = gdk_pixbuf_get_width (pb); 209 int w = gdk_pixbuf_get_width (pb);
149 int h = gdk_pixbuf_get_height (pb); 210 int h = gdk_pixbuf_get_height (pb);
150 fprintf (stderr, "new %d %d\n", w, h);
151 int bpp = gdk_pixbuf_get_n_channels (pb); 211 int bpp = gdk_pixbuf_get_n_channels (pb);
152 int x, y, i; 212 int x, y, i;
153 guchar *src = gdk_pixbuf_get_pixels (pb), *dst; 213 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
154 int sstr = gdk_pixbuf_get_rowstride (pb), dstr; 214 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
155 215
165} 225}
166 OUTPUT: 226 OUTPUT:
167 RETVAL 227 RETVAL
168 228
169GdkPixbuf_noinc * 229GdkPixbuf_noinc *
170transpose (GdkPixbuf *pb) 230rotate (GdkPixbuf *pb, int angle)
171 CODE: 231 CODE:
172{ 232 RETVAL = gdk_pixbuf_rotate_simple (pb, angle == 0 ? GDK_PIXBUF_ROTATE_NONE
173 int w = gdk_pixbuf_get_width (pb); 233 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
174 int h = gdk_pixbuf_get_height (pb); 234 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN
175 int bpp = gdk_pixbuf_get_n_channels (pb); 235 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE
176 int x, y, i; 236 : angle);
177 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
178 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
179
180 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, h, w);
181
182 dst = gdk_pixbuf_get_pixels (RETVAL);
183 dstr = gdk_pixbuf_get_rowstride (RETVAL);
184
185 for (y = 0; y < h; y++)
186 for (x = 0; x < w; x++)
187 for (i = 0; i < bpp; i++)
188 dst[y * bpp + x * dstr + i] = src[x * bpp + y * sstr + i];
189}
190 OUTPUT:
191 RETVAL
192
193GdkPixbuf_noinc *
194flop (GdkPixbuf *pb)
195 CODE:
196{
197 int w = gdk_pixbuf_get_width (pb);
198 int h = gdk_pixbuf_get_height (pb);
199 int bpp = gdk_pixbuf_get_n_channels (pb);
200 int x, y, i;
201 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
202 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
203
204 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, w, h);
205
206 dst = gdk_pixbuf_get_pixels (RETVAL);
207 dstr = gdk_pixbuf_get_rowstride (RETVAL);
208
209 for (y = 0; y < h; y++)
210 for (x = 0; x < w; x++)
211 for (i = 0; i < bpp; i++)
212 dst[(w - 1 - x) * bpp + y * dstr + i] = src[x * bpp + y * sstr + i];
213}
214 OUTPUT: 237 OUTPUT:
215 RETVAL 238 RETVAL
216 239
217GdkPixbuf_noinc * 240GdkPixbuf_noinc *
218load_jpeg (SV *path, int thumbnail=0) 241load_jpeg (SV *path, int thumbnail=0)
222 struct jpg_err_mgr jerr; 245 struct jpg_err_mgr jerr;
223 guchar *data; 246 guchar *data;
224 int rs; 247 int rs;
225 FILE *fp; 248 FILE *fp;
226 volatile GdkPixbuf *pb = 0; 249 volatile GdkPixbuf *pb = 0;
227 gchar *filename;
228 250
229 RETVAL = 0; 251 RETVAL = 0;
230 252
231 filename = g_filename_from_utf8 (SvPVutf8_nolen (path), -1, 0, 0, 0);
232 fp = fopen (filename, "rb"); 253 fp = fopen (SvPVbyte_nolen (path), "rb");
233 g_free (filename);
234 254
235 if (!fp) 255 if (!fp)
236 XSRETURN_UNDEF; 256 XSRETURN_UNDEF;
237 257
238 cinfo.err = jpeg_std_error (&jerr.err); 258 cinfo.err = jpeg_std_error (&jerr.err);
384 } 404 }
385} 405}
386 OUTPUT: 406 OUTPUT:
387 RETVAL 407 RETVAL
388 408
409#############################################################################
410
411MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
412
413void
414dump_ascii85 (PerlIO *fp, GdkPixbuf *pb)
415 CODE:
416{
417 int w = gdk_pixbuf_get_width (pb);
418 int h = gdk_pixbuf_get_height (pb);
419 int x, y, i;
420 guchar *dst;
421 int bpp = gdk_pixbuf_get_n_channels (pb);
422 guchar *src = gdk_pixbuf_get_pixels (pb);
423 int sstr = gdk_pixbuf_get_rowstride (pb);
424
425 a85_init ();
426
427 for (y = 0; y < h; y++)
428 for (x = 0; x < w; x++)
429 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
430 a85_push (fp, src [x * bpp + y * sstr + i]);
431
432 a85_finish (fp);
433}
434
435void
436dump_binary (PerlIO *fp, GdkPixbuf *pb)
437 CODE:
438{
439 int w = gdk_pixbuf_get_width (pb);
440 int h = gdk_pixbuf_get_height (pb);
441 int x, y, i;
442 guchar *dst;
443 int bpp = gdk_pixbuf_get_n_channels (pb);
444 guchar *src = gdk_pixbuf_get_pixels (pb);
445 int sstr = gdk_pixbuf_get_rowstride (pb);
446
447 for (y = 0; y < h; y++)
448 for (x = 0; x < w; x++)
449 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
450 PerlIO_putc (fp, src [x * bpp + y * sstr + i]);
451}
452
453#############################################################################
454
455MODULE = Gtk2::CV PACKAGE = Gtk2::CV
456
389SV * 457SV *
390pb_to_p7 (GdkPixbuf *pb) 458pb_to_hv84 (GdkPixbuf *pb)
391 CODE: 459 CODE:
392{ 460{
393 int w = gdk_pixbuf_get_width (pb); 461 int w = gdk_pixbuf_get_width (pb);
394 int h = gdk_pixbuf_get_height (pb); 462 int h = gdk_pixbuf_get_height (pb);
395 int x, y; 463 int x, y;
396 guchar *dst; 464 guchar *dst;
397 int bpp = gdk_pixbuf_get_n_channels (pb); 465 int bpp = gdk_pixbuf_get_n_channels (pb);
398 guchar *src = gdk_pixbuf_get_pixels (pb); 466 guchar *src = gdk_pixbuf_get_pixels (pb);
399 int sstr = gdk_pixbuf_get_rowstride (pb); 467 int sstr = gdk_pixbuf_get_rowstride (pb);
400 int Er[IW], Eg[IW], Eb[IW];
401 int seed = 77;
402
403 RETVAL = newSV (w * h);
404 SvPOK_only (RETVAL);
405 SvCUR_set (RETVAL, w * h);
406
407 dst = (guchar *)SvPVX (RETVAL);
408
409 memset (Er, 0, sizeof (int) * IW);
410 memset (Eg, 0, sizeof (int) * IW);
411 memset (Eb, 0, sizeof (int) * IW);
412
413 /* some primitive error distribution + random dithering */
414
415 for (y = 0; y < h; y++)
416 {
417 int er = 0, eg = 0, eb = 0;
418
419 for (x = 0; x < w; x++)
420 {
421 int r, g, b;
422 guchar *p = src + x * bpp + y * sstr;
423
424 r = ((p[0] + er + Er[x]) * 7 + (RAND & 127) + 64) / 255;
425 g = ((p[1] + eg + Eg[x]) * 7 + (RAND & 127) + 64) / 255;
426 b = ((p[2] + eb + Eb[x]) * 3 + (RAND & 127) + 64) / 255;
427
428 r = r > 7 ? 7 : r < 0 ? 0 : r;
429 g = g > 7 ? 7 : g < 0 ? 0 : g;
430 b = b > 3 ? 3 : b < 0 ? 0 : b;
431
432 er += p[0] - (r * 255 + 4) / 7;
433 eg += p[1] - (g * 255 + 4) / 7;
434 eb += p[2] - (b * 255 + 2) / 3;
435
436 Er[x] = er >> 1; er -= (er + 1) >> 1;
437 Eg[x] = eg >> 1; eg -= (eg + 1) >> 1;
438 Eb[x] = eb >> 1; eb -= (eb + 1) >> 1;
439
440 *dst++ = r << 5 | g << 2 | b;
441 }
442 }
443}
444 OUTPUT:
445 RETVAL
446
447#############################################################################
448
449MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
450
451void
452dump_ascii85 (PerlIO *fp, GdkPixbuf *pb)
453 CODE:
454{
455 int w = gdk_pixbuf_get_width (pb);
456 int h = gdk_pixbuf_get_height (pb);
457 int x, y, i;
458 guchar *dst;
459 int bpp = gdk_pixbuf_get_n_channels (pb);
460 guchar *src = gdk_pixbuf_get_pixels (pb);
461 int sstr = gdk_pixbuf_get_rowstride (pb);
462
463 a85_init ();
464
465 for (y = 0; y < h; y++)
466 for (x = 0; x < w; x++)
467 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
468 a85_push (fp, src [x * bpp + y * sstr + i]);
469
470 a85_finish (fp);
471}
472
473void
474dump_binary (PerlIO *fp, GdkPixbuf *pb)
475 CODE:
476{
477 int w = gdk_pixbuf_get_width (pb);
478 int h = gdk_pixbuf_get_height (pb);
479 int x, y, i;
480 guchar *dst;
481 int bpp = gdk_pixbuf_get_n_channels (pb);
482 guchar *src = gdk_pixbuf_get_pixels (pb);
483 int sstr = gdk_pixbuf_get_rowstride (pb);
484
485 for (y = 0; y < h; y++)
486 for (x = 0; x < w; x++)
487 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
488 PerlIO_putc (fp, src [x * bpp + y * sstr + i]);
489}
490
491#############################################################################
492
493MODULE = Gtk2::CV PACKAGE = Gtk2::CV
494
495SV *
496pb_to_hv84 (GdkPixbuf *pb)
497 CODE:
498{
499 int w = gdk_pixbuf_get_width (pb);
500 int h = gdk_pixbuf_get_height (pb);
501 int x, y;
502 guchar *dst;
503 int bpp = gdk_pixbuf_get_n_channels (pb);
504 guchar *src = gdk_pixbuf_get_pixels (pb);
505 int sstr = gdk_pixbuf_get_rowstride (pb);
506 468
507 RETVAL = newSV (6 * 8 * 12 / 8); 469 RETVAL = newSV (6 * 8 * 12 / 8);
508 SvPOK_only (RETVAL); 470 SvPOK_only (RETVAL);
509 SvCUR_set (RETVAL, 6 * 8 * 12 / 8); 471 SvCUR_set (RETVAL, 6 * 8 * 12 / 8);
510 472

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines