public override void ImportFile(int index, string inPath)
        {
            if (index < 0 || index >= _TextureCount)
            {
                return;
            }

            DDSTextureHeader textureHeader  = new DDSTextureHeader();
            bool             isTextureValid = false;

            try
            {
                FileStream   iStreamIn = new FileStream(inPath, FileMode.Open, FileAccess.Read);
                BinaryReader iReaderIn = new BinaryReader(iStreamIn);

                textureHeader.ReadFromStream(iReaderIn);
                isTextureValid = textureHeader.Validate();

                iReaderIn.Close();
                iStreamIn.Close();
            }
            catch (Exception) { }

            if (!isTextureValid)
            {
                return;
            }

            _TextureDefinitions[index].NewTexturePath = inPath;
        }
        protected MemoryStream GetDXTCDataAsStream(int index)
        {
            int          streamLength = (int)(_TextureDefinitions[index].Length + 128); // size of DXTC header
            MemoryStream mStream      = new MemoryStream(streamLength);
            BinaryWriter mWriter      = new BinaryWriter(mStream);

            DDSTextureHeader textureHeader = new DDSTextureHeader();

            textureHeader.FromTextureDef(ref _TextureDefinitions[index]);
            textureHeader.WriteToSteam(mWriter);

            //byte[] dxtcZero = new byte[] { 0x00, 0x00, 0x00, 0x00 };

            //byte[] dxtcMagic = new byte[] { 0x44, 0x44, 0x53, 0x20 };
            //byte[] dxtcSize = new byte[] { 0x7C, 0x00, 0x00, 0x00 }; // is always 124
            //mWriter.Write(dxtcMagic);
            //mWriter.Write(dxtcSize);

            //byte[] dxtcFlags = new byte[] { 0x07, 0x10, 0x0A, 0x00 }; // ???
            //mWriter.Write(dxtcFlags);
            ////mWriter.Write(_TextureDefinitions[index].Flags1);
            ////byte[] dxtcFlags1a = new byte[] { 0x0A, 0x00 };
            ////mWriter.Write(dxtcFlags1a);

            //uint width = (uint)_TextureDefinitions[index].Width;
            //uint height = (uint)_TextureDefinitions[index].Height;
            //mWriter.Write(width);
            //mWriter.Write(height);

            //// uint linearsize
            //int blockSize = 16;
            //switch (_TextureDefinitions[index].Format)
            //{
            //    case VRMFormat.DXTC1:
            //        blockSize = 8;
            //        break;
            //}
            //uint linearSize = (uint)((width / 4) * (height / 4) * blockSize);
            //mWriter.Write(linearSize);

            //// uint depth
            //mWriter.Write(dxtcZero);

            //// uint mipmapcount
            //mWriter.Write(_TextureDefinitions[index].Flags2);

            //// 11 uints of zero
            //for (int i = 0; i < 11; i++)
            //{
            //    mWriter.Write(dxtcZero);
            //}

            //byte[] dxtcSize2 = new byte[] { 0x20, 0x00, 0x00, 0x00 }; // is always 32
            //byte[] dxtcFlags2 = new byte[] { 0x04, 0x00, 0x00, 0x00 }; // ???
            //mWriter.Write(dxtcSize2);
            //mWriter.Write(dxtcFlags2);
            //byte[] dxtcFourCC = new byte[0];
            //switch (_TextureDefinitions[index].Format)
            //{
            //    case VRMFormat.DXTC1:
            //        dxtcFourCC = new byte[] { 0x44, 0x58, 0x54, 0x31 };
            //        break;
            //    case VRMFormat.DXTC5:
            //        dxtcFourCC = new byte[] { 0x44, 0x58, 0x54, 0x35 }; // 0x33 as last digit = DXT3
            //        break;
            //}
            //mWriter.Write(dxtcFourCC);

            //byte[] dxtcBPP = new byte[] { 0x00, 0x00, 0x00, 0x00 }; // always zero?
            //byte[] dxtcMaskRed = new byte[] { 0x00, 0x00, 0x00, 0x00 }; // always zero?
            //byte[] dxtcMaskGreen = new byte[] { 0x00, 0x00, 0x00, 0x00 }; // always zero?
            //byte[] dxtcMaskBlue = new byte[] { 0x00, 0x00, 0x00, 0x00 }; // always zero?
            //byte[] dxtcMaskAlpha = new byte[] { 0x00, 0x00, 0x00, 0x00 }; // always zero?
            //mWriter.Write(dxtcBPP);
            //mWriter.Write(dxtcMaskRed);
            //mWriter.Write(dxtcMaskGreen);
            //mWriter.Write(dxtcMaskBlue);
            //mWriter.Write(dxtcMaskAlpha);

            //byte[] dxtcCaps1 = new byte[] { 0x08, 0x10, 0x40, 0x00 };
            //byte[] dxtcCaps2 = new byte[] { 0x00, 0x00, 0x00, 0x00 };
            //byte[] dxtcCaps3 = new byte[] { 0x00, 0x00, 0x00, 0x00 };
            //byte[] dxtcCaps4 = new byte[] { 0x00, 0x00, 0x00, 0x00 };
            //byte[] dxtcTextureStage = new byte[] { 0x00, 0x00, 0x00, 0x00 };
            //mWriter.Write(dxtcCaps1);
            //mWriter.Write(dxtcCaps2);
            //mWriter.Write(dxtcCaps3);
            //mWriter.Write(dxtcCaps4);
            //mWriter.Write(dxtcTextureStage);

            // get the actual texture data
            try
            {
                FileStream   iStream = new FileStream(_FilePath, FileMode.Open, FileAccess.Read);
                BinaryReader iReader = new BinaryReader(iStream);

                iStream.Seek(_TextureDefinitions[index].Offset + 16, SeekOrigin.Begin);
                int length = (int)(_TextureDefinitions[index].Length - 16);
                for (int byteNum = 0; byteNum < length; byteNum++)
                {
                    mWriter.Write(iReader.ReadByte());
                }

                iReader.Close();
                iStream.Close();
            }
            catch (Exception ex)
            {
                throw new TextureFileException("Error reading texture data from file.", ex);
            }
            mStream.Seek(0, SeekOrigin.Begin);
            return(mStream);
        }
        public bool Validate()
        {
            // bool isPowerOfTwo = (x != 0) && ((x & (x - 1)) == 0);
            if ((dxtcWidth < 0) || ((dxtcWidth & (dxtcWidth - 1)) != 0) ||
                (dxtcHeight < 0) || ((dxtcHeight & (dxtcHeight - 1)) != 0))
            {
                return(false);
            }

            VRMFormat format = VRMFormat.Uncompressed;

            switch (dxtcFourCC.b3)
            {
            case 0x31:
                format = VRMFormat.DXTC1;
                break;

            case 0x35:
                format = VRMFormat.DXTC5;
                break;

            default:
                return(false);
            }

            DDSTextureHeader ddsHeader = new DDSTextureHeader();

            ddsHeader.Initialise(
                dxtcWidth,
                dxtcHeight,
                format,
                dxtcMipMapCount
                );

            bool isValid = true;

            isValid &= (dxtcMagic.u == ddsHeader.dxtcMagic.u);
            isValid &= (dxtcSize.u == ddsHeader.dxtcSize.u);
            // My edited glyph texture has no linear size, but apparantly we can just calculate it.
            // Safe to ignore in validate function?
            // isValid &= (dxtcFlags.u == ddsHeader.dxtcFlags.u);
            isValid &= (dxtcWidth == ddsHeader.dxtcWidth);
            isValid &= (dxtcHeight == ddsHeader.dxtcHeight);
            // isValid &= (dxtcLinearSize == ddsHeader.dxtcLinearSize);
            isValid &= (dxtcDepth == ddsHeader.dxtcDepth);
            isValid &= (dxtcMipMapCount == ddsHeader.dxtcMipMapCount);
            isValid &= (dxtcSize2.u == ddsHeader.dxtcSize2.u);
            isValid &= (dxtcFlags2.u == ddsHeader.dxtcFlags2.u);
            isValid &= (dxtcFourCC.u == ddsHeader.dxtcFourCC.u);
            isValid &= (dxtcBPP.u == ddsHeader.dxtcBPP.u);
            isValid &= (dxtcMaskRed.u == ddsHeader.dxtcMaskRed.u);
            isValid &= (dxtcMaskGreen.u == ddsHeader.dxtcMaskGreen.u);
            isValid &= (dxtcMaskBlue.u == ddsHeader.dxtcMaskBlue.u);
            isValid &= (dxtcMaskAlpha.u == ddsHeader.dxtcMaskAlpha.u);
            isValid &= (dxtcCaps1.u == ddsHeader.dxtcCaps1.u);
            isValid &= (dxtcCaps2.u == ddsHeader.dxtcCaps2.u);
            isValid &= (dxtcCaps3.u == ddsHeader.dxtcCaps3.u);
            isValid &= (dxtcCaps4.u == ddsHeader.dxtcCaps4.u);
            isValid &= (dxtcTextureStage.u == ddsHeader.dxtcTextureStage.u);

            if (isValid)
            {
                return(true);
            }

            return(false);
        }