AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
December 2003

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2003.12.24 18:04 "writing custom tags with TIFFSetField", by Carl J Collin
2003.12.26 11:51 "Re: writing custom tags with TIFFSetField", by Andrey Kiselev
2003.12.26 18:02 "Error with sample code to copy a custom tag", by Carl J Collin
2003.12.26 18:32 "Re: Error with sample code to copy a custom tag", by Andrey Kiselev
2003.12.26 18:48 "CopyTag error again...", by Carl J Collin
2003.12.26 19:17 "Re: CopyTag error again...", by Andrey Kiselev

2003.12.26 11:51 "Re: writing custom tags with TIFFSetField", by Andrey Kiselev

On Wed, Dec 24, 2003 at 12:04:19PM -0600, Carl J. Collin wrote:
> I am trying to update tiffcp to read and write a custom tag (Wang
> Annotations).  Well, in the newest CVS it looks like TIFFGetField
> might be finally able to acquire the custom tag data.  But when I try
> and write it using TIFFSetField it seems to be getting written to a
> different tag number than what was specified on the tag line.  Beyond
> that, I can't figure out how writing to the TIFFTagValue that is
> specified in the default section of _TIFFVSetField actually writes to
> the new tiff directory.  Has anyone seen any examples of reading and
> writing to custom tags using the new interface in 3.6.X?

Carl,

It is a bit tricky to modify tiffcp to enable custom tags copying. I'm
recommend ti fill the feature request and shall try to implement such a
feature in the next libtiff release.

I have attached an example code which shows how you can copy your tag.

                                      Regards,
				      Andrey  

-- 
Andrey V. Kiselev
Home phone:  +7 812 5274898  ICQ# 26871517


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

#define TIFFTAG_WANG 32932

static void TagExtender(TIFF *tiff)
{
    static const TIFFFieldInfo xtiffFieldInfo[] = {
        { TIFFTAG_WANG, -1, -1, TIFF_BYTE,  FIELD_CUSTOM,   1,  0,  "Wang" }
    };

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

int main(int argc, char **argv)
{
    TIFF    *in, *out;
    char    *buf, *wang;
    int     i, count;

    if (argc < 3)
    {
        fprintf(stderr, "Usage: %s in.tiff out.tiff\n", argv[0]);
        return 0;
    }

    /* Register the custom tag hadler */
    TIFFSetTagExtender(TagExtender);

    in = TIFFOpen(argv[1], "r");
    if (!in)
    {
        fprintf(stderr, "Can't open input file %s\n", argv[1]);
        return 1;
    }
    
    TIFFGetField(in, TIFFTAG_WANG, &count, &wang);

    out = TIFFOpen(argv[2], "w");
    if (!out)
    {
        fprintf(stderr, "Can't open output file %s\n", argv[2]);
        TIFFClose(in);
        return 2;
    }

    TIFFSetField(out, TIFFTAG_IMAGEWIDTH, 256);
    TIFFSetField(out, TIFFTAG_IMAGELENGTH, 256);
    TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
    TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 3);
    TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
    TIFFSetField(out, TIFFTAG_WANG, count, wang);

    buf = _TIFFmalloc(3 * 256 * 256);
    TIFFWriteEncodedStrip(out, 0, buf, 3 * 256 * 256);
    _TIFFfree(buf);

    TIFFClose(out);
    TIFFClose(in);

    return 0;
}