/alps/ufodecode

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/ufodecode

« back to all changes in this revision

Viewing changes to test/ipedec.c

  • Committer: Matthias Vogelgesang
  • Date: 2012-10-22 13:22:51 UTC
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: matthias.vogelgesang@kit.edu-20121022132251-c1nq4q268cmgy7wf
Add -s/--superimpose flag to color borders

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
    int print_frame_rate;
17
17
    int print_num_rows;
18
18
    int cont;
 
19
    int superimpose;
19
20
} Options;
20
21
 
21
22
static int
55
56
  -r, --num-rows=N          N rows that are contained in the file\n\
56
57
  -c, --clear-frame         Clear the frame for each iteration\n\
57
58
  -d, --dry-run             Do not save the frames\n\
 
59
  -s, --superimpose=C       Superimpose frames on top of the first with color C as borders\n\
58
60
  -f, --print-frame-rate    Print frame rate on STDOUT\n\
59
61
      --print-num-rows      Print number of rows on STDOUT\n\
60
62
      --continue            Continue decoding frames even when errors occur\n");
135
137
    t->useconds += end.tv_usec - t->start.tv_usec;
136
138
}
137
139
 
 
140
static void
 
141
superimpose_on_top (uint16_t *top, uint16_t *bottom, uint16_t color)
 
142
{
 
143
    int x, y;
 
144
    int in_void = top[0] == 0;
 
145
 
 
146
    for (y = 0; y < 1088; y++) {
 
147
        int offset = y * 2048;
 
148
 
 
149
        if ((in_void && top[offset] != 0) ||
 
150
            (!in_void && top[offset] == 0)) {
 
151
            in_void = 1 - in_void;
 
152
 
 
153
            for (x = 0; x < 2048; x++)
 
154
                top[offset++] = color;
 
155
        } 
 
156
        else {
 
157
            for (x = 0; x < 2048; x++, offset++) {
 
158
                if (top[offset] == 0) 
 
159
                    top[offset] = bottom[offset];
 
160
            }
 
161
        }
 
162
    }
 
163
}
 
164
 
138
165
static int
139
166
process_file(const char *filename, Options *opts)
140
167
{
143
170
    Timer           *timer;
144
171
    char            *buffer;
145
172
    size_t           num_bytes;
 
173
    size_t           frame_size;
 
174
    uint16_t        *orig;
146
175
    uint16_t        *pixels;
147
176
    uint32_t         time_stamp, old_time_stamp;
148
177
    int              n_frames;
151
180
    char             output_name[256];
152
181
    float            mtime;
153
182
 
 
183
    frame_size = 2048 * 1088 * sizeof(uint16_t);
154
184
    error = read_raw_file(filename, &buffer, &num_bytes);
155
185
 
156
186
    if (error) {
175
205
        }
176
206
    }
177
207
 
 
208
    if (opts->superimpose)
 
209
        orig = (uint16_t *) malloc(frame_size);
 
210
 
 
211
    pixels = (uint16_t *) malloc(frame_size);
 
212
 
178
213
    timer = timer_new ();
179
 
    pixels = (uint16_t *) malloc(2048 * 1088 * sizeof(uint16_t));
180
214
    n_frames = 0;
181
215
    old_time_stamp = 0;
182
216
 
183
217
    while (error != EIO) {
184
 
        if (opts->clear_frame)
185
 
            memset(pixels, 0, 2048 * 1088 * sizeof(uint16_t));
 
218
        if (opts->clear_frame || opts->superimpose)
 
219
            memset(pixels, 0, frame_size);
186
220
 
187
221
        timer_start (timer);
188
222
        error = ufo_decoder_get_next_frame(decoder, &pixels, &meta);
189
223
        timer_stop (timer);
190
224
        n_frames++;
191
225
 
 
226
        if (opts->superimpose && n_frames == 1)
 
227
            memcpy (orig, pixels, frame_size);
 
228
 
192
229
        if (!error) {
193
 
 
194
230
            if (opts->verbose) {
195
231
                printf("Status for frame %i\n", n_frames);
196
232
                print_meta_data (&meta);
209
245
            if (opts->print_frame_rate || opts->print_num_rows)
210
246
                printf("\n");
211
247
 
 
248
            if (opts->superimpose)
 
249
                superimpose_on_top (pixels, orig, opts->superimpose);
 
250
 
212
251
            if (!opts->dry_run)
213
252
                fwrite(pixels, sizeof(uint16_t), 2048 * 1088, fp);
214
253
        }
246
285
    int getopt_ret, index;
247
286
 
248
287
    enum {
 
288
        SUPERIMPOSE  = 's',
249
289
        CLEAR_FRAME  = 'c',
250
290
        DRY_RUN      = 'd',
251
291
        FRAME_RATE   = 'f',
265
305
        { "print-frame-rate",   no_argument, 0, FRAME_RATE },
266
306
        { "continue",           no_argument, 0, CONTINUE },
267
307
        { "print-num-rows",     no_argument, 0, NUM_ROWS },
 
308
        { "superimpose",        required_argument, 0, SUPERIMPOSE },
268
309
        { 0, 0, 0, 0 }
269
310
    };
270
311
 
275
316
        .clear_frame = 0,
276
317
        .print_frame_rate = 0,
277
318
        .print_num_rows = 0,
278
 
        .cont = 0
 
319
        .cont = 0,
 
320
        .superimpose = 0
279
321
    };
280
322
 
281
 
    while ((getopt_ret = getopt_long(argc, (char *const *) argv, "r:cvhdf", long_options, &index)) != -1) {
 
323
    while ((getopt_ret = getopt_long(argc, (char *const *) argv, "r:s:cvhdf", long_options, &index)) != -1) {
282
324
        switch (getopt_ret) {
283
325
            case SET_NUM_ROWS:
284
326
                opts.rows = atoi(optarg);
303
345
                break;
304
346
            case NUM_ROWS:
305
347
                opts.print_num_rows = 1;
 
348
            case SUPERIMPOSE:
 
349
                opts.superimpose = atoi(optarg);
 
350
                break;
306
351
            default:
307
352
                break;
308
353
        }
309
354
    }
310
355
 
 
356
    if (opts.clear_frame && opts.superimpose) {
 
357
        fprintf(stderr, "Error: --clear-frame and --superimpose are mutual exclusive\n");
 
358
        return 1;
 
359
    }
 
360
 
311
361
    if (optind == argc) {
312
362
        printf("ipedec: no input files\n");
313
363
        return 1;