/// <summary> /// Loads an image from a storage into a texture. /// </summary> /// <param name="rwops">The storage.</param> /// <param name="shouldDispose">Whether the storage should be disposed when loading is finished.</param> /// <param name="type">The type of the image.</param> /// <param name="renderer">The renderer.</param> /// <param name="colorKey">The color key for the image.</param> /// <returns>The image.</returns> public static Texture Load(RWOps rwops, bool shouldDispose, string type, Renderer renderer, Color?colorKey = default) { using var loadedSurface = Load(rwops, shouldDispose, type); if (colorKey != null) { loadedSurface.ColorKey = loadedSurface.PixelFormat.Map(colorKey.Value.Red, colorKey.Value.Green, colorKey.Value.Blue, colorKey.Value.Alpha); } return(renderer.CreateTexture(loadedSurface)); }
internal Tileset(Renderer renderer, Size tileSize, Size margin, Size size, string type, byte[] resource, Color?colorKey) { TileSize = tileSize; Margin = margin; Size = size; _colorKey = colorKey; _type = type; Texture = Image.Load(RWOps.CreateReadOnly(resource), true, _type, renderer, _colorKey); }
/// <summary> /// Whether the storage is an PNM image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsPnm(RWOps rwops) => Native.IMG_isPNM(rwops.Native);
/// <summary> /// Whether the storage is an PNG image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsPng(RWOps rwops) => Native.IMG_isPNG(rwops.Pointer);
/// <summary> /// Whether the storage is an PCX image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsPcx(RWOps rwops) => Native.IMG_isPCX(rwops.Native);
/// <summary> /// Load a Webp image from a storage. /// </summary> /// <param name="rwops">The storage.</param> /// <returns>The image.</returns> public static Surface LoadWebp(RWOps rwops) => Surface.PointerToInstanceNotNull(Native.IMG_LoadWEBP_RW(rwops.Native));
/// <summary> /// Saves a surface as a JPG image. /// </summary> /// <param name="surface">The surface.</param> /// <param name="rwops">The storage.</param> /// <param name="shouldDispose">Whether the storage should be disposed when loading is finished.</param> /// <param name="quality">The quality to save as.</param> public static void SaveJpg(Surface surface, RWOps rwops, bool shouldDispose, int quality) => Native.CheckError(Native.IMG_SaveJPG_RW(surface.Native, rwops.Native, shouldDispose, quality));
/// <summary> /// Whether the storage is an XCF image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsXcf(RWOps rwops) => Native.IMG_isXCF(rwops.Native);
/// <summary> /// Whether the storage is an XV image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsXv(RWOps rwops) => Native.IMG_isXV(rwops.Native);
/// <summary> /// Save all the dollar templates. /// </summary> /// <param name="rwops">The storage.</param> public static void SaveAllDollarTemplates(RWOps rwops) => Native.CheckError(Native.SDL_SaveAllDollarTemplates(rwops.Pointer));
/// <summary> /// Save a dollar template. /// </summary> /// <param name="rwops">The storage.</param> public void SaveDollarTemplate(RWOps rwops) => Native.CheckError(Native.SDL_SaveDollarTemplate(Index, rwops.Pointer));
/// <summary> /// Adds game controller mappings from the data source. /// </summary> /// <param name="rwops">The data source.</param> /// <param name="shouldDispose">Whether the data source should be disposed after use.</param> /// <returns>The number of mappings added.</returns> public static int AddMappings(RWOps rwops, bool shouldDispose) => Native.CheckError(Native.SDL_GameControllerAddMappingsFromRW(rwops.Pointer, shouldDispose));
/// <summary> /// Loads a dollar template. /// </summary> /// <param name="device">The touch device.</param> /// <param name="rwops">The storage.</param> public static void LoadDollarTemplates(TouchDevice device, RWOps rwops) => Native.CheckError(Native.SDL_LoadDollarTemplates(device.Index, rwops.Pointer));
/// <summary> /// Loads an image from a storage. /// </summary> /// <param name="rwops">The storage.</param> /// <param name="shouldDispose">Whether the storage should be disposed when loading is finished.</param> /// <param name="type">The type of the image.</param> /// <returns>The image.</returns> public static Surface Load(RWOps rwops, bool shouldDispose, string type) => Surface.PointerToInstanceNotNull(Native.IMG_LoadTyped_RW(rwops.Pointer, shouldDispose, type));
/// <summary> /// Load a Xv image from a storage. /// </summary> /// <param name="rwops">The storage.</param> /// <returns>The image.</returns> public static Surface LoadXv(RWOps rwops) => Surface.PointerToInstanceNotNull(Native.IMG_LoadXV_RW(rwops.Pointer));
/// <summary> /// Whether the storage is an XV image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsXv(RWOps rwops) => Native.IMG_isXV(rwops.Pointer);
/// <summary> /// Whether the storage is an SVG image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsSvg(RWOps rwops) => Native.IMG_isSVG(rwops.Native);
/// <summary> /// Whether the storage is an ICO image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsIco(RWOps rwops) => Native.IMG_isICO(rwops.Native);
/// <summary> /// Whether the storage is an TIFF image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsTif(RWOps rwops) => Native.IMG_isTIF(rwops.Native);
/// <summary> /// Whether the storage is an CUR image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsCur(RWOps rwops) => Native.IMG_isCUR(rwops.Native);
/// <summary> /// Whether the storage is an XPM image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsXpm(RWOps rwops) => Native.IMG_isXPM(rwops.Native);
/// <summary> /// Whether the storage is an BMP image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsBmp(RWOps rwops) => Native.IMG_isBMP(rwops.Native);
/// <summary> /// Whether the storage is an WEBP image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsWebp(RWOps rwops) => Native.IMG_isWEBP(rwops.Native);
/// <summary> /// Loads an image from a storage. /// </summary> /// <param name="rwops">The storage.</param> /// <param name="shouldDispose">Whether the storage should be disposed when loading is finished.</param> /// <returns>The image.</returns> public static Surface Load(RWOps rwops, bool shouldDispose) => Surface.PointerToInstanceNotNull(Native.IMG_Load_RW(rwops.Native, shouldDispose));
/// <summary> /// Saves a surface as a PNG image. /// </summary> /// <param name="surface">The surface.</param> /// <param name="rwops">The storage.</param> /// <param name="shouldDispose">Whether the storage should be disposed when loading is finished.</param> public static void SavePng(Surface surface, RWOps rwops, bool shouldDispose) => Native.CheckError(Native.IMG_SavePNG_RW(surface.Native, rwops.Native, shouldDispose));
/// <summary> /// Loads an image as a texture from a storage. /// </summary> /// <param name="renderer">The renderer.</param> /// <param name="rwops">The storage.</param> /// <param name="shouldDispose">Whether the storage should be disposed when loading is finished.</param> /// <returns>The texture.</returns> public static Texture LoadTexture(Renderer renderer, RWOps rwops, bool shouldDispose) => Texture.PointerToInstanceNotNull(Native.IMG_LoadTexture_RW(renderer.Pointer, rwops.Pointer, shouldDispose));
/// <summary> /// Whether the storage is an JPG image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsJpg(RWOps rwops) => Native.IMG_isJPG(rwops.Native);
/// <summary> /// Whether the storage is an GIF image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsGif(RWOps rwops) => Native.IMG_isGIF(rwops.Pointer);
/// <summary> /// Loads an image as a texture from a storage. /// </summary> /// <param name="renderer">The renderer.</param> /// <param name="rwops">The storage.</param> /// <param name="shouldDispose">Whether the storage should be disposed when loading is finished.</param> /// <param name="type">The type of the image.</param> /// <returns>The texture.</returns> public static Texture LoadTexture(Renderer renderer, RWOps rwops, bool shouldDispose, string type) => Texture.PointerToInstanceNotNull(Native.IMG_LoadTextureTyped_RW(renderer.Native, rwops.Native, shouldDispose, type));
/// <summary> /// Whether the storage is an LBM image. /// </summary> /// <param name="rwops">The storage.</param> /// <returns><c>true</c> if it is, <c>false</c> otherwise.</returns> public static bool IsLbm(RWOps rwops) => Native.IMG_isLBM(rwops.Native);