output_width(1280),
output_height(720),
top(0),
- left(0),
- pad_from_bottom(0)
+ left(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);
}
string PaddingEffect::output_fragment_shader()
{
Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
- 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;
- }
+ float offset[2] = {
+ left / output_width,
+ (output_height - input_height - top) / output_height
+ };
set_uniform_vec2(glsl_program_num, prefix, "offset", offset);
float scale[2] = {
// The border color is taken to be in linear gamma, sRGB, with premultiplied alpha.
// You may not change it after calling finalize(), since that could change the
// graph (need_linear_light() etc. depend on the border color you choose).
-//
-// As a convenience, if the flag “pad_from_bottom” is nonzero, the “top” parameter
-// will mean pixels from the bottom (matching OpenGL's usual bottom-left convention),
-// instead of from the top as usual.
#include <GL/glew.h>
#include <string>
int input_width, input_height;
int output_width, output_height;
float top, left;
- int pad_from_bottom;
};
} // namespace movit
expect_equal(expected_data, out_data, 1, 1);
}
-TEST(PaddingEffectTest, CropFromBottom) {
- float data[2 * 2] = {
- 1.0f, 0.5f,
- 0.8f, 0.3f,
- };
- float expected_data[1 * 1] = {
- 0.5f,
- };
- float out_data[1 * 1];
-
- EffectChainTester tester(NULL, 1, 1);
-
- ImageFormat format;
- format.color_space = COLORSPACE_sRGB;
- format.gamma_curve = GAMMA_LINEAR;
-
- FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, 2, 2);
- input->set_pixel_data(data);
- tester.get_chain()->add_input(input);
-
- Effect *effect = tester.get_chain()->add_effect(new PaddingEffect());
- CHECK(effect->set_int("width", 1));
- CHECK(effect->set_int("height", 1));
- CHECK(effect->set_float("left", -1.0f));
- CHECK(effect->set_float("top", -1.0f));
- CHECK(effect->set_int("pad_from_bottom", 1));
-
- tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR, OUTPUT_ALPHA_FORMAT_PREMULTIPLIED);
- expect_equal(expected_data, out_data, 1, 1);
-}
-
TEST(PaddingEffectTest, AlphaIsCorrectEvenWithNonLinearInputsAndOutputs) {
float data[2 * 1] = {
1.0f,