Пример #1
0
        public static BMPImage ConvertDDSToBMP(DDSImage dds)
        {
            //Creates new empty BMP file
            BMPImage bmp = new BMPImage((UInt32)dds.Width, (UInt32)dds.Height);

            //container for colors
            RGBColor[] colors = new RGBColor[4];
            int texelsX = (int)dds.Width / 4;
            int x, y = 0;
            //iterates through all data in DDS file
            for (int i = 0; i < dds.ImageDataLength; i++)
            {
                DDSImage.TexelBlock t = dds.GetImageData(i);
                colors = ReadMainColors(t);

                RGBColor color = new RGBColor(0,0,0);

                byte[] texelCol = new byte[4];
                for (int k=0;k<t.blocks.Length;k++)
                {

                    texelCol[0] = (byte)(t.blocks[k] & 0x3);
                    texelCol[1] = (byte)((t.blocks[k] & 0xC) >> 2);
                    texelCol[2] = (byte)((t.blocks[k] & 0x30) >> 4);
                    texelCol[3] = (byte)((t.blocks[k] & 0xC0) >> 6);

                    for (int j = 0; j < 4; j++)
                    {
                        color = colors[texelCol[j]];

                        x = (i % texelsX) * 4 + j;
                        y = ((int)dds.Height - 1) - ((i / texelsX) * 4) - k;

                        bmp.AddImageData(x, y, color);
                    }
                }
            }

            bmp.Save(dds.FileName);
            return bmp;
        }
Пример #2
0
        public static BMPImage ConvertDDSToBMP(DDSImage dds)
        {
            //Creates new empty BMP file
            BMPImage bmp = new BMPImage((UInt32)dds.Width, (UInt32)dds.Height);

            //container for colors
            RGBColor[] colors = new RGBColor[4];
            int        texelsX = (int)dds.Width / 4;
            int        x, y = 0;

            //iterates through all data in DDS file
            for (int i = 0; i < dds.ImageDataLength; i++)
            {
                DDSImage.TexelBlock t = dds.GetImageData(i);
                colors = ReadMainColors(t);

                RGBColor color = new RGBColor(0, 0, 0);

                byte[] texelCol = new byte[4];
                for (int k = 0; k < t.blocks.Length; k++)
                {
                    texelCol[0] = (byte)(t.blocks[k] & 0x3);
                    texelCol[1] = (byte)((t.blocks[k] & 0xC) >> 2);
                    texelCol[2] = (byte)((t.blocks[k] & 0x30) >> 4);
                    texelCol[3] = (byte)((t.blocks[k] & 0xC0) >> 6);

                    for (int j = 0; j < 4; j++)
                    {
                        color = colors[texelCol[j]];

                        x = (i % texelsX) * 4 + j;
                        y = ((int)dds.Height - 1) - ((i / texelsX) * 4) - k;

                        bmp.AddImageData(x, y, color);
                    }
                }
            }

            bmp.Save(dds.FileName);
            return(bmp);
        }