1 /******************************************************************************
2 * $Id: addtiffo.c,v 1.3 2000/04/18 22:48:31 warmerda Exp $
3 *
4 * Project: GeoTIFF Overview Builder
5 * Purpose: Mainline for building overviews in a TIFF file.
6 * Author: Frank Warmerdam, warmerda@home.com
7 *
8 ******************************************************************************
9 * Copyright (c) 1999, Frank Warmerdam
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
28 ******************************************************************************
29 *
30 * $Log: addtiffo.c,v $
31 * Revision 1.3 2000/04/18 22:48:31 warmerda
32 * Added support for averaging resampling
33 *
34 * Revision 1.2 2000/01/28 15:36:38 warmerda
35 * pass TIFF handle instead of filename to overview builder
36 *
37 * Revision 1.1 1999/08/17 01:47:59 warmerda
38 * New
39 *
40 * Revision 1.1 1999/03/12 17:46:32 warmerda
41 * New
42 *
43 * Revision 1.2 1999/02/11 22:27:12 warmerda
44 * Added multi-sample support
45 *
46 * Revision 1.1 1999/02/11 18:12:30 warmerda
47 * New
48 */
49
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include "tiffio.h"
53
54 void TIFFBuildOverviews( TIFF *, int, int *, int, const char *,
55 int (*)(double,void*), void * );
56
57 /************************************************************************/
58 /* main() */
59 /************************************************************************/
60
main(int argc,char ** argv)61 int main( int argc, char ** argv )
62
63 {
64 int anOverviews[100];
65 int nOverviewCount = 0;
66 int bUseSubIFD = 0;
67 TIFF *hTIFF;
68 const char *pszResampling = "nearest";
69
70 /* -------------------------------------------------------------------- */
71 /* Usage: */
72 /* -------------------------------------------------------------------- */
73 if( argc < 2 )
74 {
75 printf( "Usage: addtiffo [-r {nearest,average,mode}]\n"
76 " tiff_filename [resolution_reductions]\n"
77 "\n"
78 "Example:\n"
79 " %% addtifo abc.tif 2 4 8 16\n" );
80 exit( 1 );
81 }
82
83 while( argv[1][0] == '-' )
84 {
85 if( strcmp(argv[1],"-subifd") == 0 )
86 {
87 bUseSubIFD = 1;
88 argv++;
89 argc--;
90 }
91 else if( strcmp(argv[1],"-r") == 0 )
92 {
93 argv += 2;
94 argc -= 2;
95 pszResampling = *argv;
96 }
97 }
98
99 /* -------------------------------------------------------------------- */
100 /* Collect the user requested reduction factors. */
101 /* -------------------------------------------------------------------- */
102 while( nOverviewCount < argc - 2 && nOverviewCount < 100 )
103 {
104 anOverviews[nOverviewCount] = atoi(argv[nOverviewCount+2]);
105 nOverviewCount++;
106 }
107
108 /* -------------------------------------------------------------------- */
109 /* Default to four overview levels. It would be nicer if it */
110 /* defaulted based on the size of the source image. */
111 /* -------------------------------------------------------------------- */
112 if( nOverviewCount == 0 )
113 {
114 nOverviewCount = 4;
115
116 anOverviews[0] = 2;
117 anOverviews[1] = 4;
118 anOverviews[2] = 8;
119 anOverviews[3] = 16;
120 }
121
122 /* -------------------------------------------------------------------- */
123 /* Build the overview. */
124 /* -------------------------------------------------------------------- */
125 hTIFF = TIFFOpen( argv[1], "r+" );
126 if( hTIFF == NULL )
127 {
128 fprintf( stderr, "TIFFOpen(%s) failed.\n", argv[1] );
129 exit( 1 );
130 }
131
132 TIFFBuildOverviews( hTIFF, nOverviewCount, anOverviews, bUseSubIFD,
133 pszResampling, NULL, NULL );
134
135 TIFFClose( hTIFF );
136
137 /* -------------------------------------------------------------------- */
138 /* Optionally test for memory leaks. */
139 /* -------------------------------------------------------------------- */
140 #ifdef DBMALLOC
141 malloc_dump(1);
142 #endif
143
144 exit( 0 );
145 }
146