Small PP improvement, avoid buffer copy
[platform/upstream/libaec.git] / src / libaec.h
1 /**
2  * @file libaec.h
3  *
4  * @author Mathis Rosenhauer, Deutsches Klimarechenzentrum
5  * @author Moritz Hanke, Deutsches Klimarechenzentrum
6  * @author Joerg Behrens, Deutsches Klimarechenzentrum
7  * @author Luis Kornblueh, Max-Planck-Institut fuer Meteorologie
8  *
9  * @section LICENSE
10  * Copyright 2012
11  *
12  * Mathis Rosenhauer,                 Luis Kornblueh
13  * Moritz Hanke,
14  * Joerg Behrens
15  *
16  * Deutsches Klimarechenzentrum GmbH  Max-Planck-Institut fuer Meteorologie
17  * Bundesstr. 45a                     Bundesstr. 53
18  * 20146 Hamburg                      20146 Hamburg
19  * Germany                            Germany
20  *
21  * All rights reserved.
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
26  *
27  * 1. Redistributions of source code must retain the above copyright
28  *    notice, this list of conditions and the following disclaimer.
29  * 2. Redistributions in binary form must reproduce the above
30  *    copyright notice, this list of conditions and the following
31  *    disclaimer in the documentation and/or other materials provided
32  *    with the distribution.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
37  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
38  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
39  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
41  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
43  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
44  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
45  * OF THE POSSIBILITY OF SUCH DAMAGE.
46  *
47  * @section DESCRIPTION
48  *
49  * Adaptive Entropy Coding library
50  *
51  */
52
53 #ifndef LIBAEC_H
54 #define LIBAEC_H
55
56 #include <stddef.h>
57
58 struct internal_state;
59
60 struct aec_stream {
61     const unsigned char *next_in;
62     size_t avail_in;            /* number of bytes available at
63                                  * next_in
64                                  */
65     size_t total_in;            /* total number of input bytes read so
66                                  * far
67                                  */
68     unsigned char *next_out;
69     size_t avail_out;           /* remaining free space at next_out */
70     size_t total_out;           /* total number of bytes output so far */
71     int bits_per_sample;        /* resolution in bits per sample (n =
72                                  * 1, ..., 32)
73                                  */
74     int block_size;             /* block size in samples */
75     int rsi;                    /* Reference sample interval, the number
76                                  * of _blocks_ between consecutive
77                                  * reference samples (up to 4096).
78                                  */
79     int flags;
80
81     struct internal_state *state;
82 };
83
84 /* Sample data description flags */
85 #define AEC_DATA_SIGNED 1        /* Samples are signed. Telling libaec
86                                   * this results in a slightly better
87                                   * compression ratio. Default is
88                                   * unsigned.
89                                   */
90 #define AEC_DATA_3BYTE 2         /* 24 bit samples are coded in 3 bytes */
91 #define AEC_DATA_MSB 4           /* Samples are stored with their most
92                                   * significant bit first. This has
93                                   * nothing to do with the endianness
94                                   * of the host. Default is LSB.
95                                   */
96 #define AEC_DATA_PREPROCESS 8    /* Set if preprocessor should be used */
97
98 /* Return codes of library functions */
99 #define AEC_OK            0
100 #define AEC_CONF_ERROR   (-1)
101 #define AEC_STREAM_ERROR (-2)
102 #define AEC_DATA_ERROR   (-3)
103 #define AEC_MEM_ERROR    (-4)
104
105 /* Options for flushing */
106 #define AEC_NO_FLUSH      0      /* Do not enforce output
107                                   * flushing. More input may be
108                                   * provided with later calls. So far
109                                   * only relevant for encoding.
110                                   */
111 #define AEC_FLUSH         1      /* Flush output and end encoding. The
112                                   * last call to aec_encode() must set
113                                   * AEC_FLUSH to drain all output.
114                                   *
115                                   * It is not possible to continue
116                                   * encoding of the same stream after it
117                                   * has been flushed because the last byte
118                                   * may be padded with fill bits.
119                                   */
120
121 /* Streaming encoding and decoding functions */
122 int aec_encode_init(struct aec_stream *strm);
123 int aec_encode(struct aec_stream *strm, int flush);
124 int aec_encode_end(struct aec_stream *strm);
125
126 int aec_decode_init(struct aec_stream *strm);
127 int aec_decode(struct aec_stream *strm, int flush);
128 int aec_decode_end(struct aec_stream *strm);
129
130 /* Utility functions for encoding or decoding a memory buffer. */
131 int aec_buffer_encode(struct aec_stream *strm);
132 int aec_buffer_decode(struct aec_stream *strm);
133
134 #endif /* LIBAEC_H */