3 <h3 id="TOP">Index</h3>
5 <ul><li><a href="#NAME">NAME</a></li>
6 <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
7 <li><a href="#CATEGORY">CATEGORY</a></li>
8 <li><a href="#SUPPORTED_FORMATS">SUPPORTED FORMATS </a></li>
9 <li><a href="#LOADING_METHODS">LOADING METHODS</a>
10 <ul><li><a href="#load">load</a>
11 <ul><li><a href="#Return">Return</a></li>
14 <li><a href="#load_typed_rw">load_typed_rw</a>
15 <ul><li><a href="#Transparency">Transparency </a></li>
16 <li><a href="#Return-2">Return </a></li>
19 <li><a href="#is_TYPE">is_[TYPE]</a>
20 <ul><li><a href="#Return-3">Return</a></li>
21 <li><a href="#Example">Example</a></li>
24 <li><a href="#load_TYPE_rw">load_[TYPE]_rw</a>
25 <ul><li><a href="#Return-4">Return</a></li>
26 <li><a href="#Example-2">Example</a></li>
29 <li><a href="#read_XPM_from_array">read_XPM_from_array</a>
30 <ul><li><a href="#Return-5">Return</a></li>
31 <li><a href="#Example-3">Example</a></li>
36 <li><a href="#MISC_METHODS">MISC METHODS</a>
37 <ul><li><a href="#linked_version">linked_version</a>
38 <ul><li><a href="#Return-6">Return</a></li>
39 <li><a href="#Example-4">Example</a></li>
42 <li><a href="#init">init</a>
43 <ul><li><a href="#Flags">Flags</a></li>
44 <li><a href="#Return-7">Return</a></li>
45 <li><a href="#Example-5">Example</a></li>
48 <li><a href="#quit">quit</a>
49 <ul><li><a href="#Example-6">Example</a></li>
52 <li><a href="#set_error">set_error</a></li>
53 <li><a href="#get_error">get_error</a></li>
56 <li><a href="#SEE_ALSO">SEE ALSO</a>
61 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
62 <div id="NAME_CONTENT">
63 <p>SDL::Image - Bindings for the SDL_Image library</p>
66 <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
67 <div id="DESCRIPTION_CONTENT">
68 <p>SDL::Image allows you to load many different format of images into memory as an SDL::Surface.</p>
71 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
72 <div id="CATEGORY_CONTENT">
76 <h1 id="SUPPORTED_FORMATS">SUPPORTED FORMATS </h1><p><a href="#TOP" class="toplink">Top</a></p>
77 <div id="SUPPORTED_FORMATS_CONTENT">
78 <p>The following types are supported:</p>
82 <p>TrueVision Targa (MUST have .tga) </p>
86 <p>Windows Bitmap(.bmp) </p>
90 <p>Portable Anymap (.pnm)
91 .pbm = Portable BitMap (mono)
92 .pgm = Portable GreyMap (256 greys)
93 .ppm = Portable PixMap (full color)</p>
97 <p>X11 Pixmap (.xpm) can be #included directly in code
98 This is NOT the same as XBM(X11 Bitmap) format, which is for monocolor images. </p>
102 <p>GIMP native (.xcf) (XCF = eXperimental Computing Facility?)
103 This format is always changing, and since there's no library supplied by the GIMP project to load XCF, the loader may frequently fail to load much of any image from an XCF file. It's better to load this in GIMP and convert to a better supported image format. </p>
107 <p>ZSoft IBM PC Paintbrush (.pcx) </p>
111 <p>CompuServe Graphics Interchange Format (.gif) </p>
115 <p>Joint Photographic Experts Group JFIF format (.jpg or .jpeg) </p>
119 <p>Tagged Image File Format (.tif or .tiff) </p>
123 <p>Interleaved Bitmap (.lbm or .iff) FORM : ILBM or PBM(packed bitmap)
124 HAM6, HAM8, and 24bit types are not supported. </p>
128 <p>Portable Network Graphics (.png) </p>
140 <h1 id="LOADING_METHODS">LOADING METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
141 <div id="LOADING_METHODS_CONTENT">
144 <h2 id="load">load</h2>
145 <div id="load_CONTENT">
146 <pre> my $surface = SDL::Image::load( $file );
149 <p>$file Image file name to load a surface from. </p>
150 <p>Load file for use as an image in a new <a href="SDL-Surface">SDL::Surface</a>. This actually calls <code>IMG_LoadTyped_RW</code> the binded function to <a href="/SDL-Image.html#load_typed_rw">SDL::Image::load_typed_rw</a>, with the file extension used as the type string. This can load all supported image files, including TGA as long as the filename ends with ".tga". It is best to call this outside of event loops, and rather keep the loaded images around until you are really done with them, as disk speed and image conversion to a surface is not that speedy.
151 Note: If the image format loader requires initialization, it will attempt to do that the first time it is needed if you have not already called <a href="/SDL-Image.html#init">SDL::Image::init</a> to load support for your image format.
152 Note: If the image format supports a transparent pixel, <a href="SDL-Image">SDL::Image</a> will set the colorkey for the surface. You can enable RLE acceleration on the surface afterwards by calling:
153 <a href="/SDL-Video.html#set_color_key">SDL::Video::set_color_key</a></p>
154 <pre> my $image = SDL::Image::load( $some_png_file );
155 SDL::Video::set_color_key($image, SDL_RLEACCEL, $image->format->colorkey);
160 <h3 id="Return">Return</h3>
161 <div id="Return_CONTENT">
162 <p>An image as a <a href="SDL-Surface">SDL::Surface</a>. NULL is returned on errors, such as no support built for the image, or a file reading error. Use <a href="/SDL.html#get_error">SDL::get_error</a> to get cause of error.</p>
165 <h2 id="load_typed_rw">load_typed_rw</h2>
166 <div id="load_typed_rw_CONTENT">
167 <pre> SDL::Image::load_typed_rw($src, $freesrc, $type);
173 <p>The source <a href="SDL-Wops">SDL::RWops</a> as a pointer. The image is loaded from this. </p>
177 <p>A non-zero value mean is will automatically close/free the src for you. Since SDL Perl cannot handle the memory inside this function you would most likely want 1 here.</p>
181 <p>A string that indicates which format type to interpret the image as.</p>
182 <p>Here is a list of the currently recognized strings (case is not important):</p>
185 <dt>"BMP"</dt>
186 <dt>"CUR"</dt>
187 <dt>"GIF"</dt>
188 <dt>"ICO"</dt>
189 <dt>"JPG"</dt>
190 <dt>"LBM"</dt>
191 <dt>"PCX"</dt>
192 <dt>"PNG"</dt>
193 <dt>"PNM"</dt>
194 <dt>"TGA"</dt>
195 <dt>"TIF"</dt>
196 <dt>"XCF"</dt>
197 <dt>"XPM"</dt>
198 <dt>"XV"</dt>
203 <p>Load src for use as a surface. This can load all supported image formats. This method does not guarantee that the format specified by type is the format of the loaded image, except in the case when TGA format is specified (or any other non-magicable format in the future). Using SDL_RWops is not covered here, but they enable you to load from almost any source.
204 Note: If the image format loader requires initialization, it will attempt to do that the first time it is needed if you have not already called <a href="/SDL-Image.html#init">SDL::Image::init</a> to load support for your image format.
205 Note: If the image format supports a transparent pixel, <a href="SDL-Image">SDL::Image</a> will set the colorkey for the surface. You can enable RLE acceleration on the surface afterwards by calling:
206 <a href="/SDL-Video.html#set_color_key">SDL::Video::set_color_key</a></p>
209 <h3 id="Transparency">Transparency </h3>
210 <div id="Transparency_CONTENT">
215 my $file2 = SDL::RWOps->new_file("test/data/menu.png", "rb");
216 my $image = SDL::Image::load_typed_rw($file2, 1, "PNG");
218 SDL::Video::set_color_key($image, SDL_RLEACCEL, $image->format->colorkey);
223 <h3 id="Return-2">Return </h3>
224 <div id="Return_CONTENT-2">
225 <p>The image as a new <a href="SDL-Surface">SDL::Surface</a>. NULL is returned on errors. </p>
228 <h2 id="is_TYPE">is_[TYPE]</h2>
229 <div id="is_TYPE_CONTENT">
230 <p>Test for valid, supported image files:</p>
246 <p>These functions take a <a href="SDL-Ops">SDL::RWOps</a> as a parameter.</p>
249 <h3 id="Return-3">Return</h3>
250 <div id="Return_CONTENT-3">
251 <p>1 if the image is a valid [TYPE] and the [TYPE] format support is compiled into SDL_image. 0 is returned otherwise. </p>
254 <h3 id="Example">Example</h3>
255 <div id="Example_CONTENT">
256 <pre> use SDL::RWOps;
259 my $file = SDL::RWOps->new_file("file", "rb");
261 print "Image is BMP" if ( SDL::is_BMP );
266 <h2 id="load_TYPE_rw">load_[TYPE]_rw</h2>
267 <div id="load_TYPE_rw_CONTENT">
268 <p>Specific loader for known formats:</p>
278 <dt>load_PNM_rw </dt>
284 <p>These functions take a <a href="SDL-Wop">SDL::RWop</a> as a parameter</p>
287 <h3 id="Return-4">Return</h3>
288 <div id="Return_CONTENT-4">
289 <p>The image as a new <a href="SDL-Surface">SDL::Surface</a>. NULL is returned on errors, like if the [TYPE] is not supported, or a read error.</p>
292 <h3 id="Example-2">Example</h3>
293 <div id="Example_CONTENT-2">
298 my $file = SDL::RWOps->new_file("file.png", "rb");
300 my $image = SDL::Image::load_PNG_rw($file);
302 die SDL::get_error if (!$image);
307 <h2 id="read_XPM_from_array">read_XPM_from_array</h2>
308 <div id="read_XPM_from_array_CONTENT">
309 <pre> my $picture = SDL::Image::read_XPM_from_array(\@XPM, $width);
312 <p>This functions takes the reference of an array in the valid @XPM format. Also the $width of the XPM image.</p>
315 <h3 id="Return-5">Return</h3>
316 <div id="Return_CONTENT-5">
317 <p>The image as a new <a href="SDL-Surface">SDL::Surface</a>. NULL is returned on errors, like if XPM is not supported, or a read error. </p>
320 <h3 id="Example-3">Example</h3>
321 <div id="Example_CONTENT-3">
343 ' .@$%&&%$@. ',
344 ' .@*&&&&&&*@. ',
345 ' +$&&&&&&&&$+ ',
346 ' @%&&&&&&&&%@ ',
347 ' #&&&&&&&&&&# ',
348 ' #&&&&&&&&&&# ',
349 ' @%&&&&&&&&%@ ',
350 ' +$&&&&&&&&$+ ',
351 ' .@*&&&&&&*@. ',
352 ' .@$%&&%$@. ',
364 my $picture = SDL::Image::read_XPM_from_array(\@XPM, 30);
369 <h1 id="MISC_METHODS">MISC METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
370 <div id="MISC_METHODS_CONTENT">
373 <h2 id="linked_version">linked_version</h2>
374 <div id="linked_version_CONTENT">
375 <p>Provides the version of linked sdl_image library.</p>
378 <h3 id="Return-6">Return</h3>
379 <div id="Return_CONTENT-6">
380 <p>Returns a <a href="SDL-Version">SDL::Version</a> object</p>
383 <h3 id="Example-4">Example</h3>
384 <div id="Example_CONTENT-4">
385 <pre> my $version = SDL::Image::linked_version();
386 print $version->major.' '.$version->minor.' '.$version->patch;
391 <h2 id="init">init</h2>
392 <div id="init_CONTENT">
393 <p><strong>For version SDL_image 1.2.10 and up</strong></p>
396 <h3 id="Flags">Flags</h3>
397 <div id="Flags_CONTENT">
398 <p>bitwise OR'd set of image formats to support by loading a library now. The values you may OR together to pass in are: </p>
400 <dt>IMG_INIT_JPG </dt>
401 <dt>IMG_INIT_PNG </dt>
402 <dt>IMG_INIT_TIF</dt>
404 <p>Initialize by loading support as indicated by the flags, or at least return success if support is already loaded. You may call this multiple times, which will actually require you to call IMG_Quit just once to clean up. You may call this function with a 0 to retrieve whether support was built-in or not loaded yet.
405 Note: to load JPG, PNG, and/or TIF images you can call IMG_Init with the right IMG_INIT_* flags OR'd together before you program gets busy, to prevent a later hiccup while it loads the library, and to check that you do have the support that you need before you try and use it.
406 Note: No initialization is needed nor performed when using the SDL::Image::is_JPG, SDL::Image::is_PNG, and SDL::Image::is_TIF functions.
407 Note: this function does not always set the error string, so do not depend on SDL::Image::get_error being meaningful all the time. </p>
410 <h3 id="Return-7">Return</h3>
411 <div id="Return_CONTENT-7">
412 <p>A bitmask of all the currently inited image loaders.</p>
415 <h3 id="Example-5">Example</h3>
416 <div id="Example_CONTENT-5">
417 <pre> use SDL::Image;
418 my $flags = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_JPG;
419 my $inited = SDL::Image::init($flags);
424 <h2 id="quit">quit</h2>
425 <div id="quit_CONTENT">
426 <p><strong>For version SDL_image 1.2.10 and up</strong></p>
427 <p>This function cleans up all dynamically loaded library handles, freeing memory. If support is required again it will be initialized again, either by <a href="/SDL-Image.html#init">SDL::Image::init</a> or loading an image with dynamic support required. You may call this function when <a href="/SDL-Image.html#load">SDL::Image::load</a> functions are no longer needed for the JPG, PNG, and TIF image formats. You only need to call this function once, no matter how many times <a href="/SDL-Image.html#init">SDL::Image::init</a> was called. </p>
430 <h3 id="Example-6">Example</h3>
431 <div id="Example_CONTENT-6">
432 <pre> use SDL::Image;
433 SDL::Image::init(IMG_INIT_JPG); #loads JPG support
434 SDL::Image::load("file.png"); #loads PNG support
435 SDL::Image::quit(); #unloads everything
440 <h2 id="set_error">set_error</h2>
441 <div id="set_error_CONTENT">
442 <p>Same as <a href="/SDL.html#set_error">SDL::set_error</a></p>
445 <h2 id="get_error">get_error</h2>
446 <div id="get_error_CONTENT">
447 <p>Same as <a href="/SDL.html#get_error">SDL::get_error</a></p>
450 <h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
451 <div id="SEE_ALSO_CONTENT">
452 <p><a href="SDL">SDL</a>, <a href="SDL-Surface">SDL::Surface</a>, <a href="SDL-Video">SDL::Video</a>, <a href="SDL-Ops">SDL::RWOps</a></p>