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