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 | ||
02d1d628 AMH |
1140 | MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_ |
1141 | ||
1142 | Imager::Color | |
1143 | ICL_new_internal(r,g,b,a) | |
1144 | unsigned char r | |
1145 | unsigned char g | |
1146 | unsigned char b | |
1147 | unsigned char a | |
1148 | ||
1149 | void | |
1150 | ICL_DESTROY(cl) | |
1151 | Imager::Color cl | |
1152 | ||
1153 | ||
29106a11 | 1154 | void |
02d1d628 AMH |
1155 | ICL_set_internal(cl,r,g,b,a) |
1156 | Imager::Color cl | |
1157 | unsigned char r | |
1158 | unsigned char g | |
1159 | unsigned char b | |
1160 | unsigned char a | |
29106a11 | 1161 | PPCODE: |
b7346865 TC |
1162 | cl->rgba.r = r; |
1163 | cl->rgba.g = g; | |
1164 | cl->rgba.b = b; | |
1165 | cl->rgba.a = a; | |
29106a11 TC |
1166 | EXTEND(SP, 1); |
1167 | PUSHs(ST(0)); | |
02d1d628 AMH |
1168 | |
1169 | void | |
1170 | ICL_info(cl) | |
1171 | Imager::Color cl | |
1172 | ||
1173 | ||
1174 | void | |
1175 | ICL_rgba(cl) | |
1176 | Imager::Color cl | |
1177 | PPCODE: | |
1178 | EXTEND(SP, 4); | |
b482243a TC |
1179 | PUSHs(sv_2mortal(newSViv(cl->rgba.r))); |
1180 | PUSHs(sv_2mortal(newSViv(cl->rgba.g))); | |
1181 | PUSHs(sv_2mortal(newSViv(cl->rgba.b))); | |
1182 | PUSHs(sv_2mortal(newSViv(cl->rgba.a))); | |
02d1d628 | 1183 | |
efdc2568 TC |
1184 | Imager::Color |
1185 | i_hsv_to_rgb(c) | |
1186 | Imager::Color c | |
1187 | CODE: | |
1188 | RETVAL = mymalloc(sizeof(i_color)); | |
1189 | *RETVAL = *c; | |
1190 | i_hsv_to_rgb(RETVAL); | |
1191 | OUTPUT: | |
1192 | RETVAL | |
1193 | ||
1194 | Imager::Color | |
1195 | i_rgb_to_hsv(c) | |
1196 | Imager::Color c | |
1197 | CODE: | |
1198 | RETVAL = mymalloc(sizeof(i_color)); | |
1199 | *RETVAL = *c; | |
1200 | i_rgb_to_hsv(RETVAL); | |
1201 | OUTPUT: | |
1202 | RETVAL | |
1203 | ||
02d1d628 AMH |
1204 | |
1205 | ||
faa9b3e7 | 1206 | MODULE = Imager PACKAGE = Imager::Color::Float PREFIX=ICLF_ |
02d1d628 | 1207 | |
faa9b3e7 TC |
1208 | Imager::Color::Float |
1209 | ICLF_new_internal(r, g, b, a) | |
1210 | double r | |
1211 | double g | |
1212 | double b | |
1213 | double a | |
1214 | ||
1215 | void | |
1216 | ICLF_DESTROY(cl) | |
1217 | Imager::Color::Float cl | |
02d1d628 | 1218 | |
faa9b3e7 TC |
1219 | void |
1220 | ICLF_rgba(cl) | |
1221 | Imager::Color::Float cl | |
1222 | PREINIT: | |
1223 | int ch; | |
1224 | PPCODE: | |
1225 | EXTEND(SP, MAXCHANNELS); | |
1226 | for (ch = 0; ch < MAXCHANNELS; ++ch) { | |
1227 | /* printf("%d: %g\n", ch, cl->channel[ch]); */ | |
1228 | PUSHs(sv_2mortal(newSVnv(cl->channel[ch]))); | |
1229 | } | |
1230 | ||
1231 | void | |
1232 | ICLF_set_internal(cl,r,g,b,a) | |
1233 | Imager::Color::Float cl | |
1234 | double r | |
1235 | double g | |
1236 | double b | |
1237 | double a | |
1238 | PPCODE: | |
1239 | cl->rgba.r = r; | |
1240 | cl->rgba.g = g; | |
1241 | cl->rgba.b = b; | |
1242 | cl->rgba.a = a; | |
1243 | EXTEND(SP, 1); | |
1244 | PUSHs(ST(0)); | |
02d1d628 | 1245 | |
efdc2568 TC |
1246 | Imager::Color::Float |
1247 | i_hsv_to_rgb(c) | |
1248 | Imager::Color::Float c | |
1249 | CODE: | |
1250 | RETVAL = mymalloc(sizeof(i_fcolor)); | |
1251 | *RETVAL = *c; | |
1252 | i_hsv_to_rgbf(RETVAL); | |
1253 | OUTPUT: | |
1254 | RETVAL | |
1255 | ||
1256 | Imager::Color::Float | |
1257 | i_rgb_to_hsv(c) | |
1258 | Imager::Color::Float c | |
1259 | CODE: | |
1260 | RETVAL = mymalloc(sizeof(i_fcolor)); | |
1261 | *RETVAL = *c; | |
1262 | i_rgb_to_hsvf(RETVAL); | |
1263 | OUTPUT: | |
1264 | RETVAL | |
efdc2568 | 1265 | |
02d1d628 AMH |
1266 | MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_ |
1267 | ||
1268 | Imager::ImgRaw | |
1269 | IIM_new(x,y,ch) | |
8d14daab TC |
1270 | i_img_dim x |
1271 | i_img_dim y | |
02d1d628 AMH |
1272 | int ch |
1273 | ||
1274 | void | |
1275 | IIM_DESTROY(im) | |
1276 | Imager::ImgRaw im | |
1277 | ||
1278 | ||
1279 | ||
1280 | MODULE = Imager PACKAGE = Imager | |
1281 | ||
1282 | PROTOTYPES: ENABLE | |
1283 | ||
1284 | ||
1285 | Imager::IO | |
1286 | io_new_fd(fd) | |
1287 | int fd | |
1288 | ||
1289 | Imager::IO | |
1290 | io_new_bufchain() | |
1291 | ||
1292 | ||
4dfa5522 | 1293 | Imager::IO |
6d5c85a2 TC |
1294 | io_new_buffer(data_sv) |
1295 | SV *data_sv | |
4dfa5522 | 1296 | CODE: |
a87997b2 | 1297 | i_clear_error(); |
6d5c85a2 | 1298 | RETVAL = do_io_new_buffer(aTHX_ data_sv); |
a87997b2 TC |
1299 | if (!RETVAL) |
1300 | XSRETURN(0); | |
4dfa5522 AMH |
1301 | OUTPUT: |
1302 | RETVAL | |
10461f9a TC |
1303 | |
1304 | Imager::IO | |
1305 | io_new_cb(writecb, readcb, seekcb, closecb, maxwrite = CBDATA_BUFSIZE) | |
1306 | SV *writecb; | |
1307 | SV *readcb; | |
1308 | SV *seekcb; | |
1309 | SV *closecb; | |
10461f9a | 1310 | CODE: |
6d5c85a2 | 1311 | RETVAL = do_io_new_cb(aTHX_ writecb, readcb, seekcb, closecb); |
10461f9a TC |
1312 | OUTPUT: |
1313 | RETVAL | |
4dfa5522 | 1314 | |
6d5c85a2 | 1315 | SV * |
02d1d628 AMH |
1316 | io_slurp(ig) |
1317 | Imager::IO ig | |
1318 | PREINIT: | |
1319 | unsigned char* data; | |
4dfa5522 | 1320 | size_t tlength; |
6d5c85a2 | 1321 | CODE: |
02d1d628 AMH |
1322 | data = NULL; |
1323 | tlength = io_slurp(ig, &data); | |
6d5c85a2 | 1324 | RETVAL = newSVpv((char *)data,tlength); |
02d1d628 | 1325 | myfree(data); |
6d5c85a2 TC |
1326 | OUTPUT: |
1327 | RETVAL | |
02d1d628 AMH |
1328 | |
1329 | ||
77157728 TC |
1330 | undef_int |
1331 | i_set_image_file_limits(width, height, bytes) | |
8d14daab TC |
1332 | i_img_dim width |
1333 | i_img_dim height | |
1334 | size_t bytes | |
77157728 TC |
1335 | |
1336 | void | |
1337 | i_get_image_file_limits() | |
1338 | PREINIT: | |
8d14daab TC |
1339 | i_img_dim width, height; |
1340 | size_t bytes; | |
77157728 TC |
1341 | PPCODE: |
1342 | if (i_get_image_file_limits(&width, &height, &bytes)) { | |
1343 | EXTEND(SP, 3); | |
1344 | PUSHs(sv_2mortal(newSViv(width))); | |
1345 | PUSHs(sv_2mortal(newSViv(height))); | |
8d14daab | 1346 | PUSHs(sv_2mortal(newSVuv(bytes))); |
77157728 TC |
1347 | } |
1348 | ||
e1558ffe TC |
1349 | bool |
1350 | i_int_check_image_file_limits(width, height, channels, sample_size) | |
1351 | i_img_dim width | |
1352 | i_img_dim height | |
1353 | int channels | |
1354 | size_t sample_size | |
1355 | PROTOTYPE: DISABLE | |
1356 | ||
6d5c85a2 TC |
1357 | MODULE = Imager PACKAGE = Imager::IO PREFIX = io_ |
1358 | ||
1359 | Imager::IO | |
1360 | io_new_fd(class, fd) | |
1361 | int fd | |
1362 | CODE: | |
1363 | RETVAL = io_new_fd(fd); | |
1364 | OUTPUT: | |
1365 | RETVAL | |
1366 | ||
1367 | Imager::IO | |
1368 | io_new_buffer(class, data_sv) | |
1369 | SV *data_sv | |
1370 | CODE: | |
a87997b2 | 1371 | i_clear_error(); |
6d5c85a2 | 1372 | RETVAL = do_io_new_buffer(aTHX_ data_sv); |
a87997b2 TC |
1373 | if (!RETVAL) |
1374 | XSRETURN(0); | |
6d5c85a2 TC |
1375 | OUTPUT: |
1376 | RETVAL | |
1377 | ||
1378 | Imager::IO | |
1379 | io_new_cb(class, writecb, readcb, seekcb, closecb) | |
1380 | SV *writecb; | |
1381 | SV *readcb; | |
1382 | SV *seekcb; | |
1383 | SV *closecb; | |
1384 | CODE: | |
1385 | RETVAL = do_io_new_cb(aTHX_ writecb, readcb, seekcb, closecb); | |
1386 | OUTPUT: | |
1387 | RETVAL | |
1388 | ||
1389 | Imager::IO | |
1390 | io_new_bufchain(class) | |
1391 | CODE: | |
1392 | RETVAL = io_new_bufchain(); | |
1393 | OUTPUT: | |
1394 | RETVAL | |
1395 | ||
52d990d6 TC |
1396 | Imager::IO |
1397 | io__new_perlio(class, io) | |
1398 | PerlIO *io | |
1399 | CODE: | |
1400 | RETVAL = im_io_new_perlio(aTHX_ io); | |
1401 | OUTPUT: | |
1402 | RETVAL | |
1403 | ||
6d5c85a2 TC |
1404 | SV * |
1405 | io_slurp(class, ig) | |
1406 | Imager::IO ig | |
1407 | PREINIT: | |
1408 | unsigned char* data; | |
1409 | size_t tlength; | |
1410 | CODE: | |
1411 | data = NULL; | |
1412 | tlength = io_slurp(ig, &data); | |
1413 | RETVAL = newSVpv((char *)data,tlength); | |
1414 | myfree(data); | |
1415 | OUTPUT: | |
1416 | RETVAL | |
1417 | ||
eda1622c TC |
1418 | MODULE = Imager PACKAGE = Imager::IO PREFIX = i_io_ |
1419 | ||
6d5c85a2 TC |
1420 | IV |
1421 | i_io_raw_write(ig, data_sv) | |
eda1622c TC |
1422 | Imager::IO ig |
1423 | SV *data_sv | |
1424 | PREINIT: | |
1425 | void *data; | |
1426 | STRLEN size; | |
1427 | CODE: | |
40a88898 | 1428 | data = SvPVbyte(data_sv, size); |
6d5c85a2 | 1429 | RETVAL = i_io_raw_write(ig, data, size); |
eda1622c TC |
1430 | OUTPUT: |
1431 | RETVAL | |
1432 | ||
1f6c1c10 | 1433 | void |
6d5c85a2 | 1434 | i_io_raw_read(ig, buffer_sv, size) |
eda1622c TC |
1435 | Imager::IO ig |
1436 | SV *buffer_sv | |
8d14daab | 1437 | IV size |
eda1622c TC |
1438 | PREINIT: |
1439 | void *buffer; | |
8d14daab | 1440 | ssize_t result; |
1f6c1c10 TC |
1441 | PPCODE: |
1442 | if (size <= 0) | |
6d5c85a2 | 1443 | croak("size negative in call to i_io_raw_read()"); |
d1442cc4 TC |
1444 | /* prevent an undefined value warning if they supplied an |
1445 | undef buffer. | |
1446 | Orginally conditional on !SvOK(), but this will prevent the | |
1447 | downgrade from croaking */ | |
1448 | sv_setpvn(buffer_sv, "", 0); | |
1449 | #ifdef SvUTF8 | |
1450 | if (SvUTF8(buffer_sv)) | |
1451 | sv_utf8_downgrade(buffer_sv, FALSE); | |
1452 | #endif | |
eda1622c | 1453 | buffer = SvGROW(buffer_sv, size+1); |
6d5c85a2 | 1454 | result = i_io_raw_read(ig, buffer, size); |
1f6c1c10 TC |
1455 | if (result >= 0) { |
1456 | SvCUR_set(buffer_sv, result); | |
1457 | *SvEND(buffer_sv) = '\0'; | |
1458 | SvPOK_only(buffer_sv); | |
1459 | EXTEND(SP, 1); | |
1460 | PUSHs(sv_2mortal(newSViv(result))); | |
eda1622c | 1461 | } |
1f6c1c10 TC |
1462 | ST(1) = buffer_sv; |
1463 | SvSETMAGIC(ST(1)); | |
1464 | ||
1465 | void | |
6d5c85a2 | 1466 | i_io_raw_read2(ig, size) |
1f6c1c10 | 1467 | Imager::IO ig |
8d14daab | 1468 | IV size |
1f6c1c10 TC |
1469 | PREINIT: |
1470 | SV *buffer_sv; | |
1471 | void *buffer; | |
8d14daab | 1472 | ssize_t result; |
1f6c1c10 TC |
1473 | PPCODE: |
1474 | if (size <= 0) | |
1475 | croak("size negative in call to i_io_read2()"); | |
1476 | buffer_sv = newSV(size); | |
1477 | buffer = SvGROW(buffer_sv, size+1); | |
6d5c85a2 | 1478 | result = i_io_raw_read(ig, buffer, size); |
1f6c1c10 | 1479 | if (result >= 0) { |
eda1622c TC |
1480 | SvCUR_set(buffer_sv, result); |
1481 | *SvEND(buffer_sv) = '\0'; | |
1482 | SvPOK_only(buffer_sv); | |
1f6c1c10 TC |
1483 | EXTEND(SP, 1); |
1484 | PUSHs(sv_2mortal(buffer_sv)); | |
eda1622c | 1485 | } |
1f6c1c10 TC |
1486 | else { |
1487 | /* discard it */ | |
1488 | SvREFCNT_dec(buffer_sv); | |
1489 | } | |
eda1622c | 1490 | |
8d14daab | 1491 | off_t |
6d5c85a2 | 1492 | i_io_raw_seek(ig, position, whence) |
eda1622c | 1493 | Imager::IO ig |
8d14daab | 1494 | off_t position |
eda1622c | 1495 | int whence |
c3cc977e | 1496 | |
1f6c1c10 | 1497 | int |
6d5c85a2 | 1498 | i_io_raw_close(ig) |
eda1622c TC |
1499 | Imager::IO ig |
1500 | ||
1501 | void | |
1502 | i_io_DESTROY(ig) | |
c3cc977e AMH |
1503 | Imager::IO ig |
1504 | ||
ffddd407 TC |
1505 | int |
1506 | i_io_CLONE_SKIP(...) | |
1507 | CODE: | |
8d14daab | 1508 | (void)items; /* avoid unused warning for XS variable */ |
ffddd407 TC |
1509 | RETVAL = 1; |
1510 | OUTPUT: | |
1511 | RETVAL | |
1512 | ||
6d5c85a2 TC |
1513 | int |
1514 | i_io_getc(ig) | |
1515 | Imager::IO ig | |
1516 | ||
1517 | int | |
1518 | i_io_putc(ig, c) | |
1519 | Imager::IO ig | |
1520 | int c | |
1521 | ||
1522 | int | |
1523 | i_io_close(ig) | |
1524 | Imager::IO ig | |
1525 | ||
1526 | int | |
1527 | i_io_flush(ig) | |
1528 | Imager::IO ig | |
1529 | ||
1530 | int | |
1531 | i_io_peekc(ig) | |
1532 | Imager::IO ig | |
1533 | ||
1534 | int | |
1535 | i_io_seek(ig, off, whence) | |
1536 | Imager::IO ig | |
1537 | off_t off | |
1538 | int whence | |
1539 | ||
1540 | void | |
1541 | i_io_peekn(ig, size) | |
1542 | Imager::IO ig | |
1543 | STRLEN size | |
1544 | PREINIT: | |
1545 | SV *buffer_sv; | |
1546 | void *buffer; | |
1547 | ssize_t result; | |
1548 | PPCODE: | |
1549 | buffer_sv = newSV(size+1); | |
1550 | buffer = SvGROW(buffer_sv, size+1); | |
1551 | result = i_io_peekn(ig, buffer, size); | |
1552 | if (result >= 0) { | |
1553 | SvCUR_set(buffer_sv, result); | |
1554 | *SvEND(buffer_sv) = '\0'; | |
1555 | SvPOK_only(buffer_sv); | |
1556 | EXTEND(SP, 1); | |
1557 | PUSHs(sv_2mortal(buffer_sv)); | |
1558 | } | |
1559 | else { | |
1560 | /* discard it */ | |
1561 | SvREFCNT_dec(buffer_sv); | |
1562 | } | |
1563 | ||
1564 | void | |
1565 | i_io_read(ig, buffer_sv, size) | |
1566 | Imager::IO ig | |
1567 | SV *buffer_sv | |
1568 | IV size | |
1569 | PREINIT: | |
1570 | void *buffer; | |
1571 | ssize_t result; | |
1572 | PPCODE: | |
1573 | if (size <= 0) | |
1574 | croak("size negative in call to i_io_read()"); | |
d1442cc4 TC |
1575 | /* prevent an undefined value warning if they supplied an |
1576 | undef buffer. | |
1577 | Orginally conditional on !SvOK(), but this will prevent the | |
1578 | downgrade from croaking */ | |
1579 | sv_setpvn(buffer_sv, "", 0); | |
1580 | #ifdef SvUTF8 | |
1581 | if (SvUTF8(buffer_sv)) | |
1582 | sv_utf8_downgrade(buffer_sv, FALSE); | |
1583 | #endif | |
6d5c85a2 TC |
1584 | buffer = SvGROW(buffer_sv, size+1); |
1585 | result = i_io_read(ig, buffer, size); | |
1586 | if (result >= 0) { | |
1587 | SvCUR_set(buffer_sv, result); | |
1588 | *SvEND(buffer_sv) = '\0'; | |
1589 | SvPOK_only(buffer_sv); | |
1590 | EXTEND(SP, 1); | |
1591 | PUSHs(sv_2mortal(newSViv(result))); | |
1592 | } | |
1593 | ST(1) = buffer_sv; | |
1594 | SvSETMAGIC(ST(1)); | |
1595 | ||
1596 | void | |
1597 | i_io_read2(ig, size) | |
1598 | Imager::IO ig | |
1599 | STRLEN size | |
1600 | PREINIT: | |
1601 | SV *buffer_sv; | |
1602 | void *buffer; | |
1603 | ssize_t result; | |
1604 | PPCODE: | |
1605 | if (size == 0) | |
1606 | croak("size zero in call to read2()"); | |
1607 | buffer_sv = newSV(size); | |
1608 | buffer = SvGROW(buffer_sv, size+1); | |
1609 | result = i_io_read(ig, buffer, size); | |
1610 | if (result > 0) { | |
1611 | SvCUR_set(buffer_sv, result); | |
1612 | *SvEND(buffer_sv) = '\0'; | |
1613 | SvPOK_only(buffer_sv); | |
1614 | EXTEND(SP, 1); | |
1615 | PUSHs(sv_2mortal(buffer_sv)); | |
1616 | } | |
1617 | else { | |
1618 | /* discard it */ | |
1619 | SvREFCNT_dec(buffer_sv); | |
1620 | } | |
1621 | ||
1622 | void | |
1623 | i_io_gets(ig, size = 8192, eol = NEWLINE) | |
1624 | Imager::IO ig | |
1625 | STRLEN size | |
1626 | int eol | |
1627 | PREINIT: | |
1628 | SV *buffer_sv; | |
1629 | void *buffer; | |
1630 | ssize_t result; | |
1631 | PPCODE: | |
1632 | if (size < 2) | |
1633 | croak("size too small in call to gets()"); | |
1634 | buffer_sv = sv_2mortal(newSV(size+1)); | |
1635 | buffer = SvPVX(buffer_sv); | |
1636 | result = i_io_gets(ig, buffer, size+1, eol); | |
1637 | if (result > 0) { | |
1638 | SvCUR_set(buffer_sv, result); | |
1639 | *SvEND(buffer_sv) = '\0'; | |
1640 | SvPOK_only(buffer_sv); | |
1641 | EXTEND(SP, 1); | |
1642 | PUSHs(buffer_sv); | |
1643 | } | |
1644 | ||
1645 | IV | |
1646 | i_io_write(ig, data_sv) | |
1647 | Imager::IO ig | |
1648 | SV *data_sv | |
1649 | PREINIT: | |
1650 | void *data; | |
1651 | STRLEN size; | |
1652 | CODE: | |
40a88898 | 1653 | data = SvPVbyte(data_sv, size); |
6d5c85a2 TC |
1654 | RETVAL = i_io_write(ig, data, size); |
1655 | OUTPUT: | |
1656 | RETVAL | |
1657 | ||
1658 | void | |
1659 | i_io_dump(ig, flags = I_IO_DUMP_DEFAULT) | |
1660 | Imager::IO ig | |
1661 | int flags | |
1662 | ||
1663 | bool | |
1664 | i_io_set_buffered(ig, flag = 1) | |
1665 | Imager::IO ig | |
1666 | int flag | |
1667 | ||
1668 | bool | |
1669 | i_io_is_buffered(ig) | |
1670 | Imager::IO ig | |
1671 | ||
1672 | bool | |
1673 | i_io_eof(ig) | |
1674 | Imager::IO ig | |
1675 | ||
1676 | bool | |
1677 | i_io_error(ig) | |
1678 | Imager::IO ig | |
1679 | ||
c3cc977e AMH |
1680 | MODULE = Imager PACKAGE = Imager |
1681 | ||
1682 | PROTOTYPES: ENABLE | |
1683 | ||
02d1d628 AMH |
1684 | void |
1685 | i_list_formats() | |
1686 | PREINIT: | |
1687 | char* item; | |
1688 | int i; | |
1689 | PPCODE: | |
1690 | i=0; | |
1691 | while( (item=i_format_list[i++]) != NULL ) { | |
1692 | EXTEND(SP, 1); | |
1693 | PUSHs(sv_2mortal(newSVpv(item,0))); | |
1694 | } | |
1695 | ||
ec76939c TC |
1696 | Imager::ImgRaw |
1697 | i_sametype(im, x, y) | |
1698 | Imager::ImgRaw im | |
8d14daab TC |
1699 | i_img_dim x |
1700 | i_img_dim y | |
ec76939c TC |
1701 | |
1702 | Imager::ImgRaw | |
1703 | i_sametype_chans(im, x, y, channels) | |
1704 | Imager::ImgRaw im | |
8d14daab TC |
1705 | i_img_dim x |
1706 | i_img_dim y | |
ec76939c TC |
1707 | int channels |
1708 | ||
10ea52a3 | 1709 | int |
bd8052a6 TC |
1710 | i_init_log(name_sv,level) |
1711 | SV* name_sv | |
02d1d628 | 1712 | int level |
bd8052a6 TC |
1713 | PREINIT: |
1714 | const char *name = SvOK(name_sv) ? SvPV_nolen(name_sv) : NULL; | |
1715 | CODE: | |
10ea52a3 TC |
1716 | RETVAL = i_init_log(name, level); |
1717 | OUTPUT: | |
1718 | RETVAL | |
02d1d628 | 1719 | |
7f882a01 | 1720 | void |
bf1573f9 | 1721 | i_log_entry(string,level) |
7f882a01 AMH |
1722 | char* string |
1723 | int level | |
1724 | ||
10ea52a3 TC |
1725 | int |
1726 | i_log_enabled() | |
7f882a01 | 1727 | |
02d1d628 AMH |
1728 | void |
1729 | i_img_info(im) | |
1730 | Imager::ImgRaw im | |
1731 | PREINIT: | |
8d14daab | 1732 | i_img_dim info[4]; |
02d1d628 AMH |
1733 | PPCODE: |
1734 | i_img_info(im,info); | |
1735 | EXTEND(SP, 4); | |
1736 | PUSHs(sv_2mortal(newSViv(info[0]))); | |
1737 | PUSHs(sv_2mortal(newSViv(info[1]))); | |
1738 | PUSHs(sv_2mortal(newSViv(info[2]))); | |
1739 | PUSHs(sv_2mortal(newSViv(info[3]))); | |
1740 | ||
1741 | ||
1742 | ||
1743 | ||
1744 | void | |
1745 | i_img_setmask(im,ch_mask) | |
1746 | Imager::ImgRaw im | |
1747 | int ch_mask | |
1748 | ||
1749 | int | |
1750 | i_img_getmask(im) | |
1751 | Imager::ImgRaw im | |
1752 | ||
1753 | int | |
1754 | i_img_getchannels(im) | |
1755 | Imager::ImgRaw im | |
1756 | ||
1757 | void | |
1758 | i_img_getdata(im) | |
1759 | Imager::ImgRaw im | |
1760 | PPCODE: | |
1761 | EXTEND(SP, 1); | |
26fd367b TC |
1762 | PUSHs(im->idata ? |
1763 | sv_2mortal(newSVpv((char *)im->idata, im->bytes)) | |
faa9b3e7 | 1764 | : &PL_sv_undef); |
02d1d628 | 1765 | |
3b000586 TC |
1766 | IV |
1767 | i_img_get_width(im) | |
1768 | Imager::ImgRaw im | |
1769 | ||
1770 | IV | |
1771 | i_img_get_height(im) | |
1772 | Imager::ImgRaw im | |
1773 | ||
35db02fc TC |
1774 | int |
1775 | i_img_color_model(im) | |
1776 | Imager::ImgRaw im | |
1777 | ||
1778 | int | |
1779 | i_img_color_channels(im) | |
1780 | Imager::ImgRaw im | |
1781 | ||
1782 | int | |
1783 | i_img_alpha_channel(im) | |
1784 | Imager::ImgRaw im | |
1785 | CODE: | |
1786 | if (!i_img_alpha_channel(im, &RETVAL)) | |
1787 | XSRETURN(0); | |
1788 | OUTPUT: | |
1789 | RETVAL | |
3b000586 | 1790 | |
bd8052a6 TC |
1791 | void |
1792 | i_img_is_monochrome(im) | |
1793 | Imager::ImgRaw im | |
1794 | PREINIT: | |
1795 | int zero_is_white; | |
1796 | int result; | |
1797 | PPCODE: | |
1798 | result = i_img_is_monochrome(im, &zero_is_white); | |
1799 | if (result) { | |
1800 | if (GIMME_V == G_ARRAY) { | |
1801 | EXTEND(SP, 2); | |
1802 | PUSHs(&PL_sv_yes); | |
1803 | PUSHs(sv_2mortal(newSViv(zero_is_white))); | |
1804 | } | |
1805 | else { | |
1806 | EXTEND(SP, 1); | |
1807 | PUSHs(&PL_sv_yes); | |
1808 | } | |
1809 | } | |
02d1d628 AMH |
1810 | |
1811 | void | |
aa833c97 | 1812 | i_line(im,x1,y1,x2,y2,val,endp) |
02d1d628 | 1813 | Imager::ImgRaw im |
8d14daab TC |
1814 | i_img_dim x1 |
1815 | i_img_dim y1 | |
1816 | i_img_dim x2 | |
1817 | i_img_dim y2 | |
02d1d628 | 1818 | Imager::Color val |
aa833c97 | 1819 | int endp |
02d1d628 AMH |
1820 | |
1821 | void | |
b437ce0a | 1822 | i_line_aa(im,x1,y1,x2,y2,val,endp) |
02d1d628 | 1823 | Imager::ImgRaw im |
8d14daab TC |
1824 | i_img_dim x1 |
1825 | i_img_dim y1 | |
1826 | i_img_dim x2 | |
1827 | i_img_dim y2 | |
02d1d628 | 1828 | Imager::Color val |
b437ce0a | 1829 | int endp |
02d1d628 AMH |
1830 | |
1831 | void | |
1832 | i_box(im,x1,y1,x2,y2,val) | |
1833 | Imager::ImgRaw im | |
8d14daab TC |
1834 | i_img_dim x1 |
1835 | i_img_dim y1 | |
1836 | i_img_dim x2 | |
1837 | i_img_dim y2 | |
02d1d628 AMH |
1838 | Imager::Color val |
1839 | ||
1840 | void | |
1841 | i_box_filled(im,x1,y1,x2,y2,val) | |
1842 | Imager::ImgRaw im | |
8d14daab TC |
1843 | i_img_dim x1 |
1844 | i_img_dim y1 | |
1845 | i_img_dim x2 | |
1846 | i_img_dim y2 | |
02d1d628 AMH |
1847 | Imager::Color val |
1848 | ||
7477ff14 TC |
1849 | int |
1850 | i_box_filledf(im,x1,y1,x2,y2,val) | |
1851 | Imager::ImgRaw im | |
8d14daab TC |
1852 | i_img_dim x1 |
1853 | i_img_dim y1 | |
1854 | i_img_dim x2 | |
1855 | i_img_dim y2 | |
7477ff14 TC |
1856 | Imager::Color::Float val |
1857 | ||
f1ac5027 TC |
1858 | void |
1859 | i_box_cfill(im,x1,y1,x2,y2,fill) | |
1860 | Imager::ImgRaw im | |
8d14daab TC |
1861 | i_img_dim x1 |
1862 | i_img_dim y1 | |
1863 | i_img_dim x2 | |
1864 | i_img_dim y2 | |
f1ac5027 TC |
1865 | Imager::FillHandle fill |
1866 | ||
02d1d628 AMH |
1867 | void |
1868 | i_arc(im,x,y,rad,d1,d2,val) | |
1869 | Imager::ImgRaw im | |
8d14daab TC |
1870 | i_img_dim x |
1871 | i_img_dim y | |
1872 | double rad | |
1873 | double d1 | |
1874 | double d2 | |
02d1d628 AMH |
1875 | Imager::Color val |
1876 | ||
a8652edf TC |
1877 | void |
1878 | i_arc_aa(im,x,y,rad,d1,d2,val) | |
1879 | Imager::ImgRaw im | |
1880 | double x | |
1881 | double y | |
1882 | double rad | |
1883 | double d1 | |
1884 | double d2 | |
1885 | Imager::Color val | |
1886 | ||
f1ac5027 TC |
1887 | void |
1888 | i_arc_cfill(im,x,y,rad,d1,d2,fill) | |
1889 | Imager::ImgRaw im | |
8d14daab TC |
1890 | i_img_dim x |
1891 | i_img_dim y | |
1892 | double rad | |
1893 | double d1 | |
1894 | double d2 | |
f1ac5027 TC |
1895 | Imager::FillHandle fill |
1896 | ||
a8652edf TC |
1897 | void |
1898 | i_arc_aa_cfill(im,x,y,rad,d1,d2,fill) | |
1899 | Imager::ImgRaw im | |
1900 | double x | |
1901 | double y | |
1902 | double rad | |
1903 | double d1 | |
1904 | double d2 | |
1905 | Imager::FillHandle fill | |
02d1d628 AMH |
1906 | |
1907 | ||
6af18d2b AMH |
1908 | void |
1909 | i_circle_aa(im,x,y,rad,val) | |
1910 | Imager::ImgRaw im | |
8d14daab TC |
1911 | double x |
1912 | double y | |
1913 | double rad | |
6af18d2b AMH |
1914 | Imager::Color val |
1915 | ||
bf18ef3a TC |
1916 | void |
1917 | i_circle_aa_fill(im,x,y,rad,fill) | |
1918 | Imager::ImgRaw im | |
1919 | double x | |
1920 | double y | |
1921 | double rad | |
1922 | Imager::FillHandle fill | |
1923 | ||
40068b33 TC |
1924 | int |
1925 | i_circle_out(im,x,y,rad,val) | |
1926 | Imager::ImgRaw im | |
1927 | i_img_dim x | |
1928 | i_img_dim y | |
1929 | i_img_dim rad | |
1930 | Imager::Color val | |
1931 | ||
1932 | int | |
1933 | i_circle_out_aa(im,x,y,rad,val) | |
1934 | Imager::ImgRaw im | |
1935 | i_img_dim x | |
1936 | i_img_dim y | |
1937 | i_img_dim rad | |
1938 | Imager::Color val | |
1939 | ||
1940 | int | |
1941 | i_arc_out(im,x,y,rad,d1,d2,val) | |
1942 | Imager::ImgRaw im | |
1943 | i_img_dim x | |
1944 | i_img_dim y | |
1945 | i_img_dim rad | |
8d14daab TC |
1946 | double d1 |
1947 | double d2 | |
40068b33 TC |
1948 | Imager::Color val |
1949 | ||
1950 | int | |
1951 | i_arc_out_aa(im,x,y,rad,d1,d2,val) | |
1952 | Imager::ImgRaw im | |
1953 | i_img_dim x | |
1954 | i_img_dim y | |
1955 | i_img_dim rad | |
8d14daab TC |
1956 | double d1 |
1957 | double d2 | |
40068b33 | 1958 | Imager::Color val |
6af18d2b AMH |
1959 | |
1960 | ||
02d1d628 | 1961 | void |
987245e2 | 1962 | i_bezier_multi(im,x,y,val) |
02d1d628 | 1963 | Imager::ImgRaw im |
987245e2 TC |
1964 | double *x |
1965 | double *y | |
1966 | Imager::Color val | |
1967 | PREINIT: | |
1968 | STRLEN size_x; | |
1969 | STRLEN size_y; | |
1970 | PPCODE: | |
1971 | if (size_x != size_y) | |
1972 | croak("Imager: x and y arrays to i_bezier_multi must be equal length\n"); | |
1973 | i_bezier_multi(im,size_x,x,y,val); | |
02d1d628 | 1974 | |
1c5252ed | 1975 | int |
0d80f37e | 1976 | i_poly_aa_m(im,x,y,mode,val) |
02d1d628 | 1977 | Imager::ImgRaw im |
19e9591b TC |
1978 | double *x |
1979 | double *y | |
0d80f37e | 1980 | i_poly_fill_mode_t mode |
a54e32ba TC |
1981 | Imager::Color val |
1982 | PREINIT: | |
19e9591b TC |
1983 | STRLEN size_x; |
1984 | STRLEN size_y; | |
a54e32ba | 1985 | CODE: |
19e9591b | 1986 | if (size_x != size_y) |
a54e32ba | 1987 | croak("Imager: x and y arrays to i_poly_aa must be equal length\n"); |
0d80f37e | 1988 | RETVAL = i_poly_aa_m(im, size_x, x, y, mode, val); |
a54e32ba TC |
1989 | OUTPUT: |
1990 | RETVAL | |
02d1d628 | 1991 | |
1c5252ed | 1992 | int |
0d80f37e | 1993 | i_poly_aa_cfill_m(im, x, y, mode, fill) |
43c5dacb | 1994 | Imager::ImgRaw im |
19e9591b TC |
1995 | double *x |
1996 | double *y | |
0d80f37e | 1997 | i_poly_fill_mode_t mode |
a54e32ba TC |
1998 | Imager::FillHandle fill |
1999 | PREINIT: | |
19e9591b TC |
2000 | STRLEN size_x; |
2001 | STRLEN size_y; | |
a54e32ba | 2002 | CODE: |
19e9591b | 2003 | if (size_x != size_y) |
a54e32ba | 2004 | croak("Imager: x and y arrays to i_poly_aa_cfill must be equal length\n"); |
0d80f37e | 2005 | RETVAL = i_poly_aa_cfill_m(im, size_x, x, y, mode, fill); |
a54e32ba TC |
2006 | OUTPUT: |
2007 | RETVAL | |
02d1d628 | 2008 | |
0d80f37e TC |
2009 | int |
2010 | i_poly_poly_aa(im, polys, mode, color) | |
2011 | Imager::ImgRaw im | |
2012 | i_polygon_list polys | |
2013 | i_poly_fill_mode_t mode | |
2014 | Imager::Color color | |
2015 | CODE: | |
2016 | RETVAL = i_poly_poly_aa(im, polys.count, polys.polygons, mode, color); | |
2017 | OUTPUT: | |
2018 | RETVAL | |
2019 | ||
2020 | int | |
2021 | i_poly_poly_aa_cfill(im, polys, mode, fill) | |
2022 | Imager::ImgRaw im | |
2023 | i_polygon_list polys | |
2024 | i_poly_fill_mode_t mode | |
2025 | Imager::FillHandle fill | |
2026 | CODE: | |
2027 | RETVAL = i_poly_poly_aa_cfill(im, polys.count, polys.polygons, mode, fill); | |
2028 | OUTPUT: | |
2029 | RETVAL | |
2030 | ||
a321d497 | 2031 | undef_int |
02d1d628 AMH |
2032 | i_flood_fill(im,seedx,seedy,dcol) |
2033 | Imager::ImgRaw im | |
8d14daab TC |
2034 | i_img_dim seedx |
2035 | i_img_dim seedy | |
02d1d628 AMH |
2036 | Imager::Color dcol |
2037 | ||
a321d497 | 2038 | undef_int |
cc6483e0 TC |
2039 | i_flood_cfill(im,seedx,seedy,fill) |
2040 | Imager::ImgRaw im | |
8d14daab TC |
2041 | i_img_dim seedx |
2042 | i_img_dim seedy | |
cc6483e0 TC |
2043 | Imager::FillHandle fill |
2044 | ||
3efb0915 TC |
2045 | undef_int |
2046 | i_flood_fill_border(im,seedx,seedy,dcol, border) | |
2047 | Imager::ImgRaw im | |
8d14daab TC |
2048 | i_img_dim seedx |
2049 | i_img_dim seedy | |
3efb0915 TC |
2050 | Imager::Color dcol |
2051 | Imager::Color border | |
2052 | ||
2053 | undef_int | |
2054 | i_flood_cfill_border(im,seedx,seedy,fill, border) | |
2055 | Imager::ImgRaw im | |
8d14daab TC |
2056 | i_img_dim seedx |
2057 | i_img_dim seedy | |
3efb0915 TC |
2058 | Imager::FillHandle fill |
2059 | Imager::Color border | |
2060 | ||
02d1d628 AMH |
2061 | |
2062 | void | |
2063 | i_copyto(im,src,x1,y1,x2,y2,tx,ty) | |
2064 | Imager::ImgRaw im | |
2065 | Imager::ImgRaw src | |
8d14daab TC |
2066 | i_img_dim x1 |
2067 | i_img_dim y1 | |
2068 | i_img_dim x2 | |
2069 | i_img_dim y2 | |
2070 | i_img_dim tx | |
2071 | i_img_dim ty | |
02d1d628 AMH |
2072 | |
2073 | ||
2074 | void | |
2075 | i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans) | |
2076 | Imager::ImgRaw im | |
2077 | Imager::ImgRaw src | |
8d14daab TC |
2078 | i_img_dim x1 |
2079 | i_img_dim y1 | |
2080 | i_img_dim x2 | |
2081 | i_img_dim y2 | |
2082 | i_img_dim tx | |
2083 | i_img_dim ty | |
02d1d628 AMH |
2084 | Imager::Color trans |
2085 | ||
92bda632 TC |
2086 | Imager::ImgRaw |
2087 | i_copy(src) | |
02d1d628 AMH |
2088 | Imager::ImgRaw src |
2089 | ||
2090 | ||
faa9b3e7 | 2091 | undef_int |
71dc4a83 | 2092 | i_rubthru(im,src,tx,ty,src_minx,src_miny,src_maxx,src_maxy) |
02d1d628 AMH |
2093 | Imager::ImgRaw im |
2094 | Imager::ImgRaw src | |
8d14daab TC |
2095 | i_img_dim tx |
2096 | i_img_dim ty | |
2097 | i_img_dim src_minx | |
2098 | i_img_dim src_miny | |
2099 | i_img_dim src_maxx | |
2100 | i_img_dim src_maxy | |
71dc4a83 | 2101 | |
9b1ec2b8 TC |
2102 | undef_int |
2103 | i_compose(out, src, out_left, out_top, src_left, src_top, width, height, combine = ic_normal, opacity = 0.0) | |
2104 | Imager::ImgRaw out | |
2105 | Imager::ImgRaw src | |
8d14daab TC |
2106 | i_img_dim out_left |
2107 | i_img_dim out_top | |
2108 | i_img_dim src_left | |
2109 | i_img_dim src_top | |
2110 | i_img_dim width | |
2111 | i_img_dim height | |
9b1ec2b8 TC |
2112 | int combine |
2113 | double opacity | |
2114 | ||
2115 | undef_int | |
2116 | 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) | |
2117 | Imager::ImgRaw out | |
2118 | Imager::ImgRaw src | |
2119 | Imager::ImgRaw mask | |
8d14daab TC |
2120 | i_img_dim out_left |
2121 | i_img_dim out_top | |
2122 | i_img_dim src_left | |
2123 | i_img_dim src_top | |
2124 | i_img_dim mask_left | |
2125 | i_img_dim mask_top | |
2126 | i_img_dim width | |
2127 | i_img_dim height | |
9b1ec2b8 TC |
2128 | int combine |
2129 | double opacity | |
02d1d628 | 2130 | |
b47464c1 TC |
2131 | Imager::ImgRaw |
2132 | i_combine(src_av, channels_av = NULL) | |
2133 | AV *src_av | |
2134 | AV *channels_av | |
2135 | PREINIT: | |
2136 | i_img **imgs = NULL; | |
2137 | STRLEN in_count; | |
2138 | int *channels = NULL; | |
2139 | int i; | |
2140 | SV **psv; | |
2141 | IV tmp; | |
2142 | CODE: | |
2143 | in_count = av_len(src_av) + 1; | |
2144 | if (in_count > 0) { | |
2145 | imgs = mymalloc(sizeof(i_img*) * in_count); | |
2146 | channels = mymalloc(sizeof(int) * in_count); | |
2147 | for (i = 0; i < in_count; ++i) { | |
2148 | psv = av_fetch(src_av, i, 0); | |
2149 | if (!psv || !*psv || !sv_derived_from(*psv, "Imager::ImgRaw")) { | |
2150 | myfree(imgs); | |
2151 | myfree(channels); | |
2152 | croak("imgs must contain only images"); | |
2153 | } | |
2154 | tmp = SvIV((SV*)SvRV(*psv)); | |
2155 | imgs[i] = INT2PTR(i_img*, tmp); | |
2156 | if (channels_av && | |
2157 | (psv = av_fetch(channels_av, i, 0)) != NULL && | |
2158 | *psv) { | |
2159 | channels[i] = SvIV(*psv); | |
2160 | } | |
2161 | else { | |
2162 | channels[i] = 0; | |
2163 | } | |
2164 | } | |
2165 | } | |
2166 | RETVAL = i_combine(imgs, channels, in_count); | |
2167 | myfree(imgs); | |
2168 | myfree(channels); | |
2169 | OUTPUT: | |
2170 | RETVAL | |
2171 | ||
142c26ff AMH |
2172 | undef_int |
2173 | i_flipxy(im, direction) | |
2174 | Imager::ImgRaw im | |
2175 | int direction | |
2176 | ||
faa9b3e7 TC |
2177 | Imager::ImgRaw |
2178 | i_rotate90(im, degrees) | |
2179 | Imager::ImgRaw im | |
2180 | int degrees | |
2181 | ||
2182 | Imager::ImgRaw | |
0d3b936e | 2183 | i_rotate_exact(im, amount, ...) |
faa9b3e7 TC |
2184 | Imager::ImgRaw im |
2185 | double amount | |
0d3b936e TC |
2186 | PREINIT: |
2187 | i_color *backp = NULL; | |
2188 | i_fcolor *fbackp = NULL; | |
2189 | int i; | |
2190 | SV * sv1; | |
2191 | CODE: | |
2192 | /* extract the bg colors if any */ | |
2193 | /* yes, this is kind of strange */ | |
2194 | for (i = 2; i < items; ++i) { | |
2195 | sv1 = ST(i); | |
2196 | if (sv_derived_from(sv1, "Imager::Color")) { | |
2197 | IV tmp = SvIV((SV*)SvRV(sv1)); | |
2198 | backp = INT2PTR(i_color *, tmp); | |
2199 | } | |
2200 | else if (sv_derived_from(sv1, "Imager::Color::Float")) { | |
2201 | IV tmp = SvIV((SV*)SvRV(sv1)); | |
2202 | fbackp = INT2PTR(i_fcolor *, tmp); | |
2203 | } | |
2204 | } | |
2205 | RETVAL = i_rotate_exact_bg(im, amount, backp, fbackp); | |
2206 | OUTPUT: | |
2207 | RETVAL | |
faa9b3e7 TC |
2208 | |
2209 | Imager::ImgRaw | |
87b3f212 | 2210 | i_matrix_transform(im, xsize, ysize, matrix_av, ...) |
faa9b3e7 | 2211 | Imager::ImgRaw im |
487ec752 TC |
2212 | i_img_dim xsize |
2213 | i_img_dim ysize | |
87b3f212 | 2214 | AV *matrix_av |
487ec752 TC |
2215 | PREINIT: |
2216 | double matrix[9]; | |
2217 | STRLEN len; | |
2218 | SV *sv1; | |
2219 | int i; | |
2220 | i_color *backp = NULL; | |
2221 | i_fcolor *fbackp = NULL; | |
2222 | CODE: | |
2223 | len=av_len(matrix_av)+1; | |
2224 | if (len > 9) | |
2225 | len = 9; | |
2226 | for (i = 0; i < len; ++i) { | |
2227 | sv1=(*(av_fetch(matrix_av,i,0))); | |
2228 | matrix[i] = SvNV(sv1); | |
2229 | } | |
2230 | for (; i < 9; ++i) | |
2231 | matrix[i] = 0; | |
2232 | /* extract the bg colors if any */ | |
2233 | /* yes, this is kind of strange */ | |
2234 | for (i = 4; i < items; ++i) { | |
2235 | sv1 = ST(i); | |
2236 | if (sv_derived_from(sv1, "Imager::Color")) { | |
2237 | IV tmp = SvIV((SV*)SvRV(sv1)); | |
2238 | backp = INT2PTR(i_color *, tmp); | |
2239 | } | |
2240 | else if (sv_derived_from(sv1, "Imager::Color::Float")) { | |
2241 | IV tmp = SvIV((SV*)SvRV(sv1)); | |
2242 | fbackp = INT2PTR(i_fcolor *, tmp); | |
2243 | } | |
2244 | } | |
2245 | RETVAL = i_matrix_transform_bg(im, xsize, ysize, matrix, backp, fbackp); | |
2246 | OUTPUT: | |
2247 | RETVAL | |
02d1d628 | 2248 | |
167660cd | 2249 | undef_int |
02d1d628 AMH |
2250 | i_gaussian(im,stdev) |
2251 | Imager::ImgRaw im | |
167660cd | 2252 | double stdev |
02d1d628 | 2253 | |
b6381851 TC |
2254 | void |
2255 | i_unsharp_mask(im,stdev,scale) | |
2256 | Imager::ImgRaw im | |
8d14daab | 2257 | double stdev |
b6381851 TC |
2258 | double scale |
2259 | ||
6a3cbaef TC |
2260 | int |
2261 | i_conv(im,coef) | |
2262 | Imager::ImgRaw im | |
2263 | AV *coef | |
2264 | PREINIT: | |
2265 | double* c_coef; | |
2266 | int len; | |
2267 | SV* sv1; | |
2268 | int i; | |
2269 | CODE: | |
2270 | len = av_len(coef) + 1; | |
2271 | c_coef=mymalloc( len * sizeof(double) ); | |
2272 | for(i = 0; i < len; i++) { | |
2273 | sv1 = (*(av_fetch(coef, i, 0))); | |
2274 | c_coef[i] = (double)SvNV(sv1); | |
2275 | } | |
2276 | RETVAL = i_conv(im, c_coef, len); | |
2277 | myfree(c_coef); | |
2278 | OUTPUT: | |
2279 | RETVAL | |
02d1d628 | 2280 | |
d5477d3d TC |
2281 | Imager::ImgRaw |
2282 | i_convert(src, avmain) | |
f5991c03 | 2283 | Imager::ImgRaw src |
d5477d3d | 2284 | AV *avmain |
f5991c03 | 2285 | PREINIT: |
62869327 | 2286 | double *coeff; |
f5991c03 TC |
2287 | int outchan; |
2288 | int inchan; | |
f5991c03 | 2289 | SV **temp; |
f5991c03 TC |
2290 | AV *avsub; |
2291 | int len; | |
2292 | int i, j; | |
2293 | CODE: | |
f5991c03 TC |
2294 | outchan = av_len(avmain)+1; |
2295 | /* find the biggest */ | |
2296 | inchan = 0; | |
2297 | for (j=0; j < outchan; ++j) { | |
2298 | temp = av_fetch(avmain, j, 0); | |
2299 | if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) { | |
2300 | avsub = (AV*)SvRV(*temp); | |
2301 | len = av_len(avsub)+1; | |
2302 | if (len > inchan) | |
2303 | inchan = len; | |
2304 | } | |
26eb06dd TC |
2305 | else { |
2306 | i_push_errorf(0, "invalid matrix: element %d is not an array ref", j); | |
2307 | XSRETURN(0); | |
2308 | } | |
f5991c03 | 2309 | } |
62869327 | 2310 | coeff = mymalloc(sizeof(double) * outchan * inchan); |
f5991c03 TC |
2311 | for (j = 0; j < outchan; ++j) { |
2312 | avsub = (AV*)SvRV(*av_fetch(avmain, j, 0)); | |
2313 | len = av_len(avsub)+1; | |
2314 | for (i = 0; i < len; ++i) { | |
2315 | temp = av_fetch(avsub, i, 0); | |
2316 | if (temp) | |
2317 | coeff[i+j*inchan] = SvNV(*temp); | |
2318 | else | |
2319 | coeff[i+j*inchan] = 0; | |
2320 | } | |
2321 | while (i < inchan) | |
2322 | coeff[i++ + j*inchan] = 0; | |
2323 | } | |
d5477d3d | 2324 | RETVAL = i_convert(src, coeff, outchan, inchan); |
f5991c03 | 2325 | myfree(coeff); |
f5991c03 TC |
2326 | OUTPUT: |
2327 | RETVAL | |
40eba1ea AMH |
2328 | |
2329 | ||
1136f089 | 2330 | undef_int |
85f38e13 | 2331 | i_map(im, pmaps_av) |
40eba1ea | 2332 | Imager::ImgRaw im |
85f38e13 | 2333 | AV *pmaps_av |
64655904 TC |
2334 | PREINIT: |
2335 | unsigned int mask = 0; | |
64655904 TC |
2336 | AV *avsub; |
2337 | SV **temp; | |
2338 | int len; | |
2339 | int i, j; | |
2340 | unsigned char (*maps)[256]; | |
2341 | CODE: | |
2342 | len = av_len(pmaps_av)+1; | |
2343 | if (im->channels < len) | |
2344 | len = im->channels; | |
2345 | maps = mymalloc( len * sizeof(unsigned char [256]) ); | |
2346 | for (j=0; j<len ; j++) { | |
2347 | temp = av_fetch(pmaps_av, j, 0); | |
2348 | if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) { | |
2349 | avsub = (AV*)SvRV(*temp); | |
2350 | if(av_len(avsub) != 255) | |
2351 | continue; | |
2352 | mask |= 1<<j; | |
2353 | for (i=0; i<256 ; i++) { | |
2354 | int val; | |
2355 | temp = av_fetch(avsub, i, 0); | |
2356 | val = temp ? SvIV(*temp) : 0; | |
2357 | if (val<0) val = 0; | |
2358 | if (val>255) val = 255; | |
2359 | maps[j][i] = val; | |
2360 | } | |
2361 | } | |
2362 | } | |
2363 | i_map(im, maps, mask); | |
2364 | myfree(maps); | |
2365 | RETVAL = 1; | |
2366 | OUTPUT: | |
2367 | RETVAL | |
40eba1ea | 2368 | |
02d1d628 AMH |
2369 | float |
2370 | i_img_diff(im1,im2) | |
2371 | Imager::ImgRaw im1 | |
2372 | Imager::ImgRaw im2 | |
2373 | ||
e41cfe8f TC |
2374 | double |
2375 | i_img_diffd(im1,im2) | |
2376 | Imager::ImgRaw im1 | |
2377 | Imager::ImgRaw im2 | |
02d1d628 | 2378 | |
4498c8bd TC |
2379 | int |
2380 | i_img_samef(im1, im2, epsilon = i_img_epsilonf(), what=NULL) | |
2381 | Imager::ImgRaw im1 | |
2382 | Imager::ImgRaw im2 | |
2383 | double epsilon | |
2384 | const char *what | |
2385 | ||
2386 | double | |
2387 | i_img_epsilonf() | |
2388 | ||
813d4d0a TC |
2389 | bool |
2390 | _is_color_object(sv) | |
2391 | SV* sv | |
2392 | CODE: | |
2393 | SvGETMAGIC(sv); | |
2394 | RETVAL = SvOK(sv) && SvROK(sv) && | |
2395 | (sv_derived_from(sv, "Imager::Color") | |
2396 | || sv_derived_from(sv, "Imager::Color::Float")); | |
2397 | OUTPUT: | |
2398 | RETVAL | |
2399 | ||
02d1d628 AMH |
2400 | #ifdef HAVE_LIBTT |
2401 | ||
2402 | ||
4b19f77a | 2403 | Imager::Font::TT |
02d1d628 AMH |
2404 | i_tt_new(fontname) |
2405 | char* fontname | |
2406 | ||
4b19f77a AMH |
2407 | |
2408 | MODULE = Imager PACKAGE = Imager::Font::TT PREFIX=TT_ | |
2409 | ||
2410 | #define TT_DESTROY(handle) i_tt_destroy(handle) | |
2411 | ||
02d1d628 | 2412 | void |
4b19f77a AMH |
2413 | TT_DESTROY(handle) |
2414 | Imager::Font::TT handle | |
2415 | ||
ffddd407 TC |
2416 | int |
2417 | TT_CLONE_SKIP(...) | |
2418 | CODE: | |
8d14daab | 2419 | (void)items; /* avoid unused warning */ |
ffddd407 TC |
2420 | RETVAL = 1; |
2421 | OUTPUT: | |
2422 | RETVAL | |
2423 | ||
02d1d628 | 2424 | |
4b19f77a | 2425 | MODULE = Imager PACKAGE = Imager |
02d1d628 AMH |
2426 | |
2427 | ||
2428 | undef_int | |
e3b4d6c3 | 2429 | i_tt_text(handle,im,xb,yb,cl,points,str_sv,smooth,utf8,align=1) |
4b19f77a | 2430 | Imager::Font::TT handle |
02d1d628 | 2431 | Imager::ImgRaw im |
8d14daab TC |
2432 | i_img_dim xb |
2433 | i_img_dim yb | |
02d1d628 | 2434 | Imager::Color cl |
8d14daab | 2435 | double points |
4f68b48f | 2436 | SV * str_sv |
02d1d628 | 2437 | int smooth |
4f68b48f | 2438 | int utf8 |
9ab6338b | 2439 | int align |
4f68b48f TC |
2440 | PREINIT: |
2441 | char *str; | |
2442 | STRLEN len; | |
2443 | CODE: | |
e3b4d6c3 | 2444 | str = SvPV(str_sv, len); |
4f68b48f TC |
2445 | #ifdef SvUTF8 |
2446 | if (SvUTF8(str_sv)) | |
2447 | utf8 = 1; | |
2448 | #endif | |
4f68b48f | 2449 | RETVAL = i_tt_text(handle, im, xb, yb, cl, points, str, |
9ab6338b | 2450 | len, smooth, utf8, align); |
4f68b48f TC |
2451 | OUTPUT: |
2452 | RETVAL | |
02d1d628 AMH |
2453 | |
2454 | ||
2455 | undef_int | |
e3b4d6c3 | 2456 | i_tt_cp(handle,im,xb,yb,channel,points,str_sv,smooth,utf8,align=1) |
4b19f77a | 2457 | Imager::Font::TT handle |
02d1d628 | 2458 | Imager::ImgRaw im |
8d14daab TC |
2459 | i_img_dim xb |
2460 | i_img_dim yb | |
02d1d628 | 2461 | int channel |
8d14daab | 2462 | double points |
4f68b48f | 2463 | SV * str_sv |
02d1d628 | 2464 | int smooth |
4f68b48f | 2465 | int utf8 |
9ab6338b | 2466 | int align |
4f68b48f TC |
2467 | PREINIT: |
2468 | char *str; | |
2469 | STRLEN len; | |
2470 | CODE: | |
e3b4d6c3 | 2471 | str = SvPV(str_sv, len); |
4f68b48f TC |
2472 | #ifdef SvUTF8 |
2473 | if (SvUTF8(str_sv)) | |
2474 | utf8 = 1; | |
2475 | #endif | |
4f68b48f | 2476 | RETVAL = i_tt_cp(handle, im, xb, yb, channel, points, str, len, |
9ab6338b | 2477 | smooth, utf8, align); |
4f68b48f TC |
2478 | OUTPUT: |
2479 | RETVAL | |
02d1d628 AMH |
2480 | |
2481 | ||
a659442a | 2482 | void |
7e3298ec | 2483 | i_tt_bbox(handle,point,str_sv,utf8) |
4b19f77a | 2484 | Imager::Font::TT handle |
8d14daab | 2485 | double point |
4f68b48f | 2486 | SV* str_sv |
4f68b48f | 2487 | int utf8 |
02d1d628 | 2488 | PREINIT: |
8d14daab TC |
2489 | i_img_dim cords[BOUNDING_BOX_COUNT]; |
2490 | int rc; | |
4f68b48f TC |
2491 | char * str; |
2492 | STRLEN len; | |
3799c4d1 | 2493 | int i; |
02d1d628 | 2494 | PPCODE: |
7e3298ec | 2495 | str = SvPV(str_sv, len); |
4f68b48f TC |
2496 | #ifdef SvUTF8 |
2497 | if (SvUTF8(ST(2))) | |
2498 | utf8 = 1; | |
2499 | #endif | |
4f68b48f | 2500 | if ((rc=i_tt_bbox(handle,point,str,len,cords, utf8))) { |
3799c4d1 TC |
2501 | EXTEND(SP, rc); |
2502 | for (i = 0; i < rc; ++i) { | |
2503 | PUSHs(sv_2mortal(newSViv(cords[i]))); | |
2504 | } | |
02d1d628 AMH |
2505 | } |
2506 | ||
eeaa33fd TC |
2507 | void |
2508 | i_tt_has_chars(handle, text_sv, utf8) | |
2509 | Imager::Font::TT handle | |
2510 | SV *text_sv | |
2511 | int utf8 | |
2512 | PREINIT: | |
2513 | char const *text; | |
2514 | STRLEN len; | |
2515 | char *work; | |
8d14daab TC |
2516 | size_t count; |
2517 | size_t i; | |
eeaa33fd | 2518 | PPCODE: |
7e3298ec TC |
2519 | i_clear_error(); |
2520 | text = SvPV(text_sv, len); | |
eeaa33fd TC |
2521 | #ifdef SvUTF8 |
2522 | if (SvUTF8(text_sv)) | |
2523 | utf8 = 1; | |
2524 | #endif | |
eeaa33fd TC |
2525 | work = mymalloc(len); |
2526 | count = i_tt_has_chars(handle, text, len, utf8, work); | |
2527 | if (GIMME_V == G_ARRAY) { | |
7eb58d07 TC |
2528 | if (count) { |
2529 | EXTEND(SP, count); | |
2530 | for (i = 0; i < count; ++i) { | |
2531 | PUSHs(boolSV(work[i])); | |
2532 | } | |
2533 | } | |
eeaa33fd TC |
2534 | } |
2535 | else { | |
2536 | EXTEND(SP, 1); | |
2537 | PUSHs(sv_2mortal(newSVpv(work, count))); | |
2538 | } | |
2539 | myfree(work); | |
02d1d628 | 2540 | |
3799c4d1 TC |
2541 | void |
2542 | i_tt_dump_names(handle) | |
2543 | Imager::Font::TT handle | |
02d1d628 | 2544 | |
3799c4d1 TC |
2545 | void |
2546 | i_tt_face_name(handle) | |
2547 | Imager::Font::TT handle | |
2548 | PREINIT: | |
2549 | char name[255]; | |
8d14daab | 2550 | size_t len; |
3799c4d1 TC |
2551 | PPCODE: |
2552 | len = i_tt_face_name(handle, name, sizeof(name)); | |
2553 | if (len) { | |
2554 | EXTEND(SP, 1); | |
8d14daab | 2555 | PUSHs(sv_2mortal(newSVpv(name, len-1))); |
3799c4d1 | 2556 | } |
02d1d628 | 2557 | |
19fa4baf AMH |
2558 | void |
2559 | i_tt_glyph_name(handle, text_sv, utf8 = 0) | |
3799c4d1 TC |
2560 | Imager::Font::TT handle |
2561 | SV *text_sv | |
2562 | int utf8 | |
2563 | PREINIT: | |
2564 | char const *text; | |
2565 | STRLEN work_len; | |
718b8c97 | 2566 | size_t len; |
8d14daab | 2567 | size_t outsize; |
3799c4d1 TC |
2568 | char name[255]; |
2569 | PPCODE: | |
7e3298ec TC |
2570 | i_clear_error(); |
2571 | text = SvPV(text_sv, work_len); | |
3799c4d1 TC |
2572 | #ifdef SvUTF8 |
2573 | if (SvUTF8(text_sv)) | |
2574 | utf8 = 1; | |
2575 | #endif | |
3799c4d1 TC |
2576 | len = work_len; |
2577 | while (len) { | |
17892255 | 2578 | unsigned long ch; |
3799c4d1 TC |
2579 | if (utf8) { |
2580 | ch = i_utf8_advance(&text, &len); | |
2581 | if (ch == ~0UL) { | |
2582 | i_push_error(0, "invalid UTF8 character"); | |
7e3298ec | 2583 | XSRETURN_EMPTY; |
3799c4d1 TC |
2584 | } |
2585 | } | |
2586 | else { | |
2587 | ch = *text++; | |
2588 | --len; | |
2589 | } | |
ea3099db | 2590 | EXTEND(SP, 1); |
af070d99 | 2591 | if ((outsize = i_tt_glyph_name(handle, ch, name, sizeof(name))) != 0) { |
ea3099db | 2592 | PUSHs(sv_2mortal(newSVpv(name, 0))); |
3799c4d1 TC |
2593 | } |
2594 | else { | |
ea3099db | 2595 | PUSHs(&PL_sv_undef); |
7e3298ec | 2596 | } |
3799c4d1 TC |
2597 | } |
2598 | ||
2599 | #endif | |
02d1d628 | 2600 | |
53a6bbd4 | 2601 | const char * |
e10bf46e AMH |
2602 | i_test_format_probe(ig, length) |
2603 | Imager::IO ig | |
2604 | int length | |
2605 | ||
02d1d628 | 2606 | Imager::ImgRaw |
d87dc9a4 | 2607 | i_readpnm_wiol(ig, allow_incomplete) |
02d1d628 | 2608 | Imager::IO ig |
d87dc9a4 | 2609 | int allow_incomplete |
02d1d628 AMH |
2610 | |
2611 | ||
2086be61 TC |
2612 | void |
2613 | i_readpnm_multi_wiol(ig, allow_incomplete) | |
2614 | Imager::IO ig | |
2615 | int allow_incomplete | |
2616 | PREINIT: | |
2617 | i_img **imgs; | |
2618 | int count=0; | |
2619 | int i; | |
2620 | PPCODE: | |
2621 | imgs = i_readpnm_multi_wiol(ig, &count, allow_incomplete); | |
2622 | if (imgs) { | |
2623 | EXTEND(SP, count); | |
2624 | for (i = 0; i < count; ++i) { | |
2625 | SV *sv = sv_newmortal(); | |
2626 | sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]); | |
2627 | PUSHs(sv); | |
2628 | } | |
2629 | myfree(imgs); | |
2630 | } | |
2631 | ||
067d6bdc AMH |
2632 | undef_int |
2633 | i_writeppm_wiol(im, ig) | |
2634 | Imager::ImgRaw im | |
2635 | Imager::IO ig | |
2636 | ||
2637 | ||
2086be61 TC |
2638 | |
2639 | ||
2640 | ||
02d1d628 | 2641 | Imager::ImgRaw |
895dbd34 AMH |
2642 | i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl) |
2643 | Imager::IO ig | |
8d14daab TC |
2644 | i_img_dim x |
2645 | i_img_dim y | |
02d1d628 AMH |
2646 | int datachannels |
2647 | int storechannels | |
2648 | int intrl | |
2649 | ||
2650 | undef_int | |
895dbd34 | 2651 | i_writeraw_wiol(im,ig) |
02d1d628 | 2652 | Imager::ImgRaw im |
895dbd34 AMH |
2653 | Imager::IO ig |
2654 | ||
261f91c5 TC |
2655 | undef_int |
2656 | i_writebmp_wiol(im,ig) | |
2657 | Imager::ImgRaw im | |
2658 | Imager::IO ig | |
02d1d628 | 2659 | |
705fd961 | 2660 | Imager::ImgRaw |
d87dc9a4 | 2661 | i_readbmp_wiol(ig, allow_incomplete=0) |
705fd961 | 2662 | Imager::IO ig |
d87dc9a4 | 2663 | int allow_incomplete |
705fd961 | 2664 | |
1ec86afa AMH |
2665 | |
2666 | undef_int | |
febba01f | 2667 | i_writetga_wiol(im,ig, wierdpack, compress, idstring) |
1ec86afa AMH |
2668 | Imager::ImgRaw im |
2669 | Imager::IO ig | |
febba01f AMH |
2670 | int wierdpack |
2671 | int compress | |
2672 | char* idstring | |
2673 | PREINIT: | |
febba01f AMH |
2674 | int idlen; |
2675 | CODE: | |
2676 | idlen = SvCUR(ST(4)); | |
2677 | RETVAL = i_writetga_wiol(im, ig, wierdpack, compress, idstring, idlen); | |
2678 | OUTPUT: | |
2679 | RETVAL | |
2680 | ||
1ec86afa AMH |
2681 | |
2682 | Imager::ImgRaw | |
2683 | i_readtga_wiol(ig, length) | |
2684 | Imager::IO ig | |
2685 | int length | |
2686 | ||
2687 | ||
737a830c AMH |
2688 | |
2689 | ||
02d1d628 AMH |
2690 | Imager::ImgRaw |
2691 | i_scaleaxis(im,Value,Axis) | |
2692 | Imager::ImgRaw im | |
8d14daab | 2693 | double Value |
02d1d628 AMH |
2694 | int Axis |
2695 | ||
2696 | Imager::ImgRaw | |
2697 | i_scale_nn(im,scx,scy) | |
2698 | Imager::ImgRaw im | |
8d14daab TC |
2699 | double scx |
2700 | double scy | |
02d1d628 | 2701 | |
658f724e TC |
2702 | Imager::ImgRaw |
2703 | i_scale_mixing(im, width, height) | |
2704 | Imager::ImgRaw im | |
8d14daab TC |
2705 | i_img_dim width |
2706 | i_img_dim height | |
658f724e | 2707 | |
02d1d628 AMH |
2708 | Imager::ImgRaw |
2709 | i_haar(im) | |
2710 | Imager::ImgRaw im | |
2711 | ||
2712 | int | |
2713 | i_count_colors(im,maxc) | |
2714 | Imager::ImgRaw im | |
2715 | int maxc | |
2716 | ||
fe622da1 | 2717 | void |
a60905e4 TC |
2718 | i_get_anonymous_color_histo(im, maxc = 0x40000000) |
2719 | Imager::ImgRaw im | |
2720 | int maxc | |
4c99febf | 2721 | PREINIT: |
fe622da1 | 2722 | int i; |
a60905e4 | 2723 | unsigned int * col_usage = NULL; |
4c99febf TC |
2724 | int col_cnt; |
2725 | PPCODE: | |
2726 | col_cnt = i_get_anonymous_color_histo(im, &col_usage, maxc); | |
8b810590 TC |
2727 | if (col_cnt <= 0) { |
2728 | XSRETURN_EMPTY; | |
2729 | } | |
2730 | EXTEND(SP, col_cnt); | |
2731 | for (i = 0; i < col_cnt; i++) { | |
2732 | PUSHs(sv_2mortal(newSViv( col_usage[i]))); | |
fe622da1 | 2733 | } |
8b810590 | 2734 | myfree(col_usage); |
fe622da1 | 2735 | |
02d1d628 | 2736 | |
fb9cb3f9 | 2737 | void |
19e9591b | 2738 | i_transform(im, opx, opy, parm) |
02d1d628 | 2739 | Imager::ImgRaw im |
19e9591b TC |
2740 | int *opx |
2741 | int *opy | |
2742 | double *parm | |
02d1d628 | 2743 | PREINIT: |
19e9591b | 2744 | STRLEN size_opx, size_opy, size_parm; |
fb9cb3f9 TC |
2745 | i_img *result; |
2746 | PPCODE: | |
19e9591b | 2747 | result=i_transform(im,opx,size_opx,opy,size_opy,parm,size_parm); |
fb9cb3f9 TC |
2748 | if (result) { |
2749 | SV *result_sv = sv_newmortal(); | |
2750 | EXTEND(SP, 1); | |
2751 | sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result); | |
2752 | PUSHs(result_sv); | |
2753 | } | |
02d1d628 | 2754 | |
fb9cb3f9 | 2755 | void |
e5744e01 TC |
2756 | i_transform2(sv_width,sv_height,channels,sv_ops,av_n_regs,av_c_regs,av_in_imgs) |
2757 | SV *sv_width | |
2758 | SV *sv_height | |
2759 | SV *sv_ops | |
2760 | AV *av_n_regs | |
2761 | AV *av_c_regs | |
2762 | AV *av_in_imgs | |
2763 | int channels | |
02d1d628 | 2764 | PREINIT: |
8d14daab TC |
2765 | i_img_dim width; |
2766 | i_img_dim height; | |
02d1d628 | 2767 | struct rm_op *ops; |
953209f8 | 2768 | STRLEN ops_len; |
02d1d628 AMH |
2769 | int ops_count; |
2770 | double *n_regs; | |
2771 | int n_regs_count; | |
2772 | i_color *c_regs; | |
2773 | int c_regs_count; | |
2774 | int in_imgs_count; | |
2775 | i_img **in_imgs; | |
ea9e6c3f | 2776 | SV *sv1; |
02d1d628 AMH |
2777 | IV tmp; |
2778 | int i; | |
fb9cb3f9 TC |
2779 | i_img *result; |
2780 | PPCODE: | |
e5744e01 TC |
2781 | |
2782 | in_imgs_count = av_len(av_in_imgs)+1; | |
2783 | for (i = 0; i < in_imgs_count; ++i) { | |
2784 | sv1 = *av_fetch(av_in_imgs, i, 0); | |
2785 | if (!sv_derived_from(sv1, "Imager::ImgRaw")) { | |
2786 | croak("sv_in_img must contain only images"); | |
02d1d628 AMH |
2787 | } |
2788 | } | |
b8c2033e | 2789 | if (in_imgs_count > 0) { |
02d1d628 AMH |
2790 | in_imgs = mymalloc(in_imgs_count*sizeof(i_img*)); |
2791 | for (i = 0; i < in_imgs_count; ++i) { | |
e5744e01 | 2792 | sv1 = *av_fetch(av_in_imgs,i,0); |
02d1d628 AMH |
2793 | if (!sv_derived_from(sv1, "Imager::ImgRaw")) { |
2794 | croak("Parameter 5 must contain only images"); | |
2795 | } | |
2796 | tmp = SvIV((SV*)SvRV(sv1)); | |
e375fbd8 | 2797 | in_imgs[i] = INT2PTR(i_img*, tmp); |
02d1d628 AMH |
2798 | } |
2799 | } | |
2800 | else { | |
2801 | /* no input images */ | |
2802 | in_imgs = NULL; | |
2803 | } | |
2804 | /* default the output size from the first input if possible */ | |
e5744e01 TC |
2805 | if (SvOK(sv_width)) |
2806 | width = SvIV(sv_width); | |
02d1d628 AMH |
2807 | else if (in_imgs_count) |
2808 | width = in_imgs[0]->xsize; | |
2809 | else | |
2810 | croak("No output image width supplied"); | |
2811 | ||
e5744e01 TC |
2812 | if (SvOK(sv_height)) |
2813 | height = SvIV(sv_height); | |
02d1d628 AMH |
2814 | else if (in_imgs_count) |
2815 | height = in_imgs[0]->ysize; | |
2816 | else | |
2817 | croak("No output image height supplied"); | |
2818 | ||
e5744e01 | 2819 | ops = (struct rm_op *)SvPV(sv_ops, ops_len); |
02d1d628 AMH |
2820 | if (ops_len % sizeof(struct rm_op)) |
2821 | croak("Imager: Parameter 3 must be a bitmap of regops\n"); | |
2822 | ops_count = ops_len / sizeof(struct rm_op); | |
e5744e01 TC |
2823 | |
2824 | n_regs_count = av_len(av_n_regs)+1; | |
02d1d628 AMH |
2825 | n_regs = mymalloc(n_regs_count * sizeof(double)); |
2826 | for (i = 0; i < n_regs_count; ++i) { | |
e5744e01 | 2827 | sv1 = *av_fetch(av_n_regs,i,0); |
02d1d628 AMH |
2828 | if (SvOK(sv1)) |
2829 | n_regs[i] = SvNV(sv1); | |
2830 | } | |
e5744e01 | 2831 | c_regs_count = av_len(av_c_regs)+1; |
02d1d628 AMH |
2832 | c_regs = mymalloc(c_regs_count * sizeof(i_color)); |
2833 | /* I don't bother initializing the colou?r registers */ | |
2834 | ||
fb9cb3f9 | 2835 | result=i_transform2(width, height, channels, ops, ops_count, |
02d1d628 AMH |
2836 | n_regs, n_regs_count, |
2837 | c_regs, c_regs_count, in_imgs, in_imgs_count); | |
2838 | if (in_imgs) | |
2839 | myfree(in_imgs); | |
2840 | myfree(n_regs); | |
2841 | myfree(c_regs); | |
fb9cb3f9 TC |
2842 | if (result) { |
2843 | SV *result_sv = sv_newmortal(); | |
2844 | EXTEND(SP, 1); | |
2845 | sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result); | |
2846 | PUSHs(result_sv); | |
2847 | } | |
02d1d628 AMH |
2848 | |
2849 | ||
2850 | void | |
2851 | i_contrast(im,intensity) | |
2852 | Imager::ImgRaw im | |
2853 | float intensity | |
2854 | ||
2855 | void | |
2856 | i_hardinvert(im) | |
2857 | Imager::ImgRaw im | |
2858 | ||
5558f899 TC |
2859 | void |
2860 | i_hardinvertall(im) | |
2861 | Imager::ImgRaw im | |
2862 | ||
02d1d628 AMH |
2863 | void |
2864 | i_noise(im,amount,type) | |
2865 | Imager::ImgRaw im | |
2866 | float amount | |
2867 | unsigned char type | |
2868 | ||
2869 | void | |
2870 | i_bumpmap(im,bump,channel,light_x,light_y,strength) | |
2871 | Imager::ImgRaw im | |
2872 | Imager::ImgRaw bump | |
2873 | int channel | |
8d14daab TC |
2874 | i_img_dim light_x |
2875 | i_img_dim light_y | |
2876 | i_img_dim strength | |
02d1d628 | 2877 | |
b2778574 AMH |
2878 | |
2879 | void | |
2880 | i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is) | |
2881 | Imager::ImgRaw im | |
2882 | Imager::ImgRaw bump | |
2883 | int channel | |
8d14daab TC |
2884 | i_img_dim tx |
2885 | i_img_dim ty | |
2886 | double Lx | |
2887 | double Ly | |
2888 | double Lz | |
b2778574 AMH |
2889 | float cd |
2890 | float cs | |
2891 | float n | |
2892 | Imager::Color Ia | |
2893 | Imager::Color Il | |
2894 | Imager::Color Is | |
2895 | ||
2896 | ||
2897 | ||
02d1d628 AMH |
2898 | void |
2899 | i_postlevels(im,levels) | |
2900 | Imager::ImgRaw im | |
2901 | int levels | |
2902 | ||
2903 | void | |
2904 | i_mosaic(im,size) | |
2905 | Imager::ImgRaw im | |
8d14daab | 2906 | i_img_dim size |
02d1d628 AMH |
2907 | |
2908 | void | |
2909 | i_watermark(im,wmark,tx,ty,pixdiff) | |
2910 | Imager::ImgRaw im | |
2911 | Imager::ImgRaw wmark | |
8d14daab TC |
2912 | i_img_dim tx |
2913 | i_img_dim ty | |
02d1d628 AMH |
2914 | int pixdiff |
2915 | ||
2916 | ||
2917 | void | |
2918 | i_autolevels(im,lsat,usat,skew) | |
2919 | Imager::ImgRaw im | |
2920 | float lsat | |
2921 | float usat | |
2922 | float skew | |
2923 | ||
ac00f58d TC |
2924 | void |
2925 | i_autolevels_mono(im,lsat,usat) | |
2926 | Imager::ImgRaw im | |
2927 | float lsat | |
2928 | float usat | |
2929 | ||
02d1d628 AMH |
2930 | void |
2931 | i_radnoise(im,xo,yo,rscale,ascale) | |
2932 | Imager::ImgRaw im | |
2933 | float xo | |
2934 | float yo | |
2935 | float rscale | |
2936 | float ascale | |
2937 | ||
2938 | void | |
2939 | i_turbnoise(im, xo, yo, scale) | |
2940 | Imager::ImgRaw im | |
2941 | float xo | |
2942 | float yo | |
2943 | float scale | |
2944 | ||
2945 | ||
2946 | void | |
0aaa8b4d | 2947 | i_gradgen(im, xo, yo, ac, dmeasure) |
02d1d628 | 2948 | Imager::ImgRaw im |
0aaa8b4d TC |
2949 | i_img_dim *xo |
2950 | i_img_dim *yo | |
2951 | i_color *ac | |
2952 | int dmeasure | |
02d1d628 | 2953 | PREINIT: |
0aaa8b4d TC |
2954 | STRLEN size_xo; |
2955 | STRLEN size_yo; | |
2956 | STRLEN size_ac; | |
02d1d628 | 2957 | CODE: |
0aaa8b4d TC |
2958 | if (size_xo != size_yo || size_xo != size_ac) |
2959 | croak("i_gradgen: x, y and color arrays must be the same size"); | |
2960 | if (size_xo < 2) | |
2961 | croak("Usage: i_gradgen array refs must have more than 1 entry each"); | |
2962 | i_gradgen(im, size_xo, xo, yo, ac, dmeasure); | |
a73aeb5f | 2963 | |
dff75dee TC |
2964 | Imager::ImgRaw |
2965 | i_diff_image(im, im2, mindist=0) | |
2966 | Imager::ImgRaw im | |
2967 | Imager::ImgRaw im2 | |
01b84320 | 2968 | double mindist |
02d1d628 | 2969 | |
e310e5f9 | 2970 | undef_int |
6607600c TC |
2971 | i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs) |
2972 | Imager::ImgRaw im | |
2973 | double xa | |
2974 | double ya | |
2975 | double xb | |
2976 | double yb | |
2977 | int type | |
2978 | int repeat | |
2979 | int combine | |
2980 | int super_sample | |
2981 | double ssample_param | |
2982 | PREINIT: | |
6607600c | 2983 | AV *asegs; |
6607600c TC |
2984 | int count; |
2985 | i_fountain_seg *segs; | |
6607600c | 2986 | CODE: |
6607600c TC |
2987 | if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10)))) |
2988 | croak("i_fountain: argument 11 must be an array ref"); | |
2989 | ||
2990 | asegs = (AV *)SvRV(ST(10)); | |
b13a3ddb | 2991 | segs = load_fount_segs(aTHX_ asegs, &count); |
e310e5f9 TC |
2992 | RETVAL = i_fountain(im, xa, ya, xb, yb, type, repeat, combine, |
2993 | super_sample, ssample_param, count, segs); | |
6607600c | 2994 | myfree(segs); |
e310e5f9 TC |
2995 | OUTPUT: |
2996 | RETVAL | |
02d1d628 | 2997 | |
f1ac5027 TC |
2998 | Imager::FillHandle |
2999 | i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs) | |
3000 | double xa | |
3001 | double ya | |
3002 | double xb | |
3003 | double yb | |
3004 | int type | |
3005 | int repeat | |
3006 | int combine | |
3007 | int super_sample | |
3008 | double ssample_param | |
3009 | PREINIT: | |
3010 | AV *asegs; | |
3011 | int count; | |
3012 | i_fountain_seg *segs; | |
3013 | CODE: | |
3014 | if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9)))) | |
3015 | croak("i_fountain: argument 11 must be an array ref"); | |
3016 | ||
3017 | asegs = (AV *)SvRV(ST(9)); | |
b13a3ddb | 3018 | segs = load_fount_segs(aTHX_ asegs, &count); |
f1ac5027 TC |
3019 | RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, |
3020 | super_sample, ssample_param, count, segs); | |
3021 | myfree(segs); | |
3022 | OUTPUT: | |
3023 | RETVAL | |
3024 | ||
52f2b10a TC |
3025 | Imager::FillHandle |
3026 | i_new_fill_opacity(other_fill, alpha_mult) | |
3027 | Imager::FillHandle other_fill | |
3028 | double alpha_mult | |
3029 | ||
4f4f776a TC |
3030 | void |
3031 | i_errors() | |
3032 | PREINIT: | |
3033 | i_errmsg *errors; | |
3034 | int i; | |
4f4f776a | 3035 | AV *av; |
4f4f776a TC |
3036 | SV *sv; |
3037 | PPCODE: | |
3038 | errors = i_errors(); | |
3039 | i = 0; | |
3040 | while (errors[i].msg) { | |
3041 | av = newAV(); | |
3042 | sv = newSVpv(errors[i].msg, strlen(errors[i].msg)); | |
3043 | if (!av_store(av, 0, sv)) { | |
3044 | SvREFCNT_dec(sv); | |
3045 | } | |
3046 | sv = newSViv(errors[i].code); | |
3047 | if (!av_store(av, 1, sv)) { | |
3048 | SvREFCNT_dec(sv); | |
3049 | } | |
57bbbbe7 | 3050 | XPUSHs(sv_2mortal(newRV_noinc((SV*)av))); |
4f4f776a TC |
3051 | ++i; |
3052 | } | |
02d1d628 | 3053 | |
2b405c9e TC |
3054 | void |
3055 | i_clear_error() | |
3056 | ||
3057 | void | |
3058 | i_push_error(code, msg) | |
3059 | int code | |
3060 | const char *msg | |
3061 | ||
e310e5f9 | 3062 | undef_int |
02d1d628 AMH |
3063 | i_nearest_color(im, ...) |
3064 | Imager::ImgRaw im | |
3065 | PREINIT: | |
3066 | int num; | |
8d14daab TC |
3067 | i_img_dim *xo; |
3068 | i_img_dim *yo; | |
02d1d628 AMH |
3069 | i_color *ival; |
3070 | int dmeasure; | |
3071 | int i; | |
3072 | SV *sv; | |
3073 | AV *axx; | |
3074 | AV *ayy; | |
3075 | AV *ac; | |
3076 | CODE: | |
3077 | if (items != 5) | |
3078 | croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)"); | |
3079 | if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1)))) | |
3080 | croak("i_nearest_color: Second argument must be an array ref"); | |
3081 | if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2)))) | |
3082 | croak("i_nearest_color: Third argument must be an array ref"); | |
3083 | if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3)))) | |
3084 | croak("i_nearest_color: Fourth argument must be an array ref"); | |
3085 | axx = (AV *)SvRV(ST(1)); | |
3086 | ayy = (AV *)SvRV(ST(2)); | |
3087 | ac = (AV *)SvRV(ST(3)); | |
3088 | dmeasure = (int)SvIV(ST(4)); | |
3089 | ||
3090 | num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy); | |
3091 | num = num <= av_len(ac) ? num : av_len(ac); | |
3092 | num++; | |
3093 | if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each"); | |
945dff7f TC |
3094 | xo = malloc_temp(aTHX_ sizeof(i_img_dim) * num ); |
3095 | yo = malloc_temp(aTHX_ sizeof(i_img_dim) * num ); | |
3096 | ival = malloc_temp(aTHX_ sizeof(i_color) * num ); | |
02d1d628 | 3097 | for(i = 0; i<num; i++) { |
8d14daab TC |
3098 | xo[i] = (i_img_dim)SvIV(* av_fetch(axx, i, 0)); |
3099 | yo[i] = (i_img_dim)SvIV(* av_fetch(ayy, i, 0)); | |
02d1d628 AMH |
3100 | sv = *av_fetch(ac, i, 0); |
3101 | if ( !sv_derived_from(sv, "Imager::Color") ) { | |
3102 | free(axx); free(ayy); free(ac); | |
3103 | croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color"); | |
3104 | } | |
4c4c2ffd | 3105 | ival[i] = *INT2PTR(i_color *, SvIV((SV *)SvRV(sv))); |
02d1d628 | 3106 | } |
e310e5f9 TC |
3107 | RETVAL = i_nearest_color(im, num, xo, yo, ival, dmeasure); |
3108 | OUTPUT: | |
3109 | RETVAL | |
02d1d628 AMH |
3110 | |
3111 | void | |
3112 | malloc_state() | |
3113 | ||
02d1d628 AMH |
3114 | void |
3115 | DSO_open(filename) | |
3116 | char* filename | |
3117 | PREINIT: | |
3118 | void *rc; | |
3119 | char *evstr; | |
3120 | PPCODE: | |
3121 | rc=DSO_open(filename,&evstr); | |
3122 | if (rc!=NULL) { | |
3123 | if (evstr!=NULL) { | |
3124 | EXTEND(SP,2); | |
e375fbd8 | 3125 | PUSHs(sv_2mortal(newSViv(PTR2IV(rc)))); |
02d1d628 AMH |
3126 | PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr)))); |
3127 | } else { | |
3128 | EXTEND(SP,1); | |
e375fbd8 | 3129 | PUSHs(sv_2mortal(newSViv(PTR2IV(rc)))); |
02d1d628 AMH |
3130 | } |
3131 | } | |
3132 | ||
3133 | ||
3134 | undef_int | |
3135 | DSO_close(dso_handle) | |
3136 | void* dso_handle | |
3137 | ||
3138 | void | |
3139 | DSO_funclist(dso_handle_v) | |
3140 | void* dso_handle_v | |
3141 | PREINIT: | |
3142 | int i; | |
3143 | DSO_handle *dso_handle; | |
d8e0c3ba | 3144 | func_ptr *functions; |
02d1d628 AMH |
3145 | PPCODE: |
3146 | dso_handle=(DSO_handle*)dso_handle_v; | |
d8e0c3ba | 3147 | functions = DSO_funclist(dso_handle); |
02d1d628 | 3148 | i=0; |
d8e0c3ba | 3149 | while( functions[i].name != NULL) { |
02d1d628 | 3150 | EXTEND(SP,1); |
d8e0c3ba | 3151 | PUSHs(sv_2mortal(newSVpv(functions[i].name,0))); |
02d1d628 | 3152 | EXTEND(SP,1); |
d8e0c3ba | 3153 | PUSHs(sv_2mortal(newSVpv(functions[i++].pcode,0))); |
02d1d628 AMH |
3154 | } |
3155 | ||
02d1d628 AMH |
3156 | void |
3157 | DSO_call(handle,func_index,hv) | |
3158 | void* handle | |
3159 | int func_index | |
75cebca8 | 3160 | HV *hv |
02d1d628 | 3161 | PPCODE: |
02d1d628 AMH |
3162 | DSO_call( (DSO_handle *)handle,func_index,hv); |
3163 | ||
befd4be1 | 3164 | Imager::Color |
f5991c03 TC |
3165 | i_get_pixel(im, x, y) |
3166 | Imager::ImgRaw im | |
8d14daab TC |
3167 | i_img_dim x |
3168 | i_img_dim y; | |
faa9b3e7 | 3169 | CODE: |
befd4be1 | 3170 | RETVAL = (i_color *)mymalloc(sizeof(i_color)); |
2ea4aa42 | 3171 | memset(RETVAL, 0, sizeof(*RETVAL)); |
befd4be1 TC |
3172 | if (i_gpix(im, x, y, RETVAL) != 0) { |
3173 | myfree(RETVAL); | |
3174 | XSRETURN_UNDEF; | |
faa9b3e7 | 3175 | } |
a659442a TC |
3176 | OUTPUT: |
3177 | RETVAL | |
faa9b3e7 TC |
3178 | |
3179 | ||
3180 | int | |
3181 | i_ppix(im, x, y, cl) | |
3182 | Imager::ImgRaw im | |
8d14daab TC |
3183 | i_img_dim x |
3184 | i_img_dim y | |
faa9b3e7 TC |
3185 | Imager::Color cl |
3186 | ||
3187 | Imager::ImgRaw | |
3188 | i_img_pal_new(x, y, channels, maxpal) | |
8d14daab TC |
3189 | i_img_dim x |
3190 | i_img_dim y | |
faa9b3e7 TC |
3191 | int channels |
3192 | int maxpal | |
3193 | ||
3194 | Imager::ImgRaw | |
05f2584a | 3195 | i_img_to_pal(src, quant_hv) |
faa9b3e7 | 3196 | Imager::ImgRaw src |
05f2584a | 3197 | HV *quant_hv |
faa9b3e7 TC |
3198 | PREINIT: |
3199 | HV *hv; | |
3200 | i_quantize quant; | |
3201 | CODE: | |
faa9b3e7 | 3202 | memset(&quant, 0, sizeof(quant)); |
ec6d8908 | 3203 | quant.version = 1; |
faa9b3e7 | 3204 | quant.mc_size = 256; |
a3b721bb TC |
3205 | i_clear_error(); |
3206 | if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) { | |
3207 | XSRETURN_EMPTY; | |
3208 | } | |
faa9b3e7 TC |
3209 | RETVAL = i_img_to_pal(src, &quant); |
3210 | if (RETVAL) { | |
05f2584a | 3211 | ip_copy_colors_back(aTHX_ quant_hv, &quant); |
faa9b3e7 | 3212 | } |
ec6d8908 | 3213 | ip_cleanup_quant_opts(aTHX_ &quant); |
faa9b3e7 TC |
3214 | OUTPUT: |
3215 | RETVAL | |
3216 | ||
3217 | Imager::ImgRaw | |
3218 | i_img_to_rgb(src) | |
3219 | Imager::ImgRaw src | |
3220 | ||
5e9a7fbd TC |
3221 | void |
3222 | i_img_make_palette(HV *quant_hv, ...) | |
3223 | PREINIT: | |
3224 | size_t count = items - 1; | |
3225 | i_quantize quant; | |
3226 | i_img **imgs = NULL; | |
3227 | ssize_t i; | |
3228 | PPCODE: | |
3229 | if (count <= 0) | |
3230 | croak("Please supply at least one image (%d)", (int)count); | |
3231 | imgs = mymalloc(sizeof(i_img *) * count); | |
3232 | for (i = 0; i < count; ++i) { | |
3233 | SV *img_sv = ST(i + 1); | |
3234 | if (SvROK(img_sv) && sv_derived_from(img_sv, "Imager::ImgRaw")) { | |
3235 | imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(img_sv))); | |
3236 | } | |
3237 | else { | |
3238 | myfree(imgs); | |
ec2f6280 | 3239 | croak("Image %d is not an image object", (int)i+1); |
5e9a7fbd TC |
3240 | } |
3241 | } | |
3242 | memset(&quant, 0, sizeof(quant)); | |
3243 | quant.version = 1; | |
3244 | quant.mc_size = 256; | |
a3b721bb TC |
3245 | if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) { |
3246 | XSRETURN_EMPTY; | |
3247 | } | |
5e9a7fbd TC |
3248 | i_quant_makemap(&quant, imgs, count); |
3249 | EXTEND(SP, quant.mc_count); | |
3250 | for (i = 0; i < quant.mc_count; ++i) { | |
3251 | SV *sv_c = make_i_color_sv(aTHX_ quant.mc_colors + i); | |
3252 | PUSHs(sv_c); | |
3253 | } | |
3254 | ip_cleanup_quant_opts(aTHX_ &quant); | |
e906e86a | 3255 | myfree(imgs); |
5e9a7fbd TC |
3256 | |
3257 | ||
faa9b3e7 TC |
3258 | void |
3259 | i_gpal(im, l, r, y) | |
3260 | Imager::ImgRaw im | |
8d14daab TC |
3261 | i_img_dim l |
3262 | i_img_dim r | |
3263 | i_img_dim y | |
faa9b3e7 TC |
3264 | PREINIT: |
3265 | i_palidx *work; | |
3266 | int count, i; | |
3267 | PPCODE: | |
3268 | if (l < r) { | |
3269 | work = mymalloc((r-l) * sizeof(i_palidx)); | |
3270 | count = i_gpal(im, l, r, y, work); | |
3271 | if (GIMME_V == G_ARRAY) { | |
3272 | EXTEND(SP, count); | |
3273 | for (i = 0; i < count; ++i) { | |
3274 | PUSHs(sv_2mortal(newSViv(work[i]))); | |
3275 | } | |
3276 | } | |
3277 | else { | |
3278 | EXTEND(SP, 1); | |
26fd367b | 3279 | PUSHs(sv_2mortal(newSVpv((char *)work, count * sizeof(i_palidx)))); |
faa9b3e7 TC |
3280 | } |
3281 | myfree(work); | |
3282 | } | |
3283 | else { | |
3284 | if (GIMME_V != G_ARRAY) { | |
3285 | EXTEND(SP, 1); | |
3286 | PUSHs(&PL_sv_undef); | |
3287 | } | |
3288 | } | |
3289 | ||
3290 | int | |
3291 | i_ppal(im, l, y, ...) | |
3292 | Imager::ImgRaw im | |
8d14daab TC |
3293 | i_img_dim l |
3294 | i_img_dim y | |
faa9b3e7 TC |
3295 | PREINIT: |
3296 | i_palidx *work; | |
ebe9b189 | 3297 | i_img_dim i; |
faa9b3e7 TC |
3298 | CODE: |
3299 | if (items > 3) { | |
ebe9b189 | 3300 | work = malloc_temp(aTHX_ sizeof(i_palidx) * (items-3)); |
faa9b3e7 TC |
3301 | for (i=0; i < items-3; ++i) { |
3302 | work[i] = SvIV(ST(i+3)); | |
3303 | } | |
4cda4e76 | 3304 | validate_i_ppal(im, work, items - 3); |
faa9b3e7 | 3305 | RETVAL = i_ppal(im, l, l+items-3, y, work); |
faa9b3e7 TC |
3306 | } |
3307 | else { | |
3308 | RETVAL = 0; | |
3309 | } | |
3310 | OUTPUT: | |
3311 | RETVAL | |
3312 | ||
4cda4e76 TC |
3313 | int |
3314 | i_ppal_p(im, l, y, data) | |
3315 | Imager::ImgRaw im | |
8d14daab TC |
3316 | i_img_dim l |
3317 | i_img_dim y | |
4cda4e76 TC |
3318 | SV *data |
3319 | PREINIT: | |
3320 | i_palidx const *work; | |
4cda4e76 | 3321 | STRLEN len; |
4cda4e76 TC |
3322 | CODE: |
3323 | work = (i_palidx const *)SvPV(data, len); | |
3324 | len /= sizeof(i_palidx); | |
3325 | if (len > 0) { | |
3326 | validate_i_ppal(im, work, len); | |
3327 | RETVAL = i_ppal(im, l, l+len, y, work); | |
3328 | } | |
3329 | else { | |
3330 | RETVAL = 0; | |
3331 | } | |
3332 | OUTPUT: | |
3333 | RETVAL | |
3334 | ||
42505e61 | 3335 | SysRet |
faa9b3e7 TC |
3336 | i_addcolors(im, ...) |
3337 | Imager::ImgRaw im | |
3338 | PREINIT: | |
faa9b3e7 TC |
3339 | i_color *colors; |
3340 | int i; | |
3341 | CODE: | |
3342 | if (items < 2) | |
3343 | croak("i_addcolors: no colors to add"); | |
3344 | colors = mymalloc((items-1) * sizeof(i_color)); | |
3345 | for (i=0; i < items-1; ++i) { | |
3346 | if (sv_isobject(ST(i+1)) | |
3347 | && sv_derived_from(ST(i+1), "Imager::Color")) { | |
3348 | IV tmp = SvIV((SV *)SvRV(ST(i+1))); | |
4c4c2ffd | 3349 | colors[i] = *INT2PTR(i_color *, tmp); |
faa9b3e7 TC |
3350 | } |
3351 | else { | |
3352 | myfree(colors); | |
ca4d914e | 3353 | croak("i_addcolor: pixels must be Imager::Color objects"); |
faa9b3e7 TC |
3354 | } |
3355 | } | |
42505e61 | 3356 | RETVAL = i_addcolors(im, colors, items-1); |
7d5febef | 3357 | myfree(colors); |
a659442a TC |
3358 | OUTPUT: |
3359 | RETVAL | |
faa9b3e7 | 3360 | |
1501d9b3 | 3361 | undef_int |
faa9b3e7 TC |
3362 | i_setcolors(im, index, ...) |
3363 | Imager::ImgRaw im | |
3364 | int index | |
3365 | PREINIT: | |
3366 | i_color *colors; | |
3367 | int i; | |
3368 | CODE: | |
3369 | if (items < 3) | |
3370 | croak("i_setcolors: no colors to add"); | |
3371 | colors = mymalloc((items-2) * sizeof(i_color)); | |
3372 | for (i=0; i < items-2; ++i) { | |
3373 | if (sv_isobject(ST(i+2)) | |
3374 | && sv_derived_from(ST(i+2), "Imager::Color")) { | |
3375 | IV tmp = SvIV((SV *)SvRV(ST(i+2))); | |
4c4c2ffd | 3376 | colors[i] = *INT2PTR(i_color *, tmp); |
faa9b3e7 TC |
3377 | } |
3378 | else { | |
3379 | myfree(colors); | |
3380 | croak("i_setcolors: pixels must be Imager::Color objects"); | |
3381 | } | |
3382 | } | |
3383 | RETVAL = i_setcolors(im, index, colors, items-2); | |
3384 | myfree(colors); | |
1501d9b3 TC |
3385 | OUTPUT: |
3386 | RETVAL | |
faa9b3e7 TC |
3387 | |
3388 | void | |
1592522f | 3389 | i_getcolors(im, index, count=1) |
faa9b3e7 TC |
3390 | Imager::ImgRaw im |
3391 | int index | |
1592522f | 3392 | int count |
faa9b3e7 TC |
3393 | PREINIT: |
3394 | i_color *colors; | |
faa9b3e7 TC |
3395 | int i; |
3396 | PPCODE: | |
faa9b3e7 TC |
3397 | if (count < 1) |
3398 | croak("i_getcolors: count must be positive"); | |
1592522f | 3399 | colors = malloc_temp(aTHX_ sizeof(i_color) * count); |
faa9b3e7 | 3400 | if (i_getcolors(im, index, colors, count)) { |
1592522f | 3401 | EXTEND(SP, count); |
faa9b3e7 | 3402 | for (i = 0; i < count; ++i) { |
5e9a7fbd | 3403 | SV *sv = make_i_color_sv(aTHX_ colors+i); |
faa9b3e7 TC |
3404 | PUSHs(sv); |
3405 | } | |
3406 | } | |
faa9b3e7 | 3407 | |
a659442a | 3408 | undef_neg_int |
faa9b3e7 TC |
3409 | i_colorcount(im) |
3410 | Imager::ImgRaw im | |
faa9b3e7 | 3411 | |
a659442a | 3412 | undef_neg_int |
faa9b3e7 TC |
3413 | i_maxcolors(im) |
3414 | Imager::ImgRaw im | |
faa9b3e7 | 3415 | |
0862f397 | 3416 | i_palidx |
faa9b3e7 TC |
3417 | i_findcolor(im, color) |
3418 | Imager::ImgRaw im | |
3419 | Imager::Color color | |
faa9b3e7 | 3420 | CODE: |
0862f397 TC |
3421 | if (!i_findcolor(im, color, &RETVAL)) { |
3422 | XSRETURN_UNDEF; | |
faa9b3e7 | 3423 | } |
a659442a TC |
3424 | OUTPUT: |
3425 | RETVAL | |
faa9b3e7 TC |
3426 | |
3427 | int | |
3428 | i_img_bits(im) | |
3429 | Imager::ImgRaw im | |
3430 | ||
3431 | int | |
3432 | i_img_type(im) | |
3433 | Imager::ImgRaw im | |
3434 | ||
3435 | int | |
3436 | i_img_virtual(im) | |
3437 | Imager::ImgRaw im | |
3438 | ||
3439 | void | |
6a9807e8 | 3440 | i_gsamp(im, l, r, y, channels) |
faa9b3e7 | 3441 | Imager::ImgRaw im |
8d14daab TC |
3442 | i_img_dim l |
3443 | i_img_dim r | |
3444 | i_img_dim y | |
6a9807e8 | 3445 | i_channel_list channels |
faa9b3e7 | 3446 | PREINIT: |
faa9b3e7 | 3447 | i_sample_t *data; |
8d14daab | 3448 | i_img_dim count, i; |
faa9b3e7 | 3449 | PPCODE: |
faa9b3e7 | 3450 | if (l < r) { |
f37708ce | 3451 | data = mymalloc(sizeof(i_sample_t) * (r-l) * channels.count); |
6a9807e8 | 3452 | count = i_gsamp(im, l, r, y, data, channels.channels, channels.count); |
faa9b3e7 TC |
3453 | if (GIMME_V == G_ARRAY) { |
3454 | EXTEND(SP, count); | |
3455 | for (i = 0; i < count; ++i) | |
3456 | PUSHs(sv_2mortal(newSViv(data[i]))); | |
3457 | } | |
3458 | else { | |
3459 | EXTEND(SP, 1); | |
26fd367b | 3460 | PUSHs(sv_2mortal(newSVpv((char *)data, count * sizeof(i_sample_t)))); |
faa9b3e7 | 3461 | } |
a73aeb5f | 3462 | myfree(data); |
faa9b3e7 TC |
3463 | } |
3464 | else { | |
3465 | if (GIMME_V != G_ARRAY) { | |
f37708ce | 3466 | XSRETURN_UNDEF; |
faa9b3e7 TC |
3467 | } |
3468 | } | |
3469 | ||
bd8052a6 | 3470 | undef_neg_int |
6a9807e8 | 3471 | i_gsamp_bits(im, l, r, y, bits, target, offset, channels) |
bd8052a6 | 3472 | Imager::ImgRaw im |
8d14daab TC |
3473 | i_img_dim l |
3474 | i_img_dim r | |
3475 | i_img_dim y | |
bd8052a6 TC |
3476 | int bits |
3477 | AV *target | |
8d14daab | 3478 | STRLEN offset |
6a9807e8 | 3479 | i_channel_list channels |
bd8052a6 | 3480 | PREINIT: |
bd8052a6 | 3481 | unsigned *data; |
8d14daab | 3482 | i_img_dim count, i; |
bd8052a6 TC |
3483 | CODE: |
3484 | i_clear_error(); | |
3485 | if (items < 8) | |
3486 | croak("No channel numbers supplied to g_samp()"); | |
3487 | if (l < r) { | |
6a9807e8 TC |
3488 | data = mymalloc(sizeof(unsigned) * (r-l) * channels.count); |
3489 | count = i_gsamp_bits(im, l, r, y, data, channels.channels, channels.count, bits); | |
bd8052a6 TC |
3490 | for (i = 0; i < count; ++i) { |
3491 | av_store(target, i+offset, newSVuv(data[i])); | |
3492 | } | |
3493 | myfree(data); | |
3494 | RETVAL = count; | |
3495 | } | |
3496 | else { | |
3497 | RETVAL = 0; | |
3498 | } | |
3499 | OUTPUT: | |
3500 | RETVAL | |
3501 | ||
3502 | undef_neg_int | |
6a9807e8 | 3503 | i_psamp_bits(im, l, y, bits, channels, data_av, data_offset = 0, pixel_count = -1) |
bd8052a6 | 3504 | Imager::ImgRaw im |
8d14daab TC |
3505 | i_img_dim l |
3506 | i_img_dim y | |
bd8052a6 | 3507 | int bits |
6a9807e8 | 3508 | i_channel_list channels |
bd8052a6 | 3509 | AV *data_av |
848b7f32 TC |
3510 | i_img_dim data_offset |
3511 | i_img_dim pixel_count | |
bd8052a6 | 3512 | PREINIT: |
8d14daab TC |
3513 | STRLEN data_count; |
3514 | size_t data_used; | |
bd8052a6 | 3515 | unsigned *data; |
8d14daab | 3516 | ptrdiff_t i; |
bd8052a6 TC |
3517 | CODE: |
3518 | i_clear_error(); | |
bd8052a6 TC |
3519 | |
3520 | data_count = av_len(data_av) + 1; | |
3521 | if (data_offset < 0) { | |
848b7f32 | 3522 | croak("data_offset must be non-negative"); |
bd8052a6 TC |
3523 | } |
3524 | if (data_offset > data_count) { | |
3525 | croak("data_offset greater than number of samples supplied"); | |
3526 | } | |
3527 | if (pixel_count == -1 || | |
6a9807e8 TC |
3528 | data_offset + pixel_count * channels.count > data_count) { |
3529 | pixel_count = (data_count - data_offset) / channels.count; | |
bd8052a6 TC |
3530 | } |
3531 | ||
6a9807e8 | 3532 | data_used = pixel_count * channels.count; |
bd8052a6 TC |
3533 | data = mymalloc(sizeof(unsigned) * data_count); |
3534 | for (i = 0; i < data_used; ++i) | |
3535 | data[i] = SvUV(*av_fetch(data_av, data_offset + i, 0)); | |
3536 | ||
6a9807e8 TC |
3537 | RETVAL = i_psamp_bits(im, l, l + pixel_count, y, data, channels.channels, |
3538 | channels.count, bits); | |
bd8052a6 TC |
3539 | |
3540 | if (data) | |
3541 | myfree(data); | |
bd8052a6 TC |
3542 | OUTPUT: |
3543 | RETVAL | |
a73aeb5f | 3544 | |
48b9a7bf | 3545 | undef_neg_int |
848b7f32 | 3546 | i_psamp(im, x, y, channels, data, offset = 0, width = -1) |
48b9a7bf TC |
3547 | Imager::ImgRaw im |
3548 | i_img_dim x | |
3549 | i_img_dim y | |
3550 | i_channel_list channels | |
3551 | i_sample_list data | |
848b7f32 TC |
3552 | i_img_dim offset |
3553 | i_img_dim width | |
48b9a7bf TC |
3554 | PREINIT: |
3555 | i_img_dim r; | |
3556 | CODE: | |
48b9a7bf | 3557 | i_clear_error(); |
848b7f32 TC |
3558 | if (offset < 0) { |
3559 | i_push_error(0, "offset must be non-negative"); | |
3560 | XSRETURN_UNDEF; | |
3561 | } | |
3562 | if (offset > 0) { | |
3563 | if (offset > data.count) { | |
3564 | i_push_error(0, "offset greater than number of samples supplied"); | |
3565 | XSRETURN_UNDEF; | |
3566 | } | |
3567 | data.samples += offset; | |
3568 | data.count -= offset; | |
3569 | } | |
3570 | if (width == -1 || | |
3571 | width * channels.count > data.count) { | |
3572 | width = data.count / channels.count; | |
3573 | } | |
3574 | r = x + width; | |
48b9a7bf TC |
3575 | RETVAL = i_psamp(im, x, r, y, data.samples, channels.channels, channels.count); |
3576 | OUTPUT: | |
3577 | RETVAL | |
3578 | ||
3579 | undef_neg_int | |
848b7f32 | 3580 | i_psampf(im, x, y, channels, data, offset = 0, width = -1) |
48b9a7bf TC |
3581 | Imager::ImgRaw im |
3582 | i_img_dim x | |
3583 | i_img_dim y | |
3584 | i_channel_list channels | |
3585 | i_fsample_list data | |
848b7f32 TC |
3586 | i_img_dim offset |
3587 | i_img_dim width | |
48b9a7bf TC |
3588 | PREINIT: |
3589 | i_img_dim r; | |
3590 | CODE: | |
48b9a7bf | 3591 | i_clear_error(); |
848b7f32 TC |
3592 | if (offset < 0) { |
3593 | i_push_error(0, "offset must be non-negative"); | |
3594 | XSRETURN_UNDEF; | |
3595 | } | |
3596 | if (offset > 0) { | |
3597 | if (offset > data.count) { | |
3598 | i_push_error(0, "offset greater than number of samples supplied"); | |
3599 | XSRETURN_UNDEF; | |
3600 | } | |
3601 | data.samples += offset; | |
3602 | data.count -= offset; | |
3603 | } | |
3604 | if (width == -1 || | |
3605 | width * channels.count > data.count) { | |
3606 | width = data.count / channels.count; | |
3607 | } | |
3608 | r = x + width; | |
48b9a7bf TC |
3609 | RETVAL = i_psampf(im, x, r, y, data.samples, channels.channels, channels.count); |
3610 | OUTPUT: | |
3611 | RETVAL | |
3612 | ||
faa9b3e7 TC |
3613 | Imager::ImgRaw |
3614 | i_img_masked_new(targ, mask, x, y, w, h) | |
3615 | Imager::ImgRaw targ | |
8d14daab TC |
3616 | i_img_dim x |
3617 | i_img_dim y | |
3618 | i_img_dim w | |
3619 | i_img_dim h | |
faa9b3e7 TC |
3620 | PREINIT: |
3621 | i_img *mask; | |
3622 | CODE: | |
3623 | if (SvOK(ST(1))) { | |
3624 | if (!sv_isobject(ST(1)) | |
3625 | || !sv_derived_from(ST(1), "Imager::ImgRaw")) { | |
3626 | croak("i_img_masked_new: parameter 2 must undef or an image"); | |
3627 | } | |
4c4c2ffd | 3628 | mask = INT2PTR(i_img *, SvIV((SV *)SvRV(ST(1)))); |
faa9b3e7 TC |
3629 | } |
3630 | else | |
3631 | mask = NULL; | |
3632 | RETVAL = i_img_masked_new(targ, mask, x, y, w, h); | |
3633 | OUTPUT: | |
3634 | RETVAL | |
3635 | ||
3636 | int | |
3637 | i_plin(im, l, y, ...) | |
3638 | Imager::ImgRaw im | |
8d14daab TC |
3639 | i_img_dim l |
3640 | i_img_dim y | |
faa9b3e7 TC |
3641 | PREINIT: |
3642 | i_color *work; | |
8d14daab | 3643 | STRLEN i; |
ca4d914e | 3644 | STRLEN len; |
8d14daab | 3645 | size_t count; |
faa9b3e7 TC |
3646 | CODE: |
3647 | if (items > 3) { | |
ca4d914e TC |
3648 | if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) { |
3649 | /* supplied as a byte string */ | |
3650 | work = (i_color *)SvPV(ST(3), len); | |
3651 | count = len / sizeof(i_color); | |
3652 | if (count * sizeof(i_color) != len) { | |
3653 | croak("i_plin: length of scalar argument must be multiple of sizeof i_color"); | |
faa9b3e7 | 3654 | } |
ca4d914e TC |
3655 | RETVAL = i_plin(im, l, l+count, y, work); |
3656 | } | |
3657 | else { | |
3658 | work = mymalloc(sizeof(i_color) * (items-3)); | |
3659 | for (i=0; i < items-3; ++i) { | |
3660 | if (sv_isobject(ST(i+3)) | |
3661 | && sv_derived_from(ST(i+3), "Imager::Color")) { | |
3662 | IV tmp = SvIV((SV *)SvRV(ST(i+3))); | |
3663 | work[i] = *INT2PTR(i_color *, tmp); | |
3664 | } | |
3665 | else { | |
3666 | myfree(work); | |
3667 | croak("i_plin: pixels must be Imager::Color objects"); | |
3668 | } | |
faa9b3e7 | 3669 | } |
ca4d914e TC |
3670 | RETVAL = i_plin(im, l, l+items-3, y, work); |
3671 | myfree(work); | |
faa9b3e7 | 3672 | } |
faa9b3e7 TC |
3673 | } |
3674 | else { | |
3675 | RETVAL = 0; | |
3676 | } | |
3677 | OUTPUT: | |
3678 | RETVAL | |
3679 | ||
3680 | int | |
3681 | i_ppixf(im, x, y, cl) | |
3682 | Imager::ImgRaw im | |
8d14daab TC |
3683 | i_img_dim x |
3684 | i_img_dim y | |
faa9b3e7 TC |
3685 | Imager::Color::Float cl |
3686 | ||
3687 | void | |
6a9807e8 | 3688 | i_gsampf(im, l, r, y, channels) |
faa9b3e7 | 3689 | Imager::ImgRaw im |
8d14daab TC |
3690 | i_img_dim l |
3691 | i_img_dim r | |
3692 | i_img_dim y | |
6a9807e8 | 3693 | i_channel_list channels |
faa9b3e7 | 3694 | PREINIT: |
faa9b3e7 | 3695 | i_fsample_t *data; |
8d14daab | 3696 | i_img_dim count, i; |
faa9b3e7 | 3697 | PPCODE: |
faa9b3e7 | 3698 | if (l < r) { |
6a9807e8 TC |
3699 | data = mymalloc(sizeof(i_fsample_t) * (r-l) * channels.count); |
3700 | count = i_gsampf(im, l, r, y, data, channels.channels, channels.count); | |
faa9b3e7 TC |
3701 | if (GIMME_V == G_ARRAY) { |
3702 | EXTEND(SP, count); | |
3703 | for (i = 0; i < count; ++i) | |
3704 | PUSHs(sv_2mortal(newSVnv(data[i]))); | |
3705 | } | |
3706 | else { | |
3707 | EXTEND(SP, 1); | |
3708 | PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t)))); | |
3709 | } | |
3631271b | 3710 | myfree(data); |
faa9b3e7 TC |
3711 | } |
3712 | else { | |
3713 | if (GIMME_V != G_ARRAY) { | |
5736f588 | 3714 | XSRETURN_UNDEF; |
faa9b3e7 TC |
3715 | } |
3716 | } | |
3717 | ||
3718 | int | |
3719 | i_plinf(im, l, y, ...) | |
3720 | Imager::ImgRaw im | |
8d14daab TC |
3721 | i_img_dim l |
3722 | i_img_dim y | |
faa9b3e7 TC |
3723 | PREINIT: |
3724 | i_fcolor *work; | |
8d14daab | 3725 | i_img_dim i; |
ca4d914e | 3726 | STRLEN len; |
8d14daab | 3727 | size_t count; |
faa9b3e7 TC |
3728 | CODE: |
3729 | if (items > 3) { | |
ca4d914e TC |
3730 | if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) { |
3731 | /* supplied as a byte string */ | |
3732 | work = (i_fcolor *)SvPV(ST(3), len); | |
3733 | count = len / sizeof(i_fcolor); | |
3734 | if (count * sizeof(i_fcolor) != len) { | |
3735 | croak("i_plin: length of scalar argument must be multiple of sizeof i_fcolor"); | |
faa9b3e7 | 3736 | } |
ca4d914e TC |
3737 | RETVAL = i_plinf(im, l, l+count, y, work); |
3738 | } | |
3739 | else { | |
3740 | work = mymalloc(sizeof(i_fcolor) * (items-3)); | |
3741 | for (i=0; i < items-3; ++i) { | |
3742 | if (sv_isobject(ST(i+3)) | |
3743 | && sv_derived_from(ST(i+3), "Imager::Color::Float")) { | |
3744 | IV tmp = SvIV((SV *)SvRV(ST(i+3))); | |
3745 | work[i] = *INT2PTR(i_fcolor *, tmp); | |
3746 | } | |
3747 | else { | |
3748 | myfree(work); | |
3749 | croak("i_plinf: pixels must be Imager::Color::Float objects"); | |
3750 | } | |
faa9b3e7 | 3751 | } |
ca4d914e TC |
3752 | /**(char *)0 = 1;*/ |
3753 | RETVAL = i_plinf(im, l, l+items-3, y, work); | |
3754 | myfree(work); | |
faa9b3e7 | 3755 | } |
faa9b3e7 TC |
3756 | } |
3757 | else { | |
3758 | RETVAL = 0; | |
3759 | } | |
3760 | OUTPUT: | |
3761 | RETVAL | |
3762 | ||
73d80423 | 3763 | Imager::Color::Float |
faa9b3e7 TC |
3764 | i_gpixf(im, x, y) |
3765 | Imager::ImgRaw im | |
8d14daab TC |
3766 | i_img_dim x |
3767 | i_img_dim y; | |
faa9b3e7 | 3768 | CODE: |
73d80423 | 3769 | RETVAL = (i_fcolor *)mymalloc(sizeof(i_fcolor)); |
2ea4aa42 | 3770 | memset(RETVAL, 0, sizeof(*RETVAL)); |
73d80423 TC |
3771 | if (i_gpixf(im, x, y, RETVAL) != 0) { |
3772 | myfree(RETVAL); | |
3773 | XSRETURN_UNDEF; | |
faa9b3e7 | 3774 | } |
a659442a TC |
3775 | OUTPUT: |
3776 | RETVAL | |
3777 | ||
faa9b3e7 TC |
3778 | void |
3779 | i_glin(im, l, r, y) | |
3780 | Imager::ImgRaw im | |
8d14daab TC |
3781 | i_img_dim l |
3782 | i_img_dim r | |
3783 | i_img_dim y | |
faa9b3e7 TC |
3784 | PREINIT: |
3785 | i_color *vals; | |
8d14daab | 3786 | i_img_dim count, i; |
faa9b3e7 TC |
3787 | PPCODE: |
3788 | if (l < r) { | |
3789 | vals = mymalloc((r-l) * sizeof(i_color)); | |
b3aa972f | 3790 | memset(vals, 0, (r-l) * sizeof(i_color)); |
faa9b3e7 | 3791 | count = i_glin(im, l, r, y, vals); |
ca4d914e TC |
3792 | if (GIMME_V == G_ARRAY) { |
3793 | EXTEND(SP, count); | |
3794 | for (i = 0; i < count; ++i) { | |
5e9a7fbd | 3795 | SV *sv = make_i_color_sv(aTHX_ vals+i); |
ca4d914e TC |
3796 | PUSHs(sv); |
3797 | } | |
3798 | } | |
3799 | else if (count) { | |
3800 | EXTEND(SP, 1); | |
3801 | PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_color)))); | |
faa9b3e7 TC |
3802 | } |
3803 | myfree(vals); | |
3804 | } | |
3805 | ||
3806 | void | |
3807 | i_glinf(im, l, r, y) | |
3808 | Imager::ImgRaw im | |
8d14daab TC |
3809 | i_img_dim l |
3810 | i_img_dim r | |
3811 | i_img_dim y | |
faa9b3e7 TC |
3812 | PREINIT: |
3813 | i_fcolor *vals; | |
8d14daab | 3814 | i_img_dim count, i; |
919e0000 | 3815 | i_fcolor zero; |
faa9b3e7 | 3816 | PPCODE: |
919e0000 TC |
3817 | for (i = 0; i < MAXCHANNELS; ++i) |
3818 | zero.channel[i] = 0; | |
faa9b3e7 TC |
3819 | if (l < r) { |
3820 | vals = mymalloc((r-l) * sizeof(i_fcolor)); | |
b3aa972f TC |
3821 | for (i = 0; i < r-l; ++i) |
3822 | vals[i] = zero; | |
faa9b3e7 | 3823 | count = i_glinf(im, l, r, y, vals); |
ca4d914e TC |
3824 | if (GIMME_V == G_ARRAY) { |
3825 | EXTEND(SP, count); | |
3826 | for (i = 0; i < count; ++i) { | |
3827 | SV *sv; | |
3828 | i_fcolor *col = mymalloc(sizeof(i_fcolor)); | |
3829 | *col = vals[i]; | |
3830 | sv = sv_newmortal(); | |
3831 | sv_setref_pv(sv, "Imager::Color::Float", (void *)col); | |
3832 | PUSHs(sv); | |
3833 | } | |
3834 | } | |
3835 | else if (count) { | |
3836 | EXTEND(SP, 1); | |
3837 | PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_fcolor)))); | |
faa9b3e7 TC |
3838 | } |
3839 | myfree(vals); | |
3840 | } | |
3841 | ||
bdd4c63b TC |
3842 | Imager::ImgRaw |
3843 | i_img_8_new(x, y, ch) | |
3844 | i_img_dim x | |
3845 | i_img_dim y | |
3846 | int ch | |
3847 | ||
faa9b3e7 TC |
3848 | Imager::ImgRaw |
3849 | i_img_16_new(x, y, ch) | |
8d14daab TC |
3850 | i_img_dim x |
3851 | i_img_dim y | |
faa9b3e7 TC |
3852 | int ch |
3853 | ||
167660cd TC |
3854 | Imager::ImgRaw |
3855 | i_img_to_rgb16(im) | |
3856 | Imager::ImgRaw im | |
3857 | ||
365ea842 TC |
3858 | Imager::ImgRaw |
3859 | i_img_double_new(x, y, ch) | |
8d14daab TC |
3860 | i_img_dim x |
3861 | i_img_dim y | |
365ea842 TC |
3862 | int ch |
3863 | ||
bfe6ba3f TC |
3864 | Imager::ImgRaw |
3865 | i_img_to_drgb(im) | |
3866 | Imager::ImgRaw im | |
3867 | ||
faa9b3e7 | 3868 | undef_int |
b9e2571f | 3869 | i_tags_addn(im, name_sv, code, idata) |
faa9b3e7 | 3870 | Imager::ImgRaw im |
b9e2571f | 3871 | SV *name_sv |
faa9b3e7 TC |
3872 | int code |
3873 | int idata | |
3874 | PREINIT: | |
3875 | char *name; | |
3876 | STRLEN len; | |
3877 | CODE: | |
b9e2571f TC |
3878 | SvGETMAGIC(name_sv); |
3879 | if (SvOK(name_sv)) | |
3880 | name = SvPV_nomg(name_sv, len); | |
faa9b3e7 TC |
3881 | else |
3882 | name = NULL; | |
3883 | RETVAL = i_tags_addn(&im->tags, name, code, idata); | |
3884 | OUTPUT: | |
3885 | RETVAL | |
3886 | ||
3887 | undef_int | |
a4da28d7 | 3888 | i_tags_add(im, name_sv, code, data_sv, idata) |
faa9b3e7 | 3889 | Imager::ImgRaw im |
a4da28d7 | 3890 | SV *name_sv |
faa9b3e7 | 3891 | int code |
a4da28d7 | 3892 | SV *data_sv |
faa9b3e7 TC |
3893 | int idata |
3894 | PREINIT: | |
3895 | char *name; | |
3896 | char *data; | |
3897 | STRLEN len; | |
3898 | CODE: | |
a4da28d7 TC |
3899 | SvGETMAGIC(name_sv); |
3900 | if (SvOK(name_sv)) | |
3901 | name = SvPV_nomg(name_sv, len); | |
faa9b3e7 TC |
3902 | else |
3903 | name = NULL; | |
a4da28d7 TC |
3904 | SvGETMAGIC(data_sv); |
3905 | if (SvOK(data_sv)) | |
3906 | data = SvPV(data_sv, len); | |
faa9b3e7 TC |
3907 | else { |
3908 | data = NULL; | |
3909 | len = 0; | |
3910 | } | |
3911 | RETVAL = i_tags_add(&im->tags, name, code, data, len, idata); | |
3912 | OUTPUT: | |
3913 | RETVAL | |
3914 | ||
f4aca831 | 3915 | SysRet |
faa9b3e7 TC |
3916 | i_tags_find(im, name, start) |
3917 | Imager::ImgRaw im | |
3918 | char *name | |
3919 | int start | |
3920 | PREINIT: | |
3921 | int entry; | |
3922 | CODE: | |
3923 | if (i_tags_find(&im->tags, name, start, &entry)) { | |
f4aca831 | 3924 | RETVAL = entry; |
faa9b3e7 | 3925 | } else { |
f4aca831 | 3926 | XSRETURN_UNDEF; |
faa9b3e7 | 3927 | } |
a659442a TC |
3928 | OUTPUT: |
3929 | RETVAL | |
faa9b3e7 | 3930 | |
f4aca831 | 3931 | SysRet |
faa9b3e7 TC |
3932 | i_tags_findn(im, code, start) |
3933 | Imager::ImgRaw im | |
3934 | int code | |
3935 | int start | |