Skip to content

Commit 7e7f39e

Browse files
committed
add another configure method; more error checking
Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz>
1 parent f51dbff commit 7e7f39e

File tree

2 files changed

+62
-24
lines changed

2 files changed

+62
-24
lines changed

include/rawtoaces/rawtoaces_util.h

+18
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class ImageConverter
106106

107107
/// Configures the converter using the requested white balance and colour
108108
/// matrix method, and the metadata of the file provided in `input_file`.
109+
/// This method loads the metadata from the given image file and
110+
/// initialises the options to give the OIIO raw image reader to
111+
/// decode the pixels.
109112
/// @param input_filename
110113
/// A file name of the raw image file to read the metadata from.
111114
/// @param options
@@ -117,6 +120,21 @@ class ImageConverter
117120
bool configure(
118121
const std::string &input_filename, OIIO::ParamValueList &options );
119122

123+
/// Configures the converter using the requested white balance and colour
124+
/// matrix method, and the metadata of the given OIIO::ImageSpec object.
125+
/// Use this method if you already have an image read from file to save
126+
/// on disk operations.
127+
/// @param imageSpec
128+
/// An image spec obtained from OIIO::ImageInput or OIIO::ImageBuf.
129+
/// @param options
130+
/// Conversion hints to be passed to OIIO when reading an image file.
131+
/// The list can be pre- or post- updated with other hints, unrelated to
132+
/// the rawtoaces conversion.
133+
/// @result
134+
/// `true` if configured successfully.
135+
bool configure(
136+
const OIIO::ImageSpec &imageSpec, OIIO::ParamValueList &options );
137+
120138
/// Apply the colour space conversion matrix (or matrices) to convert the
121139
/// image buffer from the raw camera colour space to ACES.
122140
/// @param dst

src/rawtoaces_util2/rawtoaces_util.cpp

+44-24
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,11 @@ bool ImageConverter::parse_params( const OIIO::ArgParse &argParse )
430430

431431
headroom = argParse["headroom"].get<float>();
432432

433-
std::string illum = argParse["illuminant"].get();
433+
illuminant = argParse["illuminant"].get();
434434

435435
if ( wbMethod == WBMethod::Illuminant )
436436
{
437-
if ( illum.size() == 0 )
437+
if ( illuminant.empty() )
438438
{
439439
std::cerr << "Warning: the white balancing method was set to "
440440
<< "\"illuminant\", but no \"--illuminant\" parameter "
@@ -444,7 +444,7 @@ bool ImageConverter::parse_params( const OIIO::ArgParse &argParse )
444444
}
445445
else
446446
{
447-
if ( illum.size() != 0 )
447+
if ( !illuminant.empty() )
448448
{
449449
std::cerr << "Warning: the \"--illuminant\" parameter provided "
450450
<< "but the white balancing mode different from "
@@ -529,13 +529,8 @@ bool ImageConverter::parse_params( const OIIO::ArgParse &argParse )
529529
}
530530

531531
bool ImageConverter::configure(
532-
const std::string &input_filename, OIIO::ParamValueList &options )
532+
const OIIO::ImageSpec &imageSpec, OIIO::ParamValueList &options )
533533
{
534-
_read_raw = options.get_string( "raw:Demosaic" ) == "none";
535-
536-
OIIO::ImageSpec imageSpec;
537-
538-
options["raw:ColorSpace"] = "XYZ";
539534
options["raw:use_camera_wb"] = 0;
540535
options["raw:use_auto_wb"] = 0;
541536

@@ -553,16 +548,6 @@ bool ImageConverter::configure(
553548
"raw:cropbox", OIIO::TypeDesc( OIIO::TypeDesc::INT, 4 ), cropbox );
554549
}
555550

556-
OIIO::ImageSpec temp_spec;
557-
temp_spec.extra_attribs = options;
558-
559-
auto imageInput = OIIO::ImageInput::create( "raw", false, &temp_spec );
560-
bool result = imageInput->open( input_filename, imageSpec, temp_spec );
561-
if ( !result )
562-
{
563-
return false;
564-
}
565-
566551
_is_DNG = imageSpec.extra_attribs.find( "raw:dng:version" )->get_int() > 0;
567552

568553
switch ( wbMethod )
@@ -635,7 +620,11 @@ bool ImageConverter::configure(
635620
}
636621
break;
637622

638-
default: break;
623+
default:
624+
std::cerr
625+
<< "ERROR: This white balancing method has not been configured "
626+
<< "properly." << std::endl;
627+
exit( 1 );
639628
}
640629

641630
switch ( matrixMethod )
@@ -645,12 +634,16 @@ bool ImageConverter::configure(
645634
options["raw:use_camera_matrix"] = 0;
646635
break;
647636
case MatrixMethod::Metadata:
637+
options["raw:ColorSpace"] = "XYZ";
648638
options["raw:use_camera_matrix"] = _is_DNG ? 1 : 3;
649639
break;
650-
case MatrixMethod::Adobe: options["raw:use_camera_matrix"] = 1; break;
640+
case MatrixMethod::Adobe:
641+
options["raw:ColorSpace"] = "XYZ";
642+
options["raw:use_camera_matrix"] = 1;
643+
break;
651644
case MatrixMethod::Custom:
652-
options["raw:use_camera_matrix"] = 0;
653645
options["raw:ColorSpace"] = "raw";
646+
options["raw:use_camera_matrix"] = 0;
654647

655648
_IDT_matrix.resize( 3 );
656649
for ( int i = 0; i < 3; i++ )
@@ -661,9 +654,12 @@ bool ImageConverter::configure(
661654
_IDT_matrix[i][j] = customMatrix[i][j];
662655
}
663656
}
664-
665657
break;
666-
default: break;
658+
default:
659+
std::cerr
660+
<< "ERROR: This matrix method has not been configured properly."
661+
<< std::endl;
662+
exit( 1 );
667663
}
668664

669665
bool spectral_white_balance = wbMethod == WBMethod::Illuminant;
@@ -711,6 +707,30 @@ bool ImageConverter::configure(
711707
return true;
712708
}
713709

710+
bool ImageConverter::configure(
711+
const std::string &input_filename, OIIO::ParamValueList &options )
712+
{
713+
_read_raw = options.get_string( "raw:Demosaic" ) == "none";
714+
715+
OIIO::ImageSpec imageSpec;
716+
717+
options["raw:ColorSpace"] = "XYZ";
718+
options["raw:use_camera_wb"] = 0;
719+
options["raw:use_auto_wb"] = 0;
720+
721+
OIIO::ImageSpec temp_spec;
722+
temp_spec.extra_attribs = options;
723+
724+
auto imageInput = OIIO::ImageInput::create( "raw", false, &temp_spec );
725+
bool result = imageInput->open( input_filename, imageSpec, temp_spec );
726+
if ( !result )
727+
{
728+
return false;
729+
}
730+
731+
return configure( imageSpec, options );
732+
}
733+
714734
bool ImageConverter::applyMatrix(
715735
const std::vector<std::vector<double>> &matrix,
716736
OIIO::ImageBuf &dst,

0 commit comments

Comments
 (0)