Esempio n. 1
0
 /// <summary>
 /// Create a new PIXELFORMAT with default values.
 /// </summary>
 public PIXELFORMAT()
 {
     dwFlags       = 0;
     dwFourCC      = 0;
     dwRGBBitCount = 0;
     dwRBitMask    = 0;
     dwGBitMask    = 0;
     dwBBitMask    = 0;
     dwABitMask    = 0;
 }
Esempio n. 2
0
 public void Read(BinaryReaderExt reader)
 {
     dwSize        = reader.ReadUInt32();
     dwFlags       = (DDPF)reader.ReadInt32();
     dwFourCC      = reader.ReadInt32();
     dwRGBBitCount = reader.ReadUInt32();
     dwRBitMask    = reader.ReadUInt32();
     dwGBitMask    = reader.ReadUInt32();
     dwBBitMask    = reader.ReadUInt32();
     dwABitMask    = reader.ReadUInt32();
 }
Esempio n. 3
0
 internal PIXELFORMAT(BinaryReaderEx br)
 {
     br.AssertInt32(32); // dwSize
     dwFlags       = (DDPF)br.ReadUInt32();
     dwFourCC      = br.ReadASCII(4);
     dwRGBBitCount = br.ReadInt32();
     dwRBitMask    = br.ReadUInt32();
     dwGBitMask    = br.ReadUInt32();
     dwBBitMask    = br.ReadUInt32();
     dwABitMask    = br.ReadUInt32();
 }
Esempio n. 4
0
        public void Read(BinaryReader br)
        {
            dwMagic = br.ReadInt32();

            // DDSURFACEDESC2
            dwSize              = br.ReadInt32();
            dwFlags             = (DDSD)br.ReadInt32();
            dwHeight            = br.ReadInt32();
            dwWidth             = br.ReadInt32();
            dwPitchOrLinearSize = br.ReadInt32();
            dwDepth             = br.ReadInt32();
            dwMipMapCount       = br.ReadInt32();
            dwReserved1         = new int[11];
            for (int x = 0; x < dwReserved1.Length; x++)
            {
                dwReserved1[x] = br.ReadInt32();
            }

            // DDPIXELFORMAT
            dwSize2           = br.ReadInt32();
            dwFlags2          = (DDPF)br.ReadInt32();
            dwFourCC          = (FourCC)br.ReadInt32();
            dwRGBBitCount     = br.ReadInt32();
            dwRBitMask        = br.ReadInt32();
            dwGBitMask        = br.ReadInt32();
            dwBBitMask        = br.ReadInt32();
            dwRGBAlphaBitMask = br.ReadUInt32();

            // DDSCAPS2;
            dwCaps1   = (DDSCAPS)br.ReadInt32();
            dwCaps2   = (DDSCAPS2)br.ReadInt32();
            Reserved2 = new int[2];
            for (int x = 0; x < Reserved2.Length; x++)
            {
                Reserved2[x] = br.ReadInt32();
            }

            dwReserved3 = br.ReadInt32();
        }
Esempio n. 5
0
        public void Read(BinaryReader br)
        {
            int num;

            dwMagic             = br.ReadInt32();
            dwSize              = br.ReadInt32();
            dwFlags             = (DDSD)br.ReadInt32();
            dwHeight            = br.ReadInt32();
            dwWidth             = br.ReadInt32();
            dwPitchOrLinearSize = br.ReadInt32();
            dwDepth             = br.ReadInt32();
            dwMipMapCount       = br.ReadInt32();
            dwReserved1         = new int[11];

            for (num = 0; num < dwReserved1.Length; num++)
            {
                dwReserved1[num] = br.ReadInt32();
            }

            dwSize2           = br.ReadInt32();
            dwFlags2          = (DDPF)br.ReadInt32();
            dwFourCC          = (FourCC)br.ReadInt32();
            dwRGBBitCount     = br.ReadInt32();
            dwRBitMask        = br.ReadInt32();
            dwGBitMask        = br.ReadInt32();
            dwBBitMask        = br.ReadInt32();
            dwRGBAlphaBitMask = br.ReadUInt32();
            dwCaps1           = (DDSCAPS)br.ReadInt32();
            dwCaps2           = (DDSCAPS2)br.ReadInt32();
            Reserved2         = new int[2];

            for (num = 0; num < Reserved2.Length; num++)
            {
                Reserved2[num] = br.ReadInt32();
            }

            dwReserved3 = br.ReadInt32();
        }
Esempio n. 6
0
        public DDS(bitmap.BitmapData BitmapInfo)
        {
            dwMagic  = 0x20534444;
            dwSize   = 0x7c;
            dwFlags  = 0;
            dwFlags |= DDSD.CAPS;
            dwFlags |= DDSD.HEIGHT;
            dwFlags |= DDSD.WIDTH;
            dwFlags |= DDSD.PIXELFORMAT;
            dwHeight = BitmapInfo.VirtualHeight;
            dwWidth  = BitmapInfo.VirtualWidth;

            if (BitmapInfo.Format == BitmapFormat.A8R8G8B8)
            {
                dwFlags            |= DDSD.PITCH;
                dwPitchOrLinearSize = dwWidth * 4;
            }
            else
            {
                dwFlags            |= DDSD.LINEARSIZE;
                dwPitchOrLinearSize = BitmapInfo.RawSize;
            }

            dwDepth       = 0;
            dwMipMapCount = 0;
            dwReserved1   = new int[11];
            dwSize2       = 0x20;
            dwFlags2      = 0;
            dwFourCC      = FourCC.None;

            switch (BitmapInfo.Format)
            {
            case BitmapFormat.A8R8G8B8:
                dwFlags2 |= DDPF.RGB;
                dwFlags2 |= DDPF.ALPHAPIXELS;
                break;

            case BitmapFormat.Dxt1:
                dwFlags2 |= DDPF.FOURCC;
                dwFourCC  = FourCC.DXT1;
                break;

            case BitmapFormat.Dxt3:
                dwFlags2 |= DDPF.FOURCC;
                dwFourCC  = FourCC.DXT3;
                break;

            case BitmapFormat.Dxt5:
                dwFlags2 |= DDPF.FOURCC;
                dwFourCC  = FourCC.DXT5;
                break;
            }

            if (BitmapInfo.Format == BitmapFormat.A8R8G8B8)
            {
                dwRGBBitCount     = 0x20;
                dwRBitMask        = 0xff0000;
                dwGBitMask        = 0xff00;
                dwBBitMask        = 0xff;
                dwRGBAlphaBitMask = 0xff000000;
            }
            else
            {
                dwRGBBitCount     = 0;
                dwRBitMask        = 0;
                dwGBitMask        = 0;
                dwBBitMask        = 0;
                dwRGBAlphaBitMask = 0;
            }

            dwCaps1     = 0;
            dwCaps1    |= DDSCAPS.TEXTURE;
            dwCaps2     = 0;
            Reserved2   = new int[2];
            dwReserved3 = 0;
        }
Esempio n. 7
0
        public static byte[] Headerize(TPF.Texture texture)
        {
            if (Encoding.ASCII.GetString(texture.Bytes, 0, 4) == "DDS ")
            {
                return(texture.Bytes);
            }

            DDS         dds   = new DDS();
            PIXELFORMAT ddspf = dds.ddspf;

            byte format = texture.Format;

            if (format != 16 && format != 26)
            {
                DDSD dwFlags = DDSD.CAPS | DDSD.HEIGHT | DDSD.WIDTH | DDSD.PIXELFORMAT | DDSD.MIPMAPCOUNT;
                if (format == 0 || format == 1 || format == 3 || format == 5)
                {
                    dwFlags |= DDSD.LINEARSIZE;
                }
                else if (format == 9 || format == 10)
                {
                    dwFlags |= DDSD.PITCH;
                }
                dds.dwFlags = dwFlags;

                dds.dwHeight = texture.Header.Height;
                dds.dwWidth  = texture.Header.Width;

                if (format == 9 || format == 10)
                {
                    dds.dwPitchOrLinearSize = (texture.Header.Width * 32 + 7) / 8;
                }
                //else if (format == 0 || format == 1)
                //    pitch = Math.Max(1, (texture.Header.Width + 3) / 4) * (8 * 8 * 8);
                //else if (format == 5)
                //    pitch = Math.Max(1, (texture.Header.Width + 3) / 4) * (16 * 16 * 8);

                dds.dwDepth       = 1;
                dds.dwMipMapCount = texture.Mipmaps;

                DDPF ddspfdwFlags = 0;
                if (format == 0 || format == 1 || format == 3 || format == 5)
                {
                    ddspfdwFlags |= DDPF.FOURCC;
                }
                else if (format == 9)
                {
                    ddspfdwFlags |= DDPF.ALPHAPIXELS | DDPF.RGB;
                }
                else if (format == 10)
                {
                    ddspfdwFlags |= DDPF.RGB;
                }
                ddspf.dwFlags = ddspfdwFlags;

                if (format == 0 || format == 1)
                {
                    ddspf.SetFourCCAsString("DXT1");
                }
                else if (format == 3)
                {
                    ddspf.SetFourCCAsString("DXT3");
                }
                else if (format == 5)
                {
                    ddspf.SetFourCCAsString("DXT5");
                }
                else
                {
                    ddspf.dwFourCC = 0;
                }

                if (format == 9 || format == 10)
                {
                    ddspf.dwRGBBitCount = 32;
                }

                if (format == 9)
                {
                    ddspf.dwRBitMask = 0x00FF0000;
                    ddspf.dwGBitMask = 0x0000FF00;
                    ddspf.dwBBitMask = 0x000000FF;
                    ddspf.dwABitMask = 0xFF000000;
                }
                else if (format == 10)
                {
                    ddspf.dwRBitMask = 0x000000FF;
                    ddspf.dwGBitMask = 0x0000FF00;
                    ddspf.dwBBitMask = 0x00FF0000;
                    ddspf.dwABitMask = 0x00000000;
                }

                DDSCAPS dwCaps = DDSCAPS.TEXTURE;
                if (texture.Type == TPF.TexType.Cubemap)
                {
                    dwCaps |= DDSCAPS.COMPLEX;
                }
                if (texture.Mipmaps > 1)
                {
                    dwCaps |= DDSCAPS.COMPLEX | DDSCAPS.MIPMAP;
                }
                dds.dwCaps = dwCaps;

                if (texture.Type == TPF.TexType.Cubemap)
                {
                    dds.dwCaps2 = CUBEMAP_ALLFACES;
                }
                else if (texture.Type == TPF.TexType.Volume)
                {
                    dds.dwCaps2 = DDSCAPS2.VOLUME;
                }
            }
            else
            {
                //int a = 0;
            }

            return(dds.Write(texture.Bytes));
        }
Esempio n. 8
0
        public DDS(HaloDeveloper.Raw.BitmapRaw.BitmapSubmap BitmapInfo)
        {
            dwMagic = 0x20534444; // "DDS "
            dwSize  = 0x7C;       // Size of DDSURFACEDESC2 struct

            // Setup the basic flags that we know we will always have
            dwFlags  = 0;
            dwFlags |= DDSD.CAPS;
            dwFlags |= DDSD.HEIGHT;
            dwFlags |= DDSD.WIDTH;
            dwFlags |= DDSD.PIXELFORMAT;

            // Set our height and width
            dwHeight = BitmapInfo.vHeight;
            dwWidth  = BitmapInfo.vWidth;

            // We will provide a pitch or linear size
            if (BitmapInfo.Format == TextureFormat.A8R8G8B8)
            {
                dwFlags            |= DDSD.PITCH;
                dwPitchOrLinearSize = dwWidth * 4;
            }
            else
            {
                dwFlags            |= DDSD.LINEARSIZE;
                dwPitchOrLinearSize = BitmapInfo.RawLength; // Size of first mip
            }
            dwDepth = 0;                                    // I havent seen this used yet in xtd's

            // We will provide a mipmap count if theres more then 1 level
            //if (BitmapInfo.Levels > 1)
            //{
            //    dwFlags |= DDSD.MIPMAPCOUNT;
            //    dwMipMapCount = BitmapInfo.Levels;
            //}
            //else
            dwMipMapCount = 0;

            dwReserved1 = new int[11]; // Reserved

            dwSize2 = 0x00000020;      // Size of DDPIXELFORMAT struct

            // Fill out our flags and fourcc
            dwFlags2 = 0;
            dwFourCC = FourCC.None;
            switch (BitmapInfo.Format)
            {
            case TextureFormat.DXT1:
                dwFlags2 |= DDPF.FOURCC;
                dwFourCC  = FourCC.DXT1;
                break;

            case TextureFormat.DXT3:
                dwFlags2 |= DDPF.FOURCC;
                dwFourCC  = FourCC.DXT3;
                break;

            case TextureFormat.DXT5:
                dwFlags2 |= DDPF.FOURCC;
                dwFourCC  = FourCC.DXT5;
                break;

            case TextureFormat.A8R8G8B8:
                dwFlags2 |= DDPF.RGB;
                dwFlags2 |= DDPF.ALPHAPIXELS;
                break;
            }

            // Fill in the rest of the struct
            if (BitmapInfo.Format == TextureFormat.A8R8G8B8)
            {
                dwRGBBitCount     = 0x20;
                dwRBitMask        = 0x00ff0000;
                dwGBitMask        = 0x0000ff00;
                dwBBitMask        = 0x000000ff;
                dwRGBAlphaBitMask = 0xff000000;
            }
            else
            {
                dwRGBBitCount     = 0x00000000;
                dwRBitMask        = 0x00000000;
                dwGBitMask        = 0x00000000;
                dwBBitMask        = 0x00000000;
                dwRGBAlphaBitMask = 0x00000000;
            }

            // Fill in our DDSCAPS2 info
            dwCaps1  = 0;
            dwCaps1 |= DDSCAPS.TEXTURE;
            //if (BitmapInfo.Levels > 1)
            //{
            //    dwCaps1 |= DDSCAPS.COMPLEX;
            //    dwCaps1 |= DDSCAPS.MIPMAP;
            //}
            dwCaps2   = 0;
            Reserved2 = new int[2];

            dwReserved3 = 0x00000000;
        }