Commit 4e64405a authored by Mathis Rosenhauer's avatar Mathis Rosenhauer Committed by Thomas Jahns

Rename everything to aec

parent 833c349c
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
#include <getopt.h> #include <getopt.h>
#include "libae.h" #include "libaec.h"
#define CHUNK 1024 #define CHUNK 1024
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
ae_stream strm; aec_stream strm;
uint8_t *in; uint8_t *in;
uint8_t *out; uint8_t *out;
int chunk, total_out, status, c; int chunk, total_out, status, c;
...@@ -25,7 +25,7 @@ int main(int argc, char *argv[]) ...@@ -25,7 +25,7 @@ int main(int argc, char *argv[])
strm.bit_per_sample = 8; strm.bit_per_sample = 8;
strm.block_size = 8; strm.block_size = 8;
strm.rsi = 2; strm.rsi = 2;
strm.flags = AE_DATA_PREPROCESS; strm.flags = AEC_DATA_PREPROCESS;
opterr = 0; opterr = 0;
while ((c = getopt (argc, argv, "d3Mscb:B:R:J:")) != -1) while ((c = getopt (argc, argv, "d3Mscb:B:R:J:")) != -1)
...@@ -50,13 +50,13 @@ int main(int argc, char *argv[]) ...@@ -50,13 +50,13 @@ int main(int argc, char *argv[])
cflag = 1; cflag = 1;
break; break;
case 's': case 's':
strm.flags |= AE_DATA_SIGNED; strm.flags |= AEC_DATA_SIGNED;
break; break;
case 'M': case 'M':
strm.flags |= AE_DATA_MSB; strm.flags |= AEC_DATA_MSB;
break; break;
case '3': case '3':
strm.flags |= AE_DATA_3BYTE; strm.flags |= AEC_DATA_3BYTE;
break; break;
case '?': case '?':
if (optopt == 'b') if (optopt == 'b')
...@@ -84,7 +84,7 @@ int main(int argc, char *argv[]) ...@@ -84,7 +84,7 @@ int main(int argc, char *argv[])
if (strm.bit_per_sample > 16) if (strm.bit_per_sample > 16)
{ {
if (strm.bit_per_sample <= 24 && strm.flags & AE_DATA_3BYTE) if (strm.bit_per_sample <= 24 && strm.flags & AEC_DATA_3BYTE)
chunk *= 3; chunk *= 3;
else else
chunk *= 4; chunk *= 4;
...@@ -124,16 +124,16 @@ int main(int argc, char *argv[]) ...@@ -124,16 +124,16 @@ int main(int argc, char *argv[])
if (dflag) if (dflag)
{ {
if ((ext = strstr(infn, ".aee")) == NULL) if ((ext = strstr(infn, ".aec")) == NULL)
{ {
fprintf(stderr, "Error: input file needs to end with .aee\n"); fprintf(stderr, "Error: input file needs to end with .aec\n");
exit(-1); exit(-1);
} }
strncpy(outfn, infn, ext - infn); strncpy(outfn, infn, ext - infn);
} }
else else
{ {
sprintf(outfn, "%s.aee", infn); sprintf(outfn, "%s.aec", infn);
} }
if ((outfp = fopen(outfn, "w")) == NULL) if ((outfp = fopen(outfn, "w")) == NULL)
...@@ -142,12 +142,12 @@ int main(int argc, char *argv[]) ...@@ -142,12 +142,12 @@ int main(int argc, char *argv[])
if (dflag) if (dflag)
{ {
if (ae_decode_init(&strm) != AE_OK) if (aec_decode_init(&strm) != AEC_OK)
return 1; return 1;
} }
else else
{ {
if (ae_encode_init(&strm) != AE_OK) if (aec_encode_init(&strm) != AEC_OK)
return 1; return 1;
} }
...@@ -162,11 +162,11 @@ int main(int argc, char *argv[]) ...@@ -162,11 +162,11 @@ int main(int argc, char *argv[])
} }
if (dflag) if (dflag)
status = ae_decode(&strm, AE_NO_FLUSH); status = aec_decode(&strm, AEC_NO_FLUSH);
else else
status = ae_encode(&strm, AE_NO_FLUSH); status = aec_encode(&strm, AEC_NO_FLUSH);
if (status != AE_OK) if (status != AEC_OK)
{ {
fprintf(stderr, "error is %i\n", status); fprintf(stderr, "error is %i\n", status);
return 1; return 1;
...@@ -189,11 +189,11 @@ int main(int argc, char *argv[]) ...@@ -189,11 +189,11 @@ int main(int argc, char *argv[])
if (dflag) if (dflag)
{ {
ae_decode_end(&strm); aec_decode_end(&strm);
} }
else else
{ {
if ((status = ae_encode(&strm, AE_FLUSH)) != AE_OK) if ((status = aec_encode(&strm, AEC_FLUSH)) != AEC_OK)
{ {
fprintf(stderr, "error is %i\n", status); fprintf(stderr, "error is %i\n", status);
return 1; return 1;
...@@ -204,7 +204,7 @@ int main(int argc, char *argv[]) ...@@ -204,7 +204,7 @@ int main(int argc, char *argv[])
fwrite(out, strm.total_out - total_out, 1, outfp); fwrite(out, strm.total_out - total_out, 1, outfp);
} }
ae_encode_end(&strm); aec_encode_end(&strm);
} }
fclose(infp); fclose(infp);
......
#ifndef AEE_ACCESSORS_H
#define AEE_ACCESSORS_H
#include <inttypes.h>
#include "libae.h"
uint32_t get_8(ae_streamp strm);
uint32_t get_lsb_16(ae_streamp strm);
uint32_t get_msb_16(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);
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
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
#include "libae.h" #include "libaec.h"
#define MIN(a, b) (((a) < (b))? (a): (b)) #define MIN(a, b) (((a) < (b))? (a): (b))
...@@ -20,7 +20,7 @@ typedef struct internal_state { ...@@ -20,7 +20,7 @@ typedef struct internal_state {
int id; /* option ID */ int id; /* option ID */
int id_len; /* bit length of code option identification key */ int id_len; /* bit length of code option identification key */
int *id_table; /* table maps IDs to states */ int *id_table; /* table maps IDs to states */
void (*put_sample)(ae_streamp, int64_t); void (*put_sample)(aec_streamp, int64_t);
int ref_int; /* reference sample is every ref_int samples */ int ref_int; /* reference sample is every ref_int samples */
int64_t last_out; /* previous output for post-processing */ int64_t last_out; /* previous output for post-processing */
int64_t xmin; /* minimum integer for post-processing */ int64_t xmin; /* minimum integer for post-processing */
...@@ -42,7 +42,8 @@ typedef struct internal_state { ...@@ -42,7 +42,8 @@ typedef struct internal_state {
} decode_state; } decode_state;
/* decoding table for the second-extension option */ /* decoding table for the second-extension option */
static const int second_extension[92][2] = { static const int second_extension[92][2] =
{
{0, 0}, {0, 0},
{1, 1}, {1, 1}, {1, 1}, {1, 1},
{2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
...@@ -74,7 +75,7 @@ enum ...@@ -74,7 +75,7 @@ enum
M_UNCOMP_COPY, M_UNCOMP_COPY,
}; };
static void put_msb_32(ae_streamp strm, int64_t data) static void put_msb_32(aec_streamp strm, int64_t data)
{ {
*strm->next_out++ = data >> 24; *strm->next_out++ = data >> 24;
*strm->next_out++ = data >> 16; *strm->next_out++ = data >> 16;
...@@ -84,7 +85,7 @@ static void put_msb_32(ae_streamp strm, int64_t data) ...@@ -84,7 +85,7 @@ static void put_msb_32(ae_streamp strm, int64_t data)
strm->total_out += 4; strm->total_out += 4;
} }
static void put_msb_24(ae_streamp strm, int64_t data) static void put_msb_24(aec_streamp strm, int64_t data)
{ {
*strm->next_out++ = data >> 16; *strm->next_out++ = data >> 16;
*strm->next_out++ = data >> 8; *strm->next_out++ = data >> 8;
...@@ -93,7 +94,7 @@ static void put_msb_24(ae_streamp strm, int64_t data) ...@@ -93,7 +94,7 @@ static void put_msb_24(ae_streamp strm, int64_t data)
strm->total_out += 3; strm->total_out += 3;
} }
static void put_msb_16(ae_streamp strm, int64_t data) static void put_msb_16(aec_streamp strm, int64_t data)
{ {
*strm->next_out++ = data >> 8; *strm->next_out++ = data >> 8;
*strm->next_out++ = data; *strm->next_out++ = data;
...@@ -101,7 +102,7 @@ static void put_msb_16(ae_streamp strm, int64_t data) ...@@ -101,7 +102,7 @@ static void put_msb_16(ae_streamp strm, int64_t data)
strm->total_out += 2; strm->total_out += 2;
} }
static void put_lsb_32(ae_streamp strm, int64_t data) static void put_lsb_32(aec_streamp strm, int64_t data)
{ {
*strm->next_out++ = data; *strm->next_out++ = data;
*strm->next_out++ = data >> 8; *strm->next_out++ = data >> 8;
...@@ -111,7 +112,7 @@ static void put_lsb_32(ae_streamp strm, int64_t data) ...@@ -111,7 +112,7 @@ static void put_lsb_32(ae_streamp strm, int64_t data)
strm->total_out += 4; strm->total_out += 4;
} }
static void put_lsb_24(ae_streamp strm, int64_t data) static void put_lsb_24(aec_streamp strm, int64_t data)
{ {
*strm->next_out++ = data; *strm->next_out++ = data;
*strm->next_out++ = data >> 8; *strm->next_out++ = data >> 8;
...@@ -120,7 +121,7 @@ static void put_lsb_24(ae_streamp strm, int64_t data) ...@@ -120,7 +121,7 @@ static void put_lsb_24(ae_streamp strm, int64_t data)
strm->total_out += 3; strm->total_out += 3;
} }
static void put_lsb_16(ae_streamp strm, int64_t data) static void put_lsb_16(aec_streamp strm, int64_t data)
{ {
*strm->next_out++ = data; *strm->next_out++ = data;
*strm->next_out++ = data >> 8; *strm->next_out++ = data >> 8;
...@@ -128,14 +129,14 @@ static void put_lsb_16(ae_streamp strm, int64_t data) ...@@ -128,14 +129,14 @@ static void put_lsb_16(ae_streamp strm, int64_t data)
strm->total_out += 2; strm->total_out += 2;
} }
static void put_8(ae_streamp strm, int64_t data) static void put_8(aec_streamp strm, int64_t data)
{ {
*strm->next_out++ = data; *strm->next_out++ = data;
strm->avail_out--; strm->avail_out--;
strm->total_out++; strm->total_out++;
} }
static inline void u_put(ae_streamp strm, int64_t sample) static inline void u_put(aec_streamp strm, int64_t sample)
{ {
int64_t x, d, th, D, lower; int64_t x, d, th, D, lower;
decode_state *state = strm->state; decode_state *state = strm->state;
...@@ -163,7 +164,7 @@ static inline void u_put(ae_streamp strm, int64_t sample) ...@@ -163,7 +164,7 @@ static inline void u_put(ae_streamp strm, int64_t sample)
} }
else else
{ {
if (strm->flags & AE_DATA_SIGNED) if (strm->flags & AEC_DATA_SIGNED)
{ {
int m = 64 - strm->bit_per_sample; int m = 64 - strm->bit_per_sample;
/* Reference samples have to be sign extended */ /* Reference samples have to be sign extended */
...@@ -175,7 +176,7 @@ static inline void u_put(ae_streamp strm, int64_t sample) ...@@ -175,7 +176,7 @@ static inline void u_put(ae_streamp strm, int64_t sample)
state->samples_out++; state->samples_out++;
} }
static inline int64_t u_get(ae_streamp strm, unsigned int n) static inline int64_t u_get(aec_streamp strm, unsigned int n)
{ {
/** /**
Unsafe get n bit from input stream Unsafe get n bit from input stream
...@@ -197,7 +198,7 @@ static inline int64_t u_get(ae_streamp strm, unsigned int n) ...@@ -197,7 +198,7 @@ static inline int64_t u_get(ae_streamp strm, unsigned int n)
return (state->acc >> state->bitp) & ((1ULL << n) - 1); return (state->acc >> state->bitp) & ((1ULL << n) - 1);
} }
static inline int64_t u_get_fs(ae_streamp strm) static inline int64_t u_get_fs(aec_streamp strm)
{ {
/** /**
Interpret a Fundamental Sequence from the input buffer. Interpret a Fundamental Sequence from the input buffer.
...@@ -214,7 +215,7 @@ static inline int64_t u_get_fs(ae_streamp strm) ...@@ -214,7 +215,7 @@ static inline int64_t u_get_fs(ae_streamp strm)
return fs; return fs;
} }
static inline void fast_split(ae_streamp strm) static inline void fast_split(aec_streamp strm)
{ {
int i, k; int i, k;
decode_state *state; decode_state *state;
...@@ -235,7 +236,7 @@ static inline void fast_split(ae_streamp strm) ...@@ -235,7 +236,7 @@ static inline void fast_split(ae_streamp strm)
} }
} }
static inline void fast_zero(ae_streamp strm) static inline void fast_zero(aec_streamp strm)
{ {
int i = strm->state->i; int i = strm->state->i;
...@@ -243,7 +244,7 @@ static inline void fast_zero(ae_streamp strm) ...@@ -243,7 +244,7 @@ static inline void fast_zero(ae_streamp strm)
u_put(strm, 0); u_put(strm, 0);
} }
static inline void fast_se(ae_streamp strm) static inline void fast_se(aec_streamp strm)
{ {
int i; int i;
int64_t gamma, beta, ms, delta1; int64_t gamma, beta, ms, delta1;
...@@ -267,7 +268,7 @@ static inline void fast_se(ae_streamp strm) ...@@ -267,7 +268,7 @@ static inline void fast_se(ae_streamp strm)
} }
} }
static inline void fast_uncomp(ae_streamp strm) static inline void fast_uncomp(aec_streamp strm)
{ {
int i; int i;
...@@ -275,7 +276,7 @@ static inline void fast_uncomp(ae_streamp strm) ...@@ -275,7 +276,7 @@ static inline void fast_uncomp(ae_streamp strm)
u_put(strm, u_get(strm, strm->bit_per_sample)); u_put(strm, u_get(strm, strm->bit_per_sample));
} }
int ae_decode_init(ae_streamp strm) int aec_decode_init(aec_streamp strm)
{ {
int i, modi; int i, modi;
decode_state *state; decode_state *state;
...@@ -283,14 +284,14 @@ int ae_decode_init(ae_streamp strm) ...@@ -283,14 +284,14 @@ int ae_decode_init(ae_streamp strm)
/* Some sanity checks */ /* Some sanity checks */
if (strm->bit_per_sample > 32 || strm->bit_per_sample == 0) if (strm->bit_per_sample > 32 || strm->bit_per_sample == 0)
{ {
return AE_CONF_ERROR; return AEC_CONF_ERROR;
} }
/* Internal state for decoder */ /* Internal state for decoder */
state = (decode_state *) malloc(sizeof(decode_state)); state = (decode_state *) malloc(sizeof(decode_state));
if (state == NULL) if (state == NULL)
{ {
return AE_MEM_ERROR; return AEC_MEM_ERROR;
} }
strm->state = state; strm->state = state;
...@@ -298,10 +299,10 @@ int ae_decode_init(ae_streamp strm) ...@@ -298,10 +299,10 @@ int ae_decode_init(ae_streamp strm)
{ {
state->id_len = 5; state->id_len = 5;
if (strm->bit_per_sample <= 24 && strm->flags & AE_DATA_3BYTE) if (strm->bit_per_sample <= 24 && strm->flags & AEC_DATA_3BYTE)
{ {
state->byte_per_sample = 3; state->byte_per_sample = 3;
if (strm->flags & AE_DATA_MSB) if (strm->flags & AEC_DATA_MSB)
state->put_sample = put_msb_24; state->put_sample = put_msb_24;
else else
state->put_sample = put_lsb_24; state->put_sample = put_lsb_24;
...@@ -309,7 +310,7 @@ int ae_decode_init(ae_streamp strm) ...@@ -309,7 +310,7 @@ int ae_decode_init(ae_streamp strm)
else else
{ {
state->byte_per_sample = 4; state->byte_per_sample = 4;
if (strm->flags & AE_DATA_MSB) if (strm->flags & AEC_DATA_MSB)
state->put_sample = put_msb_32; state->put_sample = put_msb_32;
else else
state->put_sample = put_lsb_32; state->put_sample = put_lsb_32;
...@@ -322,7 +323,7 @@ int ae_decode_init(ae_streamp strm) ...@@ -322,7 +323,7 @@ int ae_decode_init(ae_streamp strm)
state->byte_per_sample = 2; state->byte_per_sample = 2;
state->id_len = 4; state->id_len = 4;
state->out_blklen = strm->block_size * 2; state->out_blklen = strm->block_size * 2;
if (strm->flags & AE_DATA_MSB) if (strm->flags & AEC_DATA_MSB)
state->put_sample = put_msb_16; state->put_sample = put_msb_16;
else else
state->put_sample = put_lsb_16; state->put_sample = put_lsb_16;
...@@ -333,10 +334,9 @@ int ae_decode_init(ae_streamp strm) ...@@ -333,10 +334,9 @@ int ae_decode_init(ae_streamp strm)
state->id_len = 3; state->id_len = 3;
state->out_blklen = strm->block_size; state->out_blklen = strm->block_size;
state->put_sample = put_8; state->put_sample = put_8;
} }
if (strm->flags & AE_DATA_SIGNED) if (strm->flags & AEC_DATA_SIGNED)
{ {
state->xmin = -(1ULL << (strm->bit_per_sample - 1)); state->xmin = -(1ULL << (strm->bit_per_sample - 1));
state->xmax = (1ULL << (strm->bit_per_sample - 1)) - 1; state->xmax = (1ULL << (strm->bit_per_sample - 1)) - 1;
...@@ -355,7 +355,7 @@ int ae_decode_init(ae_streamp strm) ...@@ -355,7 +355,7 @@ int ae_decode_init(ae_streamp strm)
state->id_table = (int *)malloc(modi * sizeof(int)); state->id_table = (int *)malloc(modi * sizeof(int));
if (state->id_table == NULL) if (state->id_table == NULL)
{ {
return AE_MEM_ERROR; return AEC_MEM_ERROR;
} }
state->id_table[0] = M_LOW_ENTROPY; state->id_table[0] = M_LOW_ENTROPY;
for (i = 1; i < modi - 1; i++) for (i = 1; i < modi - 1; i++)
...@@ -367,7 +367,7 @@ int ae_decode_init(ae_streamp strm) ...@@ -367,7 +367,7 @@ int ae_decode_init(ae_streamp strm)
state->block = (int64_t *)malloc(strm->block_size * sizeof(int64_t)); state->block = (int64_t *)malloc(strm->block_size * sizeof(int64_t));
if (state->block == NULL) if (state->block == NULL)
{ {
return AE_MEM_ERROR; return AEC_MEM_ERROR;
} }
strm->total_in = 0; strm->total_in = 0;
strm->total_out = 0; strm->total_out = 0;
...@@ -375,12 +375,12 @@ int ae_decode_init(ae_streamp strm) ...@@ -375,12 +375,12 @@ int ae_decode_init(ae_streamp strm)
state->samples_out = 0; state->samples_out = 0;
state->bitp = 0; state->bitp = 0;
state->fs = 0; state->fs = 0;
state->pp = strm->flags & AE_DATA_PREPROCESS; state->pp = strm->flags & AEC_DATA_PREPROCESS;
state->mode = M_ID; state->mode = M_ID;
return AE_OK; return AEC_OK;
} }
int ae_decode_end(ae_streamp strm) int aec_decode_end(aec_streamp strm)
{ {
decode_state *state; decode_state *state;
...@@ -388,7 +388,7 @@ int ae_decode_end(ae_streamp strm) ...@@ -388,7 +388,7 @@ int ae_decode_end(ae_streamp strm)
free(state->block); free(state->block);
free(state->id_table); free(state->id_table);
free(state); free(state);
return AE_OK; return AEC_OK;
} }
#define ASK(n) \ #define ASK(n) \
...@@ -452,7 +452,7 @@ int ae_decode_end(ae_streamp strm) ...@@ -452,7 +452,7 @@ int ae_decode_end(ae_streamp strm)
} while (0) } while (0)
int ae_decode(ae_streamp strm, int flush) int aec_decode(aec_streamp strm, int flush)
{ {
/** /**
Finite-state machine implementation of the adaptive entropy Finite-state machine implementation of the adaptive entropy
...@@ -643,10 +643,10 @@ int ae_decode(ae_streamp strm, int flush) ...@@ -643,10 +643,10 @@ int ae_decode(ae_streamp strm, int flush)
break; break;
default: default:
return AE_STREAM_ERROR; return AEC_STREAM_ERROR;
} }
} }
req_buffer: req_buffer:
return AE_OK; return AEC_OK;
} }
/** /**
* @file aee.c * @file encode.c
* @author Mathis Rosenhauer, Deutsches Klimarechenzentrum * @author Mathis Rosenhauer, Deutsches Klimarechenzentrum
* @section DESCRIPTION * @section DESCRIPTION
* *
...@@ -14,25 +14,25 @@ ...@@ -14,25 +14,25 @@
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
#include "libae.h" #include "libaec.h"
#include "aee.h" #include "encode.h"
#include "aee_accessors.h" #include "encode_accessors.h"
/* Marker for Remainder Of Segment condition in zero block encoding */ /* Marker for Remainder Of Segment condition in zero block encoding */
#define ROS -1 #define ROS -1