comparison rv34.c @ 10117:d0f2f4e4436c libavcodec

Adjust r->avail_cache[] indexes to avoid alignment issues when zeroing block inside it.
author kostya
date Sun, 30 Aug 2009 06:16:33 +0000
parents 305536ce781f
children 4dafbd9c8918
comparison
equal deleted inserted replaced
10116:6cade2cdd63b 10117:d0f2f4e4436c
438 438
439 /** macroblock partition height in 8x8 blocks */ 439 /** macroblock partition height in 8x8 blocks */
440 static const uint8_t part_sizes_h[RV34_MB_TYPES] = { 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2 }; 440 static const uint8_t part_sizes_h[RV34_MB_TYPES] = { 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2 };
441 441
442 /** availability index for subblocks */ 442 /** availability index for subblocks */
443 static const uint8_t avail_indexes[4] = { 5, 6, 9, 10 }; 443 static const uint8_t avail_indexes[4] = { 6, 7, 10, 11 };
444 444
445 /** 445 /**
446 * motion vector prediction 446 * motion vector prediction
447 * 447 *
448 * Motion prediction performed for the block by using median prediction of 448 * Motion prediction performed for the block by using median prediction of
551 int type = cur_pic->mb_type[mb_pos]; 551 int type = cur_pic->mb_type[mb_pos];
552 552
553 memset(A, 0, sizeof(A)); 553 memset(A, 0, sizeof(A));
554 memset(B, 0, sizeof(B)); 554 memset(B, 0, sizeof(B));
555 memset(C, 0, sizeof(C)); 555 memset(C, 0, sizeof(C));
556 if((r->avail_cache[5-1] & type) & mask){ 556 if((r->avail_cache[6-1] & type) & mask){
557 A[0] = cur_pic->motion_val[dir][mv_pos - 1][0]; 557 A[0] = cur_pic->motion_val[dir][mv_pos - 1][0];
558 A[1] = cur_pic->motion_val[dir][mv_pos - 1][1]; 558 A[1] = cur_pic->motion_val[dir][mv_pos - 1][1];
559 has_A = 1; 559 has_A = 1;
560 } 560 }
561 if((r->avail_cache[5-4] & type) & mask){ 561 if((r->avail_cache[6-4] & type) & mask){
562 B[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride][0]; 562 B[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride][0];
563 B[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride][1]; 563 B[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride][1];
564 has_B = 1; 564 has_B = 1;
565 } 565 }
566 if(r->avail_cache[5-4] && (r->avail_cache[5-2] & type) & mask){ 566 if(r->avail_cache[6-4] && (r->avail_cache[6-2] & type) & mask){
567 C[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride + 2][0]; 567 C[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride + 2][0];
568 C[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride + 2][1]; 568 C[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride + 2][1];
569 has_C = 1; 569 has_C = 1;
570 }else if((s->mb_x+1) == s->mb_width && (r->avail_cache[5-5] & type) & mask){ 570 }else if((s->mb_x+1) == s->mb_width && (r->avail_cache[6-5] & type) & mask){
571 C[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride - 1][0]; 571 C[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride - 1][0];
572 C[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride - 1][1]; 572 C[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride - 1][1];
573 has_C = 1; 573 has_C = 1;
574 } 574 }
575 575
956 int itype; 956 int itype;
957 int avail[6*8] = {0}; 957 int avail[6*8] = {0};
958 int idx; 958 int idx;
959 959
960 // Set neighbour information. 960 // Set neighbour information.
961 if(r->avail_cache[0]) 961 if(r->avail_cache[1])
962 avail[0] = 1; 962 avail[0] = 1;
963 if(r->avail_cache[1]) 963 if(r->avail_cache[2])
964 avail[1] = avail[2] = 1; 964 avail[1] = avail[2] = 1;
965 if(r->avail_cache[2]) 965 if(r->avail_cache[3])
966 avail[3] = avail[4] = 1; 966 avail[3] = avail[4] = 1;
967 if(r->avail_cache[3]) 967 if(r->avail_cache[4])
968 avail[5] = 1; 968 avail[5] = 1;
969 if(r->avail_cache[4]) 969 if(r->avail_cache[5])
970 avail[8] = avail[16] = 1; 970 avail[8] = avail[16] = 1;
971 if(r->avail_cache[8]) 971 if(r->avail_cache[9])
972 avail[24] = avail[32] = 1; 972 avail[24] = avail[32] = 1;
973 973
974 Y = s->dest[0]; 974 Y = s->dest[0];
975 U = s->dest[1]; 975 U = s->dest[1];
976 V = s->dest[2]; 976 V = s->dest[2];
985 } 985 }
986 Y += s->linesize * 4 - 4*4; 986 Y += s->linesize * 4 - 4*4;
987 intra_types += r->intra_types_stride; 987 intra_types += r->intra_types_stride;
988 } 988 }
989 intra_types -= r->intra_types_stride * 4; 989 intra_types -= r->intra_types_stride * 4;
990 fill_rectangle(r->avail_cache + 5, 2, 2, 4, 0, 4); 990 fill_rectangle(r->avail_cache + 6, 2, 2, 4, 0, 4);
991 for(j = 0; j < 2; j++){ 991 for(j = 0; j < 2; j++){
992 idx = 5 + j*4; 992 idx = 6 + j*4;
993 for(i = 0; i < 2; i++, cbp >>= 1, idx++){ 993 for(i = 0; i < 2; i++, cbp >>= 1, idx++){
994 rv34_pred_4x4_block(r, U + i*4 + j*4*s->uvlinesize, s->uvlinesize, ittrans[intra_types[i*2+j*2*r->intra_types_stride]], r->avail_cache[idx-4], r->avail_cache[idx-1], !i && !j, r->avail_cache[idx-3]); 994 rv34_pred_4x4_block(r, U + i*4 + j*4*s->uvlinesize, s->uvlinesize, ittrans[intra_types[i*2+j*2*r->intra_types_stride]], r->avail_cache[idx-4], r->avail_cache[idx-1], !i && !j, r->avail_cache[idx-3]);
995 rv34_pred_4x4_block(r, V + i*4 + j*4*s->uvlinesize, s->uvlinesize, ittrans[intra_types[i*2+j*2*r->intra_types_stride]], r->avail_cache[idx-4], r->avail_cache[idx-1], !i && !j, r->avail_cache[idx-3]); 995 rv34_pred_4x4_block(r, V + i*4 + j*4*s->uvlinesize, s->uvlinesize, ittrans[intra_types[i*2+j*2*r->intra_types_stride]], r->avail_cache[idx-4], r->avail_cache[idx-1], !i && !j, r->avail_cache[idx-3]);
996 r->avail_cache[idx] = 1; 996 r->avail_cache[idx] = 1;
997 if(cbp & 0x01) 997 if(cbp & 0x01)
1000 rv34_add_4x4_block(V + i*4 + j*4*s->uvlinesize, s->uvlinesize, s->block[5], i*4+j*32); 1000 rv34_add_4x4_block(V + i*4 + j*4*s->uvlinesize, s->uvlinesize, s->block[5], i*4+j*32);
1001 } 1001 }
1002 } 1002 }
1003 }else{ 1003 }else{
1004 itype = ittrans16[intra_types[0]]; 1004 itype = ittrans16[intra_types[0]];
1005 itype = adjust_pred16(itype, r->avail_cache[5-4], r->avail_cache[5-1]); 1005 itype = adjust_pred16(itype, r->avail_cache[6-4], r->avail_cache[6-1]);
1006 r->h.pred16x16[itype](Y, s->linesize); 1006 r->h.pred16x16[itype](Y, s->linesize);
1007 dsp->add_pixels_clamped(s->block[0], Y, s->linesize); 1007 dsp->add_pixels_clamped(s->block[0], Y, s->linesize);
1008 dsp->add_pixels_clamped(s->block[1], Y + 8, s->linesize); 1008 dsp->add_pixels_clamped(s->block[1], Y + 8, s->linesize);
1009 Y += s->linesize * 8; 1009 Y += s->linesize * 8;
1010 dsp->add_pixels_clamped(s->block[2], Y, s->linesize); 1010 dsp->add_pixels_clamped(s->block[2], Y, s->linesize);
1011 dsp->add_pixels_clamped(s->block[3], Y + 8, s->linesize); 1011 dsp->add_pixels_clamped(s->block[3], Y + 8, s->linesize);
1012 1012
1013 itype = ittrans16[intra_types[0]]; 1013 itype = ittrans16[intra_types[0]];
1014 if(itype == PLANE_PRED8x8) itype = DC_PRED8x8; 1014 if(itype == PLANE_PRED8x8) itype = DC_PRED8x8;
1015 itype = adjust_pred16(itype, r->avail_cache[5-4], r->avail_cache[5-1]); 1015 itype = adjust_pred16(itype, r->avail_cache[6-4], r->avail_cache[6-1]);
1016 r->h.pred8x8[itype](U, s->uvlinesize); 1016 r->h.pred8x8[itype](U, s->uvlinesize);
1017 dsp->add_pixels_clamped(s->block[4], U, s->uvlinesize); 1017 dsp->add_pixels_clamped(s->block[4], U, s->uvlinesize);
1018 r->h.pred8x8[itype](V, s->uvlinesize); 1018 r->h.pred8x8[itype](V, s->uvlinesize);
1019 dsp->add_pixels_clamped(s->block[5], V, s->uvlinesize); 1019 dsp->add_pixels_clamped(s->block[5], V, s->uvlinesize);
1020 } 1020 }
1171 int dist; 1171 int dist;
1172 int mb_pos = s->mb_x + s->mb_y * s->mb_stride; 1172 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
1173 1173
1174 // Calculate which neighbours are available. Maybe it's worth optimizing too. 1174 // Calculate which neighbours are available. Maybe it's worth optimizing too.
1175 memset(r->avail_cache, 0, sizeof(r->avail_cache)); 1175 memset(r->avail_cache, 0, sizeof(r->avail_cache));
1176 fill_rectangle(r->avail_cache + 5, 2, 2, 4, 1, 4); 1176 fill_rectangle(r->avail_cache + 6, 2, 2, 4, 1, 4);
1177 dist = (s->mb_x - s->resync_mb_x) + (s->mb_y - s->resync_mb_y) * s->mb_width; 1177 dist = (s->mb_x - s->resync_mb_x) + (s->mb_y - s->resync_mb_y) * s->mb_width;
1178 if(s->mb_x && dist) 1178 if(s->mb_x && dist)
1179 r->avail_cache[4] = 1179 r->avail_cache[5] =
1180 r->avail_cache[8] = s->current_picture_ptr->mb_type[mb_pos - 1]; 1180 r->avail_cache[9] = s->current_picture_ptr->mb_type[mb_pos - 1];
1181 if(dist >= s->mb_width) 1181 if(dist >= s->mb_width)
1182 r->avail_cache[1] = 1182 r->avail_cache[2] =
1183 r->avail_cache[2] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride]; 1183 r->avail_cache[3] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride];
1184 if(((s->mb_x+1) < s->mb_width) && dist >= s->mb_width - 1) 1184 if(((s->mb_x+1) < s->mb_width) && dist >= s->mb_width - 1)
1185 r->avail_cache[3] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride + 1]; 1185 r->avail_cache[4] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride + 1];
1186 if(s->mb_x && dist > s->mb_width) 1186 if(s->mb_x && dist > s->mb_width)
1187 r->avail_cache[0] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride - 1]; 1187 r->avail_cache[1] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride - 1];
1188 1188
1189 s->qscale = r->si.quant; 1189 s->qscale = r->si.quant;
1190 cbp = cbp2 = rv34_decode_mb_header(r, intra_types); 1190 cbp = cbp2 = rv34_decode_mb_header(r, intra_types);
1191 r->cbp_luma [mb_pos] = cbp; 1191 r->cbp_luma [mb_pos] = cbp;
1192 r->cbp_chroma[mb_pos] = cbp >> 16; 1192 r->cbp_chroma[mb_pos] = cbp >> 16;