Commit 4add047d authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

Limit scope

parent 6cd141a9
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src tests SUBDIRS = src tests
EXTRA_DIST = doc/patent.txt CMakeLists.txt cmake/config.h.in \ EXTRA_DIST = doc/patent.txt CMakeLists.txt cmake/config.h.in \
cmake/macros.cmake README.md README.SZIP CHANGELOG.am Copyright.txt data cmake/macros.cmake README.md README.SZIP CHANGELOG.md Copyright.txt data
sampledata = 121B2TestData sampledata = 121B2TestData
sampledata_url = http://cwe.ccsds.org/sls/docs/SLS-DC/BB121B2TestData/$(sampledata).zip sampledata_url = http://cwe.ccsds.org/sls/docs/SLS-DC/BB121B2TestData/$(sampledata).zip
......
This diff is collapsed.
...@@ -97,8 +97,7 @@ struct internal_state { ...@@ -97,8 +97,7 @@ struct internal_state {
/* length of output block in bytes */ /* length of output block in bytes */
uint32_t out_blklen; uint32_t out_blklen;
/* counter for samples */ uint32_t sample_counter;
uint32_t n, i;
/* accumulator for currently used bit sequence */ /* accumulator for currently used bit sequence */
uint64_t acc; uint64_t acc;
......
...@@ -117,15 +117,12 @@ static inline void copy64(uint8_t *dst, uint64_t src) ...@@ -117,15 +117,12 @@ static inline void copy64(uint8_t *dst, uint64_t src)
static inline void emitblock_fs(struct aec_stream *strm, int k, int ref) static inline void emitblock_fs(struct aec_stream *strm, int k, int ref)
{ {
size_t i;
uint32_t used; /* used bits in 64 bit accumulator */
uint64_t acc; /* accumulator */
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
acc = (uint64_t)*state->cds << 56; uint64_t acc = (uint64_t)*state->cds << 56;
used = 7 - state->bits; uint32_t used = 7 - state->bits; /* used bits in 64 bit accumulator */
for (i = ref; i < strm->block_size; i++) { for (size_t i = ref; i < strm->block_size; i++) {
used += (state->block[i] >> k) + 1; used += (state->block[i] >> k) + 1;
while (used > 63) { while (used > 63) {
copy64(state->cds, acc); copy64(state->cds, acc);
...@@ -147,16 +144,14 @@ static inline void emitblock(struct aec_stream *strm, int k, int ref) ...@@ -147,16 +144,14 @@ static inline void emitblock(struct aec_stream *strm, int k, int ref)
Emit the k LSB of a whole block of input data. Emit the k LSB of a whole block of input data.
*/ */
uint64_t a;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
uint32_t *in = state->block + ref; uint32_t *in = state->block + ref;
uint32_t *in_end = state->block + strm->block_size; uint32_t *in_end = state->block + strm->block_size;
uint64_t mask = (UINT64_C(1) << k) - 1; uint64_t mask = (UINT64_C(1) << k) - 1;
uint8_t *o = state->cds; uint8_t *o = state->cds;
uint64_t a = *o;
int p = state->bits; int p = state->bits;
a = *o;
while(in < in_end) { while(in < in_end) {
a <<= 56; a <<= 56;
p = (p % 8) + 56; p = (p % 8) + 56;
...@@ -247,12 +242,11 @@ static void preprocess_unsigned(struct aec_stream *strm) ...@@ -247,12 +242,11 @@ static void preprocess_unsigned(struct aec_stream *strm)
uint32_t *restrict d = state->data_pp; uint32_t *restrict d = state->data_pp;
uint32_t xmax = state->xmax; uint32_t xmax = state->xmax;
uint32_t rsi = strm->rsi * strm->block_size - 1; uint32_t rsi = strm->rsi * strm->block_size - 1;
size_t i;
state->ref = 1; state->ref = 1;
state->ref_sample = x[0]; state->ref_sample = x[0];
d[0] = 0; d[0] = 0;
for (i = 0; i < rsi; i++) { for (size_t i = 0; i < rsi; i++) {
if (x[i + 1] >= x[i]) { if (x[i + 1] >= x[i]) {
D = x[i + 1] - x[i]; D = x[i + 1] - x[i];
if (D <= x[i]) if (D <= x[i])
...@@ -284,14 +278,13 @@ static void preprocess_signed(struct aec_stream *strm) ...@@ -284,14 +278,13 @@ static void preprocess_signed(struct aec_stream *strm)
int32_t xmin = (int32_t)state->xmin; int32_t xmin = (int32_t)state->xmin;
uint32_t rsi = strm->rsi * strm->block_size - 1; uint32_t rsi = strm->rsi * strm->block_size - 1;
uint32_t m = UINT64_C(1) << (strm->bits_per_sample - 1); uint32_t m = UINT64_C(1) << (strm->bits_per_sample - 1);
size_t i;
state->ref = 1; state->ref = 1;
state->ref_sample = x[0]; state->ref_sample = x[0];
d[0] = 0; d[0] = 0;
x[0] = (x[0] ^ m) - m; x[0] = (x[0] ^ m) - m;
for (i = 0; i < rsi; i++) { for (size_t i = 0; i < rsi; i++) {
x[i + 1] = (x[i + 1] ^ m) - m; x[i + 1] = (x[i + 1] ^ m) - m;
if (x[i + 1] < x[i]) { if (x[i + 1] < x[i]) {
D = (uint32_t)(x[i] - x[i + 1]); D = (uint32_t)(x[i] - x[i + 1]);
...@@ -316,11 +309,10 @@ static inline uint64_t block_fs(struct aec_stream *strm, int k) ...@@ -316,11 +309,10 @@ static inline uint64_t block_fs(struct aec_stream *strm, int k)
Sum FS of all samples in block for given splitting position. Sum FS of all samples in block for given splitting position.
*/ */
size_t i;
uint64_t fs = 0;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
uint64_t fs = 0;
for (i = 0; i < strm->block_size; i++) for (size_t i = 0; i < strm->block_size; i++)
fs += (uint64_t)(state->block[i] >> k); fs += (uint64_t)(state->block[i] >> k);
return fs; return fs;
...@@ -353,26 +345,29 @@ static uint32_t assess_splitting_option(struct aec_stream *strm) ...@@ -353,26 +345,29 @@ static uint32_t assess_splitting_option(struct aec_stream *strm)
analogue check can be done for decreasing k. analogue check can be done for decreasing k.
*/ */
int k;
int k_min;
int this_bs; /* Block size of current block */
int no_turn; /* 1 if we shouldn't reverse */
int dir; /* Direction, 1 means increasing k, 0 decreasing k */
uint64_t len; /* CDS length for current k */
uint64_t len_min; /* CDS length minimum so far */
uint64_t fs_len; /* Length of FS part (not including 1s) */
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
this_bs = strm->block_size - state->ref; /* Block size of current block */
len_min = UINT64_MAX; int this_bs = strm->block_size - state->ref;
k = k_min = state->k;
no_turn = k == 0; /* CDS length minimum so far */
dir = 1; uint64_t len_min = UINT64_MAX;
int k = state->k;
int k_min = k;
/* 1 if we shouldn't reverse */
int no_turn = (k == 0);
/* Direction, 1 means increasing k, 0 decreasing k */
int dir = 1;
for (;;) { for (;;) {
fs_len = block_fs(strm, k); /* Length of FS part (not including 1s) */
len = fs_len + this_bs * (k + 1); uint64_t fs_len = block_fs(strm, k);
/* CDS length for current k */
uint64_t len = fs_len + this_bs * (k + 1);
if (len < len_min) { if (len < len_min) {
if (len_min < UINT64_MAX) if (len_min < UINT64_MAX)
...@@ -417,15 +412,12 @@ static uint32_t assess_se_option(struct aec_stream *strm) ...@@ -417,15 +412,12 @@ static uint32_t assess_se_option(struct aec_stream *strm)
If length is above limit just return UINT32_MAX. If length is above limit just return UINT32_MAX.
*/ */
size_t i;
uint64_t len, d;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
uint32_t *block = state->block; uint32_t *block = state->block;
uint64_t len = 1;
len = 1; for (size_t i = 0; i < strm->block_size; i += 2) {
uint64_t d = (uint64_t)block[i] + (uint64_t)block[i + 1];
for (i = 0; i < strm->block_size; i += 2) {
d = (uint64_t)block[i] + (uint64_t)block[i + 1];
len += d * (d + 1) / 2 + block[i + 1] + 1; len += d * (d + 1) / 2 + block[i + 1] + 1;
if (len > state->uncomp_len) if (len > state->uncomp_len)
return UINT32_MAX; return UINT32_MAX;
...@@ -493,7 +485,6 @@ static int m_flush_block(struct aec_stream *strm) ...@@ -493,7 +485,6 @@ static int m_flush_block(struct aec_stream *strm)
Fall back to slow flushing if in buffered mode. Fall back to slow flushing if in buffered mode.
*/ */
int n;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
#ifdef ENABLE_RSI_PADDING #ifdef ENABLE_RSI_PADDING
...@@ -505,7 +496,7 @@ static int m_flush_block(struct aec_stream *strm) ...@@ -505,7 +496,7 @@ static int m_flush_block(struct aec_stream *strm)
#endif #endif
if (state->direct_out) { if (state->direct_out) {
n = (int)(state->cds - strm->next_out); int n = (int)(state->cds - strm->next_out);
strm->next_out += n; strm->next_out += n;
strm->avail_out -= n; strm->avail_out -= n;
state->mode = m_get_block; state->mode = m_get_block;
...@@ -546,16 +537,14 @@ static int m_encode_uncomp(struct aec_stream *strm) ...@@ -546,16 +537,14 @@ static int m_encode_uncomp(struct aec_stream *strm)
static int m_encode_se(struct aec_stream *strm) static int m_encode_se(struct aec_stream *strm)
{ {
size_t i;
uint32_t d;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
emit(state, 1, state->id_len + 1); emit(state, 1, state->id_len + 1);
if (state->ref) if (state->ref)
emit(state, state->ref_sample, strm->bits_per_sample); emit(state, state->ref_sample, strm->bits_per_sample);
for (i = 0; i < strm->block_size; i+= 2) { for (size_t i = 0; i < strm->block_size; i+= 2) {
d = state->block[i] + state->block[i + 1]; uint32_t d = state->block[i] + state->block[i + 1];
emitfs(state, d * (d + 1) / 2 + state->block[i + 1]); emitfs(state, d * (d + 1) / 2 + state->block[i + 1]);
} }
...@@ -588,15 +577,14 @@ static int m_select_code_option(struct aec_stream *strm) ...@@ -588,15 +577,14 @@ static int m_select_code_option(struct aec_stream *strm)
Decide which code option to use. Decide which code option to use.
*/ */
uint32_t split_len;
uint32_t se_len;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
uint32_t split_len;
if (state->id_len > 1) if (state->id_len > 1)
split_len = assess_splitting_option(strm); split_len = assess_splitting_option(strm);
else else
split_len = UINT32_MAX; split_len = UINT32_MAX;
se_len = assess_se_option(strm); uint32_t se_len = assess_se_option(strm);
if (split_len < state->uncomp_len) { if (split_len < state->uncomp_len) {
if (split_len < se_len) if (split_len < se_len)
...@@ -620,10 +608,10 @@ static int m_check_zero_block(struct aec_stream *strm) ...@@ -620,10 +608,10 @@ static int m_check_zero_block(struct aec_stream *strm)
end of a segment or RSI. end of a segment or RSI.
*/ */
size_t i;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
uint32_t *p = state->block; uint32_t *p = state->block;
size_t i;
for (i = 0; i < strm->block_size; i++) for (i = 0; i < strm->block_size; i++)
if (p[i] != 0) if (p[i] != 0)
break; break;
...@@ -912,7 +900,6 @@ int aec_encode(struct aec_stream *strm, int flush) ...@@ -912,7 +900,6 @@ int aec_encode(struct aec_stream *strm, int flush)
Finite-state machine implementation of the adaptive entropy Finite-state machine implementation of the adaptive entropy
encoder. encoder.
*/ */
int n;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
state->flush = flush; state->flush = flush;
...@@ -922,7 +909,7 @@ int aec_encode(struct aec_stream *strm, int flush) ...@@ -922,7 +909,7 @@ int aec_encode(struct aec_stream *strm, int flush)
while (state->mode(strm) == M_CONTINUE); while (state->mode(strm) == M_CONTINUE);
if (state->direct_out) { if (state->direct_out) {
n = (int)(state->cds - strm->next_out); int n = (int)(state->cds - strm->next_out);
strm->next_out += n; strm->next_out += n;
strm->avail_out -= n; strm->avail_out -= n;
...@@ -938,9 +925,8 @@ int aec_encode(struct aec_stream *strm, int flush) ...@@ -938,9 +925,8 @@ int aec_encode(struct aec_stream *strm, int flush)
int aec_encode_end(struct aec_stream *strm) int aec_encode_end(struct aec_stream *strm)
{ {
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
int status;
status = AEC_OK; int status = AEC_OK;
if (state->flush == AEC_FLUSH && state->flushed == 0) if (state->flush == AEC_FLUSH && state->flushed == 0)
status = AEC_STREAM_ERROR; status = AEC_STREAM_ERROR;
cleanup(strm); cleanup(strm);
...@@ -949,9 +935,7 @@ int aec_encode_end(struct aec_stream *strm) ...@@ -949,9 +935,7 @@ int aec_encode_end(struct aec_stream *strm)
int aec_buffer_encode(struct aec_stream *strm) int aec_buffer_encode(struct aec_stream *strm)
{ {
int status; int status = aec_encode_init(strm);
status = aec_encode_init(strm);
if (status != AEC_OK) if (status != AEC_OK)
return status; return status;
status = aec_encode(strm, AEC_FLUSH); status = aec_encode(strm, AEC_FLUSH);
......
...@@ -66,9 +66,7 @@ uint32_t aec_get_8(struct aec_stream *strm) ...@@ -66,9 +66,7 @@ uint32_t aec_get_8(struct aec_stream *strm)
uint32_t aec_get_lsb_16(struct aec_stream *strm) uint32_t aec_get_lsb_16(struct aec_stream *strm)
{ {
uint32_t data; uint32_t data = ((uint32_t)strm->next_in[1] << 8)
data = ((uint32_t)strm->next_in[1] << 8)
| (uint32_t)strm->next_in[0]; | (uint32_t)strm->next_in[0];
strm->next_in += 2; strm->next_in += 2;
...@@ -78,9 +76,7 @@ uint32_t aec_get_lsb_16(struct aec_stream *strm) ...@@ -78,9 +76,7 @@ uint32_t aec_get_lsb_16(struct aec_stream *strm)
uint32_t aec_get_msb_16(struct aec_stream *strm) uint32_t aec_get_msb_16(struct aec_stream *strm)
{ {
uint32_t data; uint32_t data = ((uint32_t)strm->next_in[0] << 8)
data = ((uint32_t)strm->next_in[0] << 8)
| (uint32_t)strm->next_in[1]; | (uint32_t)strm->next_in[1];
strm->next_in += 2; strm->next_in += 2;
...@@ -90,9 +86,7 @@ uint32_t aec_get_msb_16(struct aec_stream *strm) ...@@ -90,9 +86,7 @@ uint32_t aec_get_msb_16(struct aec_stream *strm)
uint32_t aec_get_lsb_24(struct aec_stream *strm) uint32_t aec_get_lsb_24(struct aec_stream *strm)
{ {
uint32_t data; uint32_t data = ((uint32_t)strm->next_in[2] << 16)
data = ((uint32_t)strm->next_in[2] << 16)
| ((uint32_t)strm->next_in[1] << 8) | ((uint32_t)strm->next_in[1] << 8)
| (uint32_t)strm->next_in[0]; | (uint32_t)strm->next_in[0];
...@@ -103,9 +97,7 @@ uint32_t aec_get_lsb_24(struct aec_stream *strm) ...@@ -103,9 +97,7 @@ uint32_t aec_get_lsb_24(struct aec_stream *strm)
uint32_t aec_get_msb_24(struct aec_stream *strm) uint32_t aec_get_msb_24(struct aec_stream *strm)
{ {
uint32_t data; uint32_t data = ((uint32_t)strm->next_in[0] << 16)
data = ((uint32_t)strm->next_in[0] << 16)
| ((uint32_t)strm->next_in[1] << 8) | ((uint32_t)strm->next_in[1] << 8)
| (uint32_t)strm->next_in[2]; | (uint32_t)strm->next_in[2];
...@@ -116,9 +108,7 @@ uint32_t aec_get_msb_24(struct aec_stream *strm) ...@@ -116,9 +108,7 @@ uint32_t aec_get_msb_24(struct aec_stream *strm)
uint32_t aec_get_lsb_32(struct aec_stream *strm) uint32_t aec_get_lsb_32(struct aec_stream *strm)
{ {
uint32_t data; uint32_t data = ((uint32_t)strm->next_in[3] << 24)
data = ((uint32_t)strm->next_in[3] << 24)
| ((uint32_t)strm->next_in[2] << 16) | ((uint32_t)strm->next_in[2] << 16)
| ((uint32_t)strm->next_in[1] << 8) | ((uint32_t)strm->next_in[1] << 8)
| (uint32_t)strm->next_in[0]; | (uint32_t)strm->next_in[0];
...@@ -130,9 +120,7 @@ uint32_t aec_get_lsb_32(struct aec_stream *strm) ...@@ -130,9 +120,7 @@ uint32_t aec_get_lsb_32(struct aec_stream *strm)
uint32_t aec_get_msb_32(struct aec_stream *strm) uint32_t aec_get_msb_32(struct aec_stream *strm)
{ {
uint32_t data; uint32_t data = ((uint32_t)strm->next_in[0] << 24)
data = ((uint32_t)strm->next_in[0] << 24)
| ((uint32_t)strm->next_in[1] << 16) | ((uint32_t)strm->next_in[1] << 16)
| ((uint32_t)strm->next_in[2] << 8) | ((uint32_t)strm->next_in[2] << 8)
| (uint32_t)strm->next_in[3]; | (uint32_t)strm->next_in[3];
...@@ -144,12 +132,11 @@ uint32_t aec_get_msb_32(struct aec_stream *strm) ...@@ -144,12 +132,11 @@ uint32_t aec_get_msb_32(struct aec_stream *strm)
void aec_get_rsi_8(struct aec_stream *strm) void aec_get_rsi_8(struct aec_stream *strm)
{ {
int i;
uint32_t *restrict out = strm->state->data_raw; uint32_t *restrict out = strm->state->data_raw;
unsigned const char *restrict in = strm->next_in; unsigned const char *restrict in = strm->next_in;
int rsi = strm->rsi * strm->block_size; int rsi = strm->rsi * strm->block_size;
for (i = 0; i < rsi; i++) for (int i = 0; i < rsi; i++)
out[i] = (uint32_t)in[i]; out[i] = (uint32_t)in[i];
strm->next_in += rsi; strm->next_in += rsi;
...@@ -158,12 +145,11 @@ void aec_get_rsi_8(struct aec_stream *strm) ...@@ -158,12 +145,11 @@ void aec_get_rsi_8(struct aec_stream *strm)
void aec_get_rsi_lsb_16(struct aec_stream *strm) void aec_get_rsi_lsb_16(struct aec_stream *strm)
{ {
int i;
uint32_t *restrict out = strm->state->data_raw; uint32_t *restrict out = strm->state->data_raw;
const unsigned char *restrict in = strm->next_in; const unsigned char *restrict in = strm->next_in;
int rsi = strm->rsi * strm->block_size; int rsi = strm->rsi * strm->block_size;
for (i = 0; i < rsi; i++) for (int i = 0; i < rsi; i++)
out[i] = (uint32_t)in[2 * i] | ((uint32_t)in[2 * i + 1] << 8); out[i] = (uint32_t)in[2 * i] | ((uint32_t)in[2 * i + 1] << 8);
strm->next_in += 2 * rsi; strm->next_in += 2 * rsi;
...@@ -172,12 +158,11 @@ void aec_get_rsi_lsb_16(struct aec_stream *strm) ...@@ -172,12 +158,11 @@ void aec_get_rsi_lsb_16(struct aec_stream *strm)
void aec_get_rsi_msb_16(struct aec_stream *strm) void aec_get_rsi_msb_16(struct aec_stream *strm)
{ {
int i;
uint32_t *restrict out = strm->state->data_raw; uint32_t *restrict out = strm->state->data_raw;
const unsigned char *restrict in = strm->next_in; const unsigned char *restrict in = strm->next_in;
int rsi = strm->rsi * strm->block_size; int rsi = strm->rsi * strm->block_size;
for (i = 0; i < rsi; i++) for (int i = 0; i < rsi; i++)
out[i] = ((uint32_t)in[2 * i] << 8) | (uint32_t)in[2 * i + 1]; out[i] = ((uint32_t)in[2 * i] << 8) | (uint32_t)in[2 * i + 1];
strm->next_in += 2 * rsi; strm->next_in += 2 * rsi;
...@@ -186,12 +171,11 @@ void aec_get_rsi_msb_16(struct aec_stream *strm) ...@@ -186,12 +171,11 @@ void aec_get_rsi_msb_16(struct aec_stream *strm)
void aec_get_rsi_lsb_24(struct aec_stream *strm) void aec_get_rsi_lsb_24(struct aec_stream *strm)
{ {
int i;
uint32_t *restrict out = strm->state->data_raw; uint32_t *restrict out = strm->state->data_raw;
const unsigned char *restrict in = strm->next_in; const unsigned char *restrict in = strm->next_in;
int rsi = strm->rsi * strm->block_size; int rsi = strm->rsi * strm->block_size;
for (i = 0; i < rsi; i++) for (int i = 0; i < rsi; i++)
out[i] = (uint32_t)in[3 * i] out[i] = (uint32_t)in[3 * i]
| ((uint32_t)in[3 * i + 1] << 8) | ((uint32_t)in[3 * i + 1] << 8)
| ((uint32_t)in[3 * i + 2] << 16); | ((uint32_t)in[3 * i + 2] << 16);
...@@ -202,12 +186,11 @@ void aec_get_rsi_lsb_24(struct aec_stream *strm) ...@@ -202,12 +186,11 @@ void aec_get_rsi_lsb_24(struct aec_stream *strm)
void aec_get_rsi_msb_24(struct aec_stream *strm) void aec_get_rsi_msb_24(struct aec_stream *strm)
{ {
int i;
uint32_t *restrict out = strm->state->data_raw; uint32_t *restrict out = strm->state->data_raw;
const unsigned char *restrict in = strm->next_in; const unsigned char *restrict in = strm->next_in;
int rsi = strm->rsi * strm->block_size; int rsi = strm->rsi * strm->block_size;
for (i = 0; i < rsi; i++) for (int i = 0; i < rsi; i++)
out[i] = ((uint32_t)in[3 * i] << 16) out[i] = ((uint32_t)in[3 * i] << 16)
| ((uint32_t)in[3 * i + 1] << 8) | ((uint32_t)in[3 * i + 1] << 8)
| (uint32_t)in[3 * i + 2]; | (uint32_t)in[3 * i + 2];
...@@ -229,12 +212,11 @@ void aec_get_rsi_msb_24(struct aec_stream *strm) ...@@ -229,12 +212,11 @@ void aec_get_rsi_msb_24(struct aec_stream *strm)
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
void aec_get_rsi_lsb_32(struct aec_stream *strm) void aec_get_rsi_lsb_32(struct aec_stream *strm)
{ {
int i;
uint32_t *restrict out = strm->state->data_raw; uint32_t *restrict out = strm->state->data_raw;
const unsigned char *restrict in = strm->next_in; const unsigned char *restrict in = strm->next_in;
int rsi = strm->rsi * strm->block_size; int rsi = strm->rsi * strm->block_size;
for (i = 0; i < rsi; i++) for (int i = 0; i < rsi; i++)
out[i] = (uint32_t)in[4 * i] out[i] = (uint32_t)in[4 * i]
| ((uint32_t)in[4 * i + 1] << 8) | ((uint32_t)in[4 * i + 1] << 8)
| ((uint32_t)in[4 * i + 2] << 16) | ((uint32_t)in[4 * i + 2] << 16)
...@@ -249,7 +231,6 @@ AEC_GET_RSI_NATIVE_32(msb); ...@@ -249,7 +231,6 @@ AEC_GET_RSI_NATIVE_32(msb);
#else /* !WORDS_BIGENDIAN */ #else /* !WORDS_BIGENDIAN */
void aec_get_rsi_msb_32(struct aec_stream *strm) void aec_get_rsi_msb_32(struct aec_stream *strm)
{ {
int i;
uint32_t *restrict out = strm->state->data_raw; uint32_t *restrict out = strm->state->data_raw;
const unsigned char *restrict in = strm->next_in; const unsigned char *restrict in = strm->next_in;
int rsi = strm->rsi * strm->block_size; int rsi = strm->rsi * strm->block_size;
...@@ -257,7 +238,7 @@ void aec_get_rsi_msb_32(struct aec_stream *strm) ...@@ -257,7 +238,7 @@ void aec_get_rsi_msb_32(struct aec_stream *strm)
strm->next_in += 4 * rsi; strm->next_in += 4 * rsi;
strm->avail_in -= 4 * rsi; strm->avail_in -= 4 * rsi;
for (i = 0; i < rsi; i++) for (int i = 0; i < rsi; i++)
out[i] = ((uint32_t)in[4 * i] << 24) out[i] = ((uint32_t)in[4 * i] << 24)
| ((uint32_t)in[4 * i + 1] << 16) | ((uint32_t)in[4 * i + 1] << 16)
| ((uint32_t)in[4 * i + 2] << 8) | ((uint32_t)in[4 * i + 2] << 8)
......
...@@ -12,14 +12,13 @@ ...@@ -12,14 +12,13 @@
static int convert_options(int sz_opts) static int convert_options(int sz_opts)
{ {
int co[NOPTS]; int co[NOPTS];
int i;
int opts = 0; int opts = 0;
memset(co, 0, sizeof(int) * NOPTS); memset(co, 0, sizeof(int) * NOPTS);
co[SZ_MSB_OPTION_MASK] = AEC_DATA_MSB; co[SZ_MSB_OPTION_MASK] = AEC_DATA_MSB;
co[SZ_NN_OPTION_MASK] = AEC_DATA_PREPROCESS; co[SZ_NN_OPTION_MASK] = AEC_DATA_PREPROCESS;
for (i = 1; i < NOPTS; i <<= 1) for (int i = 1; i < NOPTS; i <<= 1)
if (sz_opts & i) if (sz_opts & i)
opts |= co[i]; opts |= co[i];
...@@ -39,32 +38,22 @@ static int bits_to_bytes(int bit_length) ...@@ -39,32 +38,22 @@ static int bits_to_bytes(int bit_length)
static void interleave_buffer(void *dest, const void *src, static void interleave_buffer(void *dest, const void *src,
size_t n, int wordsize) size_t n, int wordsize)
{ {
size_t i; const unsigned char *src8 = (unsigned char *)src;
int j; unsigned char *dest8 = (unsigned char *)dest;
const unsigned char *src8;
unsigned char *dest8;
src8 = (unsigned char *)src; for (size_t i = 0; i < n / wordsize; i++)
dest8 = (unsigned char *)dest; for (size_t j = 0; j < wordsize; j++)
for (i = 0; i < n / wordsize; i++)
for (j = 0; j < wordsize; j++)
dest8[j * (n / wordsize) + i] = src8[i * wordsize + j]; dest8[j * (n / wordsize) + i] = src8[i * wordsize + j];
} }
static void deinterleave_buffer(void *dest, const void *src, static void deinterleave_buffer(void *dest, const void *src,
size_t n, int wordsize) size_t n, int wordsize)
{ {
size_t i; const unsigned char *src8 = (unsigned char *)src;
int j; unsigned char *dest8 = (unsigned char *)dest;
const unsigned char *src8;
unsigned char *dest8;
src8 = (unsigned char *)src;
dest8 = (unsigned char *)dest;
for (i = 0; i < n / wordsize; i++) for (size_t i = 0; i < n / wordsize; i++)
for (j = 0; j < wordsize; j++) for (size_t j = 0; j < wordsize; j++)
dest8[i * wordsize + j] = src8[j * (n / wordsize) + i]; dest8[i * wordsize + j] = src8[j * (n / wordsize) + i];
} }
...@@ -72,22 +61,21 @@ static void add_padding(void *dest, const void *src, size_t src_length, ...@@ -72,22 +61,21 @@ static void add_padding(void *dest, const void *src, size_t src_length,
size_t line_size, size_t padding_size, size_t line_size, size_t padding_size,
int pixel_size, int pp) int pixel_size, int pp)
{ {
size_t i, j, k, ls, ps;
const char *pixel;
const char zero_pixel[] = {0, 0, 0, 0}; const char zero_pixel[] = {0, 0, 0, 0};
pixel = zero_pixel; const char *pixel = zero_pixel;
j = 0; size_t j = 0;
i = 0; size_t i = 0;
while (i < src_length) { while (i < src_length) {
ls = MIN(src_length - i, line_size); size_t ps;
size_t ls = MIN(src_length - i, line_size);