1 #ifndef TONEMAPPING_ANIMATION_HXX
 2 #define TONEMAPPING_ANIMATION_HXX
 3 
 4 #include "Image.hxx"
 5 #include "ToneMapping.hxx"
 6 
 7 class ToneMappingAnimation
 8 {
 9     private:
10         float LdMax;
11         unsigned int image_number;
12 
13     public:
14         ToneMappingAnimation (float LdMax, unsigned int image_number)
15         : LdMax(LdMax), image_number(image_number)
16         {};
17         
18         ~ToneMappingAnimation()
19         {};
20         
21         void map()
22         {
23             std::cout << "ToneMapping begin" << std::endl;
24             
25             // local global variables
26             char dataname[100];
27             std::vector<float> scaling_factor;
28 
29             /**
30              * get the filename, load the image and compute the scaling factor for it
31              */
32             for (unsigned int i = 0; i < image_number; i++)
33             {
34                 sprintf(dataname,"pictures/%04d.png",i);
35                 
36                 Image image;
37                 image.LoadImage(dataname);
38                 
39                 ToneMapping* tone = new ToneMapping(LdMax);
40                     scaling_factor.push_back(tone->scalingfactor(image));
41                 delete tone;
42             }
43             
44             // debug
45             assert( scaling_factor.size() == image_number );
46             
47             /**
48              * compute average scaling factor
49              */
50             float sum = 0.0;
51             for (unsigned int i = 0; i < scaling_factor.size(); i++)
52                 sum += scaling_factor[i];
53             float final = sum / (float) ( scaling_factor.size() );
54             
55             /**
56              * scale
57              * therefore load the image again,
58              * multiply the color at each pixel with the scaling factor
59              * and then write the image
60              */
61             for (unsigned int i = 0; i < image_number; i++)
62             {
63                 sprintf(dataname,"pictures/%04d.png",i);
64 
65                 Image image;
66                 image.LoadImage(dataname);
67 
68                 int resX = image.getWidth();
69                 int resY = image.getHeight();
70                 
71                 for (int i = 0; i < resX; i++)
72                     for (int j = 0; j < resY; j++)
73                     {
74                         Vec4f color = Min(Max(image.getPixel(i,j) * final,Vec3f(0)),Vec3f(1));
75                         image.setPixel( color, i, j );
76                     }
77 
78                 image.WritePPM(dataname);
79             }
80 
81             std::cout << "ToneMapping finished" << std::endl;
82         };
83 };
84 
85 #endif


syntax highlighted by Code2HTML, v. 0.9.1