/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: 2011-12-02 07:49:09 UTC
  • Revision ID: matthias.vogelgesang@kit.edu-20111202074909-d1ymsoe4h3zg7gft
Rename to `ufodecode`

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#include <stdlib.h>
4
4
#include <string.h>
5
5
#include <errno.h>
6
 
#include "libipe.h"
7
 
#include "libipe-private.h"
 
6
#include "ufodecode.h"
 
7
#include "ufodecode-private.h"
8
8
#include "config.h"
 
9
 
 
10
#ifdef HAVE_SSE
9
11
#include <xmmintrin.h>
 
12
#endif
10
13
 
11
14
#define IPECAMERA_NUM_CHANNELS 16
12
15
#define IPECAMERA_PIXELS_PER_CHANNEL 128
31
34
 *
32
35
 * \param height Number of rows that are expected in the data stream
33
36
 * \param raw The data stream from the camera or NULL if set later with
34
 
 * ipe_decoder_set_raw_data.
 
37
 * ufo_decoder_set_raw_data.
35
38
 * \param num_bytes Size of the data stream buffer in bytes
36
39
 *
37
40
 * \return A new decoder instance that can be used to iterate over the frames
38
 
 * using ipe_decoder_get_next_frame.
 
41
 * using ufo_decoder_get_next_frame.
39
42
 */
40
 
ipe_decoder ipe_decoder_new(uint32_t height, uint32_t *raw, size_t num_bytes)
 
43
ufo_decoder ufo_decoder_new(uint32_t height, uint32_t *raw, size_t num_bytes)
41
44
{
42
 
    ipe_decoder decoder = malloc(sizeof(struct ipe_decoder_t));
 
45
    ufo_decoder decoder = malloc(sizeof(struct ufo_decoder_t));
43
46
    if (decoder == NULL)
44
47
        return NULL;
45
48
 
46
49
    decoder->height = height;
47
 
    ipe_decoder_set_raw_data(decoder, raw, num_bytes);
 
50
    ufo_decoder_set_raw_data(decoder, raw, num_bytes);
48
51
    return decoder;
49
52
}
50
53
 
52
55
/**
53
56
 * \brief Release decoder instance
54
57
 *
55
 
 * \param decoder An ipe_decoder instance
 
58
 * \param decoder An ufo_decoder instance
56
59
 */
57
 
void ipe_decoder_free(ipe_decoder decoder)
 
60
void ufo_decoder_free(ufo_decoder decoder)
58
61
{
59
62
    free(decoder);
60
63
}
63
66
/**
64
67
 * \brief Set raw data stream
65
68
 *
66
 
 * \param decoder An ipe_decoder instance
 
69
 * \param decoder An ufo_decoder instance
67
70
 * \param raw Raw data stream
68
71
 * \param num_bytes Size of data stream buffer in bytes
69
72
 */
70
 
void ipe_decoder_set_raw_data(ipe_decoder decoder, uint32_t *raw, size_t num_bytes)
 
73
void ufo_decoder_set_raw_data(ufo_decoder decoder, uint32_t *raw, size_t num_bytes)
71
74
{
72
75
    decoder->raw = raw;
73
76
    decoder->num_bytes = num_bytes;
74
77
    decoder->current_pos = 0;
75
78
}
76
79
 
77
 
static int ipe_decode_frame(uint16_t *pixel_buffer, uint32_t *raw, int num_rows, int *offset)
 
80
static int ufo_decode_frame(uint16_t *pixel_buffer, uint32_t *raw, int num_rows, int *offset)
78
81
{
79
82
    static int channel_order[IPECAMERA_NUM_CHANNELS] = { 15, 13, 14, 12, 10, 8, 11, 7, 9, 6, 5, 2, 4, 3, 0, 1 };
80
83
 
86
89
    const int bytes = 43;
87
90
 
88
91
#ifdef HAVE_SSE
89
 
    const uint32_t mask = 0x3FF;
90
 
    __m128i mmask = _mm_set_epi32(mask, mask, mask, mask);
 
92
    __m128i mask = _mm_set_epi32(0x3FF, 0x3FF, 0x3FF, 0x3FF);
91
93
    __m128i packed;
92
94
    __m128i tmp1, tmp2;
93
95
    uint32_t result[4] __attribute__ ((aligned (16))) = {0};
125
127
            packed = _mm_set_epi32(raw[i], raw[i+1], raw[i+2], raw[i+3]);
126
128
 
127
129
            tmp1 = _mm_srli_epi32(packed, 20);
128
 
            tmp2 = _mm_and_si128(tmp1, mmask);
 
130
            tmp2 = _mm_and_si128(tmp1, mask);
129
131
            _mm_storeu_si128((__m128i*) result, tmp2);
130
132
            pixel_buffer[base] = result[0];
131
133
            pixel_buffer[base+3] = result[1];
133
135
            pixel_buffer[base+9] = result[3];
134
136
 
135
137
            tmp1 = _mm_srli_epi32(packed, 10);
136
 
            tmp2 = _mm_and_si128(tmp1, mmask);
 
138
            tmp2 = _mm_and_si128(tmp1, mask);
137
139
            _mm_storeu_si128((__m128i*) result, tmp2);
138
140
            pixel_buffer[base+1] = result[0];
139
141
            pixel_buffer[base+4] = result[1];
140
142
            pixel_buffer[base+7] = result[2];
141
143
            pixel_buffer[base+10] = result[3];
142
144
 
143
 
            tmp1 = _mm_and_si128(packed, mmask);
 
145
            tmp1 = _mm_and_si128(packed, mask);
144
146
            _mm_storeu_si128((__m128i*) result, tmp1);
145
147
            pixel_buffer[base+2] = result[0];
146
148
            pixel_buffer[base+5] = result[1];
200
202
 * \param width Width of frame in pixels
201
203
 * \param heigh Height of frame in pixels
202
204
 */
203
 
void ipe_deinterlace_interpolate(const uint16_t *in, uint16_t *out, int width, int height)
 
205
void ufo_deinterlace_interpolate(const uint16_t *in, uint16_t *out, int width, int height)
204
206
{
205
207
    const size_t row_size_bytes = width * sizeof(uint16_t);
206
208
 
230
232
 * \param width Width of frame in pixels
231
233
 * \param heigh Height of frame in pixels
232
234
 */
233
 
void ipe_deinterlace_weave(const uint16_t *in1, const uint16_t *in2, uint16_t *out, int width, int height)
 
235
void ufo_deinterlace_weave(const uint16_t *in1, const uint16_t *in2, uint16_t *out, int width, int height)
234
236
{
235
237
    const size_t row_size_bytes = width * sizeof(uint16_t);
236
238
    for (int row = 0; row < height; row++) {
248
250
 * This function tries to decode the next frame in the currently set raw data
249
251
 * stream. 
250
252
 *
251
 
 * \param decoder An ipe_decoder instance
 
253
 * \param decoder An ufo_decoder instance
252
254
 * \param pixels If pointer with NULL content is passed, a new buffer is
253
255
 * allocated otherwise, this user-supplied buffer is used.
254
256
 * \param frame_number Frame number as reported in the header
258
260
 * NULL was passed but no memory could be allocated, EILSEQ if data stream is
259
261
 * corrupt and EFAULT if pixels is a NULL-pointer.
260
262
 */
261
 
int ipe_decoder_get_next_frame(ipe_decoder decoder, uint16_t **pixels, uint32_t *frame_number, uint32_t *time_stamp)
 
263
int ufo_decoder_get_next_frame(ufo_decoder decoder, uint16_t **pixels, uint32_t *frame_number, uint32_t *time_stamp)
262
264
{
263
265
 
264
266
    uint32_t *raw = decoder->raw;
301
303
    pos += 8;
302
304
#endif
303
305
 
304
 
    err = ipe_decode_frame(*pixels, raw + pos, decoder->height, &advance);
 
306
    err = ufo_decode_frame(*pixels, raw + pos, decoder->height, &advance);
305
307
    if (err)
306
308
        return EILSEQ;
307
309