示例#1
0
        public void LoadTagData()
        {
            BinaryReader br = new BinaryReader(m_stream);

            m_header.Load(ref br);
            br.BaseStream.Seek(m_header.Bitmaps.Offset, SeekOrigin.Begin);
            //br.BaseStream.Seek(m_header.Bitmaps.Unknown, SeekOrigin.Begin);
            m_images = new BITM_IMAGE[m_header.Bitmaps.Count];
            for (int x = 0; x < m_header.Bitmaps.Count; x++)
            {
                m_images[x] = new BITM_IMAGE();
                m_images[x].Load(ref br);
            }
            // Now load the raw data
            br.BaseStream.Seek(m_header.TIFFSize, SeekOrigin.Begin);
            for (int x = 0; x < m_header.Bitmaps.Count; x++)
            {
                m_images[x].DDSData = new byte[m_images[x].size];
                m_images[x].DDSData = br.ReadBytes(m_images[x].size);
                if ((m_images[x].flags & 0x08) == 0x08)
                {
                    DeSwizzleBitmap(ref m_images[x]);
                }
            }
        }
示例#2
0
        public void Generate(ref BITM_IMAGE image, bool bCubemap)
        {
            caps1  = 0;
            caps1 |= (int)DDSEnum.DDSCAPS_TEXTURE;
            if (image.num_mipmaps > 0)
            {
                caps1 |= (int)DDSEnum.DDSCAPS_MIPMAP;
                caps1 |= (int)DDSEnum.DDSCAPS_COMPLEX;
            }

            caps2 = 0;
            if (bCubemap)
            {
                caps2 |= (int)DDSEnum.DDSCAPS2_CUBEMAP;
                caps2 |= (int)DDSEnum.DDSCAPS2_CUBEMAP_NEGATIVEX;
                caps2 |= (int)DDSEnum.DDSCAPS2_CUBEMAP_POSITIVEZ;
                caps2 |= (int)DDSEnum.DDSCAPS2_CUBEMAP_POSITIVEY;
                caps2 |= (int)DDSEnum.DDSCAPS2_CUBEMAP_POSITIVEX;
                caps2 |= (int)DDSEnum.DDSCAPS2_CUBEMAP_NEGATIVEZ;
                caps2 |= (int)DDSEnum.DDSCAPS2_CUBEMAP_NEGATIVEY;
                caps1 |= (int)DDSEnum.DDSCAPS_COMPLEX;
            }

            caps3 = 0;
            caps4 = 0;
        }
示例#3
0
        public void DeSwizzleBitmap(ref BITM_IMAGE bi_Obj)
        {
            DeSwizzle DeSwizz = new DeSwizzle();

            DeSwizz.depth  = (ushort)bi_Obj.depth;
            DeSwizz.height = (ushort)bi_Obj.height;
            DeSwizz.width  = (ushort)bi_Obj.width;
            switch (bi_Obj.format)
            {
            case 0x06:
                DeSwizz.DeSwizzleData(ref bi_Obj.DDSData, 16);
                DeSwizz = null;
                break;

            case 0x0B:
                DeSwizz.DeSwizzleData(ref bi_Obj.DDSData, 32);
                DeSwizz = null;
                break;

            case 0x02:
                DeSwizz.DeSwizzleData(ref bi_Obj.DDSData, 8);
                DeSwizz = null;
                break;

            case 0x03:
                DeSwizz.DeSwizzleData(ref bi_Obj.DDSData, 16);
                DeSwizz = null;
                break;

            case 0x11:
                DeSwizz.DeSwizzleData(ref bi_Obj.DDSData, 8);
                DeSwizz = null;
                break;

            case 0x01:
                DeSwizz.DeSwizzleData(ref bi_Obj.DDSData, 8);
                DeSwizz = null;
                break;

            case 0x0A:
                DeSwizz.DeSwizzleData(ref bi_Obj.DDSData, 32);
                DeSwizz = null;
                break;

            case 0x0F:
                DeSwizz.DeSwizzleData(ref bi_Obj.DDSData, 16);
                DeSwizz = null;
                break;

            case 0x09:
                DeSwizz.DeSwizzleData(ref bi_Obj.DDSData, 16);
                DeSwizz = null;
                break;
            }
        }
示例#4
0
        public void Generate(ref BITM_IMAGE image)
        {
            size  = 32;
            Flags = 0;
            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;
            }

            switch ((TagBitmap.BitmFormat)image.format)
            {
            case TagBitmap.BitmFormat.DXT1:
                Flags      |= (int)DDSEnum.DDPF_ALPHAPIXELS;
                Flags      |= (int)DDSEnum.DDPF_ALPHAPREMULT;
                RGBBitCount = 4;
                break;

            case TagBitmap.BitmFormat.DXT2AND3:
            case TagBitmap.BitmFormat.DXT4AND5:
                RGBBitCount = 8;
                break;

            case TagBitmap.BitmFormat.R5G6B5:
                RGBBitCount     = 16;
                RBitMask        = 0xF800;
                GBitMask        = 0x7E0;
                BBitMask        = 0x1F;
                RGBAlphaBitMask = 0x0;
                break;

            case TagBitmap.BitmFormat.A8:
                RGBBitCount     = 8;
                Flags           = Flags + (short)DDSEnum.DDPF_ALPHAPIXELS;
                RBitMask        = 0x0;
                GBitMask        = 0x0;
                BBitMask        = 0x0;
                RGBAlphaBitMask = 0xFF;
                break;

            case  TagBitmap.BitmFormat.Y8:
                RGBBitCount     = 8;
                Flags           = Flags + (short)DDSEnum.DDPF_ALPHAPIXELS;
                RBitMask        = 0x0;
                GBitMask        = 0x0;
                BBitMask        = 0x0;
                RGBAlphaBitMask = 0xFF;
                break;

            case TagBitmap.BitmFormat.P8:
                RGBBitCount     = 8;
                Flags           = Flags + (short)DDSEnum.DDPF_ALPHAPIXELS;
                RBitMask        = 0x0;
                GBitMask        = 0x0;
                BBitMask        = 0x0;
                RGBAlphaBitMask = 0xFF;
                break;

            case TagBitmap.BitmFormat.AY8:
                RGBBitCount     = 8;
                Flags           = Flags + (short)DDSEnum.DDPF_ALPHAPIXELS;
                RBitMask        = 0xF;
                GBitMask        = 0x0;
                BBitMask        = 0x0;
                RGBAlphaBitMask = 0xF0;
                break;

            case TagBitmap.BitmFormat.A8Y8:
                RGBBitCount     = 16;
                Flags           = Flags + (short)DDSEnum.DDPF_ALPHAPIXELS;
                RBitMask        = 0xFF;
                GBitMask        = 0x0;
                BBitMask        = 0x0;
                RGBAlphaBitMask = 0xFF00;
                break;

            case TagBitmap.BitmFormat.A1R5G5B5:
                RGBBitCount     = 16;
                Flags           = Flags + (short)DDSEnum.DDPF_ALPHAPIXELS;
                RBitMask        = 0x7C00;
                GBitMask        = 0x3E0;
                BBitMask        = 0x1F;
                RGBAlphaBitMask = 0x8000;
                break;

            case TagBitmap.BitmFormat.A4R4G4B4:
                RGBBitCount     = 16;
                Flags           = Flags + (short)DDSEnum.DDPF_ALPHAPIXELS;
                RBitMask        = 0xF00;
                GBitMask        = 0xF0;
                BBitMask        = 0xF;
                RGBAlphaBitMask = 0xF000;
                break;

            case TagBitmap.BitmFormat.X8R8G8B8:
                RGBBitCount     = 32;
                RBitMask        = 0xFF0000;
                GBitMask        = 0xFF00;
                BBitMask        = 0xFF;
                RGBAlphaBitMask = 0x00000000;
                break;

            case TagBitmap.BitmFormat.A8R8G8B8:
                RGBBitCount = 32;
                Flags       = Flags + (short)DDSEnum.DDPF_ALPHAPIXELS;
                RBitMask    = 0xFF0000;
                GBitMask    = 0xFF00;
                BBitMask    = 0xFF;
                unchecked
                {
                    RGBAlphaBitMask = (int)0xFF000000;
                }
                break;

            default:
                RGBBitCount = 0;
                break;
            }
        }
示例#5
0
        public void Generate(ref BITM_IMAGE image, bool bCubemap)
        {
            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
            {
                flags = flags + (short)DDSEnum.DDSD_PITCH;
            }
            height = image.height;
            width  = image.width;

            /*
             *        switch((TagBitmap.BitmFormat)image.format)
             *        {
             * case TagBitmap.BitmFormat.DXT1:
             *                        RGBBitCount = 4;
             *                        break;
             * case TagBitmap.BitmFormat.DXT2AND3:
             * case TagBitmap.BitmFormat.DXT4AND5:
             *                        RGBBitCount = 8;
             *                        break;
             * case TagBitmap.BitmFormat.R5G6B5:
             *                        RGBBitCount = 16;
             *                        break;
             *                case TagBitmap.BitmFormat.A8:
             *                        RGBBitCount = 8;
             *                        break;
             *                case  TagBitmap.BitmFormat.Y8:
             *                        RGBBitCount = 8;
             *                        break;
             *                case TagBitmap.BitmFormat.P8:
             *                        RGBBitCount = 8;
             *                        break;
             *                case TagBitmap.BitmFormat.AY8:
             *                        RGBBitCount = 8;
             *                        break;
             *                case TagBitmap.BitmFormat.A8Y8:
             *                        RGBBitCount = 16;
             *                        break;
             *                case TagBitmap.BitmFormat.A1R5G5B5:
             *                        RGBBitCount = 16;
             *                        break;
             *                case TagBitmap.BitmFormat.A4R4G4B4:
             *                        RGBBitCount = 16;
             *                        break;
             *                case TagBitmap.BitmFormat.X8R8G8B8:
             *                        RGBBitCount = 32;
             *                        break;
             *                case TagBitmap.BitmFormat.A8R8G8B8:
             *                        RGBBitCount = 32;
             *                        break;
             *                default:
             *                        RGBBitCount = 0;
             *                        break;
             *        }
             */

            depth = 0;
            //disable mips for cubemaps, for now anyway
            if (bCubemap)
            {
                MipMapCount = 0;
            }
            else
            {
                MipMapCount = image.num_mipmaps;
            }

            if ((MipMapCount > 0) && (!bCubemap))
            {
                flags = flags + (int)DDSEnum.DDSD_MIPMAPCOUNT;
            }

            Reserved1 = new int[11];
            for (int i = 0; i < Reserved1.Length; i++)
            {
                Reserved1[i] = 0;
            }

            ddfPixelFormat.Generate(ref image);
            ddsCaps.Generate(ref image, bCubemap);

            if ((image.flags & (short)DDSEnum.DDSD_PITCH) != 0)
            {
                PitchOrLinearSize = (image.width * ddfPixelFormat.RGBBitCount) / 8;
            }

            if ((image.flags & (int)DDSEnum.DDSD_LINEARSIZE) != 0)
            {
                PitchOrLinearSize = image.size;
            }
        }
示例#6
0
 public void generate(ref BITM_IMAGE image, bool bCubemap)
 {
     ddsd.Generate(ref image, bCubemap);
 }
示例#7
0
 public void GenerateAndWriteHeader(ref BinaryWriter bw, ref BITM_IMAGE b, bool bCubemap)
 {
     header.generate(ref b, bCubemap);
     header.WriteStruct(ref bw);
 }