source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ToneMapper.cpp @ 2968

Revision 2968, 1.4 KB checked in by mattausch, 16 years ago (diff)
Line 
1#include "ToneMapper.h"
2#include "FrameBufferObject.h"
3
4
5using namespace std;
6
7
8namespace CHCDemoEngine
9{
10
11
12ToneMapper::ToneMapper()
13{
14}
15
16
17float ToneMapper::CalcImageKey(float *pixels, int w, int h) const
18{
19        float totalLum = .0f;
20
21        int size = w * h * 4;
22
23        // get avg log luminance
24        for (int i = 0; i < size; i += 4)
25        {
26                float r = pixels[i + 0];
27                float g = pixels[i + 1];
28                float b = pixels[i + 2];
29
30                float pixLum = 0.2125f * r + 0.7154f * g + 0.0721f * b;
31
32                totalLum += log(pixLum + 1e-6f);
33        }
34
35        const float key = exp(totalLum / (float)(w * h));
36
37        static float previousKey = key;
38        const float factor = 1.0f;
39
40        const float imageKey = key;// * factor + previousKey * (1.0f - factor);
41        previousKey = imageKey;
42       
43        cout << "key: " << key << endl;
44
45        return imageKey;
46}
47
48
49float ToneMapper::CalcMaxLuminance(float *pixels, int w, int h) const
50{
51        float maxLum = 1e-6f;
52
53        int size = w * h * 4;
54
55        for (int i = 0; i < size; i += 4)
56        {
57                float r = pixels[i + 0];
58                float g = pixels[i + 1];
59                float b = pixels[i + 2];
60
61                float pixLum = 0.2125f * r + 0.7154f * g + 0.0721f * b;
62
63                if (pixLum > maxLum)
64                        maxLum = pixLum;
65        }
66
67/*      for (int i = 0; i < h; ++ i)
68        {
69                for (int j = 0; j < w; ++ j)
70                {
71                        const int idx = i * w + j;
72
73                        float r = pixels[4 * idx + 0];
74                        float g = pixels[4 * idx + 1];
75                        float b = pixels[4 * idx + 2];
76
77                        if (pixLum > maxLum)
78                                maxLum = pixLum;
79                }
80        }
81*/
82        return maxLum;
83}
84
85
86}
Note: See TracBrowser for help on using the repository browser.