Ejemplo n.º 1
0
        private void ReadHeader(Ibasa.IO.BinaryReader reader)
        {
            HeaderFlags = (HeaderFlagsEnum)reader.ReadInt32();
            Height      = reader.ReadInt32();
            Width       = reader.ReadInt32();
            Pitch       = reader.ReadInt32();
            Depth       = reader.ReadInt32();
            MipmapCount = reader.ReadInt32();
            reader.ReadBytes(44); //skip padding

            int pixelSize = reader.ReadInt32();

            if (pixelSize != 32)
            {
                throw new InvalidDataException(string.Format("Pixel format size {0} does not match 32.", pixelSize));
            }

            PixelFlags  = (PixelFlagsEnum)reader.ReadInt32();
            FourCC      = new FourCC(reader.ReadInt32());
            RGBBitCount = reader.ReadInt32();
            RBitMask    = reader.ReadInt32();
            GBitMask    = reader.ReadInt32();
            BBitMask    = reader.ReadInt32();
            ABitMask    = reader.ReadInt32();

            SurfaceFlags = (SurfaceFlagsEnum)reader.ReadInt32();
            CubemapFlags = (CubemapFlagsEnum)reader.ReadInt32();

            reader.ReadBytes(12); //skip padding
        }
Ejemplo n.º 2
0
        private void SelectSaveFormat()
        {
            if (Image.Format.IsCompressed || Image.ArraySize > 1)
            {
                PixelFlags = PixelFlagsEnum.FourCC;
                RGBBitCount = RBitMask = GBitMask = BBitMask = ABitMask = 0;

                if (Image.ArraySize == 1)
                {
                    //try to use DXT1/2/3

                    if (Image.Format.Name == "BC1_UNorm")
                    {
                        FourCC = new FourCC("DXT1");
                    }
                    else if (Image.Format.Name == "BC2_UNorm")
                    {
                        FourCC = new FourCC("DXT3");
                    }
                    else if (Image.Format.Name == "BC3_UNorm")
                    {
                        FourCC = new FourCC("DXT5");
                    }
                }
                else
                {
                    //use dx10
                    FourCC = new FourCC("DX10");
                    if (Enum.TryParse<DxgiFormat>(Image.Format.Name, out DxgiFormat))
                        return;
                }
            }
            else
            {
                //try plain formats
                if (Image.Format.Name == "R8G8B8A8_UNorm")
                {
                    PixelFlags = PixelFlagsEnum.Rgb | PixelFlagsEnum.AlphaPixels;
                    FourCC = new FourCC(0);
                    RGBBitCount = 32;
                    RBitMask = 0xff;
                    GBitMask = 0xff00;
                    BBitMask = 0xff0000;
                    ABitMask = unchecked((int)0xff000000);
                }
                else if (Image.Format.Name == "B5G6R5_UNorm")
                {
                    PixelFlags = PixelFlagsEnum.Rgb;
                    FourCC = new FourCC(0);
                    RGBBitCount = 15;
                    RBitMask = 0xf800;
                    GBitMask = 0x7e0;
                    BBitMask = 0x1f;
                    ABitMask = 0;
                }
                else if (Image.Format.Name == "B5G5R5A1_UNorm")
                {
                    PixelFlags = PixelFlagsEnum.Rgb | PixelFlagsEnum.AlphaPixels;
                    FourCC = new FourCC(0);
                    RGBBitCount = 15;
                    RBitMask = 0xf800;
                    GBitMask = 0x7e0;
                    BBitMask = 0x1f;
                    ABitMask = 0x8000;
                }
                else if (Image.Format.Name == "A8_UNorm")
                {
                    PixelFlags = PixelFlagsEnum.Alpha;
                    FourCC = new FourCC(0);
                    RGBBitCount = 8;
                    RBitMask = 0;
                    GBitMask = 0;
                    BBitMask = 0;
                    ABitMask = 0xff;
                }
                else
                {
                    //use dx10
                    FourCC = new FourCC("DX10");
                    if (Enum.TryParse<DxgiFormat>(Image.Format.Name, out DxgiFormat))
                        return;
                }
            }
            
            throw new NotSupportedException("Unsupported format.");
        }
Ejemplo n.º 3
0
        private void ReadHeader(Ibasa.IO.BinaryReader reader)
        {
            HeaderFlags = (HeaderFlagsEnum)reader.ReadInt32();
            Height = reader.ReadInt32();
            Width = reader.ReadInt32();
            Pitch = reader.ReadInt32();
            Depth = reader.ReadInt32();
            MipmapCount = reader.ReadInt32();
            reader.ReadBytes(44); //skip padding

            int pixelSize = reader.ReadInt32();
            if (pixelSize != 32)
                throw new InvalidDataException(string.Format("Pixel format size {0} does not match 32.", pixelSize));

            PixelFlags = (PixelFlagsEnum)reader.ReadInt32();
            FourCC = new FourCC(reader.ReadInt32());
            RGBBitCount = reader.ReadInt32();
            RBitMask = reader.ReadInt32();
            GBitMask = reader.ReadInt32();
            BBitMask = reader.ReadInt32();
            ABitMask = reader.ReadInt32();

            SurfaceFlags = (SurfaceFlagsEnum)reader.ReadInt32();
            CubemapFlags = (CubemapFlagsEnum)reader.ReadInt32();

            reader.ReadBytes(12); //skip padding
        }
Ejemplo n.º 4
0
        private void FixupInternalState()
        {
            HeaderFlags |= (HeaderFlagsEnum.Caps | HeaderFlagsEnum.Height | HeaderFlagsEnum.Width | HeaderFlagsEnum.PixelFormat);
            SurfaceFlags |= SurfaceFlagsEnum.Texture;

            //cubemap
            if(CubemapFlags != CubemapFlagsEnum.Volume && CubemapFlags != 0)
            {
                CubemapFlags |= CubemapFlagsEnum.Cubemap;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
                if (IsDX10Mode)
                {
                    CubemapFlags |= CubemapFlagsEnum.AllFaces;
                    MiscFlags |= MiscFlagsEnum.TextureCube;
                }
            }
            if(IsDX10Mode && MiscFlags.HasFlag(MiscFlagsEnum.TextureCube))
            {
                
                CubemapFlags |= CubemapFlagsEnum.Cubemap| CubemapFlagsEnum.AllFaces;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
            }

            //volume textures
            if(HeaderFlags.HasFlag(HeaderFlagsEnum.Depth) || CubemapFlags.HasFlag(CubemapFlagsEnum.Volume))
            {
                HeaderFlags |= HeaderFlagsEnum.Depth;
                CubemapFlags |= CubemapFlagsEnum.Volume;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
            }

            //sanatize pixel flags
            if(PixelFlags.HasFlag(PixelFlagsEnum.Rgb) && PixelFlags.HasFlag(PixelFlagsEnum.AlphaPixels))
                PixelFlags = PixelFlagsEnum.Rgb | PixelFlagsEnum.AlphaPixels;
            else if(PixelFlags.HasFlag(PixelFlagsEnum.Rgb))
                PixelFlags = PixelFlagsEnum.Rgb;
            else if(PixelFlags.HasFlag(PixelFlagsEnum.Luminance) && PixelFlags.HasFlag(PixelFlagsEnum.AlphaPixels))
                PixelFlags = PixelFlagsEnum.Luminance | PixelFlagsEnum.AlphaPixels;
            else if(PixelFlags.HasFlag(PixelFlagsEnum.Luminance))
                PixelFlags = PixelFlagsEnum.Luminance;
            else if(PixelFlags.HasFlag(PixelFlagsEnum.FourCC))
                PixelFlags = PixelFlagsEnum.FourCC;
            else if(PixelFlags.HasFlag(PixelFlagsEnum.Yuv))
                PixelFlags = PixelFlagsEnum.Yuv;
            else if(PixelFlags.HasFlag(PixelFlagsEnum.Alpha))
                PixelFlags = PixelFlagsEnum.Alpha;

            if (!PixelFlags.HasFlag(PixelFlagsEnum.FourCC))
            { 
                //uncompressed
                HeaderFlags |= HeaderFlagsEnum.Pitch;
                HeaderFlags &= ~HeaderFlagsEnum.LinearSize;
            }
            else
            {
                //dont know
                //HeaderFlags |= HeaderFlagsEnum.LinearSize;
                //HeaderFlags &= ~HeaderFlagsEnum.Pitch;
            }

            if (IsDX10Mode)
            {
                if(ResourceDimension == ResourceDimensionEnum.Texture3D || HeaderFlags.HasFlag(HeaderFlagsEnum.Depth))
                {
                    ResourceDimension = ResourceDimensionEnum.Texture3D;
                    HeaderFlags |= HeaderFlagsEnum.Depth;
                    CubemapFlags |= CubemapFlagsEnum.Volume;
                    SurfaceFlags |= SurfaceFlagsEnum.Complex;
                }
            }

            Width = Math.Max(Width, 1);
            Height = Math.Max(Height, 1);
            Depth = HeaderFlags.HasFlag(HeaderFlagsEnum.Depth) ? Math.Max(Depth, 1) : 0;
            MipmapCount = HeaderFlags.HasFlag(HeaderFlagsEnum.MipmapCount) ? Math.Max(MipmapCount, 1) : 0;
        }
Ejemplo n.º 5
0
        private void SelectSaveFormat()
        {
            if (Image.Format.IsCompressed || Image.ArraySize > 1)
            {
                PixelFlags  = PixelFlagsEnum.FourCC;
                RGBBitCount = RBitMask = GBitMask = BBitMask = ABitMask = 0;

                if (Image.ArraySize == 1)
                {
                    //try to use DXT1/2/3

                    if (Image.Format.Name == "BC1_UNorm")
                    {
                        FourCC = new FourCC("DXT1");
                    }
                    else if (Image.Format.Name == "BC2_UNorm")
                    {
                        FourCC = new FourCC("DXT3");
                    }
                    else if (Image.Format.Name == "BC3_UNorm")
                    {
                        FourCC = new FourCC("DXT5");
                    }
                }
                else
                {
                    //use dx10
                    FourCC = new FourCC("DX10");
                    if (Enum.TryParse <DxgiFormat>(Image.Format.Name, out DxgiFormat))
                    {
                        return;
                    }
                }
            }
            else
            {
                //try plain formats
                if (Image.Format.Name == "R8G8B8A8_UNorm")
                {
                    PixelFlags  = PixelFlagsEnum.Rgb | PixelFlagsEnum.AlphaPixels;
                    FourCC      = new FourCC(0);
                    RGBBitCount = 32;
                    RBitMask    = 0xff;
                    GBitMask    = 0xff00;
                    BBitMask    = 0xff0000;
                    ABitMask    = unchecked ((int)0xff000000);
                }
                else if (Image.Format.Name == "B5G6R5_UNorm")
                {
                    PixelFlags  = PixelFlagsEnum.Rgb;
                    FourCC      = new FourCC(0);
                    RGBBitCount = 15;
                    RBitMask    = 0xf800;
                    GBitMask    = 0x7e0;
                    BBitMask    = 0x1f;
                    ABitMask    = 0;
                }
                else if (Image.Format.Name == "B5G5R5A1_UNorm")
                {
                    PixelFlags  = PixelFlagsEnum.Rgb | PixelFlagsEnum.AlphaPixels;
                    FourCC      = new FourCC(0);
                    RGBBitCount = 15;
                    RBitMask    = 0xf800;
                    GBitMask    = 0x7e0;
                    BBitMask    = 0x1f;
                    ABitMask    = 0x8000;
                }
                else if (Image.Format.Name == "A8_UNorm")
                {
                    PixelFlags  = PixelFlagsEnum.Alpha;
                    FourCC      = new FourCC(0);
                    RGBBitCount = 8;
                    RBitMask    = 0;
                    GBitMask    = 0;
                    BBitMask    = 0;
                    ABitMask    = 0xff;
                }
                else
                {
                    //use dx10
                    FourCC = new FourCC("DX10");
                    if (Enum.TryParse <DxgiFormat>(Image.Format.Name, out DxgiFormat))
                    {
                        return;
                    }
                }
            }

            throw new NotSupportedException("Unsupported format.");
        }
Ejemplo n.º 6
0
        private void FixupInternalState()
        {
            HeaderFlags  |= (HeaderFlagsEnum.Caps | HeaderFlagsEnum.Height | HeaderFlagsEnum.Width | HeaderFlagsEnum.PixelFormat);
            SurfaceFlags |= SurfaceFlagsEnum.Texture;

            //cubemap
            if (CubemapFlags != CubemapFlagsEnum.Volume && CubemapFlags != 0)
            {
                CubemapFlags |= CubemapFlagsEnum.Cubemap;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
                if (IsDX10Mode)
                {
                    CubemapFlags |= CubemapFlagsEnum.AllFaces;
                    MiscFlags    |= MiscFlagsEnum.TextureCube;
                }
            }
            if (IsDX10Mode && MiscFlags.HasFlag(MiscFlagsEnum.TextureCube))
            {
                CubemapFlags |= CubemapFlagsEnum.Cubemap | CubemapFlagsEnum.AllFaces;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
            }

            //volume textures
            if (HeaderFlags.HasFlag(HeaderFlagsEnum.Depth) || CubemapFlags.HasFlag(CubemapFlagsEnum.Volume))
            {
                HeaderFlags  |= HeaderFlagsEnum.Depth;
                CubemapFlags |= CubemapFlagsEnum.Volume;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
            }

            //sanatize pixel flags
            if (PixelFlags.HasFlag(PixelFlagsEnum.Rgb) && PixelFlags.HasFlag(PixelFlagsEnum.AlphaPixels))
            {
                PixelFlags = PixelFlagsEnum.Rgb | PixelFlagsEnum.AlphaPixels;
            }
            else if (PixelFlags.HasFlag(PixelFlagsEnum.Rgb))
            {
                PixelFlags = PixelFlagsEnum.Rgb;
            }
            else if (PixelFlags.HasFlag(PixelFlagsEnum.Luminance) && PixelFlags.HasFlag(PixelFlagsEnum.AlphaPixels))
            {
                PixelFlags = PixelFlagsEnum.Luminance | PixelFlagsEnum.AlphaPixels;
            }
            else if (PixelFlags.HasFlag(PixelFlagsEnum.Luminance))
            {
                PixelFlags = PixelFlagsEnum.Luminance;
            }
            else if (PixelFlags.HasFlag(PixelFlagsEnum.FourCC))
            {
                PixelFlags = PixelFlagsEnum.FourCC;
            }
            else if (PixelFlags.HasFlag(PixelFlagsEnum.Yuv))
            {
                PixelFlags = PixelFlagsEnum.Yuv;
            }
            else if (PixelFlags.HasFlag(PixelFlagsEnum.Alpha))
            {
                PixelFlags = PixelFlagsEnum.Alpha;
            }

            if (!PixelFlags.HasFlag(PixelFlagsEnum.FourCC))
            {
                //uncompressed
                HeaderFlags |= HeaderFlagsEnum.Pitch;
                HeaderFlags &= ~HeaderFlagsEnum.LinearSize;
            }
            else
            {
                //dont know
                //HeaderFlags |= HeaderFlagsEnum.LinearSize;
                //HeaderFlags &= ~HeaderFlagsEnum.Pitch;
            }

            if (IsDX10Mode)
            {
                if (ResourceDimension == ResourceDimensionEnum.Texture3D || HeaderFlags.HasFlag(HeaderFlagsEnum.Depth))
                {
                    ResourceDimension = ResourceDimensionEnum.Texture3D;
                    HeaderFlags      |= HeaderFlagsEnum.Depth;
                    CubemapFlags     |= CubemapFlagsEnum.Volume;
                    SurfaceFlags     |= SurfaceFlagsEnum.Complex;
                }
            }

            Width       = Math.Max(Width, 1);
            Height      = Math.Max(Height, 1);
            Depth       = HeaderFlags.HasFlag(HeaderFlagsEnum.Depth) ? Math.Max(Depth, 1) : 0;
            MipmapCount = HeaderFlags.HasFlag(HeaderFlagsEnum.MipmapCount) ? Math.Max(MipmapCount, 1) : 0;
        }