Go to the documentation of this file.
25 #define BITSTREAM_READER_LE
162 }
else if (
mode == 0) {
179 const int *quant_matrix,
int *
skip,
int *dc_level)
181 const uint8_t *scantable =
s->permutated_scantable;
184 memset(
s->wblocks, 0,
s->wblocks_size);
186 for (
int i = 0;
i < 64;
i++) {
187 int16_t *
block =
s->wblocks + scantable[
i];
189 for (
int j = 0; j <
s->blocks_w;) {
196 for (
int k = 0; k < rskip; k++)
197 block[64 * k] = *dc_level * quant_matrix[0];
209 block[0] = (
i == 0 ? *dc_level :
level) * quant_matrix[
i];
220 const int *quant_matrix,
int *
skip,
223 const uint8_t *scantable =
s->permutated_scantable;
226 memset(
s->wblocks, 0,
s->wblocks_size);
227 memset(
s->map, 0,
s->map_size);
229 for (
int i = 0;
i < 64;
i++) {
230 int16_t *
block =
s->wblocks + scantable[
i];
232 for (
int j = 0; j <
s->blocks_w;) {
256 const int *quant_matrix,
int *
skip,
int *dc_level)
258 const uint8_t *scantable =
s->permutated_scantable;
259 const int offset =
s->plus ? 0 : 1024;
260 int16_t *
block =
s->block;
263 memset(
block, 0,
sizeof(
s->block));
273 block[scantable[0]] =
offset + *dc_level * quant_matrix[0];
275 for (
int i = 1;
i < 64;) {
299 int ret,
skip = 0, dc_level = 0;
300 const int offset =
s->plus ? 0 : 1024;
307 64 *
s->blocks_w *
sizeof(*
s->wblocks));
311 for (
int y = 0; y <
s->blocks_h; y++) {
316 for (
int x = 0; x <
s->blocks_w; x++) {
323 for (
int y = 0; y <
s->blocks_h; y++) {
324 for (
int x = 0; x <
s->blocks_w; x++) {
345 const int *quant_matrix,
int *
skip,
348 const uint8_t *scantable =
s->permutated_scantable;
349 int16_t *
block =
s->block;
352 memset(
block, 0,
sizeof(
s->block));
354 for (
int i = 0;
i < 64;) {
385 64 *
s->blocks_w *
sizeof(*
s->wblocks));
390 s->blocks_w *
sizeof(*
s->map));
394 for (
int y = 0; y <
s->blocks_h; y++) {
399 for (
int x = 0; x <
s->blocks_w; x++) {
400 int shift = plane == 0;
402 int orig_mv_x =
s->mvectors[mvpos].x;
403 int mv_x =
s->mvectors[mvpos].x / (1 + !
shift);
404 int mv_y =
s->mvectors[mvpos].y / (1 + !
shift);
405 int h =
s->avctx->coded_height >> !
shift;
406 int w =
s->avctx->coded_width >> !
shift;
409 if (orig_mv_x >= -32) {
410 if (y * 8 + mv_y < 0 || y * 8 + mv_y + 8 >
h ||
411 x * 8 + mv_x < 0 || x * 8 + mv_x + 8 >
w)
415 prev->
data[plane] + ((
s->blocks_h - 1 - y) * 8 - mv_y) * prev->
linesize[plane] + (x * 8 + mv_x),
418 s->idsp.idct(
s->wblocks + x * 64);
419 for (
int i = 0;
i < 64;
i++)
420 s->wblocks[
i + x * 64] = (
s->wblocks[
i + x * 64] + 1) & 0xFFFC;
421 s->idsp.add_pixels_clamped(&
s->wblocks[x*64],
frame->
data[plane] + (
s->blocks_h - 1 - y) * 8 *
frame->
linesize[plane] + x * 8,
430 }
else if (
s->flags & 2) {
431 for (
int y = 0; y <
s->blocks_h; y++) {
432 for (
int x = 0; x <
s->blocks_w; x++) {
433 int shift = plane == 0;
435 int orig_mv_x =
s->mvectors[mvpos].x;
436 int mv_x =
s->mvectors[mvpos].x / (1 + !
shift);
437 int mv_y =
s->mvectors[mvpos].y / (1 + !
shift);
438 int h =
s->avctx->coded_height >> !
shift;
439 int w =
s->avctx->coded_width >> !
shift;
446 if (orig_mv_x >= -32) {
447 if (y * 8 + mv_y < 0 || y * 8 + mv_y + 8 >
h ||
448 x * 8 + mv_x < 0 || x * 8 + mv_x + 8 >
w)
452 prev->
data[plane] + ((
s->blocks_h - 1 - y) * 8 - mv_y) * prev->
linesize[plane] + (x * 8 + mv_x),
455 s->idsp.idct(
s->block);
456 for (
int i = 0;
i < 64;
i++)
457 s->block[
i] = (
s->block[
i] + 1) & 0xFFFC;
467 }
else if (
s->flags & 1) {
469 64 *
s->blocks_w *
sizeof(*
s->wblocks));
474 s->blocks_w *
sizeof(*
s->map));
478 for (
int y = 0; y <
s->blocks_h; y++) {
483 for (
int x = 0; x <
s->blocks_w; x++) {
491 for (
int y = 0; y <
s->blocks_h; y++) {
492 for (
int x = 0; x <
s->blocks_w; x++) {
519 double f = 1.0 -
fabs(qscale);
521 if (!
s->key_frame && (
s->flags & 2)) {
523 for (
int i = 0;
i < 64;
i++) {
528 for (
int i = 0;
i < 64;
i++) {
529 luma[
i] =
FFMAX(1, 16 - qscale * 32);
535 for (
int i = 0;
i < 64;
i++) {
540 for (
int i = 0;
i < 64;
i++) {
547 for (
int i = 0;
i < 64;
i++) {
550 s->luma_quant_matrix[
i] = luma[
pos] * ((
pos / 8) & 1 ? -1 : 1);
551 s->chroma_quant_matrix[
i] =
chroma[
pos] * ((
pos / 8) & 1 ? -1 : 1);
558 uint8_t
r = 0,
g = 0,
b = 0;
563 for (
int y = 0; y < avctx->
height; y++) {
564 for (
int x = 0; x < avctx->
width; x++) {
565 dst[x*3+0] = bytestream2_get_byteu(gbyte) +
r;
567 dst[x*3+1] = bytestream2_get_byteu(gbyte) +
g;
569 dst[x*3+2] = bytestream2_get_byteu(gbyte) +
b;
579 uint8_t **
u, uint8_t **v,
580 int ylinesize,
int ulinesize,
int vlinesize,
582 int *nx,
int *ny,
int *np,
int w,
int h)
584 uint8_t *y0dst = *y0;
585 uint8_t *y1dst = *y1;
588 int x = *nx, y = *ny,
pos = *np;
591 y0dst[2*x+0] += fill[0];
592 y0dst[2*x+1] += fill[1];
593 y1dst[2*x+0] += fill[2];
594 y1dst[2*x+1] += fill[3];
596 }
else if (
pos == 1) {
605 y0dst -= 2*ylinesize;
606 y1dst -= 2*ylinesize;
610 y0dst[2*x+0] += fill[2];
611 y0dst[2*x+1] += fill[3];
613 }
else if (
pos == 2) {
614 y1dst[2*x+0] += fill[0];
615 y1dst[2*x+1] += fill[1];
624 y0dst -= 2*ylinesize;
625 y1dst -= 2*ylinesize;
646 int runlen, y = 0, x = 0;
651 code = bytestream2_peek_le32(gbyte);
652 runlen =
code & 0xFFFFFF;
654 if (
code >> 24 == 0x77) {
657 for (
int i = 0;
i < 4;
i++)
658 fill[
i] = bytestream2_get_byte(gbyte);
663 for (
int i = 0;
i < 4;
i++) {
676 for (
int i = 0;
i < 4;
i++)
677 fill[
i] = bytestream2_get_byte(gbyte);
679 for (
int i = 0;
i < 4;
i++) {
702 int runlen, y = 0, x = 0,
pos = 0;
707 code = bytestream2_peek_le32(gbyte);
708 runlen =
code & 0xFFFFFF;
710 if (
code >> 24 == 0x77) {
713 for (
int i = 0;
i < 4;
i++)
714 fill[
i] = bytestream2_get_byte(gbyte);
729 for (
int i = 0;
i < 4;
i++)
730 fill[
i] = bytestream2_get_byte(gbyte);
752 uint8_t ly0 = 0, ly1 = 0, ly2 = 0, ly3 = 0, lu = 0, lv = 0;
754 for (
int y = 0; y < avctx->
height / 2; y++) {
755 for (
int x = 0; x < avctx->
width / 2; x++) {
756 y0dst[x*2+0] = bytestream2_get_byte(gbyte) + ly0;
758 y0dst[x*2+1] = bytestream2_get_byte(gbyte) + ly1;
760 y1dst[x*2+0] = bytestream2_get_byte(gbyte) + ly2;
762 y1dst[x*2+1] = bytestream2_get_byte(gbyte) + ly3;
764 udst[x] = bytestream2_get_byte(gbyte) + lu;
766 vdst[x] = bytestream2_get_byte(gbyte) + lv;
821 nb_mvs *
sizeof(*
s->mvectors));
826 (
s->size[0] +
s->size[1] +
s->size[2]))) < 0)
829 memset(
s->mvectors, 0,
sizeof(*
s->mvectors) * nb_mvs);
831 for (
int i = 0;
i < nb_mvs;
i++) {
839 for (
int i = 0;
i < nb_mvs;
i++) {
904 if (idx < 256 && idx >= 0) {
906 }
else if (idx >= 0) {
907 get_tree_codes(codes, nodes, nodes[idx].child[0], pfx + (0 << bitpos), bitpos + 1);
908 get_tree_codes(codes, nodes, nodes[idx].child[1], pfx + (1
U << bitpos), bitpos + 1);
914 int zlcount = 0, curlen, idx, nindex, last, llast;
915 int blcounts[32] = { 0 };
921 for (
int i = 0;
i < 256;
i++) {
922 int bitlen = bitlens[
i];
923 int blcount = blcounts[bitlen];
925 zlcount += bitlen < 1;
926 syms[(bitlen << 8) + blcount] =
i;
930 for (
int i = 0;
i < 512;
i++) {
935 for (
int i = 0;
i < 256;
i++) {
936 node_idx[
i] = 257 +
i;
944 for (curlen = 1; curlen < 32; curlen++) {
945 if (blcounts[curlen] > 0) {
946 int max_zlcount = zlcount + blcounts[curlen];
948 for (
int i = 0; zlcount < 256 && zlcount < max_zlcount; zlcount++,
i++) {
949 int p = node_idx[nindex - 1 + 512];
950 int ch = syms[256 * curlen +
i];
955 if (nodes[p].child[0] == -1) {
956 nodes[p].
child[0] = ch;
958 nodes[p].
child[1] = ch;
970 p = node_idx[nindex - 1 + 512];
972 if (nodes[p].child[0] == -1) {
973 nodes[p].
child[0] = ch;
975 nodes[p].
child[1] = ch;
984 for (
int i = 0;
i < idx;
i++)
985 node_idx[512 +
i] = old_idx[
i];
999 uint32_t new_codes[256];
1001 uint8_t symbols[256];
1002 uint32_t codes[256];
1009 for (
int i = 0;
i < 256;
i++) {
1011 bits[nb_codes] = bitlen[
i];
1012 codes[nb_codes] = new_codes[
i];
1013 symbols[nb_codes] =
i;
1039 if (
s->output_size > avctx->
width * avctx->
height * 9LL + 10000)
1052 for (
int i = 0;
i < count;
i++)
1055 for (
int i = 0;
i < 256;
i++) {
1060 for (
int i = 0;
i < 256;
i++)
1072 s->output[x++] =
val;
1085 unsigned compressed_size;
1094 header = bytestream2_get_le32(gbyte);
1095 s->fflags = bytestream2_get_le32(gbyte);
1096 s->bitstream_size =
s->fflags & 0x1FFFFFFF;
1099 if (avpkt->
size <
s->bitstream_size + 8)
1109 if (!
s->key_frame) {
1110 if (!
s->prev_frame->data[0]) {
1125 }
else if (!
s->dct) {
1131 w = bytestream2_get_le32(gbyte);
1132 h = bytestream2_get_le32(gbyte);
1133 if (
w == INT32_MIN ||
h == INT32_MIN)
1155 s->compression = bytestream2_get_le32(gbyte);
1156 if (
s->compression < 0 ||
s->compression > 100)
1159 for (
int i = 0;
i < 3;
i++)
1160 s->size[
i] = bytestream2_get_le32(gbyte);
1162 compressed_size =
s->output_size;
1165 compressed_size = avpkt->
size;
1168 if (
s->size[0] < 0 ||
s->size[1] < 0 ||
s->size[2] < 0 ||
1169 skip +
s->size[0] +
s->size[1] +
s->size[2] > compressed_size) {
1178 if (!
s->dct && !
s->rgb)
1180 else if (!
s->dct &&
s->rgb)
1189 if (!(
s->flags & 2)) {
1197 }
else if (!
s->dct && !
s->rgb) {
1230 if (!
s->rgb && !
s->dct) {
1238 s->idsp.idct_permutation);
1261 s->mvectors_size = 0;
1263 s->wblocks_size = 0;
1265 s->padded_output_size = 0;
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)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static int get_bits_left(GetBitContext *gb)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static double cb(void *priv, double x, double y)
#define u(width, name, range_min, range_max)
static av_cold int decode_init(AVCodecContext *avctx)
static int decode_inter(AVCodecContext *avctx, GetBitContext *gb, AVFrame *frame, AVFrame *prev)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_bits_count(const GetBitContext *s)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
unsigned padded_output_size
int chroma_quant_matrix[64]
static void copy_block8(uint8_t *dst, const uint8_t *src, ptrdiff_t dstStride, ptrdiff_t srcStride, int h)
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
int luma_quant_matrix[64]
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
static int decode_intra_blocks(AGMContext *s, GetBitContext *gb, const int *quant_matrix, int *skip, int *dc_level)
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.
static int decode_inter_block(AGMContext *s, GetBitContext *gb, const int *quant_matrix, int *skip, int *map)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static void decode_flush(AVCodecContext *avctx)
static void skip_bits(GetBitContext *s, int n)
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
AVCodec p
The public AVCodec.
static int decode_huffman2(AVCodecContext *avctx, int header, int size)
static double val(void *priv, double ch)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static int read_code(GetBitContext *gb, int *oskip, int *level, int *map, int mode)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
#define FF_CODEC_DECODE_CB(func)
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static av_cold int decode_close(AVCodecContext *avctx)
#define CODEC_LONG_NAME(str)
static int decode_inter_plane(AGMContext *s, GetBitContext *gb, int size, const int *quant_matrix, AVFrame *frame, AVFrame *prev, int plane)
const FFCodec ff_agm_decoder
Describe the class of an AVClass context structure.
static __device__ float fabs(float a)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static int decode_runlen_rgb(AVCodecContext *avctx, GetByteContext *gbyte, AVFrame *frame)
@ AV_PICTURE_TYPE_I
Intra.
static int decode_motion_vectors(AVCodecContext *avctx, GetBitContext *gb)
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
enum AVPictureType pict_type
Picture type of the frame.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
static int decode_intra_block(AGMContext *s, GetBitContext *gb, const int *quant_matrix, int *skip, int *dc_level)
#define DECLARE_ALIGNED(n, t, v)
static int shift(int a, int b)
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
#define FF_CODEC_CAP_EXPORTS_CROPPING
The decoder sets the cropping fields in the output frames manually.
static int decode_runlen(AVCodecContext *avctx, GetByteContext *gbyte, AVFrame *frame)
static const uint8_t header[24]
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
int flags
A combination of AV_PKT_FLAG values.
int ff_vlc_init_sparse(VLC *vlc, 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)
Build VLC decoding tables suitable for use with get_vlc2().
#define i(width, name, range_min, range_max)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
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...
const uint8_t ff_mjpeg_std_chrominance_quant_tbl[64]
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
const char * name
Name of the codec implementation.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
const uint8_t ff_zigzag_direct[64]
void ff_vlc_free(VLC *vlc)
static int decode_intra_plane(AGMContext *s, GetBitContext *gb, int size, const int *quant_matrix, AVFrame *frame, int plane)
static const uint8_t * align_get_bits(GetBitContext *s)
const uint8_t ff_mjpeg_std_luminance_quant_tbl[64]
int av_frame_replace(AVFrame *dst, const AVFrame *src)
Ensure the destination frame refers to the same data described by the source frame,...
main external API structure.
static int decode_inter_blocks(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 build_huff(const uint8_t *bitlen, VLC *vlc)
int coded_width
Bitstream width / height, may be different from width/height e.g.
@ AV_PICTURE_TYPE_P
Predicted.
const VDPAUPixFmtMap * map
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
This structure stores compressed data.
int width
picture width / height.
uint8_t permutated_scantable[64]
static int decode_raw_intra(AVCodecContext *avctx, GetByteContext *gbyte, AVFrame *frame)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
The exact code depends on how similar the blocks are and how related they are to the block
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define MKTAG(a, b, c, d)
static int make_new_tree(const uint8_t *bitlens, uint32_t *codes)
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
static void get_tree_codes(uint32_t *codes, Node *nodes, int idx, uint32_t pfx, int bitpos)
static int decode_intra(AVCodecContext *avctx, GetBitContext *gb, AVFrame *frame)
static void compute_quant_matrix(AGMContext *s, double qscale)