Exemplo n.º 1
0
        public void PixelBufferConstructor()
        {
            tlog.Debug(tag, $"PixelBufferConstructor START");

            var testingTarget = new PixelBuffer(100, 50, PixelFormat.L8);

            Assert.IsNotNull(testingTarget, "Can't create success object PixelBuffer");
            Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should be an instance of PixelBuffer type.");

            testingTarget.Dispose();
            tlog.Debug(tag, $"PixelBufferConstructor END (OK)");
        }
Exemplo n.º 2
0
        public void PixelBufferConstructorByIntPtr()
        {
            tlog.Debug(tag, $"PixelBufferConstructorByIntPtr START");

            using (PixelBuffer pixelBuffer = new PixelBuffer(100, 50, PixelFormat.BGR8888))
            {
                var testingTarget = new PixelBuffer(PixelBuffer.getCPtr(pixelBuffer).Handle, true);
                Assert.IsNotNull(testingTarget, "Can't create success object PixelBuffer");
                Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should be an instance of PixelBuffer type.");

                testingTarget.Dispose();
            }

            tlog.Debug(tag, $"PixelBufferConstructorByIntPtr END (OK)");
        }
Exemplo n.º 3
0
 public void SetPopup(PopupShowEventArgs e)
 {
     if (e.Visible)
     {
         _popupBounds = e.Bounds;
     }
     else
     {
         lock (_syncRoot)
         {
             PopupPixels?.Dispose();
             PopupPixels = null;
         }
     }
 }
Exemplo n.º 4
0
        public void PixelBufferGetBuffer()
        {
            tlog.Debug(tag, $"PixelBufferGetBuffer START");

            var testingTarget = new PixelBuffer(100, 50, PixelFormat.BGR8888);

            Assert.IsNotNull(testingTarget, "Can't create success object PixelData");
            Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should be an instance of PixelData type.");

            var result = testingTarget.GetBuffer();

            Assert.IsNotNull(result);

            testingTarget.Dispose();
            tlog.Debug(tag, $"PixelBufferGetBuffer END (OK)");
        }
Exemplo n.º 5
0
        public void PixelBufferGetHeight()
        {
            tlog.Debug(tag, $"PixelBufferGetHeight START");

            var testingTarget = new PixelBuffer(100, 50, PixelFormat.BGR8888);

            Assert.IsNotNull(testingTarget, "Can't create success object PixelBuffer");
            Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should be an instance of PixelBuffer type.");

            var result = testingTarget.GetHeight();

            Assert.AreEqual(50, result, "Should be equal!");

            testingTarget.Dispose();
            tlog.Debug(tag, $"PixelBufferGetHeight END (OK)");
        }
Exemplo n.º 6
0
        public void PixelBufferRotate()
        {
            tlog.Debug(tag, $"PixelBufferRotate START");

            using (Degree degree = new Degree(30))
            {
                var testingTarget = new PixelBuffer(100, 50, PixelFormat.BGR8888);
                Assert.IsNotNull(testingTarget, "Can't create success object PixelData");
                Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should be an instance of PixelData type.");

                var result = testingTarget.Rotate(degree);
                Assert.IsTrue(result);

                testingTarget.Dispose();
            }

            tlog.Debug(tag, $"PixelBufferRotate END (OK)");
        }
Exemplo n.º 7
0
        public void PixelBufferCrop()
        {
            tlog.Debug(tag, $"PixelBufferCrop START");

            var testingTarget = new PixelBuffer(100, 50, PixelFormat.BGR8888);

            Assert.IsNotNull(testingTarget, "Can't create success object PixelData");
            Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should be an instance of PixelData type.");

            Assert.AreEqual(100, testingTarget.GetWidth(), "Shoule be equal!");
            Assert.AreEqual(50, testingTarget.GetHeight(), "Shoule be equal!");

            testingTarget.Crop(150, 100, 50, 100);
            Assert.AreEqual(50, testingTarget.GetWidth(), "Shoule be equal!");
            Assert.AreEqual(100, testingTarget.GetHeight(), "Shoule be equal!");

            testingTarget.Dispose();
            tlog.Debug(tag, $"PixelBufferCrop END (OK)");
        }
Exemplo n.º 8
0
        public void PixelBufferApplyGaussianBlur()
        {
            tlog.Debug(tag, $"PixelBufferApplyGaussianBlur START");

            var testingTarget = new PixelBuffer(100, 50, PixelFormat.BGR8888);

            Assert.IsNotNull(testingTarget, "Can't create success object PixelData");
            Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should be an instance of PixelData type.");

            try
            {
                testingTarget.ApplyGaussianBlur(1.0f);
            }
            catch (Exception e)
            {
                Assert.Fail("Fail!");
            }

            testingTarget.Dispose();
            tlog.Debug(tag, $"PixelBufferApplyGaussianBlur END (OK)");
        }
Exemplo n.º 9
0
        public void Draw(CefPaintEventArgs e)
        {
            lock (_syncRoot)
            {
                PixelBuffer pixelBuffer;
                if (e.PaintElementType == CefPaintElementType.View)
                {
                    if (ViewPixels == null || ViewPixels.Width != e.Width || ViewPixels.Height != e.Height)
                    {
                        if (ViewPixels != null)
                        {
                            ViewPixels.Dispose();
                        }

                        ViewPixels = new PixelBuffer(e.Width, e.Height);
                    }
                    pixelBuffer = ViewPixels;
                }
                else if (e.PaintElementType == CefPaintElementType.Popup)
                {
                    if (PopupPixels == null || PopupPixels.Width != e.Width || PopupPixels.Height != e.Height)
                    {
                        if (PopupPixels != null)
                        {
                            PopupPixels.Dispose();
                        }
                        PopupPixels = new PixelBuffer(e.Width, e.Height);
                    }
                    pixelBuffer = PopupPixels;
                }
                else
                {
                    return;
                }

                Marshal.Copy(e.Buffer, pixelBuffer.DIB, 0, pixelBuffer.Size);
                pixelBuffer.AddDirtyRects(e.DirtyRects);
            }
        }
Exemplo n.º 10
0
        public void PixelBufferApplyMaskWithCropOrNot()
        {
            tlog.Debug(tag, $"PixelBufferApplyMaskWithCropOrNot START");

            var testingTarget = new PixelBuffer(100, 50, PixelFormat.BGR8888);

            Assert.IsNotNull(testingTarget, "Can't create success object PixelData");
            Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should be an instance of PixelData type.");

            try
            {
                using (PixelBuffer pixelBuffer = new PixelBuffer(50, 100, PixelFormat.A8))
                {
                    testingTarget.ApplyMask(pixelBuffer, 0.5f, true);
                }
            }
            catch (Exception e)
            {
                Assert.Fail("Fail!");
            }

            testingTarget.Dispose();
            tlog.Debug(tag, $"PixelBufferApplyMaskWithCropOrNot END (OK)");
        }
Exemplo n.º 11
0
        public unsafe CefRect Draw(CefPaintEventArgs e)
        {
            float         ppd    = OffscreenGraphics.PixelsPerDip;
            VirtualDevice device = this.Device;

            CefRect[] dirtyRects = e.DirtyRects;
            if (dirtyRects.Length == 0)
            {
                return(new CefRect());
            }

            CefRect r           = dirtyRects[0];
            CefRect invalidRect = new CefRect(r.X, r.Y, r.Width, r.Height);

            for (int i = 1; i < dirtyRects.Length; i++)
            {
                invalidRect.Union(dirtyRects[i]);
            }

            if (device != null)
            {
                invalidRect.Scale(device.Scale * ppd / device.DevicePixelRatio);
            }

            if (e.PaintElementType == CefPaintElementType.Popup)
            {
                invalidRect.Offset(_popupBounds.X, _popupBounds.Y);
            }

            if (invalidRect.IsNullSize)
            {
                return(new CefRect());
            }

            lock (_syncRoot)
            {
                int width  = e.Width;
                int height = e.Height;

                if (device != null)
                {
                    if (e.PaintElementType == CefPaintElementType.View)
                    {
                        width  = (int)(_bounds.Width * device.Scale * ppd);
                        height = (int)(_bounds.Height * device.Scale * ppd);
                    }
                    else if (e.PaintElementType == CefPaintElementType.Popup)
                    {
                        width  = (int)(e.Width / device.DevicePixelRatio * device.Scale * ppd);
                        height = (int)(e.Height / device.DevicePixelRatio * device.Scale * ppd);
                    }
                }

                PixelBuffer pixelBuffer;
                if (e.PaintElementType == CefPaintElementType.View)
                {
                    if (ViewPixels == null || ViewPixels.Width != width || ViewPixels.Height != height)
                    {
                        if (ViewPixels != null)
                        {
                            ViewPixels.Dispose();
                        }

                        ViewPixels = new PixelBuffer(width, height);
                    }
                    pixelBuffer = ViewPixels;
                }
                else if (e.PaintElementType == CefPaintElementType.Popup)
                {
                    if (PopupPixels == null || PopupPixels.Width != width || PopupPixels.Height != height)
                    {
                        if (PopupPixels != null)
                        {
                            PopupPixels.Dispose();
                        }
                        PopupPixels = new PixelBuffer(width, height);
                    }
                    pixelBuffer = PopupPixels;
                }
                else
                {
                    return(new CefRect());
                }

                if (e.Width == pixelBuffer.Width && e.Height == pixelBuffer.Height)
                {
                    long bufferSize = pixelBuffer.Source.ByteCount;
                    Buffer.MemoryCopy(e.Buffer.ToPointer(), pixelBuffer.Source.GetPixels().ToPointer(), bufferSize, bufferSize);
                }
                else
                {
                    using (var canvas = new SKCanvas(pixelBuffer.Source))
                        using (var paint = new SKPaint())
                        {
                            canvas.Clear();
                            paint.FilterQuality = SKFilterQuality.Medium;
                            using (var source = new SKBitmap())
                            {
                                source.InstallPixels(new SKImageInfo(e.Width, e.Height, SKColorType.Bgra8888, SKAlphaType.Opaque), e.Buffer);
                                canvas.DrawBitmap(source, new SKRect(0, 0, pixelBuffer.Width, pixelBuffer.Height), paint);
                            }
                            canvas.Flush();
                        }
                }
            }

            invalidRect.Inflate(2, 2);
            return(invalidRect);
        }
Exemplo n.º 12
0
 public void Dispose()
 {
     temporaryBuffer.Dispose();
 }
Exemplo n.º 13
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            _buffer.Dispose();
        }
Exemplo n.º 14
0
        public CefRect Draw(CefPaintEventArgs e)
        {
            float         ppd    = OffscreenGraphics.PixelsPerDip;
            VirtualDevice device = this.Device;

            CefRect[] dirtyRects = e.DirtyRects;
            if (dirtyRects.Length == 0)
            {
                return(new CefRect());
            }

            CefRect r           = dirtyRects[0];
            CefRect invalidRect = new CefRect(r.X, r.Y, r.Width, r.Height);

            for (int i = 1; i < dirtyRects.Length; i++)
            {
                invalidRect.Union(dirtyRects[i]);
            }

            if (device != null)
            {
                invalidRect.Scale(device.Scale * ppd / device.DevicePixelRatio);
            }

            if (e.PaintElementType == CefPaintElementType.Popup)
            {
                invalidRect.Offset(_popupBounds.X, _popupBounds.Y);
            }

            if (invalidRect.IsNullSize)
            {
                return(new CefRect());
            }

            lock (_syncRoot)
            {
                int width  = e.Width;
                int height = e.Height;

                if (device != null)
                {
                    if (e.PaintElementType == CefPaintElementType.View)
                    {
                        width  = (int)(_bounds.Width * device.Scale * ppd);
                        height = (int)(_bounds.Height * device.Scale * ppd);
                    }
                    else if (e.PaintElementType == CefPaintElementType.Popup)
                    {
                        width  = (int)(e.Width / device.DevicePixelRatio * device.Scale * ppd);
                        height = (int)(e.Height / device.DevicePixelRatio * device.Scale * ppd);
                    }
                }

                PixelBuffer pixelBuffer;
                if (e.PaintElementType == CefPaintElementType.View)
                {
                    if (ViewPixels == null || ViewPixels.Width != width || ViewPixels.Height != height)
                    {
                        if (ViewPixels != null)
                        {
                            ViewPixels.Dispose();
                        }

                        ViewPixels = new PixelBuffer(width, height);
                    }
                    pixelBuffer = ViewPixels;
                }
                else if (e.PaintElementType == CefPaintElementType.Popup)
                {
                    if (PopupPixels == null || PopupPixels.Width != width || PopupPixels.Height != height)
                    {
                        if (PopupPixels != null)
                        {
                            PopupPixels.Dispose();
                        }
                        PopupPixels = new PixelBuffer(width, height);
                    }
                    pixelBuffer = PopupPixels;
                }
                else
                {
                    return(new CefRect());
                }

                using (Graphics g = Graphics.FromImage(pixelBuffer.Source))
                {
                    Color background = this.Background;
                    if (background.A > 0)
                    {
                        using (var brush = new SolidBrush(background))
                        {
                            g.FillRectangle(brush, 0, 0, width, height);
                        }
                    }

                    using (var bitmap = new Bitmap(e.Width, e.Height, e.Width << 2, PixelFormat.Format32bppArgb, e.Buffer))
                    {
                        if (e.Width != width || e.Height != height)
                        {
                            g.CompositingQuality = CompositingQuality.HighSpeed;
                            g.InterpolationMode  = this.InterpolationMode;
                            g.DrawImage(bitmap, 0, 0, width, height);
                        }
                        else
                        {
                            g.DrawImage(bitmap, 0, 0);
                        }
                        g.Flush();
                    }
                }
            }

            invalidRect.Inflate(2, 2);
            return(invalidRect);
        }
Exemplo n.º 15
0
 public void Dispose()
 {
     previousFrame.Dispose();
 }