Exemple #1
0
        protected void Bake()
        {
            Client.DebugLog("Baking " + BakeType.ToString());
            BakedTexture = new AssetTexture(new Image(BakeWidth, BakeHeight, ImageChannels.Color | ImageChannels.Alpha | ImageChannels.Bump));
            int i = 0;

            for (int y = 0; y < BakeHeight; y++)
            {
                for (int x = 0; x < BakeWidth; x++)
                {
                    if (((x ^ y) & 0x10) == 0)
                    {
                        BakedTexture.Image.Red[i]   = 255;
                        BakedTexture.Image.Green[i] = 0;
                        BakedTexture.Image.Blue[i]  = 0;
                        BakedTexture.Image.Alpha[i] = 255;
                        BakedTexture.Image.Bump[i]  = 0;
                    }
                    else
                    {
                        BakedTexture.Image.Red[i]   = 0;
                        BakedTexture.Image.Green[i] = 0;
                        BakedTexture.Image.Blue[i]  = 255;
                        BakedTexture.Image.Alpha[i] = 255;
                        BakedTexture.Image.Bump[i]  = 0;
                    }

                    ++i;
                }
            }

            BakedTexture.Encode();
        }
Exemple #2
0
        private void Assets_OnImageReceived(ImageDownload image, AssetTexture asset)
        {
            Image = image;
            Asset = asset;

            DownloadHandle.Set();
        }
Exemple #3
0
        /// <summary>
        /// Adds an image to this baking texture and potentially processes it, or
        /// stores it for processing later
        /// </summary>
        /// <param name="index">The baking texture index of the image to be added</param>
        /// <param name="texture">JPEG2000 compressed image to be
        /// added to the baking texture</param>
        /// <param name="needsDecode">True if <code>Decode()</code> needs to be
        /// called for the texture, otherwise false</param>
        /// <returns>True if this texture is completely baked and JPEG2000 data
        /// is available, otherwise false</returns>
        public bool AddTexture(AppearanceManager.TextureIndex index, AssetTexture texture, bool needsDecode)
        {
            lock (_textures)
            {
                if (needsDecode)
                {
                    try
                    {
                        texture.Decode();
                    }
                    catch (Exception e)
                    {
                        Logger.Log(String.Format("AddTexture({0}, {1})", index, texture.AssetID), Helpers.LogLevel.Error, e);
                        return(false);
                    }
                }

                _textures.Add(index, texture);
                Logger.DebugLog(String.Format("Added texture {0} (ID: {1}) to bake {2}", index, texture.AssetID, _bakeType), _client);
            }

            if (_textures.Count >= _textureCount)
            {
                Bake();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
        private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
        {
            resultState = state;
            Asset       = asset;

            DownloadHandle.Set();
        }
Exemple #5
0
        public override string Execute(string[] args, UUID fromAgentID)
        {
            if (args.Length != 1 && args.Length != 2)
            {
                return("Usage: downloadtexture [texture-uuid] [discardlevel]");
            }

            TextureID = UUID.Zero;
            DownloadHandle.Reset();
            Asset = null;

            if (UUID.TryParse(args[0], out TextureID))
            {
                int discardLevel = 0;

                if (args.Length > 1)
                {
                    if (!Int32.TryParse(args[1], out discardLevel))
                    {
                        return("Usage: downloadtexture [texture-uuid] [discardlevel]");
                    }
                }

                Client.Assets.RequestImage(TextureID, ImageType.Normal, Assets_OnImageReceived);

                if (DownloadHandle.WaitOne(120 * 1000, false))
                {
                    if (resultState == TextureRequestState.Finished)
                    {
                        if (Asset != null && Asset.Decode())
                        {
                            try { File.WriteAllBytes(Asset.AssetID + ".jp2", Asset.AssetData); }
                            catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); }

                            return(String.Format("Saved {0}.jp2 ({1}x{2})", Asset.AssetID, Asset.Image.Width, Asset.Image.Height));
                        }
                        else
                        {
                            return("Failed to decode texture " + TextureID.ToString());
                        }
                    }
                    else if (resultState == TextureRequestState.NotFound)
                    {
                        return("Simulator reported texture not found: " + TextureID.ToString());
                    }
                    else
                    {
                        return("Download failed for texture " + TextureID + " " + resultState);
                    }
                }
                else
                {
                    return("Timed out waiting for texture download");
                }
            }
            else
            {
                return("Usage: downloadtexture [texture-uuid]");
            }
        }
        private void Assets_OnImageReceived(ImageDownload image, AssetTexture asset)
        {
            if (Textures.Contains(image.ID))
            {
                lock (Textures)
                    Textures.Remove(image.ID);

                if (image.Success)
                {
                    try { File.WriteAllBytes(image.ID.ToString() + ".jp2", asset.AssetData); }
                    catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); }

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

                    Logger.Log("Finished downloading image " + image.ID.ToString(), Helpers.LogLevel.Info, Client);
                }
                else
                {
                    Logger.Log("Failed to download image " + image.ID.ToString(), Helpers.LogLevel.Warning, Client);
                }
            }
        }
        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 #8
0
 void Assets_OnImageReceived(ImageDownload image, AssetTexture assetTexture)
 {
     if (image.Success)
     {
         picInsignia.Image = OpenJPEGNet.OpenJPEG.DecodeToImage(image.AssetData);
     }
 }
Exemple #9
0
        private static void ImageReceived(TextureRequestState state, AssetTexture assetID)
        {
            resultState = state;
            asset       = assetID;

            DownloadHandle.Set();
        }
Exemple #10
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 #11
0
 void OnComplete(TextureRequestState state, AssetTexture image)
 {
     if (state == TextureRequestState.Finished)
     {
         File.WriteAllBytes(directoryname + "/assets/" + image.AssetID.ToString() + "_texture.jp2", image.AssetData);
     }
 }
Exemple #12
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 #13
0
    public AssetProperties(Asset asset)
    {
        foreach (AssetValue val in asset)
        {
            //is this one supposed to be different from the others? "DisplayName vs Name"
            if (val.DisplayName.Equals("Color") && val.ValueType == AssetValueTypeEnum.kAssetValueTypeColor)
            {
                color = ((ColorAssetValue)val).Value;
            }

            /*    //I am unable to find any reference to gloss in the API, and I've found the value changes from material to material
             * else if (val.Name.Equals("generic_glossiness") && val.ValueType == AssetValueTypeEnum.kAssetValueTypeFloat)
             * {
             *  generic_glossiness = ((FloatAssetValue)val).Value;
             * }
             */
            //opacity is a double
            else if (val.DisplayName.Equals("Transparency") && val.ValueType == AssetValueTypeEnum.kAssetValueTypeFloat)
            {
                transparency = ((FloatAssetValue)val).Value;
            }
            else if (val.DisplayName.Equals("Translucency") && val.ValueType == AssetValueTypeEnum.kAssetValueTypeFloat)
            {
                translucency = ((FloatAssetValue)val).Value;
            }
            else if (val.ValueType == AssetValueTypeEnum.kAssetValueTextureType)
            {
                AssetTexture tex = ((TextureAssetValue)val).Value;
            }
            else if (val.Name.Contains("reflectivity") && val.Name.Contains("0deg") && val.ValueType == AssetValueTypeEnum.kAssetValueTypeFloat)
            {
                specular = ((FloatAssetValue)val).Value;
            }
        }
    }
Exemple #14
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!");
                    }
                }
            }
        }
        private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
        {
            resultState = state;
            Asset = asset;

            DownloadHandle.Set();
        }
Exemple #16
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 #17
0
 void Assets_OnImageReceived(ImageDownload image, AssetTexture asset)
 {
     if (asset.AssetID == _MapImageID)
     {
         ManagedImage nullImage;
         OpenJPEG.DecodeToImage(asset.AssetData, out nullImage, out _MapLayer);
     }
 }
Exemple #18
0
 public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture)
 {
     if (state == TextureRequestState.Finished)
     {
         lock (Manager.AssetsReceived)
             Manager.AssetsReceived[assetTexture.AssetID] = true;
     }
 }
Exemple #19
0
 void Assets_OnImageReceived(ImageDownload image, AssetTexture asset)
 {
     if (asset.AssetID == _MapImageID)
     {
         ManagedImage nullImage;
         OpenJPEG.DecodeToImage(asset.AssetData, out nullImage, out _MapLayer);
     }
 }
        public override string Execute(string[] args, UUID fromAgentID)
        {
            if (args.Length != 1 && args.Length != 2)
                return "Usage: downloadtexture [texture-uuid] [discardlevel]";

            TextureID = UUID.Zero;
            DownloadHandle.Reset();
            Asset = null;

            if (UUID.TryParse(args[0], out TextureID))
            {
                int discardLevel = 0;

                if (args.Length > 1)
                {
                    if (!Int32.TryParse(args[1], out discardLevel))
                        return "Usage: downloadtexture [texture-uuid] [discardlevel]";
                }

                Client.Assets.RequestImage(TextureID, ImageType.Normal, Assets_OnImageReceived);

                if (DownloadHandle.WaitOne(120 * 1000, false))
                {
                    if (resultState == TextureRequestState.Finished)
                    {
                        if (Asset != null && Asset.Decode())
                        {
                            try { File.WriteAllBytes(Asset.AssetID + ".jp2", Asset.AssetData); }
                            catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); }

                            return String.Format("Saved {0}.jp2 ({1}x{2})", Asset.AssetID, Asset.Image.Width, Asset.Image.Height);
                        }
                        else
                        {
                            return "Failed to decode texture " + TextureID.ToString();
                        }
                    }
                    else if (resultState == TextureRequestState.NotFound)
                    {
                        return "Simulator reported texture not found: " + TextureID.ToString();
                    }
                    else
                    {
                        return "Download failed for texture " + TextureID + " " +  resultState;
                    }
                }
                else
                {
                    return "Timed out waiting for texture download";
                }
            }
            else
            {
                return "Usage: downloadtexture [texture-uuid]";
            }
        }
Exemple #21
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); });
            }
        }
Exemple #22
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;
            }
        }
Exemple #23
0
 private void Assets_OnImageReceived(ImageDownload image, AssetTexture asset)
 {
     if (enabled && alreadyRequested.ContainsKey(image.ID))
     {
         if (image.Success)
         {
             Logger.DebugLog(String.Format("Finished downloading texture {0} ({1} bytes)", image.ID, image.Size));
         }
         else
         {
             Logger.Log("Failed to download texture " + image.ID.ToString(), Helpers.LogLevel.Warning);
         }
     }
 }
Exemple #24
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]");
            }
        }
 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);
         }
     }
 }
        void LoadAssets(string path)
        {
            try
            {
                string[] textures  = Directory.GetFiles(path, "*.jp2", SearchOption.TopDirectoryOnly);
                string[] clothing  = Directory.GetFiles(path, "*.clothing", SearchOption.TopDirectoryOnly);
                string[] bodyparts = Directory.GetFiles(path, "*.bodypart", SearchOption.TopDirectoryOnly);
                string[] sounds    = Directory.GetFiles(path, "*.ogg", SearchOption.TopDirectoryOnly);

                for (int i = 0; i < textures.Length; i++)
                {
                    UUID  assetID = ParseUUIDFromFilename(textures[i]);
                    Asset asset   = new AssetTexture(assetID, File.ReadAllBytes(textures[i]));
                    asset.Temporary = true;
                    StoreAsset(asset);
                }

                for (int i = 0; i < clothing.Length; i++)
                {
                    UUID  assetID = ParseUUIDFromFilename(clothing[i]);
                    Asset asset   = new AssetClothing(assetID, File.ReadAllBytes(clothing[i]));
                    asset.Temporary = true;
                    StoreAsset(asset);
                }

                for (int i = 0; i < bodyparts.Length; i++)
                {
                    UUID  assetID = ParseUUIDFromFilename(bodyparts[i]);
                    Asset asset   = new AssetBodypart(assetID, File.ReadAllBytes(bodyparts[i]));
                    asset.Temporary = true;
                    StoreAsset(asset);
                }

                for (int i = 0; i < sounds.Length; i++)
                {
                    UUID  assetID = ParseUUIDFromFilename(sounds[i]);
                    Asset asset   = new AssetSound(assetID, File.ReadAllBytes(sounds[i]));
                    asset.Temporary = true;
                    StoreAsset(asset);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, Helpers.LogLevel.Warning, ex);
            }
        }
Exemple #27
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 #28
0
        /// <summary>
        /// Adds an image to this baking texture and potentially processes it, or
        /// stores it for processing later
        /// </summary>
        /// <param name="index">The baking texture index of the image to be added</param>
        /// <param name="jp2data">JPEG2000 compressed image to be added to the
        /// baking texture</param>
        /// <returns>True if this texture is completely baked and JPEG2000 data
        /// is available, otherwise false</returns>
        public bool AddTexture(AppearanceManager.TextureIndex index, AssetTexture texture)
        {
            lock (Textures)
            {
                texture.Decode();
                Textures.Add(index, texture);
                Client.DebugLog("Adding texture " + index.ToString() + " to bake " + BakeType.ToString());
            }

            if (Textures.Count == TextureCount)
            {
                Bake();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #29
0
        private void Assets_OnImageReceived(AssetTexture assetTexture)
        {
            if (assetTexture.AssetID != this.imageID)
            {
                return;
            }

            if (InvokeRequired)
            {
                if (IsHandleCreated || !instance.MonoRuntime)
                {
                    BeginInvoke(new MethodInvoker(() => Assets_OnImageReceived(assetTexture)));
                }
                return;
            }

            try
            {
                progressBar1.Hide();
                lblProgress.Hide();

                if (!OpenJPEG.DecodeToImage(assetTexture.AssetData, out imgManaged, out image))
                {
                    throw new Exception("decoding failure");
                }

                Text = Text; // yeah, really ;)

                pictureBox1.Image   = image;
                pictureBox1.Enabled = true;
                jpegdata            = assetTexture.AssetData;
                if (Detached)
                {
                    ClientSize = pictureBox1.Size = new Size(image.Width, image.Height);
                }
            }
            catch (Exception excp)
            {
                this.Hide();
                System.Console.WriteLine("Error decoding image: " + excp.Message);
            }
        }
Exemple #30
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 #31
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;
            }

            this.imagecache.AddImage(image.ID, decodedImage);
            BeginInvoke(new OnSetFinalImage(SetFinalImage), new object[] { decodedImage });
        }
Exemple #32
0
 private void Assets_OnImageReceived(AssetTexture assetTexture)
 {
     try
     {
         byte[]       jpegdata;
         ManagedImage imgManaged;
         Image        image;
         SimAsset     sa = SimAssetStore.FindOrCreateAsset(assetTexture.AssetID, assetTexture.AssetType);
         if (!OpenJPEG.DecodeToImage(assetTexture.AssetData, out imgManaged, out image))
         {
             throw new Exception("decoding failure");
         }
         jpegdata     = assetTexture.AssetData;
         sa._TypeData = jpegdata;
         UUIDTypeObjectSetValue(assetTexture.AssetID, jpegdata);
         assetTexture.Decode();
     }
     catch (Exception excp)
     {
         System.Console.WriteLine("Error decoding image: " + excp.Message);
     }
 }
Exemple #33
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");
                }
            }
        }
        public void StoreAsset(Asset asset)
        {
            if (asset is AssetTexture)
            {
                AssetTexture texture = (AssetTexture)asset;

                if (texture.DecodeLayerBoundaries())
                {
                    lock (AssetStore)
                        AssetStore[asset.AssetID] = texture;
                    if (!asset.Temporary)
                    {
                        SaveAsset(texture);
                    }
                }
                else
                {
                    Logger.Log(String.Format("Failed to decoded layer boundaries on texture {0}", texture.AssetID),
                               Helpers.LogLevel.Warning);
                }
            }
            else
            {
                if (asset.Decode())
                {
                    lock (AssetStore)
                        AssetStore[asset.AssetID] = asset;
                    if (!asset.Temporary)
                    {
                        SaveAsset(asset);
                    }
                }
                else
                {
                    Logger.Log(String.Format("Failed to decode {0} asset {1}", asset.AssetType, asset.AssetID),
                               Helpers.LogLevel.Warning);
                }
            }
        }
        /// <summary>
        /// Decode Jpeg2000 Asset Data
        /// </summary>
        /// <param name="AssetId">UUID of Asset</param>
        /// <param name="j2kdata">Byte Array Asset Data </param>
        private void doJ2kDecode(UUID AssetId, byte[] j2kdata)
        {
            int DecodeTime = 0;
            DecodeTime = Environment.TickCount;
            OpenJPEG.J2KLayerInfo[] layers = new OpenJPEG.J2KLayerInfo[0]; // Dummy result for if it fails.  Informs that there's only full quality

            if (!OpenJpegFail)
            {
                if (!fCache.TryLoadCacheForAsset(AssetId, out layers))
                {
                    try
                    {

                        AssetTexture texture = new AssetTexture(AssetId, j2kdata);
                        if (texture.DecodeLayerBoundaries())
                        {
                            bool sane = true;

                            // Sanity check all of the layers
                            for (int i = 0; i < texture.LayerInfo.Length; i++)
                            {
                                if (texture.LayerInfo[i].End > texture.AssetData.Length)
                                {
                                    sane = false;
                                    break;
                                }
                            }

                            if (sane)
                            {
                                layers = texture.LayerInfo;
                                fCache.SaveFileCacheForAsset(AssetId, layers);
                               

                                    // Write out decode time
                                    m_log.InfoFormat("[J2KDecoderModule]: {0} Decode Time: {1}", Environment.TickCount - DecodeTime,
                                                     AssetId);
                               
                            }
                            else
                            {
                                m_log.WarnFormat(
                                    "[J2KDecoderModule]: JPEG2000 texture decoding succeeded, but sanity check failed for {0}",
                                    AssetId);
                            }
                        }

                        else
                        {
                            /*
                            Random rnd = new Random();
                             // scramble ends for test
                            for (int i = 0; i < texture.LayerInfo.Length; i++)
                            {
                                texture.LayerInfo[i].End = rnd.Next(999999);
                            }
                            */

                            // Try to do some heuristics error correction!  Yeah.
                            bool sane2Heuristics = true;


                            if (texture.Image == null)
                                sane2Heuristics = false;

                            if (texture.LayerInfo == null)
                                sane2Heuristics = false;

                            if (sane2Heuristics)
                            {


                                if (texture.LayerInfo.Length == 0)
                                    sane2Heuristics = false;
                            }

                            if (sane2Heuristics)
                            {
                                // Last layer start is less then the end of the file and last layer start is greater then 0
                                if (texture.LayerInfo[texture.LayerInfo.Length - 1].Start < texture.AssetData.Length && texture.LayerInfo[texture.LayerInfo.Length - 1].Start > 0)
                                {
                                }
                                else
                                {
                                    sane2Heuristics = false;
                                }

                            }

                            if (sane2Heuristics)
                            {
                                int start = 0;
                                
                                // try to fix it by using consistant data in the start field
                                for (int i = 0; i < texture.LayerInfo.Length; i++)
                                {
                                    if (i == 0)
                                        start = 0;

                                    if (i == texture.LayerInfo.Length - 1)
                                        texture.LayerInfo[i].End = texture.AssetData.Length;
                                    else
                                        texture.LayerInfo[i].End = texture.LayerInfo[i + 1].Start - 1;

                                    // in this case, the end of the next packet is less then the start of the last packet
                                    // after we've attempted to fix it which means the start of the last packet is borked
                                    // there's no recovery from this
                                    if (texture.LayerInfo[i].End < start)
                                    {
                                        sane2Heuristics = false;
                                        break;
                                    }
 
                                    if (texture.LayerInfo[i].End < 0 || texture.LayerInfo[i].End > texture.AssetData.Length)
                                    {
                                        sane2Heuristics = false;
                                        break;
                                    }

                                    if (texture.LayerInfo[i].Start < 0 || texture.LayerInfo[i].Start > texture.AssetData.Length)
                                    {
                                        sane2Heuristics = false;
                                        break;
                                    }

                                    start = texture.LayerInfo[i].Start;
                                }
                            }

                            if (sane2Heuristics)
                            {
                                layers = texture.LayerInfo;
                                fCache.SaveFileCacheForAsset(AssetId, layers);


                                // Write out decode time
                                m_log.InfoFormat("[J2KDecoderModule]: HEURISTICS SUCCEEDED {0} Decode Time: {1}", Environment.TickCount - DecodeTime,
                                                 AssetId);

                            }
                            else
                            {
                                m_log.WarnFormat("[J2KDecoderModule]: JPEG2000 texture decoding failed for {0}.   Is this a texture?  is it J2K?", AssetId);
                            }
                        }
                        texture = null; // dereference and dispose of ManagedImage
                    }
                    catch (DllNotFoundException)
                    {
                        m_log.Error(
                            "[J2KDecoderModule]: OpenJpeg is not installed properly. Decoding disabled!  This will slow down texture performance!  Often times this is because of an old version of GLIBC.  You must have version 2.4 or above!");
                        OpenJpegFail = true;
                    }
                    catch (Exception ex)
                    {
                        m_log.WarnFormat(
                            "[J2KDecoderModule]: JPEG2000 texture decoding threw an exception for {0}, {1}",
                            AssetId, ex);
                    }
                }
               
            }

            // Cache Decoded layers
            lock (m_cacheddecode)
            {
                if (m_cacheddecode.ContainsKey(AssetId))
                    m_cacheddecode.Remove(AssetId);
                m_cacheddecode.Add(AssetId, layers);

            }            

            // Notify Interested Parties
            lock (m_notifyList)
            {
                if (m_notifyList.ContainsKey(AssetId))
                {
                    foreach (DecodedCallback d in m_notifyList[AssetId])
                    {
                        if (d != null)
                            d.DynamicInvoke(AssetId, layers);
                    }
                    m_notifyList.Remove(AssetId);
                }
            }
        }
Exemple #36
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);
            //}
        }
        private static bool LoadAsset(string assetPath, byte[] data, AssetLoadedCallback assetCallback, long bytesRead, long totalBytes)
        {
            // Right now we're nastily obtaining the UUID from the filename
            string filename = assetPath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);
            int i = filename.LastIndexOf(ArchiveConstants.ASSET_EXTENSION_SEPARATOR);

            if (i == -1)
            {
                Logger.Log(String.Format(
                    "[OarFile]: Could not find extension information in asset path {0} since it's missing the separator {1}.  Skipping",
                    assetPath, ArchiveConstants.ASSET_EXTENSION_SEPARATOR), Helpers.LogLevel.Warning);
                return false;
            }

            string extension = filename.Substring(i);
            UUID uuid;
            UUID.TryParse(filename.Remove(filename.Length - extension.Length), out uuid);

            if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension))
            {
                AssetType assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];
                Asset asset = null;

                switch (assetType)
                {
                    case AssetType.Animation:
                        asset = new AssetAnimation(uuid, data);
                        break;
                    case AssetType.Bodypart:
                        asset = new AssetBodypart(uuid, data);
                        break;
                    case AssetType.Clothing:
                        asset = new AssetClothing(uuid, data);
                        break;
                    case AssetType.Gesture:
                        asset = new AssetGesture(uuid, data);
                        break;
                    case AssetType.Landmark:
                        asset = new AssetLandmark(uuid, data);
                        break;
                    case AssetType.LSLBytecode:
                        asset = new AssetScriptBinary(uuid, data);
                        break;
                    case AssetType.LSLText:
                        asset = new AssetScriptText(uuid, data);
                        break;
                    case AssetType.Notecard:
                        asset = new AssetNotecard(uuid, data);
                        break;
                    case AssetType.Object:
                        asset = new AssetPrim(uuid, data);
                        break;
                    case AssetType.Sound:
                        asset = new AssetSound(uuid, data);
                        break;
                    case AssetType.Texture:
                        asset = new AssetTexture(uuid, data);
                        break;
                    default:
                        Logger.Log("[OarFile] Unhandled asset type " + assetType, Helpers.LogLevel.Error);
                        break;
                }

                if (asset != null)
                {
                    assetCallback(asset, bytesRead, totalBytes);
                    return true;
                }
            }

            Logger.Log("[OarFile] Failed to load asset", Helpers.LogLevel.Warning);
            return false;
        }
        //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 });
        }
 void onGotImage(AssetTexture asset)
 {
     if (asset == null)
     {
         Logger.Log("Try get image got a null asset",Helpers.LogLevel.Debug);
         return;
     }
     if(asset.AssetID==this.target_asset)
     {
         this_asset = asset;
         Thread decode = new Thread(new ThreadStart(this.decodethread));
         Logger.Log("Begining a decode thread for asset "+asset.AssetID.ToString(),Helpers.LogLevel.Debug);
         decode.Start();
     }
 }
Exemple #40
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 #41
0
        void DisplayPartialImage(AssetTexture assetTexture)
        {
            if (InvokeRequired)
            {
                if (IsHandleCreated || !instance.MonoRuntime)
                    BeginInvoke(new MethodInvoker(() => DisplayPartialImage(assetTexture)));
                return;
            }

            try
            {
                ManagedImage tmp;
                System.Drawing.Image img;
                if (OpenJPEG.DecodeToImage(assetTexture.AssetData, out tmp, out img))
                {
                    pictureBox1.Image = img;
                    pictureBox1.Enabled = true;
                }
            }
            catch (Exception) { }
        }
Exemple #42
0
        protected void Bake()
        {
            BakedTexture = new AssetTexture(new Image(BakeWidth, BakeHeight, ImageChannels.Color | ImageChannels.Alpha | ImageChannels.Bump));

            if (BakeType == AppearanceManager.BakeType.Eyes)
            {
                if (!DrawLayer(AppearanceManager.TextureIndex.EyesIris))
                    oldBake();
            }
            else if (BakeType == AppearanceManager.BakeType.Head)
            {
                if (!DrawLayer(AppearanceManager.TextureIndex.HeadBodypaint))
                    oldBake();
            }
            else if (BakeType == AppearanceManager.BakeType.Skirt)
            {
                if (!DrawLayer(AppearanceManager.TextureIndex.Skirt))
                    oldBake();
            }
            else if (BakeType == AppearanceManager.BakeType.UpperBody)
            {
                if (!DrawLayer(AppearanceManager.TextureIndex.UpperBodypaint))
                    oldBake();
                DrawLayer(AppearanceManager.TextureIndex.UpperUndershirt);
                DrawLayer(AppearanceManager.TextureIndex.UpperGloves);
                DrawLayer(AppearanceManager.TextureIndex.UpperShirt);
                DrawLayer(AppearanceManager.TextureIndex.UpperJacket);
            }
            else if (BakeType == AppearanceManager.BakeType.LowerBody)
            {
                if (!DrawLayer(AppearanceManager.TextureIndex.LowerBodypaint))
                    oldBake();
                DrawLayer(AppearanceManager.TextureIndex.LowerUnderpants);
                DrawLayer(AppearanceManager.TextureIndex.LowerSocks);
                DrawLayer(AppearanceManager.TextureIndex.LowerShoes);
                DrawLayer(AppearanceManager.TextureIndex.LowerPants);
                DrawLayer(AppearanceManager.TextureIndex.LowerJacket);
            }

            BakedTexture.Encode();

        }
Exemple #43
0
        private bool DrawLayer(AppearanceManager.TextureIndex textureIndex)
        {
            int i = 0;

            AssetTexture texture = new AssetTexture();

            if ( ! Textures.TryGetValue(textureIndex, out texture))
                return false;

            Client.DebugLog("DrawLayer(): baking layer " + textureIndex.ToString());

            Image source = texture.Image;

            source.ResizeNearestNeighbor(BakeWidth, BakeHeight);

            if (textureIndex == AppearanceManager.TextureIndex.HeadBodypaint
                || textureIndex == AppearanceManager.TextureIndex.UpperBodypaint
                || textureIndex == AppearanceManager.TextureIndex.LowerBodypaint
                || textureIndex == AppearanceManager.TextureIndex.Skirt
                || textureIndex == AppearanceManager.TextureIndex.EyesIris)
            { // initial layer, just copy onto baked layer

                for (int y = 0; y < BakeHeight; y++)
                {
                    for (int x = 0; x < BakeWidth; x++)
                    {
                        if ((source.Channels & ImageChannels.Alpha) != 0)
                        {
                            if (source.Alpha[i] != 0)
                            {
                                BakedTexture.Image.Red[i] = source.Red[i];
                                BakedTexture.Image.Green[i] = source.Green[i];
                                BakedTexture.Image.Blue[i] = source.Blue[i];

                                BakedTexture.Image.Alpha[i] = source.Alpha[i];
                                BakedTexture.Image.Bump[i] = 0;
                            }
                        }
                        else
                        {
                            BakedTexture.Image.Red[i] = source.Red[i];
                            BakedTexture.Image.Green[i] = source.Green[i];
                            BakedTexture.Image.Blue[i] = source.Blue[i];
                            BakedTexture.Image.Alpha[i] = 255;

                            BakedTexture.Image.Bump[i] = 0;
                        }

                        ++i;
                    }
                }
            }
            else // not skin layer, so composite with alpha blending
            {

                for (int y = 0; y < BakeHeight; y++)
                {
                    for (int x = 0; x < BakeWidth; x++)
                    {

                        float alpha = (float)source.Alpha[i];
                        alpha /= 255.0f;
                        float red = (float)source.Red[i];
                        float green = (float)source.Green[i];
                        float blue = (float)source.Blue[i];
                        red /= 255.0f;
                        green /= 255.0f;
                        blue /= 255.0f;

                        float currRed = (float)BakedTexture.Image.Red[i];
                        float currGreen = (float)BakedTexture.Image.Green[i];
                        float currBlue = (float)BakedTexture.Image.Blue[i];

                        currRed /= 255.0F;
                        currGreen /= 255.0F;
                        currBlue /= 255.0F;

                        BakedTexture.Image.Red[i] = (byte)(255.0f * ((currRed * (1.0 - alpha)) + (red * alpha)));

                        BakedTexture.Image.Green[i] = (byte)(255.0f * ((currGreen * (1.0 - alpha)) + (green * alpha)));
                        BakedTexture.Image.Blue[i] = (byte)(255.0f * ((currBlue * (1.0 - alpha)) + (blue * alpha)));

                        i++;
                    }
                }
            }
            return true;
        }
 void statusupdate(TextureRequestState state, AssetTexture assetTexture)
 {
     if (state == TextureRequestState.Finished && gotdata == false)
        {
        gotdata = true;
        onGotImage(assetTexture);
        }
 }
Exemple #45
0
        /// <summary>
        /// Adds an image to this baking texture and potentially processes it, or
        /// stores it for processing later
        /// </summary>
        /// <param name="index">The baking texture index of the image to be added</param>
        /// <param name="texture">JPEG2000 compressed image to be added to the 
        /// baking texture</param>
        /// <returns>True if this texture is completely baked and JPEG2000 data 
        /// is available, otherwise false</returns>
        public bool AddTexture(AppearanceManager.TextureIndex index, AssetTexture texture)
        {
            lock (Textures)
            {
                try 
                {

                    texture.Decode();
                    Textures.Add(index, texture);
                    Client.DebugLog("Adding texture " + index.ToString() + " ID: " + texture.AssetID.ToString() + " to bake " + BakeType.ToString());
                }
                catch ( Exception e )
                {
                    Client.DebugLog( "caught exception while trying add texture: " + e.Message.ToString());
                }

            }

            if (Textures.Count == TextureCount)
            {
                Bake();
                
                return true;
            }
            else
                return false;
        }
Exemple #46
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 #47
0
        /// <summary>
        /// The worker thread that sends the request and handles timeouts
        /// </summary>
        /// <param name="threadContext">A <see cref="TaskInfo"/> object containing the request details</param>
        private void TextureRequestDoWork(Object threadContext)
        {
            TaskInfo task = (TaskInfo) threadContext;
            
            task.State = TextureRequestState.Progress;

#if DEBUG_TIMING
            task.NetworkTime = DateTime.UtcNow;
#endif
            // start the timeout timer
            resetEvents[task.RequestSlot].Reset();
            RequestImage(task.RequestID, task.Type, 1013000.0f, 0, 0);

            // don't release this worker slot until texture is downloaded or timeout occurs
            if (!resetEvents[task.RequestSlot].WaitOne(_Assets.PipelineRequestTimeout, false))
            {
                // Timed out
                Logger.Log("Worker " + task.RequestSlot + " Timeout waiting for Texture " + task.RequestID + " to Download Got " + task.Transfer.Transferred + " of " + task.Transfer.Size, Helpers.LogLevel.Warning);

                AssetTexture texture = new AssetTexture(task.RequestID, task.Transfer.AssetData);
                foreach (TextureDownloadCallback callback in task.Callbacks)
                {
                    callback(TextureRequestState.Timeout, texture);
                }

                _Assets.FireImageProgressEvent(task.RequestID, task.Transfer.Transferred, task.Transfer.Size);

                lock (_Transfers)
                    _Transfers.Remove(task.RequestID);
            }

            // free up this download slot
            lock(lockerObject)
                threadpoolSlots[task.RequestSlot] = -1;
        }
Exemple #48
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 #49
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 #50
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!");
                }
            }
        }
        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 #52
0
        protected void Bake()
        {
            _bakedTexture = new AssetTexture(new ManagedImage(_bakeWidth, _bakeHeight,
                ManagedImage.ImageChannels.Color | ManagedImage.ImageChannels.Alpha | ManagedImage.ImageChannels.Bump));

            if (_bakeType == AppearanceManager.BakeType.Eyes)
            {
                InitBakedLayerColor(255, 255, 255);
                if (!DrawLayer(AppearanceManager.TextureIndex.EyesIris))
                {
                    Logger.Log("Missing texture for EYES - unable to bake layer", Helpers.LogLevel.Warning, _client);
                }
            }
            else if (_bakeType == AppearanceManager.BakeType.Head)
            {
                // FIXME: Need to use the visual parameters to determine the base skin color in RGB but
                // it's not apparent how to define RGB levels from the skin color parameters, so
                // for now use a grey foundation for the skin
                InitBakedLayerColor(128, 128, 128);
                DrawLayer(AppearanceManager.TextureIndex.HeadBodypaint);

                // HACK: Bake the eyelashes in if we have them
                ManagedImage eyelashes = LoadAlphaLayer("head_alpha.tga");

                if (eyelashes != null)
                {
                    Logger.DebugLog("Loaded head_alpha.tga, baking in eyelashes");
                    DrawLayer(eyelashes, true);
                }
                else
                {
                    Logger.Log("head_alpha.tga resource not found, skipping eyelashes", Helpers.LogLevel.Info);
                }
            }
            else if (_bakeType == AppearanceManager.BakeType.Skirt)
            {
                float skirtRed = 1.0f, skirtGreen = 1.0f, skirtBlue = 1.0f;

                try
                {
                    _paramValues.TryGetValue(VisualParams.Find("skirt_red", "skirt").ParamID, out skirtRed);
                    _paramValues.TryGetValue(VisualParams.Find("skirt_green", "skirt").ParamID, out skirtGreen);
                    _paramValues.TryGetValue(VisualParams.Find("skirt_blue", "skirt").ParamID, out skirtBlue);
                }
                catch
                {
                    Logger.Log("Unable to determine skirt color from visual params", Helpers.LogLevel.Warning, _client);
                }

                InitBakedLayerColor((byte)(skirtRed * 255.0f), (byte)(skirtGreen * 255.0f), (byte)(skirtBlue * 255.0f));
                DrawLayer(AppearanceManager.TextureIndex.Skirt);
            }
            else if (_bakeType == AppearanceManager.BakeType.UpperBody)
            {
                InitBakedLayerColor(128, 128, 128);
                DrawLayer(AppearanceManager.TextureIndex.UpperBodypaint);
                DrawLayer(AppearanceManager.TextureIndex.UpperUndershirt);
                DrawLayer(AppearanceManager.TextureIndex.UpperGloves);
                DrawLayer(AppearanceManager.TextureIndex.UpperShirt);
                DrawLayer(AppearanceManager.TextureIndex.UpperJacket);
            }
            else if (_bakeType == AppearanceManager.BakeType.LowerBody)
            {
                InitBakedLayerColor(128, 128, 128);
                DrawLayer(AppearanceManager.TextureIndex.LowerBodypaint);
                DrawLayer(AppearanceManager.TextureIndex.LowerUnderpants);
                DrawLayer(AppearanceManager.TextureIndex.LowerSocks);
                DrawLayer(AppearanceManager.TextureIndex.LowerShoes);
                DrawLayer(AppearanceManager.TextureIndex.LowerPants);
                DrawLayer(AppearanceManager.TextureIndex.LowerJacket);
            }

            _bakedTexture.Encode();
        }
        //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 #54
0
        private void Assets_OnImageReceived(AssetTexture assetTexture)
        {
            if (assetTexture.AssetID != this.imageID)
            {
                return;
            }

            if (InvokeRequired)
            {
                if (IsHandleCreated || !instance.MonoRuntime)
                    BeginInvoke(new MethodInvoker(() => Assets_OnImageReceived(assetTexture)));
                return;
            }

            try
            {
                progressBar1.Hide();
                lblProgress.Hide();

                if (!OpenJPEG.DecodeToImage(assetTexture.AssetData, out imgManaged, out image))
                {
                    throw new Exception("decoding failure");
                }

                Text = Text; // yeah, really ;)

                pictureBox1.Image = image;
                pictureBox1.Enabled = true;
                jpegdata = assetTexture.AssetData;
                if (Detached)
                {
                    ClientSize = pictureBox1.Size = new Size(image.Width, image.Height);
                }
            }
            catch (Exception excp)
            {
                this.Hide();
                System.Console.WriteLine("Error decoding image: " + excp.Message);
            }
        }
Exemple #55
0
        /// <summary>
        /// The worker thread that sends the request and handles timeouts
        /// </summary>
        /// <param name="threadContext">A <see cref="TaskInfo"/> object containing the request details</param>
        private void TextureRequestDoWork(Object threadContext)
        {
            TaskInfo task = (TaskInfo)threadContext;

            task.State = TextureRequestState.Progress;

#if DEBUG_TIMING
            task.NetworkTime = DateTime.UtcNow;
#endif
            // Find the first missing packet in the download
            ushort packet = 0;
            if (task.Transfer.PacketsSeen != null && task.Transfer.PacketsSeen.Count > 0)
                packet = GetFirstMissingPacket(task.Transfer.PacketsSeen);

            // Request the texture
            RequestImage(task.RequestID, task.Type, task.Transfer.Priority, task.Transfer.DiscardLevel, packet);

            // Set starting time
            task.Transfer.TimeSinceLastPacket = 0;

            // Don't release this worker slot until texture is downloaded or timeout occurs
            if (!resetEvents[task.RequestSlot].WaitOne())
            {
                // Timed out
                Logger.Log("Worker " + task.RequestSlot + " timeout waiting for texture " + task.RequestID + " to download got " +
                    task.Transfer.Transferred + " of " + task.Transfer.Size, Helpers.LogLevel.Warning);

                AssetTexture texture = new AssetTexture(task.RequestID, task.Transfer.AssetData);
                foreach (TextureDownloadCallback callback in task.Callbacks)
                    callback(TextureRequestState.Timeout, texture);

                _Client.Assets.FireImageProgressEvent(task.RequestID, task.Transfer.Transferred, task.Transfer.Size);

                RemoveTransfer(task.RequestID);
            }

            // Free up this download slot
            lock (lockerObject)
                threadpoolSlots[task.RequestSlot] = -1;
        }
Exemple #56
0
        public static Asset CreateAssetWrapper(AssetType type, UUID uuid, byte[] data)
        {
            Asset asset;

            switch (type)
            {
                case AssetType.Animation:
                    asset = new AssetAnimation(uuid, data);
                    break;
                case AssetType.Gesture:
                    asset = new AssetGesture(uuid, data);
                    break;
                case AssetType.Landmark:
                    asset = new AssetLandmark(uuid, data);
                    break;
                case AssetType.Bodypart:
                    asset = new AssetBodypart(uuid, data);
                    break;
                case AssetType.Clothing:
                    asset = new AssetClothing(uuid, data);
                    break;
                case AssetType.LSLBytecode:
                    asset = new AssetScriptBinary(uuid, data);
                    break;
                case AssetType.LSLText:
                    asset = new AssetScriptText(uuid, data);
                    break;
                case AssetType.Notecard:
                    asset = new AssetNotecard(uuid, data);
                    break;
                case AssetType.Sound:
                    asset = new AssetSound(uuid, data);
                    break;
                case AssetType.Texture:
                    asset = new AssetTexture(uuid, data);
                    break;
#if COGBOT_LIBOMV
                    case AssetType.CallingCard:
                    asset = new AssetCallingCard(uuid, data);
                    break;
#endif
                default:
#if COGBOT_LIBOMV
                    asset = new AssetMutable(type, uuid, data);
                    Logger.Log("[OarFile] Not Implemented asset type " + type, Helpers.LogLevel.Error);
#else
                    throw new NotImplementedException("Unimplemented asset type: " + type);
#endif
                    break;
            }
            return asset;
        }
Exemple #57
0
        protected void oldBake()
        {
            Client.DebugLog("Baking " + BakeType.ToString());
            BakedTexture = new AssetTexture(new Image(BakeWidth, BakeHeight, ImageChannels.Color | ImageChannels.Alpha | ImageChannels.Bump));
            int i = 0;

            for (int y = 0; y < BakeHeight; y++)
            {
                for (int x = 0; x < BakeWidth; x++)
                {
                    if (((x ^ y) & 0x10) == 0)
                    {
                        BakedTexture.Image.Red[i] = 255;
                        BakedTexture.Image.Green[i] = 0;
                        BakedTexture.Image.Blue[i] = 0;
                        BakedTexture.Image.Alpha[i] = 255;
                        BakedTexture.Image.Bump[i] = 0;
                    }
                    else
                    {
                        BakedTexture.Image.Red[i] = 0;
                        BakedTexture.Image.Green[i] = 0;
                        BakedTexture.Image.Blue[i] = 255;
                        BakedTexture.Image.Alpha[i] = 255;
                        BakedTexture.Image.Bump[i] = 0;
                    }

                    ++i;
                }
            }

            BakedTexture.Encode();
        }
Exemple #58
0
 public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture)
 {
     if (state == TextureRequestState.Finished)
     {
         lock (Manager.AssetsReceived)
             Manager.AssetsReceived[assetTexture.AssetID] = true;
     }
 }
Exemple #59
0
        private Asset CreateAssetWrapper(AssetType type)
        {
            Asset asset;

            switch (type)
            {
                case AssetType.Notecard:
                    asset = new AssetNotecard();
                    break;
                case AssetType.LSLText:
                    asset = new AssetScriptText();
                    break;
                case AssetType.LSLBytecode:
                    asset = new AssetScriptBinary();
                    break;
                case AssetType.Texture:
                    asset = new AssetTexture();
                    break;
                case AssetType.Object:
                    asset = new AssetPrim();
                    break;
                case AssetType.Clothing:
                    asset = new AssetClothing();
                    break;
                case AssetType.Bodypart:
                    asset = new AssetBodypart();
                    break;
                case AssetType.Animation:
                    asset = new AssetAnimation();
                    break;
                case AssetType.Sound:
                    asset = new AssetSound();
                    break;
                case AssetType.Landmark:
                    asset = new AssetLandmark();
                    break;
                case AssetType.Gesture:
                    asset = new AssetGesture();
                    break;
                default:
                    Logger.Log("Unimplemented asset type: " + type, Helpers.LogLevel.Error, Client);
                    return null;
            }

            return asset;
        }
Exemple #60
0
 public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture)
 {
     //TODO: Implement texture saving and applying
 }