Пример #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;
                }
            }
        }
Пример #2
0
        private void Assets_OnImageReceived(ImageDownload image, AssetTexture asset)
        {
            Image = image;
            Asset = asset;

            DownloadHandle.Set();
        }
Пример #3
0
 void Assets_OnImageReceived(ImageDownload image)
 {
     if (image.Success)
     {
         picInsignia.Image = OpenJPEGNet.OpenJPEG.DecodeToImage(image.AssetData);
     }
 }
Пример #4
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;
            }
        }
Пример #5
0
        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]";
            }
        }
Пример #6
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 });
        }
Пример #7
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 });
        }
Пример #8
0
        /// <summary>
        /// Requests multiple Images
        /// </summary>
        /// <param name="Images">List of requested images</param>
        public void RequestImages(List<ImageRequest> Images)
        {
            for (int iri = 0; iri < Images.Count; iri++)
            {
                if (Transfers.ContainsKey(Images[iri].ImageID))
                    Images.RemoveAt(iri);
            }

            if (Images.Count > 0)
            {
                // Build and send the request packet
                RequestImagePacket request = new RequestImagePacket();
                request.AgentData.AgentID = Client.Self.AgentID;
                request.AgentData.SessionID = Client.Self.SessionID;
                request.RequestImage = new RequestImagePacket.RequestImageBlock[Images.Count];

                for (int iru = 0; iru < Images.Count; ++iru)
                {
                    ImageDownload transfer = new ImageDownload();
                    //transfer.AssetType = AssetType.Texture // Handled in ImageDataHandler.
                    transfer.ID = Images[iru].ImageID;
                    transfer.Simulator = Client.Network.CurrentSim;

                    // Add this transfer to the dictionary
                    lock (Transfers) Transfers[transfer.ID] = transfer;
                    request.RequestImage[iru] = new RequestImagePacket.RequestImageBlock();
                    request.RequestImage[iru].DiscardLevel = (sbyte)Images[iru].DiscardLevel;
                    request.RequestImage[iru].DownloadPriority = Images[iru].Priority;
                    request.RequestImage[iru].Packet = 0;
                    request.RequestImage[iru].Image = Images[iru].ImageID;
                    request.RequestImage[iru].Type = (byte)Images[iru].Type;
                }

                Client.Network.SendPacket(request, Client.Network.CurrentSim);
            }
            else
            {
                Client.Log("RequestImages() called for an image(s) we are already downloading or an empty list, ignoring",
                    Helpers.LogLevel.Info);
            }
        }
Пример #9
0
        /// <summary>
        /// Initiate an image download. This is an asynchronous function
        /// </summary>
        /// <param name="imageID">The image to download</param>
        /// <param name="type">Type of the image to download, either a baked
        /// avatar texture or a normal texture</param>
        /// <param name="priority">Priority level of the download. Default is
        /// <c>1,013,000.0f</c></param>
        /// <param name="discardLevel">Number of quality layers to discard</param>
        /// <remarks>Sending a priority of 0, and a discardlevel of -1 aborts
        /// download</remarks>
        public void RequestImage(LLUUID imageID, ImageType type, float priority, int discardLevel)
        {
            // allows aborting of download
            if (Transfers.ContainsKey(imageID) && priority.Equals(0) && discardLevel.Equals(-1))
                Transfers.Remove(imageID);

            if (!Transfers.ContainsKey(imageID) && !priority.Equals(0) && !discardLevel.Equals(-1))
            {
                ImageDownload transfer = new ImageDownload();
                //transfer.AssetType = AssetType.Texture // Handled in ImageDataHandler.
                transfer.ID = imageID;
                transfer.Simulator = Client.Network.CurrentSim;

                // Add this transfer to the dictionary
                lock (Transfers) Transfers[transfer.ID] = transfer;

                // Build and send the request packet
                RequestImagePacket request = new RequestImagePacket();
                request.AgentData.AgentID = Client.Self.AgentID;
                request.AgentData.SessionID = Client.Self.SessionID;
                request.RequestImage = new RequestImagePacket.RequestImageBlock[1];
                request.RequestImage[0] = new RequestImagePacket.RequestImageBlock();
                request.RequestImage[0].DiscardLevel = (sbyte)discardLevel;
                request.RequestImage[0].DownloadPriority = priority;
                request.RequestImage[0].Packet = 0;
                request.RequestImage[0].Image = imageID;
                request.RequestImage[0].Type = (byte)type;

                Client.Network.SendPacket(request, transfer.Simulator);
            }
            else
            {
                Client.Log("RequestImage() called for an image we are already downloading, ignoring",
                    Helpers.LogLevel.Info);
            }
        }
Пример #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);
                }
            }
        }
Пример #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);
            }
        }
Пример #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);
     }
 }
Пример #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 });
        }