/* * Copyright (C) 2004 Michael Niedermayer * Copyright (C) 2006 Robert Edele * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef AVCODEC_SNOW_H #define AVCODEC_SNOW_H #include "libavutil/motion_vector.h" #include "avcodec.h" #include "hpeldsp.h" #include "snow_dwt.h" #include "rangecoder.h" #include "mathops.h" #include "h264qpel.h" #include "videodsp.h" #define SNOW_MAX_PLANES 4 #define MID_STATE 128 #define MAX_PLANES 4 #define QSHIFT 5 #define QROOT (1<ref_frames == 1){ *mx = mid_pred(left->mx, top->mx, tr->mx); *my = mid_pred(left->my, top->my, tr->my); }else{ const int *scale = ff_scale_mv_ref[ref]; *mx = mid_pred((left->mx * scale[left->ref] + 128) >>8, (top ->mx * scale[top ->ref] + 128) >>8, (tr ->mx * scale[tr ->ref] + 128) >>8); *my = mid_pred((left->my * scale[left->ref] + 128) >>8, (top ->my * scale[top ->ref] + 128) >>8, (tr ->my * scale[tr ->ref] + 128) >>8); } } static av_always_inline int same_block(BlockNode *a, BlockNode *b){ if((a->type&BLOCK_INTRA) && (b->type&BLOCK_INTRA)){ return !((a->color[0] - b->color[0]) | (a->color[1] - b->color[1]) | (a->color[2] - b->color[2])); }else{ return !((a->mx - b->mx) | (a->my - b->my) | (a->ref - b->ref) | ((a->type ^ b->type)&BLOCK_INTRA)); } } //FIXME name cleanup (b_w, block_w, b_width stuff) //XXX should we really inline it? 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){ const int b_width = s->b_width << s->block_max_depth; const int b_height= s->b_height << s->block_max_depth; const int b_stride= b_width; BlockNode *lt= &s->block[b_x + b_y*b_stride]; BlockNode *rt= lt+1; BlockNode *lb= lt+b_stride; BlockNode *rb= lb+1; uint8_t *block[4]; // When src_stride is large enough, it is possible to interleave the blocks. // Otherwise the blocks are written sequentially in the tmp buffer. int tmp_step= src_stride >= 7*MB_SIZE ? MB_SIZE : MB_SIZE*src_stride; uint8_t *tmp = s->scratchbuf; uint8_t *ptmp; int x,y; if(b_x<0){ lt= rt; lb= rb; }else if(b_x + 1 >= b_width){ rt= lt; rb= lb; } if(b_y<0){ lt= lb; rt= rb; }else if(b_y + 1 >= b_height){ lb= lt; rb= rt; } if(src_x<0){ //FIXME merge with prev & always round internal width up to *16 obmc -= src_x; b_w += src_x; if(!sliced && !offset_dst) dst -= src_x; src_x=0; } if(src_x + b_w > w){ b_w = w - src_x; } if(src_y<0){ obmc -= src_y*obmc_stride; b_h += src_y; if(!sliced && !offset_dst) dst -= src_y*dst_stride; src_y=0; } if(src_y + b_h> h){ b_h = h - src_y; } if(b_w<=0 || b_h<=0) return; if(!sliced && offset_dst) dst += src_x + src_y*dst_stride; dst8+= src_x + src_y*src_stride; // src += src_x + src_y*src_stride; ptmp= tmp + 3*tmp_step; block[0]= ptmp; ptmp+=tmp_step; ff_snow_pred_block(s, block[0], tmp, src_stride, src_x, src_y, b_w, b_h, lt, plane_index, w, h); if(same_block(lt, rt)){ block[1]= block[0]; }else{ block[1]= ptmp; ptmp+=tmp_step; ff_snow_pred_block(s, block[1], tmp, src_stride, src_x, src_y, b_w, b_h, rt, plane_index, w, h); } if(same_block(lt, lb)){ block[2]= block[0]; }else if(same_block(rt, lb)){ block[2]= block[1]; }else{ block[2]= ptmp; ptmp+=tmp_step; ff_snow_pred_block(s, block[2], tmp, src_stride, src_x, src_y, b_w, b_h, lb, plane_index, w, h); } if(same_block(lt, rb) ){ block[3]= block[0]; }else if(same_block(rt, rb)){ block[3]= block[1]; }else if(same_block(lb, rb)){ block[3]= block[2]; }else{ block[3]= ptmp; ff_snow_pred_block(s, block[3], tmp, src_stride, src_x, src_y, b_w, b_h, rb, plane_index, w, h); } if(sliced){ s->dwt.inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); }else{ for(y=0; y>1); const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1); const uint8_t *obmc4= obmc3+ (obmc_stride>>1); for(x=0; x>= 8 - FRAC_BITS; } if(add){ v += dst[x + y*dst_stride]; v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS; if(v&(~255)) v= ~(v>>31); dst8[x + y*src_stride] = v; }else{ dst[x + y*dst_stride] -= v; } } } } } static av_always_inline void predict_slice(SnowContext *s, IDWTELEM *buf, int plane_index, int add, int mb_y){ Plane *p= &s->plane[plane_index]; const int mb_w= s->b_width << s->block_max_depth; const int mb_h= s->b_height << s->block_max_depth; int x, y, mb_x; int block_size = MB_SIZE >> s->block_max_depth; int block_w = plane_index ? block_size>>s->chroma_h_shift : block_size; int block_h = plane_index ? block_size>>s->chroma_v_shift : block_size; const uint8_t *obmc = plane_index ? ff_obmc_tab[s->block_max_depth+s->chroma_h_shift] : ff_obmc_tab[s->block_max_depth]; const int obmc_stride= plane_index ? (2*block_size)>>s->chroma_h_shift : 2*block_size; int ref_stride= s->current_picture->linesize[plane_index]; uint8_t *dst8= s->current_picture->data[plane_index]; int w= p->width; int h= p->height; av_assert2(s->chroma_h_shift == s->chroma_v_shift); // obmc params assume squares if(s->keyframe || (s->avctx->debug&512)){ if(mb_y==mb_h) return; if(add){ for(y=block_h*mb_y; y>= FRAC_BITS; if(v&(~255)) v= ~(v>>31); dst8[x + y*ref_stride]= v; } } }else{ for(y=block_h*mb_y; yb_height << s->block_max_depth; int mb_y; for(mb_y=0; mb_y<=mb_h; mb_y++) predict_slice(s, buf, plane_index, add, mb_y); } static inline 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 int w= s->b_width << s->block_max_depth; const int rem_depth= s->block_max_depth - level; const int index= (x + y*w) << rem_depth; const int block_w= 1<block[index + i + j*w]= block; } } } extern const int8_t ff_quant3bA[256]; #define QEXPSHIFT (7-FRAC_BITS+8) //FIXME try to change this to 0 #endif /* AVCODEC_SNOW_H */