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