2 * @file encode_accessors.c
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
12 * Mathis Rosenhauer, Luis Kornblueh
16 * Deutsches Klimarechenzentrum GmbH Max-Planck-Institut fuer Meteorologie
17 * Bundesstr. 45a Bundesstr. 53
18 * 20146 Hamburg 20146 Hamburg
21 * All rights reserved.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
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.
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.
47 * @section DESCRIPTION
49 * Read various data types from input stream
62 #include "encode_accessors.h"
64 uint32_t aec_get_8(struct aec_stream *strm)
67 return *strm->next_in++;
70 uint32_t aec_get_lsb_16(struct aec_stream *strm)
74 data = ((uint32_t)strm->next_in[1] << 8)
75 | (uint32_t)strm->next_in[0];
82 uint32_t aec_get_msb_16(struct aec_stream *strm)
86 data = ((uint32_t)strm->next_in[0] << 8)
87 | (uint32_t)strm->next_in[1];
94 uint32_t aec_get_lsb_24(struct aec_stream *strm)
98 data = ((uint32_t)strm->next_in[2] << 16)
99 | ((uint32_t)strm->next_in[1] << 8)
100 | (uint32_t)strm->next_in[0];
107 uint32_t aec_get_msb_24(struct aec_stream *strm)
111 data = ((uint32_t)strm->next_in[0] << 16)
112 | ((uint32_t)strm->next_in[1] << 8)
113 | (uint32_t)strm->next_in[2];
120 uint32_t aec_get_lsb_32(struct aec_stream *strm)
124 data = ((uint32_t)strm->next_in[3] << 24)
125 | ((uint32_t)strm->next_in[2] << 16)
126 | ((uint32_t)strm->next_in[1] << 8)
127 | (uint32_t)strm->next_in[0];
134 uint32_t aec_get_msb_32(struct aec_stream *strm)
138 data = ((uint32_t)strm->next_in[0] << 24)
139 | ((uint32_t)strm->next_in[1] << 16)
140 | ((uint32_t)strm->next_in[2] << 8)
141 | (uint32_t)strm->next_in[3];
148 void aec_get_rsi_8(struct aec_stream *strm)
151 uint32_t *restrict out = strm->state->data_raw;
152 unsigned const char *restrict in = strm->next_in;
153 int rsi = strm->rsi * strm->block_size;
155 for (i = 0; i < rsi; i++)
156 out[i] = (uint32_t)in[i];
158 strm->next_in += rsi;
159 strm->avail_in -= rsi;
162 void aec_get_rsi_lsb_16(struct aec_stream *strm)
165 uint32_t *restrict out = strm->state->data_raw;
166 const unsigned char *restrict in = strm->next_in;
167 int rsi = strm->rsi * strm->block_size;
169 for (i = 0; i < rsi; i++)
170 out[i] = (uint32_t)in[2 * i] | ((uint32_t)in[2 * i + 1] << 8);
172 strm->next_in += 2 * rsi;
173 strm->avail_in -= 2 * rsi;
176 void aec_get_rsi_msb_16(struct aec_stream *strm)
179 uint32_t *restrict out = strm->state->data_raw;
180 const unsigned char *restrict in = strm->next_in;
181 int rsi = strm->rsi * strm->block_size;
183 for (i = 0; i < rsi; i++)
184 out[i] = ((uint32_t)in[2 * i] << 8) | (uint32_t)in[2 * i + 1];
186 strm->next_in += 2 * rsi;
187 strm->avail_in -= 2 * rsi;
190 void aec_get_rsi_lsb_24(struct aec_stream *strm)
193 uint32_t *restrict out = strm->state->data_raw;
194 const unsigned char *restrict in = strm->next_in;
195 int rsi = strm->rsi * strm->block_size;
197 for (i = 0; i < rsi; i++)
198 out[i] = (uint32_t)in[3 * i]
199 | ((uint32_t)in[3 * i + 1] << 8)
200 | ((uint32_t)in[3 * i + 2] << 16);
202 strm->next_in += 3 * rsi;
203 strm->avail_in -= 3 * rsi;
206 void aec_get_rsi_msb_24(struct aec_stream *strm)
209 uint32_t *restrict out = strm->state->data_raw;
210 const unsigned char *restrict in = strm->next_in;
211 int rsi = strm->rsi * strm->block_size;
213 for (i = 0; i < rsi; i++)
214 out[i] = ((uint32_t)in[3 * i] << 16)
215 | ((uint32_t)in[3 * i + 1] << 8)
216 | (uint32_t)in[3 * i + 2];
218 strm->next_in += 3 * rsi;
219 strm->avail_in -= 3 * rsi;
222 #define AEC_GET_RSI_NATIVE_32(BO) \
223 void aec_get_rsi_##BO##_32(struct aec_stream *strm) \
225 int rsi = strm->rsi * strm->block_size; \
226 memcpy(strm->state->data_raw, \
227 strm->next_in, 4 * rsi); \
228 strm->next_in += 4 * rsi; \
229 strm->avail_in -= 4 * rsi; \
232 #ifdef WORDS_BIGENDIAN
233 void aec_get_rsi_lsb_32(struct aec_stream *strm)
236 uint32_t *restrict out = strm->state->data_raw;
237 const unsigned char *restrict in = strm->next_in;
238 int rsi = strm->rsi * strm->block_size;
240 for (i = 0; i < rsi; i++)
241 out[i] = (uint32_t)in[4 * i]
242 | ((uint32_t)in[4 * i + 1] << 8)
243 | ((uint32_t)in[4 * i + 2] << 16)
244 | ((uint32_t)in[4 * i + 3] << 24);
246 strm->next_in += 4 * rsi;
247 strm->avail_in -= 4 * rsi;
250 AEC_GET_RSI_NATIVE_32(msb);
252 #else /* !WORDS_BIGENDIAN */
253 void aec_get_rsi_msb_32(struct aec_stream *strm)
256 uint32_t *restrict out = strm->state->data_raw;
257 const unsigned char *restrict in = strm->next_in;
258 int rsi = strm->rsi * strm->block_size;
260 strm->next_in += 4 * rsi;
261 strm->avail_in -= 4 * rsi;
263 for (i = 0; i < rsi; i++)
264 out[i] = ((uint32_t)in[4 * i] << 24)
265 | ((uint32_t)in[4 * i + 1] << 16)
266 | ((uint32_t)in[4 * i + 2] << 8)
267 | (uint32_t)in[4 * i + 3];
270 AEC_GET_RSI_NATIVE_32(lsb);
272 #endif /* !WORDS_BIGENDIAN */