p = pixels + i;
p = pixels + k;
void setup_cursors(void) {	rfbCursorPtr rfb_curs;	char *scale = NULL;	int i, j, n = 0;	static int first = 1;	rfbLog("setting up %d cursors...\n", CURS_MAX);	if (first) {		for (i=0; i<CURS_MAX; i++) {			cursors[i] = NULL;		}	}	first = 0;	if (screen) {		screen->cursor = NULL;		LOCK(screen->cursorMutex);	}	for (i=0; i<CURS_MAX; i++) {		cursor_info_t *ci;		if (cursors[i]) {			/* clear out any existing ones: */			ci = cursors[i];			if (ci->rfb) {				/* this is the rfbCursor part: */				if (ci->rfb->richSource) {					free(ci->rfb->richSource);				}				if (ci->rfb->source) {					free(ci->rfb->source);				}				if (ci->rfb->mask) {					free(ci->rfb->mask);				}				free(ci->rfb);			}			if (ci->data) {				free(ci->data);			}			if (ci->mask) {				free(ci->mask);			}			free(ci);		}		/* create new struct: */		ci = (cursor_info_t *) malloc(sizeof(cursor_info_t));		ci->data = NULL; 		ci->mask = NULL; 		ci->wx = 0;		ci->wy = 0;		ci->sx = 0;		ci->sy = 0;		ci->reverse = 0;		ci->rfb = NULL;		cursors[i] = ci;	}	/* clear any xfixes cursor cache (no freeing is done) */	get_xfixes_cursor(1);	/* manually fill in the data+masks: */	cur_empty.data	= curs_empty_data;	cur_empty.mask	= curs_empty_mask;	cur_dot.data	= curs_dot_data;	cur_dot.mask	= curs_dot_mask;	cur_arrow.data	= curs_arrow_data;	cur_arrow.mask	= curs_arrow_mask;	cur_arrow2.data	= curs_arrow2_data;	cur_arrow2.mask	= curs_arrow2_mask;	cur_arrow3.data	= curs_arrow3_data;	cur_arrow3.mask	= curs_arrow3_mask;	cur_arrow4.data	= curs_arrow4_data;	cur_arrow4.mask	= curs_arrow4_mask;	cur_arrow5.data	= curs_arrow5_data;	cur_arrow5.mask	= curs_arrow5_mask;	cur_arrow6.data	= curs_arrow6_data;	cur_arrow6.mask	= curs_arrow6_mask;	cur_root.data	= curs_root_data;	cur_root.mask	= curs_root_mask;	cur_plus.data	= curs_plus_data;	cur_plus.mask	= curs_plus_mask;	cur_fleur.data	= curs_fleur_data;	cur_fleur.mask	= curs_fleur_mask;	cur_xterm.data	= curs_xterm_data;	cur_xterm.mask	= curs_xterm_mask;	curs_copy(cursors[CURS_EMPTY], &cur_empty);	n++;	curs_copy(cursors[CURS_DOT],   &cur_dot);	n++;	if (alt_arrow < 1 || alt_arrow > alt_arrow_max) {		alt_arrow = 1;	}	if (alt_arrow == 1) {		curs_copy(cursors[CURS_ARROW], &cur_arrow);	n++;	} else if (alt_arrow == 2) {		curs_copy(cursors[CURS_ARROW], &cur_arrow2);	n++;	} else if (alt_arrow == 3) {		curs_copy(cursors[CURS_ARROW], &cur_arrow3);	n++;	} else if (alt_arrow == 4) {		curs_copy(cursors[CURS_ARROW], &cur_arrow4);	n++;	} else if (alt_arrow == 5) {		curs_copy(cursors[CURS_ARROW], &cur_arrow5);	n++;	} else if (alt_arrow == 6) {		curs_copy(cursors[CURS_ARROW], &cur_arrow6);	n++;	} else {		alt_arrow = 1;		curs_copy(cursors[CURS_ARROW], &cur_arrow);	n++;	}	curs_copy(cursors[CURS_ROOT], &cur_root);	n++;	curs_copy(cursors[CURS_WM],   &cur_fleur);	n++;	curs_copy(cursors[CURS_TERM], &cur_xterm);	n++;	curs_copy(cursors[CURS_PLUS], &cur_plus);	n++;	if (scale_cursor_str) {		scale = scale_cursor_str;	} else if (scaling && scale_str) {		scale = scale_str;	}	/* scale = NULL zeroes everything */	parse_scale_string(scale, &scale_cursor_fac, &scaling_cursor,	    &scaling_cursor_blend, &j, &j, &scaling_cursor_interpolate,	    &scale_cursor_numer, &scale_cursor_denom);	for (i=0; i<n; i++) {		/* create rfbCursors for the special cursors: */		cursor_info_t *ci = cursors[i];		if (scaling_cursor && scale_cursor_fac != 1.0) {			int w, h, x, y, i;			unsigned long *pixels;			w = ci->wx;			h = ci->wy;			pixels = (unsigned long *) malloc(4*w*h);			i = 0;			for (y=0; y<h; y++) {				for (x=0; x<w; x++) {					char d = ci->data[i];					char m = ci->mask[i];					unsigned long *p;					p = pixels + i;					/* set alpha on */					*p = 0xff000000;					if (d == ' ' && m == ' ') {						/* alpha off */						*p = 0x00000000;					} else if (d != ' ') {						/* body */						if (ci->reverse) {							*p |= 0x00000000;						} else {							*p |= 0x00ffffff;						}					} else if (m != ' ') {						/* edge */						if (ci->reverse) {							*p |= 0x00ffffff;						} else {							*p |= 0x00000000;						}					}					i++;				}			}			rfb_curs = pixels2curs(pixels, w, h, ci->sx, ci->sy,			    bpp/8);			free(pixels);		} else {			/* standard X cursor */			rfb_curs = rfbMakeXCursor(ci->wx, ci->wy,			    ci->data, ci->mask);			if (ci->reverse) {				rfb_curs->foreRed   = 0x0000;				rfb_curs->foreGreen = 0x0000;				rfb_curs->foreBlue  = 0x0000;				rfb_curs->backRed   = 0xffff;				rfb_curs->backGreen = 0xffff;				rfb_curs->backBlue  = 0xffff;			}			rfb_curs->xhot = ci->sx;			rfb_curs->yhot = ci->sy;			rfb_curs->cleanup = FALSE;			rfb_curs->cleanupSource = FALSE;			rfb_curs->cleanupMask = FALSE;			rfb_curs->cleanupRichSource = FALSE;			if (bpp == 8 && indexed_color) {				/*				 * use richsource in PseudoColor for better				 * looking cursors (i.e. two-color).				 */				int x, y, k = 0, bw;				int black = 0, white = 1;				char d, m;				if (dpy) {	/* raw_fb hack */					black = BlackPixel(dpy, scr);					white = WhitePixel(dpy, scr);				}				rfb_curs->richSource				    = (char *)calloc(ci->wx * ci->wy, 1);				for (y = 0; y < ci->wy; y++) {				    for (x = 0; x < ci->wx; x++) {					d = *(ci->data + k);					m = *(ci->mask + k);					if (d == ' ' && m == ' ') {						k++;						continue;					} else if (m != ' ' && d == ' ') {						bw = black;					} else {						bw = white;					}					if (ci->reverse) {						if (bw == black) {							bw = white;						} else {							bw = black;						}					}					*(rfb_curs->richSource+k) =					    (unsigned char) bw;					k++;				    }				}			}		}		ci->rfb = rfb_curs;	}	if (screen) {		UNLOCK(screen->cursorMutex);	}	rfbLog("  done.\n");}