Skip to content

Commit e86e816

Browse files
committed
analysis
Signed-off-by: Anton Dukhovnikov <[email protected]>
1 parent 184bbc4 commit e86e816

File tree

7 files changed

+166
-82
lines changed

7 files changed

+166
-82
lines changed

.github/workflows/analysis.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright Contributors to the rawtoaces project.
3+
4+
name: Analysis
5+
permissions:
6+
contents: read
7+
8+
on:
9+
schedule:
10+
# Run nightly
11+
- cron: "0 8 * * *"
12+
# Run weekly
13+
# - cron: "0 0 * * 0"
14+
push:
15+
# Run on pushes only to main or if the branch name contains "analysis"
16+
branches:
17+
- main
18+
- '*analysis*'
19+
paths:
20+
- '**'
21+
- '!**.md'
22+
- '!**.rst'
23+
- '!**/ci.yml'
24+
- '!**/docs.yml'
25+
- '!**/scorecard.yml'
26+
- '!**/wheel.yml'
27+
- '!**.properties'
28+
- '!docs/**'
29+
pull_request:
30+
branches:
31+
- '*analysis*'
32+
33+
# Allow subsequent pushes to the same PR or REF to cancel any previous jobs.
34+
concurrency:
35+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
36+
cancel-in-progress: true
37+
38+
jobs:
39+
analysis:
40+
name: "Static analysis"
41+
# Exclude runs on forks, since only the main org has the SonarCloud
42+
# account credentials.
43+
# if: github.repository == 'AcademySoftwareFoundation/rawtoaces'
44+
# secrets:
45+
# PASSED_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
# PASSED_SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
47+
runs-on: ubuntu-latest
48+
# container:
49+
# image: aswf/ci-osl:2024-clang17.2
50+
strategy:
51+
fail-fast: false
52+
env:
53+
CC: clang
54+
CXX: clang++
55+
steps:
56+
- uses: actions/checkout@v4
57+
58+
- name: Dependencies
59+
shell: bash
60+
run: |
61+
build_scripts/install_deps_linux.bash
62+
63+
- name: Configure CMake
64+
run: >
65+
cmake
66+
-B build
67+
-S .
68+
-D CMAKE_INSTALL_PREFIX=${{ github.workspace }}/install
69+
-D CMAKE_CXX_STANDARD=17
70+
-D CMAKE_BUILD_TYPE=Debug
71+
-D ENABLE_COVERAGE=ON
72+
-D CMAKE_CXX_FLAGS="-g -O0"
73+
-D CMAKE_EXPORT_COMPILE_COMMANDS=ON
74+
75+
- uses: whisperity/codechecker-analysis-action@v1
76+
id: codechecker
77+
with:
78+
logfile: ${{ github.workspace }}/build/compile_commands.json
79+
80+
- uses: actions/upload-artifact@v4
81+
with:
82+
name: "CodeChecker Bug Reports"
83+
path: ${{ steps.codechecker.outputs.result-html-dir }}
84+
85+
- name: "Break build if CodeChecker reported any findings"
86+
if: ${{ steps.codechecker.outputs.warnings == 'true' }}
87+
run: exit 1

include/rawtoaces/image_converter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ class ImageConverter
277277

278278
private:
279279
// Solved transform of the current image.
280-
std::vector<std::vector<double>> _IDT_matrix;
281-
std::vector<std::vector<double>> _CAT_matrix;
282-
std::vector<double> _WB_multipliers;
280+
std::vector<std::vector<double>> _idt_matrix;
281+
std::vector<std::vector<double>> _cat_matrix;
282+
std::vector<double> _wb_multipliers;
283283
};
284284

285285
} //namespace util

include/rawtoaces/rawtoaces_core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ class SpectralSolver
169169
std::vector<std::string> _search_directories;
170170
std::vector<SpectralData> _all_illuminants;
171171

172-
std::vector<double> _WB_multipliers;
173-
std::vector<std::vector<double>> _IDT_matrix;
172+
std::vector<double> _wb_multipliers;
173+
std::vector<std::vector<double>> _idt_matrix;
174174
};
175175

176176
/// DNG metadata required to calculate an input transform.

src/rawtoaces_core/define.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright Contributors to the rawtoaces Project.
33

4-
#ifndef _DEFINE_h__
5-
#define _DEFINE_h__
4+
#pragma once
65

76
#include <string>
87
#include <algorithm>
@@ -343,5 +342,3 @@ inline bool isValidCT( std::string str )
343342

344343
} // namespace core
345344
} // namespace rta
346-
347-
#endif

src/rawtoaces_core/mathOps.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright Contributors to the rawtoaces Project.
33

4-
#ifndef _MATHOPS_h__
5-
#define _MATHOPS_h__
4+
#pragma once
65

76
#include "define.h"
87

@@ -491,5 +490,3 @@ getCalcXYZt( const vector<vector<T>> &RGB, const T beta_params[6] )
491490

492491
} // namespace core
493492
} // namespace rta
494-
495-
#endif

src/rawtoaces_core/rawtoaces_core.cpp

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ void calculate_daylight_SPD( const int &cct_input, Spectrum &spectrum )
5555
cct = cct_input * 1.0;
5656
else
5757
{
58-
fprintf(
59-
stderr,
60-
"The range of Correlated Color Temperature for "
61-
"Day Light should be from 4000 to 25000. \n" );
58+
std::cerr << "The range of Correlated Color Temperature for "
59+
<< "Day Light should be from 4000 to 25000." << std::endl;
6260
exit( 1 );
6361
}
6462

@@ -104,10 +102,8 @@ void calculate_blackbody_SPD( const int &cct, Spectrum &spectrum )
104102
{
105103
if ( cct < 1500 || cct >= 4000 )
106104
{
107-
fprintf(
108-
stderr,
109-
"The range of Color Temperature for BlackBody "
110-
"should be from 1500 to 3999. \n" );
105+
std::cerr << "The range of Color Temperature for BlackBody "
106+
<< "should be from 1500 to 3999." << std::endl;
111107
exit( 1 );
112108
}
113109

@@ -147,10 +143,11 @@ void generate_illuminant(
147143
auto &main_spectral_set = main_iter->second;
148144

149145
// Add the power channel and get a reference to it
150-
auto &power_spectrum = main_spectral_set
151-
.emplace_back( SpectralData::SpectralChannel(
152-
"power", Spectrum( 0 ) ) )
153-
.second;
146+
auto &power_spectrum =
147+
main_spectral_set
148+
.emplace_back(
149+
SpectralData::SpectralChannel( "power", Spectrum( 0 ) ) )
150+
.second;
154151

155152
illuminant.illuminant = type;
156153
if ( is_daylight )
@@ -168,15 +165,15 @@ SpectralSolver::SpectralSolver(
168165
: _search_directories( search_directories )
169166
{
170167
verbosity = 0;
171-
_IDT_matrix.resize( 3 );
172-
_WB_multipliers.resize( 3 );
168+
_idt_matrix.resize( 3 );
169+
_wb_multipliers.resize( 3 );
173170
for ( int i = 0; i < 3; i++ )
174171
{
175-
_IDT_matrix[i].resize( 3 );
176-
_WB_multipliers[i] = 1.0;
172+
_idt_matrix[i].resize( 3 );
173+
_wb_multipliers[i] = 1.0;
177174
for ( size_t j = 0; j < 3; j++ )
178175
{
179-
_IDT_matrix[i][j] = neutral3[i][j];
176+
_idt_matrix[i][j] = neutral3[i][j];
180177
}
181178
}
182179
}
@@ -402,7 +399,7 @@ bool SpectralSolver::find_illuminant( const vector<double> &wb )
402399
{
403400
sse = sse_tmp;
404401
illuminant = current_illuminant;
405-
_WB_multipliers = wb_tmp;
402+
_wb_multipliers = wb_tmp;
406403
}
407404
}
408405

@@ -431,7 +428,7 @@ bool SpectralSolver::calculate_WB()
431428
return false;
432429
}
433430

434-
_WB_multipliers = _calculate_WB( camera, illuminant );
431+
_wb_multipliers = _calculate_WB( camera, illuminant );
435432
return true;
436433
}
437434

@@ -455,7 +452,7 @@ calculate_CM( const SpectralData &camera, const SpectralData &illuminant )
455452
double g = ( camera_g * illuminant_spectrum ).integrate();
456453
double b = ( camera_b * illuminant_spectrum ).integrate();
457454

458-
double max = std::max( r, std::max( g, b ) );
455+
double max = std::max( { r, g, b } );
459456

460457
std::vector<double> result( 3 );
461458
result[0] = max / r;
@@ -613,14 +610,14 @@ struct IDTOptimizationCost
613610
IDTOptimizationCost(
614611
const std::vector<std::vector<double>> &RGB,
615612
const std::vector<std::vector<double>> &out_LAB )
616-
: _RGB( RGB ), _outLAB( out_LAB )
613+
: _in_RGB( RGB ), _out_LAB( out_LAB )
617614
{}
618615

619616
template <typename T>
620617
bool operator()( const T *beta_params, T *residuals ) const;
621618

622-
const std::vector<std::vector<double>> _RGB;
623-
const std::vector<std::vector<double>> _outLAB;
619+
const std::vector<std::vector<double>> _in_RGB;
620+
const std::vector<std::vector<double>> _out_LAB;
624621
};
625622

626623
/// Perform curve fitting optimization to find optimal IDT matrix parameters.
@@ -746,10 +743,10 @@ bool SpectralSolver::calculate_IDT_matrix()
746743
double beta_params_start[6] = { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 };
747744

748745
auto TI = calculate_TI( illuminant, training_data );
749-
auto RGB = calculate_RGB( camera, _WB_multipliers, TI );
746+
auto RGB = calculate_RGB( camera, _wb_multipliers, TI );
750747
auto XYZ = calculate_XYZ( observer, illuminant, TI );
751748

752-
return curveFit( RGB, XYZ, beta_params_start, verbosity, _IDT_matrix );
749+
return curveFit( RGB, XYZ, beta_params_start, verbosity, _idt_matrix );
753750
}
754751

755752
// =====================================================================
@@ -763,12 +760,12 @@ bool SpectralSolver::calculate_IDT_matrix()
763760

764761
const vector<vector<double>> &SpectralSolver::get_IDT_matrix() const
765762
{
766-
return _IDT_matrix;
763+
return _idt_matrix;
767764
}
768765

769766
const vector<double> &SpectralSolver::get_WB_multipliers() const
770767
{
771-
return _WB_multipliers;
768+
return _wb_multipliers;
772769
}
773770

774771
MetadataSolver::MetadataSolver( const core::Metadata &metadata )
@@ -953,13 +950,13 @@ vector<double> find_XYZ_to_camera_matrix(
953950

954951
if ( metadata.calibration[0].illuminant == 0 )
955952
{
956-
fprintf( stderr, " No calibration illuminants were found. \n " );
953+
std::cerr << "No calibration illuminants were found." << std::endl;
957954
return metadata.calibration[0].XYZ_to_RGB_matrix;
958955
}
959956

960957
if ( neutral_RGB.size() == 0 )
961958
{
962-
fprintf( stderr, " no neutral RGB values were found. \n " );
959+
std::cerr << "No neutral RGB values were found." << std::endl;
963960
return metadata.calibration[0].XYZ_to_RGB_matrix;
964961
}
965962

@@ -980,9 +977,9 @@ vector<double> find_XYZ_to_camera_matrix(
980977
metadata.calibration[1].XYZ_to_RGB_matrix;
981978

982979
double low_mired =
983-
std::max( min_mired, std::min( max_mired, std::min( mir1, mir2 ) ) );
980+
std::clamp( std::min( mir1, mir2 ), min_mired, max_mired );
984981
double high_mired =
985-
std::max( min_mired, std::min( max_mired, std::max( mir1, mir2 ) ) );
982+
std::clamp( std::max( mir1, mir2 ), min_mired, max_mired );
986983
double mirStep = std::max( 5.0, ( high_mired - low_mired ) / 50.0 );
987984

988985
double current_mired = 0.0, last_mired = 0.0, estimated_mired = 0.0,
@@ -1232,19 +1229,19 @@ vector<vector<double>> MetadataSolver::calculate_IDT_matrix()
12321229
template <typename T>
12331230
bool IDTOptimizationCost::operator()( const T *beta_params, T *residuals ) const
12341231
{
1235-
vector<vector<T>> RGB_copy( _RGB.size(), vector<T>( 3 ) );
1236-
for ( size_t i = 0; i < _RGB.size(); i++ )
1232+
vector<vector<T>> RGB_copy( _in_RGB.size(), vector<T>( 3 ) );
1233+
for ( size_t i = 0; i < _in_RGB.size(); i++ )
12371234
for ( size_t j = 0; j < 3; j++ )
1238-
RGB_copy[i][j] = T( _RGB[i][j] );
1235+
RGB_copy[i][j] = T( _in_RGB[i][j] );
12391236

12401237
vector<vector<T>> out_calc_LAB =
12411238
XYZ_to_LAB( getCalcXYZt( RGB_copy, beta_params ) );
1242-
for ( size_t i = 0; i < _RGB.size(); i++ )
1239+
for ( size_t i = 0; i < _in_RGB.size(); i++ )
12431240
for ( size_t j = 0; j < 3; j++ )
1244-
residuals[i * 3 + j] = _outLAB[i][j] - out_calc_LAB[i][j];
1241+
residuals[i * 3 + j] = _out_LAB[i][j] - out_calc_LAB[i][j];
12451242

12461243
return true;
12471244
}
12481245

12491246
} // namespace core
1250-
} // namespace rta
1247+
} // namespace rta

0 commit comments

Comments
 (0)