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

Comparing CV/CV.xs (file contents):
Revision 1.41 by root, Sat Mar 1 04:11:26 2008 UTC vs.
Revision 1.47 by root, Tue Jun 7 06:59:57 2016 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, int iw = 0, int ih = 0)
303 CODE: 317 CODE:
304{ 318{
305 struct jpeg_decompress_struct cinfo; 319 struct jpeg_decompress_struct cinfo;
306 struct jpg_err_mgr jerr; 320 struct jpg_err_mgr jerr;
307 guchar *data; 321 guchar *data;
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
352 { 369 {
353 cinfo.dct_method = JDCT_FASTEST; 370 cinfo.dct_method = JDCT_FASTEST;
354 cinfo.do_fancy_upsampling = FALSE; 371 cinfo.do_fancy_upsampling = FALSE;
355 372
356 while (cinfo.scale_denom < 8 373 while (cinfo.scale_denom < 8
357 && cinfo.output_width >= IW*4 374 && cinfo.output_width >= iw*4
358 && cinfo.output_height >= IH*4) 375 && cinfo.output_height >= ih*4)
359 { 376 {
360 cinfo.scale_denom <<= 1; 377 cinfo.scale_denom <<= 1;
361 jpeg_calc_output_dimensions (&cinfo); 378 jpeg_calc_output_dimensions (&cinfo);
362 } 379 }
363 } 380 }
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);
430 d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d)); 450 d = ((int)*pa_++) - ((int)*pb_++); diff += d*d; peak = MAX (peak, abs (d));
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 }
455
456 perlinterp_acquire ();
435 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}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines