Diff of /tools/PTmasker.c [35f549] .. [a07dce]  Maximize  Restore

Switch to unified view

a/tools/PTmasker.c b/tools/PTmasker.c
...
...
46
#include "filter.h"
46
#include "filter.h"
47
#include "panorama.h"
47
#include "panorama.h"
48
#include "PTcommon.h"
48
#include "PTcommon.h"
49
#include "ptstitch.h"
49
#include "ptstitch.h"
50
#include "pttiff.h"
50
#include "pttiff.h"
51
51
52
52
#define PT_MASKER_USAGE "PTmasker [options] <tiffFiles>+\n\n"   \
53
#define PT_MASKER_USAGE "PTmasker [options] <tiffFiles>+\n\n"   \
53
                         "Options:\n"\
54
                         "Options:\n"\
54
                         "\t-p <prefix>\tPrefix for output files (defaults to masked%%4d)\n"\
55
                         "\t-p <prefix>\tPrefix for output files (defaults to masked%%4d)\n"\
55
                         "\t-e <feather>\tSize of the feather (defaults to zero)\n"\
56
                         "\t-e <feather>\tSize of the feather (defaults to zero)\n"\
56
                         "\t-f\t\tForce processing (do not stop at warnings)\n"\
57
                         "\t-f\t\tForce processing (do not stop at warnings)\n"\
57
                         "\t-x\t\tDelete source files (use with care)\n"\
58
                         "\t-x\t\tDelete source files (use with care)\n"\
58
                         "\t-q\t\tQuiet run\n"\
59
                         "\t-q\t\tQuiet run\n"\
59
                         "\t-h\t\tShow this message\n"\
60
                         "\t-h\t\tShow this message\n"\
61
                         "\t-z\t\tEnable Extended depth of field\n"\
62
                         "\t-m\t\tFocus estimation mask type\n"\
63
                         "\t\t\t0  hard-edged masks, mutually exclusive\n"\
64
                         "\t\t\t1  hard-edged masks, stack of nested masks\n"\
65
                         "\t\t\t2  blended masks, stack of nested masks\n"\
66
                         "\t\t\t\t2 is default & strongly recommended -- this option includes a smoothing computation that seems to help a lot.\n"\
67
                         "\t-w <integer>\t\tFocus estimation window size. Only available if -z\n"\
68
                         "\t\t\tRecommended value is 0.5% of image width, e.g. 4 pixels for an 800-pixel image\n."\
69
                         "\t\t\tComputation cost for focus estimation increases proportional to N^2.  Default w4.\n"\
70
                         "\t-s <integer>\t\tSmoothing window size,  Only available if -z\n"\
71
                         "\t\t\tRecommended value is 0.5% of image width, e.g. 4 pixels for an 800-pixel image\n."\
72
                         "\t\t\tComputation cost for focus estimation increases proportional to N^2.  Default w4.\n"\
60
                         "\n"
73
                         "\n"
61
74
62
#define PT_MASKER_VERSION "PTmasker Version " VERSION ", originally written by Helmut Dersch, rewritten by Daniel M German\n"
75
#define PT_MASKER_VERSION "PTmasker Version " VERSION ", originally written by Helmut Dersch, rewritten by Daniel M German\n"
76
77
#define Z_DEFAULT_MASK_TYPE 2
78
#define Z_DEFAULT_WINDOW_SIZE 4
79
#define Z_DEFAULT_SMOOTHING_WINDOW_SIZE 4
63
80
64
#define DEFAULT_PREFIX    "masked"
81
#define DEFAULT_PREFIX    "masked"
65
82
66
int main(int argc,char *argv[])
83
int main(int argc,char *argv[])
67
{
84
{
...
...
74
    int filesCount;
91
    int filesCount;
75
    int base = 0;
92
    int base = 0;
76
    int ptForceProcessing = 0;
93
    int ptForceProcessing = 0;
77
    int feather = 0;
94
    int feather = 0;
78
    int ptDeleteSources = 0;
95
    int ptDeleteSources = 0;
96
    int enableFocusEstimation = 0;
97
    int focusEstimationWindowSize = 0;
98
    int focusEstimationMaskType = -1;
99
    int focusEstimationSmoothingWindowSize = 0;
79
100
80
    ptrInputFiles = NULL;
101
    ptrInputFiles = NULL;
81
102
82
    counter = 0;
103
    counter = 0;
83
    outputPrefix[0] = 0;
104
    outputPrefix[0] = 0;
84
105
85
    printf(PT_MASKER_VERSION);
106
    printf(PT_MASKER_VERSION);
86
107
87
    while ((opt = getopt(argc, argv, "p:fqhxe:")) != -1) {
108
    while ((opt = getopt(argc, argv, "p:fqhxe:zw:s:m:")) != -1) {
88
109
89
        // o and f -> set output file
110
        // o and f -> set output file
90
        // h       -> help
111
        // h       -> help
91
        // q       -> quiet?
112
        // q       -> quiet?
92
        // k       -> base image, defaults to first
113
        // k       -> base image, defaults to first
...
...
98
        if (errno != 0) {
119
        if (errno != 0) {
99
        PrintError("Illegal value for feather");
120
        PrintError("Illegal value for feather");
100
        return -1;
121
        return -1;
101
        }
122
        }
102
        break;
123
        break;
124
  case 'w':
125
      focusEstimationWindowSize = strtol(optarg, NULL, 10);
126
      if (errno != 0 || focusEstimationWindowSize <= 0) {
127
      PrintError("Illegal value for focus estimation window size [%s]", optarg);
128
      return -1;
129
      }
130
      break;
131
  case 'm':
132
      focusEstimationMaskType = strtol(optarg, NULL, 10);
133
      if (errno != 0 || focusEstimationMaskType  <0 || focusEstimationMaskType > 2) {
134
        PrintError("Illegal value for focus estimation window type [%s]", optarg);
135
      return -1;
136
      }
137
      break;
138
  case 's':
139
      focusEstimationSmoothingWindowSize = strtol(optarg, NULL, 10);
140
      if (errno != 0 || focusEstimationSmoothingWindowSize <= 0) {
141
      PrintError("Illegal value for focus estimation smoothing window size [%s]", optarg);
142
      return -1;
143
      }
144
      break;
145
103
    case 'p':
146
    case 'p':
104
        if (strlen(optarg) < MAX_PATH_LENGTH) {
147
        if (strlen(optarg) < MAX_PATH_LENGTH) {
105
        strcpy(outputPrefix, optarg);
148
        strcpy(outputPrefix, optarg);
106
        } else {
149
        } else {
107
        PrintError("Illegal length for output prefix");
150
        PrintError("Illegal length for output prefix");
108
        return -1;
151
        return -1;
109
        }
152
        }
110
        break;
153
        break;
154
        case 'z':
155
      enableFocusEstimation = 1;
156
            break;
111
        case 'f':
157
        case 'f':
112
        ptForceProcessing = 1;
158
        ptForceProcessing = 1;
113
            break;
159
            break;
114
        case 'q':
160
        case 'q':
115
            ptQuietFlag = 1;
161
            ptQuietFlag = 1;
...
...
119
            break;
165
            break;
120
        case 'h':
166
        case 'h':
121
            printf(PT_MASKER_USAGE);
167
            printf(PT_MASKER_USAGE);
122
            exit(0);
168
            exit(0);
123
        default:
169
        default:
170
            printf(PT_MASKER_USAGE);
171
            exit(1);
124
            break;
172
            break;
125
        }
173
        }
126
    }
174
    }
127
  
175
  
128
    // check if an output prefix was given
176
    // check if an output prefix was given
129
    if (!(*outputPrefix)) {
177
    if (!(*outputPrefix)) {
130
        strcpy(outputPrefix, "masked");
178
        strcpy(outputPrefix, "masked");
131
    }
179
    }
132
180
133
    filesCount = argc - optind;
181
    filesCount = argc - optind;
182
134
  
183
  
135
    if (filesCount < 1) {
184
    if (filesCount < 1) {
136
        PrintError("No files specified in the command line");
185
        PrintError("No files specified in the command line");
137
        fprintf(stderr, PT_MASKER_USAGE);
186
        fprintf(stderr, PT_MASKER_USAGE);
138
        return -1;
187
        return -1;
139
    }
188
    }
189
190
    if (enableFocusEstimation == 0) {
191
  if (focusEstimationWindowSize != 0 ||
192
      focusEstimationSmoothingWindowSize != 0 ||
193
      focusEstimationMaskType != -1)  {
194
      PrintError("You should specify -z option in order to use options -m -w  or -s");
195
      return -1;
196
  }
197
    } else {
198
  if (feather == 0) {
199
      PrintError("-z requires feathering (use -e)");
200
      return -1;
201
  }
202
203
  if (filesCount == 1) {
204
      PrintError("-z requires more than one file, disabing -z");
205
      enableFocusEstimation = 0;
206
  }
207
  // At this point we know we are to do Z processing
208
  // set defaults if no values are given
209
210
  if (focusEstimationWindowSize == 0)
211
      focusEstimationWindowSize = Z_DEFAULT_WINDOW_SIZE;
212
  if (focusEstimationSmoothingWindowSize == 0)
213
      focusEstimationSmoothingWindowSize = Z_DEFAULT_SMOOTHING_WINDOW_SIZE;
214
  if (focusEstimationMaskType == -1)
215
      focusEstimationMaskType =  Z_DEFAULT_MASK_TYPE;
216
    }
217
140
    // Allocate memory for filenames
218
    // Allocate memory for filenames
141
    if ((ptrInputFiles = calloc(filesCount, sizeof(fullPath))) == NULL || 
219
    if ((ptrInputFiles = calloc(filesCount, sizeof(fullPath))) == NULL || 
142
        (ptrOutputFiles = calloc(filesCount, sizeof(fullPath))) == NULL)        {
220
        (ptrOutputFiles = calloc(filesCount, sizeof(fullPath))) == NULL)        {
143
        PrintError("Not enough memory");
221
        PrintError("Not enough memory");
144
        return -1;
222
        return -1;
...
...
194
    } else
272
    } else
195
        return 1;
273
        return 1;
196
274
197
    }
275
    }
198
276
277
    if (enableFocusEstimation)  {
278
  ZCombSetFocusWindowHalfwidth(focusEstimationWindowSize);
279
  ZCombSetSmoothingWindowHalfwidth(focusEstimationSmoothingWindowSize);
280
  ZCombSetMaskType(focusEstimationMaskType);
281
  ZCombSetEnabled();
282
    }
283
284
285
199
    if (panoStitchReplaceMasks(ptrInputFiles, ptrOutputFiles, filesCount,
286
    if (panoStitchReplaceMasks(ptrInputFiles, ptrOutputFiles, filesCount,
200
                   feather) != 0) {
287
                   feather) != 0) {
201
    PrintError("Could not create stitching masks");
288
    PrintError("Could not create stitching masks");
202
    return -1;
289
    return -1;
203
    }
290
    }