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.26 by root, Sun Aug 21 02:18:30 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
138#endif 140#endif
139 OUTPUT: 141 OUTPUT:
140 RETVAL 142 RETVAL
141 143
142GdkPixbuf_noinc * 144GdkPixbuf_noinc *
145dealpha_expose (GdkPixbuf *pb)
146 CODE:
147{
148 int w = gdk_pixbuf_get_width (pb);
149 int h = gdk_pixbuf_get_height (pb);
150 fprintf (stderr, "new %d %d\n", w, h);
151 int bpp = gdk_pixbuf_get_n_channels (pb);
152 int x, y, i;
153 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
154 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
155
156 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
157
158 dst = gdk_pixbuf_get_pixels (RETVAL);
159 dstr = gdk_pixbuf_get_rowstride (RETVAL);
160
161 for (x = 0; x < w; x++)
162 for (y = 0; y < h; y++)
163 for (i = 0; i < 3; i++)
164 dst[x * 3 + y * dstr + i] = src[x * bpp + y * sstr + i];
165}
166 OUTPUT:
167 RETVAL
168
169GdkPixbuf_noinc *
143transpose (GdkPixbuf *pb) 170transpose (GdkPixbuf *pb)
144 CODE: 171 CODE:
145{ 172{
146 int w = gdk_pixbuf_get_width (pb); 173 int w = gdk_pixbuf_get_width (pb);
147 int h = gdk_pixbuf_get_height (pb); 174 int h = gdk_pixbuf_get_height (pb);
186} 213}
187 OUTPUT: 214 OUTPUT:
188 RETVAL 215 RETVAL
189 216
190GdkPixbuf_noinc * 217GdkPixbuf_noinc *
191load_jpeg (char *path, int thumbnail=0) 218load_jpeg (SV *path, int thumbnail=0)
192 CODE: 219 CODE:
193{ 220{
194 struct jpeg_decompress_struct cinfo; 221 struct jpeg_decompress_struct cinfo;
195 struct jpg_err_mgr jerr; 222 struct jpg_err_mgr jerr;
196 guchar *data; 223 guchar *data;
197 int rs; 224 int rs;
198 FILE *fp; 225 FILE *fp;
199 volatile GdkPixbuf *pb = 0; 226 volatile GdkPixbuf *pb = 0;
227 gchar *filename;
228
200 RETVAL = 0; 229 RETVAL = 0;
201 230
202 if (!(fp = fopen (path, "rb"))) 231 filename = g_filename_from_utf8 (SvPVutf8_nolen (path), -1, 0, 0, 0);
232 fp = fopen (filename, "rb");
233 g_free (filename);
234
235 if (!fp)
203 XSRETURN_UNDEF; 236 XSRETURN_UNDEF;
204 237
205 cinfo.err = jpeg_std_error (&jerr.err); 238 cinfo.err = jpeg_std_error (&jerr.err);
206 239
207 jerr.err.error_exit = cv_error_exit; 240 jerr.err.error_exit = cv_error_exit;
288foldcase (SV *pathsv) 321foldcase (SV *pathsv)
289 PROTOTYPE: $ 322 PROTOTYPE: $
290 CODE: 323 CODE:
291{ 324{
292 STRLEN plen; 325 STRLEN plen;
293 U8 *path = SvPVutf8 (pathsv, plen); 326 U8 *path = (U8 *)SvPVutf8 (pathsv, plen);
294 U8 *pend = path + plen; 327 U8 *pend = path + plen;
295 U8 dst [plen * 6 * 3], *dstp = dst; 328 U8 dst [plen * 6 * 3], *dstp = dst;
296 329
297 while (path < pend) 330 while (path < pend)
298 { 331 {
319 dstp += cl; 352 dstp += cl;
320 path += is_utf8_char (path); 353 path += is_utf8_char (path);
321 } 354 }
322 } 355 }
323 356
324 RETVAL = newSVpvn (dst, dstp - dst); 357 RETVAL = newSVpvn ((const char *)dst, dstp - dst);
325} 358}
326 OUTPUT: 359 OUTPUT:
327 RETVAL 360 RETVAL
328 361
329GdkPixbuf_noinc * 362GdkPixbuf_noinc *
330p7_to_pb (int w, int h, guchar *src) 363p7_to_pb (int w, int h, SV *src_sv)
331 PROTOTYPE: @ 364 PROTOTYPE: @
332 CODE: 365 CODE:
333{ 366{
334 int x, y; 367 int x, y;
335 guchar *dst, *d; 368 guchar *dst, *d;
336 int dstr; 369 int dstr;
370 guchar *src = (guchar *)SvPVbyte_nolen (src_sv);
337 371
338 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); 372 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
339 dst = gdk_pixbuf_get_pixels (RETVAL); 373 dst = gdk_pixbuf_get_pixels (RETVAL);
340 dstr = gdk_pixbuf_get_rowstride (RETVAL); 374 dstr = gdk_pixbuf_get_rowstride (RETVAL);
341 375
368 402
369 RETVAL = newSV (w * h); 403 RETVAL = newSV (w * h);
370 SvPOK_only (RETVAL); 404 SvPOK_only (RETVAL);
371 SvCUR_set (RETVAL, w * h); 405 SvCUR_set (RETVAL, w * h);
372 406
373 dst = SvPVX (RETVAL); 407 dst = (guchar *)SvPVX (RETVAL);
374 408
375 memset (Er, 0, sizeof (int) * IW); 409 memset (Er, 0, sizeof (int) * IW);
376 memset (Eg, 0, sizeof (int) * IW); 410 memset (Eg, 0, sizeof (int) * IW);
377 memset (Eb, 0, sizeof (int) * IW); 411 memset (Eb, 0, sizeof (int) * IW);
378 412
472 506
473 RETVAL = newSV (6 * 8 * 12 / 8); 507 RETVAL = newSV (6 * 8 * 12 / 8);
474 SvPOK_only (RETVAL); 508 SvPOK_only (RETVAL);
475 SvCUR_set (RETVAL, 6 * 8 * 12 / 8); 509 SvCUR_set (RETVAL, 6 * 8 * 12 / 8);
476 510
477 dst = SvPVX (RETVAL); 511 dst = (guchar *)SvPVX (RETVAL);
478 512
479 /* some primitive error distribution + random dithering */ 513 /* some primitive error distribution + random dithering */
480 514
481 for (y = 0; y < h; y++) 515 for (y = 0; y < h; y++)
482 { 516 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines