diff --git a/src/doc/builtinplugins.rst b/src/doc/builtinplugins.rst index 1b469fc88b..c113366dfb 100644 --- a/src/doc/builtinplugins.rst +++ b/src/doc/builtinplugins.rst @@ -1950,7 +1950,23 @@ options are supported: - If nonzero, will use libraw's exposure correction. (Default: 0) * - ``raw:use_camera_wb`` - int - - If 1, use libraw's camera white balance adjustment. (Default: 1) + - If 1, use libraw's camera white balance adjustment. Takes precedence + over ``raw:use_auto_wb``, ``raw:greybox``, ``raw:user_mul``. + (Default: 1) + * - ``raw:use_auto_wb`` + - int + - If 1, white balance automatically by averaging over the entire image. + Only applies if ``raw:use_camera_wb`` is not equal to 0. Takes + precedence over ``raw:greybox``, ``raw:user_mul``. + (Default: 0) + * - ``raw:greybox`` + - int[4] + - White balance by averaging over the given box. The four values are the + X and Y coordinate of the top-left corner, the width and the height. + Only applies if the size is non-zero, and ``raw:use_camera_wb`` is not + equal to 0, ``raw:use_auto_wb`` is not equal to 0. Takes + precedence over ``raw:user_mul``. + (Default: 0, 0, 0, 0; meaning no correction.) * - ``raw:use_camera_matrix`` - int - Whether to use the embedded color profile, if it's present: 0 = @@ -1958,6 +1974,10 @@ options are supported: * - ``raw:adjust_maximum_thr`` - float - If nonzero, auto-adjusting maximum value. (Default:0.0) + * - ``raw:user_black`` + - int + - If not negative, sets the camera minimum value that will be normalized to + appear 0. (Default: -1) * - ``raw:user_sat`` - int - If nonzero, sets the camera maximum value that will be normalized to @@ -1974,7 +1994,8 @@ options are supported: * - ``raw:user_mul`` - float[4] - Sets user white balance coefficients. Only applies if ``raw:use_camera_wb`` - is not equal to 0. + is not equal to 0, ``raw:use_auto_wb`` is not equal to 0, and the + ``raw:greybox`` box is zero size. * - ``raw:ColorSpace`` - string - Which color primaries to use for the returned pixel values: ``raw``, diff --git a/src/raw.imageio/rawinput.cpp b/src/raw.imageio/rawinput.cpp index de11ad132f..3c16718696 100644 --- a/src/raw.imageio/rawinput.cpp +++ b/src/raw.imageio/rawinput.cpp @@ -463,6 +463,9 @@ RawInput::open_raw(bool unpack, const std::string& name, // Turn off maximum threshold value (unless set to non-zero) m_processor->imgdata.params.adjust_maximum_thr = config.get_float_attribute("raw:adjust_maximum_thr", 0.0f); + // Set camera minimum value if "raw:user_black" is not negative + m_processor->imgdata.params.user_black + = config.get_int_attribute("raw:user_black", -1); // Set camera maximum value if "raw:user_sat" is not 0 m_processor->imgdata.params.user_sat = config.get_int_attribute("raw:user_sat", 0); @@ -506,21 +509,34 @@ RawInput::open_raw(bool unpack, const std::string& name, params.user_mul[2] = norm[2]; params.user_mul[3] = norm[3]; } else { - // Set user white balance coefficients. - // Only has effect if "raw:use_camera_wb" is equal to 0, - // i.e. we are not using the camera white balance - auto p = config.find_attribute("raw:user_mul"); - if (p && p->type() == TypeDesc(TypeDesc::FLOAT, 4)) { - m_processor->imgdata.params.user_mul[0] = p->get(0); - m_processor->imgdata.params.user_mul[1] = p->get(1); - m_processor->imgdata.params.user_mul[2] = p->get(2); - m_processor->imgdata.params.user_mul[3] = p->get(3); - } - if (p && p->type() == TypeDesc(TypeDesc::DOUBLE, 4)) { - m_processor->imgdata.params.user_mul[0] = p->get(0); - m_processor->imgdata.params.user_mul[1] = p->get(1); - m_processor->imgdata.params.user_mul[2] = p->get(2); - m_processor->imgdata.params.user_mul[3] = p->get(3); + if (config.get_int_attribute("raw:use_auto_wb", 0) == 1) { + m_processor->imgdata.params.use_auto_wb = 1; + } else { + auto p = config.find_attribute("raw:greybox"); + if (p && p->type() == TypeDesc(TypeDesc::INT, 4)) { + // p->get() didn't work for me here + m_processor->imgdata.params.greybox[0] = p->get_int_indexed(0); + m_processor->imgdata.params.greybox[1] = p->get_int_indexed(1); + m_processor->imgdata.params.greybox[2] = p->get_int_indexed(2); + m_processor->imgdata.params.greybox[3] = p->get_int_indexed(3); + } else { + // Set user white balance coefficients. + // Only has effect if "raw:use_camera_wb" is equal to 0, + // i.e. we are not using the camera white balance + auto p = config.find_attribute("raw:user_mul"); + if (p && p->type() == TypeDesc(TypeDesc::FLOAT, 4)) { + m_processor->imgdata.params.user_mul[0] = p->get(0); + m_processor->imgdata.params.user_mul[1] = p->get(1); + m_processor->imgdata.params.user_mul[2] = p->get(2); + m_processor->imgdata.params.user_mul[3] = p->get(3); + } + if (p && p->type() == TypeDesc(TypeDesc::DOUBLE, 4)) { + m_processor->imgdata.params.user_mul[0] = p->get(0); + m_processor->imgdata.params.user_mul[1] = p->get(1); + m_processor->imgdata.params.user_mul[2] = p->get(2); + m_processor->imgdata.params.user_mul[3] = p->get(3); + } + } } } @@ -1401,6 +1417,34 @@ RawInput::get_colorinfo() cspan(&(m_processor->imgdata.color.cam_xyz[0][0]), &(m_processor->imgdata.color.cam_xyz[3][3])), false, 0.f); + + if (m_processor->imgdata.idata.dng_version) { + add("raw", "dng:version", m_processor->imgdata.idata.dng_version); + + auto const& c = m_processor->imgdata.rawdata.color; + +#if LIBRAW_VERSION >= LIBRAW_MAKE_VERSION(0, 20, 0) + add("raw", "dng:baseline_exposure", c.dng_levels.baseline_exposure); +#else + add("raw", "dng:baseline_exposure", c.baseline_exposure); +#endif + + for (int i = 0; i < 2; i++) { + std::string index = std::to_string(i + 1); + add("raw", "dng:calibration_illuminant" + index, + c.dng_color[i].illuminant); + + add("raw", "dng:color_matrix" + index, + cspan(&(c.dng_color[i].colormatrix[0][0]), + &(c.dng_color[i].colormatrix[3][3])), + false, 0.f); + + add("raw", "dng:camera_calibration" + index, + cspan(&(c.dng_color[i].calibration[0][0]), + &(c.dng_color[i].calibration[3][4])), + false, 0.f); + } + } }