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