/// <summary> /// Saves the specified <see cref="TexImage"/> into a file with the specified format. /// </summary> /// <param name="image">The image.</param> /// <param name="fileName">Name of the file.</param> /// <param name="format">The new format.</param> /// <param name="minimumMipMapSize">Minimum size of the mip map.</param> public void Save(TexImage image, String fileName, PixelFormat format, int minimumMipMapSize = 1) { if (fileName == null || fileName.Equals("")) { Log.Error("No file name entered."); throw new TextureToolsException("No file name entered."); } if (minimumMipMapSize < 0) { Log.Error("The minimup Mipmap size can't be negative. Put 0 or 1 for a complete Mipmap chain."); throw new TextureToolsException("The minimup Mipmap size can't be negative. Put 0 or 1 for a complete Mipmap chain."); } if (image.Format != format && format.IsCompressed() && !image.Format.IsCompressed()) { TexImage workingImage = (TexImage)image.Clone(); Compress(workingImage, format); ExecuteRequest(workingImage, new ExportRequest(fileName, minimumMipMapSize)); workingImage.Dispose(); } else if (image.Format != format && format.IsCompressed()) { TexImage workingImage = (TexImage)image.Clone(); Decompress(workingImage, image.Format.IsSRgb()); Compress(workingImage, format); ExecuteRequest(workingImage, new ExportRequest(fileName, minimumMipMapSize)); workingImage.Dispose(); } else { ExecuteRequest(image, new ExportRequest(fileName, minimumMipMapSize)); } }
/// <summary> /// Create a new image from the alpha component of a reference image. /// </summary> /// <param name="texImage">The image from which to take the alpha</param> /// <returns>The <see cref="TexImage"/> containing the alpha component as rgb color. Note: it is the user responsibility to dispose the returned image.</returns> public unsafe TexImage CreateImageFromAlphaComponent(TexImage texImage) { if (texImage.Dimension != TexImage.TextureDimension.Texture2D || texImage.Format.IsCompressed()) throw new NotImplementedException(); var alphaImage = (TexImage)texImage.Clone(true); var rowPtr = alphaImage.Data; for (int i = 0; i < alphaImage.Height; i++) { var pByte = (byte*)rowPtr; for (int x = 0; x < alphaImage.Width; x++) { pByte[0] = pByte[3]; pByte[1] = pByte[3]; pByte[2] = pByte[3]; pByte += 4; } rowPtr = IntPtr.Add(rowPtr, alphaImage.RowPitch); } return alphaImage; }
/// <summary> /// Create a new image from the alpha component of a reference image. /// </summary> /// <param name="texImage">The image from which to take the alpha</param> /// <returns>The <see cref="TexImage"/> containing the alpha component as rgb color. Note: it is the user responsibility to dispose the returned image.</returns> public unsafe TexImage CreateImageFromAlphaComponent(TexImage texImage) { var alphaImage = (TexImage)texImage.Clone(true); var rowPtr = alphaImage.Data; for (int i = 0; i < alphaImage.Height; i++) { var pByte = (byte*)rowPtr; for (int x = 0; x < alphaImage.Width; x++) { pByte[0] = pByte[3]; pByte[1] = pByte[3]; pByte[2] = pByte[3]; pByte += 4; } rowPtr = IntPtr.Add(rowPtr, alphaImage.RowPitch); } return alphaImage; }