rem: for (y=0, ofs=0; y < image->height; y++) { for (x=0; x < image->width; x++, ofs+=channels-3) {  r = rtable[ptr[ofs++]]; g = gtable[ptr[ofs++]]; b = btable[ptr[ofs++]]; pixel = (r<<roffs) | (g<<goffs) | (b<<boffs); XPutPixel(ximg->image, x, y, pixel); } }
add: if (rmask==0xff && gmask==0xff && bmask==0xff) { for (y=0; y < image->height; y++) { for (x=0; x < image->width; x++, ptr+=channels) {  pixel = (*(ptr)<<roffs) | (*(ptr+1)<<goffs) | (*(ptr+2)<<boffs); XPutPixel(ximg->image, x, y, pixel); } } } else { for (y=0, ofs=0; y < image->height; y++) { for (x=0; x < image->width; x++, ofs+=channels-3) {  r = rtable[ptr[ofs++]]; g = gtable[ptr[ofs++]]; b = btable[ptr[ofs++]]; pixel = (r<<roffs) | (g<<goffs) | (b<<boffs); XPutPixel(ximg->image, x, y, pixel); } } }
context: image2TrueColor(RContext *ctx, RImage *image){    RXImage *ximg;    unsigned short rmask, gmask, bmask;    unsigned short roffs, goffs, boffs;    unsigned short *rtable, *gtable, *btable;    int channels = (image->format == RRGBAFormat ? 4 : 3);    ximg = RCreateXImage(ctx, ctx->depth, image->width, image->height);    if (!ximg) {	return NULL;    }    roffs = ctx->red_offset;    goffs = ctx->green_offset;    boffs = ctx->blue_offset;        rmask = ctx->visual->red_mask >> roffs;    gmask = ctx->visual->green_mask >> goffs;    bmask = ctx->visual->blue_mask >> boffs;    rtable = computeTable(rmask);    gtable = computeTable(gmask);    btable = computeTable(bmask);    if (rtable==NULL || gtable==NULL || btable==NULL) {	RErrorCode = RERR_NOMEMORY;        RDestroyXImage(ctx, ximg);        return NULL;    }#ifdef BENCH    cycle_bench(1);#endif    if (ctx->attribs->render_mode==RBestMatchRendering) {	int ofs, r, g, b;	int x, y;	unsigned long pixel;	unsigned char *ptr = image->data;	        /* fake match */#ifdef DEBUG        puts("true color match");#endif	for (y=0, ofs=0; y < image->height; y++) {	    for (x=0; x < image->width; x++, ofs+=channels-3) {		/* reduce pixel */                r = rtable[ptr[ofs++]];                g = gtable[ptr[ofs++]];                b = btable[ptr[ofs++]];                pixel = (r<<roffs) | (g<<goffs) | (b<<boffs);		XPutPixel(ximg->image, x, y, pixel);	    }	}    } else {        /* dither */	const int dr=0xff/rmask;	const int dg=0xff/gmask;        const int db=0xff/bmask;#ifdef DEBUG        puts("true color dither");#endif		{	    char *err;	    char *nerr;	    int ch = image->format == RRGBAFormat ? 4 : 3;	    err = malloc(ch*(image->width+2));	    nerr = malloc(ch*(image->width+2));	    if (!err || !nerr) {		if (nerr)		    free(nerr);		RErrorCode = RERR_NOMEMORY;		RDestroyXImage(ctx, ximg);		return NULL;	    }	    	    memset(err, 0, ch*(image->width+2));	    memset(nerr, 0, ch*(image->width+2));	    convertTrueColor_generic(ximg, image, err, nerr, 				     rtable, gtable, btable,				     dr, dg, db, roffs, goffs, boffs);	    free(err);	    free(nerr);	}    }#ifdef BENCH    cycle_bench(0);#endif    return ximg;}