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.49 by greg, Mon Apr 12 22:16:02 2021 UTC

# Line 425 | Line 425 | double  Lddyn
425   )
426   {
427          static const char funcName[] = "tmFixedMapping";
428 <        int     maxV = (1L<<(8*sizeof(TMAP_TYP))) - 1;
429 <        double  minD;
430 <        int     i;
428 >        const int       maxV = (1L<<(8*sizeof(TMAP_TYP))) - 1;
429 >        double          minD;
430 >        int             i;
431          
432          if (!tmNewMap(tms))
433                  returnErr(TM_E_NOMEM);
# Line 439 | Line 439 | double  Lddyn
439          for (i = tms->mbrmax-tms->mbrmin+1; i--; ) {
440                  double  d;
441                  d = expmult/tms->inpsf * tmLuminance(tms->mbrmin + i);
442 <                if (d <= minD)
443 <                        break;          /* map initialized to zeroes */
444 <                d = (d - minD)/(1. - minD);
442 >                if (d >= 2.*minD)
443 >                        d -= minD;
444 >                else                    /* soft black crushing */
445 >                        d *= d/(4.*minD);
446 >                d /= 1. - minD;
447                  d = TM_BRES*pow(d, 1./gamval);
448 <                tms->lumap[i] = (d >= maxV) ? maxV : (int)d;
448 >                tms->lumap[i] = (d > maxV) ? maxV : (int)d;
449          }
450          returnOK;
451   }
# Line 486 | Line 488 | double Ldmax
488                  histot += tms->histo[i];
489                  sum += (double)(j -= HISTEP) * tms->histo[i];
490          }
489        threshold = histot*0.002 + .5;
491          if (!histot)
492                  returnErr(TM_E_TMFAIL);
493 +        threshold = histot*0.025 + 1.;
494          Lwavg = tmLuminance( (double)sum / histot );
495                                          /* use linear tone mapping? */
496          if (tms->flags & TM_F_LINEAR || threshold < 4 ||
# Line 532 | Line 534 | double Ldmax
534                          free(cumf);
535                          goto linearmap;
536                  }
537 <        } while (trimmings > threshold);
537 >                threshold = 0.025*histot + 1.;
538 >
539 >        } while ((threshold > 4) & (trimmings > threshold));
540                                          /* allocate space for mapping */
541          if (!tmNewMap(tms))
542                  returnErr(TM_E_NOMEM);
# Line 688 | Line 692 | TMstruct       *tms
692          tms->mbrmin = tms->hbrmin;
693          tms->mbrmax = tms->hbrmax;
694          if (tms->mbrmin > tms->mbrmax)
695 <                return 0;
695 >                return(0);
696          if (tms->lumap == NULL)
697                  tms->lumap = (TMAP_TYP *)calloc(tms->mbrmax-tms->mbrmin+1,
698                                                  sizeof(TMAP_TYP));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines