screen->serverFormat.trueColour = (uint8_t) TRUE;
screen->serverFormat.trueColour = TRUE;  screen->serverFormat.redShift   = 0; screen->serverFormat.greenShift = 0; screen->serverFormat.blueShift  = 0; screen->serverFormat.redMax     = 0; screen->serverFormat.greenMax   = 0; screen->serverFormat.blueMax    = 0;   main_red_shift   = 0; main_green_shift = 0; main_blue_shift  = 0; main_red_max     = 0; main_green_max   = 0; main_blue_max    = 0; main_red_mask    = fb->red_mask; main_green_mask  = fb->green_mask; main_blue_mask   = fb->blue_mask;
void initialize_screen(int *argc, char **argv, XImage *fb) {	int have_masks = 0;	int width  = fb->width;	int height = fb->height;		main_bytes_per_line = fb->bytes_per_line;	main_red_mask   = fb->red_mask;	main_green_mask = fb->green_mask;	main_blue_mask  = fb->blue_mask;	if (scaling) {		double eps = 0.000001;		width  = (int) (width  * scale_fac + eps); 		height = (int) (height * scale_fac + eps); 		if (scale_denom && scaling_pad) {			/* it is not clear this padding is useful anymore */			rfbLog("width  %% denom: %d %% %d = %d\n", width,			    scale_denom, width  % scale_denom);			rfbLog("height %% denom: %d %% %d = %d\n", height,			    scale_denom, height % scale_denom);			if (width % scale_denom != 0) {				int w = width;				w += scale_denom - (w % scale_denom);				if (!scaling_nomult4 && w % 4 != 0) {					/* need to make mult of 4 as well */					int c = 0;						while (w % 4 != 0 && c++ <= 5) {						w += scale_denom;					}				}				width = w;				rfbLog("padded width  to: %d (mult of %d%s\n",				    width, scale_denom, !scaling_nomult4 ?				    " and 4)" : ")");			}			if (height % scale_denom != 0) {				height += scale_denom - (height % scale_denom);				rfbLog("padded height to: %d (mult of %d)\n",				    height, scale_denom);			}		}		if (!scaling_nomult4 && width % 4 != 0 && width > 2) {			/* reset width to be multiple of 4 */			int width0 = width;			if ((width+1) % 4 == 0) {				width = width+1;			} else if ((width-1) % 4 == 0) {				width = width-1;			} else if ((width+2) % 4 == 0) {				width = width+2;			}			rfbLog("reset scaled width %d -> %d to be a multiple of"			    " 4 (to\n", width0, width);			rfbLog("make vncviewers happy). use -scale m/n:n4 to "			    "disable.\n");		}		scaled_x = width;		scaled_y = height;		rfb_bytes_per_line = (main_bytes_per_line / fb->width) * width;		rfbLog("scaling screen: %dx%d -> %dx%d  scale_fac=%.5f\n",		    fb->width, fb->height, scaled_x, scaled_y, scale_fac);	} else {		rfb_bytes_per_line = main_bytes_per_line;	}	screen = rfbGetScreen(argc, argv, width, height, fb->bits_per_pixel,	    8, fb->bits_per_pixel/8);	if (! quiet) {		fprintf(stderr, "\n");	}	if (! screen) {		int i;		rfbLog("\n");		rfbLog("failed to create rfb screen.\n");		for (i=0; i< *argc; i++)  {			rfbLog("\t[%d]  %s\n", i, argv[i]);		}		clean_up_exit(1);	}/* * This ifdef is a transient for source compatibility for people who download * the x11vnc.c file by itself and plop it down into their libvncserver tree. * Remove at some point.  BTW, this assumes no usage of earlier "0.7pre". */#if NON_CVS && defined(LIBVNCSERVER_VERSION)	if (strcmp(LIBVNCSERVER_VERSION, "0.6"))#endif	{ 		if (*argc != 1) {			int i;			rfbLog("*** unrecognized option(s) ***\n");			for (i=1; i< *argc; i++)  {				rfbLog("\t[%d]  %s\n", i, argv[i]);			}			rfbLog("For a list of options run: x11vnc -help\n");			rfbLog("\n");			rfbLog("Here is a list of removed or obsolete"			    " options:\n");			rfbLog("\n");			rfbLog("removed: -hints, -nohints\n");			rfbLog("removed: -cursorposall\n");			rfbLog("\n");			rfbLog("renamed: -old_copytile, use -onetile\n");			rfbLog("renamed: -mouse,   use -cursor\n");			rfbLog("renamed: -mouseX,  use -cursor X\n");			rfbLog("renamed: -X,       use -cursor X\n");			rfbLog("renamed: -nomouse, use -nocursor\n");					clean_up_exit(1);		}	}	screen->paddedWidthInBytes = rfb_bytes_per_line;	screen->serverFormat.bitsPerPixel = fb->bits_per_pixel;	screen->serverFormat.depth = fb->depth;	screen->serverFormat.trueColour = (uint8_t) TRUE;	have_masks = ((fb->red_mask|fb->green_mask|fb->blue_mask) != 0);	if (force_indexed_color) {		have_masks = 0;	}	if ( ! have_masks && screen->serverFormat.bitsPerPixel == 8	    && CellsOfScreen(ScreenOfDisplay(dpy,scr)) ) {		/* indexed colour */		if (!quiet) {			rfbLog("X display %s is 8bpp indexed color\n",			    DisplayString(dpy));			if (! flash_cmap && ! overlay) {				rfbLog("\n");				rfbLog("In 8bpp PseudoColor mode if you "				    "experience color\n");				rfbLog("problems you may want to enable "				    "following the\n");				rfbLog("changing colormap by using the "				    "-flashcmap option.\n");				rfbLog("\n");			}		}		indexed_colour = 1;		set_colormap();	} else {		/* general case ... */		if (! quiet) {			rfbLog("X display %s is %dbpp depth=%d true "			    "color\n", DisplayString(dpy), fb->bits_per_pixel,			    fb->depth);		}		/* convert masks to bit shifts and max # colors */		screen->serverFormat.redShift = 0;		if ( fb->red_mask ) {			while ( ! (fb->red_mask			    & (1 << screen->serverFormat.redShift) ) ) {				    screen->serverFormat.redShift++;			}		}		screen->serverFormat.greenShift = 0;		if ( fb->green_mask ) {			while ( ! (fb->green_mask			    & (1 << screen->serverFormat.greenShift) ) ) {				    screen->serverFormat.greenShift++;			}		}		screen->serverFormat.blueShift = 0;		if ( fb->blue_mask ) {			while ( ! (fb->blue_mask			    & (1 << screen->serverFormat.blueShift) ) ) {				    screen->serverFormat.blueShift++;			}		}		screen->serverFormat.redMax		    = fb->red_mask >> screen->serverFormat.redShift;		screen->serverFormat.greenMax		    = fb->green_mask >> screen->serverFormat.greenShift;		screen->serverFormat.blueMax		    = fb->blue_mask >> screen->serverFormat.blueShift;		main_red_max   = screen->serverFormat.redMax;		main_green_max = screen->serverFormat.greenMax;		main_blue_max  = screen->serverFormat.blueMax;		main_red_shift   = screen->serverFormat.redShift;		main_green_shift = screen->serverFormat.greenShift;		main_blue_shift  = screen->serverFormat.blueShift;	}	if (overlay && ! quiet) {		rfbLog("\n");		rfbLog("Overlay mode enabled:  If you experience color\n");		rfbLog("problems when popup menus are on the screen, try\n");		rfbLog("disabling SaveUnders in your X server, one way is\n");		rfbLog("to start the X server with the '-su' option, e.g.:\n");		rfbLog("Xsun -su ... see Xserver(1), xinit(1) for more info.\n");		rfbLog("\n");	}	/* nofb is for pointer/keyboard only handling.  */	if (nofb) {		main_fb = NULL;		rfb_fb = main_fb;		screen->displayHook = nofb_hook;	} else {		main_fb = fb->data;		if (scaling) {			rfb_fb = (char *) malloc(rfb_bytes_per_line * height);			memset(rfb_fb, 0, rfb_bytes_per_line * height);		} else {			rfb_fb = main_fb;		}	}	screen->frameBuffer = rfb_fb;	/* called from inetd, we need to treat stdio as our socket */	if (inetd) {		int fd = dup(0);		if (fd < 3) {			rfbErr("dup(0) = %d failed.\n", fd);			rfbLogPerror("dup");			clean_up_exit(1);		}		fclose(stdin);		fclose(stdout);		/* we keep stderr for logging */		screen->inetdSock = fd;		screen->port = 0;	} else if (! got_rfbport) {		screen->autoPort = TRUE;	}	if (! got_nevershared && ! got_alwaysshared) {		if (shared) {			screen->alwaysShared = TRUE;		} else {			screen->dontDisconnect = TRUE;			screen->neverShared = TRUE;		}	}	/* XXX the following is based on libvncserver defaults. */	if (screen->deferUpdateTime == 5) {		/* XXX will be fixed someday */		screen->deferUpdateTime = defer_update;	}	/* event callbacks: */	screen->newClientHook = new_client;	screen->kbdAddEvent = keyboard;	screen->ptrAddEvent = pointer;	if (watch_selection) {		screen->setXCutText = xcut_receive;	}	setup_cursors();	if (! show_cursor) {		screen->cursor = NULL;	} else {		screen->cursor = cursors[0]->rfb;	}	rfbInitServer(screen);	bpp = screen->serverFormat.bitsPerPixel;	depth = screen->serverFormat.depth;	if (scaling) {		mark_rect_as_modified(0, 0, dpy_x, dpy_y, 0);	}	if (viewonly_passwd) {		/* append the view only passwd after the normal passwd */		char **passwds_new = malloc(3*sizeof(char**));		char **passwds_old = (char **) screen->authPasswdData;		passwds_new[0] = passwds_old[0];		passwds_new[1] = viewonly_passwd;		passwds_new[2] = NULL;		screen->authPasswdData = (void*) passwds_new;	}}