using System;
using System.Runtime.InteropServices;

namespace SDL2
{
	public static class SDL_image
	{
		public static void SDL_IMAGE_VERSION(out SDL.SDL_version X)
		{
			X.major = 2;
			X.minor = 0;
			X.patch = 2;
		}

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl, EntryPoint = "IMG_Linked_Version")]
		private static extern IntPtr INTERNAL_IMG_Linked_Version();

		public static SDL.SDL_version IMG_Linked_Version()
		{
			return (SDL.SDL_version)Marshal.PtrToStructure(SDL_image.INTERNAL_IMG_Linked_Version(), typeof(SDL.SDL_version));
		}

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl)]
		public static extern int IMG_Init(SDL_image.IMG_InitFlags flags);

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl)]
		public static extern void IMG_Quit();

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl, EntryPoint = "IMG_Load")]
		private static extern IntPtr INTERNAL_IMG_Load(byte[] file);

		public static IntPtr IMG_Load(string file)
		{
			return SDL_image.INTERNAL_IMG_Load(SDL.UTF8_ToNative(file));
		}

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl)]
		public static extern IntPtr IMG_Load_RW(IntPtr src, int freesrc);

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl, EntryPoint = "IMG_LoadTyped_RW")]
		private static extern IntPtr INTERNAL_IMG_LoadTyped_RW(IntPtr src, int freesrc, byte[] type);

		public static IntPtr IMG_LoadTyped_RW(IntPtr src, int freesrc, string type)
		{
			return SDL_image.INTERNAL_IMG_LoadTyped_RW(src, freesrc, SDL.UTF8_ToNative(type));
		}

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl, EntryPoint = "IMG_LoadTexture")]
		private static extern IntPtr INTERNAL_IMG_LoadTexture(IntPtr renderer, byte[] file);

		public static IntPtr IMG_LoadTexture(IntPtr renderer, string file)
		{
			return SDL_image.INTERNAL_IMG_LoadTexture(renderer, SDL.UTF8_ToNative(file));
		}

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl)]
		public static extern IntPtr IMG_LoadTexture_RW(IntPtr renderer, IntPtr src, int freesrc);

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl, EntryPoint = "IMG_LoadTextureTyped_RW")]
		private static extern IntPtr INTERNAL_IMG_LoadTextureTyped_RW(IntPtr renderer, IntPtr src, int freesrc, byte[] type);

		public static IntPtr IMG_LoadTextureTyped_RW(IntPtr renderer, IntPtr src, int freesrc, string type)
		{
			return SDL_image.INTERNAL_IMG_LoadTextureTyped_RW(renderer, src, freesrc, SDL.UTF8_ToNative(type));
		}

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl)]
		public static extern IntPtr IMG_ReadXPMFromArray([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] [In] string[] xpm);

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl, EntryPoint = "IMG_SavePNG")]
		private static extern int INTERNAL_IMG_SavePNG(IntPtr surface, byte[] file);

		public static int IMG_SavePNG(IntPtr surface, string file)
		{
			return SDL_image.INTERNAL_IMG_SavePNG(surface, SDL.UTF8_ToNative(file));
		}

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl)]
		public static extern int IMG_SavePNG_RW(IntPtr surface, IntPtr dst, int freedst);

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl, EntryPoint = "IMG_SaveJPG")]
		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 SDL_image.INTERNAL_IMG_SaveJPG(surface, SDL.UTF8_ToNative(file), quality);
		}

		[DllImport("SDL2_image", CallingConvention = CallingConvention.Cdecl)]
		public static extern int IMG_SaveJPG_RW(IntPtr surface, IntPtr dst, int freedst, int quality);

		private const string nativeLibName = "SDL2_image";

		public const int SDL_IMAGE_MAJOR_VERSION = 2;

		public const int SDL_IMAGE_MINOR_VERSION = 0;

		public const int SDL_IMAGE_PATCHLEVEL = 2;

		[Flags]
		public enum IMG_InitFlags
		{
			IMG_INIT_JPG = 1,
			IMG_INIT_PNG = 2,
			IMG_INIT_TIF = 4,
			IMG_INIT_WEBP = 8
		}
	}
}
