
Thread
2023.04.10 15:23 "[Tiff] CFAREPEATPATTERNDIM and CFAPATTERN", by David C. Partridge
I *think* I have these two worked out:
Reading:
constexpr uint8_t TIFF_CFAPattern_RGGB[] { 0,1,1,2 };
constexpr uint8_t TIFF_CFAPattern_BGGR[] { 2,1,1,0 };
constexpr uint8_t TIFF_CFAPattern_GRBG[] { 1,0,2,1 };
constexpr uint8_t TIFF_CFAPattern_GBRG[] { 1,2,0,1 };
//
/ Attempt to read the CFA from the root IFD if this is a CFA image
//
if (PHOTOMETRIC_CFA == photo)
{
uint16_t cfarepeatpatterndim[2]{ 0 };
if (TIFFGetField(m_tiff, TIFFTAG_CFAREPEATPATTERNDIM, &cfarepeatpatterndim))
{
uint16_t
x{ (cfarepeatpatterndim[0]) },
y{ (cfarepeatpatterndim[1]) };
uint8_t* cfapattern = static_cast<uint8_t*>(_alloca(x * y));
TIFFGetField(m_tiff, TIFFTAG_CFAPATTERN, x*y, cfapattern);
}
}
and Writing:
TIFFSetField(m_tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_CFA);
constexpr uint16_t cfapatterndim[2]{ 2,2 };
TIFFSetField(m_tiff, TIFFTAG_CFAREPEATPATTERNDIM, cfapatterndim);
//
// Note that when writing the CFA pattern, need to specify how many
// octets are to be written.
//
switch (cfatype)
{
case CFATYPE_BGGR:
TIFFSetField(m_tiff, TIFFTAG_CFAPATTERN, 4, TIFF_CFAPattern_BGGR);
break;
case CFATYPE_GRBG:
TIFFSetField(m_tiff, TIFFTAG_CFAPATTERN, 4, TIFF_CFAPattern_GRBG);
break;
case CFATYPE_GBRG:
TIFFSetField(m_tiff, TIFFTAG_CFAPATTERN, 4, TIFF_CFAPattern_GBRG);
break;
case CFATYPE_RGGB:
TIFFSetField(m_tiff, TIFFTAG_CFAPATTERN, 4, TIFF_CFAPattern_RGGB);
break;
}
I'd be most grateful if someone who knows TIFF a lot better than I would validate that code.
However, I'm still a bit puzzled how I should read/write the data for EXIFTAG_CFAPATTERN which is defined as:
{EXIFTAG_CFAPATTERN, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "CFAPattern", NULL}
as the length is a priori unknown AFAICT?
PS could someone please explain how I should interpret the meaning of e.g. TIFF_SETGET_C16_UINT8
Thank you, David