From 5d4c0425579de66b3e2dd7d0095e890278f8efcf Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 2 Feb 2013 00:38:46 +0100 Subject: [PATCH 1/1] Give the alpha enums somewhat better/more consistent names, and shuffle them around a bit. --- blur_effect.h | 2 +- demo.cpp | 2 +- effect.h | 12 ++++++------ effect_chain.cpp | 12 ++++++------ effect_chain.h | 2 +- flat_input.h | 4 ++-- gamma_compression_effect.h | 2 +- overlay_effect.h | 2 +- padding_effect.cpp | 2 +- padding_effect_test.cpp | 2 +- test_util.h | 4 ++-- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/blur_effect.h b/blur_effect.h index 792014b..4af11a2 100644 --- a/blur_effect.h +++ b/blur_effect.h @@ -24,7 +24,7 @@ public: virtual bool needs_texture_bounce() const { return true; } virtual bool needs_mipmaps() const { return true; } virtual bool needs_srgb_primaries() const { return false; } - virtual AlphaHandling alpha_handling() const { return INPUT_AND_OUTPUT_ALPHA_PREMULTIPLIED; } + virtual AlphaHandling alpha_handling() const { return INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA; } virtual void inform_input_size(unsigned input_num, unsigned width, unsigned height); diff --git a/demo.cpp b/demo.cpp index 6e5f18c..298b536 100644 --- a/demo.cpp +++ b/demo.cpp @@ -196,7 +196,7 @@ int main(int argc, char **argv) //Effect *sandbox_effect = chain.add_effect(new SandboxEffect()); //sandbox_effect->set_float("parm", 42.0f); //chain.add_effect(new MirrorEffect()); - chain.add_output(inout_format, OUTPUT_ALPHA_POSTMULTIPLIED); + chain.add_output(inout_format, OUTPUT_POSTMULTIPLIED_ALPHA); chain.set_dither_bits(8); chain.finalize(); diff --git a/effect.h b/effect.h index c911f27..43849df 100644 --- a/effect.h +++ b/effect.h @@ -99,7 +99,7 @@ public: // This is the most natural format for processing, and the default in // most of Movit (just like linear light is). // - // If you set INPUT_AND_OUTPUT_ALPHA_PREMULTIPLIED, all of your inputs + // If you set INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA, all of your inputs // (if any) are guaranteed to also be in premultiplied alpha. // Otherwise, you can get postmultiplied or premultiplied alpha; // you won't know. If you have multiple inputs, you will get the same @@ -113,13 +113,13 @@ public: // pre- and postmultiplied. OUTPUT_BLANK_ALPHA, + // Always outputs postmultiplied alpha. Only appropriate for inputs. + OUTPUT_POSTMULTIPLIED_ALPHA, + // Always outputs premultiplied alpha. As noted above, // you will then also get all inputs in premultiplied alpha. // If you set this, you should also set needs_linear_light(). - INPUT_AND_OUTPUT_ALPHA_PREMULTIPLIED, - - // Always outputs postmultiplied alpha. Only appropriate for inputs. - OUTPUT_ALPHA_POSTMULTIPLIED, + INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA, // Keeps the type of alpha unchanged from input to output. // Usually appropriate if you process all color channels @@ -128,7 +128,7 @@ public: // Does not make sense for inputs. DONT_CARE_ALPHA_TYPE, }; - virtual AlphaHandling alpha_handling() const { return INPUT_AND_OUTPUT_ALPHA_PREMULTIPLIED; } + virtual AlphaHandling alpha_handling() const { return INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA; } // Whether this effect expects its input to come directly from // a texture. If this is true, the framework will not chain the diff --git a/effect_chain.cpp b/effect_chain.cpp index 8a7ea9a..c04e34d 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -776,10 +776,10 @@ void EffectChain::find_color_spaces_for_inputs() case Effect::OUTPUT_BLANK_ALPHA: node->output_alpha_type = ALPHA_BLANK; break; - case Effect::INPUT_AND_OUTPUT_ALPHA_PREMULTIPLIED: + case Effect::INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA: node->output_alpha_type = ALPHA_PREMULTIPLIED; break; - case Effect::OUTPUT_ALPHA_POSTMULTIPLIED: + case Effect::OUTPUT_POSTMULTIPLIED_ALPHA: node->output_alpha_type = ALPHA_POSTMULTIPLIED; break; case Effect::DONT_CARE_ALPHA_TYPE: @@ -885,7 +885,7 @@ void EffectChain::propagate_alpha() } // Only inputs can have unconditional alpha output (OUTPUT_BLANK_ALPHA - // or OUTPUT_ALPHA_POSTMULTIPLIED), and they have already been + // or OUTPUT_POSTMULTIPLIED_ALPHA), and they have already been // taken care of above. Rationale: Even if you could imagine // e.g. an effect that took in an image and set alpha=1.0 // unconditionally, it wouldn't make any sense to have it as @@ -893,7 +893,7 @@ void EffectChain::propagate_alpha() // got its input pre- or postmultiplied, so it wouldn't know // whether to divide away the old alpha or not. Effect::AlphaHandling alpha_handling = node->effect->alpha_handling(); - assert(alpha_handling == Effect::INPUT_AND_OUTPUT_ALPHA_PREMULTIPLIED || + assert(alpha_handling == Effect::INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA || alpha_handling == Effect::DONT_CARE_ALPHA_TYPE); // If the node has multiple inputs, check that they are all valid and @@ -933,7 +933,7 @@ void EffectChain::propagate_alpha() continue; } - if (alpha_handling == Effect::INPUT_AND_OUTPUT_ALPHA_PREMULTIPLIED) { + if (alpha_handling == Effect::INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA) { // If the effect has asked for premultiplied alpha, check that it has got it. if (any_postmultiplied) { node->output_alpha_type = ALPHA_INVALID; @@ -1141,7 +1141,7 @@ void EffectChain::fix_output_alpha() return; } if (output->output_alpha_type == ALPHA_PREMULTIPLIED && - output_alpha_format == OUTPUT_ALPHA_POSTMULTIPLIED) { + output_alpha_format == OUTPUT_POSTMULTIPLIED_ALPHA) { Node *conversion = add_node(new AlphaDivisionEffect()); connect_nodes(output, conversion); propagate_alpha(); diff --git a/effect_chain.h b/effect_chain.h index bfe52c0..f5064eb 100644 --- a/effect_chain.h +++ b/effect_chain.h @@ -23,7 +23,7 @@ enum AlphaType { // (see effect.h for a discussion of pre- versus postmultiplied alpha). enum OutputAlphaFormat { OUTPUT_ALPHA_PREMULTIPLIED, - OUTPUT_ALPHA_POSTMULTIPLIED, + OUTPUT_POSTMULTIPLIED_ALPHA, }; // A node in the graph; basically an effect and some associated information. diff --git a/flat_input.h b/flat_input.h index 87a0d5e..24a3fca 100644 --- a/flat_input.h +++ b/flat_input.h @@ -30,10 +30,10 @@ public: switch (pixel_format) { case FORMAT_RGBA_PREMULTIPLIED_ALPHA: case FORMAT_BGRA_PREMULTIPLIED_ALPHA: - return INPUT_AND_OUTPUT_ALPHA_PREMULTIPLIED; + return INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA; case FORMAT_RGBA_POSTMULTIPLIED_ALPHA: case FORMAT_BGRA_POSTMULTIPLIED_ALPHA: - return OUTPUT_ALPHA_POSTMULTIPLIED; + return OUTPUT_POSTMULTIPLIED_ALPHA; case FORMAT_RGB: case FORMAT_BGR: case FORMAT_GRAYSCALE: diff --git a/gamma_compression_effect.h b/gamma_compression_effect.h index 2744d2d..46ac80e 100644 --- a/gamma_compression_effect.h +++ b/gamma_compression_effect.h @@ -26,7 +26,7 @@ public: // Actually needs postmultiplied input as well as outputting it. // EffectChain will take care of that. - virtual AlphaHandling alpha_handling() const { return OUTPUT_ALPHA_POSTMULTIPLIED; } + virtual AlphaHandling alpha_handling() const { return OUTPUT_POSTMULTIPLIED_ALPHA; } private: GammaCurve destination_curve; diff --git a/overlay_effect.h b/overlay_effect.h index 64224af..d26d917 100644 --- a/overlay_effect.h +++ b/overlay_effect.h @@ -24,7 +24,7 @@ public: // Actually, if either image has blank alpha, our output will have // blank alpha, too. However, understanding that would require changes // to EffectChain, so postpone that optimization for later. - virtual AlphaHandling alpha_handling() const { return INPUT_AND_OUTPUT_ALPHA_PREMULTIPLIED; } + virtual AlphaHandling alpha_handling() const { return INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA; } }; #endif // !defined(_OVERLAY_EFFECT_H) diff --git a/padding_effect.cpp b/padding_effect.cpp index c06a1ac..3c4919a 100644 --- a/padding_effect.cpp +++ b/padding_effect.cpp @@ -96,7 +96,7 @@ Effect::AlphaHandling PaddingEffect::alpha_handling() const if (border_color.r == 0.0 && border_color.g == 0.0 && border_color.b == 0.0) { return DONT_CARE_ALPHA_TYPE; } - return INPUT_AND_OUTPUT_ALPHA_PREMULTIPLIED; + return INPUT_AND_OUTPUT_PREMULTIPLIED_ALPHA; } void PaddingEffect::get_output_size(unsigned *width, unsigned *height, unsigned *virtual_width, unsigned *virtual_height) const diff --git a/padding_effect_test.cpp b/padding_effect_test.cpp index ecd0d1e..1d2be79 100644 --- a/padding_effect_test.cpp +++ b/padding_effect_test.cpp @@ -103,7 +103,7 @@ TEST(PaddingEffectTest, BorderColorIsInLinearGamma) { RGBATriplet border_color(0.2f, 0.4f, 0.6f, 0.8f); // Same as the pixel in data[]. CHECK(effect->set_vec4("border_color", (float *)&border_color)); - tester.run(out_data, GL_RGBA, COLORSPACE_REC_601_625, GAMMA_REC_601, OUTPUT_ALPHA_POSTMULTIPLIED); + tester.run(out_data, GL_RGBA, COLORSPACE_REC_601_625, GAMMA_REC_601, OUTPUT_POSTMULTIPLIED_ALPHA); expect_equal(expected_data, out_data, 4, 2); } diff --git a/test_util.h b/test_util.h index 9066591..eca6b6a 100644 --- a/test_util.h +++ b/test_util.h @@ -15,8 +15,8 @@ public: EffectChain *get_chain() { return &chain; } Input *add_input(const float *data, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve); Input *add_input(const unsigned char *data, MovitPixelFormat pixel_format, Colorspace color_space, GammaCurve gamma_curve); - void run(float *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format = OUTPUT_ALPHA_POSTMULTIPLIED); - void run(unsigned char *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format = OUTPUT_ALPHA_POSTMULTIPLIED); + void run(float *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format = OUTPUT_POSTMULTIPLIED_ALPHA); + void run(unsigned char *out_data, GLenum format, Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format = OUTPUT_POSTMULTIPLIED_ALPHA); private: void finalize_chain(Colorspace color_space, GammaCurve gamma_curve, OutputAlphaFormat alpha_format); -- 2.39.2