AWARE [SYSTEMS]
AWare Systems, , Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
September 2006

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
Archive maintained by AWare Systems



New Datamatrix section



Valid HTML 4.01!



2006.09.26 14:22 "2003.08.07 16:40 "Custom tags", by Andrey Kiselev", by Robert Scheck

I tried to run this example program,
but after each "TIFFSetField()" I got errormessage like this:
   _TIFFVSetField: test.tif: Invalid tag "MyTag" (not supported by codec).

I'm using LIBTIFF, Version 3.8.2 for Windows.
Do You know, what's the problem?



Test-Code:

#include <tiffio.h>
#include <stdio.h>

#define TIFFTAG_ASCIITAG 666
#define TIFFTAG_LONGTAG 667
#define TIFFTAG_SHORTTAG 668
#define TIFFTAG_RATIONALTAG 669
#define TIFFTAG_FLOATTAG 670
#define TIFFTAG_DOUBLETAG 671
#define TIFFTAG_BYTE 672

static void TagExtender(TIFF *tiff)
{
    static const TIFFFieldInfo xtiffFieldInfo[] = {
        { TIFFTAG_ASCIITAG,    -1,-1, TIFF_ASCII, FIELD_CUSTOM,
          1,             0,              "MyTag" },
        { TIFFTAG_SHORTTAG, 1, 1, TIFF_SHORT,  FIELD_CUSTOM, 0, 1,
            "ShortTag" },
        { TIFFTAG_LONGTAG, 1, 1, TIFF_LONG,  FIELD_CUSTOM, 0, 1,
            "LongTag" },
        { TIFFTAG_RATIONALTAG, 1, 1, TIFF_RATIONAL,  FIELD_CUSTOM, 0, 1,
            "RationalTag" },
        { TIFFTAG_FLOATTAG, 1, 1, TIFF_FLOAT,  FIELD_CUSTOM, 0, 1,
            "FloatTag" },
        { TIFFTAG_DOUBLETAG, 1, 1, TIFF_DOUBLE,  FIELD_CUSTOM, 0, 1,
            "DoubleTag" },
        { TIFFTAG_BYTE, 1, 1, TIFF_BYTE,  FIELD_CUSTOM, 0, 1,
            "DoubleTag" },
    };

    TIFFMergeFieldInfo( tiff, xtiffFieldInfo,
                                         sizeof(xtiffFieldInfo) / 
sizeof(xtiffFieldInfo[0]) );
}

int main()
{
    TIFF    *tiff;
    char    *pszString;
    long    iLong, *paiLong;
    short   iShort, *paiShort;
    float   fFloat, *pafFloat;
    double  dfDouble, *padfDouble;
    char    iByte, *paiByte;

    unsigned short iCount;

    TIFFSetTagExtender(TagExtender);

    tiff = TIFFOpen("test.tif", "r+");
    TIFFSetField(tiff, TIFFTAG_ASCIITAG, "Tag contents");
    iShort = 263;
    TIFFSetField(tiff, TIFFTAG_SHORTTAG, 1, &iShort);
    iLong = 117;
    TIFFSetField(tiff, TIFFTAG_LONGTAG, 1, &iLong);
    fFloat = 0.333333;
    TIFFSetField(tiff, TIFFTAG_RATIONALTAG, 1, &fFloat);
    fFloat = 0.666666;
    TIFFSetField(tiff, TIFFTAG_FLOATTAG, 1, &fFloat);
    dfDouble = 0.1234567;
    TIFFSetField(tiff, TIFFTAG_DOUBLETAG, 1, &dfDouble);
    iByte = 89;
    TIFFSetField(tiff, TIFFTAG_BYTE, 1, &iByte);
    TIFFRewriteDirectory(tiff);
    TIFFClose(tiff);

    tiff = TIFFOpen("test.tif", "r");
    TIFFGetField(tiff, TIFFTAG_ASCIITAG, &pszString);
    printf("ASCII tag: %s\n", pszString);
    TIFFGetField(tiff, TIFFTAG_SHORTTAG, &iCount, &paiShort);
    if (iCount == 1)
            printf("Short tag: %d\n", paiShort[0]);
    TIFFGetField(tiff, TIFFTAG_LONGTAG, &iCount, &paiLong);
    if (iCount == 1)
            printf("Long tag: %ld\n", paiLong[0]);
    TIFFGetField(tiff, TIFFTAG_RATIONALTAG, &iCount, &pafFloat);
    if (iCount == 1)
            printf("Rational tag: %f\n", pafFloat[0]);
    TIFFGetField(tiff, TIFFTAG_FLOATTAG, &iCount, &pafFloat);
    if (iCount == 1)
            printf("Float tag: %f\n", pafFloat[0]);
    TIFFGetField(tiff, TIFFTAG_DOUBLETAG, &iCount, &padfDouble);
    if (iCount == 1)
            printf("Double tag: %lf\n", padfDouble[0]);
    TIFFGetField(tiff, TIFFTAG_BYTE, &iCount, &paiByte);
    if (iCount == 1)
            printf("Byte tag: %d\n", paiByte[0]);
    TIFFClose(tiff);

    return 0;
}





Robert Scheck
Senior Software Engineer
----------------------------------------
Beta Systems Software AG
Business Line ECM
Hübnerstraße 3, D-86150 Augsburg
Phone +49 (0) 821 - 7941 - 215
Fax +49 (0) 821 - 7941 - 353
Email: robert.scheck@betasystems.com
http://www.betasystems.com



[This message is confidential. It may also be privileged or otherwise
protected by work product immunity or other legal rules. If you have
received it by mistake please let us know by reply and then delete it from
your system; you should not copy it or disclose its contents to anyone. All
messages sent to and from Beta Systems may be monitored to ensure compliance
with internal policies and to protect our business. Emails are not secure
and cannot be guaranteed to be error free as they can be intercepted,
amended, lost or destroyed, or contain viruses. Anyone who communicates with
us by email is taken to accept these risks.]