Added new article
[sdlgit/SDL-Site.git] / pages / SDL-Image.html-inc
index f295dd3..8faed1e 100644 (file)
@@ -4,20 +4,49 @@
 
 <ul><li><a href="#NAME">NAME</a></li>
 <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
-<li><a href="#SUPPORTED_FORMATS">SUPPORTED FORMATS </a></li>
 <li><a href="#CATEGORY">CATEGORY</a></li>
-<li><a href="#METHODS">METHODS</a>
-<ul><li><a href="#load">load</a></li>
-<li><a href="#Returns">Returns</a></li>
-<li><a href="#load_typed_rw">load_typed_rw</a></li>
-<li><a href="#is_TYPE">is_[TYPE]</a></li>
-<li><a href="#load_TYPE_rw">load_[TYPE]_rw</a></li>
-<li><a href="#read_XPM_from_array">read_XPM_from_array</a></li>
-<li><a href="#linked_version">linked_version</a></li>
+<li><a href="#SUPPORTED_FORMATS">SUPPORTED FORMATS </a></li>
+<li><a href="#LOADING_METHODS">LOADING METHODS</a>
+<ul><li><a href="#load">load</a>
+<ul><li><a href="#Return">Return</a></li>
+</ul>
+</li>
+<li><a href="#load_typed_rw">load_typed_rw</a>
+<ul><li><a href="#Transparency">Transparency </a></li>
+<li><a href="#Return-2">Return </a></li>
+</ul>
+</li>
+<li><a href="#is_TYPE">is_[TYPE]</a>
+<ul><li><a href="#Return-3">Return</a></li>
+<li><a href="#Example">Example</a></li>
+</ul>
+</li>
+<li><a href="#load_TYPE_rw">load_[TYPE]_rw</a>
+<ul><li><a href="#Return-4">Return</a></li>
+<li><a href="#Example-2">Example</a></li>
+</ul>
+</li>
+<li><a href="#read_XPM_from_array">read_XPM_from_array</a>
+<ul><li><a href="#Return-5">Return</a></li>
+<li><a href="#Example-3">Example</a></li>
+</ul>
+</li>
+</ul>
+</li>
+<li><a href="#MISC_METHODS">MISC METHODS</a>
+<ul><li><a href="#linked_version">linked_version</a>
+<ul><li><a href="#Return-6">Return</a></li>
+<li><a href="#Example-4">Example</a></li>
+</ul>
+</li>
 <li><a href="#init">init</a>
 <ul><li><a href="#Flags">Flags</a></li>
-<li><a href="#Return">Return</a></li>
-<li><a href="#Example">Example</a></li>
+<li><a href="#Return-7">Return</a></li>
+<li><a href="#Example-5">Example</a></li>
+</ul>
+</li>
+<li><a href="#quit">quit</a>
+<ul><li><a href="#Example-6">Example</a></li>
 </ul>
 </li>
 <li><a href="#set_error">set_error</a></li>
 <p>SDL::Image allows you to load many different format of images into memory as an SDL::Surface.</p>
 
 </div>
+<h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="CATEGORY_CONTENT">
+<p>Image</p>
+
+</div>
 <h1 id="SUPPORTED_FORMATS">SUPPORTED FORMATS </h1><p><a href="#TOP" class="toplink">Top</a></p>
 <div id="SUPPORTED_FORMATS_CONTENT">
 <p>The following types are supported:</p>
@@ -94,16 +128,17 @@ HAM6, HAM8, and 24bit types are not supported. </p>
                <p>Portable Network Graphics (.png) </p>
        </dd>
        <dt>XV</dt>
+       <dt>ICO</dt>
+       <dt>CUR</dt>
 </dl>
 
-</div>
-<h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
-<div id="CATEGORY_CONTENT">
-<p>TODO, SDL, Image</p>
+
+
+
 
 </div>
-<h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
-<div id="METHODS_CONTENT">
+<h1 id="LOADING_METHODS">LOADING METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="LOADING_METHODS_CONTENT">
 
 </div>
 <h2 id="load">load</h2>
@@ -112,40 +147,241 @@ HAM6, HAM8, and 24bit types are not supported. </p>
 
 </pre>
 <p>$file Image file name to load a surface from. </p>
-<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.  
-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.
-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:
-<a href="/SDL-Video::set_color_key.html">SDL::Video::set_color_key</a></p>
+<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.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 &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.  
+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.
+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:
+<a href="/SDL-Video.html#set_color_key">SDL::Video::set_color_key</a></p>
 <pre>  my $image = SDL::Image::load( $some_png_file );
   SDL::Video::set_color_key($image, SDL_RLEACCEL, $image-&gt;format-&gt;colorkey);
 
 </pre>
 
 </div>
-<h2 id="Returns">Returns</h2>
-<div id="Returns_CONTENT">
-<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>
+<h3 id="Return">Return</h3>
+<div id="Return_CONTENT">
+<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.html#get_error">SDL::get_error</a> to get cause of error.</p>
 
 </div>
 <h2 id="load_typed_rw">load_typed_rw</h2>
 <div id="load_typed_rw_CONTENT">
+<pre>  SDL::Image::load_typed_rw($src, $freesrc, $type);
+
+</pre>
+<dl>
+       <dt>src</dt>
+       <dd>
+               <p>The source <a href="SDL-RWops.html">SDL::RWops</a> as a pointer. The image is loaded from this. </p>
+       </dd>
+       <dt>freesrc</dt>
+       <dd>
+               <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>
+       </dd>
+       <dt>type</dt>
+       <dd>
+               <p>A string that indicates which format type to interpret the image as.</p>
+               <p>Here is a list of the currently recognized strings (case is not important):</p>
+               <p>
+                       <dl>
+                               <dt>&quot;BMP&quot;</dt>
+                               <dt>&quot;CUR&quot;</dt>
+                               <dt>&quot;GIF&quot;</dt>
+                               <dt>&quot;ICO&quot;</dt>
+                               <dt>&quot;JPG&quot;</dt>
+                               <dt>&quot;LBM&quot;</dt>
+                               <dt>&quot;PCX&quot;</dt>
+                               <dt>&quot;PNG&quot;</dt>
+                               <dt>&quot;PNM&quot;</dt>
+                               <dt>&quot;TGA&quot;</dt>
+                               <dt>&quot;TIF&quot;</dt>
+                               <dt>&quot;XCF&quot;</dt>
+                               <dt>&quot;XPM&quot;</dt>
+                               <dt>&quot;XV&quot;</dt>
+                       </dl>
+               </p>
+       </dd>
+</dl>
+<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.
+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.
+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:
+<a href="/SDL-Video.html#set_color_key">SDL::Video::set_color_key</a></p>
+
+</div>
+<h3 id="Transparency">Transparency </h3>
+<div id="Transparency_CONTENT">
+<pre>  use SDL;
+  use SDL::RWOps;
+  use SDL::Image;
+
+  my $file2 = SDL::RWOps-&gt;new_file(&quot;test/data/menu.png&quot;, &quot;rb&quot;);
+  my $image = SDL::Image::load_typed_rw($file2, 1, &quot;PNG&quot;);
+
+  SDL::Video::set_color_key($image, SDL_RLEACCEL, $image-&gt;format-&gt;colorkey);
+
+</pre>
+
+</div>
+<h3 id="Return-2">Return </h3>
+<div id="Return_CONTENT-2">
+<p>The image as a new <a href="SDL-Surface.html">SDL::Surface</a>. NULL is returned on errors. </p>
 
 </div>
 <h2 id="is_TYPE">is_[TYPE]</h2>
 <div id="is_TYPE_CONTENT">
+<p>Test for valid, supported image files:</p>
+<dl>
+       <dt>is_ICO</dt>
+       <dt>is_CUR</dt>
+       <dt>is_PNG</dt>
+       <dt>is_BMP</dt>
+       <dt>is_GIF</dt>
+       <dt>is_JPG</dt>
+       <dt>is_LBM</dt>
+       <dt>is_PCX</dt>
+       <dt>is_PNM </dt>
+       <dt>is_TIF</dt>
+       <dt>is_XCF</dt>
+       <dt>is_XPM</dt>
+       <dt>is_XV</dt>
+</dl>
+<p>These functions take a <a href="SDL-RWOps.html">SDL::RWOps</a> as a parameter.</p>
+
+</div>
+<h3 id="Return-3">Return</h3>
+<div id="Return_CONTENT-3">
+<p>1 if the image is a valid [TYPE]  and the [TYPE] format support is compiled into SDL_image. 0 is returned otherwise. </p>
+
+</div>
+<h3 id="Example">Example</h3>
+<div id="Example_CONTENT">
+<pre> use SDL::RWOps;
+ use SDL::Image;
+
+ my $file = SDL::RWOps-&gt;new_file(&quot;file&quot;, &quot;rb&quot;);
+
+ print &quot;Image is BMP&quot; if ( SDL::is_BMP );
+
+</pre>
 
 </div>
 <h2 id="load_TYPE_rw">load_[TYPE]_rw</h2>
 <div id="load_TYPE_rw_CONTENT">
+<p>Specific loader for known formats:</p>
+<dl>
+       <dt>load_ICO_rw</dt>
+       <dt>load_CUR_rw</dt>
+       <dt>load_PNG_rw</dt>
+       <dt>load_BMP_rw</dt>
+       <dt>load_GIF_rw</dt>
+       <dt>load_JPG_rw</dt>
+       <dt>load_LBM_rw</dt>
+       <dt>load_PCX_rw</dt>
+       <dt>load_PNM_rw </dt>
+       <dt>load_TIF_rw</dt>
+       <dt>load_XCF_rw</dt>
+       <dt>load_XPM_rw</dt>
+       <dt>load_XV_rw</dt>
+</dl>
+<p>These functions take a <a href="SDL-RWop.html">SDL::RWop</a> as a parameter</p>
+
+</div>
+<h3 id="Return-4">Return</h3>
+<div id="Return_CONTENT-4">
+<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>
+
+</div>
+<h3 id="Example-2">Example</h3>
+<div id="Example_CONTENT-2">
+<pre> use SDL;
+ use SDL::RWOps;
+ use SDL::Image;
+
+ my $file = SDL::RWOps-&gt;new_file(&quot;file.png&quot;, &quot;rb&quot;);  
+
+ my $image = SDL::Image::load_PNG_rw($file);
+
+ die SDL::get_error if (!$image);  
+
+</pre>
 
 </div>
 <h2 id="read_XPM_from_array">read_XPM_from_array</h2>
 <div id="read_XPM_from_array_CONTENT">
+<pre> my $picture = SDL::Image::read_XPM_from_array(\@XPM, $width);
+
+</pre>
+<p>This functions takes the reference of an array in the valid @XPM format. Also the $width of the XPM image.</p>
+
+</div>
+<h3 id="Return-5">Return</h3>
+<div id="Return_CONTENT-5">
+<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>
+
+</div>
+<h3 id="Example-3">Example</h3>
+<div id="Example_CONTENT-3">
+<pre>  my @XPM= (
+       '30 30 9 1',
+       '       c #FFFFFF',
+       '.      c #EFEFEF',
+       '+      c #CFCFCF',
+       '@      c #9F9F9F',
+       '#      c #808080',
+       '$      c #505050',
+       '%      c #202020',
+       '&amp;  c #000000',
+       '*      c #303030',
+       '                              ',
+       '                              ',
+       '                              ',
+       '                              ',
+       '                              ',
+       '                              ',
+       '                              ',
+       '                              ',
+       '                              ',
+       '           .+@##@+.           ',
+       '          .@$%&amp;&amp;%$@.          ',
+       '         .@*&amp;&amp;&amp;&amp;&amp;&amp;*@.         ',
+       '         +$&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;$+         ',
+       '         @%&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;%@         ',
+       '         #&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;#         ',
+       '         #&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;#         ',
+       '         @%&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;%@         ',
+       '         +$&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;$+         ',
+       '         .@*&amp;&amp;&amp;&amp;&amp;&amp;*@.         ',
+       '          .@$%&amp;&amp;%$@.          ',
+       '           .+@##@+.           ',
+       '                              ',
+       '                              ',
+       '                              ',
+       '                              ',
+       '                              ',
+       '                              ',
+       '                              ',
+       '                              ',
+       '                              ',);
+
+       my $picture = SDL::Image::read_XPM_from_array(\@XPM, 30);
+
+</pre>
+
+</div>
+<h1 id="MISC_METHODS">MISC METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="MISC_METHODS_CONTENT">
 
 </div>
 <h2 id="linked_version">linked_version</h2>
 <div id="linked_version_CONTENT">
-<p>Provides the version of linked sdl_image library. see <a href="/SDL-Version.html">SDL::Version</a></p>
+<p>Provides the version of linked sdl_image library.</p>
+
+</div>
+<h3 id="Return-6">Return</h3>
+<div id="Return_CONTENT-6">
+<p>Returns a <a href="SDL-Version.html">SDL::Version</a> object</p>
+
+</div>
+<h3 id="Example-4">Example</h3>
+<div id="Example_CONTENT-4">
 <pre>  my $version = SDL::Image::linked_version();
        print $version-&gt;major.' '.$version-&gt;minor.' '.$version-&gt;patch;
 
@@ -156,13 +392,6 @@ Note: If the image format supports a transparent pixel, <a href="/SDL-Image.html
 <div id="init_CONTENT">
 <p><strong>For version SDL_image 1.2.10 and up</strong></p>
 
-
-
-
-
-
-
-
 </div>
 <h3 id="Flags">Flags</h3>
 <div id="Flags_CONTENT">
@@ -178,13 +407,13 @@ Note: No initialization is needed nor performed when using the SDL::Image::is_JP
 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>
 
 </div>
-<h3 id="Return">Return</h3>
-<div id="Return_CONTENT">
-<p>A bitmask of all the currentl initted image loaders.</p>
+<h3 id="Return-7">Return</h3>
+<div id="Return_CONTENT-7">
+<p>A bitmask of all the currently inited image loaders.</p>
 
 </div>
-<h3 id="Example">Example</h3>
-<div id="Example_CONTENT">
+<h3 id="Example-5">Example</h3>
+<div id="Example_CONTENT-5">
 <pre>  use SDL::Image;
   my $flags = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_JPG;
   my $inited = SDL::Image::init($flags);
@@ -192,17 +421,35 @@ Note: this function does not always set the error string, so do not depend on SD
 </pre>
 
 </div>
+<h2 id="quit">quit</h2>
+<div id="quit_CONTENT">
+<p><strong>For version SDL_image 1.2.10 and up</strong></p>
+<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>
+
+</div>
+<h3 id="Example-6">Example</h3>
+<div id="Example_CONTENT-6">
+<pre> use SDL::Image;
+ SDL::Image::init(IMG_INIT_JPG); #loads JPG support
+ SDL::Image::load(&quot;file.png&quot;); #loads PNG support
+ SDL::Image::quit(); #unloads everything
+
+</pre>
+
+</div>
 <h2 id="set_error">set_error</h2>
 <div id="set_error_CONTENT">
+<p>Same as <a href="/SDL.html#set_error">SDL::set_error</a></p>
 
 </div>
 <h2 id="get_error">get_error</h2>
 <div id="get_error_CONTENT">
+<p>Same as <a href="/SDL.html#get_error">SDL::get_error</a></p>
 
 </div>
 <h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
 <div id="SEE_ALSO_CONTENT">
-<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>
+<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>
 
 </div>
 </div>
\ No newline at end of file