2
0

addtiffo.c 6.0 KB

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