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
14int main() {
15 printf("I need the ALLOW24BPP LibVNCServer flag to work\n");
16 exit(1);
17}
18#else
19
20static void HandleKey(rfbBool down,rfbKeySym key,rfbClientPtr cl)
21{
22 if(down && (key==XK_Escape || key=='q' || key=='Q'))
24}
25
26int 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 if(sscanf(buffer,"%d %d",&width,&height) != 2) {
54 printf("Failed to get width or height.\n");
55 exit(3);
56 }
57 rfbLog("Got width %d and height %d.\n",width,height);
58 fgets(buffer,1024,in);
59
60 /* vncviewers have problems with widths which are no multiple of 4. */
61 paddedWidth = width;
62
63 /* if your vncviewer doesn't have problems with a width
64 which is not a multiple of 4, you can comment this. */
65 if(width&3)
66 paddedWidth+=4-(width&3);
67
68 /* initialize data for vnc server */
69 rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,3);
70 if(!rfbScreen)
71 return 1;
72 if(argc>1)
73 rfbScreen->desktopName = argv[1];
74 else
75 rfbScreen->desktopName = "Picture";
76 rfbScreen->alwaysShared = TRUE;
77 rfbScreen->kbdAddEvent = HandleKey;
78
79 /* enable http */
80 rfbScreen->httpDir = "../webclients";
81
82 /* allocate picture and read it */
83 if (paddedWidth>SIZE_MAX/3 || (height!=0 && paddedWidth*3>SIZE_MAX/height))
84 return 1;
85 rfbScreen->frameBuffer = (char*)malloc(paddedWidth*3*height);
86 if(!rfbScreen->frameBuffer)
87 return 1;
88 fread(rfbScreen->frameBuffer,width*3,height,in);
89 fclose(in);
90
91 /* pad to paddedWidth */
92 if(width != paddedWidth) {
93 int padCount = 3*(paddedWidth - width);
94 for(j=height-1;j>=0;j--) {
95 memmove(rfbScreen->frameBuffer+3*paddedWidth*j,
96 rfbScreen->frameBuffer+3*width*j,
97 3*width);
98 memset(rfbScreen->frameBuffer+3*paddedWidth*(j+1)-padCount,
99 0,padCount);
100 }
101 }
102
103 /* initialize server */
104 rfbInitServer(rfbScreen);
105
106 /* run event loop */
107 rfbRunEventLoop(rfbScreen,40000,FALSE);
108
109 return(0);
110}
111#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