From 61e2a7671f7b22227dcdc34dd303ae4fcc802aaa Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 28 Jul 2015 14:01:45 +0200 Subject: [PATCH] Save a mul in YCbCrInput by folding the scaling into the matrix. --- ycbcr_input.cpp | 7 +++++-- ycbcr_input.frag | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ycbcr_input.cpp b/ycbcr_input.cpp index 22d689d..25fb979 100644 --- a/ycbcr_input.cpp +++ b/ycbcr_input.cpp @@ -143,7 +143,8 @@ void YCbCrInput::set_gl_state(GLuint glsl_program_num, const string& prefix, uns string YCbCrInput::output_fragment_shader() { - float coeff[3], offset[3], scale[3]; + float coeff[3], offset[3]; + double scale[3]; switch (ycbcr_format.luma_coefficients) { case YCBCR_REC_601: @@ -209,11 +210,13 @@ string YCbCrInput::output_fragment_shader() // Inverting the matrix gives us what we need to go from YCbCr back to RGB. Matrix3d ycbcr_to_rgb = rgb_to_ycbcr.inverse(); + // Fold in the scaling. + ycbcr_to_rgb *= Map(scale).asDiagonal(); + string frag_shader; frag_shader = output_glsl_mat3("PREFIX(inv_ycbcr_matrix)", ycbcr_to_rgb); frag_shader += output_glsl_vec3("PREFIX(offset)", offset[0], offset[1], offset[2]); - frag_shader += output_glsl_vec3("PREFIX(scale)", scale[0], scale[1], scale[2]); float cb_offset_x = compute_chroma_offset( ycbcr_format.cb_x_position, ycbcr_format.chroma_subsampling_x, widths[1]); diff --git a/ycbcr_input.frag b/ycbcr_input.frag index fbf20d1..bd6ff76 100644 --- a/ycbcr_input.frag +++ b/ycbcr_input.frag @@ -14,7 +14,6 @@ vec4 FUNCNAME(vec2 tc) { ycbcr.z = tex2D(PREFIX(tex_cr), tc + PREFIX(cr_offset)).x; ycbcr -= PREFIX(offset); - ycbcr *= PREFIX(scale); vec4 rgba; rgba.rgb = PREFIX(inv_ycbcr_matrix) * ycbcr; -- 2.39.2