コード例 #1
0
        protected override Tuple <Image, object> GetImage()
        {
            var source = HasChanges ? ChangesFile : Path;

            _currentDDS = TexHelper.Instance.LoadFromDDSFile(source, DDS_FLAGS.NONE);

            var codec = TexHelper.Instance.GetWICCodec(WICCodecs.PNG);

            var metadata = _currentDDS.GetMetadata();

            ScratchImage decompressed;

            try
            {
                decompressed = _currentDDS.Decompress(DXGI_FORMAT.UNKNOWN);
            }
            catch (ArgumentException e)
            {
                decompressed = _currentDDS;
            }

            try
            {
                var imageStream = decompressed.SaveToWICMemory(0, WIC_FLAGS.NONE, codec);
                var image       = Image.FromStream(imageStream);

                var properties = new TexMetadataView(metadata);

                return(new Tuple <Image, object>(image, properties));
            }
            catch (Exception e)
            {
                return(new Tuple <Image, object>(null, null));
            }
        }
コード例 #2
0
        protected override object GetImageProperties(object genericImage)
        {
            if (!(genericImage is ScratchImage scratchImage))
            {
                return(null);
            }

            TexMetadata metadata   = scratchImage.GetMetadata();
            var         properties = new TexMetadataView(metadata);

            return(properties);
        }
コード例 #3
0
        protected override Tuple <Image, object> GetImage()
        {
            if (!HasChanges)
            {
                var crunchedData = System.IO.File.ReadAllBytes(Path);
                var data         = CrnDecompress(crunchedData);

                System.IO.File.WriteAllBytes(ChangesFile, data);
            }

            _currentDDS = TexHelper.Instance.LoadFromDDSFile(ChangesFile, DDS_FLAGS.NONE);

            var codec = TexHelper.Instance.GetWICCodec(WICCodecs.PNG);

            var metadata = _currentDDS.GetMetadata();

            ScratchImage decompressed;

            try
            {
                decompressed = _currentDDS.Decompress(DXGI_FORMAT.UNKNOWN);
            }
            catch (ArgumentException e)
            {
                decompressed = _currentDDS;
            }

            try
            {
                var imageStream = decompressed.SaveToWICMemory(0, WIC_FLAGS.NONE, codec);
                var image       = Image.FromStream(imageStream);

                var properties = new TexMetadataView(metadata);

                return(new Tuple <Image, object>(image, properties));
            }
            catch (Exception e)
            {
                return(new Tuple <Image, object>(null, null));
            }
            finally
            {
                decompressed.Dispose();
            }
        }
コード例 #4
0
        protected override Tuple <Image, object> GetImage()
        {
            var source = HasChanges ? ChangesFile : Path;

            var data = RemoveHeaders(source);

            var unmanagedPointer = Marshal.AllocHGlobal(data.Length);

            Marshal.Copy(data, 0, unmanagedPointer, data.Length);

            _currentDDS = TexHelper.Instance.LoadFromDDSMemory(unmanagedPointer, data.Length, DDS_FLAGS.NONE);

            Marshal.FreeHGlobal(unmanagedPointer);

            var codec = TexHelper.Instance.GetWICCodec(WICCodecs.PNG);

            var metadata = _currentDDS.GetMetadata();

            ScratchImage decompressed;

            try
            {
                decompressed = _currentDDS.Decompress(DXGI_FORMAT.UNKNOWN);
            }
            catch (ArgumentException e)
            {
                decompressed = _currentDDS;
            }

            var imageStream = decompressed.SaveToWICMemory(0, WIC_FLAGS.NONE, codec);
            var image       = Image.FromStream(imageStream);

            var properties = new TexMetadataView(metadata);

            return(new Tuple <Image, object>(image, properties));
        }