SDL2.Image.pas 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. unit SDL2.Image;
  2. (*******************************************************************************
  3. SDL2_Image.pas v1.0 29/07/2013 first version for DelphiXE
  4. v1.1 27/08/2013 add MACOS compability
  5. v1.2 31/05/2014 delete sdl2.inc
  6. Simple DirectMedia Layer
  7. Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
  8. Pascal-Header-Conversion SDL from the JEDI-Team written by Domenique Louis and others.
  9. convert SDL/SDL2 to SDL2 for DelphiXE by Kotai 2013/2014 www.remakesonline.com
  10. The initial developer of this Pascal code was :
  11. Dominqiue Louis <[email protected]>
  12. ********************************************************************************)
  13. interface
  14. uses
  15. SDL2.Import;
  16. const
  17. {$IFDEF MSWINDOWS}
  18. SDL_ImageLibName = 'SDL2_Image.dll';
  19. {$ENDIF}
  20. {$IFDEF ANDROID}
  21. SDL_ImageLibName = 'libSDL2_image.so';
  22. {$ENDIF}
  23. {$IFDEF MACOS}
  24. {$IFDEF IOS}
  25. SDL_ImageLibName = 'libSDL2_image.a';
  26. {$ELSE}
  27. SDL_ImageLibName = 'SDL2_image';
  28. // SDL_ImageLibName = '../Frameworks/SDL2_image.framework/Versions/A/SDL2_image';
  29. {$ENDIF}
  30. {$ENDIF}
  31. {* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL *}
  32. SDL_IMAGE_MAJOR_VERSION = 2;
  33. SDL_IMAGE_MINOR_VERSION = 0;
  34. SDL_IMAGE_PATCHLEVEL = 0;
  35. {* This macro can be used to fill a version structure with the compile-time
  36. * version of the SDL_image library.
  37. *}
  38. procedure SDL_IMAGE_VERSION(Out X: TSDL_Version);
  39. {* This function gets the version of the dynamically linked SDL_image library.
  40. it should NOT be used to fill a version structure, instead you should
  41. use the SDL_IMAGE_VERSION() macro.
  42. *}
  43. function IMG_Linked_Version(): TSDL_Version;
  44. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_Linked_Version' {$ENDIF} {$ENDIF};
  45. const
  46. IMG_INIT_JPG = $00000001;
  47. IMG_INIT_PNG = $00000002;
  48. IMG_INIT_TIF = $00000004;
  49. IMG_INIT_WEBP = $00000008;
  50. type
  51. TIMG_InitFlags = DWord;
  52. {* Loads dynamic libraries and prepares them for use. Flags should be
  53. one or more flags from IMG_InitFlags OR'd together.
  54. It returns the flags successfully initialized, or 0 on failure.
  55. *}
  56. function IMG_Init(flags: SInt32): SInt32;
  57. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_Init' {$ENDIF} {$ENDIF};
  58. {* Unloads libraries loaded with IMG_Init *}
  59. procedure IMG_Quit();
  60. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_Quit' {$ENDIF} {$ENDIF};
  61. {* Load an image from an SDL data source.
  62. The 'type' may be one of: "BMP", "GIF", "PNG", etc.
  63. If the image format supports a transparent pixel, SDL will set the
  64. colorkey for the surface. You can enable RLE acceleration on the
  65. surface afterwards by calling:
  66. SDL_SetColorKey(image, SDL_RLEACCEL, image->format->colorkey);
  67. *}
  68. function IMG_LoadTyped_RW(src: PSDL_RWops; freesrc: SInt32; _type: PChar): PSDL_Surface;
  69. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadTyped_RW' {$ENDIF} {$ENDIF};
  70. {* Convenience functions *}
  71. function IMG_Load(_file: PChar): PSDL_Surface;
  72. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_Load' {$ENDIF} {$ENDIF};
  73. function IMG_Load_RW(src: PSDL_RWops; freesrc: SInt32): PSDL_Surface;
  74. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_Load_RW' {$ENDIF} {$ENDIF};
  75. {* Load an image directly into a render texture. *}
  76. function IMG_LoadTexture(renderer: PSDL_Renderer; _file: PChar): PSDL_Texture;
  77. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadTexture' {$ENDIF} {$ENDIF};
  78. function IMG_LoadTexture_RW(renderer: PSDL_Renderer; src: PSDL_RWops; freesrc: SInt32): PSDL_Texture;
  79. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadTexture_RW' {$ENDIF} {$ENDIF};
  80. function IMG_LoadTextureTyped_RW(renderer: PSDL_Renderer; src: PSDL_RWops; freesrc: SInt32; _type: PChar): PSDL_Texture;
  81. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadTextureTyped_RW' {$ENDIF} {$ENDIF};
  82. {* Functions to detect a file type, given a seekable source *}
  83. function IMG_isICO(src: PSDL_RWops): SInt32;
  84. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_isICO' {$ENDIF} {$ENDIF};
  85. function IMG_isCUR(src: PSDL_RWops): SInt32;
  86. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_isCUR' {$ENDIF} {$ENDIF};
  87. function IMG_isBMP(src: PSDL_RWops): SInt32;
  88. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_isBMP' {$ENDIF} {$ENDIF};
  89. function IMG_isGIF(src: PSDL_RWops): SInt32;
  90. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_isGIF' {$ENDIF} {$ENDIF};
  91. function IMG_isJPG(src: PSDL_RWops): SInt32;
  92. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_isJPG' {$ENDIF} {$ENDIF};
  93. function IMG_isLBM(src: PSDL_RWops): SInt32;
  94. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_isLBM' {$ENDIF} {$ENDIF};
  95. function IMG_isPCX(src: PSDL_RWops): SInt32;
  96. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_isPCX' {$ENDIF} {$ENDIF};
  97. function IMG_isPNG(src: PSDL_RWops): SInt32;
  98. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_isPNG' {$ENDIF} {$ENDIF};
  99. function IMG_isPNM(src: PSDL_RWops): SInt32;
  100. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_isPNM' {$ENDIF} {$ENDIF};
  101. function IMG_isTIF(src: PSDL_RWops): SInt32;
  102. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_isTIF' {$ENDIF} {$ENDIF};
  103. function IMG_isXCF(src: PSDL_RWops): SInt32;
  104. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '-IMG_isXCF' {$ENDIF} {$ENDIF};
  105. function IMG_isXPM(src: PSDL_RWops): SInt32;
  106. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_isXPM' {$ENDIF} {$ENDIF};
  107. function IMG_isXV(src: PSDL_RWops): SInt32;
  108. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_isXV' {$ENDIF} {$ENDIF};
  109. function IMG_isWEBP(src: PSDL_RWops): SInt32;
  110. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_isWEBP' {$ENDIF} {$ENDIF};
  111. {* Individual loading functions *}
  112. function IMG_LoadICO_RW(src: PSDL_RWops): PSDL_Surface;
  113. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadICO_RW' {$ENDIF} {$ENDIF};
  114. function IMG_LoadCUR_RW(src: PSDL_RWops): PSDL_Surface;
  115. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadCUR_RW' {$ENDIF} {$ENDIF};
  116. function IMG_LoadBMP_RW(src: PSDL_RWops): PSDL_Surface;
  117. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadBMP_RW' {$ENDIF} {$ENDIF};
  118. function IMG_LoadGIF_RW(src: PSDL_RWops): PSDL_Surface;
  119. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadGIF_RW' {$ENDIF} {$ENDIF};
  120. function IMG_LoadJPG_RW(src: PSDL_RWops): PSDL_Surface;
  121. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadJPG_RW' {$ENDIF} {$ENDIF};
  122. function IMG_LoadLBM_RW(src: PSDL_RWops): PSDL_Surface;
  123. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadLBM_RW' {$ENDIF} {$ENDIF};
  124. function IMG_LoadPCX_RW(src: PSDL_RWops): PSDL_Surface;
  125. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadPCX_RW' {$ENDIF} {$ENDIF};
  126. function IMG_LoadPNG_RW(src: PSDL_RWops): PSDL_Surface;
  127. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadPNG_RW' {$ENDIF} {$ENDIF};
  128. function IMG_LoadPNM_RW(src: PSDL_RWops): PSDL_Surface;
  129. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadPNM_RW' {$ENDIF} {$ENDIF};
  130. function IMG_LoadTGA_RW(src: PSDL_RWops): PSDL_Surface;
  131. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadTGA_RW' {$ENDIF} {$ENDIF};
  132. function IMG_LoadTIF_RW(src: PSDL_RWops): PSDL_Surface;
  133. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadTIF_RW' {$ENDIF} {$ENDIF};
  134. function IMG_LoadXCF_RW(src: PSDL_RWops): PSDL_Surface;
  135. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadXCF_RW' {$ENDIF} {$ENDIF};
  136. function IMG_LoadXPM_RW(src: PSDL_RWops): PSDL_Surface;
  137. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadXMP_RW' {$ENDIF} {$ENDIF};
  138. function IMG_LoadXV_RW(src: PSDL_RWops): PSDL_Surface;
  139. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadXV_RW' {$ENDIF} {$ENDIF};
  140. function IMG_LoadWEBP_RW(src: PSDL_RWops): PSDL_Surface;
  141. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_LoadWEBP_RW' {$ENDIF} {$ENDIF};
  142. function IMG_ReadXPMFromArray(xpm: PPChar): PSDL_Surface;
  143. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_ReadXPMFromArray' {$ENDIF} {$ENDIF};
  144. {* Individual saving functions *}
  145. function IMG_SavePNG(surface: PSDL_Surface; const _file: PChar): SInt32;
  146. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_SavePNG' {$ENDIF} {$ENDIF};
  147. function IMG_SavePNG_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: SInt32): SInt32;
  148. cdecl; external SDL_ImageLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_IMG_SavePNG_RW' {$ENDIF} {$ENDIF};
  149. {* We'll use SDL for reporting errors *}
  150. function IMG_SetError(fmt: PChar): SInt32;
  151. function IMG_GetError: PChar;
  152. implementation
  153. //******************************************************************************
  154. procedure SDL_IMAGE_VERSION(Out X: TSDL_Version);
  155. begin
  156. X.major := SDL_IMAGE_MAJOR_VERSION;
  157. X.minor := SDL_IMAGE_MINOR_VERSION;
  158. X.patch := SDL_IMAGE_PATCHLEVEL;
  159. end;
  160. //******************************************************************************
  161. function IMG_SetError(fmt: PChar): SInt32;
  162. begin
  163. Result := SDL_SetError(fmt);
  164. end;
  165. //******************************************************************************
  166. function IMG_GetError: PChar;
  167. begin
  168. Result := SDL_GetError;
  169. end;
  170. end.