most numeric parameters to the XS implementation now throw an exception if supplied...
[imager.git] / ICO / ICO.xs
CommitLineData
b13a3ddb 1#define PERL_NO_GET_CONTEXT
b00687b2
TC
2#include "EXTERN.h"
3#include "perl.h"
4#include "XSUB.h"
5#include "imext.h"
6#include "imperl.h"
7#include "imicon.h"
13eb8ccd 8#include "ppport.h"
b00687b2
TC
9
10DEFINE_IMAGER_CALLBACKS;
11
12MODULE = Imager::File::ICO PACKAGE = Imager::File::ICO
13
14PROTOTYPES: DISABLE
15
16Imager::ImgRaw
f17a0a60 17i_readico_single(ig, index, masked = 0, alpha_masked = 0)
b00687b2
TC
18 Imager::IO ig
19 int index
413dc198 20 bool masked
f17a0a60 21 bool alpha_masked
b00687b2
TC
22
23void
f17a0a60 24i_readico_multi(ig, masked = 0, alpha_masked = 0)
b00687b2 25 Imager::IO ig
413dc198 26 bool masked
f17a0a60 27 bool alpha_masked
b00687b2
TC
28 PREINIT:
29 i_img **imgs;
30 int count;
31 int i;
32 PPCODE:
f17a0a60 33 imgs = i_readico_multi(ig, &count, masked, alpha_masked);
b00687b2
TC
34 if (imgs) {
35 EXTEND(SP, count);
36 for (i = 0; i < count; ++i) {
37 SV *sv = sv_newmortal();
38 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
39 PUSHs(sv);
40 }
41 myfree(imgs);
42 }
43
2b405c9e
TC
44int
45i_writeico_wiol(ig, im)
46 Imager::IO ig
47 Imager::ImgRaw im
48
49undef_int
50i_writeico_multi_wiol(ig, ...)
51 Imager::IO ig
52 PREINIT:
53 int i;
54 int img_count;
55 i_img **imgs;
56 CODE:
57 if (items < 2)
58 croak("Usage: i_writeico_multi_wiol(ig, images...)");
59 img_count = items - 1;
60 RETVAL = 1;
61 if (img_count < 1) {
62 RETVAL = 0;
63 i_clear_error();
64 i_push_error(0, "You need to specify images to save");
65 }
66 else {
67 imgs = mymalloc(sizeof(i_img *) * img_count);
68 for (i = 0; i < img_count; ++i) {
69 SV *sv = ST(1+i);
70 imgs[i] = NULL;
71 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
72 imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(sv)));
73 }
74 else {
75 i_clear_error();
76 i_push_error(0, "Only images can be saved");
77 myfree(imgs);
78 RETVAL = 0;
79 break;
80 }
81 }
82 if (RETVAL) {
83 RETVAL = i_writeico_multi_wiol(ig, imgs, img_count);
84 }
85 myfree(imgs);
86 }
87 OUTPUT:
88 RETVAL
89
90int
91i_writecur_wiol(ig, im)
92 Imager::IO ig
93 Imager::ImgRaw im
94
95undef_int
96i_writecur_multi_wiol(ig, ...)
97 Imager::IO ig
98 PREINIT:
99 int i;
100 int img_count;
101 i_img **imgs;
102 CODE:
103 if (items < 2)
104 croak("Usage: i_writecur_multi_wiol(ig, images...)");
105 img_count = items - 1;
106 RETVAL = 1;
107 if (img_count < 1) {
108 RETVAL = 0;
109 i_clear_error();
110 i_push_error(0, "You need to specify images to save");
111 }
112 else {
113 imgs = mymalloc(sizeof(i_img *) * img_count);
114 for (i = 0; i < img_count; ++i) {
115 SV *sv = ST(1+i);
116 imgs[i] = NULL;
117 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
118 imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(sv)));
119 }
120 else {
121 i_clear_error();
122 i_push_error(0, "Only images can be saved");
123 myfree(imgs);
124 RETVAL = 0;
125 break;
126 }
127 }
128 if (RETVAL) {
129 RETVAL = i_writecur_multi_wiol(ig, imgs, img_count);
130 }
131 myfree(imgs);
132 }
133 OUTPUT:
134 RETVAL
b00687b2
TC
135
136BOOT:
137 PERL_INITIALIZE_IMAGER_CALLBACKS;