2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Helge Norberg, helge.norberg@svt.se
26 #include "../frame/frame_transform.h"
28 namespace caspar { namespace core {
30 template<typename Derived, typename Base>
31 bool is(const spl::shared_ptr<Base>& base)
33 return dynamic_cast<const Derived*>(base.get()) != nullptr;
36 template<typename Derived, typename Base>
37 spl::shared_ptr<const Derived> as(const spl::shared_ptr<Base>& base)
39 return spl::dynamic_pointer_cast<const Derived>(base);
42 static std::pair<double, double> translate(
43 double x, double y, const frame_transform& transform)
45 auto& img_transform = transform.image_transform;
46 auto fill_x = img_transform.fill_translation[0];
47 auto fill_y = img_transform.fill_translation[1];
48 auto scale_x = img_transform.fill_scale[0];
49 auto scale_y = img_transform.fill_scale[1];
51 if (fill_x != 0.0 || fill_y != 0.0 || scale_x != 1.0 || scale_y != 1.0)
53 double translated_x = (x - fill_x) / scale_x;
54 double translated_y = (y - fill_y) / scale_y;
56 return std::make_pair(translated_x, translated_y);
60 return std::make_pair(x, y);