36 Plane *p= &
s->plane[plane_index];
37 const int mb_w=
s->b_width <<
s->block_max_depth;
38 const int mb_h=
s->b_height <<
s->block_max_depth;
40 int block_size =
MB_SIZE >>
s->block_max_depth;
41 int block_w = plane_index ? block_size>>
s->chroma_h_shift : block_size;
42 int block_h = plane_index ? block_size>>
s->chroma_v_shift : block_size;
44 int obmc_stride= plane_index ? (2*block_size)>>
s->chroma_h_shift : 2*block_size;
45 int ref_stride=
s->current_picture->linesize[plane_index];
46 uint8_t *dst8=
s->current_picture->data[plane_index];
50 if(
s->keyframe || (
s->avctx->debug&512)){
55 for(y=block_h*mb_y; y<
FFMIN(
h,block_h*(mb_y+1)); y++){
62 if(v&(~255)) v= ~(v>>31);
63 dst8[x + y*ref_stride]= v;
67 for(y=block_h*mb_y; y<
FFMIN(
h,block_h*(mb_y+1)); y++){
80 for(mb_x=0; mb_x<=mb_w; mb_x++){
82 block_w*mb_x - block_w/2,
83 block_h*mb_y - block_h/2,
86 w, ref_stride, obmc_stride,
91 if(
s->avmv && mb_y < mb_h && plane_index == 0)
92 for(mb_x=0; mb_x<mb_w; mb_x++){
94 const int b_width =
s->b_width <<
s->block_max_depth;
95 const int b_stride= b_width;
96 BlockNode *bn= &
s->block[mb_x + mb_y*b_stride];
105 avmv->
dst_x = block_w*mb_x - block_w/2;
106 avmv->
dst_y = block_h*mb_y - block_h/2;
118 const int w=
b->width;
132 new_index = save_state[0];
135 for(y=start_y; y<
h; y++){
140 v =
b->x_coeff[new_index].coeff;
141 x =
b->x_coeff[new_index++].x;
143 register int t= (
int)( (v>>1)*(unsigned)qmul + qadd)>>
QEXPSHIFT;
144 register int u= -(v&1);
147 v =
b->x_coeff[new_index].coeff;
148 x =
b->x_coeff[new_index++].x;
153 save_state[0] = new_index;
159 const int w=
s->b_width <<
s->block_max_depth;
160 const int rem_depth=
s->block_max_depth -
level;
161 const int index= (x + y*
w) << rem_depth;
162 int trx= (x+1)<<rem_depth;
171 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);
175 if(
level==
s->block_max_depth ||
get_rac(&
s->c, &
s->block_state[4 + s_context])){
177 int l = left->
color[0];
188 pred_mv(
s, &mx, &my, 0, left, top, tr);
190 if (ld < -255 || ld > 255) {
194 if (
s->nb_planes > 2) {
197 if (cbd < -255 || cbd > 255 || crd < -255 || crd > 255) {
204 if(
s->ref_frames > 1)
205 ref=
get_symbol(&
s->c, &
s->block_state[128 + 1024 + 32*ref_context], 0);
206 if (
ref >=
s->ref_frames) {
211 mx+= (unsigned)
get_symbol(&
s->c, &
s->block_state[128 + 32*(mx_context + 16*!!
ref)], 1);
212 my+= (unsigned)
get_symbol(&
s->c, &
s->block_state[128 + 32*(my_context + 16*!!
ref)], 1);
214 set_blocks(
s,
level, x, y, l,
cb,
cr, mx, my,
ref,
type);
226 const int w=
b->width;
234 for(y=start_y; y<end_y; y++){
249 const int w=
b->width;
258 for(y=start_y; y<end_y; y++){
272 if(y)
line[x] += prev[x];
279 int plane_index,
level, orientation;
281 for(plane_index=0; plane_index <
s->nb_planes; plane_index++){
283 for(orientation=
level ? 1:0; orientation<4; orientation++){
285 if (plane_index==2) q=
s->plane[1].band[
level][orientation].qlog;
286 else if(orientation==2) q=
s->plane[plane_index].band[
level][1].qlog;
288 s->plane[plane_index].band[
level][orientation].qlog= q;
294 #define GET_S(dst, check) \
295 tmp= get_symbol(&s->c, s->header_state, 0);\
297 av_log(s->avctx, AV_LOG_ERROR, "Error " #dst " is %d\n", tmp);\
298 return AVERROR_INVALIDDATA;\
303 int plane_index,
tmp;
306 memset(kstate,
MID_STATE,
sizeof(kstate));
309 if(
s->keyframe ||
s->always_reset){
311 s->spatial_decomposition_type=
315 s->block_max_depth= 0;
319 s->always_reset=
get_rac(&
s->c,
s->header_state);
320 s->temporal_decomposition_type=
get_symbol(&
s->c,
s->header_state, 0);
321 s->temporal_decomposition_count=
get_symbol(&
s->c,
s->header_state, 0);
324 if (
s->colorspace_type == 1) {
327 }
else if(
s->colorspace_type == 0) {
331 if(
s->chroma_h_shift == 1 &&
s->chroma_v_shift==1){
333 }
else if(
s->chroma_h_shift == 0 &&
s->chroma_v_shift==0){
335 }
else if(
s->chroma_h_shift == 2 &&
s->chroma_v_shift==2){
338 av_log(
s,
AV_LOG_ERROR,
"unsupported color subsample mode %d %d\n",
s->chroma_h_shift,
s->chroma_v_shift);
339 s->chroma_h_shift =
s->chroma_v_shift = 1;
346 s->chroma_h_shift =
s->chroma_v_shift = 1;
352 s->spatial_scalability=
get_rac(&
s->c,
s->header_state);
362 for(plane_index=0; plane_index<
FFMIN(
s->nb_planes, 2); plane_index++){
364 Plane *p= &
s->plane[plane_index];
372 unsigned hcoeff =
get_symbol(&
s->c,
s->header_state, 0);
380 s->plane[2].diag_mc=
s->plane[1].diag_mc;
381 s->plane[2].htaps =
s->plane[1].htaps;
382 memcpy(
s->plane[2].hcoeff,
s->plane[1].hcoeff,
sizeof(
s->plane[1].hcoeff));
390 s->spatial_decomposition_type+= (unsigned)
get_symbol(&
s->c,
s->header_state, 1);
391 if(
s->spatial_decomposition_type > 1U){
392 av_log(
s->avctx,
AV_LOG_ERROR,
"spatial_decomposition_type %d not supported\n",
s->spatial_decomposition_type);
396 s->avctx->height>>
s->chroma_v_shift) >> (
s->spatial_decomposition_count-1) <= 1){
397 av_log(
s->avctx,
AV_LOG_ERROR,
"spatial_decomposition_count %d too large for size\n",
s->spatial_decomposition_count);
400 if (
s->avctx->width > 65536-4) {
407 s->mv_scale += (unsigned)
get_symbol(&
s->c,
s->header_state, 1);
409 s->block_max_depth+= (unsigned)
get_symbol(&
s->c,
s->header_state, 1);
410 if(
s->block_max_depth > 1 ||
s->block_max_depth < 0 ||
s->mv_scale > 256U){
412 s->block_max_depth= 0;
416 if (
FFABS(
s->qbias) > 127) {
433 if (
s->c.bytestream >=
s->c.bytestream_end)
446 int buf_size = avpkt->
size;
451 int level, orientation, plane_index;
467 s->spatial_decomposition_count * 11 + 1,
469 s->spatial_idwt_buffer)) < 0)
472 for(plane_index=0; plane_index <
s->nb_planes; plane_index++){
473 Plane *p= &
s->plane[plane_index];
489 "keyframe:%d qlog:%d qbias: %d mvscale: %d "
490 "decomposition_type:%d decomposition_count:%d\n",
491 s->keyframe,
s->qlog,
s->qbias,
s->mv_scale,
492 s->spatial_decomposition_type,
493 s->spatial_decomposition_count
513 for(plane_index=0; plane_index <
s->nb_planes; plane_index++){
514 Plane *p= &
s->plane[plane_index];
520 if(
s->avctx->debug&2048){
521 memset(
s->spatial_dwt_buffer, 0,
sizeof(
DWTELEM)*
w*
h);
526 int v=
s->current_picture->data[plane_index][y*
s->current_picture->linesize[plane_index] + x];
527 s->mconly_picture->data[plane_index][y*
s->mconly_picture->linesize[plane_index] + x]= v;
533 for(orientation=
level ? 1 : 0; orientation<4; orientation++){
540 const int mb_h=
s->b_height <<
s->block_max_depth;
541 const int block_size =
MB_SIZE >>
s->block_max_depth;
542 const int block_h = plane_index ? block_size>>
s->chroma_v_shift : block_size;
550 for(mb_y=0; mb_y<=mb_h; mb_y++){
552 int slice_starty = block_h*mb_y;
553 int slice_h = block_h*(mb_y+1);
555 if (!(
s->keyframe ||
s->avctx->debug&512)){
556 slice_starty =
FFMAX(0, slice_starty - (block_h >> 1));
557 slice_h -= (block_h >> 1);
561 for(orientation=
level ? 1 : 0; orientation<4; orientation++){
565 int our_mb_start = mb_y;
566 int our_mb_end = (mb_y + 1);
568 start_y = (mb_y ? ((block_h * our_mb_start) >> (
s->spatial_decomposition_count -
level)) +
s->spatial_decomposition_count -
level + extra: 0);
569 end_y = (((block_h * our_mb_end) >> (
s->spatial_decomposition_count -
level)) +
s->spatial_decomposition_count -
level + extra);
570 if (!(
s->keyframe ||
s->avctx->debug&512)){
571 start_y =
FFMAX(0, start_y - (block_h >> (1+
s->spatial_decomposition_count -
level)));
572 end_y =
FFMAX(0, end_y - (block_h >> (1+
s->spatial_decomposition_count -
level)));
574 start_y =
FFMIN(
b->height, start_y);
575 end_y =
FFMIN(
b->height, end_y);
577 if (start_y != end_y){
578 if (orientation == 0){
580 int correlate_end_y =
FFMIN(
b->height, end_y + 1);
581 int correlate_start_y =
FFMIN(
b->height, (start_y ? start_y + 1 : 0));
592 for(; yd<slice_h; yd+=4){
597 for(; yq<slice_h && yq<
h; yq++){
622 if(!(
s->avctx->debug&2048))
626 if (res >= 0 &&
s->avmv_index) {
640 bytes_read=
c->bytestream -
c->bytestream_start;
static uint32_t inverse(uint32_t v)
find multiplicative inverse modulo 2 ^ 32
Libavcodec external API header.
#define FF_DEBUG_PICT_INFO
static av_cold int init(AVCodecContext *avctx)
#define u(width, name, range_min, range_max)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define MAX_DECOMPOSITIONS
static float add(float src0, float src1)
static const double htaps[HTAPS]
The 2nd half (48 coeffs) of a 96-tap symmetric lowpass filter.
static av_noinline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
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, buffer_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.
static 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 void pred_mv(DiracBlock *block, int stride, int x, int y, int ref)
#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...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ 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_release_buffer(AVCodecContext *avctx)
void ff_snow_reset_contexts(SnowContext *s)
int ff_snow_common_init_after_header(AVCodecContext *avctx)
int ff_snow_frame_start(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)
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)
static void unpack_coeffs(SnowContext *s, SubBand *b, SubBand *parent, int orientation)
const uint8_t *const ff_obmc_tab[4]
#define BLOCK_INTRA
Intra block, inter otherwise.
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)
#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 decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
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 void dequantize_slice_buffered(SnowContext *s, slice_buffer *sb, SubBand *b, IDWTELEM *src, int stride, int start_y, int end_y)
main external API structure.
const char * name
Name of the codec implementation.
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.
uint8_t color[3]
Color for intra.
int16_t my
Motion vector component Y, see mv_scale.
uint8_t type
Bitfield of BLOCK_*.
SubBand band[DWT_LEVELS_3D][4]
int8_t hcoeff[HTAPS_MAX/2]
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)