3 Imager::API - Imager's C API - introduction.
10 DEFINE_IMAGER_CALLBACKS;
12 MODULE = Your::Module PACKAGE = Your::Module
17 PERL_INITIALIZE_IMAGER_CALLBACKS;
24 The API allows you to access Imager functions at the C level from XS
27 The intent is to allow users to:
33 write C code that does Imager operations the user might do from Perl,
34 but faster, for example, the Imager::CountColor example.
38 write C code that implements an application specific version of some
39 core Imager object, for example, Imager::SDL.
43 write C code that hooks into Imager's existing methods, such as filter
44 or file format handlers.
48 See L<Imager::Inline> for information on using Imager's Inline::C
57 don't return an object you received as a parameter - this will cause
58 the object to be freed twice.
64 The API makes the following types visible:
70 i_img - used to represent an image
74 i_color - used to represent a color with up to 8 bits per sample.
78 i_fcolor - used to represent a color with a double per sample.
82 i_fill_t - an abstract fill
86 At this point there is no consolidated font object type, and hence the
87 font functions are not visible through Imager's API.
91 This contains the dimensions of the image (C<xsize>, C<ysize>,
92 C<channels>), image metadata (C<ch_mask>, C<bits>, C<type>,
93 C<virtual>), potentially image data (C<idata>) and the a function
94 table, with pointers to functions to perform various low level image
97 The only time you should directly write to any value in this type is
98 if you're implementing your own image type.
100 The typemap includes type names Imager and Imager::ImgRaw as typedefs
103 For incoming parameters the typemap will accept either Imager or
104 Imager::ImgRaw objects.
106 For return values the typemap will produce a full Imager object for an
107 Imager return type and a raw image object for an Imager::ImgRaw return
110 =head2 C<i_color> - 8-bit color
112 Represents an 8-bit per sample color. This is a union containing
113 several different structs for access to components of a color:
119 C<gray> - single member C<gray_color>.
123 C<rgb> - C<r>, C<g>, C<b> members.
127 C<rgba> - C<r>, C<g>, C<b>, C<a> members.
131 C<channels> - array of channels.
135 Use Imager::Color for parameter and return value types.
137 =head2 C<i_fcolor> - floating point color
139 Similar to C<i_color> except that each component is a double instead of
142 Use Imager::Color::Float for parameter and return value types.
144 =head2 C<i_fill_t> - fill objects
146 Abstract type containing pointers called to perform low level fill
149 Unless you're defining your own fill objects you should treat this as
152 Use Imager::FillHandle for parameter and return value types. At the
153 Perl level this is stored in the C<fill> member of the Perl level
156 =head1 Create an XS module using the Imager API
164 and bootstrap your XS code - see L<XSLoader> or L<DynaLoader>.
168 You'll need the following in your XS source:
174 include the Imager external API header, and the perl interface header:
181 create the variables used to hold the callback table:
183 DEFINE_IMAGER_CALLBACKS;
187 initialize the callback table in your C<BOOT> code:
190 PERL_INITIALIZE_IMAGER_CALLBACKS;
196 In any other source files where you want to access the Imager API,
203 include the Imager external API header:
209 =head2 C<Makefile.PL>
211 If you're creating an XS module that depends on Imager's API your
212 C<Makefile.PL> will need to do the following:
218 C<use Imager::ExtUtils;>
222 include Imager's include directory in INC:
224 INC => Imager::ExtUtils->includes
228 use Imager's typemap:
230 TYPEMAPS => [ Imager::ExtUtils->typemap ]
234 include Imager 0.48 as a PREREQ_PM:
243 Since you use Imager::ExtUtils in C<Makefile.PL> (or C<Build.PL>) you
244 should include Imager in your configure_requires:
248 configure_requires => { Imager => "0.48" }
255 Tony Cook <tony@imager.perl.org>
259 Imager, Imager::ExtUtils, Imager::APIRef, Imager::Inline