3 Imager::API - Imager's C API - introduction.
10 DEFINE_IMAGER_CALLBACKS;
12 MODULE = Your::Module PACKAGE = Your::Module
17 /* any release with the API */
18 PERL_INITIALIZE_IMAGER_CALLBACKS;
19 /* preferred from Imager 0.91 */
20 PERL_INITIALIZE_IMAGER_CALLBACKS_NAME("My::Module");
27 The API allows you to access Imager functions at the C level from XS
30 The intent is to allow users to:
36 write C code that does Imager operations the user might do from Perl,
37 but faster, for example, the Imager::CountColor example.
41 write C code that implements an application specific version of some
42 core Imager object, for example, Imager::SDL.
46 write C code that hooks into Imager's existing methods, such as filter
47 or file format handlers.
51 See L<Imager::Inline> for information on using Imager's Inline::C
60 don't return an object you received as a parameter - this will cause
61 the object to be freed twice.
67 The API makes the following types visible:
73 i_img - used to represent an image
77 i_color - used to represent a color with up to 8 bits per sample.
81 i_fcolor - used to represent a color with a double per sample.
85 i_fill_t - an abstract fill
89 At this point there is no consolidated font object type, and hence the
90 font functions are not visible through Imager's API.
94 This contains the dimensions of the image (C<xsize>, C<ysize>,
95 C<channels>), image metadata (C<ch_mask>, C<bits>, C<type>,
96 C<virtual>), potentially image data (C<idata>) and the a function
97 table, with pointers to functions to perform various low level image
100 The only time you should directly write to any value in this type is
101 if you're implementing your own image type.
103 The typemap includes type names Imager and Imager::ImgRaw as typedefs
106 For incoming parameters the typemap will accept either Imager or
107 Imager::ImgRaw objects.
109 For return values the typemap will produce a full Imager object for an
110 Imager return type and a raw image object for an Imager::ImgRaw return
113 =head2 C<i_color> - 8-bit color
115 Represents an 8-bit per sample color. This is a union containing
116 several different structs for access to components of a color:
122 C<gray> - single member C<gray_color>.
126 C<rgb> - C<r>, C<g>, C<b> members.
130 C<rgba> - C<r>, C<g>, C<b>, C<a> members.
134 C<channels> - array of channels.
138 Use Imager::Color for parameter and return value types.
140 =head2 C<i_fcolor> - floating point color
142 Similar to C<i_color> except that each component is a double instead of
145 Use Imager::Color::Float for parameter and return value types.
147 =head2 C<i_fill_t> - fill objects
149 Abstract type containing pointers called to perform low level fill
152 Unless you're defining your own fill objects you should treat this as
155 Use Imager::FillHandle for parameter and return value types. At the
156 Perl level this is stored in the C<fill> member of the Perl level
159 =head1 Create an XS module using the Imager API
167 and bootstrap your XS code - see L<XSLoader> or L<DynaLoader>.
171 You'll need the following in your XS source:
177 include the Imager external API header, and the perl interface header:
184 create the variables used to hold the callback table:
186 DEFINE_IMAGER_CALLBACKS;
190 initialize the callback table in your C<BOOT> code:
193 PERL_INITIALIZE_IMAGER_CALLBACKS;
195 From Imager 0.91 you can supply your module name to improve error
199 PERL_INITIALIZE_IMAGER_CALLBACKS_NAME("My::Module");
205 In any other source files where you want to access the Imager API,
212 include the Imager external API header:
218 =head2 C<Makefile.PL>
220 If you're creating an XS module that depends on Imager's API your
221 C<Makefile.PL> will need to do the following:
227 C<use Imager::ExtUtils;>
231 include Imager's include directory in INC:
233 INC => Imager::ExtUtils->includes
237 use Imager's typemap:
239 TYPEMAPS => [ Imager::ExtUtils->typemap ]
243 include Imager 0.48 as a PREREQ_PM:
252 Since you use Imager::ExtUtils in C<Makefile.PL> (or C<Build.PL>) you
253 should include Imager in your configure_requires:
257 configure_requires => { Imager => "0.48" }
264 Tony Cook <tonyc@cpan.org>
268 Imager, Imager::ExtUtils, Imager::APIRef, Imager::Inline