/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 src/ufodecode.c

  • Committer: Matthias Vogelgesang
  • Date: 2012-07-16 12:34:00 UTC
  • Revision ID: matthias.vogelgesang@kit.edu-20120716123400-7nx0fhwauzg9w121
Clean up source a bit

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
#define CHECKS
14
14
 
15
 
#define IPECAMERA_NUM_ROWS 1088
16
 
#define IPECAMERA_NUM_CHANNELS 16 /**< Number of channels per row */
17
 
#define IPECAMERA_PIXELS_PER_CHANNEL 128 /**< Number of pixels per channel */
 
15
#define IPECAMERA_NUM_ROWS              1088
 
16
#define IPECAMERA_NUM_CHANNELS          16      /**< Number of channels per row */
 
17
#define IPECAMERA_PIXELS_PER_CHANNEL    128     /**< Number of pixels per channel */
18
18
#define IPECAMERA_WIDTH (IPECAMERA_NUM_CHANNELS * IPECAMERA_PIXELS_PER_CHANNEL) /**< Total pixel width of row */
19
19
 
20
20
typedef struct {
69
69
 * \return A new decoder instance that can be used to iterate over the frames
70
70
 * using ufo_decoder_get_next_frame.
71
71
 */
72
 
ufo_decoder ufo_decoder_new(int32_t height, uint32_t width, uint32_t *raw, size_t num_bytes)
 
72
ufo_decoder
 
73
ufo_decoder_new (int32_t height, uint32_t width, uint32_t *raw, size_t num_bytes)
73
74
{
74
75
    if (width % IPECAMERA_PIXELS_PER_CHANNEL)
75
76
        return NULL;
91
92
 *
92
93
 * \param decoder An ufo_decoder instance
93
94
 */
94
 
void ufo_decoder_free(ufo_decoder decoder)
 
95
void
 
96
ufo_decoder_free(ufo_decoder decoder)
95
97
{
96
98
    free(decoder);
97
99
}
103
105
 * \param raw Raw data stream
104
106
 * \param num_bytes Size of data stream buffer in bytes
105
107
 */
106
 
void ufo_decoder_set_raw_data(ufo_decoder decoder, uint32_t *raw, size_t num_bytes)
 
108
void
 
109
ufo_decoder_set_raw_data(ufo_decoder decoder, uint32_t *raw, size_t num_bytes)
107
110
{
108
111
    decoder->raw = raw;
109
112
    decoder->num_bytes = num_bytes;
110
113
    decoder->current_pos = 0;
111
114
}
112
115
 
113
 
static int ufo_decode_frame_channels_v0(ufo_decoder decoder, 
114
 
        uint16_t *pixel_buffer, uint16_t *cmask, uint32_t *raw, 
115
 
        size_t num_words, size_t *offset)
 
116
static int
 
117
ufo_decode_frame_channels_v0(ufo_decoder     decoder, 
 
118
                             uint16_t       *pixel_buffer, 
 
119
                             uint16_t       *cmask, 
 
120
                             uint32_t       *raw, 
 
121
                             size_t          num_words, 
 
122
                             size_t         *offset)
116
123
{
117
124
    static int channel_order[IPECAMERA_NUM_CHANNELS] = { 15, 13, 14, 12, 10, 8, 11, 7, 9, 6, 5, 2, 4, 3, 0, 1 };
118
125
    static int channel_size = (2 + IPECAMERA_PIXELS_PER_CHANNEL / 3);
251
258
    return 0;
252
259
}
253
260
 
254
 
static int ufo_decode_frame_channels_v4(ufo_decoder decoder, 
255
 
        uint16_t *pixel_buffer, uint16_t *cmask, uint32_t *raw, 
256
 
        size_t num_words, size_t num_rows, size_t *offset)
 
261
static int
 
262
ufo_decode_frame_channels_v4(ufo_decoder     decoder,
 
263
                             uint16_t       *pixel_buffer, 
 
264
                             uint16_t       *cmask, 
 
265
                             uint32_t       *raw, 
 
266
                             size_t          num_words, 
 
267
                             size_t          num_rows, 
 
268
                             size_t         *offset)
257
269
{
258
270
    static const int channel_order[IPECAMERA_NUM_CHANNELS] = { 15, 13, 14, 12, 10, 8, 11, 7, 9, 6, 5, 2, 4, 3, 0, 1 };
259
271
    static const int channel_size = (2 + IPECAMERA_PIXELS_PER_CHANNEL / 3);
394
406
    return 0;
395
407
}
396
408
 
397
 
static int ufo_decode_frame_channels_v5(ufo_decoder decoder, 
398
 
        uint16_t *pixel_buffer, uint16_t *cmask, uint32_t *raw, 
399
 
        size_t num_words, size_t num_rows, size_t *offset)
 
409
static int
 
410
ufo_decode_frame_channels_v5(ufo_decoder     decoder, 
 
411
                             uint16_t       *pixel_buffer, 
 
412
                             uint16_t       *cmask, 
 
413
                             uint32_t       *raw, 
 
414
                             size_t          num_words, 
 
415
                             size_t          num_rows, 
 
416
                             size_t         *offset)
400
417
{
401
418
    size_t base = 0, index = 0;
402
419
 
418
435
 
419
436
            index = header->row_number * IPECAMERA_WIDTH + header->pixel_number;
420
437
 
 
438
            /* TODO: this branch should be removed from the inner loop */
421
439
            if (header->pixel_size == 10) {
 
440
                /* Skip header + two zero-filled words */
422
441
                base += 3;
 
442
 
423
443
                pixel_buffer[index + 15*IPECAMERA_PIXELS_PER_CHANNEL] = 0x3ff & (raw[base] >> 22);
424
444
                pixel_buffer[index + 13*IPECAMERA_PIXELS_PER_CHANNEL] = 0x3ff & (raw[base] >> 12);
425
445
                pixel_buffer[index + 14*IPECAMERA_PIXELS_PER_CHANNEL] = 0x3ff & (raw[base] >> 2);
438
458
                pixel_buffer[index +  1*IPECAMERA_PIXELS_PER_CHANNEL] = 0x3ff & raw[base+4];
439
459
            }
440
460
            else if (header->pixel_size == 12) {
 
461
                /* Skip header + one zero-filled word */
441
462
                base += 2;
 
463
 
442
464
                pixel_buffer[index + 15*IPECAMERA_PIXELS_PER_CHANNEL] = 0xfff & (raw[base] >> 20);
443
465
                pixel_buffer[index + 13*IPECAMERA_PIXELS_PER_CHANNEL] = 0xfff & (raw[base] >> 8);
444
466
                pixel_buffer[index + 14*IPECAMERA_PIXELS_PER_CHANNEL] = (0xff & raw[base]) << 4 | (raw[base+1] >> 28);
455
477
                pixel_buffer[index +  3*IPECAMERA_PIXELS_PER_CHANNEL] = ((0xf & raw[base+4]) << 8) | (raw[base+5] >> 24);
456
478
                pixel_buffer[index +  0*IPECAMERA_PIXELS_PER_CHANNEL] = 0x3ff & (raw[base+5] >> 12);
457
479
                pixel_buffer[index +  1*IPECAMERA_PIXELS_PER_CHANNEL] = 0x3ff & raw[base+5];
458
 
                /* printf ("0x%x -> 0x%x\n", raw[base], 0xfff & (raw[base] >> 20)); */
459
480
             
460
481
                base += 1;
461
482
            }
464
485
                return 1;
465
486
            }
466
487
 
 
488
            /* Skip footer */
467
489
            base += 5;
468
490
        }
469
491
 
538
560
 *
539
561
 * \return number of decoded bytes or 0 in case of error
540
562
 */
541
 
size_t ufo_decoder_decode_frame(ufo_decoder decoder, uint32_t *raw, 
542
 
        size_t num_bytes, uint16_t *pixels, 
543
 
        uint32_t *num_rows, uint32_t *frame_number, uint32_t *time_stamp, 
544
 
        uint16_t *cmask)
 
563
size_t ufo_decoder_decode_frame(ufo_decoder  decoder,
 
564
                                uint32_t    *raw, 
 
565
                                size_t       num_bytes, 
 
566
                                uint16_t    *pixels, 
 
567
                                uint32_t    *num_rows, 
 
568
                                uint32_t    *frame_number,
 
569
                                uint32_t    *time_stamp, 
 
570
                                uint16_t    *cmask)
545
571
{
546
572
    int err = 0;
547
573
    size_t pos = 0;
629
655
 
630
656
#ifdef CHECKS
631
657
    CHECK_VALUE(raw[pos++], 0x0AAAAAAA);
632
 
    /* CHECK_VALUE(raw[pos++], 0x0BBBBBBB); */
633
658
    pos++;
634
659
    pos++; /* 0x840dffff expected */
635
660
    pos++; /* 0x0f001001 expected */
636
661
    pos++; /* 0x28000111 explains problems if status2 is wrong */
637
662
    pos++;
638
 
    /* CHECK_VALUE(raw[pos++], 0x0FFFFFFF); */
639
663
    CHECK_VALUE(raw[pos++], 0x00000000);
640
664
    CHECK_VALUE(raw[pos++], 0x01111111);
641
665
 
666
690
 * NULL was passed but no memory could be allocated, EILSEQ if data stream is
667
691
 * corrupt and EFAULT if pixels is a NULL-pointer.
668
692
 */
669
 
int ufo_decoder_get_next_frame(ufo_decoder decoder, uint16_t **pixels, 
670
 
        uint32_t *num_rows, uint32_t *frame_number, uint32_t *time_stamp, 
671
 
        uint16_t *cmask)
 
693
int ufo_decoder_get_next_frame(ufo_decoder    decoder, 
 
694
                               uint16_t     **pixels, 
 
695
                               uint32_t      *num_rows, 
 
696
                               uint32_t      *frame_number, 
 
697
                               uint32_t      *time_stamp, 
 
698
                               uint16_t      *cmask)
672
699
{
673
700
    uint32_t *raw = decoder->raw;
674
701
    size_t pos = decoder->current_pos;