00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "reinhard.h"
00032
00033 using namespace lux;
00034
00035
00036 ReinhardOp::ReinhardOp(float prS, float poS, float b)
00037 {
00038 pre_scale = prS;
00039 post_scale = poS;
00040 burn = b;
00041 }
00042
00043 void ReinhardOp::Map(const float *y, int xRes, int yRes,
00044 float maxDisplayY, float *scale) const
00045 {
00046 const float alpha = .1f;
00047 const float invA = 1.f / 683.f;
00048
00049
00050 float Ywa = 0.;
00051 for (int i = 0; i < xRes * yRes; ++i)
00052 if (y[i] > 0) Ywa += y[i];
00053 Ywa = Ywa / (xRes * yRes);
00054 Ywa *= invA;
00055
00056 const float Yw = pre_scale * alpha * burn;
00057 const float invY2 = 1.f / (Yw * Yw);
00058 const float pScale = pre_scale * alpha / Ywa;
00059
00060 for (int i = 0; i < xRes * yRes; ++i) {
00061 float ys = y[i] * invA;
00062 scale[i] = pScale * (maxDisplayY * invA *
00063 post_scale * (1.f + ys * invY2) / (1.f + ys));
00064 }
00065 }
00066
00067 ToneMap * ReinhardOp::CreateToneMap(const ParamSet &ps) {
00068 float pre_scale = ps.FindOneFloat("prescale", 1.f);
00069 float post_scale = ps.FindOneFloat("postscale", 1.f);
00070 float burn = ps.FindOneFloat("burn", 7.f);
00071 return new ReinhardOp(pre_scale, post_scale, burn);
00072 }