Skip to content

Commit 3c254fb

Browse files
authored
Fix C++ lint (#2009)
* Fix C++ lint * More fixes
1 parent 249f547 commit 3c254fb

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

torchvision/csrc/cpu/decoder/defs.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ struct VideoFormat {
5353
When width = 0, height = 0, minDimension = 0, and maxDimension = 0,
5454
keep the orignal frame resolution
5555
When width = 0, height = 0, minDimension != 0, and maxDimension = 0,
56-
keep the aspect ratio and resize the frame so that shorter edge size is minDimension
56+
keep the aspect ratio and resize the frame so that shorter edge size is
57+
minDimension
5758
When width = 0, height = 0, minDimension = 0, and maxDimension != 0,
58-
keep the aspect ratio and resize the frame so that longer edge size is maxDimension
59+
keep the aspect ratio and resize the frame so that longer edge size is
60+
maxDimension
5961
When width = 0, height = 0, minDimension != 0, and maxDimension != 0,
6062
resize the frame so that shorter edge size is minDimension, and
6163
longer edge size is maxDimension. The aspect ratio may not be preserved
@@ -64,7 +66,8 @@ struct VideoFormat {
6466
When width != 0, height = 0, minDimension = 0, and maxDimension = 0,
6567
keep the aspect ratio and resize the frame so that frame width is $width
6668
When width != 0, height != 0, minDimension = 0, and maxDimension = 0,
67-
resize the frame so that frame width and height are set to $width and $height,
69+
resize the frame so that frame width and height are set to $width and
70+
$height,
6871
respectively
6972
*/
7073
size_t width{0}; // width in pixels

torchvision/csrc/cpu/decoder/util.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ size_t size(const AVSubtitle& sub) {
284284
}
285285

286286
bool validateVideoFormat(const VideoFormat& f) {
287+
// clang-format off
287288
/*
288289
Valid parameters values for decoder
289290
____________________________________________________________________________________
@@ -307,6 +308,7 @@ bool validateVideoFormat(const VideoFormat& f) {
307308
|_____|_____|______________|______________|___________|____________________________|
308309
309310
*/
311+
// clang-format on
310312
return (f.width == 0 && // #1, #6, #7 and #8
311313
f.height == 0 && f.cropImage == 0) ||
312314
(f.width != 0 && // #4 and #5
@@ -346,8 +348,7 @@ void setFormatDimensions(
346348
destW = minDimension;
347349
destH = round(double(srcH * minDimension) / srcW);
348350
}
349-
}
350-
else if (minDimension == 0 && maxDimension > 0) { // #7
351+
} else if (minDimension == 0 && maxDimension > 0) { // #7
351352
if (srcW > srcH) {
352353
// landscape
353354
destW = maxDimension;
@@ -357,8 +358,7 @@ void setFormatDimensions(
357358
destH = maxDimension;
358359
destW = round(double(srcW * maxDimension) / srcH);
359360
}
360-
}
361-
else if (minDimension > 0 && maxDimension > 0) { // #8
361+
} else if (minDimension > 0 && maxDimension > 0) { // #8
362362
if (srcW > srcH) {
363363
// landscape
364364
destW = maxDimension;
@@ -368,8 +368,7 @@ void setFormatDimensions(
368368
destW = minDimension;
369369
destH = maxDimension;
370370
}
371-
}
372-
else { // #1
371+
} else { // #1
373372
destW = srcW;
374373
destH = srcH;
375374
}

torchvision/csrc/cpu/decoder/util_test.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,32 @@
44
#include "util.h"
55

66
TEST(Util, TestSetFormatDimensions) {
7-
const size_t test_cases[][9] = {
8-
// (userW, userH, srcW, srcH, minDimension, maxDimension, cropImage, destW, destH)
9-
{0, 0, 172, 128, 0, 0, 0, 172, 128}, // #1
10-
{86, 0, 172, 128, 0, 0, 0, 86, 64}, // #2
11-
{64, 0, 128, 172, 0, 0, 0, 64, 86}, // #2
12-
{0, 32, 172, 128, 0, 0, 0, 43, 32}, // #3
13-
{32, 0, 128, 172, 0, 0, 0, 32, 43}, // #3
14-
{60, 50, 172, 128, 0, 0, 0, 60, 50}, // #4
15-
{50, 60, 128, 172, 0, 0, 0, 50, 60}, // #4
16-
{86, 40, 172, 128, 0, 0, 1, 86, 64}, // #5
17-
{86, 92, 172, 128, 0, 0, 1, 124, 92}, // #5
18-
{0, 0, 172, 128, 256, 0, 0, 344, 256}, // #6
19-
{0, 0, 128, 172, 256, 0, 0, 256, 344}, // #6
20-
{0, 0, 128, 172, 0, 344, 0, 256, 344}, // #7
21-
{0, 0, 172, 128, 0, 344, 0, 344, 256}, // #7
22-
{0, 0, 172, 128, 100, 344, 0, 344, 100},// #8
23-
{0, 0, 128, 172, 100, 344, 0, 100, 344} // #8
24-
};
7+
// clang-format off
8+
const size_t test_cases[][9] = {
9+
// (userW, userH, srcW, srcH, minDimension, maxDimension, cropImage, destW, destH)
10+
{0, 0, 172, 128, 0, 0, 0, 172, 128}, // #1
11+
{86, 0, 172, 128, 0, 0, 0, 86, 64}, // #2
12+
{64, 0, 128, 172, 0, 0, 0, 64, 86}, // #2
13+
{0, 32, 172, 128, 0, 0, 0, 43, 32}, // #3
14+
{32, 0, 128, 172, 0, 0, 0, 32, 43}, // #3
15+
{60, 50, 172, 128, 0, 0, 0, 60, 50}, // #4
16+
{50, 60, 128, 172, 0, 0, 0, 50, 60}, // #4
17+
{86, 40, 172, 128, 0, 0, 1, 86, 64}, // #5
18+
{86, 92, 172, 128, 0, 0, 1, 124, 92}, // #5
19+
{0, 0, 172, 128, 256, 0, 0, 344, 256}, // #6
20+
{0, 0, 128, 172, 256, 0, 0, 256, 344}, // #6
21+
{0, 0, 128, 172, 0, 344, 0, 256, 344}, // #7
22+
{0, 0, 172, 128, 0, 344, 0, 344, 256}, // #7
23+
{0, 0, 172, 128, 100, 344, 0, 344, 100},// #8
24+
{0, 0, 128, 172, 100, 344, 0, 100, 344} // #8
25+
};
26+
// clang-format onn
2527

26-
for (const auto& tc : test_cases) {
27-
size_t destW = 0;
28-
size_t destH = 0;
29-
ffmpeg::Util::setFormatDimensions(destW, destH, tc[0], tc[1], tc[2], tc[3], tc[4], tc[5], tc[6]);
30-
CHECK(destW == tc[7]);
31-
CHECK(destH == tc[8]);
32-
}
28+
for (const auto& tc : test_cases) {
29+
size_t destW = 0;
30+
size_t destH = 0;
31+
ffmpeg::Util::setFormatDimensions(destW, destH, tc[0], tc[1], tc[2], tc[3], tc[4], tc[5], tc[6]);
32+
CHECK(destW == tc[7]);
33+
CHECK(destH == tc[8]);
34+
}
3335
}

0 commit comments

Comments
 (0)