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

Comparing CV/CV.xs (file contents):
Revision 1.40 by root, Sat Nov 25 15:00:51 2006 UTC vs.
Revision 1.46 by root, Sat Jul 4 05:31:17 2015 UTC

14#include <gdk-pixbuf/gdk-pixbuf.h> 14#include <gdk-pixbuf/gdk-pixbuf.h>
15 15
16#include <gperl.h> 16#include <gperl.h>
17#include <gtk2perl.h> 17#include <gtk2perl.h>
18 18
19#include <assert.h>
20
21#include "perlmulticore.h"
22
19#define IW 80 /* MUST match Schnauzer.pm! */ 23#define IW 80 /* MUST match Schnauzer.pm! */
20#define IH 60 /* MUST match Schnauzer.pm! */ 24#define IH 60 /* MUST match Schnauzer.pm! */
21 25
22#define RAND (seed = (seed + 7141) * 54773 % 134456) 26#define RAND (seed = (seed + 7141) * 54773 % 134456)
23 27
24#define LINELENGTH 240 28#define LINELENGTH 240
25 29
26#define ELLIPSIS "\xe2\x80\xa6" 30#define ELLIPSIS "\xe2\x80\xa6"
31
32typedef char *octet_string;
27 33
28struct jpg_err_mgr 34struct jpg_err_mgr
29{ 35{
30 struct jpeg_error_mgr err; 36 struct jpeg_error_mgr err;
31 jmp_buf setjmp_buffer; 37 jmp_buf setjmp_buffer;
202 208
203 OUTPUT: 209 OUTPUT:
204 RETVAL 210 RETVAL
205 211
206const char * 212const char *
207magic (const char *path) 213magic (octet_string path)
208 CODE: 214 CODE:
209{ 215{
210 static magic_t cookie; 216 static magic_t cookie;
211 217
212 if (!cookie) 218 if (!cookie)
213 { 219 {
214 cookie = magic_open (MAGIC_NONE); 220 cookie = magic_open (MAGIC_SYMLINK);
215 221
216 if (cookie) 222 if (cookie)
217 magic_load (cookie, 0); 223 magic_load (cookie, 0);
218 else 224 else
219 XSRETURN_UNDEF; 225 XSRETURN_UNDEF;
223} 229}
224 OUTPUT: 230 OUTPUT:
225 RETVAL 231 RETVAL
226 232
227const char * 233const char *
228magic_mime (const char *path) 234magic_mime (octet_string path)
229 CODE: 235 CODE:
230{ 236{
231 static magic_t cookie; 237 static magic_t cookie;
232 238
233 if (!cookie) 239 if (!cookie)
234 { 240 {
235 cookie = magic_open (MAGIC_MIME); 241 cookie = magic_open (MAGIC_MIME | MAGIC_SYMLINK);
236 242
237 if (cookie) 243 if (cookie)
238 magic_load (cookie, 0); 244 magic_load (cookie, 0);
239 else 245 else
240 XSRETURN_UNDEF; 246 XSRETURN_UNDEF;
241 } 247 }
242 248
249 perlinterp_release ();
243 RETVAL = magic_file (cookie, path); 250 RETVAL = magic_file (cookie, path);
251 perlinterp_acquire ();
244} 252}
245 OUTPUT: 253 OUTPUT:
246 RETVAL 254 RETVAL
247 255
248# missing/broken in Gtk2 perl module 256# missing/broken in Gtk2 perl module
264 RETVAL 272 RETVAL
265 273
266GdkPixbuf_noinc * 274GdkPixbuf_noinc *
267dealpha_expose (GdkPixbuf *pb) 275dealpha_expose (GdkPixbuf *pb)
268 CODE: 276 CODE:
277 perlinterp_release ();
269{ 278{
270 int w = gdk_pixbuf_get_width (pb); 279 int w = gdk_pixbuf_get_width (pb);
271 int h = gdk_pixbuf_get_height (pb); 280 int h = gdk_pixbuf_get_height (pb);
272 int bpp = gdk_pixbuf_get_n_channels (pb); 281 int bpp = gdk_pixbuf_get_n_channels (pb);
273 int x, y, i; 282 int x, y, i;
282 for (x = 0; x < w; x++) 291 for (x = 0; x < w; x++)
283 for (y = 0; y < h; y++) 292 for (y = 0; y < h; y++)
284 for (i = 0; i < 3; i++) 293 for (i = 0; i < 3; i++)
285 dst[x * 3 + y * dstr + i] = src[x * bpp + y * sstr + i]; 294 dst[x * 3 + y * dstr + i] = src[x * bpp + y * sstr + i];
286} 295}
296 perlinterp_acquire ();
287 OUTPUT: 297 OUTPUT:
288 RETVAL 298 RETVAL
289 299
290GdkPixbuf_noinc * 300GdkPixbuf_noinc *
291rotate (GdkPixbuf *pb, int angle) 301rotate (GdkPixbuf *pb, int angle)
292 CODE: 302 CODE:
303 perlinterp_release ();
304 if (angle < 0)
305 angle += 360;
293 RETVAL = gdk_pixbuf_rotate_simple (pb, angle == 0 ? GDK_PIXBUF_ROTATE_NONE 306 RETVAL = gdk_pixbuf_rotate_simple (pb, angle == 0 ? GDK_PIXBUF_ROTATE_NONE
294 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE 307 : angle == 90 ? GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
295 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN 308 : angle == 180 ? GDK_PIXBUF_ROTATE_UPSIDEDOWN
296 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE 309 : angle == 270 ? GDK_PIXBUF_ROTATE_CLOCKWISE
297 : angle); 310 : angle);
311 perlinterp_acquire ();
298 OUTPUT: 312 OUTPUT:
299 RETVAL 313 RETVAL
300 314
301GdkPixbuf_noinc * 315GdkPixbuf_noinc *
302load_jpeg (SV *path, int thumbnail=0) 316load_jpeg (SV *path, int thumbnail=0)
314 fp = fopen (SvPVbyte_nolen (path), "rb"); 328 fp = fopen (SvPVbyte_nolen (path), "rb");
315 329
316 if (!fp) 330 if (!fp)
317 XSRETURN_UNDEF; 331 XSRETURN_UNDEF;
318 332
333 perlinterp_release ();
334
319 cinfo.err = jpeg_std_error (&jerr.err); 335 cinfo.err = jpeg_std_error (&jerr.err);
320 336
321 jerr.err.error_exit = cv_error_exit; 337 jerr.err.error_exit = cv_error_exit;
322 jerr.err.output_message = cv_error_output; 338 jerr.err.output_message = cv_error_output;
323 339
327 jpeg_destroy_decompress (&cinfo); 343 jpeg_destroy_decompress (&cinfo);
328 344
329 if (pb) 345 if (pb)
330 g_object_unref ((gpointer)pb); 346 g_object_unref ((gpointer)pb);
331 347
348 perlinterp_acquire ();
332 XSRETURN_UNDEF; 349 XSRETURN_UNDEF;
333 } 350 }
334 351
335 jpeg_create_decompress (&cinfo); 352 jpeg_create_decompress (&cinfo);
336 353
388 } 405 }
389 406
390 jpeg_finish_decompress (&cinfo); 407 jpeg_finish_decompress (&cinfo);
391 fclose (fp); 408 fclose (fp);
392 jpeg_destroy_decompress (&cinfo); 409 jpeg_destroy_decompress (&cinfo);
410 perlinterp_acquire ();
393} 411}
394 OUTPUT: 412 OUTPUT:
395 RETVAL 413 RETVAL
396 414
397void 415void
398compare (GdkPixbuf *a, GdkPixbuf *b) 416compare (GdkPixbuf *a, GdkPixbuf *b)
399 PPCODE: 417 PPCODE:
418 perlinterp_release ();
400{ 419{
401 int w = gdk_pixbuf_get_width (a); 420 int w = gdk_pixbuf_get_width (a);
402 int h = gdk_pixbuf_get_height (a); 421 int h = gdk_pixbuf_get_height (a);
422
403 int sa = gdk_pixbuf_get_rowstride (a); 423 int sa = gdk_pixbuf_get_rowstride (a);
404 int sb = gdk_pixbuf_get_rowstride (b); 424 int sb = gdk_pixbuf_get_rowstride (b);
405 425
406 guchar *pa = gdk_pixbuf_get_pixels (a); 426 guchar *pa = gdk_pixbuf_get_pixels (a);
407 guchar *pb = gdk_pixbuf_get_pixels (b); 427 guchar *pb = gdk_pixbuf_get_pixels (b);
431 d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d)); 451 d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d));
432 d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d)); 452 d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d));
433 } 453 }
434 } 454 }
435 455
456 perlinterp_acquire ();
457
436 EXTEND (SP, 2); 458 EXTEND (SP, 2);
437 PUSHs (sv_2mortal (newSVnv (sqrt (diff / (w * h * 3. * 255. * 255.))))); 459 PUSHs (sv_2mortal (newSVnv (sqrt (diff / (w * h * 3. * 255. * 255.)))));
438 PUSHs (sv_2mortal (newSVnv (peak / 255.))); 460 PUSHs (sv_2mortal (newSVnv (peak / 255.)));
439} 461}
440 462
441############################################################################# 463#############################################################################
442 464
443MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer 465MODULE = Gtk2::CV PACKAGE = Gtk2::CV::Schnauzer
444 466
467# currently only works for filenames (octet strings)
468
445SV * 469SV *
446foldcase (SV *pathsv) 470foldcase (SV *pathsv)
447 PROTOTYPE: $ 471 PROTOTYPE: $
448 CODE: 472 CODE:
449{ 473{
450 STRLEN plen; 474 STRLEN plen;
451 U8 *path = (U8 *)SvPVutf8 (pathsv, plen); 475 U8 *path = (U8 *)SvPV (pathsv, plen);
452 U8 *pend = path + plen; 476 U8 *pend = path + plen;
453 U8 dst [plen * 6 * 3], *dstp = dst; 477 U8 dst [plen * 6 * 3], *dstp = dst;
454 478
455 while (path < pend) 479 while (path < pend)
456 { 480 {
457 U8 ch = *path; 481 U8 ch = *path;
458 482
459 if (ch >= 'a' && ch <= 'z') 483 if (ch >= 'a' && ch <= 'z')
460 *dstp++ = *path++; 484 *dstp++ = *path++;
485 else if (ch >= 'A' && ch <= 'Z')
486 *dstp++ = *path++ + ('a' - 'A');
461 else if (ch >= '0' && ch <= '9') 487 else if (ch >= '0' && ch <= '9')
462 { 488 {
463 STRLEN el, nl = 0; 489 STRLEN el, nl = 0;
464 while (*path >= '0' && *path <= '9' && path < pend) 490 while (*path >= '0' && *path <= '9' && path < pend)
465 path++, nl++; 491 path++, nl++;
468 *dstp++ = '0'; 494 *dstp++ = '0';
469 495
470 memcpy (dstp, path - nl, nl); 496 memcpy (dstp, path - nl, nl);
471 dstp += nl; 497 dstp += nl;
472 } 498 }
499 else
500 *dstp++ = *path++;
501#if 0
473 else 502 else
474 { 503 {
475 STRLEN cl; 504 STRLEN cl;
476 to_utf8_fold (path, dstp, &cl); 505 to_utf8_fold (path, dstp, &cl);
477 dstp += cl; 506 dstp += cl;
478 path += is_utf8_char (path); 507 path += is_utf8_char (path);
479 } 508 }
509#endif
480 } 510 }
481 511
482 RETVAL = newSVpvn ((const char *)dst, dstp - dst); 512 RETVAL = newSVpvn ((const char *)dst, dstp - dst);
483} 513}
484 OUTPUT: 514 OUTPUT:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines