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

Comparing CV/CV.xs (file contents):
Revision 1.23 by root, Tue Aug 16 23:50:39 2005 UTC vs.
Revision 1.30 by root, Wed Dec 28 20:56:20 2005 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines