sdl2_image.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. unit sdl2_image;
  2. {*
  3. SDL_image: An example image loading library for use with SDL
  4. Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
  5. Pascal-Header-Translation 2013 by Tim Blume
  6. Both, header translation and sdl_image, under following license:
  7. This software is provided 'as-is', without any express or implied
  8. warranty. In no event will the authors be held liable for any damages
  9. arising from the use of this software.
  10. Permission is granted to anyone to use this software for any purpose,
  11. including commercial applications, and to alter it and redistribute it
  12. freely, subject to the following restrictions:
  13. 1. The origin of this software must not be misrepresented; you must not
  14. claim that you wrote the original software. If you use this software
  15. in a product, an acknowledgment in the product documentation would be
  16. appreciated but is not required.
  17. 2. Altered source versions must be plainly marked as such, and must not be
  18. misrepresented as being the original software.
  19. 3. This notice may not be removed or altered from any source distribution.
  20. *}
  21. {$DEFINE SDL_IMAGE}
  22. {$I jedi.inc}
  23. interface
  24. uses
  25. {$IFDEF FPC}
  26. ctypes,
  27. {$ENDIF}
  28. SDL2;
  29. {$I ctypes.inc}
  30. const
  31. {$IFDEF WINDOWS}
  32. IMG_LibName = 'SDL2_image.dll';
  33. {$ENDIF}
  34. {$IFDEF UNIX}
  35. {$IFDEF DARWIN}
  36. IMG_LibName = 'libSDL2_image.dylib';
  37. {$ELSE}
  38. {$IFDEF FPC}
  39. IMG_LibName = 'libSDL2_image.so';
  40. {$ELSE}
  41. IMG_LibName = 'libSDL2_image.so.0';
  42. {$ENDIF}
  43. {$ENDIF}
  44. {$ENDIF}
  45. {$IFDEF MACOS}
  46. IMG_LibName = 'SDL2_image';
  47. {$IFDEF FPC}
  48. {$linklib libSDL2_image}
  49. {$ENDIF}
  50. {$ENDIF}
  51. {* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL *}
  52. SDL_IMAGE_MAJOR_VERSION = 2;
  53. SDL_IMAGE_MINOR_VERSION = 0;
  54. SDL_IMAGE_PATCHLEVEL = 5;
  55. {* This macro can be used to fill a version structure with the compile-time
  56. * version of the SDL_image library.
  57. *}
  58. procedure SDL_IMAGE_VERSION(Out X: TSDL_Version);
  59. {* This function gets the version of the dynamically linked SDL_image library.
  60. *
  61. * Note that this function does NOT allocate a new TSDL_Version and fill it with info,
  62. * but returns a pointer to a TSDL_Version residing inside dynlinked file.
  63. *
  64. * As such, attempting to Dispose() of this memory will result in access violation.
  65. *}
  66. function IMG_Linked_Version: PSDL_Version cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_Linked_Version' {$ENDIF} {$ENDIF};
  67. const
  68. IMG_INIT_JPG = $00000001;
  69. IMG_INIT_PNG = $00000002;
  70. IMG_INIT_TIF = $00000004;
  71. IMG_INIT_WEBP = $00000008;
  72. type
  73. PPIMG_InitFlags = ^PIMG_InitFlags;
  74. PIMG_InitFlags = ^TIMG_InitFlags;
  75. TIMG_InitFlags = DWord;
  76. {* Loads dynamic libraries and prepares them for use. Flags should be
  77. one or more flags from IMG_InitFlags OR'd together.
  78. It returns the flags successfully initialized, or 0 on failure.
  79. *}
  80. function IMG_Init(flags: cint32): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_Init' {$ENDIF} {$ENDIF};
  81. {* Unloads libraries loaded with IMG_Init *}
  82. procedure IMG_Quit() cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_Quit' {$ENDIF} {$ENDIF};
  83. {* Load an image from an SDL data source.
  84. The 'type' may be one of: "BMP", "GIF", "PNG", etc.
  85. If the image format supports a transparent pixel, SDL will set the
  86. colorkey for the surface. You can enable RLE acceleration on the
  87. surface afterwards by calling:
  88. SDL_SetColorKey(image, SDL_RLEACCEL, image->format->colorkey);
  89. *}
  90. function IMG_LoadTyped_RW(src: PSDL_RWops; freesrc: cint32; _type: PAnsiChar): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadTyped_RW' {$ENDIF} {$ENDIF};
  91. {* Convenience functions *}
  92. function IMG_Load(_file: PAnsiChar): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_Load' {$ENDIF} {$ENDIF};
  93. function IMG_Load_RW(src: PSDL_RWops; freesrc: cint32): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_Load_RW' {$ENDIF} {$ENDIF};
  94. {* Load an image directly into a render texture. *}
  95. function IMG_LoadTexture(renderer: PSDL_Renderer; _file: PAnsiChar): PSDL_Texture cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadTexture' {$ENDIF} {$ENDIF};
  96. function IMG_LoadTexture_RW(renderer: PSDL_Renderer; src: PSDL_RWops; freesrc: cint32): PSDL_Texture cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadTexture_RW' {$ENDIF} {$ENDIF};
  97. function IMG_LoadTextureTyped_RW(renderer: PSDL_Renderer; src: PSDL_RWops; freesrc: cint32; _type: PAnsiChar): PSDL_Texture cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadTextureTyped_RW' {$ENDIF} {$ENDIF};
  98. {* Functions to detect a file type, given a seekable source *}
  99. function IMG_isICO(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isICO' {$ENDIF} {$ENDIF};
  100. function IMG_isCUR(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isCUR' {$ENDIF} {$ENDIF};
  101. function IMG_isBMP(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isBMP' {$ENDIF} {$ENDIF};
  102. function IMG_isGIF(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isGIF' {$ENDIF} {$ENDIF};
  103. function IMG_isJPG(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isJPG' {$ENDIF} {$ENDIF};
  104. function IMG_isLBM(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isLBM' {$ENDIF} {$ENDIF};
  105. function IMG_isPCX(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isPCX' {$ENDIF} {$ENDIF};
  106. function IMG_isPNG(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isPNG' {$ENDIF} {$ENDIF};
  107. function IMG_isPNM(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isPNM' {$ENDIF} {$ENDIF};
  108. function IMG_isSVG(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isSVG' {$ENDIF} {$ENDIF};
  109. function IMG_isTIF(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isTIF' {$ENDIF} {$ENDIF};
  110. function IMG_isXCF(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '-IMG_isXCF' {$ENDIF} {$ENDIF};
  111. function IMG_isXPM(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isXPM' {$ENDIF} {$ENDIF};
  112. function IMG_isXV(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isXV' {$ENDIF} {$ENDIF};
  113. function IMG_isWEBP(src: PSDL_RWops): cint32 cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_isWEBP' {$ENDIF} {$ENDIF};
  114. {* Individual loading functions *}
  115. function IMG_LoadICO_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadICO_RW' {$ENDIF} {$ENDIF};
  116. function IMG_LoadCUR_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadCUR_RW' {$ENDIF} {$ENDIF};
  117. function IMG_LoadBMP_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadBMP_RW' {$ENDIF} {$ENDIF};
  118. function IMG_LoadGIF_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadGIF_RW' {$ENDIF} {$ENDIF};
  119. function IMG_LoadJPG_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadJPG_RW' {$ENDIF} {$ENDIF};
  120. function IMG_LoadLBM_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadLBM_RW' {$ENDIF} {$ENDIF};
  121. function IMG_LoadPCX_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadPCX_RW' {$ENDIF} {$ENDIF};
  122. function IMG_LoadPNG_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadPNG_RW' {$ENDIF} {$ENDIF};
  123. function IMG_LoadPNM_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadPNM_RW' {$ENDIF} {$ENDIF};
  124. function IMG_LoadSVG_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadSVG_RW' {$ENDIF} {$ENDIF};
  125. function IMG_LoadTGA_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadTGA_RW' {$ENDIF} {$ENDIF};
  126. function IMG_LoadTIF_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadTIF_RW' {$ENDIF} {$ENDIF};
  127. function IMG_LoadXCF_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadXCF_RW' {$ENDIF} {$ENDIF};
  128. function IMG_LoadXPM_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadXMP_RW' {$ENDIF} {$ENDIF};
  129. function IMG_LoadXV_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadXV_RW' {$ENDIF} {$ENDIF};
  130. function IMG_LoadWEBP_RW(src: PSDL_RWops): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_LoadWEBP_RW' {$ENDIF} {$ENDIF};
  131. function IMG_ReadXPMFromArray(xpm: PPChar): PSDL_Surface cdecl; external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_ReadXPMFromArray' {$ENDIF} {$ENDIF};
  132. {* Individual saving functions *}
  133. function IMG_SavePNG(surface: PSDL_Surface; const _file: PAnsiChar): cint32 cdecl;
  134. external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_SavePNG' {$ENDIF} {$ENDIF};
  135. function IMG_SavePNG_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: cint32): cint32 cdecl;
  136. external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_SavePNG_RW' {$ENDIF} {$ENDIF};
  137. function IMG_SaveJPG(surface: PSDL_Surface; const _file: PAnsiChar; quality: cint32): cint32 cdecl;
  138. external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_SaveJPG' {$ENDIF} {$ENDIF};
  139. function IMG_SaveJPG_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: cint32; quality: cint32): cint32 cdecl;
  140. external IMG_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_IMG_SaveJPG_RW' {$ENDIF} {$ENDIF};
  141. {* We'll use SDL for reporting errors *}
  142. function IMG_SetError(fmt: PAnsiChar; args: array of const): cint; cdecl;
  143. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF}
  144. name {$IF DEFINED(DELPHI) AND DEFINED(MACOS)} '_SDL_SetError' {$ELSE} 'SDL_SetError' {$ENDIF};
  145. function IMG_GetError: PAnsiChar; cdecl;
  146. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF}
  147. name {$IF DEFINED(DELPHI) AND DEFINED(MACOS)} '_SDL_GetError' {$ELSE} 'SDL_GetError' {$ENDIF};
  148. implementation
  149. procedure SDL_IMAGE_VERSION(Out X: TSDL_Version);
  150. begin
  151. X.major := SDL_IMAGE_MAJOR_VERSION;
  152. X.minor := SDL_IMAGE_MINOR_VERSION;
  153. X.patch := SDL_IMAGE_PATCHLEVEL;
  154. end;
  155. end.