diff options
author | dscho <dscho> | 2001-08-14 10:24:32 +0000 |
---|---|---|
committer | dscho <dscho> | 2001-08-14 10:24:32 +0000 |
commit | 2634379912ea972dedc0d389049945716c90c0db (patch) | |
tree | 1dd12c9611b772e1c113980bbf7de1e61b7c37a0 /pnmshow.c | |
parent | 47341aa5545e8b354c8cd45e1372f96d9e4f6c0d (diff) | |
download | libtdevnc-2634379912ea972dedc0d389049945716c90c0db.tar.gz libtdevnc-2634379912ea972dedc0d389049945716c90c0db.zip |
comments & new example: pnmshow
Diffstat (limited to 'pnmshow.c')
-rw-r--r-- | pnmshow.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/pnmshow.c b/pnmshow.c new file mode 100644 index 0000000..0f29d90 --- /dev/null +++ b/pnmshow.c @@ -0,0 +1,67 @@ +#include <stdio.h> +#include "rfb.h" +#define XK_MISCELLANY +#include "keysymdef.h" + +void HandleKey(Bool down,KeySym key,rfbClientPtr cl) +{ + if(down && (key==XK_Escape || key=='q' || key=='Q')) + rfbCloseClient(cl); +} + +int main(int argc,char** argv) +{ + FILE* in=stdin; + int i,width,height; + unsigned char buffer[1024]; + rfbScreenInfoPtr rfbScreen; + + if(argc>1) { + in=fopen(argv[1],"rb"); + if(!in) { + printf("Couldn't find file %s.\n",argv[1]); + exit(1); + } + } + + fgets(buffer,1024,in); + if(strncmp(buffer,"P6",2)) { + printf("Not a ppm.\n"); + exit(2); + } + + /* skip comments */ + do { + fgets(buffer,1024,in); + } while(buffer[0]=='#'); + + /* get width & height */ + sscanf(buffer,"%d %d",&width,&height); + fprintf(stderr,"Got width %d and height %d (%s).\n",width,height,buffer); + fgets(buffer,1024,in); + + /* initialize data for vnc server */ + rfbScreen = rfbDefaultScreenInit(argc,argv,width,height,8,3,4); + if(argc>1) + rfbScreen->desktopName = argv[1]; + else + rfbScreen->desktopName = "Picture"; + rfbScreen->rfbAlwaysShared = TRUE; + rfbScreen->kbdAddEvent = HandleKey; + + /* allocate picture and read it */ + rfbScreen->frameBuffer = (char*)malloc(width*height*4); + fread(rfbScreen->frameBuffer,width*3,height,in); + + /* correct the format to 4 bytes instead of 3 */ + for(i=width*height-1;i>=0;i--) { + rfbScreen->frameBuffer[i*4+3]=rfbScreen->frameBuffer[i*3+2]; + rfbScreen->frameBuffer[i*4+2]=rfbScreen->frameBuffer[i*3+1]; + rfbScreen->frameBuffer[i*4+1]=rfbScreen->frameBuffer[i*3+0]; + } + + /* run event loop */ + runEventLoop(rfbScreen,40000,FALSE); + + return(0); +} |