OpenShot Library | libopenshot  0.5.0
SphericalProjection.h
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2025 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_SPHERICAL_PROJECTION_EFFECT_H
14 #define OPENSHOT_SPHERICAL_PROJECTION_EFFECT_H
15 
16 #include "../EffectBase.h"
17 #include "../Frame.h"
18 #include "../Json.h"
19 #include "../KeyFrame.h"
20 
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 namespace openshot {
26 
33 private:
34  void init_effect_details();
35 
36 public:
37  // Enums
38  enum InputModel {
40  INPUT_FEQ_EQUIDISTANT = 1, // r = f * theta
41  INPUT_FEQ_EQUISOLID = 2, // r = 2f * sin(theta/2)
42  INPUT_FEQ_STEREOGRAPHIC = 3, // r = 2f * tan(theta/2)
43  INPUT_FEQ_ORTHOGRAPHIC = 4 // r = f * sin(theta)
44  };
45 
47  MODE_RECT_SPHERE = 0, // Rectilinear view over full sphere
48  MODE_RECT_HEMISPHERE = 1, // Rectilinear view over hemisphere
49  MODE_FISHEYE_EQUIDISTANT = 2, // Output fisheye (equidistant)
50  MODE_FISHEYE_EQUISOLID = 3, // Output fisheye (equisolid)
51  MODE_FISHEYE_STEREOGRAPHIC = 4, // Output fisheye (stereographic)
52  MODE_FISHEYE_ORTHOGRAPHIC = 5 // Output fisheye (orthographic)
53  };
54 
55  enum InterpMode {
60  };
61 
62  enum InvertFlag {
65  };
66 
72 
74  int invert;
77 
80 
82  SphericalProjection(Keyframe new_yaw, Keyframe new_pitch, Keyframe new_roll,
83  Keyframe new_fov);
84 
86  std::shared_ptr<Frame> GetFrame(int64_t frame_number) override {
87  return GetFrame(std::make_shared<Frame>(), frame_number);
88  }
89 
91  std::shared_ptr<Frame> GetFrame(std::shared_ptr<Frame> frame,
92  int64_t frame_number) override;
93 
94  // JSON serialization
95  std::string Json() const override;
96  void SetJson(std::string value) override;
97  Json::Value JsonValue() const override;
98  void SetJsonValue(Json::Value root) override;
99  std::string PropertiesJSON(int64_t requested_frame) const override;
100 
101 private:
102  void project_input(double dx, double dy, double dz, double in_fov_r, int W,
103  int H, double &uf, double &vf) const;
104 
105  mutable std::vector<float> uv_map;
106  mutable int cached_width = 0;
107  mutable int cached_height = 0;
108  mutable double cached_yaw = 0.0, cached_pitch = 0.0, cached_roll = 0.0;
109  mutable double cached_in_fov = 0.0, cached_out_fov = 0.0;
110  mutable int cached_input_model = -1;
111  mutable int cached_projection_mode = -1;
112  mutable int cached_invert = -1;
113 };
114 
115 } // namespace openshot
116 
117 #endif // OPENSHOT_SPHERICAL_PROJECTION_EFFECT_H
openshot::SphericalProjection::invert
int invert
0=Normal, 1=Invert (back lens / +180°)
Definition: SphericalProjection.h:74
openshot::EffectBase
This abstract class is the base class, used by all effects in libopenshot.
Definition: EffectBase.h:53
openshot::SphericalProjection::InterpMode
InterpMode
Definition: SphericalProjection.h:55
openshot::SphericalProjection::interpolation
int interpolation
0=Nearest, 1=Bilinear, 2=Bicubic, 3=Auto
Definition: SphericalProjection.h:76
openshot::SphericalProjection::pitch
Keyframe pitch
Pitch around right-axis (degrees)
Definition: SphericalProjection.h:68
openshot::SphericalProjection::MODE_FISHEYE_EQUIDISTANT
@ MODE_FISHEYE_EQUIDISTANT
Definition: SphericalProjection.h:49
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::SphericalProjection::INTERP_BILINEAR
@ INTERP_BILINEAR
Definition: SphericalProjection.h:57
openshot::SphericalProjection::INPUT_FEQ_STEREOGRAPHIC
@ INPUT_FEQ_STEREOGRAPHIC
Definition: SphericalProjection.h:42
openshot::SphericalProjection::SetJsonValue
void SetJsonValue(Json::Value root) override
Load Json::Value into this object.
Definition: SphericalProjection.cpp:456
openshot::SphericalProjection::INTERP_BICUBIC
@ INTERP_BICUBIC
Definition: SphericalProjection.h:58
openshot::SphericalProjection::INPUT_FEQ_ORTHOGRAPHIC
@ INPUT_FEQ_ORTHOGRAPHIC
Definition: SphericalProjection.h:43
openshot::SphericalProjection::MODE_FISHEYE_STEREOGRAPHIC
@ MODE_FISHEYE_STEREOGRAPHIC
Definition: SphericalProjection.h:51
openshot::SphericalProjection::MODE_FISHEYE_EQUISOLID
@ MODE_FISHEYE_EQUISOLID
Definition: SphericalProjection.h:50
openshot::SphericalProjection::INVERT_NORMAL
@ INVERT_NORMAL
Definition: SphericalProjection.h:63
openshot::SphericalProjection::yaw
Keyframe yaw
Yaw around up-axis (degrees)
Definition: SphericalProjection.h:67
openshot::SphericalProjection::InputModel
InputModel
Definition: SphericalProjection.h:38
openshot::SphericalProjection::INPUT_FEQ_EQUIDISTANT
@ INPUT_FEQ_EQUIDISTANT
Definition: SphericalProjection.h:40
openshot::SphericalProjection::INPUT_FEQ_EQUISOLID
@ INPUT_FEQ_EQUISOLID
Definition: SphericalProjection.h:41
openshot::SphericalProjection::PropertiesJSON
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: SphericalProjection.cpp:493
openshot::Keyframe
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition: KeyFrame.h:53
openshot::SphericalProjection::INPUT_EQUIRECT
@ INPUT_EQUIRECT
Definition: SphericalProjection.h:39
openshot::SphericalProjection::MODE_RECT_HEMISPHERE
@ MODE_RECT_HEMISPHERE
Definition: SphericalProjection.h:48
openshot::SphericalProjection::MODE_RECT_SPHERE
@ MODE_RECT_SPHERE
Definition: SphericalProjection.h:47
openshot::SphericalProjection::GetFrame
std::shared_ptr< Frame > GetFrame(int64_t frame_number) override
ClipBase override: create a fresh Frame then call the main GetFrame.
Definition: SphericalProjection.h:86
openshot::SphericalProjection::INTERP_NEAREST
@ INTERP_NEAREST
Definition: SphericalProjection.h:56
openshot::SphericalProjection::projection_mode
int projection_mode
0=Sphere, 1=Hemisphere, 2=Fisheye
Definition: SphericalProjection.h:73
openshot::SphericalProjection::SphericalProjection
SphericalProjection()
Blank ctor (for JSON deserialization)
Definition: SphericalProjection.cpp:23
openshot::SphericalProjection::Json
std::string Json() const override
Generate JSON string of this object.
Definition: SphericalProjection.cpp:422
openshot::SphericalProjection
Projects 360° or fisheye video through a virtual camera. Supports yaw, pitch, roll,...
Definition: SphericalProjection.h:32
openshot::SphericalProjection::in_fov
Keyframe in_fov
Source lens coverage / FOV (degrees)
Definition: SphericalProjection.h:71
openshot::SphericalProjection::INTERP_AUTO
@ INTERP_AUTO
Definition: SphericalProjection.h:59
openshot::SphericalProjection::ProjectionMode
ProjectionMode
Definition: SphericalProjection.h:46
openshot::SphericalProjection::InvertFlag
InvertFlag
Definition: SphericalProjection.h:62
openshot::SphericalProjection::SetJson
void SetJson(std::string value) override
Load JSON string into this object.
Definition: SphericalProjection.cpp:443
openshot::SphericalProjection::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: SphericalProjection.cpp:427
openshot::SphericalProjection::input_model
int input_model
0=Equirect, 1=Fisheye-Equidistant
Definition: SphericalProjection.h:75
openshot::SphericalProjection::fov
Keyframe fov
Output field-of-view (degrees)
Definition: SphericalProjection.h:70
openshot::SphericalProjection::roll
Keyframe roll
Roll around forward-axis (degrees)
Definition: SphericalProjection.h:69
openshot::SphericalProjection::MODE_FISHEYE_ORTHOGRAPHIC
@ MODE_FISHEYE_ORTHOGRAPHIC
Definition: SphericalProjection.h:52
openshot::SphericalProjection::INVERT_BACK
@ INVERT_BACK
Definition: SphericalProjection.h:64