Esempio n. 1
0
            public void CopyToImage(X11Image image)
            {
                if (image.Height != height || image.Width != width)
                {
                    throw new InvalidOperationException($"Source size ({width} x {height}) does not match image size ({image.Width} x {image.Height}).");
                }

                using (X11Bitmap xBitmap = X11Bitmap.Create(image.Display, image.Visual, width, height))
                {
                    if (pixelFormat == PixelFormat.RGBA_32)
                    {
                        PixelConverter.Convert_RGBA_32BE_To_PARGB_32(dataPtr, stride, xBitmap.ImageData, 4 * width, width, height);
                    }
                    else if (pixelFormat == PixelFormat.RGB_24)
                    {
                        PixelConverter.Convert_RGB_24BE_To_ARGB_32(dataPtr, stride, xBitmap.ImageData, 4 * width, width, height);
                    }
                    else
                    {
                        throw new InvalidOperationException($"Unexpected pixel format: {pixelFormat}.");
                    }

                    var gcValues = new XGCValues();
                    var gc       = LibX11.XCreateGC(image.Display, image.PixmapId, 0, ref gcValues);
                    try
                    {
                        LibX11.XPutImage(image.Display, image.PixmapId, gc, xBitmap.XImage, 0, 0, 0, 0, (uint)width, (uint)height);
                    }
                    finally
                    {
                        LibX11.XFreeGC(image.Display, gc);
                    }
                }
            }
Esempio n. 2
0
        private void WithExtraCanvas(Rectangle rect, Action <X11Canvas> action)
        {
            using (X11Image tempImage = X11Image.Create(display, visual, drawableId, rect.Width, rect.Height))
            {
                var gcValues = new XGCValues();
                gcValues.foreground = ToPArgb(Color.Transparent);
                var gcValueMask = XGCValueMask.GCForeground;
                var gc          = LibX11.XCreateGC(display, drawableId, gcValueMask, ref gcValues);
                try
                {
                    // todo: check int -> uint conversion
                    LibX11.XFillRectangle(display, tempImage.PixmapId, gc, 0, 0, (uint)rect.Width, (uint)rect.Height);
                }
                finally
                {
                    LibX11.XFreeGC(display, gc);
                }

                using (var innerCanvas = X11Canvas.CreateForDrawable(display, screenNum, objectCache, visual, colormap, pictFormatPtr, tempImage.PixmapId))
                {
                    action(innerCanvas);
                    DrawImage(tempImage, rect.X + origin.X, rect.Y + origin.Y);
                }
            }
        }
Esempio n. 3
0
        private void FillEllipseXLib(Color color, int x, int y, int width, int height)
        {
            var gcValues = new XGCValues();

            gcValues.foreground = ToPArgb(color);

            var gcValueMask = XGCValueMask.GCForeground;

            var gc = LibX11.XCreateGC(display, drawableId, gcValueMask, ref gcValues);

            try
            {
                if (clipRectangles != null)
                {
                    LibX11.XSetClipRectangles(display, gc, 0, 0, clipRectangles, clipRectangles.Length, 0);
                }

                LibX11.XDrawArc(display, drawableId, gc, x, y, (uint)width - 1, (uint)height - 1, 0, 360 * 64);
                LibX11.XFillArc(display, drawableId, gc, x, y, (uint)width - 1, (uint)height - 1, 0, 360 * 64);
            }
            finally
            {
                LibX11.XFreeGC(display, gc);
            }
        }
Esempio n. 4
0
        private void DrawPathWithXLibDirectly(Color color, int width, Point[] points)
        {
            var gcValues = new XGCValues();

            gcValues.cap_style  = X11CapStyle.CapRound;
            gcValues.join_style = X11JoinStyle.JoinRound;
            gcValues.foreground = ToPArgb(color);
            gcValues.line_width = width;

            var gcValueMask = XGCValueMask.GCCapStyle | XGCValueMask.GCForeground | XGCValueMask.GCJoinStyle | XGCValueMask.GCLineWidth;

            var gc = LibX11.XCreateGC(display, drawableId, gcValueMask, ref gcValues);

            try
            {
                if (clipRectangles != null)
                {
                    LibX11.XSetClipRectangles(display, gc, 0, 0, clipRectangles, clipRectangles.Length, 0);
                }

                XPoint[] xPoints = new XPoint[points.Length];
                for (int i = 0; i < points.Length; i++)
                {
                    var point = points[i];
                    xPoints[i] = new XPoint(point.X, point.Y);
                }

                LibX11.XDrawLines(display, drawableId, gc, xPoints, xPoints.Length, X11CoordinateMode.CoordModeOrigin);
            }
            finally
            {
                LibX11.XFreeGC(display, gc);
            }
        }
Esempio n. 5
0
        public void CopyFromBitmap(Rectangle imageArea, IntPtr bitmap, int bitmapStride)
        {
            // todo: create separate validation ?
            NativeBitmapSourceParameterValidation.CopyToBitmap(this, imageArea, bitmap, bitmapStride, out _);

            using (X11Bitmap xBitmap = X11Bitmap.Create(Display, Visual, imageArea.Width, imageArea.Height))
            {
                PixelConverter.Convert_ARGB_32_To_PARGB_32(bitmap, bitmapStride, xBitmap.ImageData, imageArea.Width * 4, imageArea.Width, imageArea.Height);

                var gcValues = new XGCValues();
                var gc       = LibX11.XCreateGC(Display, PixmapId, 0, ref gcValues);
                try
                {
                    LibX11.XPutImage(Display, PixmapId, gc, xBitmap.XImage, 0, 0, imageArea.X, imageArea.Y, (uint)imageArea.Width, (uint)imageArea.Height);
                }
                finally
                {
                    LibX11.XFreeGC(Display, gc);
                }
            }
        }
Esempio n. 6
0
 public static extern GC XCreateGC(
     DisplayPtr display,
     Drawable d,
     XGCValueMask valuemask,
     [In] ref XGCValues values
     );