Esempio n. 1
0
        public bool AsyncConvertData(UUID id, string bodyData, string extraParams)
        {
            // XXX: This isn't actually being done asynchronously!
            m_textureManager.ReturnData(id, ConvertData(bodyData, extraParams));

            return(true);
        }
Esempio n. 2
0
        public bool AsyncConvertData(UUID id, string bodyData, string extraParams)
        {
            if (m_textureManager == null)
            {
                m_log.Warn("[VECTORRENDERMODULE]: No texture manager. Can't function");
                return(false);
            }
            // XXX: This isn't actually being done asynchronously!
            m_textureManager.ReturnData(id, ConvertData(bodyData, extraParams));

            return(true);
        }
Esempio n. 3
0
        private void Draw(string data, UUID id, string extraParams)
        {
            // We need to cater for old scripts that didnt use extraParams neatly, they use either an integer size which represents both width and height, or setalpha
            // we will now support multiple comma seperated params in the form  width:256,height:512,alpha:255
            int   width        = 256;
            int   height       = 256;
            int   alpha        = 255;         // 0 is transparent
            Color bgColour     = Color.White; // Default background color
            char  altDataDelim = ';';

            char[] paramDelimiter = { ',' };
            char[] nvpDelimiter   = { ':' };

            extraParams = extraParams.Trim();
            extraParams = extraParams.ToLower();

            string[] nvps = extraParams.Split(paramDelimiter);

            int temp = -1;

            foreach (string pair in nvps)
            {
                string[] nvp   = pair.Split(nvpDelimiter);
                string   name  = "";
                string   value = "";

                if (nvp[0] != null)
                {
                    name = nvp[0].Trim();
                }

                if (nvp.Length == 2)
                {
                    value = nvp[1].Trim();
                }

                switch (name)
                {
                case "width":
                    temp = parseIntParam(value);
                    if (temp != -1)
                    {
                        if (temp < 1)
                        {
                            width = 1;
                        }
                        else if (temp > 2048)
                        {
                            width = 2048;
                        }
                        else
                        {
                            width = temp;
                        }
                    }
                    break;

                case "height":
                    temp = parseIntParam(value);
                    if (temp != -1)
                    {
                        if (temp < 1)
                        {
                            height = 1;
                        }
                        else if (temp > 2048)
                        {
                            height = 2048;
                        }
                        else
                        {
                            height = temp;
                        }
                    }
                    break;

                case "alpha":
                    temp = parseIntParam(value);
                    if (temp != -1)
                    {
                        if (temp < 0)
                        {
                            alpha = 0;
                        }
                        else if (temp > 255)
                        {
                            alpha = 255;
                        }
                        else
                        {
                            alpha = temp;
                        }
                    }
                    // Allow a bitmap w/o the alpha component to be created
                    else if (value.ToLower() == "false")
                    {
                        alpha = 256;
                    }
                    break;

                case "bgcolour":
                    int hex = 0;
                    if (Int32.TryParse(value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hex))
                    {
                        bgColour = Color.FromArgb(hex);
                    }
                    else
                    {
                        bgColour = Color.FromName(value);
                    }
                    break;

                case "altdatadelim":
                    altDataDelim = value.ToCharArray()[0];
                    break;

                case "":
                    // blank string has been passed do nothing just use defaults
                    break;

                default:      // this is all for backwards compat, all a bit ugly hopfully can be removed in future
                    // could be either set alpha or just an int
                    if (name == "setalpha")
                    {
                        alpha = 0;      // set the texture to have transparent background (maintains backwards compat)
                    }
                    else
                    {
                        // this function used to accept an int on its own that represented both
                        // width and height, this is to maintain backwards compat, could be removed
                        // but would break existing scripts
                        temp = parseIntParam(name);
                        if (temp != -1)
                        {
                            if (temp > 1024)
                            {
                                temp = 1024;
                            }

                            if (temp < 128)
                            {
                                temp = 128;
                            }

                            width  = temp;
                            height = temp;
                        }
                    }
                    break;
                }
            }

            Bitmap bitmap;

            if (alpha == 256)
            {
                bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb);
            }
            else
            {
                bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            }

            Graphics graph = Graphics.FromImage(bitmap);

            // this is really just to save people filling the
            // background color in their scripts, only do when fully opaque
            if (alpha >= 255)
            {
                graph.FillRectangle(new SolidBrush(bgColour), 0, 0, width, height);
            }

            for (int w = 0; w < bitmap.Width; w++)
            {
                if (alpha <= 255)
                {
                    for (int h = 0; h < bitmap.Height; h++)
                    {
                        bitmap.SetPixel(w, h, Color.FromArgb(alpha, bitmap.GetPixel(w, h)));
                    }
                }
            }

            GDIDraw(data, graph, altDataDelim);

            byte[] imageJ2000 = new byte[0];

            try
            {
                imageJ2000 = OpenJPEG.EncodeFromImage(bitmap, true);
            }
            catch (Exception)
            {
                m_log.Error(
                    "[VECTORRENDERMODULE]: OpenJpeg Encode Failed.  Empty byte data returned!");
            }
            m_textureManager.ReturnData(id, imageJ2000);
        }