1999-08-16 21:47:59 -04:00
|
|
|
/******************************************************************************
|
2005-12-16 00:59:55 -05:00
|
|
|
* $Id: addtiffo.c,v 1.6 2005-12-16 05:59:55 fwarmerdam Exp $
|
1999-08-16 21:47:59 -04:00
|
|
|
*
|
|
|
|
* Project: GeoTIFF Overview Builder
|
|
|
|
* Purpose: Mainline for building overviews in a TIFF file.
|
2005-12-16 00:59:55 -05:00
|
|
|
* Author: Frank Warmerdam, warmerdam@pobox.com
|
1999-08-16 21:47:59 -04:00
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
* Copyright (c) 1999, Frank Warmerdam
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* $Log: addtiffo.c,v $
|
2005-12-16 00:59:55 -05:00
|
|
|
* Revision 1.6 2005-12-16 05:59:55 fwarmerdam
|
|
|
|
* Major upgrade to support YCbCr subsampled jpeg images
|
2005-12-13 10:18:11 -05:00
|
|
|
*
|
|
|
|
* Revision 1.4 2004/09/21 13:31:23 dron
|
2004-09-21 09:31:23 -04:00
|
|
|
* Add missed include string.h.
|
|
|
|
*
|
|
|
|
* Revision 1.3 2000/04/18 22:48:31 warmerda
|
2000-04-18 18:48:31 -04:00
|
|
|
* Added support for averaging resampling
|
|
|
|
*
|
|
|
|
* Revision 1.2 2000/01/28 15:36:38 warmerda
|
2000-01-28 10:36:38 -05:00
|
|
|
* pass TIFF handle instead of filename to overview builder
|
|
|
|
*
|
|
|
|
* Revision 1.1 1999/08/17 01:47:59 warmerda
|
1999-08-16 21:47:59 -04:00
|
|
|
* New
|
|
|
|
*
|
|
|
|
* Revision 1.1 1999/03/12 17:46:32 warmerda
|
|
|
|
* New
|
|
|
|
*
|
|
|
|
* Revision 1.2 1999/02/11 22:27:12 warmerda
|
|
|
|
* Added multi-sample support
|
|
|
|
*
|
|
|
|
* Revision 1.1 1999/02/11 18:12:30 warmerda
|
|
|
|
* New
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2004-09-21 09:31:23 -04:00
|
|
|
#include <string.h>
|
1999-08-16 21:47:59 -04:00
|
|
|
#include "tiffio.h"
|
|
|
|
|
2000-04-18 18:48:31 -04:00
|
|
|
void TIFFBuildOverviews( TIFF *, int, int *, int, const char *,
|
|
|
|
int (*)(double,void*), void * );
|
1999-08-16 21:47:59 -04:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* main() */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
int main( int argc, char ** argv )
|
|
|
|
|
|
|
|
{
|
2005-12-16 00:59:55 -05:00
|
|
|
int anOverviews[100]; /* TODO: un-hardwire array length, flexible allocate */
|
1999-08-16 21:47:59 -04:00
|
|
|
int nOverviewCount = 0;
|
|
|
|
int bUseSubIFD = 0;
|
2000-01-28 10:36:38 -05:00
|
|
|
TIFF *hTIFF;
|
2000-04-18 18:48:31 -04:00
|
|
|
const char *pszResampling = "nearest";
|
1999-08-16 21:47:59 -04:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/* Usage: */
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
if( argc < 2 )
|
|
|
|
{
|
2000-04-18 18:48:31 -04:00
|
|
|
printf( "Usage: addtiffo [-r {nearest,average,mode}]\n"
|
|
|
|
" tiff_filename [resolution_reductions]\n"
|
|
|
|
"\n"
|
|
|
|
"Example:\n"
|
2005-12-13 10:18:11 -05:00
|
|
|
" %% addtiffo abc.tif 2 4 8 16\n" );
|
2005-12-16 00:59:55 -05:00
|
|
|
return( 1 );
|
1999-08-16 21:47:59 -04:00
|
|
|
}
|
|
|
|
|
2000-04-18 18:48:31 -04:00
|
|
|
while( argv[1][0] == '-' )
|
1999-08-16 21:47:59 -04:00
|
|
|
{
|
2000-04-18 18:48:31 -04:00
|
|
|
if( strcmp(argv[1],"-subifd") == 0 )
|
|
|
|
{
|
|
|
|
bUseSubIFD = 1;
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
}
|
|
|
|
else if( strcmp(argv[1],"-r") == 0 )
|
|
|
|
{
|
|
|
|
argv += 2;
|
|
|
|
argc -= 2;
|
|
|
|
pszResampling = *argv;
|
|
|
|
}
|
2005-12-13 10:18:11 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Incorrect parameters\n" );
|
2005-12-16 00:59:55 -05:00
|
|
|
return( 1 );
|
2005-12-13 10:18:11 -05:00
|
|
|
}
|
1999-08-16 21:47:59 -04:00
|
|
|
}
|
|
|
|
|
2005-12-16 00:59:55 -05:00
|
|
|
/* TODO: resampling mode parameter needs to be encoded in an integer from this point on */
|
|
|
|
|
1999-08-16 21:47:59 -04:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/* Collect the user requested reduction factors. */
|
|
|
|
/* -------------------------------------------------------------------- */
|
2005-12-16 00:59:55 -05:00
|
|
|
while( nOverviewCount < argc - 2 && nOverviewCount < 100 )
|
1999-08-16 21:47:59 -04:00
|
|
|
{
|
|
|
|
anOverviews[nOverviewCount] = atoi(argv[nOverviewCount+2]);
|
2005-12-13 10:18:11 -05:00
|
|
|
if( anOverviews[nOverviewCount] <= 0)
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Incorrect parameters\n" );
|
2005-12-16 00:59:55 -05:00
|
|
|
return(1);
|
2005-12-13 10:18:11 -05:00
|
|
|
}
|
1999-08-16 21:47:59 -04:00
|
|
|
nOverviewCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/* Default to four overview levels. It would be nicer if it */
|
|
|
|
/* defaulted based on the size of the source image. */
|
|
|
|
/* -------------------------------------------------------------------- */
|
2005-12-16 00:59:55 -05:00
|
|
|
/* TODO: make it default based on the size of the source image */
|
1999-08-16 21:47:59 -04:00
|
|
|
if( nOverviewCount == 0 )
|
|
|
|
{
|
|
|
|
nOverviewCount = 4;
|
2005-12-16 00:59:55 -05:00
|
|
|
|
1999-08-16 21:47:59 -04:00
|
|
|
anOverviews[0] = 2;
|
|
|
|
anOverviews[1] = 4;
|
|
|
|
anOverviews[2] = 8;
|
|
|
|
anOverviews[3] = 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/* Build the overview. */
|
|
|
|
/* -------------------------------------------------------------------- */
|
2000-01-28 10:36:38 -05:00
|
|
|
hTIFF = TIFFOpen( argv[1], "r+" );
|
|
|
|
if( hTIFF == NULL )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "TIFFOpen(%s) failed.\n", argv[1] );
|
2005-12-16 00:59:55 -05:00
|
|
|
return( 1 );
|
2000-01-28 10:36:38 -05:00
|
|
|
}
|
|
|
|
|
2000-04-18 18:48:31 -04:00
|
|
|
TIFFBuildOverviews( hTIFF, nOverviewCount, anOverviews, bUseSubIFD,
|
|
|
|
pszResampling, NULL, NULL );
|
2000-01-28 10:36:38 -05:00
|
|
|
|
|
|
|
TIFFClose( hTIFF );
|
2005-12-16 00:59:55 -05:00
|
|
|
|
1999-08-16 21:47:59 -04:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/* Optionally test for memory leaks. */
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
#ifdef DBMALLOC
|
|
|
|
malloc_dump(1);
|
|
|
|
#endif
|
2005-12-16 00:59:55 -05:00
|
|
|
|
|
|
|
return( 0 );
|
1999-08-16 21:47:59 -04:00
|
|
|
}
|