Пример #1
0
        public static LTexture FilterLimitColor(string res, LColor start,
                                                LColor end)
        {
            int     sred   = start.R;
            int     sgreen = start.G;
            int     sblue  = start.B;
            int     ered   = end.R;
            int     egreen = end.G;
            int     eblue  = end.B;
            LPixmap tmp    = new LPixmap(res);
            LPixmap image  = new LPixmap(tmp.Width, tmp.Height, true);

            image.DrawPixmap(tmp, 0, 0);
            if (tmp != null)
            {
                tmp.Dispose();
                tmp = null;
            }
            Color[] pixels = image.GetData();
            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 = transparent;
                }
            }
            return(image.Texture);
        }
Пример #2
0
 /// <summary>
 /// ����һ��RMVX��ʽ���α�
 /// </summary>
 ///
 /// <returns></returns>
 public static LTexture MakeCursor(int w, int h)
 {
     LPixmap cursor = new LPixmap(w, h, true);
     cursor.SetColor(0, 0, 0, 255);
     cursor.FillRect(0, 0, w, h);
     cursor.SetColor(255, 255, 255, 255);
     cursor.FillRect(1, 1, w - 2, h - 2);
     cursor.SetColor(0, 0, 0, 255);
     cursor.FillRect(4, 4, w - 8, h - 8);
     cursor.SetColor(0, 0, 0, 255);
     cursor.FillRect(w / 4, 0, w / 2, h);
     cursor.SetColor(0, 0, 0, 255);
     cursor.FillRect(0, h / 4, w, h / 2);
     Color[] basePixels = cursor.GetData();
     int length = basePixels.Length;
     Color c = Color.Black;
     for (int i = 0; i < length; i++)
     {
         if (c.Equals(basePixels[i]))
         {
             basePixels[i].PackedValue = LSystem.TRANSPARENT;
         }
     }
     cursor.SetData(basePixels);
     return cursor.Texture;
 }
Пример #3
0
        public static LTexture FilterColor(string res, uint[] colors)
        {
            LPixmap tmp   = new LPixmap(res);
            LPixmap image = new LPixmap(tmp.Width, tmp.Height, true);

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

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < colors.Length; j++)
                {
                    if (pixels[i].PackedValue == colors[j])
                    {
                        pixels[i].PackedValue = transparent;
                    }
                }
            }
            image.SetData(pixels);
            return(image.Texture);
        }
Пример #4
0
        /// <summary>
        /// 绘制一个RMVX样式的游标
        /// </summary>
        ///
        /// <returns></returns>
        public static LTexture MakeCursor(int w, int h)
        {
            LPixmap cursor = new LPixmap(w, h, true);

            cursor.SetColor(0, 0, 0, 255);
            cursor.FillRect(0, 0, w, h);
            cursor.SetColor(255, 255, 255, 255);
            cursor.FillRect(1, 1, w - 2, h - 2);
            cursor.SetColor(0, 0, 0, 255);
            cursor.FillRect(4, 4, w - 8, h - 8);
            cursor.SetColor(0, 0, 0, 255);
            cursor.FillRect(w / 4, 0, w / 2, h);
            cursor.SetColor(0, 0, 0, 255);
            cursor.FillRect(0, h / 4, w, h / 2);
            Color[] basePixels = cursor.GetData();
            int     length     = basePixels.Length;
            Color   c          = Color.Black;

            for (int i = 0; i < length; i++)
            {
                if (c.Equals(basePixels[i]))
                {
                    basePixels[i].PackedValue = LSystem.TRANSPARENT;
                }
            }
            cursor.SetData(basePixels);
            return(cursor.Texture);
        }
Пример #5
0
 private void init(int width, int height, bool alpha)
 {
     this.width       = width;
     this.height      = height;
     this.hasAlpha    = alpha;
     this.buffer      = new LPixmap(width, height, alpha);
     this.pixels      = buffer.GetData();
     this.finalPixels = (Color[])CollectionUtils.CopyOf(pixels);
 }
Пример #6
0
        public static LTexture GetRMXPDialog(string fileName, int width,
                                             int height)
        {
            if (lazyImages == null)
            {
                lazyImages = new Dictionary <string, LTexture>(10);
            }
            LPixmap dialog = new LPixmap(fileName);
            int     w      = dialog.Width;

            Color[] pixels = dialog.GetData();
            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));
            }
        }
Пример #7
0
        public static LTexture GetRMXPDialog(string fileName, int width,
                int height)
        {
            if (lazyImages == null)
            {
                lazyImages = new Dictionary<string, LTexture>(10);
            }
            LPixmap dialog = new LPixmap(fileName);
            int w = dialog.Width;
            Color[] pixels = dialog.GetData();
            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);
            }
        }
Пример #8
0
 public LTexture Pack()
 {
     if (texture != null && !packing)
     {
         return(texture);
     }
     if (fileName != null)
     {
         texture = new LTexture(fileName);
     }
     else
     {
         LPixmap image = PackImage();
         if (image == null)
         {
             return(null);
         }
         if (texture != null)
         {
             texture.Destroy();
             texture = null;
         }
         if (colorMask != null)
         {
             Color[] pixels = image.GetData();
             int     size   = pixels.Length;
             uint    color  = colorMask.PackedValue;
             for (int i = 0; i < size; i++)
             {
                 if (pixels[i].PackedValue == color)
                 {
                     pixels[i].PackedValue = LSystem.TRANSPARENT;
                 }
             }
             image.SetData(pixels);
         }
         texture = image.Texture;
     }
     return(texture);
 }
Пример #9
0
        public PShadowEffect(LPixmap img, LPixmap 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;
            LPixmap temp = null;

            if (back == null)
            {
                this.scaleWidth      = width / 2;
                this.scaleHeight     = height / 2;
                temp                 = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight);
                this.image           = new LPixmap(scaleWidth, scaleHeight, true);
                this.finalDrawPixels = temp.GetData();
                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       = new LPixmap(scaleWidth, scaleHeight, true);
                if (back.GetWidth() == scaleWidth &&
                    back.GetHeight() == scaleHeight)
                {
                    this.finalBackgroundPixels = back.GetData();
                    this.backgroundPixels      = (Color[])CollectionUtils
                                                 .CopyOf(finalBackgroundPixels);
                }
                else
                {
                    LPixmap tmp = GraphicsUtils.GetResize(back, scaleWidth,
                                                          scaleHeight);
                    this.finalBackgroundPixels = tmp.GetData();
                    if (tmp != null)
                    {
                        tmp.Dispose();
                        tmp = null;
                    }
                    this.backgroundPixels = (Color[])CollectionUtils
                                            .CopyOf(finalBackgroundPixels);
                }
                this.finalDrawPixels = temp.GetData();
                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;
            }
        }
Пример #10
0
 public static LTexture FilterLimitColor(string res, LColor start,
         LColor end)
 {
     int sred = start.R;
     int sgreen = start.G;
     int sblue = start.B;
     int ered = end.R;
     int egreen = end.G;
     int eblue = end.B;
     LPixmap tmp = new LPixmap(res);
     LPixmap image = new LPixmap(tmp.Width, tmp.Height, true);
     image.DrawPixmap(tmp, 0, 0);
     if (tmp != null)
     {
         tmp.Dispose();
         tmp = null;
     }
     Color[] pixels = image.GetData();
     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 = transparent;
         }
     }
     return image.Texture;
 }
Пример #11
0
 public static LTexture FilterColor(string res, uint[] colors)
 {
     LPixmap tmp = new LPixmap(res);
     LPixmap image = new LPixmap(tmp.Width, tmp.Height, true);
     image.DrawPixmap(tmp, 0, 0);
     if (tmp != null)
     {
         tmp.Dispose();
         tmp = null;
     }
     Color[] pixels = image.GetData();
     int size = pixels.Length;
     for (int i = 0; i < size; i++)
     {
         for (int j = 0; j < colors.Length; j++)
         {
             if (pixels[i].PackedValue == colors[j])
             {
                 pixels[i].PackedValue = transparent;
             }
         }
     }
     image.SetData(pixels);
     return image.Texture;
 }
Пример #12
0
 public LPixmapData(LPixmap pix)
     : this(pix.GetData(), pix.GetWidth(), pix.GetHeight())
 {
 }
Пример #13
0
 public LPixmapData(LPixmap pix)
     : this(pix.GetData(), pix.GetWidth(), pix.GetHeight())
 {
 }
Пример #14
0
 private void init(int width, int height, bool alpha)
 {
     this.width = width;
     this.height = height;
     this.hasAlpha = alpha;
     this.buffer = new LPixmap(width, height, alpha);
     this.pixels = buffer.GetData();
     this.finalPixels = (Color[])CollectionUtils.CopyOf(pixels);
 }
Пример #15
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);
            LPixmap image = tex2d.GetImage().ScaledInstance(scaleWidth, scaleHeight);

            Color[] pixels = image.GetData();
            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();
        }
Пример #16
0
 public PShadowEffect(LPixmap img, LPixmap 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;
     LPixmap temp = null;
     if (back == null)
     {
         this.scaleWidth = width / 2;
         this.scaleHeight = height / 2;
         temp = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight);
         this.image = new LPixmap(scaleWidth, scaleHeight, true);
         this.finalDrawPixels = temp.GetData();
         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 = new LPixmap(scaleWidth, scaleHeight, true);
         if (back.GetWidth() == scaleWidth
                 && back.GetHeight() == scaleHeight)
         {
             this.finalBackgroundPixels = back.GetData();
             this.backgroundPixels = (Color[])CollectionUtils
                     .CopyOf(finalBackgroundPixels);
         }
         else
         {
             LPixmap tmp = GraphicsUtils.GetResize(back, scaleWidth,
                     scaleHeight);
             this.finalBackgroundPixels = tmp.GetData();
             if (tmp != null)
             {
                 tmp.Dispose();
                 tmp = null;
             }
             this.backgroundPixels = (Color[])CollectionUtils
                     .CopyOf(finalBackgroundPixels);
         }
         this.finalDrawPixels = temp.GetData();
         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;
     }
 }