X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=main.cpp;h=3c807a1b7af588fb9b9cffb4a56f734b350d5f75;hp=bbc775271b7d3c46b26caa03f5ed39997d7a0ae0;hb=42c35394ef92bb5179fc4879cb55b866fd422d28;hpb=05ae48a62f4a507c1eef75b9220f88f2b9fda563 diff --git a/main.cpp b/main.cpp index bbc7752..3c807a1 100644 --- a/main.cpp +++ b/main.cpp @@ -18,14 +18,17 @@ #include #include -#include -#include - #include "effect.h" #include "effect_chain.h" #include "util.h" +#include "opengl.h" #include "widgets.h" +#include "flat_input.h" +#include "lift_gamma_gain_effect.h" +#include "saturation_effect.h" +#include "diffusion_effect.h" + unsigned char result[WIDTH * HEIGHT * 4]; float lift_theta = 0.0f, lift_rad = 0.0f, lift_v = 0.0f; @@ -44,9 +47,9 @@ void update_hsv(Effect *lift_gamma_gain_effect, Effect *saturation_effect) RGBTriplet gamma(1.0f, 1.0f, 1.0f); RGBTriplet gain(1.0f, 1.0f, 1.0f); - hsv2rgb(lift_theta, lift_rad, lift_v, &lift.r, &lift.g, &lift.b); - hsv2rgb(gamma_theta, gamma_rad, gamma_v * 2.0f, &gamma.r, &gamma.g, &gamma.b); - hsv2rgb(gain_theta, gain_rad, gain_v * 4.0f, &gain.r, &gain.g, &gain.b); + hsv2rgb_normalized(lift_theta, lift_rad, lift_v, &lift.r, &lift.g, &lift.b); + hsv2rgb_normalized(gamma_theta, gamma_rad, gamma_v * 2.0f, &gamma.r, &gamma.g, &gamma.b); + hsv2rgb_normalized(gain_theta, gain_rad, gain_v * 4.0f, &gain.r, &gain.g, &gain.b); bool ok = lift_gamma_gain_effect->set_vec3("lift", (float *)&lift); ok = ok && lift_gamma_gain_effect->set_vec3("gamma", (float *)&gamma); @@ -160,24 +163,26 @@ int main(int argc, char **argv) EffectChain chain(WIDTH, HEIGHT); ImageFormat inout_format; - inout_format.pixel_format = FORMAT_BGRA; inout_format.color_space = COLORSPACE_sRGB; inout_format.gamma_curve = GAMMA_sRGB; - chain.add_input(inout_format); - Effect *lift_gamma_gain_effect = chain.add_effect(EFFECT_LIFT_GAMMA_GAIN); - Effect *saturation_effect = chain.add_effect(EFFECT_SATURATION); - Effect *diffusion_effect = chain.add_effect(EFFECT_DIFFUSION); - //Effect *vignette_effect = chain.add_effect(EFFECT_VIGNETTE); - //Effect *sandbox_effect = chain.add_effect(EFFECT_SANDBOX); + FlatInput *input = new FlatInput(inout_format, FORMAT_BGRA, img_w, img_h); + chain.add_input(input); + Effect *lift_gamma_gain_effect = chain.add_effect(new LiftGammaGainEffect()); + Effect *saturation_effect = chain.add_effect(new SaturationEffect()); + Effect *diffusion_effect = chain.add_effect(new DiffusionEffect()); + //Effect *vignette_effect = chain.add_effect(new VignetteEffect()); + //Effect *sandbox_effect = chain.add_effect(new SandboxEffect()); //sandbox_effect->set_float("parm", 42.0f); - //chain.add_effect(EFFECT_MIRROR); + //chain.add_effect(new MirrorEffect()); chain.add_output(inout_format); chain.finalize(); - // generate a PDO to hold the data we read back with glReadPixels() - // (Intel/DRI goes into a slow path if we don't read to PDO) - glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 1); + // generate a PBO to hold the data we read back with glReadPixels() + // (Intel/DRI goes into a slow path if we don't read to PBO) + GLuint pbo; + glGenBuffers(1, &pbo); + glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pbo); glBufferData(GL_PIXEL_PACK_BUFFER_ARB, WIDTH * HEIGHT * 4, NULL, GL_STREAM_READ); make_hsv_wheel_texture(); @@ -217,9 +222,10 @@ int main(int argc, char **argv) diffusion_effect->set_float("radius", blur_radius); diffusion_effect->set_float("blurred_mix_amount", blurred_mix_amount); - chain.render_to_screen(src_img); + input->set_pixel_data(src_img); + chain.render_to_screen(); - glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 1); + glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pbo); check_error(); glReadPixels(0, 0, WIDTH, HEIGHT, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, BUFFER_OFFSET(0)); check_error(); @@ -241,7 +247,7 @@ int main(int argc, char **argv) SDL_GL_SwapBuffers(); check_error(); - glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 1); + glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pbo); check_error(); unsigned char *screenbuf = (unsigned char *)glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY); check_error();