| 18 |  |  | 
| 19 |  | static const char       rmx_mismatch_warn[] = "WARNING: data type mismatch\n"; | 
| 20 |  |  | 
| 21 | – | #define array_size(rm)  (sizeof(double)*(rm)->nrows*(rm)->ncols*(rm)->ncomp) | 
| 22 | – | #define mapped_size(rm) ((char *)(rm)->mtx + array_size(rm) - (char *)(rm)->mapped) | 
| 23 | – |  | 
| 21 |  | /* Initialize a RMATRIX struct but don't allocate array space */ | 
| 22 |  | RMATRIX * | 
| 23 | < | rmx_new(int nr, int nc, int n) | 
| 23 | > | rmx_new(int nr, int nc, int ncomp) | 
| 24 |  | { | 
| 25 |  | RMATRIX *dnew; | 
| 26 |  |  | 
| 27 | < | if (n <= 0) | 
| 27 | > | if (ncomp <= 0) | 
| 28 |  | return(NULL); | 
| 29 |  |  | 
| 30 |  | dnew = (RMATRIX *)calloc(1, sizeof(RMATRIX)); | 
| 31 | < | if (dnew) { | 
| 32 | < | dnew->dtype = DTdouble; | 
| 33 | < | dnew->nrows = nr; | 
| 34 | < | dnew->ncols = nc; | 
| 35 | < | dnew->ncomp = n; | 
| 36 | < | setcolor(dnew->cexp, 1.f, 1.f, 1.f); | 
| 37 | < | memcpy(dnew->wlpart, WLPART, sizeof(dnew->wlpart)); | 
| 38 | < | } | 
| 31 | > | if (!dnew) | 
| 32 | > | return(NULL); | 
| 33 | > |  | 
| 34 | > | dnew->dtype = DTrmx_native; | 
| 35 | > | dnew->nrows = nr; | 
| 36 | > | dnew->ncols = nc; | 
| 37 | > | dnew->ncomp = ncomp; | 
| 38 | > | setcolor(dnew->cexp, 1.f, 1.f, 1.f); | 
| 39 | > | memcpy(dnew->wlpart, WLPART, sizeof(dnew->wlpart)); | 
| 40 | > |  | 
| 41 |  | return(dnew); | 
| 42 |  | } | 
| 43 |  |  | 
| 46 |  | rmx_prepare(RMATRIX *rm) | 
| 47 |  | { | 
| 48 |  | if (!rm) return(0); | 
| 49 | < | if (rm->mtx) | 
| 49 | > | if (rm->mtx)                    /* assume it's right size */ | 
| 50 |  | return(1); | 
| 51 |  | if ((rm->nrows <= 0) | (rm->ncols <= 0) | (rm->ncomp <= 0)) | 
| 52 |  | return(0); | 
| 53 | < | rm->mtx = (double *)malloc(array_size(rm)); | 
| 53 | > | rm->mtx = (rmx_dtype *)malloc(rmx_array_size(rm)); | 
| 54 | > | rm->pflags |= RMF_FREEMEM; | 
| 55 |  | return(rm->mtx != NULL); | 
| 56 |  | } | 
| 57 |  |  | 
| 58 |  | /* Call rmx_new() and rmx_prepare() */ | 
| 59 |  | RMATRIX * | 
| 60 | < | rmx_alloc(int nr, int nc, int n) | 
| 60 | > | rmx_alloc(int nr, int nc, int ncomp) | 
| 61 |  | { | 
| 62 | < | RMATRIX *dnew = rmx_new(nr, nc, n); | 
| 62 | > | RMATRIX *dnew = rmx_new(nr, nc, ncomp); | 
| 63 |  |  | 
| 64 | < | if (dnew && !rmx_prepare(dnew)) { | 
| 64 | > | if (!rmx_prepare(dnew)) { | 
| 65 |  | rmx_free(dnew); | 
| 66 | < | dnew = NULL; | 
| 66 | > | return(NULL); | 
| 67 |  | } | 
| 68 |  | return(dnew); | 
| 69 |  | } | 
| 77 |  | free(rm->info); | 
| 78 |  | rm->info = NULL; | 
| 79 |  | } | 
| 80 | – | if (rm->mtx) { | 
| 80 |  | #ifdef MAP_FILE | 
| 81 | < | if (rm->mapped) { | 
| 82 | < | munmap(rm->mapped, mapped_size(rm)); | 
| 83 | < | rm->mapped = NULL; | 
| 84 | < | } else | 
| 81 | > | if (rm->mapped) { | 
| 82 | > | munmap(rm->mapped, rmx_mapped_size(rm)); | 
| 83 | > | rm->mapped = NULL; | 
| 84 | > | } else | 
| 85 |  | #endif | 
| 86 | < | free(rm->mtx); | 
| 87 | < | rm->mtx = NULL; | 
| 86 | > | if (rm->pflags & RMF_FREEMEM) { | 
| 87 | > | free(rm->mtx); | 
| 88 | > | rm->pflags &= ~RMF_FREEMEM; | 
| 89 |  | } | 
| 90 | + | rm->mtx = NULL; | 
| 91 |  | } | 
| 92 |  |  | 
| 93 |  | /* Free an RMATRIX struct and data */ | 
| 116 |  | int | 
| 117 |  | rmx_addinfo(RMATRIX *rm, const char *info) | 
| 118 |  | { | 
| 119 | < | int     oldlen = 0; | 
| 119 | > | size_t  oldlen = 0; | 
| 120 |  |  | 
| 121 |  | if (!rm || !info || !*info) | 
| 122 |  | return(0); | 
| 123 |  | if (!rm->info) { | 
| 124 |  | rm->info = (char *)malloc(strlen(info)+1); | 
| 124 | – | if (rm->info) rm->info[0] = '\0'; | 
| 125 |  | } else { | 
| 126 |  | oldlen = strlen(rm->info); | 
| 127 |  | rm->info = (char *)realloc(rm->info, | 
| 140 |  | char    fmt[MAXFMTLEN]; | 
| 141 |  | int     i; | 
| 142 |  |  | 
| 143 | < | if (headidval(NULL, s)) | 
| 143 | > | if (isheadid(s)) | 
| 144 |  | return(0); | 
| 145 |  | if (isncomp(s)) { | 
| 146 |  | ip->ncomp = ncompval(s); | 
| 147 | < | return(0); | 
| 147 | > | return(ip->ncomp - 1); | 
| 148 |  | } | 
| 149 |  | if (!strncmp(s, "NROWS=", 6)) { | 
| 150 |  | ip->nrows = atoi(s+6); | 
| 151 | < | return(0); | 
| 151 | > | return(ip->nrows - 1); | 
| 152 |  | } | 
| 153 |  | if (!strncmp(s, "NCOLS=", 6)) { | 
| 154 |  | ip->ncols = atoi(s+6); | 
| 155 | < | return(0); | 
| 155 | > | return(ip->ncols - 1); | 
| 156 |  | } | 
| 157 |  | if ((i = isbigendian(s)) >= 0) { | 
| 158 | < | ip->swapin = (nativebigendian() != i); | 
| 158 | > | if (nativebigendian() != i) | 
| 159 | > | ip->pflags |= RMF_SWAPIN; | 
| 160 | > | else | 
| 161 | > | ip->pflags &= ~RMF_SWAPIN; | 
| 162 |  | return(0); | 
| 163 |  | } | 
| 164 |  | if (isexpos(s)) { | 
| 165 |  | float   f = exposval(s); | 
| 166 |  | scalecolor(ip->cexp, f); | 
| 167 | < | return(0); | 
| 167 | > | return(f > .0 ? 0 : -1); | 
| 168 |  | } | 
| 169 |  | if (iscolcor(s)) { | 
| 170 |  | COLOR   ctmp; | 
| 171 | < | colcorval(ctmp, s); | 
| 171 | > | if (!colcorval(ctmp, s)) return(-1); | 
| 172 |  | multcolor(ip->cexp, ctmp); | 
| 173 |  | return(0); | 
| 174 |  | } | 
| 175 | < | if (iswlsplit(s)) { | 
| 176 | < | wlsplitval(ip->wlpart, s); | 
| 177 | < | return(0); | 
| 175 | < | } | 
| 175 | > | if (iswlsplit(s)) | 
| 176 | > | return(wlsplitval(ip->wlpart, s) - 1); | 
| 177 | > |  | 
| 178 |  | if (!formatval(fmt, s)) { | 
| 179 |  | rmx_addinfo(ip, s); | 
| 180 |  | return(0); | 
| 184 |  | ip->dtype = i; | 
| 185 |  | return(0); | 
| 186 |  | } | 
| 187 | < | return(-1); | 
| 187 | > | return(-1);             /* bad format */ | 
| 188 |  | } | 
| 189 |  |  | 
| 190 |  | static int | 
| 191 | < | rmx_load_ascii(double *drp, const RMATRIX *rm, FILE *fp) | 
| 191 | > | rmx_load_ascii(rmx_dtype *drp, const RMATRIX *rm, FILE *fp) | 
| 192 |  | { | 
| 193 |  | int     j, k; | 
| 194 |  |  | 
| 195 |  | for (j = 0; j < rm->ncols; j++) | 
| 196 |  | for (k = rm->ncomp; k-- > 0; ) | 
| 197 | < | if (fscanf(fp, "%lf", drp++) != 1) | 
| 197 | > | if (fscanf(fp, rmx_scanfmt, drp++) != 1) | 
| 198 |  | return(0); | 
| 199 |  | return(1); | 
| 200 |  | } | 
| 201 |  |  | 
| 202 |  | static int | 
| 203 | < | rmx_load_float(double *drp, const RMATRIX *rm, FILE *fp) | 
| 203 | > | rmx_load_float(rmx_dtype *drp, const RMATRIX *rm, FILE *fp) | 
| 204 |  | { | 
| 205 | + | #if DTrmx_native==DTfloat | 
| 206 | + | if (getbinary(drp, sizeof(*drp)*rm->ncomp, rm->ncols, fp) != rm->ncols) | 
| 207 | + | return(0); | 
| 208 | + | if (rm->pflags & RMF_SWAPIN) | 
| 209 | + | swap32((char *)drp, rm->ncols*rm->ncomp); | 
| 210 | + | #else | 
| 211 |  | int     j, k; | 
| 212 | < | float   val[100]; | 
| 212 | > | float   val[MAXCOMP]; | 
| 213 |  |  | 
| 214 | < | if (rm->ncomp > 100) { | 
| 214 | > | if (rm->ncomp > MAXCOMP) { | 
| 215 |  | fputs("Unsupported # components in rmx_load_float()\n", stderr); | 
| 216 |  | exit(1); | 
| 217 |  | } | 
| 218 |  | for (j = 0; j < rm->ncols; j++) { | 
| 219 |  | if (getbinary(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) | 
| 220 |  | return(0); | 
| 221 | < | if (rm->swapin) | 
| 221 | > | if (rm->pflags & RMF_SWAPIN) | 
| 222 |  | swap32((char *)val, rm->ncomp); | 
| 223 |  | for (k = 0; k < rm->ncomp; k++) | 
| 224 |  | *drp++ = val[k]; | 
| 225 |  | } | 
| 226 | + | #endif | 
| 227 |  | return(1); | 
| 228 |  | } | 
| 229 |  |  | 
| 230 |  | static int | 
| 231 | < | rmx_load_double(double *drp, const RMATRIX *rm, FILE *fp) | 
| 231 | > | rmx_load_double(rmx_dtype *drp, const RMATRIX *rm, FILE *fp) | 
| 232 |  | { | 
| 233 | + | #if DTrmx_native==DTdouble | 
| 234 |  | if (getbinary(drp, sizeof(*drp)*rm->ncomp, rm->ncols, fp) != rm->ncols) | 
| 235 |  | return(0); | 
| 236 | < | if (rm->swapin) | 
| 236 | > | if (rm->pflags & RMF_SWAPIN) | 
| 237 |  | swap64((char *)drp, rm->ncols*rm->ncomp); | 
| 238 | + | #else | 
| 239 | + | int     j, k; | 
| 240 | + | double  val[MAXCOMP]; | 
| 241 | + |  | 
| 242 | + | if (rm->ncomp > MAXCOMP) { | 
| 243 | + | fputs("Unsupported # components in rmx_load_double()\n", stderr); | 
| 244 | + | exit(1); | 
| 245 | + | } | 
| 246 | + | for (j = 0; j < rm->ncols; j++) { | 
| 247 | + | if (getbinary(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) | 
| 248 | + | return(0); | 
| 249 | + | if (rm->pflags & RMF_SWAPIN) | 
| 250 | + | swap64((char *)val, rm->ncomp); | 
| 251 | + | for (k = 0; k < rm->ncomp; k++) | 
| 252 | + | *drp++ = (float)val[k]; | 
| 253 | + | } | 
| 254 | + | #endif | 
| 255 |  | return(1); | 
| 256 |  | } | 
| 257 |  |  | 
| 258 |  | static int | 
| 259 | < | rmx_load_rgbe(double *drp, const RMATRIX *rm, FILE *fp) | 
| 259 | > | rmx_load_rgbe(rmx_dtype *drp, const RMATRIX *rm, FILE *fp) | 
| 260 |  | { | 
| 261 |  | COLR    *scan; | 
| 262 |  | COLOR   col; | 
| 279 |  | } | 
| 280 |  |  | 
| 281 |  | static int | 
| 282 | < | rmx_load_spec(double *drp, const RMATRIX *rm, FILE *fp) | 
| 282 | > | rmx_load_spec(rmx_dtype *drp, const RMATRIX *rm, FILE *fp) | 
| 283 |  | { | 
| 284 | < | uby8    *scan; | 
| 285 | < | SCOLOR  scol; | 
| 284 | > | COLRV   *scan; | 
| 285 | > | COLORV  scol[MAXCOMP]; | 
| 286 |  | int     j, k; | 
| 287 |  |  | 
| 288 | < | if ((rm->ncomp < 3) | (rm->ncomp > MAXCSAMP)) | 
| 288 | > | if ((rm->ncomp < 3) | (rm->ncomp > MAXCOMP)) | 
| 289 |  | return(0); | 
| 290 | < | scan = (uby8 *)tempbuffer((rm->ncomp+1)*rm->ncols); | 
| 290 | > | scan = (COLRV *)tempbuffer((rm->ncomp+1)*rm->ncols); | 
| 291 |  | if (!scan) | 
| 292 |  | return(0); | 
| 293 |  | if (freadscolrs(scan, rm->ncomp, rm->ncols, fp) < 0) | 
| 312 |  | rm->ncomp = 3; | 
| 313 |  | setcolor(rm->cexp, 1.f, 1.f, 1.f); | 
| 314 |  | memcpy(rm->wlpart, WLPART, sizeof(rm->wlpart)); | 
| 315 | < | rm->swapin = 0; | 
| 315 | > | rm->pflags = 0; | 
| 316 |  | } | 
| 317 |  | rm->dtype = DTascii;                    /* assumed w/o FORMAT */ | 
| 318 |  | if (getheader(fp, get_dminfo, rm) < 0) { | 
| 319 | < | fputs("Unrecognized matrix format\n", stderr); | 
| 319 | > | fputs("Bad matrix header\n", stderr); | 
| 320 |  | return(0); | 
| 321 |  | } | 
| 322 |  | if ((rm->dtype == DTrgbe) | (rm->dtype == DTxyze) && | 
| 332 |  | return(1); | 
| 333 |  | } | 
| 334 |  |  | 
| 335 | < | /* Load next row as double (cannot be XML) */ | 
| 335 | > | /* Load next row as rmx_dtype (cannot be XML) */ | 
| 336 |  | int | 
| 337 | < | rmx_load_row(double *drp, const RMATRIX *rm, FILE *fp) | 
| 337 | > | rmx_load_row(rmx_dtype *drp, const RMATRIX *rm, FILE *fp) | 
| 338 |  | { | 
| 339 |  | switch (rm->dtype) { | 
| 340 |  | case DTascii: | 
| 361 |  | int     i; | 
| 362 |  | #ifdef MAP_FILE | 
| 363 |  | long    pos;            /* map memory for file > 1MB if possible */ | 
| 364 | < | if ((rm->dtype == DTdouble) & !rm->swapin && array_size(rm) >= 1L<<20 && | 
| 365 | < | (pos = ftell(fp)) >= 0 && !(pos % sizeof(double))) { | 
| 366 | < | rm->mapped = mmap(NULL, array_size(rm)+pos, PROT_READ|PROT_WRITE, | 
| 364 | > | if ((rm->dtype == DTrmx_native) & !(rm->pflags & RMF_SWAPIN) & | 
| 365 | > | (rmx_array_size(rm) >= 1L<<20) && | 
| 366 | > | (pos = ftell(fp)) >= 0 && !(pos % sizeof(rmx_dtype))) { | 
| 367 | > | rm->mapped = mmap(NULL, rmx_array_size(rm)+pos, PROT_READ|PROT_WRITE, | 
| 368 |  | MAP_PRIVATE, fileno(fp), 0); | 
| 369 |  | if (rm->mapped != MAP_FAILED) { | 
| 370 | < | rm->mtx = (double *)rm->mapped + pos/sizeof(double); | 
| 370 | > | if (rm->pflags & RMF_FREEMEM) | 
| 371 | > | free(rm->mtx); | 
| 372 | > | rm->mtx = (rmx_dtype *)rm->mapped + pos/sizeof(rmx_dtype); | 
| 373 | > | rm->pflags &= ~RMF_FREEMEM; | 
| 374 |  | return(1); | 
| 375 |  | }               /* else fall back on reading into memory */ | 
| 376 |  | rm->mapped = NULL; | 
| 378 |  | #endif | 
| 379 |  | if (!rmx_prepare(rm)) { /* need in-core matrix array */ | 
| 380 |  | fprintf(stderr, "Cannot allocate %g MByte matrix array\n", | 
| 381 | < | (1./(1L<<20))*(double)array_size(rm)); | 
| 381 | > | (1./(1L<<20))*(double)rmx_array_size(rm)); | 
| 382 |  | return(0); | 
| 383 |  | } | 
| 384 |  | for (i = 0; i < rm->nrows; i++) | 
| 389 |  |  | 
| 390 |  | /* Load matrix from supported file type */ | 
| 391 |  | RMATRIX * | 
| 392 | < | rmx_load(const char *inspec, RMPref rmp) | 
| 392 | > | rmx_load(const char *inspec) | 
| 393 |  | { | 
| 394 |  | FILE            *fp; | 
| 395 |  | RMATRIX         *dnew; | 
| 403 |  | fp = stdin; | 
| 404 |  | else if (inspec[0] == '!') | 
| 405 |  | fp = popen(inspec+1, "r"); | 
| 406 | < | else if (rmp != RMPnone) { | 
| 376 | < | const char      *sp = inspec;   /* check suffix */ | 
| 377 | < | while (*sp) | 
| 378 | < | ++sp; | 
| 379 | < | while (sp > inspec && sp[-1] != '.') | 
| 380 | < | --sp; | 
| 381 | < | if (!strcasecmp(sp, "XML")) {   /* assume it's a BSDF */ | 
| 382 | < | CMATRIX *cm = rmp==RMPtrans ? cm_loadBTDF(inspec) : | 
| 383 | < | cm_loadBRDF(inspec, rmp==RMPreflB) ; | 
| 384 | < | if (!cm) | 
| 385 | < | return(NULL); | 
| 386 | < | dnew = rmx_from_cmatrix(cm); | 
| 387 | < | cm_free(cm); | 
| 388 | < | dnew->dtype = DTascii; | 
| 389 | < | return(dnew);           /* return here */ | 
| 390 | < | }                               /* else open it ourselves */ | 
| 406 | > | else | 
| 407 |  | fp = fopen(inspec, "r"); | 
| 408 | < | } | 
| 409 | < | if (!fp) | 
| 408 | > | if (!fp) { | 
| 409 | > | fprintf(stderr, "Cannot open for reading: %s\n", inspec); | 
| 410 |  | return(NULL); | 
| 411 | + | } | 
| 412 |  | #ifdef getc_unlocked | 
| 413 |  | flockfile(fp); | 
| 414 |  | #endif | 
| 424 |  |  | 
| 425 |  | if (fp != stdin) {                      /* close input stream */ | 
| 426 |  | if (inspec[0] == '!') | 
| 427 | < | pclose(fp); | 
| 427 | > | ok &= pclose(fp)==0; | 
| 428 |  | else | 
| 429 |  | fclose(fp); | 
| 430 |  | } | 
| 440 |  | /* undo exposure? */ | 
| 441 |  | if ((dnew->cexp[0] != 1.f) | | 
| 442 |  | (dnew->cexp[1] != 1.f) | (dnew->cexp[2] != 1.f)) { | 
| 443 | < | double  cmlt[MAXCSAMP]; | 
| 443 | > | double  cmlt[MAXCOMP]; | 
| 444 |  | int     i; | 
| 445 | < | cmlt[0] = 1./dnew->cexp[0]; | 
| 429 | < | cmlt[1] = 1./dnew->cexp[1]; | 
| 430 | < | cmlt[2] = 1./dnew->cexp[2]; | 
| 431 | < | if (dnew->ncomp > MAXCSAMP) { | 
| 445 | > | if (dnew->ncomp > MAXCOMP) { | 
| 446 |  | fprintf(stderr, "Excess spectral components in: %s\n", | 
| 447 |  | inspec); | 
| 448 |  | rmx_free(dnew); | 
| 449 |  | return(NULL); | 
| 450 |  | } | 
| 451 | + | cmlt[0] = 1./dnew->cexp[0]; | 
| 452 | + | cmlt[1] = 1./dnew->cexp[1]; | 
| 453 | + | cmlt[2] = 1./dnew->cexp[2]; | 
| 454 |  | for (i = dnew->ncomp; i-- > 3; ) | 
| 455 | < | cmlt[i] = cmlt[1]; | 
| 455 | > | cmlt[i] = cmlt[1];      /* XXX hack! */ | 
| 456 |  | rmx_scale(dnew, cmlt); | 
| 457 |  | setcolor(dnew->cexp, 1.f, 1.f, 1.f); | 
| 458 |  | } | 
| 459 |  | return(dnew); | 
| 460 |  | } | 
| 461 |  |  | 
| 462 | + | #if DTrmx_native==DTdouble | 
| 463 |  | static int | 
| 464 | < | rmx_write_ascii(const double *dp, int nc, int len, FILE *fp) | 
| 464 | > | rmx_write_float(const rmx_dtype *dp, int len, FILE *fp) | 
| 465 |  | { | 
| 466 | < | while (len-- > 0) { | 
| 467 | < | int     k = nc; | 
| 468 | < | while (nc-- > 0) | 
| 469 | < | fprintf(fp, " %.7e", *dp++); | 
| 470 | < | fputc('\t', fp); | 
| 466 | > | float   val; | 
| 467 | > |  | 
| 468 | > | while (len--) { | 
| 469 | > | val = (float)*dp++; | 
| 470 | > | if (putbinary(&val, sizeof(val), 1, fp) != 1) | 
| 471 | > | return(0); | 
| 472 |  | } | 
| 473 | < | return(fputc('\n', fp) != EOF); | 
| 473 | > | return(1); | 
| 474 |  | } | 
| 475 | < |  | 
| 475 | > | #else | 
| 476 |  | static int | 
| 477 | < | rmx_write_float(const double *dp, int len, FILE *fp) | 
| 477 | > | rmx_write_double(const rmx_dtype *dp, int len, FILE *fp) | 
| 478 |  | { | 
| 479 | < | float   val; | 
| 479 | > | double  val; | 
| 480 |  |  | 
| 481 |  | while (len--) { | 
| 482 |  | val = *dp++; | 
| 483 | < | if (putbinary(&val, sizeof(float), 1, fp) != 1) | 
| 483 | > | if (putbinary(&val, sizeof(val), 1, fp) != 1) | 
| 484 |  | return(0); | 
| 485 |  | } | 
| 486 |  | return(1); | 
| 487 |  | } | 
| 488 | + | #endif | 
| 489 |  |  | 
| 490 |  | static int | 
| 491 | < | rmx_write_rgbe(const double *dp, int nc, int len, FILE *fp) | 
| 491 | > | rmx_write_ascii(const rmx_dtype *dp, int ncomp, int len, FILE *fp) | 
| 492 |  | { | 
| 493 | + | while (len-- > 0) { | 
| 494 | + | int     k = ncomp; | 
| 495 | + | while (k-- > 0) | 
| 496 | + | fprintf(fp, " %.7e", *dp++); | 
| 497 | + | fputc('\t', fp); | 
| 498 | + | } | 
| 499 | + | return(fputc('\n', fp) != EOF); | 
| 500 | + | } | 
| 501 | + |  | 
| 502 | + | static int | 
| 503 | + | rmx_write_rgbe(const rmx_dtype *dp, int ncomp, int len, FILE *fp) | 
| 504 | + | { | 
| 505 |  | COLR    *scan; | 
| 506 |  | int     j; | 
| 507 |  |  | 
| 508 | < | if ((nc != 1) & (nc != 3)) return(0); | 
| 508 | > | if ((ncomp != 1) & (ncomp != 3)) return(0); | 
| 509 |  | scan = (COLR *)tempbuffer(sizeof(COLR)*len); | 
| 510 |  | if (!scan) return(0); | 
| 511 |  |  | 
| 512 | < | for (j = 0; j < len; j++, dp += nc) | 
| 513 | < | if (nc == 1) | 
| 512 | > | for (j = 0; j < len; j++, dp += ncomp) | 
| 513 | > | if (ncomp == 1) | 
| 514 |  | setcolr(scan[j], dp[0], dp[0], dp[0]); | 
| 515 |  | else | 
| 516 |  | setcolr(scan[j], dp[0], dp[1], dp[2]); | 
| 519 |  | } | 
| 520 |  |  | 
| 521 |  | static int | 
| 522 | < | rmx_write_spec(const double *dp, int nc, int len, FILE *fp) | 
| 522 | > | rmx_write_spec(const rmx_dtype *dp, int ncomp, int len, FILE *fp) | 
| 523 |  | { | 
| 524 | < | uby8    *scan; | 
| 525 | < | SCOLOR  scol; | 
| 524 | > | COLRV   *scan; | 
| 525 | > | COLORV  scol[MAXCOMP]; | 
| 526 |  | int     j, k; | 
| 527 |  |  | 
| 528 | < | if (nc < 3) return(0); | 
| 529 | < | scan = (uby8 *)tempbuffer((nc+1)*len); | 
| 528 | > | if ((ncomp < 3) | (ncomp > MAXCOMP)) return(0); | 
| 529 | > | scan = (COLRV *)tempbuffer((ncomp+1)*len); | 
| 530 |  | if (!scan) return(0); | 
| 531 | < | for (j = len; j--; dp += nc) { | 
| 532 | < | for (k = nc; k--; ) | 
| 531 | > | for (j = 0; j < len; j++, dp += ncomp) { | 
| 532 | > | for (k = ncomp; k--; ) | 
| 533 |  | scol[k] = dp[k]; | 
| 534 | < | scolor2scolr(scan+j*(nc+1), scol, nc); | 
| 534 | > | scolor2scolr(scan+j*(ncomp+1), scol, ncomp); | 
| 535 |  | } | 
| 536 | < | return(fwritescolrs(scan, nc, len, fp) >= 0); | 
| 536 | > | return(fwritescolrs(scan, ncomp, len, fp) >= 0); | 
| 537 |  | } | 
| 538 |  |  | 
| 539 |  | /* Check if CIE XYZ primaries were specified */ | 
| 557 |  | int | 
| 558 |  | rmx_write_header(const RMATRIX *rm, int dtype, FILE *fp) | 
| 559 |  | { | 
| 560 | < | if (!rm | !fp || !rm->mtx | (rm->ncols <= 0)) | 
| 560 | > | if (!rm | !fp || rm->ncols <= 0) | 
| 561 |  | return(0); | 
| 562 |  | if (rm->info) | 
| 563 |  | fputs(rm->info, fp); | 
| 564 | < | if (dtype == DTfromHeader) | 
| 564 | > | if (dtype == DTfromHeader) { | 
| 565 |  | dtype = rm->dtype; | 
| 566 | < | else if (dtype == DTrgbe && (rm->dtype == DTxyze || | 
| 566 | > | #if DTrmx_native==DTfloat | 
| 567 | > | if (dtype == DTdouble)          /* but stored as float? */ | 
| 568 | > | dtype = DTfloat; | 
| 569 | > | #endif | 
| 570 | > | } else if (dtype == DTrgbe && (rm->dtype == DTxyze || | 
| 571 |  | findCIEprims(rm->info))) | 
| 572 |  | dtype = DTxyze; | 
| 573 |  | else if ((dtype == DTxyze) & (rm->dtype == DTrgbe)) | 
| 574 |  | dtype = DTrgbe; | 
| 575 | < | if ((dtype == DTspec) & (rm->ncomp < 3)) | 
| 575 | > | if ((dtype < DTspec) & (rm->ncomp > 3)) | 
| 576 | > | dtype = DTspec; | 
| 577 | > | else if ((dtype == DTspec) & (rm->ncomp <= 3)) | 
| 578 |  | return(0); | 
| 579 |  |  | 
| 580 |  | if (dtype == DTascii)                   /* set file type (WINDOWS) */ | 
| 595 |  | } | 
| 596 |  | if (dtype >= DTspec) {                  /* # components & split? */ | 
| 597 |  | fputncomp(rm->ncomp, fp); | 
| 598 | < | if (dtype == DTspec || (rm->ncomp > 3 && | 
| 599 | < | memcmp(rm->wlpart, WLPART, sizeof(WLPART)))) | 
| 598 | > | if (rm->ncomp > 3 && | 
| 599 | > | memcmp(rm->wlpart, WLPART, sizeof(WLPART))) | 
| 600 |  | fputwlsplit(rm->wlpart, fp); | 
| 601 |  | } else if ((rm->ncomp != 3) & (rm->ncomp != 1)) | 
| 602 |  | return(0);                      /* wrong # components */ | 
| 611 |  |  | 
| 612 |  | /* Write out matrix data (usually by row) */ | 
| 613 |  | int | 
| 614 | < | rmx_write_data(const double *dp, int nc, int len, int dtype, FILE *fp) | 
| 614 | > | rmx_write_data(const rmx_dtype *dp, int ncomp, int len, int dtype, FILE *fp) | 
| 615 |  | { | 
| 616 |  | switch (dtype) { | 
| 617 | < | case DTascii: | 
| 580 | < | return(rmx_write_ascii(dp, nc, len, fp)); | 
| 617 | > | #if DTrmx_native==DTdouble | 
| 618 |  | case DTfloat: | 
| 619 | < | return(rmx_write_float(dp, nc*len, fp)); | 
| 619 | > | return(rmx_write_float(dp, ncomp*len, fp)); | 
| 620 | > | #else | 
| 621 |  | case DTdouble: | 
| 622 | < | return(putbinary(dp, sizeof(*dp)*nc, len, fp) == len); | 
| 622 | > | return(rmx_write_double(dp, ncomp*len, fp)); | 
| 623 | > | #endif | 
| 624 | > | case DTrmx_native: | 
| 625 | > | return(putbinary(dp, sizeof(*dp)*ncomp, len, fp) == len); | 
| 626 | > | case DTascii: | 
| 627 | > | return(rmx_write_ascii(dp, ncomp, len, fp)); | 
| 628 |  | case DTrgbe: | 
| 629 |  | case DTxyze: | 
| 630 | < | return(rmx_write_rgbe(dp, nc, len, fp)); | 
| 630 | > | return(rmx_write_rgbe(dp, ncomp, len, fp)); | 
| 631 |  | case DTspec: | 
| 632 | < | return(rmx_write_spec(dp, nc, len, fp)); | 
| 632 | > | return(rmx_write_spec(dp, ncomp, len, fp)); | 
| 633 |  | } | 
| 634 |  | return(0); | 
| 635 |  | } | 
| 647 |  | #ifdef getc_unlocked | 
| 648 |  | flockfile(fp); | 
| 649 |  | #endif | 
| 650 | < | if (dtype == DTdouble)                  /* write all at once? */ | 
| 650 | > | if (dtype == DTrmx_native)              /* write all at once? */ | 
| 651 |  | ok = rmx_write_data(rm->mtx, rm->ncomp, | 
| 652 |  | rm->nrows*rm->ncols, dtype, fp); | 
| 653 |  | else                                    /* else row by row */ | 
| 674 |  |  | 
| 675 |  | if (!rid) | 
| 676 |  | return(NULL); | 
| 677 | < | memset(rid->mtx, 0, array_size(rid)); | 
| 677 | > | memset(rid->mtx, 0, rmx_array_size(rid)); | 
| 678 |  | for (i = dim; i--; ) { | 
| 679 | < | double      *dp = rmx_lval(rid,i,i); | 
| 679 | > | rmx_dtype   *dp = rmx_lval(rid,i,i); | 
| 680 |  | for (k = n; k--; ) | 
| 681 |  | dp[k] = 1.; | 
| 682 |  | } | 
| 683 |  | return(rid); | 
| 684 |  | } | 
| 685 |  |  | 
| 686 | < | /* Duplicate the given matrix */ | 
| 686 | > | /* Duplicate the given matrix (may be unallocated) */ | 
| 687 |  | RMATRIX * | 
| 688 |  | rmx_copy(const RMATRIX *rm) | 
| 689 |  | { | 
| 690 |  | RMATRIX *dnew; | 
| 691 |  |  | 
| 692 | < | if (!rm || !rm->mtx) | 
| 692 | > | if (!rm) | 
| 693 |  | return(NULL); | 
| 694 | < | dnew = rmx_alloc(rm->nrows, rm->ncols, rm->ncomp); | 
| 694 | > | dnew = rmx_new(rm->nrows, rm->ncols, rm->ncomp); | 
| 695 |  | if (!dnew) | 
| 696 |  | return(NULL); | 
| 697 | + | if (rm->mtx) { | 
| 698 | + | if (!rmx_prepare(dnew)) { | 
| 699 | + | rmx_free(dnew); | 
| 700 | + | return(NULL); | 
| 701 | + | } | 
| 702 | + | memcpy(dnew->mtx, rm->mtx, rmx_array_size(dnew)); | 
| 703 | + | } | 
| 704 |  | rmx_addinfo(dnew, rm->info); | 
| 705 |  | dnew->dtype = rm->dtype; | 
| 706 |  | copycolor(dnew->cexp, rm->cexp); | 
| 707 |  | memcpy(dnew->wlpart, rm->wlpart, sizeof(dnew->wlpart)); | 
| 658 | – | memcpy(dnew->mtx, rm->mtx, array_size(dnew)); | 
| 708 |  | return(dnew); | 
| 709 |  | } | 
| 710 |  |  | 
| 711 | < | /* Allocate and assign transposed matrix */ | 
| 712 | < | RMATRIX * | 
| 713 | < | rmx_transpose(const RMATRIX *rm) | 
| 711 | > | /* Replace data in first matrix with data from second */ | 
| 712 | > | int | 
| 713 | > | rmx_transfer_data(RMATRIX *rdst, RMATRIX *rsrc, int dometa) | 
| 714 |  | { | 
| 715 | < | RMATRIX *dnew; | 
| 716 | < | int     i, j; | 
| 715 | > | if (!rdst | !rsrc) | 
| 716 | > | return(0); | 
| 717 | > | if (dometa) {           /* transfer everything? */ | 
| 718 | > | rmx_reset(rdst); | 
| 719 | > | *rdst = *rsrc; | 
| 720 | > | rsrc->info = NULL; rsrc->mapped = NULL; rsrc->mtx = NULL; | 
| 721 | > | return(1); | 
| 722 | > | } | 
| 723 | > | /* just matrix data -- leave metadata */ | 
| 724 | > | if ((rdst->nrows != rsrc->nrows) | | 
| 725 | > | (rdst->ncols != rsrc->ncols) | | 
| 726 | > | (rdst->ncomp != rsrc->ncomp)) | 
| 727 | > | return(0); | 
| 728 | > | #ifdef MAP_FILE | 
| 729 | > | if (rdst->mapped) | 
| 730 | > | munmap(rdst->mapped, rmx_mapped_size(rdst)); | 
| 731 | > | else | 
| 732 | > | #endif | 
| 733 | > | if (rdst->pflags & RMF_FREEMEM) { | 
| 734 | > | free(rdst->mtx); | 
| 735 | > | rdst->pflags &= ~RMF_FREEMEM; | 
| 736 | > | } | 
| 737 | > | rdst->mapped = rsrc->mapped; | 
| 738 | > | rdst->mtx = rsrc->mtx; | 
| 739 | > | rdst->pflags |= rsrc->pflags & RMF_FREEMEM; | 
| 740 | > | rsrc->mapped = NULL; rsrc->mtx = NULL; | 
| 741 | > | return(1); | 
| 742 | > | } | 
| 743 |  |  | 
| 744 | < | if (!rm || !rm->mtx) | 
| 744 | > | /* Transpose the given matrix */ | 
| 745 | > | int | 
| 746 | > | rmx_transpose(RMATRIX *rm) | 
| 747 | > | { | 
| 748 | > | uby8            *bmap; | 
| 749 | > | rmx_dtype       val[MAXCOMP]; | 
| 750 | > | RMATRIX         dold; | 
| 751 | > | int             i, j; | 
| 752 | > |  | 
| 753 | > | if (!rm || !rm->mtx | (rm->ncomp > MAXCOMP)) | 
| 754 |  | return(0); | 
| 755 | < | if ((rm->nrows == 1) | (rm->ncols == 1)) { | 
| 756 | < | dnew = rmx_copy(rm); | 
| 757 | < | if (!dnew) | 
| 758 | < | return(NULL); | 
| 759 | < | dnew->nrows = rm->ncols; | 
| 760 | < | dnew->ncols = rm->nrows; | 
| 761 | < | return(dnew); | 
| 755 | > | if (rm->info) | 
| 756 | > | rmx_addinfo(rm, "Transposed rows and columns\n"); | 
| 757 | > | if ((rm->nrows == 1) | (rm->ncols == 1)) { /* vector? */ | 
| 758 | > | j = rm->ncols; | 
| 759 | > | rm->ncols = rm->nrows; | 
| 760 | > | rm->nrows = j; | 
| 761 | > | return(1); | 
| 762 |  | } | 
| 763 | < | dnew = rmx_alloc(rm->ncols, rm->nrows, rm->ncomp); | 
| 764 | < | if (!dnew) | 
| 765 | < | return(NULL); | 
| 766 | < | if (rm->info) { | 
| 767 | < | rmx_addinfo(dnew, rm->info); | 
| 768 | < | rmx_addinfo(dnew, "Transposed rows and columns\n"); | 
| 763 | > | if (rm->nrows == rm->ncols) {   /* square matrix case */ | 
| 764 | > | for (i = rm->nrows; --i > 0; ) | 
| 765 | > | for (j = i; j-- > 0; ) { | 
| 766 | > | memcpy(val, rmx_val(rm,i,j), | 
| 767 | > | sizeof(rmx_dtype)*rm->ncomp); | 
| 768 | > | memcpy(rmx_lval(rm,i,j), rmx_val(rm,j,i), | 
| 769 | > | sizeof(rmx_dtype)*rm->ncomp); | 
| 770 | > | memcpy(rmx_lval(rm,j,i), val, | 
| 771 | > | sizeof(rmx_dtype)*rm->ncomp); | 
| 772 | > | } | 
| 773 | > | return(1); | 
| 774 |  | } | 
| 775 | < | dnew->dtype = rm->dtype; | 
| 776 | < | copycolor(dnew->cexp, rm->cexp); | 
| 777 | < | memcpy(dnew->wlpart, rm->wlpart, sizeof(dnew->wlpart)); | 
| 778 | < | for (j = dnew->ncols; j--; ) | 
| 779 | < | for (i = dnew->nrows; i--; ) | 
| 780 | < | memcpy(rmx_lval(dnew,i,j), rmx_val(rm,j,i), | 
| 781 | < | sizeof(double)*dnew->ncomp); | 
| 782 | < | return(dnew); | 
| 775 | > | #define bmbyte(r,c)     bmap[((r)*rm->ncols+(c))>>3] | 
| 776 | > | #define bmbit(r,c)      (1 << ((r)*rm->ncols+(c) & 7)) | 
| 777 | > | #define bmop(r,c, op)   (bmbyte(r,c) op bmbit(r,c)) | 
| 778 | > | #define bmtest(r,c)     bmop(r,c,&) | 
| 779 | > | #define bmset(r,c)      bmop(r,c,|=) | 
| 780 | > | /* loop completion bitmap */ | 
| 781 | > | bmap = (uby8 *)calloc(((size_t)rm->nrows*rm->ncols+7)>>3, 1); | 
| 782 | > | if (!bmap) | 
| 783 | > | return(0); | 
| 784 | > | dold = *rm; | 
| 785 | > | rm->ncols = dold.nrows; rm->nrows = dold.ncols; | 
| 786 | > | for (i = rm->nrows; i--; )      /* try every starting point */ | 
| 787 | > | for (j = rm->ncols; j--; ) { | 
| 788 | > | int     i0, j0; | 
| 789 | > | int     i1 = i; | 
| 790 | > | size_t  j1 = j; | 
| 791 | > | if (bmtest(i, j)) | 
| 792 | > | continue;       /* traversed loop earlier */ | 
| 793 | > | memcpy(val, rmx_val(rm,i,j), | 
| 794 | > | sizeof(rmx_dtype)*rm->ncomp); | 
| 795 | > | for ( ; ; ) {           /* new transpose loop */ | 
| 796 | > | const rmx_dtype     *ds; | 
| 797 | > | i0 = i1; j0 = j1; | 
| 798 | > | ds = rmx_val(&dold, j0, i0); | 
| 799 | > | j1 = (ds - dold.mtx)/dold.ncomp; | 
| 800 | > | i1 = j1 / rm->ncols; | 
| 801 | > | j1 -= (size_t)i1*rm->ncols; | 
| 802 | > | bmset(i1, j1);      /* mark as done */ | 
| 803 | > | if ((i1 == i) & (j1 == j)) | 
| 804 | > | break;          /* back at start */ | 
| 805 | > | memcpy(rmx_lval(rm,i0,j0), ds, | 
| 806 | > | sizeof(rmx_dtype)*rm->ncomp); | 
| 807 | > | }                       /* complete the loop */ | 
| 808 | > | memcpy(rmx_lval(rm,i0,j0), val, | 
| 809 | > | sizeof(rmx_dtype)*rm->ncomp); | 
| 810 | > | } | 
| 811 | > | free(bmap);                     /* all done! */ | 
| 812 | > | return(1); | 
| 813 | > | #undef  bmbyte | 
| 814 | > | #undef  bmbit | 
| 815 | > | #undef  bmop | 
| 816 | > | #undef  bmtest | 
| 817 | > | #undef  bmset | 
| 818 |  | } | 
| 819 |  |  | 
| 820 |  | /* Multiply (concatenate) two matrices and allocate the result */ | 
| 840 |  | for (k = mres->ncomp; k--; ) { | 
| 841 |  | double      d = 0; | 
| 842 |  | for (h = m1->ncols; h--; ) | 
| 843 | < | d += rmx_val(m1,i,h)[k] * rmx_val(m2,h,j)[k]; | 
| 844 | < | rmx_lval(mres,i,j)[k] = d; | 
| 843 | > | d += (double)rmx_val(m1,i,h)[k] * | 
| 844 | > | rmx_val(m2,h,j)[k]; | 
| 845 | > | rmx_lval(mres,i,j)[k] = (rmx_dtype)d; | 
| 846 |  | } | 
| 847 |  | return(mres); | 
| 848 |  | } | 
| 867 |  | for (i = m1->nrows; i--; ) | 
| 868 |  | for (j = m1->ncols; j--; ) | 
| 869 |  | if (divide) { | 
| 870 | < | double      d; | 
| 870 | > | rmx_dtype   d; | 
| 871 |  | if (m2->ncomp == 1) { | 
| 872 |  | d = rmx_val(m2,i,j)[0]; | 
| 873 |  | if (d == 0) { | 
| 890 |  | } | 
| 891 |  | } else { | 
| 892 |  | if (m2->ncomp == 1) { | 
| 893 | < | const double    d = rmx_val(m2,i,j)[0]; | 
| 893 | > | const rmx_dtype d = rmx_val(m2,i,j)[0]; | 
| 894 |  | for (k = m1->ncomp; k--; ) | 
| 895 |  | rmx_lval(m1,i,j)[k] *= d; | 
| 896 |  | } else | 
| 931 |  | rmx_addinfo(msum, rmx_mismatch_warn); | 
| 932 |  | for (i = msum->nrows; i--; ) | 
| 933 |  | for (j = msum->ncols; j--; ) { | 
| 934 | < | const double    *da = rmx_val(madd,i,j); | 
| 935 | < | double          *ds = rmx_lval(msum,i,j); | 
| 934 | > | const rmx_dtype *da = rmx_val(madd,i,j); | 
| 935 | > | rmx_dtype       *ds = rmx_lval(msum,i,j); | 
| 936 |  | for (k = msum->ncomp; k--; ) | 
| 937 | < | ds[k] += sf[k] * da[k]; | 
| 937 | > | ds[k] += (rmx_dtype)sf[k] * da[k]; | 
| 938 |  | } | 
| 939 |  | if (mysf) | 
| 940 |  | free(mysf); | 
| 951 |  | return(0); | 
| 952 |  | for (i = rm->nrows; i--; ) | 
| 953 |  | for (j = rm->ncols; j--; ) { | 
| 954 | < | double  *dp = rmx_lval(rm,i,j); | 
| 954 | > | rmx_dtype       *dp = rmx_lval(rm,i,j); | 
| 955 |  | for (k = rm->ncomp; k--; ) | 
| 956 | < | dp[k] *= sf[k]; | 
| 956 | > | dp[k] *= (rmx_dtype)sf[k]; | 
| 957 |  | } | 
| 958 |  | if (rm->info) | 
| 959 |  | rmx_addinfo(rm, "Applied scalar\n"); | 
| 983 |  | dnew->dtype = msrc->dtype; | 
| 984 |  | for (i = dnew->nrows; i--; ) | 
| 985 |  | for (j = dnew->ncols; j--; ) { | 
| 986 | < | const double    *ds = rmx_val(msrc,i,j); | 
| 986 | > | const rmx_dtype *ds = rmx_val(msrc,i,j); | 
| 987 |  | for (kd = dnew->ncomp; kd--; ) { | 
| 988 |  | double      d = 0; | 
| 989 |  | for (ks = msrc->ncomp; ks--; ) | 
| 990 |  | d += cmat[kd*msrc->ncomp + ks] * ds[ks]; | 
| 991 | < | rmx_lval(dnew,i,j)[kd] = d; | 
| 991 | > | rmx_lval(dnew,i,j)[kd] = (rmx_dtype)d; | 
| 992 |  | } | 
| 993 |  | } | 
| 994 |  | return(dnew); | 
| 995 |  | } | 
| 996 |  |  | 
| 872 | – | /* Convert a color matrix to newly allocated RMATRIX buffer */ | 
| 873 | – | RMATRIX * | 
| 874 | – | rmx_from_cmatrix(const CMATRIX *cm) | 
| 875 | – | { | 
| 876 | – | int     i, j; | 
| 877 | – | RMATRIX *dnew; | 
| 878 | – |  | 
| 879 | – | if (!cm) | 
| 880 | – | return(NULL); | 
| 881 | – | dnew = rmx_alloc(cm->nrows, cm->ncols, 3); | 
| 882 | – | if (!dnew) | 
| 883 | – | return(NULL); | 
| 884 | – | dnew->dtype = DTfloat; | 
| 885 | – | for (i = dnew->nrows; i--; ) | 
| 886 | – | for (j = dnew->ncols; j--; ) { | 
| 887 | – | const COLORV    *cv = cm_lval(cm,i,j); | 
| 888 | – | double          *dp = rmx_lval(dnew,i,j); | 
| 889 | – | dp[0] = cv[0]; | 
| 890 | – | dp[1] = cv[1]; | 
| 891 | – | dp[2] = cv[2]; | 
| 892 | – | } | 
| 893 | – | return(dnew); | 
| 894 | – | } | 
| 895 | – |  | 
| 896 | – | /* Convert general matrix to newly allocated CMATRIX buffer */ | 
| 897 | – | CMATRIX * | 
| 898 | – | cm_from_rmatrix(const RMATRIX *rm) | 
| 899 | – | { | 
| 900 | – | int     i, j; | 
| 901 | – | CMATRIX *cnew; | 
| 902 | – |  | 
| 903 | – | if (!rm || !rm->mtx | (rm->ncomp == 2)) | 
| 904 | – | return(NULL); | 
| 905 | – | cnew = cm_alloc(rm->nrows, rm->ncols); | 
| 906 | – | if (!cnew) | 
| 907 | – | return(NULL); | 
| 908 | – | for (i = cnew->nrows; i--; ) | 
| 909 | – | for (j = cnew->ncols; j--; ) { | 
| 910 | – | const double    *dp = rmx_val(rm,i,j); | 
| 911 | – | COLORV          *cv = cm_lval(cnew,i,j); | 
| 912 | – | switch (rm->ncomp) { | 
| 913 | – | case 3: | 
| 914 | – | setcolor(cv, dp[0], dp[1], dp[2]); | 
| 915 | – | break; | 
| 916 | – | case 1: | 
| 917 | – | setcolor(cv, dp[0], dp[0], dp[0]); | 
| 918 | – | break; | 
| 919 | – | default: { | 
| 920 | – | SCOLOR  scol; | 
| 921 | – | int     k; | 
| 922 | – | for (k = rm->ncomp; k--; ) | 
| 923 | – | scol[k] = dp[k]; | 
| 924 | – | scolor2color(cv, scol, rm->ncomp, rm->wlpart); | 
| 925 | – | } break; | 
| 926 | – | } | 
| 927 | – | } | 
| 928 | – | return(cnew); | 
| 929 | – | } |