X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=core%2Fframe%2Fframe_transform.h;h=bf2cdb35f550a12e299a90b6c05f70446482d751;hb=f7b48279d43e30c270ef532f97d59f0582a73efc;hp=0159b695f4ebfaab6565c467c0254ba39765d2e6;hpb=e059c077f56667d7e8d31b1873a0a813ee55ee25;p=casparcg diff --git a/core/frame/frame_transform.h b/core/frame/frame_transform.h index 0159b695f..bf2cdb35f 100644 --- a/core/frame/frame_transform.h +++ b/core/frame/frame_transform.h @@ -1,79 +1,194 @@ -/* -* Copyright (c) 2011 Sveriges Television AB -* -* This file is part of CasparCG (www.casparcg.com). -* -* CasparCG 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 3 of the License, or -* (at your option) any later version. -* -* CasparCG 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 CasparCG. If not, see . -* -* Author: Robert Nagy, ronag89@gmail.com -*/ - -#pragma once - -#include -#include - -#include - -namespace caspar { namespace core { - -struct levels sealed -{ - levels() - : min_input(0.0) - , max_input(1.0) - , gamma(1.0) - , min_output(0.0) - , max_output(1.0) - { - } - double min_input; - double max_input; - double gamma; - double min_output; - double max_output; -}; - -struct frame_transform sealed -{ -public: - - frame_transform(); - - double volume; - double opacity; - double contrast; - double brightness; - double saturation; - boost::array fill_translation; - boost::array fill_scale; - boost::array clip_translation; - boost::array clip_scale; - levels levels; - - field_mode field_mode; - bool is_key; - bool is_mix; - - frame_transform& frame_transform::operator*=(const frame_transform &other); - frame_transform frame_transform::operator*(const frame_transform &other) const; -}; - -frame_transform tween(double time, const frame_transform& source, const frame_transform& dest, double duration, const tweener_t& tweener); - -bool operator<(const frame_transform& lhs, const frame_transform& rhs); -bool operator==(const frame_transform& lhs, const frame_transform& rhs); -bool operator!=(const frame_transform& lhs, const frame_transform& rhs); - -}} \ No newline at end of file +/* +* Copyright (c) 2011 Sveriges Television AB +* +* This file is part of CasparCG (www.casparcg.com). +* +* CasparCG 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 3 of the License, or +* (at your option) any later version. +* +* CasparCG 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 CasparCG. If not, see . +* +* Author: Robert Nagy, ronag89@gmail.com +*/ + +#pragma once + +#include +#include + +#include +#include + +#include +#include + +namespace caspar { namespace core { + +struct chroma +{ + enum class type + { + none, + green, + blue + }; + + type key = type::none; + double threshold = 0.0; + double softness = 0.0; + double spill = 0.0; +}; + +struct levels final +{ + double min_input = 0.0; + double max_input = 1.0; + double gamma = 1.0; + double min_output = 0.0; + double max_output = 1.0; +}; + +struct corners final +{ + boost::array ul = boost::array { { 0.0, 0.0 } }; + boost::array ur = boost::array { { 1.0, 0.0 } }; + boost::array lr = boost::array { { 1.0, 1.0 } }; + boost::array ll = boost::array { { 0.0, 1.0 } }; +}; + +struct rectangle final +{ + boost::array ul = boost::array { { 0.0, 0.0 } }; + boost::array lr = boost::array { { 1.0, 1.0 } }; +}; + +struct image_transform final +{ + double opacity = 1.0; + double contrast = 1.0; + double brightness = 1.0; + double saturation = 1.0; + + // A bug in VS 2013 prevents us from writing: + // boost::array fill_translation = { { 0.0, 0.0 } }; + // See http://blogs.msdn.com/b/vcblog/archive/2014/08/19/the-future-of-non-static-data-member-initialization.aspx + boost::array anchor = boost::array { { 0.0, 0.0 } }; + boost::array fill_translation = boost::array { { 0.0, 0.0 } }; + boost::array fill_scale = boost::array { { 1.0, 1.0 } }; + boost::array clip_translation = boost::array { { 0.0, 0.0 } }; + boost::array clip_scale = boost::array { { 1.0, 1.0 } }; + double angle = 0.0; + rectangle crop; + corners perspective; + core::levels levels; + core::chroma chroma; + + core::field_mode field_mode = core::field_mode::progressive; + bool is_key = false; + bool is_mix = false; + bool is_still = false; + bool use_mipmap = false; + core::blend_mode blend_mode = core::blend_mode::normal; + int layer_depth = 0; + + image_transform& operator*=(const image_transform &other); + image_transform operator*(const image_transform &other) const; + + static image_transform tween(double time, const image_transform& source, const image_transform& dest, double duration, const tweener& tween); +}; + +bool operator==(const image_transform& lhs, const image_transform& rhs); +bool operator!=(const image_transform& lhs, const image_transform& rhs); + +struct audio_transform final +{ + double volume = 1.0; + bool is_still = false; + + audio_transform& operator*=(const audio_transform &other); + audio_transform operator*(const audio_transform &other) const; + + static audio_transform tween(double time, const audio_transform& source, const audio_transform& dest, double duration, const tweener& tween); +}; + +bool operator==(const audio_transform& lhs, const audio_transform& rhs); +bool operator!=(const audio_transform& lhs, const audio_transform& rhs); + +//__declspec(align(16)) +struct frame_transform final +{ +public: + frame_transform(); + + core::image_transform image_transform; + core::audio_transform audio_transform; + + //char padding[(sizeof(core::image_transform) + sizeof(core::audio_transform)) % 16]; + + frame_transform& operator*=(const frame_transform &other); + frame_transform operator*(const frame_transform &other) const; + + static frame_transform tween(double time, const frame_transform& source, const frame_transform& dest, double duration, const tweener& tween); +}; + +bool operator==(const frame_transform& lhs, const frame_transform& rhs); +bool operator!=(const frame_transform& lhs, const frame_transform& rhs); + +class tweened_transform +{ + frame_transform source_; + frame_transform dest_; + int duration_; + int time_; + tweener tweener_; +public: + tweened_transform() + : duration_(0) + , time_(0) + { + dest_.image_transform.use_mipmap = env::properties().get(L"configuration.mixer.mipmapping_default_on", false); + } + + tweened_transform(const frame_transform& source, const frame_transform& dest, int duration, const tweener& tween) + : source_(source) + , dest_(dest) + , duration_(duration) + , time_(0) + , tweener_(tween) + { + } + + const frame_transform& dest() const + { + return dest_; + } + + frame_transform fetch() + { + return time_ == duration_ ? dest_ : frame_transform::tween(static_cast(time_), source_, dest_, static_cast(duration_), tweener_); + } + + frame_transform fetch_and_tick(int num) + { + time_ = std::min(time_+num, duration_); + return fetch(); + } +}; + +chroma::type get_chroma_mode(const std::wstring& str); +std::wstring get_chroma_mode(chroma::type type); + +namespace detail { + +void set_current_aspect_ratio(double aspect_ratio); +double get_current_aspect_ratio(); + +}}}