Blender V5.3
otio_resolve.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_index_range.hh"
10#include "BLI_math_constants.hh"
11
12#include "DNA_scene_types.h"
13#include "DNA_sequence_types.h"
14
15#include "otio_resolve.hh"
16
17namespace blender::io::otio {
18
20{
21 static const ResolveNumber numbers[] = {
22 {"Transform", "transformationZoomX", "transform.scale_x", ResolveUnit::FitWidth},
23 {"Transform", "transformationZoomY", "transform.scale_y", ResolveUnit::FitHeight},
24 {"Transform", "transformationPan", "transform.offset_x", ResolveUnit::SceneWidth},
25 {"Transform", "transformationTilt", "transform.offset_y", ResolveUnit::SceneHeight},
26 {"Transform", "transformationRotationAngle", "transform.rotation", ResolveUnit::Degrees},
27 {"Cropping", "cropLeft", "crop.min_x", ResolveUnit::MediaWidth},
28 {"Cropping", "cropRight", "crop.max_x", ResolveUnit::MediaWidth},
29 {"Cropping", "cropBottom", "crop.min_y", ResolveUnit::MediaHeight},
30 {"Cropping", "cropTop", "crop.max_y", ResolveUnit::MediaHeight},
31 {"Composite", "opacity", "blend_alpha", ResolveUnit::Percent},
32 {"Fairlight Clip Pan", "pan", "pan", ResolveUnit::Percent},
33 {"Edge Wipe", "angle", "angle", ResolveUnit::Degrees},
34 };
35 return Span(numbers, std::size(numbers));
36}
37
38ResolveUnits::ResolveUnits(const Scene &scene, const Strip &strip)
39 : scene_size(scene.r.xsch, scene.r.ysch), media_size(scene_size)
40{
41 if (strip.data && strip.data->stripdata && strip.data->stripdata->orig_width > 0) {
42 media_size = float2(strip.data->stripdata->orig_width, strip.data->stripdata->orig_height);
43 }
44}
45
46double ResolveUnits::to_blender(const ResolveUnit unit) const
47{
48 switch (unit) {
50 return 1.0;
52 return 0.01;
54 return DEG2RAD(1.0);
56 return scene_size.x;
58 return scene_size.y;
60 return media_size.x;
62 return media_size.y;
64 return fit_scale.x;
66 return fit_scale.y;
67 }
68 return 1.0;
69}
70
75
76AnyDictionary &ensure_dictionary(AnyDictionary &parent, const std::string &key)
77{
78 std::any &value = parent[key];
79 if (!std::any_cast<AnyDictionary>(&value)) {
80 value = AnyDictionary();
81 }
82 return *std::any_cast<AnyDictionary>(&value);
83}
84
85static const char *composite_mode_blend_types[] = {
86 "ALPHA_OVER", "ADD", "SUBTRACT", "DIFFERENCE", "MULTIPLY", "SCREEN",
87 "OVERLAY", "HARD_LIGHT", "SOFT_LIGHT", "DARKEN", "LIGHTEN", "DODGE",
88 "BURN", "EXCLUSION", "HUE", "SATURATION", "COLOR", "VALUE",
89 nullptr, "ADD", "LINEAR_BURN", "LINEAR_LIGHT", "VIVID_LIGHT", "PIN_LIGHT",
90};
91
92const char *resolve_blend_type(const int64_t composite_mode)
93{
94 return composite_mode >= 0 && composite_mode < int64_t(std::size(composite_mode_blend_types)) ?
95 composite_mode_blend_types[composite_mode] :
96 nullptr;
97}
98
99std::optional<int64_t> resolve_composite_mode(const StringRef blend_type)
100{
101 for (const int64_t mode : IndexRange(std::size(composite_mode_blend_types))) {
102 if (composite_mode_blend_types[mode] && blend_type == composite_mode_blend_types[mode]) {
103 return mode;
104 }
105 }
106 return std::nullopt;
107}
108
109} // namespace blender::io::otio
#define DEG2RAD(_deg)
constexpr IndexRange()=default
constexpr Span()=default
const T & data(const Action &owning_action) const
const char * resolve_blend_type(const int64_t composite_mode)
AnyDictionary & ensure_dictionary(AnyDictionary &parent, const std::string &key)
Span< ResolveNumber > resolve_numbers()
std::optional< int64_t > resolve_composite_mode(const StringRef blend_type)
static const char * composite_mode_blend_types[]
__int64 int64_t
Definition BKE_text.h:90
VecBase< float, 2 > float2
ResolveUnits(const Scene &scene, const Strip &strip)
double to_blender(ResolveUnit unit) const