/apps/desktop/libvncserver/draw.c

http://ftk.googlecode.com/ · C · 61 lines · 52 code · 8 blank · 1 comment · 15 complexity · 70460ea64c0fdcc2d08caf5dc83cd93b MD5 · raw file

  1. #include <rfb/rfb.h>
  2. void rfbFillRect(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2,rfbPixel col)
  3. {
  4. int rowstride = s->paddedWidthInBytes, bpp = s->bitsPerPixel>>3;
  5. int i,j;
  6. char* colour=(char*)&col;
  7. if(!rfbEndianTest)
  8. colour += 4-bpp;
  9. for(j=y1;j<y2;j++)
  10. for(i=x1;i<x2;i++)
  11. memcpy(s->frameBuffer+j*rowstride+i*bpp,colour,bpp);
  12. rfbMarkRectAsModified(s,x1,y1,x2,y2);
  13. }
  14. #define SETPIXEL(x,y) \
  15. memcpy(s->frameBuffer+(y)*rowstride+(x)*bpp,colour,bpp)
  16. void rfbDrawPixel(rfbScreenInfoPtr s,int x,int y,rfbPixel col)
  17. {
  18. int rowstride = s->paddedWidthInBytes, bpp = s->bitsPerPixel>>3;
  19. char* colour=(char*)&col;
  20. if(!rfbEndianTest)
  21. colour += 4-bpp;
  22. SETPIXEL(x,y);
  23. rfbMarkRectAsModified(s,x,y,x+1,y+1);
  24. }
  25. void rfbDrawLine(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2,rfbPixel col)
  26. {
  27. int rowstride = s->paddedWidthInBytes, bpp = s->bitsPerPixel>>3;
  28. int i;
  29. char* colour=(char*)&col;
  30. if(!rfbEndianTest)
  31. colour += 4-bpp;
  32. #define SWAPPOINTS { i=x1; x1=x2; x2=i; i=y1; y1=y2; y2=i; }
  33. if(abs(x1-x2)<abs(y1-y2)) {
  34. if(y1>y2)
  35. SWAPPOINTS
  36. for(i=y1;i<=y2;i++)
  37. SETPIXEL(x1+(i-y1)*(x2-x1)/(y2-y1),i);
  38. /* TODO: Maybe make this more intelligently? */
  39. if(x2<x1) { i=x1; x1=x2; x2=i; }
  40. rfbMarkRectAsModified(s,x1,y1,x2+1,y2+1);
  41. } else {
  42. if(x1>x2)
  43. SWAPPOINTS
  44. else if(x1==x2) {
  45. rfbDrawPixel(s,x1,y1,col);
  46. return;
  47. }
  48. for(i=x1;i<=x2;i++)
  49. SETPIXEL(i,y1+(i-x1)*(y2-y1)/(x2-x1));
  50. if(y2<y1) { i=y1; y1=y2; y2=i; }
  51. rfbMarkRectAsModified(s,x1,y1,x2+1,y2+1);
  52. }
  53. }