Commit b2253e36 authored by dscho's avatar dscho

changes from Justin, zippy added

parent 68202741
...@@ -24,11 +24,11 @@ OSX_LIBS = -framework ApplicationServices -framework Carbon ...@@ -24,11 +24,11 @@ OSX_LIBS = -framework ApplicationServices -framework Carbon
SOURCES=main.c rfbserver.c sraRegion.c auth.c sockets.c \ SOURCES=main.c rfbserver.c sraRegion.c auth.c sockets.c \
stats.c corre.c hextile.c rre.c translate.c cutpaste.c \ stats.c corre.c hextile.c rre.c translate.c cutpaste.c \
zlib.c tight.c httpd.c cursor.c font.c \ zlib.c tight.c httpd.c cursor.c font.c \
draw.c selbox.c d3des.c vncauth.c draw.c selbox.c d3des.c vncauth.c cargs.c
OBJS=main.o rfbserver.o sraRegion.o auth.o sockets.o \ OBJS=main.o rfbserver.o sraRegion.o auth.o sockets.o \
stats.o corre.o hextile.o rre.o translate.o cutpaste.o \ stats.o corre.o hextile.o rre.o translate.o cutpaste.o \
zlib.o tight.o httpd.o cursor.o font.o \ zlib.o tight.o httpd.o cursor.o font.o \
draw.o selbox.o d3des.o vncauth.o draw.o selbox.o d3des.o vncauth.o cargs.o
INSTALLHEADER=rfb.h rfbproto.h sraRegion.h keysym.h INSTALLHEADER=rfb.h rfbproto.h sraRegion.h keysym.h
all: example pnmshow storepasswd all: example pnmshow storepasswd
...@@ -80,6 +80,10 @@ fontsel: fontsel.o libvncserver.a ...@@ -80,6 +80,10 @@ fontsel: fontsel.o libvncserver.a
vncev: vncev.o libvncserver.a vncev: vncev.o libvncserver.a
$(CC) -o vncev vncev.o -L. -lvncserver -lz -ljpeg $(CC) -o vncev vncev.o -L. -lvncserver -lz -ljpeg
# Example from Justin
zippy: zippy.o libvncserver.a
$(CC) -o zippy zippy.o -L. -lvncserver -lz -ljpeg
clean: clean:
rm -f $(OBJS) *~ core "#"* *.bak *.orig storepasswd.o \ rm -f $(OBJS) *~ core "#"* *.bak *.orig storepasswd.o \
mac.o example.o pnmshow.o pnmshow24.o sratest.o \ mac.o example.o pnmshow.o pnmshow24.o sratest.o \
......
#ifndef D3DES_H
#define D3DES_H
/* /*
* This is D3DES (V5.09) by Richard Outerbridge with the double and * This is D3DES (V5.09) by Richard Outerbridge with the double and
* triple-length support removed for use in VNC. * triple-length support removed for use in VNC.
...@@ -49,3 +52,5 @@ extern void des(unsigned char *, unsigned char *); ...@@ -49,3 +52,5 @@ extern void des(unsigned char *, unsigned char *);
/* d3des.h V5.09 rwo 9208.04 15:06 Graven Imagery /* d3des.h V5.09 rwo 9208.04 15:06 Graven Imagery
********************************************************************/ ********************************************************************/
#endif
...@@ -239,7 +239,7 @@ void MakeRichCursor(rfbScreenInfoPtr rfbScreen) ...@@ -239,7 +239,7 @@ void MakeRichCursor(rfbScreenInfoPtr rfbScreen)
int main(int argc,char** argv) int main(int argc,char** argv)
{ {
rfbScreenInfoPtr rfbScreen = rfbScreenInfoPtr rfbScreen =
rfbGetScreen(argc,argv,maxx,maxy,8,3,bpp); rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp);
rfbScreen->desktopName = "LibVNCServer Example"; rfbScreen->desktopName = "LibVNCServer Example";
rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp); rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp);
rfbScreen->rfbAlwaysShared = TRUE; rfbScreen->rfbAlwaysShared = TRUE;
......
...@@ -38,7 +38,7 @@ void showFont(int index) ...@@ -38,7 +38,7 @@ void showFont(int index)
int main(int argc,char** argv) int main(int argc,char** argv)
{ {
rfbFontDataPtr font; rfbFontDataPtr font;
rfbScreenInfoPtr s=rfbGetScreen(argc,argv,640,480,8,3,3); rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,640,480,8,3,3);
int i,j; int i,j;
s->frameBuffer=(char*)malloc(640*480*3); s->frameBuffer=(char*)malloc(640*480*3);
......
#ifndef KEYSYM_H
#define KEYSYM_H
/* $XConsortium: keysym.h,v 1.15 94/04/17 20:10:55 rws Exp $ */ /* $XConsortium: keysym.h,v 1.15 94/04/17 20:10:55 rws Exp $ */
/*********************************************************** /***********************************************************
...@@ -1632,3 +1635,5 @@ SOFTWARE. ...@@ -1632,3 +1635,5 @@ SOFTWARE.
/* Euro currency symbol */ /* Euro currency symbol */
#define XK_EuroSign 0x20ac #define XK_EuroSign 0x20ac
#endif
...@@ -266,7 +266,7 @@ PtrAddEvent(buttonMask, x, y, cl) ...@@ -266,7 +266,7 @@ PtrAddEvent(buttonMask, x, y, cl)
void void
ScreenInit(int argc, char**argv) ScreenInit(int argc, char**argv)
{ {
rfbScreen = rfbGetScreen(argc,argv, rfbScreen = rfbGetScreen(&argc,argv,
CGDisplayPixelsWide(kCGDirectMainDisplay), CGDisplayPixelsWide(kCGDirectMainDisplay),
CGDisplayPixelsHigh(kCGDirectMainDisplay), CGDisplayPixelsHigh(kCGDirectMainDisplay),
CGDisplayBitsPerSample(kCGDirectMainDisplay), CGDisplayBitsPerSample(kCGDirectMainDisplay),
......
...@@ -209,8 +209,6 @@ void rfbMarkRectAsModified(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y ...@@ -209,8 +209,6 @@ void rfbMarkRectAsModified(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y
sraRgnDestroy(region); sraRgnDestroy(region);
} }
int rfbDeferUpdateTime = 40; /* ms */
#ifdef HAVE_PTHREADS #ifdef HAVE_PTHREADS
static void * static void *
clientOutput(void *data) clientOutput(void *data)
...@@ -243,7 +241,7 @@ clientOutput(void *data) ...@@ -243,7 +241,7 @@ clientOutput(void *data)
/* OK, now, to save bandwidth, wait a little while for more /* OK, now, to save bandwidth, wait a little while for more
updates to come along. */ updates to come along. */
usleep(rfbDeferUpdateTime * 1000); usleep(cl->screen->rfbDeferUpdateTime * 1000);
/* Now, get the region we're going to update, and remove /* Now, get the region we're going to update, and remove
it from cl->modifiedRegion _before_ we send the update. it from cl->modifiedRegion _before_ we send the update.
...@@ -312,58 +310,6 @@ listenerRun(void *data) ...@@ -312,58 +310,6 @@ listenerRun(void *data)
} }
#endif #endif
static void
usage(void)
{
fprintf(stderr, "-rfbport port TCP port for RFB protocol\n");
fprintf(stderr, "-rfbwait time max time in ms to wait for RFB client\n");
fprintf(stderr, "-rfbauth passwd-file use authentication on RFB protocol\n"
" (use 'storepasswd' to create a password file)\n");
fprintf(stderr, "-deferupdate time time in ms to defer updates "
"(default 40)\n");
fprintf(stderr, "-desktop name VNC desktop name (default \"LibVNCServer\")\n");
fprintf(stderr, "-alwaysshared always treat new clients as shared\n");
fprintf(stderr, "-nevershared never treat new clients as shared\n");
fprintf(stderr, "-dontdisconnect don't disconnect existing clients when a "
"new non-shared\n"
" connection comes in (refuse new connection "
"instead)\n");
exit(1);
}
static void
processArguments(rfbScreenInfoPtr rfbScreen,int argc, char *argv[])
{
int i;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-rfbport") == 0) { /* -rfbport port */
if (i + 1 >= argc) usage();
rfbScreen->rfbPort = atoi(argv[++i]);
} else if (strcmp(argv[i], "-rfbwait") == 0) { /* -rfbwait ms */
if (i + 1 >= argc) usage();
rfbScreen->rfbMaxClientWait = atoi(argv[++i]);
} else if (strcmp(argv[i], "-rfbauth") == 0) { /* -rfbauth passwd-file */
if (i + 1 >= argc) usage();
rfbScreen->rfbAuthPasswdData = argv[++i];
} else if (strcmp(argv[i], "-deferupdate") == 0) { /* -desktop desktop-name */
if (i + 1 >= argc) usage();
rfbScreen->rfbDeferUpdateTime = atoi(argv[++i]);
} else if (strcmp(argv[i], "-desktop") == 0) { /* -desktop desktop-name */
if (i + 1 >= argc) usage();
rfbScreen->desktopName = argv[++i];
} else if (strcmp(argv[i], "-alwaysshared") == 0) {
rfbScreen->rfbAlwaysShared = TRUE;
} else if (strcmp(argv[i], "-nevershared") == 0) {
rfbScreen->rfbNeverShared = TRUE;
} else if (strcmp(argv[i], "-dontdisconnect") == 0) {
rfbScreen->rfbDontDisconnect = TRUE;
} else {
/* usage(); we no longer exit for unknown arguments */
}
}
}
void void
defaultKbdAddEvent(Bool down, KeySym keySym, rfbClientPtr cl) defaultKbdAddEvent(Bool down, KeySym keySym, rfbClientPtr cl)
{ {
...@@ -451,11 +397,30 @@ Bool defaultPasswordCheck(rfbClientPtr cl,char* response,int len) ...@@ -451,11 +397,30 @@ Bool defaultPasswordCheck(rfbClientPtr cl,char* response,int len)
return(TRUE); return(TRUE);
} }
/* for this method, rfbAuthPasswdData is really a pointer to an array
of char*'s, where the last pointer is 0. */
Bool checkPasswordByList(rfbClientPtr cl,char* response,int len)
{
int i;
char **passwds;
for(passwds=(char**)cl->screen->rfbAuthPasswdData;*passwds;passwds++) {
vncEncryptBytes(cl->authChallenge, *passwds);
if (memcmp(cl->authChallenge, response, len) == 0)
return(TRUE);
}
rfbLog("rfbAuthProcessClientMessage: authentication failed from %s\n",
cl->host);
return(FALSE);
}
void doNothingWithClient(rfbClientPtr cl) void doNothingWithClient(rfbClientPtr cl)
{ {
} }
rfbScreenInfoPtr rfbGetScreen(int argc,char** argv, rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv,
int width,int height,int bitsPerSample,int samplesPerPixel, int width,int height,int bitsPerSample,int samplesPerPixel,
int bytesPerPixel) int bytesPerPixel)
{ {
...@@ -495,11 +460,12 @@ rfbScreenInfoPtr rfbGetScreen(int argc,char** argv, ...@@ -495,11 +460,12 @@ rfbScreenInfoPtr rfbGetScreen(int argc,char** argv,
rfbScreen->rfbDontDisconnect = FALSE; rfbScreen->rfbDontDisconnect = FALSE;
rfbScreen->rfbAuthPasswdData = 0; rfbScreen->rfbAuthPasswdData = 0;
processArguments(rfbScreen,argc,argv);
rfbScreen->width = width; rfbScreen->width = width;
rfbScreen->height = height; rfbScreen->height = height;
rfbScreen->bitsPerPixel = rfbScreen->depth = 8*bytesPerPixel; rfbScreen->bitsPerPixel = rfbScreen->depth = 8*bytesPerPixel;
rfbProcessArguments(rfbScreen,argc,argv);
#ifdef WIN32 #ifdef WIN32
{ {
DWORD dummy=255; DWORD dummy=255;
...@@ -555,6 +521,8 @@ rfbScreenInfoPtr rfbGetScreen(int argc,char** argv, ...@@ -555,6 +521,8 @@ rfbScreenInfoPtr rfbGetScreen(int argc,char** argv,
IF_PTHREADS(rfbScreen->backgroundLoop = FALSE); IF_PTHREADS(rfbScreen->backgroundLoop = FALSE);
rfbScreen->rfbDeferUpdateTime=5;
/* proc's and hook's */ /* proc's and hook's */
rfbScreen->kbdAddEvent = defaultKbdAddEvent; rfbScreen->kbdAddEvent = defaultKbdAddEvent;
...@@ -575,20 +543,14 @@ rfbScreenInfoPtr rfbGetScreen(int argc,char** argv, ...@@ -575,20 +543,14 @@ rfbScreenInfoPtr rfbGetScreen(int argc,char** argv,
void rfbScreenCleanup(rfbScreenInfoPtr rfbScreen) void rfbScreenCleanup(rfbScreenInfoPtr rfbScreen)
{ {
/* TODO */ /* TODO: hang up on all clients and free all reserved memory */
if(rfbScreen->frameBuffer)
free(rfbScreen->frameBuffer);
if(rfbScreen->colourMap.data.bytes) if(rfbScreen->colourMap.data.bytes)
free(rfbScreen->colourMap.data.bytes); free(rfbScreen->colourMap.data.bytes);
TINI_MUTEX(rfbScreen->cursorMutex); TINI_MUTEX(rfbScreen->cursorMutex);
free(rfbScreen); free(rfbScreen);
} }
#ifdef HAVE_PTHREADS
void rfbInitServerWithPthreads(rfbScreenInfoPtr rfbScreen)
#else
void rfbInitServer(rfbScreenInfoPtr rfbScreen) void rfbInitServer(rfbScreenInfoPtr rfbScreen)
#endif
{ {
#ifdef WIN32 #ifdef WIN32
WSADATA trash; WSADATA trash;
...@@ -629,7 +591,9 @@ rfbProcessEvents(rfbScreenInfoPtr rfbScreen,long usec) ...@@ -629,7 +591,9 @@ rfbProcessEvents(rfbScreenInfoPtr rfbScreen,long usec)
cl=rfbClientIteratorNext(i); cl=rfbClientIteratorNext(i);
while(cl) { while(cl) {
if(cl->sock>=0 && FB_UPDATE_PENDING(cl)) { if(cl->sock>=0 && FB_UPDATE_PENDING(cl)) {
if(cl->startDeferring.tv_usec == 0) { if(cl->screen->rfbDeferUpdateTime == 0) {
rfbSendFramebufferUpdate(cl,cl->modifiedRegion);
} else if(cl->startDeferring.tv_usec == 0) {
gettimeofday(&cl->startDeferring,NULL); gettimeofday(&cl->startDeferring,NULL);
if(cl->startDeferring.tv_usec == 0) if(cl->startDeferring.tv_usec == 0)
cl->startDeferring.tv_usec++; cl->startDeferring.tv_usec++;
...@@ -668,6 +632,9 @@ void rfbRunEventLoop(rfbScreenInfoPtr rfbScreen, long usec, Bool runInBackground ...@@ -668,6 +632,9 @@ void rfbRunEventLoop(rfbScreenInfoPtr rfbScreen, long usec, Bool runInBackground
#endif #endif
} }
if(usec<0)
usec=rfbScreen->rfbDeferUpdateTime*1000;
while(1) while(1)
rfbProcessEvents(rfbScreen,usec); rfbProcessEvents(rfbScreen,usec);
} }
...@@ -45,7 +45,7 @@ int main(int argc,char** argv) ...@@ -45,7 +45,7 @@ int main(int argc,char** argv)
paddedWidth+=4-(width&3); paddedWidth+=4-(width&3);
/* initialize data for vnc server */ /* initialize data for vnc server */
rfbScreen = rfbGetScreen(argc,argv,paddedWidth,height,8,3,4); rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,4);
if(argc>1) if(argc>1)
rfbScreen->desktopName = argv[1]; rfbScreen->desktopName = argv[1];
else else
......
...@@ -52,7 +52,7 @@ int main(int argc,char** argv) ...@@ -52,7 +52,7 @@ int main(int argc,char** argv)
paddedWidth+=4-(width&3); paddedWidth+=4-(width&3);
/* initialize data for vnc server */ /* initialize data for vnc server */
rfbScreen = rfbGetScreen(argc,argv,paddedWidth,height,8,3,3); rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,3);
if(argc>1) if(argc>1)
rfbScreen->desktopName = argv[1]; rfbScreen->desktopName = argv[1];
else else
......
#ifndef RFB_H
#define RFB_H
/* /*
* rfb.h - header file for RFB DDX implementation. * rfb.h - header file for RFB DDX implementation.
*/ */
...@@ -285,7 +288,9 @@ typedef struct ...@@ -285,7 +288,9 @@ typedef struct
Bool dontConvertRichCursorToXCursor; Bool dontConvertRichCursorToXCursor;
struct rfbCursor* cursor; struct rfbCursor* cursor;
/* the following members have to be supplied by the serving process */ /* the frameBufferhas to be supplied by the serving process.
* The buffer will not be freed by
*/
char* frameBuffer; char* frameBuffer;
KbdAddEventProcPtr kbdAddEvent; KbdAddEventProcPtr kbdAddEvent;
KbdReleaseAllKeysProcPtr kbdReleaseAllKeys; KbdReleaseAllKeysProcPtr kbdReleaseAllKeys;
...@@ -720,6 +725,12 @@ extern int rfbSelectBox(rfbScreenInfoPtr rfbScreen, ...@@ -720,6 +725,12 @@ extern int rfbSelectBox(rfbScreenInfoPtr rfbScreen,
Pixel foreColour, Pixel backColour, Pixel foreColour, Pixel backColour,
int border,SelectionChangedHookPtr selChangedHook); int border,SelectionChangedHookPtr selChangedHook);
/* cargs.c */
extern void rfbUsage();
extern void rfbProcessArguments(rfbScreenInfoPtr rfbScreen,int* argc, char *argv[]);
extern void rfbProcessSizeArguments(int* width,int* height,int* bpp,int* argc, char *argv[]);
/* main.c */ /* main.c */
extern void rfbLog(char *format, ...); extern void rfbLog(char *format, ...);
...@@ -736,7 +747,7 @@ void rfbMarkRegionAsModified(rfbScreenInfoPtr rfbScreen,sraRegionPtr modRegion); ...@@ -736,7 +747,7 @@ void rfbMarkRegionAsModified(rfbScreenInfoPtr rfbScreen,sraRegionPtr modRegion);
void doNothingWithClient(rfbClientPtr cl); void doNothingWithClient(rfbClientPtr cl);
/* functions to make a vnc server */ /* functions to make a vnc server */
extern rfbScreenInfoPtr rfbGetScreen(int argc,char** argv, extern rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv,
int width,int height,int bitsPerSample,int samplesPerPixel, int width,int height,int bitsPerSample,int samplesPerPixel,
int bytesPerPixel); int bytesPerPixel);
extern void rfbInitServer(rfbScreenInfoPtr rfbScreen); extern void rfbInitServer(rfbScreenInfoPtr rfbScreen);
...@@ -749,3 +760,5 @@ extern void rfbScreenCleanup(rfbScreenInfoPtr screenInfo); ...@@ -749,3 +760,5 @@ extern void rfbScreenCleanup(rfbScreenInfoPtr screenInfo);
extern void rfbRunEventLoop(rfbScreenInfoPtr screenInfo, long usec, Bool runInBackground); extern void rfbRunEventLoop(rfbScreenInfoPtr screenInfo, long usec, Bool runInBackground);
extern void rfbProcessEvents(rfbScreenInfoPtr screenInfo,long usec); extern void rfbProcessEvents(rfbScreenInfoPtr screenInfo,long usec);
#endif
#ifndef RFBPROTO_H
#define RFBPROTO_H
/* /*
* Copyright (C) 2000, 2001 Const Kaplinsky. All Rights Reserved. * Copyright (C) 2000, 2001 Const Kaplinsky. All Rights Reserved.
* Copyright (C) 2000 Tridia Corporation. All Rights Reserved. * Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
...@@ -783,3 +786,5 @@ typedef union { ...@@ -783,3 +786,5 @@ typedef union {
rfbPointerEventMsg pe; rfbPointerEventMsg pe;
rfbClientCutTextMsg cct; rfbClientCutTextMsg cct;
} rfbClientToServerMsg; } rfbClientToServerMsg;
#endif
#ifndef SRAREGION_H
#define SRAREGION_H
/* -=- SRA - Simple Region Algorithm /* -=- SRA - Simple Region Algorithm
* A simple rectangular region implementation. * A simple rectangular region implementation.
* Copyright (c) 2001 James "Wez" Weatherall, Johannes E. Schindelin * Copyright (c) 2001 James "Wez" Weatherall, Johannes E. Schindelin
...@@ -53,3 +56,5 @@ void sraRgnPrint(const sraRegion *s); ...@@ -53,3 +56,5 @@ void sraRgnPrint(const sraRegion *s);
extern Bool sraClipRect(int *x, int *y, int *w, int *h, extern Bool sraClipRect(int *x, int *y, int *w, int *h,
int cx, int cy, int cw, int ch); int cx, int cy, int cw, int ch);
#endif
...@@ -99,7 +99,7 @@ void newclient(rfbClientPtr cl) ...@@ -99,7 +99,7 @@ void newclient(rfbClientPtr cl)
int main(int argc,char** argv) int main(int argc,char** argv)
{ {
rfbScreenInfoPtr s=rfbGetScreen(argc,argv,640,480,8,1,1); rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,640,480,8,1,1);
s->colourMap.is16=FALSE; s->colourMap.is16=FALSE;
s->colourMap.count=2; s->colourMap.count=2;
s->colourMap.data.bytes="\xd0\xd0\xd0\x30\x01\xe0"; s->colourMap.data.bytes="\xd0\xd0\xd0\x30\x01\xe0";
......
#include <stdio.h>
#include <stdlib.h>
#include <rfb.h>
#include <keysym.h>
#include "radon.h"
int maxx=400, maxy=400, bpp=4;
/* odd maxx doesn't work (vncviewer bug) */
/* Here we create a structure so that every client has it's own pointer */
/* turns the framebuffer black */
void blank_framebuffer(char* frame_buffer, int x1, int y1, int x2, int y2);
/* displays a red bar, a green bar, and a blue bar */
void draw_primary_colors (char* frame_buffer, int x1, int y1, int x2, int y2);
void linecount (char* frame_buffer);
/* handles mouse events */
void on_mouse_event (int buttonMask,int x,int y,rfbClientPtr cl);
/* handles keyboard events */
void on_key_press (Bool down,KeySym key,rfbClientPtr cl);
int main (int argc, char **argv)
{
int i;
rfbScreenInfoPtr server;
rfbProcessSizeArguments(&maxx,&maxy,&bpp,&argc,argv);
server = rfbGetScreen (&argc, argv, maxx, maxy, 8, 3, bpp);
server->desktopName = "Zippy das wundersquirrel\'s VNC server";
server->frameBuffer = (char*)malloc(maxx*maxy*bpp);
server->rfbAlwaysShared = TRUE;
server->kbdAddEvent = on_key_press;
server->ptrAddEvent = on_mouse_event;
rfbInitServer (server);
blank_framebuffer(server->frameBuffer, 0, 0, maxx, maxy);
rfbRunEventLoop (server, -1, FALSE);
free(server->frameBuffer);
rfbScreenCleanup (server);
return 0;
}
void blank_framebuffer(char* frame_buffer, int x1, int y1, int x2, int y2)
{
int i;
for (i=0; i < maxx * maxy * bpp; i++) frame_buffer[i]=(char) 0;
}
void draw_primary_colors (char* frame_buffer, int x1, int y1, int x2, int y2)
{
int i, j, current_pixel;
for (i=y1; i < y2; i++){
for (j=x1; j < x2; j++) {
current_pixel = (i*x2 + j) * bpp;
if (i < y2 ) {
frame_buffer[current_pixel+0] = (char) 128;
frame_buffer[current_pixel+1] = (char) 0;
frame_buffer[current_pixel+2] = (char) 0;
}
if (i < y2/3*2) {
frame_buffer[current_pixel+0] = (char) 0;
frame_buffer[current_pixel+1] = (char) 128;
frame_buffer[current_pixel+2] = (char) 0;
}
if (i < y2/3) {
frame_buffer[current_pixel+0] = (char) 0;
frame_buffer[current_pixel+1] = (char) 0;
frame_buffer[current_pixel+2] = (char) 128;
}
}
}
}
/* Dscho's versions (slower, but works for bpp != 3 or 4) */
void draw_primary_colours_generic(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2)
{
rfbPixelFormat f=s->rfbServerFormat;
int i,j;
for(j=y1;j<y2;j++)
for(i=x1;i<x2;i++)
if(j<y1*2/3+y2/3)
rfbDrawPixel(s,i,j,f.redMax<<f.redShift);
else if(j<y1/3+y2*2/3)
rfbDrawPixel(s,i,j,f.greenMax<<f.greenShift);
else
rfbDrawPixel(s,i,j,f.blueMax<<f.blueShift);
}
void draw_primary_colours_generic_fast(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2)
{
rfbPixelFormat f=s->rfbServerFormat;
int i,j,y3=(y1*2+y2)/3,y4=(y1+y2*2)/3;
/* draw first pixel */
rfbDrawPixel(s,x1,y1,f.redMax<<f.redShift);
rfbDrawPixel(s,x1,y3,f.greenMax<<f.greenShift);
rfbDrawPixel(s,x1,y4,f.blueMax<<f.blueShift);
/* then copy stripes */
for(j=0;j<y2-y4;j++)
for(i=x1;i<x2;i++) {
#define ADDR(x,y) s->frameBuffer+(x)*bpp+(y)*s->paddedWidthInBytes
memcpy(ADDR(i,j+y1),ADDR(x1,y1),bpp);
memcpy(ADDR(i,j+y3),ADDR(x1,y3),bpp);
memcpy(ADDR(i,j+y4),ADDR(x1,y4),bpp);
}
}
void draw_primary_colours_generic_ultrafast(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2)
{
rfbPixelFormat f=s->rfbServerFormat;
int i,j,y3=(y1*2+y2)/3,y4=(y1+y2*2)/3;
/* fill rectangles */
rfbFillRect(s,x1,y1,x2,y3,f.redMax<<f.redShift);
rfbFillRect(s,x1,y3,x2,y4,f.greenMax<<f.greenShift);
rfbFillRect(s,x1,y4,x2,y2,f.blueMax<<f.blueShift);
}
void linecount (char* frame_buffer)
{
int i,j,k, current_pixel;
for (i=maxy-4; i>maxy-20; i-=4)
for (j=0; j<4; j++) for (k=0; k < maxx; k++) {
current_pixel = (i*j*maxx + k) * bpp;
if (i%2 == 0) {
frame_buffer[current_pixel+0] = (char) 0;
frame_buffer[current_pixel+1] = (char) 0;
frame_buffer[current_pixel+2] = (char) 128;
}
if (i%2 == 1) {
frame_buffer[current_pixel+0] = (char) 128;
frame_buffer[current_pixel+1] = (char) 0;
frame_buffer[current_pixel+2] = (char) 0;
}
}
}
void on_key_press (Bool down,KeySym key,rfbClientPtr cl)
{
if (down) //or else the action occurs on both the press and depress
switch (key) {
case XK_b:
case XK_B:
rfbUndrawCursor(cl->screen);
blank_framebuffer(cl->screen->frameBuffer, 0, 0, maxx, maxy);
rfbDrawString(cl->screen,&radonFont,20,maxy-20,"Hello, World!",0xffffff);
rfbMarkRectAsModified(cl->screen,0, 0,maxx,maxy);
fprintf (stderr, "Framebuffer blanked\n");
break;
case XK_p:
case XK_P:
rfbUndrawCursor(cl->screen);
/* draw_primary_colors (cl->screen->frameBuffer, 0, 0, maxx, maxy); */
draw_primary_colours_generic_ultrafast (cl->screen, 0, 0, maxx, maxy);
rfbMarkRectAsModified(cl->screen,0, 0,maxx,maxy);
fprintf (stderr, "Primary colors displayed\n");
break;
case XK_Q:
case XK_q:
fprintf (stderr, "Exiting now\n");
exit(0);
case XK_C:
case XK_c:
rfbUndrawCursor(cl->screen);
rfbDrawString(cl->screen,&radonFont,20,100,"Hello, World!",0xffffff);
rfbMarkRectAsModified(cl->screen,0, 0,maxx,maxy);
break;
default:
fprintf (stderr, "The %c key was pressed\n", (char) key);
}
}
void on_mouse_event (int buttonMask,int x,int y,rfbClientPtr cl)
{
printf("buttonMask: %i\n"
"x: %i\n" "y: %i\n", buttonMask, x, y);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment