]> git.sesse.net Git - casparcg/blob - core/interaction/util.h
[ffmpeg] Classify most ffmpeg errors as user errors, so we don't get a stacktrace...
[casparcg] / core / interaction / util.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
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.
10 *
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.
15 *
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/>.
18 *
19 * Author: Helge Norberg, helge.norberg@svt.se
20 */
21
22 #pragma once
23
24 #include <map>
25
26 #include "../frame/frame_transform.h"
27
28 namespace caspar { namespace core {
29
30 template<typename Derived, typename Base>
31 bool is(const spl::shared_ptr<Base>& base)
32 {
33         return dynamic_cast<const Derived*>(base.get()) != nullptr;
34 }
35
36 template<typename Derived, typename Base>
37 spl::shared_ptr<const Derived> as(const spl::shared_ptr<Base>& base)
38 {
39         return spl::dynamic_pointer_cast<const Derived>(base);
40 }
41
42 static std::pair<double, double> translate(
43                 double x, double y, const frame_transform& transform)
44 {
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];
50
51         if (fill_x != 0.0 || fill_y != 0.0 || scale_x != 1.0 || scale_y != 1.0)
52         {
53                 double translated_x = (x - fill_x) / scale_x;
54                 double translated_y = (y - fill_y) / scale_y;
55
56                 return std::make_pair(translated_x, translated_y);
57         }
58         else
59         {
60                 return std::make_pair(x, y);
61         }
62 }
63
64 }}