sdl2-cs/src/SDL2_image.cs

289 lines
8.2 KiB
C#
Raw Normal View History

2013-04-03 12:15:53 -04:00
#region License
/* SDL2# - C# Wrapper for SDL2
*
2020-01-01 11:07:58 -05:00
* Copyright (c) 2013-2020 Ethan Lee.
2013-04-03 12:15:53 -04:00
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in a
* product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
* Ethan "flibitijibibo" Lee <flibitijibibo@flibitijibibo.com>
*
*/
#endregion
#region Using Statements
using System;
using System.Runtime.InteropServices;
#endregion
namespace SDL2
{
public static class SDL_image
2013-04-03 12:15:53 -04:00
{
#region SDL2# Variables
2013-04-03 12:15:53 -04:00
/* Used by DllImport to load the native library. */
2018-09-10 00:04:00 -04:00
private const string nativeLibName = "SDL2_image";
2013-04-03 12:15:53 -04:00
#endregion
#region SDL_image.h
/* Similar to the headers, this is the version we're expecting to be
* running with. You will likely want to check this somewhere in your
* program!
*/
public const int SDL_IMAGE_MAJOR_VERSION = 2;
public const int SDL_IMAGE_MINOR_VERSION = 0;
public const int SDL_IMAGE_PATCHLEVEL = 6;
[Flags]
public enum IMG_InitFlags
{
IMG_INIT_JPG = 0x00000001,
IMG_INIT_PNG = 0x00000002,
IMG_INIT_TIF = 0x00000004,
IMG_INIT_WEBP = 0x00000008
}
public static void SDL_IMAGE_VERSION(out SDL.SDL_version X)
{
X.major = SDL_IMAGE_MAJOR_VERSION;
X.minor = SDL_IMAGE_MINOR_VERSION;
X.patch = SDL_IMAGE_PATCHLEVEL;
}
2018-04-25 11:51:21 -04:00
[DllImport(nativeLibName, EntryPoint = "IMG_Linked_Version", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr INTERNAL_IMG_Linked_Version();
public static SDL.SDL_version IMG_Linked_Version()
{
SDL.SDL_version result;
2018-04-25 11:51:21 -04:00
IntPtr result_ptr = INTERNAL_IMG_Linked_Version();
result = (SDL.SDL_version) Marshal.PtrToStructure(
result_ptr,
2013-04-17 18:08:38 -04:00
typeof(SDL.SDL_version)
);
return result;
}
2013-04-17 18:08:38 -04:00
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2013-04-07 09:12:02 -04:00
public static extern int IMG_Init(IMG_InitFlags flags);
2013-04-17 18:08:38 -04:00
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void IMG_Quit();
/* IntPtr refers to an SDL_Surface* */
[DllImport(nativeLibName, EntryPoint = "IMG_Load", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr INTERNAL_IMG_Load(
byte[] file
);
public static IntPtr IMG_Load(string file)
{
return INTERNAL_IMG_Load(SDL.UTF8_ToNative(file));
}
2014-03-07 11:02:24 -05:00
/* src refers to an SDL_RWops*, IntPtr to an SDL_Surface* */
/* THIS IS A PUBLIC RWops FUNCTION! */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr IMG_Load_RW(
IntPtr src,
int freesrc
);
2014-12-27 22:14:52 -05:00
/* src refers to an SDL_RWops*, IntPtr to an SDL_Surface* */
/* THIS IS A PUBLIC RWops FUNCTION! */
[DllImport(nativeLibName, EntryPoint = "IMG_LoadTyped_RW", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr INTERNAL_IMG_LoadTyped_RW(
2014-12-27 22:14:52 -05:00
IntPtr src,
int freesrc,
byte[] type
2014-12-27 22:14:52 -05:00
);
public static IntPtr IMG_LoadTyped_RW(
IntPtr src,
int freesrc,
string type
) {
return INTERNAL_IMG_LoadTyped_RW(
src,
freesrc,
SDL.UTF8_ToNative(type)
);
}
2014-12-27 22:14:52 -05:00
/* IntPtr refers to an SDL_Texture*, renderer to an SDL_Renderer* */
[DllImport(nativeLibName, EntryPoint = "IMG_LoadTexture", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr INTERNAL_IMG_LoadTexture(
IntPtr renderer,
byte[] file
);
public static IntPtr IMG_LoadTexture(
IntPtr renderer,
string file
) {
return INTERNAL_IMG_LoadTexture(
renderer,
SDL.UTF8_ToNative(file)
);
}
2014-12-27 22:14:52 -05:00
/* renderer refers to an SDL_Renderer*.
* src refers to an SDL_RWops*.
* IntPtr to an SDL_Texture*.
*/
/* THIS IS A PUBLIC RWops FUNCTION! */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr IMG_LoadTexture_RW(
IntPtr renderer,
IntPtr src,
int freesrc
);
/* renderer refers to an SDL_Renderer*.
* src refers to an SDL_RWops*.
* IntPtr to an SDL_Texture*.
*/
/* THIS IS A PUBLIC RWops FUNCTION! */
[DllImport(nativeLibName, EntryPoint = "IMG_LoadTextureTyped_RW", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr INTERNAL_IMG_LoadTextureTyped_RW(
2014-12-27 22:14:52 -05:00
IntPtr renderer,
IntPtr src,
int freesrc,
byte[] type
2014-12-27 22:14:52 -05:00
);
public static IntPtr IMG_LoadTextureTyped_RW(
IntPtr renderer,
IntPtr src,
int freesrc,
string type
) {
return INTERNAL_IMG_LoadTextureTyped_RW(
renderer,
src,
freesrc,
SDL.UTF8_ToNative(type)
);
}
2014-12-27 22:14:52 -05:00
/* IntPtr refers to an SDL_Surface* */
2013-04-17 18:08:38 -04:00
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr IMG_ReadXPMFromArray(
[In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)]
string[] xpm
);
2013-11-18 11:28:32 -05:00
/* surface refers to an SDL_Surface* */
[DllImport(nativeLibName, EntryPoint = "IMG_SavePNG", CallingConvention = CallingConvention.Cdecl)]
private static extern int INTERNAL_IMG_SavePNG(
2013-11-18 11:28:32 -05:00
IntPtr surface,
byte[] file
2013-11-18 11:28:32 -05:00
);
public static int IMG_SavePNG(IntPtr surface, string file)
{
return INTERNAL_IMG_SavePNG(
surface,
SDL.UTF8_ToNative(file)
);
}
2013-11-18 11:28:32 -05:00
2014-03-07 11:02:24 -05:00
/* surface refers to an SDL_Surface*, dst to an SDL_RWops* */
/* THIS IS A PUBLIC RWops FUNCTION! */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int IMG_SavePNG_RW(
IntPtr surface,
IntPtr dst,
int freedst
);
2017-11-18 20:50:56 -05:00
/* surface refers to an SDL_Surface* */
[DllImport(nativeLibName, EntryPoint = "IMG_SaveJPG", CallingConvention = CallingConvention.Cdecl)]
private static extern int INTERNAL_IMG_SaveJPG(
IntPtr surface,
byte[] file,
int quality
);
public static int IMG_SaveJPG(IntPtr surface, string file, int quality)
{
return INTERNAL_IMG_SaveJPG(
surface,
SDL.UTF8_ToNative(file),
quality
);
}
/* surface refers to an SDL_Surface*, dst to an SDL_RWops* */
/* THIS IS A PUBLIC RWops FUNCTION! */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int IMG_SaveJPG_RW(
IntPtr surface,
IntPtr dst,
int freedst,
int quality
);
#region Animated Image Support
/* This region is only available in 2.0.6 or higher. */
public struct IMG_Animation
{
public int w;
public int h;
public IntPtr frames; /* SDL_Surface** */
public IntPtr delays; /* int* */
}
/* IntPtr refers to an IMG_Animation* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr IMG_LoadAnimation(
[In()] [MarshalAs(UnmanagedType.LPStr)]
string file
);
/* IntPtr refers to an IMG_Animation*, src to an SDL_RWops* */
/* THIS IS A PUBLIC RWops FUNCTION! */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr IMG_LoadAnimation_RW(
IntPtr src,
int freesrc
);
/* IntPtr refers to an IMG_Animation*, src to an SDL_RWops* */
/* THIS IS A PUBLIC RWops FUNCTION! */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr IMG_LoadAnimationTyped_RW(
IntPtr src,
int freesrc,
[In()] [MarshalAs(UnmanagedType.LPStr)]
string type
);
/* anim refers to an IMG_Animation* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void IMG_FreeAnimation(IntPtr anim);
/* IntPtr refers to an IMG_Animation*, src to an SDL_RWops* */
/* THIS IS A PUBLIC RWops FUNCTION! */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr IMG_LoadGIFAnimation_RW(IntPtr src);
#endregion
#endregion
2013-04-03 12:15:53 -04:00
}
2013-04-17 03:41:40 -04:00
}