From 72afc695d201f9d2a0dcb316ec62f1610db5fa74 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 21 Apr 2017 20:19:00 +0200 Subject: [PATCH] Change from RGBA to BGRA; slightly more Intel GPU-friendly, and Caspar uses that format. --- bmusb | 2 +- ffmpeg_capture.cpp | 2 +- ffmpeg_capture.h | 6 +++--- mixer.cpp | 14 +++++++------- pbo_frame_allocator.cpp | 12 ++++++------ theme.cpp | 8 +++++--- theme.h | 4 ++-- 7 files changed, 25 insertions(+), 23 deletions(-) diff --git a/bmusb b/bmusb index 824260a..c245ceb 160000 --- a/bmusb +++ b/bmusb @@ -1 +1 @@ -Subproject commit 824260a0732a49b5a18f2e16e04b0373c37a3bea +Subproject commit c245ceb9081e412bb815480481670e295ddfc71a diff --git a/ffmpeg_capture.cpp b/ffmpeg_capture.cpp index 2f9c6fd..ab35c5c 100644 --- a/ffmpeg_capture.cpp +++ b/ffmpeg_capture.cpp @@ -297,7 +297,7 @@ bool FFmpegCapture::play_video(const string &pathname) if (sws_ctx == nullptr || sws_last_width != frame->width || sws_last_height != frame->height) { sws_ctx.reset( sws_getContext(frame->width, frame->height, (AVPixelFormat)frame->format, - width, height, AV_PIX_FMT_RGBA, + width, height, AV_PIX_FMT_BGRA, SWS_BICUBIC, nullptr, nullptr, nullptr)); sws_last_width = frame->width; sws_last_height = frame->height; diff --git a/ffmpeg_capture.h b/ffmpeg_capture.h index 3b2f0e4..9753c00 100644 --- a/ffmpeg_capture.h +++ b/ffmpeg_capture.h @@ -117,13 +117,13 @@ public: uint32_t get_current_video_mode() const override { return 0; } std::set get_available_pixel_formats() const override { - return std::set{ bmusb::PixelFormat_8BitRGBA }; + return std::set{ bmusb::PixelFormat_8BitBGRA }; } void set_pixel_format(bmusb::PixelFormat pixel_format) override { - assert(pixel_format == bmusb::PixelFormat_8BitRGBA); + assert(pixel_format == bmusb::PixelFormat_8BitBGRA); } bmusb::PixelFormat get_current_pixel_format() const override { - return bmusb::PixelFormat_8BitRGBA; + return bmusb::PixelFormat_8BitBGRA; } std::map get_available_video_inputs() const override { diff --git a/mixer.cpp b/mixer.cpp index 84419f4..3a14a75 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -89,7 +89,7 @@ void ensure_texture_resolution(PBOFrameAllocator::Userdata *userdata, unsigned f case bmusb::PixelFormat_8BitYCbCr: first = userdata->tex_y[field] == 0 || userdata->tex_cbcr[field] == 0; break; - case bmusb::PixelFormat_8BitRGBA: + case bmusb::PixelFormat_8BitBGRA: first = userdata->tex_rgba[field] == 0; break; default: @@ -122,13 +122,13 @@ void ensure_texture_resolution(PBOFrameAllocator::Userdata *userdata, unsigned f check_error(); break; } - case bmusb::PixelFormat_8BitRGBA: + case bmusb::PixelFormat_8BitBGRA: glBindTexture(GL_TEXTURE_2D, userdata->tex_rgba[field]); check_error(); if (global_flags.can_disable_srgb_decoder) { // See the comments in tweaked_inputs.h. - glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr); } else { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, nullptr); } check_error(); break; @@ -403,7 +403,7 @@ void Mixer::configure_card(unsigned card_index, CaptureInterface *capture, CardT bmusb::PixelFormat pixel_format; if (card_type == CardType::FFMPEG_INPUT) { - pixel_format = bmusb::PixelFormat_8BitRGBA; + pixel_format = bmusb::PixelFormat_8BitBGRA; } else if (global_flags.ten_bit_input) { pixel_format = PixelFormat_10BitYCbCr; } else { @@ -660,9 +660,9 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode, upload_texture(userdata->tex_cbcr[field], cbcr_width, video_format.height, cbcr_width * sizeof(uint16_t), interlaced_stride, GL_RG, GL_UNSIGNED_BYTE, field_cbcr_start); break; } - case bmusb::PixelFormat_8BitRGBA: { + case bmusb::PixelFormat_8BitBGRA: { size_t field_start = video_offset + video_format.stride * field_start_line; - upload_texture(userdata->tex_rgba[field], video_format.width, video_format.height, video_format.stride, interlaced_stride, GL_RGBA, GL_UNSIGNED_BYTE, field_start); + upload_texture(userdata->tex_rgba[field], video_format.width, video_format.height, video_format.stride, interlaced_stride, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, field_start); break; } default: diff --git a/pbo_frame_allocator.cpp b/pbo_frame_allocator.cpp index ed1ddb5..35e4ed5 100644 --- a/pbo_frame_allocator.cpp +++ b/pbo_frame_allocator.cpp @@ -38,7 +38,7 @@ PBOFrameAllocator::PBOFrameAllocator(bmusb::PixelFormat pixel_format, size_t fra // For 8-bit Y'CbCr, we ask the driver to split Y' and Cb/Cr // into separate textures. For 10-bit, the input format (v210) // is complicated enough that we need to interpolate up to 4:4:4, - // which we do in a compute shader ourselves. For RGBA, the data + // which we do in a compute shader ourselves. For BGRA, the data // is already 4:4:4:4. frame.interleaved = (pixel_format == bmusb::PixelFormat_8BitYCbCr); @@ -58,7 +58,7 @@ PBOFrameAllocator::PBOFrameAllocator(bmusb::PixelFormat pixel_format, size_t fra glGenTextures(2, userdata[i].tex_444); check_error(); break; - case bmusb::PixelFormat_8BitRGBA: + case bmusb::PixelFormat_8BitBGRA: glGenTextures(2, userdata[i].tex_rgba); check_error(); break; @@ -134,7 +134,7 @@ PBOFrameAllocator::PBOFrameAllocator(bmusb::PixelFormat pixel_format, size_t fra check_error(); } break; - case bmusb::PixelFormat_8BitRGBA: + case bmusb::PixelFormat_8BitBGRA: glBindTexture(GL_TEXTURE_2D, userdata[i].tex_rgba[field]); check_error(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -145,9 +145,9 @@ PBOFrameAllocator::PBOFrameAllocator(bmusb::PixelFormat pixel_format, size_t fra check_error(); if (field == 0) { if (global_flags.can_disable_srgb_decoder) { // See the comments in tweaked_inputs.h. - glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); } else { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); } check_error(); } @@ -192,7 +192,7 @@ PBOFrameAllocator::~PBOFrameAllocator() glDeleteTextures(2, ((Userdata *)frame.userdata)->tex_cbcr); check_error(); break; - case bmusb::PixelFormat_8BitRGBA: + case bmusb::PixelFormat_8BitBGRA: glDeleteTextures(2, ((Userdata *)frame.userdata)->tex_rgba); check_error(); break; diff --git a/theme.cpp b/theme.cpp index 1434baa..56e7ce2 100644 --- 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( - 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); @@ -692,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 { @@ -798,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); diff --git a/theme.h b/theme.h index b04050e..51107d6 100644 --- a/theme.h +++ b/theme.h @@ -103,7 +103,7 @@ private: // the mixer, and communicates that state over to the actual YCbCrInput. class LiveInputWrapper { public: - // Note: is irrelevant for PixelFormat_8BitRGBA. + // Note: is irrelevant for PixelFormat_8BitBGRA. LiveInputWrapper(Theme *theme, movit::EffectChain *chain, bmusb::PixelFormat pixel_format, bool override_bounce, bool deinterlace); void connect_signal(int signal_num); @@ -112,7 +112,7 @@ public: { if (deinterlace) { return deinterlace_effect; - } else if (pixel_format == bmusb::PixelFormat_8BitRGBA) { + } else if (pixel_format == bmusb::PixelFormat_8BitBGRA) { return rgba_inputs[0]; } else { return ycbcr_inputs[0]; -- 2.39.2