private void Assets_OnImageReceived(ImageDownload image, AssetTexture asset)
        {
            Image = image;
            Asset = asset;

            DownloadHandle.Set();
        }
示例#2
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
        /// <code>1,013,000.0f</code></param>
        /// <param name="discardLevel">Number of quality layers to discard</param>
        public void RequestImage(LLUUID imageID, ImageType type, float priority, int discardLevel)
        {
            if (!Transfers.ContainsKey(imageID))
            {
                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);
            }
        }
示例#3
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;
                }
            }
        }
示例#4
0
 void Assets_OnImageReceived(ImageDownload image)
 {
     if (image.Success)
     {
         picInsignia.Image = OpenJPEGNet.OpenJPEG.DecodeToImage(image.AssetData);
     }
 }
        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;
            }
        }
示例#6
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))
            {
                try { OnImageReceived(transfer, new AssetTexture(transfer.AssetData)); }
                catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
            }
        }
        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]";
            }
        }
示例#8
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 });
        }
示例#9
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());

                    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)
                {
                    try { OnImageReceived(transfer, new AssetTexture(transfer.AssetData)); }
                    catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                }
            }
        }
示例#10
0
        /// <summary>
        /// Requests multiple Images
        /// </summary>
        /// <param name="Images">List of requested images</param>
        public void RequestImages(List <ImageRequest> Images)
        {
            for (int iri = Images.Count; iri > 0; --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);
            }
        }
示例#11
0
文件: Profile.cs 项目: SObS/SLeek
        //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 });
        }
示例#12
0
        /// <summary>
        /// The requested image does not exist on the asset server
        /// </summary>
        private void ImageNotInDatabaseHandler(Packet packet, Simulator simulator)
        {
            ImageNotInDatabasePacket notin    = (ImageNotInDatabasePacket)packet;
            ImageDownload            transfer = null;

            lock (Transfers)
            {
                if (Transfers.ContainsKey(notin.ImageID.ID))
                {
                    transfer          = (ImageDownload)Transfers[notin.ImageID.ID];
                    transfer.NotFound = true;
                    Transfers.Remove(transfer.ID);
                }
            }

            // Fire the event with our transfer that contains Success = false;
            if (transfer != null && OnImageReceived != null)
            {
                try { OnImageReceived(transfer, null); }
                catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
            }
        }
示例#13
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);
                }
            }
        }
示例#14
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 });
        }
示例#15
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);
     }
 }
示例#16
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);
            }
        }
示例#17
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);
            }
        }
示例#18
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);
            }
        }