From f243f859f49d46f4e654a24f28c3d557b8a92e4f Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sun, 30 Oct 2022 02:09:33 +0100 Subject: [PATCH 1/2] obs/gs/rendertarget: Add support for color spaces --- source/obs/gs/gs-rendertarget.cpp | 60 +++++++++++++++++++++---------- source/obs/gs/gs-rendertarget.hpp | 41 +++++++++++---------- 2 files changed, 65 insertions(+), 36 deletions(-) diff --git a/source/obs/gs/gs-rendertarget.cpp b/source/obs/gs/gs-rendertarget.cpp index 5a3a6d8457..729f2ee16d 100644 --- a/source/obs/gs/gs-rendertarget.cpp +++ b/source/obs/gs/gs-rendertarget.cpp @@ -1,21 +1,22 @@ -/* - * Modern effects for a modern Streamer - * Copyright (C) 2017 Michael Fabian Dirks - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ +// Copyright (c) 2017-2022 Michael Fabian Dirks +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. #include "gs-rendertarget.hpp" #include "obs/gs/gs-helper.hpp" @@ -46,6 +47,12 @@ streamfx::obs::gs::rendertarget_op streamfx::obs::gs::rendertarget::render(uint3 return {this, width, height}; } +streamfx::obs::gs::rendertarget_op streamfx::obs::gs::rendertarget::render(uint32_t width, uint32_t height, + gs_color_space cs) +{ + return {this, width, height, cs}; +} + gs_texture_t* streamfx::obs::gs::rendertarget::get_object() { auto gctx = streamfx::obs::gs::context(); @@ -100,6 +107,23 @@ streamfx::obs::gs::rendertarget_op::rendertarget_op(streamfx::obs::gs::rendertar parent->_is_being_rendered = true; } +streamfx::obs::gs::rendertarget_op::rendertarget_op(streamfx::obs::gs::rendertarget* rt, uint32_t width, + uint32_t height, gs_color_space cs) + : parent(rt) +{ + if (parent == nullptr) + throw std::invalid_argument("rt"); + if (parent->_is_being_rendered) + throw std::logic_error("Can't start rendering to the same render target twice."); + + auto gctx = streamfx::obs::gs::context(); + gs_texrender_reset(parent->_render_target); + if (!gs_texrender_begin_with_color_space(parent->_render_target, width, height, cs)) { + throw std::runtime_error("Failed to begin rendering to render target."); + } + parent->_is_being_rendered = true; +} + streamfx::obs::gs::rendertarget_op::rendertarget_op(streamfx::obs::gs::rendertarget_op&& r) noexcept { this->parent = r.parent; diff --git a/source/obs/gs/gs-rendertarget.hpp b/source/obs/gs/gs-rendertarget.hpp index d736cdd4ee..9467446742 100644 --- a/source/obs/gs/gs-rendertarget.hpp +++ b/source/obs/gs/gs-rendertarget.hpp @@ -1,21 +1,22 @@ -/* - * Modern effects for a modern Streamer - * Copyright (C) 2017 Michael Fabian Dirks - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ +// Copyright (c) 2017-2022 Michael Fabian Dirks +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. #pragma once #include "common.hpp" @@ -54,6 +55,8 @@ namespace streamfx::obs::gs { gs_zstencil_format get_zstencil_format(); streamfx::obs::gs::rendertarget_op render(uint32_t width, uint32_t height); + + streamfx::obs::gs::rendertarget_op render(uint32_t width, uint32_t height, gs_color_space cs); }; class rendertarget_op { @@ -64,6 +67,8 @@ namespace streamfx::obs::gs { rendertarget_op(streamfx::obs::gs::rendertarget* rt, uint32_t width, uint32_t height); + rendertarget_op(streamfx::obs::gs::rendertarget* rt, uint32_t width, uint32_t height, gs_color_space cs); + // Move Constructor rendertarget_op(streamfx::obs::gs::rendertarget_op&&) noexcept; From 366ae646654f67ae910b5e6e9724c3460771d145 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sun, 30 Oct 2022 02:09:45 +0100 Subject: [PATCH 2/2] obs/source-factory: Add support for color spaces --- source/obs/obs-source-factory.cpp | 37 ++++++++--------- source/obs/obs-source-factory.hpp | 66 ++++++++++++++++++++++--------- 2 files changed, 67 insertions(+), 36 deletions(-) diff --git a/source/obs/obs-source-factory.cpp b/source/obs/obs-source-factory.cpp index be07b0e9d6..1ba973f8c1 100644 --- a/source/obs/obs-source-factory.cpp +++ b/source/obs/obs-source-factory.cpp @@ -1,20 +1,21 @@ -/* - * Modern effects for a modern Streamer - * Copyright (C) 2018 Michael Fabian Dirks - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ +// Copyright (c) 2018 Michael Fabian Dirks +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. #include "obs-source-factory.hpp" diff --git a/source/obs/obs-source-factory.hpp b/source/obs/obs-source-factory.hpp index e5c2bf2b37..2f38406916 100644 --- a/source/obs/obs-source-factory.hpp +++ b/source/obs/obs-source-factory.hpp @@ -1,21 +1,22 @@ -/* - * Modern effects for a modern Streamer - * Copyright (C) 2018 Michael Fabian Dirks - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ +// Copyright (c) 2018-2022 Michael Fabian Dirks +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. #pragma once #include "common.hpp" @@ -223,6 +224,30 @@ namespace streamfx::obs { } public /* Instance > Video */: + void support_color_space(bool v) + { + if (v) { + _info.video_get_color_space = _video_get_color_space; + } else { + _info.video_get_color_space = nullptr; + } + } + + static gs_color_space _video_get_color_space(void* data, size_t count, const gs_color_space* preferred_spaces) + { + try { + if (data) + return reinterpret_cast<_instance*>(data)->video_get_color_space(count, preferred_spaces); + return GS_CS_SRGB; + } catch (const std::exception& ex) { + DLOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); + return GS_CS_SRGB; + } catch (...) { + DLOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); + return GS_CS_SRGB; + } + } + static void _video_tick(void* data, float seconds) noexcept { try { @@ -839,6 +864,11 @@ namespace streamfx::obs { virtual void filter_remove(obs_source_t* source) {} public /* Instance > Video */: + virtual gs_color_space video_get_color_space(size_t count, const gs_color_space* preferred_spaces) + { + return GS_CS_SRGB; + } + virtual void video_tick(float_t seconds) {} virtual void video_render(gs_effect_t* effect) {}