/lib/pods/SDL/Image.pod

http://github.com/PerlGameDev/SDL · Unknown · 433 lines · 254 code · 179 blank · 0 comment · 0 complexity · 4f96b068d486e712e1d45f4688ae62ac MD5 · raw file

  1. =pod
  2. =head1 NAME
  3. SDL::Image - Bindings for the SDL_Image library
  4. =head1 DESCRIPTION
  5. SDL::Image allows you to load many different format of images into memory as an SDL::Surface.
  6. =head1 CATEGORY
  7. Image
  8. =head1 SUPPORTED FORMATS
  9. The following types are supported:
  10. =over
  11. =item TGA
  12. TrueVision Targa (MUST have .tga)
  13. =item BMP
  14. Windows Bitmap(.bmp)
  15. =item PNM
  16. Portable Anymap (.pnm)
  17. .pbm = Portable BitMap (mono)
  18. .pgm = Portable GreyMap (256 greys)
  19. .ppm = Portable PixMap (full color)
  20. =item XPM
  21. X11 Pixmap (.xpm) can be #included directly in code
  22. This is NOT the same as XBM(X11 Bitmap) format, which is for monocolor images.
  23. =item XCF
  24. GIMP native (.xcf) (XCF = eXperimental Computing Facility?)
  25. 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
  26. of any image from an XCF file. It's better to load this in GIMP and convert to a better supported image format.
  27. =item PCX
  28. ZSoft IBM PC Paintbrush (.pcx)
  29. =item GIF
  30. CompuServe Graphics Interchange Format (.gif)
  31. =item JPG
  32. Joint Photographic Experts Group JFIF format (.jpg or .jpeg)
  33. =item TIF
  34. Tagged Image File Format (.tif or .tiff)
  35. =item LBM
  36. Interleaved Bitmap (.lbm or .iff) FORM : ILBM or PBM(packed bitmap), HAM6, HAM8, and 24bit types are not supported.
  37. =item PNG
  38. Portable Network Graphics (.png)
  39. =item XV
  40. =item ICO
  41. =item CUR
  42. =back
  43. =head1 LOADING METHODS
  44. =head2 load
  45. my $surface = SDL::Image::load( $file );
  46. $file Image file name to load a surface from.
  47. Load file for use as an image in a new L<SDL::Surface>. This actually calls L<SDL::Image::load_typed_rw|SDL::Image/"load_typed_rw">, with the
  48. 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
  49. 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
  50. conversion to a surface is not that speedy.
  51. B<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
  52. L<SDL::Image::init|SDL::Image/"init"> to load support for your image format.
  53. B<Note>: If the image format supports a transparent pixel, L<SDL::Image> will set the colorkey for the surface. You can enable RLE acceleration on
  54. the surface afterwards by calling:
  55. L<SDL::Video::set_color_key|SDL::Video/"set_color_key">
  56. my $image = SDL::Image::load( $some_png_file );
  57. SDL::Video::set_color_key($image, SDL_RLEACCEL, $image->format->colorkey);
  58. =head3 Return
  59. An image as a L<SDL::Surface>. NULL is returned on errors, such as no support built for the image, or a file reading error. Use
  60. L<SDL::get_error|SDL/"get_error"> to get cause of error.
  61. =head2 load_typed_rw
  62. SDL::Image::load_typed_rw($src, $freesrc, $type);
  63. =over
  64. =item src
  65. The source L<SDL::RWops> as a pointer. The image is loaded from this.
  66. =item freesrc
  67. 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
  68. likely want 1 here.
  69. =item type
  70. A string that indicates which format type to interpret the image as.
  71. Here is a list of the currently recognized strings (case is not important):
  72. =over
  73. =item "BMP"
  74. =item "CUR"
  75. =item "GIF"
  76. =item "ICO"
  77. =item "JPG"
  78. =item "LBM"
  79. =item "PCX"
  80. =item "PNG"
  81. =item "PNM"
  82. =item "TGA"
  83. =item "TIF"
  84. =item "XCF"
  85. =item "XPM"
  86. =item "XV"
  87. =back
  88. =back
  89. 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
  90. 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
  91. not covered here, but they enable you to load from almost any source.
  92. B<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
  93. L<SDL::Image::init|SDL::Image/"init"> to load support for your image format.
  94. B<Note>: If the image format supports a transparent pixel, L<SDL::Image> will set the colorkey for the surface. You can enable RLE acceleration on
  95. the surface afterwards by calling: L<SDL::Video::set_color_key|SDL::Video/"set_color_key">
  96. =head3 Transparency
  97. use SDL;
  98. use SDL::RWOps;
  99. use SDL::Image;
  100. my $file2 = SDL::RWOps->new_file("test/data/menu.png", "rb");
  101. my $image = SDL::Image::load_typed_rw($file2, 1, "PNG");
  102. SDL::Video::set_color_key($image, SDL_RLEACCEL, $image->format->colorkey);
  103. =head3 Return
  104. The image as a new L<SDL::Surface>. NULL is returned on errors.
  105. =head2 is_[TYPE]
  106. Test for valid, supported image files:
  107. =over
  108. =item is_ICO
  109. =item is_CUR
  110. =item is_PNG
  111. =item is_BMP
  112. =item is_GIF
  113. =item is_JPG
  114. =item is_LBM
  115. =item is_PCX
  116. =item is_PNM
  117. =item is_TIF
  118. =item is_XCF
  119. =item is_XPM
  120. =item is_XV
  121. =back
  122. These functions take a L<SDL::RWOps> as a parameter.
  123. =head3 Return
  124. 1 if the image is a valid [TYPE] and the [TYPE] format support is compiled into SDL_image. 0 is returned otherwise.
  125. =head3 Example
  126. use SDL::RWOps;
  127. use SDL::Image;
  128. my $file = SDL::RWOps->new_file("file", "rb");
  129. print "Image is BMP" if ( SDL::is_BMP );
  130. =head2 load_[TYPE]_rw
  131. Specific loader for known formats:
  132. =over
  133. =item load_ICO_rw
  134. =item load_CUR_rw
  135. =item load_PNG_rw
  136. =item load_BMP_rw
  137. =item load_GIF_rw
  138. =item load_JPG_rw
  139. =item load_LBM_rw
  140. =item load_PCX_rw
  141. =item load_PNM_rw
  142. =item load_TIF_rw
  143. =item load_XCF_rw
  144. =item load_XPM_rw
  145. =item load_XV_rw
  146. =back
  147. These functions take a L<SDL::RWop> as a parameter
  148. =head3 Return
  149. The image as a new L<SDL::Surface>. NULL is returned on errors, like if the [TYPE] is not supported, or a read error.
  150. =head3 Example
  151. use SDL;
  152. use SDL::RWOps;
  153. use SDL::Image;
  154. my $file = SDL::RWOps->new_file("file.png", "rb");
  155. my $image = SDL::Image::load_PNG_rw($file);
  156. die SDL::get_error if (!$image);
  157. =head2 read_XPM_from_array
  158. my $picture = SDL::Image::read_XPM_from_array(\@XPM, $width);
  159. This functions takes the reference of an array in the valid @XPM format. Also the $width of the XPM image.
  160. =head3 Return
  161. The image as a new L<SDL::Surface>. NULL is returned on errors, like if XPM is not supported, or a read error.
  162. =head3 Example
  163. my @XPM= (
  164. '30 30 9 1',
  165. ' c #FFFFFF',
  166. '. c #EFEFEF',
  167. '+ c #CFCFCF',
  168. '@ c #9F9F9F',
  169. '# c #808080',
  170. '$ c #505050',
  171. '% c #202020',
  172. '& c #000000',
  173. '* c #303030',
  174. ' ',
  175. ' ',
  176. ' ',
  177. ' ',
  178. ' ',
  179. ' ',
  180. ' ',
  181. ' ',
  182. ' ',
  183. ' .+@##@+. ',
  184. ' .@$%&&%$@. ',
  185. ' .@*&&&&&&*@. ',
  186. ' +$&&&&&&&&$+ ',
  187. ' @%&&&&&&&&%@ ',
  188. ' #&&&&&&&&&&# ',
  189. ' #&&&&&&&&&&# ',
  190. ' @%&&&&&&&&%@ ',
  191. ' +$&&&&&&&&$+ ',
  192. ' .@*&&&&&&*@. ',
  193. ' .@$%&&%$@. ',
  194. ' .+@##@+. ',
  195. ' ',
  196. ' ',
  197. ' ',
  198. ' ',
  199. ' ',
  200. ' ',
  201. ' ',
  202. ' ',
  203. ' ',);
  204. my $picture = SDL::Image::read_XPM_from_array(\@XPM, 30);
  205. =head1 MISC METHODS
  206. =head2 linked_version
  207. Provides the version of linked sdl_image library.
  208. =head3 Return
  209. Returns a L<SDL::Version> object
  210. =head3 Example
  211. my $version = SDL::Image::linked_version();
  212. print $version->major.' '.$version->minor.' '.$version->patch;
  213. =head2 init
  214. B<For version SDL_image 1.2.10 and up>
  215. =head3 Flags
  216. bitwise OR'd set of image formats to support by loading a library now. The values you may OR together to pass in are:
  217. =over
  218. =item IMG_INIT_JPG
  219. =item IMG_INIT_PNG
  220. =item IMG_INIT_TIF
  221. =back
  222. 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,
  223. 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
  224. or not loaded yet.
  225. B<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
  226. 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.
  227. B<Note>: No initialization is needed nor performed when using the SDL::Image::is_JPG, SDL::Image::is_PNG, and SDL::Image::is_TIF functions.
  228. B<Note>: this function does not always set the error string, so do not depend on SDL::Image::get_error being meaningful all the time.
  229. =head3 Return
  230. A bitmask of all the currently inited image loaders.
  231. =head3 Example
  232. use SDL::Image;
  233. my $flags = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_JPG;
  234. my $inited = SDL::Image::init($flags);
  235. =head2 quit
  236. B<For version SDL_image 1.2.10 and up>
  237. This function cleans up all dynamically loaded library handles, freeing memory. If support is required again it will be initialized again, either
  238. by L<SDL::Image::init|SDL::Image/"init"> or loading an image with dynamic support required. You may call this function when
  239. L<SDL::Image::load|SDL::Image/"load"> functions are no longer needed for the JPG, PNG, and TIF image formats. You only need to call this function
  240. once, no matter how many times L<SDL::Image::init|SDL::Image/"init"> was called.
  241. =head3 Example
  242. use SDL::Image;
  243. SDL::Image::init(IMG_INIT_JPG); #loads JPG support
  244. SDL::Image::load("file.png"); #loads PNG support
  245. SDL::Image::quit(); #unloads everything
  246. =head2 set_error
  247. Same as L<SDL::set_error|SDL/"set_error">
  248. =head2 get_error
  249. Same as L<SDL::get_error|SDL/"get_error">
  250. =head1 SEE ALSO
  251. L<SDL>, L<SDL::Surface>, L<SDL::Video>, L<SDL::RWOps>
  252. =head1 AUTHORS
  253. See L<SDL/AUTHORS>.
  254. =cut