Skip to content

Commit 7b3a170

Browse files
antond-wetasoswow
andauthored
simplify core API (#178)
* simplify core API Signed-off-by: Anton Dukhovnikov <[email protected]> * address review issues Signed-off-by: Anton Dukhovnikov <[email protected]> * address review issues Signed-off-by: Anton Dukhovnikov <[email protected]> * Update src/rawtoaces_core/rawtoaces_core.cpp Co-authored-by: Aleksandr Motsjonov <[email protected]> Signed-off-by: Anton Dukhovnikov <[email protected]> --------- Signed-off-by: Anton Dukhovnikov <[email protected]> Co-authored-by: Aleksandr Motsjonov <[email protected]>
1 parent 927bf4c commit 7b3a170

File tree

9 files changed

+436
-612
lines changed

9 files changed

+436
-612
lines changed

include/rawtoaces/image_converter.h

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ namespace util
1515
/// directory, create an entry in `batches` and fill it with the file names
1616
/// from that directory. If the `path` is a file, add its name to the first
1717
/// entry in `batches`.
18-
/// - parameter path: path to a file or directory to process.
19-
/// - parameter batches: the collection of batches to fill in.
20-
/// - returns `false` if the file or directory requested in `path` does not
18+
/// @param path path to a file or directory to process.
19+
/// @param batches the collection of batches to fill in.
20+
/// @result `false` if the file or directory requested in `path` does not
2121
/// exist.
2222
bool collect_image_files(
2323
const std::string &path, std::vector<std::vector<std::string>> &batches );
@@ -128,8 +128,7 @@ class ImageConverter
128128
/// The parser object can be amended by the calling code afterwards if
129129
/// needed. This method is optional, all of the settings above can be
130130
/// modified directly.
131-
/// - parameter arg_parser:
132-
/// The command line parser object to be updated.
131+
/// @param arg_parser The command line parser object to be updated.
133132
void init_parser( OIIO::ArgParse &arg_parser );
134133

135134
/// Initialise the converter settings from the command line parser object.
@@ -138,10 +137,8 @@ class ImageConverter
138137
/// `OIIO::ArgParse::parse_args()`.
139138
/// This method is optional, all of the settings above can be modified
140139
/// directly.
141-
/// - parameter arg_parser:
142-
/// the command line parser object
143-
/// - returns
144-
/// `true` if parsed successfully
140+
/// @param arg_parser the command line parser object
141+
/// @result `true` if parsed successfully
145142
bool parse_parameters( const OIIO::ArgParse &arg_parser );
146143

147144
/// Collects all illuminants supported by this version.
@@ -156,13 +153,13 @@ class ImageConverter
156153
/// This method loads the metadata from the given image file and
157154
/// initialises the options to give the OIIO raw image reader to
158155
/// decode the pixels.
159-
/// - parameter input_filename:
156+
/// @param input_filename
160157
/// A file name of the raw image file to read the metadata from.
161-
/// - parameter options:
158+
/// @param options
162159
/// Conversion hints to be passed to OIIO when reading an image file.
163160
/// The list can be pre- or post- updated with other hints, unrelated to
164161
/// the rawtoaces conversion.
165-
/// - returns
162+
/// @result
166163
/// `true` if configured successfully.
167164
bool configure(
168165
const std::string &input_filename, OIIO::ParamValueList &options );
@@ -171,13 +168,13 @@ class ImageConverter
171168
/// matrix method, and the metadata of the given OIIO::ImageSpec object.
172169
/// Use this method if you already have an image read from file to save
173170
/// on disk operations.
174-
/// - parameter imageSpec:
171+
/// @param imageSpec
175172
/// An image spec obtained from OIIO::ImageInput or OIIO::ImageBuf.
176-
/// - parameter hints:
173+
/// @param hints
177174
/// Conversion hints to be passed to OIIO when reading an image file.
178175
/// The list can be pre- or post- updated with other hints, unrelated to
179176
/// the rawtoaces conversion.
180-
/// - returns
177+
/// @result
181178
/// `true` if configured successfully.
182179
bool
183180
configure( const OIIO::ImageSpec &imageSpec, OIIO::ParamValueList &hints );
@@ -192,85 +189,85 @@ class ImageConverter
192189

193190
/// Apply the colour space conversion matrix (or matrices) to convert the
194191
/// image buffer from the raw camera colour space to ACES.
195-
/// - parameter dst:
192+
/// @param dst
196193
/// Destination image buffer.
197-
/// - parameter src:
194+
/// @param src
198195
/// Source image buffer, can be the same as `dst` for in-place
199196
/// conversion.
200-
/// - returns
197+
/// @result
201198
/// `true` if applied successfully.
202199
bool apply_matrix(
203200
OIIO::ImageBuf &dst, const OIIO::ImageBuf &src, OIIO::ROI roi = {} );
204201

205202
/// Apply the headroom scale to image buffer.
206-
/// - parameter dst:
203+
/// @param dst
207204
/// Destination image buffer.
208-
/// - parameter src:
205+
/// @param src
209206
/// Source image buffer, can be the same as `dst` for in-place
210207
/// conversion.
211-
/// - returns
208+
/// @result
212209
/// `true` if applied successfully.
213210
bool apply_scale(
214211
OIIO::ImageBuf &dst, const OIIO::ImageBuf &src, OIIO::ROI roi = {} );
215212

216213
/// Apply the cropping mode as specified in crop_mode.
217-
/// - parameter dst:
214+
/// @param dst
218215
/// Destination image buffer.
219-
/// - parameter src:
216+
/// @param src
220217
/// Source image buffer, can be the same as `dst` for in-place
221218
/// conversion.
222-
/// - returns
219+
/// @result
223220
/// `true` if applied successfully.
224221
bool apply_crop(
225222
OIIO::ImageBuf &dst, const OIIO::ImageBuf &src, OIIO::ROI roi = {} );
226223

227224
/// Make output file path and check if it is writable.
228-
/// - parameter path:
225+
/// @param path
229226
/// A reference to a variable containing the input file path. The output file path gets generated
230227
/// in-place.
231-
/// - parameter suffix:
228+
/// @param suffix
232229
/// A suffix to add to the file name.
233-
/// - returns
230+
/// @result
234231
/// `true` if the file can be written, e.g. the output directory exists, or creating directories
235232
/// is allowed; the file does not exist or overwriting is allowed.
236233
bool
237234
make_output_path( std::string &path, const std::string &suffix = "_aces" );
238235

239236
/// Saves the image into ACES Container.
240-
/// - parameter output_filename:
237+
/// @param output_filename
241238
/// Full path to the file to be saved.
242-
/// - parameter buf:
239+
/// @param buf
243240
/// Image buffer to be saved.
244-
/// - returns
241+
/// @result
245242
/// `true` if saved successfully.
246243
bool
247244
save_image( const std::string &output_filename, const OIIO::ImageBuf &buf );
248245

249246
/// A convenience single-call method to process an image. This is equivalent to calling the following
250247
/// methods sequentially: `make_output_path`->`configure`->`apply_matrix`->
251248
/// `apply_scale`->`apply_crop`->`save`.
252-
/// - parameter input_filename:
249+
/// @param input_filename
253250
/// Full path to the file to be converted.
254-
/// - returns
251+
/// @result
255252
/// `true` if processed successfully.
256253
bool process_image( const std::string &input_filename );
257254

258255
/// Get the solved white balance multipliers of the currently processed
259256
/// image. The multipliers become available after calling either of the
260257
/// two `configure` methods.
261-
/// - returns a reference to the multipliers vector.
258+
/// @result a reference to the multipliers vector.
262259
const std::vector<double> &get_WB_multipliers();
263260

264261
/// Get the solved input transform matrix of the currently processed image.
265262
/// The multipliers become available after calling either of the two
266263
/// `configure` methods.
267-
/// - returns a reference to the matrix.
264+
/// @result a reference to the matrix.
268265
const std::vector<std::vector<double>> &get_IDT_matrix();
269266

270267
/// Get the solved chromatic adaptation transform matrix of the currently
271268
/// processed image. The multipliers become available after calling either
272269
/// of the two `configure` methods.
273-
/// - returns a reference to the matrix.
270+
/// @result a reference to the matrix.
274271
const std::vector<std::vector<double>> &get_CAT_matrix();
275272

276273
private:

include/rawtoaces/rawtoaces_core.h

Lines changed: 74 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -28,95 +28,104 @@ static const std::vector<std::vector<double> > CAT_D65_to_ACES = {
2828
// clang-format on
2929

3030
/// Calculate spectral power distribution of a daylight illuminant of given CCT
31-
/// - parameter cct: correlated colour temperature of the requested illuminant.
32-
/// - parameter spectrum: a reference to a `Spectrum` object to full with the
31+
/// @param cct correlated colour temperature of the requested illuminant.
32+
/// @param spectrum a reference to a `Spectrum` object to full with the
3333
/// calculated values.
3434
void calculate_daylight_SPD( const int &cct, Spectrum &spectrum );
3535

3636
/// Calculate spectral power distribution of a blackbody illuminant of given CCT
37-
/// - parameter cct: correlated colour temperature of the requested illuminant.
38-
/// - parameter spectrum: a reference to a `Spectrum` object to full with the
37+
/// @param cct correlated colour temperature of the requested illuminant.
38+
/// @param spectrum a reference to a `Spectrum` object to full with the
3939
/// calculated values.
4040
void calculate_blackbody_SPD( const int &cct, Spectrum &spectrum );
4141

4242
/// Solve an input transform using spectral sensitivity curves of a camera.
4343
class SpectralSolver
4444
{
4545
public:
46-
SpectralSolver();
46+
/// The camera spectral data. Can be either assigned directly, loaded
47+
/// in-place place via `solver.camera.load()`, or found via
48+
/// `solver.find_camera()`.
49+
SpectralData camera;
50+
51+
/// The illuminant spectral data. Can be either assigned directly, loaded
52+
/// in-place place via `solver.illuminant.load()`, or found via
53+
/// `solver.find_illuminant()`.
54+
SpectralData illuminant;
55+
56+
/// The observer spectral data. Can be either assigned directly, or loaded
57+
/// in-place place via `solver.observer.load()`.
58+
SpectralData observer;
59+
60+
/// The training set spectral data. Can be either assigned directly, or loaded
61+
/// in-place place via `solver.training_data.load()`.
62+
SpectralData training_data;
63+
64+
/// The constructor. Takes the database search path as an optional
65+
/// parameter.
66+
/// @param search_directories optional database search path.
67+
SpectralSolver( const std::vector<std::string> &search_directories = {} );
68+
69+
/// A helper method collecting of spectral data files of a given type from
70+
/// the database.
71+
/// @param type data type of the files to search for.
72+
/// @result a collection of files found in the database.
73+
std::vector<std::string>
74+
collect_data_files( const std::string &type ) const;
75+
76+
/// A helper method loading the spectral data for a file at the given path.
77+
/// @param file_path the path to the file to load. If the path is relative,
78+
/// all locations in the search path will be searched in.
79+
/// @param out_data the `SpectralData` object to be filled with the loaded
80+
/// data.
81+
/// @result `true` is loaded successfully.
82+
bool
83+
load_spectral_data( const std::string &file_path, SpectralData &out_data );
4784

4885
/// Load spectral sensitivity data for a camera.
49-
/// - parameter path: a path to the data file
50-
/// - parameter make: the camera make to verify the loaded data against.
51-
/// - parameter model: the camera model to verify the loaded data against.
52-
/// - returns `true` if loaded successfully.
53-
bool load_camera(
54-
const std::string &path,
55-
const std::string &make,
56-
const std::string &model );
57-
58-
/// Load spectral power distribution data for an illuminant.
59-
/// If an illuminant type specified, try to find the matching data,
60-
/// otherwise load all known illuminants.
61-
/// - parameter paths: a set of data file paths to the data file
62-
/// - parameter type: illuminant type to load.
63-
/// - returns `true` if loaded successfully.
64-
bool load_illuminant(
65-
const std::vector<std::string> &paths, const std::string &type = "" );
66-
67-
/// Load spectral reflectivity data for a training set (a colour chart).
68-
/// - parameter path: a path to the data file
69-
/// - returns `true` if loaded successfully.
70-
bool load_training_data( const std::string &path );
71-
72-
/// Load spectral sensitivity data for an observer
73-
/// (colour matching functions).
74-
/// - parameter path: a path to the data file
75-
/// - returns `true` if loaded successfully.
76-
bool load_observer( const std::string &path );
86+
/// @param make the camera make to search for.
87+
/// @param model the camera model to search for.
88+
/// @result `true` if loaded successfully.
89+
bool find_camera( const std::string &make, const std::string &model );
90+
91+
/// Find spectral power distribution data of an illuminant of the given
92+
/// type.
93+
/// @param type illuminant type. Can be one of the built-in types,
94+
/// e.g. `d55`, `3200k`, or a custom illuminant stored in the database.
95+
/// @result `true` if loaded successfully.
96+
bool find_illuminant( const std::string &type );
7797

7898
/// Find the illuminant best matching the given white-balancing multipliers.
79-
/// See `get_best_illuminant()` to access the result.
80-
/// - parameter wb_multipliers: white-balancing multipliers to match.
81-
/// - parameter highlight: the highlight recovery mode, used for
82-
/// normalisation.
83-
void find_best_illuminant(
84-
const std::vector<double> &wb_multipliers, int highlight );
85-
86-
/// Select an illuminant of a given type.
87-
/// See `get_best_illuminant()` to access the result.
88-
/// - parameter type: illuminant type to select.
89-
/// - parameter highlight: the highlight recovery mode, used for
90-
/// normalisation.
91-
void select_illuminant( const std::string &type, int highlight );
92-
93-
/// Calculate an input transform matrix.
94-
/// See `get_IDT_matrix()` to access the result.
95-
/// - returns `true` if calculated successfully.
99+
/// @param wb_multipliers white-balancing multipliers to match.
100+
/// @result `true` if loaded successfully.
101+
bool find_illuminant( const std::vector<double> &wb_multipliers );
102+
103+
/// Calculate the white-balance multipliers for the given configuration.
104+
/// The `camera`, and `illuminant` data have to be configured prior to this
105+
/// call. See `get_WB_multipliers()` to access the result.
106+
/// @result `true` if calculated successfully.
107+
bool calculate_WB();
108+
109+
/// Calculate an input transform matrix. The `camera`, `illuminant`,
110+
/// `observer` and `training_data` have to be configured prior to this
111+
/// call. See `get_IDT_matrix()` to access the result.
112+
/// @result `true` if calculated successfully.
96113
bool calculate_IDT_matrix();
97114

98-
/// Get the illuminant configured using `find_best_illuminant()` or
99-
/// `select_illuminant()`.
100-
/// - returns a reference to the illuminant.
101-
const SpectralData &get_best_illuminant() const;
102-
103115
/// Get the matrix calculated using `calculate_IDT_matrix()`.
104-
/// - returns a reference to the matrix.
116+
/// @result a reference to the matrix.
105117
const std::vector<std::vector<double>> &get_IDT_matrix() const;
106118

107119
/// Get the white-balance multipliers calculated using
108120
/// `find_best_illuminant()` or `select_illuminant()`.
109-
/// - returns a reference to the multipliers.
121+
/// @result a reference to the multipliers.
110122
const std::vector<double> &get_WB_multipliers() const;
111123

112124
int verbosity = 0;
113125

114126
private:
115-
SpectralData _camera;
116-
SpectralData _best_illuminant;
117-
SpectralData _observer;
118-
SpectralData _training_data;
119-
std::vector<SpectralData> _illuminants;
127+
std::vector<std::string> _search_directories;
128+
std::vector<SpectralData> _all_illuminants;
120129

121130
std::vector<double> _WB_multipliers;
122131
std::vector<std::vector<double>> _IDT_matrix;
@@ -142,17 +151,17 @@ class MetadataSolver
142151
{
143152
public:
144153
/// Initialise the solver using DNG metadata.
145-
/// - parameter metadata: DNG metadata
154+
/// @param metadata DNG metadata
146155
MetadataSolver( const core::Metadata &metadata );
147156

148157
/// Calculate an input transform matrix.
149-
/// - returns: calculated matrix
158+
/// @result calculated matrix
150159
std::vector<std::vector<double>> calculate_IDT_matrix();
151160

152161
/// Calculate a chromatic adaptation transform matrix. Strictly speaking,
153162
/// this matrix is not required for image processing, as it is embedded in
154163
/// the IDT, see `calculate_IDT_matrix`.
155-
/// - returns: calculated matrix
164+
/// @result calculated matrix
156165
std::vector<std::vector<double>> calculate_CAT_matrix();
157166

158167
private:

0 commit comments

Comments
 (0)