Exemplo n.º 1
0
 public static int ComputeSlicePitch(int width, int height, DXGI_FORMAT format)
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         return((int)TexconvNative.ComputeSlicePitch(format, width, height));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Exemplo n.º 2
0
 public static DDSMetadata GetMetadataFromDDSMemory(byte[] buffer)
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         var md  = TexconvNative.GetMetadataFromDDSMemory(buffer, DDSFLAGS.DDS_FLAGS_NONE);
         var bpp = TexconvNative.BitsPerPixel(md.format);
         return(new DDSMetadata(md, (uint)bpp, true));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Exemplo n.º 3
0
        public static bool ConvertFromDdsAndSave(Stream ms, string outfilename, ESaveFileTypes filetype, bool vflip = false, bool hflip = false)
        {
            byte[] rentedBuffer = null;
            try
            {
                var offset = 0;

                var len = checked ((int)ms.Length);
                rentedBuffer = ArrayPool <byte> .Shared.Rent(len);

                int readBytes;
                while (offset < len &&
                       (readBytes = ms.Read(rentedBuffer, offset, len - offset)) > 0)
                {
                    offset += readBytes;
                }

                var outDir = new FileInfo(outfilename).Directory.FullName;
                Directory.CreateDirectory(outDir);
                var fileName  = Path.GetFileNameWithoutExtension(outfilename);
                var extension = filetype.ToString().ToLower();
                var newpath   = Path.Combine(outDir, $"{fileName}.{extension}");

                //TexconvNative.ConvertAndSaveDdsImage(rentedBuffer, newpath, filetype, vflip, hflip);
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    var buffer = Array.Empty <byte>();
                    using (var blob = new ManagedBlob())
                    {
                        var l = TexconvNative.ConvertFromDds(rentedBuffer, blob.GetBlob(), filetype, vflip, hflip);
                        buffer = blob.GetBytes();
                    }
                    File.WriteAllBytes(newpath, buffer);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            finally
            {
                if (rentedBuffer is object)
                {
                    ArrayPool <byte> .Shared.Return(rentedBuffer);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Converts texture stream with given extension stream to dds
        /// </summary>
        public static byte[] ConvertToDds(Stream stream, EUncookExtension inExtension, DXGI_FORMAT?outFormat = null, bool vflip = false, bool hflip = false)
        {
            if (inExtension == EUncookExtension.dds)
            {
                throw new NotSupportedException("texture to convert to dds must not be dds iteslf");
            }

            byte[] rentedBuffer = null;
            try
            {
                var offset = 0;

                var len = checked ((int)stream.Length);
                rentedBuffer = ArrayPool <byte> .Shared.Rent(len);

                int readBytes;
                while (offset < len &&
                       (readBytes = stream.Read(rentedBuffer, offset, len - offset)) > 0)
                {
                    offset += readBytes;
                }

                var format = outFormat ?? DXGI_FORMAT.DXGI_FORMAT_UNKNOWN;

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    var buffer = Array.Empty <byte>();
                    using (var blob = new ManagedBlob())
                    {
                        var l = TexconvNative.ConvertToDds(rentedBuffer, blob.GetBlob(), ToSaveFormat(inExtension),
                                                           format, vflip, hflip);
                        buffer = blob.GetBytes();
                    }
                    return(buffer);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            finally
            {
                if (rentedBuffer is object)
                {
                    ArrayPool <byte> .Shared.Return(rentedBuffer);
                }
            }
        }
Exemplo n.º 5
0
        public static DDSMetadata GetMetadataFromTGAFile(string path)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                var md  = TexconvNative.GetMetadataFromTGAFile(path, TGA_FLAGS.TGA_FLAGS_NONE);
                var bpp = TexconvNative.BitsPerPixel(md.format);
                return(new DDSMetadata(md, (uint)bpp, true));
            }
            else
            {
                //using (var image = Image.Load(path))
                //{

                //}
                throw new NotImplementedException();
            }
        }