Skip to content

Commit 95d6f71

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

File tree

14 files changed

+204
-104
lines changed

14 files changed

+204
-104
lines changed

.github/workflows/analysis.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
runs-on: ubuntu-latest
45+
strategy:
46+
fail-fast: false
47+
env:
48+
CC: clang
49+
CXX: clang++
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- name: Dependencies
54+
shell: bash
55+
run: |
56+
build_scripts/install_deps_linux.bash
57+
58+
- name: Configure CMake
59+
run: >
60+
cmake
61+
-B build
62+
-S .
63+
-D CMAKE_INSTALL_PREFIX=${{ github.workspace }}/install
64+
-D CMAKE_CXX_STANDARD=17
65+
-D CMAKE_BUILD_TYPE=Debug
66+
-D ENABLE_COVERAGE=ON
67+
-D CMAKE_CXX_FLAGS="-g -O0"
68+
-D CMAKE_EXPORT_COMPILE_COMMANDS=ON
69+
70+
- uses: whisperity/codechecker-analysis-action@v1
71+
id: codechecker
72+
with:
73+
logfile: ${{ github.workspace }}/build/compile_commands.json
74+
config: '/home/runner/work/rawtoaces/rawtoaces/tests/static_analysis/codechecker.json'
75+
76+
- uses: actions/upload-artifact@v4
77+
if: ${{ steps.codechecker.outputs.warnings == 'true' }}
78+
with:
79+
name: "CodeChecker Bug Reports"
80+
path: ${{ steps.codechecker.outputs.result-html-dir }}
81+
82+
- name: "Break build if CodeChecker reported any findings"
83+
if: ${{ steps.codechecker.outputs.warnings == 'true' }}
84+
run: exit 1

include/rawtoaces/image_converter.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#pragma once
55

6-
#include <OpenImageIO/imagebuf.h>
7-
#include <OpenImageIO/argparse.h>
6+
#include <OpenImageIO/imagebuf.h> // NOLINT
7+
#include <OpenImageIO/argparse.h> // NOLINT
88

99
namespace rta
1010
{
@@ -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: 39 additions & 42 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,9 @@ 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_data = main_spectral_set.emplace_back(
147+
SpectralData::SpectralChannel( "power", Spectrum( 0 ) ) );
148+
auto &power_spectrum = power_data.second;
154149

155150
illuminant.illuminant = type;
156151
if ( is_daylight )
@@ -168,15 +163,15 @@ SpectralSolver::SpectralSolver(
168163
: _search_directories( search_directories )
169164
{
170165
verbosity = 0;
171-
_IDT_matrix.resize( 3 );
172-
_WB_multipliers.resize( 3 );
166+
_idt_matrix.resize( 3 );
167+
_wb_multipliers.resize( 3 );
173168
for ( int i = 0; i < 3; i++ )
174169
{
175-
_IDT_matrix[i].resize( 3 );
176-
_WB_multipliers[i] = 1.0;
170+
_idt_matrix[i].resize( 3 );
171+
_wb_multipliers[i] = 1.0;
177172
for ( size_t j = 0; j < 3; j++ )
178173
{
179-
_IDT_matrix[i][j] = neutral3[i][j];
174+
_idt_matrix[i][j] = neutral3[i][j];
180175
}
181176
}
182177
}
@@ -402,7 +397,7 @@ bool SpectralSolver::find_illuminant( const vector<double> &wb )
402397
{
403398
sse = sse_tmp;
404399
illuminant = current_illuminant;
405-
_WB_multipliers = wb_tmp;
400+
_wb_multipliers = wb_tmp;
406401
}
407402
}
408403

@@ -431,7 +426,7 @@ bool SpectralSolver::calculate_WB()
431426
return false;
432427
}
433428

434-
_WB_multipliers = _calculate_WB( camera, illuminant );
429+
_wb_multipliers = _calculate_WB( camera, illuminant );
435430
return true;
436431
}
437432

@@ -455,7 +450,7 @@ calculate_CM( const SpectralData &camera, const SpectralData &illuminant )
455450
double g = ( camera_g * illuminant_spectrum ).integrate();
456451
double b = ( camera_b * illuminant_spectrum ).integrate();
457452

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

460455
std::vector<double> result( 3 );
461456
result[0] = max / r;
@@ -613,14 +608,14 @@ struct IDTOptimizationCost
613608
IDTOptimizationCost(
614609
const std::vector<std::vector<double>> &RGB,
615610
const std::vector<std::vector<double>> &out_LAB )
616-
: _RGB( RGB ), _outLAB( out_LAB )
611+
: _in_RGB( RGB ), _out_LAB( out_LAB )
617612
{}
618613

619614
template <typename T>
620615
bool operator()( const T *beta_params, T *residuals ) const;
621616

622-
const std::vector<std::vector<double>> _RGB;
623-
const std::vector<std::vector<double>> _outLAB;
617+
const std::vector<std::vector<double>> _in_RGB;
618+
const std::vector<std::vector<double>> _out_LAB;
624619
};
625620

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

748743
auto TI = calculate_TI( illuminant, training_data );
749-
auto RGB = calculate_RGB( camera, _WB_multipliers, TI );
744+
auto RGB = calculate_RGB( camera, _wb_multipliers, TI );
750745
auto XYZ = calculate_XYZ( observer, illuminant, TI );
751746

752-
return curveFit( RGB, XYZ, beta_params_start, verbosity, _IDT_matrix );
747+
return curveFit( RGB, XYZ, beta_params_start, verbosity, _idt_matrix );
753748
}
754749

755750
// =====================================================================
@@ -763,12 +758,12 @@ bool SpectralSolver::calculate_IDT_matrix()
763758

764759
const vector<vector<double>> &SpectralSolver::get_IDT_matrix() const
765760
{
766-
return _IDT_matrix;
761+
return _idt_matrix;
767762
}
768763

769764
const vector<double> &SpectralSolver::get_WB_multipliers() const
770765
{
771-
return _WB_multipliers;
766+
return _wb_multipliers;
772767
}
773768

774769
MetadataSolver::MetadataSolver( const core::Metadata &metadata )
@@ -953,13 +948,13 @@ vector<double> find_XYZ_to_camera_matrix(
953948

954949
if ( metadata.calibration[0].illuminant == 0 )
955950
{
956-
fprintf( stderr, " No calibration illuminants were found. \n " );
951+
std::cerr << "No calibration illuminants were found." << std::endl;
957952
return metadata.calibration[0].XYZ_to_RGB_matrix;
958953
}
959954

960955
if ( neutral_RGB.size() == 0 )
961956
{
962-
fprintf( stderr, " no neutral RGB values were found. \n " );
957+
std::cerr << "No neutral RGB values were found." << std::endl;
963958
return metadata.calibration[0].XYZ_to_RGB_matrix;
964959
}
965960

@@ -980,16 +975,16 @@ vector<double> find_XYZ_to_camera_matrix(
980975
metadata.calibration[1].XYZ_to_RGB_matrix;
981976

982977
double low_mired =
983-
std::max( min_mired, std::min( max_mired, std::min( mir1, mir2 ) ) );
978+
std::clamp( std::min( mir1, mir2 ), min_mired, max_mired );
984979
double high_mired =
985-
std::max( min_mired, std::min( max_mired, std::max( mir1, mir2 ) ) );
986-
double mirStep = std::max( 5.0, ( high_mired - low_mired ) / 50.0 );
980+
std::clamp( std::max( mir1, mir2 ), min_mired, max_mired );
981+
double mired_step = std::max( 5.0, ( high_mired - low_mired ) / 50.0 );
987982

988-
double current_mired = 0.0, last_mired = 0.0, estimated_mired = 0.0,
989-
current_error = 0.0, last_error = 0.0, smallest_error = 0.0;
983+
double last_mired = 0.0, estimated_mired = 0.0, current_error = 0.0,
984+
last_error = 0.0, smallest_error = 0.0;
990985

991-
for ( current_mired = low_mired; current_mired < high_mired;
992-
current_mired += mirStep )
986+
double current_mired = low_mired;
987+
while( current_mired < high_mired )
993988
{
994989
current_error =
995990
current_mired -
@@ -1020,6 +1015,8 @@ vector<double> find_XYZ_to_camera_matrix(
10201015

10211016
last_error = current_error;
10221017
last_mired = current_mired;
1018+
1019+
current_mired += mired_step;
10231020
}
10241021

10251022
return XYZ_to_camera_weighted_matrix(
@@ -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)