Esempio n. 1
0
 private static void ProccesImage(string fileName)
 {
     if (fileName.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase))
     {
         BMPImage bmp = new BMPImage(fileName.Remove(fileName.Length - 4));
         DDSImage dds = ImageCompression.ConvertBMPToDDS(bmp);
         Console.WriteLine("Saved");
     }
     else if (fileName.EndsWith(".dds", StringComparison.OrdinalIgnoreCase))
     {
         DDSImage dds = new DDSImage(fileName.Remove(fileName.Length - 4));
         BMPImage bmp = ImageCompression.ConvertDDSToBMP(dds);
         Console.WriteLine("Saved");
     }
     else
     {
         Console.WriteLine(fileName + " File not supported");
     }
 }
Esempio n. 2
0
 private static void ProccesImage(string fileName)
 {
     if (fileName.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase))
     {
         BMPImage bmp = new BMPImage(fileName.Remove(fileName.Length-4));
         DDSImage dds = ImageCompression.ConvertBMPToDDS(bmp);
         Console.WriteLine("Saved");
     }
     else if(fileName.EndsWith(".dds", StringComparison.OrdinalIgnoreCase))
     {
         DDSImage dds = new DDSImage(fileName.Remove(fileName.Length-4));
         BMPImage bmp = ImageCompression.ConvertDDSToBMP(dds);
         Console.WriteLine("Saved");
     }
     else
     {
         Console.WriteLine(fileName+ " File not supported");
     }
 }
        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;
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public static DDSImage ConvertBMPToDDS(BMPImage bmp)
        {
            // In this algorithm (0,0) is the lower left corner because BMP data starts from there
            DDSImage dds = new DDSImage(bmp.Width, bmp.Height);

            for (int y = 0; y < bmp.Height; y += 4)
            {
                for (int x = 0; x < bmp.Width; x += 4)
                {
                    RGBColor[] block = new RGBColor[DDSConst.DDS_BLOCK_SIZE];
                    for (int i = 0; i < block.Length; i++)
                    {
                        block[i] = bmp.GetImageData(x + (i % 4), (int)bmp.Height - 1 - (y + (i / 4)));
                    }
                    dds.AddImageData(CompressDataBlock(block));
                }
            }

            dds.Save(bmp.FileName);
            return(dds);
        }
        public static DDSImage ConvertBMPToDDS(BMPImage bmp)
        {
            // In this algorithm (0,0) is the lower left corner because BMP data starts from there
            DDSImage dds = new DDSImage(bmp.Width,bmp.Height);

            for (int y = 0; y< bmp.Height; y += 4)
            {
                for (int x = 0; x < bmp.Width; x += 4)
                {

                    RGBColor[] block = new RGBColor[DDSConst.DDS_BLOCK_SIZE];
                    for (int i = 0; i < block.Length; i++)
                    {
                        block[i] = bmp.GetImageData(x +(i%4) , (int)bmp.Height - 1 - (y + (i / 4)));
                    }
                    dds.AddImageData(CompressDataBlock(block));
                }
            }

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