From a934711c89626df5f2d04c8c1bb8d57192b541fd Mon Sep 17 00:00:00 2001 From: Anton Dukhovnikov Date: Tue, 21 Jan 2025 17:17:03 +1300 Subject: [PATCH] feat(raw): add black level and BPS metadata Signed-off-by: Anton Dukhovnikov --- src/raw.imageio/rawinput.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/raw.imageio/rawinput.cpp b/src/raw.imageio/rawinput.cpp index 93a9417f21..45099bd51e 100644 --- a/src/raw.imageio/rawinput.cpp +++ b/src/raw.imageio/rawinput.cpp @@ -678,6 +678,23 @@ RawInput::open_raw(bool unpack, const std::string& name, m_spec.channelnames.clear(); m_spec.channelnames.emplace_back("Y"); + uint32_t raw_bps = m_processor->imgdata.rawdata.color.raw_bps; + + float black_level = m_processor->imgdata.rawdata.color.black; + if (black_level == 0) { + unsigned* cblack = m_processor->imgdata.rawdata.color.cblack; + size_t size = cblack[4] * cblack[5]; + size_t offset = 6; + if (size == 0) { + size = 4; + offset = 0; + } + + for (size_t i = 0; i < size; i++) + black_level += cblack[offset + i]; + black_level /= size; + } + // Put the details about the filter pattern into the metadata std::string filter; const bool is_xtrans @@ -697,6 +714,8 @@ RawInput::open_raw(bool unpack, const std::string& name, filter = "unknown"; } m_spec.attribute("raw:FilterPattern", filter); + m_spec.attribute("raw:BlackLevel", black_level); + m_spec.attribute("raw:BitsPerSample", raw_bps); // Also, any previously set demosaicing options are void, so remove them m_spec.erase_attribute("oiio:ColorSpace");