LibVNCServer/LibVNCClient
pnmshow24.c
Go to the documentation of this file.
1 
9 #include <stdio.h>
10 #include <rfb/rfb.h>
11 #include <rfb/keysym.h>
12 
13 #ifndef LIBVNCSERVER_ALLOW24BPP
14 int main() {
15  printf("I need the ALLOW24BPP LibVNCServer flag to work\n");
16  exit(1);
17 }
18 #else
19 
20 static void HandleKey(rfbBool down,rfbKeySym key,rfbClientPtr cl)
21 {
22  if(down && (key==XK_Escape || key=='q' || key=='Q'))
23  rfbCloseClient(cl);
24 }
25 
26 int main(int argc,char** argv)
27 {
28  FILE* in=stdin;
29  int j,width,height,paddedWidth;
30  char buffer[1024];
31  rfbScreenInfoPtr rfbScreen;
32 
33  if(argc>1) {
34  in=fopen(argv[1],"rb");
35  if(!in) {
36  printf("Couldn't find file %s.\n",argv[1]);
37  exit(1);
38  }
39  }
40 
41  fgets(buffer,1024,in);
42  if(strncmp(buffer,"P6",2)) {
43  printf("Not a ppm.\n");
44  exit(2);
45  }
46 
47  /* skip comments */
48  do {
49  fgets(buffer,1024,in);
50  } while(buffer[0]=='#');
51 
52  /* get width & height */
53  sscanf(buffer,"%d %d",&width,&height);
54  rfbLog("Got width %d and height %d.\n",width,height);
55  fgets(buffer,1024,in);
56 
57  /* vncviewers have problems with widths which are no multiple of 4. */
58  paddedWidth = width;
59 
60  /* if your vncviewer doesn't have problems with a width
61  which is not a multiple of 4, you can comment this. */
62  if(width&3)
63  paddedWidth+=4-(width&3);
64 
65  /* initialize data for vnc server */
66  rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,3);
67  if(!rfbScreen)
68  return 1;
69  if(argc>1)
70  rfbScreen->desktopName = argv[1];
71  else
72  rfbScreen->desktopName = "Picture";
73  rfbScreen->alwaysShared = TRUE;
74  rfbScreen->kbdAddEvent = HandleKey;
75 
76  /* enable http */
77  rfbScreen->httpDir = "../webclients";
78 
79  /* allocate picture and read it */
80  rfbScreen->frameBuffer = (char*)malloc(paddedWidth*3*height);
81  if(!rfbScreen->frameBuffer)
82  return 1;
83  fread(rfbScreen->frameBuffer,width*3,height,in);
84  fclose(in);
85 
86  /* pad to paddedWidth */
87  if(width != paddedWidth) {
88  int padCount = 3*(paddedWidth - width);
89  for(j=height-1;j>=0;j--) {
90  memmove(rfbScreen->frameBuffer+3*paddedWidth*j,
91  rfbScreen->frameBuffer+3*width*j,
92  3*width);
93  memset(rfbScreen->frameBuffer+3*paddedWidth*(j+1)-padCount,
94  0,padCount);
95  }
96  }
97 
98  /* initialize server */
99  rfbInitServer(rfbScreen);
100 
101  /* run event loop */
102  rfbRunEventLoop(rfbScreen,40000,FALSE);
103 
104  return(0);
105 }
106 #endif
void rfbInitServer(rfbScreenInfoPtr rfbScreen)
void rfbRunEventLoop(rfbScreenInfoPtr screenInfo, long usec, rfbBool runInBackground)
void rfbCloseClient(rfbClientPtr cl)
rfbScreenInfoPtr rfbGetScreen(int *argc, char **argv, int width, int height, int bitsPerSample, int samplesPerPixel, int bytesPerPixel)
rfbLogProc rfbLog
#define XK_Escape
Definition: keysym.h:131
int main()
Definition: pnmshow24.c:14
int8_t rfbBool
Definition: rfbproto.h:108
uint32_t rfbKeySym
Definition: rfbproto.h:122
#define TRUE
Definition: rfbproto.h:112
#define FALSE
Definition: rfbproto.h:110
#define height
Definition: vncev.c:19
#define width
Definition: vncev.c:18