]> git.saurik.com Git - wxWidgets.git/blob - src/tiff/contrib/addtiffo/addtiffo.c
No changes, just use wxRecursionGuard instead of manual boolean flag.
[wxWidgets.git] / src / tiff / contrib / addtiffo / addtiffo.c
1 /******************************************************************************
2 *
3 * Project: GeoTIFF Overview Builder
4 * Purpose: Mainline for building overviews in a TIFF file.
5 * Author: Frank Warmerdam, warmerdam@pobox.com
6 *
7 ******************************************************************************
8 * Copyright (c) 1999, Frank Warmerdam
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 ******************************************************************************
28 *
29 * $Log: addtiffo.c,v $
30 * Revision 1.7 2010-06-08 18:55:15 bfriesen
31 * * contrib: Add an emacs formatting mode footer to all source files
32 * so that emacs can be effectively used.
33 *
34 * Revision 1.6 2005/12/16 05:59:55 fwarmerdam
35 * Major upgrade to support YCbCr subsampled jpeg images
36 *
37 * Revision 1.4 2004/09/21 13:31:23 dron
38 * Add missed include string.h.
39 *
40 * Revision 1.3 2000/04/18 22:48:31 warmerda
41 * Added support for averaging resampling
42 *
43 * Revision 1.2 2000/01/28 15:36:38 warmerda
44 * pass TIFF handle instead of filename to overview builder
45 *
46 * Revision 1.1 1999/08/17 01:47:59 warmerda
47 * New
48 *
49 * Revision 1.1 1999/03/12 17:46:32 warmerda
50 * New
51 *
52 * Revision 1.2 1999/02/11 22:27:12 warmerda
53 * Added multi-sample support
54 *
55 * Revision 1.1 1999/02/11 18:12:30 warmerda
56 * New
57 */
58
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #include "tiffio.h"
63
64 void TIFFBuildOverviews( TIFF *, int, int *, int, const char *,
65 int (*)(double,void*), void * );
66
67 /************************************************************************/
68 /* main() */
69 /************************************************************************/
70
71 int main( int argc, char ** argv )
72
73 {
74 int anOverviews[100]; /* TODO: un-hardwire array length, flexible allocate */
75 int nOverviewCount = 0;
76 int bUseSubIFD = 0;
77 TIFF *hTIFF;
78 const char *pszResampling = "nearest";
79
80 /* -------------------------------------------------------------------- */
81 /* Usage: */
82 /* -------------------------------------------------------------------- */
83 if( argc < 2 )
84 {
85 printf( "Usage: addtiffo [-r {nearest,average,mode}]\n"
86 " tiff_filename [resolution_reductions]\n"
87 "\n"
88 "Example:\n"
89 " %% addtiffo abc.tif 2 4 8 16\n" );
90 return( 1 );
91 }
92
93 while( argv[1][0] == '-' )
94 {
95 if( strcmp(argv[1],"-subifd") == 0 )
96 {
97 bUseSubIFD = 1;
98 argv++;
99 argc--;
100 }
101 else if( strcmp(argv[1],"-r") == 0 )
102 {
103 argv += 2;
104 argc -= 2;
105 pszResampling = *argv;
106 }
107 else
108 {
109 fprintf( stderr, "Incorrect parameters\n" );
110 return( 1 );
111 }
112 }
113
114 /* TODO: resampling mode parameter needs to be encoded in an integer from this point on */
115
116 /* -------------------------------------------------------------------- */
117 /* Collect the user requested reduction factors. */
118 /* -------------------------------------------------------------------- */
119 while( nOverviewCount < argc - 2 && nOverviewCount < 100 )
120 {
121 anOverviews[nOverviewCount] = atoi(argv[nOverviewCount+2]);
122 if( anOverviews[nOverviewCount] <= 0)
123 {
124 fprintf( stderr, "Incorrect parameters\n" );
125 return(1);
126 }
127 nOverviewCount++;
128 }
129
130 /* -------------------------------------------------------------------- */
131 /* Default to four overview levels. It would be nicer if it */
132 /* defaulted based on the size of the source image. */
133 /* -------------------------------------------------------------------- */
134 /* TODO: make it default based on the size of the source image */
135 if( nOverviewCount == 0 )
136 {
137 nOverviewCount = 4;
138
139 anOverviews[0] = 2;
140 anOverviews[1] = 4;
141 anOverviews[2] = 8;
142 anOverviews[3] = 16;
143 }
144
145 /* -------------------------------------------------------------------- */
146 /* Build the overview. */
147 /* -------------------------------------------------------------------- */
148 hTIFF = TIFFOpen( argv[1], "r+" );
149 if( hTIFF == NULL )
150 {
151 fprintf( stderr, "TIFFOpen(%s) failed.\n", argv[1] );
152 return( 1 );
153 }
154
155 TIFFBuildOverviews( hTIFF, nOverviewCount, anOverviews, bUseSubIFD,
156 pszResampling, NULL, NULL );
157
158 TIFFClose( hTIFF );
159
160 /* -------------------------------------------------------------------- */
161 /* Optionally test for memory leaks. */
162 /* -------------------------------------------------------------------- */
163 #ifdef DBMALLOC
164 malloc_dump(1);
165 #endif
166
167 return( 0 );
168 }
169 /*
170 * Local Variables:
171 * mode: c
172 * c-basic-offset: 8
173 * fill-column: 78
174 * End:
175 */