Advertisement
Guest User

Clemens Eisserer

a guest
Oct 18th, 2008
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <X11/Xlib.h>
  3. #include <X11/extensions/Xrender.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <stdlib.h>
  7. #include <sys/time.h>
  8.  
  9. Display *display;
  10. int screen;
  11. Window root, window;
  12. XEvent event;
  13.  
  14. Pixmap sourcePixmap;
  15. Picture sourcePicture;
  16.  
  17. Pixmap maskPixmap;
  18. Picture maskPicture;
  19.  
  20. /*Creates source picture*/
  21. Picture createSourcePicture()
  22. {
  23.     XRenderPictFormat *fmt = XRenderFindStandardFormat(display, PictStandardRGB24);
  24.     sourcePixmap = XCreatePixmap(display, window, 100, 100, 24);
  25.     XRenderPictureAttributes pict_attr;
  26.     Picture picture = XRenderCreatePicture(display, sourcePixmap, fmt, 0, &pict_attr);
  27.  
  28.         XRenderColor yellow={.red=0xffff, .green=0xffff, .blue=0, .alpha=0xffff};
  29.         XRenderFillRectangle (display, PictOpSrc, picture, &yellow, 0, 0, 1000, 1000);
  30.      
  31.     return picture;
  32. }
  33.  
  34. /*Creates mask picture*/
  35. Picture createMaskPicture()
  36. {
  37.     XRenderPictFormat *fmt = XRenderFindStandardFormat(display, PictStandardA8);
  38.     maskPixmap = XCreatePixmap(display, window, 1, 1, 8);
  39.     XRenderPictureAttributes pict_attr;
  40.     Picture picture = XRenderCreatePicture(display, maskPixmap, fmt, 0, &pict_attr);
  41.  
  42.         XRenderColor yellow={.red=0xffff, .green=0xffff, .blue=0, .alpha=0xffff};
  43.         XRenderFillRectangle (display, PictOpSrc, picture, &yellow, 0, 0, 1000, 1000);
  44.      
  45.     return picture;
  46. }
  47.  
  48. int main(int argc, char *argv[])
  49. {
  50.         /*Bosing initialization stuff*/
  51.     display=XOpenDisplay(NULL);
  52.    
  53.     int render_event_base, render_error_base;
  54.     int render_present=XRenderQueryExtension(display, &render_event_base, &render_error_base);
  55.     if (!render_present) {
  56.         fprintf(stderr, "RENDER extension missing!\n");
  57.         abort();
  58.     }
  59.    
  60.     XRenderPictFormat *fmt=XRenderFindStandardFormat(display, PictStandardRGB24);
  61.     screen=DefaultScreen(display);
  62.     root=DefaultRootWindow(display);
  63.    
  64.     window = XCreateWindow(display, root, 0, 0, 640, 480, 0,
  65.         DefaultDepth(display, screen), InputOutput,
  66.         DefaultVisual(display, screen),
  67.         0, NULL);
  68.     XRenderPictureAttributes pict_attr;
  69.    
  70.     pict_attr.poly_edge=PolyEdgeSmooth;
  71.     pict_attr.poly_mode=PolyModeImprecise;
  72.     Picture picture=XRenderCreatePicture(display, window, fmt, CPPolyEdge|CPPolyMode, &pict_attr);
  73.    
  74.     XSelectInput(display, window, KeyPressMask|KeyReleaseMask|ExposureMask
  75.         |ButtonPressMask|StructureNotifyMask);
  76.    
  77.    
  78.     /* now make the window visible */
  79.     XMapWindow(display, window);
  80.    
  81.     XRenderColor color_white = {.red=0xffff, .green=0xffff, .blue=0xffff, .alpha=0xffff};
  82.    
  83.         sourcePicture = createSourcePicture();
  84.         maskPicture = createMaskPicture();
  85.  
  86.         XRenderSetPictureFilter(display, sourcePicture, "fast", NULL, 0);
  87.         XRenderSetPictureFilter(display, maskPicture, "fast", NULL, 0);
  88.  
  89.         XTransform xf;
  90.         xf.matrix[0][0] = XDoubleToFixed(0.438791280945186);
  91.         xf.matrix[0][1] = XDoubleToFixed(0.239712769302102);
  92.         xf.matrix[0][2] = XDoubleToFixed(-13.755117572194017);
  93.         xf.matrix[1][0] = XDoubleToFixed(-0.239712769302102);
  94.         xf.matrix[1][1] = XDoubleToFixed(0.438791280945186);
  95.         xf.matrix[1][2] = XDoubleToFixed(7.343992411903851);
  96.         xf.matrix[2][0] = 0;
  97.         xf.matrix[2][1] = 0;
  98.         xf.matrix[2][2] = 1<<16;
  99.         XRenderSetPictureTransform (display, sourcePicture, &xf);
  100.  
  101.  
  102.         xf.matrix[0][0] = XDoubleToFixed(0.013712227529537);
  103.         xf.matrix[0][1] = XDoubleToFixed(0.007491024040691);
  104.         xf.matrix[0][2] = XDoubleToFixed(-0.429847424131063);
  105.         xf.matrix[1][0] = XDoubleToFixed(-0.007491024040691);
  106.         xf.matrix[1][1] = XDoubleToFixed(0.013712227529537);
  107.         xf.matrix[1][2] = XDoubleToFixed(0.229499762871995);
  108.         xf.matrix[2][0] = 0;
  109.         xf.matrix[2][1] = 0;
  110.         xf.matrix[2][2] = 1<<16;
  111.         XRenderSetPictureTransform (display, maskPicture, &xf);
  112.  
  113.     while(1) {
  114.         XNextEvent(display, &event);
  115.        
  116.         switch(event.type) {
  117.             case Expose:
  118. {
  119.                 XRenderFillRectangle(display, PictOpOver,
  120.                     picture, &color_white, 0, 0, 1000, 1000);
  121.  
  122.                                  XRenderComposite (display, PictOpOver, sourcePicture, maskPicture, picture, 0, 0, 0, 0, 0, 0, 500, 500);
  123.  
  124.                 break;
  125.             case DestroyNotify:
  126.                 return 0;
  127.         }
  128.     }
  129.    
  130. }
  131.     return 0;
  132. }
  133.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement