Skip to content

Commit f82c01d

Browse files
author
Chad Walker
committed
make use of crop_x, crop_y, crop_with, crop_height keyframes
1 parent 0d4ea7f commit f82c01d

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/Clip.cpp

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

7878
// Init crop settings
79-
crop_gravity = GRAVITY_CENTER;
80-
crop_width = Keyframe(-1.0);
81-
crop_height = Keyframe(-1.0);
79+
crop_gravity = GRAVITY_TOP_LEFT;
80+
crop_width = Keyframe(1.0);
81+
crop_height = Keyframe(1.0);
8282
crop_x = Keyframe(0.0);
8383
crop_y = Keyframe(0.0);
8484

src/Timeline.cpp

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

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

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

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

0 commit comments

Comments
 (0)