/alps/ufodecode

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/ufodecode

« back to all changes in this revision

Viewing changes to test/ipedec.c

  • Committer: Matthias Vogelgesang
  • Date: 2012-07-05 09:12:38 UTC
  • Revision ID: matthias.vogelgesang@kit.edu-20120705091238-iqkhneqm6g7u1fzp
Add verbosity flag to output frequency and frame

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    printf("usage: ipedec [--num-rows=ROWS] [--clear-frame] FILE [FILE ...]\n\
41
41
Options:\n\
42
42
  -h, --help         Show this help message and exit\n\
 
43
  -v, --verbose      Print additional information on STDOUT\n\
43
44
  -r, --num-rows=N   N rows that are contained in the file\n\
44
45
  -c, --clear-frame  Clear the frame for each iteration\n");
45
46
}
46
47
 
47
 
static void process_file(const char *filename, int rows, int clear_frame)
 
48
static void process_file(const char *filename, int rows, int clear_frame, int verbose)
48
49
{
49
50
    char *buffer = NULL;
50
51
    size_t num_bytes = 0;
51
52
    int err = 0;
52
53
    uint16_t *pixels = (uint16_t *) malloc(2048 * 1088 * sizeof(uint16_t));
53
 
    uint32_t num_rows, frame_number, time_stamp;
 
54
    uint32_t num_rows, frame_number, time_stamp, old_time_stamp = 0;
54
55
    int num_frames = 0;
55
56
    struct timeval start, end;
56
57
    long seconds = 0L, useconds = 0L;
85
86
        err = ufo_decoder_get_next_frame(decoder, &pixels, &num_rows, &frame_number, &time_stamp, NULL);
86
87
        gettimeofday(&end, NULL);
87
88
 
 
89
        if (verbose) {
 
90
            int time_stamp_diff = 80 * (time_stamp - old_time_stamp);
 
91
 
 
92
            if (time_stamp_diff != 0)
 
93
                printf(" %d\t %d\n", 1000000000 / time_stamp_diff, num_rows);
 
94
 
 
95
            old_time_stamp = time_stamp;
 
96
        }
 
97
 
88
98
        if (!err) {
89
99
            num_frames++;
90
100
            seconds += end.tv_sec - start.tv_sec;
112
122
    static struct option long_options[] = {
113
123
        { "num-rows", required_argument, 0, 'r' },
114
124
        { "clear-frame", no_argument, 0, 'c' },
 
125
        { "verbose", no_argument, 0, 'v' },
115
126
        { "help", no_argument, 0, 'h' },
116
127
        { 0, 0, 0, 0 }
117
128
    };
118
129
 
119
130
    int clear_frame = 0;
 
131
    int verbose = 0;
120
132
    int rows = 1088;
121
133
 
122
134
    if (argc == 1) {
124
136
        return 0;
125
137
    }
126
138
 
127
 
    while ((getopt_ret = getopt_long(argc, (char *const *) argv, "r:ch", long_options, &index)) != -1) {
 
139
    while ((getopt_ret = getopt_long(argc, (char *const *) argv, "r:cvh", long_options, &index)) != -1) {
128
140
        switch (getopt_ret) {
129
141
            case 'r': 
130
142
                rows = atoi(optarg);
132
144
            case 'c':
133
145
                clear_frame = 1;
134
146
                break;
 
147
            case 'v':
 
148
                verbose = 1;
 
149
                break;
135
150
            case 'h':
136
151
                usage();
137
152
                return 0;
141
156
    }
142
157
 
143
158
    while (optind < argc)
144
 
        process_file(argv[optind++], rows, clear_frame);
 
159
        process_file(argv[optind++], rows, clear_frame, verbose);
145
160
 
146
161
    return 0;
147
162
}