Exemplo n.º 1
0
        public static LTexture FilterColor(string res, LColor height, Loon.Core.Graphics.Opengl.LTexture.Format format)
        {
            uint      color = height.GetRGB();
            LImage    tmp   = LImage.CreateImage(res);
            LImage    image = LImage.CreateImage(tmp.GetWidth(), tmp.GetHeight(), true);
            LGraphics g     = image.GetLGraphics();

            g.DrawImage(tmp, 0, 0);
            g.Dispose();
            if (tmp != null)
            {
                tmp.Dispose();
                tmp = null;
            }
            Color[] pixels = image.GetPixels();
            int     size   = pixels.Length;

            for (int i = 0; i < size; i++)
            {
                if (pixels[i].PackedValue == color)
                {
                    pixels[i].PackedValue = LSystem.TRANSPARENT;
                }
            }
            image.SetFormat(format);
            image.SetPixels(pixels, image.GetWidth(), image.GetHeight());
            LTexture texture = image.GetTexture();

            if (image != null)
            {
                image.Dispose();
                image = null;
            }
            return(texture);
        }
Exemplo n.º 2
0
 public LTexture Pack(Loon.Core.Graphics.Opengl.LTexture.Format format)
 {
     if (texture != null && !packing)
     {
         return(texture);
     }
     if (fileName != null)
     {
         texture       = new LTexture(GLLoader.GetTextureData(fileName), format);
         texture.isExt = true;
     }
     else
     {
         LImage image = PackImage();
         if (image == null)
         {
             return(null);
         }
         if (texture != null)
         {
             texture.Destroy();
             texture = null;
         }
         if (colorMask != null)
         {
             Color[] pixels = image.GetPixels();
             int     size   = pixels.Length;
             uint    color  = colorMask.GetRGB();
             for (int i = 0; i < size; i++)
             {
                 if (pixels[i].PackedValue == color)
                 {
                     pixels[i].PackedValue = LSystem.TRANSPARENT;
                 }
             }
             image.SetPixels(pixels, image.GetWidth(), image.GetHeight());
         }
         texture       = new LTexture(GLLoader.GetTextureData(image), format);
         texture.isExt = true;
         if (image != null)
         {
             image.Dispose();
             image = null;
         }
     }
     return(texture);
 }
Exemplo n.º 3
0
        public static LTexture GetRMXPDialog(string fileName, int width,
                                             int height)
        {
            if (lazyImages == null)
            {
                lazyImages = new Dictionary <string, LTexture>(10);
            }
            LImage dialog = LImage.CreateImage(fileName);
            int    w      = dialog.GetWidth();

            Color[] pixels = dialog.GetPixels();
            int     index  = -1;
            int     count  = 0;
            uint    pixel;

            for (int i = 0; i < 5; i++)
            {
                pixel = pixels[(141 + i) + w * 12].PackedValue;

                if (index == -1)
                {
                    index = (int)pixel;
                }
                if (index == pixel)
                {
                    count++;
                }
            }
            if (count == 5)
            {
                return(GetRMXPDialog(dialog, width, height, 16, 5));
            }
            else if (count == 1)
            {
                return(GetRMXPDialog(dialog, width, height, 27, 5));
            }
            else if (count == 2)
            {
                return(GetRMXPDialog(dialog, width, height, 20, 5));
            }
            else
            {
                return(GetRMXPDialog(dialog, width, height, 27, 5));
            }
        }
Exemplo n.º 4
0
        public static LTexture FilterLimitColor(string res, LColor start,
                                                LColor end, Loon.Core.Graphics.Opengl.LTexture.Format format)
        {
            int       sred   = start.R;
            int       sgreen = start.G;
            int       sblue  = start.B;
            int       ered   = end.R;
            int       egreen = end.G;
            int       eblue  = end.B;
            LImage    tmp    = LImage.CreateImage(res);
            LImage    image  = LImage.CreateImage(tmp.GetWidth(), tmp.GetHeight(), true);
            LGraphics g      = image.GetLGraphics();

            g.DrawImage(tmp, 0, 0);
            g.Dispose();
            if (tmp != null)
            {
                tmp.Dispose();
                tmp = null;
            }
            Color[] pixels = image.GetPixels();
            int     size   = pixels.Length;

            for (int i = 0; i < size; i++)
            {
                Color pixel = pixels[i];
                if ((pixel.R >= sred && pixel.G >= sgreen && pixel.B >= sblue) &&
                    (pixel.R <= ered && pixel.G <= egreen && pixel.B <= eblue))
                {
                    pixels[i].PackedValue = LSystem.TRANSPARENT;
                }
            }
            image.SetFormat(format);
            image.SetPixels(pixels, image.GetWidth(), image.GetHeight());
            LTexture texture = image.GetTexture();

            if (image != null)
            {
                image.Dispose();
                image = null;
            }
            return(texture);
        }
Exemplo n.º 5
0
        public PShadowEffect(LImage img, LImage back, int x, int y, int w, int h)
        {
            if (deasilTrans == null || widdershinTrans == null)
            {
                deasilTrans = new Color[max_pixel];
                for (int i = 0; i < max_pixel; i++)
                {
                    deasilTrans[i] = new Color(i, i, i);
                }
                int count = 0;
                widdershinTrans = new Color[max_pixel];
                for (int i = 0; i < max_pixel; i++)
                {
                    widdershinTrans[count++] = deasilTrans[i];
                }
            }
            this.SetLocation(x, y);
            this.width   = w;
            this.height  = h;
            this.visible = true;
            LImage temp = null;

            if (back == null)
            {
                this.scaleWidth      = width / 2;
                this.scaleHeight     = height / 2;
                temp                 = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight);
                this.image           = LImage.CreateImage(scaleWidth, scaleHeight, true);
                this.finalDrawPixels = temp.GetPixels();
                this.nowDrawPixels   = (Color[])CollectionUtils.CopyOf(finalDrawPixels);
                if (temp != null)
                {
                    temp.Dispose();
                    temp = null;
                }
            }
            else
            {
                this.scaleWidth  = width / 2;
                this.scaleHeight = height / 2;
                temp             = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight);
                this.image       = LImage.CreateImage(scaleWidth, scaleHeight, true);
                if (back.GetWidth() == scaleWidth &&
                    back.GetHeight() == scaleHeight)
                {
                    this.finalBackgroundPixels = back.GetPixels();
                    this.backgroundPixels      = (Color[])CollectionUtils
                                                 .CopyOf(finalBackgroundPixels);
                }
                else
                {
                    LImage tmp = GraphicsUtils.GetResize(back, scaleWidth,
                                                         scaleHeight);
                    this.finalBackgroundPixels = tmp.GetPixels();
                    if (tmp != null)
                    {
                        tmp.Dispose();
                        tmp = null;
                    }
                    this.backgroundPixels = (Color[])CollectionUtils
                                            .CopyOf(finalBackgroundPixels);
                }
                this.finalDrawPixels = temp.GetPixels();
                this.nowDrawPixels   = (Color[])CollectionUtils.CopyOf(finalDrawPixels);
            }
            this.SetBlackToWhite(flag);
            if (temp != null)
            {
                temp.Dispose();
                temp = null;
            }
            if (img != null)
            {
                img.Dispose();
                img = null;
            }
            if (back != null)
            {
                back.Dispose();
                back = null;
            }
        }
Exemplo n.º 6
0
        private void Create(LImage image)
        {

            if (image == null)
            {
                return;
            }
            if (buffer != null)
            {
                return;
            }

            fileName = image.GetPath();


            this.isExt = image.isExt;
            this.hasAlpha = image.hasAlpha;
            int srcWidth = image.Width;
            int srcHeight = image.Height;

            if (GLEx.IsPowerOfTwo(srcWidth) && GLEx.IsPowerOfTwo(srcHeight))
            {
                this.width = srcWidth;
                this.height = srcHeight;
                this.texHeight = srcHeight;
                this.texWidth = srcWidth;
                this.buffer = image.GetBitmap();
                if (image.IsAutoDispose())
                {
                    image.Dispose();
                    image = null;
                }
                return;
            }

            int texWidth = GLEx.ToPowerOfTwo(srcWidth);
            int texHeight = GLEx.ToPowerOfTwo(srcHeight);

            this.width = srcWidth;
            this.height = srcHeight;
            this.texHeight = texHeight;
            this.texWidth = texWidth;
            Color[] src = image.GetPixels();
            Color[] dst = new Color[texWidth * texHeight];
            for (int size = 0; size < height; size++)
            {
                Array.Copy(src, size * width
                        , dst, size * texWidth, width);
            }
            if (buffer == null)
            {
                buffer = new Texture2D(GL.device, texWidth, texHeight);
            }
            buffer.SetData<Color>(dst);
            src = null;
            dst = null;
            if (image != null && image.IsAutoDispose())
            {
                image.Dispose();
                image = null;
            }
        }
Exemplo n.º 7
0
        private void Create(LImage image)
        {
            if (image == null)
            {
                return;
            }
            if (buffer != null)
            {
                return;
            }

            fileName = image.GetPath();


            this.isExt    = image.isExt;
            this.hasAlpha = image.hasAlpha;
            int srcWidth  = image.Width;
            int srcHeight = image.Height;

            if (GLEx.IsPowerOfTwo(srcWidth) && GLEx.IsPowerOfTwo(srcHeight))
            {
                this.width     = srcWidth;
                this.height    = srcHeight;
                this.texHeight = srcHeight;
                this.texWidth  = srcWidth;
                this.buffer    = image.GetBitmap();
                if (image.IsAutoDispose())
                {
                    image.Dispose();
                    image = null;
                }
                return;
            }

            int texWidth  = GLEx.ToPowerOfTwo(srcWidth);
            int texHeight = GLEx.ToPowerOfTwo(srcHeight);

            this.width     = srcWidth;
            this.height    = srcHeight;
            this.texHeight = texHeight;
            this.texWidth  = texWidth;
            Color[] src = image.GetPixels();
            Color[] dst = new Color[texWidth * texHeight];
            for (int size = 0; size < height; size++)
            {
                Array.Copy(src, size * width
                           , dst, size * texWidth, width);
            }
            if (buffer == null)
            {
                buffer = new Texture2D(GL.device, texWidth, texHeight);
            }
            buffer.SetData <Color>(dst);
            src = null;
            dst = null;
            if (image != null && image.IsAutoDispose())
            {
                image.Dispose();
                image = null;
            }
        }
Exemplo n.º 8
0
        private void Init(LTexture tex2d, float limit, bool remove, float scale)
        {
            this.isVisible    = true;
            this.expandLimit  = limit;
            this.width        = tex2d.GetWidth();
            this.height       = tex2d.GetHeight();
            this.scaleWidth   = (int)(width * scale);
            this.scaleHeight  = (int)(height * scale);
            this.loopMaxCount = (MathUtils.Max(scaleWidth, scaleHeight) / 2) + 1;
            this.fractions    = new float[(scaleWidth * scaleHeight) * maxElements];
            this.exWidth      = (int)(scaleWidth * expandLimit);
            this.exHeigth     = (int)(scaleHeight * expandLimit);
            LImage image = tex2d.GetImage().ScaledInstance(scaleWidth, scaleHeight);

            Color[] pixels = image.GetPixels();
            if (image != null)
            {
                image.Dispose();
                image = null;
            }
            this.size   = pixels.Length;
            this.pixmap = new LPixmapData(exWidth, exHeigth, true);
            int   no = 0, idx = 0;
            int   length = fractions.Length;
            float angle  = 0;
            float speed  = 0;

            System.Random random = LSystem.random;
            for (int y = 0; y < scaleHeight; y++)
            {
                for (int x = 0; x < scaleWidth; x++)
                {
                    if (idx + maxElements < length)
                    {
                        no    = y * scaleWidth + x;
                        angle = random.Next(360);
                        speed = 10f / random.Next(30);
                        fractions[idx + 0] = x;
                        fractions[idx + 1] = y;
                        fractions[idx + 2] = (MathUtils.Cos(angle * MathUtils.PI
                                                            / 180) * speed);
                        fractions[idx + 3] = (MathUtils.Sin(angle * MathUtils.PI
                                                            / 180) * speed);
                        fractions[idx + 4] = (pixels[no].PackedValue == 0xff00 ? 0xffffff
                                                        : pixels[no].PackedValue);
                        fractions[idx + 5] = x / 6 + random.Next(10);
                        idx += maxElements;
                    }
                }
            }
            if (remove)
            {
                if (tex2d != null)
                {
                    tex2d.Destroy();
                    tex2d = null;
                }
            }
            this.tmp = tex2d;
            this.StartUsePixelThread();
        }