comparison mpegvideo.c @ 651:45e8f39fda50 libavcodec

put/avg_pixels16 fixing 2 small qpel bugs
author michaelni
date Wed, 11 Sep 2002 12:39:53 +0000
parents ef4a33aad86e
children c7647afc3ce5
comparison
equal deleted inserted replaced
650:ef4a33aad86e 651:45e8f39fda50
1061 /* apply one mpeg motion vector to the three components */ 1061 /* apply one mpeg motion vector to the three components */
1062 static inline void mpeg_motion(MpegEncContext *s, 1062 static inline void mpeg_motion(MpegEncContext *s,
1063 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, 1063 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr,
1064 int dest_offset, 1064 int dest_offset,
1065 UINT8 **ref_picture, int src_offset, 1065 UINT8 **ref_picture, int src_offset,
1066 int field_based, op_pixels_func *pix_op, 1066 int field_based, op_pixels_func (*pix_op)[4],
1067 int motion_x, int motion_y, int h) 1067 int motion_x, int motion_y, int h)
1068 { 1068 {
1069 UINT8 *ptr; 1069 UINT8 *ptr;
1070 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize; 1070 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize;
1071 int emu=0; 1071 int emu=0;
1072 1072 #if 0
1073 if(s->quarter_sample) 1073 if(s->quarter_sample)
1074 { 1074 {
1075 motion_x>>=1; 1075 motion_x>>=1;
1076 motion_y>>=1; 1076 motion_y>>=1;
1077 } 1077 }
1078 #endif
1078 dxy = ((motion_y & 1) << 1) | (motion_x & 1); 1079 dxy = ((motion_y & 1) << 1) | (motion_x & 1);
1079 src_x = s->mb_x * 16 + (motion_x >> 1); 1080 src_x = s->mb_x * 16 + (motion_x >> 1);
1080 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1); 1081 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1);
1081 1082
1082 /* WARNING: do no forget half pels */ 1083 /* WARNING: do no forget half pels */
1099 emulated_edge_mc(s, ptr, linesize, 17, h+1, src_x, src_y, s->h_edge_pos, v_edge_pos); 1100 emulated_edge_mc(s, ptr, linesize, 17, h+1, src_x, src_y, s->h_edge_pos, v_edge_pos);
1100 ptr= s->edge_emu_buffer; 1101 ptr= s->edge_emu_buffer;
1101 emu=1; 1102 emu=1;
1102 } 1103 }
1103 } 1104 }
1104 pix_op[dxy](dest_y, ptr, linesize, h); 1105 pix_op[0][dxy](dest_y, ptr, linesize, h);
1105 pix_op[dxy](dest_y + 8, ptr + 8, linesize, h);
1106 1106
1107 if(s->flags&CODEC_FLAG_GRAY) return; 1107 if(s->flags&CODEC_FLAG_GRAY) return;
1108 1108
1109 if (s->out_format == FMT_H263) { 1109 if (s->out_format == FMT_H263) {
1110 dxy = 0; 1110 dxy = 0;
1134 ptr = ref_picture[1] + offset; 1134 ptr = ref_picture[1] + offset;
1135 if(emu){ 1135 if(emu){
1136 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1); 1136 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1);
1137 ptr= s->edge_emu_buffer; 1137 ptr= s->edge_emu_buffer;
1138 } 1138 }
1139 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, uvlinesize, h >> 1); 1139 pix_op[1][dxy](dest_cb + (dest_offset >> 1), ptr, uvlinesize, h >> 1);
1140 1140
1141 ptr = ref_picture[2] + offset; 1141 ptr = ref_picture[2] + offset;
1142 if(emu){ 1142 if(emu){
1143 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1); 1143 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1);
1144 ptr= s->edge_emu_buffer; 1144 ptr= s->edge_emu_buffer;
1145 } 1145 }
1146 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1); 1146 pix_op[1][dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1);
1147 } 1147 }
1148 1148
1149 static inline void qpel_motion(MpegEncContext *s, 1149 static inline void qpel_motion(MpegEncContext *s,
1150 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, 1150 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr,
1151 int dest_offset, 1151 int dest_offset,
1152 UINT8 **ref_picture, int src_offset, 1152 UINT8 **ref_picture, int src_offset,
1153 int field_based, op_pixels_func *pix_op, 1153 int field_based, op_pixels_func (*pix_op)[4],
1154 qpel_mc_func *qpix_op, 1154 qpel_mc_func (*qpix_op)[16],
1155 int motion_x, int motion_y, int h) 1155 int motion_x, int motion_y, int h)
1156 { 1156 {
1157 UINT8 *ptr; 1157 UINT8 *ptr;
1158 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize; 1158 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize;
1159 int emu=0; 1159 int emu=0;
1181 emulated_edge_mc(s, ptr, linesize, 17, h+1, src_x, src_y, s->h_edge_pos, v_edge_pos); 1181 emulated_edge_mc(s, ptr, linesize, 17, h+1, src_x, src_y, s->h_edge_pos, v_edge_pos);
1182 ptr= s->edge_emu_buffer; 1182 ptr= s->edge_emu_buffer;
1183 emu=1; 1183 emu=1;
1184 } 1184 }
1185 } 1185 }
1186 qpix_op[dxy](dest_y , ptr , linesize, linesize, motion_x&3, motion_y&3); 1186 qpix_op[0][dxy](dest_y, ptr, linesize);
1187 qpix_op[dxy](dest_y + 8, ptr + 8, linesize, linesize, motion_x&3, motion_y&3); 1187
1188 qpix_op[dxy](dest_y + linesize*8 , ptr + linesize*8 , linesize, linesize, motion_x&3, motion_y&3);
1189 qpix_op[dxy](dest_y + linesize*8 + 8, ptr + linesize*8 + 8, linesize, linesize, motion_x&3, motion_y&3);
1190
1191 if(s->flags&CODEC_FLAG_GRAY) return; 1188 if(s->flags&CODEC_FLAG_GRAY) return;
1192 1189
1193 mx= (motion_x>>1) | (motion_x&1); 1190 mx= (motion_x>>1) | (motion_x&1);
1194 my= (motion_y>>1) | (motion_y&1); 1191 my= (motion_y>>1) | (motion_y&1);
1195 1192
1214 ptr = ref_picture[1] + offset; 1211 ptr = ref_picture[1] + offset;
1215 if(emu){ 1212 if(emu){
1216 emulated_edge_mc(s, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1); 1213 emulated_edge_mc(s, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1);
1217 ptr= s->edge_emu_buffer; 1214 ptr= s->edge_emu_buffer;
1218 } 1215 }
1219 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1); 1216 pix_op[1][dxy](dest_cb + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1);
1220 1217
1221 ptr = ref_picture[2] + offset; 1218 ptr = ref_picture[2] + offset;
1222 if(emu){ 1219 if(emu){
1223 emulated_edge_mc(s, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1); 1220 emulated_edge_mc(s, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1);
1224 ptr= s->edge_emu_buffer; 1221 ptr= s->edge_emu_buffer;
1225 } 1222 }
1226 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1); 1223 pix_op[1][dxy](dest_cr + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1);
1227 } 1224 }
1228 1225
1229 1226
1230 static inline void MPV_motion(MpegEncContext *s, 1227 static inline void MPV_motion(MpegEncContext *s,
1231 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, 1228 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr,
1232 int dir, UINT8 **ref_picture, 1229 int dir, UINT8 **ref_picture,
1233 op_pixels_func *pix_op, qpel_mc_func *qpix_op) 1230 op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16])
1234 { 1231 {
1235 int dxy, offset, mx, my, src_x, src_y, motion_x, motion_y; 1232 int dxy, offset, mx, my, src_x, src_y, motion_x, motion_y;
1236 int mb_x, mb_y, i; 1233 int mb_x, mb_y, i;
1237 UINT8 *ptr, *dest; 1234 UINT8 *ptr, *dest;
1238 int emu=0; 1235 int emu=0;
1241 mb_y = s->mb_y; 1238 mb_y = s->mb_y;
1242 1239
1243 switch(s->mv_type) { 1240 switch(s->mv_type) {
1244 case MV_TYPE_16X16: 1241 case MV_TYPE_16X16:
1245 if(s->mcsel){ 1242 if(s->mcsel){
1246 #if 0
1247 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
1248 ref_picture, 0,
1249 0, pix_op,
1250 s->sprite_offset[0][0]>>3,
1251 s->sprite_offset[0][1]>>3,
1252 16);
1253 #else
1254 gmc1_motion(s, dest_y, dest_cb, dest_cr, 0, 1243 gmc1_motion(s, dest_y, dest_cb, dest_cr, 0,
1255 ref_picture, 0, 1244 ref_picture, 0,
1256 16); 1245 16);
1257 #endif 1246 }else if(s->quarter_sample){
1258 }else if(s->quarter_sample && dir==0){ //FIXME
1259 qpel_motion(s, dest_y, dest_cb, dest_cr, 0, 1247 qpel_motion(s, dest_y, dest_cb, dest_cr, 0,
1260 ref_picture, 0, 1248 ref_picture, 0,
1261 0, pix_op, qpix_op, 1249 0, pix_op, qpix_op,
1262 s->mv[dir][0][0], s->mv[dir][0][1], 16); 1250 s->mv[dir][0][0], s->mv[dir][0][1], 16);
1263 }else{ 1251 }else{
1291 emulated_edge_mc(s, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos); 1279 emulated_edge_mc(s, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
1292 ptr= s->edge_emu_buffer; 1280 ptr= s->edge_emu_buffer;
1293 } 1281 }
1294 } 1282 }
1295 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; 1283 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize;
1296 pix_op[dxy](dest, ptr, s->linesize, 8); 1284 pix_op[1][dxy](dest, ptr, s->linesize, 8);
1297 } 1285 }
1298 1286
1299 if(s->flags&CODEC_FLAG_GRAY) break; 1287 if(s->flags&CODEC_FLAG_GRAY) break;
1300 /* In case of 8X8, we construct a single chroma motion vector 1288 /* In case of 8X8, we construct a single chroma motion vector
1301 with a special rounding */ 1289 with a special rounding */
1338 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); 1326 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
1339 ptr= s->edge_emu_buffer; 1327 ptr= s->edge_emu_buffer;
1340 emu=1; 1328 emu=1;
1341 } 1329 }
1342 } 1330 }
1343 pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8); 1331 pix_op[1][dxy](dest_cb, ptr, s->uvlinesize, 8);
1344 1332
1345 ptr = ref_picture[2] + offset; 1333 ptr = ref_picture[2] + offset;
1346 if(emu){ 1334 if(emu){
1347 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); 1335 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
1348 ptr= s->edge_emu_buffer; 1336 ptr= s->edge_emu_buffer;
1349 } 1337 }
1350 pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8); 1338 pix_op[1][dxy](dest_cr, ptr, s->uvlinesize, 8);
1351 break; 1339 break;
1352 case MV_TYPE_FIELD: 1340 case MV_TYPE_FIELD:
1353 if (s->picture_structure == PICT_FRAME) { 1341 if (s->picture_structure == PICT_FRAME) {
1354 /* top field */ 1342 /* top field */
1355 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, 1343 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
1508 } 1496 }
1509 1497
1510 if (!(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) { 1498 if (!(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) {
1511 UINT8 *dest_y, *dest_cb, *dest_cr; 1499 UINT8 *dest_y, *dest_cb, *dest_cr;
1512 int dct_linesize, dct_offset; 1500 int dct_linesize, dct_offset;
1513 op_pixels_func *op_pix; 1501 op_pixels_func (*op_pix)[4];
1514 qpel_mc_func *op_qpix; 1502 qpel_mc_func (*op_qpix)[16];
1515 1503
1516 /* avoid copy if macroblock skipped in last frame too 1504 /* avoid copy if macroblock skipped in last frame too
1517 dont touch it for B-frames as they need the skip info from the next p-frame */ 1505 dont touch it for B-frames as they need the skip info from the next p-frame */
1518 if (s->pict_type != B_TYPE) { 1506 if (s->pict_type != B_TYPE) {
1519 UINT8 *mbskip_ptr = &s->mbskip_table[mb_xy]; 1507 UINT8 *mbskip_ptr = &s->mbskip_table[mb_xy];
1548 /* motion handling */ 1536 /* motion handling */
1549 /* decoding or more than one mb_type (MC was allready done otherwise) */ 1537 /* decoding or more than one mb_type (MC was allready done otherwise) */
1550 if((!s->encoding) || (s->mb_type[mb_xy]&(s->mb_type[mb_xy]-1))){ 1538 if((!s->encoding) || (s->mb_type[mb_xy]&(s->mb_type[mb_xy]-1))){
1551 if ((!s->no_rounding) || s->pict_type==B_TYPE){ 1539 if ((!s->no_rounding) || s->pict_type==B_TYPE){
1552 op_pix = put_pixels_tab; 1540 op_pix = put_pixels_tab;
1553 op_qpix= qpel_mc_rnd_tab; 1541 op_qpix= put_qpel_pixels_tab;
1554 }else{ 1542 }else{
1555 op_pix = put_no_rnd_pixels_tab; 1543 op_pix = put_no_rnd_pixels_tab;
1556 op_qpix= qpel_mc_no_rnd_tab; 1544 op_qpix= put_no_rnd_qpel_pixels_tab;
1557 } 1545 }
1558 1546
1559 if (s->mv_dir & MV_DIR_FORWARD) { 1547 if (s->mv_dir & MV_DIR_FORWARD) {
1560 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix); 1548 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix);
1561 if ((!s->no_rounding) || s->pict_type==B_TYPE) 1549 op_pix = avg_pixels_tab;
1562 op_pix = avg_pixels_tab; 1550 op_qpix= avg_qpel_pixels_tab;
1563 else
1564 op_pix = avg_no_rnd_pixels_tab;
1565 } 1551 }
1566 if (s->mv_dir & MV_DIR_BACKWARD) { 1552 if (s->mv_dir & MV_DIR_BACKWARD) {
1567 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); 1553 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix);
1568 } 1554 }
1569 } 1555 }
1727 ptr= s->edge_emu_buffer; 1713 ptr= s->edge_emu_buffer;
1728 } 1714 }
1729 get_pixels(s->block[5], ptr, wrap); 1715 get_pixels(s->block[5], ptr, wrap);
1730 } 1716 }
1731 }else{ 1717 }else{
1732 op_pixels_func *op_pix; 1718 op_pixels_func (*op_pix)[4];
1733 qpel_mc_func *op_qpix; 1719 qpel_mc_func (*op_qpix)[16];
1734 UINT8 *dest_y, *dest_cb, *dest_cr; 1720 UINT8 *dest_y, *dest_cb, *dest_cr;
1735 UINT8 *ptr_y, *ptr_cb, *ptr_cr; 1721 UINT8 *ptr_y, *ptr_cb, *ptr_cr;
1736 int wrap_y, wrap_c; 1722 int wrap_y, wrap_c;
1737 int emu=0; 1723 int emu=0;
1738 1724
1745 ptr_cb = s->new_picture[1] + (mb_y * 8 * wrap_c) + mb_x * 8; 1731 ptr_cb = s->new_picture[1] + (mb_y * 8 * wrap_c) + mb_x * 8;
1746 ptr_cr = s->new_picture[2] + (mb_y * 8 * wrap_c) + mb_x * 8; 1732 ptr_cr = s->new_picture[2] + (mb_y * 8 * wrap_c) + mb_x * 8;
1747 1733
1748 if ((!s->no_rounding) || s->pict_type==B_TYPE){ 1734 if ((!s->no_rounding) || s->pict_type==B_TYPE){
1749 op_pix = put_pixels_tab; 1735 op_pix = put_pixels_tab;
1750 op_qpix= qpel_mc_rnd_tab; 1736 op_qpix= put_qpel_pixels_tab;
1751 }else{ 1737 }else{
1752 op_pix = put_no_rnd_pixels_tab; 1738 op_pix = put_no_rnd_pixels_tab;
1753 op_qpix= qpel_mc_no_rnd_tab; 1739 op_qpix= put_no_rnd_qpel_pixels_tab;
1754 } 1740 }
1755 1741
1756 if (s->mv_dir & MV_DIR_FORWARD) { 1742 if (s->mv_dir & MV_DIR_FORWARD) {
1757 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix); 1743 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix);
1758 if ((!s->no_rounding) || s->pict_type==B_TYPE) 1744 op_pix = avg_pixels_tab;
1759 op_pix = avg_pixels_tab; 1745 op_qpix= avg_qpel_pixels_tab;
1760 else
1761 op_pix = avg_no_rnd_pixels_tab;
1762 } 1746 }
1763 if (s->mv_dir & MV_DIR_BACKWARD) { 1747 if (s->mv_dir & MV_DIR_BACKWARD) {
1764 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); 1748 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix);
1765 } 1749 }
1766 1750