00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00050 #define BLOCK_INTRA 1
00051 #define BLOCK_OPT 2
00052
00053 uint8_t level;
00054 }BlockNode;
00055
00056 static const BlockNode null_block= {
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 + 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
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 DWTELEM *temp_dwt_buffer;
00136 IDWTELEM *spatial_idwt_buffer;
00137 IDWTELEM *temp_idwt_buffer;
00138 int *run_buffer;
00139 int colorspace_type;
00140 int chroma_h_shift;
00141 int chroma_v_shift;
00142 int spatial_scalability;
00143 int qlog;
00144 int last_qlog;
00145 int lambda;
00146 int lambda2;
00147 int pass1_rc;
00148 int mv_scale;
00149 int last_mv_scale;
00150 int qbias;
00151 int last_qbias;
00152 #define QBIAS_SHIFT 3
00153 int b_width;
00154 int b_height;
00155 int block_max_depth;
00156 int last_block_max_depth;
00157 Plane plane[MAX_PLANES];
00158 BlockNode *block;
00159 #define ME_CACHE_SIZE 1024
00160 unsigned me_cache[ME_CACHE_SIZE];
00161 unsigned me_cache_generation;
00162 slice_buffer sb;
00163 int memc_only;
00164 int no_bitstream;
00165
00166 MpegEncContext m;
00167
00168 uint8_t *scratchbuf;
00169 uint8_t *emu_edge_buffer;
00170 }SnowContext;
00171
00172
00173 extern const uint8_t * const ff_obmc_tab[4];
00174 extern uint8_t ff_qexp[QROOT];
00175 extern int ff_scale_mv_ref[MAX_REF_FRAMES][MAX_REF_FRAMES];
00176
00177
00178
00179 static av_always_inline void snow_interleave_line_header(int * i, int width, IDWTELEM * low, IDWTELEM * high){
00180 (*i) = (width) - 2;
00181
00182 if (width & 1){
00183 low[(*i)+1] = low[((*i)+1)>>1];
00184 (*i)--;
00185 }
00186 }
00187
00188 static av_always_inline void snow_interleave_line_footer(int * i, IDWTELEM * low, IDWTELEM * high){
00189 for (; (*i)>=0; (*i)-=2){
00190 low[(*i)+1] = high[(*i)>>1];
00191 low[*i] = low[(*i)>>1];
00192 }
00193 }
00194
00195 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){
00196 for(; i<w; i++){
00197 dst[i] = src[i] - ((mul * (ref[i] + ref[i + 1]) + add) >> shift);
00198 }
00199
00200 if((width^lift_high)&1){
00201 dst[w] = src[w] - ((mul * 2 * ref[w] + add) >> shift);
00202 }
00203 }
00204
00205 static av_always_inline void snow_horizontal_compose_liftS_lead_out(int i, IDWTELEM * dst, IDWTELEM * src, IDWTELEM * ref, int width, int w){
00206 for(; i<w; i++){
00207 dst[i] = src[i] + ((ref[i] + ref[(i+1)]+W_BO + 4 * src[i]) >> W_BS);
00208 }
00209
00210 if(width&1){
00211 dst[w] = src[w] + ((2 * ref[w] + W_BO + 4 * src[w]) >> W_BS);
00212 }
00213 }
00214
00215
00216
00217 int ff_snow_common_init(AVCodecContext *avctx);
00218 int ff_snow_common_init_after_header(AVCodecContext *avctx);
00219 void ff_snow_common_end(SnowContext *s);
00220 void ff_snow_release_buffer(AVCodecContext *avctx);
00221 void ff_snow_reset_contexts(SnowContext *s);
00222 int ff_snow_alloc_blocks(SnowContext *s);
00223 int ff_snow_frame_start(SnowContext *s);
00224 void ff_snow_pred_block(SnowContext *s, uint8_t *dst, uint8_t *tmp, int stride,
00225 int sx, int sy, int b_w, int b_h, BlockNode *block,
00226 int plane_index, int w, int h);
00227
00228
00229
00230 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){
00231 const int w= s->b_width << s->block_max_depth;
00232 const int rem_depth= s->block_max_depth - level;
00233 const int index= (x + y*w) << rem_depth;
00234 const int block_w= 1<<rem_depth;
00235 BlockNode block;
00236 int i,j;
00237
00238 block.color[0]= l;
00239 block.color[1]= cb;
00240 block.color[2]= cr;
00241 block.mx= mx;
00242 block.my= my;
00243 block.ref= ref;
00244 block.type= type;
00245 block.level= level;
00246
00247 for(j=0; j<block_w; j++){
00248 for(i=0; i<block_w; i++){
00249 s->block[index + i + j*w]= block;
00250 }
00251 }
00252 }
00253
00254 static inline void pred_mv(SnowContext *s, int *mx, int *my, int ref,
00255 const BlockNode *left, const BlockNode *top, const BlockNode *tr){
00256 if(s->ref_frames == 1){
00257 *mx = mid_pred(left->mx, top->mx, tr->mx);
00258 *my = mid_pred(left->my, top->my, tr->my);
00259 }else{
00260 const int *scale = ff_scale_mv_ref[ref];
00261 *mx = mid_pred((left->mx * scale[left->ref] + 128) >>8,
00262 (top ->mx * scale[top ->ref] + 128) >>8,
00263 (tr ->mx * scale[tr ->ref] + 128) >>8);
00264 *my = mid_pred((left->my * scale[left->ref] + 128) >>8,
00265 (top ->my * scale[top ->ref] + 128) >>8,
00266 (tr ->my * scale[tr ->ref] + 128) >>8);
00267 }
00268 }
00269
00270 static av_always_inline int same_block(BlockNode *a, BlockNode *b){
00271 if((a->type&BLOCK_INTRA) && (b->type&BLOCK_INTRA)){
00272 return !((a->color[0] - b->color[0]) | (a->color[1] - b->color[1]) | (a->color[2] - b->color[2]));
00273 }else{
00274 return !((a->mx - b->mx) | (a->my - b->my) | (a->ref - b->ref) | ((a->type ^ b->type)&BLOCK_INTRA));
00275 }
00276 }
00277
00278
00279
00280 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){
00281 const int b_width = s->b_width << s->block_max_depth;
00282 const int b_height= s->b_height << s->block_max_depth;
00283 const int b_stride= b_width;
00284 BlockNode *lt= &s->block[b_x + b_y*b_stride];
00285 BlockNode *rt= lt+1;
00286 BlockNode *lb= lt+b_stride;
00287 BlockNode *rb= lb+1;
00288 uint8_t *block[4];
00289 int tmp_step= src_stride >= 7*MB_SIZE ? MB_SIZE : MB_SIZE*src_stride;
00290 uint8_t *tmp = s->scratchbuf;
00291 uint8_t *ptmp;
00292 int x,y;
00293
00294 if(b_x<0){
00295 lt= rt;
00296 lb= rb;
00297 }else if(b_x + 1 >= b_width){
00298 rt= lt;
00299 rb= lb;
00300 }
00301 if(b_y<0){
00302 lt= lb;
00303 rt= rb;
00304 }else if(b_y + 1 >= b_height){
00305 lb= lt;
00306 rb= rt;
00307 }
00308
00309 if(src_x<0){
00310 obmc -= src_x;
00311 b_w += src_x;
00312 if(!sliced && !offset_dst)
00313 dst -= src_x;
00314 src_x=0;
00315 }else if(src_x + b_w > w){
00316 b_w = w - src_x;
00317 }
00318 if(src_y<0){
00319 obmc -= src_y*obmc_stride;
00320 b_h += src_y;
00321 if(!sliced && !offset_dst)
00322 dst -= src_y*dst_stride;
00323 src_y=0;
00324 }else if(src_y + b_h> h){
00325 b_h = h - src_y;
00326 }
00327
00328 if(b_w<=0 || b_h<=0) return;
00329
00330 av_assert2(src_stride > 2*MB_SIZE + 5);
00331
00332 if(!sliced && offset_dst)
00333 dst += src_x + src_y*dst_stride;
00334 dst8+= src_x + src_y*src_stride;
00335
00336
00337 ptmp= tmp + 3*tmp_step;
00338 block[0]= ptmp;
00339 ptmp+=tmp_step;
00340 ff_snow_pred_block(s, block[0], tmp, src_stride, src_x, src_y, b_w, b_h, lt, plane_index, w, h);
00341
00342 if(same_block(lt, rt)){
00343 block[1]= block[0];
00344 }else{
00345 block[1]= ptmp;
00346 ptmp+=tmp_step;
00347 ff_snow_pred_block(s, block[1], tmp, src_stride, src_x, src_y, b_w, b_h, rt, plane_index, w, h);
00348 }
00349
00350 if(same_block(lt, lb)){
00351 block[2]= block[0];
00352 }else if(same_block(rt, lb)){
00353 block[2]= block[1];
00354 }else{
00355 block[2]= ptmp;
00356 ptmp+=tmp_step;
00357 ff_snow_pred_block(s, block[2], tmp, src_stride, src_x, src_y, b_w, b_h, lb, plane_index, w, h);
00358 }
00359
00360 if(same_block(lt, rb) ){
00361 block[3]= block[0];
00362 }else if(same_block(rt, rb)){
00363 block[3]= block[1];
00364 }else if(same_block(lb, rb)){
00365 block[3]= block[2];
00366 }else{
00367 block[3]= ptmp;
00368 ff_snow_pred_block(s, block[3], tmp, src_stride, src_x, src_y, b_w, b_h, rb, plane_index, w, h);
00369 }
00370 if(sliced){
00371 s->dwt.inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8);
00372 }else{
00373 for(y=0; y<b_h; y++){
00374
00375 const uint8_t *obmc1= obmc + y*obmc_stride;
00376 const uint8_t *obmc2= obmc1+ (obmc_stride>>1);
00377 const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
00378 const uint8_t *obmc4= obmc3+ (obmc_stride>>1);
00379 for(x=0; x<b_w; x++){
00380 int v= obmc1[x] * block[3][x + y*src_stride]
00381 +obmc2[x] * block[2][x + y*src_stride]
00382 +obmc3[x] * block[1][x + y*src_stride]
00383 +obmc4[x] * block[0][x + y*src_stride];
00384
00385 v <<= 8 - LOG2_OBMC_MAX;
00386 if(FRAC_BITS != 8){
00387 v >>= 8 - FRAC_BITS;
00388 }
00389 if(add){
00390 v += dst[x + y*dst_stride];
00391 v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS;
00392 if(v&(~255)) v= ~(v>>31);
00393 dst8[x + y*src_stride] = v;
00394 }else{
00395 dst[x + y*dst_stride] -= v;
00396 }
00397 }
00398 }
00399 }
00400 }
00401
00402 static av_always_inline void predict_slice(SnowContext *s, IDWTELEM *buf, int plane_index, int add, int mb_y){
00403 Plane *p= &s->plane[plane_index];
00404 const int mb_w= s->b_width << s->block_max_depth;
00405 const int mb_h= s->b_height << s->block_max_depth;
00406 int x, y, mb_x;
00407 int block_size = MB_SIZE >> s->block_max_depth;
00408 int block_w = plane_index ? block_size>>s->chroma_h_shift : block_size;
00409 int block_h = plane_index ? block_size>>s->chroma_v_shift : block_size;
00410 const uint8_t *obmc = plane_index ? ff_obmc_tab[s->block_max_depth+s->chroma_h_shift] : ff_obmc_tab[s->block_max_depth];
00411 const int obmc_stride= plane_index ? (2*block_size)>>s->chroma_h_shift : 2*block_size;
00412 int ref_stride= s->current_picture.linesize[plane_index];
00413 uint8_t *dst8= s->current_picture.data[plane_index];
00414 int w= p->width;
00415 int h= p->height;
00416 av_assert2(s->chroma_h_shift == s->chroma_v_shift);
00417 if(s->keyframe || (s->avctx->debug&512)){
00418 if(mb_y==mb_h)
00419 return;
00420
00421 if(add){
00422 for(y=block_h*mb_y; y<FFMIN(h,block_h*(mb_y+1)); y++){
00423 for(x=0; x<w; x++){
00424 int v= buf[x + y*w] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1));
00425 v >>= FRAC_BITS;
00426 if(v&(~255)) v= ~(v>>31);
00427 dst8[x + y*ref_stride]= v;
00428 }
00429 }
00430 }else{
00431 for(y=block_h*mb_y; y<FFMIN(h,block_h*(mb_y+1)); y++){
00432 for(x=0; x<w; x++){
00433 buf[x + y*w]-= 128<<FRAC_BITS;
00434 }
00435 }
00436 }
00437
00438 return;
00439 }
00440
00441 for(mb_x=0; mb_x<=mb_w; mb_x++){
00442 add_yblock(s, 0, NULL, buf, dst8, obmc,
00443 block_w*mb_x - block_w/2,
00444 block_h*mb_y - block_h/2,
00445 block_w, block_h,
00446 w, h,
00447 w, ref_stride, obmc_stride,
00448 mb_x - 1, mb_y - 1,
00449 add, 1, plane_index);
00450 }
00451 }
00452
00453 static av_always_inline void predict_plane(SnowContext *s, IDWTELEM *buf, int plane_index, int add){
00454 const int mb_h= s->b_height << s->block_max_depth;
00455 int mb_y;
00456 for(mb_y=0; mb_y<=mb_h; mb_y++)
00457 predict_slice(s, buf, plane_index, add, mb_y);
00458 }
00459
00460 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){
00461 const int w= s->b_width << s->block_max_depth;
00462 const int rem_depth= s->block_max_depth - level;
00463 const int index= (x + y*w) << rem_depth;
00464 const int block_w= 1<<rem_depth;
00465 const int block_h= 1<<rem_depth;
00466 BlockNode block;
00467 int i,j;
00468
00469 block.color[0]= l;
00470 block.color[1]= cb;
00471 block.color[2]= cr;
00472 block.mx= mx;
00473 block.my= my;
00474 block.ref= ref;
00475 block.type= type;
00476 block.level= level;
00477
00478 for(j=0; j<block_h; j++){
00479 for(i=0; i<block_w; i++){
00480 s->block[index + i + j*w]= block;
00481 }
00482 }
00483 }
00484
00485 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){
00486 SnowContext *s = c->avctx->priv_data;
00487 const int offset[3]= {
00488 y*c-> stride + x,
00489 ((y*c->uvstride + x)>>s->chroma_h_shift),
00490 ((y*c->uvstride + x)>>s->chroma_h_shift),
00491 };
00492 int i;
00493 for(i=0; i<3; i++){
00494 c->src[0][i]= src [i];
00495 c->ref[0][i]= ref [i] + offset[i];
00496 }
00497 av_assert2(!ref_index);
00498 }
00499
00500
00501
00502
00503 extern const int8_t ff_quant3bA[256];
00504
00505 #define QEXPSHIFT (7-FRAC_BITS+8) //FIXME try to change this to 0
00506
00507 static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed){
00508 int i;
00509
00510 if(v){
00511 const int a= FFABS(v);
00512 const int e= av_log2(a);
00513 const int el= FFMIN(e, 10);
00514 put_rac(c, state+0, 0);
00515
00516 for(i=0; i<el; i++){
00517 put_rac(c, state+1+i, 1);
00518 }
00519 for(; i<e; i++){
00520 put_rac(c, state+1+9, 1);
00521 }
00522 put_rac(c, state+1+FFMIN(i,9), 0);
00523
00524 for(i=e-1; i>=el; i--){
00525 put_rac(c, state+22+9, (a>>i)&1);
00526 }
00527 for(; i>=0; i--){
00528 put_rac(c, state+22+i, (a>>i)&1);
00529 }
00530
00531 if(is_signed)
00532 put_rac(c, state+11 + el, v < 0);
00533 }else{
00534 put_rac(c, state+0, 1);
00535 }
00536 }
00537
00538 static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){
00539 if(get_rac(c, state+0))
00540 return 0;
00541 else{
00542 int i, e, a;
00543 e= 0;
00544 while(get_rac(c, state+1 + FFMIN(e,9))){
00545 e++;
00546 }
00547
00548 a= 1;
00549 for(i=e-1; i>=0; i--){
00550 a += a + get_rac(c, state+22 + FFMIN(i,9));
00551 }
00552
00553 e= -(is_signed && get_rac(c, state+11 + FFMIN(e,10)));
00554 return (a^e)-e;
00555 }
00556 }
00557
00558 static inline void put_symbol2(RangeCoder *c, uint8_t *state, int v, int log2){
00559 int i;
00560 int r= log2>=0 ? 1<<log2 : 1;
00561
00562 av_assert2(v>=0);
00563 av_assert2(log2>=-4);
00564
00565 while(v >= r){
00566 put_rac(c, state+4+log2, 1);
00567 v -= r;
00568 log2++;
00569 if(log2>0) r+=r;
00570 }
00571 put_rac(c, state+4+log2, 0);
00572
00573 for(i=log2-1; i>=0; i--){
00574 put_rac(c, state+31-i, (v>>i)&1);
00575 }
00576 }
00577
00578 static inline int get_symbol2(RangeCoder *c, uint8_t *state, int log2){
00579 int i;
00580 int r= log2>=0 ? 1<<log2 : 1;
00581 int v=0;
00582
00583 av_assert2(log2>=-4);
00584
00585 while(log2<28 && get_rac(c, state+4+log2)){
00586 v+= r;
00587 log2++;
00588 if(log2>0) r+=r;
00589 }
00590
00591 for(i=log2-1; i>=0; i--){
00592 v+= get_rac(c, state+31-i)<<i;
00593 }
00594
00595 return v;
00596 }
00597
00598 static inline void unpack_coeffs(SnowContext *s, SubBand *b, SubBand * parent, int orientation){
00599 const int w= b->width;
00600 const int h= b->height;
00601 int x,y;
00602
00603 int run, runs;
00604 x_and_coeff *xc= b->x_coeff;
00605 x_and_coeff *prev_xc= NULL;
00606 x_and_coeff *prev2_xc= xc;
00607 x_and_coeff *parent_xc= parent ? parent->x_coeff : NULL;
00608 x_and_coeff *prev_parent_xc= parent_xc;
00609
00610 runs= get_symbol2(&s->c, b->state[30], 0);
00611 if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3);
00612 else run= INT_MAX;
00613
00614 for(y=0; y<h; y++){
00615 int v=0;
00616 int lt=0, t=0, rt=0;
00617
00618 if(y && prev_xc->x == 0){
00619 rt= prev_xc->coeff;
00620 }
00621 for(x=0; x<w; x++){
00622 int p=0;
00623 const int l= v;
00624
00625 lt= t; t= rt;
00626
00627 if(y){
00628 if(prev_xc->x <= x)
00629 prev_xc++;
00630 if(prev_xc->x == x + 1)
00631 rt= prev_xc->coeff;
00632 else
00633 rt=0;
00634 }
00635 if(parent_xc){
00636 if(x>>1 > parent_xc->x){
00637 parent_xc++;
00638 }
00639 if(x>>1 == parent_xc->x){
00640 p= parent_xc->coeff;
00641 }
00642 }
00643 if(l|lt|t|rt|p){
00644 int context= av_log2(3*(l>>1) + (lt>>1) + (t&~1) + (rt>>1) + (p>>1));
00645
00646 v=get_rac(&s->c, &b->state[0][context]);
00647 if(v){
00648 v= 2*(get_symbol2(&s->c, b->state[context + 2], context-4) + 1);
00649 v+=get_rac(&s->c, &b->state[0][16 + 1 + 3 + ff_quant3bA[l&0xFF] + 3*ff_quant3bA[t&0xFF]]);
00650
00651 xc->x=x;
00652 (xc++)->coeff= v;
00653 }
00654 }else{
00655 if(!run){
00656 if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3);
00657 else run= INT_MAX;
00658 v= 2*(get_symbol2(&s->c, b->state[0 + 2], 0-4) + 1);
00659 v+=get_rac(&s->c, &b->state[0][16 + 1 + 3]);
00660
00661 xc->x=x;
00662 (xc++)->coeff= v;
00663 }else{
00664 int max_run;
00665 run--;
00666 v=0;
00667 av_assert2(run >= 0);
00668 if(y) max_run= FFMIN(run, prev_xc->x - x - 2);
00669 else max_run= FFMIN(run, w-x-1);
00670 if(parent_xc)
00671 max_run= FFMIN(max_run, 2*parent_xc->x - x - 1);
00672 av_assert2(max_run >= 0 && max_run <= run);
00673
00674 x+= max_run;
00675 run-= max_run;
00676 }
00677 }
00678 }
00679 (xc++)->x= w+1;
00680 prev_xc= prev2_xc;
00681 prev2_xc= xc;
00682
00683 if(parent_xc){
00684 if(y&1){
00685 while(parent_xc->x != parent->width+1)
00686 parent_xc++;
00687 parent_xc++;
00688 prev_parent_xc= parent_xc;
00689 }else{
00690 parent_xc= prev_parent_xc;
00691 }
00692 }
00693 }
00694
00695 (xc++)->x= w+1;
00696 }
00697
00698 #endif