man TIFFGetField does not mention TIFFTAG_CFAREPEATPATTERNDIM, meaning this
is a custom field and therefore should be read in the following way if Im
not mistaken:
uint32
value_count=0;
void*
raw_data=NULL;
if(TIFFGetField(tif, tiffTag, &value_count, &raw_data)==1) {
//
HTH
Paavo
From: Tiff <[email protected]> On Behalf Of David C. Partridge
Sent: esmaspäev, 10. aprill 2023 19:16
To: [email protected]
Subject: Re: [Tiff] CFAREPEATPATTERNDIM and CFAPATTERN
Hmmm It seems that I got the *writing* about correct:
Photometric (1 Short): Unknown (32803)
::
::
33421 (2 Short): 2, 2
33422 (4 Byte): 1, 2, 0, 1
as shown by AsTiffTagViewer (is there a better tool for this?)
But the code for reading:
uint16_t cfarepeatpatterndim[2]{ 0, 0 };
if (TIFFGetField(m_tiff, TIFFTAG_CFAREPEATPATTERNDIM,
cfarepeatpatterndim))
doesnt appear to be right as it gives me crazy results in the array
cfarepeatpatterndim
From: Tiff <[email protected]
<mailto:[email protected]> > On Behalf Of David C. Partridge
Sent: 10 April 2023 16:24
To: [email protected] <mailto:[email protected]>
Subject: [Tiff] CFAREPEATPATTERNDIM and CFAPATTERN
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;
}
Id be most grateful if someone who knows TIFF a lot better than I would
validate that code.
However, Im 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
_______________________________________________
Tiff mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/tiff