8 #include "ycbcr_conversion_effect.h"
9 #include "effect_util.h"
14 using namespace Eigen;
18 YCbCrConversionEffect::YCbCrConversionEffect(const YCbCrFormat &ycbcr_format)
19 : ycbcr_format(ycbcr_format)
21 register_uniform_mat3("ycbcr_matrix", &uniform_ycbcr_matrix);
22 register_uniform_vec3("offset", uniform_offset);
23 register_uniform_bool("clamp_range", &uniform_clamp_range);
25 // Only used when clamp_range is true.
26 register_uniform_vec3("ycbcr_min", uniform_ycbcr_min);
27 register_uniform_vec3("ycbcr_max", uniform_ycbcr_max);
30 string YCbCrConversionEffect::output_fragment_shader()
32 return read_file("ycbcr_conversion_effect.frag");
35 void YCbCrConversionEffect::set_gl_state(GLuint glsl_program_num, const string &prefix, unsigned *sampler_num)
37 Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
39 Matrix3d ycbcr_to_rgb;
40 compute_ycbcr_matrix(ycbcr_format, uniform_offset, &ycbcr_to_rgb);
42 uniform_ycbcr_matrix = ycbcr_to_rgb.inverse();
44 if (ycbcr_format.full_range) {
45 // The card will clamp for us later.
46 uniform_clamp_range = false;
48 uniform_clamp_range = true;
50 // These limits come from BT.601 page 8, or BT.701, page 5.
51 // TODO: Use num_levels. Currently we support 8-bit levels only.
52 uniform_ycbcr_min[0] = 16.0 / 255.0;
53 uniform_ycbcr_min[1] = 16.0 / 255.0;
54 uniform_ycbcr_min[2] = 16.0 / 255.0;
55 uniform_ycbcr_max[0] = 235.0 / 255.0;
56 uniform_ycbcr_max[1] = 240.0 / 255.0;
57 uniform_ycbcr_max[2] = 240.0 / 255.0;