49 for (
int i = e - 1;
i >= 0;
i--)
70 for (
int i =
log2 - 1;
i >= 0;
i--)
78 const int w =
b->width;
79 const int h =
b->height;
92 for (
int y = 0; y <
h; y++) {
94 int lt = 0, t = 0, rt = 0;
96 if (y && prev_xc->
x == 0)
99 for (
int x = 0; x <
w; x++) {
108 if (prev_xc->
x == x + 1)
114 if (x>>1 > parent_xc->
x)
116 if (x>>1 == parent_xc->
x)
117 p = parent_xc->
coeff;
120 int context =
av_log2(3*(l>>1) + (lt>>1) + (t&~1) + (rt>>1) + (p>>1));
122 v =
get_rac(&
s->c, &
b->state[0][context]);
124 v = 2*(
get_symbol2(&
s->c,
b->state[context + 2], context-4) + 1);
126 if ((uint16_t)v != v) {
138 v +=
get_rac(&
s->c, &
b->state[0][16 + 1 + 3]);
139 if ((uint16_t)v != v) {
151 if (y) max_run =
FFMIN(
run, prev_xc->
x - x - 2);
154 max_run =
FFMIN(max_run, 2*parent_xc->
x - x - 1);
168 while (parent_xc->
x != parent->
width+1)
171 prev_parent_xc= parent_xc;
173 parent_xc= prev_parent_xc;
182 Plane *p= &
s->plane[plane_index];
183 const int mb_w=
s->b_width <<
s->block_max_depth;
184 const int mb_h=
s->b_height <<
s->block_max_depth;
186 int block_size =
MB_SIZE >>
s->block_max_depth;
187 int block_w = plane_index ? block_size>>
s->chroma_h_shift : block_size;
188 int block_h = plane_index ? block_size>>
s->chroma_v_shift : block_size;
190 int obmc_stride= plane_index ? (2*block_size)>>
s->chroma_h_shift : 2*block_size;
191 int ref_stride=
s->current_picture->linesize[plane_index];
192 uint8_t *dst8=
s->current_picture->data[plane_index];
196 if(
s->keyframe || (
s->avctx->debug&512)){
201 for(y=block_h*mb_y; y<
FFMIN(
h,block_h*(mb_y+1)); y++){
208 if(v&(~255)) v= ~(v>>31);
209 dst8[x + y*ref_stride]= v;
213 for(y=block_h*mb_y; y<
FFMIN(
h,block_h*(mb_y+1)); y++){
226 for(mb_x=0; mb_x<=mb_w; mb_x++){
228 block_w*mb_x - block_w/2,
229 block_h*mb_y - block_h/2,
232 w, ref_stride, obmc_stride,
234 add, 0, plane_index);
237 if(
s->avmv && mb_y < mb_h && plane_index == 0)
238 for(mb_x=0; mb_x<mb_w; mb_x++){
240 const int b_width =
s->b_width <<
s->block_max_depth;
241 const int b_stride= b_width;
242 BlockNode *bn= &
s->block[mb_x + mb_y*b_stride];
251 avmv->
dst_x = block_w*mb_x - block_w/2;
252 avmv->
dst_y = block_h*mb_y - block_h/2;
264 const int w=
b->width;
278 new_index = save_state[0];
281 for(y=start_y; y<
h; y++){
286 v =
b->x_coeff[new_index].coeff;
287 x =
b->x_coeff[new_index++].x;
289 register int t= (int)( (v>>1)*(
unsigned)qmul + qadd)>>
QEXPSHIFT;
290 register int u= -(v&1);
293 v =
b->x_coeff[new_index].coeff;
294 x =
b->x_coeff[new_index++].x;
299 save_state[0] = new_index;
305 const int w=
s->b_width <<
s->block_max_depth;
306 const int rem_depth=
s->block_max_depth -
level;
307 const int index= (x + y*
w) << rem_depth;
308 int trx= (x+1)<<rem_depth;
317 set_blocks(
s,
level, x, y,
null_block.color[0],
null_block.color[1],
null_block.color[2],
null_block.mx,
null_block.my,
null_block.ref,
BLOCK_INTRA);
321 if(
level==
s->block_max_depth ||
get_rac(&
s->c, &
s->block_state[4 + s_context])){
323 int l =
left->color[0];
336 if (ld < -255 || ld > 255) {
340 if (
s->nb_planes > 2) {
343 if (cbd < -255 || cbd > 255 || crd < -255 || crd > 255) {
350 if(
s->ref_frames > 1)
351 ref=
get_symbol(&
s->c, &
s->block_state[128 + 1024 + 32*ref_context], 0);
352 if (
ref >=
s->ref_frames) {
357 mx+= (unsigned)
get_symbol(&
s->c, &
s->block_state[128 + 32*(mx_context + 16*!!
ref)], 1);
358 my+= (unsigned)
get_symbol(&
s->c, &
s->block_state[128 + 32*(my_context + 16*!!
ref)], 1);
360 set_blocks(
s,
level, x, y, l,
cb,
cr,
mx,
my,
ref,
type);
372 const int w=
b->width;
380 for(y=start_y; y<end_y; y++){
395 const int w=
b->width;
404 for(y=start_y; y<end_y; y++){
418 if(y)
line[x] += prev[x];
425 int plane_index,
level, orientation;
427 for(plane_index=0; plane_index <
s->nb_planes; plane_index++){
429 for(orientation=
level ? 1:0; orientation<4; orientation++){
431 if (plane_index==2) q=
s->plane[1].band[
level][orientation].qlog;
432 else if(orientation==2) q=
s->plane[plane_index].band[
level][1].qlog;
434 s->plane[plane_index].band[
level][orientation].qlog= q;
440#define GET_S(dst, check) \
441 tmp= get_symbol(&s->c, s->header_state, 0);\
443 av_log(s->avctx, AV_LOG_ERROR, "Error " #dst " is %d\n", tmp);\
444 return AVERROR_INVALIDDATA;\
449 int plane_index,
tmp;
452 memset(kstate,
MID_STATE,
sizeof(kstate));
455 if(
s->keyframe ||
s->always_reset){
457 s->spatial_decomposition_type=
461 s->block_max_depth= 0;
465 s->always_reset=
get_rac(&
s->c,
s->header_state);
466 s->temporal_decomposition_type=
get_symbol(&
s->c,
s->header_state, 0);
467 s->temporal_decomposition_count=
get_symbol(&
s->c,
s->header_state, 0);
470 if (
s->colorspace_type == 1) {
473 }
else if(
s->colorspace_type == 0) {
477 if(
s->chroma_h_shift == 1 &&
s->chroma_v_shift==1){
479 }
else if(
s->chroma_h_shift == 0 &&
s->chroma_v_shift==0){
481 }
else if(
s->chroma_h_shift == 2 &&
s->chroma_v_shift==2){
485 "unsupported color subsample mode %d %d\n",
486 s->chroma_h_shift,
s->chroma_v_shift);
487 s->chroma_h_shift =
s->chroma_v_shift = 1;
494 s->chroma_h_shift =
s->chroma_v_shift = 1;
500 s->spatial_scalability=
get_rac(&
s->c,
s->header_state);
510 for(plane_index=0; plane_index<
FFMIN(
s->nb_planes, 2); plane_index++){
512 Plane *p= &
s->plane[plane_index];
513 p->diag_mc=
get_rac(&
s->c,
s->header_state);
520 unsigned hcoeff =
get_symbol(&
s->c,
s->header_state, 0);
523 p->hcoeff[
i]= hcoeff * (1-2*(
i&1));
526 p->hcoeff[0]= 32-sum;
528 s->plane[2].diag_mc=
s->plane[1].diag_mc;
529 s->plane[2].htaps =
s->plane[1].htaps;
530 memcpy(
s->plane[2].hcoeff,
s->plane[1].hcoeff,
sizeof(
s->plane[1].hcoeff));
538 s->spatial_decomposition_type+= (unsigned)
get_symbol(&
s->c,
s->header_state, 1);
539 if(
s->spatial_decomposition_type > 1U){
540 av_log(
s->avctx,
AV_LOG_ERROR,
"spatial_decomposition_type %d not supported\n",
s->spatial_decomposition_type);
544 s->avctx->height>>
s->chroma_v_shift) >> (
s->spatial_decomposition_count-1) <= 1){
545 av_log(
s->avctx,
AV_LOG_ERROR,
"spatial_decomposition_count %d too large for size\n",
s->spatial_decomposition_count);
548 if (
s->avctx->width > 65536-4) {
555 s->mv_scale += (unsigned)
get_symbol(&
s->c,
s->header_state, 1);
557 s->block_max_depth+= (unsigned)
get_symbol(&
s->c,
s->header_state, 1);
558 if(
s->block_max_depth > 1 ||
s->block_max_depth < 0 ||
s->mv_scale > 256U){
560 s->block_max_depth= 0;
564 if (
FFABS(
s->qbias) > 127) {
581 if (
s->c.bytestream >=
s->c.bytestream_end)
593 const uint8_t *buf = avpkt->
data;
594 int buf_size = avpkt->
size;
598 int level, orientation, plane_index;
608 if (avctx->
debug & 2048) {
615 if (
s->current_picture->data[0] &&
s->current_picture->format != avctx->
pix_fmt) {
627 s->spatial_decomposition_count * 11 + 1,
629 s->spatial_idwt_buffer)) < 0)
632 for(plane_index=0; plane_index <
s->nb_planes; plane_index++){
633 Plane *p= &
s->plane[plane_index];
634 p->fast_mc= p->diag_mc && p->htaps==6 && p->hcoeff[0]==40
644 s->current_picture->width =
s->avctx->width;
645 s->current_picture->height =
s->avctx->height;
655 "keyframe:%d qlog:%d qbias: %d mvscale: %d "
656 "decomposition_type:%d decomposition_count:%d\n",
657 s->keyframe,
s->qlog,
s->qbias,
s->mv_scale,
658 s->spatial_decomposition_type,
659 s->spatial_decomposition_count
679 for(plane_index=0; plane_index <
s->nb_planes; plane_index++){
680 Plane *p= &
s->plane[plane_index];
686 if(
s->avctx->debug&2048){
687 memset(
s->spatial_dwt_buffer, 0,
sizeof(
DWTELEM)*
w*
h);
692 int v=
s->current_picture->data[plane_index][y*
s->current_picture->linesize[plane_index] + x];
693 s->mconly_picture->data[plane_index][y*
s->mconly_picture->linesize[plane_index] + x]= v;
699 for(orientation=
level ? 1 : 0; orientation<4; orientation++){
706 const int mb_h=
s->b_height <<
s->block_max_depth;
707 const int block_size =
MB_SIZE >>
s->block_max_depth;
708 const int block_h = plane_index ? block_size>>
s->chroma_v_shift : block_size;
716 for(mb_y=0; mb_y<=mb_h; mb_y++){
718 int slice_starty = block_h*mb_y;
719 int slice_h = block_h*(mb_y+1);
721 if (!(
s->keyframe ||
s->avctx->debug&512)){
722 slice_starty =
FFMAX(0, slice_starty - (block_h >> 1));
723 slice_h -= (block_h >> 1);
727 for(orientation=
level ? 1 : 0; orientation<4; orientation++){
731 int our_mb_start = mb_y;
732 int our_mb_end = (mb_y + 1);
734 start_y = (mb_y ? ((block_h * our_mb_start) >> (
s->spatial_decomposition_count -
level)) +
s->spatial_decomposition_count -
level + extra: 0);
735 end_y = (((block_h * our_mb_end) >> (
s->spatial_decomposition_count -
level)) +
s->spatial_decomposition_count -
level + extra);
736 if (!(
s->keyframe ||
s->avctx->debug&512)){
737 start_y =
FFMAX(0, start_y - (block_h >> (1+
s->spatial_decomposition_count -
level)));
738 end_y =
FFMAX(0, end_y - (block_h >> (1+
s->spatial_decomposition_count -
level)));
740 start_y =
FFMIN(
b->height, start_y);
741 end_y =
FFMIN(
b->height, end_y);
743 if (start_y != end_y){
744 if (orientation == 0){
745 SubBand * correlate_band = &p->band[0][0];
746 int correlate_end_y =
FFMIN(
b->height, end_y + 1);
747 int correlate_start_y =
FFMIN(
b->height, (start_y ? start_y + 1 : 0));
758 for(; yd<slice_h; yd+=4){
763 for(; yq<slice_h && yq<
h; yq++){
773 y =
FFMIN(p->height, slice_starty);
774 end_y =
FFMIN(p->height, slice_h);
788 if(!(
s->avctx->debug&2048))
792 if (res >= 0 &&
s->avmv_index) {
806 bytes_read=
c->bytestream -
c->bytestream_start;
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
const FFCodec ff_snow_decoder
static av_cold void close(AVCodecParserContext *s)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Libavcodec external API header.
#define FF_DEBUG_PICT_INFO
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#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...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define MAX_DECOMPOSITIONS
static const double htaps[HTAPS]
The 2nd half (48 coeffs) of a 96-tap symmetric lowpass filter.
int(* init)(AVBSFContext *ctx)
static struct @346255127015250356166251341105367306144006377143 state
#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.
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
#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.
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size)
Add a new side data to a frame.
@ AV_FRAME_DATA_MOTION_VECTORS
Motion vectors exported by some codecs (on demand through the export_mvs flag set in the libavcodec A...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
int av_size_mult(size_t a, size_t b, size_t *r)
Multiply two size_t values checking for overflow.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
static av_cold int decode_end(AVCodecContext *avctx)
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
#define u(width, name, range_min, range_max)
static void pred_mv(DiracBlock *block, int stride, int x, int y, int ref)
Memory handling functions.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size)
void ff_build_rac_states(RangeCoder *c, int factor, int max_p)
static int get_rac(RangeCoder *c, uint8_t *const state)
av_cold int ff_snow_common_init(AVCodecContext *avctx)
void ff_snow_reset_contexts(SnowContext *s)
int ff_snow_common_init_after_header(AVCodecContext *avctx)
int ff_snow_frames_prepare(SnowContext *s)
av_cold void ff_snow_common_end(SnowContext *s)
int ff_snow_alloc_blocks(SnowContext *s)
static av_always_inline void predict_plane(SnowContext *s, IDWTELEM *buf, int plane_index, int add)
const uint8_t ff_qexp[QROOT]
static void set_blocks(SnowContext *s, int level, int x, int y, int l, int cb, int cr, int mx, int my, int ref, int type)
const uint8_t *const ff_obmc_tab[4]
#define BLOCK_INTRA
Intra block, inter otherwise.
const int8_t ff_quant3bA[256]
static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer *sb, IDWTELEM *dst, uint8_t *dst8, const uint8_t *obmc, int src_x, int src_y, int b_w, int b_h, int w, int h, int dst_stride, int src_stride, int obmc_stride, int b_x, int b_y, int add, int offset_dst, int plane_index)
static const BlockNode null_block
void ff_slice_buffer_release(slice_buffer *buf, int line)
void ff_spatial_idwt_buffered_slice(SnowDWTContext *dsp, DWTCompose *cs, slice_buffer *slice_buf, IDWTELEM *temp, int width, int height, int stride_line, int type, int decomposition_count, int y)
void ff_slice_buffer_flush(slice_buffer *buf)
int ff_slice_buffer_init(slice_buffer *buf, int line_count, int max_allocated_lines, int line_width, IDWTELEM *base_buffer)
void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width, int height, int stride_line, int type, int decomposition_count)
void ff_slice_buffer_destroy(slice_buffer *buf)
#define slice_buffer_get_line(slice_buf, line_num)
static void decode_qlogs(SnowContext *s)
static int decode_blocks(SnowContext *s)
static int decode_header(SnowContext *s)
static void correlate_slice_buffered(SnowContext *s, slice_buffer *sb, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median, int start_y, int end_y)
static void unpack_coeffs(SnowContext *s, SubBand *b, SubBand *parent, int orientation)
#define GET_S(dst, check)
static av_cold int decode_end(AVCodecContext *avctx)
static int decode_q_branch(SnowContext *s, int level, int x, int y)
static int get_symbol2(RangeCoder *c, uint8_t *state, int log2)
static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer *sb, IDWTELEM *old_buffer, int plane_index, int add, int mb_y)
static void decode_subband_slice_buffered(SnowContext *s, SubBand *b, slice_buffer *sb, int start_y, int h, int save_state[1])
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
static void dequantize_slice_buffered(SnowContext *s, slice_buffer *sb, SubBand *b, IDWTELEM *src, int stride, int start_y, int end_y)
static int get_symbol(RangeCoder *c, uint8_t *state, int is_signed)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
int32_t source
Where the current macroblock comes from; negative value when it comes from the past,...
int16_t dst_x
Absolute destination position.
uint64_t flags
Extra flag information.
int32_t motion_x
Motion vector src_x = dst_x + motion_x / motion_scale src_y = dst_y + motion_y / motion_scale.
uint8_t w
Width and height of the block.
int16_t src_x
Absolute source position.
This structure stores compressed data.
uint8_t ref
Reference frame index.
int16_t mx
Motion vector component X, see mv_scale.
int16_t my
Motion vector component Y, see mv_scale.
uint8_t type
Bitfield of BLOCK_*.
Used to minimize the amount of memory used in order to optimize cache performance.
IDWTELEM ** line
For use by idwt and predict_slices.
static int ref[MAX_W *MAX_W]
static double cr(void *priv, double x, double y)
static double cb(void *priv, double x, double y)
static const double coeff[2][5]