public CRNTextureImporter(byte[] data)
        {
            var  converter = new EndianBitConverter();
            uint sig       = converter.ToUInt16(data, 0);

            if (sig != SigValue)
            {
                converter.InvertEndian = true;
                sig = converter.ToUInt16(data, 0);
                if (sig != SigValue)
                {
                    throw new Exception("Invalid CRN Texture.");
                }
            }

            HeaderSize = converter.ToUInt16(data, 2);
            CRC16      = converter.ToUInt16(data, 4);
            DataSize   = converter.ToUInt32(data, 6);
            DataCRC16  = converter.ToUInt16(data, 10);

            Width  = converter.ToUInt16(data, 12);
            Height = converter.ToUInt16(data, 14);
            Levels = data[16];
            Faces  = data[17];
            Format = (CRNFormat)data[18];
            Flags  = (CRNHeaderFlags)converter.ToUInt16(data, 19);

            UserData0 = converter.ToUInt32(data, 25);
            UserData1 = converter.ToUInt32(data, 29);

            byte[]    dxtData = unitils.UnityCRN.Transcode(data);
            Texture2D tex; // Bad, prefer direct conversion instead of using Texture2D

            if (ImageConversion.LoadDDSImage(dxtData, out tex))
            {
                RawTextureData = tex.GetRawTextureData();
            }
        }
Beispiel #2
0
        public DDSTextureImporter(byte[] data)
        {
            var  converter = new EndianBitConverter();
            uint magic     = converter.ToUInt32(data, 0);

            if (magic != DwMagic)
            {
                converter.InvertEndian = true;
                magic = converter.ToUInt32(data, 0);
                if (magic != DwMagic)
                {
                    throw new Exception("Invalid DDS Texture.");
                }
            }

            HeaderSize        = converter.ToUInt32(data, 4);
            Flags             = (DDSHeaderFlags)converter.ToUInt32(data, 8);
            Height            = converter.ToUInt32(data, 12);
            Width             = converter.ToUInt32(data, 16);
            PitchOrLinearSize = converter.ToUInt32(data, 20);
            Depth             = converter.ToUInt32(data, 24);
            MipMapCount       = converter.ToUInt32(data, 28);

            PixelFormat.Size        = converter.ToUInt32(data, 76);
            PixelFormat.Flags       = (DDSPixelFormatFlags)converter.ToUInt32(data, 80);
            converter.InvertEndian  = true;
            PixelFormat.FourCC      = (DDSFormat)converter.ToUInt32(data, 84);
            converter.InvertEndian  = false;
            PixelFormat.RGBBitCount = converter.ToUInt32(data, 88);
            PixelFormat.RBitMask    = converter.ToUInt32(data, 92);
            PixelFormat.GBitMask    = converter.ToUInt32(data, 96);
            PixelFormat.BBitMask    = converter.ToUInt32(data, 100);
            PixelFormat.ABitMask    = converter.ToUInt32(data, 104);

            Caps  = converter.ToUInt32(data, 108);
            Caps2 = converter.ToUInt32(data, 112);

            RawTextureData = new byte[data.Length - 128];
            Buffer.BlockCopy(data, 128, RawTextureData, 0, data.Length - 128);
        }