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

Comparing CV/CV.xs (file contents):
Revision 1.24 by root, Wed Aug 17 05:25:28 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:
140#endif 180#endif
141 OUTPUT: 181 OUTPUT:
142 RETVAL 182 RETVAL
143 183
144GdkPixbuf_noinc * 184GdkPixbuf_noinc *
145transpose (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 int bpp = gdk_pixbuf_get_n_channels (pb); 190 int bpp = gdk_pixbuf_get_n_channels (pb);
151 int x, y, i; 191 int x, y, i;
152 guchar *src = gdk_pixbuf_get_pixels (pb), *dst; 192 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
153 int sstr = gdk_pixbuf_get_rowstride (pb), dstr; 193 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
154 194
155 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, h, w); 195 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
156 196
157 dst = gdk_pixbuf_get_pixels (RETVAL); 197 dst = gdk_pixbuf_get_pixels (RETVAL);
158 dstr = gdk_pixbuf_get_rowstride (RETVAL); 198 dstr = gdk_pixbuf_get_rowstride (RETVAL);
159 199
160 for (y = 0; y < h; y++)
161 for (x = 0; x < w; x++) 200 for (x = 0; x < w; x++)
201 for (y = 0; y < h; y++)
162 for (i = 0; i < bpp; i++) 202 for (i = 0; i < 3; i++)
163 dst[y * bpp + x * dstr + i] = src[x * bpp + y * sstr + i]; 203 dst[x * 3 + y * dstr + i] = src[x * bpp + y * sstr + i];
164} 204}
165 OUTPUT: 205 OUTPUT:
166 RETVAL 206 RETVAL
167 207
168GdkPixbuf_noinc * 208GdkPixbuf_noinc *
169flop (GdkPixbuf *pb) 209rotate (GdkPixbuf *pb, int angle)
170 CODE: 210 CODE:
171{ 211 RETVAL = gdk_pixbuf_rotate_simple (pb, angle == 0 ? GDK_PIXBUF_ROTATE_NONE
172 int w = gdk_pixbuf_get_width (pb); 212 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
173 int h = gdk_pixbuf_get_height (pb); 213 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN
174 int bpp = gdk_pixbuf_get_n_channels (pb); 214 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE
175 int x, y, i; 215 : angle);
176 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
177 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
178
179 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, w, h);
180
181 dst = gdk_pixbuf_get_pixels (RETVAL);
182 dstr = gdk_pixbuf_get_rowstride (RETVAL);
183
184 for (y = 0; y < h; y++)
185 for (x = 0; x < w; x++)
186 for (i = 0; i < bpp; i++)
187 dst[(w - 1 - x) * bpp + y * dstr + i] = src[x * bpp + y * sstr + i];
188}
189 OUTPUT: 216 OUTPUT:
190 RETVAL 217 RETVAL
191 218
192GdkPixbuf_noinc * 219GdkPixbuf_noinc *
193load_jpeg (SV *path, int thumbnail=0) 220load_jpeg (SV *path, int thumbnail=0)
197 struct jpg_err_mgr jerr; 224 struct jpg_err_mgr jerr;
198 guchar *data; 225 guchar *data;
199 int rs; 226 int rs;
200 FILE *fp; 227 FILE *fp;
201 volatile GdkPixbuf *pb = 0; 228 volatile GdkPixbuf *pb = 0;
202 gchar *filename;
203 229
204 RETVAL = 0; 230 RETVAL = 0;
205 231
206 filename = g_filename_from_utf8 (SvPVutf8_nolen (path), -1, 0, 0, 0);
207 fp = fopen (filename, "rb"); 232 fp = fopen (SvPVbyte_nolen (path), "rb");
208 g_free (filename);
209 233
210 if (!fp) 234 if (!fp)
211 XSRETURN_UNDEF; 235 XSRETURN_UNDEF;
212 236
213 cinfo.err = jpeg_std_error (&jerr.err); 237 cinfo.err = jpeg_std_error (&jerr.err);
296foldcase (SV *pathsv) 320foldcase (SV *pathsv)
297 PROTOTYPE: $ 321 PROTOTYPE: $
298 CODE: 322 CODE:
299{ 323{
300 STRLEN plen; 324 STRLEN plen;
301 U8 *path = SvPVutf8 (pathsv, plen); 325 U8 *path = (U8 *)SvPVutf8 (pathsv, plen);
302 U8 *pend = path + plen; 326 U8 *pend = path + plen;
303 U8 dst [plen * 6 * 3], *dstp = dst; 327 U8 dst [plen * 6 * 3], *dstp = dst;
304 328
305 while (path < pend) 329 while (path < pend)
306 { 330 {
327 dstp += cl; 351 dstp += cl;
328 path += is_utf8_char (path); 352 path += is_utf8_char (path);
329 } 353 }
330 } 354 }
331 355
332 RETVAL = newSVpvn (dst, dstp - dst); 356 RETVAL = newSVpvn ((const char *)dst, dstp - dst);
333} 357}
334 OUTPUT: 358 OUTPUT:
335 RETVAL 359 RETVAL
336 360
337GdkPixbuf_noinc * 361GdkPixbuf_noinc *
340 CODE: 364 CODE:
341{ 365{
342 int x, y; 366 int x, y;
343 guchar *dst, *d; 367 guchar *dst, *d;
344 int dstr; 368 int dstr;
345 guchar *src = SvPVbyte_nolen (src_sv); 369 guchar *src = (guchar *)SvPVbyte_nolen (src_sv);
346 370
347 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); 371 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
348 dst = gdk_pixbuf_get_pixels (RETVAL); 372 dst = gdk_pixbuf_get_pixels (RETVAL);
349 dstr = gdk_pixbuf_get_rowstride (RETVAL); 373 dstr = gdk_pixbuf_get_rowstride (RETVAL);
350 374
359 } 383 }
360} 384}
361 OUTPUT: 385 OUTPUT:
362 RETVAL 386 RETVAL
363 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
364SV * 436SV *
365pb_to_p7 (GdkPixbuf *pb) 437pb_to_hv84 (GdkPixbuf *pb)
366 CODE: 438 CODE:
367{ 439{
368 int w = gdk_pixbuf_get_width (pb); 440 int w = gdk_pixbuf_get_width (pb);
369 int h = gdk_pixbuf_get_height (pb); 441 int h = gdk_pixbuf_get_height (pb);
370 int x, y; 442 int x, y;
371 guchar *dst; 443 guchar *dst;
372 int bpp = gdk_pixbuf_get_n_channels (pb); 444 int bpp = gdk_pixbuf_get_n_channels (pb);
373 guchar *src = gdk_pixbuf_get_pixels (pb); 445 guchar *src = gdk_pixbuf_get_pixels (pb);
374 int sstr = gdk_pixbuf_get_rowstride (pb); 446 int sstr = gdk_pixbuf_get_rowstride (pb);
375 int Er[IW], Eg[IW], Eb[IW];
376 int seed = 77;
377
378 RETVAL = newSV (w * h);
379 SvPOK_only (RETVAL);
380 SvCUR_set (RETVAL, w * h);
381
382 dst = SvPVX (RETVAL);
383
384 memset (Er, 0, sizeof (int) * IW);
385 memset (Eg, 0, sizeof (int) * IW);
386 memset (Eb, 0, sizeof (int) * IW);
387
388 /* some primitive error distribution + random dithering */
389
390 for (y = 0; y < h; y++)
391 {
392 int er = 0, eg = 0, eb = 0;
393
394 for (x = 0; x < w; x++)
395 {
396 int r, g, b;
397 guchar *p = src + x * bpp + y * sstr;
398
399 r = ((p[0] + er + Er[x]) * 7 + (RAND & 127) + 64) / 255;
400 g = ((p[1] + eg + Eg[x]) * 7 + (RAND & 127) + 64) / 255;
401 b = ((p[2] + eb + Eb[x]) * 3 + (RAND & 127) + 64) / 255;
402
403 r = r > 7 ? 7 : r < 0 ? 0 : r;
404 g = g > 7 ? 7 : g < 0 ? 0 : g;
405 b = b > 3 ? 3 : b < 0 ? 0 : b;
406
407 er += p[0] - (r * 255 + 4) / 7;
408 eg += p[1] - (g * 255 + 4) / 7;
409 eb += p[2] - (b * 255 + 2) / 3;
410
411 Er[x] = er >> 1; er -= (er + 1) >> 1;
412 Eg[x] = eg >> 1; eg -= (eg + 1) >> 1;
413 Eb[x] = eb >> 1; eb -= (eb + 1) >> 1;
414
415 *dst++ = r << 5 | g << 2 | b;
416 }
417 }
418}
419 OUTPUT:
420 RETVAL
421
422#############################################################################
423
424MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
425
426void
427dump_ascii85 (PerlIO *fp, GdkPixbuf *pb)
428 CODE:
429{
430 int w = gdk_pixbuf_get_width (pb);
431 int h = gdk_pixbuf_get_height (pb);
432 int x, y, i;
433 guchar *dst;
434 int bpp = gdk_pixbuf_get_n_channels (pb);
435 guchar *src = gdk_pixbuf_get_pixels (pb);
436 int sstr = gdk_pixbuf_get_rowstride (pb);
437
438 a85_init ();
439
440 for (y = 0; y < h; y++)
441 for (x = 0; x < w; x++)
442 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
443 a85_push (fp, src [x * bpp + y * sstr + i]);
444
445 a85_finish (fp);
446}
447
448void
449dump_binary (PerlIO *fp, GdkPixbuf *pb)
450 CODE:
451{
452 int w = gdk_pixbuf_get_width (pb);
453 int h = gdk_pixbuf_get_height (pb);
454 int x, y, i;
455 guchar *dst;
456 int bpp = gdk_pixbuf_get_n_channels (pb);
457 guchar *src = gdk_pixbuf_get_pixels (pb);
458 int sstr = gdk_pixbuf_get_rowstride (pb);
459
460 for (y = 0; y < h; y++)
461 for (x = 0; x < w; x++)
462 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
463 PerlIO_putc (fp, src [x * bpp + y * sstr + i]);
464}
465
466#############################################################################
467
468MODULE = Gtk2::CV PACKAGE = Gtk2::CV
469
470SV *
471pb_to_hv84 (GdkPixbuf *pb)
472 CODE:
473{
474 int w = gdk_pixbuf_get_width (pb);
475 int h = gdk_pixbuf_get_height (pb);
476 int x, y;
477 guchar *dst;
478 int bpp = gdk_pixbuf_get_n_channels (pb);
479 guchar *src = gdk_pixbuf_get_pixels (pb);
480 int sstr = gdk_pixbuf_get_rowstride (pb);
481 447
482 RETVAL = newSV (6 * 8 * 12 / 8); 448 RETVAL = newSV (6 * 8 * 12 / 8);
483 SvPOK_only (RETVAL); 449 SvPOK_only (RETVAL);
484 SvCUR_set (RETVAL, 6 * 8 * 12 / 8); 450 SvCUR_set (RETVAL, 6 * 8 * 12 / 8);
485 451
486 dst = SvPVX (RETVAL); 452 dst = (guchar *)SvPVX (RETVAL);
487 453
488 /* some primitive error distribution + random dithering */ 454 /* some primitive error distribution + random dithering */
489 455
490 for (y = 0; y < h; y++) 456 for (y = 0; y < h; y++)
491 { 457 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines