Advertisement
Guest User

Untitled

a guest
Apr 8th, 2018
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <X11/X.h>
  3. #include <X11/Xutil.h>
  4. // Compile with: gcc -shared -O3 -Wall -fPIC -Wl,-soname,prtscn -o prtscn.so prtscn.c -lX11
  5.  
  6. extern "C" void getScreen(const int, const int, const int, const int, unsigned char *);
  7. extern "C" void getScreen(const int xx,const int yy,const int W, const int H, /*out*/ unsigned char * data)
  8. {
  9. Display *display = XOpenDisplay(NULL);
  10. Window root = DefaultRootWindow(display);
  11.  
  12. XImage *image = XGetImage(display,root, xx,yy, W,H, AllPlanes, ZPixmap);
  13.  
  14. unsigned long red_mask = image->red_mask;
  15. unsigned long green_mask = image->green_mask;
  16. unsigned long blue_mask = image->blue_mask;
  17. int x, y;
  18. int ii = 0;
  19. for (y = 0; y < H; y++) {
  20. for (x = 0; x < W; x++) {
  21. unsigned long pixel = XGetPixel(image,x,y);
  22. unsigned char blue = (pixel & blue_mask);
  23. unsigned char green = (pixel & green_mask) >> 8;
  24. unsigned char red = (pixel & red_mask) >> 16;
  25.  
  26. data[ii + 2] = blue;
  27. data[ii + 1] = green;
  28. data[ii + 0] = red;
  29. ii += 3;
  30. }
  31. }
  32. XDestroyImage(image);
  33. XDestroyWindow(display, root);
  34. XCloseDisplay(display);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement