Commit | Line | Data |
---|---|---|
02d1d628 AMH |
1 | #ifdef __cplusplus |
2 | extern "C" { | |
3 | #endif | |
4 | #include "EXTERN.h" | |
5 | #include "perl.h" | |
6 | #include "XSUB.h" | |
7 | #include "ppport.h" | |
8 | #ifdef __cplusplus | |
9 | ||
10 | #endif | |
11 | ||
12 | #include "image.h" | |
13 | #include "feat.h" | |
14 | #include "dynaload.h" | |
15 | #include "regmach.h" | |
16 | ||
17 | typedef io_glue* Imager__IO; | |
18 | typedef i_color* Imager__Color; | |
faa9b3e7 | 19 | typedef i_fcolor* Imager__Color__Float; |
02d1d628 AMH |
20 | typedef i_img* Imager__ImgRaw; |
21 | ||
02d1d628 | 22 | #ifdef HAVE_LIBTT |
4b19f77a | 23 | typedef TT_Fonthandle* Imager__Font__TT; |
02d1d628 AMH |
24 | #endif |
25 | ||
faa9b3e7 TC |
26 | #ifdef HAVE_FT2 |
27 | typedef FT2_Fonthandle* Imager__Font__FT2; | |
28 | #endif | |
29 | ||
b33c08f8 TC |
30 | /* These functions are all shared - then comes platform dependant code */ |
31 | static int getstr(void *hv_t,char *key,char **store) { | |
32 | SV** svpp; | |
33 | HV* hv=(HV*)hv_t; | |
34 | ||
35 | mm_log((1,"getstr(hv_t 0x%X, key %s, store 0x%X)\n",hv_t,key,store)); | |
36 | ||
37 | if ( !hv_exists(hv,key,strlen(key)) ) return 0; | |
38 | ||
39 | svpp=hv_fetch(hv, key, strlen(key), 0); | |
40 | *store=SvPV(*svpp, PL_na ); | |
41 | ||
42 | return 1; | |
43 | } | |
44 | ||
45 | static int getint(void *hv_t,char *key,int *store) { | |
46 | SV** svpp; | |
47 | HV* hv=(HV*)hv_t; | |
48 | ||
49 | mm_log((1,"getint(hv_t 0x%X, key %s, store 0x%X)\n",hv_t,key,store)); | |
50 | ||
51 | if ( !hv_exists(hv,key,strlen(key)) ) return 0; | |
52 | ||
53 | svpp=hv_fetch(hv, key, strlen(key), 0); | |
54 | *store=(int)SvIV(*svpp); | |
55 | return 1; | |
56 | } | |
57 | ||
58 | static int getdouble(void *hv_t,char* key,double *store) { | |
59 | SV** svpp; | |
60 | HV* hv=(HV*)hv_t; | |
61 | ||
62 | mm_log((1,"getdouble(hv_t 0x%X, key %s, store 0x%X)\n",hv_t,key,store)); | |
63 | ||
64 | if ( !hv_exists(hv,key,strlen(key)) ) return 0; | |
65 | svpp=hv_fetch(hv, key, strlen(key), 0); | |
66 | *store=(float)SvNV(*svpp); | |
67 | return 1; | |
68 | } | |
69 | ||
70 | static int getvoid(void *hv_t,char* key,void **store) { | |
71 | SV** svpp; | |
72 | HV* hv=(HV*)hv_t; | |
73 | ||
74 | mm_log((1,"getvoid(hv_t 0x%X, key %s, store 0x%X)\n",hv_t,key,store)); | |
75 | ||
76 | if ( !hv_exists(hv,key,strlen(key)) ) return 0; | |
77 | ||
78 | svpp=hv_fetch(hv, key, strlen(key), 0); | |
79 | *store = INT2PTR(void*, SvIV(*svpp)); | |
80 | ||
81 | return 1; | |
82 | } | |
83 | ||
84 | static int getobj(void *hv_t,char *key,char *type,void **store) { | |
85 | SV** svpp; | |
86 | HV* hv=(HV*)hv_t; | |
87 | ||
88 | mm_log((1,"getobj(hv_t 0x%X, key %s,type %s, store 0x%X)\n",hv_t,key,type,store)); | |
89 | ||
90 | if ( !hv_exists(hv,key,strlen(key)) ) return 0; | |
91 | ||
92 | svpp=hv_fetch(hv, key, strlen(key), 0); | |
93 | ||
94 | if (sv_derived_from(*svpp,type)) { | |
95 | IV tmp = SvIV((SV*)SvRV(*svpp)); | |
96 | *store = INT2PTR(void*, tmp); | |
97 | } else { | |
98 | mm_log((1,"getobj: key exists in hash but is not of correct type")); | |
99 | return 0; | |
100 | } | |
101 | ||
102 | return 1; | |
103 | } | |
104 | ||
105 | UTIL_table_t i_UTIL_table={getstr,getint,getdouble,getvoid,getobj}; | |
4dfa5522 AMH |
106 | |
107 | void my_SvREFCNT_dec(void *p) { | |
108 | SvREFCNT_dec((SV*)p); | |
109 | } | |
110 | ||
7f882a01 | 111 | |
b33c08f8 | 112 | static void |
7f882a01 AMH |
113 | log_entry(char *string, int level) { |
114 | mm_log((level, string)); | |
115 | } | |
116 | ||
117 | ||
02d1d628 AMH |
118 | typedef struct i_reader_data_tag |
119 | { | |
120 | /* presumably a CODE ref or name of a sub */ | |
121 | SV *sv; | |
122 | } i_reader_data; | |
123 | ||
124 | /* used by functions that want callbacks */ | |
125 | static int read_callback(char *userdata, char *buffer, int need, int want) { | |
126 | i_reader_data *rd = (i_reader_data *)userdata; | |
127 | int count; | |
128 | int result; | |
129 | SV *data; | |
130 | dSP; dTARG = sv_newmortal(); | |
131 | /* thanks to Simon Cozens for help with the dTARG above */ | |
132 | ||
133 | ENTER; | |
134 | SAVETMPS; | |
135 | EXTEND(SP, 2); | |
136 | PUSHMARK(SP); | |
137 | PUSHi(want); | |
138 | PUSHi(need); | |
139 | PUTBACK; | |
140 | ||
141 | count = perl_call_sv(rd->sv, G_SCALAR); | |
142 | ||
143 | SPAGAIN; | |
144 | ||
145 | if (count != 1) | |
146 | croak("Result of perl_call_sv(..., G_SCALAR) != 1"); | |
147 | ||
148 | data = POPs; | |
149 | ||
150 | if (SvOK(data)) { | |
151 | STRLEN len; | |
152 | char *ptr = SvPV(data, len); | |
153 | if (len > want) | |
154 | croak("Too much data returned in reader callback"); | |
155 | ||
156 | memcpy(buffer, ptr, len); | |
157 | result = len; | |
158 | } | |
159 | else { | |
160 | result = -1; | |
161 | } | |
162 | ||
163 | PUTBACK; | |
164 | FREETMPS; | |
165 | LEAVE; | |
166 | ||
167 | return result; | |
168 | } | |
169 | ||
170 | typedef struct | |
171 | { | |
172 | SV *sv; /* a coderef or sub name */ | |
173 | } i_writer_data; | |
174 | ||
175 | /* used by functions that want callbacks */ | |
176 | static int write_callback(char *userdata, char const *data, int size) { | |
177 | i_writer_data *wd = (i_writer_data *)userdata; | |
178 | int count; | |
179 | int success; | |
180 | SV *sv; | |
181 | dSP; | |
182 | ||
183 | ENTER; | |
184 | SAVETMPS; | |
185 | EXTEND(SP, 1); | |
186 | PUSHMARK(SP); | |
187 | XPUSHs(sv_2mortal(newSVpv((char *)data, size))); | |
188 | PUTBACK; | |
189 | ||
190 | count = perl_call_sv(wd->sv, G_SCALAR); | |
191 | ||
192 | SPAGAIN; | |
193 | ||
194 | if (count != 1) | |
195 | croak("Result of perl_call_sv(..., G_SCALAR) != 1"); | |
196 | ||
197 | sv = POPs; | |
198 | success = SvTRUE(sv); | |
199 | ||
200 | ||
201 | PUTBACK; | |
202 | FREETMPS; | |
203 | LEAVE; | |
204 | ||
205 | return success; | |
206 | } | |
207 | ||
10461f9a TC |
208 | #define CBDATA_BUFSIZE 8192 |
209 | ||
210 | struct cbdata { | |
211 | /* the SVs we use to call back to Perl */ | |
212 | SV *writecb; | |
213 | SV *readcb; | |
214 | SV *seekcb; | |
215 | SV *closecb; | |
216 | ||
217 | /* we need to remember whether the buffer contains write data or | |
218 | read data | |
219 | */ | |
220 | int reading; | |
221 | int writing; | |
222 | ||
223 | /* how far we've read into the buffer (not used for writing) */ | |
224 | int where; | |
225 | ||
226 | /* the amount of space used/data available in the buffer */ | |
227 | int used; | |
228 | ||
229 | /* the maximum amount to fill the buffer before flushing | |
230 | If any write is larger than this then the buffer is flushed and | |
231 | the full write is performed. The write is _not_ split into | |
232 | maxwrite sized calls | |
233 | */ | |
234 | int maxlength; | |
235 | ||
236 | char buffer[CBDATA_BUFSIZE]; | |
237 | }; | |
238 | ||
239 | /* | |
240 | ||
241 | call_writer(cbd, buf, size) | |
242 | ||
243 | Low-level function to call the perl writer callback. | |
244 | ||
245 | */ | |
246 | ||
247 | static ssize_t call_writer(struct cbdata *cbd, void const *buf, size_t size) { | |
248 | int count; | |
249 | int success; | |
250 | SV *sv; | |
251 | dSP; | |
252 | ||
253 | if (!SvOK(cbd->writecb)) | |
254 | return -1; | |
255 | ||
256 | ENTER; | |
257 | SAVETMPS; | |
258 | EXTEND(SP, 1); | |
259 | PUSHMARK(SP); | |
260 | PUSHs(sv_2mortal(newSVpv((char *)buf, size))); | |
261 | PUTBACK; | |
262 | ||
263 | count = perl_call_sv(cbd->writecb, G_SCALAR); | |
264 | ||
265 | SPAGAIN; | |
266 | if (count != 1) | |
267 | croak("Result of perl_call_sv(..., G_SCALAR) != 1"); | |
268 | ||
269 | sv = POPs; | |
270 | success = SvTRUE(sv); | |
271 | ||
272 | ||
273 | PUTBACK; | |
274 | FREETMPS; | |
275 | LEAVE; | |
276 | ||
277 | return success ? size : 0; | |
278 | } | |
279 | ||
280 | static ssize_t call_reader(struct cbdata *cbd, void *buf, size_t size, | |
281 | size_t maxread) { | |
282 | int count; | |
283 | int result; | |
284 | SV *data; | |
285 | dSP; | |
286 | ||
287 | if (!SvOK(cbd->readcb)) | |
288 | return -1; | |
289 | ||
290 | ENTER; | |
291 | SAVETMPS; | |
292 | EXTEND(SP, 2); | |
293 | PUSHMARK(SP); | |
294 | PUSHs(sv_2mortal(newSViv(size))); | |
295 | PUSHs(sv_2mortal(newSViv(maxread))); | |
296 | PUTBACK; | |
297 | ||
298 | count = perl_call_sv(cbd->readcb, G_SCALAR); | |
299 | ||
300 | SPAGAIN; | |
301 | ||
302 | if (count != 1) | |
303 | croak("Result of perl_call_sv(..., G_SCALAR) != 1"); | |
304 | ||
305 | data = POPs; | |
306 | ||
307 | if (SvOK(data)) { | |
308 | STRLEN len; | |
309 | char *ptr = SvPV(data, len); | |
310 | if (len > maxread) | |
311 | croak("Too much data returned in reader callback"); | |
312 | ||
313 | memcpy(buf, ptr, len); | |
314 | result = len; | |
315 | } | |
316 | else { | |
317 | result = -1; | |
318 | } | |
319 | ||
320 | PUTBACK; | |
321 | FREETMPS; | |
322 | LEAVE; | |
323 | ||
324 | return result; | |
325 | } | |
326 | ||
327 | static ssize_t write_flush(struct cbdata *cbd) { | |
328 | ssize_t result; | |
329 | ||
330 | result = call_writer(cbd, cbd->buffer, cbd->used); | |
331 | cbd->used = 0; | |
332 | return result; | |
333 | } | |
334 | ||
335 | static off_t io_seeker(void *p, off_t offset, int whence) { | |
336 | struct cbdata *cbd = p; | |
337 | int count; | |
338 | off_t result; | |
339 | dSP; | |
340 | ||
341 | if (!SvOK(cbd->seekcb)) | |
342 | return -1; | |
343 | ||
344 | if (cbd->writing) { | |
345 | if (cbd->used && write_flush(cbd) <= 0) | |
346 | return -1; | |
347 | cbd->writing = 0; | |
348 | } | |
349 | if (whence == SEEK_CUR && cbd->reading && cbd->where != cbd->used) { | |
350 | offset -= cbd->where - cbd->used; | |
351 | } | |
352 | cbd->reading = 0; | |
353 | cbd->where = cbd->used = 0; | |
354 | ||
355 | ENTER; | |
356 | SAVETMPS; | |
357 | EXTEND(SP, 2); | |
358 | PUSHMARK(SP); | |
359 | PUSHs(sv_2mortal(newSViv(offset))); | |
360 | PUSHs(sv_2mortal(newSViv(whence))); | |
361 | PUTBACK; | |
362 | ||
363 | count = perl_call_sv(cbd->seekcb, G_SCALAR); | |
364 | ||
365 | SPAGAIN; | |
366 | ||
367 | if (count != 1) | |
368 | croak("Result of perl_call_sv(..., G_SCALAR) != 1"); | |
369 | ||
370 | result = POPi; | |
371 | ||
372 | PUTBACK; | |
373 | FREETMPS; | |
374 | LEAVE; | |
375 | ||
376 | return result; | |
377 | } | |
378 | ||
379 | static ssize_t io_writer(void *p, void const *data, size_t size) { | |
380 | struct cbdata *cbd = p; | |
381 | ||
382 | /*printf("io_writer(%p, %p, %u)\n", p, data, size);*/ | |
383 | if (!cbd->writing) { | |
384 | if (cbd->reading && cbd->where < cbd->used) { | |
385 | /* we read past the place where the caller expected us to be | |
386 | so adjust our position a bit */ | |
387 | *(char *)0 = 0; | |
388 | if (io_seeker(p, cbd->where - cbd->used, SEEK_CUR) < 0) { | |
389 | return -1; | |
390 | } | |
391 | cbd->reading = 0; | |
392 | } | |
393 | cbd->where = cbd->used = 0; | |
394 | } | |
395 | cbd->writing = 1; | |
396 | if (cbd->used && cbd->used + size > cbd->maxlength) { | |
397 | if (write_flush(cbd) <= 0) { | |
398 | return 0; | |
399 | } | |
400 | cbd->used = 0; | |
401 | } | |
402 | if (cbd->used+size <= cbd->maxlength) { | |
403 | memcpy(cbd->buffer + cbd->used, data, size); | |
404 | cbd->used += size; | |
405 | return size; | |
406 | } | |
407 | /* it doesn't fit - just pass it up */ | |
408 | return call_writer(cbd, data, size); | |
409 | } | |
410 | ||
411 | static ssize_t io_reader(void *p, void *data, size_t size) { | |
412 | struct cbdata *cbd = p; | |
413 | ssize_t total; | |
414 | char *out = data; /* so we can do pointer arithmetic */ | |
10461f9a TC |
415 | |
416 | if (cbd->writing) { | |
417 | if (write_flush(cbd) <= 0) | |
418 | return 0; | |
419 | cbd->writing = 0; | |
420 | } | |
421 | ||
422 | cbd->reading = 1; | |
423 | if (size <= cbd->used - cbd->where) { | |
424 | /* simplest case */ | |
425 | memcpy(data, cbd->buffer+cbd->where, size); | |
426 | cbd->where += size; | |
427 | return size; | |
428 | } | |
429 | total = 0; | |
430 | memcpy(out, cbd->buffer + cbd->where, cbd->used - cbd->where); | |
431 | total += cbd->used - cbd->where; | |
432 | size -= cbd->used - cbd->where; | |
433 | out += cbd->used - cbd->where; | |
434 | if (size < sizeof(cbd->buffer)) { | |
435 | int did_read; | |
436 | int copy_size; | |
437 | while (size | |
438 | && (did_read = call_reader(cbd, cbd->buffer, size, | |
439 | sizeof(cbd->buffer))) > 0) { | |
440 | cbd->where = 0; | |
441 | cbd->used = did_read; | |
442 | ||
b33c08f8 | 443 | copy_size = i_min(size, cbd->used); |
10461f9a TC |
444 | memcpy(out, cbd->buffer, copy_size); |
445 | cbd->where += copy_size; | |
446 | out += copy_size; | |
447 | total += copy_size; | |
448 | size -= copy_size; | |
449 | } | |
450 | } | |
451 | else { | |
452 | /* just read the rest - too big for our buffer*/ | |
453 | int did_read; | |
454 | while ((did_read = call_reader(cbd, out, size, size)) > 0) { | |
455 | size -= did_read; | |
456 | total += did_read; | |
457 | out += did_read; | |
458 | } | |
459 | } | |
460 | ||
461 | return total; | |
462 | } | |
463 | ||
464 | static void io_closer(void *p) { | |
465 | struct cbdata *cbd = p; | |
466 | ||
467 | if (cbd->writing && cbd->used > 0) { | |
468 | write_flush(cbd); | |
469 | cbd->writing = 0; | |
470 | } | |
471 | ||
472 | if (SvOK(cbd->closecb)) { | |
473 | dSP; | |
474 | ||
475 | ENTER; | |
476 | SAVETMPS; | |
477 | PUSHMARK(SP); | |
478 | PUTBACK; | |
479 | ||
480 | perl_call_sv(cbd->closecb, G_VOID); | |
481 | ||
482 | SPAGAIN; | |
483 | PUTBACK; | |
484 | FREETMPS; | |
485 | LEAVE; | |
486 | } | |
487 | } | |
488 | ||
489 | static void io_destroyer(void *p) { | |
490 | struct cbdata *cbd = p; | |
491 | ||
492 | SvREFCNT_dec(cbd->writecb); | |
493 | SvREFCNT_dec(cbd->readcb); | |
494 | SvREFCNT_dec(cbd->seekcb); | |
495 | SvREFCNT_dec(cbd->closecb); | |
496 | } | |
497 | ||
02d1d628 AMH |
498 | struct value_name { |
499 | char *name; | |
500 | int value; | |
501 | }; | |
502 | static int lookup_name(struct value_name *names, int count, char *name, int def_value) | |
503 | { | |
504 | int i; | |
505 | for (i = 0; i < count; ++i) | |
506 | if (strEQ(names[i].name, name)) | |
507 | return names[i].value; | |
508 | ||
509 | return def_value; | |
510 | } | |
511 | static struct value_name transp_names[] = | |
512 | { | |
513 | { "none", tr_none }, | |
514 | { "threshold", tr_threshold }, | |
515 | { "errdiff", tr_errdiff }, | |
516 | { "ordered", tr_ordered, }, | |
517 | }; | |
518 | ||
519 | static struct value_name make_color_names[] = | |
520 | { | |
521 | { "none", mc_none, }, | |
522 | { "webmap", mc_web_map, }, | |
523 | { "addi", mc_addi, }, | |
97c4effc | 524 | { "mediancut", mc_median_cut, }, |
02d1d628 AMH |
525 | }; |
526 | ||
527 | static struct value_name translate_names[] = | |
528 | { | |
529 | #ifdef HAVE_LIBGIF | |
530 | { "giflib", pt_giflib, }, | |
531 | #endif | |
532 | { "closest", pt_closest, }, | |
533 | { "perturb", pt_perturb, }, | |
534 | { "errdiff", pt_errdiff, }, | |
535 | }; | |
536 | ||
537 | static struct value_name errdiff_names[] = | |
538 | { | |
539 | { "floyd", ed_floyd, }, | |
540 | { "jarvis", ed_jarvis, }, | |
541 | { "stucki", ed_stucki, }, | |
542 | { "custom", ed_custom, }, | |
543 | }; | |
544 | ||
545 | static struct value_name orddith_names[] = | |
546 | { | |
547 | { "random", od_random, }, | |
548 | { "dot8", od_dot8, }, | |
549 | { "dot4", od_dot4, }, | |
550 | { "hline", od_hline, }, | |
551 | { "vline", od_vline, }, | |
552 | { "/line", od_slashline, }, | |
553 | { "slashline", od_slashline, }, | |
554 | { "\\line", od_backline, }, | |
555 | { "backline", od_backline, }, | |
e7d4ea82 | 556 | { "tiny", od_tiny, }, |
02d1d628 AMH |
557 | { "custom", od_custom, }, |
558 | }; | |
559 | ||
bf9dd17c | 560 | static int |
07e3e23d | 561 | hv_fetch_bool(HV *hv, char *name, int def) { |
bf9dd17c TC |
562 | SV **sv; |
563 | ||
564 | sv = hv_fetch(hv, name, strlen(name), 0); | |
565 | if (sv && *sv) { | |
566 | return SvTRUE(*sv); | |
567 | } | |
568 | else | |
569 | return def; | |
570 | } | |
571 | ||
572 | static int | |
07e3e23d | 573 | hv_fetch_int(HV *hv, char *name, int def) { |
bf9dd17c TC |
574 | SV **sv; |
575 | ||
576 | sv = hv_fetch(hv, name, strlen(name), 0); | |
577 | if (sv && *sv) { | |
578 | return SvIV(*sv); | |
579 | } | |
580 | else | |
581 | return def; | |
582 | } | |
583 | ||
02d1d628 AMH |
584 | /* look through the hash for quantization options */ |
585 | static void handle_quant_opts(i_quantize *quant, HV *hv) | |
586 | { | |
587 | /*** POSSIBLY BROKEN: do I need to unref the SV from hv_fetch ***/ | |
588 | SV **sv; | |
589 | int i; | |
590 | STRLEN len; | |
591 | char *str; | |
592 | ||
46a04ceb TC |
593 | quant->mc_colors = mymalloc(quant->mc_size * sizeof(i_color)); |
594 | ||
02d1d628 AMH |
595 | sv = hv_fetch(hv, "transp", 6, 0); |
596 | if (sv && *sv && (str = SvPV(*sv, len))) { | |
597 | quant->transp = | |
598 | lookup_name(transp_names, sizeof(transp_names)/sizeof(*transp_names), | |
599 | str, tr_none); | |
600 | if (quant->transp != tr_none) { | |
601 | quant->tr_threshold = 127; | |
602 | sv = hv_fetch(hv, "tr_threshold", 12, 0); | |
603 | if (sv && *sv) | |
604 | quant->tr_threshold = SvIV(*sv); | |
605 | } | |
606 | if (quant->transp == tr_errdiff) { | |
607 | sv = hv_fetch(hv, "tr_errdiff", 10, 0); | |
608 | if (sv && *sv && (str = SvPV(*sv, len))) | |
609 | quant->tr_errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd); | |
610 | } | |
611 | if (quant->transp == tr_ordered) { | |
e7d4ea82 | 612 | quant->tr_orddith = od_tiny; |
02d1d628 AMH |
613 | sv = hv_fetch(hv, "tr_orddith", 10, 0); |
614 | if (sv && *sv && (str = SvPV(*sv, len))) | |
615 | quant->tr_orddith = lookup_name(orddith_names, sizeof(orddith_names)/sizeof(*orddith_names), str, od_random); | |
616 | ||
617 | if (quant->tr_orddith == od_custom) { | |
618 | sv = hv_fetch(hv, "tr_map", 6, 0); | |
619 | if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) { | |
620 | AV *av = (AV*)SvRV(*sv); | |
621 | len = av_len(av) + 1; | |
622 | if (len > sizeof(quant->tr_custom)) | |
623 | len = sizeof(quant->tr_custom); | |
624 | for (i = 0; i < len; ++i) { | |
625 | SV **sv2 = av_fetch(av, i, 0); | |
626 | if (sv2 && *sv2) { | |
627 | quant->tr_custom[i] = SvIV(*sv2); | |
628 | } | |
629 | } | |
630 | while (i < sizeof(quant->tr_custom)) | |
631 | quant->tr_custom[i++] = 0; | |
632 | } | |
633 | } | |
634 | } | |
635 | } | |
636 | quant->make_colors = mc_addi; | |
637 | sv = hv_fetch(hv, "make_colors", 11, 0); | |
638 | if (sv && *sv && (str = SvPV(*sv, len))) { | |
639 | quant->make_colors = | |
640 | lookup_name(make_color_names, sizeof(make_color_names)/sizeof(*make_color_names), str, mc_addi); | |
641 | } | |
642 | sv = hv_fetch(hv, "colors", 6, 0); | |
643 | if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { | |
644 | /* needs to be an array of Imager::Color | |
645 | note that the caller allocates the mc_color array and sets mc_size | |
646 | to it's size */ | |
647 | AV *av = (AV *)SvRV(*sv); | |
648 | quant->mc_count = av_len(av)+1; | |
649 | if (quant->mc_count > quant->mc_size) | |
650 | quant->mc_count = quant->mc_size; | |
651 | for (i = 0; i < quant->mc_count; ++i) { | |
652 | SV **sv1 = av_fetch(av, i, 0); | |
653 | if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) { | |
4c4c2ffd | 654 | i_color *col = INT2PTR(i_color *, SvIV((SV*)SvRV(*sv1))); |
02d1d628 AMH |
655 | quant->mc_colors[i] = *col; |
656 | } | |
657 | } | |
658 | } | |
659 | sv = hv_fetch(hv, "max_colors", 10, 0); | |
660 | if (sv && *sv) { | |
661 | i = SvIV(*sv); | |
662 | if (i <= quant->mc_size && i >= quant->mc_count) | |
663 | quant->mc_size = i; | |
664 | } | |
665 | ||
666 | quant->translate = pt_closest; | |
667 | sv = hv_fetch(hv, "translate", 9, 0); | |
668 | if (sv && *sv && (str = SvPV(*sv, len))) { | |
669 | quant->translate = lookup_name(translate_names, sizeof(translate_names)/sizeof(*translate_names), str, pt_closest); | |
670 | } | |
671 | sv = hv_fetch(hv, "errdiff", 7, 0); | |
672 | if (sv && *sv && (str = SvPV(*sv, len))) { | |
673 | quant->errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd); | |
674 | } | |
675 | if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) { | |
676 | /* get the error diffusion map */ | |
677 | sv = hv_fetch(hv, "errdiff_width", 13, 0); | |
678 | if (sv && *sv) | |
679 | quant->ed_width = SvIV(*sv); | |
680 | sv = hv_fetch(hv, "errdiff_height", 14, 0); | |
681 | if (sv && *sv) | |
682 | quant->ed_height = SvIV(*sv); | |
683 | sv = hv_fetch(hv, "errdiff_orig", 12, 0); | |
684 | if (sv && *sv) | |
685 | quant->ed_orig = SvIV(*sv); | |
686 | if (quant->ed_width > 0 && quant->ed_height > 0) { | |
687 | int sum = 0; | |
688 | quant->ed_map = mymalloc(sizeof(int)*quant->ed_width*quant->ed_height); | |
689 | sv = hv_fetch(hv, "errdiff_map", 11, 0); | |
690 | if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { | |
691 | AV *av = (AV*)SvRV(*sv); | |
692 | len = av_len(av) + 1; | |
693 | if (len > quant->ed_width * quant->ed_height) | |
694 | len = quant->ed_width * quant->ed_height; | |
695 | for (i = 0; i < len; ++i) { | |
696 | SV **sv2 = av_fetch(av, i, 0); | |
697 | if (sv2 && *sv2) { | |
698 | quant->ed_map[i] = SvIV(*sv2); | |
699 | sum += quant->ed_map[i]; | |
700 | } | |
701 | } | |
702 | } | |
703 | if (!sum) { | |
704 | /* broken map */ | |
705 | myfree(quant->ed_map); | |
706 | quant->ed_map = 0; | |
707 | quant->errdiff = ed_floyd; | |
708 | } | |
709 | } | |
710 | } | |
711 | sv = hv_fetch(hv, "perturb", 7, 0); | |
712 | if (sv && *sv) | |
713 | quant->perturb = SvIV(*sv); | |
714 | } | |
715 | ||
46a04ceb TC |
716 | static void cleanup_quant_opts(i_quantize *quant) { |
717 | myfree(quant->mc_colors); | |
718 | if (quant->ed_map) | |
719 | myfree(quant->ed_map); | |
720 | } | |
721 | ||
97c4effc | 722 | #if 0 |
02d1d628 AMH |
723 | /* look through the hash for options to add to opts */ |
724 | static void handle_gif_opts(i_gif_opts *opts, HV *hv) | |
725 | { | |
02d1d628 AMH |
726 | SV **sv; |
727 | int i; | |
728 | /**((char *)0) = '\0';*/ | |
bf9dd17c TC |
729 | opts->each_palette = hv_fetch_bool(hv, "gif_each_palette", 0); |
730 | opts->interlace = hv_fetch_bool(hv, "interlace", 0); | |
731 | ||
02d1d628 AMH |
732 | sv = hv_fetch(hv, "gif_delays", 10, 0); |
733 | if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { | |
734 | AV *av = (AV*)SvRV(*sv); | |
735 | opts->delay_count = av_len(av)+1; | |
736 | opts->delays = mymalloc(sizeof(int) * opts->delay_count); | |
737 | for (i = 0; i < opts->delay_count; ++i) { | |
738 | SV *sv1 = *av_fetch(av, i, 0); | |
739 | opts->delays[i] = SvIV(sv1); | |
740 | } | |
741 | } | |
742 | sv = hv_fetch(hv, "gif_user_input", 14, 0); | |
743 | if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { | |
744 | AV *av = (AV*)SvRV(*sv); | |
745 | opts->user_input_count = av_len(av)+1; | |
746 | opts->user_input_flags = mymalloc(opts->user_input_count); | |
747 | for (i = 0; i < opts->user_input_count; ++i) { | |
748 | SV *sv1 = *av_fetch(av, i, 0); | |
749 | opts->user_input_flags[i] = SvIV(sv1) != 0; | |
750 | } | |
751 | } | |
752 | sv = hv_fetch(hv, "gif_disposal", 12, 0); | |
753 | if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { | |
754 | AV *av = (AV*)SvRV(*sv); | |
755 | opts->disposal_count = av_len(av)+1; | |
756 | opts->disposal = mymalloc(opts->disposal_count); | |
757 | for (i = 0; i < opts->disposal_count; ++i) { | |
758 | SV *sv1 = *av_fetch(av, i, 0); | |
759 | opts->disposal[i] = SvIV(sv1); | |
760 | } | |
761 | } | |
762 | sv = hv_fetch(hv, "gif_tran_color", 14, 0); | |
763 | if (sv && *sv && SvROK(*sv) && sv_derived_from(*sv, "Imager::Color")) { | |
4c4c2ffd | 764 | i_color *col = INT2PTR(i_color *, SvIV((SV *)SvRV(*sv))); |
02d1d628 AMH |
765 | opts->tran_color = *col; |
766 | } | |
767 | sv = hv_fetch(hv, "gif_positions", 13, 0); | |
768 | if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { | |
769 | AV *av = (AV *)SvRV(*sv); | |
770 | opts->position_count = av_len(av) + 1; | |
771 | opts->positions = mymalloc(sizeof(i_gif_pos) * opts->position_count); | |
772 | for (i = 0; i < opts->position_count; ++i) { | |
773 | SV **sv2 = av_fetch(av, i, 0); | |
774 | opts->positions[i].x = opts->positions[i].y = 0; | |
775 | if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { | |
776 | AV *av2 = (AV*)SvRV(*sv2); | |
777 | SV **sv3; | |
778 | sv3 = av_fetch(av2, 0, 0); | |
779 | if (sv3 && *sv3) | |
780 | opts->positions[i].x = SvIV(*sv3); | |
781 | sv3 = av_fetch(av2, 1, 0); | |
782 | if (sv3 && *sv3) | |
783 | opts->positions[i].y = SvIV(*sv3); | |
784 | } | |
785 | } | |
786 | } | |
787 | /* Netscape2.0 loop count extension */ | |
bf9dd17c TC |
788 | opts->loop_count = hv_fetch_int(hv, "gif_loop_count", 0); |
789 | ||
790 | opts->eliminate_unused = hv_fetch_bool(hv, "gif_eliminate_unused", 1); | |
02d1d628 AMH |
791 | } |
792 | ||
46a04ceb TC |
793 | static void cleanup_gif_opts(i_gif_opts *opts) { |
794 | if (opts->delays) | |
795 | myfree(opts->delays); | |
796 | if (opts->user_input_flags) | |
797 | myfree(opts->user_input_flags); | |
798 | if (opts->disposal) | |
799 | myfree(opts->disposal); | |
800 | if (opts->positions) | |
801 | myfree(opts->positions); | |
802 | } | |
803 | ||
97c4effc TC |
804 | #endif |
805 | ||
02d1d628 AMH |
806 | /* copies the color map from the hv into the colors member of the HV */ |
807 | static void copy_colors_back(HV *hv, i_quantize *quant) { | |
808 | SV **sv; | |
809 | AV *av; | |
810 | int i; | |
811 | SV *work; | |
812 | ||
813 | sv = hv_fetch(hv, "colors", 6, 0); | |
814 | if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) { | |
815 | SV *ref; | |
816 | av = newAV(); | |
817 | ref = newRV_inc((SV*) av); | |
818 | sv = hv_store(hv, "colors", 6, ref, 0); | |
819 | } | |
820 | else { | |
821 | av = (AV *)SvRV(*sv); | |
822 | } | |
823 | av_extend(av, quant->mc_count+1); | |
824 | for (i = 0; i < quant->mc_count; ++i) { | |
825 | i_color *in = quant->mc_colors+i; | |
826 | Imager__Color c = ICL_new_internal(in->rgb.r, in->rgb.g, in->rgb.b, 255); | |
827 | work = sv_newmortal(); | |
828 | sv_setref_pv(work, "Imager::Color", (void *)c); | |
829 | SvREFCNT_inc(work); | |
830 | if (!av_store(av, i, work)) { | |
831 | SvREFCNT_dec(work); | |
832 | } | |
833 | } | |
834 | } | |
835 | ||
f1ac5027 | 836 | /* loads the segments of a fountain fill into an array */ |
b33c08f8 TC |
837 | static i_fountain_seg * |
838 | load_fount_segs(AV *asegs, int *count) { | |
f1ac5027 TC |
839 | /* Each element of segs must contain: |
840 | [ start, middle, end, c0, c1, segtype, colortrans ] | |
841 | start, middle, end are doubles from 0 to 1 | |
842 | c0, c1 are Imager::Color::Float or Imager::Color objects | |
843 | segtype, colortrans are ints | |
844 | */ | |
845 | int i, j; | |
846 | AV *aseg; | |
847 | SV *sv; | |
848 | i_fountain_seg *segs; | |
849 | double work[3]; | |
850 | int worki[2]; | |
851 | ||
852 | *count = av_len(asegs)+1; | |
853 | if (*count < 1) | |
854 | croak("i_fountain must have at least one segment"); | |
855 | segs = mymalloc(sizeof(i_fountain_seg) * *count); | |
856 | for(i = 0; i < *count; i++) { | |
857 | SV **sv1 = av_fetch(asegs, i, 0); | |
858 | if (!sv1 || !*sv1 || !SvROK(*sv1) | |
859 | || SvTYPE(SvRV(*sv1)) != SVt_PVAV) { | |
860 | myfree(segs); | |
861 | croak("i_fountain: segs must be an arrayref of arrayrefs"); | |
862 | } | |
863 | aseg = (AV *)SvRV(*sv1); | |
864 | if (av_len(aseg) != 7-1) { | |
865 | myfree(segs); | |
866 | croak("i_fountain: a segment must have 7 members"); | |
867 | } | |
868 | for (j = 0; j < 3; ++j) { | |
869 | SV **sv2 = av_fetch(aseg, j, 0); | |
870 | if (!sv2 || !*sv2) { | |
871 | myfree(segs); | |
872 | croak("i_fountain: XS error"); | |
873 | } | |
874 | work[j] = SvNV(*sv2); | |
875 | } | |
876 | segs[i].start = work[0]; | |
877 | segs[i].middle = work[1]; | |
878 | segs[i].end = work[2]; | |
879 | for (j = 0; j < 2; ++j) { | |
880 | SV **sv3 = av_fetch(aseg, 3+j, 0); | |
881 | if (!sv3 || !*sv3 || !SvROK(*sv3) || | |
882 | (!sv_derived_from(*sv3, "Imager::Color") | |
883 | && !sv_derived_from(*sv3, "Imager::Color::Float"))) { | |
884 | myfree(segs); | |
885 | croak("i_fountain: segs must contain colors in elements 3 and 4"); | |
886 | } | |
887 | if (sv_derived_from(*sv3, "Imager::Color::Float")) { | |
4c4c2ffd | 888 | segs[i].c[j] = *INT2PTR(i_fcolor *, SvIV((SV *)SvRV(*sv3))); |
f1ac5027 TC |
889 | } |
890 | else { | |
4c4c2ffd | 891 | i_color c = *INT2PTR(i_color *, SvIV((SV *)SvRV(*sv3))); |
f1ac5027 TC |
892 | int ch; |
893 | for (ch = 0; ch < MAXCHANNELS; ++ch) { | |
894 | segs[i].c[j].channel[ch] = c.channel[ch] / 255.0; | |
895 | } | |
896 | } | |
897 | } | |
898 | for (j = 0; j < 2; ++j) { | |
899 | SV **sv2 = av_fetch(aseg, j+5, 0); | |
900 | if (!sv2 || !*sv2) { | |
901 | myfree(segs); | |
902 | croak("i_fountain: XS error"); | |
903 | } | |
904 | worki[j] = SvIV(*sv2); | |
905 | } | |
906 | segs[i].type = worki[0]; | |
907 | segs[i].color = worki[1]; | |
908 | } | |
909 | ||
910 | return segs; | |
911 | } | |
912 | ||
faa9b3e7 TC |
913 | /* I don't think ICLF_* names belong at the C interface |
914 | this makes the XS code think we have them, to let us avoid | |
915 | putting function bodies in the XS code | |
916 | */ | |
917 | #define ICLF_new_internal(r, g, b, a) i_fcolor_new((r), (g), (b), (a)) | |
918 | #define ICLF_DESTROY(cl) i_fcolor_destroy(cl) | |
919 | ||
f1ac5027 TC |
920 | /* for the fill objects |
921 | Since a fill object may later have dependent images, (or fills!) | |
922 | we need perl wrappers - oh well | |
923 | */ | |
924 | #define IFILL_DESTROY(fill) i_fill_destroy(fill); | |
925 | typedef i_fill_t* Imager__FillHandle; | |
926 | ||
b33c08f8 TC |
927 | /* the m_init_log() function was called init_log(), renamed to reduce |
928 | potential naming conflicts */ | |
929 | #define init_log m_init_log | |
930 | ||
02d1d628 AMH |
931 | MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_ |
932 | ||
933 | Imager::Color | |
934 | ICL_new_internal(r,g,b,a) | |
935 | unsigned char r | |
936 | unsigned char g | |
937 | unsigned char b | |
938 | unsigned char a | |
939 | ||
940 | void | |
941 | ICL_DESTROY(cl) | |
942 | Imager::Color cl | |
943 | ||
944 | ||
29106a11 | 945 | void |
02d1d628 AMH |
946 | ICL_set_internal(cl,r,g,b,a) |
947 | Imager::Color cl | |
948 | unsigned char r | |
949 | unsigned char g | |
950 | unsigned char b | |
951 | unsigned char a | |
29106a11 | 952 | PPCODE: |
46062ab6 | 953 | ICL_set_internal(cl, r, g, b, a); |
29106a11 TC |
954 | EXTEND(SP, 1); |
955 | PUSHs(ST(0)); | |
02d1d628 AMH |
956 | |
957 | void | |
958 | ICL_info(cl) | |
959 | Imager::Color cl | |
960 | ||
961 | ||
962 | void | |
963 | ICL_rgba(cl) | |
964 | Imager::Color cl | |
965 | PPCODE: | |
966 | EXTEND(SP, 4); | |
967 | PUSHs(sv_2mortal(newSVnv(cl->rgba.r))); | |
968 | PUSHs(sv_2mortal(newSVnv(cl->rgba.g))); | |
969 | PUSHs(sv_2mortal(newSVnv(cl->rgba.b))); | |
970 | PUSHs(sv_2mortal(newSVnv(cl->rgba.a))); | |
971 | ||
efdc2568 TC |
972 | Imager::Color |
973 | i_hsv_to_rgb(c) | |
974 | Imager::Color c | |
975 | CODE: | |
976 | RETVAL = mymalloc(sizeof(i_color)); | |
977 | *RETVAL = *c; | |
978 | i_hsv_to_rgb(RETVAL); | |
979 | OUTPUT: | |
980 | RETVAL | |
981 | ||
982 | Imager::Color | |
983 | i_rgb_to_hsv(c) | |
984 | Imager::Color c | |
985 | CODE: | |
986 | RETVAL = mymalloc(sizeof(i_color)); | |
987 | *RETVAL = *c; | |
988 | i_rgb_to_hsv(RETVAL); | |
989 | OUTPUT: | |
990 | RETVAL | |
991 | ||
02d1d628 AMH |
992 | |
993 | ||
faa9b3e7 | 994 | MODULE = Imager PACKAGE = Imager::Color::Float PREFIX=ICLF_ |
02d1d628 | 995 | |
faa9b3e7 TC |
996 | Imager::Color::Float |
997 | ICLF_new_internal(r, g, b, a) | |
998 | double r | |
999 | double g | |
1000 | double b | |
1001 | double a | |
1002 | ||
1003 | void | |
1004 | ICLF_DESTROY(cl) | |
1005 | Imager::Color::Float cl | |
02d1d628 | 1006 | |
faa9b3e7 TC |
1007 | void |
1008 | ICLF_rgba(cl) | |
1009 | Imager::Color::Float cl | |
1010 | PREINIT: | |
1011 | int ch; | |
1012 | PPCODE: | |
1013 | EXTEND(SP, MAXCHANNELS); | |
1014 | for (ch = 0; ch < MAXCHANNELS; ++ch) { | |
1015 | /* printf("%d: %g\n", ch, cl->channel[ch]); */ | |
1016 | PUSHs(sv_2mortal(newSVnv(cl->channel[ch]))); | |
1017 | } | |
1018 | ||
1019 | void | |
1020 | ICLF_set_internal(cl,r,g,b,a) | |
1021 | Imager::Color::Float cl | |
1022 | double r | |
1023 | double g | |
1024 | double b | |
1025 | double a | |
1026 | PPCODE: | |
1027 | cl->rgba.r = r; | |
1028 | cl->rgba.g = g; | |
1029 | cl->rgba.b = b; | |
1030 | cl->rgba.a = a; | |
1031 | EXTEND(SP, 1); | |
1032 | PUSHs(ST(0)); | |
02d1d628 | 1033 | |
efdc2568 TC |
1034 | Imager::Color::Float |
1035 | i_hsv_to_rgb(c) | |
1036 | Imager::Color::Float c | |
1037 | CODE: | |
1038 | RETVAL = mymalloc(sizeof(i_fcolor)); | |
1039 | *RETVAL = *c; | |
1040 | i_hsv_to_rgbf(RETVAL); | |
1041 | OUTPUT: | |
1042 | RETVAL | |
1043 | ||
1044 | Imager::Color::Float | |
1045 | i_rgb_to_hsv(c) | |
1046 | Imager::Color::Float c | |
1047 | CODE: | |
1048 | RETVAL = mymalloc(sizeof(i_fcolor)); | |
1049 | *RETVAL = *c; | |
1050 | i_rgb_to_hsvf(RETVAL); | |
1051 | OUTPUT: | |
1052 | RETVAL | |
1053 | ||
1054 | ||
02d1d628 AMH |
1055 | MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_ |
1056 | ||
1057 | Imager::ImgRaw | |
1058 | IIM_new(x,y,ch) | |
1059 | int x | |
1060 | int y | |
1061 | int ch | |
1062 | ||
1063 | void | |
1064 | IIM_DESTROY(im) | |
1065 | Imager::ImgRaw im | |
1066 | ||
1067 | ||
1068 | ||
1069 | MODULE = Imager PACKAGE = Imager | |
1070 | ||
1071 | PROTOTYPES: ENABLE | |
1072 | ||
1073 | ||
1074 | Imager::IO | |
1075 | io_new_fd(fd) | |
1076 | int fd | |
1077 | ||
1078 | Imager::IO | |
1079 | io_new_bufchain() | |
1080 | ||
1081 | ||
4dfa5522 AMH |
1082 | Imager::IO |
1083 | io_new_buffer(data) | |
1084 | char *data | |
1085 | PREINIT: | |
1086 | size_t length; | |
4dfa5522 AMH |
1087 | CODE: |
1088 | SvPV(ST(0), length); | |
1089 | SvREFCNT_inc(ST(0)); | |
1090 | RETVAL = io_new_buffer(data, length, my_SvREFCNT_dec, ST(0)); | |
1091 | OUTPUT: | |
1092 | RETVAL | |
10461f9a TC |
1093 | |
1094 | Imager::IO | |
1095 | io_new_cb(writecb, readcb, seekcb, closecb, maxwrite = CBDATA_BUFSIZE) | |
1096 | SV *writecb; | |
1097 | SV *readcb; | |
1098 | SV *seekcb; | |
1099 | SV *closecb; | |
1100 | int maxwrite; | |
1101 | PREINIT: | |
1102 | struct cbdata *cbd; | |
1103 | CODE: | |
1104 | cbd = mymalloc(sizeof(struct cbdata)); | |
1105 | SvREFCNT_inc(writecb); | |
1106 | cbd->writecb = writecb; | |
1107 | SvREFCNT_inc(readcb); | |
1108 | cbd->readcb = readcb; | |
1109 | SvREFCNT_inc(seekcb); | |
1110 | cbd->seekcb = seekcb; | |
1111 | SvREFCNT_inc(closecb); | |
1112 | cbd->closecb = closecb; | |
1113 | cbd->reading = cbd->writing = cbd->where = cbd->used = 0; | |
1114 | if (maxwrite > CBDATA_BUFSIZE) | |
1115 | maxwrite = CBDATA_BUFSIZE; | |
1116 | cbd->maxlength = maxwrite; | |
1117 | RETVAL = io_new_cb(cbd, io_reader, io_writer, io_seeker, io_closer, | |
1118 | io_destroyer); | |
1119 | OUTPUT: | |
1120 | RETVAL | |
4dfa5522 | 1121 | |
02d1d628 AMH |
1122 | void |
1123 | io_slurp(ig) | |
1124 | Imager::IO ig | |
1125 | PREINIT: | |
1126 | unsigned char* data; | |
4dfa5522 | 1127 | size_t tlength; |
02d1d628 AMH |
1128 | PPCODE: |
1129 | data = NULL; | |
1130 | tlength = io_slurp(ig, &data); | |
02d1d628 | 1131 | EXTEND(SP,1); |
26fd367b | 1132 | PUSHs(sv_2mortal(newSVpv((char *)data,tlength))); |
02d1d628 AMH |
1133 | myfree(data); |
1134 | ||
1135 | ||
c3cc977e AMH |
1136 | MODULE = Imager PACKAGE = Imager::IO PREFIX = io_glue_ |
1137 | ||
1138 | void | |
1139 | io_glue_DESTROY(ig) | |
1140 | Imager::IO ig | |
1141 | ||
1142 | ||
1143 | MODULE = Imager PACKAGE = Imager | |
1144 | ||
1145 | PROTOTYPES: ENABLE | |
1146 | ||
1147 | ||
02d1d628 AMH |
1148 | |
1149 | void | |
1150 | i_list_formats() | |
1151 | PREINIT: | |
1152 | char* item; | |
1153 | int i; | |
1154 | PPCODE: | |
1155 | i=0; | |
1156 | while( (item=i_format_list[i++]) != NULL ) { | |
1157 | EXTEND(SP, 1); | |
1158 | PUSHs(sv_2mortal(newSVpv(item,0))); | |
1159 | } | |
1160 | ||
1161 | undef_int | |
1162 | i_has_format(frmt) | |
1163 | char* frmt | |
1164 | ||
1165 | Imager::ImgRaw | |
1166 | i_img_new() | |
1167 | ||
1168 | Imager::ImgRaw | |
1169 | i_img_empty(im,x,y) | |
1170 | Imager::ImgRaw im | |
1171 | int x | |
1172 | int y | |
1173 | ||
1174 | Imager::ImgRaw | |
1175 | i_img_empty_ch(im,x,y,ch) | |
1176 | Imager::ImgRaw im | |
1177 | int x | |
1178 | int y | |
1179 | int ch | |
1180 | ||
1181 | void | |
f83bf98a | 1182 | m_init_log(name,level) |
02d1d628 AMH |
1183 | char* name |
1184 | int level | |
1185 | ||
7f882a01 AMH |
1186 | void |
1187 | log_entry(string,level) | |
1188 | char* string | |
1189 | int level | |
1190 | ||
1191 | ||
02d1d628 AMH |
1192 | void |
1193 | i_img_exorcise(im) | |
1194 | Imager::ImgRaw im | |
1195 | ||
1196 | void | |
1197 | i_img_destroy(im) | |
1198 | Imager::ImgRaw im | |
1199 | ||
1200 | void | |
1201 | i_img_info(im) | |
1202 | Imager::ImgRaw im | |
1203 | PREINIT: | |
1204 | int info[4]; | |
1205 | PPCODE: | |
1206 | i_img_info(im,info); | |
1207 | EXTEND(SP, 4); | |
1208 | PUSHs(sv_2mortal(newSViv(info[0]))); | |
1209 | PUSHs(sv_2mortal(newSViv(info[1]))); | |
1210 | PUSHs(sv_2mortal(newSViv(info[2]))); | |
1211 | PUSHs(sv_2mortal(newSViv(info[3]))); | |
1212 | ||
1213 | ||
1214 | ||
1215 | ||
1216 | void | |
1217 | i_img_setmask(im,ch_mask) | |
1218 | Imager::ImgRaw im | |
1219 | int ch_mask | |
1220 | ||
1221 | int | |
1222 | i_img_getmask(im) | |
1223 | Imager::ImgRaw im | |
1224 | ||
1225 | int | |
1226 | i_img_getchannels(im) | |
1227 | Imager::ImgRaw im | |
1228 | ||
1229 | void | |
1230 | i_img_getdata(im) | |
1231 | Imager::ImgRaw im | |
1232 | PPCODE: | |
1233 | EXTEND(SP, 1); | |
26fd367b TC |
1234 | PUSHs(im->idata ? |
1235 | sv_2mortal(newSVpv((char *)im->idata, im->bytes)) | |
faa9b3e7 | 1236 | : &PL_sv_undef); |
02d1d628 AMH |
1237 | |
1238 | ||
1239 | void | |
aa833c97 | 1240 | i_line(im,x1,y1,x2,y2,val,endp) |
02d1d628 AMH |
1241 | Imager::ImgRaw im |
1242 | int x1 | |
1243 | int y1 | |
1244 | int x2 | |
1245 | int y2 | |
1246 | Imager::Color val | |
aa833c97 | 1247 | int endp |
02d1d628 AMH |
1248 | |
1249 | void | |
b437ce0a | 1250 | i_line_aa(im,x1,y1,x2,y2,val,endp) |
02d1d628 AMH |
1251 | Imager::ImgRaw im |
1252 | int x1 | |
1253 | int y1 | |
1254 | int x2 | |
1255 | int y2 | |
1256 | Imager::Color val | |
b437ce0a | 1257 | int endp |
02d1d628 AMH |
1258 | |
1259 | void | |
1260 | i_box(im,x1,y1,x2,y2,val) | |
1261 | Imager::ImgRaw im | |
1262 | int x1 | |
1263 | int y1 | |
1264 | int x2 | |
1265 | int y2 | |
1266 | Imager::Color val | |
1267 | ||
1268 | void | |
1269 | i_box_filled(im,x1,y1,x2,y2,val) | |
1270 | Imager::ImgRaw im | |
1271 | int x1 | |
1272 | int y1 | |
1273 | int x2 | |
1274 | int y2 | |
1275 | Imager::Color val | |
1276 | ||
f1ac5027 TC |
1277 | void |
1278 | i_box_cfill(im,x1,y1,x2,y2,fill) | |
1279 | Imager::ImgRaw im | |
1280 | int x1 | |
1281 | int y1 | |
1282 | int x2 | |
1283 | int y2 | |
1284 | Imager::FillHandle fill | |
1285 | ||
02d1d628 AMH |
1286 | void |
1287 | i_arc(im,x,y,rad,d1,d2,val) | |
1288 | Imager::ImgRaw im | |
1289 | int x | |
1290 | int y | |
1291 | float rad | |
1292 | float d1 | |
1293 | float d2 | |
1294 | Imager::Color val | |
1295 | ||
f1ac5027 TC |
1296 | void |
1297 | i_arc_cfill(im,x,y,rad,d1,d2,fill) | |
1298 | Imager::ImgRaw im | |
1299 | int x | |
1300 | int y | |
1301 | float rad | |
1302 | float d1 | |
1303 | float d2 | |
1304 | Imager::FillHandle fill | |
1305 | ||
02d1d628 AMH |
1306 | |
1307 | ||
6af18d2b AMH |
1308 | void |
1309 | i_circle_aa(im,x,y,rad,val) | |
1310 | Imager::ImgRaw im | |
1311 | float x | |
1312 | float y | |
1313 | float rad | |
1314 | Imager::Color val | |
1315 | ||
1316 | ||
1317 | ||
02d1d628 AMH |
1318 | void |
1319 | i_bezier_multi(im,xc,yc,val) | |
1320 | Imager::ImgRaw im | |
1321 | Imager::Color val | |
1322 | PREINIT: | |
1323 | double *x,*y; | |
1324 | int len; | |
1325 | AV *av1; | |
1326 | AV *av2; | |
1327 | SV *sv1; | |
1328 | SV *sv2; | |
1329 | int i; | |
1330 | PPCODE: | |
1331 | ICL_info(val); | |
1332 | if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n"); | |
1333 | if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n"); | |
1334 | if (!SvROK(ST(2))) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n"); | |
1335 | if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n"); | |
1336 | av1=(AV*)SvRV(ST(1)); | |
1337 | av2=(AV*)SvRV(ST(2)); | |
1338 | if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_bezier_multi must be equal length\n"); | |
1339 | len=av_len(av1)+1; | |
1340 | x=mymalloc( len*sizeof(double) ); | |
1341 | y=mymalloc( len*sizeof(double) ); | |
1342 | for(i=0;i<len;i++) { | |
1343 | sv1=(*(av_fetch(av1,i,0))); | |
1344 | sv2=(*(av_fetch(av2,i,0))); | |
1345 | x[i]=(double)SvNV(sv1); | |
1346 | y[i]=(double)SvNV(sv2); | |
1347 | } | |
1348 | i_bezier_multi(im,len,x,y,val); | |
1349 | myfree(x); | |
1350 | myfree(y); | |
1351 | ||
1352 | ||
1353 | void | |
1354 | i_poly_aa(im,xc,yc,val) | |
1355 | Imager::ImgRaw im | |
1356 | Imager::Color val | |
1357 | PREINIT: | |
1358 | double *x,*y; | |
1359 | int len; | |
1360 | AV *av1; | |
1361 | AV *av2; | |
1362 | SV *sv1; | |
1363 | SV *sv2; | |
1364 | int i; | |
1365 | PPCODE: | |
1366 | ICL_info(val); | |
1367 | if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n"); | |
1368 | if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n"); | |
1369 | if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n"); | |
1370 | if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n"); | |
1371 | av1=(AV*)SvRV(ST(1)); | |
1372 | av2=(AV*)SvRV(ST(2)); | |
1373 | if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa must be equal length\n"); | |
1374 | len=av_len(av1)+1; | |
1375 | x=mymalloc( len*sizeof(double) ); | |
1376 | y=mymalloc( len*sizeof(double) ); | |
1377 | for(i=0;i<len;i++) { | |
1378 | sv1=(*(av_fetch(av1,i,0))); | |
1379 | sv2=(*(av_fetch(av2,i,0))); | |
1380 | x[i]=(double)SvNV(sv1); | |
1381 | y[i]=(double)SvNV(sv2); | |
1382 | } | |
1383 | i_poly_aa(im,len,x,y,val); | |
1384 | myfree(x); | |
1385 | myfree(y); | |
1386 | ||
43c5dacb TC |
1387 | void |
1388 | i_poly_aa_cfill(im,xc,yc,fill) | |
1389 | Imager::ImgRaw im | |
1390 | Imager::FillHandle fill | |
1391 | PREINIT: | |
1392 | double *x,*y; | |
1393 | int len; | |
1394 | AV *av1; | |
1395 | AV *av2; | |
1396 | SV *sv1; | |
1397 | SV *sv2; | |
1398 | int i; | |
1399 | PPCODE: | |
1400 | if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa_cfill must be a reference to an array\n"); | |
1401 | if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa_cfill must be a reference to an array\n"); | |
1402 | if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa_cfill must be a reference to an array\n"); | |
1403 | if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa_cfill must be a reference to an array\n"); | |
1404 | av1=(AV*)SvRV(ST(1)); | |
1405 | av2=(AV*)SvRV(ST(2)); | |
1406 | if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa_cfill must be equal length\n"); | |
1407 | len=av_len(av1)+1; | |
1408 | x=mymalloc( len*sizeof(double) ); | |
1409 | y=mymalloc( len*sizeof(double) ); | |
1410 | for(i=0;i<len;i++) { | |
1411 | sv1=(*(av_fetch(av1,i,0))); | |
1412 | sv2=(*(av_fetch(av2,i,0))); | |
1413 | x[i]=(double)SvNV(sv1); | |
1414 | y[i]=(double)SvNV(sv2); | |
1415 | } | |
1416 | i_poly_aa_cfill(im,len,x,y,fill); | |
1417 | myfree(x); | |
1418 | myfree(y); | |
1419 | ||
02d1d628 AMH |
1420 | |
1421 | ||
a321d497 | 1422 | undef_int |
02d1d628 AMH |
1423 | i_flood_fill(im,seedx,seedy,dcol) |
1424 | Imager::ImgRaw im | |
1425 | int seedx | |
1426 | int seedy | |
1427 | Imager::Color dcol | |
1428 | ||
a321d497 | 1429 | undef_int |
cc6483e0 TC |
1430 | i_flood_cfill(im,seedx,seedy,fill) |
1431 | Imager::ImgRaw im | |
1432 | int seedx | |
1433 | int seedy | |
1434 | Imager::FillHandle fill | |
1435 | ||
02d1d628 AMH |
1436 | |
1437 | void | |
1438 | i_copyto(im,src,x1,y1,x2,y2,tx,ty) | |
1439 | Imager::ImgRaw im | |
1440 | Imager::ImgRaw src | |
1441 | int x1 | |
1442 | int y1 | |
1443 | int x2 | |
1444 | int y2 | |
1445 | int tx | |
1446 | int ty | |
1447 | ||
1448 | ||
1449 | void | |
1450 | i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans) | |
1451 | Imager::ImgRaw im | |
1452 | Imager::ImgRaw src | |
1453 | int x1 | |
1454 | int y1 | |
1455 | int x2 | |
1456 | int y2 | |
1457 | int tx | |
1458 | int ty | |
1459 | Imager::Color trans | |
1460 | ||
1461 | void | |
1462 | i_copy(im,src) | |
1463 | Imager::ImgRaw im | |
1464 | Imager::ImgRaw src | |
1465 | ||
1466 | ||
faa9b3e7 | 1467 | undef_int |
71dc4a83 | 1468 | i_rubthru(im,src,tx,ty,src_minx,src_miny,src_maxx,src_maxy) |
02d1d628 AMH |
1469 | Imager::ImgRaw im |
1470 | Imager::ImgRaw src | |
1471 | int tx | |
1472 | int ty | |
71dc4a83 AMH |
1473 | int src_minx |
1474 | int src_miny | |
1475 | int src_maxx | |
1476 | int src_maxy | |
1477 | ||
02d1d628 | 1478 | |
142c26ff AMH |
1479 | undef_int |
1480 | i_flipxy(im, direction) | |
1481 | Imager::ImgRaw im | |
1482 | int direction | |
1483 | ||
faa9b3e7 TC |
1484 | Imager::ImgRaw |
1485 | i_rotate90(im, degrees) | |
1486 | Imager::ImgRaw im | |
1487 | int degrees | |
1488 | ||
1489 | Imager::ImgRaw | |
1490 | i_rotate_exact(im, amount) | |
1491 | Imager::ImgRaw im | |
1492 | double amount | |
1493 | ||
1494 | Imager::ImgRaw | |
1495 | i_matrix_transform(im, xsize, ysize, matrix) | |
1496 | Imager::ImgRaw im | |
1497 | int xsize | |
1498 | int ysize | |
1499 | PREINIT: | |
1500 | double matrix[9]; | |
1501 | AV *av; | |
1502 | IV len; | |
1503 | SV *sv1; | |
1504 | int i; | |
1505 | CODE: | |
1506 | if (!SvROK(ST(3)) || SvTYPE(SvRV(ST(3))) != SVt_PVAV) | |
1507 | croak("i_matrix_transform: parameter 4 must be an array ref\n"); | |
1508 | av=(AV*)SvRV(ST(3)); | |
1509 | len=av_len(av)+1; | |
1510 | if (len > 9) | |
1511 | len = 9; | |
1512 | for (i = 0; i < len; ++i) { | |
1513 | sv1=(*(av_fetch(av,i,0))); | |
1514 | matrix[i] = SvNV(sv1); | |
1515 | } | |
1516 | for (; i < 9; ++i) | |
1517 | matrix[i] = 0; | |
1518 | RETVAL = i_matrix_transform(im, xsize, ysize, matrix); | |
1519 | OUTPUT: | |
1520 | RETVAL | |
02d1d628 AMH |
1521 | |
1522 | void | |
1523 | i_gaussian(im,stdev) | |
1524 | Imager::ImgRaw im | |
1525 | float stdev | |
1526 | ||
b6381851 TC |
1527 | void |
1528 | i_unsharp_mask(im,stdev,scale) | |
1529 | Imager::ImgRaw im | |
1530 | float stdev | |
1531 | double scale | |
1532 | ||
02d1d628 AMH |
1533 | void |
1534 | i_conv(im,pcoef) | |
1535 | Imager::ImgRaw im | |
1536 | PREINIT: | |
1537 | float* coeff; | |
1538 | int len; | |
1539 | AV* av; | |
1540 | SV* sv1; | |
1541 | int i; | |
1542 | PPCODE: | |
1543 | if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n"); | |
1544 | if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n"); | |
1545 | av=(AV*)SvRV(ST(1)); | |
1546 | len=av_len(av)+1; | |
1547 | coeff=mymalloc( len*sizeof(float) ); | |
1548 | for(i=0;i<len;i++) { | |
1549 | sv1=(*(av_fetch(av,i,0))); | |
1550 | coeff[i]=(float)SvNV(sv1); | |
1551 | } | |
1552 | i_conv(im,coeff,len); | |
1553 | myfree(coeff); | |
1554 | ||
f5991c03 TC |
1555 | undef_int |
1556 | i_convert(im, src, coeff) | |
1557 | Imager::ImgRaw im | |
1558 | Imager::ImgRaw src | |
1559 | PREINIT: | |
1560 | float *coeff; | |
1561 | int outchan; | |
1562 | int inchan; | |
1563 | AV *avmain; | |
1564 | SV **temp; | |
f5991c03 TC |
1565 | AV *avsub; |
1566 | int len; | |
1567 | int i, j; | |
1568 | CODE: | |
f5991c03 TC |
1569 | if (!SvROK(ST(2)) || SvTYPE(SvRV(ST(2))) != SVt_PVAV) |
1570 | croak("i_convert: parameter 3 must be an arrayref\n"); | |
1571 | avmain = (AV*)SvRV(ST(2)); | |
1572 | outchan = av_len(avmain)+1; | |
1573 | /* find the biggest */ | |
1574 | inchan = 0; | |
1575 | for (j=0; j < outchan; ++j) { | |
1576 | temp = av_fetch(avmain, j, 0); | |
1577 | if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) { | |
1578 | avsub = (AV*)SvRV(*temp); | |
1579 | len = av_len(avsub)+1; | |
1580 | if (len > inchan) | |
1581 | inchan = len; | |
1582 | } | |
1583 | } | |
1584 | coeff = mymalloc(sizeof(float) * outchan * inchan); | |
1585 | for (j = 0; j < outchan; ++j) { | |
1586 | avsub = (AV*)SvRV(*av_fetch(avmain, j, 0)); | |
1587 | len = av_len(avsub)+1; | |
1588 | for (i = 0; i < len; ++i) { | |
1589 | temp = av_fetch(avsub, i, 0); | |
1590 | if (temp) | |
1591 | coeff[i+j*inchan] = SvNV(*temp); | |
1592 | else | |
1593 | coeff[i+j*inchan] = 0; | |
1594 | } | |
1595 | while (i < inchan) | |
1596 | coeff[i++ + j*inchan] = 0; | |
1597 | } | |
1598 | RETVAL = i_convert(im, src, coeff, outchan, inchan); | |
1599 | myfree(coeff); | |
f5991c03 TC |
1600 | OUTPUT: |
1601 | RETVAL | |
40eba1ea AMH |
1602 | |
1603 | ||
1604 | void | |
1605 | i_map(im, pmaps) | |
1606 | Imager::ImgRaw im | |
1607 | PREINIT: | |
1608 | unsigned int mask = 0; | |
1609 | AV *avmain; | |
1610 | AV *avsub; | |
1611 | SV **temp; | |
1612 | int len; | |
1613 | int i, j; | |
1614 | unsigned char (*maps)[256]; | |
1615 | CODE: | |
1616 | if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV) | |
1617 | croak("i_map: parameter 2 must be an arrayref\n"); | |
1618 | avmain = (AV*)SvRV(ST(1)); | |
1619 | len = av_len(avmain)+1; | |
1620 | if (im->channels < len) len = im->channels; | |
1621 | ||
1622 | maps = mymalloc( len * sizeof(unsigned char [256]) ); | |
1623 | ||
1624 | for (j=0; j<len ; j++) { | |
1625 | temp = av_fetch(avmain, j, 0); | |
1626 | if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) { | |
1627 | avsub = (AV*)SvRV(*temp); | |
1628 | if(av_len(avsub) != 255) continue; | |
1629 | mask |= 1<<j; | |
1630 | for (i=0; i<256 ; i++) { | |
9495ee93 | 1631 | int val; |
40eba1ea | 1632 | temp = av_fetch(avsub, i, 0); |
9495ee93 AMH |
1633 | val = temp ? SvIV(*temp) : 0; |
1634 | if (val<0) val = 0; | |
1635 | if (val>255) val = 255; | |
1636 | maps[j][i] = val; | |
40eba1ea AMH |
1637 | } |
1638 | } | |
1639 | } | |
1640 | i_map(im, maps, mask); | |
1641 | myfree(maps); | |
1642 | ||
1643 | ||
1644 | ||
02d1d628 AMH |
1645 | float |
1646 | i_img_diff(im1,im2) | |
1647 | Imager::ImgRaw im1 | |
1648 | Imager::ImgRaw im2 | |
1649 | ||
1650 | ||
1651 | ||
1652 | undef_int | |
4cb58f1b TC |
1653 | i_init_fonts(t1log=0) |
1654 | int t1log | |
02d1d628 AMH |
1655 | |
1656 | #ifdef HAVE_LIBT1 | |
1657 | ||
1658 | void | |
1659 | i_t1_set_aa(st) | |
1660 | int st | |
1661 | ||
1662 | int | |
6b012d62 | 1663 | i_t1_new(pfb,afm) |
02d1d628 AMH |
1664 | char* pfb |
1665 | char* afm | |
1666 | ||
1667 | int | |
1668 | i_t1_destroy(font_id) | |
1669 | int font_id | |
1670 | ||
1671 | ||
1672 | undef_int | |
1bd75e4c | 1673 | i_t1_cp(im,xb,yb,channel,fontnum,points,str_sv,len_ignored,align,utf8=0,flags="") |
02d1d628 AMH |
1674 | Imager::ImgRaw im |
1675 | int xb | |
1676 | int yb | |
1677 | int channel | |
1678 | int fontnum | |
1679 | float points | |
1bd75e4c | 1680 | SV* str_sv |
02d1d628 | 1681 | int align |
1bd75e4c TC |
1682 | int utf8 |
1683 | char* flags | |
1684 | PREINIT: | |
1685 | char *str; | |
1686 | STRLEN len; | |
1687 | CODE: | |
1688 | #ifdef SvUTF8 | |
1689 | if (SvUTF8(str_sv)) | |
1690 | utf8 = 1; | |
1691 | #endif | |
1692 | str = SvPV(str_sv, len); | |
1693 | RETVAL = i_t1_cp(im, xb,yb,channel,fontnum,points,str,len,align, | |
1694 | utf8,flags); | |
1695 | OUTPUT: | |
1696 | RETVAL | |
1697 | ||
02d1d628 AMH |
1698 | |
1699 | void | |
1bd75e4c | 1700 | i_t1_bbox(fontnum,point,str_sv,len_ignored,utf8=0,flags="") |
02d1d628 AMH |
1701 | int fontnum |
1702 | float point | |
1bd75e4c TC |
1703 | SV* str_sv |
1704 | int utf8 | |
1705 | char* flags | |
02d1d628 | 1706 | PREINIT: |
1bd75e4c TC |
1707 | char *str; |
1708 | STRLEN len; | |
3799c4d1 | 1709 | int cords[BOUNDING_BOX_COUNT]; |
1bd75e4c | 1710 | int i; |
3799c4d1 | 1711 | int rc; |
02d1d628 | 1712 | PPCODE: |
1bd75e4c TC |
1713 | #ifdef SvUTF8 |
1714 | if (SvUTF8(str_sv)) | |
1715 | utf8 = 1; | |
1716 | #endif | |
1717 | str = SvPV(str_sv, len); | |
3799c4d1 TC |
1718 | rc = i_t1_bbox(fontnum,point,str,len,cords,utf8,flags); |
1719 | if (rc > 0) { | |
1720 | EXTEND(SP, rc); | |
1721 | for (i = 0; i < rc; ++i) | |
1722 | PUSHs(sv_2mortal(newSViv(cords[i]))); | |
1723 | } | |
02d1d628 AMH |
1724 | |
1725 | ||
1726 | ||
1727 | undef_int | |
1bd75e4c | 1728 | i_t1_text(im,xb,yb,cl,fontnum,points,str_sv,len_ignored,align,utf8=0,flags="") |
02d1d628 AMH |
1729 | Imager::ImgRaw im |
1730 | int xb | |
1731 | int yb | |
1732 | Imager::Color cl | |
1733 | int fontnum | |
1734 | float points | |
1bd75e4c | 1735 | SV* str_sv |
02d1d628 | 1736 | int align |
1bd75e4c TC |
1737 | int utf8 |
1738 | char* flags | |
1739 | PREINIT: | |
1740 | char *str; | |
1741 | STRLEN len; | |
1742 | CODE: | |
1743 | #ifdef SvUTF8 | |
1744 | if (SvUTF8(str_sv)) | |
1745 | utf8 = 1; | |
1746 | #endif | |
1747 | str = SvPV(str_sv, len); | |
1748 | RETVAL = i_t1_text(im, xb,yb,cl,fontnum,points,str,len,align, | |
1749 | utf8,flags); | |
1750 | OUTPUT: | |
1751 | RETVAL | |
02d1d628 | 1752 | |
3799c4d1 TC |
1753 | void |
1754 | i_t1_has_chars(handle, text_sv, utf8 = 0) | |
1755 | int handle | |
1756 | SV *text_sv | |
1757 | int utf8 | |
1758 | PREINIT: | |
1759 | char const *text; | |
1760 | STRLEN len; | |
1761 | char *work; | |
1762 | int count; | |
1763 | int i; | |
1764 | PPCODE: | |
1765 | #ifdef SvUTF8 | |
1766 | if (SvUTF8(text_sv)) | |
1767 | utf8 = 1; | |
1768 | #endif | |
1769 | text = SvPV(text_sv, len); | |
1770 | work = mymalloc(len); | |
1771 | count = i_t1_has_chars(handle, text, len, utf8, work); | |
1772 | if (GIMME_V == G_ARRAY) { | |
1773 | EXTEND(SP, count); | |
1774 | for (i = 0; i < count; ++i) { | |
1775 | PUSHs(sv_2mortal(newSViv(work[i]))); | |
1776 | } | |
1777 | } | |
1778 | else { | |
1779 | EXTEND(SP, 1); | |
1780 | PUSHs(sv_2mortal(newSVpv(work, count))); | |
1781 | } | |
1782 | myfree(work); | |
1783 | ||
1784 | void | |
1785 | i_t1_face_name(handle) | |
1786 | int handle | |
1787 | PREINIT: | |
1788 | char name[255]; | |
1789 | int len; | |
1790 | PPCODE: | |
1791 | len = i_t1_face_name(handle, name, sizeof(name)); | |
1792 | if (len) { | |
1793 | EXTEND(SP, 1); | |
1794 | PUSHs(sv_2mortal(newSVpv(name, strlen(name)))); | |
1795 | } | |
1796 | ||
19fa4baf AMH |
1797 | void |
1798 | i_t1_glyph_name(handle, text_sv, utf8 = 0) | |
3799c4d1 TC |
1799 | int handle |
1800 | SV *text_sv | |
1801 | int utf8 | |
1802 | PREINIT: | |
1803 | char const *text; | |
1804 | STRLEN work_len; | |
1805 | int len; | |
1806 | int outsize; | |
1807 | char name[255]; | |
1808 | PPCODE: | |
1809 | #ifdef SvUTF8 | |
1810 | if (SvUTF8(text_sv)) | |
1811 | utf8 = 1; | |
1812 | #endif | |
1813 | text = SvPV(text_sv, work_len); | |
1814 | len = work_len; | |
1815 | while (len) { | |
1816 | unsigned char ch; | |
1817 | if (utf8) { | |
1818 | ch = i_utf8_advance(&text, &len); | |
1819 | if (ch == ~0UL) { | |
1820 | i_push_error(0, "invalid UTF8 character"); | |
1821 | break; | |
1822 | } | |
1823 | } | |
1824 | else { | |
1825 | ch = *text++; | |
1826 | --len; | |
1827 | } | |
1828 | EXTEND(SP, 1); | |
1829 | if (outsize = i_t1_glyph_name(handle, ch, name, sizeof(name))) { | |
1830 | PUSHs(sv_2mortal(newSVpv(name, 0))); | |
1831 | } | |
1832 | else { | |
1833 | PUSHs(&PL_sv_undef); | |
1834 | } | |
1835 | } | |
1836 | ||
02d1d628 AMH |
1837 | #endif |
1838 | ||
1839 | #ifdef HAVE_LIBTT | |
1840 | ||
1841 | ||
4b19f77a | 1842 | Imager::Font::TT |
02d1d628 AMH |
1843 | i_tt_new(fontname) |
1844 | char* fontname | |
1845 | ||
4b19f77a AMH |
1846 | |
1847 | MODULE = Imager PACKAGE = Imager::Font::TT PREFIX=TT_ | |
1848 | ||
1849 | #define TT_DESTROY(handle) i_tt_destroy(handle) | |
1850 | ||
02d1d628 | 1851 | void |
4b19f77a AMH |
1852 | TT_DESTROY(handle) |
1853 | Imager::Font::TT handle | |
1854 | ||
02d1d628 | 1855 | |
4b19f77a | 1856 | MODULE = Imager PACKAGE = Imager |
02d1d628 AMH |
1857 | |
1858 | ||
1859 | undef_int | |
4f68b48f | 1860 | i_tt_text(handle,im,xb,yb,cl,points,str_sv,len_ignored,smooth,utf8) |
4b19f77a | 1861 | Imager::Font::TT handle |
02d1d628 AMH |
1862 | Imager::ImgRaw im |
1863 | int xb | |
1864 | int yb | |
1865 | Imager::Color cl | |
1866 | float points | |
4f68b48f TC |
1867 | SV * str_sv |
1868 | int len_ignored | |
02d1d628 | 1869 | int smooth |
4f68b48f TC |
1870 | int utf8 |
1871 | PREINIT: | |
1872 | char *str; | |
1873 | STRLEN len; | |
1874 | CODE: | |
1875 | #ifdef SvUTF8 | |
1876 | if (SvUTF8(str_sv)) | |
1877 | utf8 = 1; | |
1878 | #endif | |
1879 | str = SvPV(str_sv, len); | |
1880 | RETVAL = i_tt_text(handle, im, xb, yb, cl, points, str, | |
1881 | len, smooth, utf8); | |
1882 | OUTPUT: | |
1883 | RETVAL | |
02d1d628 AMH |
1884 | |
1885 | ||
1886 | undef_int | |
4f68b48f | 1887 | i_tt_cp(handle,im,xb,yb,channel,points,str_sv,len_ignored,smooth,utf8) |
4b19f77a | 1888 | Imager::Font::TT handle |
02d1d628 AMH |
1889 | Imager::ImgRaw im |
1890 | int xb | |
1891 | int yb | |
1892 | int channel | |
1893 | float points | |
4f68b48f TC |
1894 | SV * str_sv |
1895 | int len_ignored | |
02d1d628 | 1896 | int smooth |
4f68b48f TC |
1897 | int utf8 |
1898 | PREINIT: | |
1899 | char *str; | |
1900 | STRLEN len; | |
1901 | CODE: | |
1902 | #ifdef SvUTF8 | |
1903 | if (SvUTF8(str_sv)) | |
1904 | utf8 = 1; | |
1905 | #endif | |
1906 | str = SvPV(str_sv, len); | |
1907 | RETVAL = i_tt_cp(handle, im, xb, yb, channel, points, str, len, | |
1908 | smooth, utf8); | |
1909 | OUTPUT: | |
1910 | RETVAL | |
02d1d628 AMH |
1911 | |
1912 | ||
1913 | undef_int | |
4f68b48f | 1914 | i_tt_bbox(handle,point,str_sv,len_ignored, utf8) |
4b19f77a | 1915 | Imager::Font::TT handle |
02d1d628 | 1916 | float point |
4f68b48f TC |
1917 | SV* str_sv |
1918 | int len_ignored | |
1919 | int utf8 | |
02d1d628 | 1920 | PREINIT: |
3799c4d1 | 1921 | int cords[BOUNDING_BOX_COUNT],rc; |
4f68b48f TC |
1922 | char * str; |
1923 | STRLEN len; | |
3799c4d1 | 1924 | int i; |
02d1d628 | 1925 | PPCODE: |
4f68b48f TC |
1926 | #ifdef SvUTF8 |
1927 | if (SvUTF8(ST(2))) | |
1928 | utf8 = 1; | |
1929 | #endif | |
1930 | str = SvPV(str_sv, len); | |
1931 | if ((rc=i_tt_bbox(handle,point,str,len,cords, utf8))) { | |
3799c4d1 TC |
1932 | EXTEND(SP, rc); |
1933 | for (i = 0; i < rc; ++i) { | |
1934 | PUSHs(sv_2mortal(newSViv(cords[i]))); | |
1935 | } | |
02d1d628 AMH |
1936 | } |
1937 | ||
eeaa33fd TC |
1938 | void |
1939 | i_tt_has_chars(handle, text_sv, utf8) | |
1940 | Imager::Font::TT handle | |
1941 | SV *text_sv | |
1942 | int utf8 | |
1943 | PREINIT: | |
1944 | char const *text; | |
1945 | STRLEN len; | |
1946 | char *work; | |
1947 | int count; | |
1948 | int i; | |
1949 | PPCODE: | |
1950 | #ifdef SvUTF8 | |
1951 | if (SvUTF8(text_sv)) | |
1952 | utf8 = 1; | |
1953 | #endif | |
1954 | text = SvPV(text_sv, len); | |
1955 | work = mymalloc(len); | |
1956 | count = i_tt_has_chars(handle, text, len, utf8, work); | |
1957 | if (GIMME_V == G_ARRAY) { | |
1958 | EXTEND(SP, count); | |
1959 | for (i = 0; i < count; ++i) { | |
1960 | PUSHs(sv_2mortal(newSViv(work[i]))); | |
1961 | } | |
1962 | } | |
1963 | else { | |
1964 | EXTEND(SP, 1); | |
1965 | PUSHs(sv_2mortal(newSVpv(work, count))); | |
1966 | } | |
1967 | myfree(work); | |
02d1d628 | 1968 | |
3799c4d1 TC |
1969 | void |
1970 | i_tt_dump_names(handle) | |
1971 | Imager::Font::TT handle | |
02d1d628 | 1972 | |
3799c4d1 TC |
1973 | void |
1974 | i_tt_face_name(handle) | |
1975 | Imager::Font::TT handle | |
1976 | PREINIT: | |
1977 | char name[255]; | |
1978 | int len; | |
1979 | PPCODE: | |
1980 | len = i_tt_face_name(handle, name, sizeof(name)); | |
1981 | if (len) { | |
1982 | EXTEND(SP, 1); | |
1983 | PUSHs(sv_2mortal(newSVpv(name, strlen(name)))); | |
1984 | } | |
02d1d628 | 1985 | |
19fa4baf AMH |
1986 | void |
1987 | i_tt_glyph_name(handle, text_sv, utf8 = 0) | |
3799c4d1 TC |
1988 | Imager::Font::TT handle |
1989 | SV *text_sv | |
1990 | int utf8 | |
1991 | PREINIT: | |
1992 | char const *text; | |
1993 | STRLEN work_len; | |
1994 | int len; | |
1995 | int outsize; | |
1996 | char name[255]; | |
1997 | PPCODE: | |
1998 | #ifdef SvUTF8 | |
1999 | if (SvUTF8(text_sv)) | |
2000 | utf8 = 1; | |
2001 | #endif | |
2002 | text = SvPV(text_sv, work_len); | |
2003 | len = work_len; | |
2004 | while (len) { | |
2005 | unsigned char ch; | |
2006 | if (utf8) { | |
2007 | ch = i_utf8_advance(&text, &len); | |
2008 | if (ch == ~0UL) { | |
2009 | i_push_error(0, "invalid UTF8 character"); | |
2010 | break; | |
2011 | } | |
2012 | } | |
2013 | else { | |
2014 | ch = *text++; | |
2015 | --len; | |
2016 | } | |
2017 | EXTEND(SP, 1); | |
2018 | if (outsize = i_tt_glyph_name(handle, ch, name, sizeof(name))) { | |
2019 | PUSHs(sv_2mortal(newSVpv(name, 0))); | |
2020 | } | |
2021 | else { | |
2022 | PUSHs(&PL_sv_undef); | |
2023 | } | |
2024 | } | |
2025 | ||
2026 | #endif | |
02d1d628 AMH |
2027 | |
2028 | ||
2029 | #ifdef HAVE_LIBJPEG | |
2030 | undef_int | |
dd55acc8 | 2031 | i_writejpeg_wiol(im, ig, qfactor) |
02d1d628 | 2032 | Imager::ImgRaw im |
dd55acc8 | 2033 | Imager::IO ig |
02d1d628 AMH |
2034 | int qfactor |
2035 | ||
02d1d628 AMH |
2036 | |
2037 | void | |
2038 | i_readjpeg_wiol(ig) | |
2039 | Imager::IO ig | |
2040 | PREINIT: | |
2041 | char* iptc_itext; | |
2042 | int tlength; | |
2043 | i_img* rimg; | |
2044 | SV* r; | |
2045 | PPCODE: | |
2046 | iptc_itext = NULL; | |
2047 | rimg = i_readjpeg_wiol(ig,-1,&iptc_itext,&tlength); | |
2048 | if (iptc_itext == NULL) { | |
2049 | r = sv_newmortal(); | |
2050 | EXTEND(SP,1); | |
2051 | sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg); | |
2052 | PUSHs(r); | |
2053 | } else { | |
2054 | r = sv_newmortal(); | |
2055 | EXTEND(SP,2); | |
2056 | sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg); | |
2057 | PUSHs(r); | |
2058 | PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength))); | |
2059 | myfree(iptc_itext); | |
2060 | } | |
2061 | ||
2062 | ||
2063 | #endif | |
2064 | ||
2065 | ||
e10bf46e AMH |
2066 | char * |
2067 | i_test_format_probe(ig, length) | |
2068 | Imager::IO ig | |
2069 | int length | |
2070 | ||
02d1d628 AMH |
2071 | |
2072 | ||
2073 | #ifdef HAVE_LIBTIFF | |
2074 | ||
2075 | Imager::ImgRaw | |
2076 | i_readtiff_wiol(ig, length) | |
2077 | Imager::IO ig | |
2078 | int length | |
2079 | ||
10461f9a TC |
2080 | void |
2081 | i_readtiff_multi_wiol(ig, length) | |
2082 | Imager::IO ig | |
2083 | int length | |
2084 | PREINIT: | |
2085 | i_img **imgs; | |
2086 | int count; | |
2087 | int i; | |
2088 | PPCODE: | |
2089 | imgs = i_readtiff_multi_wiol(ig, length, &count); | |
2090 | if (imgs) { | |
2091 | EXTEND(SP, count); | |
2092 | for (i = 0; i < count; ++i) { | |
2093 | SV *sv = sv_newmortal(); | |
2094 | sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]); | |
2095 | PUSHs(sv); | |
2096 | } | |
2097 | myfree(imgs); | |
2098 | } | |
2099 | ||
02d1d628 AMH |
2100 | |
2101 | undef_int | |
2102 | i_writetiff_wiol(im, ig) | |
2103 | Imager::ImgRaw im | |
2104 | Imager::IO ig | |
2105 | ||
10461f9a TC |
2106 | undef_int |
2107 | i_writetiff_multi_wiol(ig, ...) | |
2108 | Imager::IO ig | |
2109 | PREINIT: | |
2110 | int i; | |
2111 | int img_count; | |
2112 | i_img **imgs; | |
2113 | CODE: | |
2114 | if (items < 2) | |
2115 | croak("Usage: i_writetiff_multi_wiol(ig, images...)"); | |
2116 | img_count = items - 1; | |
2117 | RETVAL = 1; | |
2118 | if (img_count < 1) { | |
2119 | RETVAL = 0; | |
2120 | i_clear_error(); | |
2121 | i_push_error(0, "You need to specify images to save"); | |
2122 | } | |
2123 | else { | |
2124 | imgs = mymalloc(sizeof(i_img *) * img_count); | |
2125 | for (i = 0; i < img_count; ++i) { | |
2126 | SV *sv = ST(1+i); | |
2127 | imgs[i] = NULL; | |
2128 | if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) { | |
4c4c2ffd | 2129 | imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(sv))); |
10461f9a TC |
2130 | } |
2131 | else { | |
2132 | i_clear_error(); | |
2133 | i_push_error(0, "Only images can be saved"); | |
2134 | myfree(imgs); | |
2135 | RETVAL = 0; | |
2136 | break; | |
2137 | } | |
2138 | } | |
2139 | if (RETVAL) { | |
2140 | RETVAL = i_writetiff_multi_wiol(ig, imgs, img_count); | |
2141 | } | |
2142 | myfree(imgs); | |
2143 | } | |
2144 | OUTPUT: | |
2145 | RETVAL | |
2146 | ||
d2dfdcc9 | 2147 | undef_int |
4c2d6970 | 2148 | i_writetiff_wiol_faxable(im, ig, fine) |
d2dfdcc9 TC |
2149 | Imager::ImgRaw im |
2150 | Imager::IO ig | |
4c2d6970 | 2151 | int fine |
d2dfdcc9 | 2152 | |
10461f9a TC |
2153 | undef_int |
2154 | i_writetiff_multi_wiol_faxable(ig, fine, ...) | |
2155 | Imager::IO ig | |
2156 | int fine | |
2157 | PREINIT: | |
2158 | int i; | |
2159 | int img_count; | |
2160 | i_img **imgs; | |
2161 | CODE: | |
2162 | if (items < 3) | |
2163 | croak("Usage: i_writetiff_multi_wiol_faxable(ig, fine, images...)"); | |
2164 | img_count = items - 2; | |
2165 | RETVAL = 1; | |
2166 | if (img_count < 1) { | |
2167 | RETVAL = 0; | |
2168 | i_clear_error(); | |
2169 | i_push_error(0, "You need to specify images to save"); | |
2170 | } | |
2171 | else { | |
2172 | imgs = mymalloc(sizeof(i_img *) * img_count); | |
2173 | for (i = 0; i < img_count; ++i) { | |
2174 | SV *sv = ST(2+i); | |
2175 | imgs[i] = NULL; | |
2176 | if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) { | |
4c4c2ffd | 2177 | imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(sv))); |
10461f9a TC |
2178 | } |
2179 | else { | |
2180 | i_clear_error(); | |
2181 | i_push_error(0, "Only images can be saved"); | |
2182 | myfree(imgs); | |
2183 | RETVAL = 0; | |
2184 | break; | |
2185 | } | |
2186 | } | |
2187 | if (RETVAL) { | |
2188 | RETVAL = i_writetiff_multi_wiol_faxable(ig, imgs, img_count, fine); | |
2189 | } | |
2190 | myfree(imgs); | |
2191 | } | |
2192 | OUTPUT: | |
2193 | RETVAL | |
02d1d628 AMH |
2194 | |
2195 | ||
10461f9a | 2196 | #endif /* HAVE_LIBTIFF */ |
02d1d628 AMH |
2197 | |
2198 | ||
2199 | #ifdef HAVE_LIBPNG | |
2200 | ||
2201 | Imager::ImgRaw | |
790923a4 AMH |
2202 | i_readpng_wiol(ig, length) |
2203 | Imager::IO ig | |
2204 | int length | |
02d1d628 AMH |
2205 | |
2206 | ||
2207 | undef_int | |
790923a4 | 2208 | i_writepng_wiol(im, ig) |
02d1d628 | 2209 | Imager::ImgRaw im |
790923a4 | 2210 | Imager::IO ig |
02d1d628 AMH |
2211 | |
2212 | ||
2213 | #endif | |
2214 | ||
2215 | ||
2216 | #ifdef HAVE_LIBGIF | |
2217 | ||
03bd24d4 TC |
2218 | void |
2219 | i_giflib_version() | |
2220 | PPCODE: | |
2221 | PUSHs(sv_2mortal(newSVnv(IM_GIFMAJOR+IM_GIFMINOR*0.1))); | |
2222 | ||
02d1d628 AMH |
2223 | undef_int |
2224 | i_writegif(im,fd,colors,pixdev,fixed) | |
2225 | Imager::ImgRaw im | |
2226 | int fd | |
2227 | int colors | |
2228 | int pixdev | |
2229 | PREINIT: | |
2230 | int fixedlen; | |
2231 | Imager__Color fixed; | |
2232 | Imager__Color tmp; | |
2233 | AV* av; | |
2234 | SV* sv1; | |
2235 | IV Itmp; | |
2236 | int i; | |
2237 | CODE: | |
2238 | if (!SvROK(ST(4))) croak("Imager: Parameter 4 must be a reference to an array\n"); | |
2239 | if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n"); | |
2240 | av=(AV*)SvRV(ST(4)); | |
2241 | fixedlen=av_len(av)+1; | |
2242 | fixed=mymalloc( fixedlen*sizeof(i_color) ); | |
2243 | for(i=0;i<fixedlen;i++) { | |
2244 | sv1=(*(av_fetch(av,i,0))); | |
2245 | if (sv_derived_from(sv1, "Imager::Color")) { | |
2246 | Itmp = SvIV((SV*)SvRV(sv1)); | |
2247 | tmp = (i_color*) Itmp; | |
2248 | } else croak("Imager: one of the elements of array ref is not of Imager::Color type\n"); | |
2249 | fixed[i]=*tmp; | |
2250 | } | |
2251 | RETVAL=i_writegif(im,fd,colors,pixdev,fixedlen,fixed); | |
2252 | myfree(fixed); | |
2253 | ST(0) = sv_newmortal(); | |
2254 | if (RETVAL == 0) ST(0)=&PL_sv_undef; | |
2255 | else sv_setiv(ST(0), (IV)RETVAL); | |
2256 | ||
2257 | ||
2258 | ||
2259 | ||
2260 | undef_int | |
2261 | i_writegifmc(im,fd,colors) | |
067d6bdc | 2262 | Imager::ImgRaw im |
02d1d628 AMH |
2263 | int fd |
2264 | int colors | |
2265 | ||
02d1d628 AMH |
2266 | |
2267 | undef_int | |
2268 | i_writegif_gen(fd, ...) | |
2269 | int fd | |
2270 | PROTOTYPE: $$@ | |
2271 | PREINIT: | |
2272 | i_quantize quant; | |
02d1d628 AMH |
2273 | i_img **imgs = NULL; |
2274 | int img_count; | |
2275 | int i; | |
2276 | HV *hv; | |
2277 | CODE: | |
2278 | if (items < 3) | |
2279 | croak("Usage: i_writegif_gen(fd,hashref, images...)"); | |
2280 | if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1)))) | |
2281 | croak("i_writegif_gen: Second argument must be a hash ref"); | |
2282 | hv = (HV *)SvRV(ST(1)); | |
2283 | memset(&quant, 0, sizeof(quant)); | |
2284 | quant.mc_size = 256; | |
02d1d628 | 2285 | handle_quant_opts(&quant, hv); |
02d1d628 AMH |
2286 | img_count = items - 2; |
2287 | RETVAL = 1; | |
2288 | if (img_count < 1) { | |
2289 | RETVAL = 0; | |
95b44a76 TC |
2290 | i_clear_error(); |
2291 | i_push_error(0, "You need to specify images to save"); | |
02d1d628 AMH |
2292 | } |
2293 | else { | |
2294 | imgs = mymalloc(sizeof(i_img *) * img_count); | |
2295 | for (i = 0; i < img_count; ++i) { | |
2296 | SV *sv = ST(2+i); | |
2297 | imgs[i] = NULL; | |
2298 | if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) { | |
4c4c2ffd | 2299 | imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(sv))); |
02d1d628 AMH |
2300 | } |
2301 | else { | |
95b44a76 TC |
2302 | i_clear_error(); |
2303 | i_push_error(0, "Only images can be saved"); | |
02d1d628 AMH |
2304 | RETVAL = 0; |
2305 | break; | |
2306 | } | |
2307 | } | |
2308 | if (RETVAL) { | |
97c4effc | 2309 | RETVAL = i_writegif_gen(&quant, fd, imgs, img_count); |
02d1d628 AMH |
2310 | } |
2311 | myfree(imgs); | |
2312 | if (RETVAL) { | |
2313 | copy_colors_back(hv, &quant); | |
2314 | } | |
2315 | } | |
a73aeb5f AMH |
2316 | ST(0) = sv_newmortal(); |
2317 | if (RETVAL == 0) ST(0)=&PL_sv_undef; | |
2318 | else sv_setiv(ST(0), (IV)RETVAL); | |
46a04ceb | 2319 | cleanup_quant_opts(&quant); |
a73aeb5f | 2320 | |
02d1d628 AMH |
2321 | |
2322 | undef_int | |
2323 | i_writegif_callback(cb, maxbuffer,...) | |
2324 | int maxbuffer; | |
2325 | PREINIT: | |
2326 | i_quantize quant; | |
02d1d628 AMH |
2327 | i_img **imgs = NULL; |
2328 | int img_count; | |
2329 | int i; | |
2330 | HV *hv; | |
2331 | i_writer_data wd; | |
2332 | CODE: | |
2333 | if (items < 4) | |
2334 | croak("Usage: i_writegif_callback(\\&callback,maxbuffer,hashref, images...)"); | |
2335 | if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2)))) | |
2336 | croak("i_writegif_callback: Second argument must be a hash ref"); | |
2337 | hv = (HV *)SvRV(ST(2)); | |
2338 | memset(&quant, 0, sizeof(quant)); | |
2339 | quant.mc_size = 256; | |
02d1d628 | 2340 | handle_quant_opts(&quant, hv); |
02d1d628 AMH |
2341 | img_count = items - 3; |
2342 | RETVAL = 1; | |
2343 | if (img_count < 1) { | |
2344 | RETVAL = 0; | |
2345 | } | |
2346 | else { | |
2347 | imgs = mymalloc(sizeof(i_img *) * img_count); | |
2348 | for (i = 0; i < img_count; ++i) { | |
2349 | SV *sv = ST(3+i); | |
2350 | imgs[i] = NULL; | |
2351 | if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) { | |
4c4c2ffd | 2352 | imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(sv))); |
02d1d628 AMH |
2353 | } |
2354 | else { | |
2355 | RETVAL = 0; | |
2356 | break; | |
2357 | } | |
2358 | } | |
2359 | if (RETVAL) { | |
2360 | wd.sv = ST(0); | |
97c4effc | 2361 | RETVAL = i_writegif_callback(&quant, write_callback, (char *)&wd, maxbuffer, imgs, img_count); |
02d1d628 AMH |
2362 | } |
2363 | myfree(imgs); | |
2364 | if (RETVAL) { | |
2365 | copy_colors_back(hv, &quant); | |
2366 | } | |
2367 | } | |
46a04ceb TC |
2368 | ST(0) = sv_newmortal(); |
2369 | if (RETVAL == 0) ST(0)=&PL_sv_undef; | |
2370 | else sv_setiv(ST(0), (IV)RETVAL); | |
46a04ceb | 2371 | cleanup_quant_opts(&quant); |
02d1d628 | 2372 | |
10461f9a TC |
2373 | undef_int |
2374 | i_writegif_wiol(ig, opts,...) | |
2375 | Imager::IO ig | |
2376 | PREINIT: | |
2377 | i_quantize quant; | |
10461f9a TC |
2378 | i_img **imgs = NULL; |
2379 | int img_count; | |
2380 | int i; | |
2381 | HV *hv; | |
2382 | CODE: | |
2383 | if (items < 3) | |
2384 | croak("Usage: i_writegif_wiol(IO,hashref, images...)"); | |
2385 | if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1)))) | |
2386 | croak("i_writegif_callback: Second argument must be a hash ref"); | |
2387 | hv = (HV *)SvRV(ST(1)); | |
2388 | memset(&quant, 0, sizeof(quant)); | |
2389 | quant.mc_size = 256; | |
10461f9a | 2390 | handle_quant_opts(&quant, hv); |
10461f9a TC |
2391 | img_count = items - 2; |
2392 | RETVAL = 1; | |
2393 | if (img_count < 1) { | |
2394 | RETVAL = 0; | |
2395 | } | |
2396 | else { | |
2397 | imgs = mymalloc(sizeof(i_img *) * img_count); | |
2398 | for (i = 0; i < img_count; ++i) { | |
2399 | SV *sv = ST(2+i); | |
2400 | imgs[i] = NULL; | |
2401 | if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) { | |
4c4c2ffd | 2402 | imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(sv))); |
10461f9a TC |
2403 | } |
2404 | else { | |
2405 | RETVAL = 0; | |
2406 | break; | |
2407 | } | |
2408 | } | |
2409 | if (RETVAL) { | |
97c4effc | 2410 | RETVAL = i_writegif_wiol(ig, &quant, imgs, img_count); |
10461f9a TC |
2411 | } |
2412 | myfree(imgs); | |
2413 | if (RETVAL) { | |
2414 | copy_colors_back(hv, &quant); | |
2415 | } | |
2416 | } | |
2417 | ST(0) = sv_newmortal(); | |
2418 | if (RETVAL == 0) ST(0)=&PL_sv_undef; | |
2419 | else sv_setiv(ST(0), (IV)RETVAL); | |
10461f9a TC |
2420 | cleanup_quant_opts(&quant); |
2421 | ||
02d1d628 AMH |
2422 | void |
2423 | i_readgif(fd) | |
2424 | int fd | |
2425 | PREINIT: | |
2426 | int* colour_table; | |
2427 | int colours, q, w; | |
2428 | i_img* rimg; | |
2429 | SV* temp[3]; | |
2430 | AV* ct; | |
2431 | SV* r; | |
2432 | PPCODE: | |
2433 | colour_table = NULL; | |
2434 | colours = 0; | |
2435 | ||
895dbd34 | 2436 | if(GIMME_V == G_ARRAY) { |
02d1d628 AMH |
2437 | rimg = i_readgif(fd,&colour_table,&colours); |
2438 | } else { | |
2439 | /* don't waste time with colours if they aren't wanted */ | |
2440 | rimg = i_readgif(fd,NULL,NULL); | |
2441 | } | |
895dbd34 | 2442 | |
02d1d628 AMH |
2443 | if (colour_table == NULL) { |
2444 | EXTEND(SP,1); | |
2445 | r=sv_newmortal(); | |
2446 | sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg); | |
2447 | PUSHs(r); | |
2448 | } else { | |
2449 | /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */ | |
2450 | /* I don't know if I have the reference counts right or not :( */ | |
2451 | /* Neither do I :-) */ | |
2452 | /* No Idea here either */ | |
2453 | ||
2454 | ct=newAV(); | |
2455 | av_extend(ct, colours); | |
2456 | for(q=0; q<colours; q++) { | |
2457 | for(w=0; w<3; w++) | |
2458 | temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w])); | |
2459 | av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp))); | |
2460 | } | |
2461 | myfree(colour_table); | |
895dbd34 | 2462 | |
02d1d628 | 2463 | EXTEND(SP,2); |
895dbd34 | 2464 | r = sv_newmortal(); |
02d1d628 AMH |
2465 | sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg); |
2466 | PUSHs(r); | |
2467 | PUSHs(newRV_noinc((SV*)ct)); | |
2468 | } | |
2469 | ||
10461f9a TC |
2470 | void |
2471 | i_readgif_wiol(ig) | |
2472 | Imager::IO ig | |
2473 | PREINIT: | |
2474 | int* colour_table; | |
2475 | int colours, q, w; | |
2476 | i_img* rimg; | |
2477 | SV* temp[3]; | |
2478 | AV* ct; | |
2479 | SV* r; | |
2480 | PPCODE: | |
2481 | colour_table = NULL; | |
2482 | colours = 0; | |
02d1d628 | 2483 | |
10461f9a TC |
2484 | if(GIMME_V == G_ARRAY) { |
2485 | rimg = i_readgif_wiol(ig,&colour_table,&colours); | |
2486 | } else { | |
2487 | /* don't waste time with colours if they aren't wanted */ | |
2488 | rimg = i_readgif_wiol(ig,NULL,NULL); | |
2489 | } | |
2490 | ||
2491 | if (colour_table == NULL) { | |
2492 | EXTEND(SP,1); | |
2493 | r=sv_newmortal(); | |
2494 | sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg); | |
2495 | PUSHs(r); | |
2496 | } else { | |
2497 | /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */ | |
2498 | /* I don't know if I have the reference counts right or not :( */ | |
2499 | /* Neither do I :-) */ | |
2500 | /* No Idea here either */ | |
02d1d628 | 2501 | |
10461f9a TC |
2502 | ct=newAV(); |
2503 | av_extend(ct, colours); | |
2504 | for(q=0; q<colours; q++) { | |
2505 | for(w=0; w<3; w++) | |
2506 | temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w])); | |
2507 | av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp))); | |
2508 | } | |
2509 | myfree(colour_table); | |
02d1d628 | 2510 | |
10461f9a TC |
2511 | EXTEND(SP,2); |
2512 | r = sv_newmortal(); | |
2513 | sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg); | |
2514 | PUSHs(r); | |
2515 | PUSHs(newRV_noinc((SV*)ct)); | |
2516 | } | |
02d1d628 AMH |
2517 | |
2518 | void | |
2519 | i_readgif_scalar(...) | |
2520 | PROTOTYPE: $ | |
2521 | PREINIT: | |
2522 | char* data; | |
21e952df | 2523 | STRLEN length; |
02d1d628 AMH |
2524 | int* colour_table; |
2525 | int colours, q, w; | |
2526 | i_img* rimg; | |
2527 | SV* temp[3]; | |
2528 | AV* ct; | |
2529 | SV* r; | |
2530 | PPCODE: | |
2531 | data = (char *)SvPV(ST(0), length); | |
2532 | colour_table=NULL; | |
2533 | colours=0; | |
2534 | ||
2535 | if(GIMME_V == G_ARRAY) { | |
2536 | rimg=i_readgif_scalar(data,length,&colour_table,&colours); | |
2537 | } else { | |
2538 | /* don't waste time with colours if they aren't wanted */ | |
2539 | rimg=i_readgif_scalar(data,length,NULL,NULL); | |
2540 | } | |
2541 | ||
2542 | if (colour_table == NULL) { | |
2543 | EXTEND(SP,1); | |
2544 | r=sv_newmortal(); | |
2545 | sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg); | |
2546 | PUSHs(r); | |
2547 | } else { | |
2548 | /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */ | |
2549 | /* I don't know if I have the reference counts right or not :( */ | |
2550 | /* Neither do I :-) */ | |
2551 | ct=newAV(); | |
2552 | av_extend(ct, colours); | |
2553 | for(q=0; q<colours; q++) { | |
2554 | for(w=0; w<3; w++) | |
2555 | temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w])); | |
2556 | av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp))); | |
2557 | } | |
2558 | myfree(colour_table); | |
2559 | ||
2560 | EXTEND(SP,2); | |
2561 | r=sv_newmortal(); | |
2562 | sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg); | |
2563 | PUSHs(r); | |
2564 | PUSHs(newRV_noinc((SV*)ct)); | |
2565 | } | |
2566 | ||
2567 | void | |
2568 | i_readgif_callback(...) | |
2569 | PROTOTYPE: & | |
2570 | PREINIT: | |
2571 | char* data; | |
2572 | int length; | |
2573 | int* colour_table; | |
2574 | int colours, q, w; | |
2575 | i_img* rimg; | |
2576 | SV* temp[3]; | |
2577 | AV* ct; | |
2578 | SV* r; | |
2579 | i_reader_data rd; | |
2580 | PPCODE: | |
2581 | rd.sv = ST(0); | |
2582 | colour_table=NULL; | |
2583 | colours=0; | |
2584 | ||
2585 | if(GIMME_V == G_ARRAY) { | |
2586 | rimg=i_readgif_callback(read_callback, (char *)&rd,&colour_table,&colours); | |
2587 | } else { | |
2588 | /* don't waste time with colours if they aren't wanted */ | |
2589 | rimg=i_readgif_callback(read_callback, (char *)&rd,NULL,NULL); | |
2590 | } | |
2591 | ||
2592 | if (colour_table == NULL) { | |
2593 | EXTEND(SP,1); | |
2594 | r=sv_newmortal(); | |
2595 | sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg); | |
2596 | PUSHs(r); | |
2597 | } else { | |
2598 | /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */ | |
2599 | /* I don't know if I have the reference counts right or not :( */ | |
2600 | /* Neither do I :-) */ | |
2601 | /* Neither do I - maybe I'll move this somewhere */ | |
2602 | ct=newAV(); | |
2603 | av_extend(ct, colours); | |
2604 | for(q=0; q<colours; q++) { | |
2605 | for(w=0; w<3; w++) | |
2606 | temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w])); | |
2607 | av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp))); | |
2608 | } | |
2609 | myfree(colour_table); | |
2610 | ||
2611 | EXTEND(SP,2); | |
2612 | r=sv_newmortal(); | |
2613 | sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg); | |
2614 | PUSHs(r); | |
2615 | PUSHs(newRV_noinc((SV*)ct)); | |
2616 | } | |
2617 | ||
faa9b3e7 TC |
2618 | void |
2619 | i_readgif_multi(fd) | |
2620 | int fd | |
2621 | PREINIT: | |
2622 | i_img **imgs; | |
2623 | int count; | |
2624 | int i; | |
2625 | PPCODE: | |
2626 | imgs = i_readgif_multi(fd, &count); | |
2627 | if (imgs) { | |
2628 | EXTEND(SP, count); | |
2629 | for (i = 0; i < count; ++i) { | |
2630 | SV *sv = sv_newmortal(); | |
2631 | sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]); | |
2632 | PUSHs(sv); | |
2633 | } | |
2634 | myfree(imgs); | |
2635 | } | |
02d1d628 | 2636 | |
faa9b3e7 TC |
2637 | void |
2638 | i_readgif_multi_scalar(data) | |
2639 | PREINIT: | |
2640 | i_img **imgs; | |
2641 | int count; | |
2642 | char *data; | |
21e952df | 2643 | STRLEN length; |
faa9b3e7 TC |
2644 | int i; |
2645 | PPCODE: | |
2646 | data = (char *)SvPV(ST(0), length); | |
2647 | imgs = i_readgif_multi_scalar(data, length, &count); | |
2648 | if (imgs) { | |
2649 | EXTEND(SP, count); | |
2650 | for (i = 0; i < count; ++i) { | |
2651 | SV *sv = sv_newmortal(); | |
2652 | sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]); | |
2653 | PUSHs(sv); | |
2654 | } | |
2655 | myfree(imgs); | |
2656 | } | |
02d1d628 | 2657 | |
faa9b3e7 TC |
2658 | void |
2659 | i_readgif_multi_callback(cb) | |
2660 | PREINIT: | |
2661 | i_reader_data rd; | |
2662 | i_img **imgs; | |
2663 | int count; | |
2664 | int i; | |
2665 | PPCODE: | |
2666 | rd.sv = ST(0); | |
2667 | imgs = i_readgif_multi_callback(read_callback, (char *)&rd, &count); | |
2668 | if (imgs) { | |
2669 | EXTEND(SP, count); | |
2670 | for (i = 0; i < count; ++i) { | |
2671 | SV *sv = sv_newmortal(); | |
2672 | sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]); | |
2673 | PUSHs(sv); | |
2674 | } | |
2675 | myfree(imgs); | |
2676 | } | |
02d1d628 | 2677 | |
10461f9a TC |
2678 | void |
2679 | i_readgif_multi_wiol(ig) | |
2680 | Imager::IO ig | |
2681 | PREINIT: | |
2682 | i_img **imgs; | |
2683 | int count; | |
2684 | int i; | |
2685 | PPCODE: | |
2686 | imgs = i_readgif_multi_wiol(ig, &count); | |
2687 | if (imgs) { | |
2688 | EXTEND(SP, count); | |
2689 | for (i = 0; i < count; ++i) { | |
2690 | SV *sv = sv_newmortal(); | |
2691 | sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]); | |
2692 | PUSHs(sv); | |
2693 | } | |
2694 | myfree(imgs); | |
2695 | } | |
2696 | ||
2697 | ||
02d1d628 AMH |
2698 | #endif |
2699 | ||
2700 | ||
2701 | ||
2702 | Imager::ImgRaw | |
2703 | i_readpnm_wiol(ig, length) | |
2704 | Imager::IO ig | |
2705 | int length | |
2706 | ||
2707 | ||
067d6bdc AMH |
2708 | undef_int |
2709 | i_writeppm_wiol(im, ig) | |
2710 | Imager::ImgRaw im | |
2711 | Imager::IO ig | |
2712 | ||
2713 | ||
02d1d628 | 2714 | Imager::ImgRaw |
895dbd34 AMH |
2715 | i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl) |
2716 | Imager::IO ig | |
02d1d628 AMH |
2717 | int x |
2718 | int y | |
2719 | int datachannels | |
2720 | int storechannels | |
2721 | int intrl | |
2722 | ||
2723 | undef_int | |
895dbd34 | 2724 | i_writeraw_wiol(im,ig) |
02d1d628 | 2725 | Imager::ImgRaw im |
895dbd34 AMH |
2726 | Imager::IO ig |
2727 | ||
261f91c5 TC |
2728 | undef_int |
2729 | i_writebmp_wiol(im,ig) | |
2730 | Imager::ImgRaw im | |
2731 | Imager::IO ig | |
02d1d628 | 2732 | |
705fd961 TC |
2733 | Imager::ImgRaw |
2734 | i_readbmp_wiol(ig) | |
2735 | Imager::IO ig | |
2736 | ||
1ec86afa AMH |
2737 | |
2738 | undef_int | |
febba01f | 2739 | i_writetga_wiol(im,ig, wierdpack, compress, idstring) |
1ec86afa AMH |
2740 | Imager::ImgRaw im |
2741 | Imager::IO ig | |
febba01f AMH |
2742 | int wierdpack |
2743 | int compress | |
2744 | char* idstring | |
2745 | PREINIT: | |
febba01f AMH |
2746 | int idlen; |
2747 | CODE: | |
2748 | idlen = SvCUR(ST(4)); | |
2749 | RETVAL = i_writetga_wiol(im, ig, wierdpack, compress, idstring, idlen); | |
2750 | OUTPUT: | |
2751 | RETVAL | |
2752 | ||
1ec86afa AMH |
2753 | |
2754 | Imager::ImgRaw | |
2755 | i_readtga_wiol(ig, length) | |
2756 | Imager::IO ig | |
2757 | int length | |
2758 | ||
2759 | ||
737a830c AMH |
2760 | undef_int |
2761 | i_writergb_wiol(im,ig, wierdpack, compress, idstring) | |
2762 | Imager::ImgRaw im | |
2763 | Imager::IO ig | |
2764 | int wierdpack | |
2765 | int compress | |
2766 | char* idstring | |
2767 | PREINIT: | |
737a830c AMH |
2768 | int idlen; |
2769 | CODE: | |
2770 | idlen = SvCUR(ST(4)); | |
2771 | RETVAL = i_writergb_wiol(im, ig, wierdpack, compress, idstring, idlen); | |
2772 | OUTPUT: | |
2773 | RETVAL | |
2774 | ||
2775 | ||
2776 | Imager::ImgRaw | |
2777 | i_readrgb_wiol(ig, length) | |
2778 | Imager::IO ig | |
2779 | int length | |
2780 | ||
2781 | ||
2782 | ||
02d1d628 AMH |
2783 | Imager::ImgRaw |
2784 | i_scaleaxis(im,Value,Axis) | |
2785 | Imager::ImgRaw im | |
2786 | float Value | |
2787 | int Axis | |
2788 | ||
2789 | Imager::ImgRaw | |
2790 | i_scale_nn(im,scx,scy) | |
2791 | Imager::ImgRaw im | |
2792 | float scx | |
2793 | float scy | |
2794 | ||
2795 | Imager::ImgRaw | |
2796 | i_haar(im) | |
2797 | Imager::ImgRaw im | |
2798 | ||
2799 | int | |
2800 | i_count_colors(im,maxc) | |
2801 | Imager::ImgRaw im | |
2802 | int maxc | |
2803 | ||
2804 | ||
2805 | Imager::ImgRaw | |
2806 | i_transform(im,opx,opy,parm) | |
2807 | Imager::ImgRaw im | |
2808 | PREINIT: | |
2809 | double* parm; | |
2810 | int* opx; | |
2811 | int* opy; | |
2812 | int opxl; | |
2813 | int opyl; | |
2814 | int parmlen; | |
2815 | AV* av; | |
2816 | SV* sv1; | |
2817 | int i; | |
2818 | CODE: | |
2819 | if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n"); | |
2820 | if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to an array\n"); | |
2821 | if (!SvROK(ST(3))) croak("Imager: Parameter 3 must be a reference to an array\n"); | |
2822 | if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n"); | |
2823 | if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 must be a reference to an array\n"); | |
2824 | if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 3 must be a reference to an array\n"); | |
2825 | av=(AV*)SvRV(ST(1)); | |
2826 | opxl=av_len(av)+1; | |
2827 | opx=mymalloc( opxl*sizeof(int) ); | |
2828 | for(i=0;i<opxl;i++) { | |
2829 | sv1=(*(av_fetch(av,i,0))); | |
2830 | opx[i]=(int)SvIV(sv1); | |
2831 | } | |
2832 | av=(AV*)SvRV(ST(2)); | |
2833 | opyl=av_len(av)+1; | |
2834 | opy=mymalloc( opyl*sizeof(int) ); | |
2835 | for(i=0;i<opyl;i++) { | |
2836 | sv1=(*(av_fetch(av,i,0))); | |
2837 | opy[i]=(int)SvIV(sv1); | |
2838 | } | |
2839 | av=(AV*)SvRV(ST(3)); | |
2840 | parmlen=av_len(av)+1; | |
2841 | parm=mymalloc( parmlen*sizeof(double) ); | |
2842 | for(i=0;i<parmlen;i++) { /* FIXME: Bug? */ | |
2843 | sv1=(*(av_fetch(av,i,0))); | |
2844 | parm[i]=(double)SvNV(sv1); | |
2845 | } | |
2846 | RETVAL=i_transform(im,opx,opxl,opy,opyl,parm,parmlen); | |
2847 | myfree(parm); | |
2848 | myfree(opy); | |
2849 | myfree(opx); | |
2850 | ST(0) = sv_newmortal(); | |
2851 | if (RETVAL == 0) ST(0)=&PL_sv_undef; | |
2852 | else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL); | |
2853 | ||
2854 | Imager::ImgRaw | |
e5744e01 TC |
2855 | i_transform2(sv_width,sv_height,channels,sv_ops,av_n_regs,av_c_regs,av_in_imgs) |
2856 | SV *sv_width | |
2857 | SV *sv_height | |
2858 | SV *sv_ops | |
2859 | AV *av_n_regs | |
2860 | AV *av_c_regs | |
2861 | AV *av_in_imgs | |
2862 | int channels | |
02d1d628 AMH |
2863 | PREINIT: |
2864 | int width; | |
2865 | int height; | |
02d1d628 | 2866 | struct rm_op *ops; |
953209f8 | 2867 | STRLEN ops_len; |
02d1d628 AMH |
2868 | int ops_count; |
2869 | double *n_regs; | |
2870 | int n_regs_count; | |
2871 | i_color *c_regs; | |
2872 | int c_regs_count; | |
2873 | int in_imgs_count; | |
2874 | i_img **in_imgs; | |
ea9e6c3f | 2875 | SV *sv1; |
02d1d628 AMH |
2876 | IV tmp; |
2877 | int i; | |
2878 | CODE: | |
e5744e01 TC |
2879 | |
2880 | in_imgs_count = av_len(av_in_imgs)+1; | |
2881 | for (i = 0; i < in_imgs_count; ++i) { | |
2882 | sv1 = *av_fetch(av_in_imgs, i, 0); | |
2883 | if (!sv_derived_from(sv1, "Imager::ImgRaw")) { | |
2884 | croak("sv_in_img must contain only images"); | |
02d1d628 AMH |
2885 | } |
2886 | } | |
b8c2033e | 2887 | if (in_imgs_count > 0) { |
02d1d628 AMH |
2888 | in_imgs = mymalloc(in_imgs_count*sizeof(i_img*)); |
2889 | for (i = 0; i < in_imgs_count; ++i) { | |
e5744e01 | 2890 | sv1 = *av_fetch(av_in_imgs,i,0); |
02d1d628 AMH |
2891 | if (!sv_derived_from(sv1, "Imager::ImgRaw")) { |
2892 | croak("Parameter 5 must contain only images"); | |
2893 | } | |
2894 | tmp = SvIV((SV*)SvRV(sv1)); | |
e375fbd8 | 2895 | in_imgs[i] = INT2PTR(i_img*, tmp); |
02d1d628 AMH |
2896 | } |
2897 | } | |
2898 | else { | |
2899 | /* no input images */ | |
2900 | in_imgs = NULL; | |
2901 | } | |
2902 | /* default the output size from the first input if possible */ | |
e5744e01 TC |
2903 | if (SvOK(sv_width)) |
2904 | width = SvIV(sv_width); | |
02d1d628 AMH |
2905 | else if (in_imgs_count) |
2906 | width = in_imgs[0]->xsize; | |
2907 | else | |
2908 | croak("No output image width supplied"); | |
2909 | ||
e5744e01 TC |
2910 | if (SvOK(sv_height)) |
2911 | height = SvIV(sv_height); | |
02d1d628 AMH |
2912 | else if (in_imgs_count) |
2913 | height = in_imgs[0]->ysize; | |
2914 | else | |
2915 | croak("No output image height supplied"); | |
2916 | ||
e5744e01 | 2917 | ops = (struct rm_op *)SvPV(sv_ops, ops_len); |
02d1d628 AMH |
2918 | if (ops_len % sizeof(struct rm_op)) |
2919 | croak("Imager: Parameter 3 must be a bitmap of regops\n"); | |
2920 | ops_count = ops_len / sizeof(struct rm_op); | |
e5744e01 TC |
2921 | |
2922 | n_regs_count = av_len(av_n_regs)+1; | |
02d1d628 AMH |
2923 | n_regs = mymalloc(n_regs_count * sizeof(double)); |
2924 | for (i = 0; i < n_regs_count; ++i) { | |
e5744e01 | 2925 | sv1 = *av_fetch(av_n_regs,i,0); |
02d1d628 AMH |
2926 | if (SvOK(sv1)) |
2927 | n_regs[i] = SvNV(sv1); | |
2928 | } | |
e5744e01 | 2929 | c_regs_count = av_len(av_c_regs)+1; |
02d1d628 AMH |
2930 | c_regs = mymalloc(c_regs_count * sizeof(i_color)); |
2931 | /* I don't bother initializing the colou?r registers */ | |
2932 | ||
e5744e01 | 2933 | RETVAL=i_transform2(width, height, channels, ops, ops_count, |
02d1d628 AMH |
2934 | n_regs, n_regs_count, |
2935 | c_regs, c_regs_count, in_imgs, in_imgs_count); | |
2936 | if (in_imgs) | |
2937 | myfree(in_imgs); | |
2938 | myfree(n_regs); | |
2939 | myfree(c_regs); | |
2940 | ST(0) = sv_newmortal(); | |
2941 | if (RETVAL == 0) ST(0)=&PL_sv_undef; | |
2942 | else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL); | |
2943 | ||
2944 | ||
2945 | void | |
2946 | i_contrast(im,intensity) | |
2947 | Imager::ImgRaw im | |
2948 | float intensity | |
2949 | ||
2950 | void | |
2951 | i_hardinvert(im) | |
2952 | Imager::ImgRaw im | |
2953 | ||
2954 | void | |
2955 | i_noise(im,amount,type) | |
2956 | Imager::ImgRaw im | |
2957 | float amount | |
2958 | unsigned char type | |
2959 | ||
2960 | void | |
2961 | i_bumpmap(im,bump,channel,light_x,light_y,strength) | |
2962 | Imager::ImgRaw im | |
2963 | Imager::ImgRaw bump | |
2964 | int channel | |
2965 | int light_x | |
2966 | int light_y | |
2967 | int strength | |
2968 | ||
b2778574 AMH |
2969 | |
2970 | void | |
2971 | i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is) | |
2972 | Imager::ImgRaw im | |
2973 | Imager::ImgRaw bump | |
2974 | int channel | |
2975 | int tx | |
2976 | int ty | |
2977 | float Lx | |
2978 | float Ly | |
2979 | float Lz | |
2980 | float cd | |
2981 | float cs | |
2982 | float n | |
2983 | Imager::Color Ia | |
2984 | Imager::Color Il | |
2985 | Imager::Color Is | |
2986 | ||
2987 | ||
2988 | ||
02d1d628 AMH |
2989 | void |
2990 | i_postlevels(im,levels) | |
2991 | Imager::ImgRaw im | |
2992 | int levels | |
2993 | ||
2994 | void | |
2995 | i_mosaic(im,size) | |
2996 | Imager::ImgRaw im | |
2997 | int size | |
2998 | ||
2999 | void | |
3000 | i_watermark(im,wmark,tx,ty,pixdiff) | |
3001 | Imager::ImgRaw im | |
3002 | Imager::ImgRaw wmark | |
3003 | int tx | |
3004 | int ty | |
3005 | int pixdiff | |
3006 | ||
3007 | ||
3008 | void | |
3009 | i_autolevels(im,lsat,usat,skew) | |
3010 | Imager::ImgRaw im | |
3011 | float lsat | |
3012 | float usat | |
3013 | float skew | |
3014 | ||
3015 | void | |
3016 | i_radnoise(im,xo,yo,rscale,ascale) | |
3017 | Imager::ImgRaw im | |
3018 | float xo | |
3019 | float yo | |
3020 | float rscale | |
3021 | float ascale | |
3022 | ||
3023 | void | |
3024 | i_turbnoise(im, xo, yo, scale) | |
3025 | Imager::ImgRaw im | |
3026 | float xo | |
3027 | float yo | |
3028 | float scale | |
3029 | ||
3030 | ||
3031 | void | |
3032 | i_gradgen(im, ...) | |
3033 | Imager::ImgRaw im | |
3034 | PREINIT: | |
3035 | int num; | |
3036 | int *xo; | |
3037 | int *yo; | |
3038 | i_color *ival; | |
3039 | int dmeasure; | |
3040 | int i; | |
3041 | SV *sv; | |
3042 | AV *axx; | |
3043 | AV *ayy; | |
3044 | AV *ac; | |
3045 | CODE: | |
3046 | if (items != 5) | |
3047 | croak("Usage: i_gradgen(im, xo, yo, ival, dmeasure)"); | |
3048 | if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1)))) | |
3049 | croak("i_gradgen: Second argument must be an array ref"); | |
3050 | if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2)))) | |
3051 | croak("i_gradgen: Third argument must be an array ref"); | |
3052 | if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3)))) | |
3053 | croak("i_gradgen: Fourth argument must be an array ref"); | |
3054 | axx = (AV *)SvRV(ST(1)); | |
3055 | ayy = (AV *)SvRV(ST(2)); | |
3056 | ac = (AV *)SvRV(ST(3)); | |
3057 | dmeasure = (int)SvIV(ST(4)); | |
3058 | ||
3059 | num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy); | |
3060 | num = num <= av_len(ac) ? num : av_len(ac); | |
3061 | num++; | |
3062 | if (num < 2) croak("Usage: i_gradgen array refs must have more than 1 entry each"); | |
3063 | xo = mymalloc( sizeof(int) * num ); | |
3064 | yo = mymalloc( sizeof(int) * num ); | |
3065 | ival = mymalloc( sizeof(i_color) * num ); | |
3066 | for(i = 0; i<num; i++) { | |
3067 | xo[i] = (int)SvIV(* av_fetch(axx, i, 0)); | |
3068 | yo[i] = (int)SvIV(* av_fetch(ayy, i, 0)); | |
3069 | sv = *av_fetch(ac, i, 0); | |
3070 | if ( !sv_derived_from(sv, "Imager::Color") ) { | |
3071 | free(axx); free(ayy); free(ac); | |
3072 | croak("i_gradgen: Element of fourth argument is not derived from Imager::Color"); | |
3073 | } | |
4c4c2ffd | 3074 | ival[i] = *INT2PTR(i_color *, SvIV((SV *)SvRV(sv))); |
02d1d628 AMH |
3075 | } |
3076 | i_gradgen(im, num, xo, yo, ival, dmeasure); | |
a73aeb5f AMH |
3077 | myfree(xo); |
3078 | myfree(yo); | |
3079 | myfree(ival); | |
3080 | ||
dff75dee TC |
3081 | Imager::ImgRaw |
3082 | i_diff_image(im, im2, mindist=0) | |
3083 | Imager::ImgRaw im | |
3084 | Imager::ImgRaw im2 | |
3085 | int mindist | |
02d1d628 | 3086 | |
6607600c TC |
3087 | void |
3088 | i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs) | |
3089 | Imager::ImgRaw im | |
3090 | double xa | |
3091 | double ya | |
3092 | double xb | |
3093 | double yb | |
3094 | int type | |
3095 | int repeat | |
3096 | int combine | |
3097 | int super_sample | |
3098 | double ssample_param | |
3099 | PREINIT: | |
6607600c | 3100 | AV *asegs; |
6607600c TC |
3101 | int count; |
3102 | i_fountain_seg *segs; | |
6607600c | 3103 | CODE: |
6607600c TC |
3104 | if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10)))) |
3105 | croak("i_fountain: argument 11 must be an array ref"); | |
3106 | ||
3107 | asegs = (AV *)SvRV(ST(10)); | |
f1ac5027 | 3108 | segs = load_fount_segs(asegs, &count); |
6607600c TC |
3109 | i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, |
3110 | ssample_param, count, segs); | |
3111 | myfree(segs); | |
02d1d628 | 3112 | |
f1ac5027 TC |
3113 | Imager::FillHandle |
3114 | i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs) | |
3115 | double xa | |
3116 | double ya | |
3117 | double xb | |
3118 | double yb | |
3119 | int type | |
3120 | int repeat | |
3121 | int combine | |
3122 | int super_sample | |
3123 | double ssample_param | |
3124 | PREINIT: | |
3125 | AV *asegs; | |
3126 | int count; | |
3127 | i_fountain_seg *segs; | |
3128 | CODE: | |
3129 | if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9)))) | |
3130 | croak("i_fountain: argument 11 must be an array ref"); | |
3131 | ||
3132 | asegs = (AV *)SvRV(ST(9)); | |
3133 | segs = load_fount_segs(asegs, &count); | |
3134 | RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, | |
3135 | super_sample, ssample_param, count, segs); | |
3136 | myfree(segs); | |
3137 | OUTPUT: | |
3138 | RETVAL | |
3139 | ||
4f4f776a TC |
3140 | void |
3141 | i_errors() | |
3142 | PREINIT: | |
3143 | i_errmsg *errors; | |
3144 | int i; | |
4f4f776a | 3145 | AV *av; |
4f4f776a TC |
3146 | SV *sv; |
3147 | PPCODE: | |
3148 | errors = i_errors(); | |
3149 | i = 0; | |
3150 | while (errors[i].msg) { | |
3151 | av = newAV(); | |
3152 | sv = newSVpv(errors[i].msg, strlen(errors[i].msg)); | |
3153 | if (!av_store(av, 0, sv)) { | |
3154 | SvREFCNT_dec(sv); | |
3155 | } | |
3156 | sv = newSViv(errors[i].code); | |
3157 | if (!av_store(av, 1, sv)) { | |
3158 | SvREFCNT_dec(sv); | |
3159 | } | |
3160 | PUSHs(sv_2mortal(newRV_noinc((SV*)av))); | |
3161 | ++i; | |
3162 | } | |
02d1d628 AMH |
3163 | |
3164 | void | |
3165 | i_nearest_color(im, ...) | |
3166 | Imager::ImgRaw im | |
3167 | PREINIT: | |
3168 | int num; | |
3169 | int *xo; | |
3170 | int *yo; | |
3171 | i_color *ival; | |
3172 | int dmeasure; | |
3173 | int i; | |
3174 | SV *sv; | |
3175 | AV *axx; | |
3176 | AV *ayy; | |
3177 | AV *ac; | |
3178 | CODE: | |
3179 | if (items != 5) | |
3180 | croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)"); | |
3181 | if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1)))) | |
3182 | croak("i_nearest_color: Second argument must be an array ref"); | |
3183 | if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2)))) | |
3184 | croak("i_nearest_color: Third argument must be an array ref"); | |
3185 | if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3)))) | |
3186 | croak("i_nearest_color: Fourth argument must be an array ref"); | |
3187 | axx = (AV *)SvRV(ST(1)); | |
3188 | ayy = (AV *)SvRV(ST(2)); | |
3189 | ac = (AV *)SvRV(ST(3)); | |
3190 | dmeasure = (int)SvIV(ST(4)); | |
3191 | ||
3192 | num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy); | |
3193 | num = num <= av_len(ac) ? num : av_len(ac); | |
3194 | num++; | |
3195 | if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each"); | |
3196 | xo = mymalloc( sizeof(int) * num ); | |
3197 | yo = mymalloc( sizeof(int) * num ); | |
3198 | ival = mymalloc( sizeof(i_color) * num ); | |
3199 | for(i = 0; i<num; i++) { | |
3200 | xo[i] = (int)SvIV(* av_fetch(axx, i, 0)); | |
3201 | yo[i] = (int)SvIV(* av_fetch(ayy, i, 0)); | |
3202 | sv = *av_fetch(ac, i, 0); | |
3203 | if ( !sv_derived_from(sv, "Imager::Color") ) { | |
3204 | free(axx); free(ayy); free(ac); | |
3205 | croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color"); | |
3206 | } | |
4c4c2ffd | 3207 | ival[i] = *INT2PTR(i_color *, SvIV((SV *)SvRV(sv))); |
02d1d628 AMH |
3208 | } |
3209 | i_nearest_color(im, num, xo, yo, ival, dmeasure); | |
3210 | ||
3211 | ||
3212 | ||
3213 | ||
3214 | void | |
3215 | malloc_state() | |
3216 | ||
3217 | void | |
3218 | hashinfo(hv) | |
3219 | PREINIT: | |
3220 | HV* hv; | |
3221 | int stuff; | |
3222 | PPCODE: | |
3223 | if (!SvROK(ST(0))) croak("Imager: Parameter 0 must be a reference to a hash\n"); | |
3224 | hv=(HV*)SvRV(ST(0)); | |
3225 | if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 0 must be a reference to a hash\n"); | |
3226 | if (getint(hv,"stuff",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n"); | |
3227 | if (getint(hv,"stuff2",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n"); | |
3228 | ||
3229 | void | |
3230 | DSO_open(filename) | |
3231 | char* filename | |
3232 | PREINIT: | |
3233 | void *rc; | |
3234 | char *evstr; | |
3235 | PPCODE: | |
3236 | rc=DSO_open(filename,&evstr); | |
3237 | if (rc!=NULL) { | |
3238 | if (evstr!=NULL) { | |
3239 | EXTEND(SP,2); | |
e375fbd8 | 3240 | PUSHs(sv_2mortal(newSViv(PTR2IV(rc)))); |
02d1d628 AMH |
3241 | PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr)))); |
3242 | } else { | |
3243 | EXTEND(SP,1); | |
e375fbd8 | 3244 | PUSHs(sv_2mortal(newSViv(PTR2IV(rc)))); |
02d1d628 AMH |
3245 | } |
3246 | } | |
3247 | ||
3248 | ||
3249 | undef_int | |
3250 | DSO_close(dso_handle) | |
3251 | void* dso_handle | |
3252 | ||
3253 | void | |
3254 | DSO_funclist(dso_handle_v) | |
3255 | void* dso_handle_v | |
3256 | PREINIT: | |
3257 | int i; | |
3258 | DSO_handle *dso_handle; | |
3259 | PPCODE: | |
3260 | dso_handle=(DSO_handle*)dso_handle_v; | |
3261 | i=0; | |
3262 | while( dso_handle->function_list[i].name != NULL) { | |
3263 | EXTEND(SP,1); | |
3264 | PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i].name,0))); | |
3265 | EXTEND(SP,1); | |
3266 | PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i++].pcode,0))); | |
3267 | } | |
3268 | ||
3269 | ||
3270 | void | |
3271 | DSO_call(handle,func_index,hv) | |
3272 | void* handle | |
3273 | int func_index | |
3274 | PREINIT: | |
3275 | HV* hv; | |
3276 | PPCODE: | |
3277 | if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to a hash\n"); | |
3278 | hv=(HV*)SvRV(ST(2)); | |
3279 | if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 2 must be a reference to a hash\n"); | |
3280 | DSO_call( (DSO_handle *)handle,func_index,hv); | |
3281 | ||
3282 | ||
3283 | ||
f5991c03 | 3284 | # this is mostly for testing... |
ea9e6c3f TC |
3285 | # this function results in 'RETVAL' : unreferenced local variable |
3286 | # in VC++, and might be subtley wrong | |
3287 | # the most obvious change may result in a double free so I'm leaving it | |
3288 | # for now | |
faa9b3e7 | 3289 | SV * |
f5991c03 TC |
3290 | i_get_pixel(im, x, y) |
3291 | Imager::ImgRaw im | |
3292 | int x | |
3293 | int y; | |
faa9b3e7 TC |
3294 | PREINIT: |
3295 | i_color *color; | |
3296 | CODE: | |
3297 | color = (i_color *)mymalloc(sizeof(i_color)); | |
3298 | if (i_gpix(im, x, y, color) == 0) { | |
3299 | ST(0) = sv_newmortal(); | |
3300 | sv_setref_pv(ST(0), "Imager::Color", (void *)color); | |
3301 | } | |
3302 | else { | |
3303 | myfree(color); | |
3304 | ST(0) = &PL_sv_undef; | |
3305 | } | |
3306 | ||
3307 | ||
3308 | int | |
3309 | i_ppix(im, x, y, cl) | |
3310 | Imager::ImgRaw im | |
3311 | int x | |
3312 | int y | |
3313 | Imager::Color cl | |
3314 | ||
3315 | Imager::ImgRaw | |
3316 | i_img_pal_new(x, y, channels, maxpal) | |
3317 | int x | |
3318 | int y | |
3319 | int channels | |
3320 | int maxpal | |
3321 | ||
3322 | Imager::ImgRaw | |
3323 | i_img_to_pal(src, quant) | |
3324 | Imager::ImgRaw src | |
3325 | PREINIT: | |
3326 | HV *hv; | |
3327 | i_quantize quant; | |
3328 | CODE: | |
3329 | if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1)))) | |
3330 | croak("i_img_to_pal: second argument must be a hash ref"); | |
3331 | hv = (HV *)SvRV(ST(1)); | |
3332 | memset(&quant, 0, sizeof(quant)); | |
3333 | quant.mc_size = 256; | |
faa9b3e7 TC |
3334 | handle_quant_opts(&quant, hv); |
3335 | RETVAL = i_img_to_pal(src, &quant); | |
3336 | if (RETVAL) { | |
3337 | copy_colors_back(hv, &quant); | |
3338 | } | |
46a04ceb | 3339 | cleanup_quant_opts(&quant); |
faa9b3e7 TC |
3340 | OUTPUT: |
3341 | RETVAL | |
3342 | ||
3343 | Imager::ImgRaw | |
3344 | i_img_to_rgb(src) | |
3345 | Imager::ImgRaw src | |
3346 | ||
3347 | void | |
3348 | i_gpal(im, l, r, y) | |
3349 | Imager::ImgRaw im | |
3350 | int l | |
3351 | int r | |
3352 | int y | |
3353 | PREINIT: | |
3354 | i_palidx *work; | |
3355 | int count, i; | |
3356 | PPCODE: | |
3357 | if (l < r) { | |
3358 | work = mymalloc((r-l) * sizeof(i_palidx)); | |
3359 | count = i_gpal(im, l, r, y, work); | |
3360 | if (GIMME_V == G_ARRAY) { | |
3361 | EXTEND(SP, count); | |
3362 | for (i = 0; i < count; ++i) { | |
3363 | PUSHs(sv_2mortal(newSViv(work[i]))); | |
3364 | } | |
3365 | } | |
3366 | else { | |
3367 | EXTEND(SP, 1); | |
26fd367b | 3368 | PUSHs(sv_2mortal(newSVpv((char *)work, count * sizeof(i_palidx)))); |
faa9b3e7 TC |
3369 | } |
3370 | myfree(work); | |
3371 | } | |
3372 | else { | |
3373 | if (GIMME_V != G_ARRAY) { | |
3374 | EXTEND(SP, 1); | |
3375 | PUSHs(&PL_sv_undef); | |
3376 | } | |
3377 | } | |
3378 | ||
3379 | int | |
3380 | i_ppal(im, l, y, ...) | |
3381 | Imager::ImgRaw im | |
3382 | int l | |
3383 | int y | |
3384 | PREINIT: | |
3385 | i_palidx *work; | |
ea9e6c3f | 3386 | int i; |
faa9b3e7 TC |
3387 | CODE: |
3388 | if (items > 3) { | |
3389 | work = mymalloc(sizeof(i_palidx) * (items-3)); | |
3390 | for (i=0; i < items-3; ++i) { | |
3391 | work[i] = SvIV(ST(i+3)); | |
3392 | } | |
3393 | RETVAL = i_ppal(im, l, l+items-3, y, work); | |
3394 | myfree(work); | |
3395 | } | |
3396 | else { | |
3397 | RETVAL = 0; | |
3398 | } | |
3399 | OUTPUT: | |
3400 | RETVAL | |
3401 | ||
3402 | SV * | |
3403 | i_addcolors(im, ...) | |
3404 | Imager::ImgRaw im | |
3405 | PREINIT: | |
3406 | int index; | |
3407 | i_color *colors; | |
3408 | int i; | |
3409 | CODE: | |
3410 | if (items < 2) | |
3411 | croak("i_addcolors: no colors to add"); | |
3412 | colors = mymalloc((items-1) * sizeof(i_color)); | |
3413 | for (i=0; i < items-1; ++i) { | |
3414 | if (sv_isobject(ST(i+1)) | |
3415 | && sv_derived_from(ST(i+1), "Imager::Color")) { | |
3416 | IV tmp = SvIV((SV *)SvRV(ST(i+1))); | |
4c4c2ffd | 3417 | colors[i] = *INT2PTR(i_color *, tmp); |
faa9b3e7 TC |
3418 | } |
3419 | else { | |
3420 | myfree(colors); | |
3421 | croak("i_plin: pixels must be Imager::Color objects"); | |
3422 | } | |
3423 | } | |
3424 | index = i_addcolors(im, colors, items-1); | |
3425 | myfree(colors); | |
3426 | if (index == 0) { | |
3427 | ST(0) = sv_2mortal(newSVpv("0 but true", 0)); | |
3428 | } | |
3429 | else if (index == -1) { | |
3430 | ST(0) = &PL_sv_undef; | |
3431 | } | |
3432 | else { | |
3433 | ST(0) = sv_2mortal(newSViv(index)); | |
3434 | } | |
3435 | ||
1501d9b3 | 3436 | undef_int |
faa9b3e7 TC |
3437 | i_setcolors(im, index, ...) |
3438 | Imager::ImgRaw im | |
3439 | int index | |
3440 | PREINIT: | |
3441 | i_color *colors; | |
3442 | int i; | |
3443 | CODE: | |
3444 | if (items < 3) | |
3445 | croak("i_setcolors: no colors to add"); | |
3446 | colors = mymalloc((items-2) * sizeof(i_color)); | |
3447 | for (i=0; i < items-2; ++i) { | |
3448 | if (sv_isobject(ST(i+2)) | |
3449 | && sv_derived_from(ST(i+2), "Imager::Color")) { | |
3450 | IV tmp = SvIV((SV *)SvRV(ST(i+2))); | |
4c4c2ffd | 3451 | colors[i] = *INT2PTR(i_color *, tmp); |
faa9b3e7 TC |
3452 | } |
3453 | else { | |
3454 | myfree(colors); | |
3455 | croak("i_setcolors: pixels must be Imager::Color objects"); | |
3456 | } | |
3457 | } | |
3458 | RETVAL = i_setcolors(im, index, colors, items-2); | |
3459 | myfree(colors); | |
1501d9b3 TC |
3460 | OUTPUT: |
3461 | RETVAL | |
faa9b3e7 TC |
3462 | |
3463 | void | |
3464 | i_getcolors(im, index, ...) | |
3465 | Imager::ImgRaw im | |
3466 | int index | |
3467 | PREINIT: | |
3468 | i_color *colors; | |
3469 | int count = 1; | |
3470 | int i; | |
3471 | PPCODE: | |
3472 | if (items > 3) | |
3473 | croak("i_getcolors: too many arguments"); | |
3474 | if (items == 3) | |
3475 | count = SvIV(ST(2)); | |
3476 | if (count < 1) | |
3477 | croak("i_getcolors: count must be positive"); | |
3478 | colors = mymalloc(sizeof(i_color) * count); | |
3479 | if (i_getcolors(im, index, colors, count)) { | |
3480 | for (i = 0; i < count; ++i) { | |
3481 | i_color *pv; | |
3482 | SV *sv = sv_newmortal(); | |
3483 | pv = mymalloc(sizeof(i_color)); | |
3484 | *pv = colors[i]; | |
3485 | sv_setref_pv(sv, "Imager::Color", (void *)pv); | |
3486 | PUSHs(sv); | |
3487 | } | |
3488 | } | |
3489 | myfree(colors); | |
3490 | ||
3491 | ||
3492 | SV * | |
3493 | i_colorcount(im) | |
3494 | Imager::ImgRaw im | |
3495 | PREINIT: | |
3496 | int count; | |
3497 | CODE: | |
3498 | count = i_colorcount(im); | |
3499 | if (count >= 0) { | |
3500 | ST(0) = sv_2mortal(newSViv(count)); | |
3501 | } | |
3502 | else { | |
3503 | ST(0) = &PL_sv_undef; | |
3504 | } | |
3505 | ||
3506 | SV * | |
3507 | i_maxcolors(im) | |
3508 | Imager::ImgRaw im | |
3509 | PREINIT: | |
3510 | int count; | |
3511 | CODE: | |
3512 | count = i_maxcolors(im); | |
3513 | if (count >= 0) { | |
3514 | ST(0) = sv_2mortal(newSViv(count)); | |
3515 | } | |
3516 | else { | |
3517 | ST(0) = &PL_sv_undef; | |
3518 | } | |
3519 | ||
3520 | SV * | |
3521 | i_findcolor(im, color) | |
3522 | Imager::ImgRaw im | |
3523 | Imager::Color color | |
3524 | PREINIT: | |
3525 | i_palidx index; | |
3526 | CODE: | |
3527 | if (i_findcolor(im, color, &index)) { | |
3528 | ST(0) = sv_2mortal(newSViv(index)); | |
3529 | } | |
3530 | else { | |
3531 | ST(0) = &PL_sv_undef; | |
3532 | } | |
3533 | ||
3534 | int | |
3535 | i_img_bits(im) | |
3536 | Imager::ImgRaw im | |
3537 | ||
3538 | int | |
3539 | i_img_type(im) | |
3540 | Imager::ImgRaw im | |
3541 | ||
3542 | int | |
3543 | i_img_virtual(im) | |
3544 | Imager::ImgRaw im | |
3545 | ||
3546 | void | |
3547 | i_gsamp(im, l, r, y, ...) | |
3548 | Imager::ImgRaw im | |
3549 | int l | |
3550 | int r | |
3551 | int y | |
3552 | PREINIT: | |
3553 | int *chans; | |
3554 | int chan_count; | |
3555 | i_sample_t *data; | |
3556 | int count, i; | |
3557 | PPCODE: | |
3558 | if (items < 5) | |
3559 | croak("No channel numbers supplied to g_samp()"); | |
3560 | if (l < r) { | |
3561 | chan_count = items - 4; | |
3562 | chans = mymalloc(sizeof(int) * chan_count); | |
3563 | for (i = 0; i < chan_count; ++i) | |
3564 | chans[i] = SvIV(ST(i+4)); | |
4dfa5522 | 3565 | data = mymalloc(sizeof(i_sample_t) * (r-l) * chan_count); /* XXX: memleak? */ |
faa9b3e7 | 3566 | count = i_gsamp(im, l, r, y, data, chans, chan_count); |
4dfa5522 | 3567 | myfree(chans); |
faa9b3e7 TC |
3568 | if (GIMME_V == G_ARRAY) { |
3569 | EXTEND(SP, count); | |
3570 | for (i = 0; i < count; ++i) | |
3571 | PUSHs(sv_2mortal(newSViv(data[i]))); | |
3572 | } | |
3573 | else { | |
3574 | EXTEND(SP, 1); | |
26fd367b | 3575 | PUSHs(sv_2mortal(newSVpv((char *)data, count * sizeof(i_sample_t)))); |
faa9b3e7 | 3576 | } |
a73aeb5f | 3577 | myfree(data); |
faa9b3e7 TC |
3578 | } |
3579 | else { | |
3580 | if (GIMME_V != G_ARRAY) { | |
3581 | EXTEND(SP, 1); | |
3582 | PUSHs(&PL_sv_undef); | |
3583 | } | |
3584 | } | |
3585 | ||
a73aeb5f | 3586 | |
faa9b3e7 TC |
3587 | Imager::ImgRaw |
3588 | i_img_masked_new(targ, mask, x, y, w, h) | |
3589 | Imager::ImgRaw targ | |
3590 | int x | |
3591 | int y | |
3592 | int w | |
3593 | int h | |
3594 | PREINIT: | |
3595 | i_img *mask; | |
3596 | CODE: | |
3597 | if (SvOK(ST(1))) { | |
3598 | if (!sv_isobject(ST(1)) | |
3599 | || !sv_derived_from(ST(1), "Imager::ImgRaw")) { | |
3600 | croak("i_img_masked_new: parameter 2 must undef or an image"); | |
3601 | } | |
4c4c2ffd | 3602 | mask = INT2PTR(i_img *, SvIV((SV *)SvRV(ST(1)))); |
faa9b3e7 TC |
3603 | } |
3604 | else | |
3605 | mask = NULL; | |
3606 | RETVAL = i_img_masked_new(targ, mask, x, y, w, h); | |
3607 | OUTPUT: | |
3608 | RETVAL | |
3609 | ||
3610 | int | |
3611 | i_plin(im, l, y, ...) | |
3612 | Imager::ImgRaw im | |
3613 | int l | |
3614 | int y | |
3615 | PREINIT: | |
3616 | i_color *work; | |
ea9e6c3f | 3617 | int i; |
faa9b3e7 TC |
3618 | CODE: |
3619 | if (items > 3) { | |
3620 | work = mymalloc(sizeof(i_color) * (items-3)); | |
3621 | for (i=0; i < items-3; ++i) { | |
3622 | if (sv_isobject(ST(i+3)) | |
3623 | && sv_derived_from(ST(i+3), "Imager::Color")) { | |
3624 | IV tmp = SvIV((SV *)SvRV(ST(i+3))); | |
4c4c2ffd | 3625 | work[i] = *INT2PTR(i_color *, tmp); |
faa9b3e7 TC |
3626 | } |
3627 | else { | |
3628 | myfree(work); | |
3629 | croak("i_plin: pixels must be Imager::Color objects"); | |
3630 | } | |
3631 | } | |
3632 | /**(char *)0 = 1;*/ | |
3633 | RETVAL = i_plin(im, l, l+items-3, y, work); | |
3634 | myfree(work); | |
3635 | } | |
3636 | else { | |
3637 | RETVAL = 0; | |
3638 | } | |
3639 | OUTPUT: | |
3640 | RETVAL | |
3641 | ||
3642 | int | |
3643 | i_ppixf(im, x, y, cl) | |
3644 | Imager::ImgRaw im | |
3645 | int x | |
3646 | int y | |
3647 | Imager::Color::Float cl | |
3648 | ||
3649 | void | |
3650 | i_gsampf(im, l, r, y, ...) | |
3651 | Imager::ImgRaw im | |
3652 | int l | |
3653 | int r | |
3654 | int y | |
3655 | PREINIT: | |
3656 | int *chans; | |
3657 | int chan_count; | |
3658 | i_fsample_t *data; | |
3659 | int count, i; | |
3660 | PPCODE: | |
3661 | if (items < 5) | |
3662 | croak("No channel numbers supplied to g_sampf()"); | |
3663 | if (l < r) { | |
3664 | chan_count = items - 4; | |
3665 | chans = mymalloc(sizeof(int) * chan_count); | |
3666 | for (i = 0; i < chan_count; ++i) | |
3667 | chans[i] = SvIV(ST(i+4)); | |
3668 | data = mymalloc(sizeof(i_fsample_t) * (r-l) * chan_count); | |
3669 | count = i_gsampf(im, l, r, y, data, chans, chan_count); | |
3670 | if (GIMME_V == G_ARRAY) { | |
3671 | EXTEND(SP, count); | |
3672 | for (i = 0; i < count; ++i) | |
3673 | PUSHs(sv_2mortal(newSVnv(data[i]))); | |
3674 | } | |
3675 | else { | |
3676 | EXTEND(SP, 1); | |
3677 | PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t)))); | |
3678 | } | |
3679 | } | |
3680 | else { | |
3681 | if (GIMME_V != G_ARRAY) { | |
3682 | EXTEND(SP, 1); | |
3683 | PUSHs(&PL_sv_undef); | |
3684 | } | |
3685 | } | |
3686 | ||
3687 | int | |
3688 | i_plinf(im, l, y, ...) | |
3689 | Imager::ImgRaw im | |
3690 | int l | |
3691 | int y | |
3692 | PREINIT: | |
3693 | i_fcolor *work; | |
ea9e6c3f | 3694 | int i; |
faa9b3e7 TC |
3695 | CODE: |
3696 | if (items > 3) { | |
3697 | work = mymalloc(sizeof(i_fcolor) * (items-3)); | |
3698 | for (i=0; i < items-3; ++i) { | |
3699 | if (sv_isobject(ST(i+3)) | |
3700 | && sv_derived_from(ST(i+3), "Imager::Color::Float")) { | |
3701 | IV tmp = SvIV((SV *)SvRV(ST(i+3))); | |
4c4c2ffd | 3702 | work[i] = *INT2PTR(i_fcolor *, tmp); |
faa9b3e7 TC |
3703 | } |
3704 | else { | |
3705 | myfree(work); | |
3706 | croak("i_plin: pixels must be Imager::Color::Float objects"); | |
3707 | } | |
3708 | } | |
3709 | /**(char *)0 = 1;*/ | |
3710 | RETVAL = i_plinf(im, l, l+items-3, y, work); | |
3711 | myfree(work); | |
3712 | } | |
3713 | else { | |
3714 | RETVAL = 0; | |
3715 | } | |
3716 | OUTPUT: | |
3717 | RETVAL | |
3718 | ||
3719 | SV * | |
3720 | i_gpixf(im, x, y) | |
3721 | Imager::ImgRaw im | |
3722 | int x | |
3723 | int y; | |
3724 | PREINIT: | |
3725 | i_fcolor *color; | |
3726 | CODE: | |
3727 | color = (i_fcolor *)mymalloc(sizeof(i_fcolor)); | |
3728 | if (i_gpixf(im, x, y, color) == 0) { | |
3729 | ST(0) = sv_newmortal(); | |
3730 | sv_setref_pv(ST(0), "Imager::Color::Float", (void *)color); | |
3731 | } | |
3732 | else { | |
3733 | myfree(color); | |
3734 | ST(0) = &PL_sv_undef; | |
3735 | } | |
3736 | ||
3737 | void | |
3738 | i_glin(im, l, r, y) | |
3739 | Imager::ImgRaw im | |
3740 | int l | |
3741 | int r | |
3742 | int y | |
3743 | PREINIT: | |
3744 | i_color *vals; | |
3745 | int count, i; | |
3746 | PPCODE: | |
3747 | if (l < r) { | |
3748 | vals = mymalloc((r-l) * sizeof(i_color)); | |
3749 | count = i_glin(im, l, r, y, vals); | |
3750 | EXTEND(SP, count); | |
3751 | for (i = 0; i < count; ++i) { | |
3752 | SV *sv; | |
3753 | i_color *col = mymalloc(sizeof(i_color)); | |
3754 | sv = sv_newmortal(); | |
3755 | sv_setref_pv(sv, "Imager::Color", (void *)col); | |
3756 | PUSHs(sv); | |
3757 | } | |
3758 | myfree(vals); | |
3759 | } | |
3760 | ||
3761 | void | |
3762 | i_glinf(im, l, r, y) | |
3763 | Imager::ImgRaw im | |
3764 | int l | |
3765 | int r | |
3766 | int y | |
3767 | PREINIT: | |
3768 | i_fcolor *vals; | |
3769 | int count, i; | |
3770 | PPCODE: | |
3771 | if (l < r) { | |
3772 | vals = mymalloc((r-l) * sizeof(i_fcolor)); | |
3773 | count = i_glinf(im, l, r, y, vals); | |
3774 | EXTEND(SP, count); | |
3775 | for (i = 0; i < count; ++i) { | |
3776 | SV *sv; | |
3777 | i_fcolor *col = mymalloc(sizeof(i_fcolor)); | |
3778 | *col = vals[i]; | |
3779 | sv = sv_newmortal(); | |
3780 | sv_setref_pv(sv, "Imager::Color::Float", (void *)col); | |
3781 | PUSHs(sv); | |
3782 | } | |
3783 | myfree(vals); | |
3784 | } | |
3785 | ||
3786 | Imager::ImgRaw | |
3787 | i_img_16_new(x, y, ch) | |
3788 | int x | |
3789 | int y | |
3790 | int ch | |
3791 | ||
365ea842 TC |
3792 | Imager::ImgRaw |
3793 | i_img_double_new(x, y, ch) | |
3794 | int x | |
3795 | int y | |
3796 | int ch | |
3797 | ||
faa9b3e7 TC |
3798 | undef_int |
3799 | i_tags_addn(im, name, code, idata) | |
3800 | Imager::ImgRaw im | |
3801 | int code | |
3802 | int idata | |
3803 | PREINIT: | |
3804 | char *name; | |
3805 | STRLEN len; | |
3806 | CODE: | |
3807 | if (SvOK(ST(1))) | |
3808 | name = SvPV(ST(1), len); | |
3809 | else | |
3810 | name = NULL; | |
3811 | RETVAL = i_tags_addn(&im->tags, name, code, idata); | |
3812 | OUTPUT: | |
3813 | RETVAL | |
3814 | ||
3815 | undef_int | |
3816 | i_tags_add(im, name, code, data, idata) | |
3817 | Imager::ImgRaw im | |
3818 | int code | |
3819 | int idata | |
3820 | PREINIT: | |
3821 | char *name; | |
3822 | char *data; | |
3823 | STRLEN len; | |
3824 | CODE: | |
3825 | if (SvOK(ST(1))) | |
3826 | name = SvPV(ST(1), len); | |
3827 | else | |
3828 | name = NULL; | |
3829 | if (SvOK(ST(3))) | |
3830 | data = SvPV(ST(3), len); | |
3831 | else { | |
3832 | data = NULL; | |
3833 | len = 0; | |
3834 | } | |
3835 | RETVAL = i_tags_add(&im->tags, name, code, data, len, idata); | |
3836 | OUTPUT: | |
3837 | RETVAL | |
3838 | ||
3839 | SV * | |
3840 | i_tags_find(im, name, start) | |
3841 | Imager::ImgRaw im | |
3842 | char *name | |
3843 | int start | |
3844 | PREINIT: | |
3845 | int entry; | |
3846 | CODE: | |
3847 | if (i_tags_find(&im->tags, name, start, &entry)) { | |
3848 | if (entry == 0) | |
3849 | ST(0) = sv_2mortal(newSVpv("0 but true", 0)); | |
3850 | else | |
3851 | ST(0) = sv_2mortal(newSViv(entry)); | |
3852 | } else { | |
3853 | ST(0) = &PL_sv_undef; | |
3854 | } | |
3855 | ||
3856 | SV * | |
3857 | i_tags_findn(im, code, start) | |
3858 | Imager::ImgRaw im | |
3859 | int code | |
3860 | int start | |
3861 | PREINIT: | |
3862 | int entry; | |
3863 | CODE: | |
3864 | if (i_tags_findn(&im->tags, code, start, &entry)) { | |
3865 | if (entry == 0) | |
3866 | ST(0) = sv_2mortal(newSVpv("0 but true", 0)); | |
3867 | else | |
3868 | ST(0) = sv_2mortal(newSViv(entry)); | |
3869 | } | |
3870 | else | |
3871 | ST(0) = &PL_sv_undef; | |
3872 | ||
3873 | int | |
3874 | i_tags_delete(im, entry) | |
3875 | Imager::ImgRaw im | |
3876 | int entry | |
3877 | CODE: | |
3878 | RETVAL = i_tags_delete(&im->tags, entry); | |
3879 | OUTPUT: | |
3880 | RETVAL | |
3881 | ||
3882 | int | |
3883 | i_tags_delbyname(im, name) | |
3884 | Imager::ImgRaw im | |
3885 | char * name | |
3886 | CODE: | |
3887 | RETVAL = i_tags_delbyname(&im->tags, name); | |
3888 | OUTPUT: | |
3889 | RETVAL | |
3890 | ||
3891 | int | |
3892 | i_tags_delbycode(im, code) | |
3893 | Imager::ImgRaw im | |
3894 | int code | |
3895 | CODE: | |
3896 | RETVAL = i_tags_delbycode(&im->tags, code); | |
3897 | OUTPUT: | |
3898 | RETVAL | |
3899 | ||
3900 | void | |
3901 | i_tags_get(im, index) | |
3902 | Imager::ImgRaw im | |
3903 | int index | |
3904 | PPCODE: | |
3905 | if (index >= 0 && index < im->tags.count) { | |
3906 | i_img_tag *entry = im->tags.tags + index; | |
3907 | EXTEND(SP, 5); | |
3908 | ||
3909 | if (entry->name) { | |
3910 | PUSHs(sv_2mortal(newSVpv(entry->name, 0))); | |
3911 | } | |
3912 | else { | |
3913 | PUSHs(sv_2mortal(newSViv(entry->code))); | |
3914 | } | |
3915 | if (entry->data) { | |
3916 | PUSHs(sv_2mortal(newSVpvn(entry->data, entry->size))); | |
3917 | } | |
3918 | else { | |
3919 | PUSHs(sv_2mortal(newSViv(entry->idata))); | |
3920 | } | |
3921 | } | |
3922 | ||
3923 | int | |
3924 | i_tags_count(im) | |
3925 | Imager::ImgRaw im | |
3926 | CODE: | |
3927 | RETVAL = im->tags.count; | |
3928 | OUTPUT: | |
3929 | RETVAL | |
3930 | ||
3931 | #ifdef HAVE_WIN32 | |
3932 | ||
3933 | void | |
3934 | i_wf_bbox(face, size, text) | |
3935 | char *face | |
3936 | int size | |
3937 | char *text | |
3938 | PREINIT: | |
3799c4d1 | 3939 | int cords[BOUNDING_BOX_COUNT]; |
0ab90434 | 3940 | int rc, i; |
faa9b3e7 | 3941 | PPCODE: |
3799c4d1 TC |
3942 | if (rc = i_wf_bbox(face, size, text, strlen(text), cords)) { |
3943 | EXTEND(SP, rc); | |
3944 | for (i = 0; i < rc; ++i) | |
3945 | PUSHs(sv_2mortal(newSViv(cords[i]))); | |
faa9b3e7 TC |
3946 | } |
3947 | ||
3948 | undef_int | |
3949 | i_wf_text(face, im, tx, ty, cl, size, text, align, aa) | |
3950 | char *face | |
3951 | Imager::ImgRaw im | |
3952 | int tx | |
3953 | int ty | |
3954 | Imager::Color cl | |
3955 | int size | |
3956 | char *text | |
3957 | int align | |
3958 | int aa | |
3959 | CODE: | |
3960 | RETVAL = i_wf_text(face, im, tx, ty, cl, size, text, strlen(text), | |
3961 | align, aa); | |
3962 | OUTPUT: | |
3963 | RETVAL | |
3964 | ||
3965 | undef_int | |
3966 | i_wf_cp(face, im, tx, ty, channel, size, text, align, aa) | |
3967 | char *face | |
3968 | Imager::ImgRaw im | |
3969 | int tx | |
3970 | int ty | |
3971 | int channel | |
3972 | int size | |
3973 | char *text | |
3974 | int align | |
3975 | int aa | |
f5991c03 | 3976 | CODE: |
faa9b3e7 TC |
3977 | RETVAL = i_wf_cp(face, im, tx, ty, channel, size, text, strlen(text), |
3978 | align, aa); | |
f5991c03 TC |
3979 | OUTPUT: |
3980 | RETVAL | |
02d1d628 | 3981 | |
faa9b3e7 TC |
3982 | |
3983 | #endif | |
3984 | ||
3985 | #ifdef HAVE_FT2 | |
3986 | ||
3987 | MODULE = Imager PACKAGE = Imager::Font::FT2 PREFIX=FT2_ | |
3988 | ||
3989 | #define FT2_DESTROY(font) i_ft2_destroy(font) | |
3990 | ||
3991 | void | |
3992 | FT2_DESTROY(font) | |
3993 | Imager::Font::FT2 font | |
3994 | ||
3995 | MODULE = Imager PACKAGE = Imager::Font::FreeType2 | |
3996 | ||
3997 | Imager::Font::FT2 | |
3998 | i_ft2_new(name, index) | |
3999 | char *name | |
4000 | int index | |
4001 | ||
4002 | undef_int | |
4003 | i_ft2_setdpi(font, xdpi, ydpi) | |
4004 | Imager::Font::FT2 font | |
4005 | int xdpi | |
4006 | int ydpi | |
4007 | ||
4008 | void | |
4009 | i_ft2_getdpi(font) | |
4010 | Imager::Font::FT2 font | |
4011 | PREINIT: | |
4012 | int xdpi, ydpi; | |
4013 | CODE: | |
4014 | if (i_ft2_getdpi(font, &xdpi, &ydpi)) { | |
4015 | EXTEND(SP, 2); | |
4016 | PUSHs(sv_2mortal(newSViv(xdpi))); | |
4017 | PUSHs(sv_2mortal(newSViv(ydpi))); | |
4018 | } | |
4019 | ||
4020 | undef_int | |
4021 | i_ft2_sethinting(font, hinting) | |
4022 | Imager::Font::FT2 font | |
4023 | int hinting | |
4024 | ||
4025 | undef_int | |
4026 | i_ft2_settransform(font, matrix) | |
4027 | Imager::Font::FT2 font | |
4028 | PREINIT: | |
4029 | double matrix[6]; | |
4030 | int len; | |
4031 | AV *av; | |
4032 | SV *sv1; | |
4033 | int i; | |
4034 | CODE: | |
4035 | if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV) | |
4036 | croak("i_ft2_settransform: parameter 2 must be an array ref\n"); | |
4037 | av=(AV*)SvRV(ST(1)); | |
4038 | len=av_len(av)+1; | |
4039 | if (len > 6) | |
4040 | len = 6; | |
4041 | for (i = 0; i < len; ++i) { | |
4042 | sv1=(*(av_fetch(av,i,0))); | |
4043 | matrix[i] = SvNV(sv1); | |
4044 | } | |
4045 | for (; i < 6; ++i) | |
4046 | matrix[i] = 0; | |
4047 | RETVAL = i_ft2_settransform(font, matrix); | |
4048 | OUTPUT: | |
4049 | RETVAL | |
4050 | ||
4051 | void | |
3799c4d1 | 4052 | i_ft2_bbox(font, cheight, cwidth, text_sv, utf8) |
faa9b3e7 TC |
4053 | Imager::Font::FT2 font |
4054 | double cheight | |
4055 | double cwidth | |
3799c4d1 | 4056 | SV *text_sv |
5cb9270b | 4057 | int utf8 |
faa9b3e7 | 4058 | PREINIT: |
3799c4d1 | 4059 | int bbox[BOUNDING_BOX_COUNT]; |
faa9b3e7 | 4060 | int i; |
3799c4d1 TC |
4061 | char *text; |
4062 | STRLEN text_len; | |
4063 | int rc; | |
faa9b3e7 | 4064 | PPCODE: |
3799c4d1 | 4065 | text = SvPV(text_sv, text_len); |
5cb9270b | 4066 | #ifdef SvUTF8 |
3799c4d1 | 4067 | if (SvUTF8(text_sv)) |
5cb9270b TC |
4068 | utf8 = 1; |
4069 | #endif | |
3799c4d1 TC |
4070 | rc = i_ft2_bbox(font, cheight, cwidth, text, text_len, bbox, utf8); |
4071 | if (rc) { | |
4072 | EXTEND(SP, rc); | |
4073 | for (i = 0; i < rc; ++i) | |
faa9b3e7 TC |
4074 | PUSHs(sv_2mortal(newSViv(bbox[i]))); |
4075 | } | |
4076 | ||
4077 | void | |
4078 | i_ft2_bbox_r(font, cheight, cwidth, text, vlayout, utf8) | |
4079 | Imager::Font::FT2 font | |
4080 | double cheight | |
4081 | double cwidth | |
4082 | char *text | |
4083 | int vlayout | |
4084 | int utf8 | |
4085 | PREINIT: | |
4086 | int bbox[8]; | |
4087 | int i; | |
4088 | PPCODE: | |
4089 | #ifdef SvUTF8 | |
4090 | if (SvUTF8(ST(3))) | |
4091 | utf8 = 1; | |
4092 | #endif | |
4093 | if (i_ft2_bbox_r(font, cheight, cwidth, text, strlen(text), vlayout, | |
4094 | utf8, bbox)) { | |
4095 | EXTEND(SP, 8); | |
4096 | for (i = 0; i < 8; ++i) | |
4097 | PUSHs(sv_2mortal(newSViv(bbox[i]))); | |
4098 | } | |
4099 | ||
4100 | undef_int | |
4101 | i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text, align, aa, vlayout, utf8) | |
4102 | Imager::Font::FT2 font | |
4103 | Imager::ImgRaw im | |
4104 | int tx | |
4105 | int ty | |
4106 | Imager::Color cl | |
4107 | double cheight | |
4108 | double cwidth | |
4109 | int align | |
4110 | int aa | |
4111 | int vlayout | |
4112 | int utf8 | |
4113 | PREINIT: | |
4114 | char *text; | |
4115 | STRLEN len; | |
4116 | CODE: | |
4117 | #ifdef SvUTF8 | |
4118 | if (SvUTF8(ST(7))) { | |
4119 | utf8 = 1; | |
4120 | } | |
4121 | #endif | |
4122 | text = SvPV(ST(7), len); | |
4123 | RETVAL = i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text, | |
4124 | len, align, aa, vlayout, utf8); | |
4125 | OUTPUT: | |
4126 | RETVAL | |
4127 | ||
4128 | undef_int | |
4129 | i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text, align, aa, vlayout, utf8) | |
4130 | Imager::Font::FT2 font | |
4131 | Imager::ImgRaw im | |
4132 | int tx | |
4133 | int ty | |
4134 | int channel | |
4135 | double cheight | |
4136 | double cwidth | |
4137 | char *text | |
4138 | int align | |
4139 | int aa | |
4140 | int vlayout | |
4141 | int utf8 | |
4142 | CODE: | |
4143 | #ifdef SvUTF8 | |
4144 | if (SvUTF8(ST(7))) | |
4145 | utf8 = 1; | |
4146 | #endif | |
4147 | RETVAL = i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text, | |
4148 | strlen(text), align, aa, vlayout, 1); | |
4149 | OUTPUT: | |
4150 | RETVAL | |
4151 | ||
4152 | void | |
4153 | ft2_transform_box(font, x0, x1, x2, x3) | |
4154 | Imager::Font::FT2 font | |
4155 | int x0 | |
4156 | int x1 | |
4157 | int x2 | |
4158 | int x3 | |
4159 | PREINIT: | |
4160 | int box[4]; | |
4161 | PPCODE: | |
4162 | box[0] = x0; box[1] = x1; box[2] = x2; box[3] = x3; | |
4163 | ft2_transform_box(font, box); | |
4164 | EXTEND(SP, 4); | |
4165 | PUSHs(sv_2mortal(newSViv(box[0]))); | |
4166 | PUSHs(sv_2mortal(newSViv(box[1]))); | |
4167 | PUSHs(sv_2mortal(newSViv(box[2]))); | |
4168 | PUSHs(sv_2mortal(newSViv(box[3]))); | |
3dec2c92 TC |
4169 | |
4170 | void | |
eeaa33fd | 4171 | i_ft2_has_chars(handle, text_sv, utf8) |
3dec2c92 | 4172 | Imager::Font::FT2 handle |
eeaa33fd | 4173 | SV *text_sv |
3dec2c92 TC |
4174 | int utf8 |
4175 | PREINIT: | |
4176 | char *text; | |
4177 | STRLEN len; | |
4178 | char *work; | |
4179 | int count; | |
4180 | int i; | |
4181 | PPCODE: | |
4182 | #ifdef SvUTF8 | |
eeaa33fd | 4183 | if (SvUTF8(text_sv)) |
3dec2c92 TC |
4184 | utf8 = 1; |
4185 | #endif | |
eeaa33fd | 4186 | text = SvPV(text_sv, len); |
3dec2c92 TC |
4187 | work = mymalloc(len); |
4188 | count = i_ft2_has_chars(handle, text, len, utf8, work); | |
4189 | if (GIMME_V == G_ARRAY) { | |
4190 | EXTEND(SP, count); | |
4191 | for (i = 0; i < count; ++i) { | |
4192 | PUSHs(sv_2mortal(newSViv(work[i]))); | |
4193 | } | |
4194 | } | |
4195 | else { | |
4196 | EXTEND(SP, 1); | |
4197 | PUSHs(sv_2mortal(newSVpv(work, count))); | |
4198 | } | |
4199 | myfree(work); | |
4200 | ||
3799c4d1 TC |
4201 | void |
4202 | i_ft2_face_name(handle) | |
4203 | Imager::Font::FT2 handle | |
4204 | PREINIT: | |
4205 | char name[255]; | |
4206 | int len; | |
4207 | PPCODE: | |
4208 | len = i_ft2_face_name(handle, name, sizeof(name)); | |
4209 | if (len) { | |
4210 | EXTEND(SP, 1); | |
4211 | PUSHs(sv_2mortal(newSVpv(name, 0))); | |
4212 | } | |
4213 | ||
042cdaea TC |
4214 | undef_int |
4215 | i_ft2_can_face_name() | |
4216 | ||
19fa4baf AMH |
4217 | void |
4218 | i_ft2_glyph_name(handle, text_sv, utf8 = 0) | |
3799c4d1 TC |
4219 | Imager::Font::FT2 handle |
4220 | SV *text_sv | |
4221 | int utf8 | |
4222 | PREINIT: | |
4223 | char const *text; | |
4224 | STRLEN work_len; | |
4225 | int len; | |
4226 | int outsize; | |
4227 | char name[255]; | |
4228 | PPCODE: | |
4229 | #ifdef SvUTF8 | |
4230 | if (SvUTF8(text_sv)) | |
4231 | utf8 = 1; | |
4232 | #endif | |
4233 | text = SvPV(text_sv, work_len); | |
4234 | len = work_len; | |
4235 | while (len) { | |
4236 | unsigned char ch; | |
4237 | if (utf8) { | |
4238 | ch = i_utf8_advance(&text, &len); | |
4239 | if (ch == ~0UL) { | |
4240 | i_push_error(0, "invalid UTF8 character"); | |
4241 | break; | |
4242 | } | |
4243 | } | |
4244 | else { | |
4245 | ch = *text++; | |
4246 | --len; | |
4247 | } | |
4248 | EXTEND(SP, 1); | |
4249 | if (outsize = i_ft2_glyph_name(handle, ch, name, sizeof(name))) { | |
4250 | PUSHs(sv_2mortal(newSVpv(name, 0))); | |
4251 | } | |
4252 | else { | |
4253 | PUSHs(&PL_sv_undef); | |
4254 | } | |
4255 | } | |
4256 | ||
4257 | int | |
4258 | i_ft2_can_do_glyph_names() | |
4259 | ||
4260 | int | |
4261 | i_ft2_face_has_glyph_names(handle) | |
4262 | Imager::Font::FT2 handle | |
4263 | ||
faa9b3e7 TC |
4264 | #endif |
4265 | ||
f1ac5027 TC |
4266 | MODULE = Imager PACKAGE = Imager::FillHandle PREFIX=IFILL_ |
4267 | ||
4268 | void | |
4269 | IFILL_DESTROY(fill) | |
4270 | Imager::FillHandle fill | |
4271 | ||
4272 | MODULE = Imager PACKAGE = Imager | |
4273 | ||
4274 | Imager::FillHandle | |
4275 | i_new_fill_solid(cl, combine) | |
4276 | Imager::Color cl | |
4277 | int combine | |
4278 | ||
4279 | Imager::FillHandle | |
4280 | i_new_fill_solidf(cl, combine) | |
4281 | Imager::Color::Float cl | |
4282 | int combine | |
4283 | ||
4284 | Imager::FillHandle | |
4285 | i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy) | |
4286 | Imager::Color fg | |
4287 | Imager::Color bg | |
4288 | int combine | |
4289 | int hatch | |
4290 | int dx | |
4291 | int dy | |
4292 | PREINIT: | |
4293 | unsigned char *cust_hatch; | |
4294 | STRLEN len; | |
4295 | CODE: | |
4296 | if (SvOK(ST(4))) { | |
26fd367b | 4297 | cust_hatch = (unsigned char *)SvPV(ST(4), len); |
f1ac5027 TC |
4298 | } |
4299 | else | |
4300 | cust_hatch = NULL; | |
4301 | RETVAL = i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy); | |
4302 | OUTPUT: | |
4303 | RETVAL | |
4304 | ||
efdc2568 TC |
4305 | Imager::FillHandle |
4306 | i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy) | |
4307 | Imager::Color::Float fg | |
4308 | Imager::Color::Float bg | |
4309 | int combine | |
4310 | int hatch | |
4311 | int dx | |
4312 | int dy | |
4313 | PREINIT: | |
4314 | unsigned char *cust_hatch; | |
4315 | STRLEN len; | |
4316 | CODE: | |
4317 | if (SvOK(ST(4))) { | |
26fd367b | 4318 | cust_hatch = (unsigned char *)SvPV(ST(4), len); |
efdc2568 TC |
4319 | } |
4320 | else | |
4321 | cust_hatch = NULL; | |
4322 | RETVAL = i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy); | |
4323 | OUTPUT: | |
4324 | RETVAL | |
4325 | ||
f576ce7e TC |
4326 | Imager::FillHandle |
4327 | i_new_fill_image(src, matrix, xoff, yoff, combine) | |
4328 | Imager |