10 #include "encode_accessors.h"
12 uint32_t get_8(struct aec_stream *strm)
16 return *strm->next_in++;
19 uint32_t get_lsb_24(struct aec_stream *strm)
23 data = ((uint32_t)strm->next_in[2] << 16)
24 | ((uint32_t)strm->next_in[1] << 8)
25 | (uint32_t)strm->next_in[0];
33 uint32_t get_msb_24(struct aec_stream *strm)
37 data = ((uint32_t)strm->next_in[0] << 16)
38 | ((uint32_t)strm->next_in[1] << 8)
39 | (uint32_t)strm->next_in[2];
47 #ifdef WORDS_BIGENDIAN
49 uint32_t get_lsb_16(struct aec_stream *strm)
53 data = ((uint32_t)strm->next_in[1] << 8)
54 | (uint32_t)strm->next_in[0];
62 uint32_t get_msb_16(struct aec_stream *strm)
66 data = *(uint16_t *)strm->next_in;
73 uint32_t get_lsb_32(struct aec_stream *strm)
77 data = ((uint32_t)strm->next_in[3] << 24)
78 | ((uint32_t)strm->next_in[2] << 16)
79 | ((uint32_t)strm->next_in[1] << 8)
80 | (uint32_t)strm->next_in[0];
88 uint32_t get_msb_32(struct aec_stream *strm)
92 data = *(uint32_t *)strm->next_in;
98 #else /* not WORDS_BIGENDIAN */
100 uint32_t get_lsb_16(struct aec_stream *strm)
104 data = *(uint16_t *)strm->next_in;
111 uint32_t get_msb_16(struct aec_stream *strm)
115 data = ((uint32_t)strm->next_in[0] << 8)
116 | (uint32_t)strm->next_in[1];
124 uint32_t get_lsb_32(struct aec_stream *strm)
128 data = *(uint32_t *)strm->next_in;
135 uint32_t get_msb_32(struct aec_stream *strm)
139 data = ((uint32_t)strm->next_in[0] << 24)
140 | ((uint32_t)strm->next_in[1] << 16)
141 | ((uint32_t)strm->next_in[2] << 8)
142 | (uint32_t)strm->next_in[3];
149 #endif /* not WORDS_BIGENDIAN */
151 #define GET_BLOCK_8(BS) \
152 static void get_block_8_bs_##BS(struct aec_stream *strm) \
155 uint32_t *block = strm->state->block_buf; \
157 for (i = 0; i < strm->rsi; i++) \
158 for (j = 0; j < BS; j++) \
159 block[i * BS + j] = strm->next_in[i * BS + j]; \
161 strm->next_in += BS * strm->rsi; \
162 strm->total_in += BS * strm->rsi; \
163 strm->avail_in -= BS * strm->rsi; \
166 #define GET_BLOCK_NATIVE_16(BS) \
167 static void get_block_native_16_bs_##BS(struct aec_stream *strm) \
170 uint32_t *block = strm->state->block_buf; \
171 uint16_t *next_in = (uint16_t *)strm->next_in; \
173 for (i = 0; i < strm->rsi; i++) \
174 for (j = 0; j < BS; j++) \
175 block[i * BS + j] = (uint32_t)next_in[i * BS + j]; \
177 strm->next_in += 2 * BS * strm->rsi; \
178 strm->total_in += 2 * BS * strm->rsi; \
179 strm->avail_in -= 2 * BS * strm->rsi; \
182 #define GET_BLOCK_LSB_16(BS) \
183 static void get_block_lsb_16_bs_##BS(struct aec_stream *strm) \
186 uint32_t *block = strm->state->block_buf; \
188 for (i = 0; i < strm->rsi; i++) \
189 for (j = 0; j < BS; j++) \
190 block[i * BS + j] = \
191 (uint32_t)strm->next_in[2 * (i * BS + j)] \
192 | ((uint32_t)strm->next_in[2 * (i * BS + j) + 1] \
195 strm->next_in += 2 * BS * strm->rsi; \
196 strm->total_in += 2 * BS * strm->rsi; \
197 strm->avail_in -= 2 * BS * strm->rsi; \
200 #define GET_BLOCK_MSB_16(BS) \
201 static void get_block_msb_16_bs_##BS(struct aec_stream *strm) \
204 uint32_t *block = strm->state->block_buf; \
206 for (i = 0; i < strm->rsi; i++) \
207 for (j = 0; j < BS; j++) \
208 block[i * BS + j] = \
209 ((uint32_t)strm->next_in[2 * (i * BS + j)] << 8) \
210 | (uint32_t)strm->next_in[2 * (i * BS + j) + 1]; \
212 strm->next_in += 2 * BS * strm->rsi; \
213 strm->total_in += 2 * BS * strm->rsi; \
214 strm->avail_in -= 2 * BS * strm->rsi; \
217 #define GET_BLOCK_LSB_24(BS) \
218 static void get_block_lsb_24_bs_##BS(struct aec_stream *strm) \
221 uint32_t *block = strm->state->block_buf; \
223 for (i = 0; i < strm->rsi; i++) \
224 for (j = 0; j < BS; j++) \
225 block[i * BS + j] = \
226 (uint32_t)strm->next_in[3 * (i * BS + j)] \
227 | ((uint32_t)strm->next_in[3 * (i * BS + j) + 1] \
229 | ((uint32_t)strm->next_in[3 * (i * BS + j) + 2] \
232 strm->next_in += 3 * BS * strm->rsi; \
233 strm->total_in += 3 * BS * strm->rsi; \
234 strm->avail_in -= 3 * BS * strm->rsi; \
237 #define GET_BLOCK_MSB_24(BS) \
238 static void get_block_msb_24_bs_##BS(struct aec_stream *strm) \
241 uint32_t *block = strm->state->block_buf; \
243 for (i = 0; i < strm->rsi; i++) \
244 for (j = 0; j < BS; j++) \
245 block[i * BS + j] = \
246 ((uint32_t)strm->next_in[3 * (i * BS + j)] \
248 | ((uint32_t)strm->next_in[3 * (i * BS + j) + 1] \
250 | (uint32_t)strm->next_in[3 * (i * BS + j) + 2]; \
252 strm->next_in += 3 * BS * strm->rsi; \
253 strm->total_in += 3 * BS * strm->rsi; \
254 strm->avail_in -= 3 * BS * strm->rsi; \
257 #define GET_BLOCK_NATIVE_32(BS) \
258 static void get_block_native_32_bs_##BS(struct aec_stream *strm) \
260 memcpy(strm->state->block_buf, \
262 4 * BS * strm->rsi); \
264 strm->next_in += 4 * BS * strm->rsi; \
265 strm->total_in += 4 * BS * strm->rsi; \
266 strm->avail_in -= 4 * BS * strm->rsi; \
269 #define GET_BLOCK_LSB_32(BS) \
270 static void get_block_lsb_32_bs_##BS(struct aec_stream *strm) \
273 uint32_t *block = strm->state->block_buf; \
275 for (i = 0; i < strm->rsi; i++) \
276 for (j = 0; j < BS; j++) \
277 block[i * BS + j] = \
278 (uint32_t)strm->next_in[4 * (i * BS + j)] \
279 | ((uint32_t)strm->next_in[4 * (i * BS + j) + 1] \
281 | ((uint32_t)strm->next_in[4 * (i * BS + j) + 2] \
283 | ((uint32_t)strm->next_in[4 * (i * BS + j) + 3] \
286 strm->next_in += 4 * BS * strm->rsi; \
287 strm->total_in += 4 * BS * strm->rsi; \
288 strm->avail_in -= 4 * BS * strm->rsi; \
291 #define GET_BLOCK_MSB_32(BS) \
292 static void get_block_msb_32_bs_##BS(struct aec_stream *strm) \
295 uint32_t *block = strm->state->block_buf; \
297 for (i = 0; i < strm->rsi; i++) \
298 for (j = 0; j < BS; j++) \
299 block[i * BS + j] = \
300 ((uint32_t)strm->next_in[4 * (i * BS + j)] \
302 | ((uint32_t)strm->next_in[4 * (i * BS + j) + 1] \
304 | ((uint32_t)strm->next_in[4 * (i * BS + j) + 2] \
306 | (uint32_t)strm->next_in[4 * (i * BS + j) + 3]; \
308 strm->next_in += 4 * BS * strm->rsi; \
309 strm->total_in += 4 * BS * strm->rsi; \
310 strm->avail_in -= 4 * BS * strm->rsi; \
313 #define GET_BLOCK_FUNCS(A, B) \
314 void (*get_block_funcs_##A[])(struct aec_stream *) = { \
315 get_block_##B##_bs_8, \
316 get_block_##B##_bs_16, \
317 get_block_##B##_bs_32, \
318 get_block_##B##_bs_64, \
326 GET_BLOCK_FUNCS(8, 8);
329 GET_BLOCK_LSB_24(16);
330 GET_BLOCK_LSB_24(32);
331 GET_BLOCK_LSB_24(64);
333 GET_BLOCK_FUNCS(lsb_24, lsb_24);
336 GET_BLOCK_MSB_24(16);
337 GET_BLOCK_MSB_24(32);
338 GET_BLOCK_MSB_24(64);
340 GET_BLOCK_FUNCS(msb_24, msb_24);
342 GET_BLOCK_NATIVE_16(8);
343 GET_BLOCK_NATIVE_16(16);
344 GET_BLOCK_NATIVE_16(32);
345 GET_BLOCK_NATIVE_16(64);
347 GET_BLOCK_NATIVE_32(8);
348 GET_BLOCK_NATIVE_32(16);
349 GET_BLOCK_NATIVE_32(32);
350 GET_BLOCK_NATIVE_32(64);
352 #ifdef WORDS_BIGENDIAN
355 GET_BLOCK_LSB_16(16);
356 GET_BLOCK_LSB_16(32);
357 GET_BLOCK_LSB_16(64);
360 GET_BLOCK_LSB_32(16);
361 GET_BLOCK_LSB_32(32);
362 GET_BLOCK_LSB_32(64);
364 GET_BLOCK_FUNCS(lsb_16, lsb_16);
365 GET_BLOCK_FUNCS(msb_16, native_16);
366 GET_BLOCK_FUNCS(lsb_32, lsb_32);
367 GET_BLOCK_FUNCS(msb_32, native_32);
369 #else /* not WORDS_BIGENDIAN */
372 GET_BLOCK_MSB_16(16);
373 GET_BLOCK_MSB_16(32);
374 GET_BLOCK_MSB_16(64);
377 GET_BLOCK_MSB_32(16);
378 GET_BLOCK_MSB_32(32);
379 GET_BLOCK_MSB_32(64);
381 GET_BLOCK_FUNCS(lsb_16, native_16);
382 GET_BLOCK_FUNCS(msb_16, msb_16);
383 GET_BLOCK_FUNCS(lsb_32, native_32);
384 GET_BLOCK_FUNCS(msb_32, msb_32);
386 #endif /* not WORDS_BIGENDIAN */