diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2011-12-09 09:36:41 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2011-12-09 09:36:41 +0100 |
commit | abe088c58aeb876d1471fa99e0fc5c1d85cb1403 (patch) | |
tree | 025db8dd920e416dc6252b0a9bacfd630134d1cc | |
parent | e8b824dac6a2ce4d56c7d08f74f3e80bf1c01d3a (diff) | |
download | ufodecode-abe088c58aeb876d1471fa99e0fc5c1d85cb1403.tar.gz ufodecode-abe088c58aeb876d1471fa99e0fc5c1d85cb1403.tar.bz2 ufodecode-abe088c58aeb876d1471fa99e0fc5c1d85cb1403.tar.xz ufodecode-abe088c58aeb876d1471fa99e0fc5c1d85cb1403.zip |
Fix: wrong order of pixels when using SSE
-rw-r--r-- | src/ufodecode.c | 54 | ||||
-rw-r--r-- | test/ipedec.c | 7 |
2 files changed, 34 insertions, 27 deletions
diff --git a/src/ufodecode.c b/src/ufodecode.c index a6a89dc..d1a3984 100644 --- a/src/ufodecode.c +++ b/src/ufodecode.c @@ -135,34 +135,37 @@ static int ufo_decode_frame(uint16_t *pixel_buffer, uint32_t *raw, int num_rows, tmp1 = _mm_srli_epi32(packed, 20); tmp2 = _mm_and_si128(tmp1, mask); _mm_storeu_si128((__m128i*) result, tmp2); - pixel_buffer[base] = result[0]; - pixel_buffer[base+3] = result[1]; - pixel_buffer[base+6] = result[2]; - pixel_buffer[base+9] = result[3]; + + pixel_buffer[base+0] = result[3]; + pixel_buffer[base+3] = result[2]; + pixel_buffer[base+6] = result[1]; + pixel_buffer[base+9] = result[0]; tmp1 = _mm_srli_epi32(packed, 10); tmp2 = _mm_and_si128(tmp1, mask); _mm_storeu_si128((__m128i*) result, tmp2); - pixel_buffer[base+1] = result[0]; - pixel_buffer[base+4] = result[1]; - pixel_buffer[base+7] = result[2]; - pixel_buffer[base+10] = result[3]; + pixel_buffer[base+1] = result[3]; + pixel_buffer[base+4] = result[2]; + pixel_buffer[base+7] = result[1]; + pixel_buffer[base+10] = result[0]; tmp1 = _mm_and_si128(packed, mask); _mm_storeu_si128((__m128i*) result, tmp1); - pixel_buffer[base+2] = result[0]; - pixel_buffer[base+5] = result[1]; - pixel_buffer[base+8] = result[2]; - pixel_buffer[base+11] = result[3]; + pixel_buffer[base+2] = result[3]; + pixel_buffer[base+5] = result[2]; + pixel_buffer[base+8] = result[1]; + pixel_buffer[base+11] = result[0]; } - /* Compute last pixels the usual way */ - for (int i = bytes-4; i < bytes; i++) { - data = raw[i]; - pixel_buffer[base++] = (data >> 20) & 0x3FF; - pixel_buffer[base++] = (data >> 10) & 0x3FF; - pixel_buffer[base++] = data & 0x3FF; - } + /* Compute last pixels by hand */ + data = raw[41]; + pixel_buffer[base++] = (data >> 20) & 0x3FF; + pixel_buffer[base++] = (data >> 10) & 0x3FF; + pixel_buffer[base++] = data & 0x3FF; + data = raw[42]; + pixel_buffer[base++] = (data >> 20) & 0x3FF; + pixel_buffer[base++] = (data >> 10) & 0x3FF; + pixel_buffer[base++] = data & 0x3FF; #else for (int i = 1 ; i < bytes; i++) { data = raw[i]; @@ -298,14 +301,14 @@ int ufo_decoder_get_next_frame(ufo_decoder decoder, uint16_t **pixels, uint32_t CHECK_VALUE(raw[pos++], 0x55555555); CHECK_VALUE(raw[pos++], 0x56666666); CHECK_VALUE(raw[pos] >> 28, 0x5); - *frame_number = raw[pos++] & 0xF0000000; + *frame_number = raw[pos++] & 0xFFFFFFF; CHECK_VALUE(raw[pos] >> 28, 0x5); - *time_stamp = raw[pos++] & 0xF0000000; + *time_stamp = raw[pos++] & 0xFFFFFFF; if (err) return EILSEQ; #else - *frame_number = raw[pos + 6] & 0xF0000000; - *time_stamp = raw[pos + 7] & 0xF0000000; + *frame_number = raw[pos + 6] & 0xFFFFFFF; + *time_stamp = raw[pos + 7] & 0xFFFFFFF; pos += 8; #endif @@ -318,9 +321,8 @@ int ufo_decoder_get_next_frame(ufo_decoder decoder, uint16_t **pixels, uint32_t #ifdef DEBUG CHECK_VALUE(raw[pos++], 0x0AAAAAAA); CHECK_VALUE(raw[pos++], 0x0BBBBBBB); - CHECK_VALUE(raw[pos++], 0x0CCCCCCC); - CHECK_VALUE(raw[pos++], 0x0DDDDDDD); - CHECK_VALUE(raw[pos++], 0x0EEEEEEE); + /* TODO: what should we check? */ + pos += 3; CHECK_VALUE(raw[pos++], 0x0FFFFFFF); CHECK_VALUE(raw[pos++], 0x00000000); CHECK_VALUE(raw[pos++], 0x01111111); diff --git a/test/ipedec.c b/test/ipedec.c index 94c8d59..f14498d 100644 --- a/test/ipedec.c +++ b/test/ipedec.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <stdint.h> +#include <string.h> #include <unistd.h> #include <sys/time.h> #include <errno.h> @@ -42,8 +43,11 @@ int main(int argc, char const* argv[]) char *buffer = NULL; size_t num_bytes = 0; - if (read_raw_file(argv[1], &buffer, &num_bytes)) + int error = read_raw_file(argv[1], &buffer, &num_bytes); + if (error) { + printf("file reading error: %s\n", strerror(error)); return EXIT_FAILURE; + } const int rows = atoi(argv[2]); @@ -55,6 +59,7 @@ int main(int argc, char const* argv[]) struct timeval start, end; long seconds = 0L, useconds = 0L; + FILE *fp = fopen("test.raw", "wb"); while (!err) { |