Skip to content

Commit 36470f2

Browse files
antond-wetascott-wilson
authored andcommitted
feat(raw): add black level and BPS metadata (AcademySoftwareFoundation#4601)
Adds attributes to the input's ImageSpec for the black level and bit depth when the raw bayer buffer is requested. Signed-off-by: Anton Dukhovnikov <[email protected]> Signed-off-by: Scott Wilson <[email protected]>
1 parent 602f20b commit 36470f2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/raw.imageio/rawinput.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,23 @@ RawInput::open_raw(bool unpack, const std::string& name,
678678
m_spec.channelnames.clear();
679679
m_spec.channelnames.emplace_back("Y");
680680

681+
uint32_t raw_bps = m_processor->imgdata.rawdata.color.raw_bps;
682+
683+
float black_level = m_processor->imgdata.rawdata.color.black;
684+
if (black_level == 0) {
685+
unsigned* cblack = m_processor->imgdata.rawdata.color.cblack;
686+
size_t size = cblack[4] * cblack[5];
687+
size_t offset = 6;
688+
if (size == 0) {
689+
size = 4;
690+
offset = 0;
691+
}
692+
693+
for (size_t i = 0; i < size; i++)
694+
black_level += cblack[offset + i];
695+
black_level /= size;
696+
}
697+
681698
// Put the details about the filter pattern into the metadata
682699
std::string filter;
683700
const bool is_xtrans
@@ -697,6 +714,8 @@ RawInput::open_raw(bool unpack, const std::string& name,
697714
filter = "unknown";
698715
}
699716
m_spec.attribute("raw:FilterPattern", filter);
717+
m_spec.attribute("raw:BlackLevel", black_level);
718+
m_spec.attribute("raw:BitsPerSample", raw_bps);
700719

701720
// Also, any previously set demosaicing options are void, so remove them
702721
m_spec.erase_attribute("oiio:ColorSpace");

0 commit comments

Comments
 (0)