Add feature 85117: [liboscar/icq] password changing support for ICQ.
[kdenetwork.git] / krfb / libvncserver / pnmshow.c
blob05e45b9c8b18eec25dd60ba7a4bd18878f1702f6
1 #include <stdio.h>
2 #include "rfb.h"
3 #include "keysym.h"
5 void HandleKey(Bool down,KeySym key,rfbClientPtr cl)
7 if(down && (key==XK_Escape || key=='q' || key=='Q'))
8 rfbCloseClient(cl);
11 int main(int argc,char** argv)
13 FILE* in=stdin;
14 int i,j,k,width,height,paddedWidth;
15 unsigned char buffer[1024];
16 rfbScreenInfoPtr rfbScreen;
18 if(argc>1) {
19 in=fopen(argv[1],"rb");
20 if(!in) {
21 printf("Couldn't find file %s.\n",argv[1]);
22 exit(1);
26 fgets(buffer,1024,in);
27 if(strncmp(buffer,"P6",2)) {
28 printf("Not a ppm.\n");
29 exit(2);
32 /* skip comments */
33 do {
34 fgets(buffer,1024,in);
35 } while(buffer[0]=='#');
37 /* get width & height */
38 sscanf(buffer,"%d %d",&width,&height);
39 fprintf(stderr,"Got width %d and height %d.\n",width,height);
40 fgets(buffer,1024,in);
42 /* vncviewers have problems with widths which are no multiple of 4. */
43 paddedWidth = width;
44 if(width&3)
45 paddedWidth+=4-(width&3);
47 /* initialize data for vnc server */
48 rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,4);
49 if(argc>1)
50 rfbScreen->desktopName = argv[1];
51 else
52 rfbScreen->desktopName = "Picture";
53 rfbScreen->rfbAlwaysShared = TRUE;
54 rfbScreen->kbdAddEvent = HandleKey;
56 /* enable http */
57 rfbScreen->httpDir = "./classes";
59 /* allocate picture and read it */
60 rfbScreen->frameBuffer = (char*)malloc(paddedWidth*4*height);
61 fread(rfbScreen->frameBuffer,width*3,height,in);
62 fclose(in);
64 /* correct the format to 4 bytes instead of 3 (and pad to paddedWidth) */
65 for(j=height-1;j>=0;j--) {
66 for(i=width-1;i>=0;i--)
67 for(k=2;k>=0;k--)
68 rfbScreen->frameBuffer[(j*paddedWidth+i)*4+k]=
69 rfbScreen->frameBuffer[(j*width+i)*3+k];
70 for(i=width*4;i<paddedWidth*4;i++)
71 rfbScreen->frameBuffer[j*paddedWidth*4+i]=0;
74 /* initialize server */
75 rfbInitServer(rfbScreen);
77 /* run event loop */
78 rfbRunEventLoop(rfbScreen,40000,FALSE);
80 return(0);