25#define BITSTREAM_READER_LE
34static const int8_t
map_3bit[] = { -4, -3, -2, -1, +1, +2, +3, +4 };
64 for (
int x3 = 0; x3 < 3; x3++)
65 for (
int x2 = 0; x2 < 3; x2++)
66 for (
int x1 = 0; x1 < 3; x1++)
67 mul_3x3[x1 + x2 * 3 + x3 * 3 * 3] = x1 + (x2 << 4) + (x3 << 8);
68 for (
int x3 = 0; x3 < 5; x3++)
69 for (
int x2 = 0; x2 < 5; x2++)
70 for (
int x1 = 0; x1 < 5; x1++)
71 mul_3x5[x1 + x2 * 5 + x3 * 5 * 5] = x1 + (x2 << 4) + (x3 << 8);
72 for (
int x2 = 0; x2 < 11; x2++)
73 for (
int x1 = 0; x1 < 11; x1++)
74 mul_2x11[x1 + x2 * 11] = x1 + (x2 << 4);
92 if (
s->max_samples == 0)
93 s->max_samples = UINT64_MAX;
96 s->cols = 1 <<
s->level;
97 s->wrapbuf_len = 2 *
s->cols - 2;
98 s->block_len =
s->rows *
s->cols;
99 s->max_framesize =
s->block_len;
102 s->wrapbuf =
av_calloc(
s->wrapbuf_len,
sizeof(
int));
105 if (!
s->block || !
s->wrapbuf || !
s->ampbuf || !
s->bitstream)
108 s->midbuf =
s->ampbuf + 0x8000;
116#define set_pos(s, r, c, idx) do { \
117 unsigned pos = ((r) << s->level) + (c); \
118 s->block[pos] = s->midbuf[(idx)]; \
125 for (
i = 0;
i <
s->rows;
i++)
139 int b, middle = 1 << (ind - 1);
141 for (
i = 0;
i <
s->rows;
i++) {
153 for (
i = 0;
i <
s->rows;
i++) {
178 for (
i = 0;
i <
s->rows;
i++) {
196 for (
i = 0;
i <
s->rows;
i++) {
200 if (
i >=
s->rows)
break;
222 for (
i = 0;
i <
s->rows;
i++) {
240 for (
i = 0;
i <
s->rows;
i++) {
274 for (
i = 0;
i <
s->rows;
i++) {
299 for (
i = 0;
i <
s->rows;
i++) {
326 for (
i = 0;
i <
s->rows;
i++) {
345 for (
i = 0;
i <
s->rows;
i++) {
354 n2 = ((
mul_3x3[
b] >> 4) & 0x0F) - 1;
355 n3 = ((
mul_3x3[
b] >> 8) & 0x0F) - 1;
374 for (
i = 0;
i <
s->rows;
i++) {
383 n2 = ((
mul_3x5[
b] >> 4) & 0x0F) - 2;
384 n3 = ((
mul_3x5[
b] >> 8) & 0x0F) - 2;
402 for (
i = 0;
i <
s->rows;
i++) {
443 for (
i = 0;
i <
s->cols;
i++) {
452static void juggle(
int *wrap_p,
int *block_p,
unsigned sub_len,
unsigned sub_count)
456 unsigned int r0, r1, r2, r3;
458 for (
i = 0;
i < sub_len;
i++) {
462 for (j = 0; j < sub_count/2; j++) {
464 *p = r1 * 2 + (r0 + r2);
467 *p = r2 * 2 - (r1 + r3);
481 unsigned sub_count, sub_len, todo_count, step_subcount,
i;
482 int *wrap_p, *block_p, *p;
492 step_subcount = (2048 >>
s->level) - 2;
498 todo_count =
s->rows;
502 sub_count = step_subcount;
503 if (sub_count > todo_count)
504 sub_count = todo_count;
506 sub_len =
s->cols / 2;
509 juggle(wrap_p, block_p, sub_len, sub_count);
510 wrap_p += sub_len * 2;
512 for (
i = 0, p = block_p;
i < sub_count;
i++) {
517 while (sub_len > 1) {
520 juggle(wrap_p, block_p, sub_len, sub_count);
521 wrap_p += sub_len * 2;
524 if (todo_count <= step_subcount)
527 todo_count -= step_subcount;
528 block_p += step_subcount <<
s->level;
535 int pwr, count,
val,
i, x, ret;
542 for (
i = 0, x = 0;
i < count;
i++) {
547 for (
i = 1, x = -
val;
i <= count;
i++) {
568 int ret, n, buf_size, input_buf_size;
570 if (!
pkt->size && !
s->bitstream_size) {
575 buf_size =
FFMIN(
pkt->size,
s->max_framesize -
s->bitstream_size);
576 input_buf_size = buf_size;
577 if (
s->bitstream_index +
s->bitstream_size + buf_size >
s->max_framesize) {
578 memmove(
s->bitstream, &
s->bitstream[
s->bitstream_index],
s->bitstream_size);
579 s->bitstream_index = 0;
582 memcpy(&
s->bitstream[
s->bitstream_index +
s->bitstream_size],
pkt->data, buf_size);
583 buf = &
s->bitstream[
s->bitstream_index];
584 buf_size +=
s->bitstream_size;
585 s->bitstream_size = buf_size;
586 if (buf_size < s->max_framesize &&
pkt->data) {
588 return input_buf_size;
595 s->max_samples -=
FFMIN(
frame->nb_samples,
s->max_samples);
604 samples = (int16_t *)
frame->data[0];
606 int val =
s->block[n] >>
s->level;
614 if (n > buf_size &&
pkt->data) {
615 s->bitstream_size = 0;
616 s->bitstream_index = 0;
620 if (
s->bitstream_size > 0) {
621 s->bitstream_index += n;
622 s->bitstream_size -=
FFMIN(
s->bitstream_size, n);
623 return input_buf_size;
632 s->bitstream_size = 0;
633 s->bitstream_index = 0;
644 s->bitstream_size = 0;
650 .p.name =
"interplayacm",
static double val(void *priv, double ch)
static av_cold void decode_flush(AVCodecContext *avctx)
const FFCodec ff_interplay_acm_decoder
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
bitstream reader API header.
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
@ AV_CODEC_ID_INTERPLAY_ACM
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_SAMPLE_FMT_S16
signed 16 bits
static const int8_t map_1bit[]
static int k44(InterplayACMContext *s, unsigned ind, unsigned col)
static int fill_block(InterplayACMContext *s)
#define set_pos(s, r, c, idx)
static av_cold void decode_init_static(void)
static int mul_3x3[3 *3 *3]
static int t27(InterplayACMContext *s, unsigned ind, unsigned col)
static void juggle_block(InterplayACMContext *s)
static int t37(InterplayACMContext *s, unsigned ind, unsigned col)
static int mul_3x5[5 *5 *5]
static av_cold int decode_close(AVCodecContext *avctx)
static int t15(InterplayACMContext *s, unsigned ind, unsigned col)
static int k13(InterplayACMContext *s, unsigned ind, unsigned col)
static const filler filler_list[]
static int linear(InterplayACMContext *s, unsigned ind, unsigned col)
static av_cold int decode_init(AVCodecContext *avctx)
static int k24(InterplayACMContext *s, unsigned ind, unsigned col)
static int k12(InterplayACMContext *s, unsigned ind, unsigned col)
static int k23(InterplayACMContext *s, unsigned ind, unsigned col)
static int k45(InterplayACMContext *s, unsigned ind, unsigned col)
static int zero(InterplayACMContext *s, unsigned ind, unsigned col)
static int k35(InterplayACMContext *s, unsigned ind, unsigned col)
static const int8_t map_2bit_near[]
static int bad(InterplayACMContext *s, unsigned ind, unsigned col)
static void juggle(int *wrap_p, int *block_p, unsigned sub_len, unsigned sub_count)
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *pkt)
int(* filler)(InterplayACMContext *s, unsigned ind, unsigned col)
static const int8_t map_2bit_far[]
static void decode_flush(AVCodecContext *avctx)
static const int8_t map_3bit[]
static int k34(InterplayACMContext *s, unsigned ind, unsigned col)
static int decode_block(InterplayACMContext *s)
static int mul_2x11[11 *11]
static av_cold int decode_init(AVCodecContext *avctx)
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
static av_cold int decode_close(AVCodecContext *avctx)
static int ff_thread_once(char *control, void(*routine)(void))
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
int nb_channels
Number of channels in this layout.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.