Beispiel #1
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>
        public void Decompress(TexImage image, PvrTextureLibraryData libraryData, DecompressingRequest request)
        {
            Log.Info("Decompressing texture ...");

            if (!Utilities.Transcode(libraryData.Texture, PixelType.Standard8PixelType, libraryData.Header.GetChannelType(), libraryData.Header.GetColourSpace(), ECompressorQuality.ePVRTCNormal, true))
            {
                Log.Error("Decompression failed!");
                throw new TextureToolsException("Decompression failed!");
            }

            image.Format = request.DecompressedFormat;

            int pitch,slice;
            Tools.ComputePitch(image.Format, image.Width, image.Height, out pitch, out slice);
            image.RowPitch = pitch;
            image.SlicePitch = slice;
 
            UpdateImage(image, libraryData);
        }
Beispiel #2
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, DxtTextureLibraryData libraryData, DecompressingRequest request)
        {
            Log.Info("Decompressing texture ...");

            // determine the output format to avoid any sRGB/RGB conversions (only decompression, no conversion)
            var outputFormat = !((PixelFormat)libraryData.Metadata.format).IsSRgb() ? request.DecompressedFormat.ToNonSRgb() : request.DecompressedFormat.ToSRgb();

            var scratchImage = new ScratchImage();
            var hr = Utilities.Decompress(libraryData.DxtImages, libraryData.DxtImages.Length, ref libraryData.Metadata, (DXGI_FORMAT)outputFormat, scratchImage);

            if (hr != HRESULT.S_OK)
            {
                Log.Error("Decompression failed: " + hr);
                throw new TextureToolsException("Decompression failed: " + hr);
            }

            // Freeing Memory
            if (image.DisposingLibrary != null) image.DisposingLibrary.Dispose(image);
            
            libraryData.Image = scratchImage;
            libraryData.DxtImages = libraryData.Image.GetImages();
            libraryData.Metadata = libraryData.Image.metadata;
            image.DisposingLibrary = this;

            // adapt the image format based on desired output format
            ChangeDxtImageType(libraryData, (DXGI_FORMAT)request.DecompressedFormat);

            UpdateImage(image, libraryData);
        }
Beispiel #3
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;
        }