comparison mpegvideo.c @ 582:5132a4ee50cd libavcodec

different edge positions fixed with edge emu / dr1
author michaelni
date Thu, 25 Jul 2002 20:22:36 +0000
parents 23eee7d73c4b
children 9e271424160f
comparison
equal deleted inserted replaced
581:8adda0af04e2 582:5132a4ee50cd
143 else 143 else
144 s->dct_unquantize = s->dct_unquantize_mpeg1; 144 s->dct_unquantize = s->dct_unquantize_mpeg1;
145 145
146 s->mb_width = (s->width + 15) / 16; 146 s->mb_width = (s->width + 15) / 16;
147 s->mb_height = (s->height + 15) / 16; 147 s->mb_height = (s->height + 15) / 16;
148
149 /* set default edge pos, will be overriden in decode_header if needed */
150 s->h_edge_pos= s->mb_width*16;
151 s->v_edge_pos= s->mb_height*16;
152
148 s->mb_num = s->mb_width * s->mb_height; 153 s->mb_num = s->mb_width * s->mb_height;
149 if(!(s->flags&CODEC_FLAG_DR1)){ 154 if(!(s->flags&CODEC_FLAG_DR1)){
150 s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH; 155 s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH;
151 s->uvlinesize = s->mb_width * 8 + EDGE_WIDTH; 156 s->uvlinesize = s->mb_width * 8 + EDGE_WIDTH;
152 157
622 s->mb_skiped = 0; 627 s->mb_skiped = 0;
623 s->decoding_error=0; 628 s->decoding_error=0;
624 avctx->mbskip_table= s->mbskip_table; 629 avctx->mbskip_table= s->mbskip_table;
625 630
626 if(avctx->flags&CODEC_FLAG_DR1){ 631 if(avctx->flags&CODEC_FLAG_DR1){
627 int i;
628 avctx->get_buffer_callback(avctx, s->width, s->height, s->pict_type); 632 avctx->get_buffer_callback(avctx, s->width, s->height, s->pict_type);
629 633
630 s->linesize = avctx->dr_stride; 634 s->linesize = avctx->dr_stride;
631 s->uvlinesize= avctx->dr_uvstride; 635 s->uvlinesize= avctx->dr_uvstride;
632 s->ip_buffer_count= avctx->dr_ip_buffer_count; 636 s->ip_buffer_count= avctx->dr_ip_buffer_count;
674 { 678 {
675 // if((s->picture_number%100)==0 && s->encoding) printf("sads:%d //\n", sads); 679 // if((s->picture_number%100)==0 && s->encoding) printf("sads:%d //\n", sads);
676 680
677 /* draw edge for correct motion prediction if outside */ 681 /* draw edge for correct motion prediction if outside */
678 if (s->pict_type != B_TYPE && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) { 682 if (s->pict_type != B_TYPE && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) {
679 if(s->avctx==NULL || s->avctx->codec->id!=CODEC_ID_MPEG4 || s->divx_version>=500){ 683 draw_edges(s->current_picture[0], s->linesize , s->h_edge_pos , s->v_edge_pos , EDGE_WIDTH );
680 draw_edges(s->current_picture[0], s->linesize, s->mb_width*16, s->mb_height*16, EDGE_WIDTH); 684 draw_edges(s->current_picture[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);
681 draw_edges(s->current_picture[1], s->uvlinesize, s->mb_width*8, s->mb_height*8, EDGE_WIDTH/2); 685 draw_edges(s->current_picture[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);
682 draw_edges(s->current_picture[2], s->uvlinesize, s->mb_width*8, s->mb_height*8, EDGE_WIDTH/2);
683 }else{
684 /* mpeg4? / opendivx / xvid */
685 draw_edges(s->current_picture[0], s->linesize, s->width, s->height, EDGE_WIDTH);
686 draw_edges(s->current_picture[1], s->uvlinesize, s->width/2, s->height/2, EDGE_WIDTH/2);
687 draw_edges(s->current_picture[2], s->uvlinesize, s->width/2, s->height/2, EDGE_WIDTH/2);
688 }
689 } 686 }
690 emms_c(); 687 emms_c();
691 688
692 if(s->pict_type!=B_TYPE){ 689 if(s->pict_type!=B_TYPE){
693 s->last_non_b_pict_type= s->pict_type; 690 s->last_non_b_pict_type= s->pict_type;
906 uvlinesize = s->uvlinesize; 903 uvlinesize = s->uvlinesize;
907 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; 904 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset;
908 905
909 dest_y+=dest_offset; 906 dest_y+=dest_offset;
910 if(s->flags&CODEC_FLAG_EMU_EDGE){ 907 if(s->flags&CODEC_FLAG_EMU_EDGE){
911 if(src_x<0 || src_y<0 || src_x + (motion_x&15) + 16 > s->width 908 if(src_x<0 || src_y<0 || src_x + (motion_x&15) + 16 > s->h_edge_pos
912 || src_y + (motion_y&15) + h > s->height){ 909 || src_y + (motion_y&15) + h > s->v_edge_pos){
913 emulated_edge_mc(s, ptr, linesize, 17, h+1, src_x, src_y, s->width, s->height); 910 emulated_edge_mc(s, ptr, linesize, 17, h+1, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
914 ptr= s->edge_emu_buffer; 911 ptr= s->edge_emu_buffer;
915 emu=1; 912 emu=1;
916 } 913 }
917 } 914 }
918 gmc1(dest_y , ptr , linesize, h, motion_x&15, motion_y&15, s->no_rounding); 915 gmc1(dest_y , ptr , linesize, h, motion_x&15, motion_y&15, s->no_rounding);
932 motion_y =0; 929 motion_y =0;
933 930
934 offset = (src_y * uvlinesize) + src_x + (src_offset>>1); 931 offset = (src_y * uvlinesize) + src_x + (src_offset>>1);
935 ptr = ref_picture[1] + offset; 932 ptr = ref_picture[1] + offset;
936 if(emu){ 933 if(emu){
937 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->width>>1, s->height>>1); 934 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
938 ptr= s->edge_emu_buffer; 935 ptr= s->edge_emu_buffer;
939 } 936 }
940 gmc1(dest_cb + (dest_offset>>1), ptr, uvlinesize, h>>1, motion_x&15, motion_y&15, s->no_rounding); 937 gmc1(dest_cb + (dest_offset>>1), ptr, uvlinesize, h>>1, motion_x&15, motion_y&15, s->no_rounding);
941 938
942 ptr = ref_picture[2] + offset; 939 ptr = ref_picture[2] + offset;
943 if(emu){ 940 if(emu){
944 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->width>>1, s->height>>1); 941 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
945 ptr= s->edge_emu_buffer; 942 ptr= s->edge_emu_buffer;
946 } 943 }
947 gmc1(dest_cr + (dest_offset>>1), ptr, uvlinesize, h>>1, motion_x&15, motion_y&15, s->no_rounding); 944 gmc1(dest_cr + (dest_offset>>1), ptr, uvlinesize, h>>1, motion_x&15, motion_y&15, s->no_rounding);
948 945
949 return; 946 return;
952 static void emulated_edge_mc(MpegEncContext *s, UINT8 *src, int linesize, int block_w, int block_h, 949 static void emulated_edge_mc(MpegEncContext *s, UINT8 *src, int linesize, int block_w, int block_h,
953 int src_x, int src_y, int w, int h){ 950 int src_x, int src_y, int w, int h){
954 int x, y; 951 int x, y;
955 int start_y, start_x, end_y, end_x; 952 int start_y, start_x, end_y, end_x;
956 UINT8 *buf= s->edge_emu_buffer; 953 UINT8 *buf= s->edge_emu_buffer;
957 #if 0 954
958 if(s->codec_id!=CODEC_ID_MPEG4 || s->divx_version>=500){
959 if(block_w < 10){
960 w= (w+7)&(~7);
961 h= (h+7)&(~7);
962 }else{
963 w= (w+15)&(~15);
964 h= (h+15)&(~15);
965 }
966 }
967 #endif
968 if(src_y>= h){ 955 if(src_y>= h){
969 src+= (h-1-src_y)*linesize; 956 src+= (h-1-src_y)*linesize;
970 src_y=h-1; 957 src_y=h-1;
971 }else if(src_y<=-block_h){ 958 }else if(src_y<=-block_h){
972 src+= (1-block_h-src_y)*linesize; 959 src+= (1-block_h-src_y)*linesize;
1027 UINT8 **ref_picture, int src_offset, 1014 UINT8 **ref_picture, int src_offset,
1028 int field_based, op_pixels_func *pix_op, 1015 int field_based, op_pixels_func *pix_op,
1029 int motion_x, int motion_y, int h) 1016 int motion_x, int motion_y, int h)
1030 { 1017 {
1031 UINT8 *ptr; 1018 UINT8 *ptr;
1032 int dxy, offset, mx, my, src_x, src_y, height, linesize, uvlinesize; 1019 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize;
1033 int emu=0; 1020 int emu=0;
1034 1021
1035 if(s->quarter_sample) 1022 if(s->quarter_sample)
1036 { 1023 {
1037 motion_x>>=1; 1024 motion_x>>=1;
1041 src_x = s->mb_x * 16 + (motion_x >> 1); 1028 src_x = s->mb_x * 16 + (motion_x >> 1);
1042 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1); 1029 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1);
1043 1030
1044 /* WARNING: do no forget half pels */ 1031 /* WARNING: do no forget half pels */
1045 height = s->height >> field_based; 1032 height = s->height >> field_based;
1033 v_edge_pos = s->v_edge_pos >> field_based;
1046 src_x = clip(src_x, -16, s->width); 1034 src_x = clip(src_x, -16, s->width);
1047 if (src_x == s->width) 1035 if (src_x == s->width)
1048 dxy &= ~1; 1036 dxy &= ~1;
1049 src_y = clip(src_y, -16, height); 1037 src_y = clip(src_y, -16, height);
1050 if (src_y == height) 1038 if (src_y == height)
1053 uvlinesize = s->uvlinesize << field_based; 1041 uvlinesize = s->uvlinesize << field_based;
1054 ptr = ref_picture[0] + (src_y * linesize) + (src_x) + src_offset; 1042 ptr = ref_picture[0] + (src_y * linesize) + (src_x) + src_offset;
1055 dest_y += dest_offset; 1043 dest_y += dest_offset;
1056 1044
1057 if(s->flags&CODEC_FLAG_EMU_EDGE){ 1045 if(s->flags&CODEC_FLAG_EMU_EDGE){
1058 if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 16 > s->width 1046 if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 16 > s->h_edge_pos
1059 || src_y + (motion_y&1) + h > height){ 1047 || src_y + (motion_y&1) + h > v_edge_pos){
1060 emulated_edge_mc(s, ptr, linesize, 17, h+1, src_x, src_y, s->width, height); 1048 emulated_edge_mc(s, ptr, linesize, 17, h+1, src_x, src_y, s->h_edge_pos, v_edge_pos);
1061 ptr= s->edge_emu_buffer; 1049 ptr= s->edge_emu_buffer;
1062 emu=1; 1050 emu=1;
1063 } 1051 }
1064 } 1052 }
1065 pix_op[dxy](dest_y, ptr, linesize, h); 1053 pix_op[dxy](dest_y, ptr, linesize, h);
1092 if (src_y == (height >> 1)) 1080 if (src_y == (height >> 1))
1093 dxy &= ~2; 1081 dxy &= ~2;
1094 offset = (src_y * uvlinesize) + src_x + (src_offset >> 1); 1082 offset = (src_y * uvlinesize) + src_x + (src_offset >> 1);
1095 ptr = ref_picture[1] + offset; 1083 ptr = ref_picture[1] + offset;
1096 if(emu){ 1084 if(emu){
1097 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->width>>1, height>>1); 1085 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1);
1098 ptr= s->edge_emu_buffer; 1086 ptr= s->edge_emu_buffer;
1099 } 1087 }
1100 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, uvlinesize, h >> 1); 1088 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, uvlinesize, h >> 1);
1101 1089
1102 ptr = ref_picture[2] + offset; 1090 ptr = ref_picture[2] + offset;
1103 if(emu){ 1091 if(emu){
1104 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->width>>1, height>>1); 1092 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1);
1105 ptr= s->edge_emu_buffer; 1093 ptr= s->edge_emu_buffer;
1106 } 1094 }
1107 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1); 1095 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1);
1108 } 1096 }
1109 1097
1114 int field_based, op_pixels_func *pix_op, 1102 int field_based, op_pixels_func *pix_op,
1115 qpel_mc_func *qpix_op, 1103 qpel_mc_func *qpix_op,
1116 int motion_x, int motion_y, int h) 1104 int motion_x, int motion_y, int h)
1117 { 1105 {
1118 UINT8 *ptr; 1106 UINT8 *ptr;
1119 int dxy, offset, mx, my, src_x, src_y, height, linesize; 1107 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize;
1120 int emu=0; 1108 int emu=0;
1121 1109
1122 dxy = ((motion_y & 3) << 2) | (motion_x & 3); 1110 dxy = ((motion_y & 3) << 2) | (motion_x & 3);
1123 src_x = s->mb_x * 16 + (motion_x >> 2); 1111 src_x = s->mb_x * 16 + (motion_x >> 2);
1124 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); 1112 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2);
1125 1113
1126 height = s->height >> field_based; 1114 height = s->height >> field_based;
1115 v_edge_pos = s->v_edge_pos >> field_based;
1127 src_x = clip(src_x, -16, s->width); 1116 src_x = clip(src_x, -16, s->width);
1128 if (src_x == s->width) 1117 if (src_x == s->width)
1129 dxy &= ~3; 1118 dxy &= ~3;
1130 src_y = clip(src_y, -16, height); 1119 src_y = clip(src_y, -16, height);
1131 if (src_y == height) 1120 if (src_y == height)
1134 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; 1123 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset;
1135 dest_y += dest_offset; 1124 dest_y += dest_offset;
1136 //printf("%d %d %d\n", src_x, src_y, dxy); 1125 //printf("%d %d %d\n", src_x, src_y, dxy);
1137 1126
1138 if(s->flags&CODEC_FLAG_EMU_EDGE){ 1127 if(s->flags&CODEC_FLAG_EMU_EDGE){
1139 if(src_x<0 || src_y<0 || src_x + (motion_x&3) + 16 > s->width 1128 if(src_x<0 || src_y<0 || src_x + (motion_x&3) + 16 > s->h_edge_pos
1140 || src_y + (motion_y&3) + h > height){ 1129 || src_y + (motion_y&3) + h > v_edge_pos){
1141 emulated_edge_mc(s, ptr, linesize, 17, h+1, src_x, src_y, s->width, height); 1130 emulated_edge_mc(s, ptr, linesize, 17, h+1, src_x, src_y, s->h_edge_pos, v_edge_pos);
1142 ptr= s->edge_emu_buffer; 1131 ptr= s->edge_emu_buffer;
1143 emu=1; 1132 emu=1;
1144 } 1133 }
1145 } 1134 }
1146 qpix_op[dxy](dest_y , ptr , linesize, linesize, motion_x&3, motion_y&3); 1135 qpix_op[dxy](dest_y , ptr , linesize, linesize, motion_x&3, motion_y&3);
1171 dxy &= ~2; 1160 dxy &= ~2;
1172 1161
1173 offset = (src_y * s->uvlinesize) + src_x + (src_offset >> 1); 1162 offset = (src_y * s->uvlinesize) + src_x + (src_offset >> 1);
1174 ptr = ref_picture[1] + offset; 1163 ptr = ref_picture[1] + offset;
1175 if(emu){ 1164 if(emu){
1176 emulated_edge_mc(s, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->width>>1, height>>1); 1165 emulated_edge_mc(s, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1);
1177 ptr= s->edge_emu_buffer; 1166 ptr= s->edge_emu_buffer;
1178 } 1167 }
1179 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1); 1168 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1);
1180 1169
1181 ptr = ref_picture[2] + offset; 1170 ptr = ref_picture[2] + offset;
1182 if(emu){ 1171 if(emu){
1183 emulated_edge_mc(s, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->width>>1, height>>1); 1172 emulated_edge_mc(s, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1);
1184 ptr= s->edge_emu_buffer; 1173 ptr= s->edge_emu_buffer;
1185 } 1174 }
1186 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1); 1175 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1);
1187 } 1176 }
1188 1177
1244 if (src_y == s->height) 1233 if (src_y == s->height)
1245 dxy &= ~2; 1234 dxy &= ~2;
1246 1235
1247 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); 1236 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x);
1248 if(s->flags&CODEC_FLAG_EMU_EDGE){ 1237 if(s->flags&CODEC_FLAG_EMU_EDGE){
1249 if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 8 > s->width 1238 if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 8 > s->h_edge_pos
1250 || src_y + (motion_y&1) + 8 > s->height){ 1239 || src_y + (motion_y&1) + 8 > s->v_edge_pos){
1251 emulated_edge_mc(s, ptr, s->linesize, 9, 9, src_x, src_y, s->width, s->height); 1240 emulated_edge_mc(s, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
1252 ptr= s->edge_emu_buffer; 1241 ptr= s->edge_emu_buffer;
1253 } 1242 }
1254 } 1243 }
1255 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; 1244 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize;
1256 pix_op[dxy](dest, ptr, s->linesize, 8); 1245 pix_op[dxy](dest, ptr, s->linesize, 8);
1291 dxy &= ~2; 1280 dxy &= ~2;
1292 1281
1293 offset = (src_y * (s->uvlinesize)) + src_x; 1282 offset = (src_y * (s->uvlinesize)) + src_x;
1294 ptr = ref_picture[1] + offset; 1283 ptr = ref_picture[1] + offset;
1295 if(s->flags&CODEC_FLAG_EMU_EDGE){ 1284 if(s->flags&CODEC_FLAG_EMU_EDGE){
1296 if(src_x<0 || src_y<0 || src_x + (dxy &1) + 8 > s->width >>1 1285 if(src_x<0 || src_y<0 || src_x + (dxy &1) + 8 > s->h_edge_pos>>1
1297 || src_y + (dxy>>1) + 8 > s->height>>1){ 1286 || src_y + (dxy>>1) + 8 > s->v_edge_pos>>1){
1298 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->width>>1, s->height>>1); 1287 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
1299 ptr= s->edge_emu_buffer; 1288 ptr= s->edge_emu_buffer;
1300 emu=1; 1289 emu=1;
1301 } 1290 }
1302 } 1291 }
1303 pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8); 1292 pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8);
1304 1293
1305 ptr = ref_picture[2] + offset; 1294 ptr = ref_picture[2] + offset;
1306 if(emu){ 1295 if(emu){
1307 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->width>>1, s->height>>1); 1296 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
1308 ptr= s->edge_emu_buffer; 1297 ptr= s->edge_emu_buffer;
1309 } 1298 }
1310 pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8); 1299 pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8);
1311 break; 1300 break;
1312 case MV_TYPE_FIELD: 1301 case MV_TYPE_FIELD:
2020 } 2009 }
2021 2010
2022 //printf("f_code %d ///\n", s->f_code); 2011 //printf("f_code %d ///\n", s->f_code);
2023 2012
2024 // printf("%d %d\n", s->avg_mb_var, s->mc_mb_var); 2013 // printf("%d %d\n", s->avg_mb_var, s->mc_mb_var);
2025
2026 if(s->flags&CODEC_FLAG_PASS2) 2014 if(s->flags&CODEC_FLAG_PASS2)
2027 s->qscale = ff_rate_estimate_qscale_pass2(s); 2015 s->qscale = ff_rate_estimate_qscale_pass2(s);
2028 else if (!s->fixed_qscale) 2016 else if (!s->fixed_qscale)
2029 s->qscale = ff_rate_estimate_qscale(s); 2017 s->qscale = ff_rate_estimate_qscale(s);
2030 2018