add: ximg->image->data = (char*)data;
context: image2PseudoColor(RContext *ctx, RImage *image){    RXImage *ximg;    register int x, y, r, g, b;    unsigned char *red, *grn, *blu;    unsigned long pixel;    const int cpc=ctx->attribs->colors_per_channel;    const unsigned short rmask = cpc-1; /* different sizes could be used */    const unsigned short gmask = rmask; /* for r,g,b */    const unsigned short bmask = rmask;    unsigned short *rtable, *gtable, *btable;    const int cpccpc = cpc*cpc;    unsigned char *data;    int ofs;    /*register unsigned char maxrgb = 0xff;*/    ximg = RCreateXImage(ctx, ctx->depth, image->width, image->height);    if (!ximg) {	return NULL;    }    red = image->data[0];    grn = image->data[1];    blu = image->data[2];    data = ximg->image->data;    /* Tables are same at the moment because rmask==gmask==bmask. */    rtable = computeTable(rmask);    gtable = computeTable(gmask);    btable = computeTable(bmask);    if (rtable==NULL || gtable==NULL || btable==NULL) {        sprintf(RErrorString, "out of memory");        RDestroyXImage(ctx, ximg);        return NULL;    }    if (ctx->attribs->render_mode == RM_MATCH) {        /* fake match */#ifdef DEBUG        printf("pseudo color match with %d colors per channel\n", cpc);#endif	for (y=0, ofs = 0; y<image->height; y++) {	    for (x=0; x<image->width; x++, ofs++) {		/* reduce pixel */                r = rtable[red[ofs]];                g = gtable[grn[ofs]];                b = btable[blu[ofs]];		pixel = r*cpccpc + g*cpc + b;                /*data[ofs] = ctx->colors[pixel].pixel;*/                XPutPixel(ximg->image, x, y, ctx->colors[pixel].pixel);	    }	}    } else {	/* dither */	short *rerr, *gerr, *berr;	short *nrerr, *ngerr, *nberr;	short *terr;	int rer, ger, ber;	const int dr=0xff/rmask;	const int dg=0xff/gmask;	const int db=0xff/bmask;#ifdef DEBUG        printf("pseudo color dithering with %d colors per channel\n", cpc);#endif	rerr = (short*)alloca((image->width+2)*sizeof(short));	gerr = (short*)alloca((image->width+2)*sizeof(short));	berr = (short*)alloca((image->width+2)*sizeof(short));	nrerr = (short*)alloca((image->width+2)*sizeof(short));	ngerr = (short*)alloca((image->width+2)*sizeof(short));	nberr = (short*)alloca((image->width+2)*sizeof(short));	if (!rerr || !gerr || !berr || !nrerr || !ngerr || !nberr) {	    sprintf(RErrorString, "out of memory");	    RDestroyXImage(ctx, ximg);	    return NULL;	}	for (x=0; x<image->width; x++) {	    rerr[x] = red[x];	    gerr[x] = grn[x];	    berr[x] = blu[x];	}        rerr[x] = gerr[x] = berr[x] = 0;	/* convert and dither the image to XImage */	for (y=0, ofs=0; y<image->height; y++) {	    if (y<image->height-1) {		int x1;		for (x=0, x1=ofs+image->width; x<image->width; x++, x1++) {		    nrerr[x] = red[x1];		    ngerr[x] = grn[x1];		    nberr[x] = blu[x1];		}		/* last column */		x1--;		nrerr[x] = red[x1];		ngerr[x] = grn[x1];		nberr[x] = blu[x1];	    }	    for (x=0; x<image->width; x++, ofs++) {		/* reduce pixel */                if (rerr[x]>0xff) rerr[x]=0xff; else if (rerr[x]<0) rerr[x]=0;                if (gerr[x]>0xff) gerr[x]=0xff; else if (gerr[x]<0) gerr[x]=0;                if (berr[x]>0xff) berr[x]=0xff; else if (berr[x]<0) berr[x]=0;                r = rtable[rerr[x]];                g = gtable[gerr[x]];                b = btable[berr[x]];		pixel = r*cpccpc + g*cpc + b;                /*data[ofs] = ctx->colors[pixel].pixel;*/                XPutPixel(ximg->image, x, y, ctx->colors[pixel].pixel);		/* calc error */		rer = rerr[x] - r*dr;		ger = gerr[x] - g*dg;		ber = berr[x] - b*db;		/* distribute error */		r = (rer*3)/8;		g = (ger*3)/8;		b = (ber*3)/8;		/* x+1, y */		rerr[x+1]+=r;		gerr[x+1]+=g;		berr[x+1]+=b;		/* x, y+1 */		nrerr[x]+=r;		ngerr[x]+=g;		nberr[x]+=b;		/* x+1, y+1 */		nrerr[x+1]+=rer-2*r;		ngerr[x+1]+=ger-2*g;		nberr[x+1]+=ber-2*b;	    }	    /* skip to next line */	    terr = rerr;	    rerr = nrerr;	    nrerr = terr;	    terr = gerr;	    gerr = ngerr;	    ngerr = terr;	    terr = berr;	    berr = nberr;	    nberr = terr;	}    }    return ximg;}