• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavcodec/snow.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
00003  * Copyright (C) 2006 Robert Edele <yartrebo@earthlink.net>
00004  *
00005  * This file is part of Libav.
00006  *
00007  * Libav is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * Libav is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with Libav; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #ifndef AVCODEC_SNOW_H
00023 #define AVCODEC_SNOW_H
00024 
00025 #include "dsputil.h"
00026 #include "dwt.h"
00027 
00028 #include "rangecoder.h"
00029 #include "mathops.h"
00030 #include "mpegvideo.h"
00031 
00032 #define MID_STATE 128
00033 
00034 #define MAX_PLANES 4
00035 #define QSHIFT 5
00036 #define QROOT (1<<QSHIFT)
00037 #define LOSSLESS_QLOG -128
00038 #define FRAC_BITS 4
00039 #define MAX_REF_FRAMES 8
00040 
00041 #define LOG2_OBMC_MAX 8
00042 #define OBMC_MAX (1<<(LOG2_OBMC_MAX))
00043 typedef struct BlockNode{
00044     int16_t mx;
00045     int16_t my;
00046     uint8_t ref;
00047     uint8_t color[3];
00048     uint8_t type;
00049 //#define TYPE_SPLIT    1
00050 #define BLOCK_INTRA   1
00051 #define BLOCK_OPT     2
00052 //#define TYPE_NOCOLOR  4
00053     uint8_t level; //FIXME merge into type?
00054 }BlockNode;
00055 
00056 static const BlockNode null_block= { //FIXME add border maybe
00057     .color= {128,128,128},
00058     .mx= 0,
00059     .my= 0,
00060     .ref= 0,
00061     .type= 0,
00062     .level= 0,
00063 };
00064 
00065 #define LOG2_MB_SIZE 4
00066 #define MB_SIZE (1<<LOG2_MB_SIZE)
00067 #define ENCODER_EXTRA_BITS 4
00068 #define HTAPS_MAX 8
00069 
00070 typedef struct x_and_coeff{
00071     int16_t x;
00072     uint16_t coeff;
00073 } x_and_coeff;
00074 
00075 typedef struct SubBand{
00076     int level;
00077     int stride;
00078     int width;
00079     int height;
00080     int qlog;        
00081     DWTELEM *buf;
00082     IDWTELEM *ibuf;
00083     int buf_x_offset;
00084     int buf_y_offset;
00085     int stride_line; 
00086     x_and_coeff * x_coeff;
00087     struct SubBand *parent;
00088     uint8_t state[/*7*2*/ 7 + 512][32];
00089 }SubBand;
00090 
00091 typedef struct Plane{
00092     int width;
00093     int height;
00094     SubBand band[MAX_DECOMPOSITIONS][4];
00095 
00096     int htaps;
00097     int8_t hcoeff[HTAPS_MAX/2];
00098     int diag_mc;
00099     int fast_mc;
00100 
00101     int last_htaps;
00102     int8_t last_hcoeff[HTAPS_MAX/2];
00103     int last_diag_mc;
00104 }Plane;
00105 
00106 typedef struct SnowContext{
00107     AVClass *class;
00108     AVCodecContext *avctx;
00109     RangeCoder c;
00110     DSPContext dsp;
00111     DWTContext dwt;
00112     AVFrame new_picture;
00113     AVFrame input_picture;              
00114     AVFrame current_picture;
00115     AVFrame last_picture[MAX_REF_FRAMES];
00116     uint8_t *halfpel_plane[MAX_REF_FRAMES][4][4];
00117     AVFrame mconly_picture;
00118 //     uint8_t q_context[16];
00119     uint8_t header_state[32];
00120     uint8_t block_state[128 + 32*128];
00121     int keyframe;
00122     int always_reset;
00123     int version;
00124     int spatial_decomposition_type;
00125     int last_spatial_decomposition_type;
00126     int temporal_decomposition_type;
00127     int spatial_decomposition_count;
00128     int last_spatial_decomposition_count;
00129     int temporal_decomposition_count;
00130     int max_ref_frames;
00131     int ref_frames;
00132     int16_t (*ref_mvs[MAX_REF_FRAMES])[2];
00133     uint32_t *ref_scores[MAX_REF_FRAMES];
00134     DWTELEM *spatial_dwt_buffer;
00135     IDWTELEM *spatial_idwt_buffer;
00136     int colorspace_type;
00137     int chroma_h_shift;
00138     int chroma_v_shift;
00139     int spatial_scalability;
00140     int qlog;
00141     int last_qlog;
00142     int lambda;
00143     int lambda2;
00144     int pass1_rc;
00145     int mv_scale;
00146     int last_mv_scale;
00147     int qbias;
00148     int last_qbias;
00149 #define QBIAS_SHIFT 3
00150     int b_width;
00151     int b_height;
00152     int block_max_depth;
00153     int last_block_max_depth;
00154     Plane plane[MAX_PLANES];
00155     BlockNode *block;
00156 #define ME_CACHE_SIZE 1024
00157     unsigned me_cache[ME_CACHE_SIZE];
00158     unsigned me_cache_generation;
00159     slice_buffer sb;
00160     int memc_only;
00161 
00162     MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to eventually make the motion estimation independent of MpegEncContext, so this will be removed then (FIXME/XXX)
00163 
00164     uint8_t *scratchbuf;
00165 }SnowContext;
00166 
00167 /* Tables */
00168 extern const uint8_t * const obmc_tab[4];
00169 #ifdef __sgi
00170 // Avoid a name clash on SGI IRIX
00171 #undef qexp
00172 #endif
00173 extern uint8_t qexp[QROOT];
00174 extern int scale_mv_ref[MAX_REF_FRAMES][MAX_REF_FRAMES];
00175 
00176 /* C bits used by mmx/sse2/altivec */
00177 
00178 static av_always_inline void snow_interleave_line_header(int * i, int width, IDWTELEM * low, IDWTELEM * high){
00179     (*i) = (width) - 2;
00180 
00181     if (width & 1){
00182         low[(*i)+1] = low[((*i)+1)>>1];
00183         (*i)--;
00184     }
00185 }
00186 
00187 static av_always_inline void snow_interleave_line_footer(int * i, IDWTELEM * low, IDWTELEM * high){
00188     for (; (*i)>=0; (*i)-=2){
00189         low[(*i)+1] = high[(*i)>>1];
00190         low[*i] = low[(*i)>>1];
00191     }
00192 }
00193 
00194 static av_always_inline void snow_horizontal_compose_lift_lead_out(int i, IDWTELEM * dst, IDWTELEM * src, IDWTELEM * ref, int width, int w, int lift_high, int mul, int add, int shift){
00195     for(; i<w; i++){
00196         dst[i] = src[i] - ((mul * (ref[i] + ref[i + 1]) + add) >> shift);
00197     }
00198 
00199     if((width^lift_high)&1){
00200         dst[w] = src[w] - ((mul * 2 * ref[w] + add) >> shift);
00201     }
00202 }
00203 
00204 static av_always_inline void snow_horizontal_compose_liftS_lead_out(int i, IDWTELEM * dst, IDWTELEM * src, IDWTELEM * ref, int width, int w){
00205         for(; i<w; i++){
00206             dst[i] = src[i] + ((ref[i] + ref[(i+1)]+W_BO + 4 * src[i]) >> W_BS);
00207         }
00208 
00209         if(width&1){
00210             dst[w] = src[w] + ((2 * ref[w] + W_BO + 4 * src[w]) >> W_BS);
00211         }
00212 }
00213 
00214 /* common code */
00215 
00216 int ff_snow_common_init(AVCodecContext *avctx);
00217 int ff_snow_common_init_after_header(AVCodecContext *avctx);
00218 void ff_snow_common_end(SnowContext *s);
00219 void ff_snow_release_buffer(AVCodecContext *avctx);
00220 void ff_snow_reset_contexts(SnowContext *s);
00221 int ff_snow_alloc_blocks(SnowContext *s);
00222 int ff_snow_frame_start(SnowContext *s);
00223 void ff_snow_pred_block(SnowContext *s, uint8_t *dst, uint8_t *tmp, int stride,
00224                      int sx, int sy, int b_w, int b_h, BlockNode *block,
00225                      int plane_index, int w, int h);
00226 /* common inline functions */
00227 //XXX doublecheck all of them should stay inlined
00228 
00229 static inline void snow_set_blocks(SnowContext *s, int level, int x, int y, int l, int cb, int cr, int mx, int my, int ref, int type){
00230     const int w= s->b_width << s->block_max_depth;
00231     const int rem_depth= s->block_max_depth - level;
00232     const int index= (x + y*w) << rem_depth;
00233     const int block_w= 1<<rem_depth;
00234     BlockNode block;
00235     int i,j;
00236 
00237     block.color[0]= l;
00238     block.color[1]= cb;
00239     block.color[2]= cr;
00240     block.mx= mx;
00241     block.my= my;
00242     block.ref= ref;
00243     block.type= type;
00244     block.level= level;
00245 
00246     for(j=0; j<block_w; j++){
00247         for(i=0; i<block_w; i++){
00248             s->block[index + i + j*w]= block;
00249         }
00250     }
00251 }
00252 
00253 static inline void pred_mv(SnowContext *s, int *mx, int *my, int ref,
00254                            const BlockNode *left, const BlockNode *top, const BlockNode *tr){
00255     if(s->ref_frames == 1){
00256         *mx = mid_pred(left->mx, top->mx, tr->mx);
00257         *my = mid_pred(left->my, top->my, tr->my);
00258     }else{
00259         const int *scale = scale_mv_ref[ref];
00260         *mx = mid_pred((left->mx * scale[left->ref] + 128) >>8,
00261                        (top ->mx * scale[top ->ref] + 128) >>8,
00262                        (tr  ->mx * scale[tr  ->ref] + 128) >>8);
00263         *my = mid_pred((left->my * scale[left->ref] + 128) >>8,
00264                        (top ->my * scale[top ->ref] + 128) >>8,
00265                        (tr  ->my * scale[tr  ->ref] + 128) >>8);
00266     }
00267 }
00268 
00269 static av_always_inline int same_block(BlockNode *a, BlockNode *b){
00270     if((a->type&BLOCK_INTRA) && (b->type&BLOCK_INTRA)){
00271         return !((a->color[0] - b->color[0]) | (a->color[1] - b->color[1]) | (a->color[2] - b->color[2]));
00272     }else{
00273         return !((a->mx - b->mx) | (a->my - b->my) | (a->ref - b->ref) | ((a->type ^ b->type)&BLOCK_INTRA));
00274     }
00275 }
00276 
00277 //FIXME name cleanup (b_w, block_w, b_width stuff)
00278 //XXX should we really inline it?
00279 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){
00280     const int b_width = s->b_width  << s->block_max_depth;
00281     const int b_height= s->b_height << s->block_max_depth;
00282     const int b_stride= b_width;
00283     BlockNode *lt= &s->block[b_x + b_y*b_stride];
00284     BlockNode *rt= lt+1;
00285     BlockNode *lb= lt+b_stride;
00286     BlockNode *rb= lb+1;
00287     uint8_t *block[4];
00288     int tmp_step= src_stride >= 7*MB_SIZE ? MB_SIZE : MB_SIZE*src_stride;
00289     uint8_t *tmp = s->scratchbuf;
00290     uint8_t *ptmp;
00291     int x,y;
00292 
00293     if(b_x<0){
00294         lt= rt;
00295         lb= rb;
00296     }else if(b_x + 1 >= b_width){
00297         rt= lt;
00298         rb= lb;
00299     }
00300     if(b_y<0){
00301         lt= lb;
00302         rt= rb;
00303     }else if(b_y + 1 >= b_height){
00304         lb= lt;
00305         rb= rt;
00306     }
00307 
00308     if(src_x<0){ //FIXME merge with prev & always round internal width up to *16
00309         obmc -= src_x;
00310         b_w += src_x;
00311         if(!sliced && !offset_dst)
00312             dst -= src_x;
00313         src_x=0;
00314     }else if(src_x + b_w > w){
00315         b_w = w - src_x;
00316     }
00317     if(src_y<0){
00318         obmc -= src_y*obmc_stride;
00319         b_h += src_y;
00320         if(!sliced && !offset_dst)
00321             dst -= src_y*dst_stride;
00322         src_y=0;
00323     }else if(src_y + b_h> h){
00324         b_h = h - src_y;
00325     }
00326 
00327     if(b_w<=0 || b_h<=0) return;
00328 
00329     assert(src_stride > 2*MB_SIZE + 5);
00330 
00331     if(!sliced && offset_dst)
00332         dst += src_x + src_y*dst_stride;
00333     dst8+= src_x + src_y*src_stride;
00334 //    src += src_x + src_y*src_stride;
00335 
00336     ptmp= tmp + 3*tmp_step;
00337     block[0]= ptmp;
00338     ptmp+=tmp_step;
00339     ff_snow_pred_block(s, block[0], tmp, src_stride, src_x, src_y, b_w, b_h, lt, plane_index, w, h);
00340 
00341     if(same_block(lt, rt)){
00342         block[1]= block[0];
00343     }else{
00344         block[1]= ptmp;
00345         ptmp+=tmp_step;
00346         ff_snow_pred_block(s, block[1], tmp, src_stride, src_x, src_y, b_w, b_h, rt, plane_index, w, h);
00347     }
00348 
00349     if(same_block(lt, lb)){
00350         block[2]= block[0];
00351     }else if(same_block(rt, lb)){
00352         block[2]= block[1];
00353     }else{
00354         block[2]= ptmp;
00355         ptmp+=tmp_step;
00356         ff_snow_pred_block(s, block[2], tmp, src_stride, src_x, src_y, b_w, b_h, lb, plane_index, w, h);
00357     }
00358 
00359     if(same_block(lt, rb) ){
00360         block[3]= block[0];
00361     }else if(same_block(rt, rb)){
00362         block[3]= block[1];
00363     }else if(same_block(lb, rb)){
00364         block[3]= block[2];
00365     }else{
00366         block[3]= ptmp;
00367         ff_snow_pred_block(s, block[3], tmp, src_stride, src_x, src_y, b_w, b_h, rb, plane_index, w, h);
00368     }
00369     if(sliced){
00370         s->dwt.inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
00371     }else{
00372         for(y=0; y<b_h; y++){
00373             //FIXME ugly misuse of obmc_stride
00374             const uint8_t *obmc1= obmc + y*obmc_stride;
00375             const uint8_t *obmc2= obmc1+ (obmc_stride>>1);
00376             const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
00377             const uint8_t *obmc4= obmc3+ (obmc_stride>>1);
00378             for(x=0; x<b_w; x++){
00379                 int v=   obmc1[x] * block[3][x + y*src_stride]
00380                         +obmc2[x] * block[2][x + y*src_stride]
00381                         +obmc3[x] * block[1][x + y*src_stride]
00382                         +obmc4[x] * block[0][x + y*src_stride];
00383 
00384                 v <<= 8 - LOG2_OBMC_MAX;
00385                 if(FRAC_BITS != 8){
00386                     v >>= 8 - FRAC_BITS;
00387                 }
00388                 if(add){
00389                     v += dst[x + y*dst_stride];
00390                     v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS;
00391                     if(v&(~255)) v= ~(v>>31);
00392                     dst8[x + y*src_stride] = v;
00393                 }else{
00394                     dst[x + y*dst_stride] -= v;
00395                 }
00396             }
00397         }
00398     }
00399 }
00400 
00401 static av_always_inline void predict_slice(SnowContext *s, IDWTELEM *buf, int plane_index, int add, int mb_y){
00402     Plane *p= &s->plane[plane_index];
00403     const int mb_w= s->b_width  << s->block_max_depth;
00404     const int mb_h= s->b_height << s->block_max_depth;
00405     int x, y, mb_x;
00406     int block_size = MB_SIZE >> s->block_max_depth;
00407     int block_w    = plane_index ? block_size/2 : block_size;
00408     const uint8_t *obmc  = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth];
00409     const int obmc_stride= plane_index ? block_size : 2*block_size;
00410     int ref_stride= s->current_picture.linesize[plane_index];
00411     uint8_t *dst8= s->current_picture.data[plane_index];
00412     int w= p->width;
00413     int h= p->height;
00414 
00415     if(s->keyframe || (s->avctx->debug&512)){
00416         if(mb_y==mb_h)
00417             return;
00418 
00419         if(add){
00420             for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){
00421                 for(x=0; x<w; x++){
00422                     int v= buf[x + y*w] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1));
00423                     v >>= FRAC_BITS;
00424                     if(v&(~255)) v= ~(v>>31);
00425                     dst8[x + y*ref_stride]= v;
00426                 }
00427             }
00428         }else{
00429             for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){
00430                 for(x=0; x<w; x++){
00431                     buf[x + y*w]-= 128<<FRAC_BITS;
00432                 }
00433             }
00434         }
00435 
00436         return;
00437     }
00438 
00439     for(mb_x=0; mb_x<=mb_w; mb_x++){
00440         add_yblock(s, 0, NULL, buf, dst8, obmc,
00441                    block_w*mb_x - block_w/2,
00442                    block_w*mb_y - block_w/2,
00443                    block_w, block_w,
00444                    w, h,
00445                    w, ref_stride, obmc_stride,
00446                    mb_x - 1, mb_y - 1,
00447                    add, 1, plane_index);
00448     }
00449 }
00450 
00451 static av_always_inline void predict_plane(SnowContext *s, IDWTELEM *buf, int plane_index, int add){
00452     const int mb_h= s->b_height << s->block_max_depth;
00453     int mb_y;
00454     for(mb_y=0; mb_y<=mb_h; mb_y++)
00455         predict_slice(s, buf, plane_index, add, mb_y);
00456 }
00457 
00458 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){
00459     const int w= s->b_width << s->block_max_depth;
00460     const int rem_depth= s->block_max_depth - level;
00461     const int index= (x + y*w) << rem_depth;
00462     const int block_w= 1<<rem_depth;
00463     BlockNode block;
00464     int i,j;
00465 
00466     block.color[0]= l;
00467     block.color[1]= cb;
00468     block.color[2]= cr;
00469     block.mx= mx;
00470     block.my= my;
00471     block.ref= ref;
00472     block.type= type;
00473     block.level= level;
00474 
00475     for(j=0; j<block_w; j++){
00476         for(i=0; i<block_w; i++){
00477             s->block[index + i + j*w]= block;
00478         }
00479     }
00480 }
00481 
00482 static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){
00483     const int offset[3]= {
00484           y*c->  stride + x,
00485         ((y*c->uvstride + x)>>1),
00486         ((y*c->uvstride + x)>>1),
00487     };
00488     int i;
00489     for(i=0; i<3; i++){
00490         c->src[0][i]= src [i];
00491         c->ref[0][i]= ref [i] + offset[i];
00492     }
00493     assert(!ref_index);
00494 }
00495 
00496 
00497 /* bitstream functions */
00498 
00499 extern const int8_t quant3bA[256];
00500 
00501 #define QEXPSHIFT (7-FRAC_BITS+8) //FIXME try to change this to 0
00502 
00503 static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed){
00504     int i;
00505 
00506     if(v){
00507         const int a= FFABS(v);
00508         const int e= av_log2(a);
00509         const int el= FFMIN(e, 10);
00510         put_rac(c, state+0, 0);
00511 
00512         for(i=0; i<el; i++){
00513             put_rac(c, state+1+i, 1);  //1..10
00514         }
00515         for(; i<e; i++){
00516             put_rac(c, state+1+9, 1);  //1..10
00517         }
00518         put_rac(c, state+1+FFMIN(i,9), 0);
00519 
00520         for(i=e-1; i>=el; i--){
00521             put_rac(c, state+22+9, (a>>i)&1); //22..31
00522         }
00523         for(; i>=0; i--){
00524             put_rac(c, state+22+i, (a>>i)&1); //22..31
00525         }
00526 
00527         if(is_signed)
00528             put_rac(c, state+11 + el, v < 0); //11..21
00529     }else{
00530         put_rac(c, state+0, 1);
00531     }
00532 }
00533 
00534 static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){
00535     if(get_rac(c, state+0))
00536         return 0;
00537     else{
00538         int i, e, a;
00539         e= 0;
00540         while(get_rac(c, state+1 + FFMIN(e,9))){ //1..10
00541             e++;
00542         }
00543 
00544         a= 1;
00545         for(i=e-1; i>=0; i--){
00546             a += a + get_rac(c, state+22 + FFMIN(i,9)); //22..31
00547         }
00548 
00549         e= -(is_signed && get_rac(c, state+11 + FFMIN(e,10))); //11..21
00550         return (a^e)-e;
00551     }
00552 }
00553 
00554 static inline void put_symbol2(RangeCoder *c, uint8_t *state, int v, int log2){
00555     int i;
00556     int r= log2>=0 ? 1<<log2 : 1;
00557 
00558     assert(v>=0);
00559     assert(log2>=-4);
00560 
00561     while(v >= r){
00562         put_rac(c, state+4+log2, 1);
00563         v -= r;
00564         log2++;
00565         if(log2>0) r+=r;
00566     }
00567     put_rac(c, state+4+log2, 0);
00568 
00569     for(i=log2-1; i>=0; i--){
00570         put_rac(c, state+31-i, (v>>i)&1);
00571     }
00572 }
00573 
00574 static inline int get_symbol2(RangeCoder *c, uint8_t *state, int log2){
00575     int i;
00576     int r= log2>=0 ? 1<<log2 : 1;
00577     int v=0;
00578 
00579     assert(log2>=-4);
00580 
00581     while(get_rac(c, state+4+log2)){
00582         v+= r;
00583         log2++;
00584         if(log2>0) r+=r;
00585     }
00586 
00587     for(i=log2-1; i>=0; i--){
00588         v+= get_rac(c, state+31-i)<<i;
00589     }
00590 
00591     return v;
00592 }
00593 
00594 static inline void unpack_coeffs(SnowContext *s, SubBand *b, SubBand * parent, int orientation){
00595     const int w= b->width;
00596     const int h= b->height;
00597     int x,y;
00598 
00599     int run, runs;
00600     x_and_coeff *xc= b->x_coeff;
00601     x_and_coeff *prev_xc= NULL;
00602     x_and_coeff *prev2_xc= xc;
00603     x_and_coeff *parent_xc= parent ? parent->x_coeff : NULL;
00604     x_and_coeff *prev_parent_xc= parent_xc;
00605 
00606     runs= get_symbol2(&s->c, b->state[30], 0);
00607     if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3);
00608     else           run= INT_MAX;
00609 
00610     for(y=0; y<h; y++){
00611         int v=0;
00612         int lt=0, t=0, rt=0;
00613 
00614         if(y && prev_xc->x == 0){
00615             rt= prev_xc->coeff;
00616         }
00617         for(x=0; x<w; x++){
00618             int p=0;
00619             const int l= v;
00620 
00621             lt= t; t= rt;
00622 
00623             if(y){
00624                 if(prev_xc->x <= x)
00625                     prev_xc++;
00626                 if(prev_xc->x == x + 1)
00627                     rt= prev_xc->coeff;
00628                 else
00629                     rt=0;
00630             }
00631             if(parent_xc){
00632                 if(x>>1 > parent_xc->x){
00633                     parent_xc++;
00634                 }
00635                 if(x>>1 == parent_xc->x){
00636                     p= parent_xc->coeff;
00637                 }
00638             }
00639             if(/*ll|*/l|lt|t|rt|p){
00640                 int context= av_log2(/*FFABS(ll) + */3*(l>>1) + (lt>>1) + (t&~1) + (rt>>1) + (p>>1));
00641 
00642                 v=get_rac(&s->c, &b->state[0][context]);
00643                 if(v){
00644                     v= 2*(get_symbol2(&s->c, b->state[context + 2], context-4) + 1);
00645                     v+=get_rac(&s->c, &b->state[0][16 + 1 + 3 + quant3bA[l&0xFF] + 3*quant3bA[t&0xFF]]);
00646 
00647                     xc->x=x;
00648                     (xc++)->coeff= v;
00649                 }
00650             }else{
00651                 if(!run){
00652                     if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3);
00653                     else           run= INT_MAX;
00654                     v= 2*(get_symbol2(&s->c, b->state[0 + 2], 0-4) + 1);
00655                     v+=get_rac(&s->c, &b->state[0][16 + 1 + 3]);
00656 
00657                     xc->x=x;
00658                     (xc++)->coeff= v;
00659                 }else{
00660                     int max_run;
00661                     run--;
00662                     v=0;
00663 
00664                     if(y) max_run= FFMIN(run, prev_xc->x - x - 2);
00665                     else  max_run= FFMIN(run, w-x-1);
00666                     if(parent_xc)
00667                         max_run= FFMIN(max_run, 2*parent_xc->x - x - 1);
00668                     x+= max_run;
00669                     run-= max_run;
00670                 }
00671             }
00672         }
00673         (xc++)->x= w+1; //end marker
00674         prev_xc= prev2_xc;
00675         prev2_xc= xc;
00676 
00677         if(parent_xc){
00678             if(y&1){
00679                 while(parent_xc->x != parent->width+1)
00680                     parent_xc++;
00681                 parent_xc++;
00682                 prev_parent_xc= parent_xc;
00683             }else{
00684                 parent_xc= prev_parent_xc;
00685             }
00686         }
00687     }
00688 
00689     (xc++)->x= w+1; //end marker
00690 }
00691 
00692 #endif /* AVCODEC_SNOW_H */
Generated on Sun Apr 22 2012 21:54:04 for Libav by doxygen 1.7.1