From aca9e32b0ae0f017890a980117bad0a73d576135 Mon Sep 17 00:00:00 2001 From: Frank Warmerdam Date: Fri, 28 Jan 2000 15:36:38 +0000 Subject: [PATCH] pass TIFF handle instead of filename to overview builder --- contrib/addtiffo/addtiffo.c | 21 +++++++++++++++++---- contrib/addtiffo/tif_overview.c | 24 ++++++++---------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/contrib/addtiffo/addtiffo.c b/contrib/addtiffo/addtiffo.c index 4cfb1f67..5fbbe292 100644 --- a/contrib/addtiffo/addtiffo.c +++ b/contrib/addtiffo/addtiffo.c @@ -1,5 +1,5 @@ /****************************************************************************** - * $Id: addtiffo.c,v 1.1 1999-08-17 01:47:59 warmerda Exp $ + * $Id: addtiffo.c,v 1.2 2000-01-28 15:36:38 warmerda Exp $ * * Project: GeoTIFF Overview Builder * Purpose: Mainline for building overviews in a TIFF file. @@ -28,7 +28,10 @@ ****************************************************************************** * * $Log: addtiffo.c,v $ - * Revision 1.1 1999-08-17 01:47:59 warmerda + * Revision 1.2 2000-01-28 15:36:38 warmerda + * pass TIFF handle instead of filename to overview builder + * + * Revision 1.1 1999/08/17 01:47:59 warmerda * New * * Revision 1.1 1999/03/12 17:46:32 warmerda @@ -45,7 +48,7 @@ #include #include "tiffio.h" -void TIFFBuildOverviews( const char *, int, int *, int ); +void TIFFBuildOverviews( TIFF *, int, int *, int ); /************************************************************************/ /* main() */ @@ -57,6 +60,7 @@ int main( int argc, char ** argv ) int anOverviews[100]; int nOverviewCount = 0; int bUseSubIFD = 0; + TIFF *hTIFF; /* -------------------------------------------------------------------- */ /* Usage: */ @@ -102,7 +106,16 @@ int main( int argc, char ** argv ) /* -------------------------------------------------------------------- */ /* Build the overview. */ /* -------------------------------------------------------------------- */ - TIFFBuildOverviews( argv[1], nOverviewCount, anOverviews, bUseSubIFD ); + hTIFF = TIFFOpen( argv[1], "r+" ); + if( hTIFF == NULL ) + { + fprintf( stderr, "TIFFOpen(%s) failed.\n", argv[1] ); + exit( 1 ); + } + + TIFFBuildOverviews( hTIFF, nOverviewCount, anOverviews, bUseSubIFD ); + + TIFFClose( hTIFF ); /* -------------------------------------------------------------------- */ /* Optionally test for memory leaks. */ diff --git a/contrib/addtiffo/tif_overview.c b/contrib/addtiffo/tif_overview.c index ad59019e..4c5746af 100644 --- a/contrib/addtiffo/tif_overview.c +++ b/contrib/addtiffo/tif_overview.c @@ -1,5 +1,5 @@ /****************************************************************************** - * $Id: tif_overview.c,v 1.1 2000-01-28 15:04:03 warmerda Exp $ + * $Id: tif_overview.c,v 1.2 2000-01-28 15:36:38 warmerda Exp $ * * Project: TIFF Overview Builder * Purpose: Library function for building overviews in a TIFF file. @@ -45,7 +45,10 @@ ****************************************************************************** * * $Log: tif_overview.c,v $ - * Revision 1.1 2000-01-28 15:04:03 warmerda + * Revision 1.2 2000-01-28 15:36:38 warmerda + * pass TIFF handle instead of filename to overview builder + * + * Revision 1.1 2000/01/28 15:04:03 warmerda * New * */ @@ -68,7 +71,7 @@ # define MAX(a,b) ((a>b) ? a : b) #endif -void TIFFBuildOverviews( const char *, int, int *, int ); +void TIFFBuildOverviews( TIFF *, int, int *, int ); /************************************************************************/ /* TIFF_WriteOverview() */ @@ -316,8 +319,7 @@ void TIFF_ProcessFullResBlock( TIFF *hTIFF, int nPlanarConfig, /* overviews. */ /************************************************************************/ -void TIFFBuildOverviews( const char * pszTIFFFilename, - int nOverviews, int * panOvList, +void TIFFBuildOverviews( TIFF *hTIFF, int nOverviews, int * panOvList, int bUseSubIFDs ) { @@ -327,20 +329,12 @@ void TIFFBuildOverviews( const char * pszTIFFFilename, nPlanarConfig, nSampleFormat; int bTiled, nSXOff, nSYOff, i; unsigned char *pabySrcTile; - TIFF *hTIFF; uint16 *panRedMap, *panGreenMap, *panBlueMap; TIFFErrorHandler pfnWarning; /* -------------------------------------------------------------------- */ /* Get the base raster size. */ /* -------------------------------------------------------------------- */ - hTIFF = TIFFOpen( pszTIFFFilename, "r+" ); - if( hTIFF == NULL ) - { - fprintf( stderr, "TIFFOpen(%s) failed.\n", pszTIFFFilename ); - exit( 1 ); - } - TIFFGetField( hTIFF, TIFFTAG_IMAGEWIDTH, &nXSize ); TIFFGetField( hTIFF, TIFFTAG_IMAGELENGTH, &nYSize ); @@ -357,7 +351,7 @@ void TIFFBuildOverviews( const char * pszTIFFFilename, TIFFError( "TIFFBuildOverviews", "File `%s' has samples of %d bits per sample. Sample\n" "sizes of less than 8 bits per sample are not supported.\n", - pszTIFFFilename, nBitsPerPixel ); + TIFFFileName(hTIFF), nBitsPerPixel ); return; } @@ -491,7 +485,5 @@ void TIFFBuildOverviews( const char * pszTIFFFilename, if( papoRawBIs != NULL ) _TIFFfree( papoRawBIs ); - TIFFClose( hTIFF ); - TIFFSetWarningHandler( pfnWarning ); }