public void LoadTagData()
        {
            BinaryReader br = new BinaryReader(m_stream);

            m_header.Load(ref br);
            m_images = new H2BITM_IMAGE[m_header.Bitmaps.Count];
            for (int x = 0; x < m_header.Bitmaps.Count; x++)
            {
                m_images[x] = new H2BITM_IMAGE();
                m_images[x].Load(ref br);
            }
            // Now load the raw data
            for (int x = 0; x < m_header.Bitmaps.Count; x++)
            {
                m_images[x].DDSData = new byte[m_images[x].size[0]];
                m_images[x].DDSData = br.ReadBytes(m_images[x].size[0]);
                if ((m_images[x].flags & 0x8) == 0x8)
                {
                    DeSwiz.depth  = m_images[x].depth;
                    DeSwiz.height = m_images[x].height;
                    DeSwiz.width  = m_images[x].width;
                    DeSwiz.DeSwizzleData(ref m_images[x].DDSData, 8);
                }
                for (int s = 1; s < 6; s++)
                {
                    br.BaseStream.Position += m_images[x].size[s];
                }
            }
        }
        public void WriteHeader(ref BinaryWriter bw, ref H2BITM_IMAGE b)
        {
            DDS_HEADER header = new DDS_HEADER();

            header.generate(ref b);
            header.WriteStruct(ref bw);
        }
 public void Generate(ref H2BITM_IMAGE image)
 {
     caps1 = caps1 + (short)DDSEnum.DDSCAPS_TEXTURE;
     if (image.num_mipmaps > 0)
     {
         caps1 = caps1 + (int)DDSEnum.DDSCAPS_MIPMAP;
     }
     caps1       = caps1 + (short)DDSEnum.DDSCAPS_COMPLEX;
     caps2       = 0;
     Reserved    = new int[2];
     Reserved[0] = 0;
     Reserved[1] = 0;
 }
 public void Generate(ref H2BITM_IMAGE image)
 {
     size  = 32;
     Flags = 0;
     if (image.format == 0x12)
     {
         FourCC = "\0\0\0\0";
         Flags  = Flags + 0x020000;
     }
     else if (image.format == 14)
     {
         FourCC = "DXT1";
         Flags  = Flags + (short)DDSEnum.DDPF_FOURCC;
     }
     else if (image.format == 15)
     {
         FourCC = "DXT3";
         Flags  = Flags + (short)DDSEnum.DDPF_FOURCC;
     }
     else if (image.format == 16)
     {
         FourCC = "DXT4";
         Flags  = Flags + (short)DDSEnum.DDPF_FOURCC;
     }
     else
     {
         FourCC = "\0\0\0\0";
         Flags  = Flags + (short)DDSEnum.DDPF_RGB;
     }
     if (image.format == (short)TagBitmap.BitmFormat.L8)
     {
         RGBBitCount = 8;
     }
     else if (image.format == (short)TagBitmap.BitmFormat.R5G6B5)
     {
         RGBBitCount = 16;
     }
     else if (image.format == (short)TagBitmap.BitmFormat.A1R5G5B5)
     {
         RGBBitCount = 16;
         Flags       = Flags + (short)DDSEnum.DDPF_ALPHAPIXELS;
     }
     else if (image.format == (short)TagBitmap.BitmFormat.A4R4G4B4)
     {
         RGBBitCount = 16;
         Flags       = Flags + (short)DDSEnum.DDPF_ALPHAPIXELS;
     }
     else if (image.format == (short)TagBitmap.BitmFormat.X8R8G8B8)
     {
         Flags       = Flags + (short)DDSEnum.DDPF_ALPHAPIXELS;
         RGBBitCount = 32;
     }
     else if (image.format == (short)TagBitmap.BitmFormat.A8R8G8B8)
     {
         Flags       = Flags + (short)DDSEnum.DDPF_ALPHAPIXELS;
         RGBBitCount = 32;
     }
     else
     {
         RGBBitCount = 0;
     }
     if (image.format == (short)TagBitmap.BitmFormat.L8)
     {
         RBitMask        = 0xFF;
         GBitMask        = 0;
         BBitMask        = 0;
         RGBAlphaBitMask = 0;
     }
     else
     if (image.format == (short)TagBitmap.BitmFormat.R5G6B5)
     {
         RBitMask        = 63488;
         GBitMask        = 2016;
         BBitMask        = 31;
         RGBAlphaBitMask = 0;
     }
     else if (image.format == (short)TagBitmap.BitmFormat.A1R5G5B5)
     {
         RBitMask        = 31744;
         GBitMask        = 992;
         BBitMask        = 31;
         RGBAlphaBitMask = 32768;
     }
     else if (image.format == (short)TagBitmap.BitmFormat.A4R4G4B4)
     {
         RBitMask        = 61440;
         GBitMask        = 240;
         BBitMask        = 15;
         RGBAlphaBitMask = 15728640;
     }
     else if (image.format == (short)TagBitmap.BitmFormat.X8R8G8B8)
     {
         RBitMask        = 1044480;
         GBitMask        = 65280;
         BBitMask        = 255;
         RGBAlphaBitMask = (int)278190080;
     }
     else if (image.format == (short)TagBitmap.BitmFormat.A8R8G8B8)
     {
         RBitMask = 16711680;
         GBitMask = 65280;
         BBitMask = 255;
         //RGBAlphaBitMask = (int)4278190080;
     }
     else
     {
         RBitMask        = 0;
         GBitMask        = 0;
         BBitMask        = 0;
         RGBAlphaBitMask = 0;
     }
 }
        public void Generate(ref H2BITM_IMAGE image)
        {
            size_of_structure = 124;
            flags             = flags + (int)DDSEnum.DDSD_CAPS;
            flags             = flags + (int)DDSEnum.DDSD_PIXELFORMAT;
            flags             = flags + (int)DDSEnum.DDSD_WIDTH;
            flags             = flags + (int)DDSEnum.DDSD_HEIGHT;
            if (image.format == (short)TagBitmap.BitmFormat.DXT1 ||
                image.format == (short)TagBitmap.BitmFormat.DXT2AND3 ||
                image.format == (short)TagBitmap.BitmFormat.DXT4AND5)
            {
                flags = flags + (int)DDSEnum.DDSD_LINEARSIZE;
            }
            else
            {
                if (image.format != (short)TagBitmap.BitmFormat.L8)
                {
                    flags = flags + (short)DDSEnum.DDSD_PITCH;
                }
            }
            height = image.height;
            width  = image.width;
            int RGBBitCount = 0;

            if (image.format == (short)TagBitmap.BitmFormat.L8)
            {
                RGBBitCount = 8;
            }
            else if (image.format == (short)TagBitmap.BitmFormat.R5G6B5)
            {
                RGBBitCount = 16;
            }
            else if (image.format == (short)TagBitmap.BitmFormat.A1R5G5B5)
            {
                RGBBitCount = 16;
            }
            else if (image.format == (short)TagBitmap.BitmFormat.A4R4G4B4)
            {
                RGBBitCount = 16;
            }
            else if (image.format == (short)TagBitmap.BitmFormat.X8R8G8B8)
            {
                RGBBitCount = 32;
            }
            else if (image.format == (short)TagBitmap.BitmFormat.A8R8G8B8)
            {
                RGBBitCount = 32;
            }
            if ((image.flags & (short)DDSEnum.DDSD_PITCH) > 0)
            {
                PitchOrLinearSize = image.width * (RGBBitCount / 8);
            }
            if ((image.flags & (int)DDSEnum.DDSD_LINEARSIZE) > 0)
            {
                PitchOrLinearSize = image.size[0];
            }
            depth       = 0;
            MipMapCount = image.num_mipmaps;
            if (MipMapCount > 0)
            {
                flags = flags + (int)DDSEnum.DDSD_MIPMAPCOUNT;
            }
            Reserved1     = new int[11];
            Reserved1[0]  = 0;
            Reserved1[1]  = 0;
            Reserved1[2]  = 0;
            Reserved1[3]  = 0;
            Reserved1[4]  = 0;
            Reserved1[5]  = 0;
            Reserved1[6]  = 0;
            Reserved1[7]  = 0;
            Reserved1[8]  = 0;
            Reserved1[9]  = 0;
            Reserved1[10] = 0;
            ddfPixelFormat.Generate(ref image);
            ddsCaps.Generate(ref image);
        }
 public void generate(ref H2BITM_IMAGE image)
 {
     ddsd.Generate(ref image);
 }