Example #1
0
        /// <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;
        }
Example #2
0
        public void Dispose(TexImage image)
        {
            AtitcTextureLibraryData libraryData = (AtitcTextureLibraryData)image.LibraryData[this];

            if (libraryData.Data != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(libraryData.Data);
            }
        }
Example #3
0
        /// <summary>
        /// Decompresses the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="libraryData">The library data.</param>
        /// <exception cref="TexLibraryException">Decompression failed</exception>
        private void Decompress(TexImage image, AtitcTextureLibraryData libraryData)
        {
            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(SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm, 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           = SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm;
            image.DisposingLibrary = this;
        }
Example #4
0
        public void StartLibrary(TexImage image)
        {
            AtitcTextureLibraryData libraryData = new AtitcTextureLibraryData();
            image.LibraryData[this] = libraryData;

            libraryData.Textures = new Texture[image.SubImageArray.Length];

            int bpp = (int)image.Format.GetBPP();

            for (int i = 0; i < image.SubImageArray.Length; ++i)
            {
                libraryData.Textures[i] = new Texture(image.SubImageArray[i].Width, image.SubImageArray[i].Height, image.SubImageArray[i].RowPitch, RetrieveNativeFormat(image.Format), image.SubImageArray[i].DataSize, image.SubImageArray[i].Data);
            }

            libraryData.Data = IntPtr.Zero;
        }
Example #5
0
        public void StartLibrary(TexImage image)
        {
            AtitcTextureLibraryData libraryData = new AtitcTextureLibraryData();
            image.LibraryData[this] = libraryData;

            libraryData.Textures = new Texture[image.SubImageArray.Length];

            var bpp = Paradox.Graphics.PixelFormatExtensions.SizeInBits(image.Format);

            for (int i = 0; i < image.SubImageArray.Length; ++i)
            {
                libraryData.Textures[i] = new Texture(image.SubImageArray[i].Width, image.SubImageArray[i].Height, image.SubImageArray[i].RowPitch, RetrieveNativeFormat(image.Format), image.SubImageArray[i].DataSize, image.SubImageArray[i].Data);
            }

            libraryData.Data = IntPtr.Zero;
        }
Example #6
0
        public void StartLibrary(TexImage image)
        {
            AtitcTextureLibraryData libraryData = new AtitcTextureLibraryData();

            image.LibraryData[this] = libraryData;

            libraryData.Textures = new Texture[image.SubImageArray.Length];

            var bpp = Xenko.Graphics.PixelFormatExtensions.SizeInBits(image.Format);

            for (int i = 0; i < image.SubImageArray.Length; ++i)
            {
                libraryData.Textures[i] = new Texture(image.SubImageArray[i].Width, image.SubImageArray[i].Height, image.SubImageArray[i].RowPitch, RetrieveNativeFormat(image.Format), image.SubImageArray[i].DataSize, image.SubImageArray[i].Data);
            }

            libraryData.Data = IntPtr.Zero;
        }
Example #7
0
        public void StartLibrary(TexImage image)
        {
            AtitcTextureLibraryData libraryData = new AtitcTextureLibraryData();

            image.LibraryData[this] = libraryData;

            libraryData.Textures = new Texture[image.SubImageArray.Length];

            int bpp = (int)Tools.GetBPP(image.Format);

            for (int i = 0; i < image.SubImageArray.Length; ++i)
            {
                libraryData.Textures[i] = new Texture(image.SubImageArray[i].Width, image.SubImageArray[i].Height, image.SubImageArray[i].RowPitch, RetrieveNativeFormat(image.Format), image.SubImageArray[i].DataSize, image.SubImageArray[i].Data);
            }

            libraryData.Data = IntPtr.Zero;
        }
Example #8
0
        public void EndLibrary(TexImage image)
        {
            if (!image.LibraryData.ContainsKey(this))
            {
                return;
            }
            AtitcTextureLibraryData libraryData = (AtitcTextureLibraryData)image.LibraryData[this];

            for (int i = 0; i < libraryData.Textures.Length; ++i)
            {
                image.SubImageArray[i].Data       = libraryData.Textures[i].pData;
                image.SubImageArray[i].DataSize   = libraryData.Textures[i].dwDataSize;
                image.SubImageArray[i].Width      = libraryData.Textures[i].dwWidth;
                image.SubImageArray[i].Height     = libraryData.Textures[i].dwHeight;
                image.SubImageArray[i].RowPitch   = libraryData.Textures[i].dwPitch;
                image.SubImageArray[i].SlicePitch = libraryData.Textures[i].dwDataSize;
            }
        }
Example #9
0
        public void Execute(TexImage image, IRequest request)
        {
            AtitcTextureLibraryData libraryData = (AtitcTextureLibraryData)image.LibraryData[this];

            switch (request.Type)
            {
            case RequestType.Compressing:
                Compress(image, libraryData, (CompressingRequest)request);
                break;

            case RequestType.Decompressing:
                Decompress(image, libraryData, (DecompressingRequest)request);
                break;

            default:
                Log.Error("DxtTexLib (DirectXTex) can't handle this request: " + request.Type);
                throw new TextureToolsException("DxtTexLib (DirectXTex) can't handle this request: " + request.Type);
            }
        }
Example #10
0
        /// <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;
        }