Inheritance: GameDatabase.TextureInfo
        public static TextureInfoWrapper DDSToTexture(UrlDir.UrlFile file, TexInfo Texture, bool mipmaps, bool isCompressed, bool hasAlpha)
        {
            TextureConverter.InitImageBuffer();
            FileStream imgStream = new FileStream(Texture.filename, FileMode.Open, FileAccess.Read);
            imgStream.Position = 0;
            imgStream.Read(imageBuffer, 0, MAX_IMAGE_SIZE);
            imgStream.Close();

            TextureFormat format = TextureFormat.DXT1;
            if(hasAlpha && isCompressed)
            {
                format = TextureFormat.DXT5;
            }
            else if(hasAlpha)
            {
                format = TextureFormat.RGBA32;
            }
            else if(!isCompressed)
            {
                format = TextureFormat.RGB24;
            }

            Texture2D newTex = new Texture2D(Texture.width, Texture.height, format, mipmaps);

            newTex.LoadRawTextureData(imageBuffer);
            newTex.Apply(false, Texture.makeNotReadable);
            newTex.name = Texture.name;

            TextureInfoWrapper newTexInfo = new TextureInfoWrapper(file, newTex, Texture.isNormalMap, !Texture.makeNotReadable, isCompressed);
            newTexInfo.name = Texture.name;
            return newTexInfo;
        }
        public static void GetReadable(TexInfo Texture, bool mipmaps)
        {
            String mbmPath = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".mbm";
            String pngPath = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".png";
            String pngPathTruecolor = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".truecolor";
            String jpgPath = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".jpg";
            String tgaPath = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".tga";
            if (File.Exists(pngPath) || File.Exists(pngPathTruecolor) || File.Exists(jpgPath) || File.Exists(tgaPath) || File.Exists(mbmPath))
            {
                Texture2D tex = new Texture2D(2, 2);
                String name;
                if (Texture.name.Length > 0)
                {
                    name = Texture.name;
                }
                else
                {
                    name = Texture.name;
                }

                TextureInfoWrapper newTexture = new TextureInfoWrapper(Texture.file, tex, Texture.isNormalMap, true, false);
                Texture.texture = newTexture;
                newTexture.name = Texture.name;
                if (File.Exists(pngPath))
                {
                    Texture.filename = pngPath;
                    IMGToTexture(Texture, mipmaps, false);
                }
                else if (File.Exists(pngPathTruecolor))
                {
                    Texture.filename = pngPathTruecolor;
                    IMGToTexture(Texture, mipmaps, false);
                }
                else if (File.Exists(jpgPath))
                {
                    Texture.filename = jpgPath;
                    IMGToTexture(Texture, mipmaps, false);
                }
                else if (File.Exists(tgaPath))
                {
                    Texture.filename = tgaPath;
                    TGAToTexture(Texture, mipmaps);
                }
                else if (File.Exists(mbmPath))
                {
                    Texture.filename = mbmPath;
                    MBMToTexture(Texture, mipmaps);

                }
                tex.name = newTexture.name;
            }
        }
        public static void Resize(TextureInfoWrapper texture, int width, int height, bool mipmaps, bool convertToNormalFormat)
        {
            ActiveTextureManagement.DBGLog("Resizing...");
            Texture2D tex = texture.texture;
            TextureFormat format = tex.format;
            if (texture.isNormalMap)
            {
                format = TextureFormat.ARGB32;
            }
            else if (format == TextureFormat.DXT1 || format == TextureFormat.RGB24)
            {
                format = TextureFormat.RGB24;
            }
            else
            {
                format = TextureFormat.RGBA32;
            }

            Color32[] pixels = tex.GetPixels32();
            if (convertToNormalFormat)
            {
                ConvertToUnityNormalMap(pixels);
            }

            Color32[] newPixels = ResizePixels(pixels, tex.width, tex.height, width, height);
            tex.Resize(width, height, format, mipmaps);
            tex.SetPixels32(newPixels);
            tex.Apply(mipmaps);
        }
        public static TextureInfoWrapper FetchCacheTexture(TexInfo Texture, bool compress, bool mipmaps)
        {
            String textureName = Texture.name;
            String originalTextureFile = KSPUtil.ApplicationRootPath + "GameData/" + textureName;
            String cacheFile = KSPUtil.ApplicationRootPath + "GameData/ActiveTextureManagement/textureCache/" + textureName;
            String cacheConfigFile = cacheFile + ".tcache";
            cacheFile += ".imgcache";

            String hashString = GetMD5String(originalTextureFile);
            if (TextureHashTable.ContainsKey(hashString))
            {
                ActiveTextureManagement.DBGLog("hash triggered... " + textureName);
                TextureInfoWrapper tex = TextureHashTable[hashString];
                if (tex.name != textureName)
                {
                    TextureInfoWrapper cacheTexInfo = new TextureInfoWrapper(Texture.file, tex.texture, tex.isNormalMap, tex.isReadable, tex.isCompressed);
                    cacheTexInfo.name = textureName;
                    ActiveTextureManagement.DBGLog("Re-using from hash dictionary... " + textureName+" is a duplicate of "+tex.name);

                    return cacheTexInfo;
                }
            }

            if (File.Exists(cacheConfigFile))
            {
                ConfigNode config = ConfigNode.Load(cacheConfigFile);
                string format = config.GetValue("orig_format");
                String cacheHash = config.GetValue("md5");
                int origWidth, origHeight;
                string origWidthString = config.GetValue("orig_width");
                string origHeightString = config.GetValue("orig_height");
                int.TryParse(origWidthString, out origWidth);
                int.TryParse(origHeightString, out origHeight);

                if (origWidthString == null || origHeightString == null ||
                    cacheHash == null || format == null)
                {
                    return RebuildCache(Texture, compress, mipmaps, hashString );
                }

                originalTextureFile += format;
                Texture.Resize(origWidth, origHeight);

                if (format != null && File.Exists(originalTextureFile) && File.Exists(cacheFile))
                {

                    String cacheIsNormString = config.GetValue("is_normal");
                    String cacheIsCompressed = config.GetValue("is_compressed");
                    String cacheWidthString = config.GetValue("width");
                    String cacheHeihtString = config.GetValue("height");
                    string hasAlphaString = config.GetValue("hasAlpha");
                    string hasMipmapsString = config.GetValue("hasMipmaps");
                    bool cacheIsNorm = false;
                    int cacheWidth = 0;
                    int cacheHeight = 0;
                    bool hasAlpha = true;
                    bool hasMipmaps = true;
                    bool isCompressed = true;
                    bool.TryParse(cacheIsNormString, out cacheIsNorm);
                    bool.TryParse(cacheIsCompressed, out isCompressed);
                    int.TryParse(cacheWidthString, out cacheWidth);
                    int.TryParse(cacheHeihtString, out cacheHeight);
                    bool.TryParse(hasAlphaString, out hasAlpha);
                    bool.TryParse(hasMipmapsString, out hasMipmaps);

                    if (cacheHash != hashString || compress != isCompressed || mipmaps != hasMipmaps || cacheIsNorm != Texture.isNormalMap || Texture.resizeWidth != cacheWidth || Texture.resizeHeight != cacheHeight)
                    {
                        if (cacheHash != hashString)
                        {
                            ActiveTextureManagement.DBGLog(cacheHash + " != " + hashString);
                        }
                        if (cacheIsNorm != Texture.isNormalMap)
                        {
                            ActiveTextureManagement.DBGLog(cacheIsNorm + " != " + Texture.isNormalMap);
                        }
                        if (Texture.resizeWidth != cacheWidth)
                        {
                            ActiveTextureManagement.DBGLog(Texture.resizeWidth + " != " + cacheWidth);
                        }
                        if (Texture.resizeHeight != cacheHeight)
                        {
                            ActiveTextureManagement.DBGLog(Texture.resizeHeight + " != " + cacheHeight);
                        }
                        return RebuildCache(Texture, compress, mipmaps, hashString);
                    }
                    else
                    {
                        ActiveTextureManagement.DBGLog("Loading from cache... " + textureName);
                        Texture.needsResize = false;
                        Texture.width = Texture.resizeWidth;
                        Texture.height = Texture.resizeHeight;
                        Texture.filename = cacheFile;
                        TextureInfoWrapper tex = TextureConverter.DDSToTexture(Texture.file, Texture, hasMipmaps, isCompressed, hasAlpha);
                        if (TextureHashTable.ContainsKey(hashString))
                        {
                            TextureHashTable[hashString] = tex;
                        }
                        else
                        {
                            TextureHashTable.Add(hashString, tex);
                        }

                        return tex;
                    }
                }
                else
                {
                    return RebuildCache(Texture, compress, mipmaps, hashString);
                }
            }
            else
            {
                return RebuildCache(Texture, compress, mipmaps, hashString);
            }
        }