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 #include "dynload.h"
00033
00034 using namespace lux;
00035
00036
00037 ReinhardOp::ReinhardOp(float prS, float poS, float b)
00038 {
00039 pre_scale = prS;
00040 post_scale = poS;
00041 burn = b;
00042 }
00043
00044 void ReinhardOp::Map(vector<XYZColor> &xyz, int xRes, int yRes, float maxDisplayY) const
00045 {
00046 const float alpha = .1f;
00047 const int numPixels = xRes * yRes;
00048
00049 float Ywa = 0.f;
00050
00051 for (int i = 0; i < numPixels; ++i)
00052 if (xyz[i].Y() > 0.f) Ywa += xyz[i].Y();
00053 Ywa /= numPixels;
00054 if (Ywa == 0.f)
00055 Ywa = 1.f;
00056
00057 const float Yw = pre_scale * alpha * burn;
00058 const float invY2 = 1.f / (Yw * Yw);
00059 const float pScale = post_scale * pre_scale * alpha / Ywa;
00060
00061 for (int i = 0; i < numPixels; ++i) {
00062 float ys = xyz[i].c[1];
00063 xyz[i] *= pScale * (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 }
00073
00074 static DynamicLoader::RegisterToneMap<ReinhardOp> r("reinhard");