Ejemplo n.º 1
0
        private int GetImageSizeDefault()
        {
            var format = Platform.OutputFormat;

            int  totalSize = 0;
            uint bpp       = TextureFormatHelper.GetBytesPerPixel(format);

            for (int arrayLevel = 0; arrayLevel < ArrayCount; arrayLevel++)
            {
                for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
                {
                    uint width  = (uint)Math.Max(1, Width >> mipLevel);
                    uint height = (uint)Math.Max(1, Height >> mipLevel);

                    uint size = width * height * bpp;
                    if (IsBCNCompressed())
                    {
                        size = ((width + 3) >> 2) * ((Height + 3) >> 2) * bpp;
                        if (size < bpp)
                        {
                            size = bpp;
                        }
                    }

                    totalSize += (int)size;
                }
            }
            return(totalSize);
        }
Ejemplo n.º 2
0
        public void Export(STGenericTexture texture, TextureExportSettings settings, string filePath)
        {
            List <Surface> surfaces = texture.GetSurfaces(settings.ArrayLevel, settings.ExportArrays);

            var format = texture.Platform.OutputFormat;

            ASTC atsc = new ASTC();

            atsc.Width     = texture.Width;
            atsc.Height    = texture.Height;
            atsc.Depth     = texture.Depth;
            atsc.BlockDimX = (byte)TextureFormatHelper.GetBlockWidth(format);
            atsc.BlockDimY = (byte)TextureFormatHelper.GetBlockHeight(format);
            atsc.BlockDimZ = (byte)TextureFormatHelper.GetBlockDepth(format);
            atsc.DataBlock = ByteUtils.CombineArray(surfaces[0].mipmaps.ToArray());
            atsc.Save(new System.IO.FileStream(filePath, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite));
        }
Ejemplo n.º 3
0
        public static List <STGenericTexture.Surface> GetArrayFaces(DDS dds, uint Length, int DepthLevel = 0)
        {
            int Dx10Size = dds.IsDX10 ? 20 : 0;

            using (FileReader reader = new FileReader(dds.FileInfo.FilePath)) {
                reader.TemporarySeek((int)(dds.MainHeader.Size + Dx10Size), SeekOrigin.Begin);
                var format = dds.Platform.OutputFormat;

                var  Surfaces   = new List <STGenericTexture.Surface>();
                uint formatSize = TextureFormatHelper.GetBytesPerPixel(format);

                bool isBlock = TextureFormatHelper.IsBCNCompressed(format);
                uint Offset  = 0;

                if (dds.Depth > 1 && dds.MipCount > 1)
                {
                    var Surface = new STGenericTexture.Surface();

                    uint MipWidth = dds.Width, MipHeight = dds.Height;
                    for (int j = 0; j < dds.MipCount; ++j)
                    {
                        MipWidth  = (uint)Math.Max(1, dds.Width >> j);
                        MipHeight = (uint)Math.Max(1, dds.Height >> j);
                        for (byte d = 0; d < dds.Depth; ++d)
                        {
                            uint size = (MipWidth * MipHeight); //Total pixels
                            if (isBlock)
                            {
                                size = ((MipWidth + 3) >> 2) * ((MipHeight + 3) >> 2) * formatSize;
                                if (size < formatSize)
                                {
                                    size = formatSize;
                                }
                            }
                            else
                            {
                                size = (uint)(size * (TextureFormatHelper.GetBytesPerPixel(format))); //Bytes per pixel
                            }


                            //Only add mips to the depth level needed
                            if (d == DepthLevel)
                            {
                                Surface.mipmaps.Add(reader.getSection((int)Offset, (int)size));
                            }

                            Offset += size;

                            //Add the current depth level and only once
                            if (d == DepthLevel && j == 0)
                            {
                                Surfaces.Add(Surface);
                            }
                        }
                    }
                }
                else
                {
                    for (byte d = 0; d < dds.Depth; ++d)
                    {
                        for (byte i = 0; i < Length; ++i)
                        {
                            var Surface = new STGenericTexture.Surface();

                            uint MipWidth = dds.Width, MipHeight = dds.Height;
                            for (int j = 0; j < dds.MipCount; ++j)
                            {
                                MipWidth  = (uint)Math.Max(1, dds.Width >> j);
                                MipHeight = (uint)Math.Max(1, dds.Height >> j);

                                uint size = (MipWidth * MipHeight); //Total pixels
                                if (isBlock)
                                {
                                    size = ((MipWidth + 3) >> 2) * ((MipHeight + 3) >> 2) * formatSize;
                                    if (size < formatSize)
                                    {
                                        size = formatSize;
                                    }
                                }
                                else
                                {
                                    size = (uint)(size * (TextureFormatHelper.GetBytesPerPixel(format))); //Bytes per pixel
                                }

                                Surface.mipmaps.Add(reader.getSection((int)Offset, (int)size));
                                Offset += size;
                            }

                            if (d == DepthLevel)
                            {
                                Surfaces.Add(Surface);
                            }
                        }
                    }
                }

                return(Surfaces);
            }
        }
Ejemplo n.º 4
0
        public bool IsBCNCompressed()
        {
            var format = Platform.OutputFormat;

            return(TextureFormatHelper.IsBCNCompressed(format));
        }
Ejemplo n.º 5
0
        public uint GetBytesPerPixel()
        {
            var format = Platform.OutputFormat;

            return(TextureFormatHelper.GetBytesPerPixel(format));
        }
Ejemplo n.º 6
0
        public uint GetBlockDepth()
        {
            var format = Platform.OutputFormat;

            return(TextureFormatHelper.GetBlockDepth(format));
        }
Ejemplo n.º 7
0
        public void SetFlags(TexFormat format, bool isDX10, bool isCubemap)
        {
            var dxgiFormat = (DXGI_FORMAT)format;

            MainHeader.Flags = (uint)(DDSD.CAPS | DDSD.HEIGHT | DDSD.WIDTH | DDSD.PIXELFORMAT | DDSD.MIPMAPCOUNT | DDSD.LINEARSIZE);
            PfHeader.Caps1   = (uint)DDSCAPS.TEXTURE;
            if (MainHeader.MipCount > 1)
            {
                PfHeader.Caps1 |= (uint)(DDSCAPS.COMPLEX | DDSCAPS.MIPMAP);
            }

            if (isCubemap)
            {
                PfHeader.Caps2 |= (uint)(DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_POSITIVEX | DDSCAPS2.CUBEMAP_NEGATIVEX |
                                         DDSCAPS2.CUBEMAP_POSITIVEY | DDSCAPS2.CUBEMAP_NEGATIVEY |
                                         DDSCAPS2.CUBEMAP_POSITIVEZ | DDSCAPS2.CUBEMAP_NEGATIVEZ);
            }
            if (isDX10)
            {
                PfHeader.Flags  = (uint)DDPF.FOURCC;
                PfHeader.FourCC = FOURCC_DX10;

                Dx10Header.DxgiFormat = (uint)dxgiFormat;
                if (isCubemap)
                {
                    Dx10Header.ArrayCount = (ArrayCount / 6);
                    Dx10Header.MiscFlags1 = 0x4;
                }
                return;
            }

            var masks = DDS_RGBA.GetMasks(format);

            PfHeader.RBitMask = masks[0];
            PfHeader.GBitMask = masks[1];
            PfHeader.BBitMask = masks[2];
            PfHeader.ABitMask = masks[3];

            PfHeader.RgbBitCount = 0x8 * TextureFormatHelper.GetBytesPerPixel(format);
            PfHeader.Flags       = (uint)(DDPF.RGB | DDPF.ALPHAPIXELS);

            switch (format)
            {
            case TexFormat.RGBA8_UNORM:
            case TexFormat.RGB8_SRGB:
                break;

            case TexFormat.RGB565_UNORM:
                PfHeader.Flags = (uint)(DDPF.RGB | DDPF.ALPHAPIXELS);
                break;

            case TexFormat.BC1_SRGB:
            case TexFormat.BC1_UNORM:
                PfHeader.Flags  = (uint)DDPF.FOURCC;
                PfHeader.FourCC = FOURCC_DXT1;
                break;

            case TexFormat.BC2_SRGB:
            case TexFormat.BC2_UNORM:
                PfHeader.Flags  = (uint)DDPF.FOURCC;
                PfHeader.FourCC = FOURCC_DXT3;
                break;

            case TexFormat.BC3_SRGB:
            case TexFormat.BC3_UNORM:
                PfHeader.Flags  = (uint)DDPF.FOURCC;
                PfHeader.FourCC = FOURCC_DXT5;
                break;

            case TexFormat.BC4_UNORM:
                PfHeader.Flags  = (uint)DDPF.FOURCC;
                PfHeader.FourCC = FOURCC_BC4U;
                break;

            case TexFormat.BC4_SNORM:
                PfHeader.Flags  = (uint)DDPF.FOURCC;
                PfHeader.FourCC = FOURCC_BC4S;
                break;

            case TexFormat.BC5_UNORM:
                PfHeader.Flags  = (uint)DDPF.FOURCC;
                PfHeader.FourCC = FOURCC_BC5U;
                break;

            case TexFormat.BC5_SNORM:
                PfHeader.Flags  = (uint)DDPF.FOURCC;
                PfHeader.FourCC = FOURCC_BC5S;
                break;

            case TexFormat.BC6H_SF16:
            case TexFormat.BC6H_UF16:
            case TexFormat.BC7_UNORM:
            case TexFormat.BC7_SRGB:
                PfHeader.Flags  = (uint)DDPF.FOURCC;
                PfHeader.FourCC = FOURCC_DX10;
                if (Dx10Header == null)
                {
                    Dx10Header = new DX10Header();
                }

                Dx10Header.DxgiFormat = (uint)dxgiFormat;
                break;
            }
        }