|
7 | 7 | * @ref License |
8 | 8 | */ |
9 | 9 |
|
10 | | -// Copyright (c) 2008-2021 OpenShot Studios, LLC |
| 10 | +// Copyright (c) 2008-2025 OpenShot Studios, LLC |
11 | 11 | // |
12 | 12 | // SPDX-License-Identifier: LGPL-3.0-or-later |
13 | 13 |
|
|
16 | 16 | #include "openshot_catch.h" |
17 | 17 |
|
18 | 18 | #include "Frame.h" |
| 19 | +#include "Clip.h" |
19 | 20 | #include "effects/Crop.h" |
| 21 | +#include "effects/CropHelpers.h" |
20 | 22 |
|
21 | 23 | #include <QColor> |
22 | 24 | #include <QImage> |
@@ -144,3 +146,29 @@ TEST_CASE( "x/y offsets", "[libopenshot][effect][crop]" ) |
144 | 146 | // so it becomes a transparent pixel |
145 | 147 | CHECK(i->pixelColor(900, 360) == trans); |
146 | 148 | } |
| 149 | + |
| 150 | +TEST_CASE( "crop resize scaling helper", "[libopenshot][effect][crop][scaling]" ) |
| 151 | +{ |
| 152 | + // Build a clip with a resizing crop effect |
| 153 | + auto clip = std::make_unique<openshot::Clip>(); |
| 154 | + auto crop = new openshot::Crop(openshot::Keyframe(0.0), openshot::Keyframe(0.0), |
| 155 | + openshot::Keyframe(0.0), openshot::Keyframe(0.75)); |
| 156 | + crop->resize = true; |
| 157 | + clip->AddEffect(crop); |
| 158 | + |
| 159 | + int max_width = 900; |
| 160 | + int max_height = 500; |
| 161 | + |
| 162 | + // 25% of the height is visible, so request 4x height (capped at source size) |
| 163 | + openshot::ApplyCropResizeScale(clip.get(), 3840, 2160, max_width, max_height); |
| 164 | + CHECK(max_width == 900); |
| 165 | + CHECK(max_height == 2000); |
| 166 | + |
| 167 | + // If scaling would exceed source, it should clamp at source dimensions |
| 168 | + crop->bottom = openshot::Keyframe(0.9); // visible height = 10% |
| 169 | + max_width = 900; |
| 170 | + max_height = 500; |
| 171 | + openshot::ApplyCropResizeScale(clip.get(), 1920, 1080, max_width, max_height); |
| 172 | + CHECK(max_width == 900); // width unchanged (no horizontal crop) |
| 173 | + CHECK(max_height == 1080); // scaled height would be 5000, so it clamps |
| 174 | +} |
0 commit comments