diff options
author | Andreas Grois <andi@grois.info> | 2018-03-10 15:43:36 +0100 |
---|---|---|
committer | Andreas Grois <andi@grois.info> | 2018-03-10 15:43:36 +0100 |
commit | 704ecb6bbabe4a73c45bb6ae2433754bb8260bde (patch) | |
tree | eb0f4a46c4cca4ff3a77ad387a8b1e28e4f4a4ff /BuddhaTest/src/Helpers.cpp | |
parent | a0afe4bf8c011222b85c481ae209b09f75189858 (diff) |
Gamma correction for output
Diffstat (limited to 'BuddhaTest/src/Helpers.cpp')
-rw-r--r-- | BuddhaTest/src/Helpers.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/BuddhaTest/src/Helpers.cpp b/BuddhaTest/src/Helpers.cpp index 881d01f..bde6b8a 100644 --- a/BuddhaTest/src/Helpers.cpp +++ b/BuddhaTest/src/Helpers.cpp @@ -5,6 +5,7 @@ #include <iostream>
#include <vector>
#include <png.h>
+#include <cmath>
namespace Helpers
{
@@ -154,7 +155,7 @@ namespace Helpers return ProgramID;
}
- void WriteOutputPNG(const std::vector<uint32_t>& data, unsigned int width, unsigned int bufferHeight)
+ void WriteOutputPNG(const std::vector<uint32_t>& data, unsigned int width, unsigned int bufferHeight, double gamma)
{
std::vector<png_byte> pngData(3*width*2*bufferHeight);
std::vector<png_byte *> rows{2*bufferHeight};
@@ -170,7 +171,14 @@ namespace Helpers }
for(unsigned int i = 0; i < data.size();++i)
{
- pngData[data.size() + i] = (255*data[i] + (maxValue/2))/maxValue;
+ if(fabs(gamma - 1.0) > 0.0001)
+ {
+ pngData[data.size() + i] = 255.0 * pow(static_cast<double>(data[i])/static_cast<double>(maxValue),gamma);
+ }
+ else
+ {
+ pngData[data.size() + i] = (255*data[i] + (maxValue/2))/maxValue;
+ }
}
for(int i = 0; i < bufferHeight;++i)
{
|