… | |
… | |
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 | |
125 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV |
127 | MODULE = Gtk2::CV PACKAGE = Gtk2::CV |
126 | |
128 | |
127 | PROTOTYPES: ENABLE |
129 | PROTOTYPES: ENABLE |
128 | |
130 | |
|
|
131 | # missing in Gtk2 perl module |
|
|
132 | |
|
|
133 | gboolean |
|
|
134 | gdk_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 | |
129 | GdkPixbuf_noinc * |
144 | GdkPixbuf_noinc * |
130 | transpose (GdkPixbuf *pb) |
145 | dealpha_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 | |
153 | GdkPixbuf_noinc * |
168 | GdkPixbuf_noinc * |
154 | flop (GdkPixbuf *pb) |
169 | transpose (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 | |
|
|
192 | GdkPixbuf_noinc * |
|
|
193 | flop (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 | |
177 | GdkPixbuf_noinc * |
216 | GdkPixbuf_noinc * |
178 | load_jpeg (char *path, int thumbnail=0) |
217 | load_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; |
… | |
… | |
275 | foldcase (SV *pathsv) |
320 | foldcase (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 | |
316 | GdkPixbuf_noinc * |
361 | GdkPixbuf_noinc * |
317 | p7_to_pb (int w, int h, guchar *src) |
362 | p7_to_pb (int w, int h, SV *src_sv) |
318 | PROTOTYPE: @ |
363 | PROTOTYPE: @ |
319 | CODE: |
364 | CODE: |
320 | { |
365 | { |
321 | int x, y; |
366 | int x, y; |
322 | guchar *dst, *d; |
367 | guchar *dst, *d; |
323 | int dstr; |
368 | int dstr; |
|
|
369 | guchar *src = (guchar *)SvPVbyte_nolen (src_sv); |
324 | |
370 | |
325 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
371 | RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, w, h); |
326 | dst = gdk_pixbuf_get_pixels (RETVAL); |
372 | dst = gdk_pixbuf_get_pixels (RETVAL); |
327 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
373 | dstr = gdk_pixbuf_get_rowstride (RETVAL); |
328 | |
374 | |
… | |
… | |
355 | |
401 | |
356 | RETVAL = newSV (w * h); |
402 | RETVAL = newSV (w * h); |
357 | SvPOK_only (RETVAL); |
403 | SvPOK_only (RETVAL); |
358 | SvCUR_set (RETVAL, w * h); |
404 | SvCUR_set (RETVAL, w * h); |
359 | |
405 | |
360 | dst = SvPVX (RETVAL); |
406 | dst = (guchar *)SvPVX (RETVAL); |
361 | |
407 | |
362 | memset (Er, 0, sizeof (int) * IW); |
408 | memset (Er, 0, sizeof (int) * IW); |
363 | memset (Eg, 0, sizeof (int) * IW); |
409 | memset (Eg, 0, sizeof (int) * IW); |
364 | memset (Eb, 0, sizeof (int) * IW); |
410 | memset (Eb, 0, sizeof (int) * IW); |
365 | |
411 | |
… | |
… | |
459 | |
505 | |
460 | RETVAL = newSV (6 * 8 * 12 / 8); |
506 | RETVAL = newSV (6 * 8 * 12 / 8); |
461 | SvPOK_only (RETVAL); |
507 | SvPOK_only (RETVAL); |
462 | SvCUR_set (RETVAL, 6 * 8 * 12 / 8); |
508 | SvCUR_set (RETVAL, 6 * 8 * 12 / 8); |
463 | |
509 | |
464 | dst = SvPVX (RETVAL); |
510 | dst = (guchar *)SvPVX (RETVAL); |
465 | |
511 | |
466 | /* some primitive error distribution + random dithering */ |
512 | /* some primitive error distribution + random dithering */ |
467 | |
513 | |
468 | for (y = 0; y < h; y++) |
514 | for (y = 0; y < h; y++) |
469 | { |
515 | { |