Esempio n. 1
0
        private void Assets_OnImageReceived(ImageDownload image, AssetTexture assetTexture)
        {
            lock (OutfitAssets)
            {
                if (OutfitAssets.Contains(image.ID))
                {
                    if (image.Success)
                    {
                        try
                        {
                            File.WriteAllBytes(image.ID.ToString() + ".jp2", image.AssetData);
                            Console.WriteLine("Wrote JPEG2000 image " + image.ID.ToString() + ".jp2");

                            byte[] tgaFile = OpenJPEGNet.OpenJPEG.DecodeToTGA(image.AssetData);
                            File.WriteAllBytes(image.ID.ToString() + ".tga", tgaFile);
                            Console.WriteLine("Wrote TGA image " + image.ID.ToString() + ".tga");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Failed to download image " + image.ID.ToString());
                    }

                    OutfitAssets.Remove(image.ID);

                    if (OutfitAssets.Count == 0)
                        Client.Assets.OnImageReceived -= ImageReceivedHandler;
                }
            }
        }
        private void Assets_OnImageReceived(ImageDownload image, AssetTexture asset)
        {
            Image = image;
            Asset = asset;

            DownloadHandle.Set();
        }
Esempio n. 3
0
        void Assets_OnImageReceived(ImageDownload image, AssetTexture assetTexture)
        {
            ManagedImage imgData;
            Image bitmap;

            if (image.Success)
            {
                OpenJPEG.DecodeToImage(image.AssetData, out imgData, out bitmap);
                picInsignia.Image = bitmap;
            }
        }
        public override string Execute(string[] args, LLUUID fromAgentID)
        {
            if (args.Length != 1)
                return "Usage: downloadtexture [texture-uuid]";

            TextureID = LLUUID.Zero;
            DownloadHandle.Reset();
            Image = null;
            Asset = null;

            if (LLUUID.TryParse(args[0], out TextureID))
            {
                Client.Assets.RequestImage(TextureID, ImageType.Normal);
                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]";
            }
        }
Esempio n. 5
0
        //comes in on separate thread
        private void Assets_OnImageReceived(ImageDownload image, AssetTexture texture)
        {
            if (image.ID != item.AssetUUID) return;

            BeginInvoke(new OnSetStatusText(SetStatusText), new object[] { "Image downloaded. Decoding..." });

            System.Drawing.Image decodedImage = ImageHelper.Decode(image.AssetData);

            if (decodedImage == null)
            {
                BeginInvoke(new OnSetStatusText(SetStatusText), new object[] { "D'oh! Error decoding image." });
                BeginInvoke(new MethodInvoker(DoErrorState));
                return;
            }

            instance.ImageCache.AddImage(image.ID, decodedImage);
            BeginInvoke(new OnSetFinalImage(SetFinalImage), new object[] { decodedImage });
        }
Esempio n. 6
0
        //comes in on a separate thread
        private void Assets_OnImageReceived(ImageDownload image, AssetTexture texture)
        {
            if (image.ID != SLImageID && image.ID != FLImageID) return;

            System.Drawing.Image decodedImage = ImageHelper.Decode(image.AssetData);

            if (decodedImage == null)
            {
                if (image.ID == SLImageID) BeginInvoke(new MethodInvoker(SetBlankSLImage));
                else if (image.ID == FLImageID) BeginInvoke(new MethodInvoker(SetBlankFLImage));

                return;
            }

            instance.ImageCache.AddImage(image.ID, decodedImage);

            BeginInvoke(
                new OnSetProfileImage(SetProfileImage),
                new object[] { image.ID, decodedImage });
        }
Esempio n. 7
0
        private Asset CreateAssetWrapper(AssetType type)
        {
            Asset asset;

            switch (type)
            {
            case AssetType.Notecard:
                asset = new AssetNotecard();
                break;

            case AssetType.LSLText:
                asset = new AssetScriptText();
                break;

            case AssetType.LSLBytecode:
                asset = new AssetScriptBinary();
                break;

            case AssetType.Texture:
                asset = new AssetTexture();
                break;

            case AssetType.Object:
                asset = new AssetPrim();
                break;

            case AssetType.Clothing:
                asset = new AssetClothing();
                break;

            case AssetType.Bodypart:
                asset = new AssetBodypart();
                break;

            default:
                Client.Log("Unimplemented asset type: " + type, Helpers.LogLevel.Error);
                return(null);
            }

            return(asset);
        }
Esempio n. 8
0
        private Asset CreateAssetWrapper(AssetType type)
        {
            Asset asset;

            switch (type)
            {
                case AssetType.Notecard:
                    asset = new AssetNotecard();
                    break;
                case AssetType.LSLText:
                    asset = new AssetScriptText();
                    break;
                case AssetType.LSLBytecode:
                    asset = new AssetScriptBinary();
                    break;
                case AssetType.Texture:
                    asset = new AssetTexture();
                    break;
                case AssetType.Primitive:
                    asset = new AssetPrim();
                    break;
                case AssetType.Clothing:
                    asset = new AssetClothing();
                    break;
                case AssetType.Bodypart:
                    asset = new AssetBodypart();
                    break;
                default:
                    Client.Log("Unimplemented asset type: " + type, Helpers.LogLevel.Error);
                    return null;
            }

            return asset;
        }
Esempio n. 9
0
 void Assets_OnImageReceived(ImageDownload image, AssetTexture assetTexture)
 {
     if (image.Success)
         picInsignia.Image = OpenJPEGNet.OpenJPEG.DecodeToImage(image.AssetData);
 }
Esempio n. 10
0
        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) { Client.Log(ex.Message, Helpers.LogLevel.Error); }

                    if (asset.Decode())
                    {
                        try { File.WriteAllBytes(image.ID.ToString() + ".tga", asset.Image.ExportTGA()); }
                        catch (Exception ex) { Client.Log(ex.Message, Helpers.LogLevel.Error); }
                    }
                    else
                    {
                        Client.Log("Failed to decode image " + image.ID.ToString(), Helpers.LogLevel.Error);
                    }

                    Client.Log("Finished downloading image " + image.ID.ToString(), Helpers.LogLevel.Info);
                }
                else
                {
                    Client.Log("Failed to download image " + image.ID.ToString(), Helpers.LogLevel.Warning);
                }
            }
        }
Esempio n. 11
0
        private void Assets_OnImageReceived(ImageDownload image, AssetTexture assetTexture)
        {
            lock (ImageDownloads)
            {
                if (ImageDownloads.ContainsKey(image.ID))
                {
                    // NOTE: this image may occupy more than one TextureIndex! We must finish this loop
                    for (int at = 0; at < AgentTextures.Length; at++)
                    {
                        if (AgentTextures[at] == image.ID)
                        {
                            TextureIndex index = (TextureIndex)at;
                            Client.DebugLog("Finished downloading texture for " + index.ToString());
                            BakeType type = Baker.BakeTypeFor(index);
                            
                            //BinaryWriter writer = new BinaryWriter(File.Create("wearable_" + index.ToString() + "_" + image.ID.ToString() + ".jp2"));
                            //writer.Write(image.AssetData);
                            //writer.Close();

                            bool baked = false;

                            if (PendingBakes.ContainsKey(type))
                            {
                                if (image.Success)
                                    baked = PendingBakes[type].AddTexture(index, assetTexture);
                                else
                                {
                                    Client.Log("Texture for " + index.ToString() + " failed to download, " +
                                        "bake will be incomplete", Helpers.LogLevel.Warning);

                                    baked = PendingBakes[type].MissingTexture(index);
                                }
                            }

                            if (baked)
                            {
                                UploadBake(PendingBakes[type]);
                                PendingBakes.Remove(type);
                            }

                            ImageDownloads.Remove(image.ID);

                            if (ImageDownloads.Count == 0 && PendingUploads.Count == 0)
                            {
                                // This is a failsafe catch, as the upload completed callback should normally 
                                // be triggering the event
                                Client.DebugLog("No pending downloads or uploads detected in OnImageReceived");
                                CachedResponseEvent.Set();
                            }
                            else
                            {
                                Client.DebugLog("Pending uploads: " + PendingUploads.Count + ", pending downloads: " +
                                    ImageDownloads.Count);
                            }

                        }
                    }
                }
                else
                    Client.Log("Received an image download callback for an image we did not request " + image.ID.ToString(), Helpers.LogLevel.Warning);
            }
        }
Esempio n. 12
0
 public void Assets_OnImageReceived(ImageDownload image, AssetTexture asset)
 {
     if (image.NotFound)
     {
         Console.WriteLine("Failed to download " + image.ID + " - not found.");
         Hashtable hash = new Hashtable();
         hash.Add("MessageType", "ImageDownloaded");
         hash.Add("UUID", image.ID);
         hash.Add("Success", false);
         hash.Add("Error", "Image not found in database.");
         enqueue(hash);
     }
     else if (image.Success)
     {
         bool success = true;
         string key = image.ID.ToString();
         try
         {
             libsecondlife.Imaging.ManagedImage decoded;
             libsecondlife.Imaging.OpenJPEG.DecodeToImage(image.AssetData, out decoded);
             byte[] img = decoded.ExportTGA();
             decoded.Clear();
             File.WriteAllBytes(AjaxLife.TEXTURE_CACHE + key + ".tga", img);
             Process process = Process.Start("convert", AjaxLife.TEXTURE_CACHE + key + ".tga " + AjaxLife.TEXTURE_CACHE + key + ".png");
             process.WaitForExit();
             process.Dispose();
             File.Delete(AjaxLife.TEXTURE_CACHE + key + ".tga");
             Console.WriteLine("Downloaded image " + key + " - " + image.Size + " bytes.");
             if(AjaxLife.USE_S3)
             {
                 try
                 {
                     IThreeSharp service = new ThreeSharpQuery(AjaxLife.S3Config);
                     Affirma.ThreeSharp.Model.ObjectAddRequest request = new Affirma.ThreeSharp.Model.ObjectAddRequest(AjaxLife.TEXTURE_BUCKET, key + ".png");
                     request.LoadStreamWithFile(AjaxLife.TEXTURE_CACHE + key + ".png");
                     request.Headers.Add("x-amz-acl", "public-read");
                     service.ObjectAdd(request).DataStream.Close();
                     AjaxLife.CachedTextures.Add(image.ID);
                 }
                 catch
                 {
                     success = false;
                 }
                 File.Delete(AjaxLife.TEXTURE_CACHE + key + ".png");
             }
         }
         catch(Exception e)
         {
             success = false;
             AjaxLife.Debug("Events", "Texture download for "+key+" failed: "+e.Message);
         }
         Hashtable hash = new Hashtable();
         hash.Add("MessageType", "ImageDownloaded");
         hash.Add("Success", success);
         hash.Add("Size", image.Size);
         hash.Add("UUID", key);
         hash.Add("URL", AjaxLife.TEXTURE_ROOT + key + ".png");
         enqueue(hash);
     }
     else
     {
         Console.WriteLine("Failed to download " + image.ID + ".");
         Hashtable hash = new Hashtable();
         hash.Add("MessageType", "ImageDownloaded");
         hash.Add("UUID", image.ID);
         hash.Add("Success", false);
         hash.Add("Error", "Unknown error.");
         enqueue(hash);
     }
 }
Esempio n. 13
0
        //Separate thread
        private void Assets_OnImageReceived(ImageDownload image, AssetTexture texture)
        {
            if (image.ID != region.MapImageID) return;
            if (image.AssetData == null) return;

            mapImage = ImageHelper.Decode(image.AssetData);
            if (mapImage == null) return;

            instance.ImageCache.AddImage(image.ID, mapImage);

            imageDownloading = false;
            imageDownloaded = true;
            listBox.BeginInvoke(new MethodInvoker(RefreshListBox));
            listBox.BeginInvoke(new OnMapImageRaise(OnMapImageDownloaded), new object[] { EventArgs.Empty });
        }
Esempio n. 14
0
        /// <summary>
        /// Handles the remaining Image data that did not fit in the initial ImageData packet
        /// </summary>
        private void ImagePacketHandler(Packet packet, Simulator simulator)
        {
            ImagePacketPacket image = (ImagePacketPacket)packet;
            ImageDownload transfer = null;

            lock (Transfers)
            {
                if (Transfers.ContainsKey(image.ImageID.ID))
                {
                    transfer = (ImageDownload)Transfers[image.ImageID.ID];

                    if (transfer.Size == 0)
                    {
                        // We haven't received the header yet, block until it's received or times out
                        transfer.HeaderReceivedEvent.WaitOne(1000 * 20, false);

                        if (transfer.Size == 0)
                        {
                            Client.Log("Timed out while waiting for the image header to download for " +
                                transfer.ID.ToString(), Helpers.LogLevel.Warning);

                            transfer.Success = false;
                            Transfers.Remove(transfer.ID);
                            goto Callback;
                        }
                    }

                    // The header is downloaded, we can insert this data in to the proper position
                    Array.Copy(image.ImageData.Data, 0, transfer.AssetData, transfer.InitialDataSize +
                        (1000 * (image.ImageID.Packet - 1)), image.ImageData.Data.Length);
                    transfer.Transferred += image.ImageData.Data.Length;

                    //Client.DebugLog("Received " + image.ImageData.Data.Length + "/" + transfer.Transferred +
                    //    "/" + transfer.Size + " bytes for image " + image.ImageID.ID.ToString());

                    // Check if we downloaded the full image
                    if (transfer.Transferred >= transfer.Size)
                    {
                        transfer.Success = true;
                        Transfers.Remove(transfer.ID);
                    }
                }
            }

        Callback:

            if (transfer != null && OnImageReceived != null && (transfer.Transferred >= transfer.Size || transfer.Size == 0))
            {
                AssetTexture asset = new AssetTexture(transfer.AssetData);
                asset.AssetID = transfer.ID;

                try { OnImageReceived(transfer, asset); }
                catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Handles the Image Data packet which includes the ID and Size of the image,
        /// along with the first block of data for the image. If the image is small enough
        /// there will be no additional packets
        /// </summary>
        private void ImageDataHandler(Packet packet, Simulator simulator)
        {
            ImageDataPacket data = (ImageDataPacket)packet;
            ImageDownload transfer = null;

            lock (Transfers)
            {
                if (Transfers.ContainsKey(data.ImageID.ID))
                {
                    transfer = (ImageDownload)Transfers[data.ImageID.ID];

                    //Client.DebugLog("Received first " + data.ImageData.Data.Length + " bytes for image " +
                    //    data.ImageID.ID.ToString());
                    if (OnImageReceiveProgress != null)
                    {
                        try { OnImageReceiveProgress(data.ImageID.ID, data.ImageData.Data.Length, transfer.Size); }
                        catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                    }

                    transfer.Codec = data.ImageID.Codec;
                    transfer.PacketCount = data.ImageID.Packets;
                    transfer.Size = (int)data.ImageID.Size;
                    transfer.AssetData = new byte[transfer.Size];
                    transfer.AssetType = AssetType.Texture;
                    Buffer.BlockCopy(data.ImageData.Data, 0, transfer.AssetData, 0, data.ImageData.Data.Length);
                    transfer.InitialDataSize = data.ImageData.Data.Length;
                    transfer.Transferred += data.ImageData.Data.Length;

                    // Check if we downloaded the full image
                    if (transfer.Transferred >= transfer.Size)
                    {
                        Transfers.Remove(transfer.ID);
                        transfer.Success = true;
                    }
                }
            }

            if (transfer != null)
            {
                transfer.HeaderReceivedEvent.Set();

                if (OnImageReceived != null && transfer.Transferred >= transfer.Size)
                {
                    AssetTexture asset = new AssetTexture(transfer.AssetData);
                    asset.AssetID = transfer.ID;

                    try { OnImageReceived(transfer, asset); }
                    catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                }
            }
        }