sdl_image.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. unit sdl_image;
  2. {
  3. $Id: sdl_image.pas,v 1.7 2005/01/01 02:03:12 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.7 2005/01/01 02:03:12 savage
  86. Updated to v1.2.4
  87. Revision 1.6 2004/08/14 22:54:30 savage
  88. Updated so that Library name defines are correctly defined for MacOS X.
  89. Revision 1.5 2004/05/10 14:10:04 savage
  90. Initial MacOS X support. Fixed defines for MACOS ( Classic ) and DARWIN ( MacOS X ).
  91. Revision 1.4 2004/04/13 09:32:08 savage
  92. 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.
  93. Revision 1.3 2004/04/01 20:53:23 savage
  94. Changed Linux Shared Object names so they reflect the Symbolic Links that are created when installing the RPMs from the SDL site.
  95. Revision 1.2 2004/03/30 20:23:28 savage
  96. Tidied up use of UNIX compiler directive.
  97. Revision 1.1 2004/02/14 23:35:42 savage
  98. version 1 of sdl_image, sdl_mixer and smpeg.
  99. }
  100. {******************************************************************************}
  101. {$I jedi-sdl.inc}
  102. interface
  103. uses
  104. {$IFDEF __GPC__}
  105. gpc,
  106. {$ENDIF}
  107. sdl;
  108. const
  109. {$IFDEF WIN32}
  110. SDL_ImageLibName = 'SDL_Image.dll';
  111. {$ENDIF}
  112. {$IFDEF UNIX}
  113. {$IFDEF DARWIN}
  114. SDL_ImageLibName = 'libSDL_image.dylib';
  115. {$ELSE}
  116. SDL_ImageLibName = 'libSDL_image.so';
  117. {$ENDIF}
  118. {$ENDIF}
  119. {$IFDEF MACOS}
  120. SDL_ImageLibName = 'SDL_image';
  121. {$ENDIF}
  122. // Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
  123. SDL_IMAGE_MAJOR_VERSION = 1;
  124. {$EXTERNALSYM SDL_IMAGE_MAJOR_VERSION}
  125. SDL_IMAGE_MINOR_VERSION = 2;
  126. {$EXTERNALSYM SDL_IMAGE_MINOR_VERSION}
  127. SDL_IMAGE_PATCHLEVEL = 4;
  128. {$EXTERNALSYM SDL_IMAGE_PATCHLEVEL}
  129. { This macro can be used to fill a version structure with the compile-time
  130. version of the SDL_image library. }
  131. procedure SDL_IMAGE_VERSION( var X : TSDL_Version );
  132. {$EXTERNALSYM SDL_IMAGE_VERSION}
  133. { This function gets the version of the dynamically linked SDL_image library.
  134. it should NOT be used to fill a version structure, instead you should
  135. use the SDL_IMAGE_VERSION() macro.
  136. }
  137. function IMG_Linked_Version : PSDL_version;
  138. external {$IFDEF __GPC__}name 'IMG_Linked_Version'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  139. {$EXTERNALSYM IMG_Linked_Version}
  140. { Load an image from an SDL data source.
  141. The 'type' may be one of: "BMP", "GIF", "PNG", etc.
  142. If the image format supports a transparent pixel, SDL will set the
  143. colorkey for the surface. You can enable RLE acceleration on the
  144. surface afterwards by calling:
  145. SDL_SetColorKey(image, SDL_RLEACCEL, image.format.colorkey);
  146. }
  147. function IMG_LoadTyped_RW(src: PSDL_RWops; freesrc: Integer; _type: PChar): PSDL_Surface;
  148. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadTyped_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  149. {$EXTERNALSYM IMG_LoadTyped_RW}
  150. { Convenience functions }
  151. function IMG_Load(const _file: PChar): PSDL_Surface;
  152. cdecl; external {$IFDEF __GPC__}name 'IMG_Load'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  153. {$EXTERNALSYM IMG_Load}
  154. function IMG_Load_RW(src: PSDL_RWops; freesrc: Integer): PSDL_Surface;
  155. cdecl; external {$IFDEF __GPC__}name 'IMG_Load_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  156. {$EXTERNALSYM IMG_Load_RW}
  157. { Invert the alpha of a surface for use with OpenGL
  158. This function is now a no-op, and only provided for backwards compatibility. }
  159. function IMG_InvertAlpha(_on: Integer): Integer;
  160. cdecl; external {$IFDEF __GPC__}name 'IMG_InvertAlpha'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  161. {$EXTERNALSYM IMG_InvertAlpha}
  162. { Functions to detect a file type, given a seekable source }
  163. function IMG_isBMP(src: PSDL_RWops): Integer;
  164. cdecl; external {$IFDEF __GPC__}name 'IMG_isBMP'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  165. {$EXTERNALSYM IMG_isBMP}
  166. function IMG_isPNM(src: PSDL_RWops): Integer;
  167. cdecl; external {$IFDEF __GPC__}name 'IMG_isPNM'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  168. {$EXTERNALSYM IMG_isPNM}
  169. function IMG_isXPM(src: PSDL_RWops): Integer;
  170. cdecl; external {$IFDEF __GPC__}name 'IMG_isXPM'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  171. {$EXTERNALSYM IMG_isXPM}
  172. function IMG_isXCF(src: PSDL_RWops): Integer;
  173. cdecl; external {$IFDEF __GPC__}name 'IMG_isXCF'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  174. {$EXTERNALSYM IMG_isXCF}
  175. function IMG_isPCX(src: PSDL_RWops): Integer;
  176. cdecl; external {$IFDEF __GPC__}name 'IMG_isPCX'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  177. {$EXTERNALSYM IMG_isPCX}
  178. function IMG_isGIF(src: PSDL_RWops): Integer;
  179. cdecl; external {$IFDEF __GPC__}name 'IMG_isGIF'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  180. {$EXTERNALSYM IMG_isGIF}
  181. function IMG_isJPG(src: PSDL_RWops): Integer;
  182. cdecl; external {$IFDEF __GPC__}name 'IMG_isJPG'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  183. {$EXTERNALSYM IMG_isJPG}
  184. function IMG_isTIF(src: PSDL_RWops): Integer;
  185. cdecl; external {$IFDEF __GPC__}name 'IMG_isTIF'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  186. {$EXTERNALSYM IMG_isTIF}
  187. function IMG_isPNG(src: PSDL_RWops): Integer;
  188. cdecl; external {$IFDEF __GPC__}name 'IMG_isPNG'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  189. {$EXTERNALSYM IMG_isPNG}
  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. { Individual loading functions }
  194. function IMG_LoadBMP_RW(src: PSDL_RWops): PSDL_Surface;
  195. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadBMP_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  196. {$EXTERNALSYM IMG_LoadBMP_RW}
  197. function IMG_LoadPNM_RW(src: PSDL_RWops): PSDL_Surface;
  198. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadPNM_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  199. {$EXTERNALSYM IMG_LoadPNM_RW}
  200. function IMG_LoadXPM_RW(src: PSDL_RWops): PSDL_Surface;
  201. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadXPM_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  202. {$EXTERNALSYM IMG_LoadXPM_RW}
  203. function IMG_LoadXCF_RW(src: PSDL_RWops): PSDL_Surface;
  204. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadXCF_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  205. {$EXTERNALSYM IMG_LoadXCF_RW}
  206. function IMG_LoadPCX_RW(src: PSDL_RWops): PSDL_Surface;
  207. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadPCX_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  208. {$EXTERNALSYM IMG_LoadPCX_RW}
  209. function IMG_LoadGIF_RW(src: PSDL_RWops): PSDL_Surface;
  210. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadGIF_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  211. {$EXTERNALSYM IMG_LoadGIF_RW}
  212. function IMG_LoadJPG_RW(src: PSDL_RWops): PSDL_Surface;
  213. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadJPG_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  214. {$EXTERNALSYM IMG_LoadJPG_RW}
  215. function IMG_LoadTIF_RW(src: PSDL_RWops): PSDL_Surface;
  216. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadTIF_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  217. {$EXTERNALSYM IMG_LoadTIF_RW}
  218. function IMG_LoadPNG_RW(src: PSDL_RWops): PSDL_Surface;
  219. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadPNG_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  220. {$EXTERNALSYM IMG_LoadPNG_RW}
  221. function IMG_LoadTGA_RW(src: PSDL_RWops): PSDL_Surface;
  222. cdecl; external {$IFDEF __GPC__}name 'IMG_LoadTGA_RW'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  223. {$EXTERNALSYM IMG_LoadTGA_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. { used internally, NOT an exported function }
  228. //function IMG_string_equals( const str1 : PChar; const str2 : PChar ) : integer;
  229. //cdecl; external {$IFDEF __GPC__}name 'IMG_string_equals'{$ELSE} SDL_ImageLibName{$ENDIF __GPC__};
  230. //{ $ EXTERNALSYM IMG_string_equals}
  231. { Error Macros }
  232. { We'll use SDL for reporting errors }
  233. procedure IMG_SetError( fmt : PChar );
  234. function IMG_GetError : PChar;
  235. implementation
  236. {$IFDEF __GPC__}
  237. {$L 'sdl_image'} { link sdl_image.dll.a or libsdl_image.so or libsdl_image.a }
  238. {$ENDIF}
  239. procedure SDL_IMAGE_VERSION( var X : TSDL_Version );
  240. begin
  241. X.major := SDL_IMAGE_MAJOR_VERSION;
  242. X.minor := SDL_IMAGE_MINOR_VERSION;
  243. X.patch := SDL_IMAGE_PATCHLEVEL;
  244. end;
  245. procedure IMG_SetError( fmt : PChar );
  246. begin
  247. SDL_SetError( fmt );
  248. end;
  249. function IMG_GetError : PChar;
  250. begin
  251. result := SDL_GetError;
  252. end;
  253. end.