Skip to content

Commit 1b19ae7

Browse files
authored
Merge pull request #249 from chad3814/crop
make use of crop_x, crop_y, crop_with, crop_height keyframes
2 parents 3b62176 + e2677e4 commit 1b19ae7

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

src/Clip.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ void Clip::init_settings()
7979
wave_color = Color((unsigned char)0, (unsigned char)123, (unsigned char)255, (unsigned char)255);
8080

8181
// Init crop settings
82-
crop_gravity = GRAVITY_CENTER;
83-
crop_width = Keyframe(-1.0);
84-
crop_height = Keyframe(-1.0);
82+
crop_gravity = GRAVITY_TOP_LEFT;
83+
crop_width = Keyframe(1.0);
84+
crop_height = Keyframe(1.0);
8585
crop_x = Keyframe(0.0);
8686
crop_y = Keyframe(0.0);
8787

@@ -716,6 +716,11 @@ string Clip::PropertiesJSON(int64_t requested_frame) {
716716
root["has_audio"] = add_property_json("Enable Audio", has_audio.GetValue(requested_frame), "int", "", &has_audio, -1, 1.0, false, requested_frame);
717717
root["has_video"] = add_property_json("Enable Video", has_video.GetValue(requested_frame), "int", "", &has_video, -1, 1.0, false, requested_frame);
718718

719+
root["crop_x"] = add_property_json("Crop X", crop_x.GetValue(requested_frame), "float", "", &crop_x, -1.0, 1.0, false, requested_frame);
720+
root["crop_y"] = add_property_json("Crop Y", crop_y.GetValue(requested_frame), "float", "", &crop_y, -1.0, 1.0, false, requested_frame);
721+
root["crop_width"] = add_property_json("Crop Width", crop_width.GetValue(requested_frame), "float", "", &crop_width, 0.0, 1.0, false, requested_frame);
722+
root["crop_height"] = add_property_json("Crop Height", crop_height.GetValue(requested_frame), "float", "", &crop_height, 0.0, 1.0, false, requested_frame);
723+
719724
root["wave_color"] = add_property_json("Wave Color", 0.0, "color", "", &wave_color.red, 0, 255, false, requested_frame);
720725
root["wave_color"]["red"] = add_property_json("Red", wave_color.red.GetValue(requested_frame), "float", "", &wave_color.red, 0, 255, false, requested_frame);
721726
root["wave_color"]["blue"] = add_property_json("Blue", wave_color.blue.GetValue(requested_frame), "float", "", &wave_color.blue, 0, 255, false, requested_frame);

src/Timeline.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,43 @@ void Timeline::add_layer(std::shared_ptr<Frame> new_frame, Clip* source_clip, in
460460
}
461461
}
462462

463+
float crop_x = source_clip->crop_x.GetValue(clip_frame_number);
464+
float crop_y = source_clip->crop_y.GetValue(clip_frame_number);
465+
float crop_w = source_clip->crop_width.GetValue(clip_frame_number);
466+
float crop_h = source_clip->crop_height.GetValue(clip_frame_number);
467+
switch(source_clip->crop_gravity)
468+
{
469+
case (GRAVITY_TOP):
470+
crop_x += 0.5;
471+
break;
472+
case (GRAVITY_TOP_RIGHT):
473+
crop_x += 1.0;
474+
break;
475+
case (GRAVITY_LEFT):
476+
crop_y += 0.5;
477+
break;
478+
case (GRAVITY_CENTER):
479+
crop_x += 0.5;
480+
crop_y += 0.5;
481+
break;
482+
case (GRAVITY_RIGHT):
483+
crop_x += 1.0;
484+
crop_y += 0.5;
485+
break;
486+
case (GRAVITY_BOTTOM_LEFT):
487+
crop_y += 1.0;
488+
break;
489+
case (GRAVITY_BOTTOM):
490+
crop_x += 0.5;
491+
crop_y += 1.0;
492+
break;
493+
case (GRAVITY_BOTTOM_RIGHT):
494+
crop_x += 1.0;
495+
crop_y += 1.0;
496+
break;
497+
}
498+
499+
463500
/* GRAVITY LOCATION - Initialize X & Y to the correct values (before applying location curves) */
464501
float x = 0.0; // left
465502
float y = 0.0; // top
@@ -567,7 +604,7 @@ void Timeline::add_layer(std::shared_ptr<Frame> new_frame, Clip* source_clip, in
567604

568605
// Composite a new layer onto the image
569606
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
570-
painter.drawImage(0, 0, *source_image);
607+
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());
571608

572609
// Draw frame #'s on top of image (if needed)
573610
if (source_clip->display != FRAME_DISPLAY_NONE) {

0 commit comments

Comments
 (0)