/// <summary> /// Compresses the specified image. /// </summary> /// <param name="image">The image.</param> /// <param name="libraryData">The library data.</param> /// <param name="request">The request.</param> /// <exception cref="TexLibraryException">Compression failed</exception> private void Compress(TexImage image, AtitcTextureLibraryData libraryData, CompressingRequest request) { Log.Info("Converting/Compressing with " + request.Format + " ..."); int totalSize = 0; Texture[] texOut = new Texture[image.SubImageArray.Length]; int pitch, slice; // Setting the new Texture array that will contained the compressed data for (int i = 0; i < libraryData.Textures.Length; ++i) { Tools.ComputePitch(request.Format, libraryData.Textures[i].dwWidth, libraryData.Textures[i].dwHeight, out pitch, out slice); texOut[i] = new Texture(libraryData.Textures[i].dwWidth, libraryData.Textures[i].dwHeight, pitch, RetrieveNativeFormat(request.Format), 0, IntPtr.Zero); texOut[i].dwDataSize = Utilities.CalculateBufferSize(out texOut[i]); totalSize += texOut[i].dwDataSize; } // Allocating memory to store the compressed data image.Data = Marshal.AllocHGlobal(totalSize); libraryData.Options = new CompressOptions(false, 0, 0, 0, false, false, 0, false, Speed.ATI_TC_Speed_Normal); Result res; int offset = 0; // Compressing each sub image into the new allocated memory for (int i = 0; i < libraryData.Textures.Length; ++i) { texOut[i].pData = new IntPtr(image.Data.ToInt64() + offset); offset += texOut[i].dwDataSize; res = Utilities.ConvertTexture(out libraryData.Textures[i], out texOut[i], out libraryData.Options); if (res != Result.ATI_TC_OK) { Log.Error("Compression failed: " + res); throw new TextureToolsException("Compression failed: " + res); } libraryData.Textures[i] = texOut[i]; } // Deleting old uncompressed data if (image.DisposingLibrary != null) { image.DisposingLibrary.Dispose(image); } // Assigning the new compressed data to the current instance of <see cref="LibraryData" /> libraryData.Data = image.Data; // udpating various features image.DataSize = totalSize; image.RowPitch = libraryData.Textures[0].dwPitch; image.Format = request.Format; image.DisposingLibrary = this; }
public static void DeleteData(out Texture pTexture) { atitcDeleteData(out pTexture); }
/// <summary> /// Decompresses the specified image. /// </summary> /// <param name="image">The image.</param> /// <param name="libraryData">The library data.</param> /// <param name="request">The decompression request</param> /// <exception cref="TextureToolsException">Decompression failed</exception> private void Decompress(TexImage image, AtitcTextureLibraryData libraryData, DecompressingRequest request) { Log.Info("Decompressing texture ..."); int totalSize = 0; Texture[] texOut = new Texture[image.SubImageArray.Length]; int rowPitch, slicePitch; // Setting the new Texture array that will contained the uncompressed data for (int i = 0; i < libraryData.Textures.Length; ++i) { Tools.ComputePitch(request.DecompressedFormat, libraryData.Textures[i].dwWidth, libraryData.Textures[i].dwHeight, out rowPitch, out slicePitch); texOut[i] = new Texture(libraryData.Textures[i].dwWidth, libraryData.Textures[i].dwHeight, libraryData.Textures[i].dwWidth * 4, Format.ATI_TC_FORMAT_ARGB_8888, 0, IntPtr.Zero); texOut[i].dwDataSize = Utilities.CalculateBufferSize(out texOut[i]); totalSize += texOut[i].dwDataSize; } // Allocating memory to store the uncompressed data image.Data = Marshal.AllocHGlobal(totalSize); libraryData.Options = new CompressOptions(false, 0, 0, 0, false, false, 0, false, Speed.ATI_TC_Speed_Normal); Result res; long offset = 0; // Decompressing each sub image into the new allocated memory for (int i = 0; i < libraryData.Textures.Length; ++i) { texOut[i].pData = new IntPtr(image.Data.ToInt64() + offset); offset += texOut[i].dwDataSize; res = Utilities.ConvertTexture(out libraryData.Textures[i], out texOut[i], out libraryData.Options); if (res != Result.ATI_TC_OK) { Log.Error("Decompression failed: " + res); throw new TextureToolsException("Decompression failed: " + res); } libraryData.Textures[i] = texOut[i]; } // Deleting old compressed data if (image.DisposingLibrary != null) image.DisposingLibrary.Dispose(image); // udpating various features libraryData.Data = image.Data; image.DataSize = totalSize; image.RowPitch = libraryData.Textures[0].dwPitch; image.Format = request.DecompressedFormat; image.DisposingLibrary = this; }
public static Result ConvertTexture(out Texture pSourceTexture, out Texture pDestTexture, out CompressOptions pOptions) { return atitcConvertTexture(out pSourceTexture, out pDestTexture, out pOptions); }
public static int CalculateBufferSize(out Texture pTexture) { return atitcCalculateBufferSize(out pTexture); }
private extern static Result atitcConvertTexture(out Texture pSourceTexture, out Texture pDestTexture, out CompressOptions pOptions);
private extern static void atitcDeleteData(out Texture pTexture);
private extern static int atitcCalculateBufferSize(out Texture pTexture);