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

Accessors for all data types. Implemented with macros for all block sizes gaining slight speedup.

parent fef438b9
......@@ -3,7 +3,7 @@ CC = gcc
CFLAGS = -g -O3 -Wall -std=c99
CXXFLAGS = -O3 -Wall
OBJS = aee.o aee_mutators.o aed.o sz_compat.o
OBJS = aee.o aee_accessors.o aed.o sz_compat.o
.PHONY : all clean check
......@@ -26,8 +26,8 @@ libae.a: $(OBJS)
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
aed.o: libae.h
aee.o: aee_mutators.h aee.h libae.h
aee_mutators.o: aee.h libae.h
aee.o: aee_accessors.h aee.h libae.h
aee_accessors.o: aee.h libae.h
sz_compat.o: libae.h
install: libae.a
......
......@@ -265,7 +265,7 @@ int ae_decode_init(ae_streamp strm)
/* Some sanity checks */
if (strm->bit_per_sample > 32 || strm->bit_per_sample == 0)
{
return AE_ERRNO;
return AE_CONF_ERROR;
}
/* Internal state for decoder */
......
......@@ -4,7 +4,7 @@
* @section DESCRIPTION
*
* Adaptive Entropy Encoder
* Based on CCSDS documents 121.0-B-1 and 120.0-G-2
* Based on CCSDS documents 121.0-B-2 and 120.0-G-2
*
*/
......@@ -16,7 +16,7 @@
#include "libae.h"
#include "aee.h"
#include "aee_mutators.h"
#include "aee_accessors.h"
/* Marker for Remainder Of Segment condition in zero block encoding */
#define ROS -1
......@@ -377,7 +377,7 @@ static inline int m_select_code_option(ae_streamp strm)
direction = 1;
looked_bothways = 0;
/* Starting with splitting position of last block look left and
/* Starting with splitting position of last block. Look left and
* possibly right to find new minimum.
*/
for (;;)
......@@ -390,13 +390,21 @@ static inline int m_select_code_option(ae_streamp strm)
+ (uint64_t)(state->block_p[6] >> i)
+ (uint64_t)(state->block_p[7] >> i);
if (strm->block_size > 8)
for (j = 1; j < strm->block_size / 8; j++)
fs_len +=
(uint64_t)(state->block_p[j * 8 + 0] >> i)
+ (uint64_t)(state->block_p[j * 8 + 1] >> i)
+ (uint64_t)(state->block_p[j * 8 + 2] >> i)
+ (uint64_t)(state->block_p[j * 8 + 3] >> i)
+ (uint64_t)(state->block_p[j * 8 + 4] >> i)
+ (uint64_t)(state->block_p[j * 8 + 5] >> i)
+ (uint64_t)(state->block_p[j * 8 + 6] >> i)
+ (uint64_t)(state->block_p[j * 8 + 7] >> i);
if (state->ref == 0)
fs_len += (uint64_t)(state->block_p[0] >> i);
if (strm->block_size > 8)
for (j = 8; j < strm->block_size; j++)
fs_len += (uint64_t)(state->block_p[j] >> i);
split_len = fs_len + this_bs * (i + 1);
if (split_len < split_len_min)
......@@ -647,20 +655,21 @@ static inline int m_flush_block_cautious(ae_streamp strm)
int ae_encode_init(ae_streamp strm)
{
int bs, bsi;
encode_state *state;
/* Some sanity checks */
if (strm->bit_per_sample > 32 || strm->bit_per_sample == 0)
return AE_ERRNO;
return AE_CONF_ERROR;
if (strm->block_size != 8
&& strm->block_size != 16
&& strm->block_size != 32
&& strm->block_size != 64)
return AE_ERRNO;
return AE_CONF_ERROR;
if (strm->rsi > 4096)
return AE_ERRNO;
return AE_CONF_ERROR;
/* Internal state for encoder */
state = (encode_state *) malloc(sizeof(encode_state));
......@@ -671,6 +680,11 @@ int ae_encode_init(ae_streamp strm)
memset(state, 0, sizeof(encode_state));
strm->state = state;
bs = strm->block_size >> 3;
bsi = 0;
while (bs >>= 1)
bsi++;
if (strm->bit_per_sample > 16)
{
/* 32 bit settings */
......@@ -679,11 +693,32 @@ int ae_encode_init(ae_streamp strm)
if (strm->flags & AE_DATA_MSB)
{
state->get_sample = get_msb_32;
state->get_block = get_block_msb_32;
if (strm->bit_per_sample == 24
&& strm->flags & AE_DATA_3BYTE)
{
state->get_sample = get_msb_24;
state->get_block = get_block_funcs_msb_24[bsi];
}
else
{
state->get_sample = get_msb_32;
state->get_block = get_block_funcs_msb_32[bsi];
}
}
else
state->get_sample = get_lsb_32;
{
if (strm->bit_per_sample == 24
&& strm->flags & AE_DATA_3BYTE)
{
state->get_sample = get_lsb_24;
state->get_block = get_block_funcs_lsb_24[bsi];
}
else
{
state->get_sample = get_lsb_32;
state->get_block = get_block_funcs_lsb_32[bsi];
}
}
}
else if (strm->bit_per_sample > 8)
{
......@@ -694,27 +729,22 @@ int ae_encode_init(ae_streamp strm)
if (strm->flags & AE_DATA_MSB)
{
state->get_sample = get_msb_16;
if (strm->block_size == 8)
state->get_block = get_block_msb_16_bs_8;
else
state->get_block = get_block_msb_16;
state->get_block = get_block_funcs_msb_16[bsi];
}
else
{
state->get_sample = get_lsb_16;
state->get_block = get_block_funcs_lsb_16[bsi];
}
}
else
{
/* 8 bit settings */
state->block_len = strm->block_size;
state->id_len = 3;
state->block_len = strm->block_size;
state->get_sample = get_8;
if (strm->block_size == 8)
state->get_block = get_block_8_bs_8;
else
state->get_block = get_block_8;
state->get_block = get_block_funcs_8[bsi];
}
if (strm->flags & AE_DATA_SIGNED)
......
This diff is collapsed.
#ifndef AEE_MUTATORS_H
#define AEE_MUTATORS_H
#ifndef AEE_ACCESSORS_H
#define AEE_ACCESSORS_H
#include <inttypes.h>
#include "libae.h"
uint32_t get_lsb_32(ae_streamp strm);
uint32_t get_8(ae_streamp strm);
uint32_t get_lsb_16(ae_streamp strm);
uint32_t get_msb_32(ae_streamp strm);
uint32_t get_msb_16(ae_streamp strm);
uint32_t get_8(ae_streamp strm);
uint32_t get_lsb_32(ae_streamp strm);
uint32_t get_msb_24(ae_streamp strm);
uint32_t get_lsb_24(ae_streamp strm);
uint32_t get_msb_32(ae_streamp strm);
void get_block_msb_32(ae_streamp strm);
void get_block_msb_16_bs_8(ae_streamp strm);
void get_block_msb_16(ae_streamp strm);
void get_block_8_bs_8(ae_streamp strm);
void get_block_8(ae_streamp strm);
extern void (*get_block_funcs_8[4])(ae_streamp);
extern void (*get_block_funcs_lsb_16[4])(ae_streamp);
extern void (*get_block_funcs_msb_16[4])(ae_streamp);
extern void (*get_block_funcs_lsb_24[4])(ae_streamp);
extern void (*get_block_funcs_msb_24[4])(ae_streamp);
extern void (*get_block_funcs_lsb_32[4])(ae_streamp);
extern void (*get_block_funcs_msb_32[4])(ae_streamp);
#endif
#include <inttypes.h>
#include "libae.h"
#include "aee.h"
#include "aee_mutators.h"
uint32_t get_lsb_32(ae_streamp strm)
{
uint32_t data;
data = ((uint32_t)strm->next_in[3] << 24)
| ((uint32_t)strm->next_in[2] << 16)
| ((uint32_t)strm->next_in[1] << 8)
| (uint32_t)strm->next_in[0];
strm->next_in += 4;
strm->total_in += 4;
strm->avail_in -= 4;
return data;
}
uint32_t get_lsb_16(ae_streamp strm)
{
uint32_t data;
data = ((uint32_t)strm->next_in[1] << 8)
| (uint32_t)strm->next_in[0];
strm->next_in += 2;
strm->total_in += 2;
strm->avail_in -= 2;
return data;
}
uint32_t get_msb_32(ae_streamp strm)
{
uint32_t data;
data = ((uint32_t)strm->next_in[0] << 24)
| ((uint32_t)strm->next_in[1] << 16)
| ((uint32_t)strm->next_in[2] << 8)
| (uint32_t)strm->next_in[3];
strm->next_in += 4;
strm->total_in += 4;
strm->avail_in -= 4;
return data;
}
uint32_t get_msb_16(ae_streamp strm)
{
uint32_t data;
data = ((uint32_t)strm->next_in[0] << 8)
| (uint32_t)strm->next_in[1];
strm->next_in += 2;
strm->total_in += 2;
strm->avail_in -= 2;
return data;
}
uint32_t get_8(ae_streamp strm)
{
strm->avail_in--;
strm->total_in++;
return *strm->next_in++;
}
void get_block_msb_16_bs_8(ae_streamp strm)
{
int i;
uint32_t *block = strm->state->block_buf;
for (i = 0; i < 8 * strm->rsi; i += 8)
{
block[i + 0] = ((uint32_t)strm->next_in[0] << 8) | (uint32_t)strm->next_in[1];
block[i + 1] = ((uint32_t)strm->next_in[2] << 8) | (uint32_t)strm->next_in[3];
block[i + 2] = ((uint32_t)strm->next_in[4] << 8) | (uint32_t)strm->next_in[5];
block[i + 3] = ((uint32_t)strm->next_in[6] << 8) | (uint32_t)strm->next_in[7];
block[i + 4] = ((uint32_t)strm->next_in[8] << 8) | (uint32_t)strm->next_in[9];
block[i + 5] = ((uint32_t)strm->next_in[10] << 8) | (uint32_t)strm->next_in[11];
block[i + 6] = ((uint32_t)strm->next_in[12] << 8) | (uint32_t)strm->next_in[13];
block[i + 7] = ((uint32_t)strm->next_in[14] << 8) | (uint32_t)strm->next_in[15];
strm->next_in += 16;
}
strm->total_in += 16 * strm->rsi;
strm->avail_in -= 16 * strm->rsi;
}
void get_block_msb_16(ae_streamp strm)
{
int i;
uint32_t *block = strm->state->block_buf;
for (i = 0; i < strm->block_size * strm->rsi; i++)
{
block[i] = ((uint32_t)strm->next_in[2 * i] << 8)
| (uint32_t)strm->next_in[2 * i + 1];
}
strm->next_in += 2 * strm->block_size * strm->rsi;
strm->total_in += 2 * strm->block_size * strm->rsi;
strm->avail_in -= 2 * strm->block_size * strm->rsi;
}
void get_block_msb_32(ae_streamp strm)
{
int i;
uint32_t *block = strm->state->block_buf;
for (i = 0; i < strm->block_size * strm->rsi; i++)
{
block[i] = ((uint32_t)strm->next_in[4 * i] << 24)
| ((uint32_t)strm->next_in[4 * i + 1] << 16)
| ((uint32_t)strm->next_in[4 * i + 2] << 8)
| (uint32_t)strm->next_in[4 * i + 3];
}
strm->next_in += 4 * strm->block_size * strm->rsi;
strm->total_in += 4 * strm->block_size * strm->rsi;
strm->avail_in -= 4 * strm->block_size * strm->rsi;
}
void get_block_8_bs_8(ae_streamp strm)
{
int i;
uint32_t *block = strm->state->block_buf;
for (i = 0; i < 8 * strm->rsi; i += 8)
{
block[i + 0] = strm->next_in[i + 0];
block[i + 1] = strm->next_in[i + 1];
block[i + 2] = strm->next_in[i + 2];
block[i + 3] = strm->next_in[i + 3];
block[i + 4] = strm->next_in[i + 4];
block[i + 5] = strm->next_in[i + 5];
block[i + 6] = strm->next_in[i + 6];
block[i + 7] = strm->next_in[i + 7];
}
strm->next_in += 8 * strm->rsi;
strm->total_in += 8 * strm->rsi;
strm->avail_in -= 8 * strm->rsi;
}
void get_block_8(ae_streamp strm)
{
int i;
uint32_t *block = strm->state->block_buf;
for (i = 0; i < strm->block_size * strm->rsi; i++)
block[i] = strm->next_in[i];
strm->next_in += strm->block_size * strm->rsi;
strm->total_in += strm->block_size * strm->rsi;
strm->avail_in -= strm->block_size * strm->rsi;
}
......@@ -24,10 +24,10 @@ int main(int argc, char *argv[])
strm.bit_per_sample = 8;
strm.block_size = 8;
strm.rsi = 2;
strm.flags = AE_DATA_MSB | AE_DATA_PREPROCESS;
strm.flags = AE_DATA_PREPROCESS;
opterr = 0;
while ((c = getopt (argc, argv, "scb:B:J:R:")) != -1)
while ((c = getopt (argc, argv, "Mscb:B:J:R:")) != -1)
switch (c)
{
case 'b':
......@@ -48,6 +48,9 @@ int main(int argc, char *argv[])
case 's':
strm.flags |= AE_DATA_SIGNED;
break;
case 'M':
strm.flags |= AE_DATA_MSB;
break;
case '?':
if (optopt == 'b')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
......
......@@ -24,10 +24,10 @@ int main(int argc, char *argv[])
strm.bit_per_sample = 8;
strm.block_size = 8;
strm.rsi = 2;
strm.flags = AE_DATA_MSB | AE_DATA_PREPROCESS;
strm.flags = AE_DATA_PREPROCESS;
opterr = 0;
while ((c = getopt (argc, argv, "scb:B:R:J:")) != -1)
while ((c = getopt (argc, argv, "Mscb:B:R:J:")) != -1)
switch (c)
{
case 'b':
......@@ -48,6 +48,9 @@ int main(int argc, char *argv[])
case 's':
strm.flags |= AE_DATA_SIGNED;
break;
case 'M':
strm.flags |= AE_DATA_MSB;
break;
case '?':
if (optopt == 'b')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
......
......@@ -32,14 +32,14 @@ typedef ae_stream *ae_streamp;
/* Coder flags */
#define AE_DATA_UNSIGNED 0
#define AE_DATA_SIGNED 1
#define AE_DATA_LSB 8
#define AE_DATA_3BYTE 2 /* 24 bit samples coded in 3 bytes */
#define AE_DATA_LSB 0
#define AE_DATA_MSB 16
#define AE_DATA_PREPROCESS 32 /* Set if preprocessor should be used */
/* Return codes of library functions */
#define AE_OK 0
#define AE_STREAM_END 1
#define AE_ERRNO (-1)
#define AE_CONF_ERROR (-1)
#define AE_STREAM_ERROR (-2)
#define AE_DATA_ERROR (-3)
#define AE_MEM_ERROR (-4)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment