update for SDL::Event
[sdlgit/SDL-Site.git] / pages / SDL-Image.html-inc
CommitLineData
944366c3 1<div class="pod">
2<!-- INDEX START -->
3<h3 id="TOP">Index</h3>
4
5<ul><li><a href="#NAME">NAME</a></li>
6<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
944366c3 7<li><a href="#CATEGORY">CATEGORY</a></li>
5241ab5e 8<li><a href="#SUPPORTED_FORMATS">SUPPORTED FORMATS </a></li>
9<li><a href="#LOADING_METHODS">LOADING METHODS</a>
4e9f9db6 10<ul><li><a href="#load">load</a>
11<ul><li><a href="#Return">Return</a></li>
12</ul>
13</li>
5241ab5e 14<li><a href="#load_typed_rw">load_typed_rw</a>
001e1287 15<ul><li><a href="#Transparency">Transparency </a></li>
4e9f9db6 16<li><a href="#Return-2">Return </a></li>
5241ab5e 17</ul>
18</li>
19<li><a href="#is_TYPE">is_[TYPE]</a>
4e9f9db6 20<ul><li><a href="#Return-3">Return</a></li>
001e1287 21<li><a href="#Example">Example</a></li>
5241ab5e 22</ul>
23</li>
24<li><a href="#load_TYPE_rw">load_[TYPE]_rw</a>
4e9f9db6 25<ul><li><a href="#Return-4">Return</a></li>
001e1287 26<li><a href="#Example-2">Example</a></li>
5241ab5e 27</ul>
28</li>
29<li><a href="#read_XPM_from_array">read_XPM_from_array</a>
4e9f9db6 30<ul><li><a href="#Return-5">Return</a></li>
001e1287 31<li><a href="#Example-3">Example</a></li>
5241ab5e 32</ul>
33</li>
34</ul>
35</li>
36<li><a href="#MISC_METHODS">MISC METHODS</a>
4e9f9db6 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>
40</ul>
41</li>
944366c3 42<li><a href="#init">init</a>
43<ul><li><a href="#Flags">Flags</a></li>
4e9f9db6 44<li><a href="#Return-7">Return</a></li>
45<li><a href="#Example-5">Example</a></li>
001e1287 46</ul>
47</li>
48<li><a href="#quit">quit</a>
4e9f9db6 49<ul><li><a href="#Example-6">Example</a></li>
944366c3 50</ul>
51</li>
52<li><a href="#set_error">set_error</a></li>
37dfe383 53<li><a href="#get_error">get_error</a></li>
944366c3 54</ul>
55</li>
c7e8d3c6 56<li><a href="#SEE_ALSO">SEE ALSO</a></li>
57<li><a href="#AUTHORS">AUTHORS</a>
37dfe383 58</li>
944366c3 59</ul><hr />
60<!-- INDEX END -->
61
62<h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
63<div id="NAME_CONTENT">
64<p>SDL::Image - Bindings for the SDL_Image library</p>
65
66</div>
67<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
68<div id="DESCRIPTION_CONTENT">
69<p>SDL::Image allows you to load many different format of images into memory as an SDL::Surface.</p>
70
71</div>
5241ab5e 72<h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
73<div id="CATEGORY_CONTENT">
2672acfc 74<p>Image</p>
5241ab5e 75
76</div>
944366c3 77<h1 id="SUPPORTED_FORMATS">SUPPORTED FORMATS </h1><p><a href="#TOP" class="toplink">Top</a></p>
78<div id="SUPPORTED_FORMATS_CONTENT">
79<p>The following types are supported:</p>
80<dl>
37dfe383 81 <dt>TGA</dt>
82 <dd>
83 <p>TrueVision Targa (MUST have .tga) </p>
84 </dd>
85 <dt>BMP</dt>
86 <dd>
87 <p>Windows Bitmap(.bmp) </p>
88 </dd>
89 <dt>PNM</dt>
90 <dd>
91 <p>Portable Anymap (.pnm)
92.pbm = Portable BitMap (mono)
93.pgm = Portable GreyMap (256 greys)
94.ppm = Portable PixMap (full color)</p>
95 </dd>
96 <dt>XPM</dt>
97 <dd>
98 <p>X11 Pixmap (.xpm) can be #included directly in code
99This is NOT the same as XBM(X11 Bitmap) format, which is for monocolor images. </p>
100 </dd>
101 <dt>XCF</dt>
102 <dd>
103 <p>GIMP native (.xcf) (XCF = eXperimental Computing Facility?)
104This 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>
105 </dd>
106 <dt>PCX</dt>
107 <dd>
108 <p>ZSoft IBM PC Paintbrush (.pcx) </p>
109 </dd>
110 <dt>GIF</dt>
111 <dd>
112 <p>CompuServe Graphics Interchange Format (.gif) </p>
113 </dd>
114 <dt>JPG</dt>
115 <dd>
116 <p>Joint Photographic Experts Group JFIF format (.jpg or .jpeg) </p>
117 </dd>
118 <dt>TIF</dt>
119 <dd>
120 <p>Tagged Image File Format (.tif or .tiff) </p>
121 </dd>
122 <dt>LBM</dt>
123 <dd>
124 <p>Interleaved Bitmap (.lbm or .iff) FORM : ILBM or PBM(packed bitmap)
125HAM6, HAM8, and 24bit types are not supported. </p>
126 </dd>
127 <dt>PNG</dt>
128 <dd>
129 <p>Portable Network Graphics (.png) </p>
130 </dd>
131 <dt>XV</dt>
5241ab5e 132 <dt>ICO</dt>
133 <dt>CUR</dt>
944366c3 134</dl>
135
5241ab5e 136
137
138
944366c3 139
140</div>
5241ab5e 141<h1 id="LOADING_METHODS">LOADING METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
142<div id="LOADING_METHODS_CONTENT">
944366c3 143
144</div>
145<h2 id="load">load</h2>
146<div id="load_CONTENT">
147<pre> my $surface = SDL::Image::load( $file );
148
149</pre>
150<p>$file Image file name to load a surface from. </p>
0b221bb4 151<p>Load file for use as an image in a new <a href="SDL-Surface.html">SDL::Surface</a>. This actually calls <code>IMG_LoadTyped_RW</code> the binded function to <a href="SDL-Image::load_typed_rw.html">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 &quot;.tga&quot;. 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.
152Note: 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::init.html">SDL::Image::init</a> to load support for your image format.
55bbf7a2 153Note: If the image format supports a transparent pixel, <a href="SDL-Image.html">SDL::Image</a> will set the colorkey for the surface. You can enable RLE acceleration on the surface afterwards by calling:
0b221bb4 154<a href="SDL-Video::set_color_key.html">SDL::Video::set_color_key</a></p>
37dfe383 155<pre> my $image = SDL::Image::load( $some_png_file );
156 SDL::Video::set_color_key($image, SDL_RLEACCEL, $image-&gt;format-&gt;colorkey);
944366c3 157
37dfe383 158</pre>
944366c3 159
160</div>
4e9f9db6 161<h3 id="Return">Return</h3>
162<div id="Return_CONTENT">
0b221bb4 163<p>An image as a <a href="SDL-Surface.html">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::get_error.html">SDL::get_error</a> to get cause of error.</p>
944366c3 164
165</div>
166<h2 id="load_typed_rw">load_typed_rw</h2>
167<div id="load_typed_rw_CONTENT">
5241ab5e 168<pre> SDL::Image::load_typed_rw($src, $freesrc, $type);
169
170</pre>
171<dl>
172 <dt>src</dt>
173 <dd>
55bbf7a2 174 <p>The source <a href="SDL-RWops.html">SDL::RWops</a> as a pointer. The image is loaded from this. </p>
5241ab5e 175 </dd>
176 <dt>freesrc</dt>
177 <dd>
178 <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>
179 </dd>
180 <dt>type</dt>
181 <dd>
182 <p>A string that indicates which format type to interpret the image as.</p>
183 <p>Here is a list of the currently recognized strings (case is not important):</p>
184 <p>
185 <dl>
186 <dt>&quot;BMP&quot;</dt>
187 <dt>&quot;CUR&quot;</dt>
188 <dt>&quot;GIF&quot;</dt>
189 <dt>&quot;ICO&quot;</dt>
190 <dt>&quot;JPG&quot;</dt>
191 <dt>&quot;LBM&quot;</dt>
192 <dt>&quot;PCX&quot;</dt>
193 <dt>&quot;PNG&quot;</dt>
194 <dt>&quot;PNM&quot;</dt>
195 <dt>&quot;TGA&quot;</dt>
196 <dt>&quot;TIF&quot;</dt>
197 <dt>&quot;XCF&quot;</dt>
198 <dt>&quot;XPM&quot;</dt>
199 <dt>&quot;XV&quot;</dt>
200 </dl>
201 </p>
202 </dd>
203</dl>
204<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.
0b221bb4 205Note: 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::init.html">SDL::Image::init</a> to load support for your image format.
55bbf7a2 206Note: If the image format supports a transparent pixel, <a href="SDL-Image.html">SDL::Image</a> will set the colorkey for the surface. You can enable RLE acceleration on the surface afterwards by calling:
0b221bb4 207<a href="SDL-Video::set_color_key.html">SDL::Video::set_color_key</a></p>
001e1287 208
209</div>
210<h3 id="Transparency">Transparency </h3>
211<div id="Transparency_CONTENT">
5241ab5e 212<pre> use SDL;
213 use SDL::RWOps;
214 use SDL::Image;
215
216 my $file2 = SDL::RWOps-&gt;new_file(&quot;test/data/menu.png&quot;, &quot;rb&quot;);
217 my $image = SDL::Image::load_typed_rw($file2, 1, &quot;PNG&quot;);
218
219 SDL::Video::set_color_key($image, SDL_RLEACCEL, $image-&gt;format-&gt;colorkey);
220
221</pre>
222
223</div>
4e9f9db6 224<h3 id="Return-2">Return </h3>
225<div id="Return_CONTENT-2">
55bbf7a2 226<p>The image as a new <a href="SDL-Surface.html">SDL::Surface</a>. NULL is returned on errors. </p>
944366c3 227
228</div>
229<h2 id="is_TYPE">is_[TYPE]</h2>
230<div id="is_TYPE_CONTENT">
5241ab5e 231<p>Test for valid, supported image files:</p>
232<dl>
233 <dt>is_ICO</dt>
234 <dt>is_CUR</dt>
235 <dt>is_PNG</dt>
236 <dt>is_BMP</dt>
237 <dt>is_GIF</dt>
238 <dt>is_JPG</dt>
239 <dt>is_LBM</dt>
240 <dt>is_PCX</dt>
241 <dt>is_PNM </dt>
242 <dt>is_TIF</dt>
243 <dt>is_XCF</dt>
244 <dt>is_XPM</dt>
245 <dt>is_XV</dt>
246</dl>
55bbf7a2 247<p>These functions take a <a href="SDL-RWOps.html">SDL::RWOps</a> as a parameter.</p>
001e1287 248
249</div>
4e9f9db6 250<h3 id="Return-3">Return</h3>
251<div id="Return_CONTENT-3">
001e1287 252<p>1 if the image is a valid [TYPE] and the [TYPE] format support is compiled into SDL_image. 0 is returned otherwise. </p>
253
254</div>
255<h3 id="Example">Example</h3>
256<div id="Example_CONTENT">
5241ab5e 257<pre> use SDL::RWOps;
258 use SDL::Image;
259
260 my $file = SDL::RWOps-&gt;new_file(&quot;file&quot;, &quot;rb&quot;);
261
262 print &quot;Image is BMP&quot; if ( SDL::is_BMP );
263
5241ab5e 264</pre>
265
266</div>
944366c3 267<h2 id="load_TYPE_rw">load_[TYPE]_rw</h2>
268<div id="load_TYPE_rw_CONTENT">
5241ab5e 269<p>Specific loader for known formats:</p>
270<dl>
271 <dt>load_ICO_rw</dt>
272 <dt>load_CUR_rw</dt>
273 <dt>load_PNG_rw</dt>
274 <dt>load_BMP_rw</dt>
275 <dt>load_GIF_rw</dt>
276 <dt>load_JPG_rw</dt>
277 <dt>load_LBM_rw</dt>
278 <dt>load_PCX_rw</dt>
279 <dt>load_PNM_rw </dt>
280 <dt>load_TIF_rw</dt>
281 <dt>load_XCF_rw</dt>
282 <dt>load_XPM_rw</dt>
283 <dt>load_XV_rw</dt>
284</dl>
55bbf7a2 285<p>These functions take a <a href="SDL-RWop.html">SDL::RWop</a> as a parameter</p>
5241ab5e 286
287</div>
4e9f9db6 288<h3 id="Return-4">Return</h3>
289<div id="Return_CONTENT-4">
55bbf7a2 290<p>The image as a new <a href="SDL-Surface.html">SDL::Surface</a>. NULL is returned on errors, like if the [TYPE] is not supported, or a read error.</p>
5241ab5e 291
292</div>
001e1287 293<h3 id="Example-2">Example</h3>
294<div id="Example_CONTENT-2">
5241ab5e 295<pre> use SDL;
296 use SDL::RWOps;
297 use SDL::Image;
298
299 my $file = SDL::RWOps-&gt;new_file(&quot;file.png&quot;, &quot;rb&quot;);
300
301 my $image = SDL::Image::load_PNG_rw($file);
302
303 die SDL::get_error if (!$image);
304
305</pre>
944366c3 306
307</div>
308<h2 id="read_XPM_from_array">read_XPM_from_array</h2>
309<div id="read_XPM_from_array_CONTENT">
5241ab5e 310<pre> my $picture = SDL::Image::read_XPM_from_array(\@XPM, $width);
311
312</pre>
313<p>This functions takes the reference of an array in the valid @XPM format. Also the $width of the XPM image.</p>
314
315</div>
4e9f9db6 316<h3 id="Return-5">Return</h3>
317<div id="Return_CONTENT-5">
55bbf7a2 318<p>The image as a new <a href="SDL-Surface.html">SDL::Surface</a>. NULL is returned on errors, like if XPM is not supported, or a read error. </p>
5241ab5e 319
320</div>
001e1287 321<h3 id="Example-3">Example</h3>
322<div id="Example_CONTENT-3">
5241ab5e 323<pre> my @XPM= (
324 '30 30 9 1',
325 ' c #FFFFFF',
326 '. c #EFEFEF',
327 '+ c #CFCFCF',
328 '@ c #9F9F9F',
329 '# c #808080',
330 '$ c #505050',
331 '% c #202020',
332 '&amp; c #000000',
333 '* c #303030',
334 ' ',
335 ' ',
336 ' ',
337 ' ',
338 ' ',
339 ' ',
340 ' ',
341 ' ',
342 ' ',
343 ' .+@##@+. ',
344 ' .@$%&amp;&amp;%$@. ',
345 ' .@*&amp;&amp;&amp;&amp;&amp;&amp;*@. ',
346 ' +$&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;$+ ',
347 ' @%&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;%@ ',
348 ' #&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;# ',
349 ' #&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;# ',
350 ' @%&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;%@ ',
351 ' +$&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;$+ ',
352 ' .@*&amp;&amp;&amp;&amp;&amp;&amp;*@. ',
353 ' .@$%&amp;&amp;%$@. ',
354 ' .+@##@+. ',
355 ' ',
356 ' ',
357 ' ',
358 ' ',
359 ' ',
360 ' ',
361 ' ',
362 ' ',
363 ' ',);
364
365 my $picture = SDL::Image::read_XPM_from_array(\@XPM, 30);
366
367</pre>
368
369</div>
370<h1 id="MISC_METHODS">MISC METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
371<div id="MISC_METHODS_CONTENT">
944366c3 372
373</div>
374<h2 id="linked_version">linked_version</h2>
375<div id="linked_version_CONTENT">
4e9f9db6 376<p>Provides the version of linked sdl_image library.</p>
377
378</div>
379<h3 id="Return-6">Return</h3>
380<div id="Return_CONTENT-6">
55bbf7a2 381<p>Returns a <a href="SDL-Version.html">SDL::Version</a> object</p>
4e9f9db6 382
383</div>
384<h3 id="Example-4">Example</h3>
385<div id="Example_CONTENT-4">
944366c3 386<pre> my $version = SDL::Image::linked_version();
387 print $version-&gt;major.' '.$version-&gt;minor.' '.$version-&gt;patch;
388
389</pre>
390
391</div>
392<h2 id="init">init</h2>
393<div id="init_CONTENT">
394<p><strong>For version SDL_image 1.2.10 and up</strong></p>
395
944366c3 396</div>
397<h3 id="Flags">Flags</h3>
398<div id="Flags_CONTENT">
399<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<dl>
37dfe383 401 <dt>IMG_INIT_JPG </dt>
402 <dt>IMG_INIT_PNG </dt>
403 <dt>IMG_INIT_TIF</dt>
944366c3 404</dl>
405<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.
406Note: 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.
407Note: No initialization is needed nor performed when using the SDL::Image::is_JPG, SDL::Image::is_PNG, and SDL::Image::is_TIF functions.
408Note: this function does not always set the error string, so do not depend on SDL::Image::get_error being meaningful all the time. </p>
409
410</div>
4e9f9db6 411<h3 id="Return-7">Return</h3>
412<div id="Return_CONTENT-7">
5241ab5e 413<p>A bitmask of all the currently inited image loaders.</p>
944366c3 414
415</div>
4e9f9db6 416<h3 id="Example-5">Example</h3>
417<div id="Example_CONTENT-5">
944366c3 418<pre> use SDL::Image;
419 my $flags = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_JPG;
420 my $inited = SDL::Image::init($flags);
421
944366c3 422</pre>
423
424</div>
5241ab5e 425<h2 id="quit">quit</h2>
426<div id="quit_CONTENT">
427<p><strong>For version SDL_image 1.2.10 and up</strong></p>
0b221bb4 428<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::init.html">SDL::Image::init</a> or loading an image with dynamic support required. You may call this function when <a href="SDL-Image::load.html">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::init.html">SDL::Image::init</a> was called. </p>
001e1287 429
430</div>
4e9f9db6 431<h3 id="Example-6">Example</h3>
432<div id="Example_CONTENT-6">
5241ab5e 433<pre> use SDL::Image;
434 SDL::Image::init(IMG_INIT_JPG); #loads JPG support
435 SDL::Image::load(&quot;file.png&quot;); #loads PNG support
436 SDL::Image::quit(); #unloads everything
437
438</pre>
439
440</div>
944366c3 441<h2 id="set_error">set_error</h2>
442<div id="set_error_CONTENT">
0b221bb4 443<p>Same as <a href="SDL::set_error.html">SDL::set_error</a></p>
944366c3 444
445</div>
446<h2 id="get_error">get_error</h2>
447<div id="get_error_CONTENT">
0b221bb4 448<p>Same as <a href="SDL::get_error.html">SDL::get_error</a></p>
944366c3 449
450</div>
37dfe383 451<h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
452<div id="SEE_ALSO_CONTENT">
55bbf7a2 453<p><a href="SDL.html">SDL</a>, <a href="SDL-Surface.html">SDL::Surface</a>, <a href="SDL-Video.html">SDL::Video</a>, <a href="SDL-RWOps.html">SDL::RWOps</a></p>
37dfe383 454
455</div>
c7e8d3c6 456<h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
457<div id="AUTHORS_CONTENT">
458<p>See <b>AUTHORS</b> in <cite>SDL</cite>.</p>
459
460</div>
944366c3 461</div>