23 #define BITSTREAM_READER_LE
31 static const int8_t
map_3bit[] = { -4, -3, -2, -1, +1, +2, +3, +4 };
72 if (
s->max_samples == 0)
73 s->max_samples = UINT64_MAX;
76 s->cols = 1 <<
s->level;
77 s->wrapbuf_len = 2 *
s->cols - 2;
78 s->block_len =
s->rows *
s->cols;
79 if (
s->block_len > 1024 * 1024) {
83 s->max_framesize =
s->block_len;
86 s->wrapbuf =
av_calloc(
s->wrapbuf_len,
sizeof(
int));
89 if (!
s->block || !
s->wrapbuf || !
s->ampbuf || !
s->bitstream)
92 s->midbuf =
s->ampbuf + 0x8000;
95 for (x3 = 0; x3 < 3; x3++)
96 for (x2 = 0; x2 < 3; x2++)
97 for (x1 = 0; x1 < 3; x1++)
98 mul_3x3[x1 + x2 * 3 + x3* 3 * 3] = x1 + (x2 << 4) + (x3 << 8);
99 for (x3 = 0; x3 < 5; x3++)
100 for (x2 = 0; x2 < 5; x2++)
101 for (x1 = 0; x1 < 5; x1++)
102 mul_3x5[x1 + x2 * 5 + x3 * 5 * 5] = x1 + (x2 << 4) + (x3 << 8);
103 for (x2 = 0; x2 < 11; x2++)
104 for (x1 = 0; x1 < 11; x1++)
105 mul_2x11[x1 + x2 * 11] = x1 + (x2 << 4);
110 #define set_pos(s, r, c, idx) do { \
111 unsigned pos = ((r) << s->level) + (c); \
112 s->block[pos] = s->midbuf[(idx)]; \
119 for (
i = 0;
i <
s->rows;
i++)
133 int b, middle = 1 << (ind - 1);
135 for (
i = 0;
i <
s->rows;
i++) {
147 for (
i = 0;
i <
s->rows;
i++) {
172 for (
i = 0;
i <
s->rows;
i++) {
190 for (
i = 0;
i <
s->rows;
i++) {
194 if (
i >=
s->rows)
break;
216 for (
i = 0;
i <
s->rows;
i++) {
234 for (
i = 0;
i <
s->rows;
i++) {
268 for (
i = 0;
i <
s->rows;
i++) {
293 for (
i = 0;
i <
s->rows;
i++) {
320 for (
i = 0;
i <
s->rows;
i++) {
339 for (
i = 0;
i <
s->rows;
i++) {
348 n2 = ((
mul_3x3[
b] >> 4) & 0x0F) - 1;
349 n3 = ((
mul_3x3[
b] >> 8) & 0x0F) - 1;
368 for (
i = 0;
i <
s->rows;
i++) {
377 n2 = ((
mul_3x5[
b] >> 4) & 0x0F) - 2;
378 n3 = ((
mul_3x5[
b] >> 8) & 0x0F) - 2;
396 for (
i = 0;
i <
s->rows;
i++) {
437 for (
i = 0;
i <
s->cols;
i++) {
446 static void juggle(
int *wrap_p,
int *block_p,
unsigned sub_len,
unsigned sub_count)
450 unsigned int r0, r1, r2, r3;
452 for (
i = 0;
i < sub_len;
i++) {
456 for (j = 0; j < sub_count/2; j++) {
458 *p = r1 * 2 + (r0 + r2);
461 *p = r2 * 2 - (r1 + r3);
475 unsigned sub_count, sub_len, todo_count, step_subcount,
i;
476 int *wrap_p, *block_p, *p;
486 step_subcount = (2048 >>
s->level) - 2;
492 todo_count =
s->rows;
496 sub_count = step_subcount;
497 if (sub_count > todo_count)
498 sub_count = todo_count;
500 sub_len =
s->cols / 2;
503 juggle(wrap_p, block_p, sub_len, sub_count);
504 wrap_p += sub_len * 2;
506 for (
i = 0, p = block_p;
i < sub_count;
i++) {
511 while (sub_len > 1) {
514 juggle(wrap_p, block_p, sub_len, sub_count);
515 wrap_p += sub_len * 2;
518 if (todo_count <= step_subcount)
521 todo_count -= step_subcount;
522 block_p += step_subcount <<
s->level;
529 int pwr, count,
val,
i, x, ret;
536 for (
i = 0, x = 0;
i < count;
i++) {
541 for (
i = 1, x = -
val;
i <= count;
i++) {
563 int ret, n, buf_size, input_buf_size;
565 if (!
pkt->
size && !
s->bitstream_size) {
570 buf_size =
FFMIN(
pkt->
size,
s->max_framesize -
s->bitstream_size);
571 input_buf_size = buf_size;
572 if (
s->bitstream_index +
s->bitstream_size + buf_size >
s->max_framesize) {
573 memmove(
s->bitstream, &
s->bitstream[
s->bitstream_index],
s->bitstream_size);
574 s->bitstream_index = 0;
577 memcpy(&
s->bitstream[
s->bitstream_index +
s->bitstream_size],
pkt->
data, buf_size);
578 buf = &
s->bitstream[
s->bitstream_index];
579 buf_size +=
s->bitstream_size;
580 s->bitstream_size = buf_size;
581 if (buf_size < s->max_framesize &&
pkt->
data) {
583 return input_buf_size;
601 int val =
s->block[n] >>
s->level;
609 if (n > buf_size &&
pkt->
data) {
610 s->bitstream_size = 0;
611 s->bitstream_index = 0;
615 if (
s->bitstream_size > 0) {
616 s->bitstream_index += n;
617 s->bitstream_size -=
FFMIN(
s->bitstream_size, n);
618 return input_buf_size;
627 s->bitstream_size = 0;
628 s->bitstream_index = 0;
639 s->bitstream_size = 0;
645 .
name =
"interplayacm",
static double val(void *priv, double ch)
Libavcodec external API header.
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.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
@ 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 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)
AVCodec ff_interplay_acm_decoder
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, void *data, 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]
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int channels
number of audio channels
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.