]>
Commit | Line | Data |
---|---|---|
b13a3ddb | 1 | #define PERL_NO_GET_CONTEXT |
02d1d628 AMH |
2 | #ifdef __cplusplus |
3 | extern "C" { | |
4 | #endif | |
5 | #include "EXTERN.h" | |
6 | #include "perl.h" | |
7 | #include "XSUB.h" | |
7a6cd05b TC |
8 | #define NEED_newRV_noinc |
9 | #define NEED_sv_2pv_nolen | |
f35d1231 | 10 | #define NEED_sv_2pvbyte |
02d1d628 AMH |
11 | #include "ppport.h" |
12 | #ifdef __cplusplus | |
92bda632 | 13 | } |
02d1d628 AMH |
14 | #endif |
15 | ||
a8652edf TC |
16 | #define i_int_hlines_testing() 1 |
17 | ||
92bda632 | 18 | #include "imager.h" |
02d1d628 AMH |
19 | #include "feat.h" |
20 | #include "dynaload.h" | |
21 | #include "regmach.h" | |
92bda632 | 22 | #include "imextdef.h" |
ec6d8908 | 23 | #include "imextpltypes.h" |
52d990d6 | 24 | #include "imperlio.h" |
4498c8bd | 25 | #include <float.h> |
a8652edf | 26 | |
92bda632 TC |
27 | #if i_int_hlines_testing() |
28 | #include "imageri.h" | |
02d1d628 AMH |
29 | #endif |
30 | ||
92bda632 | 31 | #include "imperl.h" |
faa9b3e7 | 32 | |
0d80f37e TC |
33 | #define ARRAY_COUNT(array) (sizeof(array)/sizeof(*array)) |
34 | ||
31a13473 TC |
35 | /* |
36 | ||
37 | Context object management | |
38 | ||
39 | */ | |
40 | ||
41 | typedef im_context_t Imager__Context; | |
42 | ||
43 | #define im_context_DESTROY(ctx) im_context_refdec((ctx), "DESTROY") | |
44 | ||
45 | #ifdef PERL_IMPLICIT_CONTEXT | |
46 | ||
47 | #define MY_CXT_KEY "Imager::_context" XS_VERSION | |
48 | ||
49 | typedef struct { | |
50 | im_context_t ctx; | |
51 | } my_cxt_t; | |
52 | ||
53 | START_MY_CXT | |
54 | ||
31a13473 TC |
55 | static void |
56 | start_context(pTHX) { | |
57 | dMY_CXT; | |
58 | MY_CXT.ctx = im_context_new(); | |
59 | sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx); | |
31a13473 TC |
60 | } |
61 | ||
62 | static im_context_t | |
63 | perl_get_context(void) { | |
64 | dTHX; | |
65 | dMY_CXT; | |
66 | ||
2e23caff | 67 | return MY_CXT.ctx; |
31a13473 TC |
68 | } |
69 | ||
70 | #else | |
71 | ||
72 | static im_context_t perl_context; | |
73 | ||
74 | static void | |
75 | start_context(pTHX) { | |
76 | perl_context = im_context_new(); | |
2e23caff TC |
77 | |
78 | /* just so it gets destroyed */ | |
79 | sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", perl_context); | |
31a13473 | 80 | } |
cf8c77ae TC |
81 | |
82 | static im_context_t | |
83 | perl_get_context(void) { | |
31a13473 | 84 | return perl_context; |
cf8c77ae TC |
85 | } |
86 | ||
31a13473 TC |
87 | #endif |
88 | ||
6a9807e8 TC |
89 | /* used to represent channel lists parameters */ |
90 | typedef struct i_channel_list_tag { | |
91 | int *channels; | |
92 | int count; | |
93 | } i_channel_list; | |
94 | ||
48b9a7bf TC |
95 | typedef struct { |
96 | size_t count; | |
97 | const i_sample_t *samples; | |
98 | } i_sample_list; | |
99 | ||
100 | typedef struct { | |
101 | size_t count; | |
102 | const i_fsample_t *samples; | |
103 | } i_fsample_list; | |
104 | ||
0d80f37e TC |
105 | typedef struct { |
106 | size_t count; | |
107 | const i_polygon_t *polygons; | |
108 | } i_polygon_list; | |
109 | ||
ebe9b189 TC |
110 | /* |
111 | ||
112 | Allocate memory that will be discarded when mortals are discarded. | |
113 | ||
114 | */ | |
115 | ||
116 | static void * | |
117 | malloc_temp(pTHX_ size_t size) { | |
3230a191 TC |
118 | void *result; |
119 | Newx(result, size, char); | |
120 | SAVEFREEPV(result); | |
ebe9b189 | 121 | |
3230a191 | 122 | return result; |
ebe9b189 TC |
123 | } |
124 | ||
0aaa8b4d TC |
125 | static void * |
126 | calloc_temp(pTHX_ size_t size) { | |
3230a191 TC |
127 | void *result; |
128 | Newxz(result, size, char); | |
129 | SAVEFREEPV(result); | |
0aaa8b4d TC |
130 | |
131 | return result; | |
132 | } | |
133 | ||
19e9591b | 134 | /* for use with the T_AVARRAY typemap */ |
0aaa8b4d TC |
135 | #define doublePtr(size) ((double *)calloc_temp(aTHX_ sizeof(double) * (size))) |
136 | #define SvDouble(sv, pname) (SvNV(sv)) | |
137 | ||
138 | #define intPtr(size) ((int *)calloc_temp(aTHX_ sizeof(int) * (size))) | |
139 | #define SvInt(sv, pname) (SvIV(sv)) | |
140 | ||
141 | #define i_img_dimPtr(size) ((i_img_dim *)calloc_temp(aTHX_ sizeof(i_img_dim) * (size))) | |
142 | #define SvI_img_dim(sv, pname) (SvIV(sv)) | |
19e9591b | 143 | |
4615ad8d | 144 | #define i_colorPtr(size) ((i_color *)calloc_temp(aTHX_ sizeof(i_color) * (size))) |
0aaa8b4d TC |
145 | |
146 | #define SvI_color(sv, pname) S_sv_to_i_color(aTHX_ sv, pname) | |
147 | ||
148 | static i_color | |
149 | S_sv_to_i_color(pTHX_ SV *sv, const char *pname) { | |
150 | if (!sv_derived_from(sv, "Imager::Color")) { | |
b6565be6 | 151 | croak("%s: not a color object", pname); |
0aaa8b4d TC |
152 | } |
153 | return *INT2PTR(i_color *, SvIV((SV *)SvRV(sv))); | |
154 | } | |
19e9591b | 155 | |
b33c08f8 TC |
156 | /* These functions are all shared - then comes platform dependant code */ |
157 | static int getstr(void *hv_t,char *key,char **store) { | |
b13a3ddb | 158 | dTHX; |
b33c08f8 TC |
159 | SV** svpp; |
160 | HV* hv=(HV*)hv_t; | |
161 | ||
8d14daab | 162 | mm_log((1,"getstr(hv_t %p, key %s, store %p)\n",hv_t,key,store)); |
b33c08f8 TC |
163 | |
164 | if ( !hv_exists(hv,key,strlen(key)) ) return 0; | |
165 | ||
166 | svpp=hv_fetch(hv, key, strlen(key), 0); | |
167 | *store=SvPV(*svpp, PL_na ); | |
168 | ||
169 | return 1; | |
170 | } | |
171 | ||
172 | static int getint(void *hv_t,char *key,int *store) { | |
b13a3ddb | 173 | dTHX; |
b33c08f8 TC |
174 | SV** svpp; |
175 | HV* hv=(HV*)hv_t; | |
176 | ||
8d14daab | 177 | mm_log((1,"getint(hv_t %p, key %s, store %p)\n",hv_t,key,store)); |
b33c08f8 TC |
178 | |
179 | if ( !hv_exists(hv,key,strlen(key)) ) return 0; | |
180 | ||
181 | svpp=hv_fetch(hv, key, strlen(key), 0); | |
182 | *store=(int)SvIV(*svpp); | |
183 | return 1; | |
184 | } | |
185 | ||
186 | static int getdouble(void *hv_t,char* key,double *store) { | |
b13a3ddb | 187 | dTHX; |
b33c08f8 TC |
188 | SV** svpp; |
189 | HV* hv=(HV*)hv_t; | |
190 | ||
8d14daab | 191 | mm_log((1,"getdouble(hv_t %p, key %s, store %p)\n",hv_t,key,store)); |
b33c08f8 TC |
192 | |
193 | if ( !hv_exists(hv,key,strlen(key)) ) return 0; | |
194 | svpp=hv_fetch(hv, key, strlen(key), 0); | |
8d14daab | 195 | *store=(double)SvNV(*svpp); |
b33c08f8 TC |
196 | return 1; |
197 | } | |
198 | ||
199 | static int getvoid(void *hv_t,char* key,void **store) { | |
b13a3ddb | 200 | dTHX; |
b33c08f8 TC |
201 | SV** svpp; |
202 | HV* hv=(HV*)hv_t; | |
203 | ||
8d14daab | 204 | mm_log((1,"getvoid(hv_t %p, key %s, store %p)\n",hv_t,key,store)); |
b33c08f8 TC |
205 | |
206 | if ( !hv_exists(hv,key,strlen(key)) ) return 0; | |
207 | ||
208 | svpp=hv_fetch(hv, key, strlen(key), 0); | |
209 | *store = INT2PTR(void*, SvIV(*svpp)); | |
210 | ||
211 | return 1; | |
212 | } | |
213 | ||
214 | static int getobj(void *hv_t,char *key,char *type,void **store) { | |
b13a3ddb | 215 | dTHX; |
b33c08f8 TC |
216 | SV** svpp; |
217 | HV* hv=(HV*)hv_t; | |
218 | ||
8d14daab | 219 | mm_log((1,"getobj(hv_t %p, key %s,type %s, store %p)\n",hv_t,key,type,store)); |
b33c08f8 TC |
220 | |
221 | if ( !hv_exists(hv,key,strlen(key)) ) return 0; | |
222 | ||
223 | svpp=hv_fetch(hv, key, strlen(key), 0); | |
224 | ||
225 | if (sv_derived_from(*svpp,type)) { | |
226 | IV tmp = SvIV((SV*)SvRV(*svpp)); | |
227 | *store = INT2PTR(void*, tmp); | |
228 | } else { | |
229 | mm_log((1,"getobj: key exists in hash but is not of correct type")); | |
230 | return 0; | |
231 | } | |
232 | ||
233 | return 1; | |
234 | } | |
235 | ||
236 | UTIL_table_t i_UTIL_table={getstr,getint,getdouble,getvoid,getobj}; | |
4dfa5522 | 237 | |
a87997b2 TC |
238 | static void |
239 | free_buffer(void *p) { | |
240 | myfree(p); | |
4dfa5522 AMH |
241 | } |
242 | ||
7f882a01 | 243 | |
b33c08f8 | 244 | static void |
bf1573f9 | 245 | i_log_entry(char *string, int level) { |
b7506a07 | 246 | mm_log((level, "%s", string)); |
7f882a01 AMH |
247 | } |
248 | ||
5e9a7fbd TC |
249 | static SV * |
250 | make_i_color_sv(pTHX_ const i_color *c) { | |
251 | SV *sv; | |
252 | i_color *col = mymalloc(sizeof(i_color)); | |
253 | *col = *c; | |
254 | sv = sv_newmortal(); | |
255 | sv_setref_pv(sv, "Imager::Color", (void *)col); | |
256 | ||
257 | return sv; | |
258 | } | |
7f882a01 | 259 | |
10461f9a TC |
260 | #define CBDATA_BUFSIZE 8192 |
261 | ||
262 | struct cbdata { | |
263 | /* the SVs we use to call back to Perl */ | |
264 | SV *writecb; | |
265 | SV *readcb; | |
266 | SV *seekcb; | |
267 | SV *closecb; | |
10461f9a TC |
268 | }; |
269 | ||
6d5c85a2 TC |
270 | static ssize_t |
271 | call_reader(struct cbdata *cbd, void *buf, size_t size, | |
272 | size_t maxread) { | |
b13a3ddb | 273 | dTHX; |
10461f9a TC |
274 | int count; |
275 | int result; | |
276 | SV *data; | |
277 | dSP; | |
278 | ||
9d5ff8a6 TC |
279 | if (!SvOK(cbd->readcb)) { |
280 | mm_log((1, "read callback called but no readcb supplied\n")); | |
281 | i_push_error(0, "read callback called but no readcb supplied"); | |
10461f9a | 282 | return -1; |
9d5ff8a6 | 283 | } |
10461f9a TC |
284 | |
285 | ENTER; | |
286 | SAVETMPS; | |
287 | EXTEND(SP, 2); | |
288 | PUSHMARK(SP); | |
289 | PUSHs(sv_2mortal(newSViv(size))); | |
290 | PUSHs(sv_2mortal(newSViv(maxread))); | |
291 | PUTBACK; | |
292 | ||
293 | count = perl_call_sv(cbd->readcb, G_SCALAR); | |
294 | ||
295 | SPAGAIN; | |
296 | ||
297 | if (count != 1) | |
298 | croak("Result of perl_call_sv(..., G_SCALAR) != 1"); | |
299 | ||
300 | data = POPs; | |
301 | ||
302 | if (SvOK(data)) { | |
303 | STRLEN len; | |
6d5c85a2 | 304 | char *ptr = SvPVbyte(data, len); |
10461f9a | 305 | if (len > maxread) |
6d5c85a2 TC |
306 | croak("Too much data returned in reader callback (wanted %d, got %d, expected %d)", |
307 | (int)size, (int)len, (int)maxread); | |
10461f9a TC |
308 | |
309 | memcpy(buf, ptr, len); | |
310 | result = len; | |
311 | } | |
312 | else { | |
313 | result = -1; | |
314 | } | |
315 | ||
316 | PUTBACK; | |
317 | FREETMPS; | |
318 | LEAVE; | |
319 | ||
320 | return result; | |
321 | } | |
322 | ||
6d5c85a2 TC |
323 | static off_t |
324 | io_seeker(void *p, off_t offset, int whence) { | |
b13a3ddb | 325 | dTHX; |
10461f9a TC |
326 | struct cbdata *cbd = p; |
327 | int count; | |
328 | off_t result; | |
329 | dSP; | |
330 | ||
9d5ff8a6 TC |
331 | if (!SvOK(cbd->seekcb)) { |
332 | mm_log((1, "seek callback called but no seekcb supplied\n")); | |
333 | i_push_error(0, "seek callback called but no seekcb supplied"); | |
10461f9a | 334 | return -1; |
9d5ff8a6 | 335 | } |
10461f9a | 336 | |
10461f9a TC |
337 | ENTER; |
338 | SAVETMPS; | |
339 | EXTEND(SP, 2); | |
340 | PUSHMARK(SP); | |
341 | PUSHs(sv_2mortal(newSViv(offset))); | |
342 | PUSHs(sv_2mortal(newSViv(whence))); | |
343 | PUTBACK; | |
344 | ||
345 | count = perl_call_sv(cbd->seekcb, G_SCALAR); | |
346 | ||
347 | SPAGAIN; | |
348 | ||
349 | if (count != 1) | |
350 | croak("Result of perl_call_sv(..., G_SCALAR) != 1"); | |
351 | ||
352 | result = POPi; | |
353 | ||
354 | PUTBACK; | |
355 | FREETMPS; | |
356 | LEAVE; | |
357 | ||
358 | return result; | |
359 | } | |
360 | ||
6d5c85a2 TC |
361 | static ssize_t |
362 | io_writer(void *p, void const *data, size_t size) { | |
b13a3ddb | 363 | dTHX; |
10461f9a | 364 | struct cbdata *cbd = p; |
6d5c85a2 TC |
365 | I32 count; |
366 | SV *sv; | |
367 | dSP; | |
368 | bool success; | |
10461f9a | 369 | |
9d5ff8a6 TC |
370 | if (!SvOK(cbd->writecb)) { |
371 | mm_log((1, "write callback called but no writecb supplied\n")); | |
372 | i_push_error(0, "write callback called but no writecb supplied"); | |
6d5c85a2 | 373 | return -1; |
9d5ff8a6 | 374 | } |
6d5c85a2 TC |
375 | |
376 | ENTER; | |
377 | SAVETMPS; | |
378 | EXTEND(SP, 1); | |
379 | PUSHMARK(SP); | |
380 | PUSHs(sv_2mortal(newSVpv((char *)data, size))); | |
381 | PUTBACK; | |
382 | ||
383 | count = perl_call_sv(cbd->writecb, G_SCALAR); | |
384 | ||
385 | SPAGAIN; | |
386 | if (count != 1) | |
387 | croak("Result of perl_call_sv(..., G_SCALAR) != 1"); | |
388 | ||
389 | sv = POPs; | |
390 | success = SvTRUE(sv); | |
391 | ||
392 | ||
393 | PUTBACK; | |
394 | FREETMPS; | |
395 | LEAVE; | |
396 | ||
397 | return success ? size : -1; | |
10461f9a TC |
398 | } |
399 | ||
1f6c1c10 TC |
400 | static ssize_t |
401 | io_reader(void *p, void *data, size_t size) { | |
10461f9a | 402 | struct cbdata *cbd = p; |
10461f9a | 403 | |
6d5c85a2 | 404 | return call_reader(cbd, data, size, size); |
10461f9a TC |
405 | } |
406 | ||
2b405c9e | 407 | static int io_closer(void *p) { |
b13a3ddb | 408 | dTHX; |
10461f9a | 409 | struct cbdata *cbd = p; |
6d5c85a2 | 410 | int success = 1; |
10461f9a TC |
411 | |
412 | if (SvOK(cbd->closecb)) { | |
413 | dSP; | |
6d5c85a2 | 414 | I32 count; |
10461f9a TC |
415 | |
416 | ENTER; | |
417 | SAVETMPS; | |
418 | PUSHMARK(SP); | |
419 | PUTBACK; | |
420 | ||
6d5c85a2 | 421 | count = perl_call_sv(cbd->closecb, G_SCALAR); |
10461f9a TC |
422 | |
423 | SPAGAIN; | |
6d5c85a2 | 424 | |
98747309 TC |
425 | if (count) { |
426 | SV *sv = POPs; | |
427 | success = SvTRUE(sv); | |
428 | } | |
429 | else | |
430 | success = 0; | |
6d5c85a2 | 431 | |
10461f9a TC |
432 | PUTBACK; |
433 | FREETMPS; | |
434 | LEAVE; | |
435 | } | |
2b405c9e | 436 | |
6d5c85a2 | 437 | return success ? 0 : -1; |
10461f9a TC |
438 | } |
439 | ||
440 | static void io_destroyer(void *p) { | |
b13a3ddb | 441 | dTHX; |
10461f9a TC |
442 | struct cbdata *cbd = p; |
443 | ||
444 | SvREFCNT_dec(cbd->writecb); | |
445 | SvREFCNT_dec(cbd->readcb); | |
446 | SvREFCNT_dec(cbd->seekcb); | |
447 | SvREFCNT_dec(cbd->closecb); | |
a4168bea | 448 | myfree(cbd); |
10461f9a TC |
449 | } |
450 | ||
a87997b2 TC |
451 | static bool |
452 | im_SvREFSCALAR(SV *sv) { | |
453 | svtype type = SvTYPE(sv); | |
ea87cee9 TC |
454 | |
455 | switch (type) { | |
456 | case SVt_PV: | |
457 | case SVt_PVIV: | |
458 | case SVt_PVNV: | |
459 | case SVt_PVMG: | |
460 | case SVt_IV: | |
461 | case SVt_NV: | |
462 | case SVt_PVLV: | |
463 | #if PERL_VERSION > 10 | |
464 | case SVt_REGEXP: | |
465 | #endif | |
466 | return 1; | |
467 | ||
468 | default: | |
469 | return 0; | |
470 | } | |
471 | } | |
472 | ||
473 | static const char * | |
474 | describe_sv(SV *sv) { | |
475 | if (SvOK(sv)) { | |
476 | if (SvROK(sv)) { | |
477 | svtype type = SvTYPE(SvRV(sv)); | |
478 | switch (type) { | |
479 | case SVt_PVCV: return "CV"; | |
480 | case SVt_PVGV: return "GV"; | |
481 | case SVt_PVLV: return "LV"; | |
482 | default: return "some reference"; | |
483 | } | |
484 | } | |
485 | else { | |
486 | return "non-reference scalar"; | |
487 | } | |
488 | } | |
489 | else { | |
490 | return "undef"; | |
491 | } | |
a87997b2 TC |
492 | } |
493 | ||
6d5c85a2 TC |
494 | static i_io_glue_t * |
495 | do_io_new_buffer(pTHX_ SV *data_sv) { | |
496 | const char *data; | |
a87997b2 | 497 | char *data_copy; |
6d5c85a2 | 498 | STRLEN length; |
a87997b2 TC |
499 | SV *sv; |
500 | ||
501 | SvGETMAGIC(data_sv); | |
502 | if (SvROK(data_sv)) { | |
ea87cee9 | 503 | if (im_SvREFSCALAR(SvRV(data_sv))) { |
a87997b2 TC |
504 | sv = SvRV(data_sv); |
505 | } | |
506 | else { | |
ea87cee9 | 507 | i_push_errorf(0, "data is not a scalar or a reference to scalar"); |
a87997b2 TC |
508 | return NULL; |
509 | } | |
510 | } | |
511 | else { | |
512 | sv = data_sv; | |
513 | } | |
6d5c85a2 | 514 | |
a87997b2 TC |
515 | /* previously this would keep the SV around, but this is unsafe in |
516 | many ways, so always copy the bytes */ | |
517 | data = SvPVbyte(sv, length); | |
518 | data_copy = mymalloc(length); | |
519 | memcpy(data_copy, data, length); | |
520 | return io_new_buffer(data_copy, length, free_buffer, data_copy); | |
6d5c85a2 TC |
521 | } |
522 | ||
523 | static i_io_glue_t * | |
524 | do_io_new_cb(pTHX_ SV *writecb, SV *readcb, SV *seekcb, SV *closecb) { | |
525 | struct cbdata *cbd; | |
526 | ||
527 | cbd = mymalloc(sizeof(struct cbdata)); | |
528 | cbd->writecb = newSVsv(writecb); | |
529 | cbd->readcb = newSVsv(readcb); | |
530 | cbd->seekcb = newSVsv(seekcb); | |
531 | cbd->closecb = newSVsv(closecb); | |
532 | ||
9d5ff8a6 TC |
533 | mm_log((1, "do_io_new_cb(writecb %p (%s), readcb %p (%s), seekcb %p (%s), closecb %p (%s))\n", writecb, describe_sv(writecb), readcb, describe_sv(readcb), seekcb, describe_sv(seekcb), closecb, describe_sv(closecb))); |
534 | ||
6d5c85a2 TC |
535 | return io_new_cb(cbd, io_reader, io_writer, io_seeker, io_closer, |
536 | io_destroyer); | |
537 | } | |
538 | ||
02d1d628 | 539 | struct value_name { |
a3b721bb | 540 | const char *name; |
02d1d628 AMH |
541 | int value; |
542 | }; | |
a3b721bb TC |
543 | static int |
544 | lookup_name(const struct value_name *names, int count, char *name, int def_value, int push_errors, const char *id, int *failed) | |
02d1d628 AMH |
545 | { |
546 | int i; | |
a3b721bb TC |
547 | |
548 | if (push_errors) | |
549 | *failed = 0; | |
550 | ||
02d1d628 AMH |
551 | for (i = 0; i < count; ++i) |
552 | if (strEQ(names[i].name, name)) | |
553 | return names[i].value; | |
554 | ||
a3b721bb TC |
555 | if (push_errors) { |
556 | i_push_errorf(0, "unknown value '%s' for %s", name, id); | |
557 | *failed = 1; | |
558 | } | |
559 | ||
02d1d628 AMH |
560 | return def_value; |
561 | } | |
a3b721bb | 562 | |
02d1d628 AMH |
563 | static struct value_name transp_names[] = |
564 | { | |
565 | { "none", tr_none }, | |
566 | { "threshold", tr_threshold }, | |
567 | { "errdiff", tr_errdiff }, | |
568 | { "ordered", tr_ordered, }, | |
569 | }; | |
570 | ||
571 | static struct value_name make_color_names[] = | |
572 | { | |
573 | { "none", mc_none, }, | |
574 | { "webmap", mc_web_map, }, | |
575 | { "addi", mc_addi, }, | |
97c4effc | 576 | { "mediancut", mc_median_cut, }, |
9c106321 TC |
577 | { "mono", mc_mono, }, |
578 | { "monochrome", mc_mono, }, | |
5e9a7fbd TC |
579 | { "gray", mc_gray, }, |
580 | { "gray4", mc_gray4, }, | |
581 | { "gray16", mc_gray16, }, | |
02d1d628 AMH |
582 | }; |
583 | ||
584 | static struct value_name translate_names[] = | |
585 | { | |
02d1d628 | 586 | { "giflib", pt_giflib, }, |
02d1d628 AMH |
587 | { "closest", pt_closest, }, |
588 | { "perturb", pt_perturb, }, | |
589 | { "errdiff", pt_errdiff, }, | |
590 | }; | |
591 | ||
592 | static struct value_name errdiff_names[] = | |
593 | { | |
594 | { "floyd", ed_floyd, }, | |
595 | { "jarvis", ed_jarvis, }, | |
596 | { "stucki", ed_stucki, }, | |
597 | { "custom", ed_custom, }, | |
598 | }; | |
599 | ||
600 | static struct value_name orddith_names[] = | |
601 | { | |
602 | { "random", od_random, }, | |
603 | { "dot8", od_dot8, }, | |
604 | { "dot4", od_dot4, }, | |
605 | { "hline", od_hline, }, | |
606 | { "vline", od_vline, }, | |
607 | { "/line", od_slashline, }, | |
608 | { "slashline", od_slashline, }, | |
609 | { "\\line", od_backline, }, | |
610 | { "backline", od_backline, }, | |
e7d4ea82 | 611 | { "tiny", od_tiny, }, |
02d1d628 AMH |
612 | { "custom", od_custom, }, |
613 | }; | |
614 | ||
615 | /* look through the hash for quantization options */ | |
a3b721bb TC |
616 | static int |
617 | ip_handle_quant_opts_low(pTHX_ i_quantize *quant, HV *hv, int push_errors) | |
02d1d628 | 618 | { |
02d1d628 AMH |
619 | SV **sv; |
620 | int i; | |
621 | STRLEN len; | |
622 | char *str; | |
a3b721bb | 623 | int failed = 0; |
02d1d628 | 624 | |
46a04ceb TC |
625 | quant->mc_colors = mymalloc(quant->mc_size * sizeof(i_color)); |
626 | ||
02d1d628 AMH |
627 | sv = hv_fetch(hv, "transp", 6, 0); |
628 | if (sv && *sv && (str = SvPV(*sv, len))) { | |
629 | quant->transp = | |
630 | lookup_name(transp_names, sizeof(transp_names)/sizeof(*transp_names), | |
a3b721bb TC |
631 | str, tr_none, push_errors, "transp", &failed); |
632 | if (failed) | |
633 | return 0; | |
02d1d628 AMH |
634 | if (quant->transp != tr_none) { |
635 | quant->tr_threshold = 127; | |
636 | sv = hv_fetch(hv, "tr_threshold", 12, 0); | |
637 | if (sv && *sv) | |
638 | quant->tr_threshold = SvIV(*sv); | |
639 | } | |
640 | if (quant->transp == tr_errdiff) { | |
641 | sv = hv_fetch(hv, "tr_errdiff", 10, 0); | |
642 | if (sv && *sv && (str = SvPV(*sv, len))) | |
a3b721bb TC |
643 | quant->tr_errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd, push_errors, "tr_errdiff", &failed); |
644 | if (failed) | |
645 | return 0; | |
02d1d628 AMH |
646 | } |
647 | if (quant->transp == tr_ordered) { | |
e7d4ea82 | 648 | quant->tr_orddith = od_tiny; |
02d1d628 | 649 | sv = hv_fetch(hv, "tr_orddith", 10, 0); |
a3b721bb TC |
650 | if (sv && *sv && (str = SvPV(*sv, len))) { |
651 | quant->tr_orddith = lookup_name(orddith_names, sizeof(orddith_names)/sizeof(*orddith_names), str, od_random, push_errors, "tr_orddith", &failed); | |
652 | if (failed) | |
653 | return 0; | |
654 | } | |
02d1d628 AMH |
655 | |
656 | if (quant->tr_orddith == od_custom) { | |
657 | sv = hv_fetch(hv, "tr_map", 6, 0); | |
658 | if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) { | |
659 | AV *av = (AV*)SvRV(*sv); | |
660 | len = av_len(av) + 1; | |
661 | if (len > sizeof(quant->tr_custom)) | |
662 | len = sizeof(quant->tr_custom); | |
663 | for (i = 0; i < len; ++i) { | |
664 | SV **sv2 = av_fetch(av, i, 0); | |
665 | if (sv2 && *sv2) { | |
666 | quant->tr_custom[i] = SvIV(*sv2); | |
667 | } | |
668 | } | |
669 | while (i < sizeof(quant->tr_custom)) | |
670 | quant->tr_custom[i++] = 0; | |
671 | } | |
672 | } | |
673 | } | |
674 | } | |
0348fe07 | 675 | quant->make_colors = mc_median_cut; |
02d1d628 AMH |
676 | sv = hv_fetch(hv, "make_colors", 11, 0); |
677 | if (sv && *sv && (str = SvPV(*sv, len))) { | |
678 | quant->make_colors = | |
a3b721bb TC |
679 | lookup_name(make_color_names, sizeof(make_color_names)/sizeof(*make_color_names), str, mc_median_cut, push_errors, "make_colors", &failed); |
680 | if (failed) | |
681 | return 0; | |
02d1d628 AMH |
682 | } |
683 | sv = hv_fetch(hv, "colors", 6, 0); | |
684 | if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { | |
685 | /* needs to be an array of Imager::Color | |
686 | note that the caller allocates the mc_color array and sets mc_size | |
687 | to it's size */ | |
688 | AV *av = (AV *)SvRV(*sv); | |
689 | quant->mc_count = av_len(av)+1; | |
690 | if (quant->mc_count > quant->mc_size) | |
691 | quant->mc_count = quant->mc_size; | |
692 | for (i = 0; i < quant->mc_count; ++i) { | |
693 | SV **sv1 = av_fetch(av, i, 0); | |
694 | if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) { | |
4c4c2ffd | 695 | i_color *col = INT2PTR(i_color *, SvIV((SV*)SvRV(*sv1))); |
02d1d628 AMH |
696 | quant->mc_colors[i] = *col; |
697 | } | |
a3b721bb TC |
698 | else if (push_errors) { |
699 | i_push_errorf(0, "colors[%d] isn't an Imager::Color object", i); | |
700 | return 0; | |
701 | } | |
02d1d628 AMH |
702 | } |
703 | } | |
704 | sv = hv_fetch(hv, "max_colors", 10, 0); | |
705 | if (sv && *sv) { | |
706 | i = SvIV(*sv); | |
707 | if (i <= quant->mc_size && i >= quant->mc_count) | |
708 | quant->mc_size = i; | |
709 | } | |
710 | ||
711 | quant->translate = pt_closest; | |
712 | sv = hv_fetch(hv, "translate", 9, 0); | |
713 | if (sv && *sv && (str = SvPV(*sv, len))) { | |
a3b721bb TC |
714 | quant->translate = lookup_name(translate_names, sizeof(translate_names)/sizeof(*translate_names), str, pt_closest, push_errors, "translate", &failed); |
715 | if (failed) | |
716 | return 0; | |
02d1d628 AMH |
717 | } |
718 | sv = hv_fetch(hv, "errdiff", 7, 0); | |
719 | if (sv && *sv && (str = SvPV(*sv, len))) { | |
a3b721bb TC |
720 | quant->errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd, push_errors, "errdiff", &failed); |
721 | if (failed) | |
722 | return 0; | |
02d1d628 AMH |
723 | } |
724 | if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) { | |
725 | /* get the error diffusion map */ | |
726 | sv = hv_fetch(hv, "errdiff_width", 13, 0); | |
727 | if (sv && *sv) | |
728 | quant->ed_width = SvIV(*sv); | |
729 | sv = hv_fetch(hv, "errdiff_height", 14, 0); | |
730 | if (sv && *sv) | |
731 | quant->ed_height = SvIV(*sv); | |
732 | sv = hv_fetch(hv, "errdiff_orig", 12, 0); | |
733 | if (sv && *sv) | |
734 | quant->ed_orig = SvIV(*sv); | |
735 | if (quant->ed_width > 0 && quant->ed_height > 0) { | |
736 | int sum = 0; | |
737 | quant->ed_map = mymalloc(sizeof(int)*quant->ed_width*quant->ed_height); | |
738 | sv = hv_fetch(hv, "errdiff_map", 11, 0); | |
739 | if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { | |
740 | AV *av = (AV*)SvRV(*sv); | |
741 | len = av_len(av) + 1; | |
742 | if (len > quant->ed_width * quant->ed_height) | |
743 | len = quant->ed_width * quant->ed_height; | |
744 | for (i = 0; i < len; ++i) { | |
745 | SV **sv2 = av_fetch(av, i, 0); | |
746 | if (sv2 && *sv2) { | |
a3b721bb TC |
747 | IV iv = SvIV(*sv2); |
748 | if (push_errors && iv < 0) { | |
749 | i_push_errorf(0, "errdiff_map values must be non-negative, errdiff[%d] is negative", i); | |
750 | return 0; | |
751 | } | |
752 | quant->ed_map[i] = iv; | |
02d1d628 AMH |
753 | sum += quant->ed_map[i]; |
754 | } | |
755 | } | |
756 | } | |
757 | if (!sum) { | |
758 | /* broken map */ | |
759 | myfree(quant->ed_map); | |
760 | quant->ed_map = 0; | |
761 | quant->errdiff = ed_floyd; | |
a3b721bb TC |
762 | if (push_errors) { |
763 | i_push_error(0, "error diffusion map must contain some non-zero values"); | |
764 | return 0; | |
765 | } | |
02d1d628 AMH |
766 | } |
767 | } | |
768 | } | |
769 | sv = hv_fetch(hv, "perturb", 7, 0); | |
770 | if (sv && *sv) | |
771 | quant->perturb = SvIV(*sv); | |
a3b721bb TC |
772 | |
773 | return 1; | |
02d1d628 AMH |
774 | } |
775 | ||
ec6d8908 TC |
776 | static void |
777 | ip_cleanup_quant_opts(pTHX_ i_quantize *quant) { | |
46a04ceb TC |
778 | myfree(quant->mc_colors); |
779 | if (quant->ed_map) | |
780 | myfree(quant->ed_map); | |
781 | } | |
782 | ||
a3b721bb TC |
783 | static int |
784 | ip_handle_quant_opts2(pTHX_ i_quantize *quant, HV *hv) { | |
785 | int result = ip_handle_quant_opts_low(aTHX_ quant, hv, 1); | |
786 | if (!result) { | |
787 | ip_cleanup_quant_opts(aTHX_ quant); | |
788 | } | |
789 | return result; | |
790 | } | |
791 | ||
792 | static void | |
793 | ip_handle_quant_opts(pTHX_ i_quantize *quant, HV *hv) { | |
794 | (void)ip_handle_quant_opts_low(aTHX_ quant, hv, 0); | |
795 | } | |
796 | ||
02d1d628 | 797 | /* copies the color map from the hv into the colors member of the HV */ |
ec6d8908 TC |
798 | static void |
799 | ip_copy_colors_back(pTHX_ HV *hv, i_quantize *quant) { | |
02d1d628 AMH |
800 | SV **sv; |
801 | AV *av; | |
802 | int i; | |
803 | SV *work; | |
804 | ||
805 | sv = hv_fetch(hv, "colors", 6, 0); | |
806 | if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) { | |
5c0d0ddf TC |
807 | /* nothing to do */ |
808 | return; | |
02d1d628 | 809 | } |
5c0d0ddf TC |
810 | |
811 | av = (AV *)SvRV(*sv); | |
812 | av_clear(av); | |
02d1d628 AMH |
813 | av_extend(av, quant->mc_count+1); |
814 | for (i = 0; i < quant->mc_count; ++i) { | |
815 | i_color *in = quant->mc_colors+i; | |
816 | Imager__Color c = ICL_new_internal(in->rgb.r, in->rgb.g, in->rgb.b, 255); | |
817 | work = sv_newmortal(); | |
818 | sv_setref_pv(work, "Imager::Color", (void *)c); | |
819 | SvREFCNT_inc(work); | |
5c0d0ddf | 820 | av_push(av, work); |
02d1d628 AMH |
821 | } |
822 | } | |
823 | ||
0d80f37e TC |
824 | static struct value_name |
825 | poly_fill_mode_names[] = | |
826 | { | |
827 | { "evenodd", i_pfm_evenodd }, | |
828 | { "nonzero", i_pfm_nonzero } | |
829 | }; | |
830 | ||
831 | static i_poly_fill_mode_t | |
832 | S_get_poly_fill_mode(pTHX_ SV *sv) { | |
833 | if (looks_like_number(sv)) { | |
834 | IV work = SvIV(sv); | |
835 | if (work < (IV)i_pfm_evenodd || work > (IV)i_pfm_nonzero) | |
836 | work = (IV)i_pfm_evenodd; | |
837 | return (i_poly_fill_mode_t)work; | |
838 | } | |
839 | else { | |
840 | return (i_poly_fill_mode_t)lookup_name | |
841 | (poly_fill_mode_names, ARRAY_COUNT(poly_fill_mode_names), | |
a3b721bb | 842 | SvPV_nolen(sv), i_pfm_evenodd, 0, NULL, NULL); |
0d80f37e TC |
843 | } |
844 | } | |
845 | ||
846 | static void | |
847 | S_get_polygon_list(pTHX_ i_polygon_list *polys, SV *sv) { | |
848 | AV *av; | |
849 | int i; | |
850 | i_polygon_t *s; | |
851 | ||
852 | SvGETMAGIC(sv); | |
853 | if (!SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) | |
854 | croak("polys must be an arrayref"); | |
855 | ||
856 | av = (AV*)SvRV(sv); | |
857 | polys->count = av_len(av) + 1; | |
858 | if (polys->count < 1) | |
859 | croak("polypolygon: no polygons provided"); | |
860 | s = malloc_temp(aTHX_ sizeof(i_polygon_t) * polys->count); | |
861 | for (i = 0; i < polys->count; ++i) { | |
862 | SV **poly_sv = av_fetch(av, i, 0); | |
863 | AV *poly_av; | |
864 | SV **x_sv, **y_sv; | |
865 | AV *x_av, *y_av; | |
866 | double *x_data, *y_data; | |
867 | ssize_t j; | |
868 | ssize_t point_count; | |
869 | ||
870 | if (!poly_sv) | |
871 | croak("poly_polygon: nothing found for polygon %d", i); | |
872 | /* needs to be another av */ | |
873 | SvGETMAGIC(*poly_sv); | |
874 | if (!SvOK(*poly_sv) || !SvROK(*poly_sv) || SvTYPE(SvRV(*poly_sv)) != SVt_PVAV) | |
875 | croak("poly_polygon: polygon %d isn't an arrayref", i); | |
876 | poly_av = (AV*)SvRV(*poly_sv); | |
877 | /* with two elements */ | |
878 | if (av_len(poly_av) != 1) | |
879 | croak("poly_polygon: polygon %d should contain two arrays", i); | |
880 | x_sv = av_fetch(poly_av, 0, 0); | |
881 | y_sv = av_fetch(poly_av, 1, 0); | |
882 | if (!x_sv) | |
883 | croak("poly_polygon: polygon %d has no x elements", i); | |
884 | if (!y_sv) | |
885 | croak("poly_polygon: polygon %d has no y elements", i); | |
886 | SvGETMAGIC(*x_sv); | |
887 | SvGETMAGIC(*y_sv); | |
888 | if (!SvOK(*x_sv) || !SvROK(*x_sv) || SvTYPE(SvRV(*x_sv)) != SVt_PVAV) | |
889 | croak("poly_polygon: polygon %d x elements isn't an array", i); | |
890 | if (!SvOK(*y_sv) || !SvROK(*y_sv) || SvTYPE(SvRV(*y_sv)) != SVt_PVAV) | |
891 | croak("poly_polygon: polygon %d y elements isn't an array", i); | |
892 | x_av = (AV*)SvRV(*x_sv); | |
893 | y_av = (AV*)SvRV(*y_sv); | |
894 | if (av_len(x_av) != av_len(y_av)) | |
895 | croak("poly_polygon: polygon %d x and y arrays different lengths", i+1); | |
896 | point_count = av_len(x_av)+1; | |
897 | x_data = malloc_temp(aTHX_ sizeof(double) * point_count * 2); | |
898 | y_data = x_data + point_count; | |
899 | ||
900 | for (j = 0; j < point_count; ++j) { | |
901 | SV **x_item_sv = av_fetch(x_av, j, 0); | |
902 | SV **y_item_sv = av_fetch(y_av, j, 0); | |
903 | x_data[j] = x_item_sv ? SvNV(*x_item_sv) : 0; | |
904 | y_data[j] = y_item_sv ? SvNV(*y_item_sv) : 0; | |
905 | } | |
906 | s[i].x = x_data; | |
907 | s[i].y = y_data; | |
908 | s[i].count = point_count; | |
909 | } | |
910 | polys->polygons = s; | |
911 | } | |
912 | ||
f1ac5027 | 913 | /* loads the segments of a fountain fill into an array */ |
b33c08f8 | 914 | static i_fountain_seg * |
b13a3ddb | 915 | load_fount_segs(pTHX_ AV *asegs, int *count) { |
f1ac5027 TC |
916 | /* Each element of segs must contain: |
917 | [ start, middle, end, c0, c1, segtype, colortrans ] | |
918 | start, middle, end are doubles from 0 to 1 | |
919 | c0, c1 are Imager::Color::Float or Imager::Color objects | |
920 | segtype, colortrans are ints | |
921 | */ | |
922 | int i, j; | |
923 | AV *aseg; | |
f1ac5027 TC |
924 | i_fountain_seg *segs; |
925 | double work[3]; | |
926 | int worki[2]; | |
927 | ||
928 | *count = av_len(asegs)+1; | |
929 | if (*count < 1) | |
930 | croak("i_fountain must have at least one segment"); | |
931 | segs = mymalloc(sizeof(i_fountain_seg) * *count); | |
932 | for(i = 0; i < *count; i++) { | |
933 | SV **sv1 = av_fetch(asegs, i, 0); | |
934 | if (!sv1 || !*sv1 || !SvROK(*sv1) | |
935 | || SvTYPE(SvRV(*sv1)) != SVt_PVAV) { | |
936 | myfree(segs); | |
937 | croak("i_fountain: segs must be an arrayref of arrayrefs"); | |
938 | } | |
939 | aseg = (AV *)SvRV(*sv1); | |
940 | if (av_len(aseg) != 7-1) { | |
941 | myfree(segs); | |
942 | croak("i_fountain: a segment must have 7 members"); | |
943 | } | |
944 | for (j = 0; j < 3; ++j) { | |
945 | SV **sv2 = av_fetch(aseg, j, 0); | |
946 | if (!sv2 || !*sv2) { | |
947 | myfree(segs); | |
948 | croak("i_fountain: XS error"); | |
949 | } | |
950 | work[j] = SvNV(*sv2); | |
951 | } | |
952 | segs[i].start = work[0]; | |
953 | segs[i].middle = work[1]; | |
954 | segs[i].end = work[2]; | |
955 | for (j = 0; j < 2; ++j) { | |
956 | SV **sv3 = av_fetch(aseg, 3+j, 0); | |
957 | if (!sv3 || !*sv3 || !SvROK(*sv3) || | |
958 | (!sv_derived_from(*sv3, "Imager::Color") | |
959 | && !sv_derived_from(*sv3, "Imager::Color::Float"))) { | |
960 | myfree(segs); | |
961 | croak("i_fountain: segs must contain colors in elements 3 and 4"); | |
962 | } | |
963 | if (sv_derived_from(*sv3, "Imager::Color::Float")) { | |
4c4c2ffd | 964 | segs[i].c[j] = *INT2PTR(i_fcolor *, SvIV((SV *)SvRV(*sv3))); |
f1ac5027 TC |
965 | } |
966 | else { | |
4c4c2ffd | 967 | i_color c = *INT2PTR(i_color *, SvIV((SV *)SvRV(*sv3))); |
f1ac5027 TC |
968 | int ch; |
969 | for (ch = 0; ch < MAXCHANNELS; ++ch) { | |
970 | segs[i].c[j].channel[ch] = c.channel[ch] / 255.0; | |
971 | } | |
972 | } | |
973 | } | |
974 | for (j = 0; j < 2; ++j) { | |
975 | SV **sv2 = av_fetch(aseg, j+5, 0); | |
976 | if (!sv2 || !*sv2) { | |
977 | myfree(segs); | |
978 | croak("i_fountain: XS error"); | |
979 | } | |
980 | worki[j] = SvIV(*sv2); | |
981 | } | |
982 | segs[i].type = worki[0]; | |
983 | segs[i].color = worki[1]; | |
984 | } | |
985 | ||
986 | return segs; | |
987 | } | |
988 | ||
4cda4e76 TC |
989 | /* validates the indexes supplied to i_ppal |
990 | ||
991 | i_ppal() doesn't do that for speed, but I'm not comfortable doing that | |
992 | for calls from perl. | |
993 | ||
994 | */ | |
995 | static void | |
996 | validate_i_ppal(i_img *im, i_palidx const *indexes, int count) { | |
997 | int color_count = i_colorcount(im); | |
998 | int i; | |
999 | ||
1000 | if (color_count == -1) | |
1001 | croak("i_plin() called on direct color image"); | |
1002 | ||
1003 | for (i = 0; i < count; ++i) { | |
1004 | if (indexes[i] >= color_count) { | |
1005 | croak("i_plin() called with out of range color index %d (max %d)", | |
1006 | indexes[i], color_count-1); | |
1007 | } | |
1008 | } | |
1009 | } | |
1010 | ||
faa9b3e7 TC |
1011 | /* I don't think ICLF_* names belong at the C interface |
1012 | this makes the XS code think we have them, to let us avoid | |
1013 | putting function bodies in the XS code | |
1014 | */ | |
1015 | #define ICLF_new_internal(r, g, b, a) i_fcolor_new((r), (g), (b), (a)) | |
1016 | #define ICLF_DESTROY(cl) i_fcolor_destroy(cl) | |
1017 | ||
10ea52a3 TC |
1018 | #ifdef IMAGER_LOG |
1019 | #define i_log_enabled() 1 | |
1020 | #else | |
1021 | #define i_log_enabled() 0 | |
1022 | #endif | |
1023 | ||
a8652edf TC |
1024 | #if i_int_hlines_testing() |
1025 | ||
1026 | typedef i_int_hlines *Imager__Internal__Hlines; | |
1027 | ||
1028 | static i_int_hlines * | |
8d14daab | 1029 | i_int_hlines_new(i_img_dim start_y, i_img_dim count_y, i_img_dim start_x, i_img_dim count_x) { |
a8652edf TC |
1030 | i_int_hlines *result = mymalloc(sizeof(i_int_hlines)); |
1031 | i_int_init_hlines(result, start_y, count_y, start_x, count_x); | |
1032 | ||
1033 | return result; | |
1034 | } | |
1035 | ||
1036 | static i_int_hlines * | |
1037 | i_int_hlines_new_img(i_img *im) { | |
1038 | i_int_hlines *result = mymalloc(sizeof(i_int_hlines)); | |
1039 | i_int_init_hlines_img(result, im); | |
1040 | ||
1041 | return result; | |
1042 | } | |
1043 | ||
1044 | static void | |
1045 | i_int_hlines_DESTROY(i_int_hlines *hlines) { | |
1046 | i_int_hlines_destroy(hlines); | |
1047 | myfree(hlines); | |
1048 | } | |
1049 | ||
ffddd407 TC |
1050 | #define i_int_hlines_CLONE_SKIP(cls) 1 |
1051 | ||
a8652edf TC |
1052 | static int seg_compare(const void *vleft, const void *vright) { |
1053 | const i_int_hline_seg *left = vleft; | |
1054 | const i_int_hline_seg *right = vright; | |
1055 | ||
1056 | return left->minx - right->minx; | |
1057 | } | |
1058 | ||
1059 | static SV * | |
1060 | i_int_hlines_dump(i_int_hlines *hlines) { | |
b13a3ddb | 1061 | dTHX; |
8d14daab TC |
1062 | SV *dump = newSVpvf("start_y: %" i_DF " limit_y: %" i_DF " start_x: %" i_DF " limit_x: %" i_DF"\n", |
1063 | i_DFc(hlines->start_y), i_DFc(hlines->limit_y), i_DFc(hlines->start_x), i_DFc(hlines->limit_x)); | |
1064 | i_img_dim y; | |
a8652edf TC |
1065 | |
1066 | for (y = hlines->start_y; y < hlines->limit_y; ++y) { | |
1067 | i_int_hline_entry *entry = hlines->entries[y-hlines->start_y]; | |
1068 | if (entry) { | |
1069 | int i; | |
1070 | /* sort the segments, if any */ | |
1071 | if (entry->count) | |
1072 | qsort(entry->segs, entry->count, sizeof(i_int_hline_seg), seg_compare); | |
1073 | ||
8d14daab | 1074 | sv_catpvf(dump, " %" i_DF " (%" i_DF "):", i_DFc(y), i_DFc(entry->count)); |
a8652edf | 1075 | for (i = 0; i < entry->count; ++i) { |
8d14daab TC |
1076 | sv_catpvf(dump, " [%" i_DF ", %" i_DF ")", i_DFc(entry->segs[i].minx), |
1077 | i_DFc(entry->segs[i].x_limit)); | |
a8652edf TC |
1078 | } |
1079 | sv_catpv(dump, "\n"); | |
1080 | } | |
1081 | } | |
1082 | ||
1083 | return dump; | |
1084 | } | |
1085 | ||
1086 | #endif | |
1087 | ||
8d14daab TC |
1088 | static off_t |
1089 | i_sv_off_t(pTHX_ SV *sv) { | |
1090 | #if LSEEKSIZE > IVSIZE | |
1091 | return (off_t)SvNV(sv); | |
1092 | #else | |
1093 | return (off_t)SvIV(sv); | |
1094 | #endif | |
1095 | } | |
1096 | ||
1097 | static SV * | |
1098 | i_new_sv_off_t(pTHX_ off_t off) { | |
1099 | #if LSEEKSIZE > IVSIZE | |
1100 | return newSVnv(off); | |
1101 | #else | |
1102 | return newSViv(off); | |
1103 | #endif | |
1104 | } | |
1105 | ||
ec6d8908 TC |
1106 | static im_pl_ext_funcs im_perl_funcs = |
1107 | { | |
1108 | IMAGER_PL_API_VERSION, | |
1109 | IMAGER_PL_API_LEVEL, | |
1110 | ip_handle_quant_opts, | |
1111 | ip_cleanup_quant_opts, | |
a3b721bb TC |
1112 | ip_copy_colors_back, |
1113 | ip_handle_quant_opts2 | |
ec6d8908 TC |
1114 | }; |
1115 | ||
1116 | #define PERL_PL_SET_GLOBAL_CALLBACKS \ | |
1117 | sv_setiv(get_sv(PERL_PL_FUNCTION_TABLE_NAME, 1), PTR2IV(&im_perl_funcs)); | |
1118 | ||
bdd4c63b TC |
1119 | #define IIM_new i_img_8_new |
1120 | #define IIM_DESTROY i_img_destroy | |
42505e61 | 1121 | typedef int SysRet; |
bdd4c63b | 1122 | |
f7450478 TC |
1123 | #ifdef IMEXIF_ENABLE |
1124 | #define i_exif_enabled() 1 | |
1125 | #else | |
1126 | #define i_exif_enabled() 0 | |
1127 | #endif | |
1128 | ||
d16420e9 | 1129 | /* trying to use more C style names, map them here */ |
eda1622c | 1130 | #define i_io_DESTROY(ig) io_glue_destroy(ig) |
d16420e9 | 1131 | |
3b000586 TC |
1132 | #define i_img_get_width(im) ((im)->xsize) |
1133 | #define i_img_get_height(im) ((im)->ysize) | |
1134 | ||
4498c8bd TC |
1135 | #define i_img_epsilonf() (DBL_EPSILON * 4) |
1136 | ||
6d5c85a2 TC |
1137 | /* avoid some xsubpp strangeness */ |
1138 | #define NEWLINE '\n' | |
1139 | ||
0231b97e TC |
1140 | #define ICL_red(c) ((c)->rgba.r) |
1141 | #define ICL_green(c) ((c)->rgba.g) | |
1142 | #define ICL_blue(c) ((c)->rgba.b) | |
1143 | #define ICL_alpha(c) ((c)->rgba.a) | |
1144 | ||
1145 | #define ICLF_red(c) ((c)->rgba.r) | |
1146 | #define ICLF_green(c) ((c)->rgba.g) | |
1147 | #define ICLF_blue(c) ((c)->rgba.b) | |
1148 | #define ICLF_alpha(c) ((c)->rgba.a) | |
1149 | ||
02d1d628 AMH |
1150 | MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_ |
1151 | ||
1152 | Imager::Color | |
1153 | ICL_new_internal(r,g,b,a) | |
1154 | unsigned char r | |
1155 | unsigned char g | |
1156 | unsigned char b | |
1157 | unsigned char a | |
1158 | ||
1159 | void | |
1160 | ICL_DESTROY(cl) | |
1161 | Imager::Color cl | |
1162 | ||
1163 | ||
29106a11 | 1164 | void |
02d1d628 AMH |
1165 | ICL_set_internal(cl,r,g,b,a) |
1166 | Imager::Color cl | |
1167 | unsigned char r | |
1168 | unsigned char g | |
1169 | unsigned char b | |
1170 | unsigned char a | |
29106a11 | 1171 | PPCODE: |
b7346865 TC |
1172 | cl->rgba.r = r; |
1173 | cl->rgba.g = g; | |
1174 | cl->rgba.b = b; | |
1175 | cl->rgba.a = a; | |
29106a11 TC |
1176 | EXTEND(SP, 1); |
1177 | PUSHs(ST(0)); | |
02d1d628 AMH |
1178 | |
1179 | void | |
1180 | ICL_info(cl) | |
1181 | Imager::Color cl | |
1182 | ||
1183 | ||
1184 | void | |
1185 | ICL_rgba(cl) | |
1186 | Imager::Color cl | |
1187 | PPCODE: | |
1188 | EXTEND(SP, 4); | |
b482243a TC |
1189 | PUSHs(sv_2mortal(newSViv(cl->rgba.r))); |
1190 | PUSHs(sv_2mortal(newSViv(cl->rgba.g))); | |
1191 | PUSHs(sv_2mortal(newSViv(cl->rgba.b))); | |
1192 | PUSHs(sv_2mortal(newSViv(cl->rgba.a))); | |
02d1d628 | 1193 | |
efdc2568 TC |
1194 | Imager::Color |
1195 | i_hsv_to_rgb(c) | |
1196 | Imager::Color c | |
1197 | CODE: | |
1198 | RETVAL = mymalloc(sizeof(i_color)); | |
1199 | *RETVAL = *c; | |
1200 | i_hsv_to_rgb(RETVAL); | |
1201 | OUTPUT: | |
1202 | RETVAL | |
1203 | ||
1204 | Imager::Color | |
1205 | i_rgb_to_hsv(c) | |
1206 | Imager::Color c | |
1207 | CODE: | |
1208 | RETVAL = mymalloc(sizeof(i_color)); | |
1209 | *RETVAL = *c; | |
1210 | i_rgb_to_hsv(RETVAL); | |
1211 | OUTPUT: | |
1212 | RETVAL | |
1213 | ||
0231b97e TC |
1214 | int |
1215 | ICL_red(c) | |
1216 | Imager::Color c | |
1217 | ||
1218 | int | |
1219 | ICL_green(c) | |
1220 | Imager::Color c | |
1221 | ||
1222 | int | |
1223 | ICL_blue(c) | |
1224 | Imager::Color c | |
02d1d628 | 1225 | |
0231b97e TC |
1226 | int |
1227 | ICL_alpha(c) | |
1228 | Imager::Color c | |
02d1d628 | 1229 | |
faa9b3e7 | 1230 | MODULE = Imager PACKAGE = Imager::Color::Float PREFIX=ICLF_ |
02d1d628 | 1231 | |
faa9b3e7 TC |
1232 | Imager::Color::Float |
1233 | ICLF_new_internal(r, g, b, a) | |
5824f4c2 TC |
1234 | im_double r |
1235 | im_double g | |
1236 | im_double b | |
1237 | im_double a | |
faa9b3e7 TC |
1238 | |
1239 | void | |
1240 | ICLF_DESTROY(cl) | |
1241 | Imager::Color::Float cl | |
02d1d628 | 1242 | |
faa9b3e7 TC |
1243 | void |
1244 | ICLF_rgba(cl) | |
1245 | Imager::Color::Float cl | |
1246 | PREINIT: | |
1247 | int ch; | |
1248 | PPCODE: | |
1249 | EXTEND(SP, MAXCHANNELS); | |
1250 | for (ch = 0; ch < MAXCHANNELS; ++ch) { | |
1251 | /* printf("%d: %g\n", ch, cl->channel[ch]); */ | |
1252 | PUSHs(sv_2mortal(newSVnv(cl->channel[ch]))); | |
1253 | } | |
1254 | ||
1255 | void | |
1256 | ICLF_set_internal(cl,r,g,b,a) | |
1257 | Imager::Color::Float cl | |
5824f4c2 TC |
1258 | im_double r |
1259 | im_double g | |
1260 | im_double b | |
1261 | im_double a | |
faa9b3e7 TC |
1262 | PPCODE: |
1263 | cl->rgba.r = r; | |
1264 | cl->rgba.g = g; | |
1265 | cl->rgba.b = b; | |
1266 | cl->rgba.a = a; | |
1267 | EXTEND(SP, 1); | |
1268 | PUSHs(ST(0)); | |
02d1d628 | 1269 | |
efdc2568 TC |
1270 | Imager::Color::Float |
1271 | i_hsv_to_rgb(c) | |
1272 | Imager::Color::Float c | |
1273 | CODE: | |
1274 | RETVAL = mymalloc(sizeof(i_fcolor)); | |
1275 | *RETVAL = *c; | |
1276 | i_hsv_to_rgbf(RETVAL); | |
1277 | OUTPUT: | |
1278 | RETVAL | |
1279 | ||
1280 | Imager::Color::Float | |
1281 | i_rgb_to_hsv(c) | |
1282 | Imager::Color::Float c | |
1283 | CODE: | |
1284 | RETVAL = mymalloc(sizeof(i_fcolor)); | |
1285 | *RETVAL = *c; | |
1286 | i_rgb_to_hsvf(RETVAL); | |
1287 | OUTPUT: | |
1288 | RETVAL | |
efdc2568 | 1289 | |
0231b97e TC |
1290 | double |
1291 | ICLF_red(c) | |
1292 | Imager::Color::Float c | |
1293 | ||
1294 | double | |
1295 | ICLF_green(c) | |
1296 | Imager::Color::Float c | |
1297 | ||
1298 | double | |
1299 | ICLF_blue(c) | |
1300 | Imager::Color::Float c | |
1301 | ||
1302 | double | |
1303 | ICLF_alpha(c) | |
1304 | Imager::Color::Float c | |
1305 | ||
02d1d628 AMH |
1306 | MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_ |
1307 | ||
1308 | Imager::ImgRaw | |
5824f4c2 TC |
1309 | IIM_new(xsize,ysize,ch) |
1310 | i_img_dim xsize | |
1311 | i_img_dim ysize | |
02d1d628 AMH |
1312 | int ch |
1313 | ||
1314 | void | |
1315 | IIM_DESTROY(im) | |
1316 | Imager::ImgRaw im | |
1317 | ||
1318 | ||
1319 | ||
1320 | MODULE = Imager PACKAGE = Imager | |
1321 | ||
1322 | PROTOTYPES: ENABLE | |
1323 | ||
1324 | ||
1325 | Imager::IO | |
1326 | io_new_fd(fd) | |
1327 | int fd | |
1328 | ||
1329 | Imager::IO | |
1330 | io_new_bufchain() | |
1331 | ||
1332 | ||
4dfa5522 | 1333 | Imager::IO |
6d5c85a2 TC |
1334 | io_new_buffer(data_sv) |
1335 | SV *data_sv | |
4dfa5522 | 1336 | CODE: |
a87997b2 | 1337 | i_clear_error(); |
6d5c85a2 | 1338 | RETVAL = do_io_new_buffer(aTHX_ data_sv); |
a87997b2 TC |
1339 | if (!RETVAL) |
1340 | XSRETURN(0); | |
4dfa5522 AMH |
1341 | OUTPUT: |
1342 | RETVAL | |
10461f9a TC |
1343 | |
1344 | Imager::IO | |
1345 | io_new_cb(writecb, readcb, seekcb, closecb, maxwrite = CBDATA_BUFSIZE) | |
1346 | SV *writecb; | |
1347 | SV *readcb; | |
1348 | SV *seekcb; | |
1349 | SV *closecb; | |
10461f9a | 1350 | CODE: |
6d5c85a2 | 1351 | RETVAL = do_io_new_cb(aTHX_ writecb, readcb, seekcb, closecb); |
10461f9a TC |
1352 | OUTPUT: |
1353 | RETVAL | |
4dfa5522 | 1354 | |
6d5c85a2 | 1355 | SV * |
02d1d628 AMH |
1356 | io_slurp(ig) |
1357 | Imager::IO ig | |
1358 | PREINIT: | |
1359 | unsigned char* data; | |
4dfa5522 | 1360 | size_t tlength; |
6d5c85a2 | 1361 | CODE: |
02d1d628 AMH |
1362 | data = NULL; |
1363 | tlength = io_slurp(ig, &data); | |
6d5c85a2 | 1364 | RETVAL = newSVpv((char *)data,tlength); |
02d1d628 | 1365 | myfree(data); |
6d5c85a2 TC |
1366 | OUTPUT: |
1367 | RETVAL | |
02d1d628 AMH |
1368 | |
1369 | ||
77157728 TC |
1370 | undef_int |
1371 | i_set_image_file_limits(width, height, bytes) | |
8d14daab TC |
1372 | i_img_dim width |
1373 | i_img_dim height | |
1374 | size_t bytes | |
77157728 TC |
1375 | |
1376 | void | |
1377 | i_get_image_file_limits() | |
1378 | PREINIT: | |
8d14daab TC |
1379 | i_img_dim width, height; |
1380 | size_t bytes; | |
77157728 TC |
1381 | PPCODE: |
1382 | if (i_get_image_file_limits(&width, &height, &bytes)) { | |
1383 | EXTEND(SP, 3); | |
1384 | PUSHs(sv_2mortal(newSViv(width))); | |
1385 | PUSHs(sv_2mortal(newSViv(height))); | |
8d14daab | 1386 | PUSHs(sv_2mortal(newSVuv(bytes))); |
77157728 TC |
1387 | } |
1388 | ||
e1558ffe TC |
1389 | bool |
1390 | i_int_check_image_file_limits(width, height, channels, sample_size) | |
1391 | i_img_dim width | |
1392 | i_img_dim height | |
1393 | int channels | |
1394 | size_t sample_size | |
1395 | PROTOTYPE: DISABLE | |
1396 | ||
6d5c85a2 TC |
1397 | MODULE = Imager PACKAGE = Imager::IO PREFIX = io_ |
1398 | ||
1399 | Imager::IO | |
1400 | io_new_fd(class, fd) | |
1401 | int fd | |
1402 | CODE: | |
1403 | RETVAL = io_new_fd(fd); | |
1404 | OUTPUT: | |
1405 | RETVAL | |
1406 | ||
1407 | Imager::IO | |
1408 | io_new_buffer(class, data_sv) | |
1409 | SV *data_sv | |
1410 | CODE: | |
a87997b2 | 1411 | i_clear_error(); |
6d5c85a2 | 1412 | RETVAL = do_io_new_buffer(aTHX_ data_sv); |
a87997b2 TC |
1413 | if (!RETVAL) |
1414 | XSRETURN(0); | |
6d5c85a2 TC |
1415 | OUTPUT: |
1416 | RETVAL | |
1417 | ||
1418 | Imager::IO | |
1419 | io_new_cb(class, writecb, readcb, seekcb, closecb) | |
1420 | SV *writecb; | |
1421 | SV *readcb; | |
1422 | SV *seekcb; | |
1423 | SV *closecb; | |
1424 | CODE: | |
1425 | RETVAL = do_io_new_cb(aTHX_ writecb, readcb, seekcb, closecb); | |
1426 | OUTPUT: | |
1427 | RETVAL | |
1428 | ||
1429 | Imager::IO | |
1430 | io_new_bufchain(class) | |
1431 | CODE: | |
1432 | RETVAL = io_new_bufchain(); | |
1433 | OUTPUT: | |
1434 | RETVAL | |
1435 | ||
52d990d6 TC |
1436 | Imager::IO |
1437 | io__new_perlio(class, io) | |
1438 | PerlIO *io | |
1439 | CODE: | |
1440 | RETVAL = im_io_new_perlio(aTHX_ io); | |
1441 | OUTPUT: | |
1442 | RETVAL | |
1443 | ||
6d5c85a2 TC |
1444 | SV * |
1445 | io_slurp(class, ig) | |
1446 | Imager::IO ig | |
1447 | PREINIT: | |
1448 | unsigned char* data; | |
1449 | size_t tlength; | |
1450 | CODE: | |
1451 | data = NULL; | |
1452 | tlength = io_slurp(ig, &data); | |
1453 | RETVAL = newSVpv((char *)data,tlength); | |
1454 | myfree(data); | |
1455 | OUTPUT: | |
1456 | RETVAL | |
1457 | ||
eda1622c TC |
1458 | MODULE = Imager PACKAGE = Imager::IO PREFIX = i_io_ |
1459 | ||
6d5c85a2 TC |
1460 | IV |
1461 | i_io_raw_write(ig, data_sv) | |
eda1622c TC |
1462 | Imager::IO ig |
1463 | SV *data_sv | |
1464 | PREINIT: | |
1465 | void *data; | |
1466 | STRLEN size; | |
1467 | CODE: | |
40a88898 | 1468 | data = SvPVbyte(data_sv, size); |
6d5c85a2 | 1469 | RETVAL = i_io_raw_write(ig, data, size); |
eda1622c TC |
1470 | OUTPUT: |
1471 | RETVAL | |
1472 | ||
1f6c1c10 | 1473 | void |
6d5c85a2 | 1474 | i_io_raw_read(ig, buffer_sv, size) |
eda1622c TC |
1475 | Imager::IO ig |
1476 | SV *buffer_sv | |
8d14daab | 1477 | IV size |
eda1622c TC |
1478 | PREINIT: |
1479 | void *buffer; | |
8d14daab | 1480 | ssize_t result; |
1f6c1c10 TC |
1481 | PPCODE: |
1482 | if (size <= 0) | |
6d5c85a2 | 1483 | croak("size negative in call to i_io_raw_read()"); |
d1442cc4 TC |
1484 | /* prevent an undefined value warning if they supplied an |
1485 | undef buffer. | |
1486 | Orginally conditional on !SvOK(), but this will prevent the | |
1487 | downgrade from croaking */ | |
1488 | sv_setpvn(buffer_sv, "", 0); | |
1489 | #ifdef SvUTF8 | |
1490 | if (SvUTF8(buffer_sv)) | |
1491 | sv_utf8_downgrade(buffer_sv, FALSE); | |
1492 | #endif | |
eda1622c | 1493 | buffer = SvGROW(buffer_sv, size+1); |
6d5c85a2 | 1494 | result = i_io_raw_read(ig, buffer, size); |
1f6c1c10 TC |
1495 | if (result >= 0) { |
1496 | SvCUR_set(buffer_sv, result); | |
1497 | *SvEND(buffer_sv) = '\0'; | |
1498 | SvPOK_only(buffer_sv); | |
1499 | EXTEND(SP, 1); | |
1500 | PUSHs(sv_2mortal(newSViv(result))); | |
eda1622c | 1501 | } |
1f6c1c10 TC |
1502 | ST(1) = buffer_sv; |
1503 | SvSETMAGIC(ST(1)); | |
1504 | ||
1505 | void | |
6d5c85a2 | 1506 | i_io_raw_read2(ig, size) |
1f6c1c10 | 1507 | Imager::IO ig |
8d14daab | 1508 | IV size |
1f6c1c10 TC |
1509 | PREINIT: |
1510 | SV *buffer_sv; | |
1511 | void *buffer; | |
8d14daab | 1512 | ssize_t result; |
1f6c1c10 TC |
1513 | PPCODE: |
1514 | if (size <= 0) | |
1515 | croak("size negative in call to i_io_read2()"); | |
1516 | buffer_sv = newSV(size); | |
1517 | buffer = SvGROW(buffer_sv, size+1); | |
6d5c85a2 | 1518 | result = i_io_raw_read(ig, buffer, size); |
1f6c1c10 | 1519 | if (result >= 0) { |
eda1622c TC |
1520 | SvCUR_set(buffer_sv, result); |
1521 | *SvEND(buffer_sv) = '\0'; | |
1522 | SvPOK_only(buffer_sv); | |
1f6c1c10 TC |
1523 | EXTEND(SP, 1); |
1524 | PUSHs(sv_2mortal(buffer_sv)); | |
eda1622c | 1525 | } |
1f6c1c10 TC |
1526 | else { |
1527 | /* discard it */ | |
1528 | SvREFCNT_dec(buffer_sv); | |
1529 | } | |
eda1622c | 1530 | |
8d14daab | 1531 | off_t |
6d5c85a2 | 1532 | i_io_raw_seek(ig, position, whence) |
eda1622c | 1533 | Imager::IO ig |
8d14daab | 1534 | off_t position |
eda1622c | 1535 | int whence |
c3cc977e | 1536 | |
1f6c1c10 | 1537 | int |
6d5c85a2 | 1538 | i_io_raw_close(ig) |
eda1622c TC |
1539 | Imager::IO ig |
1540 | ||
1541 | void | |
1542 | i_io_DESTROY(ig) | |
c3cc977e AMH |
1543 | Imager::IO ig |
1544 | ||
ffddd407 TC |
1545 | int |
1546 | i_io_CLONE_SKIP(...) | |
1547 | CODE: | |
8d14daab | 1548 | (void)items; /* avoid unused warning for XS variable */ |
ffddd407 TC |
1549 | RETVAL = 1; |
1550 | OUTPUT: | |
1551 | RETVAL | |
1552 | ||
6d5c85a2 TC |
1553 | int |
1554 | i_io_getc(ig) | |
1555 | Imager::IO ig | |
1556 | ||
215d9ead TC |
1557 | void |
1558 | i_io_nextc(ig) | |
1559 | Imager::IO ig | |
1560 | ||
6d5c85a2 TC |
1561 | int |
1562 | i_io_putc(ig, c) | |
1563 | Imager::IO ig | |
1564 | int c | |
1565 | ||
1566 | int | |
1567 | i_io_close(ig) | |
1568 | Imager::IO ig | |
1569 | ||
1570 | int | |
1571 | i_io_flush(ig) | |
1572 | Imager::IO ig | |
1573 | ||
1574 | int | |
1575 | i_io_peekc(ig) | |
1576 | Imager::IO ig | |
1577 | ||
1578 | int | |
1579 | i_io_seek(ig, off, whence) | |
1580 | Imager::IO ig | |
1581 | off_t off | |
1582 | int whence | |
1583 | ||
1584 | void | |
1585 | i_io_peekn(ig, size) | |
1586 | Imager::IO ig | |
1587 | STRLEN size | |
1588 | PREINIT: | |
1589 | SV *buffer_sv; | |
1590 | void *buffer; | |
1591 | ssize_t result; | |
1592 | PPCODE: | |
1593 | buffer_sv = newSV(size+1); | |
1594 | buffer = SvGROW(buffer_sv, size+1); | |
1595 | result = i_io_peekn(ig, buffer, size); | |
1596 | if (result >= 0) { | |
1597 | SvCUR_set(buffer_sv, result); | |
1598 | *SvEND(buffer_sv) = '\0'; | |
1599 | SvPOK_only(buffer_sv); | |
1600 | EXTEND(SP, 1); | |
1601 | PUSHs(sv_2mortal(buffer_sv)); | |
1602 | } | |
1603 | else { | |
1604 | /* discard it */ | |
1605 | SvREFCNT_dec(buffer_sv); | |
1606 | } | |
1607 | ||
1608 | void | |
1609 | i_io_read(ig, buffer_sv, size) | |
1610 | Imager::IO ig | |
1611 | SV *buffer_sv | |
1612 | IV size | |
1613 | PREINIT: | |
1614 | void *buffer; | |
1615 | ssize_t result; | |
1616 | PPCODE: | |
1617 | if (size <= 0) | |
1618 | croak("size negative in call to i_io_read()"); | |
d1442cc4 TC |
1619 | /* prevent an undefined value warning if they supplied an |
1620 | undef buffer. | |
1621 | Orginally conditional on !SvOK(), but this will prevent the | |
1622 | downgrade from croaking */ | |
1623 | sv_setpvn(buffer_sv, "", 0); | |
1624 | #ifdef SvUTF8 | |
1625 | if (SvUTF8(buffer_sv)) | |
1626 | sv_utf8_downgrade(buffer_sv, FALSE); | |
1627 | #endif | |
6d5c85a2 TC |
1628 | buffer = SvGROW(buffer_sv, size+1); |
1629 | result = i_io_read(ig, buffer, size); | |
1630 | if (result >= 0) { | |
1631 | SvCUR_set(buffer_sv, result); | |
1632 | *SvEND(buffer_sv) = '\0'; | |
1633 | SvPOK_only(buffer_sv); | |
1634 | EXTEND(SP, 1); | |
1635 | PUSHs(sv_2mortal(newSViv(result))); | |
1636 | } | |
1637 | ST(1) = buffer_sv; | |
1638 | SvSETMAGIC(ST(1)); | |
1639 | ||
1640 | void | |
1641 | i_io_read2(ig, size) | |
1642 | Imager::IO ig | |
1643 | STRLEN size | |
1644 | PREINIT: | |
1645 | SV *buffer_sv; | |
1646 | void *buffer; | |
1647 | ssize_t result; | |
1648 | PPCODE: | |
1649 | if (size == 0) | |
1650 | croak("size zero in call to read2()"); | |
1651 | buffer_sv = newSV(size); | |
1652 | buffer = SvGROW(buffer_sv, size+1); | |
1653 | result = i_io_read(ig, buffer, size); | |
1654 | if (result > 0) { | |
1655 | SvCUR_set(buffer_sv, result); | |
1656 | *SvEND(buffer_sv) = '\0'; | |
1657 | SvPOK_only(buffer_sv); | |
1658 | EXTEND(SP, 1); | |
1659 | PUSHs(sv_2mortal(buffer_sv)); | |
1660 | } | |
1661 | else { | |
1662 | /* discard it */ | |
1663 | SvREFCNT_dec(buffer_sv); | |
1664 | } | |
1665 | ||
1666 | void | |
1667 | i_io_gets(ig, size = 8192, eol = NEWLINE) | |
1668 | Imager::IO ig | |
1669 | STRLEN size | |
1670 | int eol | |
1671 | PREINIT: | |
1672 | SV *buffer_sv; | |
1673 | void *buffer; | |
1674 | ssize_t result; | |
1675 | PPCODE: | |
1676 | if (size < 2) | |
1677 | croak("size too small in call to gets()"); | |
1678 | buffer_sv = sv_2mortal(newSV(size+1)); | |
1679 | buffer = SvPVX(buffer_sv); | |
1680 | result = i_io_gets(ig, buffer, size+1, eol); | |
1681 | if (result > 0) { | |
1682 | SvCUR_set(buffer_sv, result); | |
1683 | *SvEND(buffer_sv) = '\0'; | |
1684 | SvPOK_only(buffer_sv); | |
1685 | EXTEND(SP, 1); | |
1686 | PUSHs(buffer_sv); | |
1687 | } | |
1688 | ||
1689 | IV | |
1690 | i_io_write(ig, data_sv) | |
1691 | Imager::IO ig | |
1692 | SV *data_sv | |
1693 | PREINIT: | |
1694 | void *data; | |
1695 | STRLEN size; | |
1696 | CODE: | |
40a88898 | 1697 | data = SvPVbyte(data_sv, size); |
6d5c85a2 TC |
1698 | RETVAL = i_io_write(ig, data, size); |
1699 | OUTPUT: | |
1700 | RETVAL | |
1701 | ||
1702 | void | |
1703 | i_io_dump(ig, flags = I_IO_DUMP_DEFAULT) | |
1704 | Imager::IO ig | |
1705 | int flags | |
1706 | ||
1707 | bool | |
1708 | i_io_set_buffered(ig, flag = 1) | |
1709 | Imager::IO ig | |
1710 | int flag | |
1711 | ||
1712 | bool | |
1713 | i_io_is_buffered(ig) | |
1714 | Imager::IO ig | |
1715 | ||
1716 | bool | |
1717 | i_io_eof(ig) | |
1718 | Imager::IO ig | |
1719 | ||
1720 | bool | |
1721 | i_io_error(ig) | |
1722 | Imager::IO ig | |
1723 | ||
c3cc977e AMH |
1724 | MODULE = Imager PACKAGE = Imager |
1725 | ||
1726 | PROTOTYPES: ENABLE | |
1727 | ||
02d1d628 AMH |
1728 | void |
1729 | i_list_formats() | |
1730 | PREINIT: | |
1731 | char* item; | |
1732 | int i; | |
1733 | PPCODE: | |
1734 | i=0; | |
1735 | while( (item=i_format_list[i++]) != NULL ) { | |
1736 | EXTEND(SP, 1); | |
1737 | PUSHs(sv_2mortal(newSVpv(item,0))); | |
1738 | } | |
1739 | ||
ec76939c TC |
1740 | Imager::ImgRaw |
1741 | i_sametype(im, x, y) | |
1742 | Imager::ImgRaw im | |
8d14daab TC |
1743 | i_img_dim x |
1744 | i_img_dim y | |
ec76939c TC |
1745 | |
1746 | Imager::ImgRaw | |
1747 | i_sametype_chans(im, x, y, channels) | |
1748 | Imager::ImgRaw im | |
8d14daab TC |
1749 | i_img_dim x |
1750 | i_img_dim y | |
ec76939c TC |
1751 | int channels |
1752 | ||
10ea52a3 | 1753 | int |
bd8052a6 TC |
1754 | i_init_log(name_sv,level) |
1755 | SV* name_sv | |
02d1d628 | 1756 | int level |
bd8052a6 TC |
1757 | PREINIT: |
1758 | const char *name = SvOK(name_sv) ? SvPV_nolen(name_sv) : NULL; | |
1759 | CODE: | |
10ea52a3 TC |
1760 | RETVAL = i_init_log(name, level); |
1761 | OUTPUT: | |
1762 | RETVAL | |
02d1d628 | 1763 | |
7f882a01 | 1764 | void |
bf1573f9 | 1765 | i_log_entry(string,level) |
7f882a01 AMH |
1766 | char* string |
1767 | int level | |
1768 | ||
10ea52a3 TC |
1769 | int |
1770 | i_log_enabled() | |
7f882a01 | 1771 | |
02d1d628 AMH |
1772 | void |
1773 | i_img_info(im) | |
1774 | Imager::ImgRaw im | |
1775 | PREINIT: | |
8d14daab | 1776 | i_img_dim info[4]; |
02d1d628 AMH |
1777 | PPCODE: |
1778 | i_img_info(im,info); | |
1779 | EXTEND(SP, 4); | |
1780 | PUSHs(sv_2mortal(newSViv(info[0]))); | |
1781 | PUSHs(sv_2mortal(newSViv(info[1]))); | |
1782 | PUSHs(sv_2mortal(newSViv(info[2]))); | |
1783 | PUSHs(sv_2mortal(newSViv(info[3]))); | |
1784 | ||
1785 | ||
1786 | ||
1787 | ||
1788 | void | |
1789 | i_img_setmask(im,ch_mask) | |
1790 | Imager::ImgRaw im | |
1791 | int ch_mask | |
1792 | ||
1793 | int | |
1794 | i_img_getmask(im) | |
1795 | Imager::ImgRaw im | |
1796 | ||
1797 | int | |
1798 | i_img_getchannels(im) | |
1799 | Imager::ImgRaw im | |
1800 | ||
1801 | void | |
1802 | i_img_getdata(im) | |
1803 | Imager::ImgRaw im | |
1804 | PPCODE: | |
1805 | EXTEND(SP, 1); | |
26fd367b TC |
1806 | PUSHs(im->idata ? |
1807 | sv_2mortal(newSVpv((char *)im->idata, im->bytes)) | |
faa9b3e7 | 1808 | : &PL_sv_undef); |
02d1d628 | 1809 | |
3b000586 TC |
1810 | IV |
1811 | i_img_get_width(im) | |
1812 | Imager::ImgRaw im | |
1813 | ||
1814 | IV | |
1815 | i_img_get_height(im) | |
1816 | Imager::ImgRaw im | |
1817 | ||
35db02fc TC |
1818 | int |
1819 | i_img_color_model(im) | |
1820 | Imager::ImgRaw im | |
1821 | ||
1822 | int | |
1823 | i_img_color_channels(im) | |
1824 | Imager::ImgRaw im | |
1825 | ||
1826 | int | |
1827 | i_img_alpha_channel(im) | |
1828 | Imager::ImgRaw im | |
1829 | CODE: | |
1830 | if (!i_img_alpha_channel(im, &RETVAL)) | |
1831 | XSRETURN(0); | |
1832 | OUTPUT: | |
1833 | RETVAL | |
3b000586 | 1834 | |
bd8052a6 TC |
1835 | void |
1836 | i_img_is_monochrome(im) | |
1837 | Imager::ImgRaw im | |
1838 | PREINIT: | |
1839 | int zero_is_white; | |
1840 | int result; | |
1841 | PPCODE: | |
1842 | result = i_img_is_monochrome(im, &zero_is_white); | |
1843 | if (result) { | |
1844 | if (GIMME_V == G_ARRAY) { | |
1845 | EXTEND(SP, 2); | |
1846 | PUSHs(&PL_sv_yes); | |
1847 | PUSHs(sv_2mortal(newSViv(zero_is_white))); | |
1848 | } | |
1849 | else { | |
1850 | EXTEND(SP, 1); | |
1851 | PUSHs(&PL_sv_yes); | |
1852 | } | |
1853 | } | |
02d1d628 AMH |
1854 | |
1855 | void | |
aa833c97 | 1856 | i_line(im,x1,y1,x2,y2,val,endp) |
02d1d628 | 1857 | Imager::ImgRaw im |
8d14daab TC |
1858 | i_img_dim x1 |
1859 | i_img_dim y1 | |
1860 | i_img_dim x2 | |
1861 | i_img_dim y2 | |
02d1d628 | 1862 | Imager::Color val |
aa833c97 | 1863 | int endp |
02d1d628 AMH |
1864 | |
1865 | void | |
b437ce0a | 1866 | i_line_aa(im,x1,y1,x2,y2,val,endp) |
02d1d628 | 1867 | Imager::ImgRaw im |
8d14daab TC |
1868 | i_img_dim x1 |
1869 | i_img_dim y1 | |
1870 | i_img_dim x2 | |
1871 | i_img_dim y2 | |
02d1d628 | 1872 | Imager::Color val |
b437ce0a | 1873 | int endp |
02d1d628 AMH |
1874 | |
1875 | void | |
1876 | i_box(im,x1,y1,x2,y2,val) | |
1877 | Imager::ImgRaw im | |
8d14daab TC |
1878 | i_img_dim x1 |
1879 | i_img_dim y1 | |
1880 | i_img_dim x2 | |
1881 | i_img_dim y2 | |
02d1d628 AMH |
1882 | Imager::Color val |
1883 | ||
1884 | void | |
1885 | i_box_filled(im,x1,y1,x2,y2,val) | |
1886 | Imager::ImgRaw im | |
8d14daab TC |
1887 | i_img_dim x1 |
1888 | i_img_dim y1 | |
1889 | i_img_dim x2 | |
1890 | i_img_dim y2 | |
02d1d628 AMH |
1891 | Imager::Color val |
1892 | ||
7477ff14 TC |
1893 | int |
1894 | i_box_filledf(im,x1,y1,x2,y2,val) | |
1895 | Imager::ImgRaw im | |
8d14daab TC |
1896 | i_img_dim x1 |
1897 | i_img_dim y1 | |
1898 | i_img_dim x2 | |
1899 | i_img_dim y2 | |
7477ff14 TC |
1900 | Imager::Color::Float val |
1901 | ||
f1ac5027 TC |
1902 | void |
1903 | i_box_cfill(im,x1,y1,x2,y2,fill) | |
1904 | Imager::ImgRaw im | |
8d14daab TC |
1905 | i_img_dim x1 |
1906 | i_img_dim y1 | |
1907 | i_img_dim x2 | |
1908 | i_img_dim y2 | |
f1ac5027 TC |
1909 | Imager::FillHandle fill |
1910 | ||
02d1d628 AMH |
1911 | void |
1912 | i_arc(im,x,y,rad,d1,d2,val) | |
1913 | Imager::ImgRaw im | |
8d14daab TC |
1914 | i_img_dim x |
1915 | i_img_dim y | |
5824f4c2 TC |
1916 | im_double rad |
1917 | im_double d1 | |
1918 | im_double d2 | |
02d1d628 AMH |
1919 | Imager::Color val |
1920 | ||
a8652edf TC |
1921 | void |
1922 | i_arc_aa(im,x,y,rad,d1,d2,val) | |
1923 | Imager::ImgRaw im | |
5824f4c2 TC |
1924 | im_double x |
1925 | im_double y | |
1926 | im_double rad | |
1927 | im_double d1 | |
1928 | im_double d2 | |
a8652edf TC |
1929 | Imager::Color val |
1930 | ||
f1ac5027 TC |
1931 | void |
1932 | i_arc_cfill(im,x,y,rad,d1,d2,fill) | |
1933 | Imager::ImgRaw im | |
8d14daab TC |
1934 | i_img_dim x |
1935 | i_img_dim y | |
5824f4c2 TC |
1936 | im_double rad |
1937 | im_double d1 | |
1938 | im_double d2 | |
f1ac5027 TC |
1939 | Imager::FillHandle fill |
1940 | ||
a8652edf TC |
1941 | void |
1942 | i_arc_aa_cfill(im,x,y,rad,d1,d2,fill) | |
1943 | Imager::ImgRaw im | |
5824f4c2 TC |
1944 | im_double x |
1945 | im_double y | |
1946 | im_double rad | |
1947 | im_double d1 | |
1948 | im_double d2 | |
a8652edf | 1949 | Imager::FillHandle fill |
02d1d628 AMH |
1950 | |
1951 | ||
6af18d2b AMH |
1952 | void |
1953 | i_circle_aa(im,x,y,rad,val) | |
1954 | Imager::ImgRaw im | |
5824f4c2 TC |
1955 | im_double x |
1956 | im_double y | |
1957 | im_double rad | |
6af18d2b AMH |
1958 | Imager::Color val |
1959 | ||
bf18ef3a TC |
1960 | void |
1961 | i_circle_aa_fill(im,x,y,rad,fill) | |
1962 | Imager::ImgRaw im | |
5824f4c2 TC |
1963 | im_double x |
1964 | im_double y | |
1965 | im_double rad | |
bf18ef3a TC |
1966 | Imager::FillHandle fill |
1967 | ||
40068b33 TC |
1968 | int |
1969 | i_circle_out(im,x,y,rad,val) | |
1970 | Imager::ImgRaw im | |
1971 | i_img_dim x | |
1972 | i_img_dim y | |
1973 | i_img_dim rad | |
1974 | Imager::Color val | |
1975 | ||
1976 | int | |
1977 | i_circle_out_aa(im,x,y,rad,val) | |
1978 | Imager::ImgRaw im | |
1979 | i_img_dim x | |
1980 | i_img_dim y | |
1981 | i_img_dim rad | |
1982 | Imager::Color val | |
1983 | ||
1984 | int | |
1985 | i_arc_out(im,x,y,rad,d1,d2,val) | |
1986 | Imager::ImgRaw im | |
1987 | i_img_dim x | |
1988 | i_img_dim y | |
1989 | i_img_dim rad | |
5824f4c2 TC |
1990 | im_double d1 |
1991 | im_double d2 | |
40068b33 TC |
1992 | Imager::Color val |
1993 | ||
1994 | int | |
1995 | i_arc_out_aa(im,x,y,rad,d1,d2,val) | |
1996 | Imager::ImgRaw im | |
1997 | i_img_dim x | |
1998 | i_img_dim y | |
1999 | i_img_dim rad | |
5824f4c2 TC |
2000 | im_double d1 |
2001 | im_double d2 | |
40068b33 | 2002 | Imager::Color val |
6af18d2b AMH |
2003 | |
2004 | ||
02d1d628 | 2005 | void |
987245e2 | 2006 | i_bezier_multi(im,x,y,val) |
02d1d628 | 2007 | Imager::ImgRaw im |
987245e2 TC |
2008 | double *x |
2009 | double *y | |
2010 | Imager::Color val | |
2011 | PREINIT: | |
2012 | STRLEN size_x; | |
2013 | STRLEN size_y; | |
2014 | PPCODE: | |
2015 | if (size_x != size_y) | |
2016 | croak("Imager: x and y arrays to i_bezier_multi must be equal length\n"); | |
2017 | i_bezier_multi(im,size_x,x,y,val); | |
02d1d628 | 2018 | |
1c5252ed | 2019 | int |
0d80f37e | 2020 | i_poly_aa_m(im,x,y,mode,val) |
02d1d628 | 2021 | Imager::ImgRaw im |
19e9591b TC |
2022 | double *x |
2023 | double *y | |
0d80f37e | 2024 | i_poly_fill_mode_t mode |
a54e32ba TC |
2025 | Imager::Color val |
2026 | PREINIT: | |
19e9591b TC |
2027 | STRLEN size_x; |
2028 | STRLEN size_y; | |
a54e32ba | 2029 | CODE: |
19e9591b | 2030 | if (size_x != size_y) |
a54e32ba | 2031 | croak("Imager: x and y arrays to i_poly_aa must be equal length\n"); |
0d80f37e | 2032 | RETVAL = i_poly_aa_m(im, size_x, x, y, mode, val); |
a54e32ba TC |
2033 | OUTPUT: |
2034 | RETVAL | |
02d1d628 | 2035 | |
1c5252ed | 2036 | int |
0d80f37e | 2037 | i_poly_aa_cfill_m(im, x, y, mode, fill) |
43c5dacb | 2038 | Imager::ImgRaw im |
19e9591b TC |
2039 | double *x |
2040 | double *y | |
0d80f37e | 2041 | i_poly_fill_mode_t mode |
a54e32ba TC |
2042 | Imager::FillHandle fill |
2043 | PREINIT: | |
19e9591b TC |
2044 | STRLEN size_x; |
2045 | STRLEN size_y; | |
a54e32ba | 2046 | CODE: |
19e9591b | 2047 | if (size_x != size_y) |
a54e32ba | 2048 | croak("Imager: x and y arrays to i_poly_aa_cfill must be equal length\n"); |
0d80f37e | 2049 | RETVAL = i_poly_aa_cfill_m(im, size_x, x, y, mode, fill); |
a54e32ba TC |
2050 | OUTPUT: |
2051 | RETVAL | |
02d1d628 | 2052 | |
0d80f37e TC |
2053 | int |
2054 | i_poly_poly_aa(im, polys, mode, color) | |
2055 | Imager::ImgRaw im | |
2056 | i_polygon_list polys | |
2057 | i_poly_fill_mode_t mode | |
2058 | Imager::Color color | |
2059 | CODE: | |
2060 | RETVAL = i_poly_poly_aa(im, polys.count, polys.polygons, mode, color); | |
2061 | OUTPUT: | |
2062 | RETVAL | |
2063 | ||
2064 | int | |
2065 | i_poly_poly_aa_cfill(im, polys, mode, fill) | |
2066 | Imager::ImgRaw im | |
2067 | i_polygon_list polys | |
2068 | i_poly_fill_mode_t mode | |
2069 | Imager::FillHandle fill | |
2070 | CODE: | |
2071 | RETVAL = i_poly_poly_aa_cfill(im, polys.count, polys.polygons, mode, fill); | |
2072 | OUTPUT: | |
2073 | RETVAL | |
2074 | ||
a321d497 | 2075 | undef_int |
02d1d628 AMH |
2076 | i_flood_fill(im,seedx,seedy,dcol) |
2077 | Imager::ImgRaw im | |
8d14daab TC |
2078 | i_img_dim seedx |
2079 | i_img_dim seedy | |
02d1d628 AMH |
2080 | Imager::Color dcol |
2081 | ||
a321d497 | 2082 | undef_int |
cc6483e0 TC |
2083 | i_flood_cfill(im,seedx,seedy,fill) |
2084 | Imager::ImgRaw im | |
8d14daab TC |
2085 | i_img_dim seedx |
2086 | i_img_dim seedy | |
cc6483e0 TC |
2087 | Imager::FillHandle fill |
2088 | ||
3efb0915 TC |
2089 | undef_int |
2090 | i_flood_fill_border(im,seedx,seedy,dcol, border) | |
2091 | Imager::ImgRaw im | |
8d14daab TC |
2092 | i_img_dim seedx |
2093 | i_img_dim seedy | |
3efb0915 TC |
2094 | Imager::Color dcol |
2095 | Imager::Color border | |
2096 | ||
2097 | undef_int | |
2098 | i_flood_cfill_border(im,seedx,seedy,fill, border) | |
2099 | Imager::ImgRaw im | |
8d14daab TC |
2100 | i_img_dim seedx |
2101 | i_img_dim seedy | |
3efb0915 TC |
2102 | Imager::FillHandle fill |
2103 | Imager::Color border | |
2104 | ||
02d1d628 AMH |
2105 | |
2106 | void | |
2107 | i_copyto(im,src,x1,y1,x2,y2,tx,ty) | |
2108 | Imager::ImgRaw im | |
2109 | Imager::ImgRaw src | |
8d14daab TC |
2110 | i_img_dim x1 |
2111 | i_img_dim y1 | |
2112 | i_img_dim x2 | |
2113 | i_img_dim y2 | |
2114 | i_img_dim tx | |
2115 | i_img_dim ty | |
02d1d628 AMH |
2116 | |
2117 | ||
2118 | void | |
2119 | i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans) | |
2120 | Imager::ImgRaw im | |
2121 | Imager::ImgRaw src | |
8d14daab TC |
2122 | i_img_dim x1 |
2123 | i_img_dim y1 | |
2124 | i_img_dim x2 | |
2125 | i_img_dim y2 | |
2126 | i_img_dim tx | |
2127 | i_img_dim ty | |
02d1d628 AMH |
2128 | Imager::Color trans |
2129 | ||
92bda632 TC |
2130 | Imager::ImgRaw |
2131 | i_copy(src) | |
02d1d628 AMH |
2132 | Imager::ImgRaw src |
2133 | ||
2134 | ||
faa9b3e7 | 2135 | undef_int |
71dc4a83 | 2136 | i_rubthru(im,src,tx,ty,src_minx,src_miny,src_maxx,src_maxy) |
02d1d628 AMH |
2137 | Imager::ImgRaw im |
2138 | Imager::ImgRaw src | |
8d14daab TC |
2139 | i_img_dim tx |
2140 | i_img_dim ty | |
2141 | i_img_dim src_minx | |
2142 | i_img_dim src_miny | |
2143 | i_img_dim src_maxx | |
2144 | i_img_dim src_maxy | |
71dc4a83 | 2145 | |
9b1ec2b8 TC |
2146 | undef_int |
2147 | i_compose(out, src, out_left, out_top, src_left, src_top, width, height, combine = ic_normal, opacity = 0.0) | |
2148 | Imager::ImgRaw out | |
2149 | Imager::ImgRaw src | |
8d14daab TC |
2150 | i_img_dim out_left |
2151 | i_img_dim out_top | |
2152 | i_img_dim src_left | |
2153 | i_img_dim src_top | |
2154 | i_img_dim width | |
2155 | i_img_dim height | |
9b1ec2b8 | 2156 | int combine |
5824f4c2 | 2157 | im_double opacity |
9b1ec2b8 TC |
2158 | |
2159 | undef_int | |
2160 | i_compose_mask(out, src, mask, out_left, out_top, src_left, src_top, mask_left, mask_top, width, height, combine = ic_normal, opacity = 0.0) | |
2161 | Imager::ImgRaw out | |
2162 | Imager::ImgRaw src | |
2163 | Imager::ImgRaw mask | |
8d14daab TC |
2164 | i_img_dim out_left |
2165 | i_img_dim out_top | |
2166 | i_img_dim src_left | |
2167 | i_img_dim src_top | |
2168 | i_img_dim mask_left | |
2169 | i_img_dim mask_top | |
2170 | i_img_dim width | |
2171 | i_img_dim height | |
9b1ec2b8 | 2172 | int combine |
5824f4c2 | 2173 | im_double opacity |
02d1d628 | 2174 | |
b47464c1 TC |
2175 | Imager::ImgRaw |
2176 | i_combine(src_av, channels_av = NULL) | |
2177 | AV *src_av | |
2178 | AV *channels_av | |
2179 | PREINIT: | |
2180 | i_img **imgs = NULL; | |
2181 | STRLEN in_count; | |
2182 | int *channels = NULL; | |
2183 | int i; | |
2184 | SV **psv; | |
2185 | IV tmp; | |
2186 | CODE: | |
2187 | in_count = av_len(src_av) + 1; | |
2188 | if (in_count > 0) { | |
2189 | imgs = mymalloc(sizeof(i_img*) * in_count); | |
2190 | channels = mymalloc(sizeof(int) * in_count); | |
2191 | for (i = 0; i < in_count; ++i) { | |
2192 | psv = av_fetch(src_av, i, 0); | |
2193 | if (!psv || !*psv || !sv_derived_from(*psv, "Imager::ImgRaw")) { | |
2194 | myfree(imgs); | |
2195 | myfree(channels); | |
2196 | croak("imgs must contain only images"); | |
2197 | } | |
2198 | tmp = SvIV((SV*)SvRV(*psv)); | |
2199 | imgs[i] = INT2PTR(i_img*, tmp); | |
2200 | if (channels_av && | |
2201 | (psv = av_fetch(channels_av, i, 0)) != NULL && | |
2202 | *psv) { | |
2203 | channels[i] = SvIV(*psv); | |
2204 | } | |
2205 | else { | |
2206 | channels[i] = 0; | |
2207 | } | |
2208 | } | |
2209 | } | |
2210 | RETVAL = i_combine(imgs, channels, in_count); | |
2211 | myfree(imgs); | |
2212 | myfree(channels); | |
2213 | OUTPUT: | |
2214 | RETVAL | |
2215 | ||
142c26ff AMH |
2216 | undef_int |
2217 | i_flipxy(im, direction) | |
2218 | Imager::ImgRaw im | |
2219 | int direction | |
2220 | ||
faa9b3e7 TC |
2221 | Imager::ImgRaw |
2222 | i_rotate90(im, degrees) | |
2223 | Imager::ImgRaw im | |
2224 | int degrees | |
2225 | ||
2226 | Imager::ImgRaw | |
0d3b936e | 2227 | i_rotate_exact(im, amount, ...) |
faa9b3e7 | 2228 | Imager::ImgRaw im |
5824f4c2 | 2229 | im_double amount |
0d3b936e TC |
2230 | PREINIT: |
2231 | i_color *backp = NULL; | |
2232 | i_fcolor *fbackp = NULL; | |
2233 | int i; | |
2234 | SV * sv1; | |
2235 | CODE: | |
2236 | /* extract the bg colors if any */ | |
2237 | /* yes, this is kind of strange */ | |
2238 | for (i = 2; i < items; ++i) { | |
2239 | sv1 = ST(i); | |
2240 | if (sv_derived_from(sv1, "Imager::Color")) { | |
2241 | IV tmp = SvIV((SV*)SvRV(sv1)); | |
2242 | backp = INT2PTR(i_color *, tmp); | |
2243 | } | |
2244 | else if (sv_derived_from(sv1, "Imager::Color::Float")) { | |
2245 | IV tmp = SvIV((SV*)SvRV(sv1)); | |
2246 | fbackp = INT2PTR(i_fcolor *, tmp); | |
2247 | } | |
2248 | } | |
2249 | RETVAL = i_rotate_exact_bg(im, amount, backp, fbackp); | |
2250 | OUTPUT: | |
2251 | RETVAL | |
faa9b3e7 TC |
2252 | |
2253 | Imager::ImgRaw | |
87b3f212 | 2254 | i_matrix_transform(im, xsize, ysize, matrix_av, ...) |
faa9b3e7 | 2255 | Imager::ImgRaw im |
487ec752 TC |
2256 | i_img_dim xsize |
2257 | i_img_dim ysize | |
87b3f212 | 2258 | AV *matrix_av |
487ec752 TC |
2259 | PREINIT: |
2260 | double matrix[9]; | |
2261 | STRLEN len; | |
2262 | SV *sv1; | |
2263 | int i; | |
2264 | i_color *backp = NULL; | |
2265 | i_fcolor *fbackp = NULL; | |
2266 | CODE: | |
2267 | len=av_len(matrix_av)+1; | |
2268 | if (len > 9) | |
2269 | len = 9; | |
2270 | for (i = 0; i < len; ++i) { | |
2271 | sv1=(*(av_fetch(matrix_av,i,0))); | |
2272 | matrix[i] = SvNV(sv1); | |
2273 | } | |
2274 | for (; i < 9; ++i) | |
2275 | matrix[i] = 0; | |
2276 | /* extract the bg colors if any */ | |
2277 | /* yes, this is kind of strange */ | |
2278 | for (i = 4; i < items; ++i) { | |
2279 | sv1 = ST(i); | |
2280 | if (sv_derived_from(sv1, "Imager::Color")) { | |
2281 | IV tmp = SvIV((SV*)SvRV(sv1)); | |
2282 | backp = INT2PTR(i_color *, tmp); | |
2283 | } | |
2284 | else if (sv_derived_from(sv1, "Imager::Color::Float")) { | |
2285 | IV tmp = SvIV((SV*)SvRV(sv1)); | |
2286 | fbackp = INT2PTR(i_fcolor *, tmp); | |
2287 | } | |
2288 | } | |
2289 | RETVAL = i_matrix_transform_bg(im, xsize, ysize, matrix, backp, fbackp); | |
2290 | OUTPUT: | |
2291 | RETVAL | |
02d1d628 | 2292 | |
167660cd | 2293 | undef_int |
3d3b6bed | 2294 | i_gaussian(im,stddev) |
02d1d628 | 2295 | Imager::ImgRaw im |
3d3b6bed TC |
2296 | im_double stddev |
2297 | ||
2298 | undef_int | |
2299 | i_gaussian2(im,stddevX,stddevY) | |
2300 | Imager::ImgRaw im | |
2301 | im_double stddevX | |
2302 | im_double stddevY | |
02d1d628 | 2303 | |
b6381851 TC |
2304 | void |
2305 | i_unsharp_mask(im,stdev,scale) | |
2306 | Imager::ImgRaw im | |
5824f4c2 TC |
2307 | im_double stdev |
2308 | im_double scale | |
b6381851 | 2309 | |
6a3cbaef TC |
2310 | int |
2311 | i_conv(im,coef) | |
2312 | Imager::ImgRaw im | |
2313 | AV *coef | |
2314 | PREINIT: | |
2315 | double* c_coef; | |
2316 | int len; | |
2317 | SV* sv1; | |
2318 | int i; | |
2319 | CODE: | |
2320 | len = av_len(coef) + 1; | |
2321 | c_coef=mymalloc( len * sizeof(double) ); | |
2322 | for(i = 0; i < len; i++) { | |
2323 | sv1 = (*(av_fetch(coef, i, 0))); | |
2324 | c_coef[i] = (double)SvNV(sv1); | |
2325 | } | |
2326 | RETVAL = i_conv(im, c_coef, len); | |
2327 | myfree(c_coef); | |
2328 | OUTPUT: | |
2329 | RETVAL | |
02d1d628 | 2330 | |
d5477d3d TC |
2331 | Imager::ImgRaw |
2332 | i_convert(src, avmain) | |
f5991c03 | 2333 | Imager::ImgRaw src |
d5477d3d | 2334 | AV *avmain |
f5991c03 | 2335 | PREINIT: |
62869327 | 2336 | double *coeff; |
f5991c03 TC |
2337 | int outchan; |
2338 | int inchan; | |
f5991c03 | 2339 | SV **temp; |
f5991c03 TC |
2340 | AV *avsub; |
2341 | int len; | |
2342 | int i, j; | |
2343 | CODE: | |
f5991c03 TC |
2344 | outchan = av_len(avmain)+1; |
2345 | /* find the biggest */ | |
2346 | inchan = 0; | |
2347 | for (j=0; j < outchan; ++j) { | |
2348 | temp = av_fetch(avmain, j, 0); | |
2349 | if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) { | |
2350 | avsub = (AV*)SvRV(*temp); | |
2351 | len = av_len(avsub)+1; | |
2352 | if (len > inchan) | |
2353 | inchan = len; | |
2354 | } | |
26eb06dd TC |
2355 | else { |
2356 | i_push_errorf(0, "invalid matrix: element %d is not an array ref", j); | |
2357 | XSRETURN(0); | |
2358 | } | |
f5991c03 | 2359 | } |
62869327 | 2360 | coeff = mymalloc(sizeof(double) * outchan * inchan); |
f5991c03 TC |
2361 | for (j = 0; j < outchan; ++j) { |
2362 | avsub = (AV*)SvRV(*av_fetch(avmain, j, 0)); | |
2363 | len = av_len(avsub)+1; | |
2364 | for (i = 0; i < len; ++i) { | |
2365 | temp = av_fetch(avsub, i, 0); | |
2366 | if (temp) | |
2367 | coeff[i+j*inchan] = SvNV(*temp); | |
2368 | else | |
2369 | coeff[i+j*inchan] = 0; | |
2370 | } | |
2371 | while (i < inchan) | |
2372 | coeff[i++ + j*inchan] = 0; | |
2373 | } | |
d5477d3d | 2374 | RETVAL = i_convert(src, coeff, outchan, inchan); |
f5991c03 | 2375 | myfree(coeff); |
f5991c03 TC |
2376 | OUTPUT: |
2377 | RETVAL | |
40eba1ea AMH |
2378 | |
2379 | ||
1136f089 | 2380 | undef_int |
85f38e13 | 2381 | i_map(im, pmaps_av) |
40eba1ea | 2382 | Imager::ImgRaw im |
85f38e13 | 2383 | AV *pmaps_av |
64655904 TC |
2384 | PREINIT: |
2385 | unsigned int mask = 0; | |
64655904 TC |
2386 | AV *avsub; |
2387 | SV **temp; | |
2388 | int len; | |
2389 | int i, j; | |
2390 | unsigned char (*maps)[256]; | |
2391 | CODE: | |
2392 | len = av_len(pmaps_av)+1; | |
2393 | if (im->channels < len) | |
2394 | len = im->channels; | |
2395 | maps = mymalloc( len * sizeof(unsigned char [256]) ); | |
2396 | for (j=0; j<len ; j++) { | |
2397 | temp = av_fetch(pmaps_av, j, 0); | |
2398 | if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) { | |
2399 | avsub = (AV*)SvRV(*temp); | |
2400 | if(av_len(avsub) != 255) | |
2401 | continue; | |
2402 | mask |= 1<<j; | |
2403 | for (i=0; i<256 ; i++) { | |
2404 | int val; | |
2405 | temp = av_fetch(avsub, i, 0); | |
2406 | val = temp ? SvIV(*temp) : 0; | |
2407 | if (val<0) val = 0; | |
2408 | if (val>255) val = 255; | |
2409 | maps[j][i] = val; | |
2410 | } | |
2411 | } | |
2412 | } | |
2413 | i_map(im, maps, mask); | |
2414 | myfree(maps); | |
2415 | RETVAL = 1; | |
2416 | OUTPUT: | |
2417 | RETVAL | |
40eba1ea | 2418 | |
02d1d628 AMH |
2419 | float |
2420 | i_img_diff(im1,im2) | |
2421 | Imager::ImgRaw im1 | |
2422 | Imager::ImgRaw im2 | |
2423 | ||
e41cfe8f TC |
2424 | double |
2425 | i_img_diffd(im1,im2) | |
2426 | Imager::ImgRaw im1 | |
2427 | Imager::ImgRaw im2 | |
02d1d628 | 2428 | |
4498c8bd TC |
2429 | int |
2430 | i_img_samef(im1, im2, epsilon = i_img_epsilonf(), what=NULL) | |
2431 | Imager::ImgRaw im1 | |
2432 | Imager::ImgRaw im2 | |
5824f4c2 | 2433 | im_double epsilon |
4498c8bd TC |
2434 | const char *what |
2435 | ||
2436 | double | |
2437 | i_img_epsilonf() | |
2438 | ||
813d4d0a TC |
2439 | bool |
2440 | _is_color_object(sv) | |
2441 | SV* sv | |
2442 | CODE: | |
2443 | SvGETMAGIC(sv); | |
2444 | RETVAL = SvOK(sv) && SvROK(sv) && | |
2445 | (sv_derived_from(sv, "Imager::Color") | |
2446 | || sv_derived_from(sv, "Imager::Color::Float")); | |
2447 | OUTPUT: | |
2448 | RETVAL | |
2449 | ||
02d1d628 AMH |
2450 | #ifdef HAVE_LIBTT |
2451 | ||
2452 | ||
4b19f77a | 2453 | Imager::Font::TT |
02d1d628 AMH |
2454 | i_tt_new(fontname) |
2455 | char* fontname | |
2456 | ||
4b19f77a AMH |
2457 | |
2458 | MODULE = Imager PACKAGE = Imager::Font::TT PREFIX=TT_ | |
2459 | ||
2460 | #define TT_DESTROY(handle) i_tt_destroy(handle) | |
2461 | ||
02d1d628 | 2462 | void |
4b19f77a AMH |
2463 | TT_DESTROY(handle) |
2464 | Imager::Font::TT handle | |
2465 | ||
ffddd407 TC |
2466 | int |
2467 | TT_CLONE_SKIP(...) | |
2468 | CODE: | |
8d14daab | 2469 | (void)items; /* avoid unused warning */ |
ffddd407 TC |
2470 | RETVAL = 1; |
2471 | OUTPUT: | |
2472 | RETVAL | |
2473 | ||
02d1d628 | 2474 | |
4b19f77a | 2475 | MODULE = Imager PACKAGE = Imager |
02d1d628 AMH |
2476 | |
2477 | ||
2478 | undef_int | |
e3b4d6c3 | 2479 | i_tt_text(handle,im,xb,yb,cl,points,str_sv,smooth,utf8,align=1) |
4b19f77a | 2480 | Imager::Font::TT handle |
02d1d628 | 2481 | Imager::ImgRaw im |
8d14daab TC |
2482 | i_img_dim xb |
2483 | i_img_dim yb | |
02d1d628 | 2484 | Imager::Color cl |
5824f4c2 | 2485 | im_double points |
4f68b48f | 2486 | SV * str_sv |
02d1d628 | 2487 | int smooth |
4f68b48f | 2488 | int utf8 |
9ab6338b | 2489 | int align |
4f68b48f TC |
2490 | PREINIT: |
2491 | char *str; | |
2492 | STRLEN len; | |
2493 | CODE: | |
e3b4d6c3 | 2494 | str = SvPV(str_sv, len); |
4f68b48f TC |
2495 | #ifdef SvUTF8 |
2496 | if (SvUTF8(str_sv)) | |
2497 | utf8 = 1; | |
2498 | #endif | |
4f68b48f | 2499 | RETVAL = i_tt_text(handle, im, xb, yb, cl, points, str, |
9ab6338b | 2500 | len, smooth, utf8, align); |
4f68b48f TC |
2501 | OUTPUT: |
2502 | RETVAL | |
02d1d628 AMH |
2503 | |
2504 | ||
2505 | undef_int | |
e3b4d6c3 | 2506 | i_tt_cp(handle,im,xb,yb,channel,points,str_sv,smooth,utf8,align=1) |
4b19f77a | 2507 | Imager::Font::TT handle |
02d1d628 | 2508 | Imager::ImgRaw im |
8d14daab TC |
2509 | i_img_dim xb |
2510 | i_img_dim yb | |
02d1d628 | 2511 | int channel |
5824f4c2 | 2512 | im_double points |
4f68b48f | 2513 | SV * str_sv |
02d1d628 | 2514 | int smooth |
4f68b48f | 2515 | int utf8 |
9ab6338b | 2516 | int align |
4f68b48f TC |
2517 | PREINIT: |
2518 | char *str; | |
2519 | STRLEN len; | |
2520 | CODE: | |
e3b4d6c3 | 2521 | str = SvPV(str_sv, len); |
4f68b48f TC |
2522 | #ifdef SvUTF8 |
2523 | if (SvUTF8(str_sv)) | |
2524 | utf8 = 1; | |
2525 | #endif | |
4f68b48f | 2526 | RETVAL = i_tt_cp(handle, im, xb, yb, channel, points, str, len, |
9ab6338b | 2527 | smooth, utf8, align); |
4f68b48f TC |
2528 | OUTPUT: |
2529 | RETVAL | |
02d1d628 AMH |
2530 | |
2531 | ||
a659442a | 2532 | void |
7e3298ec | 2533 | i_tt_bbox(handle,point,str_sv,utf8) |
4b19f77a | 2534 | Imager::Font::TT handle |
5824f4c2 | 2535 | im_double point |
4f68b48f | 2536 | SV* str_sv |
4f68b48f | 2537 | int utf8 |
02d1d628 | 2538 | PREINIT: |
8d14daab TC |
2539 | i_img_dim cords[BOUNDING_BOX_COUNT]; |
2540 | int rc; | |
4f68b48f TC |
2541 | char * str; |
2542 | STRLEN len; | |
3799c4d1 | 2543 | int i; |
02d1d628 | 2544 | PPCODE: |
7e3298ec | 2545 | str = SvPV(str_sv, len); |
4f68b48f TC |
2546 | #ifdef SvUTF8 |
2547 | if (SvUTF8(ST(2))) | |
2548 | utf8 = 1; | |
2549 | #endif | |
4f68b48f | 2550 | if ((rc=i_tt_bbox(handle,point,str,len,cords, utf8))) { |
3799c4d1 TC |
2551 | EXTEND(SP, rc); |
2552 | for (i = 0; i < rc; ++i) { | |
2553 | PUSHs(sv_2mortal(newSViv(cords[i]))); | |
2554 | } | |
02d1d628 AMH |
2555 | } |
2556 | ||
eeaa33fd TC |
2557 | void |
2558 | i_tt_has_chars(handle, text_sv, utf8) | |
2559 | Imager::Font::TT handle | |
2560 | SV *text_sv | |
2561 | int utf8 | |
2562 | PREINIT: | |
2563 | char const *text; | |
2564 | STRLEN len; | |
2565 | char *work; | |
8d14daab TC |
2566 | size_t count; |
2567 | size_t i; | |
eeaa33fd | 2568 | PPCODE: |
7e3298ec TC |
2569 | i_clear_error(); |
2570 | text = SvPV(text_sv, len); | |
eeaa33fd TC |
2571 | #ifdef SvUTF8 |
2572 | if (SvUTF8(text_sv)) | |
2573 | utf8 = 1; | |
2574 | #endif | |
eeaa33fd TC |
2575 | work = mymalloc(len); |
2576 | count = i_tt_has_chars(handle, text, len, utf8, work); | |
2577 | if (GIMME_V == G_ARRAY) { | |
7eb58d07 TC |
2578 | if (count) { |
2579 | EXTEND(SP, count); | |
2580 | for (i = 0; i < count; ++i) { | |
2581 | PUSHs(boolSV(work[i])); | |
2582 | } | |
2583 | } | |
eeaa33fd TC |
2584 | } |
2585 | else { | |
2586 | EXTEND(SP, 1); | |
2587 | PUSHs(sv_2mortal(newSVpv(work, count))); | |
2588 | } | |
2589 | myfree(work); | |
02d1d628 | 2590 | |
3799c4d1 TC |
2591 | void |
2592 | i_tt_dump_names(handle) | |
2593 | Imager::Font::TT handle | |
02d1d628 | 2594 | |
3799c4d1 TC |
2595 | void |
2596 | i_tt_face_name(handle) | |
2597 | Imager::Font::TT handle | |
2598 | PREINIT: | |
2599 | char name[255]; | |
8d14daab | 2600 | size_t len; |
3799c4d1 TC |
2601 | PPCODE: |
2602 | len = i_tt_face_name(handle, name, sizeof(name)); | |
2603 | if (len) { | |
2604 | EXTEND(SP, 1); | |
8d14daab | 2605 | PUSHs(sv_2mortal(newSVpv(name, len-1))); |
3799c4d1 | 2606 | } |
02d1d628 | 2607 | |
19fa4baf AMH |
2608 | void |
2609 | i_tt_glyph_name(handle, text_sv, utf8 = 0) | |
3799c4d1 TC |
2610 | Imager::Font::TT handle |
2611 | SV *text_sv | |
2612 | int utf8 | |
2613 | PREINIT: | |
2614 | char const *text; | |
2615 | STRLEN work_len; | |
718b8c97 | 2616 | size_t len; |
8d14daab | 2617 | size_t outsize; |
3799c4d1 TC |
2618 | char name[255]; |
2619 | PPCODE: | |
7e3298ec TC |
2620 | i_clear_error(); |
2621 | text = SvPV(text_sv, work_len); | |
3799c4d1 TC |
2622 | #ifdef SvUTF8 |
2623 | if (SvUTF8(text_sv)) | |
2624 | utf8 = 1; | |
2625 | #endif | |
3799c4d1 TC |
2626 | len = work_len; |
2627 | while (len) { | |
17892255 | 2628 | unsigned long ch; |
3799c4d1 TC |
2629 | if (utf8) { |
2630 | ch = i_utf8_advance(&text, &len); | |
2631 | if (ch == ~0UL) { | |
2632 | i_push_error(0, "invalid UTF8 character"); | |
7e3298ec | 2633 | XSRETURN_EMPTY; |
3799c4d1 TC |
2634 | } |
2635 | } | |
2636 | else { | |
2637 | ch = *text++; | |
2638 | --len; | |
2639 | } | |
ea3099db | 2640 | EXTEND(SP, 1); |
af070d99 | 2641 | if ((outsize = i_tt_glyph_name(handle, ch, name, sizeof(name))) != 0) { |
ea3099db | 2642 | PUSHs(sv_2mortal(newSVpv(name, 0))); |
3799c4d1 TC |
2643 | } |
2644 | else { | |
ea3099db | 2645 | PUSHs(&PL_sv_undef); |
7e3298ec | 2646 | } |
3799c4d1 TC |
2647 | } |
2648 | ||
2649 | #endif | |
02d1d628 | 2650 | |
53a6bbd4 | 2651 | const char * |
e10bf46e AMH |
2652 | i_test_format_probe(ig, length) |
2653 | Imager::IO ig | |
2654 | int length | |
2655 | ||
b7028a2e TC |
2656 | int |
2657 | i_add_file_magic(name, bits_sv, mask_sv) | |
2658 | const char *name | |
2659 | SV *bits_sv | |
2660 | SV *mask_sv | |
2661 | PREINIT: | |
2662 | const unsigned char *bits; | |
2663 | const unsigned char *mask; | |
2664 | size_t bits_size; | |
2665 | size_t mask_size; | |
2666 | CODE: | |
2667 | i_clear_error(); | |
2668 | bits = SvPV(bits_sv, bits_size); | |
2669 | mask = SvPV(mask_sv, mask_size); | |
2670 | if (bits_size == 0) { | |
2671 | i_push_error(0, "bits must be non-empty"); | |
2672 | XSRETURN_EMPTY; | |
2673 | } | |
2674 | if (mask_size == 0) { | |
2675 | i_push_error(0, "mask must be non-empty"); | |
2676 | XSRETURN_EMPTY; | |
2677 | } | |
2678 | if (bits_size != mask_size) { | |
2679 | i_push_error(0, "bits and mask must be the same length"); | |
2680 | XSRETURN_EMPTY; | |
2681 | } | |
2682 | if (!*name) { | |
2683 | i_push_error(0, "name must be non-empty"); | |
2684 | XSRETURN_EMPTY; | |
2685 | } | |
2686 | RETVAL = i_add_file_magic(name, bits, mask, bits_size); | |
2687 | OUTPUT: | |
2688 | RETVAL | |
2689 | ||
02d1d628 | 2690 | Imager::ImgRaw |
d87dc9a4 | 2691 | i_readpnm_wiol(ig, allow_incomplete) |
02d1d628 | 2692 | Imager::IO ig |
d87dc9a4 | 2693 | int allow_incomplete |
02d1d628 AMH |
2694 | |
2695 | ||
2086be61 TC |
2696 | void |
2697 | i_readpnm_multi_wiol(ig, allow_incomplete) | |
2698 | Imager::IO ig | |
2699 | int allow_incomplete | |
2700 | PREINIT: | |
2701 | i_img **imgs; | |
2702 | int count=0; | |
2703 | int i; | |
2704 | PPCODE: | |
2705 | imgs = i_readpnm_multi_wiol(ig, &count, allow_incomplete); | |
2706 | if (imgs) { | |
2707 | EXTEND(SP, count); | |
2708 | for (i = 0; i < count; ++i) { | |
2709 | SV *sv = sv_newmortal(); | |
2710 | sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]); | |
2711 | PUSHs(sv); | |
2712 | } | |
2713 | myfree(imgs); | |
2714 | } | |
2715 | ||
067d6bdc AMH |
2716 | undef_int |
2717 | i_writeppm_wiol(im, ig) | |
2718 | Imager::ImgRaw im | |
2719 | Imager::IO ig | |
2720 | ||
2721 | ||
2086be61 TC |
2722 | |
2723 | ||
2724 | ||
02d1d628 | 2725 | Imager::ImgRaw |
895dbd34 AMH |
2726 | i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl) |
2727 | Imager::IO ig | |
8d14daab TC |
2728 | i_img_dim x |
2729 | i_img_dim y | |
02d1d628 AMH |
2730 | int datachannels |
2731 | int storechannels | |
2732 | int intrl | |
2733 | ||
2734 | undef_int | |
895dbd34 | 2735 | i_writeraw_wiol(im,ig) |
02d1d628 | 2736 | Imager::ImgRaw im |
895dbd34 AMH |
2737 | Imager::IO ig |
2738 | ||
261f91c5 TC |
2739 | undef_int |
2740 | i_writebmp_wiol(im,ig) | |
2741 | Imager::ImgRaw im | |
2742 | Imager::IO ig | |
02d1d628 | 2743 | |
705fd961 | 2744 | Imager::ImgRaw |
d87dc9a4 | 2745 | i_readbmp_wiol(ig, allow_incomplete=0) |
705fd961 | 2746 | Imager::IO ig |
d87dc9a4 | 2747 | int allow_incomplete |
705fd961 | 2748 | |
1ec86afa AMH |
2749 | |
2750 | undef_int | |
febba01f | 2751 | i_writetga_wiol(im,ig, wierdpack, compress, idstring) |
1ec86afa AMH |
2752 | Imager::ImgRaw im |
2753 | Imager::IO ig | |
febba01f AMH |
2754 | int wierdpack |
2755 | int compress | |
2756 | char* idstring | |
2757 | PREINIT: | |
febba01f AMH |
2758 | int idlen; |
2759 | CODE: | |
2760 | idlen = SvCUR(ST(4)); | |
2761 | RETVAL = i_writetga_wiol(im, ig, wierdpack, compress, idstring, idlen); | |
2762 | OUTPUT: | |
2763 | RETVAL | |
2764 | ||
1ec86afa AMH |
2765 | |
2766 | Imager::ImgRaw | |
2767 | i_readtga_wiol(ig, length) | |
2768 | Imager::IO ig | |
2769 | int length | |
2770 | ||
2771 | ||
737a830c AMH |
2772 | |
2773 | ||
02d1d628 AMH |
2774 | Imager::ImgRaw |
2775 | i_scaleaxis(im,Value,Axis) | |
2776 | Imager::ImgRaw im | |
5824f4c2 | 2777 | im_double Value |
02d1d628 AMH |
2778 | int Axis |
2779 | ||
2780 | Imager::ImgRaw | |
2781 | i_scale_nn(im,scx,scy) | |
2782 | Imager::ImgRaw im | |
5824f4c2 TC |
2783 | im_double scx |
2784 | im_double scy | |
02d1d628 | 2785 | |
658f724e TC |
2786 | Imager::ImgRaw |
2787 | i_scale_mixing(im, width, height) | |
2788 | Imager::ImgRaw im | |
8d14daab TC |
2789 | i_img_dim width |
2790 | i_img_dim height | |
658f724e | 2791 | |
02d1d628 AMH |
2792 | Imager::ImgRaw |
2793 | i_haar(im) | |
2794 | Imager::ImgRaw im | |
2795 | ||
2796 | int | |
2797 | i_count_colors(im,maxc) | |
2798 | Imager::ImgRaw im | |
2799 | int maxc | |
2800 | ||
fe622da1 | 2801 | void |
a60905e4 TC |
2802 | i_get_anonymous_color_histo(im, maxc = 0x40000000) |
2803 | Imager::ImgRaw im | |
2804 | int maxc | |
4c99febf | 2805 | PREINIT: |
fe622da1 | 2806 | int i; |
a60905e4 | 2807 | unsigned int * col_usage = NULL; |
4c99febf TC |
2808 | int col_cnt; |
2809 | PPCODE: | |
2810 | col_cnt = i_get_anonymous_color_histo(im, &col_usage, maxc); | |
8b810590 TC |
2811 | if (col_cnt <= 0) { |
2812 | XSRETURN_EMPTY; | |
2813 | } | |
2814 | EXTEND(SP, col_cnt); | |
2815 | for (i = 0; i < col_cnt; i++) { | |
2816 | PUSHs(sv_2mortal(newSViv( col_usage[i]))); | |
fe622da1 | 2817 | } |
8b810590 | 2818 | myfree(col_usage); |
fe622da1 | 2819 | |
02d1d628 | 2820 | |
fb9cb3f9 | 2821 | void |
19e9591b | 2822 | i_transform(im, opx, opy, parm) |
02d1d628 | 2823 | Imager::ImgRaw im |
19e9591b TC |
2824 | int *opx |
2825 | int *opy | |
2826 | double *parm | |
02d1d628 | 2827 | PREINIT: |
19e9591b | 2828 | STRLEN size_opx, size_opy, size_parm; |
fb9cb3f9 TC |
2829 | i_img *result; |
2830 | PPCODE: | |
19e9591b | 2831 | result=i_transform(im,opx,size_opx,opy,size_opy,parm,size_parm); |
fb9cb3f9 TC |
2832 | if (result) { |
2833 | SV *result_sv = sv_newmortal(); | |
2834 | EXTEND(SP, 1); | |
2835 | sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result); | |
2836 | PUSHs(result_sv); | |
2837 | } | |
02d1d628 | 2838 | |
fb9cb3f9 | 2839 | void |
e5744e01 TC |
2840 | i_transform2(sv_width,sv_height,channels,sv_ops,av_n_regs,av_c_regs,av_in_imgs) |
2841 | SV *sv_width | |
2842 | SV *sv_height | |
2843 | SV *sv_ops | |
2844 | AV *av_n_regs | |
2845 | AV *av_c_regs | |
2846 | AV *av_in_imgs | |
2847 | int channels | |
02d1d628 | 2848 | PREINIT: |
8d14daab TC |
2849 | i_img_dim width; |
2850 | i_img_dim height; | |
02d1d628 | 2851 | struct rm_op *ops; |
953209f8 | 2852 | STRLEN ops_len; |
02d1d628 AMH |
2853 | int ops_count; |
2854 | double *n_regs; | |
2855 | int n_regs_count; | |
2856 | i_color *c_regs; | |
2857 | int c_regs_count; | |
2858 | int in_imgs_count; | |
2859 | i_img **in_imgs; | |
ea9e6c3f | 2860 | SV *sv1; |
02d1d628 AMH |
2861 | IV tmp; |
2862 | int i; | |
fb9cb3f9 TC |
2863 | i_img *result; |
2864 | PPCODE: | |
e5744e01 TC |
2865 | |
2866 | in_imgs_count = av_len(av_in_imgs)+1; | |
2867 | for (i = 0; i < in_imgs_count; ++i) { | |
2868 | sv1 = *av_fetch(av_in_imgs, i, 0); | |
2869 | if (!sv_derived_from(sv1, "Imager::ImgRaw")) { | |
2870 | croak("sv_in_img must contain only images"); | |
02d1d628 AMH |
2871 | } |
2872 | } | |
b8c2033e | 2873 | if (in_imgs_count > 0) { |
02d1d628 AMH |
2874 | in_imgs = mymalloc(in_imgs_count*sizeof(i_img*)); |
2875 | for (i = 0; i < in_imgs_count; ++i) { | |
e5744e01 | 2876 | sv1 = *av_fetch(av_in_imgs,i,0); |
02d1d628 AMH |
2877 | if (!sv_derived_from(sv1, "Imager::ImgRaw")) { |
2878 | croak("Parameter 5 must contain only images"); | |
2879 | } | |
2880 | tmp = SvIV((SV*)SvRV(sv1)); | |
e375fbd8 | 2881 | in_imgs[i] = INT2PTR(i_img*, tmp); |
02d1d628 AMH |
2882 | } |
2883 | } | |
2884 | else { | |
2885 | /* no input images */ | |
2886 | in_imgs = NULL; | |
2887 | } | |
2888 | /* default the output size from the first input if possible */ | |
e5744e01 TC |
2889 | if (SvOK(sv_width)) |
2890 | width = SvIV(sv_width); | |
02d1d628 AMH |
2891 | else if (in_imgs_count) |
2892 | width = in_imgs[0]->xsize; | |
2893 | else | |
2894 | croak("No output image width supplied"); | |
2895 | ||
e5744e01 TC |
2896 | if (SvOK(sv_height)) |
2897 | height = SvIV(sv_height); | |
02d1d628 AMH |
2898 | else if (in_imgs_count) |
2899 | height = in_imgs[0]->ysize; | |
2900 | else | |
2901 | croak("No output image height supplied"); | |
2902 | ||
e5744e01 | 2903 | ops = (struct rm_op *)SvPV(sv_ops, ops_len); |
02d1d628 AMH |
2904 | if (ops_len % sizeof(struct rm_op)) |
2905 | croak("Imager: Parameter 3 must be a bitmap of regops\n"); | |
2906 | ops_count = ops_len / sizeof(struct rm_op); | |
e5744e01 TC |
2907 | |
2908 | n_regs_count = av_len(av_n_regs)+1; | |
02d1d628 AMH |
2909 | n_regs = mymalloc(n_regs_count * sizeof(double)); |
2910 | for (i = 0; i < n_regs_count; ++i) { | |
e5744e01 | 2911 | sv1 = *av_fetch(av_n_regs,i,0); |
02d1d628 AMH |
2912 | if (SvOK(sv1)) |
2913 | n_regs[i] = SvNV(sv1); | |
2914 | } | |
e5744e01 | 2915 | c_regs_count = av_len(av_c_regs)+1; |
02d1d628 AMH |
2916 | c_regs = mymalloc(c_regs_count * sizeof(i_color)); |
2917 | /* I don't bother initializing the colou?r registers */ | |
2918 | ||
fb9cb3f9 | 2919 | result=i_transform2(width, height, channels, ops, ops_count, |
02d1d628 AMH |
2920 | n_regs, n_regs_count, |
2921 | c_regs, c_regs_count, in_imgs, in_imgs_count); | |
2922 | if (in_imgs) | |
2923 | myfree(in_imgs); | |
2924 | myfree(n_regs); | |
2925 | myfree(c_regs); | |
fb9cb3f9 TC |
2926 | if (result) { |
2927 | SV *result_sv = sv_newmortal(); | |
2928 | EXTEND(SP, 1); | |
2929 | sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result); | |
2930 | PUSHs(result_sv); | |
2931 | } | |
02d1d628 AMH |
2932 | |
2933 | ||
2934 | void | |
2935 | i_contrast(im,intensity) | |
2936 | Imager::ImgRaw im | |
5824f4c2 | 2937 | im_float intensity |
02d1d628 AMH |
2938 | |
2939 | void | |
2940 | i_hardinvert(im) | |
2941 | Imager::ImgRaw im | |
2942 | ||
5558f899 TC |
2943 | void |
2944 | i_hardinvertall(im) | |
2945 | Imager::ImgRaw im | |
2946 | ||
02d1d628 AMH |
2947 | void |
2948 | i_noise(im,amount,type) | |
2949 | Imager::ImgRaw im | |
5824f4c2 | 2950 | im_float amount |
02d1d628 AMH |
2951 | unsigned char type |
2952 | ||
2953 | void | |
2954 | i_bumpmap(im,bump,channel,light_x,light_y,strength) | |
2955 | Imager::ImgRaw im | |
2956 | Imager::ImgRaw bump | |
2957 | int channel | |
8d14daab TC |
2958 | i_img_dim light_x |
2959 | i_img_dim light_y | |
2960 | i_img_dim strength | |
02d1d628 | 2961 | |
b2778574 AMH |
2962 | |
2963 | void | |
2964 | i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is) | |
2965 | Imager::ImgRaw im | |
2966 | Imager::ImgRaw bump | |
2967 | int channel | |
8d14daab TC |
2968 | i_img_dim tx |
2969 | i_img_dim ty | |
5824f4c2 TC |
2970 | im_double Lx |
2971 | im_double Ly | |
2972 | im_double Lz | |
2973 | im_float cd | |
2974 | im_float cs | |
2975 | im_float n | |
b2778574 AMH |
2976 | Imager::Color Ia |
2977 | Imager::Color Il | |
2978 | Imager::Color Is | |
2979 | ||
2980 | ||
2981 | ||
02d1d628 AMH |
2982 | void |
2983 | i_postlevels(im,levels) | |
2984 | Imager::ImgRaw im | |
2985 | int levels | |
2986 | ||
2987 | void | |
2988 | i_mosaic(im,size) | |
2989 | Imager::ImgRaw im | |
8d14daab | 2990 | i_img_dim size |
02d1d628 AMH |
2991 | |
2992 | void | |
2993 | i_watermark(im,wmark,tx,ty,pixdiff) | |
2994 | Imager::ImgRaw im | |
2995 | Imager::ImgRaw wmark | |
8d14daab TC |
2996 | i_img_dim tx |
2997 | i_img_dim ty | |
02d1d628 AMH |
2998 | int pixdiff |
2999 | ||
3000 | ||
3001 | void | |
3002 | i_autolevels(im,lsat,usat,skew) | |
3003 | Imager::ImgRaw im | |
5824f4c2 TC |
3004 | im_float lsat |
3005 | im_float usat | |
3006 | im_float skew | |
02d1d628 | 3007 | |
ac00f58d TC |
3008 | void |
3009 | i_autolevels_mono(im,lsat,usat) | |
3010 | Imager::ImgRaw im | |
5824f4c2 TC |
3011 | im_float lsat |
3012 | im_float usat | |
ac00f58d | 3013 | |
02d1d628 AMH |
3014 | void |
3015 | i_radnoise(im,xo,yo,rscale,ascale) | |
3016 | Imager::ImgRaw im | |
5824f4c2 TC |
3017 | im_float xo |
3018 | im_float yo | |
3019 | im_float rscale | |
3020 | im_float ascale | |
02d1d628 AMH |
3021 | |
3022 | void | |
3023 | i_turbnoise(im, xo, yo, scale) | |
3024 | Imager::ImgRaw im | |
5824f4c2 TC |
3025 | im_float xo |
3026 | im_float yo | |
3027 | im_float scale | |
02d1d628 AMH |
3028 | |
3029 | ||
3030 | void | |
0aaa8b4d | 3031 | i_gradgen(im, xo, yo, ac, dmeasure) |
02d1d628 | 3032 | Imager::ImgRaw im |
0aaa8b4d TC |
3033 | i_img_dim *xo |
3034 | i_img_dim *yo | |
3035 | i_color *ac | |
3036 | int dmeasure | |
02d1d628 | 3037 | PREINIT: |
0aaa8b4d TC |
3038 | STRLEN size_xo; |
3039 | STRLEN size_yo; | |
3040 | STRLEN size_ac; | |
02d1d628 | 3041 | CODE: |
0aaa8b4d TC |
3042 | if (size_xo != size_yo || size_xo != size_ac) |
3043 | croak("i_gradgen: x, y and color arrays must be the same size"); | |
3044 | if (size_xo < 2) | |
3045 | croak("Usage: i_gradgen array refs must have more than 1 entry each"); | |
3046 | i_gradgen(im, size_xo, xo, yo, ac, dmeasure); | |
a73aeb5f | 3047 | |
dff75dee TC |
3048 | Imager::ImgRaw |
3049 | i_diff_image(im, im2, mindist=0) | |
3050 | Imager::ImgRaw im | |
3051 | Imager::ImgRaw im2 | |
5824f4c2 | 3052 | im_double mindist |
02d1d628 | 3053 | |
dcdafbb0 AK |
3054 | Imager::ImgRaw |
3055 | i_rgbdiff_image(im, im2) | |
3056 | Imager::ImgRaw im | |
3057 | Imager::ImgRaw im2 | |
3058 | ||
e310e5f9 | 3059 | undef_int |
6607600c TC |
3060 | i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs) |
3061 | Imager::ImgRaw im | |
5824f4c2 TC |
3062 | im_double xa |
3063 | im_double ya | |
3064 | im_double xb | |
3065 | im_double yb | |
6607600c TC |
3066 | int type |
3067 | int repeat | |
3068 | int combine | |
3069 | int super_sample | |
5824f4c2 | 3070 | im_double ssample_param |
6607600c | 3071 | PREINIT: |
6607600c | 3072 | AV *asegs; |
6607600c TC |
3073 | int count; |
3074 | i_fountain_seg *segs; | |
6607600c | 3075 | CODE: |
6607600c TC |
3076 | if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10)))) |
3077 | croak("i_fountain: argument 11 must be an array ref"); | |
3078 | ||
3079 | asegs = (AV *)SvRV(ST(10)); | |
b13a3ddb | 3080 | segs = load_fount_segs(aTHX_ asegs, &count); |
e310e5f9 TC |
3081 | RETVAL = i_fountain(im, xa, ya, xb, yb, type, repeat, combine, |
3082 | super_sample, ssample_param, count, segs); | |
6607600c | 3083 | myfree(segs); |
e310e5f9 TC |
3084 | OUTPUT: |
3085 | RETVAL | |
02d1d628 | 3086 | |
f1ac5027 TC |
3087 | Imager::FillHandle |
3088 | i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs) | |
5824f4c2 TC |
3089 | im_double xa |
3090 | im_double ya | |
3091 | im_double xb | |
3092 | im_double yb | |
f1ac5027 TC |
3093 | int type |
3094 | int repeat | |
3095 | int combine | |
3096 | int super_sample | |
5824f4c2 | 3097 | im_double ssample_param |
f1ac5027 TC |
3098 | PREINIT: |
3099 | AV *asegs; | |
3100 | int count; | |
3101 | i_fountain_seg *segs; | |
3102 | CODE: | |
3103 | if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9)))) | |
3104 | croak("i_fountain: argument 11 must be an array ref"); | |
3105 | ||
3106 | asegs = (AV *)SvRV(ST(9)); | |
b13a3ddb | 3107 | segs = load_fount_segs(aTHX_ asegs, &count); |
f1ac5027 TC |
3108 | RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, |
3109 | super_sample, ssample_param, count, segs); | |
3110 | myfree(segs); | |
3111 | OUTPUT: | |
3112 | RETVAL | |
3113 | ||
52f2b10a TC |
3114 | Imager::FillHandle |
3115 | i_new_fill_opacity(other_fill, alpha_mult) | |
3116 | Imager::FillHandle other_fill | |
5824f4c2 | 3117 | im_double alpha_mult |
52f2b10a | 3118 | |
4f4f776a TC |
3119 | void |
3120 | i_errors() | |
3121 | PREINIT: | |
3122 | i_errmsg *errors; | |
3123 | int i; | |
4f4f776a | 3124 | AV *av; |
4f4f776a TC |
3125 | SV *sv; |
3126 | PPCODE: | |
3127 | errors = i_errors(); | |
3128 | i = 0; | |
3129 | while (errors[i].msg) { | |
3130 | av = newAV(); | |
3131 | sv = newSVpv(errors[i].msg, strlen(errors[i].msg)); | |
3132 | if (!av_store(av, 0, sv)) { | |
3133 | SvREFCNT_dec(sv); | |
3134 | } | |
3135 | sv = newSViv(errors[i].code); | |
3136 | if (!av_store(av, 1, sv)) { | |
3137 | SvREFCNT_dec(sv); | |
3138 | } | |
57bbbbe7 | 3139 | XPUSHs(sv_2mortal(newRV_noinc((SV*)av))); |
4f4f776a TC |
3140 | ++i; |
3141 | } | |
02d1d628 | 3142 | |
2b405c9e TC |
3143 | void |
3144 | i_clear_error() | |
3145 | ||
3146 | void | |
3147 | i_push_error(code, msg) | |
3148 | int code | |
3149 | const char *msg | |
3150 | ||
e310e5f9 | 3151 | undef_int |
02d1d628 AMH |
3152 | i_nearest_color(im, ...) |
3153 | Imager::ImgRaw im | |
3154 | PREINIT: | |
3155 | int num; | |
8d14daab TC |
3156 | i_img_dim *xo; |
3157 | i_img_dim *yo; | |
02d1d628 AMH |
3158 | i_color *ival; |
3159 | int dmeasure; | |
3160 | int i; | |
3161 | SV *sv; | |
3162 | AV *axx; | |
3163 | AV *ayy; | |
3164 | AV *ac; | |
3165 | CODE: | |
3166 | if (items != 5) | |
3167 | croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)"); | |
3168 | if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1)))) | |
3169 | croak("i_nearest_color: Second argument must be an array ref"); | |
3170 | if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2)))) | |
3171 | croak("i_nearest_color: Third argument must be an array ref"); | |
3172 | if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3)))) | |
3173 | croak("i_nearest_color: Fourth argument must be an array ref"); | |
3174 | axx = (AV *)SvRV(ST(1)); | |
3175 | ayy = (AV *)SvRV(ST(2)); | |
3176 | ac = (AV *)SvRV(ST(3)); | |
3177 | dmeasure = (int)SvIV(ST(4)); | |
3178 | ||
3179 | num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy); | |
3180 | num = num <= av_len(ac) ? num : av_len(ac); | |
3181 | num++; | |
3182 | if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each"); | |
945dff7f TC |
3183 | xo = malloc_temp(aTHX_ sizeof(i_img_dim) * num ); |
3184 | yo = malloc_temp(aTHX_ sizeof(i_img_dim) * num ); | |
3185 | ival = malloc_temp(aTHX_ sizeof(i_color) * num ); | |
02d1d628 | 3186 | for(i = 0; i<num; i++) { |
8d14daab TC |
3187 | xo[i] = (i_img_dim)SvIV(* av_fetch(axx, i, 0)); |
3188 | yo[i] = (i_img_dim)SvIV(* av_fetch(ayy, i, 0)); | |
02d1d628 AMH |
3189 | sv = *av_fetch(ac, i, 0); |
3190 | if ( !sv_derived_from(sv, "Imager::Color") ) { | |
3191 | free(axx); free(ayy); free(ac); | |
3192 | croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color"); | |
3193 | } | |
4c4c2ffd | 3194 | ival[i] = *INT2PTR(i_color *, SvIV((SV *)SvRV(sv))); |
02d1d628 | 3195 | } |
e310e5f9 TC |
3196 | RETVAL = i_nearest_color(im, num, xo, yo, ival, dmeasure); |
3197 | OUTPUT: | |
3198 | RETVAL | |
02d1d628 AMH |
3199 | |
3200 | void | |
3201 | malloc_state() | |
3202 | ||
02d1d628 AMH |
3203 | void |
3204 | DSO_open(filename) | |
3205 | char* filename | |
3206 | PREINIT: | |
3207 | void *rc; | |
3208 | char *evstr; | |
3209 | PPCODE: | |
3210 | rc=DSO_open(filename,&evstr); | |
3211 | if (rc!=NULL) { | |
3212 | if (evstr!=NULL) { | |
3213 | EXTEND(SP,2); | |
e375fbd8 | 3214 | PUSHs(sv_2mortal(newSViv(PTR2IV(rc)))); |
02d1d628 AMH |
3215 | PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr)))); |
3216 | } else { | |
3217 | EXTEND(SP,1); | |
e375fbd8 | 3218 | PUSHs(sv_2mortal(newSViv(PTR2IV(rc)))); |
02d1d628 AMH |
3219 | } |
3220 | } | |
3221 | ||
3222 | ||
3223 | undef_int | |
3224 | DSO_close(dso_handle) | |
3225 | void* dso_handle | |
3226 | ||
3227 | void | |
3228 | DSO_funclist(dso_handle_v) | |
3229 | void* dso_handle_v | |
3230 | PREINIT: | |
3231 | int i; | |
3232 | DSO_handle *dso_handle; | |
d8e0c3ba | 3233 | func_ptr *functions; |
02d1d628 AMH |
3234 | PPCODE: |
3235 | dso_handle=(DSO_handle*)dso_handle_v; | |
d8e0c3ba | 3236 | functions = DSO_funclist(dso_handle); |
02d1d628 | 3237 | i=0; |
d8e0c3ba | 3238 | while( functions[i].name != NULL) { |
02d1d628 | 3239 | EXTEND(SP,1); |
d8e0c3ba | 3240 | PUSHs(sv_2mortal(newSVpv(functions[i].name,0))); |
02d1d628 | 3241 | EXTEND(SP,1); |
d8e0c3ba | 3242 | PUSHs(sv_2mortal(newSVpv(functions[i++].pcode,0))); |
02d1d628 AMH |
3243 | } |
3244 | ||
02d1d628 AMH |
3245 | void |
3246 | DSO_call(handle,func_index,hv) | |
3247 | void* handle | |
3248 | int func_index | |
75cebca8 | 3249 | HV *hv |
02d1d628 | 3250 | PPCODE: |
02d1d628 AMH |
3251 | DSO_call( (DSO_handle *)handle,func_index,hv); |
3252 | ||
befd4be1 | 3253 | Imager::Color |
f5991c03 TC |
3254 | i_get_pixel(im, x, y) |
3255 | Imager::ImgRaw im | |
8d14daab TC |
3256 | i_img_dim x |
3257 | i_img_dim y; | |
faa9b3e7 | 3258 | CODE: |
befd4be1 | 3259 | RETVAL = (i_color *)mymalloc(sizeof(i_color)); |
2ea4aa42 | 3260 | memset(RETVAL, 0, sizeof(*RETVAL)); |
befd4be1 TC |
3261 | if (i_gpix(im, x, y, RETVAL) != 0) { |
3262 | myfree(RETVAL); | |
3263 | XSRETURN_UNDEF; | |
faa9b3e7 | 3264 | } |
a659442a TC |
3265 | OUTPUT: |
3266 | RETVAL | |
faa9b3e7 TC |
3267 | |
3268 | ||
3269 | int | |
3270 | i_ppix(im, x, y, cl) | |
3271 | Imager::ImgRaw im | |
8d14daab TC |
3272 | i_img_dim x |
3273 | i_img_dim y | |
faa9b3e7 TC |
3274 | Imager::Color cl |
3275 | ||
3276 | Imager::ImgRaw | |
3277 | i_img_pal_new(x, y, channels, maxpal) | |
8d14daab TC |
3278 | i_img_dim x |
3279 | i_img_dim y | |
faa9b3e7 TC |
3280 | int channels |
3281 | int maxpal | |
3282 | ||
3283 | Imager::ImgRaw | |
05f2584a | 3284 | i_img_to_pal(src, quant_hv) |
faa9b3e7 | 3285 | Imager::ImgRaw src |
05f2584a | 3286 | HV *quant_hv |
faa9b3e7 TC |
3287 | PREINIT: |
3288 | HV *hv; | |
3289 | i_quantize quant; | |
3290 | CODE: | |
faa9b3e7 | 3291 | memset(&quant, 0, sizeof(quant)); |
ec6d8908 | 3292 | quant.version = 1; |
faa9b3e7 | 3293 | quant.mc_size = 256; |
a3b721bb TC |
3294 | i_clear_error(); |
3295 | if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) { | |
3296 | XSRETURN_EMPTY; | |
3297 | } | |
faa9b3e7 TC |
3298 | RETVAL = i_img_to_pal(src, &quant); |
3299 | if (RETVAL) { | |
05f2584a | 3300 | ip_copy_colors_back(aTHX_ quant_hv, &quant); |
faa9b3e7 | 3301 | } |
ec6d8908 | 3302 | ip_cleanup_quant_opts(aTHX_ &quant); |
faa9b3e7 TC |
3303 | OUTPUT: |
3304 | RETVAL | |
3305 | ||
3306 | Imager::ImgRaw | |
3307 | i_img_to_rgb(src) | |
3308 | Imager::ImgRaw src | |
3309 | ||
5e9a7fbd TC |
3310 | void |
3311 | i_img_make_palette(HV *quant_hv, ...) | |
3312 | PREINIT: | |
3313 | size_t count = items - 1; | |
3314 | i_quantize quant; | |
3315 | i_img **imgs = NULL; | |
3316 | ssize_t i; | |
3317 | PPCODE: | |
3318 | if (count <= 0) | |
3319 | croak("Please supply at least one image (%d)", (int)count); | |
e9689cbf | 3320 | imgs = malloc_temp(aTHX_ count * sizeof(i_img *)); |
5e9a7fbd TC |
3321 | for (i = 0; i < count; ++i) { |
3322 | SV *img_sv = ST(i + 1); | |
3323 | if (SvROK(img_sv) && sv_derived_from(img_sv, "Imager::ImgRaw")) { | |
3324 | imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(img_sv))); | |
3325 | } | |
3326 | else { | |
ec2f6280 | 3327 | croak("Image %d is not an image object", (int)i+1); |
5e9a7fbd TC |
3328 | } |
3329 | } | |
3330 | memset(&quant, 0, sizeof(quant)); | |
3331 | quant.version = 1; | |
3332 | quant.mc_size = 256; | |
a3b721bb TC |
3333 | if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) { |
3334 | XSRETURN_EMPTY; | |
3335 | } | |
5e9a7fbd TC |
3336 | i_quant_makemap(&quant, imgs, count); |
3337 | EXTEND(SP, quant.mc_count); | |
3338 | for (i = 0; i < quant.mc_count; ++i) { | |
3339 | SV *sv_c = make_i_color_sv(aTHX_ quant.mc_colors + i); | |
3340 | PUSHs(sv_c); | |
3341 | } | |
3342 | ip_cleanup_quant_opts(aTHX_ &quant); | |
3343 | ||
3344 | ||
faa9b3e7 TC |
3345 | void |
3346 | i_gpal(im, l, r, y) | |
3347 | Imager::ImgRaw im | |
8d14daab TC |
3348 | i_img_dim l |
3349 | i_img_dim r | |
3350 | i_img_dim y | |
faa9b3e7 TC |
3351 | PREINIT: |
3352 | i_palidx *work; | |
3353 | int count, i; | |
3354 | PPCODE: | |
3355 | if (l < r) { | |
3356 | work = mymalloc((r-l) * sizeof(i_palidx)); | |
3357 | count = i_gpal(im, l, r, y, work); | |
3358 | if (GIMME_V == G_ARRAY) { | |
3359 | EXTEND(SP, count); | |
3360 | for (i = 0; i < count; ++i) { | |
3361 | PUSHs(sv_2mortal(newSViv(work[i]))); | |
3362 | } | |
3363 | } | |
3364 | else { | |
3365 | EXTEND(SP, 1); | |
26fd367b | 3366 | PUSHs(sv_2mortal(newSVpv((char *)work, count * sizeof(i_palidx)))); |
faa9b3e7 TC |
3367 | } |
3368 | myfree(work); | |
3369 | } | |
3370 | else { | |
3371 | if (GIMME_V != G_ARRAY) { | |
3372 | EXTEND(SP, 1); | |
3373 | PUSHs(&PL_sv_undef); | |
3374 | } | |
3375 | } | |
3376 | ||
3377 | int | |
3378 | i_ppal(im, l, y, ...) | |
3379 | Imager::ImgRaw im | |
8d14daab TC |
3380 | i_img_dim l |
3381 | i_img_dim y | |
faa9b3e7 TC |
3382 | PREINIT: |
3383 | i_palidx *work; | |
ebe9b189 | 3384 | i_img_dim i; |
faa9b3e7 TC |
3385 | CODE: |
3386 | if (items > 3) { | |
ebe9b189 | 3387 | work = malloc_temp(aTHX_ sizeof(i_palidx) * (items-3)); |
faa9b3e7 TC |
3388 | for (i=0; i < items-3; ++i) { |
3389 | work[i] = SvIV(ST(i+3)); | |
3390 | } | |
4cda4e76 | 3391 | validate_i_ppal(im, work, items - 3); |
faa9b3e7 | 3392 | RETVAL = i_ppal(im, l, l+items-3, y, work); |
faa9b3e7 TC |
3393 | } |
3394 | else { | |
3395 | RETVAL = 0; | |
3396 | } | |
3397 | OUTPUT: | |
3398 | RETVAL | |
3399 | ||
4cda4e76 TC |
3400 | int |
3401 | i_ppal_p(im, l, y, data) | |
3402 | Imager::ImgRaw im | |
8d14daab TC |
3403 | i_img_dim l |
3404 | i_img_dim y | |
4cda4e76 TC |
3405 | SV *data |
3406 | PREINIT: | |
3407 | i_palidx const *work; | |
4cda4e76 | 3408 | STRLEN len; |
4cda4e76 TC |
3409 | CODE: |
3410 | work = (i_palidx const *)SvPV(data, len); | |
3411 | len /= sizeof(i_palidx); | |
3412 | if (len > 0) { | |
3413 | validate_i_ppal(im, work, len); | |
3414 | RETVAL = i_ppal(im, l, l+len, y, work); | |
3415 | } | |
3416 | else { | |
3417 | RETVAL = 0; | |
3418 | } | |
3419 | OUTPUT: | |
3420 | RETVAL | |
3421 | ||
42505e61 | 3422 | SysRet |
faa9b3e7 TC |
3423 | i_addcolors(im, ...) |
3424 | Imager::ImgRaw im | |
3425 | PREINIT: | |
faa9b3e7 TC |
3426 | i_color *colors; |
3427 | int i; | |
3428 | CODE: | |
3429 | if (items < 2) | |
3430 | croak("i_addcolors: no colors to add"); | |
3431 | colors = mymalloc((items-1) * sizeof(i_color)); | |
3432 | for (i=0; i < items-1; ++i) { | |
3433 | if (sv_isobject(ST(i+1)) | |
3434 | && sv_derived_from(ST(i+1), "Imager::Color")) { | |
3435 | IV tmp = SvIV((SV *)SvRV(ST(i+1))); | |
4c4c2ffd | 3436 | colors[i] = *INT2PTR(i_color *, tmp); |
faa9b3e7 TC |
3437 | } |
3438 | else { | |
3439 | myfree(colors); | |
ca4d914e | 3440 | croak("i_addcolor: pixels must be Imager::Color objects"); |
faa9b3e7 TC |
3441 | } |
3442 | } | |
42505e61 | 3443 | RETVAL = i_addcolors(im, colors, items-1); |
7d5febef | 3444 | myfree(colors); |
a659442a TC |
3445 | OUTPUT: |
3446 | RETVAL | |
faa9b3e7 | 3447 | |
1501d9b3 | 3448 | undef_int |
faa9b3e7 TC |
3449 | i_setcolors(im, index, ...) |
3450 | Imager::ImgRaw im | |
3451 | int index | |
3452 | PREINIT: | |
3453 | i_color *colors; | |
3454 | int i; | |
3455 | CODE: | |
3456 | if (items < 3) | |
3457 | croak("i_setcolors: no colors to add"); | |
3458 | colors = mymalloc((items-2) * sizeof(i_color)); | |
3459 | for (i=0; i < items-2; ++i) { | |
3460 | if (sv_isobject(ST(i+2)) | |
3461 | && sv_derived_from(ST(i+2), "Imager::Color")) { | |
3462 | IV tmp = SvIV((SV *)SvRV(ST(i+2))); | |
4c4c2ffd | 3463 | colors[i] = *INT2PTR(i_color *, tmp); |
faa9b3e7 TC |
3464 | } |
3465 | else { | |
3466 | myfree(colors); | |
3467 | croak("i_setcolors: pixels must be Imager::Color objects"); | |
3468 | } | |
3469 | } | |
3470 | RETVAL = i_setcolors(im, index, colors, items-2); | |
3471 | myfree(colors); | |
1501d9b3 TC |
3472 | OUTPUT: |
3473 | RETVAL | |
faa9b3e7 TC |
3474 | |
3475 | void | |
1592522f | 3476 | i_getcolors(im, index, count=1) |
faa9b3e7 TC |
3477 | Imager::ImgRaw im |
3478 | int index | |
1592522f | 3479 | int count |
faa9b3e7 TC |
3480 | PREINIT: |
3481 | i_color *colors; | |
faa9b3e7 TC |
3482 | int i; |
3483 | PPCODE: | |
faa9b3e7 TC |
3484 | if (count < 1) |
3485 | croak("i_getcolors: count must be positive"); | |
1592522f | 3486 | colors = malloc_temp(aTHX_ sizeof(i_color) * count); |
faa9b3e7 | 3487 | if (i_getcolors(im, index, colors, count)) { |
1592522f | 3488 | EXTEND(SP, count); |
faa9b3e7 | 3489 | for (i = 0; i < count; ++i) { |
5e9a7fbd | 3490 | SV *sv = make_i_color_sv(aTHX_ colors+i); |
faa9b3e7 TC |
3491 | PUSHs(sv); |
3492 | } | |
3493 | } | |
faa9b3e7 | 3494 | |
a659442a | 3495 | undef_neg_int |
faa9b3e7 TC |
3496 | i_colorcount(im) |
3497 | Imager::ImgRaw im | |
faa9b3e7 | 3498 | |
a659442a | 3499 | undef_neg_int |
faa9b3e7 TC |
3500 | i_maxcolors(im) |
3501 | Imager::ImgRaw im | |
faa9b3e7 | 3502 | |
0862f397 | 3503 | i_palidx |
faa9b3e7 TC |
3504 | i_findcolor(im, color) |
3505 | Imager::ImgRaw im | |
3506 | Imager::Color color | |
faa9b3e7 | 3507 | CODE: |
0862f397 TC |
3508 | if (!i_findcolor(im, color, &RETVAL)) { |
3509 | XSRETURN_UNDEF; | |
faa9b3e7 | 3510 | } |
a659442a TC |
3511 | OUTPUT: |
3512 | RETVAL | |
faa9b3e7 TC |
3513 | |
3514 | int | |
3515 | i_img_bits(im) | |
3516 | Imager::ImgRaw im | |
3517 | ||
3518 | int | |
3519 | i_img_type(im) | |
3520 | Imager::ImgRaw im | |
3521 | ||
3522 | int | |
3523 | i_img_virtual(im) | |
3524 | Imager::ImgRaw im | |
3525 | ||
3526 | void | |
6a9807e8 | 3527 | i_gsamp(im, l, r, y, channels) |
faa9b3e7 | 3528 | Imager::ImgRaw im |
8d14daab TC |
3529 | i_img_dim l |
3530 | i_img_dim r | |
3531 | i_img_dim y | |
6a9807e8 | 3532 | i_channel_list channels |
faa9b3e7 | 3533 | PREINIT: |
faa9b3e7 | 3534 | i_sample_t *data; |
8d14daab | 3535 | i_img_dim count, i; |
faa9b3e7 | 3536 | PPCODE: |
faa9b3e7 | 3537 | if (l < r) { |
f37708ce | 3538 | data = mymalloc(sizeof(i_sample_t) * (r-l) * channels.count); |
6a9807e8 | 3539 | count = i_gsamp(im, l, r, y, data, channels.channels, channels.count); |
faa9b3e7 TC |
3540 | if (GIMME_V == G_ARRAY) { |
3541 | EXTEND(SP, count); | |
3542 | for (i = 0; i < count; ++i) | |
3543 | PUSHs(sv_2mortal(newSViv(data[i]))); | |
3544 | } | |
3545 | else { | |
3546 | EXTEND(SP, 1); | |
26fd367b | 3547 | PUSHs(sv_2mortal(newSVpv((char *)data, count * sizeof(i_sample_t)))); |
faa9b3e7 | 3548 | } |
a73aeb5f | 3549 | myfree(data); |
faa9b3e7 TC |
3550 | } |
3551 | else { | |
3552 | if (GIMME_V != G_ARRAY) { | |
f37708ce | 3553 | XSRETURN_UNDEF; |
faa9b3e7 TC |
3554 | } |
3555 | } | |
3556 | ||
bd8052a6 | 3557 | undef_neg_int |
6a9807e8 | 3558 | i_gsamp_bits(im, l, r, y, bits, target, offset, channels) |
bd8052a6 | 3559 | Imager::ImgRaw im |
8d14daab TC |
3560 | i_img_dim l |
3561 | i_img_dim r | |
3562 | i_img_dim y | |
bd8052a6 TC |
3563 | int bits |
3564 | AV *target | |
8d14daab | 3565 | STRLEN offset |
6a9807e8 | 3566 | i_channel_list channels |
bd8052a6 | 3567 | PREINIT: |
bd8052a6 | 3568 | unsigned *data; |
8d14daab | 3569 | i_img_dim count, i; |
bd8052a6 TC |
3570 | CODE: |
3571 | i_clear_error(); | |
3572 | if (items < 8) | |
3573 | croak("No channel numbers supplied to g_samp()"); | |
3574 | if (l < r) { | |
6a9807e8 TC |
3575 | data = mymalloc(sizeof(unsigned) * (r-l) * channels.count); |
3576 | count = i_gsamp_bits(im, l, r, y, data, channels.channels, channels.count, bits); | |
bd8052a6 TC |
3577 | for (i = 0; i < count; ++i) { |
3578 | av_store(target, i+offset, newSVuv(data[i])); | |
3579 | } | |
3580 | myfree(data); | |
3581 | RETVAL = count; | |
3582 | } | |
3583 | else { | |
3584 | RETVAL = 0; | |
3585 | } | |
3586 | OUTPUT: | |
3587 | RETVAL | |
3588 | ||
3589 | undef_neg_int | |
6a9807e8 | 3590 | i_psamp_bits(im, l, y, bits, channels, data_av, data_offset = 0, pixel_count = -1) |
bd8052a6 | 3591 | Imager::ImgRaw im |
8d14daab TC |
3592 | i_img_dim l |
3593 | i_img_dim y | |
bd8052a6 | 3594 | int bits |
6a9807e8 | 3595 | i_channel_list channels |
bd8052a6 | 3596 | AV *data_av |
848b7f32 TC |
3597 | i_img_dim data_offset |
3598 | i_img_dim pixel_count | |
bd8052a6 | 3599 | PREINIT: |
8d14daab TC |
3600 | STRLEN data_count; |
3601 | size_t data_used; | |
bd8052a6 | 3602 | unsigned *data; |
8d14daab | 3603 | ptrdiff_t i; |
bd8052a6 TC |
3604 | CODE: |
3605 | i_clear_error(); | |
bd8052a6 TC |
3606 | |
3607 | data_count = av_len(data_av) + 1; | |
3608 | if (data_offset < 0) { | |
848b7f32 | 3609 | croak("data_offset must be non-negative"); |
bd8052a6 TC |
3610 | } |
3611 | if (data_offset > data_count) { | |
3612 | croak("data_offset greater than number of samples supplied"); | |
3613 | } | |
3614 | if (pixel_count == -1 || | |
6a9807e8 TC |
3615 | data_offset + pixel_count * channels.count > data_count) { |
3616 | pixel_count = (data_count - data_offset) / channels.count; | |
bd8052a6 TC |
3617 | } |
3618 | ||
6a9807e8 | 3619 | data_used = pixel_count * channels.count; |
bd8052a6 TC |
3620 | data = mymalloc(sizeof(unsigned) * data_count); |
3621 | for (i = 0; i < data_used; ++i) | |
3622 | data[i] = SvUV(*av_fetch(data_av, data_offset + i, 0)); | |
3623 | ||
6a9807e8 TC |
3624 | RETVAL = i_psamp_bits(im, l, l + pixel_count, y, data, channels.channels, |
3625 | channels.count, bits); | |
bd8052a6 TC |
3626 | |
3627 | if (data) | |
3628 | myfree(data); | |
bd8052a6 TC |
3629 | OUTPUT: |
3630 | RETVAL | |
a73aeb5f | 3631 | |
48b9a7bf | 3632 | undef_neg_int |
848b7f32 | 3633 | i_psamp(im, x, y, channels, data, offset = 0, width = -1) |
48b9a7bf TC |
3634 | Imager::ImgRaw im |
3635 | i_img_dim x | |
3636 | i_img_dim y | |
3637 | i_channel_list channels | |
3638 | i_sample_list data | |
848b7f32 TC |
3639 | i_img_dim offset |
3640 | i_img_dim width | |
48b9a7bf TC |
3641 | PREINIT: |
3642 | i_img_dim r; | |
3643 | CODE: | |
48b9a7bf | 3644 | i_clear_error(); |
848b7f32 TC |
3645 | if (offset < 0) { |
3646 | i_push_error(0, "offset must be non-negative"); | |
3647 | XSRETURN_UNDEF; | |
3648 | } | |
3649 | if (offset > 0) { | |
3650 | if (offset > data.count) { | |
3651 | i_push_error(0, "offset greater than number of samples supplied"); | |
3652 | XSRETURN_UNDEF; | |
3653 | } | |
3654 | data.samples += offset; | |
3655 | data.count -= offset; | |
3656 | } | |
3657 | if (width == -1 || | |
3658 | width * channels.count > data.count) { | |
3659 | width = data.count / channels.count; | |
3660 | } | |
3661 | r = x + width; | |
48b9a7bf TC |
3662 | RETVAL = i_psamp(im, x, r, y, data.samples, channels.channels, channels.count); |
3663 | OUTPUT: | |
3664 | RETVAL | |
3665 | ||
3666 | undef_neg_int | |
848b7f32 | 3667 | i_psampf(im, x, y, channels, data, offset = 0, width = -1) |
48b9a7bf TC |
3668 | Imager::ImgRaw im |
3669 | i_img_dim x | |
3670 | i_img_dim y | |
3671 | i_channel_list channels | |
3672 | i_fsample_list data | |
848b7f32 TC |
3673 | i_img_dim offset |
3674 | i_img_dim width | |
48b9a7bf TC |
3675 | PREINIT: |
3676 | i_img_dim r; | |
3677 | CODE: | |
48b9a7bf | 3678 | i_clear_error(); |
848b7f32 TC |
3679 | if (offset < 0) { |
3680 | i_push_error(0, "offset must be non-negative"); | |
3681 | XSRETURN_UNDEF; | |
3682 | } | |
3683 | if (offset > 0) { | |
3684 | if (offset > data.count) { | |
3685 | i_push_error(0, "offset greater than number of samples supplied"); | |
3686 | XSRETURN_UNDEF; | |
3687 | } | |
3688 | data.samples += offset; | |
3689 | data.count -= offset; | |
3690 | } | |
3691 | if (width == -1 || | |
3692 | width * channels.count > data.count) { | |
3693 | width = data.count / channels.count; | |
3694 | } | |
3695 | r = x + width; | |
48b9a7bf TC |
3696 | RETVAL = i_psampf(im, x, r, y, data.samples, channels.channels, channels.count); |
3697 | OUTPUT: | |
3698 | RETVAL | |
3699 | ||
faa9b3e7 TC |
3700 | Imager::ImgRaw |
3701 | i_img_masked_new(targ, mask, x, y, w, h) | |
3702 | Imager::ImgRaw targ | |
8d14daab TC |
3703 | i_img_dim x |
3704 | i_img_dim y | |
3705 | i_img_dim w | |
3706 | i_img_dim h | |
faa9b3e7 TC |
3707 | PREINIT: |
3708 | i_img *mask; | |
3709 | CODE: | |
3710 | if (SvOK(ST(1))) { | |
3711 | if (!sv_isobject(ST(1)) | |
3712 | || !sv_derived_from(ST(1), "Imager::ImgRaw")) { | |
3713 | croak("i_img_masked_new: parameter 2 must undef or an image"); | |
3714 | } | |
4c4c2ffd | 3715 | mask = INT2PTR(i_img *, SvIV((SV *)SvRV(ST(1)))); |
faa9b3e7 TC |
3716 | } |
3717 | else | |
3718 | mask = NULL; | |
3719 | RETVAL = i_img_masked_new(targ, mask, x, y, w, h); | |
3720 | OUTPUT: | |
3721 | RETVAL | |
3722 | ||
3723 | int | |
3724 | i_plin(im, l, y, ...) | |
3725 | Imager::ImgRaw im | |
8d14daab TC |
3726 | i_img_dim l |
3727 | i_img_dim y | |
faa9b3e7 TC |
3728 | PREINIT: |
3729 | i_color *work; | |
8d14daab | 3730 | STRLEN i; |
ca4d914e | 3731 | STRLEN len; |
8d14daab | 3732 | size_t count; |
faa9b3e7 TC |
3733 | CODE: |
3734 | if (items > 3) { | |
ca4d914e TC |
3735 | if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) { |
3736 | /* supplied as a byte string */ | |
3737 | work = (i_color *)SvPV(ST(3), len); | |
3738 | count = len / sizeof(i_color); | |
3739 | if (count * sizeof(i_color) != len) { | |
3740 | croak("i_plin: length of scalar argument must be multiple of sizeof i_color"); | |
faa9b3e7 | 3741 | } |
ca4d914e TC |
3742 | RETVAL = i_plin(im, l, l+count, y, work); |
3743 | } | |
3744 | else { | |
3745 | work = mymalloc(sizeof(i_color) * (items-3)); | |
3746 | for (i=0; i < items-3; ++i) { | |
3747 | if (sv_isobject(ST(i+3)) | |
3748 | && sv_derived_from(ST(i+3), "Imager::Color")) { | |
3749 | IV tmp = SvIV((SV *)SvRV(ST(i+3))); | |
3750 | work[i] = *INT2PTR(i_color *, tmp); | |
3751 | } | |
3752 | else { | |
3753 | myfree(work); | |
3754 | croak("i_plin: pixels must be Imager::Color objects"); | |
3755 | } | |
faa9b3e7 | 3756 | } |
ca4d914e TC |
3757 | RETVAL = i_plin(im, l, l+items-3, y, work); |
3758 | myfree(work); | |
faa9b3e7 | 3759 | } |
faa9b3e7 TC |
3760 | } |
3761 | else { | |
3762 | RETVAL = 0; | |
3763 | } | |
3764 | OUTPUT: | |
3765 | RETVAL | |
3766 | ||
3767 | int | |
3768 | i_ppixf(im, x, y, cl) | |
3769 | Imager::ImgRaw im | |
8d14daab TC |
3770 | i_img_dim x |
3771 | i_img_dim y | |
faa9b3e7 TC |
3772 | Imager::Color::Float cl |
3773 | ||
3774 | void | |
6a9807e8 | 3775 | i_gsampf(im, l, r, y, channels) |
faa9b3e7 | 3776 | Imager::ImgRaw im |
8d14daab TC |
3777 | i_img_dim l |
3778 | i_img_dim r | |
3779 | i_img_dim y | |
6a9807e8 | 3780 | i_channel_list channels |
faa9b3e7 | 3781 | PREINIT: |
faa9b3e7 | 3782 | i_fsample_t *data; |
8d14daab | 3783 | i_img_dim count, i; |
faa9b3e7 | 3784 | PPCODE: |
faa9b3e7 | 3785 | if (l < r) { |
6a9807e8 TC |
3786 | data = mymalloc(sizeof(i_fsample_t) * (r-l) * channels.count); |
3787 | count = i_gsampf(im, l, r, y, data, channels.channels, channels.count); | |
faa9b3e7 TC |
3788 | if (GIMME_V == G_ARRAY) { |
3789 | EXTEND(SP, count); | |
3790 | for (i = 0; i < count; ++i) | |
3791 | PUSHs(sv_2mortal(newSVnv(data[i]))); | |
3792 | } | |
3793 | else { | |
3794 | EXTEND(SP, 1); | |
3795 | PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t)))); | |
3796 | } | |
3631271b | 3797 | myfree(data); |
faa9b3e7 TC |
3798 | } |
3799 | else { | |
3800 | if (GIMME_V != G_ARRAY) { | |
5736f588 | 3801 | XSRETURN_UNDEF; |
faa9b3e7 TC |
3802 | } |
3803 | } | |
3804 | ||
3805 | int | |
3806 | i_plinf(im, l, y, ...) | |
3807 | Imager::ImgRaw im | |
8d14daab TC |
3808 | i_img_dim l |
3809 | i_img_dim y | |
faa9b3e7 TC |
3810 | PREINIT: |
3811 | i_fcolor *work; | |
8d14daab | 3812 | i_img_dim i; |
ca4d914e | 3813 | STRLEN len; |
8d14daab | 3814 | size_t count; |
faa9b3e7 TC |
3815 | CODE: |
3816 | if (items > 3) { | |
ca4d914e TC |
3817 | if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) { |
3818 | /* supplied as a byte string */ | |
3819 | work = (i_fcolor *)SvPV(ST(3), len); | |
3820 | count = len / sizeof(i_fcolor); | |
3821 | if (count * sizeof(i_fcolor) != len) { | |
3822 | croak("i_plin: length of scalar argument must be multiple of sizeof i_fcolor"); | |
faa9b3e7 | 3823 | } |
ca4d914e TC |
3824 | RETVAL = i_plinf(im, l, l+count, y, work); |
3825 | } | |
3826 | else { | |
3827 | work = mymalloc(sizeof(i_fcolor) * (items-3)); | |
3828 | for (i=0; i < items-3; ++i) { | |
3829 | if (sv_isobject(ST(i+3)) | |
3830 | && sv_derived_from(ST(i+3), "Imager::Color::Float")) { | |
3831 | IV tmp = SvIV((SV *)SvRV(ST(i+3))); | |
3832 | work[i] = *INT2PTR(i_fcolor *, tmp); | |
3833 | } | |
3834 | else { | |
3835 | myfree(work); | |
3836 | croak("i_plinf: pixels must be Imager::Color::Float objects"); | |
3837 | } | |
faa9b3e7 | 3838 | } |
ca4d914e TC |
3839 | /**(char *)0 = 1;*/ |
3840 | RETVAL = i_plinf(im, l, l+items-3, y, work); | |
3841 | myfree(work); | |
faa9b3e7 | 3842 | } |
faa9b3e7 TC |
3843 | } |
3844 | else { | |
3845 | RETVAL = 0; | |
3846 | } | |
3847 | OUTPUT: | |
3848 | RETVAL | |
3849 | ||
73d80423 | 3850 | Imager::Color::Float |
faa9b3e7 TC |
3851 | i_gpixf(im, x, y) |
3852 | Imager::ImgRaw im | |
8d14daab TC |
3853 | i_img_dim x |
3854 | i_img_dim y; | |
faa9b3e7 | 3855 | CODE: |
73d80423 | 3856 | RETVAL = (i_fcolor *)mymalloc(sizeof(i_fcolor)); |
2ea4aa42 | 3857 | memset(RETVAL, 0, sizeof(*RETVAL)); |
73d80423 TC |
3858 | if (i_gpixf(im, x, y, RETVAL) != 0) { |
3859 | myfree(RETVAL); | |
3860 | XSRETURN_UNDEF; | |
faa9b3e7 | 3861 | } |
a659442a TC |
3862 | OUTPUT: |
3863 | RETVAL | |
3864 | ||
faa9b3e7 TC |
3865 | void |
3866 | i_glin(im, l, r, y) | |
3867 | Imager::ImgRaw im | |
8d14daab TC |
3868 | i_img_dim l |
3869 | i_img_dim r | |
3870 | i_img_dim y | |
faa9b3e7 TC |
3871 | PREINIT: |
3872 | i_color *vals; | |
8d14daab | 3873 | i_img_dim count, i; |
faa9b3e7 TC |
3874 | PPCODE: |
3875 | if (l < r) { | |
3876 | vals = mymalloc((r-l) * sizeof(i_color)); | |
b3aa972f | 3877 | memset(vals, 0, (r-l) * sizeof(i_color)); |
faa9b3e7 | 3878 | count = i_glin(im, l, r, y, vals); |
ca4d914e TC |
3879 | if (GIMME_V == G_ARRAY) { |
3880 | EXTEND(SP, count); | |
3881 | for (i = 0; i < count; ++i) { | |
5e9a7fbd | 3882 | SV *sv = make_i_color_sv(aTHX_ vals+i); |
ca4d914e TC |
3883 | PUSHs(sv); |
3884 | } | |
3885 | } | |
3886 | else if (count) { | |
3887 | EXTEND(SP, 1); | |
3888 | PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_color)))); | |
faa9b3e7 TC |
3889 | } |
3890 | myfree(vals); | |
3891 | } | |
3892 | ||
3893 | void | |
3894 | i_glinf(im, l, r, y) | |
3895 | Imager::ImgRaw im | |
8d14daab TC |
3896 | i_img_dim l |
3897 | i_img_dim r | |
3898 | i_img_dim y | |
faa9b3e7 TC |
3899 | PREINIT: |
3900 | i_fcolor *vals; | |
8d14daab | 3901 | i_img_dim count, i; |
919e0000 | 3902 | i_fcolor zero; |
faa9b3e7 | 3903 | PPCODE: |
919e0000 TC |
3904 | for (i = 0; i < MAXCHANNELS; ++i) |
3905 | zero.channel[i] = 0; | |
faa9b3e7 TC |
3906 | if (l < r) { |
3907 | vals = mymalloc((r-l) * sizeof(i_fcolor)); | |
b3aa972f TC |
3908 | for (i = 0; i < r-l; ++i) |
3909 | vals[i] = zero; | |
faa9b3e7 | 3910 | count = i_glinf(im, l, r, y, vals); |
ca4d914e TC |
3911 | if (GIMME_V == G_ARRAY) { |
3912 | EXTEND(SP, count); | |
3913 | for (i = 0; i < count; ++i) { | |
3914 | SV *sv; | |
3915 | i_fcolor *col = mymalloc(sizeof(i_fcolor)); | |
3916 | *col = vals[i]; | |
3917 | sv = sv_newmortal(); | |
3918 | sv_setref_pv(sv, "Imager::Color::Float", (void *)col); | |
3919 | PUSHs(sv); | |
3920 | } | |
3921 | } | |
3922 | else if (count) { | |
3923 | EXTEND(SP, 1); | |
3924 | PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_fcolor)))); | |
faa9b3e7 TC |
3925 | } |