OpenShot Library | libopenshot 1.1.1
Displace.h
Go to the documentation of this file.
1
9// Copyright (c) 2008-2026 OpenShot Studios, LLC
10//
11// SPDX-License-Identifier: LGPL-3.0-or-later
12
13#ifndef OPENSHOT_DISPLACE_EFFECT_H
14#define OPENSHOT_DISPLACE_EFFECT_H
15
16#include "../EffectBase.h"
17
18#include "../Frame.h"
19#include "../Json.h"
20#include "../KeyFrame.h"
21
22#include <memory>
23#include <string>
24
25namespace openshot
26{
27 // Forward declaration
28 class ReaderBase;
29
37 class Displace : public EffectBase
38 {
39 private:
40 ReaderBase* map_reader = nullptr;
41 std::shared_ptr<QImage> cached_single_map_image;
42 int cached_single_map_width = 0;
43 int cached_single_map_height = 0;
44
46 void init_effect_details();
47
49 std::shared_ptr<QImage> GetMapImage(std::shared_ptr<QImage> target_image, int64_t frame_number);
50
51 public:
53 bool invert;
59
61 Displace();
62
71 Displace(ReaderBase *map_reader, Keyframe map_strength, Keyframe map_horizontal,
72 Keyframe map_vertical, Keyframe map_brightness, Keyframe map_contrast);
73
80 std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) override { return GetFrame(std::make_shared<openshot::Frame>(), frame_number); }
81
91 std::shared_ptr<openshot::Frame> GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number) override;
92
93 // Get and Set JSON methods
94 std::string Json() const override;
95 void SetJson(const std::string value) override;
96 Json::Value JsonValue() const override;
97 void SetJsonValue(const Json::Value root) override;
98
101 std::string PropertiesJSON(int64_t requested_frame) const override;
102
104 ReaderBase* Reader() { return map_reader; };
105
107 void Reader(ReaderBase *new_reader);
108
109 ~Displace() override;
110 };
111
112}
113
114#endif
This class uses a grayscale image or video to displace frame pixels.
Definition: Displace.h:38
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number) override
This method is required for all derived classes of ClipBase, and returns a new openshot::Frame object...
Definition: Displace.h:80
Keyframe contrast
Contrast adjustment for the displacement map.
Definition: Displace.h:58
Displace()
Blank constructor, useful when using Json to load the effect properties.
Definition: Displace.cpp:66
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: Displace.cpp:241
bool invert
Invert the displacement map before converting it to offsets.
Definition: Displace.h:53
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: Displace.cpp:272
Keyframe vertical
Vertical displacement amount as a percentage of image height.
Definition: Displace.h:56
~Displace() override
Definition: Displace.cpp:347
Keyframe brightness
Brightness adjustment for the displacement map.
Definition: Displace.h:57
std::string Json() const override
Generate JSON string of this object.
Definition: Displace.cpp:236
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: Displace.cpp:259
Keyframe horizontal
Horizontal displacement amount as a percentage of image width.
Definition: Displace.h:55
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: Displace.cpp:307
bool replace_image
Replace the frame image with the processed displacement map for debugging.
Definition: Displace.h:52
ReaderBase * Reader()
Get the reader object of the displacement map.
Definition: Displace.h:104
Keyframe strength
Overall strength multiplier for the displacement effect.
Definition: Displace.h:54
This abstract class is the base class, used by all effects in libopenshot.
Definition: EffectBase.h:57
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition: KeyFrame.h:53
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:76
This namespace is the default namespace for all code in the openshot library.
Definition: AnimatedCurve.h:24