summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
9ad1a31)
Generally we try to derive such values from first principles when possible;
this is some of the oldest code in Movit, which explains why it was forgotten.
Maybe longer-term we should move this out of ColorspaceConversionEffect into a
free function in util.h or something similar, but for now, this will do.
register_int("destination_space", (int *)&destination_space);
}
register_int("destination_space", (int *)&destination_space);
}
-Matrix3d get_xyz_matrix(Colorspace space)
+Matrix3d ColorspaceConversionEffect::get_xyz_matrix(Colorspace space)
{
if (space == COLORSPACE_XYZ) {
return Matrix3d::Identity();
{
if (space == COLORSPACE_XYZ) {
return Matrix3d::Identity();
// will simply stay out-of-gamut, and probably clip in the output stage.
#include <string>
// will simply stay out-of-gamut, and probably clip in the output stage.
#include <string>
#include "effect.h"
#include "image_format.h"
#include "effect.h"
#include "image_format.h"
virtual bool needs_srgb_primaries() const { return false; }
virtual AlphaHandling alpha_handling() const { return DONT_CARE_ALPHA_TYPE; }
virtual bool needs_srgb_primaries() const { return false; }
virtual AlphaHandling alpha_handling() const { return DONT_CARE_ALPHA_TYPE; }
+ // Get a conversion matrix from the given color space to XYZ.
+ static Eigen::Matrix3d get_xyz_matrix(Colorspace space);
+
private:
Colorspace source_space, destination_space;
};
private:
Colorspace source_space, destination_space;
};
#include <GL/glew.h>
#include <assert.h>
#include <GL/glew.h>
#include <assert.h>
+#include "colorspace_conversion_effect.h"
#include "d65.h"
#include "effect_util.h"
#include "util.h"
#include "d65.h"
#include "effect_util.h"
#include "util.h"
return Vector3d(x, y, 1.0 - x - y);
}
return Vector3d(x, y, 1.0 - x - y);
}
-// Assuming sRGB primaries, from Wikipedia.
-const 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
/*
* There are several different perceptual color spaces with different intended
* uses; for instance, CIECAM02 uses one space (CAT02) for purposes of computing
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 std::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 rgb(neutral_color.r, neutral_color.g, neutral_color.b);
- Vector3d xyz = Map<const Matrix3d>(rgb_to_xyz_matrix) * rgb;
+ Vector3d xyz = rgb_to_xyz_matrix * rgb;
Vector3d lms_scale = compute_lms_scaling_factors(xyz);
/*
Vector3d lms_scale = compute_lms_scaling_factors(xyz);
/*
* has to be the opposite of the execution order.
*/
Matrix3d corr_matrix =
* has to be the opposite of the execution order.
*/
Matrix3d corr_matrix =
- Map<const Matrix3d>(rgb_to_xyz_matrix).inverse() *
+ rgb_to_xyz_matrix.inverse() *
Map<const Matrix3d>(xyz_to_lms_matrix).inverse() *
lms_scale.asDiagonal() *
Map<const Matrix3d>(xyz_to_lms_matrix) *
Map<const Matrix3d>(xyz_to_lms_matrix).inverse() *
lms_scale.asDiagonal() *
Map<const Matrix3d>(xyz_to_lms_matrix) *
- Map<const Matrix3d>(rgb_to_xyz_matrix);
set_uniform_mat3(glsl_program_num, prefix, "correction_matrix", corr_matrix);
}
set_uniform_mat3(glsl_program_num, prefix, "correction_matrix", corr_matrix);
}