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