]> git.sesse.net Git - nageru/blobdiff - theme.cpp
Fix an issue where RGBA videos would flicker.
[nageru] / theme.cpp
index 7ece56a928330bc1baad55ac357e06ebf231b963..56e7ce2de3285733707c425b7d61f076eda6266b 100644 (file)
--- a/theme.cpp
+++ b/theme.cpp
@@ -222,7 +222,7 @@ int EffectChain_add_video_input(lua_State* L)
        // doesn't care about the object anymore. (If we change this, we'd need
        // to also unregister the signal connection on __gc.)
        int ret = wrap_lua_object_nonowned<LiveInputWrapper>(
-               L, "LiveInputWrapper", theme, chain, bmusb::PixelFormat_8BitRGBA,
+               L, "LiveInputWrapper", theme, chain, bmusb::PixelFormat_8BitBGRA,
                /*override_bounce=*/false, deinterlace);
        if (ret == 1) {
                Theme *theme = get_theme_updata(L);
@@ -360,6 +360,15 @@ int VideoInput_rewind(lua_State* L)
        return 0;
 }
 
+int VideoInput_change_rate(lua_State* L)
+{
+       assert(lua_gettop(L) == 2);
+       FFmpegCapture **video_input = (FFmpegCapture **)luaL_checkudata(L, 1, "VideoInput");
+       double new_rate = luaL_checknumber(L, 2);
+       (*video_input)->change_rate(new_rate);
+       return 0;
+}
+
 int WhiteBalanceEffect_new(lua_State* L)
 {
        assert(lua_gettop(L) == 0);
@@ -562,6 +571,7 @@ const luaL_Reg ImageInput_funcs[] = {
 const luaL_Reg VideoInput_funcs[] = {
        { "new", VideoInput_new },
        { "rewind", VideoInput_rewind },
+       { "change_rate", VideoInput_change_rate },
        { NULL, NULL }
 };
 
@@ -682,8 +692,10 @@ LiveInputWrapper::LiveInputWrapper(Theme *theme, EffectChain *chain, bmusb::Pixe
                num_inputs = 1;
        }
 
-       if (pixel_format == bmusb::PixelFormat_8BitRGBA) {
+       if (pixel_format == bmusb::PixelFormat_8BitBGRA) {
                for (unsigned i = 0; i < num_inputs; ++i) {
+                       // We upload our textures ourselves, and Movit swaps
+                       // R and B in the shader if we specify BGRA, so lie and say RGBA.
                        if (global_flags.can_disable_srgb_decoder) {
                                rgba_inputs.push_back(new sRGBSwitchingFlatInput(inout_format, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, GL_UNSIGNED_BYTE, global_flags.width, global_flags.height));
                        } else {
@@ -788,7 +800,7 @@ void LiveInputWrapper::connect_signal_raw(int signal_num)
                        ycbcr_inputs[i]->set_width(this_width);
                        ycbcr_inputs[i]->set_height(this_height);
                        break;
-               case bmusb::PixelFormat_8BitRGBA:
+               case bmusb::PixelFormat_8BitBGRA:
                        rgba_inputs[i]->set_texture_num(userdata->tex_rgba[frame.field_number]);
                        rgba_inputs[i]->set_width(this_width);
                        rgba_inputs[i]->set_height(this_height);