2004.05.15 18:00 "[Tiff] tiffset usage, ResolutionUnits", by Richard Morris

2004.05.16 07:18 "Re: [Tiff] tiffset usage, ResolutionUnits", by Andrey Kiselev

Can anyone point me to any documentation on usage of the "tiffset" utility? I am trying to convert ResolutionUnits on Tiff files from cm to inches, and am not successful so far.

tiffset is not a complete ready to use application yet. Fortunately it is pretty simple to achieve your goal using the following code:

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

int main(int argc, char* argv[])
{
        TIFF *tiff;
        double xres = 0.0, yres = 0.0;

        if (argc < 2)
                return 1;

        tiff = TIFFOpen(argv[argc-1], "r+");
        if (tiff == NULL)
                return 2;

        /* For list of available tags and tag values see tiff.h */
        if (TIFFSetField(tiff, TIFFTAG_RESOLUTIONUNIT, RESUNIT_CENTIMETER) != 1)
                fprintf( stderr, "Failed to set ResolutionUnit.\n");

        /* Don't forget to calculate and set new resolution values */
        if (TIFFSetField(tiff, TIFFTAG_XRESOLUTION, xres) != 1)
                fprintf( stderr, "Failed to set XResolution.\n");
        if (TIFFSetField(tiff, TIFFTAG_YRESOLUTION, yres) != 1)
                fprintf( stderr, "Failed to set YResolution.\n");

        TIFFRewriteDirectory(tiff);
        TIFFClose(tiff);
}

But be warned that the new TIFF directory will be added to the file each time running that program, increasing the file size.

I see from the libtiff manual that the tag value for ResolutionUnits is 296, but I don't know how to set the value. From tiffdump output, I saw that tiff files with resolution in cm output "ResolutionUnit (296) SHORT (3) 1<3>", while tiffs with resolution in inches output "ResolutionUnit (296) SHORT (3) 1<2>".

That is right, inches coded by the value 2, centimeters by the value 3.

Andrey

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