From 8553e038bb00b55021c68fb6b59c195d18086cba Mon Sep 17 00:00:00 2001 From: Mathis Rosenhauer Date: Tue, 4 Feb 2014 11:21:06 +0100 Subject: [PATCH] option to pad RSI to byte boundary --- src/aec.c | 18 +++++++++++------- src/decode.c | 4 +++- src/encode.c | 2 +- src/libaec.h | 5 ++++- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/aec.c b/src/aec.c index d3e8569..d87383a 100644 --- a/src/aec.c +++ b/src/aec.c @@ -84,7 +84,7 @@ int main(int argc, char *argv[]) strm.flags = AEC_DATA_PREPROCESS; opterr = 0; - while ((c = getopt (argc, argv, "3b:cdj:mn:r:st")) != -1) + while ((c = getopt (argc, argv, "3b:cdj:mn:pr:st")) != -1) switch (c) { case '3': strm.flags |= AEC_DATA_3BYTE; @@ -107,6 +107,9 @@ int main(int argc, char *argv[]) case 'n': strm.bits_per_sample = atoi(optarg); break; + case 'p': + strm.flags |= AEC_PAD_RSI; + break; case 'r': strm.rsi = atoi(optarg); break; @@ -114,7 +117,7 @@ int main(int argc, char *argv[]) strm.flags |= AEC_DATA_SIGNED; break; case 't': - strm.flags |= AEC_DATA_RESTRICT; + strm.flags |= AEC_RESTRICTED; break; case '?': if (optopt == 'b') @@ -136,13 +139,14 @@ int main(int argc, char *argv[]) fprintf(stderr, "Usage: %s [OPTION] SOURCE\n", argv[0]); fprintf(stderr, "\nOPTIONS\n"); fprintf(stderr, "-3\n 24 bit samples are sored in 3 bytes\n"); - fprintf(stderr, "-b\n internal buffer size\n"); + fprintf(stderr, "-b size\n internal buffer sizein bytes\n"); fprintf(stderr, "-c\n write output on standard output\n"); - fprintf(stderr, "-d\n decode SOURCE. If -d is not specified encode.\n"); - fprintf(stderr, "-j\n block size in samples\n"); + fprintf(stderr, "-d\n decode SOURCE. If -d is not used: encode.\n"); + fprintf(stderr, "-j samples\n block size in samples\n"); fprintf(stderr, "-m\n samples are MSB first. Default is LSB\n"); - fprintf(stderr, "-n\n bits per sample\n"); - fprintf(stderr, "-r\n reference sample interval in blocks\n"); + fprintf(stderr, "-n bits\n bits per sample\n"); + fprintf(stderr, "-p\n pad RSI to byte boundary\n"); + fprintf(stderr, "-r blocks\n reference sample interval in blocks\n"); fprintf(stderr, "-s\n samples are signed. Default is unsigned\n"); fprintf(stderr, "-t\n use restricted set of code options\n\n"); exit(-1); diff --git a/src/decode.c b/src/decode.c index 18bd208..c916b41 100644 --- a/src/decode.c +++ b/src/decode.c @@ -202,6 +202,8 @@ static inline void check_rsi_end(struct aec_stream *strm) state->flush_output(strm); state->flush_start = state->rsi_buffer; state->rsip = state->rsi_buffer; + if (strm->flags & AEC_PAD_RSI) + state->bitp -= state->bitp % 8; } } @@ -669,7 +671,7 @@ int aec_decode_init(struct aec_stream *strm) else state->flush_output = flush_lsb_16; } else { - if (strm->flags & AEC_DATA_RESTRICT) { + if (strm->flags & AEC_RESTRICTED) { if (strm->bits_per_sample <= 4) { if (strm->bits_per_sample <= 2) state->id_len = 1; diff --git a/src/encode.c b/src/encode.c index 0446f31..77e3f89 100644 --- a/src/encode.c +++ b/src/encode.c @@ -817,7 +817,7 @@ int aec_encode_init(struct aec_stream *strm) } } else { /* 8 bit settings */ - if (strm->flags & AEC_DATA_RESTRICT) { + if (strm->flags & AEC_RESTRICTED) { if (strm->bits_per_sample <= 4) { if (strm->bits_per_sample <= 2) state->id_len = 1; diff --git a/src/libaec.h b/src/libaec.h index a1ea645..cab1795 100644 --- a/src/libaec.h +++ b/src/libaec.h @@ -94,7 +94,10 @@ struct aec_stream { * of the host. Default is LSB. */ #define AEC_DATA_PREPROCESS 8 /* Set if preprocessor should be used */ -#define AEC_DATA_RESTRICT 16 /* Use restricted set of code options */ + +#define AEC_RESTRICTED 16 /* Use restricted set of code options */ +#define AEC_PAD_RSI 32 /* Pad RSI to byte boundary. Only for + * decoding CCSDS sample data. */ /* Return codes of library functions */ #define AEC_OK 0 -- 2.7.4