rem: for (x=0; x<image->width; x++, ptr+=channels-1) {
add: for (x=0; x<image->width; x++, ptr+=channels-3) {
context: image2PseudoColor(RContext *ctx, RImage *image){    RXImage *ximg;    register int x, y, r, g, b;    unsigned char *ptr;    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;    int channels = image->format == RRGBAFormat ? 4 : 3;    ximg = RCreateXImage(ctx, ctx->depth, image->width, image->height);    if (!ximg) {	return NULL;    }    ptr = 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) {	RErrorCode = RERR_NOMEMORY;        RDestroyXImage(ctx, ximg);        return NULL;    }    if (ctx->attribs->render_mode == RBestMatchRendering) {        /* fake match */#ifdef DEBUG        printf("pseudo color match with %d colors per channel\n", cpc);#endif	for (y=0; y<image->height; y++) {	    for (x=0; x<image->width; x++, ptr+=channels-1) {		/* reduce pixel */                r = rtable[*ptr++];                g = gtable[*ptr++];                b = btable[*ptr++];		pixel = r*cpccpc + g*cpc + b;                /*data[ofs] = ctx->colors[pixel].pixel;*/                XPutPixel(ximg->image, x, y, ctx->colors[pixel].pixel);	    }	}    } else {	/* dither */	char *err;	char *nerr;	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	err = malloc(4*(image->width+3));	nerr = malloc(4*(image->width+3));	if (!err || !nerr) {	    if (nerr)		free(nerr);	    RErrorCode = RERR_NOMEMORY;	    RDestroyXImage(ctx, ximg);	    return NULL;	}	memset(err, 0, 4*(image->width+3));	memset(nerr, 0, 4*(image->width+3));	convertPseudoColor_to_8(ximg, image, err+4, nerr+4,				rtable,	gtable,	btable,				dr, dg, db, ctx->pixels, cpc);	free(err);	free(nerr);    }        return ximg;}