X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=padding_effect.cpp;h=a70025d015475f885a9841d96e40c08fe3ac762e;hp=40876b89e9a6edca0cf2c89146894c1d72f15070;hb=7dca345804c7851ff09edcc7198c5def94b9c4b1;hpb=ad66f9714e4a36008c341355700272a52484a785 diff --git a/padding_effect.cpp b/padding_effect.cpp index 40876b8..a70025d 100644 --- a/padding_effect.cpp +++ b/padding_effect.cpp @@ -5,33 +5,42 @@ #include "padding_effect.h" #include "util.h" +using namespace std; + +namespace movit { + PaddingEffect::PaddingEffect() : border_color(0.0f, 0.0f, 0.0f, 0.0f), output_width(1280), output_height(720), top(0), - left(0) + left(0), + pad_from_bottom(0) { 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_int("pad_from_bottom", &pad_from_bottom); } -std::string PaddingEffect::output_fragment_shader() +string PaddingEffect::output_fragment_shader() { return read_file("padding_effect.frag"); } -void PaddingEffect::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) +void PaddingEffect::set_gl_state(GLuint glsl_program_num, const string &prefix, unsigned *sampler_num) { Effect::set_gl_state(glsl_program_num, prefix, sampler_num); - float offset[2] = { - left / output_width, - (output_height - input_height - top) / output_height - }; + float offset[2]; + offset[0] = left / output_width; + if (pad_from_bottom) { + offset[1] = top / output_height; + } else { + offset[1] = (output_height - input_height - top) / output_height; + } set_uniform_vec2(glsl_program_num, prefix, "offset", offset); float scale[2] = { @@ -64,12 +73,16 @@ void PaddingEffect::set_gl_state(GLuint glsl_program_num, const std::string &pre // differently in different modes. // 0.0 and 1.0 are interpreted the same, no matter the gamma ramp. -// Alpha is not affected by gamma. +// Alpha is not affected by gamma per se, but the combination of +// premultiplied alpha and non-linear gamma curve does not make sense, +// so if could possibly be converting blank alpha to non-blank +// (ie., premultiplied), we need our output to be in linear light. bool PaddingEffect::needs_linear_light() const { if ((border_color.r == 0.0 || border_color.r == 1.0) && (border_color.g == 0.0 || border_color.g == 1.0) && - (border_color.b == 0.0 || border_color.b == 1.0)) { + (border_color.b == 0.0 || border_color.b == 1.0) && + border_color.a == 1.0) { return false; } return true; @@ -124,3 +137,5 @@ void PaddingEffect::inform_input_size(unsigned input_num, unsigned width, unsign input_width = width; input_height = height; } + +} // namespace movit