27 #define BITSTREAM_READER_LE
39 16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19,
40 26, 58, 60, 55, 14, 13, 16, 24, 40, 57, 69, 56,
41 14, 17, 22, 29, 51, 87, 80, 62, 18, 22, 37, 56,
42 68,109,103, 77, 24, 35, 55, 64, 81,104,113, 92,
43 49, 64, 78, 87,103,121,120,101, 72, 92, 95, 98,
48 17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66,
49 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99,
50 47, 66, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
51 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
52 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
106 int len = 0, skip = 0,
max;
180 }
else if (
mode == 0) {
197 const int *quant_matrix,
int *skip,
int *dc_level)
199 const uint8_t *scantable =
s->scantable.permutated;
202 memset(
s->wblocks, 0,
s->wblocks_size);
204 for (
int i = 0;
i < 64;
i++) {
205 int16_t *
block =
s->wblocks + scantable[
i];
207 for (
int j = 0; j <
s->blocks_w;) {
211 rskip =
FFMIN(*skip,
s->blocks_w - j);
214 for (
int k = 0; k < rskip; k++)
215 block[64 * k] = *dc_level * quant_matrix[0];
227 block[0] = (
i == 0 ? *dc_level :
level) * quant_matrix[
i];
238 const int *quant_matrix,
int *skip,
241 const uint8_t *scantable =
s->scantable.permutated;
244 memset(
s->wblocks, 0,
s->wblocks_size);
245 memset(
s->map, 0,
s->map_size);
247 for (
int i = 0;
i < 64;
i++) {
248 int16_t *
block =
s->wblocks + scantable[
i];
250 for (
int j = 0; j <
s->blocks_w;) {
254 rskip =
FFMIN(*skip,
s->blocks_w - j);
274 const int *quant_matrix,
int *skip,
int *dc_level)
276 const uint8_t *scantable =
s->scantable.permutated;
277 const int offset =
s->plus ? 0 : 1024;
278 int16_t *
block =
s->block;
281 memset(
block, 0,
sizeof(
s->block));
291 block[scantable[0]] =
offset + *dc_level * quant_matrix[0];
293 for (
int i = 1;
i < 64;) {
297 rskip =
FFMIN(*skip, 64 -
i);
317 int ret, skip = 0, dc_level = 0;
318 const int offset =
s->plus ? 0 : 1024;
325 64 *
s->blocks_w *
sizeof(*
s->wblocks));
329 for (
int y = 0; y <
s->blocks_h; y++) {
334 for (
int x = 0; x <
s->blocks_w; x++) {
341 for (
int y = 0; y <
s->blocks_h; y++) {
342 for (
int x = 0; x <
s->blocks_w; x++) {
363 const int *quant_matrix,
int *skip,
366 const uint8_t *scantable =
s->scantable.permutated;
367 int16_t *
block =
s->block;
370 memset(
block, 0,
sizeof(
s->block));
372 for (
int i = 0;
i < 64;) {
376 rskip =
FFMIN(*skip, 64 -
i);
403 64 *
s->blocks_w *
sizeof(*
s->wblocks));
408 s->blocks_w *
sizeof(*
s->map));
412 for (
int y = 0; y <
s->blocks_h; y++) {
417 for (
int x = 0; x <
s->blocks_w; x++) {
418 int shift = plane == 0;
420 int orig_mv_x =
s->mvectors[mvpos].x;
421 int mv_x =
s->mvectors[mvpos].x / (1 + !
shift);
422 int mv_y =
s->mvectors[mvpos].y / (1 + !
shift);
423 int h =
s->avctx->coded_height >> !
shift;
424 int w =
s->avctx->coded_width >> !
shift;
427 if (orig_mv_x >= -32) {
428 int src_y = (
s->blocks_h - 1 - y) * 8 - mv_y;
429 int src_x = x * 8 + mv_x;
430 if (src_y < 0 || src_y + 8 >
h ||
431 src_x < 0 || src_x + 8 >
w)
435 prev->
data[plane] + src_y * prev->
linesize[plane] + src_x,
438 s->idsp.idct(
s->wblocks + x * 64);
439 for (
int i = 0;
i < 64;
i++)
440 s->wblocks[
i + x * 64] = (
s->wblocks[
i + x * 64] + 1) & 0xFFFC;
441 s->idsp.add_pixels_clamped(&
s->wblocks[x*64],
frame->
data[plane] + (
s->blocks_h - 1 - y) * 8 *
frame->
linesize[plane] + x * 8,
450 }
else if (
s->flags & 2) {
451 for (
int y = 0; y <
s->blocks_h; y++) {
452 for (
int x = 0; x <
s->blocks_w; x++) {
453 int shift = plane == 0;
455 int orig_mv_x =
s->mvectors[mvpos].x;
456 int mv_x =
s->mvectors[mvpos].x / (1 + !
shift);
457 int mv_y =
s->mvectors[mvpos].y / (1 + !
shift);
458 int h =
s->avctx->coded_height >> !
shift;
459 int w =
s->avctx->coded_width >> !
shift;
466 if (orig_mv_x >= -32) {
467 int src_y = (
s->blocks_h - 1 - y) * 8 - mv_y;
468 int src_x = x * 8 + mv_x;
469 if (src_y < 0 || src_y + 8 >
h ||
470 src_x < 0 || src_x + 8 >
w)
474 prev->
data[plane] + src_y * prev->
linesize[plane] + src_x,
477 s->idsp.idct(
s->block);
478 for (
int i = 0;
i < 64;
i++)
479 s->block[
i] = (
s->block[
i] + 1) & 0xFFFC;
489 }
else if (
s->flags & 1) {
491 64 *
s->blocks_w *
sizeof(*
s->wblocks));
496 s->blocks_w *
sizeof(*
s->map));
500 for (
int y = 0; y <
s->blocks_h; y++) {
505 for (
int x = 0; x <
s->blocks_w; x++) {
513 for (
int y = 0; y <
s->blocks_h; y++) {
514 for (
int x = 0; x <
s->blocks_w; x++) {
541 double f = 1.0 -
fabs(qscale);
543 if (!
s->key_frame && (
s->flags & 2)) {
545 for (
int i = 0;
i < 64;
i++) {
550 for (
int i = 0;
i < 64;
i++) {
551 luma[
i] =
FFMAX(1, 16 - qscale * 32);
557 for (
int i = 0;
i < 64;
i++) {
562 for (
int i = 0;
i < 64;
i++) {
569 for (
int i = 0;
i < 64;
i++) {
572 s->luma_quant_matrix[
i] = luma[
pos] * ((
pos / 8) & 1 ? -1 : 1);
573 s->chroma_quant_matrix[
i] =
chroma[
pos] * ((
pos / 8) & 1 ? -1 : 1);
585 for (
int y = 0; y < avctx->
height; y++) {
586 for (
int x = 0; x < avctx->
width; x++) {
587 dst[x*3+0] = bytestream2_get_byteu(gbyte) +
r;
589 dst[x*3+1] = bytestream2_get_byteu(gbyte) +
g;
591 dst[x*3+2] = bytestream2_get_byteu(gbyte) +
b;
602 int ylinesize,
int ulinesize,
int vlinesize,
604 int *nx,
int *ny,
int *np,
int w,
int h)
610 int x = *nx, y = *ny,
pos = *np;
613 y0dst[2*x+0] += fill[0];
614 y0dst[2*x+1] += fill[1];
615 y1dst[2*x+0] += fill[2];
616 y1dst[2*x+1] += fill[3];
618 }
else if (
pos == 1) {
627 y0dst -= 2*ylinesize;
628 y1dst -= 2*ylinesize;
632 y0dst[2*x+0] += fill[2];
633 y0dst[2*x+1] += fill[3];
635 }
else if (
pos == 2) {
636 y1dst[2*x+0] += fill[0];
637 y1dst[2*x+1] += fill[1];
646 y0dst -= 2*ylinesize;
647 y1dst -= 2*ylinesize;
668 int runlen, y = 0, x = 0;
673 code = bytestream2_peek_le32(gbyte);
674 runlen =
code & 0xFFFFFF;
676 if (
code >> 24 == 0x77) {
679 for (
int i = 0;
i < 4;
i++)
680 fill[
i] = bytestream2_get_byte(gbyte);
685 for (
int i = 0;
i < 4;
i++) {
698 for (
int i = 0;
i < 4;
i++)
699 fill[
i] = bytestream2_get_byte(gbyte);
701 for (
int i = 0;
i < 4;
i++) {
724 int runlen, y = 0, x = 0,
pos = 0;
729 code = bytestream2_peek_le32(gbyte);
730 runlen =
code & 0xFFFFFF;
732 if (
code >> 24 == 0x77) {
735 for (
int i = 0;
i < 4;
i++)
736 fill[
i] = bytestream2_get_byte(gbyte);
751 for (
int i = 0;
i < 4;
i++)
752 fill[
i] = bytestream2_get_byte(gbyte);
774 uint8_t ly0 = 0, ly1 = 0, ly2 = 0, ly3 = 0, lu = 0, lv = 0;
776 for (
int y = 0; y < avctx->
height / 2; y++) {
777 for (
int x = 0; x < avctx->
width / 2; x++) {
778 y0dst[x*2+0] = bytestream2_get_byte(gbyte) + ly0;
780 y0dst[x*2+1] = bytestream2_get_byte(gbyte) + ly1;
782 y1dst[x*2+0] = bytestream2_get_byte(gbyte) + ly2;
784 y1dst[x*2+1] = bytestream2_get_byte(gbyte) + ly3;
786 udst[x] = bytestream2_get_byte(gbyte) + lu;
788 vdst[x] = bytestream2_get_byte(gbyte) + lv;
843 nb_mvs *
sizeof(*
s->mvectors));
848 (
s->size[0] +
s->size[1] +
s->size[2]))) < 0)
851 memset(
s->mvectors, 0,
sizeof(*
s->mvectors) * nb_mvs);
853 for (
int i = 0;
i < nb_mvs;
i++) {
861 for (
int i = 0;
i < nb_mvs;
i++) {
926 if (idx < 256 && idx >= 0) {
928 }
else if (idx >= 0) {
929 get_tree_codes(codes, nodes, nodes[idx].child[0], pfx + (0 << bitpos), bitpos + 1);
930 get_tree_codes(codes, nodes, nodes[idx].child[1], pfx + (1U << bitpos), bitpos + 1);
936 int zlcount = 0, curlen, idx, nindex, last, llast;
937 int blcounts[32] = { 0 };
943 for (
int i = 0;
i < 256;
i++) {
944 int bitlen = bitlens[
i];
945 int blcount = blcounts[bitlen];
947 zlcount += bitlen < 1;
948 syms[(bitlen << 8) + blcount] =
i;
952 for (
int i = 0;
i < 512;
i++) {
957 for (
int i = 0;
i < 256;
i++) {
958 node_idx[
i] = 257 +
i;
966 for (curlen = 1; curlen < 32; curlen++) {
967 if (blcounts[curlen] > 0) {
968 int max_zlcount = zlcount + blcounts[curlen];
970 for (
int i = 0; zlcount < 256 && zlcount < max_zlcount; zlcount++,
i++) {
971 int p = node_idx[nindex - 1 + 512];
972 int ch = syms[256 * curlen +
i];
977 if (nodes[p].child[0] == -1) {
978 nodes[p].
child[0] = ch;
980 nodes[p].
child[1] = ch;
992 p = node_idx[nindex - 1 + 512];
994 if (nodes[p].child[0] == -1) {
995 nodes[p].
child[0] = ch;
997 nodes[p].
child[1] = ch;
1006 for (
int i = 0;
i < idx;
i++)
1007 node_idx[512 +
i] = old_idx[
i];
1021 uint32_t new_codes[256];
1024 uint32_t codes[256];
1031 for (
int i = 0;
i < 256;
i++) {
1033 bits[nb_codes] = bitlen[
i];
1034 codes[nb_codes] = new_codes[
i];
1035 symbols[nb_codes] =
i;
1061 if (
s->output_size > avctx->
width * avctx->
height * 9LL + 10000)
1074 for (
int i = 0;
i < count;
i++)
1077 for (
int i = 0;
i < 256;
i++) {
1082 for (
int i = 0;
i < 256;
i++)
1094 s->output[x++] =
val;
1108 unsigned compressed_size;
1117 header = bytestream2_get_le32(gbyte);
1118 s->fflags = bytestream2_get_le32(gbyte);
1119 s->bitstream_size =
s->fflags & 0x1FFFFFFF;
1122 if (avpkt->
size <
s->bitstream_size + 8)
1129 if (!
s->key_frame) {
1130 if (!
s->prev_frame->data[0]) {
1145 }
else if (!
s->dct) {
1151 w = bytestream2_get_le32(gbyte);
1152 h = bytestream2_get_le32(gbyte);
1153 if (
w == INT32_MIN ||
h == INT32_MIN)
1175 s->compression = bytestream2_get_le32(gbyte);
1176 if (
s->compression < 0 ||
s->compression > 100)
1179 for (
int i = 0;
i < 3;
i++)
1180 s->size[
i] = bytestream2_get_le32(gbyte);
1182 compressed_size =
s->output_size;
1185 compressed_size = avpkt->
size;
1188 if (
s->size[0] < 0 ||
s->size[1] < 0 ||
s->size[2] < 0 ||
1189 skip +
s->size[0] +
s->size[1] +
s->size[2] > compressed_size) {
1198 if (!
s->dct && !
s->rgb)
1200 else if (!
s->dct &&
s->rgb)
1209 if (!(
s->flags & 2)) {
1217 }
else if (!
s->dct && !
s->rgb) {
1251 if (!
s->rgb && !
s->dct) {
1281 s->mvectors_size = 0;
1283 s->wblocks_size = 0;
1285 s->padded_output_size = 0;
static void flush(AVCodecContext *avctx)
static double val(void *priv, double ch)
static int decode_motion_vectors(AVCodecContext *avctx, GetBitContext *gb)
static int decode_intra(AVCodecContext *avctx, GetBitContext *gb, AVFrame *frame)
static int decode_inter(AVCodecContext *avctx, GetBitContext *gb, AVFrame *frame, AVFrame *prev)
static int decode_intra_plane(AGMContext *s, GetBitContext *gb, int size, const int *quant_matrix, AVFrame *frame, int plane)
static const uint8_t unscaled_luma[64]
static const uint8_t unscaled_chroma[64]
static int decode_huffman2(AVCodecContext *avctx, int header, int size)
static av_cold int decode_close(AVCodecContext *avctx)
static void get_tree_codes(uint32_t *codes, Node *nodes, int idx, uint32_t pfx, int bitpos)
static int decode_runlen_rgb(AVCodecContext *avctx, GetByteContext *gbyte, AVFrame *frame)
static int make_new_tree(const uint8_t *bitlens, uint32_t *codes)
static av_cold int decode_init(AVCodecContext *avctx)
static int decode_intra_block(AGMContext *s, GetBitContext *gb, const int *quant_matrix, int *skip, int *dc_level)
static int decode_inter_block(AGMContext *s, GetBitContext *gb, const int *quant_matrix, int *skip, int *map)
static int decode_raw_intra_rgb(AVCodecContext *avctx, GetByteContext *gbyte, AVFrame *frame)
static int decode_inter_blocks(AGMContext *s, GetBitContext *gb, const int *quant_matrix, int *skip, int *map)
static int decode_intra_blocks(AGMContext *s, GetBitContext *gb, const int *quant_matrix, int *skip, int *dc_level)
static int decode_runlen(AVCodecContext *avctx, GetByteContext *gbyte, AVFrame *frame)
static int decode_raw_intra(AVCodecContext *avctx, GetByteContext *gbyte, AVFrame *frame)
static void decode_flush(AVCodecContext *avctx)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static av_always_inline int fill_pixels(uint8_t **y0, uint8_t **y1, uint8_t **u, uint8_t **v, int ylinesize, int ulinesize, int vlinesize, uint8_t *fill, int *nx, int *ny, int *np, int w, int h)
static int build_huff(const uint8_t *bitlen, VLC *vlc)
static int read_code(GetBitContext *gb, int *oskip, int *level, int *map, int mode)
static int decode_inter_plane(AGMContext *s, GetBitContext *gb, int size, const int *quant_matrix, AVFrame *frame, AVFrame *prev, int plane)
static void compute_quant_matrix(AGMContext *s, double qscale)
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
void ff_free_vlc(VLC *vlc)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define u(width, name, range_min, range_max)
#define MKTAG(a, b, c, d)
static void copy_block8(uint8_t *dst, const uint8_t *src, ptrdiff_t dstStride, ptrdiff_t srcStride, int h)
static __device__ float fabs(float a)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
mode
Use these values in ebur128_init (or'ed).
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static int get_bits_left(GetBitContext *gb)
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.
static const uint8_t * align_get_bits(GetBitContext *s)
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
const VDPAUPixFmtMap * map
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
#define FF_CODEC_CAP_EXPORTS_CROPPING
The decoder sets the cropping fields in the output frames manually.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#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_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
const uint8_t ff_zigzag_direct[64]
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
static const uint8_t header[24]
static int shift(int a, int b)
int chroma_quant_matrix[64]
unsigned padded_output_size
int luma_quant_matrix[64]
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
int coded_width
Bitstream width / height, may be different from width/height e.g.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
static double cb(void *priv, double x, double y)
static const uint8_t offset[127][2]