ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/tonemap.c
(Generate patch)

Comparing ray/src/common/tonemap.c (file contents):
Revision 3.46 by greg, Tue Mar 2 20:09:14 2021 UTC vs.
Revision 3.54 by greg, Sat Jan 15 16:57:46 2022 UTC

# Line 95 | Line 95 | tmSetSpace(                    /* set input color space for conversions
95   TMstruct        *tms,
96   RGBPRIMP        pri,
97   double  sf,
98 < MEM_PTR dat
98 > void    *dat
99   )
100   {
101          static const char funcName[] = "tmSetSpace";
# Line 160 | Line 160 | TMstruct       *tms
160          if (tms == NULL || tms->histo == NULL)
161                  return;
162          free(tms->histo);
163 +        tms->hbrmin = 10; tms->hbrmax = -10;
164          tms->histo = NULL;
165   }
166  
# Line 320 | Line 321 | int    len
321                                  cmon[BLU] += d;
322                          }
323                  } else if (tms->flags & TM_F_BW) {
324 <                        cmon[RED] = cmon[GRN] = cmon[BLU] = lum;
324 >                        int     j = 3;
325 >                        while (j--) cs[3*i+j] = tms->cdiv[j]/(TM_BRES>>8);
326 >                        continue;
327                  }
328                  d = tms->clf[RED]*cmon[RED]/lum;
329                  cs[3*i  ] = d>=.999f ? 255 : gamtab[(int)(1024.f*d)];
# Line 343 | Line 346 | int    wt
346   {
347          static const char funcName[] = "tmAddHisto";
348          int     oldorig=0, oldlen, horig, hlen;
349 <        int     i, j;
349 >        int     i;
350  
351          if (tms == NULL)
352                  returnErr(TM_E_TMINVAL);
# Line 364 | Line 367 | int    wt
367                  oldlen = HISTI(tms->hbrmax) + 1 - oldorig;
368          }
369          for (i = len; i--; ) {
370 <                if ((j = ls[i]) < MINBRT)
370 >                if (ls[i] < MINBRT)
371                          continue;
372 <                if (j < tms->hbrmin)
373 <                        tms->hbrmin = j;
374 <                else if (j > tms->hbrmax)
375 <                        tms->hbrmax = j;
372 >                if (ls[i] < tms->hbrmin)
373 >                        tms->hbrmin = ls[i];
374 >                else if (ls[i] > tms->hbrmax)
375 >                        tms->hbrmax = ls[i];
376          }
377          horig = HISTI(tms->hbrmin);
378          hlen = HISTI(tms->hbrmax) + 1 - horig;
# Line 425 | Line 428 | double  Lddyn
428   )
429   {
430          static const char funcName[] = "tmFixedMapping";
431 <        int     maxV = (1L<<(8*sizeof(TMAP_TYP))) - 1;
432 <        double  minD;
433 <        int     i;
431 >        const int       maxV = (1L<<(8*sizeof(TMAP_TYP))) - 1;
432 >        double          minD;
433 >        int             i;
434          
435          if (!tmNewMap(tms))
436                  returnErr(TM_E_NOMEM);
# Line 439 | Line 442 | double  Lddyn
442          for (i = tms->mbrmax-tms->mbrmin+1; i--; ) {
443                  double  d;
444                  d = expmult/tms->inpsf * tmLuminance(tms->mbrmin + i);
445 <                if (d <= minD)
446 <                        break;          /* map initialized to zeroes */
447 <                d = (d - minD)/(1. - minD);
445 >                if (d >= 2.*minD)
446 >                        d -= minD;
447 >                else                    /* soft black crushing */
448 >                        d *= d/(4.*minD);
449 >                d /= 1. - minD;
450                  d = TM_BRES*pow(d, 1./gamval);
451 <                tms->lumap[i] = (d >= maxV) ? maxV : (int)d;
451 >                tms->lumap[i] = (d > maxV) ? maxV : (int)d;
452          }
453          returnOK;
454   }
# Line 486 | Line 491 | double Ldmax
491                  histot += tms->histo[i];
492                  sum += (double)(j -= HISTEP) * tms->histo[i];
493          }
489        threshold = histot*0.002 + .5;
494          if (!histot)
495                  returnErr(TM_E_TMFAIL);
496 +        threshold = histot/500 + 1;
497          Lwavg = tmLuminance( (double)sum / histot );
498                                          /* use linear tone mapping? */
499 <        if (tms->flags & TM_F_LINEAR || threshold < 4 ||
499 >        if (tms->flags & TM_F_LINEAR ||
500                          tms->hbrmax - tms->hbrmin < TM_BRTSCALE*logLddyn)
501                  goto linearmap;
502                                          /* clamp histogram */
# Line 532 | Line 537 | double Ldmax
537                          free(cumf);
538                          goto linearmap;
539                  }
540 <        } while (trimmings > threshold);
540 >        } while (40*trimmings > histot);
541                                          /* allocate space for mapping */
542          if (!tmNewMap(tms))
543                  returnErr(TM_E_NOMEM);
# Line 688 | Line 693 | TMstruct       *tms
693          tms->mbrmin = tms->hbrmin;
694          tms->mbrmax = tms->hbrmax;
695          if (tms->mbrmin > tms->mbrmax)
696 <                return 0;
696 >                return(0);
697          if (tms->lumap == NULL)
698                  tms->lumap = (TMAP_TYP *)calloc(tms->mbrmax-tms->mbrmin+1,
699                                                  sizeof(TMAP_TYP));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines