]> git.sesse.net Git - movit/blobdiff - padding_effect.cpp
Split out some private utilities into effect_util.cpp, so we do not need to include...
[movit] / padding_effect.cpp
index 9d6e292996f33aca18062597de166766d90a9550..40876b89e9a6edca0cf2c89146894c1d72f15070 100644 (file)
@@ -1,6 +1,7 @@
-#include <math.h>
 #include <GL/glew.h>
 #include <GL/glew.h>
+#include <assert.h>
 
 
+#include "effect_util.h"
 #include "padding_effect.h"
 #include "util.h"
 
 #include "padding_effect.h"
 #include "util.h"
 
@@ -46,14 +47,14 @@ void PaddingEffect::set_gl_state(GLuint glsl_program_num, const std::string &pre
        // than losing a pixel in the common cases of integer shift.
        // Thus the 1e-3 fudge factors.
        float texcoord_min[2] = {
        // than losing a pixel in the common cases of integer shift.
        // Thus the 1e-3 fudge factors.
        float texcoord_min[2] = {
-               (0.5f - 1e-3) / input_width,
-               (0.5f - 1e-3) / input_height
+               float((0.5f - 1e-3) / input_width),
+               float((0.5f - 1e-3) / input_height)
        };
        set_uniform_vec2(glsl_program_num, prefix, "texcoord_min", texcoord_min);
 
        float texcoord_max[2] = {
        };
        set_uniform_vec2(glsl_program_num, prefix, "texcoord_min", texcoord_min);
 
        float texcoord_max[2] = {
-               1.0f - (0.5f - 1e-3) / input_width,
-               1.0f - (0.5f - 1e-3) / input_height
+               float(1.0f - (0.5f - 1e-3) / input_width),
+               float(1.0f - (0.5f - 1e-3) / input_height)
        };
        set_uniform_vec2(glsl_program_num, prefix, "texcoord_max", texcoord_max);
 }
        };
        set_uniform_vec2(glsl_program_num, prefix, "texcoord_max", texcoord_max);
 }
@@ -89,20 +90,32 @@ bool PaddingEffect::needs_srgb_primaries() const
        return true;
 }
 
        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
 {
 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 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) const
+void PaddingEffect::get_output_size(unsigned *width, unsigned *height, unsigned *virtual_width, unsigned *virtual_height) const
 {
 {
-       *width = output_width;
-       *height = output_height;
+       *virtual_width = *width = output_width;
+       *virtual_height = *height = output_height;
 }
        
 void PaddingEffect::inform_input_size(unsigned input_num, unsigned width, unsigned height)
 }
        
 void PaddingEffect::inform_input_size(unsigned input_num, unsigned width, unsigned height)