Blame examples/pnmshow24.c

Packit 9c64f8
/**
Packit 9c64f8
 * @example pnmshow24.c
Packit 9c64f8
 */
Packit 9c64f8
Packit 9c64f8
#include <stdio.h>
Packit 9c64f8
#include <rfb/rfb.h>
Packit 9c64f8
#include <rfb/keysym.h>
Packit 9c64f8
Packit 9c64f8
#ifndef LIBVNCSERVER_ALLOW24BPP
Packit 9c64f8
int main() {
Packit 9c64f8
	printf("I need the ALLOW24BPP LibVNCServer flag to work\n");
Packit 9c64f8
	exit(1);
Packit 9c64f8
}
Packit 9c64f8
#else
Packit 9c64f8
Packit 9c64f8
static void HandleKey(rfbBool down,rfbKeySym key,rfbClientPtr cl)
Packit 9c64f8
{
Packit 9c64f8
  if(down && (key==XK_Escape || key=='q' || key=='Q'))
Packit 9c64f8
    rfbCloseClient(cl);
Packit 9c64f8
}
Packit 9c64f8
Packit 9c64f8
int main(int argc,char** argv)
Packit 9c64f8
{
Packit 9c64f8
  FILE* in=stdin;
Packit 9c64f8
  int j,width,height,paddedWidth;
Packit 9c64f8
  char buffer[1024];
Packit 9c64f8
  rfbScreenInfoPtr rfbScreen;
Packit 9c64f8
Packit 9c64f8
  if(argc>1) {
Packit 9c64f8
    in=fopen(argv[1],"rb");
Packit 9c64f8
    if(!in) {
Packit 9c64f8
      printf("Couldn't find file %s.\n",argv[1]);
Packit 9c64f8
      exit(1);
Packit 9c64f8
    }
Packit 9c64f8
  }
Packit 9c64f8
Packit 9c64f8
  fgets(buffer,1024,in);
Packit 9c64f8
  if(strncmp(buffer,"P6",2)) {
Packit 9c64f8
    printf("Not a ppm.\n");
Packit 9c64f8
    exit(2);
Packit 9c64f8
  }
Packit 9c64f8
Packit 9c64f8
  /* skip comments */
Packit 9c64f8
  do {
Packit 9c64f8
    fgets(buffer,1024,in);
Packit 9c64f8
  } while(buffer[0]=='#');
Packit 9c64f8
Packit 9c64f8
  /* get width & height */
Packit 9c64f8
  sscanf(buffer,"%d %d",&width,&height);
Packit 9c64f8
  rfbLog("Got width %d and height %d.\n",width,height);
Packit 9c64f8
  fgets(buffer,1024,in);
Packit 9c64f8
Packit 9c64f8
  /* vncviewers have problems with widths which are no multiple of 4. */
Packit 9c64f8
  paddedWidth = width;
Packit 9c64f8
Packit 9c64f8
  /* if your vncviewer doesn't have problems with a width
Packit 9c64f8
     which is not a multiple of 4, you can comment this. */
Packit 9c64f8
  if(width&3)
Packit 9c64f8
    paddedWidth+=4-(width&3;;
Packit 9c64f8
Packit 9c64f8
  /* initialize data for vnc server */
Packit 9c64f8
  rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,3);
Packit 9c64f8
  if(!rfbScreen)
Packit 9c64f8
    return 0;
Packit 9c64f8
  if(argc>1)
Packit 9c64f8
    rfbScreen->desktopName = argv[1];
Packit 9c64f8
  else
Packit 9c64f8
    rfbScreen->desktopName = "Picture";
Packit 9c64f8
  rfbScreen->alwaysShared = TRUE;
Packit 9c64f8
  rfbScreen->kbdAddEvent = HandleKey;
Packit 9c64f8
Packit 9c64f8
  /* enable http */
Packit 9c64f8
  rfbScreen->httpDir = "../webclients";
Packit 9c64f8
Packit 9c64f8
  /* allocate picture and read it */
Packit 9c64f8
  rfbScreen->frameBuffer = (char*)malloc(paddedWidth*3*height);
Packit 9c64f8
  fread(rfbScreen->frameBuffer,width*3,height,in);
Packit 9c64f8
  fclose(in);
Packit 9c64f8
Packit 9c64f8
  /* pad to paddedWidth */
Packit 9c64f8
  if(width != paddedWidth) {
Packit 9c64f8
    int padCount = 3*(paddedWidth - width);
Packit 9c64f8
    for(j=height-1;j>=0;j--) {
Packit 9c64f8
      memmove(rfbScreen->frameBuffer+3*paddedWidth*j,
Packit 9c64f8
	      rfbScreen->frameBuffer+3*width*j,
Packit 9c64f8
	      3*width);
Packit 9c64f8
      memset(rfbScreen->frameBuffer+3*paddedWidth*(j+1)-padCount,
Packit 9c64f8
	     0,padCount);
Packit 9c64f8
    }
Packit 9c64f8
  }
Packit 9c64f8
Packit 9c64f8
  /* initialize server */
Packit 9c64f8
  rfbInitServer(rfbScreen);
Packit 9c64f8
Packit 9c64f8
  /* run event loop */
Packit 9c64f8
  rfbRunEventLoop(rfbScreen,40000,FALSE);
Packit 9c64f8
Packit 9c64f8
  return(0);
Packit 9c64f8
}
Packit 9c64f8
#endif