rem: for (x=0; x<width; x++) {
add: for (x=0; x<image->width; x++) {
context: image2TrueColor(RContext *ctx, RImage *image){    RXImage *ximg;    register int x, y, r, g, b;    unsigned char *red, *grn, *blu;    unsigned long pixel;    unsigned short rmask, gmask, bmask;    unsigned short roffs, goffs, boffs;    unsigned short *rtable, *gtable, *btable;    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];        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;#if 0    /* this do not seem to increase speed. Only 0.06 second faster in     * rendering a 800x600 image to pixmap. 1.12 sec instead of 1.18.     * But does not require a 256*256*256 lookup table.     */    if (ctx->depth==24) {#ifdef DEBUG        puts("true color match for 24bpp");#endif	for (y=0; y < image->height; y++) {	    for (x=0; x < image->width; x++) {                pixel = (*(red++)<<roffs) | (*(grn++)<<goffs) | (*(blu++)<<boffs);		XPutPixel(ximg->image, x, y, pixel);	    }        }        return ximg;    }#endif    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        puts("true color match");#endif	for (y=0; y < image->height; y++) {	    for (x=0; x < image->width; x++) {		/* reduce pixel */                r = rtable[*red++];                g = gtable[*grn++];                b = btable[*blu++];                pixel = (r<<roffs) | (g<<goffs) | (b<<boffs);		XPutPixel(ximg->image, x, y, pixel);	    }	}    } else {        /* dither */	unsigned char *rerr, *gerr, *berr;	unsigned char *nrerr, *ngerr, *nberr;	unsigned char *rerr_, *gerr_, *berr_;	unsigned char *nrerr_, *ngerr_, *nberr_;	unsigned char *terr;	register int ac, err;	int width = image->width;	int dr=0xff-rmask;	int dg=0xff-gmask;        int db=0xff-bmask;	while ((dr & 1)==0) dr = dr >> 1;	while ((dg & 1)==0) dg = dg >> 1;	while ((db & 1)==0) db = db >> 1;#ifdef DEBUG        puts("true color dither");#endif	rerr_ = rerr = (unsigned char*)alloca((width+2)*sizeof(char));	gerr_ = gerr = (unsigned char*)alloca((width+2)*sizeof(char));	berr_ = berr = (unsigned char*)alloca((width+2)*sizeof(char));	nrerr_ = nrerr = (unsigned char*)alloca((width+2)*sizeof(char));	ngerr_ = ngerr = (unsigned char*)alloca((width+2)*sizeof(char));	nberr_ = nberr = (unsigned char*)alloca((width+2)*sizeof(char));	if (!rerr || !gerr || !berr || !nrerr || !ngerr || !nberr) {	    sprintf(RErrorString, "out of memory");	    RDestroyXImage(ctx, ximg);	    return NULL;	}	for (x=0; x<width; x++) {	    rerr[x] = *red++;	    gerr[x] = *grn++;	    berr[x] = *blu++;	}        rerr[x] = gerr[x] = berr[x] = 0;        /* convert and dither the image to XImage */	for (y=0; y<image->height; y++) {	    if (y<image->height-1) {		memcpy(nrerr, red, width);		memcpy(ngerr, grn, width);		memcpy(nberr, blu, width);		red+=width;		grn+=width;		blu+=width;		/* last column */		nrerr[x] = *(red-1);		ngerr[x] = *(grn-1);		nberr[x] = *(blu-1);	    }	    for (x=0; x<width; x++) {		/* reduce pixel */                pixel = (rtable[*rerr]<<roffs) | (gtable[*gerr]<<goffs)		    | (btable[*berr]<<boffs);		XPutPixel(ximg->image, x, y, pixel);		/* calc error */		err = *rerr&dr;		rerr++;		/* distribute error */		ac = errorTable1[err] + *rerr;		*rerr=MIN(ac, 0xff);		ac = errorTable1[err] + *nrerr;		*nrerr=MIN(ac, 0xff);		nrerr++;		ac = *nrerr + errorTable2[err];		*nrerr=MIN(ac,0xff);		/* calc error */		err = *gerr&dg;		gerr++;		/* distribute error */		ac = errorTable1[err] + *gerr;		*gerr=MIN(ac, 0xff);		ac = errorTable1[err] + *ngerr;		*ngerr=MIN(ac, 0xff);		ngerr++;		ac = *ngerr + errorTable2[err];		*ngerr=MIN(ac,0xff);		/* calc error */		err = *berr&db;		berr++;		/* distribute error */		ac = errorTable1[err] + *berr;		*berr=MIN(ac, 0xff);		ac = errorTable1[err] + *nberr;		*nberr=MIN(ac, 0xff);		nberr++;		ac = *nberr + errorTable2[err];		*nberr=MIN(ac,0xff);	    }	    /* skip to next line */	    rerr = nrerr_;	    nrerr = rerr_;	    terr = nrerr_;	    nrerr_ = rerr_;	    rerr_ = terr;	    	    gerr = ngerr_;	    ngerr = gerr_;	    terr = ngerr_;	    ngerr_ = gerr_;	    gerr_ = terr;	    berr = nberr_;	    nberr = berr_;	    terr = nberr_;	    nberr_ = berr_;	    berr_ = terr;	}    }    return ximg;}