From f82c01db2dc84eaff02808d3dcaec463c48a453c Mon Sep 17 00:00:00 2001 From: Chad Walker Date: Tue, 11 Jun 2019 17:04:07 -0500 Subject: [PATCH 1/4] make use of crop_x, crop_y, crop_with, crop_height keyframes --- src/Clip.cpp | 6 +++--- src/Timeline.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/Clip.cpp b/src/Clip.cpp index 2099705d..48085655 100644 --- a/src/Clip.cpp +++ b/src/Clip.cpp @@ -76,9 +76,9 @@ void Clip::init_settings() wave_color = Color((unsigned char)0, (unsigned char)123, (unsigned char)255, (unsigned char)255); // Init crop settings - crop_gravity = GRAVITY_CENTER; - crop_width = Keyframe(-1.0); - crop_height = Keyframe(-1.0); + crop_gravity = GRAVITY_TOP_LEFT; + crop_width = Keyframe(1.0); + crop_height = Keyframe(1.0); crop_x = Keyframe(0.0); crop_y = Keyframe(0.0); diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 37d3f71c..3d96c002 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -457,6 +457,43 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in } } + float crop_x = source_clip->crop_x.GetValue(clip_frame_number); + float crop_y = source_clip->crop_y.GetValue(clip_frame_number); + float crop_w = source_clip->crop_width.GetValue(clip_frame_number); + float crop_h = source_clip->crop_height.GetValue(clip_frame_number); + switch(source_clip->crop_gravity) + { + case (GRAVITY_TOP): + crop_x += 0.5; + break; + case (GRAVITY_TOP_RIGHT): + crop_x += 1.0; + break; + case (GRAVITY_LEFT): + crop_y += 0.5; + break; + case (GRAVITY_CENTER): + crop_x += 0.5; + crop_y += 0.5; + break; + case (GRAVITY_RIGHT): + crop_x += 1.0; + crop_y += 0.5; + break; + case (GRAVITY_BOTTOM_LEFT): + crop_y += 1.0; + break; + case (GRAVITY_BOTTOM): + crop_x += 0.5; + crop_y += 1.0; + break; + case (GRAVITY_BOTTOM_RIGHT): + crop_x += 1.0; + crop_y += 1.0; + break; + } + + /* GRAVITY LOCATION - Initialize X & Y to the correct values (before applying location curves) */ float x = 0.0; // left float y = 0.0; // top @@ -564,7 +601,7 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in // Composite a new layer onto the image painter.setCompositionMode(QPainter::CompositionMode_SourceOver); - painter.drawImage(0, 0, *source_image); + painter.drawImage(0, 0, *source_image, crop_x * scaled_source_width, crop_y * scaled_source_height, crop_w * scaled_source_width, crop_h * scaled_source_height); // Draw frame #'s on top of image (if needed) if (source_clip->display != FRAME_DISPLAY_NONE) { From 0fd335ab7bd6a50c85cbcc333fcdb79fdb56f409 Mon Sep 17 00:00:00 2001 From: Chad Walker Date: Tue, 11 Jun 2019 20:28:23 -0500 Subject: [PATCH 2/4] use source_image->width() and source_image->height() instead of scaled_source_width and scaled_source_height --- src/Timeline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 3d96c002..74aed9a4 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -601,7 +601,7 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in // Composite a new layer onto the image painter.setCompositionMode(QPainter::CompositionMode_SourceOver); - painter.drawImage(0, 0, *source_image, crop_x * scaled_source_width, crop_y * scaled_source_height, crop_w * scaled_source_width, crop_h * scaled_source_height); + painter.drawImage(0, 0, *source_image, crop_x * source_image->width(), crop_y * source_image->height(), crop_w * source_image->width(), crop_h * source_image->height()); // Draw frame #'s on top of image (if needed) if (source_clip->display != FRAME_DISPLAY_NONE) { From 094c378e67f84b8064d32c3b441f27a66afb2772 Mon Sep 17 00:00:00 2001 From: Chad Walker Date: Fri, 21 Jun 2019 23:43:56 -0500 Subject: [PATCH 3/4] add crop properties to json --- src/Clip.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Clip.cpp b/src/Clip.cpp index 48085655..0a059828 100644 --- a/src/Clip.cpp +++ b/src/Clip.cpp @@ -713,6 +713,11 @@ string Clip::PropertiesJSON(int64_t requested_frame) { root["has_audio"] = add_property_json("Enable Audio", has_audio.GetValue(requested_frame), "int", "", &has_audio, -1, 1.0, false, requested_frame); root["has_video"] = add_property_json("Enable Video", has_video.GetValue(requested_frame), "int", "", &has_video, -1, 1.0, false, requested_frame); + root["crop_x"] = add_property_json("Crop X", crop_x.GetValue(requested_frame), "float", "", &crop_x, 0.0, 0.0, false, requested_frame); + root["crop_y"] = add_property_json("Crop Y", crop_y.GetValue(requested_frame), "float", "", &crop_y, 0.0, 0.0, false, requested_frame); + root["crop_width"] = add_property_json("Crop Width", crop_width.GetValue(requested_frame), "float", "", &crop_width, 0.0, 1.0, false, requested_frame); + root["crop_height"] = add_property_json("Crop Height", crop_height.GetValue(requested_frame), "float", "", &crop_height, 0.0, 1.0, false, requested_frame); + root["wave_color"] = add_property_json("Wave Color", 0.0, "color", "", &wave_color.red, 0, 255, false, requested_frame); root["wave_color"]["red"] = add_property_json("Red", wave_color.red.GetValue(requested_frame), "float", "", &wave_color.red, 0, 255, false, requested_frame); root["wave_color"]["blue"] = add_property_json("Blue", wave_color.blue.GetValue(requested_frame), "float", "", &wave_color.blue, 0, 255, false, requested_frame); From e2677e4512b4186813ddbff239bebfd98cd39993 Mon Sep 17 00:00:00 2001 From: Chad Walker Date: Sat, 22 Jun 2019 20:19:34 -0500 Subject: [PATCH 4/4] fix the crop_x and crop_y min and max --- src/Clip.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Clip.cpp b/src/Clip.cpp index 0a059828..cca9f193 100644 --- a/src/Clip.cpp +++ b/src/Clip.cpp @@ -713,8 +713,8 @@ string Clip::PropertiesJSON(int64_t requested_frame) { root["has_audio"] = add_property_json("Enable Audio", has_audio.GetValue(requested_frame), "int", "", &has_audio, -1, 1.0, false, requested_frame); root["has_video"] = add_property_json("Enable Video", has_video.GetValue(requested_frame), "int", "", &has_video, -1, 1.0, false, requested_frame); - root["crop_x"] = add_property_json("Crop X", crop_x.GetValue(requested_frame), "float", "", &crop_x, 0.0, 0.0, false, requested_frame); - root["crop_y"] = add_property_json("Crop Y", crop_y.GetValue(requested_frame), "float", "", &crop_y, 0.0, 0.0, false, requested_frame); + root["crop_x"] = add_property_json("Crop X", crop_x.GetValue(requested_frame), "float", "", &crop_x, -1.0, 1.0, false, requested_frame); + root["crop_y"] = add_property_json("Crop Y", crop_y.GetValue(requested_frame), "float", "", &crop_y, -1.0, 1.0, false, requested_frame); root["crop_width"] = add_property_json("Crop Width", crop_width.GetValue(requested_frame), "float", "", &crop_width, 0.0, 1.0, false, requested_frame); root["crop_height"] = add_property_json("Crop Height", crop_height.GetValue(requested_frame), "float", "", &crop_height, 0.0, 1.0, false, requested_frame);