sdl_image.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. unit sdl_image;
  2. {
  3. $Id: sdl_image.pas,v 1.14 2007/05/29 21:31:13 savage Exp $
  4. }
  5. {******************************************************************************}
  6. { }
  7. { Borland Delphi SDL_Image - An example image loading library for use }
  8. { with SDL }
  9. { Conversion of the Simple DirectMedia Layer Image Headers }
  10. { }
  11. { Portions created by Sam Lantinga <[email protected]> are }
  12. { Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga }
  13. { 5635-34 Springhouse Dr. }
  14. { Pleasanton, CA 94588 (USA) }
  15. { }
  16. { All Rights Reserved. }
  17. { }
  18. { The original files are : SDL_image.h }
  19. { }
  20. { The initial developer of this Pascal code was : }
  21. { Matthias Thoma <[email protected]> }
  22. { }
  23. { Portions created by Matthias Thoma are }
  24. { Copyright (C) 2000 - 2001 Matthias Thoma. }
  25. { }
  26. { }
  27. { Contributor(s) }
  28. { -------------- }
  29. { Dominique Louis <[email protected]> }
  30. { }
  31. { Obtained through: }
  32. { Joint Endeavour of Delphi Innovators ( Project JEDI ) }
  33. { }
  34. { You may retrieve the latest version of this file at the Project }
  35. { JEDI home page, located at http://delphi-jedi.org }
  36. { }
  37. { The contents of this file are used with permission, subject to }
  38. { the Mozilla Public License Version 1.1 (the "License"); you may }
  39. { not use this file except in compliance with the License. You may }
  40. { obtain a copy of the License at }
  41. { http://www.mozilla.org/MPL/MPL-1.1.html }
  42. { }
  43. { Software distributed under the License is distributed on an }
  44. { "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
  45. { implied. See the License for the specific language governing }
  46. { rights and limitations under the License. }
  47. { }
  48. { Description }
  49. { ----------- }
  50. { A simple library to load images of various formats as SDL surfaces }
  51. { }
  52. { Requires }
  53. { -------- }
  54. { SDL.pas in your search path. }
  55. { }
  56. { Programming Notes }
  57. { ----------------- }
  58. { See the Aliens Demo on how to make use of this libaray }
  59. { }
  60. { Revision History }
  61. { ---------------- }
  62. { April 02 2001 - MT : Initial Translation }
  63. { }
  64. { May 08 2001 - DL : Added ExternalSym derectives and copyright header }
  65. { }
  66. { April 03 2003 - DL : Added jedi-sdl.inc include file to support more }
  67. { Pascal compilers. Initial support is now included }
  68. { for GnuPascal, VirtualPascal, TMT and obviously }
  69. { continue support for Delphi Kylix and FreePascal. }
  70. { }
  71. { April 08 2003 - MK : Aka Mr Kroket - Added Better FPC support }
  72. { }
  73. { April 24 2003 - DL : under instruction from Alexey Barkovoy, I have added}
  74. { better TMT Pascal support and under instruction }
  75. { from Prof. Abimbola Olowofoyeku (The African Chief),}
  76. { I have added better Gnu Pascal support }
  77. { }
  78. { April 30 2003 - DL : under instruction from David Mears AKA }
  79. { Jason Siletto, I have added FPC Linux support. }
  80. { This was compiled with fpc 1.1, so remember to set }
  81. { include file path. ie. -Fi/usr/share/fpcsrc/rtl/* }
  82. { }
  83. {
  84. $Log: sdl_image.pas,v $
  85. Revision 1.14 2007/05/29 21:31:13 savage
  86. Changes as suggested by Almindor for 64bit compatibility.
  87. Revision 1.13 2007/05/20 20:30:54 savage
  88. Initial Changes to Handle 64 Bits
  89. Revision 1.12 2006/12/02 00:14:40 savage
  90. Updated to latest version
  91. Revision 1.11 2005/04/10 18:22:59 savage
  92. Changes as suggested by Michalis, thanks.
  93. Revision 1.10 2005/04/10 11:48:33 savage
  94. Changes as suggested by Michalis, thanks.
  95. Revision 1.9 2005/01/05 01:47:07 savage
  96. Changed LibName to reflect what MacOS X should have. ie libSDL*-1.2.0.dylib respectively.
  97. Revision 1.8 2005/01/04 23:14:44 savage
  98. Changed LibName to reflect what most Linux distros will have. ie libSDL*-1.2.so.0 respectively.
  99. Revision 1.7 2005/01/01 02:03:12 savage
  100. Updated to v1.2.4
  101. Revision 1.6 2004/08/14 22:54:30 savage
  102. Updated so that Library name defines are correctly defined for MacOS X.
  103. Revision 1.5 2004/05/10 14:10:04 savage
  104. Initial MacOS X support. Fixed defines for MACOS ( Classic ) and DARWIN ( MacOS X ).
  105. Revision 1.4 2004/04/13 09:32:08 savage
  106. Changed Shared object names back to just the .so extension to avoid conflicts on various Linux/Unix distros. Therefore developers will need to create Symbolic links to the actual Share Objects if necessary.
  107. Revision 1.3 2004/04/01 20:53:23 savage
  108. Changed Linux Shared Object names so they reflect the Symbolic Links that are created when installing the RPMs from the SDL site.
  109. Revision 1.2 2004/03/30 20:23:28 savage
  110. Tidied up use of UNIX compiler directive.
  111. Revision 1.1 2004/02/14 23:35:42 savage
  112. version 1 of sdl_image, sdl_mixer and smpeg.
  113. }
  114. {******************************************************************************}
  115. {$I jedi-sdl.inc}
  116. interface
  117. uses
  118. {$IFDEF __GPC__}
  119. gpc,
  120. {$ENDIF}
  121. sdl;
  122. const
  123. {$IFDEF WINDOWS}
  124. SDL_ImageLibName = 'SDL_Image.dll';
  125. {$ENDIF}
  126. {$IFDEF UNIX}
  127. {$IFDEF DARWIN}
  128. SDL_ImageLibName = 'libSDL_image-1.2.0.dylib';
  129. {$ELSE}
  130. {$IFDEF FPC}
  131. SDL_ImageLibName = 'libSDL_image.so';
  132. {$ELSE}
  133. SDL_ImageLibName = 'libSDL_image-1.2.so.0';
  134. {$ENDIF}
  135. {$ENDIF}
  136. {$ENDIF}
  137. {$IFDEF MACOS}
  138. SDL_ImageLibName = 'SDL_image';
  139. {$ENDIF}
  140. // Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
  141. SDL_IMAGE_MAJOR_VERSION = 1;
  142. {$EXTERNALSYM SDL_IMAGE_MAJOR_VERSION}
  143. SDL_IMAGE_MINOR_VERSION = 2;
  144. {$EXTERNALSYM SDL_IMAGE_MINOR_VERSION}
  145. SDL_IMAGE_PATCHLEVEL = 5;
  146. {$EXTERNALSYM SDL_IMAGE_PATCHLEVEL}
  147. { This macro can be used to fill a version structure with the compile-time
  148. version of the SDL_image library. }
  149. procedure SDL_IMAGE_VERSION( var X : TSDL_Version );
  150. {$EXTERNALSYM SDL_IMAGE_VERSION}
  151. { This function gets the version of the dynamically linked SDL_image library.
  152. it should NOT be used to fill a version structure, instead you should
  153. use the SDL_IMAGE_VERSION() macro.
  154. }
  155. function IMG_Linked_Version : PSDL_version;
  156. external {$IFDEF __GPC__}name 'IMG_Linked_Version'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  157. {$EXTERNALSYM IMG_Linked_Version}
  158. { Load an image from an SDL data source.
  159. The 'type' may be one of: "BMP", "GIF", "PNG", etc.
  160. If the image format supports a transparent pixel, SDL will set the
  161. colorkey for the surface. You can enable RLE acceleration on the
  162. surface afterwards by calling:
  163. SDL_SetColorKey(image, SDL_RLEACCEL, image.format.colorkey);
  164. }
  165. function IMG_LoadTyped_RW(src: PSDL_RWops; freesrc: Integer; _type: PChar): PSDL_Surface;
  166. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadTyped_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  167. {$EXTERNALSYM IMG_LoadTyped_RW}
  168. { Convenience functions }
  169. function IMG_Load(const _file: PChar): PSDL_Surface;
  170. cdecl; external {$IFDEF __GPC__}name 'IMG_Load'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  171. {$EXTERNALSYM IMG_Load}
  172. function IMG_Load_RW(src: PSDL_RWops; freesrc: Integer): PSDL_Surface;
  173. cdecl; external {$IFDEF __GPC__}name 'IMG_Load_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  174. {$EXTERNALSYM IMG_Load_RW}
  175. { Invert the alpha of a surface for use with OpenGL
  176. This function is now a no-op, and only provided for backwards compatibility. }
  177. function IMG_InvertAlpha(_on: Integer): Integer;
  178. cdecl; external {$IFDEF __GPC__}name 'IMG_InvertAlpha'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  179. {$EXTERNALSYM IMG_InvertAlpha}
  180. { Functions to detect a file type, given a seekable source }
  181. function IMG_isBMP(src: PSDL_RWops): Integer;
  182. cdecl; external {$IFDEF __GPC__}name 'IMG_isBMP'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  183. {$EXTERNALSYM IMG_isBMP}
  184. function IMG_isGIF(src: PSDL_RWops): Integer;
  185. cdecl; external {$IFDEF __GPC__}name 'IMG_isGIF'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  186. {$EXTERNALSYM IMG_isGIF}
  187. function IMG_isJPG(src: PSDL_RWops): Integer;
  188. cdecl; external {$IFDEF __GPC__}name 'IMG_isJPG'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  189. {$EXTERNALSYM IMG_isJPG}
  190. function IMG_isLBM(src: PSDL_RWops): Integer;
  191. cdecl; external {$IFDEF __GPC__}name 'IMG_isLBM'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  192. {$EXTERNALSYM IMG_isLBM}
  193. function IMG_isPCX(src: PSDL_RWops): Integer;
  194. cdecl; external {$IFDEF __GPC__}name 'IMG_isPCX'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  195. {$EXTERNALSYM IMG_isPCX}
  196. function IMG_isPNG(src: PSDL_RWops): Integer;
  197. cdecl; external {$IFDEF __GPC__}name 'IMG_isPNG'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  198. {$EXTERNALSYM IMG_isPNG}
  199. function IMG_isPNM(src: PSDL_RWops): Integer;
  200. cdecl; external {$IFDEF __GPC__}name 'IMG_isPNM'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  201. {$EXTERNALSYM IMG_isPNM}
  202. function IMG_isTIF(src: PSDL_RWops): Integer;
  203. cdecl; external {$IFDEF __GPC__}name 'IMG_isTIF'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  204. {$EXTERNALSYM IMG_isTIF}
  205. function IMG_isXCF(src: PSDL_RWops): Integer;
  206. cdecl; external {$IFDEF __GPC__}name 'IMG_isXCF'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  207. {$EXTERNALSYM IMG_isXCF}
  208. function IMG_isXPM(src: PSDL_RWops): Integer;
  209. cdecl; external {$IFDEF __GPC__}name 'IMG_isXPM'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  210. {$EXTERNALSYM IMG_isXPM}
  211. function IMG_isXV(src: PSDL_RWops): Integer;
  212. cdecl; external {$IFDEF __GPC__}name 'IMG_isXV'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  213. {$EXTERNALSYM IMG_isXV}
  214. { Individual loading functions }
  215. function IMG_LoadBMP_RW(src: PSDL_RWops): PSDL_Surface;
  216. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadBMP_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  217. {$EXTERNALSYM IMG_LoadBMP_RW}
  218. function IMG_LoadGIF_RW(src: PSDL_RWops): PSDL_Surface;
  219. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadGIF_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  220. {$EXTERNALSYM IMG_LoadGIF_RW}
  221. function IMG_LoadJPG_RW(src: PSDL_RWops): PSDL_Surface;
  222. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadJPG_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  223. {$EXTERNALSYM IMG_LoadJPG_RW}
  224. function IMG_LoadLBM_RW(src: PSDL_RWops): PSDL_Surface;
  225. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadLBM_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  226. {$EXTERNALSYM IMG_LoadLBM_RW}
  227. function IMG_LoadPCX_RW(src: PSDL_RWops): PSDL_Surface;
  228. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadPCX_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  229. {$EXTERNALSYM IMG_LoadPCX_RW}
  230. function IMG_LoadPNM_RW(src: PSDL_RWops): PSDL_Surface;
  231. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadPNM_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  232. {$EXTERNALSYM IMG_LoadPNM_RW}
  233. function IMG_LoadPNG_RW(src: PSDL_RWops): PSDL_Surface;
  234. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadPNG_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  235. {$EXTERNALSYM IMG_LoadPNG_RW}
  236. function IMG_LoadTGA_RW(src: PSDL_RWops): PSDL_Surface;
  237. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadTGA_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  238. {$EXTERNALSYM IMG_LoadTGA_RW}
  239. function IMG_LoadTIF_RW(src: PSDL_RWops): PSDL_Surface;
  240. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadTIF_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  241. {$EXTERNALSYM IMG_LoadTIF_RW}
  242. function IMG_LoadXCF_RW(src: PSDL_RWops): PSDL_Surface;
  243. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadXCF_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  244. {$EXTERNALSYM IMG_LoadXCF_RW}
  245. function IMG_LoadXPM_RW(src: PSDL_RWops): PSDL_Surface;
  246. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadXPM_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  247. {$EXTERNALSYM IMG_LoadXPM_RW}
  248. function IMG_LoadXV_RW(src: PSDL_RWops): PSDL_Surface;
  249. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadXV_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  250. {$EXTERNALSYM IMG_LoadXV_RW}
  251. function IMG_ReadXPMFromArray( xpm : PPChar ): PSDL_Surface;
  252. cdecl; external {$IFDEF __GPC__}name 'IMG_ReadXPMFromArray'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  253. {$EXTERNALSYM IMG_ReadXPMFromArray}
  254. { used internally, NOT an exported function }
  255. //function IMG_string_equals( const str1 : PChar; const str2 : PChar ) : integer;
  256. //cdecl; external {$IFDEF __GPC__}name 'IMG_string_equals'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  257. //{ $ EXTERNALSYM IMG_string_equals}
  258. { Error Macros }
  259. { We'll use SDL for reporting errors }
  260. procedure IMG_SetError( fmt : PChar );
  261. function IMG_GetError : PChar;
  262. implementation
  263. {$IFDEF __GPC__}
  264. {$L 'sdl_image'} { link sdl_image.dll.a or libsdl_image.so or libsdl_image.a }
  265. {$ENDIF}
  266. procedure SDL_IMAGE_VERSION( var X : TSDL_Version );
  267. begin
  268. X.major := SDL_IMAGE_MAJOR_VERSION;
  269. X.minor := SDL_IMAGE_MINOR_VERSION;
  270. X.patch := SDL_IMAGE_PATCHLEVEL;
  271. end;
  272. procedure IMG_SetError( fmt : PChar );
  273. begin
  274. SDL_SetError( fmt );
  275. end;
  276. function IMG_GetError : PChar;
  277. begin
  278. result := SDL_GetError;
  279. end;
  280. end.