X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=padding_effect.cpp;h=5ca976c2f9fca6d8d606a469e981456c7141c56a;hp=f576baa2d5c3f8cb043a0395cdd3d3314a7bdd90;hb=82071a94aaff95d2d29d077338085a8fb27e76d1;hpb=ee7863d9cdd683dd4df9d6463d98dc59182c54fe diff --git a/padding_effect.cpp b/padding_effect.cpp index f576baa..5ca976c 100644 --- a/padding_effect.cpp +++ b/padding_effect.cpp @@ -14,13 +14,21 @@ PaddingEffect::PaddingEffect() output_width(1280), output_height(720), top(0), - left(0) + left(0), + border_offset_top(0.0f), + border_offset_left(0.0f), + border_offset_bottom(0.0f), + border_offset_right(0.0f) { register_vec4("border_color", (float *)&border_color); register_int("width", &output_width); register_int("height", &output_height); register_float("top", &top); register_float("left", &left); + register_float("border_offset_top", &border_offset_top); + register_float("border_offset_left", &border_offset_left); + register_float("border_offset_bottom", &border_offset_bottom); + register_float("border_offset_right", &border_offset_right); } string PaddingEffect::output_fragment_shader() @@ -44,23 +52,24 @@ void PaddingEffect::set_gl_state(GLuint glsl_program_num, const string &prefix, }; set_uniform_vec2(glsl_program_num, prefix, "scale", scale); - // Due to roundoff errors, the test against 0.5 is seldom exact, - // even though we test for less than and not less-than-or-equal. - // We'd rather keep an extra border pixel in those very rare cases - // (where the image is shifted pretty much exactly a half-pixel) - // than losing a pixel in the common cases of integer shift. - // Thus the 1e-3 fudge factors. - float texcoord_min[2] = { - float((0.5f - 1e-3) / input_width), - float((0.5f - 1e-3) / input_height) + float normalized_coords_to_texels[2] = { + float(input_width), float(input_height) }; - set_uniform_vec2(glsl_program_num, prefix, "texcoord_min", texcoord_min); + set_uniform_vec2(glsl_program_num, prefix, "normalized_coords_to_texels", normalized_coords_to_texels); - float texcoord_max[2] = { - float(1.0f - (0.5f - 1e-3) / input_width), - float(1.0f - (0.5f - 1e-3) / input_height) + // Texels -0.5..0.5 should map to light level 0..1 (and then we + // clamp the rest). + float offset_bottomleft[2] = { + 0.5f - border_offset_left, 0.5f + border_offset_bottom, }; - set_uniform_vec2(glsl_program_num, prefix, "texcoord_max", texcoord_max); + + // Texels size-0.5..size+0.5 should map to light level 1..0 (and then clamp). + float offset_topright[2] = { + input_width + 0.5f + border_offset_right, input_height + 0.5f - border_offset_top, + }; + + set_uniform_vec2(glsl_program_num, prefix, "offset_bottomleft", offset_bottomleft); + set_uniform_vec2(glsl_program_num, prefix, "offset_topright", offset_topright); } // We don't change the pixels of the image itself, so the only thing that @@ -133,4 +142,25 @@ void PaddingEffect::inform_input_size(unsigned input_num, unsigned width, unsign input_height = height; } +IntegralPaddingEffect::IntegralPaddingEffect() {} + +bool IntegralPaddingEffect::set_int(const std::string &key, int value) +{ + if (key == "top" || key == "left") { + return PaddingEffect::set_float(key, value); + } else { + return PaddingEffect::set_int(key, value); + } +} + +bool IntegralPaddingEffect::set_float(const std::string &key, float value) +{ + if (key == "top" || key == "left") { + // These are removed as float parameters from this version. + return false; + } else { + return PaddingEffect::set_float(key, value); + } +} + } // namespace movit