/// <summary> /// Converts an indexed 256 color image to Rgba32 /// </summary> /// <param name="inputImage"></param> /// <param name="textureFormat"></param> /// <returns></returns> public Image <Rgba32> ConvertTexture(IndexedColor256Image inputImage, TextureFormat textureFormat) { if (inputImage == null) { throw new ArgumentNullException(nameof(inputImage)); } return(InternalConvertTexture(inputImage, textureFormat)); }
/// <summary> /// Loads a texture and creates it using the specified factory /// </summary> /// <param name="inputImage"></param> /// <param name="textureFormat"></param> /// <param name="mipmap"></param> /// <param name="gd"></param> /// <param name="factory"></param> /// <returns></returns> public Texture LoadTexture(IndexedColor256Image inputImage, TextureFormat textureFormat, bool mipmap, GraphicsDevice gd, ResourceFactory factory) { if (inputImage == null) { throw new ArgumentNullException(nameof(inputImage)); } var imageSharpTexture = InternalLoadTexture(inputImage, textureFormat, mipmap); return(imageSharpTexture.CreateDeviceTexture(gd, factory)); }
/// <summary> /// Loads a texture and creates it using the specified graphics device's resource factory /// The texture is added to the given cache /// </summary> /// <param name="inputImage"></param> /// <param name="textureFormat"></param> /// <param name="mipmap"></param> /// <param name="name"></param> /// <param name="gd"></param> /// <param name="cache"></param> /// <returns></returns> public Texture LoadTexture(IndexedColor256Image inputImage, TextureFormat textureFormat, bool mipmap, string name, GraphicsDevice gd, ResourceCache cache) { if (inputImage == null) { throw new ArgumentNullException(nameof(inputImage)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } var imageSharpTexture = InternalLoadTexture(inputImage, textureFormat, mipmap); return(cache.AddTexture2D(gd, gd.ResourceFactory, imageSharpTexture, name)); }
private Image <Rgba32> InternalConvertTexture(IndexedColor256Image inputImage, TextureFormat textureFormat) { var pixels = ImageConversionUtils.ConvertIndexedToRgba32(inputImage, textureFormat); //Alpha tested textures have their fully transparent pixels modified so samplers won't sample the color used and blend it //This stops the color from bleeding through if (textureFormat == TextureFormat.AlphaTest || textureFormat == TextureFormat.IndexAlpha) { ImageConversionUtils.BoxFilter3x3(pixels, inputImage.Width, inputImage.Height); } //Rescale image to nearest power of 2 (var scaledWidth, var scaledHeight) = ComputeScaledSize((uint)inputImage.Width, (uint)inputImage.Height); var scaledPixels = ImageConversionUtils.ResampleImage(new Span <Rgba32>(pixels), inputImage.Width, inputImage.Height, (int)scaledWidth, (int)scaledHeight); return(Image.LoadPixelData(scaledPixels, (int)scaledWidth, (int)scaledHeight)); }
private ImageSharpTexture InternalLoadTexture(IndexedColor256Image inputImage, TextureFormat textureFormat, bool mipmap) { var image = InternalConvertTexture(inputImage, textureFormat); return(new ImageSharpTexture(image, mipmap)); }