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

Comparing CV/CV.xs (file contents):
Revision 1.21 by root, Sat Jul 23 03:25:51 2005 UTC vs.
Revision 1.29 by root, Sat Sep 24 01:25:17 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
148# missing in Gtk2 perl module
149
150gboolean
151gdk_net_wm_supports (GdkAtom property)
152 CODE:
153#if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE)
154 RETVAL = gdk_net_wm_supports (property);
155#else
156 RETVAL = 0;
157#endif
158 OUTPUT:
159 RETVAL
160
129GdkPixbuf_noinc * 161GdkPixbuf_noinc *
130transpose (GdkPixbuf *pb) 162dealpha_expose (GdkPixbuf *pb)
131 CODE: 163 CODE:
132{ 164{
133 int w = gdk_pixbuf_get_width (pb); 165 int w = gdk_pixbuf_get_width (pb);
134 int h = gdk_pixbuf_get_height (pb); 166 int h = gdk_pixbuf_get_height (pb);
135 int bpp = gdk_pixbuf_get_n_channels (pb); 167 int bpp = gdk_pixbuf_get_n_channels (pb);
136 int x, y, i; 168 int x, y, i;
137 guchar *src = gdk_pixbuf_get_pixels (pb), *dst; 169 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
138 int sstr = gdk_pixbuf_get_rowstride (pb), dstr; 170 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
139 171
140 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, h, w); 172 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
141 173
142 dst = gdk_pixbuf_get_pixels (RETVAL); 174 dst = gdk_pixbuf_get_pixels (RETVAL);
143 dstr = gdk_pixbuf_get_rowstride (RETVAL); 175 dstr = gdk_pixbuf_get_rowstride (RETVAL);
144 176
145 for (y = 0; y < h; y++)
146 for (x = 0; x < w; x++) 177 for (x = 0; x < w; x++)
178 for (y = 0; y < h; y++)
147 for (i = 0; i < bpp; i++) 179 for (i = 0; i < 3; i++)
148 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];
149} 181}
150 OUTPUT: 182 OUTPUT:
151 RETVAL 183 RETVAL
152 184
153GdkPixbuf_noinc * 185GdkPixbuf_noinc *
154flop (GdkPixbuf *pb) 186rotate (GdkPixbuf *pb, int angle)
155 CODE: 187 CODE:
156{ 188 RETVAL = gdk_pixbuf_rotate_simple (pb, angle == 0 ? GDK_PIXBUF_ROTATE_NONE
157 int w = gdk_pixbuf_get_width (pb); 189 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
158 int h = gdk_pixbuf_get_height (pb); 190 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN
159 int bpp = gdk_pixbuf_get_n_channels (pb); 191 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE
160 int x, y, i; 192 : angle);
161 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
162 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
163
164 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, w, h);
165
166 dst = gdk_pixbuf_get_pixels (RETVAL);
167 dstr = gdk_pixbuf_get_rowstride (RETVAL);
168
169 for (y = 0; y < h; y++)
170 for (x = 0; x < w; x++)
171 for (i = 0; i < bpp; i++)
172 dst[(w - 1 - x) * bpp + y * dstr + i] = src[x * bpp + y * sstr + i];
173}
174 OUTPUT: 193 OUTPUT:
175 RETVAL 194 RETVAL
176 195
177GdkPixbuf_noinc * 196GdkPixbuf_noinc *
178load_jpeg (char *path, int thumbnail=0) 197load_jpeg (SV *path, int thumbnail=0)
179 CODE: 198 CODE:
180{ 199{
181 struct jpeg_decompress_struct cinfo; 200 struct jpeg_decompress_struct cinfo;
182 struct jpg_err_mgr jerr; 201 struct jpg_err_mgr jerr;
183 guchar *data; 202 guchar *data;
184 int rs; 203 int rs;
185 FILE *fp; 204 FILE *fp;
186 volatile GdkPixbuf *pb = 0; 205 volatile GdkPixbuf *pb = 0;
206 gchar *filename;
207
187 RETVAL = 0; 208 RETVAL = 0;
188 209
189 if (!(fp = fopen (path, "rb"))) 210 filename = g_filename_from_utf8 (SvPVutf8_nolen (path), -1, 0, 0, 0);
211 fp = fopen (filename, "rb");
212 g_free (filename);
213
214 if (!fp)
190 XSRETURN_UNDEF; 215 XSRETURN_UNDEF;
191 216
192 cinfo.err = jpeg_std_error (&jerr.err); 217 cinfo.err = jpeg_std_error (&jerr.err);
193 218
194 jerr.err.error_exit = cv_error_exit; 219 jerr.err.error_exit = cv_error_exit;
275foldcase (SV *pathsv) 300foldcase (SV *pathsv)
276 PROTOTYPE: $ 301 PROTOTYPE: $
277 CODE: 302 CODE:
278{ 303{
279 STRLEN plen; 304 STRLEN plen;
280 U8 *path = SvPVutf8 (pathsv, plen); 305 U8 *path = (U8 *)SvPVutf8 (pathsv, plen);
281 U8 *pend = path + plen; 306 U8 *pend = path + plen;
282 U8 dst [plen * 6 * 3], *dstp = dst; 307 U8 dst [plen * 6 * 3], *dstp = dst;
283 308
284 while (path < pend) 309 while (path < pend)
285 { 310 {
306 dstp += cl; 331 dstp += cl;
307 path += is_utf8_char (path); 332 path += is_utf8_char (path);
308 } 333 }
309 } 334 }
310 335
311 RETVAL = newSVpvn (dst, dstp - dst); 336 RETVAL = newSVpvn ((const char *)dst, dstp - dst);
312} 337}
313 OUTPUT: 338 OUTPUT:
314 RETVAL 339 RETVAL
315 340
316GdkPixbuf_noinc * 341GdkPixbuf_noinc *
317p7_to_pb (int w, int h, guchar *src) 342p7_to_pb (int w, int h, SV *src_sv)
318 PROTOTYPE: @ 343 PROTOTYPE: @
319 CODE: 344 CODE:
320{ 345{
321 int x, y; 346 int x, y;
322 guchar *dst, *d; 347 guchar *dst, *d;
323 int dstr; 348 int dstr;
349 guchar *src = (guchar *)SvPVbyte_nolen (src_sv);
324 350
325 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); 351 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
326 dst = gdk_pixbuf_get_pixels (RETVAL); 352 dst = gdk_pixbuf_get_pixels (RETVAL);
327 dstr = gdk_pixbuf_get_rowstride (RETVAL); 353 dstr = gdk_pixbuf_get_rowstride (RETVAL);
328 354
337 } 363 }
338} 364}
339 OUTPUT: 365 OUTPUT:
340 RETVAL 366 RETVAL
341 367
368#############################################################################
369
370MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
371
372void
373dump_ascii85 (PerlIO *fp, GdkPixbuf *pb)
374 CODE:
375{
376 int w = gdk_pixbuf_get_width (pb);
377 int h = gdk_pixbuf_get_height (pb);
378 int x, y, i;
379 guchar *dst;
380 int bpp = gdk_pixbuf_get_n_channels (pb);
381 guchar *src = gdk_pixbuf_get_pixels (pb);
382 int sstr = gdk_pixbuf_get_rowstride (pb);
383
384 a85_init ();
385
386 for (y = 0; y < h; y++)
387 for (x = 0; x < w; x++)
388 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
389 a85_push (fp, src [x * bpp + y * sstr + i]);
390
391 a85_finish (fp);
392}
393
394void
395dump_binary (PerlIO *fp, GdkPixbuf *pb)
396 CODE:
397{
398 int w = gdk_pixbuf_get_width (pb);
399 int h = gdk_pixbuf_get_height (pb);
400 int x, y, i;
401 guchar *dst;
402 int bpp = gdk_pixbuf_get_n_channels (pb);
403 guchar *src = gdk_pixbuf_get_pixels (pb);
404 int sstr = gdk_pixbuf_get_rowstride (pb);
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 PerlIO_putc (fp, src [x * bpp + y * sstr + i]);
410}
411
412#############################################################################
413
414MODULE = Gtk2::CV PACKAGE = Gtk2::CV
415
342SV * 416SV *
343pb_to_p7 (GdkPixbuf *pb) 417pb_to_hv84 (GdkPixbuf *pb)
344 CODE: 418 CODE:
345{ 419{
346 int w = gdk_pixbuf_get_width (pb); 420 int w = gdk_pixbuf_get_width (pb);
347 int h = gdk_pixbuf_get_height (pb); 421 int h = gdk_pixbuf_get_height (pb);
348 int x, y; 422 int x, y;
349 guchar *dst; 423 guchar *dst;
350 int bpp = gdk_pixbuf_get_n_channels (pb); 424 int bpp = gdk_pixbuf_get_n_channels (pb);
351 guchar *src = gdk_pixbuf_get_pixels (pb); 425 guchar *src = gdk_pixbuf_get_pixels (pb);
352 int sstr = gdk_pixbuf_get_rowstride (pb); 426 int sstr = gdk_pixbuf_get_rowstride (pb);
353 int Er[IW], Eg[IW], Eb[IW];
354 int seed = 77;
355
356 RETVAL = newSV (w * h);
357 SvPOK_only (RETVAL);
358 SvCUR_set (RETVAL, w * h);
359
360 dst = SvPVX (RETVAL);
361
362 memset (Er, 0, sizeof (int) * IW);
363 memset (Eg, 0, sizeof (int) * IW);
364 memset (Eb, 0, sizeof (int) * IW);
365
366 /* some primitive error distribution + random dithering */
367
368 for (y = 0; y < h; y++)
369 {
370 int er = 0, eg = 0, eb = 0;
371
372 for (x = 0; x < w; x++)
373 {
374 int r, g, b;
375 guchar *p = src + x * bpp + y * sstr;
376
377 r = ((p[0] + er + Er[x]) * 7 + (RAND & 127) + 64) / 255;
378 g = ((p[1] + eg + Eg[x]) * 7 + (RAND & 127) + 64) / 255;
379 b = ((p[2] + eb + Eb[x]) * 3 + (RAND & 127) + 64) / 255;
380
381 r = r > 7 ? 7 : r < 0 ? 0 : r;
382 g = g > 7 ? 7 : g < 0 ? 0 : g;
383 b = b > 3 ? 3 : b < 0 ? 0 : b;
384
385 er += p[0] - (r * 255 + 4) / 7;
386 eg += p[1] - (g * 255 + 4) / 7;
387 eb += p[2] - (b * 255 + 2) / 3;
388
389 Er[x] = er >> 1; er -= (er + 1) >> 1;
390 Eg[x] = eg >> 1; eg -= (eg + 1) >> 1;
391 Eb[x] = eb >> 1; eb -= (eb + 1) >> 1;
392
393 *dst++ = r << 5 | g << 2 | b;
394 }
395 }
396}
397 OUTPUT:
398 RETVAL
399
400#############################################################################
401
402MODULE = Gtk2::CV PACKAGE = Gtk2::CV::PostScript
403
404void
405dump_ascii85 (PerlIO *fp, GdkPixbuf *pb)
406 CODE:
407{
408 int w = gdk_pixbuf_get_width (pb);
409 int h = gdk_pixbuf_get_height (pb);
410 int x, y, i;
411 guchar *dst;
412 int bpp = gdk_pixbuf_get_n_channels (pb);
413 guchar *src = gdk_pixbuf_get_pixels (pb);
414 int sstr = gdk_pixbuf_get_rowstride (pb);
415
416 a85_init ();
417
418 for (y = 0; y < h; y++)
419 for (x = 0; x < w; x++)
420 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
421 a85_push (fp, src [x * bpp + y * sstr + i]);
422
423 a85_finish (fp);
424}
425
426void
427dump_binary (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 for (y = 0; y < h; y++)
439 for (x = 0; x < w; x++)
440 for (i = 0; i < (bpp < 3 ? 1 : 3); i++)
441 PerlIO_putc (fp, src [x * bpp + y * sstr + i]);
442}
443
444#############################################################################
445
446MODULE = Gtk2::CV PACKAGE = Gtk2::CV
447
448SV *
449pb_to_hv84 (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;
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 427
460 RETVAL = newSV (6 * 8 * 12 / 8); 428 RETVAL = newSV (6 * 8 * 12 / 8);
461 SvPOK_only (RETVAL); 429 SvPOK_only (RETVAL);
462 SvCUR_set (RETVAL, 6 * 8 * 12 / 8); 430 SvCUR_set (RETVAL, 6 * 8 * 12 / 8);
463 431
464 dst = SvPVX (RETVAL); 432 dst = (guchar *)SvPVX (RETVAL);
465 433
466 /* some primitive error distribution + random dithering */ 434 /* some primitive error distribution + random dithering */
467 435
468 for (y = 0; y < h; y++) 436 for (y = 0; y < h; y++)
469 { 437 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines