| 1 | /****************************************************************************** |
| 2 | * Project: GeoTIFF Overview Builder |
| 3 | * Purpose: Mainline for building overviews in a TIFF file. |
| 4 | * Author: Frank Warmerdam, [email protected] |
| 5 | * |
| 6 | ****************************************************************************** |
| 7 | * Copyright (c) 1999, Frank Warmerdam |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be included |
| 17 | * in all copies or substantial portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 25 | * DEALINGS IN THE SOFTWARE. |
| 26 | ****************************************************************************** |
| 27 | * |
| 28 | * $Log: addtiffo.c,v $ |
| 29 | * Revision 1.8 2015-05-30 20:30:27 bfriesen |
| 30 | * * contrib/addtiffo/addtiffo.c (main): Possibly address Coverity |
| 31 | * 1024226 "Untrusted value as argument". |
| 32 | * |
| 33 | * Revision 1.7 2010-06-08 18:55:15 bfriesen |
| 34 | * * contrib: Add an emacs formatting mode footer to all source files |
| 35 | * so that emacs can be effectively used. |
| 36 | * |
| 37 | * Revision 1.6 2005/12/16 05:59:55 fwarmerdam |
| 38 | * Major upgrade to support YCbCr subsampled jpeg images |
| 39 | * |
| 40 | * Revision 1.4 2004/09/21 13:31:23 dron |
| 41 | * Add missed include string.h. |
| 42 | * |
| 43 | * Revision 1.3 2000/04/18 22:48:31 warmerda |
| 44 | * Added support for averaging resampling |
| 45 | * |
| 46 | * Revision 1.2 2000/01/28 15:36:38 warmerda |
| 47 | * pass TIFF handle instead of filename to overview builder |
| 48 | * |
| 49 | * Revision 1.1 1999/08/17 01:47:59 warmerda |
| 50 | * New |
| 51 | * |
| 52 | * Revision 1.1 1999/03/12 17:46:32 warmerda |
| 53 | * New |
| 54 | * |
| 55 | * Revision 1.2 1999/02/11 22:27:12 warmerda |
| 56 | * Added multi-sample support |
| 57 | * |
| 58 | * Revision 1.1 1999/02/11 18:12:30 warmerda |
| 59 | * New |
| 60 | */ |
| 61 | |
| 62 | #include "tiffio.h"cxx . . $ `<file>/libtiff/tiffio.h`/ |
| 63 | #include <stdio.h> |
| 64 | #include <stdlib.h> |
| 65 | #include <string.h> |
| 66 | |
| 67 | void TIFFBuildOverviewscxx . . $ TIFFBuildOverviews(9ab912ee29048cdd).(TIFFcxx . . $ TIFF# *, int, int *, int, const char *, |
| 68 | int (*)(double, void *), void *); |
| 69 | |
| 70 | /************************************************************************/ |
| 71 | /* main() */ |
| 72 | /************************************************************************/ |
| 73 | |
| 74 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) |
| 75 | |
| 76 | { |
| 77 | int anOverviews[100]; /* TODO: un-hardwire array length, flexible allocate |
| 78 | */ |
| 79 | int nOverviewCount = 0; |
| 80 | int bUseSubIFD = 0; |
| 81 | TIFFcxx . . $ TIFF# *hTIFF; |
| 82 | const char *pszResampling = "nearest"; |
| 83 | |
| 84 | /* -------------------------------------------------------------------- */ |
| 85 | /* Usage: */ |
| 86 | /* -------------------------------------------------------------------- */ |
| 87 | if (argc < 2) |
| 88 | { |
| 89 | printfcxx . . $ printf(581fddd72a8db8fc).("Usage: addtiffo [-r {nearest,average,mode}]\n" |
| 90 | " tiff_filename [resolution_reductions]\n" |
| 91 | "\n" |
| 92 | "Example:\n" |
| 93 | " %% addtiffo abc.tif 2 4 8 16\n"); |
| 94 | return (1); |
| 95 | } |
| 96 | |
| 97 | while (argv[1][0] == '-') |
| 98 | { |
| 99 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[1], "-subifd") == 0) |
| 100 | { |
| 101 | bUseSubIFD = 1; |
| 102 | argv++; |
| 103 | argc--; |
| 104 | } |
| 105 | else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[1], "-r") == 0) |
| 106 | { |
| 107 | argv += 2; |
| 108 | argc -= 2; |
| 109 | pszResampling = *argv; |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Incorrect parameters\n"); |
| 114 | return (1); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /* TODO: resampling mode parameter needs to be encoded in an integer from |
| 119 | * this point on */ |
| 120 | |
| 121 | /* -------------------------------------------------------------------- */ |
| 122 | /* Collect the user requested reduction factors. */ |
| 123 | /* -------------------------------------------------------------------- */ |
| 124 | while (nOverviewCount < argc - 2 && nOverviewCount < 100) |
| 125 | { |
| 126 | anOverviews[nOverviewCount] = atoicxx . . $ atoi(5c4306d8553b3696).(argv[nOverviewCount + 2]); |
| 127 | if ((anOverviews[nOverviewCount] <= 0) || |
| 128 | ((anOverviews[nOverviewCount] > 1024))) |
| 129 | { |
| 130 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Incorrect parameters\n"); |
| 131 | return (1); |
| 132 | } |
| 133 | nOverviewCount++; |
| 134 | } |
| 135 | |
| 136 | /* -------------------------------------------------------------------- */ |
| 137 | /* Default to four overview levels. It would be nicer if it */ |
| 138 | /* defaulted based on the size of the source image. */ |
| 139 | /* -------------------------------------------------------------------- */ |
| 140 | /* TODO: make it default based on the size of the source image */ |
| 141 | if (nOverviewCount == 0) |
| 142 | { |
| 143 | nOverviewCount = 4; |
| 144 | |
| 145 | anOverviews[0] = 2; |
| 146 | anOverviews[1] = 4; |
| 147 | anOverviews[2] = 8; |
| 148 | anOverviews[3] = 16; |
| 149 | } |
| 150 | |
| 151 | /* -------------------------------------------------------------------- */ |
| 152 | /* Build the overview. */ |
| 153 | /* -------------------------------------------------------------------- */ |
| 154 | hTIFF = TIFFOpencxx . . $ TIFFOpen(fb7c76ec38d30b79).(argv[1], "r+"); |
| 155 | if (hTIFF == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 156 | { |
| 157 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "TIFFOpen(%s) failed.\n", argv[1]); |
| 158 | return (1); |
| 159 | } |
| 160 | |
| 161 | TIFFBuildOverviewscxx . . $ TIFFBuildOverviews(9ab912ee29048cdd).(hTIFF, nOverviewCount, anOverviews, bUseSubIFD, |
| 162 | pszResampling, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 163 | |
| 164 | TIFFClosecxx . . $ TIFFClose(1330bca35e52c9b0).(hTIFF); |
| 165 | |
| 166 | /* -------------------------------------------------------------------- */ |
| 167 | /* Optionally test for memory leaks. */ |
| 168 | /* -------------------------------------------------------------------- */ |
| 169 | #ifdef DBMALLOC |
| 170 | malloc_dump(1); |
| 171 | #endif |
| 172 | |
| 173 | return (0); |
| 174 | } |