X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=white_balance_effect.cpp;h=07c95cac4ca473b52dda9f9d80ddbf9fda918a52;hp=8a00af4397afe6b8d2267712672bb0119572075a;hb=6a176580b95002657b381acfaf3892b345e28364;hpb=5b0f7fe5ff6af6a5e2f1620681ccf809f559393a diff --git a/white_balance_effect.cpp b/white_balance_effect.cpp index 8a00af4..07c95ca 100644 --- a/white_balance_effect.cpp +++ b/white_balance_effect.cpp @@ -1,14 +1,19 @@ -#include -#include - +#include #include +#include +#include -#include "white_balance_effect.h" -#include "util.h" -#include "opengl.h" +#include "colorspace_conversion_effect.h" #include "d65.h" +#include "effect_util.h" +#include "image_format.h" +#include "util.h" +#include "white_balance_effect.h" using namespace Eigen; +using namespace std; + +namespace movit { namespace { @@ -22,7 +27,7 @@ Vector3d convert_color_temperature_to_xyz(float T) assert(T <= 15000.0f); if (T <= 4000.0f) { - x = ((-0.2661239e9 * invT - 0.2343580e6) * invT + 0.8776956e3) * invT + 0.179910; + x = ((-0.2661239e9 * invT - 0.2343589e6) * invT + 0.8776956e3) * invT + 0.179910; } else { x = ((-3.0258469e9 * invT + 2.1070379e6) * invT + 0.2226347e3) * invT + 0.240390; } @@ -38,13 +43,6 @@ Vector3d convert_color_temperature_to_xyz(float T) return Vector3d(x, y, 1.0 - x - y); } -// Assuming sRGB primaries, from Wikipedia. -double rgb_to_xyz_matrix[9] = { - 0.4124, 0.2126, 0.0193, - 0.3576, 0.7152, 0.1192, - 0.1805, 0.0722, 0.9505, -}; - /* * There are several different perceptual color spaces with different intended * uses; for instance, CIECAM02 uses one space (CAT02) for purposes of computing @@ -107,17 +105,19 @@ WhiteBalanceEffect::WhiteBalanceEffect() { register_vec3("neutral_color", (float *)&neutral_color); register_float("output_color_temperature", &output_color_temperature); + register_uniform_mat3("correction_matrix", &uniform_correction_matrix); } -std::string WhiteBalanceEffect::output_fragment_shader() +string WhiteBalanceEffect::output_fragment_shader() { return read_file("white_balance_effect.frag"); } -void WhiteBalanceEffect::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) +void WhiteBalanceEffect::set_gl_state(GLuint glsl_program_num, const string &prefix, unsigned *sampler_num) { + Matrix3d rgb_to_xyz_matrix = ColorspaceConversionEffect::get_xyz_matrix(COLORSPACE_sRGB); Vector3d rgb(neutral_color.r, neutral_color.g, neutral_color.b); - Vector3d xyz = Map(rgb_to_xyz_matrix) * rgb; + Vector3d xyz = rgb_to_xyz_matrix * rgb; Vector3d lms_scale = compute_lms_scaling_factors(xyz); /* @@ -143,11 +143,12 @@ void WhiteBalanceEffect::set_gl_state(GLuint glsl_program_num, const std::string * Note that since we postmultiply our vectors, the order of the matrices * has to be the opposite of the execution order. */ - Matrix3d corr_matrix = - Map(rgb_to_xyz_matrix).inverse() * + uniform_correction_matrix = + rgb_to_xyz_matrix.inverse() * Map(xyz_to_lms_matrix).inverse() * lms_scale.asDiagonal() * Map(xyz_to_lms_matrix) * - Map(rgb_to_xyz_matrix); - set_uniform_mat3(glsl_program_num, prefix, "correction_matrix", corr_matrix); + rgb_to_xyz_matrix; } + +} // namespace movit