Skip to content

Commit bba7d93

Browse files
author
tsl
committed
cmake and clang-tidy actionclang-tidy fixesfixes some warnings
1 parent 2c680c9 commit bba7d93

19 files changed

+254
-565
lines changed

.clang-tidy

Lines changed: 9 additions & 415 deletions
Large diffs are not rendered by default.

.github/workflows/cmake.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: CMake-build-lint-test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
env:
9+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
10+
BUILD_TYPE: Release
11+
12+
jobs:
13+
build:
14+
# The CMake configure and build commands are platform agnostic and should work equally
15+
# well on Windows or Mac. You can convert this to a matrix build if you need
16+
# cross-platform coverage.
17+
# See: https://docs.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#configuring-a-build-matrix
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
23+
- name: Install dependencies, opencv, Qt5 for GUIs and clang-10
24+
run: sudo apt-get install libopencv-dev qtbase5-dev clang-10 ninja-build
25+
26+
- name: Create Build Environment
27+
# Some projects don't allow in-source building, so create a separate build directory
28+
# We'll use this as our working directory for all subsequent commands
29+
run: cmake -E make_directory ${{runner.workspace}}/build
30+
31+
- name: Configure CMake
32+
# Use a bash shell so we can use the same syntax for environment variable
33+
# access regardless of the host operating system
34+
shell: bash
35+
working-directory: ${{runner.workspace}}/build
36+
# Note the current convention is to use the -S and -B options here to specify source
37+
# and build directories, but this is only available with CMake 3.13 and higher.
38+
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
39+
run: cmake $GITHUB_WORKSPACE -DCMAKE_C_COMPILER=/usr/bin/clang-10 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-10 -DCMAKE_BUILD_TYPE=$BUILD_TYPE -GNinja
40+
41+
- name: Build
42+
working-directory: ${{runner.workspace}}/build
43+
shell: bash
44+
# Execute the build. You can specify a specific target with "--target <NAME>"
45+
run: cmake --build . --config $BUILD_TYPE
46+
47+
- name: clang-tidy
48+
build_dir: ${{runner.workspace}}/build
49+
uses: ZedThree/[email protected]
50+
id: review
51+
# If there are any comments, fail the check
52+
- if: steps.review.outpus.total_comments > 0
53+
run: exit 1
54+
55+
- name: Test
56+
working-directory: ${{runner.workspace}}/build
57+
shell: bash
58+
# Execute tests defined by the CMake configuration.
59+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
60+
run: ctest -C $BUILD_TYPE

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# painty ![Bazel build and test](https://github.com/lindemeier/painty/workflows/bazel-tests/badge.svg) ![clang-format](https://github.com/lindemeier/painty/workflows/clang-format/badge.svg)
1+
# painty ![CMake build, test and lint](https://github.com/lindemeier/painty/workflows/CMake-build-lint-test/badge.svg) ![Bazel build and test](https://github.com/lindemeier/painty/workflows/bazel-tests/badge.svg) ![clang-format](https://github.com/lindemeier/painty/workflows/clang-format/badge.svg)
22

33
Library containing several algorithms for:
44
- Image processing.

painty/core/Color.h

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ class ColorConverter {
118118
Scalar weight = t * t * (3 - 2 * t);
119119
return A + weight * (B - A);
120120
};
121-
Scalar x0, x1, x2, x3, y0, y1;
121+
Scalar x0;
122+
Scalar x1;
123+
Scalar x2;
124+
Scalar x3;
125+
Scalar y0;
126+
Scalar y1;
122127
// red
123128
x0 = cubicInt(ryb[2], 1., 0.163);
124129
x1 = cubicInt(ryb[2], 1., 0.);
@@ -181,18 +186,20 @@ class ColorConverter {
181186

182187
// make linear rgb, no chromatic adaption
183188
void srgb2rgb(const Scalar s, Scalar& l) const {
184-
if (s <= 0.0404482362771082)
189+
if (s <= 0.0404482362771082) {
185190
l = s / 12.92;
186-
else
191+
} else {
187192
l = std::pow(((s + 0.055) / 1.055), 2.4);
193+
}
188194
}
189195

190196
// make sRGB, with gamma
191197
void rgb2srgb(const Scalar l, Scalar& s) const {
192-
if (l <= 0.00313066844250063)
198+
if (l <= 0.00313066844250063) {
193199
s = l * 12.92;
194-
else
200+
} else {
195201
s = 1.055 * std::pow(l, 1. / 2.4) - 0.055;
202+
}
196203
}
197204

198205
// make linear rgb, no chromatic adaption
@@ -297,17 +304,19 @@ class ColorConverter {
297304

298305
const Scalar fa = 1. / 360.0;
299306

300-
if (fuzzyCompare(max, min, Epsilon))
307+
if (fuzzyCompare(max, min, Epsilon)) {
301308
hsv[0] = 0;
302-
else if (fuzzyCompare(max, srgb[0], Epsilon))
309+
} else if (fuzzyCompare(max, srgb[0], Epsilon)) {
303310
hsv[0] = 60.0 * (0 + (srgb[1] - srgb[2]) * delMax);
304-
else if (fuzzyCompare(max, srgb[1], Epsilon))
311+
} else if (fuzzyCompare(max, srgb[1], Epsilon)) {
305312
hsv[0] = 60.0 * (2 + (srgb[2] - srgb[0]) * delMax);
306-
else if (fuzzyCompare(max, srgb[2], Epsilon))
313+
} else if (fuzzyCompare(max, srgb[2], Epsilon)) {
307314
hsv[0] = 60.0 * (4 + (srgb[0] - srgb[1]) * delMax);
315+
}
308316

309-
if (hsv[0] < 0.0)
317+
if (hsv[0] < 0.0) {
310318
hsv[0] += 360.0;
319+
}
311320

312321
if (fuzzyCompare(max, 0.0, Epsilon)) {
313322
hsv[1] = 0.0;
@@ -346,16 +355,22 @@ class ColorConverter {
346355
XYZ[1] =
347356
(Luv[0] > keps) ? (std::pow((Luv[0] + 16.) / 116., 3.)) : (Luv[1] / k);
348357

349-
Scalar Xr, Yr, Zr;
358+
Scalar Xr;
359+
Scalar Yr;
360+
Scalar Zr;
350361
Xr = illuminant[0];
351362
Yr = illuminant[1];
352363
Zr = illuminant[2];
353364

354-
Scalar u0, v0;
365+
Scalar u0;
366+
Scalar v0;
355367
u0 = (4. * Xr) / (Xr + 15. * Yr + 3. * Zr);
356368
v0 = (9. * Yr) / (Xr + 15. * Yr + 3. * Zr);
357369

358-
Scalar a, b, c, d;
370+
Scalar a;
371+
Scalar b;
372+
Scalar c;
373+
Scalar d;
359374
a = (1. / 3.) * (((52. * Luv[0]) / (Luv[1] + 13. * Luv[0] * u0)) - 1.);
360375
b = -5. * XYZ[1];
361376
c = -(1. / 3.);
@@ -666,27 +681,33 @@ class ColorConverter {
666681

667682
// Ensure hue is between 0 and 2pi
668683
Scalar hpstd = std::atan2(bstd, apstd);
669-
if (hpstd < 0)
684+
if (hpstd < 0) {
670685
hpstd += 2. * Pi<Scalar>; // rollover ones that come -ve
686+
}
671687

672688
Scalar hpsample = std::atan2(bsample, apsample);
673-
if (hpsample < 0)
689+
if (hpsample < 0) {
674690
hpsample += 2. * Pi<Scalar>;
675-
if (fuzzyCompare((fabs(apsample) + fabs(bsample)), 0., Epsilon))
691+
}
692+
if (fuzzyCompare((fabs(apsample) + fabs(bsample)), 0., Epsilon)) {
676693
hpsample = 0.;
694+
}
677695

678696
Scalar dL = (Lsample - Lstd);
679697
Scalar dC = (Cpsample - Cpstd);
680698

681699
// Computation of hue difference
682700
Scalar dhp = (hpsample - hpstd);
683-
if (dhp > Pi<Scalar>)
701+
if (dhp > Pi<Scalar>) {
684702
dhp -= 2. * Pi<Scalar>;
685-
if (dhp < -Pi<Scalar>)
703+
}
704+
if (dhp < -Pi<Scalar>) {
686705
dhp += 2. * Pi<Scalar>;
706+
}
687707
// set chroma difference to zero if the product of chromas is zero
688-
if (fuzzyCompare(Cpprod, 0., Epsilon))
708+
if (fuzzyCompare(Cpprod, 0., Epsilon)) {
689709
dhp = 0.;
710+
}
690711

691712
// Note that the defining equations actually need
692713
// signed Hue and chroma differences which is different
@@ -705,16 +726,19 @@ class ColorConverter {
705726
// where needed
706727
Scalar hp = (hpstd + hpsample) / 2.;
707728
// Identify positions for which abs hue diff exceeds 180 degrees
708-
if (fabs(hpstd - hpsample) > Pi<Scalar>)
729+
if (fabs(hpstd - hpsample) > Pi<Scalar>) {
709730
hp -= Pi<Scalar>;
731+
}
710732
// rollover ones that come -ve
711-
if (hp < 0)
733+
if (hp < 0) {
712734
hp += 2. * Pi<Scalar>;
735+
}
713736

714737
// Check if one of the chroma values is zero, in which case set
715738
// mean hue to the sum which is equivalent to other value
716-
if (fuzzyCompare(Cpprod, 0., Epsilon))
739+
if (fuzzyCompare(Cpprod, 0., Epsilon)) {
717740
hp = hpsample + hpstd;
741+
}
718742

719743
Scalar Lpm502 = (Lp - 50.) * (Lp - 50.);
720744
Scalar Sl = 1. + 0.015 * Lpm502 / std::sqrt(20.0 + Lpm502);
@@ -749,9 +773,8 @@ class ColorConverter {
749773
Scalar d = ColorDifferenceCIEDE2000(lab1, lab2);
750774
if (d >= 0 && d <= d0) {
751775
return d / d0;
752-
} else {
753-
return 1.;
754776
}
777+
return 1.;
755778
}
756779

757780
private:

painty/core/Math.h

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ static constexpr auto Pi = static_cast<Float>(
3333
*/
3434
template <typename Float>
3535
typename std::enable_if<std::is_floating_point<Float>::value, bool>::type
36-
fuzzyCompare(const Float firstValue, const Float secondValue,
37-
const Float epsilon) {
36+
fuzzyCompare(Float firstValue, Float secondValue, Float epsilon) {
3837
return std::fabs(firstValue - secondValue) < epsilon;
3938
}
4039

@@ -80,7 +79,8 @@ Value generalizedBarycentricCoordinatesInterpolate(
8079

8180
if (polygon.empty() || values.empty()) {
8281
throw std::invalid_argument("Polygon is empty");
83-
} else if (polygon.size() != values.size()) {
82+
}
83+
if (polygon.size() != values.size()) {
8484
throw std::invalid_argument("Polygon size differs from values size");
8585
} else if (n == 1U) {
8686
return values.front();
@@ -142,9 +142,8 @@ Value generalizedBarycentricCoordinatesInterpolate(
142142
}
143143
if (!fuzzyCompare(W, 0.0, Eps)) {
144144
return f * (1.0 / W);
145-
} else {
146-
return values.front();
147145
}
146+
return values.front();
148147
}
149148

150149
/**
@@ -160,13 +159,12 @@ template <typename Float, typename std::enable_if_t<
160159
Float coth(const Float& x) {
161160
if (x > static_cast<Float>(20.0)) {
162161
return static_cast<Float>(1.0);
162+
}
163+
if (std::fabs(x) > static_cast<Float>(0.0)) {
164+
const auto res = std::cosh(x) / std::sinh(x);
165+
return std::isnan(res) ? static_cast<Float>(1.0) : res;
163166
} else {
164-
if (std::fabs(x) > static_cast<Float>(0.0)) {
165-
const auto res = std::cosh(x) / std::sinh(x);
166-
return std::isnan(res) ? static_cast<Float>(1.0) : res;
167-
} else {
168-
return std::numeric_limits<Float>::infinity();
169-
}
167+
return std::numeric_limits<Float>::infinity();
170168
}
171169
}
172170

@@ -187,11 +185,10 @@ Float acoth(const Float& x) {
187185
x, 1.0,
188186
static_cast<Float>(100.0) * std::numeric_limits<Float>::epsilon())) {
189187
return std::numeric_limits<Float>::infinity();
190-
} else {
191-
return std::log((x + static_cast<Float>(1.0)) /
192-
(x - static_cast<Float>(1.0))) /
193-
static_cast<Float>(2.0);
194188
}
189+
return std::log((x + static_cast<Float>(1.0)) /
190+
(x - static_cast<Float>(1.0))) /
191+
static_cast<Float>(2.0);
195192
}
196193

197194
template <

painty/core/Spline.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ inline T Cubic(const T& p_1, const T& p0, const T& p1, const T& p2,
4949
using Float = typename DataType<T>::channel_type;
5050

5151
Float t2;
52-
T a0, a1, a2, a3;
52+
T a0;
53+
T a1;
54+
T a2;
55+
T a3;
5356

5457
t2 = t * t;
5558
a0 = p2 - p1 - p_1 + p0;
@@ -104,44 +107,43 @@ class SplineEval {
104107
SplineEval(ContainerIt begin, ContainerIt end) : _begin(begin), _end(end) {}
105108

106109
value_type linear(value u) {
107-
int32_t index;
110+
int32_t index = 0;
108111
value t;
109112
getControl(u, index, t);
110113
return Linear(getIndexClamped(index), getIndexClamped(index + 1), t);
111114
}
112115

113116
value_type linearDerivative(value u) {
114-
int32_t index;
117+
int32_t index = 0;
115118
value t;
116119
getControl(u, index, t);
117120
return LinearDerivative(getIndexClamped(index), getIndexClamped(index + 1));
118121
}
119122

120123
value_type cubic(value u) {
121-
int32_t index;
124+
int32_t index = 0;
122125
value t;
123126
getControl(u, index, t);
124127
return Cubic(getIndexClamped(index - 1), getIndexClamped(index),
125128
getIndexClamped(index + 1), getIndexClamped(index + 2), t);
126129
}
127130

128131
value_type cubicDerivative(value u, int32_t order) {
129-
int32_t index;
132+
int32_t index = 0;
130133
value t;
131134
getControl(u, index, t);
132135
if (order == 2) {
133136
return CubicDerivativeSecond(
134137
getIndexClamped(index - 1), getIndexClamped(index),
135138
getIndexClamped(index + 1), getIndexClamped(index + 2), t);
136-
} else {
137-
return CubicDerivativeFirst(
138-
getIndexClamped(index - 1), getIndexClamped(index),
139-
getIndexClamped(index + 1), getIndexClamped(index + 2), t);
140139
}
140+
return CubicDerivativeFirst(
141+
getIndexClamped(index - 1), getIndexClamped(index),
142+
getIndexClamped(index + 1), getIndexClamped(index + 2), t);
141143
}
142144

143145
value cubicCurvature(value u) {
144-
int32_t index;
146+
int32_t index = 0;
145147
value t;
146148
getControl(u, index, t);
147149
return CubicCurvature(getIndexClamped(index - 1), getIndexClamped(index),
@@ -150,7 +152,7 @@ class SplineEval {
150152
}
151153

152154
value_type catmullRom(value u) {
153-
int32_t index;
155+
int32_t index = 0;
154156
value t;
155157
getControl(u, index, t);
156158
return CatmullRom(getIndexClamped(index - 1), getIndexClamped(index),

painty/image/Convolution.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ inline T gaussSigmaFromKernelRadius(const int32_t radius) {
3333
return gaussSigmaFromKernelSize<T>(radius * 2 + 1);
3434
}
3535

36-
Mat1d createGauss1stDerivativeKernel(const double sigma, const double theta,
36+
Mat1d createGauss1stDerivativeKernel(double sigma, double theta,
3737
bool normalized = true);
3838

39-
Mat1d createGauss2ndDerivativeKernel(const double sigma, const double theta,
39+
Mat1d createGauss2ndDerivativeKernel(double sigma, double theta,
4040
bool normalized = true);
4141
/**
4242
* article{DBLP:journals/saj/GwetuTV14,
@@ -97,7 +97,8 @@ Mat<T> convolve2d(const Mat<T>& source, const Mat1d& kernel) {
9797
template <class T>
9898
Mat<T> differencesOfGaussians(const Mat<T>& input, const double sigma,
9999
const double tau = 0.99) {
100-
Mat<T> d0, d1;
100+
Mat<T> d0;
101+
Mat<T> d1;
101102
cv::GaussianBlur(input, d0, cv::Size(-1, -1), sigma);
102103
cv::GaussianBlur(input, d1, cv::Size(-1, -1), 1.6 * sigma);
103104

0 commit comments

Comments
 (0)