Exemplo n.º 1
0
        } // End Sub PerformanceTest

        public static void TestX11_Simple()
        {
            System.IntPtr display = LibX11Functions.XOpenDisplay(System.IntPtr.Zero);

            int defaultScreen = LibX11Functions.XDefaultScreen(display);

            System.UIntPtr window = LibX11Functions.XRootWindow(display, defaultScreen);

            int screen_width  = LibX11Functions.DisplayWidth(display, defaultScreen);
            int screen_height = LibX11Functions.DisplayHeight(display, defaultScreen);

            XWindowAttributes xa = new XWindowAttributes();

            LibX11Functions.XGetWindowAttributes(display, window, ref xa);
            System.Console.WriteLine(xa.width);
            System.Console.WriteLine(xa.height);

            int AllPlanes = ~0;

            System.UIntPtr AllPlanes2 = new System.UIntPtr((uint)AllPlanes);

            /*
             * XImage* img = LibX11Functions.XGetImage2(display, window, 0, 0, (uint) xa.width, (uint)xa.height
             *  , AllPlanes2, LinScreen.ZPixmap);
             */


            // System.IntPtr image = LibX11Functions.XGetImage(display, window, 0, 0, (uint) xa.width, (uint)xa.height
            //     , AllPlanes2, LinScreen.ZPixmap);

            SafeX11.SlowScreenshot(display, window, 0, 0, (uint)xa.width, (uint)xa.height
                                   , AllPlanes2, LinScreen.ZPixmap, true);


            // XImage img = System.Runtime.InteropServices.Marshal.PtrToStructure<XImage>(image);


            // System.Console.WriteLine(img.bitmap_bit_order);
            // System.Console.WriteLine(img.bits_per_pixel);
            // System.Console.WriteLine(img.width);
            // System.Console.WriteLine(img.height);
            // System.Console.WriteLine(img.data);

            // // // // // //

            // System.Console.WriteLine(img->bitmap_bit_order);
            // System.Console.WriteLine(img->width);
            // System.Console.WriteLine(img->height);
            // System.Console.WriteLine(img->data);

            // rtaNetworking.Linux.tt.foo();

            // LibX11Functions.XDestroyImage2(img);


            LibX11Functions.XCloseDisplay(display);
        }
Exemplo n.º 2
0
        public static System.Drawing.Size GetXorgScreenSize()
        {
            int screen_width  = 0;
            int screen_height = 0;

            System.IntPtr display = LibX11Functions.XOpenDisplay(System.IntPtr.Zero);

            if (display == System.IntPtr.Zero)
            {
                System.Console.WriteLine("Error: Failed on XOpenDisplay.\n");
            }
            else
            {
                int defaultScreen = LibX11Functions.XDefaultScreen(display);

                screen_width  = LibX11Functions.DisplayWidth(display, defaultScreen);
                screen_height = LibX11Functions.DisplayHeight(display, defaultScreen);

                LibX11Functions.XCloseDisplay(display);
                System.Console.WriteLine("Width: " + screen_width.ToString() + " Height: " + screen_height.ToString());
            } // End Else (display == System.IntPtr.Zero)

            return(new System.Drawing.Size(screen_width, screen_height));
        } // End Function GetXorgScreen
Exemplo n.º 3
0
        public static System.Drawing.Bitmap CopyFromScreenX11(int sourceX, int sourceY,
                                                              System.Drawing.Size blockRegionSize
                                                              , System.Drawing.CopyPixelOperation copyPixelOperation)
        {
            System.UIntPtr window;
            System.IntPtr  image, defvisual, vPtr;
            int            AllPlanes = ~0, nitems = 0, pixel;

            System.UIntPtr AllPlanes2 = new System.UIntPtr((uint)AllPlanes);


            if (copyPixelOperation != System.Drawing.CopyPixelOperation.SourceCopy)
            {
                throw new System.NotImplementedException("Operation not implemented under X11");
            }

            if (Gdip.Display == System.IntPtr.Zero)
            {
                Gdip.Display = LibX11Functions.XOpenDisplay(System.IntPtr.Zero);
            }

            window    = LibX11Functions.XRootWindow(Gdip.Display, 0);
            defvisual = LibX11Functions.XDefaultVisual(Gdip.Display, 0);
            XVisualInfo visual = new XVisualInfo();

            // Get XVisualInfo for this visual
            visual.visualid = LibX11Functions.XVisualIDFromVisual(defvisual);
            vPtr            = LibX11Functions.XGetVisualInfo(Gdip.Display, VisualIDMask, ref visual, ref nitems);
            visual          = (XVisualInfo)System.Runtime.InteropServices.Marshal.PtrToStructure(vPtr, typeof(XVisualInfo));
            image           = LibX11Functions.XGetImage(Gdip.Display, window, sourceX, sourceY, (uint)blockRegionSize.Width,
                                                        (uint)blockRegionSize.Height, AllPlanes2, ZPixmap);
            if (image == System.IntPtr.Zero)
            {
                string s = string.Format("XGetImage returned NULL when asked to for a {0}x{1} region block",
                                         blockRegionSize.Width, blockRegionSize.Height);
                throw new System.InvalidOperationException(s);
            }

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(blockRegionSize.Width, blockRegionSize.Height);
            int red, blue, green;
            int red_mask = (int)visual.red_mask;
            int blue_mask  = (int)visual.blue_mask;
            int green_mask = (int)visual.green_mask;

            for (int y = 0; y < blockRegionSize.Height; y++)
            {
                for (int x = 0; x < blockRegionSize.Width; x++)
                {
                    pixel = LibX11Functions.XGetPixel(image, x, y);

                    switch (visual.depth)
                    {
                    case 16:     /* 16bbp pixel transformation */
                        red   = (int)((pixel & red_mask) >> 8) & 0xff;
                        green = (int)(((pixel & green_mask) >> 3)) & 0xff;
                        blue  = (int)((pixel & blue_mask) << 3) & 0xff;
                        break;

                    case 24:
                    case 32:
                        // int a = (int)((pixel ) >> 24) & 0xff;
                        red   = (int)((pixel & red_mask) >> 16) & 0xff;
                        green = (int)(((pixel & green_mask) >> 8)) & 0xff;
                        blue  = (int)((pixel & blue_mask)) & 0xff;
                        break;

                    default:
                        string text = string.Format("{0}bbp depth not supported.", visual.depth);
                        throw new System.NotImplementedException(text);
                    }

                    bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(255, red, green, blue));
                }
            }

            // DrawImage(bmp, destinationX, destinationY);
            // bmp.Dispose();
            LibX11Functions.XDestroyImage(image);
            LibX11Functions.XFree(vPtr);

            return(bmp);
        }