private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
        {
            resultState = state;
            Asset = asset;

            DownloadHandle.Set();
        }
        private void Assets_OnImageReceived(TextureRequestState state, AssetTexture assetTexture)
        {
            lock (OutfitAssets)
            {
                if (OutfitAssets.Contains(assetTexture.AssetID))
                {
                    if (state == TextureRequestState.Finished)
                    {
                        try
                        {
                            File.WriteAllBytes(assetTexture.AssetID + ".jp2", assetTexture.AssetData);
                            Console.WriteLine("Wrote JPEG2000 image " + assetTexture.AssetID + ".jp2");

                            ManagedImage imgData;
                            OpenJPEG.DecodeToImage(assetTexture.AssetData, out imgData);
                            byte[] tgaFile = imgData.ExportTGA();
                            File.WriteAllBytes(assetTexture.AssetID + ".tga", tgaFile);
                            Console.WriteLine("Wrote TGA image " + assetTexture.AssetID + ".tga");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Failed to download image " + assetTexture.AssetID);
                    }

                    OutfitAssets.Remove(assetTexture.AssetID);
                }
            }
        }
Exemple #3
0
        private void Assets_OnImageReceived(TextureRequestState state, AssetTexture assetTexture)
        {
            lock (OutfitAssets)
            {
                if (OutfitAssets.Contains(assetTexture.AssetID))
                {
                    if (state == TextureRequestState.Finished)
                    {
                        try
                        {
                            File.WriteAllBytes(assetTexture.AssetID + ".jp2", assetTexture.AssetData);
                            Console.WriteLine("Wrote JPEG2000 image " + assetTexture.AssetID + ".jp2");

                            ManagedImage imgData;
                            OpenJPEG.DecodeToImage(assetTexture.AssetData, out imgData);
                            byte[] tgaFile = imgData.ExportTGA();
                            File.WriteAllBytes(assetTexture.AssetID + ".tga", tgaFile);
                            Console.WriteLine("Wrote TGA image " + assetTexture.AssetID + ".tga");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Failed to download image " + assetTexture.AssetID);
                    }

                    OutfitAssets.Remove(assetTexture.AssetID);
                }
            }
        }
Exemple #4
0
        private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
        {
            resultState = state;
            Asset       = asset;

            DownloadHandle.Set();
        }
Exemple #5
0
 void OnComplete(TextureRequestState state, AssetTexture image)
 {
     if (state == TextureRequestState.Finished)
     {
         File.WriteAllBytes(directoryname + "/assets/" + image.AssetID.ToString() + "_texture.jp2", image.AssetData);
     }
 }
Exemple #6
0
 private void RegionMasterTexturePipeline_OnDownloadFinished(TextureRequestState state, AssetTexture asset)
 {
     if (state == TextureRequestState.Finished)
     {
         UUID id = asset.AssetID;
         OnAssetDownloaded(id, asset);
         ImageDownload image = RegionMasterTexturePipeline.Cache.GetCachedImage(id);
         if (image == null)
         {
             Debug("AssetTexture is null?! " + id);
         }
         else
         {
             TextureSuccess++;
             RegisterUUIDMaybe(id, image);
             OnAssetDownloaded(id, asset);
             //lock (uuidTextures) uuidTextures[id] = image;
         }
     }
     else if (state == TextureRequestState.NotFound || state == TextureRequestState.Timeout)
     {
         lock (TexturesSkipped)
         {
             Debug(
                 "Texture failed to download: " + asset + " skipped due to " + state + " TexturesSkipped=" +
                 TexturesSkipped.Count + " TextureSuccess=" + TextureSuccess + " TextureRquested=" + TextureRequested, Helpers.LogLevel.Warning);
             TexturesSkipped.Add(asset.AssetID);
         }
     }
 }
Exemple #7
0
        private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
        {
            if (state == TextureRequestState.Finished && Textures.Contains(asset.AssetID))
            {
                lock (Textures)
                    Textures.Remove(asset.AssetID);

                if (state == TextureRequestState.Finished)
                {
                    try { File.WriteAllBytes(asset.AssetID + ".jp2", asset.AssetData); }
                    catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); }

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

                    Logger.Log("Finished downloading image " + asset.AssetID, Helpers.LogLevel.Info, Client);
                }
                else
                {
                    Logger.Log("Failed to download image " + asset.AssetID + ":" + state, Helpers.LogLevel.Warning, Client);
                }
            }
        }
Exemple #8
0
        private static void ImageReceived(TextureRequestState state, AssetTexture assetID)
        {
            resultState = state;
            asset       = assetID;

            DownloadHandle.Set();
        }
Exemple #9
0
        void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
        {
            if (state == TextureRequestState.Finished && Textures.Contains(asset.AssetID))
            {
                lock (Textures)
                    Textures.Remove(asset.AssetID);

                if (state == TextureRequestState.Finished)
                {
                    try
                    {
                        File.WriteAllBytes(Path.Combine(ExportDirectory, asset.AssetID + ".jp2"), asset.AssetData);
                        LogMessage("Successfully downloaded texture {0}", asset.AssetID.ToString());
                    }
                    catch (Exception ex)
                    {
                        LogMessage("Failed to download texture {0}\r\nReason: {1}", asset.AssetID.ToString(), ex.Message);
                    }
                }
                else
                {
                    LogMessage("Failed to download texture {0}\r\nReason: {1}", asset.AssetID.ToString(), state);
                }
                lock (Textures)
                {
                    if (Textures.Count == 0)
                    {
                        LogMessage("Texture Download complete!");
                    }
                }
            }
        }
Exemple #10
0
        //comes in on a separate thread
        private void Assets_OnImageReceived(TextureRequestState image, AssetTexture texture)
        {
            ManagedImage mImg;
            Image        sImage = null;

            if (texture.AssetID != SLImageID && texture.AssetID != FLImageID)
            {
                if (texture.AssetID != PickImageID)
                {
                    return;
                }

                OpenJPEG.DecodeToImage(texture.AssetData, out mImg, out sImage);
                System.Drawing.Image decodedImage1 = sImage;

                if (decodedImage1 != null)
                {
                    this.BeginInvoke(new MethodInvoker(delegate()
                    {
                        pictureBox1.Image = decodedImage1;
                        loadwait2.Visible = false;
                    }));

                    instance.ImageCache.AddImage(texture.AssetID, decodedImage1);
                }
            }
            else
            {
                //System.Drawing.Image decodedImage = ImageHelper.Decode(image.AssetData);
                //System.Drawing.Image decodedImage = OpenJPEGNet.OpenJPEG.DecodeToImage(image.AssetData);
                OpenJPEG.DecodeToImage(texture.AssetData, out mImg, out sImage);
                System.Drawing.Image decodedImage = sImage;

                if (decodedImage == null)
                {
                    if (texture.AssetID == SLImageID)
                    {
                        BeginInvoke(new MethodInvoker(SetBlankSLImage));
                    }
                    else if (texture.AssetID == FLImageID)
                    {
                        BeginInvoke(new MethodInvoker(SetBlankFLImage));
                    }

                    return;
                }

                instance.ImageCache.AddImage(texture.AssetID, decodedImage);

                try
                {
                    BeginInvoke(new OnSetProfileImage(SetProfileImage), new object[] { texture.AssetID, decodedImage });
                }
                catch {; }

                //if (image.Success)
                //    picInsignia.Image = OpenJPEGNet.OpenJPEG.DecodeToImage(image.AssetData);
            }
        }
Exemple #11
0
 public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture)
 {
     if (state == TextureRequestState.Finished)
     {
         lock (Manager.AssetsReceived)
             Manager.AssetsReceived[assetTexture.AssetID] = true;
     }
 }
Exemple #12
0
        private void Assets_OnImageReceived(TextureRequestState image, AssetTexture texture)
        {
            if (texture.AssetID == _MapImageID)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer);

                //UpdateMiniMap(sim);
                BeginInvoke((MethodInvoker) delegate { UpdateMiniMap(sim); });
            }
        }
 private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
 {
     if (state == TextureRequestState.Finished && enabled && alreadyRequested.ContainsKey(asset.AssetID))
     {
         if (state == TextureRequestState.Finished)
         {
             Logger.DebugLog(String.Format("Finished downloading texture {0} ({1} bytes)", asset.AssetID, asset.AssetData.Length));
         }
         else
         {
             Logger.Log("Failed to download texture " + asset.AssetID + ": " + state, Helpers.LogLevel.Warning);
         }
     }
 }
Exemple #14
0
        //comes in on separate thread
        private void Assets_OnImageReceived(TextureRequestState image, AssetTexture texture)
        {
            if (texture.AssetID != item.AssetUUID)
            {
                return;
            }

            if (InvokeRequired)
            {
                BeginInvoke(new MethodInvoker(() => Assets_OnImageReceived(image, texture)));
                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 });

            ManagedImage mImg;
            Image        sImage = null;

            //System.Drawing.Image decodedImage = ImageHelper.Decode(image.AssetData);
            //System.Drawing.Image decodedImage = OpenJPEGNet.OpenJPEG.DecodeToImage(image.AssetData);
            OpenJPEG.DecodeToImage(texture.AssetData, out mImg, out sImage);
            System.Drawing.Image decodedImage = sImage;

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

            instance.ImageCache.AddImage(texture.AssetID, decodedImage);
            BeginInvoke(new OnSetFinalImage(SetFinalImage), new object[] { decodedImage });
        }
Exemple #15
0
        private void imageReceivedCallback(TextureRequestState state, AssetTexture asset)
        {
            if (state == TextureRequestState.Timeout)
            {
                // need a re-request if a texture times out but doing it here borks libomv
                //m_user.Assets.RequestImage(asset.AssetID, ImageType.Normal, imageReceivedCallback);
                return;
            }

            if (state != TextureRequestState.Finished)
            {
                return;
            }

            if (OnTextureDownloaded != null)
            {
                VTexture texture = new VTexture();
                texture.TextureId = asset.AssetID;

                ManagedImage managedImage;
                Image        tempImage;

                try
                {
                    if (OpenJPEG.DecodeToImage(asset.AssetData, out managedImage, out tempImage))
                    {
                        Bitmap   textureBitmap = new Bitmap(tempImage.Width, tempImage.Height, PixelFormat.Format32bppArgb);
                        Graphics graphics      = Graphics.FromImage(textureBitmap);
                        graphics.DrawImage(tempImage, 0, 0);
                        graphics.Flush();
                        graphics.Dispose();
                        texture.Image = textureBitmap;
                        OnTextureDownloaded(texture);
                    }
                }
                catch (Exception e)
                {
                    m_log.Error(":( :( :( :( got exception decoding image ): ): ): ):\nException: " + e.ToString());
                }
            }
        }
Exemple #16
0
        void Assets_OnImageReceived(TextureRequestState image, AssetTexture texture)
        {
            if (texture.AssetID == profile.InsigniaID)
            {
                ManagedImage imgData;
                Image        bitmap;

                try
                {
                    OpenJPEG.DecodeToImage(texture.AssetData, out imgData, out bitmap);

                    BeginInvoke(new MethodInvoker(delegate()
                    {
                        picInsignia.Image = bitmap;
                    }));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "METAbolt");
                }
            }
        }
Exemple #17
0
        /*
         *
         * private bool RequestObjectProperties(IList<SimObject> objects, int msPerRequest, Simulator sim)
         * {
         *  // Create an array of the local IDs of all the prims we are requesting properties for
         *  uint[] localids = new uint[objects.Count];
         *
         *  lock (PrimsWaiting)
         *  {
         *      PrimsWaiting.Clear();
         *
         *      for (int i = 0; i < objects.Count; ++i)
         *      {
         *          localids[i] = objects[i].LocalID;
         *          PrimsWaiting.Add(objects[i].ID, objects[i].Prim);
         *      }
         *  }
         *
         *  Client.Objects.SelectObjects(sim, localids);
         *
         *  return AllPropertiesReceived.WaitOne(2000 + msPerRequest * objects.Count, false);
         * }
         */
        private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
        {
            if (!IsExporting)
            {
                return;
            }
            lock (ToDownloadAssets) if (state == TextureRequestState.Finished)
                {
                    AssetComplete(asset.AssetID);

                    if (state == TextureRequestState.Finished)
                    {
                        string sfile = Path.GetFileName(SimAsset.CFileName(asset.AssetID, asset.AssetType));
                        try { lock (fileWriterLock) File.WriteAllBytes(assetDumpDir + sfile, asset.AssetData); }
                        catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); }
                        return;

                        if (asset.Decode())
                        {
                            try { lock (fileWriterLock) File.WriteAllBytes(assetDumpDir + asset.AssetID + ".tga", asset.Image.ExportTGA()); }
                            catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); }
                        }
                        else
                        {
                            try { lock (fileWriterLock) File.WriteAllBytes(assetDumpDir + sfile, asset.AssetData); }
                            catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); }
                            return;
                        }

                        Logger.Log("Finished downloading image " + asset.AssetID, Helpers.LogLevel.Info, Client);
                    }
                    else
                    {
                        Logger.Log("Failed to download image " + asset.AssetID + ":" + state, Helpers.LogLevel.Warning, Client);
                    }
                }
        }
Exemple #18
0
        //Separate thread
        private void Assets_OnImageReceived(TextureRequestState image, AssetTexture texture)
        {
            if (texture.AssetID != region.MapImageID)
            {
                return;
            }
            if (texture.AssetData == null)
            {
                return;
            }

            mapImage = ImageHelper.Decode(texture.AssetData);
            if (mapImage == null)
            {
                return;
            }

            instance.ImageCache.AddImage(texture.AssetID, mapImage);

            imageDownloading = false;
            imageDownloaded  = true;
            listBox.BeginInvoke(new MethodInvoker(RefreshListBox));
            listBox.BeginInvoke(new OnMapImageRaise(OnMapImageDownloaded), new object[] { EventArgs.Empty });
        }
        /*

        private bool RequestObjectProperties(IList<SimObject> objects, int msPerRequest, Simulator sim)
        {
            // Create an array of the local IDs of all the prims we are requesting properties for
            uint[] localids = new uint[objects.Count];

            lock (PrimsWaiting)
            {
                PrimsWaiting.Clear();

                for (int i = 0; i < objects.Count; ++i)
                {
                    localids[i] = objects[i].LocalID;
                    PrimsWaiting.Add(objects[i].ID, objects[i].Prim);
                }
            }

            Client.Objects.SelectObjects(sim, localids);

            return AllPropertiesReceived.WaitOne(2000 + msPerRequest * objects.Count, false);
        }
        */
        private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
        {
            if (!IsExporting) return;
            lock (ToDownloadAssets) if (state == TextureRequestState.Finished)
                {
                    AssetComplete(asset.AssetID);

                    if (state == TextureRequestState.Finished)
                    {
                        string sfile = Path.GetFileName(SimAsset.CFileName(asset.AssetID, asset.AssetType));
                        try { lock (fileWriterLock) File.WriteAllBytes(assetDumpDir + sfile, asset.AssetData); }
                        catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); }
                        return;

                        if (asset.Decode())
                        {
                            try { lock (fileWriterLock) File.WriteAllBytes(assetDumpDir + asset.AssetID + ".tga", asset.Image.ExportTGA()); }
                            catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); }
                        }
                        else
                        {
                            try { lock (fileWriterLock) File.WriteAllBytes(assetDumpDir + sfile, asset.AssetData); }
                            catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); }
                            return;
                        }

                        Logger.Log("Finished downloading image " + asset.AssetID, Helpers.LogLevel.Info, Client);
                    }
                    else
                    {
                        Logger.Log("Failed to download image " + asset.AssetID + ":" + state, Helpers.LogLevel.Warning, Client);
                    }
                }
        }
Exemple #20
0
        private void Assets_OnImageReceived(TextureRequestState image, AssetTexture texture)
        {
            if (texture.AssetID == _MapImageID)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer);
            }

            if (texture.AssetID == _MapImageID1)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer1);
            }

            if (texture.AssetID == _MapImageID2)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer2);
            }

            if (texture.AssetID == _MapImageID3)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer3);
            }

            if (texture.AssetID == _MapImageID4)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer4);
            }

            if (texture.AssetID == _MapImageID5)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer5);
            }

            if (texture.AssetID == _MapImageID6)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer6);
            }

            if (texture.AssetID == _MapImageID7)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer7);
            }

            if (texture.AssetID == _MapImageID8)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer8);
            }

            if (texture.AssetID == _MapImageID9)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer9);
            }

            //if (texture.AssetID == _MapImageID10)
            //{
            //    ManagedImage nullImage;
            //    OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer10);
            //}
        }
Exemple #21
0
 private void RegionMasterTexturePipeline_OnDownloadFinished(TextureRequestState state, AssetTexture asset)
 {
     if (state == TextureRequestState.Finished)
     {
         UUID id = asset.AssetID;
         OnAssetDownloaded(id, asset);
         ImageDownload image = RegionMasterTexturePipeline.Cache.GetCachedImage(id);
         if (image == null)
         {
             Debug("AssetTexture is null?! " + id);
         }
         else
         {
             TextureSuccess++;
             RegisterUUIDMaybe(id, image);
             OnAssetDownloaded(id, asset);
             //lock (uuidTextures) uuidTextures[id] = image;
         }
     }
     else if (state == TextureRequestState.NotFound || state == TextureRequestState.Timeout)
     {
         lock (TexturesSkipped)
         {
             Debug(
                 "Texture failed to download: " + asset + " skipped due to " + state + " TexturesSkipped=" +
                 TexturesSkipped.Count + " TextureSuccess=" + TextureSuccess + " TextureRquested=" + TextureRequested, Helpers.LogLevel.Warning);
             TexturesSkipped.Add(asset.AssetID);
         }
     }
 }
Exemple #22
0
        private void Assets_OnImageReceived(TextureRequestState image, AssetTexture texture)
        {
            if (texture.AssetID == _MapImageID)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer);

                //UpdateMiniMap(sim);
                BeginInvoke((MethodInvoker)delegate { UpdateMiniMap(sim); });
            }
        }
        //Separate thread
        private void Assets_OnImageReceived(TextureRequestState image, AssetTexture texture)
        {
            if (texture.AssetID != region.MapImageID) return;
            if (texture.AssetData == null) return;

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

            instance.ImageCache.AddImage(texture.AssetID, mapImage);

            imageDownloading = false;
            imageDownloaded = true;
            listBox.BeginInvoke(new MethodInvoker(RefreshListBox));
            listBox.BeginInvoke(new OnMapImageRaise(OnMapImageDownloaded), new object[] { EventArgs.Empty });
        }
Exemple #24
0
 public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture)
 {
     //TODO: Implement texture saving and applying
 }
        private void imageReceivedCallback(TextureRequestState state, AssetTexture asset)
        {
            if (state == TextureRequestState.Timeout)
            {
                // need a re-request if a texture times out but doing it here borks libomv
                //m_user.Assets.RequestImage(asset.AssetID, ImageType.Normal, imageReceivedCallback);
                return;
            }

            if (state != TextureRequestState.Finished)
                return;

            if (OnTextureDownloaded != null)
            {

                VTexture texture = new VTexture();
                texture.TextureId = asset.AssetID;

                ManagedImage managedImage;
                Image tempImage;

                try
                {
                    if (OpenJPEG.DecodeToImage(asset.AssetData, out managedImage, out tempImage))
                    {
                        Bitmap textureBitmap = new Bitmap(tempImage.Width, tempImage.Height, PixelFormat.Format32bppArgb);
                        Graphics graphics = Graphics.FromImage(textureBitmap);
                        graphics.DrawImage(tempImage, 0, 0);
                        graphics.Flush();
                        graphics.Dispose();
                        texture.Image = textureBitmap;
                        OnTextureDownloaded(texture);
                    }
                }
                catch (Exception e)
                {
                    m_log.Error(":( :( :( :( got exception decoding image ): ): ): ):\nException: " + e.ToString());
                }
            }
        }
Exemple #26
0
 public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture)
 {
     if (state == TextureRequestState.Finished)
     {
         lock (Manager.AssetsReceived)
             Manager.AssetsReceived[assetTexture.AssetID] = true;
     }
 }
 void statusupdate(TextureRequestState state, AssetTexture assetTexture)
 {
     if (state == TextureRequestState.Finished && gotdata == false)
        {
        gotdata = true;
        onGotImage(assetTexture);
        }
 }
Exemple #28
0
        private void Assets_OnImageReceived(TextureRequestState image, AssetTexture texture)
        {
            if (texture.AssetID == _MapImageID)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer);
            }

            if (texture.AssetID == _MapImageID1)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer1);
            }

            if (texture.AssetID == _MapImageID2)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer2);
            }

            if (texture.AssetID == _MapImageID3)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer3);
            }

            if (texture.AssetID == _MapImageID4)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer4);
            }

            if (texture.AssetID == _MapImageID5)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer5);
            }

            if (texture.AssetID == _MapImageID6)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer6);
            }

            if (texture.AssetID == _MapImageID7)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer7);
            }

            if (texture.AssetID == _MapImageID8)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer8);
            }

            if (texture.AssetID == _MapImageID9)
            {
                ManagedImage nullImage;
                OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer9);
            }

            //if (texture.AssetID == _MapImageID10)
            //{
            //    ManagedImage nullImage;
            //    OpenJPEG.DecodeToImage(texture.AssetData, out nullImage, out _MapLayer10);
            //}
        }
Exemple #29
0
        public void Assets_TextureDownloadCallback(TextureRequestState state, AssetTexture texture)
        {
            if(state == TextureRequestState.NotFound || state == TextureRequestState.Aborted || state == TextureRequestState.Timeout)
            {
                Console.WriteLine("Failed to download " + texture.AssetID + " - " + state.ToString() + ".");
                Hashtable hash = new Hashtable();
                hash.Add("MessageType", "ImageDownloaded");
                hash.Add("UUID", texture.AssetID);
                hash.Add("Success", false);
                hash.Add("Error", "Image could not be downloaded: " + state.ToString());
                enqueue(hash);
            }
            else if(state == TextureRequestState.Finished)
            {
                bool success = true;
                string key = texture.AssetID.ToString();
                try
                {
                    texture.Decode();
                    byte[] img = texture.Image.ExportRaw();
                    int size = img.Length;
                    int width = texture.Image.Width;
                    int height = texture.Image.Height;
                    texture.Image.Clear();

                    // Helpfully, it's upside-down, and has red and blue flipped.

                    // Assuming 32 bits (accurate) and a height as a multiple of two (accurate),
                    // this will vertically invert the image.
                    int length = width * 4;
                    byte[] fliptemp = new byte[length];
                    for(int i = 0; i < height / 2; ++i)
                    {
                        int index = i * width * 4;
                        int endindex = size - ((i+1) * width * 4);
                        Array.Copy(img, index, fliptemp, 0, length);
                        Array.Copy(img, endindex, img, index, length);
                        Array.Copy(fliptemp, 0, img, endindex, length);
                    }

                    // This changes RGBA to BGRA. Or possibly vice-versa. I don't actually know.
                    // The documentation is vague/nonexistent.
                    for(int i = 0; i < size; i += 4)
                    {
                        byte temp = img[i+2];
                        img[i+2] = img[i];
                        img[i] = temp;
                    }

                    // Use System.Drawing.Bitmap to create a PNG. This requires us to feed it a pointer to an array
                    // for whatever reason, so we temporarily pin the image array.
                    GCHandle handle = GCHandle.Alloc(img, GCHandleType.Pinned);
                    Bitmap bitmap = new Bitmap(texture.Image.Width, texture.Image.Height, texture.Image.Width * 4,
                                        System.Drawing.Imaging.PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
                    bitmap.Save(AjaxLife.TEXTURE_CACHE + key + ".png", System.Drawing.Imaging.ImageFormat.Png);
                    bitmap.Dispose();
                    handle.Free();
                    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");
                            request.Headers.Add("Content-Type", "image/png");
                            service.ObjectAdd(request).DataStream.Close();
                            AjaxLife.CachedTextures.Add(texture.AssetID);
                            File.Delete(AjaxLife.TEXTURE_CACHE + key + ".png");
                        }
                        catch
                        {
                            success = false;
                        }
                    }
                }
                catch(Exception e)
                {
                    success = false;
                    AjaxLife.Debug("Events", "Texture download for "+key+" failed (" + e.GetType().Name + "): " + e.Message);
                }
                Hashtable hash = new Hashtable();
                hash.Add("MessageType", "ImageDownloaded");
                hash.Add("Success", success);
                hash.Add("UUID", key);
                hash.Add("URL", AjaxLife.TEXTURE_ROOT + key + ".png");
                enqueue(hash);
            }
        }
Exemple #30
0
 public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture)
 {
     //TODO: Implement texture saving and applying
 }
 void OnComplete(TextureRequestState state, AssetTexture image)
 {
     if (state == TextureRequestState.Finished)
     {
         File.WriteAllBytes(directoryname + "/assets/" + image.AssetID.ToString() + "_texture.jp2", image.AssetData);
     }
 }
Exemple #32
0
        //comes in on a separate thread
        private void Assets_OnImageReceived(TextureRequestState image, AssetTexture texture)
        {
            ManagedImage mImg;
            Image sImage = null;

            if (texture.AssetID != SLImageID && texture.AssetID != FLImageID)
            {
                if (texture.AssetID != PickImageID) return;

                OpenJPEG.DecodeToImage(texture.AssetData, out mImg, out sImage);
                System.Drawing.Image decodedImage1 = sImage;

                if (decodedImage1 != null)
                {
                    this.BeginInvoke(new MethodInvoker(delegate()
                    {
                        pictureBox1.Image = decodedImage1;
                        loadwait2.Visible = false;
                    }));

                    instance.ImageCache.AddImage(texture.AssetID, decodedImage1);
                }
            }
            else
            {
                //System.Drawing.Image decodedImage = ImageHelper.Decode(image.AssetData);
                //System.Drawing.Image decodedImage = OpenJPEGNet.OpenJPEG.DecodeToImage(image.AssetData);
                OpenJPEG.DecodeToImage(texture.AssetData, out mImg, out sImage);
                System.Drawing.Image decodedImage = sImage;

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

                    return;
                }

                instance.ImageCache.AddImage(texture.AssetID, decodedImage);

                try
                {
                    BeginInvoke(new OnSetProfileImage(SetProfileImage), new object[] { texture.AssetID, decodedImage });
                }
                catch { ; }

                //if (image.Success)
                //    picInsignia.Image = OpenJPEGNet.OpenJPEG.DecodeToImage(image.AssetData);
            }
        }
        private void Assets_OnImageReceived(TextureRequestState state, AssetTexture assetTexture)
        {
            lock (ImageDownloads)
            {
                if (ImageDownloads.ContainsKey(assetTexture.AssetID))
                {
                    ImageDownloads.Remove(assetTexture.AssetID);

                    // 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] == assetTexture.AssetID)
                        {
                            TextureIndex index = (TextureIndex)at;
                            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;
                            AgentAssets[at]=assetTexture; //Cache this asset for rebaking, todo this could be better rather than dropping in this list.

                            if (PendingBakes.ContainsKey(type))
                            {
                                if (state == TextureRequestState.Finished)
                                {
                                    Log.DebugLog("Finished downloading texture for " + index.ToString());
                                    OpenJPEG.DecodeToImage(assetTexture.AssetData, out assetTexture.Image);
                                    baked = PendingBakes[type].AddTexture(index, assetTexture, false);
                                }
                                else
                                {
                                    Log.Log("Texture for " + index + " failed to download, " +
                                        "bake will be incomplete", Helpers.LogLevel.Warning);
                                    baked = PendingBakes[type].MissingTexture(index);
                                }
                            }

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

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

                        }
                    }
                }
                else
                {
                    Log.Log("Received an image download callback for an image we did not request " + assetTexture.AssetID,
                        Helpers.LogLevel.Warning);
                }
            }
        }
Exemple #34
0
 private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
 {
     if (state == TextureRequestState.Finished && enabled && alreadyRequested.ContainsKey(asset.AssetID))
     {
         if (state == TextureRequestState.Finished)
             Logger.DebugLog(String.Format("Finished downloading texture {0} ({1} bytes)", asset.AssetID, asset.AssetData.Length));
         else
             Logger.Log("Failed to download texture " + asset.AssetID + ": " + state, Helpers.LogLevel.Warning);
     }
 }
Exemple #35
0
        void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
        {
            if (state == TextureRequestState.Finished && Textures.Contains(asset.AssetID))
            {
                lock (Textures)
                    Textures.Remove(asset.AssetID);

                if (state == TextureRequestState.Finished)
                {
                    try
                    {
                        File.WriteAllBytes(Path.Combine(ExportDirectory,asset.AssetID + ".jp2"), asset.AssetData);
                        LogMessage("Successfully downloaded texture {0}",asset.AssetID.ToString());
                    }
                    catch (Exception ex)
                    {
                        LogMessage("Failed to download texture {0}\r\nReason: {1}",asset.AssetID.ToString(),ex.Message);
                    }
                }
                else
                {
                    LogMessage("Failed to download texture {0}\r\nReason: {1}",asset.AssetID.ToString(),state);
                }
                lock (Textures)
                {
                    if (Textures.Count == 0)
                        LogMessage("Texture Download complete!");
                }
            }
        }
Exemple #36
0
        private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
        {

            if (state == TextureRequestState.Finished && Textures.Contains(asset.AssetID))
            {
                lock (Textures)
                    Textures.Remove(asset.AssetID);

                if (state == TextureRequestState.Finished)
                {
                    try { File.WriteAllBytes(asset.AssetID + ".jp2", asset.AssetData); }
                    catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); }

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

                    Logger.Log("Finished downloading image " + asset.AssetID, Helpers.LogLevel.Info, Client);
                }
                else
                {
                    Logger.Log("Failed to download image " + asset.AssetID + ":" + state, Helpers.LogLevel.Warning, Client);
                }
            }
        }
        //comes in on separate thread
        private void Assets_OnImageReceived(TextureRequestState image, AssetTexture texture)
        {
            if (texture.AssetID != item.AssetUUID) return;

            if (InvokeRequired)
            {
                BeginInvoke(new MethodInvoker(() => Assets_OnImageReceived(image, texture)));
                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 });

            ManagedImage mImg;
            Image sImage = null;

            //System.Drawing.Image decodedImage = ImageHelper.Decode(image.AssetData);
            //System.Drawing.Image decodedImage = OpenJPEGNet.OpenJPEG.DecodeToImage(image.AssetData);
            OpenJPEG.DecodeToImage(texture.AssetData, out mImg, out sImage);
            System.Drawing.Image decodedImage = sImage;

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

            instance.ImageCache.AddImage(texture.AssetID, decodedImage);
            BeginInvoke(new OnSetFinalImage(SetFinalImage), new object[] { decodedImage });
        }
Exemple #38
0
        public void Assets_TextureDownloadCallback(TextureRequestState state, AssetTexture texture)
        {
            if (state == TextureRequestState.NotFound || state == TextureRequestState.Aborted || state == TextureRequestState.Timeout)
            {
                Console.WriteLine("Failed to download " + texture.AssetID + " - " + state.ToString() + ".");
                Hashtable hash = new Hashtable();
                hash.Add("MessageType", "ImageDownloaded");
                hash.Add("UUID", texture.AssetID);
                hash.Add("Success", false);
                hash.Add("Error", "Image could not be downloaded: " + state.ToString());
                enqueue(hash);
            }
            else if (state == TextureRequestState.Finished)
            {
                bool   success = true;
                string key     = texture.AssetID.ToString();
                try
                {
                    texture.Decode();
                    byte[] img    = texture.Image.ExportRaw();
                    int    size   = img.Length;
                    int    width  = texture.Image.Width;
                    int    height = texture.Image.Height;
                    texture.Image.Clear();

                    // Helpfully, it's upside-down, and has red and blue flipped.

                    // Assuming 32 bits (accurate) and a height as a multiple of two (accurate),
                    // this will vertically invert the image.
                    int    length   = width * 4;
                    byte[] fliptemp = new byte[length];
                    for (int i = 0; i < height / 2; ++i)
                    {
                        int index    = i * width * 4;
                        int endindex = size - ((i + 1) * width * 4);
                        Array.Copy(img, index, fliptemp, 0, length);
                        Array.Copy(img, endindex, img, index, length);
                        Array.Copy(fliptemp, 0, img, endindex, length);
                    }

                    // This changes RGBA to BGRA. Or possibly vice-versa. I don't actually know.
                    // The documentation is vague/nonexistent.
                    for (int i = 0; i < size; i += 4)
                    {
                        byte temp = img[i + 2];
                        img[i + 2] = img[i];
                        img[i]     = temp;
                    }

                    // Use System.Drawing.Bitmap to create a PNG. This requires us to feed it a pointer to an array
                    // for whatever reason, so we temporarily pin the image array.
                    GCHandle handle = GCHandle.Alloc(img, GCHandleType.Pinned);
                    Bitmap   bitmap = new Bitmap(texture.Image.Width, texture.Image.Height, texture.Image.Width * 4,
                                                 System.Drawing.Imaging.PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
                    bitmap.Save(AjaxLife.TEXTURE_CACHE + key + ".png", System.Drawing.Imaging.ImageFormat.Png);
                    bitmap.Dispose();
                    handle.Free();
                    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");
                            request.Headers.Add("Content-Type", "image/png");
                            service.ObjectAdd(request).DataStream.Close();
                            AjaxLife.CachedTextures.Add(texture.AssetID);
                            File.Delete(AjaxLife.TEXTURE_CACHE + key + ".png");
                        }
                        catch
                        {
                            success = false;
                        }
                    }
                }
                catch (Exception e)
                {
                    success = false;
                    AjaxLife.Debug("Events", "Texture download for " + key + " failed (" + e.GetType().Name + "): " + e.Message);
                }
                Hashtable hash = new Hashtable();
                hash.Add("MessageType", "ImageDownloaded");
                hash.Add("Success", success);
                hash.Add("UUID", key);
                hash.Add("URL", AjaxLife.TEXTURE_ROOT + key + ".png");
                enqueue(hash);
            }
        }