125
process_file(const char *filename, int rows, int clear_frame, int verbose)
141
superimpose_on_top (uint16_t *top, uint16_t *bottom, uint16_t color)
144
int in_void = top[0] == 0;
146
for (y = 0; y < 1088; y++) {
147
int offset = y * 2048;
149
if ((in_void && top[offset] != 0) ||
150
(!in_void && top[offset] == 0)) {
151
in_void = 1 - in_void;
153
for (x = 0; x < 2048; x++)
154
top[offset++] = color;
157
for (x = 0; x < 2048; x++, offset++) {
158
if (top[offset] == 0)
159
top[offset] = bottom[offset];
166
process_file(const char *filename, Options *opts)
127
168
UfoDecoder *decoder;
128
169
UfoDecoderMeta meta = {0};
131
172
size_t num_bytes;
133
175
uint16_t *pixels;
134
176
uint32_t time_stamp, old_time_stamp;
137
180
char output_name[256];
183
frame_size = 2048 * 1088 * sizeof(uint16_t);
139
184
error = read_raw_file(filename, &buffer, &num_bytes);
142
187
fprintf(stderr, "Error reading %s: %s\n", filename, strerror(error));
146
decoder = ufo_decoder_new(rows, 2048, (uint32_t *) buffer, num_bytes);
191
decoder = ufo_decoder_new(opts->rows, 2048, (uint32_t *) buffer, num_bytes);
148
193
if (decoder == NULL) {
149
194
fprintf(stderr, "Failed to initialize decoder\n");
153
snprintf(output_name, 256, "%s.raw", filename);
154
fp = fopen(output_name, "wb");
157
fprintf(stderr, "Failed to open file for writing\n");
198
if (!opts->dry_run) {
199
snprintf(output_name, 256, "%s.raw", filename);
200
fp = fopen(output_name, "wb");
203
fprintf(stderr, "Failed to open file for writing\n");
208
if (opts->superimpose)
209
orig = (uint16_t *) malloc(frame_size);
211
pixels = (uint16_t *) malloc(frame_size);
161
213
timer = timer_new ();
162
pixels = (uint16_t *) malloc(2048 * 1088 * sizeof(uint16_t));
165
217
while (error != EIO) {
167
memset(pixels, 0, 2048 * 1088 * sizeof(uint16_t));
218
if (opts->clear_frame || opts->superimpose)
219
memset(pixels, 0, frame_size);
169
221
timer_start (timer);
170
222
error = ufo_decoder_get_next_frame(decoder, &pixels, &meta);
171
223
timer_stop (timer);
226
if (opts->superimpose && n_frames == 1)
227
memcpy (orig, pixels, frame_size);
175
231
printf("Status for frame %i\n", n_frames);
176
232
print_meta_data (&meta);
180
fwrite(pixels, sizeof(uint16_t), 2048 * 1088, fp);
182
else if (error != EIO)
183
fprintf(stderr, "Failed to decode frame %i\n", n_frames);
188
float mtime = timer->seconds * 1000.0 + timer->useconds / 1000.0;
189
printf("Decoded %i frames in %.5fms\n", n_frames, mtime);
235
if (opts->print_frame_rate) {
236
uint32_t diff = 80 * (meta.time_stamp - old_time_stamp);
238
printf("%-6d", 1000000000 / diff);
239
old_time_stamp = meta.time_stamp;
242
if (opts->print_num_rows)
243
printf("%d", meta.n_rows);
245
if (opts->print_frame_rate || opts->print_num_rows)
248
if (opts->superimpose)
249
superimpose_on_top (pixels, orig, opts->superimpose);
252
fwrite(pixels, sizeof(uint16_t), 2048 * 1088, fp);
254
else if (error != EIO) {
255
fprintf(stderr, "Failed to decode frame %i\n", n_frames);
258
/* Save the frame even though we know it is corrupted */
260
fwrite(pixels, sizeof(uint16_t), 2048 * 1088, fp);
271
mtime = timer->seconds * 1000.0 + timer->useconds / 1000.0;
272
printf("Decoded %i frames in %.5fms\n", n_frames, mtime);
193
277
timer_destroy (timer);
194
278
ufo_decoder_free(decoder);
280
return error == EIO ? 0 : error;
197
283
int main(int argc, char const* argv[])
199
285
int getopt_ret, index;
201
299
static struct option long_options[] = {
202
{ "num-rows", required_argument, 0, 'r' },
203
{ "clear-frame", no_argument, 0, 'c' },
204
{ "verbose", no_argument, 0, 'v' },
205
{ "help", no_argument, 0, 'h' },
300
{ "num-rows", required_argument, 0, SET_NUM_ROWS },
301
{ "clear-frame", no_argument, 0, CLEAR_FRAME },
302
{ "verbose", no_argument, 0, VERBOSE },
303
{ "help", no_argument, 0, HELP },
304
{ "dry-run", no_argument, 0, DRY_RUN },
305
{ "print-frame-rate", no_argument, 0, FRAME_RATE },
306
{ "continue", no_argument, 0, CONTINUE },
307
{ "print-num-rows", no_argument, 0, NUM_ROWS },
308
{ "superimpose", required_argument, 0, SUPERIMPOSE },
312
static Options opts = {
317
.print_frame_rate = 0,
213
while ((getopt_ret = getopt_long(argc, (char *const *) argv, "r:cvh", long_options, &index)) != -1) {
323
while ((getopt_ret = getopt_long(argc, (char *const *) argv, "r:s:cvhdf", long_options, &index)) != -1) {
214
324
switch (getopt_ret) {
326
opts.rows = atoi(optarg);
329
opts.clear_frame = 1;
341
opts.print_frame_rate = 1;
347
opts.print_num_rows = 1;
349
opts.superimpose = atoi(optarg);
356
if (opts.clear_frame && opts.superimpose) {
357
fprintf(stderr, "Error: --clear-frame and --superimpose are mutual exclusive\n");
232
361
if (optind == argc) {