API documentation (mostly)
[imager.git] / lib / Imager / API.pod
CommitLineData
92bda632
TC
1=head1 NAME
2
3Imager::API - Imager's C API - introduction.
4
5=head1 SYNOPSIS
6
7 #include "imext.h"
8 #include "imperl.h"
9
10 DEFINE_IMAGER_CALLBACKS;
11
12 MODULE = Your::Module PACKAGE = Your::Module
13
14 ...
15
16 BOOT:
17 PERL_INITIALIZE_IMAGER_CALLBACKS;
18
19
20=head1 DESCRIPTION
21
22The API allows you to access Imager functions at the C level from XS
23and from Inline::C.
24
25The intent is to allow users to:
26
27=over
28
29=item *
30
31write C code that does Imager operations the user might do from Perl,
32but faster, for example, the Imager::CountColor example.
33
34=item *
35
36write C code that implements an application specific version of some
37core Imager object, for example, Imager::SDL.
38
39=item *
40
41write C code that hooks into Imagers existing methods, such as filter
42or file format handlers.
43
44=back
45
46See L<Imager::Inline> for information on using Imager's Inline::C
47support.
48
f399cac8
TC
49=head1 Beware
50
51=over
52
53=item *
54
55don't return an object you received as a parameter - this will cause
56the object to be freed twice.
57
58=back
59
92bda632
TC
60=head1 Types
61
62The API makes the following types visible:
63
64=over
65
66=item *
67
68i_img - used to represent an image
69
70=item *
71
72i_color - used to represent a color with up to 8 bits per sample.
73
74=item *
75
76i_fcolor - used to represent a color with a double per sample.
77
78=item *
79
80i_fill_t - an abstract fill
81
82=back
83
84At this point there is no consolidated font object type, and hence the
85font functions are not visible through Imager's API.
86
87=head2 i_img - images
88
89This contains the dimensions of the image (xsize, ysize, channels),
90image metadata (ch_mask, bits, type, virtual), potentially image data
91(idata) and the a function table, with pointers to functions to
92perform various low level image operations.
93
94The only time you should directly write to any value in this type is
95if you're implementing your own image type.
96
f399cac8
TC
97The typemap includes typenames Imager and Imager::ImgRaw as typedefs
98for C<i_img *>.
99
100For incoming parameters the typemap will accept either Imager or
101Imager::ImgRaw objects.
102
103For return values the typemap will produce a full Imager object for an
104Imager return type and a raw image object for an Imager::ImgRaw return
105type.
106
92bda632
TC
107=head2 i_color - 8-bit color
108
109Represents an 8-bit per sample color. This is a union containing
110several different structs for access to components of a color:
111
112=over
113
114=item *
115
116gray - single member gray_color.
117
118=item *
119
120rgb - r, g, b members.
121
122=item *
123
124rgba - r, g, b, a members.
125
126=item *
127
128channels - array of channels.
129
130=back
131
f399cac8
TC
132Use Imager::Color for parameter and return value types.
133
92bda632
TC
134=head2 i_fcolor - floating point color
135
f399cac8 136Similar to i_color except that each component is a double instead of
92bda632
TC
137an unsigned char.
138
f399cac8
TC
139Use Imager::Color::Float for parameter and return value types.
140
92bda632
TC
141=head2 i_fill_t - fill objects
142
143Abstract type containing pointers called to perform low level fill
144operations.
145
146Unless you're defining your own fill objects you should treat this as
147an opaque type.
148
f399cac8
TC
149Use Imager::FillHandle for parameter and return value types. At the
150Perl level this is stored in the C<fill> member of the Perl level
151Imager::Fill object.
152
92bda632
TC
153=head1 Create an XS module using the Imager API
154
9c05a0e0
TC
155=head2 Foo.pm
156
157Load Imager:
158
159 use Imager 0.48;
160
161and bootstrap your XS code - see L<XSLoader> or L<DynaLoader>.
162
92bda632
TC
163=head2 Foo.xs
164
165You'll need the following in your XS source:
166
167=over
168
169=item *
170
171include the Imager external API header, and the perl interface header:
172
173 #include "imext.h"
174 #include "imperl.h"
175
176=item *
177
178create the variables used to hold the callback table:
179
180 DEFINE_IMAGER_CALLBACKS;
181
182=item *
183
184initialize the callback table in your BOOT code:
185
186 BOOT:
187 PERL_INITIALIZE_IMAGER_CALLBACKS;
188
189=back
190
191=head2 foo.c
192
193In any other source files where you want to access the Imager API,
194you'll need to:
195
196=over
197
198=item *
199
200include the Imager external API header:
201
202 #include "imext.h"
203
204=back
205
206=head2 Makefile.PL
207
208If you're creating an XS module that depends on Imager's API your
209Makefile.PL will need to do the following:
210
211=over
212
213=item *
214
215C<use Imager::ExtUtils;>
216
217=item *
218
219include Imager's include directory in INC:
220
221 INC => Imager::ExtUtils->includes
222
223=item *
224
225use Imager's typemap:
226
227 TYPEMAPS => [ Imager::ExtUtils->typemap ]
228
229=item *
230
231include Imager 0.48 as a PREREQ_PM:
232
233 PREREQ_PM =>
234 {
235 Imager => 0.48,
236 },
237
6cfee9d1
TC
238=item *
239
240Since you use Imager::ExtUtils in Makefile.PL (or Build.PL) you should
241include Imager in your configure_requires:
242
243 META_MERGE =>
244 {
245 configure_requires => { Imager => "0.48" }
246 },
247
92bda632
TC
248=back
249
250=head1 AUTHOR
251
252Tony Cook <tony@imager.perl.org>
253
254=head1 SEE ALSO
255
256Imager, Imager::ExtUtils, Imager::APIRef, Imager::Inline
257
258=cut