--- ray/src/rt/srcdraw.c 2024/07/31 22:21:28 2.26 +++ ray/src/rt/srcdraw.c 2024/08/12 18:57:00 2.27 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: srcdraw.c,v 2.26 2024/07/31 22:21:28 greg Exp $"; +static const char RCSid[] = "$Id: srcdraw.c,v 2.27 2024/08/12 18:57:00 greg Exp $"; #endif /* * Draw small sources into image in case we missed them. @@ -396,7 +396,7 @@ init_drawsources( void /* add sources smaller than rad to computed subimage */ drawsources( COLORV *pic[], /* subimage pixel value array */ - int nc, /* number of target components */ + RGBPRIMP primp, /* output primaries */ float *zbf[], /* subimage distance array (opt.) */ int x0, /* origin and size of subimage */ int xsiz, @@ -404,18 +404,16 @@ drawsources( int ysiz ) { - RREAL spoly[MAXVERT][2], ppoly[MAXVERT][2]; - int nsv, npv; - int xmin, xmax, ymin, ymax, x, y; - RREAL cxy[2]; - COLOR rcol; - double w; - RAY sr; - SPLIST *sp; - int i; - /* check #components */ - if ((nc != 3) & (nc != NCSAMP)) - error(INTERNAL, "unsupported #components in drawsources()"); + const int NC = primp ? 3 : NCSAMP; + RREAL spoly[MAXVERT][2], ppoly[MAXVERT][2]; + int nsv, npv; + int xmin, xmax, ymin, ymax, x, y; + RREAL cxy[2]; + COLOR rcol; + double w; + RAY sr; + SPLIST *sp; + int i; /* check each source in our list */ for (sp = sphead; sp != NULL; sp = sp->next) { /* clip source poly to subimage */ @@ -439,8 +437,8 @@ drawsources( } /* evaluate each pixel in BBox */ for (y = ymin; y <= ymax; y++) { - COLORV *pp = pic[y-y0] + (xmin-x0)*nc; - for (x = xmin; x <= xmax; x++, pp += nc) { + COLORV *pp = pic[y-y0] + (xmin-x0)*NC; + for (x = xmin; x <= xmax; x++, pp += NC) { /* subarea for pixel */ npv = box_clip_poly(spoly, nsv, (double)x/hres, (x+1.)/hres, @@ -460,14 +458,14 @@ drawsources( rayvalue(&sr); /* compute value */ if (sintens(sr.rcol) <= FTINY) continue; /* missed/blocked */ - if (nc == 3) - scolor_rgb(rcol, sr.rcol); + if (NC == 3) + scolor_out(rcol, primp, sr.rcol); /* modify pixel */ w = poly_area(ppoly, npv) * hres * vres; if (zbf[y-y0] != NULL && sr.rxt < 0.99*zbf[y-y0][x-x0]) { zbf[y-y0][x-x0] = sr.rxt; - } else if (nc == 3) { + } else if (NC == 3) { if (!bigdiff(rcol, pp, 0.07)) { scalecolor(pp, w); continue; @@ -476,7 +474,7 @@ drawsources( scalescolor(pp, w); continue; } - if (nc == 3) { + if (NC == 3) { scalecolor(rcol, w); scalecolor(pp, 1.-w); addcolor(pp, rcol);