PageRenderTime 263ms CodeModel.GetById 151ms app.highlight 7ms RepoModel.GetById 104ms app.codeStats 0ms

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