comparison error_resilience.c @ 1064:b32afefe7d33 libavcodec

* UINTX -> uintx_t INTX -> intx_t
author kabi
date Tue, 11 Feb 2003 16:35:48 +0000
parents 06776293eabb
children 1e39f273ecd6
comparison
equal deleted inserted replaced
1063:fdeac9642346 1064:b32afefe7d33
52 dest_cr[x + y*(s->uvlinesize)]= dcv/8; 52 dest_cr[x + y*(s->uvlinesize)]= dcv/8;
53 } 53 }
54 } 54 }
55 } 55 }
56 56
57 static void filter181(INT16 *data, int width, int height, int stride){ 57 static void filter181(int16_t *data, int width, int height, int stride){
58 int x,y; 58 int x,y;
59 59
60 /* horizontal filter */ 60 /* horizontal filter */
61 for(y=1; y<height-1; y++){ 61 for(y=1; y<height-1; y++){
62 int prev_dc= data[0 + y*stride]; 62 int prev_dc= data[0 + y*stride];
93 /** 93 /**
94 * guess the dc of blocks which dont have a undamaged dc 94 * guess the dc of blocks which dont have a undamaged dc
95 * @param w width in 8 pixel blocks 95 * @param w width in 8 pixel blocks
96 * @param h height in 8 pixel blocks 96 * @param h height in 8 pixel blocks
97 */ 97 */
98 static void guess_dc(MpegEncContext *s, INT16 *dc, int w, int h, int stride, int is_luma){ 98 static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, int is_luma){
99 int b_x, b_y; 99 int b_x, b_y;
100 100
101 for(b_y=0; b_y<h; b_y++){ 101 for(b_y=0; b_y<h; b_y++){
102 for(b_x=0; b_x<w; b_x++){ 102 for(b_x=0; b_x<w; b_x++){
103 int color[4]={1024,1024,1024,1024}; 103 int color[4]={1024,1024,1024,1024};
104 int distance[4]={9999,9999,9999,9999}; 104 int distance[4]={9999,9999,9999,9999};
105 int mb_index, error, j; 105 int mb_index, error, j;
106 INT64 guess, weight_sum; 106 int64_t guess, weight_sum;
107 107
108 mb_index= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_width; 108 mb_index= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_width;
109 109
110 error= s->error_status_table[mb_index]; 110 error= s->error_status_table[mb_index];
111 111
161 } 161 }
162 162
163 weight_sum=0; 163 weight_sum=0;
164 guess=0; 164 guess=0;
165 for(j=0; j<4; j++){ 165 for(j=0; j<4; j++){
166 INT64 weight= 256*256*256*16/distance[j]; 166 int64_t weight= 256*256*256*16/distance[j];
167 guess+= weight*(INT64)color[j]; 167 guess+= weight*(int64_t)color[j];
168 weight_sum+= weight; 168 weight_sum+= weight;
169 } 169 }
170 guess= (guess + weight_sum/2) / weight_sum; 170 guess= (guess + weight_sum/2) / weight_sum;
171 171
172 dc[b_x + b_y*stride]= guess; 172 dc[b_x + b_y*stride]= guess;
177 /** 177 /**
178 * simple horizontal deblocking filter used for error resilience 178 * simple horizontal deblocking filter used for error resilience
179 * @param w width in 8 pixel blocks 179 * @param w width in 8 pixel blocks
180 * @param h height in 8 pixel blocks 180 * @param h height in 8 pixel blocks
181 */ 181 */
182 static void h_block_filter(MpegEncContext *s, UINT8 *dst, int w, int h, int stride, int is_luma){ 182 static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){
183 int b_x, b_y; 183 int b_x, b_y;
184 UINT8 *cm = cropTbl + MAX_NEG_CROP; 184 uint8_t *cm = cropTbl + MAX_NEG_CROP;
185 185
186 for(b_y=0; b_y<h; b_y++){ 186 for(b_y=0; b_y<h; b_y++){
187 for(b_x=0; b_x<w-1; b_x++){ 187 for(b_x=0; b_x<w-1; b_x++){
188 int y; 188 int y;
189 int left_status = s->error_status_table[( b_x >>is_luma) + (b_y>>is_luma)*s->mb_width]; 189 int left_status = s->error_status_table[( b_x >>is_luma) + (b_y>>is_luma)*s->mb_width];
191 int left_intra= s->mb_type [( b_x >>is_luma) + (b_y>>is_luma)*s->mb_width]&MB_TYPE_INTRA; 191 int left_intra= s->mb_type [( b_x >>is_luma) + (b_y>>is_luma)*s->mb_width]&MB_TYPE_INTRA;
192 int right_intra= s->mb_type [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_width]&MB_TYPE_INTRA; 192 int right_intra= s->mb_type [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_width]&MB_TYPE_INTRA;
193 int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR); 193 int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR);
194 int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR); 194 int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR);
195 int offset= b_x*8 + b_y*stride*8; 195 int offset= b_x*8 + b_y*stride*8;
196 INT16 *left_mv= s->motion_val[s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ( b_x <<(1-is_luma))]; 196 int16_t *left_mv= s->motion_val[s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ( b_x <<(1-is_luma))];
197 INT16 *right_mv= s->motion_val[s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ((b_x+1)<<(1-is_luma))]; 197 int16_t *right_mv= s->motion_val[s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ((b_x+1)<<(1-is_luma))];
198 198
199 if(!(left_damage||right_damage)) continue; // both undamaged 199 if(!(left_damage||right_damage)) continue; // both undamaged
200 200
201 if( (!left_intra) && (!right_intra) 201 if( (!left_intra) && (!right_intra)
202 && ABS(left_mv[0]-right_mv[0]) + ABS(left_mv[1]+right_mv[1]) < 2) continue; 202 && ABS(left_mv[0]-right_mv[0]) + ABS(left_mv[1]+right_mv[1]) < 2) continue;
237 /** 237 /**
238 * simple vertical deblocking filter used for error resilience 238 * simple vertical deblocking filter used for error resilience
239 * @param w width in 8 pixel blocks 239 * @param w width in 8 pixel blocks
240 * @param h height in 8 pixel blocks 240 * @param h height in 8 pixel blocks
241 */ 241 */
242 static void v_block_filter(MpegEncContext *s, UINT8 *dst, int w, int h, int stride, int is_luma){ 242 static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){
243 int b_x, b_y; 243 int b_x, b_y;
244 UINT8 *cm = cropTbl + MAX_NEG_CROP; 244 uint8_t *cm = cropTbl + MAX_NEG_CROP;
245 245
246 for(b_y=0; b_y<h-1; b_y++){ 246 for(b_y=0; b_y<h-1; b_y++){
247 for(b_x=0; b_x<w; b_x++){ 247 for(b_x=0; b_x<w; b_x++){
248 int x; 248 int x;
249 int top_status = s->error_status_table[(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_width]; 249 int top_status = s->error_status_table[(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_width];
251 int top_intra= s->mb_type [(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_width]&MB_TYPE_INTRA; 251 int top_intra= s->mb_type [(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_width]&MB_TYPE_INTRA;
252 int bottom_intra= s->mb_type [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_width]&MB_TYPE_INTRA; 252 int bottom_intra= s->mb_type [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_width]&MB_TYPE_INTRA;
253 int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR); 253 int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR);
254 int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR); 254 int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR);
255 int offset= b_x*8 + b_y*stride*8; 255 int offset= b_x*8 + b_y*stride*8;
256 INT16 *top_mv= s->motion_val[s->block_wrap[0]*(( b_y <<(1-is_luma)) + 1) + (b_x<<(1-is_luma))]; 256 int16_t *top_mv= s->motion_val[s->block_wrap[0]*(( b_y <<(1-is_luma)) + 1) + (b_x<<(1-is_luma))];
257 INT16 *bottom_mv= s->motion_val[s->block_wrap[0]*(((b_y+1)<<(1-is_luma)) + 1) + (b_x<<(1-is_luma))]; 257 int16_t *bottom_mv= s->motion_val[s->block_wrap[0]*(((b_y+1)<<(1-is_luma)) + 1) + (b_x<<(1-is_luma))];
258 258
259 if(!(top_damage||bottom_damage)) continue; // both undamaged 259 if(!(top_damage||bottom_damage)) continue; // both undamaged
260 260
261 if( (!top_intra) && (!bottom_intra) 261 if( (!top_intra) && (!bottom_intra)
262 && ABS(top_mv[0]-bottom_mv[0]) + ABS(top_mv[1]+bottom_mv[1]) < 2) continue; 262 && ABS(top_mv[0]-bottom_mv[0]) + ABS(top_mv[1]+bottom_mv[1]) < 2) continue;
293 } 293 }
294 } 294 }
295 } 295 }
296 296
297 static void guess_mv(MpegEncContext *s){ 297 static void guess_mv(MpegEncContext *s){
298 UINT8 fixed[s->mb_num]; 298 uint8_t fixed[s->mb_num];
299 #define MV_FROZEN 3 299 #define MV_FROZEN 3
300 #define MV_CHANGED 2 300 #define MV_CHANGED 2
301 #define MV_UNCHANGED 1 301 #define MV_UNCHANGED 1
302 const int mb_width = s->mb_width; 302 const int mb_width = s->mb_width;
303 const int mb_height= s->mb_height; 303 const int mb_height= s->mb_height;
462 462
463 s->mb_x= mb_x; 463 s->mb_x= mb_x;
464 s->mb_y= mb_y; 464 s->mb_y= mb_y;
465 for(j=0; j<pred_count; j++){ 465 for(j=0; j<pred_count; j++){
466 int score=0; 466 int score=0;
467 UINT8 *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize; 467 uint8_t *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
468 468
469 s->motion_val[mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0]; 469 s->motion_val[mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0];
470 s->motion_val[mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1]; 470 s->motion_val[mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1];
471 MPV_decode_mb(s, s->block); 471 MPV_decode_mb(s, s->block);
472 472
556 556
557 j++; 557 j++;
558 if((j%skip_amount) != 0) continue; //skip a few to speed things up 558 if((j%skip_amount) != 0) continue; //skip a few to speed things up
559 559
560 if(s->pict_type==I_TYPE){ 560 if(s->pict_type==I_TYPE){
561 UINT8 *mb_ptr = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize; 561 uint8_t *mb_ptr = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
562 UINT8 *last_mb_ptr= s->last_picture.data [0] + mb_x*16 + mb_y*16*s->linesize; 562 uint8_t *last_mb_ptr= s->last_picture.data [0] + mb_x*16 + mb_y*16*s->linesize;
563 563
564 is_intra_likely += s->dsp.pix_abs16x16(last_mb_ptr, mb_ptr , s->linesize); 564 is_intra_likely += s->dsp.pix_abs16x16(last_mb_ptr, mb_ptr , s->linesize);
565 is_intra_likely -= s->dsp.pix_abs16x16(last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize); 565 is_intra_likely -= s->dsp.pix_abs16x16(last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize);
566 }else{ 566 }else{
567 if(s->mbintra_table[i]) //HACK (this is allways inited but we should use mb_type[]) 567 if(s->mbintra_table[i]) //HACK (this is allways inited but we should use mb_type[])
793 /* fill DC for inter blocks */ 793 /* fill DC for inter blocks */
794 i= -1; 794 i= -1;
795 for(mb_y=0; mb_y<s->mb_height; mb_y++){ 795 for(mb_y=0; mb_y<s->mb_height; mb_y++){
796 for(mb_x=0; mb_x<s->mb_width; mb_x++){ 796 for(mb_x=0; mb_x<s->mb_width; mb_x++){
797 int dc, dcu, dcv, y, n; 797 int dc, dcu, dcv, y, n;
798 INT16 *dc_ptr; 798 int16_t *dc_ptr;
799 UINT8 *dest_y, *dest_cb, *dest_cr; 799 uint8_t *dest_y, *dest_cb, *dest_cr;
800 800
801 i++; 801 i++;
802 error= s->error_status_table[i]; 802 error= s->error_status_table[i];
803 803
804 if(s->mb_type[i]&MB_TYPE_INTRA) continue; //intra 804 if(s->mb_type[i]&MB_TYPE_INTRA) continue; //intra
844 #if 1 844 #if 1
845 /* render DC only intra */ 845 /* render DC only intra */
846 i= -1; 846 i= -1;
847 for(mb_y=0; mb_y<s->mb_height; mb_y++){ 847 for(mb_y=0; mb_y<s->mb_height; mb_y++){
848 for(mb_x=0; mb_x<s->mb_width; mb_x++){ 848 for(mb_x=0; mb_x<s->mb_width; mb_x++){
849 UINT8 *dest_y, *dest_cb, *dest_cr; 849 uint8_t *dest_y, *dest_cb, *dest_cr;
850 850
851 i++; 851 i++;
852 error= s->error_status_table[i]; 852 error= s->error_status_table[i];
853 853
854 if(!(s->mb_type[i]&MB_TYPE_INTRA)) continue; //inter 854 if(!(s->mb_type[i]&MB_TYPE_INTRA)) continue; //inter