|
| 1 | +/** |
| 2 | + * @file libaec.h |
| 3 | + * |
| 4 | + * @section LICENSE |
| 5 | + * Copyright 2024 Mathis Rosenhauer, Moritz Hanke, Joerg Behrens, Luis Kornblueh |
| 6 | + * All rights reserved. |
| 7 | + * |
| 8 | + * Redistribution and use in source and binary forms, with or without |
| 9 | + * modification, are permitted provided that the following conditions |
| 10 | + * are met: |
| 11 | + * |
| 12 | + * 1. Redistributions of source code must retain the above copyright |
| 13 | + * notice, this list of conditions and the following disclaimer. |
| 14 | + * 2. Redistributions in binary form must reproduce the above |
| 15 | + * copyright notice, this list of conditions and the following |
| 16 | + * disclaimer in the documentation and/or other materials provided |
| 17 | + * with the distribution. |
| 18 | + * |
| 19 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 22 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 23 | + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 24 | + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 25 | + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 26 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 28 | + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 29 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 30 | + * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | + * |
| 32 | + * @section DESCRIPTION |
| 33 | + * |
| 34 | + * Adaptive Entropy Coding library |
| 35 | + * |
| 36 | + */ |
| 37 | + |
| 38 | +#ifndef LIBAEC_H |
| 39 | +#define LIBAEC_H 1 |
| 40 | + |
| 41 | +#define AEC_VERSION_MAJOR 1 |
| 42 | +#define AEC_VERSION_MINOR 1 |
| 43 | +#define AEC_VERSION_PATCH 3 |
| 44 | +#define AEC_VERSION_STR "1.1.3" |
| 45 | + |
| 46 | +#include <stddef.h> |
| 47 | + |
| 48 | +#ifdef __cplusplus |
| 49 | +extern "C"{ |
| 50 | +#endif |
| 51 | + |
| 52 | +#if defined LIBAEC_BUILD && HAVE_VISIBILITY |
| 53 | +# define LIBAEC_DLL_EXPORTED __attribute__((__visibility__("default"))) |
| 54 | +#elif (defined _WIN32 && !defined __CYGWIN__) && defined LIBAEC_SHARED |
| 55 | +# if defined LIBAEC_BUILD |
| 56 | +# define LIBAEC_DLL_EXPORTED __declspec(dllexport) |
| 57 | +# else |
| 58 | +# define LIBAEC_DLL_EXPORTED __declspec(dllimport) |
| 59 | +# endif |
| 60 | +#else |
| 61 | +# define LIBAEC_DLL_EXPORTED |
| 62 | +#endif |
| 63 | + |
| 64 | +struct internal_state; |
| 65 | + |
| 66 | +struct aec_stream { |
| 67 | + const unsigned char *next_in; |
| 68 | + |
| 69 | + /* number of bytes available at next_in */ |
| 70 | + size_t avail_in; |
| 71 | + |
| 72 | + /* total number of input bytes read so far */ |
| 73 | + size_t total_in; |
| 74 | + |
| 75 | + unsigned char *next_out; |
| 76 | + |
| 77 | + /* remaining free space at next_out */ |
| 78 | + size_t avail_out; |
| 79 | + |
| 80 | + /* total number of bytes output so far */ |
| 81 | + size_t total_out; |
| 82 | + |
| 83 | + /* resolution in bits per sample (n = 1, ..., 32) */ |
| 84 | + unsigned int bits_per_sample; |
| 85 | + |
| 86 | + /* block size in samples */ |
| 87 | + unsigned int block_size; |
| 88 | + |
| 89 | + /* Reference sample interval, the number of blocks |
| 90 | + * between consecutive reference samples (up to 4096). */ |
| 91 | + unsigned int rsi; |
| 92 | + |
| 93 | + unsigned int flags; |
| 94 | + |
| 95 | + struct internal_state *state; |
| 96 | +}; |
| 97 | + |
| 98 | +/*********************************/ |
| 99 | +/* Sample data description flags */ |
| 100 | +/*********************************/ |
| 101 | + |
| 102 | +/* Samples are signed. Telling libaec this results in a slightly |
| 103 | + * better compression ratio. Default is unsigned. */ |
| 104 | +#define AEC_DATA_SIGNED 1 |
| 105 | + |
| 106 | +/* 24 bit samples are coded in 3 bytes */ |
| 107 | +#define AEC_DATA_3BYTE 2 |
| 108 | + |
| 109 | +/* Samples are stored with their most significant bit first. This has |
| 110 | + * nothing to do with the endianness of the host. Default is LSB. */ |
| 111 | +#define AEC_DATA_MSB 4 |
| 112 | + |
| 113 | +/* Set if preprocessor should be used */ |
| 114 | +#define AEC_DATA_PREPROCESS 8 |
| 115 | + |
| 116 | +/* Use restricted set of code options */ |
| 117 | +#define AEC_RESTRICTED 16 |
| 118 | + |
| 119 | +/* Pad RSI to byte boundary. Only used for decoding some CCSDS sample |
| 120 | + * data. Do not use this to produce new data as it violates the |
| 121 | + * standard. */ |
| 122 | +#define AEC_PAD_RSI 32 |
| 123 | + |
| 124 | +/* Do not enforce standard regarding legal block sizes. */ |
| 125 | +#define AEC_NOT_ENFORCE 64 |
| 126 | + |
| 127 | +/*************************************/ |
| 128 | +/* Return codes of library functions */ |
| 129 | +/*************************************/ |
| 130 | +#define AEC_OK 0 |
| 131 | +#define AEC_CONF_ERROR (-1) |
| 132 | +#define AEC_STREAM_ERROR (-2) |
| 133 | +#define AEC_DATA_ERROR (-3) |
| 134 | +#define AEC_MEM_ERROR (-4) |
| 135 | +#define AEC_RSI_OFFSETS_ERROR (-5) |
| 136 | + |
| 137 | +/************************/ |
| 138 | +/* Options for flushing */ |
| 139 | +/************************/ |
| 140 | + |
| 141 | +/* Do not enforce output flushing. More input may be provided with |
| 142 | + * later calls. So far only relevant for encoding. */ |
| 143 | +#define AEC_NO_FLUSH 0 |
| 144 | + |
| 145 | +/* Flush output and end encoding. The last call to aec_encode() must |
| 146 | + * set AEC_FLUSH to drain all output. |
| 147 | + * |
| 148 | + * It is not possible to continue encoding of the same stream after it |
| 149 | + * has been flushed. For one, the last block may be padded zeros after |
| 150 | + * preprocessing. Secondly, the last encoded byte may be padded with |
| 151 | + * fill bits. */ |
| 152 | +#define AEC_FLUSH 1 |
| 153 | + |
| 154 | +/*********************************************/ |
| 155 | +/* Streaming encoding and decoding functions */ |
| 156 | +/*********************************************/ |
| 157 | +LIBAEC_DLL_EXPORTED int aec_encode_init(struct aec_stream *strm); |
| 158 | +LIBAEC_DLL_EXPORTED int aec_encode_enable_offsets(struct aec_stream *strm); |
| 159 | +LIBAEC_DLL_EXPORTED int aec_encode_count_offsets(struct aec_stream *strm, size_t *rsi_offsets_count); |
| 160 | +LIBAEC_DLL_EXPORTED int aec_encode_get_offsets(struct aec_stream *strm, size_t *rsi_offsets, size_t rsi_offsets_count); |
| 161 | +LIBAEC_DLL_EXPORTED int aec_buffer_seek(struct aec_stream *strm, size_t offset); |
| 162 | +LIBAEC_DLL_EXPORTED int aec_encode(struct aec_stream *strm, int flush); |
| 163 | +LIBAEC_DLL_EXPORTED int aec_encode_end(struct aec_stream *strm); |
| 164 | + |
| 165 | +LIBAEC_DLL_EXPORTED int aec_decode_init(struct aec_stream *strm); |
| 166 | +LIBAEC_DLL_EXPORTED int aec_decode_enable_offsets(struct aec_stream *strm); |
| 167 | +LIBAEC_DLL_EXPORTED int aec_decode_count_offsets(struct aec_stream *strm, size_t *rsi_offsets_count); |
| 168 | +LIBAEC_DLL_EXPORTED int aec_decode_get_offsets(struct aec_stream *strm, size_t *rsi_offsets, size_t rsi_offsets_count); |
| 169 | +LIBAEC_DLL_EXPORTED int aec_decode(struct aec_stream *strm, int flush); |
| 170 | +LIBAEC_DLL_EXPORTED int aec_decode_range(struct aec_stream *strm, const size_t *rsi_offsets, size_t rsi_offsets_count, size_t pos, size_t size); |
| 171 | +LIBAEC_DLL_EXPORTED int aec_decode_end(struct aec_stream *strm); |
| 172 | + |
| 173 | +/***************************************************************/ |
| 174 | +/* Utility functions for encoding or decoding a memory buffer. */ |
| 175 | +/***************************************************************/ |
| 176 | +LIBAEC_DLL_EXPORTED int aec_buffer_encode(struct aec_stream *strm); |
| 177 | +LIBAEC_DLL_EXPORTED int aec_buffer_decode(struct aec_stream *strm); |
| 178 | + |
| 179 | +#ifdef __cplusplus |
| 180 | +} |
| 181 | +#endif |
| 182 | + |
| 183 | +#endif /* LIBAEC_H */ |
0 commit comments