コード例 #1
0
ファイル: DDSFile.cs プロジェクト: Lewis-Bright/relic-tools
        private static DDSFile MakeWithMipMapsFrom32bitRGBA(byte[] rawData, Converter.DXTType DXTCFormat, int width, int height, SquishFlags format)
        {
            int mips = CalcMips(width, height);

            byte[] data         = new byte[CalcDataSize(DXTCFormat, width, height, mips)];
            int    lastLocation = 0;

            byte[] temp;

            byte[] map = SquishWrapper.SquishWrapper.CompressImage(rawData, width, height, (int)format);
            map.CopyTo(data, 0);
            lastLocation += map.Length;

            if (mips > 0)
            {
                for (int i = 1; i < mips; i++)
                {
                    double reduction = (double)Math.Pow(2, i);
                    int    redWidth  = (int)Math.Round(width / reduction);
                    int    redHeight = (int)Math.Round(height / reduction);
                    map = new byte[redWidth * redHeight * 4];
                    OpenILPort.Converter.Zoom(map, rawData, width, height, redWidth, redHeight, OpenILPort.Converter.Filter.Triangle, 1.0);
                    temp = SquishWrapper.SquishWrapper.CompressImage(map, redWidth, redHeight, (int)format);
                    temp.CopyTo(data, lastLocation);
                    lastLocation += temp.Length;
                }
            }

            return(MakeFromDDSCompressedImage(data, DXTCFormat, width, height));
        }
コード例 #2
0
ファイル: DDSFile.cs プロジェクト: Lewis-Bright/relic-tools
        public DDSFile(byte[] file)
        {
            data   = file;
            height = data[12] + (data[13] << 8) + (data[14] << 16) + (data[15] << 24);
            width  = data[16] + (data[17] << 8) + (data[18] << 16) + (data[19] << 24);

            switch (data[87])
            {
            case 0x31:
                type       = Converter.DXTType.DXT1;
                blockwidth = 8;
                alphawidth = 0;
                break;

            case 0x33:
                type       = Converter.DXTType.DXT3;
                blockwidth = 16;
                alphawidth = 8;
                break;

            case 0x35:
                type       = Converter.DXTType.DXT5;
                blockwidth = 16;
                alphawidth = 8;
                break;

            default:
                throw new InvalidOperationException("Unsupported DDS type - only DXT1, DXT3 and DXT5 are currently supported");
            }
        }
コード例 #3
0
ファイル: DDSFile.cs プロジェクト: Lewis-Bright/relic-tools
        public static DDSFile MakeFrom32bitBGRA(byte[] rawData, Converter.DXTType DXTCFormat, int width, int height)
        {
            byte[] data = new byte[rawData.Length];
            rawData.CopyTo(data, 0);

            for (int i = 0; i < data.Length; i += 4)
            {
                byte temp = data[i];
                data[i]     = data[i + 2];
                data[i + 2] = temp;
            }

            return(MakeFrom32bitRGBA(data, DXTCFormat, width, height));
        }
コード例 #4
0
ファイル: DDSFile.cs プロジェクト: Lewis-Bright/relic-tools
        private DDSFile(byte[] ddsData, int imgWidth, int imgHeight, Converter.DXTType compression)
        {
            data   = new byte[128 + ddsData.Length];
            type   = compression;
            width  = imgWidth;
            height = imgHeight;

            switch (type)
            {
            case Converter.DXTType.DXT1:
                blockwidth = 8;
                alphawidth = 0;
                Converter.DXT1_Header.CopyTo(data, 0);
                break;

            case Converter.DXTType.DXT3:
                blockwidth = 16;
                alphawidth = 8;
                Converter.DXT3_Header.CopyTo(data, 0);
                break;

            case Converter.DXTType.DXT5:
                blockwidth = 16;
                alphawidth = 8;
                Converter.DXT5_Header.CopyTo(data, 0);
                break;

            default:
                throw new InvalidOperationException("Unsupported DDS type - only DXT1, DXT3 and DXT5 are currently supported");
            }

            data[12] = (byte)height;
            data[13] = (byte)(height >> 8);
            data[14] = (byte)(height >> 16);
            data[15] = (byte)(height >> 24);
            data[16] = (byte)width;
            data[17] = (byte)(width >> 8);
            data[18] = (byte)(width >> 16);
            data[19] = (byte)(width >> 24);

            int mips = CalcMips(width, height);

            data[28] = (byte)mips;
            data[29] = (byte)(mips >> 8);
            data[30] = (byte)(mips >> 16);
            data[31] = (byte)(mips >> 24);

            ddsData.CopyTo(data, 128);
        }
コード例 #5
0
ファイル: DDSFile.cs プロジェクト: Lewis-Bright/relic-tools
 private static int BlockSize(Converter.DXTType type)
 {
     if (type == Converter.DXTType.DXT1)
     {
         return(8);
     }
     else if (type == Converter.DXTType.DXT5 || type == Converter.DXTType.DXT3)
     {
         return(16);
     }
     else
     {
         throw new InvalidOperationException("Unsupported DDS type - only DXT1, DXT3 and DXT5 are currently supported");
     }
 }
コード例 #6
0
ファイル: DDSFile.cs プロジェクト: Lewis-Bright/relic-tools
        private static int CalcDataSize(Converter.DXTType type, int width, int height, int mipmaps)
        {
            int  val   = 0;
            byte bytes = (byte)BlockSize(type);

            width  = width / 4;
            height = height / 4;

            for (int i = 0; i < mipmaps; i++)
            {
                val   += width * height * bytes;
                width  = (width > 1)?width / 2:1;
                height = (height > 1)?height / 2:1;
            }

            return(val);
        }
コード例 #7
0
ファイル: DDSFile.cs プロジェクト: Lewis-Bright/relic-tools
        public static DDSFile MakeFrom32bitRGBA(byte[] rawData, Converter.DXTType DXTCFormat, int width, int height)
        {
            SquishFlags format;

            switch (DXTCFormat)
            {
            case Converter.DXTType.DXT1: format = SquishFlags.kDxt1;
                break;

            case Converter.DXTType.DXT3: format = SquishFlags.kDxt3;
                break;

            case Converter.DXTType.DXT5: format = SquishFlags.kDxt5;
                break;

            default: throw new InvalidOperationException("Invalid DXT Type supplied: " + DXTCFormat.ToString());
            }

            return(MakeWithMipMapsFrom32bitRGBA(rawData, DXTCFormat, width, height, format));
        }
コード例 #8
0
ファイル: DXTFormat.cs プロジェクト: Lewis-Bright/relic-tools
 private void bttnDxt5_Click(object sender, System.EventArgs e)
 {
     ChosenFormat = Converter.DXTType.DXT5;
     this.Close();
 }
コード例 #9
0
ファイル: DDSFile.cs プロジェクト: Lewis-Bright/relic-tools
 public static DDSFile MakeFromDDSCompressedImage(byte[] rawData, Converter.DXTType DXTCFormat, int width, int height)
 {
     return(new DDSFile(rawData, width, height, DXTCFormat));
 }