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

Comparing CV/CV.xs (file contents):
Revision 1.22 by root, Sun Aug 14 02:25:44 2005 UTC vs.
Revision 1.30 by root, Wed Dec 28 20:56:20 2005 UTC

4 4
5#include <string.h> 5#include <string.h>
6#include <setjmp.h> 6#include <setjmp.h>
7 7
8#include <jpeglib.h> 8#include <jpeglib.h>
9#include <glib.h>
10#include <gtk/gtk.h>
9#include <gdk-pixbuf/gdk-pixbuf.h> 11#include <gdk-pixbuf/gdk-pixbuf.h>
10 12
11#include <gperl.h> 13#include <gperl.h>
12#include <gtk2perl.h> 14#include <gtk2perl.h>
13 15
124 126
125MODULE = Gtk2::CV PACKAGE = Gtk2::CV 127MODULE = Gtk2::CV PACKAGE = Gtk2::CV
126 128
127PROTOTYPES: ENABLE 129PROTOTYPES: ENABLE
128 130
131# missing function in perl. really :)
132int
133common_prefix_length (a, b)
134 unsigned char *a = (unsigned char *)SvPVutf8_nolen ($arg);
135 unsigned char *b = (unsigned char *)SvPVutf8_nolen ($arg);
136 CODE:
137 RETVAL = 0;
138
139 while (*a == *b && *a)
140 {
141 RETVAL += (*a & 0xc0) != 0x80;
142 a++, b++;
143 }
144
145 OUTPUT:
146 RETVAL
147
129# missing in Gtk2 perl module 148# missing in Gtk2 perl module
130 149
131gboolean 150gboolean
132gdk_net_wm_supports (GdkAtom property) 151gdk_net_wm_supports (GdkAtom property)
133 CODE: 152 CODE:
138#endif 157#endif
139 OUTPUT: 158 OUTPUT:
140 RETVAL 159 RETVAL
141 160
142GdkPixbuf_noinc * 161GdkPixbuf_noinc *
143transpose (GdkPixbuf *pb) 162dealpha_expose (GdkPixbuf *pb)
144 CODE: 163 CODE:
145{ 164{
146 int w = gdk_pixbuf_get_width (pb); 165 int w = gdk_pixbuf_get_width (pb);
147 int h = gdk_pixbuf_get_height (pb); 166 int h = gdk_pixbuf_get_height (pb);
148 int bpp = gdk_pixbuf_get_n_channels (pb); 167 int bpp = gdk_pixbuf_get_n_channels (pb);
149 int x, y, i; 168 int x, y, i;
150 guchar *src = gdk_pixbuf_get_pixels (pb), *dst; 169 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
151 int sstr = gdk_pixbuf_get_rowstride (pb), dstr; 170 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
152 171
153 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, h, w); 172 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
154 173
155 dst = gdk_pixbuf_get_pixels (RETVAL); 174 dst = gdk_pixbuf_get_pixels (RETVAL);
156 dstr = gdk_pixbuf_get_rowstride (RETVAL); 175 dstr = gdk_pixbuf_get_rowstride (RETVAL);
157 176
158 for (y = 0; y < h; y++)
159 for (x = 0; x < w; x++) 177 for (x = 0; x < w; x++)
178 for (y = 0; y < h; y++)
160 for (i = 0; i < bpp; i++) 179 for (i = 0; i < 3; i++)
161 dst[y * bpp + x * dstr + i] = src[x * bpp + y * sstr + i]; 180 dst[x * 3 + y * dstr + i] = src[x * bpp + y * sstr + i];
162} 181}
163 OUTPUT: 182 OUTPUT:
164 RETVAL 183 RETVAL
165 184
166GdkPixbuf_noinc * 185GdkPixbuf_noinc *
167flop (GdkPixbuf *pb) 186rotate (GdkPixbuf *pb, int angle)
168 CODE: 187 CODE:
169{ 188 RETVAL = gdk_pixbuf_rotate_simple (pb, angle == 0 ? GDK_PIXBUF_ROTATE_NONE
170 int w = gdk_pixbuf_get_width (pb); 189 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
171 int h = gdk_pixbuf_get_height (pb); 190 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN
172 int bpp = gdk_pixbuf_get_n_channels (pb); 191 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE
173 int x, y, i; 192 : angle);
174 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
175 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
176
177 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, w, h);
178
179 dst = gdk_pixbuf_get_pixels (RETVAL);
180 dstr = gdk_pixbuf_get_rowstride (RETVAL);
181
182 for (y = 0; y < h; y++)
183 for (x = 0; x < w; x++)
184 for (i = 0; i < bpp; i++)
185 dst[(w - 1 - x) * bpp + y * dstr + i] = src[x * bpp + y * sstr + i];
186}
187 OUTPUT: 193 OUTPUT:
188 RETVAL 194 RETVAL
189 195
190GdkPixbuf_noinc * 196GdkPixbuf_noinc *
191load_jpeg (char *path, int thumbnail=0) 197load_jpeg (SV *path, int thumbnail=0)
192 CODE: 198 CODE:
193{ 199{
194 struct jpeg_decompress_struct cinfo; 200 struct jpeg_decompress_struct cinfo;
195 struct jpg_err_mgr jerr; 201 struct jpg_err_mgr jerr;
196 guchar *data; 202 guchar *data;
197 int rs; 203 int rs;
198 FILE *fp; 204 FILE *fp;
199 volatile GdkPixbuf *pb = 0; 205 volatile GdkPixbuf *pb = 0;
206
200 RETVAL = 0; 207 RETVAL = 0;
201 208
202 if (!(fp = fopen (path, "rb"))) 209 fp = fopen (SvPVbyte_nolen (path), "rb");
210
211 if (!fp)
203 XSRETURN_UNDEF; 212 XSRETURN_UNDEF;
204 213
205 cinfo.err = jpeg_std_error (&jerr.err); 214 cinfo.err = jpeg_std_error (&jerr.err);
206 215
207 jerr.err.error_exit = cv_error_exit; 216 jerr.err.error_exit = cv_error_exit;
288foldcase (SV *pathsv) 297foldcase (SV *pathsv)
289 PROTOTYPE: $ 298 PROTOTYPE: $
290 CODE: 299 CODE:
291{ 300{
292 STRLEN plen; 301 STRLEN plen;
293 U8 *path = SvPVutf8 (pathsv, plen); 302 U8 *path = (U8 *)SvPVutf8 (pathsv, plen);
294 U8 *pend = path + plen; 303 U8 *pend = path + plen;
295 U8 dst [plen * 6 * 3], *dstp = dst; 304 U8 dst [plen * 6 * 3], *dstp = dst;
296 305
297 while (path < pend) 306 while (path < pend)
298 { 307 {
319 dstp += cl; 328 dstp += cl;
320 path += is_utf8_char (path); 329 path += is_utf8_char (path);
321 } 330 }
322 } 331 }
323 332
324 RETVAL = newSVpvn (dst, dstp - dst); 333 RETVAL = newSVpvn ((const char *)dst, dstp - dst);
325} 334}
326 OUTPUT: 335 OUTPUT:
327 RETVAL 336 RETVAL
328 337
329GdkPixbuf_noinc * 338GdkPixbuf_noinc *
330p7_to_pb (int w, int h, guchar *src) 339p7_to_pb (int w, int h, SV *src_sv)
331 PROTOTYPE: @ 340 PROTOTYPE: @
332 CODE: 341 CODE:
333{ 342{
334 int x, y; 343 int x, y;
335 guchar *dst, *d; 344 guchar *dst, *d;
336 int dstr; 345 int dstr;
346 guchar *src = (guchar *)SvPVbyte_nolen (src_sv);
337 347
338 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); 348 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
339 dst = gdk_pixbuf_get_pixels (RETVAL); 349 dst = gdk_pixbuf_get_pixels (RETVAL);
340 dstr = gdk_pixbuf_get_rowstride (RETVAL); 350 dstr = gdk_pixbuf_get_rowstride (RETVAL);
341 351
350 } 360 }
351} 361}
352 OUTPUT: 362 OUTPUT:
353 RETVAL 363 RETVAL
354 364
365#############################################################################
366
367MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
368
369void
370dump_ascii85 (PerlIO *fp, GdkPixbuf *pb)
371 CODE:
372{
373 int w = gdk_pixbuf_get_width (pb);
374 int h = gdk_pixbuf_get_height (pb);
375 int x, y, i;
376 guchar *dst;
377 int bpp = gdk_pixbuf_get_n_channels (pb);
378 guchar *src = gdk_pixbuf_get_pixels (pb);
379 int sstr = gdk_pixbuf_get_rowstride (pb);
380
381 a85_init ();
382
383 for (y = 0; y < h; y++)
384 for (x = 0; x < w; x++)
385 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
386 a85_push (fp, src [x * bpp + y * sstr + i]);
387
388 a85_finish (fp);
389}
390
391void
392dump_binary (PerlIO *fp, GdkPixbuf *pb)
393 CODE:
394{
395 int w = gdk_pixbuf_get_width (pb);
396 int h = gdk_pixbuf_get_height (pb);
397 int x, y, i;
398 guchar *dst;
399 int bpp = gdk_pixbuf_get_n_channels (pb);
400 guchar *src = gdk_pixbuf_get_pixels (pb);
401 int sstr = gdk_pixbuf_get_rowstride (pb);
402
403 for (y = 0; y < h; y++)
404 for (x = 0; x < w; x++)
405 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
406 PerlIO_putc (fp, src [x * bpp + y * sstr + i]);
407}
408
409#############################################################################
410
411MODULE = Gtk2::CV PACKAGE = Gtk2::CV
412
355SV * 413SV *
356pb_to_p7 (GdkPixbuf *pb) 414pb_to_hv84 (GdkPixbuf *pb)
357 CODE: 415 CODE:
358{ 416{
359 int w = gdk_pixbuf_get_width (pb); 417 int w = gdk_pixbuf_get_width (pb);
360 int h = gdk_pixbuf_get_height (pb); 418 int h = gdk_pixbuf_get_height (pb);
361 int x, y; 419 int x, y;
362 guchar *dst; 420 guchar *dst;
363 int bpp = gdk_pixbuf_get_n_channels (pb); 421 int bpp = gdk_pixbuf_get_n_channels (pb);
364 guchar *src = gdk_pixbuf_get_pixels (pb); 422 guchar *src = gdk_pixbuf_get_pixels (pb);
365 int sstr = gdk_pixbuf_get_rowstride (pb); 423 int sstr = gdk_pixbuf_get_rowstride (pb);
366 int Er[IW], Eg[IW], Eb[IW];
367 int seed = 77;
368
369 RETVAL = newSV (w * h);
370 SvPOK_only (RETVAL);
371 SvCUR_set (RETVAL, w * h);
372
373 dst = SvPVX (RETVAL);
374
375 memset (Er, 0, sizeof (int) * IW);
376 memset (Eg, 0, sizeof (int) * IW);
377 memset (Eb, 0, sizeof (int) * IW);
378
379 /* some primitive error distribution + random dithering */
380
381 for (y = 0; y < h; y++)
382 {
383 int er = 0, eg = 0, eb = 0;
384
385 for (x = 0; x < w; x++)
386 {
387 int r, g, b;
388 guchar *p = src + x * bpp + y * sstr;
389
390 r = ((p[0] + er + Er[x]) * 7 + (RAND & 127) + 64) / 255;
391 g = ((p[1] + eg + Eg[x]) * 7 + (RAND & 127) + 64) / 255;
392 b = ((p[2] + eb + Eb[x]) * 3 + (RAND & 127) + 64) / 255;
393
394 r = r > 7 ? 7 : r < 0 ? 0 : r;
395 g = g > 7 ? 7 : g < 0 ? 0 : g;
396 b = b > 3 ? 3 : b < 0 ? 0 : b;
397
398 er += p[0] - (r * 255 + 4) / 7;
399 eg += p[1] - (g * 255 + 4) / 7;
400 eb += p[2] - (b * 255 + 2) / 3;
401
402 Er[x] = er >> 1; er -= (er + 1) >> 1;
403 Eg[x] = eg >> 1; eg -= (eg + 1) >> 1;
404 Eb[x] = eb >> 1; eb -= (eb + 1) >> 1;
405
406 *dst++ = r << 5 | g << 2 | b;
407 }
408 }
409}
410 OUTPUT:
411 RETVAL
412
413#############################################################################
414
415MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
416
417void
418dump_ascii85 (PerlIO *fp, GdkPixbuf *pb)
419 CODE:
420{
421 int w = gdk_pixbuf_get_width (pb);
422 int h = gdk_pixbuf_get_height (pb);
423 int x, y, i;
424 guchar *dst;
425 int bpp = gdk_pixbuf_get_n_channels (pb);
426 guchar *src = gdk_pixbuf_get_pixels (pb);
427 int sstr = gdk_pixbuf_get_rowstride (pb);
428
429 a85_init ();
430
431 for (y = 0; y < h; y++)
432 for (x = 0; x < w; x++)
433 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
434 a85_push (fp, src [x * bpp + y * sstr + i]);
435
436 a85_finish (fp);
437}
438
439void
440dump_binary (PerlIO *fp, GdkPixbuf *pb)
441 CODE:
442{
443 int w = gdk_pixbuf_get_width (pb);
444 int h = gdk_pixbuf_get_height (pb);
445 int x, y, i;
446 guchar *dst;
447 int bpp = gdk_pixbuf_get_n_channels (pb);
448 guchar *src = gdk_pixbuf_get_pixels (pb);
449 int sstr = gdk_pixbuf_get_rowstride (pb);
450
451 for (y = 0; y < h; y++)
452 for (x = 0; x < w; x++)
453 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
454 PerlIO_putc (fp, src [x * bpp + y * sstr + i]);
455}
456
457#############################################################################
458
459MODULE = Gtk2::CV PACKAGE = Gtk2::CV
460
461SV *
462pb_to_hv84 (GdkPixbuf *pb)
463 CODE:
464{
465 int w = gdk_pixbuf_get_width (pb);
466 int h = gdk_pixbuf_get_height (pb);
467 int x, y;
468 guchar *dst;
469 int bpp = gdk_pixbuf_get_n_channels (pb);
470 guchar *src = gdk_pixbuf_get_pixels (pb);
471 int sstr = gdk_pixbuf_get_rowstride (pb);
472 424
473 RETVAL = newSV (6 * 8 * 12 / 8); 425 RETVAL = newSV (6 * 8 * 12 / 8);
474 SvPOK_only (RETVAL); 426 SvPOK_only (RETVAL);
475 SvCUR_set (RETVAL, 6 * 8 * 12 / 8); 427 SvCUR_set (RETVAL, 6 * 8 * 12 / 8);
476 428
477 dst = SvPVX (RETVAL); 429 dst = (guchar *)SvPVX (RETVAL);
478 430
479 /* some primitive error distribution + random dithering */ 431 /* some primitive error distribution + random dithering */
480 432
481 for (y = 0; y < h; y++) 433 for (y = 0; y < h; y++)
482 { 434 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines