Exemplo n.º 1
0
        private void Button_Click_41(object sender, RoutedEventArgs e)
        {
            if (_currentImage == null)
            {
                return;
            }

            int inputNumber = int.Parse(NumberInput.Text);

            Stopwatch performanceCounter = new Stopwatch();

            performanceCounter.Start();

            CanvasARGB canvas = Get_ProgressOrOrigInput();

            CanvasPixel tmpCanvasPixel = CanvasPixel.CreateBitmpaFromCanvas(canvas);

            ColorReductor cr = new ColorReductor();

            cr.ReduceByMask(tmpCanvasPixel, inputNumber);


            _lastImage = CanvasPixel.CreateBitmpaFromCanvas(tmpCanvasPixel);

            performanceCounter.Stop();

            Helper_SetAppTitle(string.Format("{0,000} s    ", performanceCounter.Elapsed.TotalSeconds));

            ShowImage(false);
        }
Exemplo n.º 2
0
        public unsafe override void Load(string path, int offset)
        {
            Bitmap bp = new Bitmap(path);

            Int32[,] Bits = PaletteProcessor.BitmapToIntArray(bp);

            PaletteProcessor.RoundColor5BitsPerChannel(Bits);
            ColorReductor.ReduceColorsFromBitmap <UnityColorPalette, UnityColorPaletteIndex>(15, Bits);
            var ts = TileProcessor.GetUniqueTilesPositions(Bits, tileSize.Width, tileSize.Height);

            UnityColorPalette[] pals = PaletteProcessor.ExtractPalettesFromBitmap <UnityColorPalette, UnityColorPaletteIndex>(Bits, ts.Item1, tileSize.Width, tileSize.Height, 15);
            var tiles = TileProcessor.GetTiles <UnityColorPalette, IndexedBitmapBufferDisguise>(pals, ts.Item1, ts.Item2, Bits, tileSize.Width, tileSize.Height);

            int w = bp.Width;
            int h = bp.Height;

            foreach (var kvp in tiles)
            {
                BitmapBuffer bf         = BitmapBuffer.CreateInstance(w, h, pals[0].RealObject.BytesPerColor);
                Int32[]      retbp      = new Int32[w * h];
                GCHandle     BitsHandle = GCHandle.Alloc(retbp, GCHandleType.Pinned);
                Bitmap       finishedBP = new Bitmap(w, h, w * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject());
                byte[]       ret        = new byte[retbp.Length * 4];

                foreach (var t in kvp.Value)
                {
                    BitmapBuffer bpb = t.Item4.RealObject.CreateBitmapBuffer(Flip.GetFlip(t.Item2, t.Item3), pals[kvp.Key].RealObject);
                    bf.DrawBitmapBuffer(bpb, t.Item1.X * tileSize.Width, t.Item1.Y * tileSize.Height);
                }
                unsafe
                {
                    fixed(byte *bs = ret)
                    {
                        bf.CopyTo(bs, 0, w - 1, 0, h - 1, 0, 0, 0, 0);
                    }
                }
                Buffer.BlockCopy(ret, 0, retbp, 0, ret.Length);
                finishedBP.Save(Path.GetFileNameWithoutExtension(path) + kvp.Key.Value + ".png",
                                ImageFormat.Png);
            }
        }
Exemplo n.º 3
0
        private void Button_Click_42(object sender, RoutedEventArgs e)
        {
            if (_currentImage == null)
            {
                return;
            }


            int inputNumber = int.Parse(NumberInput.Text);

            Stopwatch performanceCounter = new Stopwatch();

            performanceCounter.Start();

            CanvasARGB canvas = Get_ProgressOrOrigInput();


            CanvasPixel tmpCanvasPixel = CanvasPixel.CreateBitmpaFromCanvas(canvas);

            ColorReductor cr = new ColorReductor();

            cr.Reduce2(tmpCanvasPixel, 4);


            canvas = CanvasPixel.CreateBitmpaFromCanvas(tmpCanvasPixel);

            RegionDetektor rd = new RegionDetektor();
            CanvasPixel    cp = rd.DetectOld(canvas, inputNumber);

            // cp.TransformFromInterleaveRGB();

            _lastImage = CanvasPixel.CreateBitmpaFromCanvas(cp);

            performanceCounter.Stop();

            Helper_SetAppTitle(string.Format("{0,000} s    - regions : {1}", performanceCounter.Elapsed.TotalSeconds, rd.TotalRegions));

            ShowImage(false);
        }