libaec.h 5.98 KB
Newer Older
1 2 3 4 5 6 7 8 9
/**
 * @file libaec.h
 *
 * @author Mathis Rosenhauer, Deutsches Klimarechenzentrum
 * @author Moritz Hanke, Deutsches Klimarechenzentrum
 * @author Joerg Behrens, Deutsches Klimarechenzentrum
 * @author Luis Kornblueh, Max-Planck-Institut fuer Meteorologie
 *
 * @section LICENSE
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
10
 * Copyright 2012 - 2014
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
 *
 * Mathis Rosenhauer,                 Luis Kornblueh
 * Moritz Hanke,
 * Joerg Behrens
 *
 * Deutsches Klimarechenzentrum GmbH  Max-Planck-Institut fuer Meteorologie
 * Bundesstr. 45a                     Bundesstr. 53
 * 20146 Hamburg                      20146 Hamburg
 * Germany                            Germany
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above
 *    copyright notice, this list of conditions and the following
 *    disclaimer in the documentation and/or other materials provided
 *    with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @section DESCRIPTION
 *
 * Adaptive Entropy Coding library
 *
 */

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
53
#ifndef LIBAEC_H
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
54
#define LIBAEC_H 1
55

56
#include <stddef.h>
57

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
58 59 60 61
#if HAVE_CONFIG_H
#  include <config.h>
#endif

62
#if _WIN32 && BUILD_SHARED_LIBS
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
63
#  ifdef DLL_EXPORT
64
#    define AEC_SCOPE __declspec(dllexport)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
65
#  else
66
#    define AEC_SCOPE extern __declspec(dllimport)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
67
#  endif
68 69
#else
#  define AEC_SCOPE extern
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
70 71
#endif

72 73
struct internal_state;

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
74
struct aec_stream {
75
    const unsigned char *next_in;
76 77 78 79 80 81
    size_t avail_in;            /* number of bytes available at
                                 * next_in
                                 */
    size_t total_in;            /* total number of input bytes read so
                                 * far
                                 */
82
    unsigned char *next_out;
83 84
    size_t avail_out;           /* remaining free space at next_out */
    size_t total_out;           /* total number of bytes output so far */
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
85
    int bits_per_sample;        /* resolution in bits per sample (n =
86 87 88
                                 * 1, ..., 32)
                                 */
    int block_size;             /* block size in samples */
89 90 91 92
    int rsi;                    /* Reference sample interval, the
                                 * number of Coded Data Sets between
                                 * consecutive reference samples (up
                                 * to 4096).
93
                                 */
94
    int flags;
95

96
    struct internal_state *state;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
97
};
98

99
/* Sample data description flags */
100
#define AEC_DATA_SIGNED 1        /* Samples are signed. Telling libaec
101
                                  * this results in a slightly better
102 103
                                  * compression ratio. Default is
                                  * unsigned.
104
                                  */
105 106
#define AEC_DATA_3BYTE 2         /* 24 bit samples are coded in 3 bytes */
#define AEC_DATA_MSB 4           /* Samples are stored with their most
107 108
                                  * significant bit first. This has
                                  * nothing to do with the endianness
109
                                  * of the host. Default is LSB.
110
                                  */
111
#define AEC_DATA_PREPROCESS 8    /* Set if preprocessor should be used */
112 113 114 115

#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. */
116 117

/* Return codes of library functions */
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
118 119 120 121 122
#define AEC_OK            0
#define AEC_CONF_ERROR   (-1)
#define AEC_STREAM_ERROR (-2)
#define AEC_DATA_ERROR   (-3)
#define AEC_MEM_ERROR    (-4)
123

124
/* Options for flushing */
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
#define AEC_NO_FLUSH      0      /* Do not enforce output
                                  * flushing. More input may be
                                  * provided with later calls. So far
                                  * only relevant for encoding.
                                  */
#define AEC_FLUSH         1      /* Flush output and end encoding. The
                                  * last call to aec_encode() must set
                                  * AEC_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.
                                  */

/* Streaming encoding and decoding functions */
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
141 142 143
AEC_SCOPE int aec_encode_init(struct aec_stream *strm);
AEC_SCOPE int aec_encode(struct aec_stream *strm, int flush);
AEC_SCOPE int aec_encode_end(struct aec_stream *strm);
144

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
145 146 147
AEC_SCOPE int aec_decode_init(struct aec_stream *strm);
AEC_SCOPE int aec_decode(struct aec_stream *strm, int flush);
AEC_SCOPE int aec_decode_end(struct aec_stream *strm);
148

149
/* Utility functions for encoding or decoding a memory buffer. */
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
150 151
AEC_SCOPE int aec_buffer_encode(struct aec_stream *strm);
AEC_SCOPE int aec_buffer_decode(struct aec_stream *strm);
152

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
153
#endif /* LIBAEC_H */