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.31 by root, Wed Feb 15 08:08:37 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_MIME);
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
131# missing in Gtk2 perl module 171# missing in Gtk2 perl module
132 172
133gboolean 173gboolean
134gdk_net_wm_supports (GdkAtom property) 174gdk_net_wm_supports (GdkAtom property)
135 CODE: 175 CODE:
145dealpha_expose (GdkPixbuf *pb) 185dealpha_expose (GdkPixbuf *pb)
146 CODE: 186 CODE:
147{ 187{
148 int w = gdk_pixbuf_get_width (pb); 188 int w = gdk_pixbuf_get_width (pb);
149 int h = gdk_pixbuf_get_height (pb); 189 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); 190 int bpp = gdk_pixbuf_get_n_channels (pb);
152 int x, y, i; 191 int x, y, i;
153 guchar *src = gdk_pixbuf_get_pixels (pb), *dst; 192 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
154 int sstr = gdk_pixbuf_get_rowstride (pb), dstr; 193 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
155 194
165} 204}
166 OUTPUT: 205 OUTPUT:
167 RETVAL 206 RETVAL
168 207
169GdkPixbuf_noinc * 208GdkPixbuf_noinc *
170transpose (GdkPixbuf *pb) 209rotate (GdkPixbuf *pb, int angle)
171 CODE: 210 CODE:
172{ 211 RETVAL = gdk_pixbuf_rotate_simple (pb, angle == 0 ? GDK_PIXBUF_ROTATE_NONE
173 int w = gdk_pixbuf_get_width (pb); 212 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
174 int h = gdk_pixbuf_get_height (pb); 213 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN
175 int bpp = gdk_pixbuf_get_n_channels (pb); 214 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE
176 int x, y, i; 215 : 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: 216 OUTPUT:
215 RETVAL 217 RETVAL
216 218
217GdkPixbuf_noinc * 219GdkPixbuf_noinc *
218load_jpeg (SV *path, int thumbnail=0) 220load_jpeg (SV *path, int thumbnail=0)
222 struct jpg_err_mgr jerr; 224 struct jpg_err_mgr jerr;
223 guchar *data; 225 guchar *data;
224 int rs; 226 int rs;
225 FILE *fp; 227 FILE *fp;
226 volatile GdkPixbuf *pb = 0; 228 volatile GdkPixbuf *pb = 0;
227 gchar *filename;
228 229
229 RETVAL = 0; 230 RETVAL = 0;
230 231
231 filename = g_filename_from_utf8 (SvPVutf8_nolen (path), -1, 0, 0, 0);
232 fp = fopen (filename, "rb"); 232 fp = fopen (SvPVbyte_nolen (path), "rb");
233 g_free (filename);
234 233
235 if (!fp) 234 if (!fp)
236 XSRETURN_UNDEF; 235 XSRETURN_UNDEF;
237 236
238 cinfo.err = jpeg_std_error (&jerr.err); 237 cinfo.err = jpeg_std_error (&jerr.err);
384 } 383 }
385} 384}
386 OUTPUT: 385 OUTPUT:
387 RETVAL 386 RETVAL
388 387
388#############################################################################
389
390MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
391
392void
393dump_ascii85 (PerlIO *fp, GdkPixbuf *pb)
394 CODE:
395{
396 int w = gdk_pixbuf_get_width (pb);
397 int h = gdk_pixbuf_get_height (pb);
398 int x, y, i;
399 guchar *dst;
400 int bpp = gdk_pixbuf_get_n_channels (pb);
401 guchar *src = gdk_pixbuf_get_pixels (pb);
402 int sstr = gdk_pixbuf_get_rowstride (pb);
403
404 a85_init ();
405
406 for (y = 0; y < h; y++)
407 for (x = 0; x < w; x++)
408 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
409 a85_push (fp, src [x * bpp + y * sstr + i]);
410
411 a85_finish (fp);
412}
413
414void
415dump_binary (PerlIO *fp, GdkPixbuf *pb)
416 CODE:
417{
418 int w = gdk_pixbuf_get_width (pb);
419 int h = gdk_pixbuf_get_height (pb);
420 int x, y, i;
421 guchar *dst;
422 int bpp = gdk_pixbuf_get_n_channels (pb);
423 guchar *src = gdk_pixbuf_get_pixels (pb);
424 int sstr = gdk_pixbuf_get_rowstride (pb);
425
426 for (y = 0; y < h; y++)
427 for (x = 0; x < w; x++)
428 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
429 PerlIO_putc (fp, src [x * bpp + y * sstr + i]);
430}
431
432#############################################################################
433
434MODULE = Gtk2::CV PACKAGE = Gtk2::CV
435
389SV * 436SV *
390pb_to_p7 (GdkPixbuf *pb) 437pb_to_hv84 (GdkPixbuf *pb)
391 CODE: 438 CODE:
392{ 439{
393 int w = gdk_pixbuf_get_width (pb); 440 int w = gdk_pixbuf_get_width (pb);
394 int h = gdk_pixbuf_get_height (pb); 441 int h = gdk_pixbuf_get_height (pb);
395 int x, y; 442 int x, y;
396 guchar *dst; 443 guchar *dst;
397 int bpp = gdk_pixbuf_get_n_channels (pb); 444 int bpp = gdk_pixbuf_get_n_channels (pb);
398 guchar *src = gdk_pixbuf_get_pixels (pb); 445 guchar *src = gdk_pixbuf_get_pixels (pb);
399 int sstr = gdk_pixbuf_get_rowstride (pb); 446 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 447
507 RETVAL = newSV (6 * 8 * 12 / 8); 448 RETVAL = newSV (6 * 8 * 12 / 8);
508 SvPOK_only (RETVAL); 449 SvPOK_only (RETVAL);
509 SvCUR_set (RETVAL, 6 * 8 * 12 / 8); 450 SvCUR_set (RETVAL, 6 * 8 * 12 / 8);
510 451

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines