Internal change
PiperOrigin-RevId: 500271109
This commit is contained in:
parent
667fd81ddc
commit
2cce88080e
|
@ -142,6 +142,9 @@ absl::Status FindOutputDimensions(int input_width, //
|
|||
static_cast<double>(input_height));
|
||||
try_width = (try_width / 2) * 2;
|
||||
try_height = (try_height / 2) * 2;
|
||||
// The output width/height should be greater than 0.
|
||||
try_width = std::max(try_width, 1);
|
||||
try_height = std::max(try_height, 1);
|
||||
|
||||
if (target_height <= 0 || try_height <= target_height) {
|
||||
// The resulting height based on the target width and aspect ratio
|
||||
|
@ -160,6 +163,9 @@ absl::Status FindOutputDimensions(int input_width, //
|
|||
static_cast<double>(input_width));
|
||||
try_width = (try_width / 2) * 2;
|
||||
try_height = (try_height / 2) * 2;
|
||||
// The output width/height should be greater than 0.
|
||||
try_width = std::max(try_width, 1);
|
||||
try_height = std::max(try_height, 1);
|
||||
|
||||
if (target_width <= 0 || try_width <= target_width) {
|
||||
// The resulting width based on the target width and aspect ratio
|
||||
|
|
|
@ -124,6 +124,16 @@ TEST(ScaleImageUtilsTest, FindOutputDimensionsPreserveRatio) {
|
|||
&output_width, &output_height));
|
||||
EXPECT_EQ(151, output_width);
|
||||
EXPECT_EQ(101, output_height);
|
||||
// Scale to height 1.
|
||||
MP_ASSERT_OK(FindOutputDimensions(10000, 10, 100, 0, 0, true, 2,
|
||||
&output_width, &output_height));
|
||||
EXPECT_EQ(100, output_width);
|
||||
EXPECT_EQ(1, output_height);
|
||||
// Scale to width 1.
|
||||
MP_ASSERT_OK(FindOutputDimensions(10, 10000, 0, 100, 0, true, 2,
|
||||
&output_width, &output_height));
|
||||
EXPECT_EQ(1, output_width);
|
||||
EXPECT_EQ(100, output_height);
|
||||
}
|
||||
|
||||
// Tests scaling without keeping the aspect ratio fixed.
|
||||
|
|
Loading…
Reference in New Issue
Block a user