X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=padding_effect.cpp;h=f7f97078e608749ab1a70db4226e2984be6281fb;hb=37f56fcbe571b2322243f6de59494bf9e0cbb37a;hp=c06a1ac49ef03b36cfa5ad338c71205aeb80d0b8;hpb=2322070a3dbeb6b46b39cca07a0fbf20e95f5468;p=movit diff --git a/padding_effect.cpp b/padding_effect.cpp index c06a1ac..f7f9707 100644 --- a/padding_effect.cpp +++ b/padding_effect.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include "padding_effect.h" #include "util.h" @@ -89,14 +89,26 @@ 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; } - return INPUT_AND_OUTPUT_ALPHA_PREMULTIPLIED; + + // 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; } void PaddingEffect::get_output_size(unsigned *width, unsigned *height, unsigned *virtual_width, unsigned *virtual_height) const