예제 #1
0
    private ConsoleBitmapDiffFrame PrepareDiffFrame(ConsoleBitmapRawFrame previous, ConsoleBitmap bitmap)
    {
        ConsoleBitmapDiffFrame diff = new ConsoleBitmapDiffFrame();

        diff.Diffs = new List <ConsoleBitmapPixelDiff>();
        int changes = 0;

        for (int y = 0; y < GetEffectiveHeight(bitmap); y++)
        {
            for (int x = 0; x < GetEffectiveWidth(bitmap); x++)
            {
                var pixel            = bitmap.GetPixel(GetEffectiveLeft + x, GetEffectiveTop + y);
                var hasPreviousPixel = previous.Pixels.Length == GetEffectiveWidth(bitmap) && previous.Pixels[0].Length == GetEffectiveHeight(bitmap);
                var previousPixel    = hasPreviousPixel ? previous.Pixels[x][y] : default(ConsoleCharacter);

                if (hasPreviousPixel == false || (pixel.EqualsIn(previousPixel) == false))
                {
                    changes++;
                    diff.Diffs.Add(new ConsoleBitmapPixelDiff()
                    {
                        X     = x,
                        Y     = y,
                        Value = pixel
                    });
                }
            }
        }

        return(diff);
    }
예제 #2
0
            private void Timer_Tick(object sender, EventArgs e)
            {
                offScreenGraphics.FillRectangle(Brushes.Black, new RectangleF(0, 0, offsreenBuffer.Width, offsreenBuffer.Height));
                for (int y = 0; y < buffer.Height - 1; y++)
                {
                    for (int x = 0; x < buffer.Width; x++)
                    {
                        var pixel          = buffer.GetPixel(x, y);
                        ConsoleCharacter c = pixel.Value.HasValue ? pixel.Value.Value : new ConsoleCharacter(' ', this.ForegroundColor, this.BackgroundColor);

                        var   fg   = (Color)typeof(Color).GetProperty(c.ForegroundColor.ToString(), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null);
                        var   bg   = (Color)typeof(Color).GetProperty(c.BackgroundColor.ToString(), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null);
                        float imgX = x * charSize.Width;
                        float imgY = y * charSize.Height;
                        offScreenGraphics.FillRectangle(new SolidBrush(bg), imgX, imgY, charSize.Width, charSize.Height);
                        offScreenGraphics.DrawString(c.ToString(), Font, new SolidBrush(fg), new PointF(imgX, imgY));
                    }
                }

                var tempImg      = onScreenBuffer;
                var tempGraphics = onScreenGraphics;

                onScreenBuffer   = offsreenBuffer;
                onScreenGraphics = offScreenGraphics;

                offsreenBuffer    = tempImg;
                offScreenGraphics = tempGraphics;
                this.Invalidate();
            }
예제 #3
0
    private ConsoleBitmapRawFrame GetRawFrame(ConsoleBitmap bitmap)
    {
        var rawFrame = new ConsoleBitmapRawFrame();

        rawFrame.Pixels = new ConsoleCharacter[GetEffectiveWidth(bitmap)][];
        for (int x = 0; x < GetEffectiveWidth(bitmap); x++)
        {
            rawFrame.Pixels[x] = new ConsoleCharacter[GetEffectiveHeight(bitmap)];
            for (int y = 0; y < GetEffectiveHeight(bitmap); y++)
            {
                var pixel = bitmap.GetPixel(GetEffectiveLeft + x, GetEffectiveTop + y);
                rawFrame.Pixels[x][y] = pixel;
            }
        }
        return(rawFrame);
    }
예제 #4
0
        public void Filter(ConsoleBitmap bitmap)
        {
            for (var x = 0; x < bitmap.Width; x++)
            {
                for (var y = 0; y < bitmap.Height; y++)
                {
                    var pixel = bitmap.GetPixel(x, y);
                    if (pixel.Value.HasValue)
                    {
                        if (pixel.Value.Value.BackgroundColor != pixel.Value.Value.ForegroundColor && pixel.Value.Value.BackgroundColor == RGB.Black && pixel.Value.Value != ' ')
                        {
                            pixel.Value = new ConsoleCharacter(pixel.Value.Value.Value, Color);
                        }

                        if (pixel.Value.Value.BackgroundColor != RGB.Black)
                        {
                            pixel.Value = new ConsoleCharacter(pixel.Value.Value.Value, pixel.Value.Value.ForegroundColor, Color);
                        }
                    }
                }
            }
        }