Exemple #1
0
        private void GeneratePreview()
        {
            if (string.IsNullOrEmpty(txbImage.Text))
            {
                return;
            }

            Bitmap vBmp = new Bitmap(txbImage.Text);

            picPreviewA.Image = vBmp;

            Bitmap vBmpResized = DrawingLogic.CopyAndResize(vBmp, Tile.WIDTH_PX * this.CreateWidth, Tile.HEIGHT_PX * this.CreateHeight);

            picPreviewB.Image = vBmpResized;

            Bitmap vBmpColorized = null;

            switch (cbxMethod.SelectedItem)
            {
            case METHOD_NEAREST:
                vBmpColorized = DrawingLogic.MapBitmapColorsToPalette((Bitmap)vBmpResized.Clone(), Palette.DEFAULT_PALETTE);
                break;

            case METHOD_FLOYDSTEINBERG:
                vBmpColorized = FloydSteinbergDither.Process((Bitmap)vBmpResized.Clone(), Palette.DEFAULT_PALETTE.mColors);
                break;
            }

            picPreviewC.Image = vBmpColorized;
        }
Exemple #2
0
        private void btnTilizator_Click(object sender, EventArgs e)
        {
            using (FrmTilizator vFrm = new FrmTilizator()) {
                if (vFrm.ShowDialog(this) == DialogResult.OK)
                {
                    //Start: create target bitmap with right size
                    Bitmap vTarget = DrawingLogic.CopyAndResize(vFrm.CreateBmp, Tile.WIDTH_PX * vFrm.CreateWidth, Tile.HEIGHT_PX * vFrm.CreateHeight);

                    //map colors
                    Palette vPal = Palette.DEFAULT_PALETTE;

                    switch (vFrm.ColorMethod)
                    {
                    case FrmTilizator.METHOD_NEAREST:
                        //Updates the bitmap in parameter
                        vTarget = DrawingLogic.MapBitmapColorsToPalette(vTarget, vPal);
                        break;

                    case FrmTilizator.METHOD_FLOYDSTEINBERG:
                        vTarget = FloydSteinbergDither.Process(vTarget, vPal.mColors);
                        break;
                    }

                    //tilization
                    int vTileNewCount = 0, vTileReusedCount = 0;
                    for (int x = 0; x < vFrm.CreateWidth; x++)
                    {
                        for (int y = 0; y < vFrm.CreateHeight; y++)
                        {
                            Rectangle vTileRect = new Rectangle(x * Tile.WIDTH_PX, y * Tile.HEIGHT_PX, Tile.WIDTH_PX, Tile.HEIGHT_PX);
                            Bitmap    vTileBmp  = (Bitmap)vTarget.Clone(vTileRect, vTarget.PixelFormat);

                            //make new tile and add/get similar from library
                            Tile vT = new Tile(vTileBmp, vPal);
                            bool vTileAlreadyExisted = false;
                            vT = this.mCurrentMap.ParentProject.mLibraries[0].AddTileWithoutDuplicate(vT, out vTileAlreadyExisted);

                            if (!vTileAlreadyExisted)
                            {
                                vTileNewCount++;
                            }
                            else
                            {
                                vTileReusedCount++;
                            }

                            //apply the tile to the map
                            this.mCurrentMap.SetTile(vT, vFrm.CreateLeft + x, vFrm.CreateTop + y);
                        }
                    }

                    //refresh
                    panMap.Invalidate();

                    ((FrmMain)this.FindForm()).SetStatus("Tilization: generated " + vTileNewCount + " tiles, reused " + vTileReusedCount + " tiles.");
                }
            }
        }
Exemple #3
0
        public void FloydSteinberg2()
        {
            var dt = new FloydSteinbergDither();

            const int WIDTH  = 100;
            const int HEIGHT = 100;

            var b1 = new Bitmap(WIDTH, HEIGHT, PixelFormat.Format32bppArgb);

            b1.SetPixel(50, 50, Color.FromArgb(255, 127, 127, 127));
            b1.SetPixel(50, 51, Color.FromArgb(255, 127, 127, 127));
            b1.SetPixel(50, 52, Color.FromArgb(255, 127, 127, 127));
            b1.SetPixel(50, 53, Color.FromArgb(255, 127, 127, 127));

            var b2 = dt.Process(b1);

            for (int x = 0; x < WIDTH; x++)
            {
                for (int y = 0; y < HEIGHT; y++)
                {
                    Color col = b2.GetPixel(x, y);

                    if (col.R != 0)
                    {
                        col.R.Should().Be(255);
                        col.G.Should().Be(255);
                        col.B.Should().Be(255);

                        x.Should().Be(50);
                        y.Should().BeOneOf(53, 51);
                    }
                    else
                    {
                        col.R.Should().Be(0);
                        col.G.Should().Be(0);
                        col.B.Should().Be(0);
                    }
                }
            }
        }
Exemple #4
0
        public void FloydSteinberg1()
        {
            var dt = new FloydSteinbergDither();

            const int XSIZE = 100;
            const int YSIZE = 100;

            var b1 = new Bitmap(XSIZE, YSIZE);

            b1.SetPixel(50, 50, Color.FromArgb(255, 255, 255, 255));

            var b2 = dt.Process(b1);

            for (int x = 0; x < XSIZE; x++)
            {
                for (int y = 0; y < YSIZE; y++)
                {
                    Color col = b2.GetPixel(x, y);

                    if (col.R != 0)
                    {
                        col.R.Should().Be(255);
                        col.G.Should().Be(255);
                        col.B.Should().Be(255);

                        x.Should().Be(50);
                        y.Should().Be(50);
                    }
                    else
                    {
                        col.R.Should().Be(0);
                        col.G.Should().Be(0);
                        col.B.Should().Be(0);
                    }
                }
            }
        }