diff --git a/src/export/IExporter.hpp b/src/export/IExporter.hpp index ee5ef1d..24c53ca 100644 --- a/src/export/IExporter.hpp +++ b/src/export/IExporter.hpp @@ -24,21 +24,5 @@ class IExporter { return 0; } - - - static void rgb_normalized_to_8bits(const RGBColor& color, uint8_t *dest){ - double r = color[0]; - double g = color[1]; - double b = color[2]; - - r = linear_to_gamma(r); - g = linear_to_gamma(g); - b = linear_to_gamma(b); - - static const Interval intensity(0.000, 0.999); - dest[0] = uint8_t(256 * intensity.Clamp(r)); - dest[1] = uint8_t(256 * intensity.Clamp(g)); - dest[2] = uint8_t(256 * intensity.Clamp(b)); - } }; diff --git a/src/export/png_exporter.cpp b/src/export/png_exporter.cpp index f5917a4..471ac58 100644 --- a/src/export/png_exporter.cpp +++ b/src/export/png_exporter.cpp @@ -96,10 +96,13 @@ void PngExporter::ImageToScanline(uint8_t filtering, uint8_t *dest) const { uint8_t *data_ptr = dest; for(uint32_t j=0; j #include @@ -32,8 +33,12 @@ int PpmExporter::Export(int width, int height, std::shared_ptr buffe for(int i=0; i +#include + using namespace std; +float MAGENTA[3] = { 1.0f, 0.0f, 1.0f }; + + string get_env_var(const string& key) { char* val = getenv(key.c_str()); + if(val == NULL){ + clog << "Could not retrieve environment variable with key '" << key << "'" << endl; + } return val == NULL ? string("") : string(val); } @@ -20,3 +31,16 @@ void change_endianess(uint32_t n, uint8_t *dest) dest[sizeof(uint32_t) - i - 1] = data_ptr[i]; } } + + +void rgb_normalized_to_8bits(const RGBColor& color, uint8_t *dest){ + static const Interval intensity(0.000, 0.999); + dest[0] = uint8_t(256 * intensity.Clamp(color[0])); + dest[1] = uint8_t(256 * intensity.Clamp(color[1])); + dest[2] = uint8_t(256 * intensity.Clamp(color[2])); +} + + +uint8_t rgb_normalized_to_8bits(float value){ + return static_cast(255.999 * std::clamp(value, 0.f, 1.f)); +} \ No newline at end of file diff --git a/src/utils.hpp b/src/utils.hpp index 565cd1e..0e16188 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -1,11 +1,18 @@ #pragma once -#include +#include "math/vec.hpp" +#include #include std::string get_env_var(const std::string& key); -void change_endianess(uint32_t n, uint8_t *dest); \ No newline at end of file +void change_endianess(uint32_t n, uint8_t *dest); + +void rgb_normalized_to_8bits(const RGBColor& color, uint8_t *dest); + +uint8_t rgb_normalized_to_8bits(float value); + +extern float MAGENTA[3]; \ No newline at end of file