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 #include "tonemap.h"
00026 #include "paramset.h"
00027
00028 class NonLinearOp : public ToneMap {
00029 public:
00030
00031 NonLinearOp(float my) { maxY = my; }
00032 void Map(const float *y, int xRes, int yRes,
00033 float maxDisplayY, float *scale) const {
00034 float invY2;
00035 if (maxY <= 0.f) {
00036
00037 float Ywa = 0.;
00038 for (int i = 0; i < xRes * yRes; ++i)
00039 if (y[i] > 0) Ywa += logf(y[i]);
00040 Ywa = expf(Ywa / (xRes * yRes));
00041 Ywa /= 683.f;
00042 invY2 = 1.f / (Ywa * Ywa);
00043 }
00044 else invY2 = 1.f / (maxY * maxY);
00045 for (int i = 0; i < xRes * yRes; ++i) {
00046 float ys = y[i] / 683.f;
00047 scale[i] = maxDisplayY / 683.f *
00048 (1.f + ys * invY2) / (1.f + ys);
00049 }
00050 }
00051 private:
00052 float maxY;
00053 };
00054
00055 extern "C" DLLEXPORT ToneMap *CreateToneMap(const ParamSet &ps) {
00056 float maxy = ps.FindOneFloat("maxY", 0.f);
00057 return new NonLinearOp(maxy);
00058 }