2016.06.28 17:36 "[Tiff] Error messages regarding CFA tags: Unknown tags", by Fabian K

2016.06.28 17:36 "[Tiff] Error messages regarding CFA tags: Unknown tags", by Fabian K

Hello,

I wish to generate a raw 16bit TIFF/EP Profile 2 file from an arbitrary
pixel array. This pixel array represents a Bayer pattern (CFA). I don't
receive any errors when compiling, however, when executing it says:

g++ 16bit_raw.cpp -Wall -pedantic-errors -ltiff
./a.out
TIFFSetField: 16bitRaw.dng: Unknown tag 33422.
TIFFSetField: 16bitRaw.dng: Unknown tag 33421.

So this is clearly related to CFAREPEATPATTERNDIM and TIFFTAG_CFAPATTERN.
My libtiff version is 4.0.6, so these tags should already be implemented in
the library as far as I know. However, the tags do not appear in the
resulting .dng file (when opened with a text editor, see below) and the
.dng file cannot be displayed with a graphics program. I don't know what
I'm missing. Moreover, I have the feeling that the bitdepth of 16 bits is
not correctly encoded in the output file. Can you please help me?

Bests, Fabian

16bit_raw.cpp:

#include "tiffio.h"
#include <iostream>
using namespace std;

int main(void)
{

TIFF *out = TIFFOpen("16bitRaw.dng", "w");

    const int sampleperpixel = 1;
    const int width = 2;
    const int height = 2;

unsigned int short image [height][width*sampleperpixel] = {};

    image[0][0] = 2;           //arbitrary pixel intensity values
    image[0][1] = 64000;
    image[1][0] = 1500;
    image[1][1] = 1;

TIFFSetField(out, TIFFTAG_SUBFILETYPE, 0); //main image

TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);

TIFFSetField(out, TIFFTAG_IMAGELENGTH, height);

TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, sampleperpixel);

TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 16);

TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);

TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_CFA); //it's a raw image

    //rectangular (or square) layout:
    if (TIFFSetField(out, TIFFTAG_CFALAYOUT, 1) == -1)
        cout << "cfalayout causes an error \n";

    //Defining Bayer pattern:
    if (TIFFSetField(out, TIFFTAG_CFAPATTERN, 4, "\001\0\002\001") == -1)
        cout << "cfapattern causes an error \n";

    //Defining dimension of Bayer pattern:
    static const short dimension[] = {2,2};
    if (TIFFSetField(out, TIFFTAG_CFAREPEATPATTERNDIM, dimension) == -1)
        cout << "cfarepeatpattern causes an error \n";

TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, width*sampleperpixel));

    TIFFWriteScanline(out, image[0], 0, 0);
    TIFFWriteScanline(out, image[1], 1, 0);
    TIFFClose(out);

    return 0;
}

Output is 16bitRaw.dng:

4949 2a00 1000 0000 0200 00fa dc05 0100
0c00 fe00 0400 0100 0000 0000 0000 0001
0300 0100 0000 0200 0000 0101 0300 0100
0000 0200 0000 0201 0300 0100 0000 1000
0000 0301 0300 0100 0000 0100 0000 0601
0300 0100 0000 2380 0000 1101 0400 0100
0000 0800 0000 1201 0300 0100 0000 0100
0000 1501 0300 0100 0000 0100 0000 1601
0300 0100 0000 0200 0000 1701 0400 0100
0000 0800 0000 17c6 0300 0100 0000 0100
0000 0000 0000