86 int idx = 1, last = 0,
val,
skip;
88 memset(
blk, 0,
sizeof(*
blk) * 64);
94 while (idx < 64 && !last) {
111 val = ac_quant * (2 * aval + 1);
123 return (idx <= 64 && last) ? 0 : -1;
126#define DCT_TEMPLATE(blk, step, bias, shift, dshift, OP) \
127 const int t0 = OP(2841 * blk[1 * step] + 565 * blk[7 * step]); \
128 const int t1 = OP( 565 * blk[1 * step] - 2841 * blk[7 * step]); \
129 const int t2 = OP(1609 * blk[5 * step] + 2408 * blk[3 * step]); \
130 const int t3 = OP(2408 * blk[5 * step] - 1609 * blk[3 * step]); \
131 const int t4 = OP(1108 * blk[2 * step] - 2676 * blk[6 * step]); \
132 const int t5 = OP(2676 * blk[2 * step] + 1108 * blk[6 * step]); \
133 const int t6 = ((blk[0 * step] + blk[4 * step]) * (1 << dshift)) + bias; \
134 const int t7 = ((blk[0 * step] - blk[4 * step]) * (1 << dshift)) + bias; \
135 const int t8 = t0 + t2; \
136 const int t9 = t0 - t2; \
137 const int tA = (int)(181U * (t9 + (t1 - t3)) + 0x80) >> 8; \
138 const int tB = (int)(181U * (t9 - (t1 - t3)) + 0x80) >> 8; \
139 const int tC = t1 + t3; \
141 blk[0 * step] = (t6 + t5 + t8) >> shift; \
142 blk[1 * step] = (t7 + t4 + tA) >> shift; \
143 blk[2 * step] = (t7 - t4 + tB) >> shift; \
144 blk[3 * step] = (t6 - t5 + tC) >> shift; \
145 blk[4 * step] = (t6 - t5 - tC) >> shift; \
146 blk[5 * step] = (t7 - t4 - tB) >> shift; \
147 blk[6 * step] = (t7 + t4 - tA) >> shift; \
148 blk[7 * step] = (t6 + t5 - t8) >> shift; \
151#define COP(x) (((x) + 4) >> 3)
159 for (
i = 0;
i < 8;
i++) {
165 for (
i = 0;
i < 8;
i++) {
173 int i, has_ac[6], off;
175 for (
i = 0;
i < 6;
i++)
178 off = x * 16 + y * 16 *
c->pic->linesize[0];
179 for (
i = 0;
i < 4;
i++) {
182 if (!x && !(
i & 1)) {
183 c->block[0] +=
c->top_dc[0];
184 c->top_dc[0] =
c->block[0];
186 c->block[0] +=
c->left_dc[(
i & 2) >> 1];
188 c->left_dc[(
i & 2) >> 1] =
c->block[0];
189 c->block[0] *=
c->luma_dc_quant;
192 off +=
c->pic->linesize[0] * 8;
193 c->idsp.put_pixels_clamped(
c->block,
194 c->pic->data[0] + off + (
i & 1) * 8,
195 c->pic->linesize[0]);
198 off = x * 8 + y * 8 *
c->pic->linesize[1];
199 for (
i = 1;
i < 3;
i++) {
203 c->block[0] +=
c->top_dc[
i];
204 c->top_dc[
i] =
c->block[0];
206 c->block[0] +=
c->left_dc[
i + 1];
208 c->left_dc[
i + 1] =
c->block[0];
209 c->block[0] *=
c->chroma_dc_quant;
211 c->idsp.put_pixels_clamped(
c->block,
c->pic->data[
i] + off,
212 c->pic->linesize[
i]);
219 int plane,
int x,
int y,
int dx,
int dy,
int size)
221 int shift = plane > 0;
224 int sstride, dstride, soff, doff;
229 if (x < 0 || sx < 0 || y < 0 || sy < 0 ||
236 sstride =
src->linesize[plane];
237 dstride =
dst->linesize[plane];
238 soff = sx + sy * sstride;
239 sbuf =
src->data[plane];
240 doff = x + y * dstride;
241 dbuf =
dst->data[plane];
244 uint8_t *dptr = &dbuf[doff];
245 const uint8_t *sptr = &sbuf[soff];
247 memcpy(dptr, sptr,
size);
256 int plane,
int x,
int y,
int dx,
int dy,
int size,
int bias)
258 int shift = plane > 0;
261 int sstride =
src->linesize[plane];
262 int dstride =
dst->linesize[plane];
263 int soff = sx + sy * sstride;
264 const uint8_t *sbuf =
src->data[plane];
265 int doff = x + y * dstride;
266 uint8_t *dbuf =
dst->data[plane];
269 if (x < 0 || sx < 0 || y < 0 || sy < 0 ||
276 for (j = 0; j <
size; j++) {
277 uint8_t *dptr = &dbuf[doff];
278 const uint8_t *sptr = &sbuf[soff];
296 int left_mv, right_mv, top_mv, bot_mv;
304 }
else if ((mb_x == 0) || (mb_x == mvi->
mb_w - 1)) {
308 MV B = mvi->
mv[ mb_x ];
309 MV C = mvi->
mv[ mb_x + 1];
316 left_mv = -((mb_x * mvi->
mb_size));
317 right_mv = ((mvi->
mb_w - mb_x - 1) * mvi->
mb_size);
318 if (res.
x < left_mv) {
321 if (res.
x > right_mv) {
324 top_mv = -((mb_y * mvi->
mb_size));
326 if (res.
y < top_mv) {
329 if (res.
y > bot_mv) {
366 int plane,
int x,
int y,
int dx,
int dy,
int size,
int bias)
382 int plane,
int x,
int y,
int size,
397 mv.x = (int8_t)(mv_code & 0xff);
398 mv.y = (int8_t)(mv_code >> 8);
413 bias = (int16_t)(bias_val);
420 int hsize =
size >> 1;
421 for (
i = 0;
i < 4;
i++) {
422 int xoff = (
i & 2) == 0 ? 0 : hsize;
423 int yoff = (
i & 1) == 0 ? 0 : hsize;
427 x + xoff, y + yoff, hsize, root_mv,
NULL);
452 int size =
comp == 0 ? tile_size : tile_size >> 1;
454 uint8_t *framebuf = buf->
data[
comp];
459 if ((right ==
size) && (bottom ==
size)) {
464 for (j = 0; j <
h; j++) {
465 for (
i = 0;
i < right;
i++) {
466 framebuf[off +
i] = 0x80;
471 if (bottom !=
size) {
473 for (j = 0; j < bottom; j++) {
475 framebuf[off +
i] = 0x80;
486 const uint8_t *buf = avpkt->
data;
487 int buf_size = avpkt->
size;
496 int skip = bytestream2_get_byte(&gb);
506 if (buf_size < c->mb_width *
c->mb_height) {
517 bytestream2_get_be32(&gb);
518 c->ac_quant = bytestream2_get_byte(&gb);
519 c->luma_dc_quant = 32;
520 c->chroma_dc_quant = 32;
526 for (
i = 0;
i < 3;
i++)
528 for (
i = 0;
i < 4;
i++)
531 for (j = 0; j <
c->mb_height; j++) {
532 for (
i = 0;
i <
c->mb_width;
i++) {
556 mvi_reset(&
c->mvi,
c->pmb_width,
c->pmb_height, 1 <<
c->tile_shift);
558 for (j = 0; j <
c->pmb_height; j++) {
559 for (
i = 0;
i <
c->pmb_width;
i++) {
567 for (plane = 0; plane < 3; plane++) {
568 int16_t x = plane == 0 ?
i <<
c->tile_shift :
i << (
c->tile_shift - 1);
569 int16_t y = plane == 0 ? j <<
c->tile_shift : j << (
c->tile_shift - 1);
570 int16_t
size = plane == 0 ? 1 <<
c->tile_shift : 1 << (
c->tile_shift - 1);
571 int16_t
mx = plane == 0 ?
mv.x :
mv.x / 2;
572 int16_t
my = plane == 0 ?
mv.y :
mv.y / 2;
579 int x =
i <<
c->tile_shift;
580 int y = j <<
c->tile_shift;
581 int size = 1 <<
c->tile_shift;
588 x =
i << (
c->tile_shift - 1);
589 y = j << (
c->tile_shift - 1);
590 size = 1 << (
c->tile_shift - 1);
622 return mb_ret < 0 ? mb_ret : buf_size;
626 const uint8_t counts[16],
627 const uint16_t **syms)
630 const uint16_t *symbols = *syms;
633 for (
int i = 0;
i < 16;
i++) {
634 unsigned count = counts[
i];
637 for (count += num; num < count; num++)
642 symbols, 2, 2, 0, 0);
657 for (
unsigned i = 0, j = 0, k = 0;;
i++) {
658 if (0x36F & (1 <<
i)) {
664 if (0x1B7 & (1 <<
i)) {
696 if (1U <<
c->tile_shift !=
c->tile_size ||
c->tile_shift < 1 ||
c->tile_shift > 30) {
697 av_log(avctx,
AV_LOG_ERROR,
"Tile size: %d, is not power of 2 > 1 and < 2^31\n",
c->tile_size);
713 c->pmb_width = (
w +
c->tile_size - 1) >>
c->tile_shift;
714 c->pmb_height = (
h +
c->tile_size - 1) >>
c->tile_shift;
717 c->mvi.mv =
av_calloc(
c->pmb_width * 2,
sizeof(*
c->mvi.mv));
718 if (!
c->pic || !
c->prev || !
c->mvi.mv)
741 .p.name =
"clearvideo",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
const FFCodec ff_clearvideo_decoder
static AVFormatContext * ctx
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
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)
static av_always_inline int bytestream2_tell(const GetByteContext *g)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static void clv_dct(int16_t *block)
static int tile_do_block(AVCodecContext *avctx, AVFrame *dst, const AVFrame *src, int plane, int x, int y, int dx, int dy, int size, int bias)
static MV * mvi_predict(MVInfo *mvi, int mb_x, int mb_y)
static av_cold void clv_init_static(void)
static int copyadd_block(AVCodecContext *avctx, AVFrame *dst, const AVFrame *src, int plane, int x, int y, int dx, int dy, int size, int bias)
static void mvi_update_prediction(MV *mv, MV diff)
static av_cold const VLCElem * build_vlc(VLCInitState *state, const uint8_t counts[16], const uint16_t **syms)
static void extend_edges(AVFrame *buf, int tile_size)
static int decode_block(CLVContext *ctx, int16_t *blk, int has_ac, int ac_quant)
static av_cold int clv_decode_init(AVCodecContext *avctx)
static int decode_tile(AVCodecContext *avctx, GetBitContext *gb, const LevelCodes *lc, AVFrame *dst, const AVFrame *src, int plane, int x, int y, int size, MV root_mv, MV *pred)
#define DCT_TEMPLATE(blk, step, bias, shift, dshift, OP)
static LevelCodes lev[4+3+3]
static av_cold int clv_decode_end(AVCodecContext *avctx)
static int clv_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
static int decode_mb(CLVContext *c, int x, int y)
static VLCElem dc_vlc[1104]
static void mvi_update_row(MVInfo *mvi)
static VLCElem ac_vlc[554]
static int copy_block(AVCodecContext *avctx, AVFrame *dst, const AVFrame *src, int plane, int x, int y, int dx, int dy, int size)
static void mvi_reset(MVInfo *mvi, int mb_w, int mb_h, int mb_size)
static const uint16_t clv_mv_syms[]
static const uint8_t clv_mv_len_counts[][16]
static const uint8_t clv_flags_bits[][16]
static const uint16_t clv_bias_syms[]
static const uint8_t clv_ac_bits[NUM_AC_CODES]
static const uint8_t clv_dc_syms[NUM_DC_CODES]
static const uint8_t clv_flags_syms[][16]
static const uint8_t clv_bias_len_counts[][16]
static const uint16_t clv_ac_syms[NUM_AC_CODES]
static const uint8_t clv_dc_lens[NUM_DC_CODES]
#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...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
int(* init)(AVBSFContext *ctx)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
static struct @346255127015250356166251341105367306144006377143 state
bitstream reader API header.
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static int get_sbits(GetBitContext *s, int n)
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
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_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
static const int8_t mv[256][2]
static int shift(int a, int b)
static void pred_mv(DiracBlock *block, int stride, int x, int y, int ref)
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
static int ff_thread_once(char *control, void(*routine)(void))
#define FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
const uint8_t ff_zigzag_direct[64]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static const uint8_t mv_syms[2][16][10]
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FF_ARRAY_ELEMS(a)
static const float pred[4]
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').
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
int coded_width
Bitstream width / height, may be different from width/height e.g.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
This structure stores compressed data.
For static VLCs, the number of bits can often be hardcoded at each get_vlc2() callsite.
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
av_cold const VLCElem * ff_vlc_init_tables_from_lengths(VLCInitState *state, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags)
#define VLC_INIT_STATE(_table)
#define VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vlc_table, nb_bits, nb_codes, lens, lens_wrap, syms, syms_wrap, syms_size, offset, flags)
static int bias(int x, int c)
static void mvp(const VVCLocalContext *lc, const int mvp_lx_flag, const int lx, const int8_t *ref_idx, const int amvr_shift, Mv *mv)