#define ROS -1
#define MIN(a, b) (((a) < (b))? (a): (b))
-#define MAX(a, b) (((a) > (b))? (a): (b))
static int m_get_block(ae_streamp strm);
static int m_get_block_cautious(ae_streamp strm);
int64_t theta, d, Delta;
encode_state *state = strm->state;
- /* If this is the first block between reference
- samples then we need to insert one.
- */
+ /* Insert reference samples into first block of Reference Sample
+ * Interval.
+ */
if(state->in_total_blocks % strm->rsi == 0)
{
state->ref = 1;
static int m_get_block_cautious(ae_streamp strm)
{
+ int pad;
encode_state *state = strm->state;
do
{
if (state->i > 0)
{
- /* pad block with last sample if we have
- a partial block */
+ /* Pad block with last sample if we have a partial
+ * block.
+ */
state->in_block[state->i] = state->in_block[state->i - 1];
}
else
state->mode = m_encode_zero;
return M_CONTINUE;
}
- /* Pad last output byte with 0 bits
- if user wants to flush, i.e. we got
- all input there is.
- */
+
+ if ((strm->flags & AE_DATA_SZ_COMPAT)
+ && (state->in_total_blocks % strm->rsi != 0))
+ {
+ /* If user wants szip copatibility then we
+ * have to pad until but not including the
+ * next reference sample.
+ */
+ pad = 64 - (state->in_total_blocks % strm->rsi % 64);
+ state->in_total_blocks += pad;
+ state->zero_blocks = (pad > 4)? ROS: pad;
+ state->mode = m_encode_zero;
+ return M_CONTINUE;
+ }
+
+ /* Pad last output byte with 0 bits if user wants
+ * to flush, i.e. we got all input there is.
+ */
emit(state, 0, state->bitp);
if (state->out_direct == 0)
*strm->next_out++ = *state->out_bp;
strm->avail_out--;
strm->total_out++;
+
return M_EXIT;
}
}
}
else if (state->zero_blocks)
{
- /* The current block isn't zero but we have to
- emit a previous zero block first. The
- current block will be handled later.
- */
+ /* The current block isn't zero but we have to emit a previous
+ * zero block first. The current block will be handled
+ * later.
+ */
state->block_deferred = 1;
state->mode = m_encode_zero;
return M_CONTINUE;
direction = 1;
looked_bothways = 0;
- /* Starting with splitting position of last block look left
- and possibly right to find new minimum.*/
+ /* Starting with splitting position of last block look left and
+ * possibly right to find new minimum.
+ */
for (;;)
{
fs_len = (state->in_block[1] >> i)
if (split_len_min < INT64_MAX)
{
/* We are moving towards the minimum so it cant be in
- the other direction.*/
+ * the other direction.
+ */
looked_bothways = 1;
}
split_len_min = split_len;
if (fs_len < this_bs)
{
/* Next can't get better because what we lose by
- additional uncompressed bits isn't compensated by a
- smaller FS part. Vice versa if we are coming from
- the other direction.*/
+ * additional uncompressed bits isn't compensated
+ * by a smaller FS part. Vice versa if we are
+ * coming from the other direction.
+ */
if (looked_bothways)
{
break;
else if (fs_len > this_bs)
{
/* Since we started looking the other way there is no
- need to turn back.*/
+ * need to turn back.
+ */
break;
}
}
else
{
- /* Stop looking for better option if we
- don't see any improvement. */
+ /* Stop looking for better option if we don't see any
+ * improvement.
+ */
if (looked_bothways)
{
break;
/* Largest possible block according to specs */
state->out_blklen = (5 + 16 * 32) / 8 + 3;
- /* Output buffer */
state->out_block = (uint8_t *)malloc(state->out_blklen);
if (state->out_block == NULL)
{
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_MSB 16
-#define AE_DATA_PREPROCESS 32 /* Set if preprocessor should be used */
-
+#define AE_DATA_UNSIGNED 0
+#define AE_DATA_SIGNED 1
+#define AE_DATA_LSB 8
+#define AE_DATA_MSB 16
+#define AE_DATA_PREPROCESS 32 /* Set if preprocessor should be used */
+#define AE_DATA_SZ_COMPAT 256 /* Set this if you want szip to decode
+ * our output. Increases output
+ * slightly.
+ */
/* Return codes of library functions */
#define AE_OK 0
#define AE_NO_FLUSH 0 /* Do not enforce output flushing. More
* input may be provided with later
* calls. So far only relevant for
- * encoding. */
+ * encoding.
+ */
#define AE_FLUSH 1 /* Flush output and end encoding. The last
* call to ae_encode() must set AE_FLUSH to
* drain all output.
* It is not possible to continue encoding
* of the same stream after it has been
* flushed because the last byte may be
- * padded with fill bits. */
+ * padded with fill bits.
+ */
int ae_decode_init(ae_streamp strm);
int ae_decode(ae_streamp strm, int flush);