rem: int channels = image->format == RRGBAFormat ? 4 : 3;
add: int channels = (image->format == RRGBAFormat ? 4 : 3);
context: image2StandardPseudoColor(RContext *ctx, RImage *image){    RXImage *ximg;    register int x, y, r, g, b;    unsigned char *ptr;    unsigned long pixel;    unsigned char *data;    unsigned int *rtable, *gtable, *btable;    unsigned int base_pixel = ctx->std_rgb_map->base_pixel;    int channels = image->format == RRGBAFormat ? 4 : 3;    /*register unsigned char maxrgb = 0xff;*/    ximg = RCreateXImage(ctx, ctx->depth, image->width, image->height);    if (!ximg) {	return NULL;    }    ptr = image->data;        data = (unsigned char *)ximg->image->data;    rtable = computeStdTable(ctx->std_rgb_map->red_mult,			     ctx->std_rgb_map->red_max);    gtable = computeStdTable(ctx->std_rgb_map->green_mult,			     ctx->std_rgb_map->green_max);    btable = computeStdTable(ctx->std_rgb_map->blue_mult,			     ctx->std_rgb_map->blue_max);    if (rtable==NULL || gtable==NULL || btable==NULL) {	RErrorCode = RERR_NOMEMORY;        RDestroyXImage(ctx, ximg);        return NULL;    }    if (ctx->attribs->render_mode == RBestMatchRendering) {	for (y=0; y<image->height; y++) {	    for (x=0; x<image->width; x++, ptr+=channels) {		/* reduce pixel */		pixel = (rtable[*ptr] + gtable[*(ptr+1)]			 + btable[*(ptr+2)] + base_pixel) & 0xffffffff;                XPutPixel(ximg->image, x, y, pixel);	    }	}    } else {	/* dither */	signed short *err, *nerr;	signed short *terr;	int rer, ger, ber;	int x1, ofs;#ifdef DEBUG        printf("pseudo color dithering with %d colors per channel\n", cpc);#endif	err = (short*)malloc(3*(image->width+2)*sizeof(short));	nerr = (short*)malloc(3*(image->width+2)*sizeof(short));	if (!err || !nerr) {	    if (err)		free(err);	    if (nerr)		free(nerr);	    RErrorCode = RERR_NOMEMORY;	    RDestroyXImage(ctx, ximg);	    return NULL;	}	for (x=0, x1=0; x<image->width*3; x1+=channels-3) {	    err[x++] = ptr[x1++];	    err[x++] = ptr[x1++];	    err[x++] = ptr[x1++];	}        err[x] = err[x+1] = err[x+2] = 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=(y+1)*image->width*channels;		     x<image->width*3;		     x1+=channels-3) {		    nerr[x++] = ptr[x1++];		    nerr[x++] = ptr[x1++];		    nerr[x++] = ptr[x1++];		}		/* last column */		x1-=channels;		nerr[x++] = ptr[x1++];		nerr[x++] = ptr[x1++];		nerr[x++] = ptr[x1++];	    }	    for (x=0; x<image->width*3; x+=3, ofs++) {		/* reduce pixel */                if (err[x]>0xff) err[x]=0xff; else if (err[x]<0) err[x]=0;                if (err[x+1]>0xff) err[x+1]=0xff; else if (err[x+1]<0) err[x+1]=0;                if (err[x+2]>0xff) err[x+2]=0xff; else if (err[x+2]<0) err[x+2]=0;                r = rtable[err[x]];                g = gtable[err[x+1]];                b = btable[err[x+2]];		pixel = r + g + b;                data[ofs] = base_pixel + pixel;		/* calc error */		rer = err[x] - (ctx->colors[pixel].red>>8);		ger = err[x+1] - (ctx->colors[pixel].green>>8);		ber = err[x+2] - (ctx->colors[pixel].blue>>8);		/* distribute error */		err[x+3*1]+=(rer*7)/16;		err[x+1+3*1]+=(ger*7)/16;		err[x+2+3*1]+=(ber*7)/16;		nerr[x]+=(rer*5)/16;		nerr[x+1]+=(ger*5)/16;		nerr[x+2]+=(ber*5)/16;		if (x>0) {		    nerr[x-3*1]+=(rer*3)/16;		    nerr[x-3*1+1]+=(ger*3)/16;		    nerr[x-3*1+2]+=(ber*3)/16;		}		nerr[x+3*1]+=rer/16;		nerr[x+1+3*1]+=ger/16;		nerr[x+2+3*1]+=ber/16;	    }	    /* skip to next line */	    terr = err;	    err = nerr;	    nerr = terr;	    ofs += ximg->image->bytes_per_line - image->width;	}	free(err);	free(nerr);    }    ximg->image->data = (char*)data;    return ximg;}