added -E switch
[tridge/junkcode.git] / tiffsetres.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "tiffio.h"
4         
5 int main(int argc, char* argv[])
6 {
7         TIFF *tiff;
8         double res = 17.74;
9         int i;
10         
11         if (argc < 2)
12                 return 1;
13
14         res = atof(argv[1]);
15
16         res = 1.0 / (res * 1.0e-4);
17
18         for (i=2;i<argc;i++) {
19                 tiff = TIFFOpen(argv[i], "r+");
20                 if (tiff == NULL) {
21                         perror(argv[i]);
22                         return 2;
23                 }
24         
25                 /* For list of available tags and tag values see tiff.h */
26                 if (TIFFSetField(tiff, TIFFTAG_RESOLUTIONUNIT, RESUNIT_CENTIMETER) != 1)
27                         fprintf( stderr, "Failed to set ResolutionUnit.\n");
28
29                 /* Don't forget to calculate and set new resolution values */
30                 if (TIFFSetField(tiff, TIFFTAG_XRESOLUTION, res) != 1)
31                         fprintf( stderr, "Failed to set XResolution.\n");
32                 if (TIFFSetField(tiff, TIFFTAG_YRESOLUTION, res) != 1)
33                         fprintf( stderr, "Failed to set YResolution.\n");
34                 
35                 TIFFRewriteDirectory(tiff);
36                 TIFFClose(tiff);
37         }
38
39         return 0;
40 }
41