c->richSource = rich;
c->richSource = (unsigned char *) rich;
rfbCursorPtr pixels2curs(unsigned long *pixels, int w, int h,    int xhot, int yhot, int Bpp) {	rfbCursorPtr c;	static unsigned long black = 0, white = 1;	static int first = 1;	char *bitmap, *rich, *alpha;	char *new_pixels = NULL;	int n_opaque, n_trans, n_alpha, len, histo[256];	int send_alpha = 0, alpha_shift, thresh;	int i, x, y;	if (first && dpy) {	/* raw_fb hack */		X_LOCK;		black = BlackPixel(dpy, scr);		white = WhitePixel(dpy, scr);		X_UNLOCK;		first = 0;	}	if (scaling_cursor && scale_cursor_fac != 1.0) {		int W, H;		W = w;		H = h;		w = scale_round(W, scale_cursor_fac);		h = scale_round(H, scale_cursor_fac);		new_pixels = (char *) malloc(4 * w * h);		scale_rect(scale_cursor_fac, scaling_cursor_blend,		    scaling_cursor_interpolate, 4,		    (char *) pixels, 4*W, new_pixels, 4*w,		    W, H, w, h,		    0, 0, W, H, 0);		pixels = (unsigned long *) new_pixels;		xhot = scale_round(xhot, scale_cursor_fac);		yhot = scale_round(yhot, scale_cursor_fac);	}	len = w * h;	/* for bitmap data */	bitmap = (char *)malloc(len+1);	bitmap[len] = '\0';	/* for rich cursor pixel data */	rich  = (char *)calloc(Bpp*len, 1);	alpha = (char *)calloc(1*len, 1);	n_opaque = 0;	n_trans = 0;	n_alpha = 0;	for (i=0; i<256; i++) {		histo[i] = 0;	}	i = 0;	for (y = 0; y < h; y++) {		for (x = 0; x < w; x++) {			unsigned long a;			a = 0xff000000 & (*(pixels+i));			a = a >> 24;	/* alpha channel */			if (a > 0) {				n_alpha++;			}			histo[a]++;			if (a < alpha_threshold) {				n_trans++;			} else {				n_opaque++;			}			i++;		}	}	if (alpha_blend) {		send_alpha = 0;		if (Bpp == 4) {			send_alpha = 1;		}		alpha_shift = 24;		if (main_red_shift == 24 || main_green_shift == 24 ||		    main_blue_shift == 24)  {			alpha_shift = 0;	/* XXX correct? */		}	}	if (n_opaque >= alpha_frac * n_alpha) {		thresh = alpha_threshold;	} else {		n_opaque = 0;		for (i=255; i>=0; i--) {			n_opaque += histo[i];			thresh = i;			if (n_opaque >= alpha_frac * n_alpha) {				break;			}		}	}	i = 0;	for (y = 0; y < h; y++) {		for (x = 0; x < w; x++) {			unsigned long r, g, b, a;			unsigned int ui;			char *p;			a = 0xff000000 & (*(pixels+i));			a = a >> 24;	/* alpha channel */			if (a < thresh) {				bitmap[i] = ' ';			} else {				bitmap[i] = 'x';			}			r = 0x00ff0000 & (*(pixels+i));			g = 0x0000ff00 & (*(pixels+i));			b = 0x000000ff & (*(pixels+i));			r = r >> 16;	/* red */			g = g >> 8;	/* green */			b = b >> 0;	/* blue */			if (alpha_remove && a != 0) {				r = (255 * r) / a;				g = (255 * g) / a;				b = (255 * b) / a;				if (r > 255) r = 255;				if (g > 255) g = 255;				if (b > 255) b = 255;			}			if (indexed_color) {				/*				 * Choose black or white for				 * PseudoColor case.				 */				int value = (r+g+b)/3;				if (value > 127) {					ui = white;				} else {					ui = black;				}			} else {				/*				 * Otherwise map the RGB data onto				 * the framebuffer format:				 */				r = (main_red_max   * r)/255;				g = (main_green_max * g)/255;				b = (main_blue_max  * b)/255;				ui = 0;				ui |= (r << main_red_shift);				ui |= (g << main_green_shift);				ui |= (b << main_blue_shift);				if (send_alpha) {					ui |= (a << alpha_shift);				}			}			/* insert value into rich source: */			p = rich + Bpp*i;			if (Bpp == 1) {				*((unsigned char *)p)				= (unsigned char) ui;			} else if (Bpp == 2) {				*((unsigned short *)p)				= (unsigned short) ui;			} else if (Bpp == 3) {				*((unsigned char *)p)				= (unsigned char) ((ui & 0x0000ff) >> 0);				*((unsigned char *)(p+1))				= (unsigned char) ((ui & 0x00ff00) >> 8);				*((unsigned char *)(p+2))				= (unsigned char) ((ui & 0xff0000) >> 16);			} else if (Bpp == 4) {				*((unsigned int *)p)				= (unsigned int) ui;			}			/* insert alpha value into alpha source: */			p = alpha + i;			*((unsigned char *)p) = (unsigned char) a;			i++;		}	}	/* create the cursor with the bitmap: */	c = rfbMakeXCursor(w, h, bitmap, bitmap);	free(bitmap);	if (new_pixels) {		free(new_pixels);	}	/* set up the cursor parameters: */	c->xhot = xhot;	c->yhot = yhot;	c->cleanup = FALSE;	c->cleanupSource = FALSE;	c->cleanupMask = FALSE;	c->cleanupRichSource = FALSE;	c->richSource = rich;	if (alpha_blend && !indexed_color) {		c->alphaSource = alpha;		c->alphaPreMultiplied = TRUE;	} else {		free(alpha);		c->alphaSource = NULL;	}	return c;}