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