AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2012.08.16 19:45 "[Tiff] Is it possible to create tags in tree structure?", by Yimin Li
2012.08.17 00:33 "Re: [Tiff] Is it possible to create tags in tree structure?", by Yimin Li

2012.08.16 19:45 "[Tiff] Is it possible to create tags in tree structure?", by Yimin Li

Hi everyone,

I am here for the first time! Thanks for help from Frank Warmerdam!

I am trying to create tags in tree structure, using libtiff. The idea is to
make a TIFFTAG_SUBIFD in sub-directory. But seems nested SUBIFDs are not
allowed. Is this direction correct? Please let me know if I am wrong.
I created a test case to start working with. It could help if people don't
want to create another one. ;) Please find it in attached file. Thank you!

Kind regards,
Yimin

#include <stdlib.h>
#include "tiffiop.h"

#define TEST_TAG 0x1111

static TIFFField Test_Fiels[] = {
    { TEST_TAG, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Test tag", NULL },
};

static TIFFFieldArray Test_FieldArray = { tfiatOther, 0, TIFFArrayCount(Test_Fiels), Test_Fiels };

int main( int argc, char* argv[] ) {

TIFF *tif;

if( ( tif = TIFFOpen( "output.tif", "w" ) ) == NULL )
    return -1;

    TIFFSetField( tif, TIFFTAG_IMAGEWIDTH, 1 );     // required by a basic tif file
    TIFFSetField( tif, TIFFTAG_IMAGELENGTH, 1 );    //
    TIFFWriteEncodedStrip( tif, 0, NULL, 0 );       //

if( !TIFFWriteDirectory( tif ) )
    return -1;

    uint64 customDirectory_L0[2] = { 0, 0 };
    uint64 customDirectory_L1[1] = { 0 };

if( TIFFCreateCustomDirectory( tif, &Test_FieldArray ) )
    return -1;

if( !TIFFSetField( tif, TEST_TAG, 1 ) )
    return -1;

if( !TIFFWriteCustomDirectory( tif, &customDirectory_L0[0] ) )
    return -1;

if( TIFFCreateCustomDirectory( tif, &Test_FieldArray ) )
    return -1;

if( !TIFFSetField(tif, TEST_TAG, 2) )
    return -1;

if( !TIFFWriteCustomDirectory( tif, &customDirectory_L0[1] ) )
    return -1;

TIFFSetDirectory( tif, 0 );

TIFFSetField( tif, TIFFTAG_SUBIFD, 2, customDirectory_L0 );

TIFFWriteDirectory( tif );

if( TIFFCreateCustomDirectory( tif, &Test_FieldArray ) )
    return -1;

if( !TIFFSetField( tif, TEST_TAG, 3 ) )
    return -1;

if( !TIFFWriteCustomDirectory( tif, &customDirectory_L1[0] ) )
    return -1;

TIFFSetSubDirectory( tif, customDirectory_L0[0] );

    if( !TIFFSetField( tif, TIFFTAG_SUBIFD, 1, customDirectory_L1 ) )   // info from console: _TIFFVSetField: output.tif: Sorry, cannot nest SubIFDs.

return -1;

TIFFClose( tif );

printf("Done.\n");

    return 0;
}