@@ -17,8 +17,6 @@ namespace rta
1717class ImageConverter
1818{
1919public:
20- ImageConverter ();
21-
2220 // / The white balancing method to use for conversion can be specified
2321 // /
2422 enum class WBMethod
@@ -83,79 +81,92 @@ class ImageConverter
8381 int highlight_mode = 0 ;
8482 int flip = 0 ;
8583 int cropbox[4 ] = { 0 , 0 , 0 , 0 };
86-
87- int verbosity;
88-
89- // / Returns a class which will be used for parsing the command line
90- // / parameters. Can be used to add additional parameters before calling
91- // / `parse()`. The additional parameters will be parsed by ignored by this
92- // / class.
93- // / @result A non-const reference to an
94- // / initialised OIIO::ArgParse class.
95- OIIO::ArgParse &argParse ();
96-
97- // / Returns an image buffer, containing the image in the current state
98- // / after the previous step of processing. The image can be modified before
99- // / executing the next step if needed.
100- // / @result A non-const reference to the image buffer.
101- OIIO::ImageBuf &imageBuffer ();
102-
103- // / Parse the command line parameters. This method can be used to
104- // / configure the converter instead of modifying each conversion parameter
105- // / individually. Additional command line parameters can be added by
106- // / modifying the structure returned by `argParse()`.
107- // / @param argc
108- // / number of parameters
109- // / @param argv
110- // / list of parameters
84+ int verbosity = 0 ;
85+
86+ // / Initialise the parser object with all the command line parameters
87+ // / used by this tool. The method also sets the help and usage strings.
88+ // / The parser object can be amended by the calling code afterwards if
89+ // / needed. This method is optional, all of the settings above can be
90+ // / modified directly.
91+ // / @param argParse
92+ // / The command line parser object to be updated.
93+ void init_parser ( OIIO::ArgParse &argParse ) const ;
94+
95+ // / Initialise the converter settings from the command line parser object.
96+ // / Prior to calling this, first initialise the object via
97+ // / `ImageConverted::init_parser()`, and call
98+ // / `OIIO::ArgParse::parse_args()`.
99+ // / This method is optional, all of the settings above can be modified
100+ // / directly.
101+ // / @param argParse
102+ // / the command line parser object
111103 // / @result
112104 // / `true` if parsed successfully
113- bool parse ( int argc, const char *argv[] );
105+ bool parse_params ( const OIIO::ArgParse &argParse );
114106
115107 // / Configures the converter using the requested white balance and colour
116108 // / matrix method, and the metadata of the file provided in `input_file`.
117109 // / @param input_filename
118110 // / A file name of the raw image file to read the metadata from.
111+ // / @param options
112+ // / Conversion hints to be passed to OIIO when reading an image file.
113+ // / The list can be pre- or post- updated with other hints, unrelated to
114+ // / the rawtoaces conversion.
119115 // / @result
120116 // / `true` if configured successfully.
121- bool configure ( const std::string &input_filename );
122-
123- // / Loads an image to convert. Note that the image file name in
124- // / `input_filename` can be differnt from the one used in `configure()`.
125- // / This is useful for configuring the converter using one image, and
126- // / applying the conversion to a different one, or multiple images.
127- // / @param input_filename
128- // / A file name of the raw image file to read the pixels from.
117+ bool configure (
118+ const std::string &input_filename, OIIO::ParamValueList &options );
119+
120+ // / Apply the colour space conversion matrix (or matrices) to convert the
121+ // / image buffer from the raw camera colour space to ACES.
122+ // / @param dst
123+ // / Destination image buffer.
124+ // / @param src
125+ // / Source image buffer, can be the same as `dst` for in-place
126+ // / conversion.
129127 // / @result
130- // / `true` if loaded successfully.
131- bool load ( const std::string &input_filename );
132-
133- // / Converts the image from raw camera colour space to ACES.
128+ // / `true` if converted successfully.
129+ bool apply_matrix (
130+ OIIO::ImageBuf &dst, const OIIO::ImageBuf &src, OIIO::ROI roi = {} );
131+
132+ // / Apply the headroom scale to image buffer.
133+ // / @param dst
134+ // / Destination image buffer.
135+ // / @param src
136+ // / Source image buffer, can be the same as `dst` for in-place
137+ // / conversion.
134138 // / @result
135139 // / `true` if converted successfully.
136- bool process ();
140+ bool apply_scale (
141+ OIIO::ImageBuf &dst, const OIIO::ImageBuf &src, OIIO::ROI roi = {} );
137142
138143 // / Saves the image into ACES Container.
144+ // / @param output_filename
145+ // / Full path to the file to be saved.
146+ // / @param buf
147+ // / Image buffer to be saved.
139148 // / @result
140149 // / `true` if saved successfully.
141- bool save ( const std::string &output_filename );
150+ bool save ( const std::string &output_filename, const OIIO::ImageBuf &buf );
142151
143152private:
144- void initArgParse ();
145- void prepareIDT_DNG ();
146- void prepareIDT_nonDNG ();
147- void prepareIDT_spectral ( bool calc_white_balance, bool calc_matrix );
148- void applyMatrix ( const std::vector<std::vector<double >> &matrix );
149-
150- bool _is_DNG;
151- std::string _configFilename;
152- std::string _cameraMake;
153- std::string _cameraModel;
154-
155- OIIO::ArgParse _argParse;
156- OIIO::ImageSpec _inputHint;
157- OIIO::ImageSpec _inputFull;
158- OIIO::ImageBuf _imageBuffer;
153+ void prepareIDT_DNG ( const OIIO::ImageSpec &imageSpec );
154+ void prepareIDT_nonDNG ( const OIIO::ImageSpec &imageSpec );
155+ void prepareIDT_spectral (
156+ const OIIO::ImageSpec &imageSpec,
157+ bool calc_white_balance,
158+ bool calc_matrix );
159+ bool applyMatrix (
160+ const std::vector<std::vector<double >> &matrix,
161+ OIIO::ImageBuf &dst,
162+ const OIIO::ImageBuf &src,
163+ OIIO::ROI roi );
164+
165+ bool _is_DNG;
166+
167+ // / Make libraw read the raw photosites data without any processing.
168+ // / This is set if the requested demosaicing method is set `None`.
169+ bool _read_raw = false ;
159170
160171 std::vector<double > _WB_mults;
161172 std::vector<std::vector<double >> _IDT_matrix;
0 commit comments