/// <summary> /// Takes a URL of a downloadable image and the name of the local image to be used as a fallback. If the image has /// been downloaded, returns the GL texture of the downloaded image, otherwise returns the GL texture of the fallback /// image. /// </summary> public string GetTextureForDownloadableImage(string par1Str, string par2Str) { ThreadedImageDownloader threaddownloadimagedata = urlToImageDataMap[par1Str]; if (threaddownloadimagedata != null && threaddownloadimagedata.Image != null && !threaddownloadimagedata.TextureSetupComplete) { if (threaddownloadimagedata.TextureName == "") { threaddownloadimagedata.TextureName = AllocateTexture(threaddownloadimagedata.Image); } else { //SetupTexture(threaddownloadimagedata.Image, threaddownloadimagedata.TextureName); } threaddownloadimagedata.TextureSetupComplete = true; } if (threaddownloadimagedata == null || threaddownloadimagedata.TextureName == "") { if (par2Str == null) { return(""); } else { return(par2Str); } } else { return(threaddownloadimagedata.TextureName); } }
/// <summary> /// Return a ThreadDownloadImageData instance for the given URL. If it does not already exist, it is created and /// uses the passed ImageBuffer. If it does, its reference count is incremented. /// </summary> public ThreadedImageDownloader ObtainImageData(string par1Str, ImageBuffer par2ImageBuffer) { ThreadedImageDownloader threaddownloadimagedata = null; if (urlToImageDataMap.ContainsKey(par1Str)) { threaddownloadimagedata = urlToImageDataMap[par1Str]; } if (threaddownloadimagedata == null) { urlToImageDataMap.Add(par1Str, new ThreadedImageDownloader(par1Str, par2ImageBuffer)); } else { threaddownloadimagedata.ReferenceCount++; } return(threaddownloadimagedata); }
/// <summary> /// Takes a URL of a downloadable image and the name of the local image to be used as a fallback. If the image has /// been downloaded, returns the GL texture of the downloaded image, otherwise returns the GL texture of the fallback /// image. /// </summary> public virtual int GetTextureForDownloadableImage(string par1Str, string par2Str) { ThreadedImageDownloader threaddownloadimagedata = UrlToImageDataMap[par1Str]; /* * if (threaddownloadimagedata != null && threaddownloadimagedata.Image != null && !threaddownloadimagedata.TextureSetupComplete) * { * if (threaddownloadimagedata.TextureName < 0) * { * threaddownloadimagedata.TextureName = AllocateAndSetupTexture(threaddownloadimagedata.Image); * } * else * { * SetupTexture(threaddownloadimagedata.Image, threaddownloadimagedata.TextureName); * } * * threaddownloadimagedata.TextureSetupComplete = true; * } * * if (threaddownloadimagedata == null || threaddownloadimagedata.TextureName < 0) * { * if (par2Str == null) * { * return -1; * } * else * { * return GetTexture(par2Str); * } * } * else * { * return threaddownloadimagedata.TextureName; * }*/ return(-1); }
/// <summary> /// Decrements the reference count for a given URL, deleting the image data if the reference count hits 0 /// </summary> public void ReleaseImageData(string par1Str) { ThreadedImageDownloader threaddownloadimagedata = null; if (urlToImageDataMap.ContainsKey(par1Str)) { threaddownloadimagedata = urlToImageDataMap[par1Str]; } if (threaddownloadimagedata != null) { threaddownloadimagedata.ReferenceCount--; if (threaddownloadimagedata.ReferenceCount == 0) { if (threaddownloadimagedata.TextureName == "") { DeleteTexture(threaddownloadimagedata.TextureName); } urlToImageDataMap.Remove(par1Str); } } }
/// <summary> /// Call setupTexture on all currently-loaded textures again to account for changes in rendering options /// </summary> public void RefreshTextures() { TexturePackBase texturepackbase = TexturePack.SelectedTexturePack; int i; Bitmap bufferedimage; for (IEnumerator <int> iterator = TextureNameToImageMap.GetKeySet().GetEnumerator(); iterator.MoveNext(); SetupTexture(bufferedimage, i)) { i = iterator.Current; bufferedimage = (Bitmap)TextureNameToImageMap.Lookup(i); } for (IEnumerator <ThreadedImageDownloader> iterator1 = UrlToImageDataMap.Values.GetEnumerator(); iterator1.MoveNext();) { ThreadedImageDownloader threaddownloadimagedata = iterator1.Current; threaddownloadimagedata.TextureSetupComplete = false; } for (IEnumerator <string> iterator2 = TextureMap.Keys.GetEnumerator(); iterator2.MoveNext();) { string s = (string)iterator2.Current; try { Bitmap bufferedimage1; if (s.StartsWith("##")) { bufferedimage1 = UnwrapImageByColumns(ReadTextureImage(texturepackbase.GetResourceAsStream(s.Substring(2)))); } else if (s.StartsWith("%clamp%")) { ClampTexture = true; bufferedimage1 = ReadTextureImage(texturepackbase.GetResourceAsStream(s.Substring(7))); } else if (s.StartsWith("%blur%")) { BlurTexture = true; bufferedimage1 = ReadTextureImage(texturepackbase.GetResourceAsStream(s.Substring(6))); } else if (s.StartsWith("%blurclamp%")) { BlurTexture = true; ClampTexture = true; bufferedimage1 = ReadTextureImage(texturepackbase.GetResourceAsStream(s.Substring(11))); } else { bufferedimage1 = ReadTextureImage(texturepackbase.GetResourceAsStream(s)); } int j = TextureMap[s]; SetupTexture(bufferedimage1, j); BlurTexture = false; ClampTexture = false; } catch (IOException ioexception) { Utilities.LogException(ioexception); } } for (IEnumerator <string> iterator3 = TextureContentsMap.Keys.GetEnumerator(); iterator3.MoveNext();) { string s1 = (string)iterator3.Current; try { Bitmap bufferedimage2; if (s1.StartsWith("##")) { bufferedimage2 = UnwrapImageByColumns(ReadTextureImage(texturepackbase.GetResourceAsStream(s1.Substring(2)))); } else if (s1.StartsWith("%clamp%")) { ClampTexture = true; bufferedimage2 = ReadTextureImage(texturepackbase.GetResourceAsStream(s1.Substring(7))); } else if (s1.StartsWith("%blur%")) { BlurTexture = true; bufferedimage2 = ReadTextureImage(texturepackbase.GetResourceAsStream(s1.Substring(6))); } else { bufferedimage2 = ReadTextureImage(texturepackbase.GetResourceAsStream(s1)); } GetImageContents(bufferedimage2, (int[])TextureContentsMap[s1]); BlurTexture = false; ClampTexture = false; } catch (IOException ioexception1) { Utilities.LogException(ioexception1); } } }