X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=padding_effect.cpp;h=00d475ac2fb23995780920569ee09203abb91177;hp=3c4919a0c3b1b98a3aa31ebf9aad14ff536bcdcf;hb=5c97329dd35909847e2120b0b368b2723ffe5a44;hpb=5d4c0425579de66b3e2dd7d0095e890278f8efcf;ds=sidebyside diff --git a/padding_effect.cpp b/padding_effect.cpp index 3c4919a..00d475a 100644 --- a/padding_effect.cpp +++ b/padding_effect.cpp @@ -1,6 +1,7 @@ -#include #include +#include +#include "effect_util.h" #include "padding_effect.h" #include "util.h" @@ -63,12 +64,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; @@ -89,13 +94,25 @@ bool PaddingEffect::needs_srgb_primaries() const return true; } -// If the border color is black, it doesn't matter if we're pre- or postmultiplied -// (or even blank, as a hack). Otherwise, it does. Effect::AlphaHandling PaddingEffect::alpha_handling() const { - if (border_color.r == 0.0 && border_color.g == 0.0 && border_color.b == 0.0) { + // If the border color is black, it doesn't matter if we're pre- or postmultiplied. + // Note that for non-solid black (i.e. alpha < 1.0), we're equally fine with + // pre- and postmultiplied, but later effects might change this status + // (consider e.g. blur), so setting DONT_CARE_ALPHA_TYPE is inappropriate, + // as it propagate blank alpha through this effect. + if (border_color.r == 0.0 && border_color.g == 0.0 && border_color.b == 0.0 && border_color.a == 1.0) { return DONT_CARE_ALPHA_TYPE; } + + // If the border color is solid, we preserve blank alpha, as we never output any + // new non-solid pixels. + if (border_color.a == 1.0) { + return INPUT_PREMULTIPLIED_ALPHA_KEEP_BLANK; + } + + // Otherwise, we're going to output our border color in premultiplied alpha, + // so the other pixels better be premultiplied as well. return INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA; }