]>
Commit | Line | Data |
---|---|---|
1 | /****************************************************************************** | |
2 | * $Id$ | |
3 | * | |
4 | * Project: GeoTIFF Overview Builder | |
5 | * Purpose: Mainline for building overviews in a TIFF file. | |
6 | * Author: Frank Warmerdam, warmerdam@pobox.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.6 2005/12/16 05:59:55 fwarmerdam | |
32 | * Major upgrade to support YCbCr subsampled jpeg images | |
33 | * | |
34 | * Revision 1.4 2004/09/21 13:31:23 dron | |
35 | * Add missed include string.h. | |
36 | * | |
37 | * Revision 1.3 2000/04/18 22:48:31 warmerda | |
38 | * Added support for averaging resampling | |
39 | * | |
40 | * Revision 1.2 2000/01/28 15:36:38 warmerda | |
41 | * pass TIFF handle instead of filename to overview builder | |
42 | * | |
43 | * Revision 1.1 1999/08/17 01:47:59 warmerda | |
44 | * New | |
45 | * | |
46 | * Revision 1.1 1999/03/12 17:46:32 warmerda | |
47 | * New | |
48 | * | |
49 | * Revision 1.2 1999/02/11 22:27:12 warmerda | |
50 | * Added multi-sample support | |
51 | * | |
52 | * Revision 1.1 1999/02/11 18:12:30 warmerda | |
53 | * New | |
54 | */ | |
55 | ||
56 | #include <stdio.h> | |
57 | #include <stdlib.h> | |
58 | #include <string.h> | |
59 | #include "tiffio.h" | |
60 | ||
61 | void TIFFBuildOverviews( TIFF *, int, int *, int, const char *, | |
62 | int (*)(double,void*), void * ); | |
63 | ||
64 | /************************************************************************/ | |
65 | /* main() */ | |
66 | /************************************************************************/ | |
67 | ||
68 | int main( int argc, char ** argv ) | |
69 | ||
70 | { | |
71 | int anOverviews[100]; /* TODO: un-hardwire array length, flexible allocate */ | |
72 | int nOverviewCount = 0; | |
73 | int bUseSubIFD = 0; | |
74 | TIFF *hTIFF; | |
75 | const char *pszResampling = "nearest"; | |
76 | ||
77 | /* -------------------------------------------------------------------- */ | |
78 | /* Usage: */ | |
79 | /* -------------------------------------------------------------------- */ | |
80 | if( argc < 2 ) | |
81 | { | |
82 | printf( "Usage: addtiffo [-r {nearest,average,mode}]\n" | |
83 | " tiff_filename [resolution_reductions]\n" | |
84 | "\n" | |
85 | "Example:\n" | |
86 | " %% addtiffo abc.tif 2 4 8 16\n" ); | |
87 | return( 1 ); | |
88 | } | |
89 | ||
90 | while( argv[1][0] == '-' ) | |
91 | { | |
92 | if( strcmp(argv[1],"-subifd") == 0 ) | |
93 | { | |
94 | bUseSubIFD = 1; | |
95 | argv++; | |
96 | argc--; | |
97 | } | |
98 | else if( strcmp(argv[1],"-r") == 0 ) | |
99 | { | |
100 | argv += 2; | |
101 | argc -= 2; | |
102 | pszResampling = *argv; | |
103 | } | |
104 | else | |
105 | { | |
106 | fprintf( stderr, "Incorrect parameters\n" ); | |
107 | return( 1 ); | |
108 | } | |
109 | } | |
110 | ||
111 | /* TODO: resampling mode parameter needs to be encoded in an integer from this point on */ | |
112 | ||
113 | /* -------------------------------------------------------------------- */ | |
114 | /* Collect the user requested reduction factors. */ | |
115 | /* -------------------------------------------------------------------- */ | |
116 | while( nOverviewCount < argc - 2 && nOverviewCount < 100 ) | |
117 | { | |
118 | anOverviews[nOverviewCount] = atoi(argv[nOverviewCount+2]); | |
119 | if( anOverviews[nOverviewCount] <= 0) | |
120 | { | |
121 | fprintf( stderr, "Incorrect parameters\n" ); | |
122 | return(1); | |
123 | } | |
124 | nOverviewCount++; | |
125 | } | |
126 | ||
127 | /* -------------------------------------------------------------------- */ | |
128 | /* Default to four overview levels. It would be nicer if it */ | |
129 | /* defaulted based on the size of the source image. */ | |
130 | /* -------------------------------------------------------------------- */ | |
131 | /* TODO: make it default based on the size of the source image */ | |
132 | if( nOverviewCount == 0 ) | |
133 | { | |
134 | nOverviewCount = 4; | |
135 | ||
136 | anOverviews[0] = 2; | |
137 | anOverviews[1] = 4; | |
138 | anOverviews[2] = 8; | |
139 | anOverviews[3] = 16; | |
140 | } | |
141 | ||
142 | /* -------------------------------------------------------------------- */ | |
143 | /* Build the overview. */ | |
144 | /* -------------------------------------------------------------------- */ | |
145 | hTIFF = TIFFOpen( argv[1], "r+" ); | |
146 | if( hTIFF == NULL ) | |
147 | { | |
148 | fprintf( stderr, "TIFFOpen(%s) failed.\n", argv[1] ); | |
149 | return( 1 ); | |
150 | } | |
151 | ||
152 | TIFFBuildOverviews( hTIFF, nOverviewCount, anOverviews, bUseSubIFD, | |
153 | pszResampling, NULL, NULL ); | |
154 | ||
155 | TIFFClose( hTIFF ); | |
156 | ||
157 | /* -------------------------------------------------------------------- */ | |
158 | /* Optionally test for memory leaks. */ | |
159 | /* -------------------------------------------------------------------- */ | |
160 | #ifdef DBMALLOC | |
161 | malloc_dump(1); | |
162 | #endif | |
163 | ||
164 | return( 0 ); | |
165 | } |