Skip to content

Commit

Permalink
Merge d85984f into dd2735e
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc authored Feb 18, 2021
2 parents dd2735e + d85984f commit d91a8a3
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions src/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ void Clip::SetJsonValue(const Json::Value root) {

// Create instance of effect
if ( (e = EffectInfo().CreateEffect(existing_effect["type"].asString()))) {

// Load Json into Effect
e->SetJsonValue(existing_effect);

Expand Down Expand Up @@ -1131,7 +1131,7 @@ bool Clip::isEqual(double a, double b)
void Clip::apply_keyframes(std::shared_ptr<Frame> frame, int width, int height)
{
// Get actual frame image data
std::shared_ptr<QImage> source_image = frame->GetImage();
auto source_image = frame->GetImage();

/* REPLACE IMAGE WITH WAVEFORM IMAGE (IF NEEDED) */
if (Waveform())
Expand All @@ -1146,31 +1146,9 @@ void Clip::apply_keyframes(std::shared_ptr<Frame> frame, int width, int height)
int alpha = wave_color.alpha.GetInt(frame->number);

// Generate Waveform Dynamically (the size of the timeline)
source_image = frame->GetWaveform(width, height, red, green, blue, alpha);
frame->AddImage(std::shared_ptr<QImage>(source_image));
}

/* ALPHA & OPACITY */
if (alpha.GetValue(frame->number) != 1.0)
{
float alpha_value = alpha.GetValue(frame->number);

// Get source image's pixels
unsigned char *pixels = source_image->bits();

// Loop through pixels
for (int pixel = 0, byte_index=0; pixel < source_image->width() * source_image->height(); pixel++, byte_index+=4)
{
// Apply alpha to pixel values (since we use a premultiplied value, we must
// multiply the alpha with all colors).
pixels[byte_index + 0] *= alpha_value;
pixels[byte_index + 1] *= alpha_value;
pixels[byte_index + 2] *= alpha_value;
pixels[byte_index + 3] *= alpha_value;
}

// Debug output
ZmqLogger::Instance()->AppendDebugMethod("Clip::apply_keyframes (Set Alpha & Opacity)", "alpha_value", alpha_value, "frame->number", frame->number);
auto wave_image = frame->GetWaveform(width, height, red, green, blue, alpha);
frame->AddImage(wave_image);
source_image.swap(wave_image);
}

/* RESIZE SOURCE IMAGE - based on scale type */
Expand Down Expand Up @@ -1311,10 +1289,18 @@ void Clip::apply_keyframes(std::shared_ptr<Frame> frame, int width, int height)
// Apply transform (translate, rotate, scale)
painter.setTransform(transform);

// Apply transparency
painter.setOpacity(alpha.GetValue(frame->number));
// Debug output
ZmqLogger::Instance()->AppendDebugMethod("Clip::apply_keyframes (Set Alpha & Opacity)", "alpha_value", alpha.GetValue(frame->number), "frame->number", frame->number);

// Composite a new layer onto the image
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.drawImage(0, 0, *source_image);

// Reset transparency
painter.setOpacity(1.0f);

if (timeline) {
Timeline *t = (Timeline *) timeline;

Expand Down

0 comments on commit d91a8a3

Please sign in to comment.