From: Steinar H. Gunderson Date: Tue, 28 Jul 2015 12:01:45 +0000 (+0200) Subject: Save a mul in YCbCrInput by folding the scaling into the matrix. X-Git-Tag: 1.2.0~48 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=61e2a7671f7b22227dcdc34dd303ae4fcc802aaa;hp=db7e679496cb587f6197822171f6fbcd61a7a6b7 Save a mul in YCbCrInput by folding the scaling into the matrix. --- 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;