Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bindings/java/openshot.i
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ typedef struct OpenShotByteBuffer {
%include "effects/ColorShift.h"
%include "effects/Crop.h"
%include "effects/Deinterlace.h"
%include "effects/FilmGrain.h"
%include "effects/Hue.h"
%include "effects/LensFlare.h"
%include "effects/Mask.h"
Expand Down
1 change: 1 addition & 0 deletions bindings/python/openshot.i
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ static int openshot_swig_is_qwidget(PyObject *obj) {
%include "effects/ColorShift.h"
%include "effects/Crop.h"
%include "effects/Deinterlace.h"
%include "effects/FilmGrain.h"
%include "effects/Hue.h"
%include "effects/LensFlare.h"
%include "effects/Mask.h"
Expand Down
1 change: 1 addition & 0 deletions bindings/ruby/openshot.i
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ typedef struct OpenShotByteBuffer {
%include "effects/ColorShift.h"
%include "effects/Crop.h"
%include "effects/Deinterlace.h"
%include "effects/FilmGrain.h"
%include "effects/Hue.h"
%include "effects/LensFlare.h"
%include "effects/Mask.h"
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ set(EFFECTS_SOURCES
effects/CropHelpers.cpp
effects/Deinterlace.cpp
effects/Displace.cpp
effects/FilmGrain.cpp
effects/Glow.cpp
effects/Hue.cpp
effects/LensFlare.cpp
Expand Down
12 changes: 10 additions & 2 deletions src/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1577,8 +1577,16 @@ QTransform Clip::get_transform(std::shared_ptr<Frame> frame, int width, int heig

/* LOCATION, ROTATION, AND SCALE */
float r = rotation.GetValue(frame->number) + parentObject_rotation; // rotate in degrees
x += width * (location_x.GetValue(frame->number) + parentObject_location_x); // move in percentage of final width
y += height * (location_y.GetValue(frame->number) + parentObject_location_y); // move in percentage of final height
float location_x_value = location_x.GetValue(frame->number) + parentObject_location_x;
float location_y_value = location_y.GetValue(frame->number) + parentObject_location_y;
auto location_offset = [](float location, float anchored_position, float canvas_size, float clip_size) {
if (location < 0.0f) {
return location * (anchored_position + clip_size);
}
return location * (canvas_size - anchored_position);
};
x += location_offset(location_x_value, x, width, scaled_source_width);
y += location_offset(location_y_value, y, height, scaled_source_height);
float shear_x_value = shear_x.GetValue(frame->number) + parentObject_shear_x;
float shear_y_value = shear_y.GetValue(frame->number) + parentObject_shear_y;
float origin_x_value = origin_x.GetValue(frame->number);
Expand Down
4 changes: 4 additions & 0 deletions src/EffectInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ EffectBase* EffectInfo::CreateEffect(std::string effect_type) {
else if (effect_type == "Displace")
return new Displace();

else if (effect_type == "FilmGrain")
return new FilmGrain();

else if (effect_type == "Glow")
return new Glow();

Expand Down Expand Up @@ -161,6 +164,7 @@ Json::Value EffectInfo::JsonValue() {
root.append(Crop().JsonInfo());
root.append(Deinterlace().JsonInfo());
root.append(Displace().JsonInfo());
root.append(FilmGrain().JsonInfo());
root.append(Glow().JsonInfo());
root.append(Hue().JsonInfo());
root.append(LensFlare().JsonInfo());
Expand Down
1 change: 1 addition & 0 deletions src/Effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "effects/Crop.h"
#include "effects/Deinterlace.h"
#include "effects/Displace.h"
#include "effects/FilmGrain.h"
#include "effects/Glow.h"
#include "effects/Hue.h"
#include "effects/LensFlare.h"
Expand Down
38 changes: 25 additions & 13 deletions src/effects/AnalogTape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ std::shared_ptr<Frame> AnalogTape::GetFrame(std::shared_ptr<Frame> frame,
fps = timeline->info.fps;
else if (clip && clip->Reader())
fps = clip->Reader()->info.fps;
int reference_w = w;
int reference_h = h;
if (timeline && timeline->info.width > 0 && timeline->info.height > 0) {
reference_w = timeline->info.width;
reference_h = timeline->info.height;
}
const float reference_scale_x = w > 0 ? static_cast<float>(reference_w) / static_cast<float>(w) : 1.0f;
const float reference_scale_y = h > 0 ? static_cast<float>(reference_h) / static_cast<float>(h) : 1.0f;
const float inverse_scale_x = reference_scale_x > 0.0f ? 1.0f / reference_scale_x : 1.0f;
double fps_d = fps.ToDouble();
double t = fps_d > 0 ? frame_number / fps_d : frame_number;

Expand All @@ -128,7 +137,7 @@ std::shared_ptr<Frame> AnalogTape::GetFrame(std::shared_ptr<Frame> frame,
const float k_stripe = stripe.GetValue(frame_number);
const float k_bands = staticBands.GetValue(frame_number);

int r_y = std::round(lerp(0.0f, 2.0f, k_soft));
int r_y = std::round(lerp(0.0f, 2.0f, k_soft) * inverse_scale_x);
if (k_noise > 0.6f)
r_y = std::min(r_y, 1);
if (r_y > 0) {
Expand All @@ -140,8 +149,8 @@ std::shared_ptr<Frame> AnalogTape::GetFrame(std::shared_ptr<Frame> frame,
Y.swap(tmpY);
}

float shift = lerp(0.0f, 2.5f, k_bleed);
int r_c = std::round(lerp(0.0f, 3.0f, k_bleed));
float shift = lerp(0.0f, 2.5f, k_bleed) * inverse_scale_x;
int r_c = std::round(lerp(0.0f, 3.0f, k_bleed) * inverse_scale_x);
float sat = 1.0f - 0.30f * k_bleed;
float shift_h = shift * 0.5f;
#ifdef _OPENMP
Expand Down Expand Up @@ -239,6 +248,7 @@ std::shared_ptr<Frame> AnalogTape::GetFrame(std::shared_ptr<Frame> frame,
#pragma omp parallel for
#endif
for (int y = 0; y < h; ++y) {
const int y_ref = static_cast<int>(std::round(static_cast<float>(y) * reference_scale_y));
float bandF = 0.0f;
if (Hfixed > 0.0f && y >= h - Hfixed)
bandF = (y - (h - Hfixed)) / std::max(1.0f, Hfixed);
Expand All @@ -265,14 +275,14 @@ std::shared_ptr<Frame> AnalogTape::GetFrame(std::shared_ptr<Frame> frame,
}
}

float rowBias = row_density(SEED, frame_number, y);
float rowBias = row_density(SEED, frame_number, y_ref);
float p = baseP * (0.25f + 1.5f * rowBias);
p *= (1.0f + 1.5f * bandF + 2.0f * burstF);

float hum = 0.008f * k_noise *
std::sin(2 * PI * (y * (6.0f / h) + 0.08f * t));
uint32_t s0 = SEED ^ 0x9e37u * kf ^ 0x85ebu * y;
uint32_t s1 = SEED ^ 0x9e37u * (kf + 1) ^ 0x85ebu * y ^ 0x1234567u;
std::sin(2 * PI * (y_ref * (6.0f / reference_h) + 0.08f * t));
uint32_t s0 = SEED ^ 0x9e37u * kf ^ 0x85ebu * y_ref;
uint32_t s1 = SEED ^ 0x9e37u * (kf + 1) ^ 0x85ebu * y_ref ^ 0x1234567u;
auto step = [](uint32_t &s) {
s ^= s << 13;
s ^= s >> 17;
Expand All @@ -282,12 +292,13 @@ std::shared_ptr<Frame> AnalogTape::GetFrame(std::shared_ptr<Frame> frame,
float lift = Gfixed * bandF + Gburst * burstF;
float rowSigma = sigmaY * (1 + (Nfixed - 1) * bandF +
(Nburst - 1) * burstF);
float k = 0.15f + 0.35f * hash01(SEED, uint32_t(frame_number), y, 777);
float k = 0.15f + 0.35f * hash01(SEED, uint32_t(frame_number), y_ref, 777);
float sL = 0.0f, sR = 0.0f;
for (int x = 0; x < w; ++x) {
if (hash01(SEED, uint32_t(frame_number), y, x) < p)
const int x_ref = static_cast<int>(std::round(static_cast<float>(x) * reference_scale_x));
if (hash01(SEED, uint32_t(frame_number), y_ref, x_ref) < p)
sL = 1.0f;
if (hash01(SEED, uint32_t(frame_number), y, w - 1 - x) < p * 0.7f)
if (hash01(SEED, uint32_t(frame_number), y_ref, reference_w - 1 - x_ref) < p * 0.7f)
sR = 1.0f;
float n = ((step(s0) & 0xFFFFFF) / 16777215.0f) * (1 - a) +
((step(s1) & 0xFFFFFF) / 16777215.0f) * a;
Expand All @@ -303,13 +314,14 @@ std::shared_ptr<Frame> AnalogTape::GetFrame(std::shared_ptr<Frame> frame,
}
}

float A = lerp(0.0f, 3.0f, k_track); // pixels
float A = lerp(0.0f, 3.0f, k_track) * inverse_scale_x; // pixels
float f = lerp(0.25f, 1.2f, k_track); // Hz
float Hsk = lerp(0.0f, 0.10f * h, k_track); // pixels
float S = lerp(0.0f, 5.0f, k_track); // pixels
float S = lerp(0.0f, 5.0f, k_track) * inverse_scale_x; // pixels
float phase = 2 * PI * (f * t) + 0.7f * (SEED * 0.001f);
for (int y = 0; y < h; ++y) {
float base = A * std::sin(2 * PI * 0.0035f * y + phase);
const float y_ref = static_cast<float>(y) * reference_scale_y;
float base = A * std::sin(2 * PI * 0.0035f * y_ref + phase);
float skew = (y >= h - Hsk)
? S * ((y - (h - Hsk)) / std::max(1.0f, Hsk))
: 0.0f;
Expand Down
Loading
Loading