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

Comparing CV/CV.xs (file contents):
Revision 1.20 by root, Fri Jul 22 06:14:25 2005 UTC vs.
Revision 1.27 by root, Sun Aug 21 02:23:52 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 in Gtk2 perl module
132
133gboolean
134gdk_net_wm_supports (GdkAtom property)
135 CODE:
136#if defined(GDK_WINDOWING_X11) && !defined(GDK_MULTIHEAD_SAFE)
137 RETVAL = gdk_net_wm_supports (property);
138#else
139 RETVAL = 0;
140#endif
141 OUTPUT:
142 RETVAL
143
129GdkPixbuf_noinc * 144GdkPixbuf_noinc *
130transpose (GdkPixbuf *pb) 145dealpha_expose (GdkPixbuf *pb)
131 CODE: 146 CODE:
132{ 147{
133 int w = gdk_pixbuf_get_width (pb); 148 int w = gdk_pixbuf_get_width (pb);
134 int h = gdk_pixbuf_get_height (pb); 149 int h = gdk_pixbuf_get_height (pb);
135 int bpp = gdk_pixbuf_get_n_channels (pb); 150 int bpp = gdk_pixbuf_get_n_channels (pb);
136 int x, y, i; 151 int x, y, i;
137 guchar *src = gdk_pixbuf_get_pixels (pb), *dst; 152 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
138 int sstr = gdk_pixbuf_get_rowstride (pb), dstr; 153 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
139 154
140 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, h, w); 155 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
141 156
142 dst = gdk_pixbuf_get_pixels (RETVAL); 157 dst = gdk_pixbuf_get_pixels (RETVAL);
143 dstr = gdk_pixbuf_get_rowstride (RETVAL); 158 dstr = gdk_pixbuf_get_rowstride (RETVAL);
144 159
145 for (y = 0; y < h; y++)
146 for (x = 0; x < w; x++) 160 for (x = 0; x < w; x++)
161 for (y = 0; y < h; y++)
147 for (i = 0; i < bpp; i++) 162 for (i = 0; i < 3; i++)
148 dst[y * bpp + x * dstr + i] = src[x * bpp + y * sstr + i]; 163 dst[x * 3 + y * dstr + i] = src[x * bpp + y * sstr + i];
149} 164}
150 OUTPUT: 165 OUTPUT:
151 RETVAL 166 RETVAL
152 167
153GdkPixbuf_noinc * 168GdkPixbuf_noinc *
154flop (GdkPixbuf *pb) 169transpose (GdkPixbuf *pb)
155 CODE: 170 CODE:
156{ 171{
157 int w = gdk_pixbuf_get_width (pb); 172 int w = gdk_pixbuf_get_width (pb);
158 int h = gdk_pixbuf_get_height (pb); 173 int h = gdk_pixbuf_get_height (pb);
159 int bpp = gdk_pixbuf_get_n_channels (pb); 174 int bpp = gdk_pixbuf_get_n_channels (pb);
160 int x, y, i; 175 int x, y, i;
161 guchar *src = gdk_pixbuf_get_pixels (pb), *dst; 176 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
162 int sstr = gdk_pixbuf_get_rowstride (pb), dstr; 177 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
163 178
179 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, h, w);
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[y * bpp + x * dstr + i] = src[x * bpp + y * sstr + i];
188}
189 OUTPUT:
190 RETVAL
191
192GdkPixbuf_noinc *
193flop (GdkPixbuf *pb)
194 CODE:
195{
196 int w = gdk_pixbuf_get_width (pb);
197 int h = gdk_pixbuf_get_height (pb);
198 int bpp = gdk_pixbuf_get_n_channels (pb);
199 int x, y, i;
200 guchar *src = gdk_pixbuf_get_pixels (pb), *dst;
201 int sstr = gdk_pixbuf_get_rowstride (pb), dstr;
202
164 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, w, h); 203 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, bpp == 4, 8, w, h);
165 204
166 dst = gdk_pixbuf_get_pixels (RETVAL); 205 dst = gdk_pixbuf_get_pixels (RETVAL);
167 dstr = gdk_pixbuf_get_rowstride (RETVAL); 206 dstr = gdk_pixbuf_get_rowstride (RETVAL);
168 207
173} 212}
174 OUTPUT: 213 OUTPUT:
175 RETVAL 214 RETVAL
176 215
177GdkPixbuf_noinc * 216GdkPixbuf_noinc *
178load_jpeg (char *path, int thumbnail=0) 217load_jpeg (SV *path, int thumbnail=0)
179 CODE: 218 CODE:
180{ 219{
181 struct jpeg_decompress_struct cinfo; 220 struct jpeg_decompress_struct cinfo;
182 struct jpg_err_mgr jerr; 221 struct jpg_err_mgr jerr;
183 guchar *data; 222 guchar *data;
184 int rs; 223 int rs;
185 FILE *fp; 224 FILE *fp;
186 volatile GdkPixbuf *pb = 0; 225 volatile GdkPixbuf *pb = 0;
226 gchar *filename;
227
187 RETVAL = 0; 228 RETVAL = 0;
188 229
189 if (!(fp = fopen (path, "rb"))) 230 filename = g_filename_from_utf8 (SvPVutf8_nolen (path), -1, 0, 0, 0);
231 fp = fopen (filename, "rb");
232 g_free (filename);
233
234 if (!fp)
190 XSRETURN_UNDEF; 235 XSRETURN_UNDEF;
191 236
192 cinfo.err = jpeg_std_error (&jerr.err); 237 cinfo.err = jpeg_std_error (&jerr.err);
193 238
194 jerr.err.error_exit = cv_error_exit; 239 jerr.err.error_exit = cv_error_exit;
225 { 270 {
226 cinfo.dct_method = JDCT_FASTEST; 271 cinfo.dct_method = JDCT_FASTEST;
227 cinfo.do_fancy_upsampling = FALSE; 272 cinfo.do_fancy_upsampling = FALSE;
228 273
229 while (cinfo.scale_denom < 8 274 while (cinfo.scale_denom < 8
230 && (cinfo.output_width >> 1) >= IW 275 && cinfo.output_width >= IW*4
231 && (cinfo.output_height >> 1) >= IH) 276 && cinfo.output_height >= IH*4)
232 { 277 {
233 cinfo.scale_denom <<= 1; 278 cinfo.scale_denom <<= 1;
234 jpeg_calc_output_dimensions (&cinfo); 279 jpeg_calc_output_dimensions (&cinfo);
235 } 280 }
236 } 281 }
275foldcase (SV *pathsv) 320foldcase (SV *pathsv)
276 PROTOTYPE: $ 321 PROTOTYPE: $
277 CODE: 322 CODE:
278{ 323{
279 STRLEN plen; 324 STRLEN plen;
280 U8 *path = SvPVutf8 (pathsv, plen); 325 U8 *path = (U8 *)SvPVutf8 (pathsv, plen);
281 U8 *pend = path + plen; 326 U8 *pend = path + plen;
282 U8 dst [plen * 6 * 3], *dstp = dst; 327 U8 dst [plen * 6 * 3], *dstp = dst;
283 328
284 while (path < pend) 329 while (path < pend)
285 { 330 {
306 dstp += cl; 351 dstp += cl;
307 path += is_utf8_char (path); 352 path += is_utf8_char (path);
308 } 353 }
309 } 354 }
310 355
311 RETVAL = newSVpvn (dst, dstp - dst); 356 RETVAL = newSVpvn ((const char *)dst, dstp - dst);
312} 357}
313 OUTPUT: 358 OUTPUT:
314 RETVAL 359 RETVAL
315 360
316GdkPixbuf_noinc * 361GdkPixbuf_noinc *
317p7_to_pb (int w, int h, guchar *src) 362p7_to_pb (int w, int h, SV *src_sv)
363 PROTOTYPE: @
318 CODE: 364 CODE:
319{ 365{
320 int x, y; 366 int x, y;
321 guchar *dst, *d; 367 guchar *dst, *d;
322 int dstr; 368 int dstr;
369 guchar *src = (guchar *)SvPVbyte_nolen (src_sv);
323 370
324 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); 371 RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h);
325 dst = gdk_pixbuf_get_pixels (RETVAL); 372 dst = gdk_pixbuf_get_pixels (RETVAL);
326 dstr = gdk_pixbuf_get_rowstride (RETVAL); 373 dstr = gdk_pixbuf_get_rowstride (RETVAL);
327 374
354 401
355 RETVAL = newSV (w * h); 402 RETVAL = newSV (w * h);
356 SvPOK_only (RETVAL); 403 SvPOK_only (RETVAL);
357 SvCUR_set (RETVAL, w * h); 404 SvCUR_set (RETVAL, w * h);
358 405
359 dst = SvPVX (RETVAL); 406 dst = (guchar *)SvPVX (RETVAL);
360 407
361 memset (Er, 0, sizeof (int) * IW); 408 memset (Er, 0, sizeof (int) * IW);
362 memset (Eg, 0, sizeof (int) * IW); 409 memset (Eg, 0, sizeof (int) * IW);
363 memset (Eb, 0, sizeof (int) * IW); 410 memset (Eb, 0, sizeof (int) * IW);
364 411
458 505
459 RETVAL = newSV (6 * 8 * 12 / 8); 506 RETVAL = newSV (6 * 8 * 12 / 8);
460 SvPOK_only (RETVAL); 507 SvPOK_only (RETVAL);
461 SvCUR_set (RETVAL, 6 * 8 * 12 / 8); 508 SvCUR_set (RETVAL, 6 * 8 * 12 / 8);
462 509
463 dst = SvPVX (RETVAL); 510 dst = (guchar *)SvPVX (RETVAL);
464 511
465 /* some primitive error distribution + random dithering */ 512 /* some primitive error distribution + random dithering */
466 513
467 for (y = 0; y < h; y++) 514 for (y = 0; y < h; y++)
468 { 515 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines