AssetData
public static void ImageDecompress(AssetBase assetBase) { if (assetBase == null) return; AssetType type = (AssetType)assetBase.Type; AssetTexture texture = null; switch(type) { case AssetType.ImageJPEG: case AssetType.ImageTGA: case AssetType.Texture: // Jpeg2000 case AssetType.TextureTGA: texture = new AssetTexture(new UUID(assetBase.ID), assetBase.Data); break; } if (texture == null) return; if (type == AssetType.Texture) { try { if (texture.Decode()) assetBase.Data = texture.Image.ExportTGA(); } catch { } } }
public override string Execute(string[] args, UUID fromAgentID) { if (args.Length != 1 && args.Length != 2) return "Usage: downloadtexture [texture-uuid] [discardlevel]"; TextureID = UUID.Zero; DownloadHandle.Reset(); Image = null; Asset = null; if (UUID.TryParse(args[0], out TextureID)) { int discardLevel = 0; if (args.Length > 1) { if (!Int32.TryParse(args[1], out discardLevel)) return "Usage: downloadtexture [texture-uuid] [discardlevel]"; } Client.Assets.RequestImage(TextureID, ImageType.Normal, 1000000.0f, discardLevel, 0); if (DownloadHandle.WaitOne(120 * 1000, false)) { if (Image != null && Image.Success) { if (Asset != null && Asset.Decode()) { try { File.WriteAllBytes(Image.ID.ToString() + ".jp2", Asset.AssetData); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); } return String.Format("Saved {0}.jp2 ({1}x{2})", Image.ID, Asset.Image.Width, Asset.Image.Height); } else { return "Failed to decode texture " + TextureID.ToString(); } } else if (Image != null && Image.NotFound) { return "Simulator reported texture not found: " + TextureID.ToString(); } else { return "Download failed for texture " + TextureID.ToString(); } } else { return "Timed out waiting for texture download"; } } else { return "Usage: downloadtexture [texture-uuid]"; } }
private void AssetImageFactory(ImageDownload image, AssetTexture asset) { string extension = "tga"; byte[] data = asset.AssetData; switch (asset.AssetType) { case AssetType.ImageJPEG: extension = "jpg"; break; case AssetType.Texture: if (asset.Decode()) data = asset.Image.ExportTGA(); else data = null; break; } if (data == null) return; Ox.IO.Save(string.Format("{0}.{1}", asset.AssetID.ToString(), extension), data); }
// LibOMV callback for completed image texture. public void imageReceivedCallback(AssetTexture asset) { if (asset == null) { m_log.Debug("[TEXTURE]: GotLIBOMV callback but asset was null"); return; } m_log.Debug("[TEXTURE]: GotLIBOMV callback for asset" + asset.AssetID); lock (downloadQueue) { if (downloadQueue.ContainsKey(asset.AssetID)) downloadQueue.Remove(asset.AssetID); } bool result = false; bool bNonJp2000 = true; string extension = string.Empty; try { AssetType type = asset.AssetType; if (asset is OpenViewer.Primitives.ExtendedAssetTexture) { type = (AssetType)((OpenViewer.Primitives.ExtendedAssetTexture)asset).ExtAssetType; //Paupaw:Get the AssetType switch (type) { case AssetType.ImageJPEG: result = true; extension = ".jpg"; break; case AssetType.ImageTGA: result = true; extension = ".tga"; break; case AssetType.Texture: //JP2000 bNonJp2000 = false; result = asset.Decode(); extension = ".tga"; break; } } else if (asset is AssetTexture) { bNonJp2000 = false; result = asset.Decode(); extension = ".tga"; } else { result = true; extension = ".jpg"; } } catch (Exception e) { //m_log.Debug("[TEXTURE]: Failed to decode asset " + asset.AssetID); if (!bNonJp2000) { bNonJp2000 = true; result = true; extension = ".jpg"; } } if (result) { byte[] imgdata = null; if (bNonJp2000) imgdata = asset.AssetData; else imgdata = asset.Image.ExportTGA(); string texturefolderpath = imagefolder; string texturepath = System.IO.Path.Combine(texturefolderpath, asset.AssetID.ToString() + extension); FileStream fs = (File.Open(texturepath, FileMode.Create)); BinaryWriter bw = new BinaryWriter(fs); bw.Write(imgdata); bw.Flush(); bw.Close(); // Immediately load it to memory if (File.Exists(System.IO.Path.Combine(texturefolderpath, asset.AssetID.ToString() + extension))) { Texture texTnorm = Reference.VideoDriver.GetTexture(System.IO.Path.Combine(texturefolderpath, asset.AssetID.ToString() + extension)); TextureExtended tex = new TextureExtended(texTnorm.Raw, extension); if (tex != null) { lock (memoryTextures) { if (!memoryTextures.ContainsKey(asset.AssetID)) { memoryTextures.Add(asset.AssetID, tex); } } } } // Update nodes that the texture is downloaded. List<VObject> nodesToUpdate = null; lock (outstandingRequests) { if (outstandingRequests.ContainsKey(asset.AssetID)) { nodesToUpdate = outstandingRequests[asset.AssetID]; outstandingRequests.Remove(asset.AssetID); } } if (nodesToUpdate == null) return; lock (nodesToUpdate) { for (int i = 0; i < nodesToUpdate.Count; i++) { VObject vObj = nodesToUpdate[i]; if (vObj == null || OnTextureLoaded == null) continue; OnTextureLoaded(asset.AssetID.ToString(), extension, vObj, asset.AssetID); Reference.Viewer.Adapter.CallReceiveImage(asset.AssetID.ToString()); } } } }
private void Assets_OnImageReceived(ImageDownload image, AssetTexture asset) { if (Textures.Contains(image.ID)) { lock (Textures) Textures.Remove(image.ID); if (image.Success) { try { File.WriteAllBytes(image.ID.ToString() + ".jp2", asset.AssetData); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); } if (asset.Decode()) { try { File.WriteAllBytes(image.ID.ToString() + ".tga", asset.Image.ExportTGA()); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); } } else { Logger.Log("Failed to decode image " + image.ID.ToString(), Helpers.LogLevel.Error, Client); } Logger.Log("Finished downloading image " + image.ID.ToString(), Helpers.LogLevel.Info, Client); } else { Logger.Log("Failed to download image " + image.ID.ToString(), Helpers.LogLevel.Warning, Client); } } }
// LibOMV callback for completed image texture. public void imageReceivedCallback(AssetTexture asset) { if (asset == null) { m_log.Debug("[TEXTURE]: GotLIBOMV callback but asset was null"); lock (ouststandingRequests) { } return; } m_log.Debug("[TEXTURE]: GotLIBOMV callback for asset" + asset.AssetID); lock (downloadQueue) { if (downloadQueue.ContainsKey(asset.AssetID)) downloadQueue.Remove(asset.AssetID); } bool result = false; bool bNonJp2000 = true; string strExtension = ".tga"; try { if (asset is AssetTexture) { bNonJp2000 = false; result = asset.Decode(); } else { //Paupaw:Get the AssetType switch (((OpenViewer.Primitives.ExtendedAssetTexture)asset).ExtAssetType) { case (int)AssetType.ImageJPEG: result = true; strExtension = ".jpg"; break; case (int)AssetType.ImageTGA: result = true; strExtension = ".tga"; break; case (int)AssetType.Texture: //JP2000 bNonJp2000 = false; result = asset.Decode(); break; } } } catch (Exception) { m_log.Debug("[TEXTURE]: Failed to decode asset " + asset.AssetID); } if (result) { // Write it to disk for picking up later in the pipeline. string texturefolderpath = imagefolder; string texturepath = System.IO.Path.Combine(texturefolderpath,asset.AssetID.ToString() + strExtension); byte[] imgdata = null; if (bNonJp2000) { imgdata = asset.AssetData; } else { imgdata = asset.Image.ExportTGA(); } FileStream fi = (File.Open(texturepath, FileMode.Create)); BinaryWriter bw = new BinaryWriter(fi); bw.Write(imgdata); bw.Flush(); bw.Close(); // Update nodes that the texture is downloaded. List<VObject> nodesToUpdate = new List<VObject>(); lock (ouststandingRequests) { if (ouststandingRequests.ContainsKey(asset.AssetID)) { nodesToUpdate = ouststandingRequests[asset.AssetID]; ouststandingRequests.Remove(asset.AssetID); } } lock (nodesToUpdate) { for (int i = 0; i < nodesToUpdate.Count; i++) { VObject vObj = nodesToUpdate[i]; if (vObj != null) { if (OnTextureLoaded != null) { OnTextureLoaded(asset.AssetID.ToString(), strExtension, vObj, asset.AssetID); } } } } } }