comparison libmpeg2/slice.c @ 49:727b1337f951

updated to libmpeg2-0.2.1-CVS
author arpi_esp
date Wed, 07 Mar 2001 01:15:02 +0000
parents 0d76b2b962ad
children 300fea6ea86a
comparison
equal deleted inserted replaced
48:66ae768fe0ea 49:727b1337f951
973 case 15: /* macroblock_stuffing (MPEG1 only) */ 973 case 15: /* macroblock_stuffing (MPEG1 only) */
974 DUMPBITS (bit_buf, bits, 11); 974 DUMPBITS (bit_buf, bits, 11);
975 NEEDBITS (bit_buf, bits, bit_ptr); 975 NEEDBITS (bit_buf, bits, bit_ptr);
976 break; 976 break;
977 default: /* end of slice, or error */ 977 default: /* end of slice, or error */
978 // printf("MB error: %d \n",(UBITS (bit_buf, 11))); // FIXME!
978 return 0; 979 return 0;
979 } 980 }
980 } 981 }
981 982
982 #undef bit_buf 983 #undef bit_buf
1022 else 1023 else
1023 get_non_intra_block (picture); 1024 get_non_intra_block (picture);
1024 idct_block_add (picture->DCTblock, dest, stride); 1025 idct_block_add (picture->DCTblock, dest, stride);
1025 } 1026 }
1026 1027
1028 #define MOTION_Y(table,offset_x,offset_y,motion_x,motion_y, \
1029 dest,src,offset_dest,offset_src,stride,height) \
1030 do { \
1031 int xy_half; \
1032 int total_offset; \
1033 \
1034 xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
1035 total_offset = ((offset_y + (motion_y >> 1)) * stride + \
1036 offset_x + (motion_x >> 1) + (offset_src)); \
1037 table[xy_half] (dest[0] + offset_x + (offset_dest), \
1038 src[0] + total_offset, stride, height); \
1039 } while (0)
1040
1041 #define MOTION_UV(table,offset_x,offset_y,motion_x,motion_y, \
1042 dest,src,offset_dest,offset_src,stride,height) \
1043 do { \
1044 int xy_half; \
1045 int total_offset; \
1046 \
1047 xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
1048 total_offset = (((offset_y + motion_y) >> 1) * (stride) + \
1049 ((offset_x + motion_x) >> 1) + (offset_src)); \
1050 table[4+xy_half] (dest[1] + (offset_x >> 1) + (offset_dest), \
1051 src[1] + total_offset, stride, height); \
1052 table[4+xy_half] (dest[2] + (offset_x >> 1) + (offset_dest), \
1053 src[2] + total_offset, stride, height); \
1054 } while (0)
1055
1027 static inline void motion_block (void (** table) (uint8_t *, uint8_t *, 1056 static inline void motion_block (void (** table) (uint8_t *, uint8_t *,
1028 int32_t, int32_t), 1057 int32_t, int32_t),
1058 int x_offset, int y_offset, int mb_y_8_offset,
1059 int src_field, int dest_field,
1029 int x_pred, int y_pred, 1060 int x_pred, int y_pred,
1030 uint8_t * dest[3], int dest_offset, 1061 uint8_t * dest[3], uint8_t * src[3],
1031 uint8_t * src[3], int src_offset, 1062 int stride, int height)
1032 int stride, int height, int second_half) 1063 {
1033 { 1064 MOTION_Y (table, x_offset, y_offset, x_pred, y_pred, dest, src,
1034 int xy_half; 1065 dest_field + mb_y_8_offset*8*stride, src_field, stride, height);
1035 uint8_t * src1;
1036 uint8_t * src2;
1037
1038 xy_half = ((y_pred & 1) << 1) | (x_pred & 1);
1039
1040 src1 = src[0] + src_offset + (x_pred >> 1) + (y_pred >> 1) * stride +
1041 second_half * (stride << 3);
1042
1043 table[xy_half] (dest[0] + dest_offset + second_half * (stride << 3),
1044 src1, stride, height);
1045 1066
1046 x_pred /= 2; 1067 x_pred /= 2;
1047 y_pred /= 2; 1068 y_pred /= 2;
1048
1049 xy_half = ((y_pred & 1) << 1) | (x_pred & 1);
1050 stride >>= 1; 1069 stride >>= 1;
1051 height >>= 1; 1070 height >>= 1;
1052 src_offset >>= 1; src_offset += second_half * (stride << 2); 1071
1053 dest_offset >>= 1; dest_offset += second_half * (stride << 2); 1072 MOTION_UV (table, x_offset, y_offset, x_pred, y_pred, dest, src,
1054 1073 (dest_field >> 1) + mb_y_8_offset*4*stride, src_field >> 1,
1055 src1 = src[1] + src_offset + (x_pred >> 1) + (y_pred >> 1) * stride; 1074 stride, height);
1056 src2 = src[2] + src_offset + (x_pred >> 1) + (y_pred >> 1) * stride; 1075 }
1057
1058 table[4+xy_half] (dest[1] + dest_offset, src1, stride, height);
1059 table[4+xy_half] (dest[2] + dest_offset, src2, stride, height);
1060 }
1061
1062 1076
1063 static void motion_mp1 (picture_t * picture, motion_t * motion, 1077 static void motion_mp1 (picture_t * picture, motion_t * motion,
1064 uint8_t * dest[3], int offset, int stride, 1078 uint8_t * dest[3], int offset, int stride,
1065 void (** table) (uint8_t *, uint8_t *, int, int)) 1079 void (** table) (uint8_t *, uint8_t *, int, int))
1066 { 1080 {
1084 if (motion->f_code[1]) { 1098 if (motion->f_code[1]) {
1085 motion_x <<= 1; 1099 motion_x <<= 1;
1086 motion_y <<= 1; 1100 motion_y <<= 1;
1087 } 1101 }
1088 1102
1089 motion_block (table, motion_x, motion_y, dest, offset, 1103 motion_block (table, offset, picture->v_offset, 0, 0, 0,
1090 motion->ref[0], offset, stride, 16, 0); 1104 motion_x, motion_y, dest, motion->ref[0], stride, 16);
1091 #undef bit_buf 1105 #undef bit_buf
1092 #undef bits 1106 #undef bits
1093 #undef bit_ptr 1107 #undef bit_ptr
1094 } 1108 }
1095 1109
1105 if (motion->f_code[1]) { 1119 if (motion->f_code[1]) {
1106 motion_x <<= 1; 1120 motion_x <<= 1;
1107 motion_y <<= 1; 1121 motion_y <<= 1;
1108 } 1122 }
1109 1123
1110 motion_block (table, motion_x, motion_y, dest, offset, 1124 motion_block (table, offset, picture->v_offset, 0, 0, 0,
1111 motion->ref[0], offset, stride, 16, 0); 1125 motion_x, motion_y, dest, motion->ref[0], stride, 16);
1112 } 1126 }
1113 1127
1114 static void motion_fr_frame (picture_t * picture, motion_t * motion, 1128 static void motion_fr_frame (picture_t * picture, motion_t * motion,
1115 uint8_t * dest[3], int offset, int stride, 1129 uint8_t * dest[3], int offset, int stride,
1116 void (** table) (uint8_t *, uint8_t *, int, int)) 1130 void (** table) (uint8_t *, uint8_t *, int, int))
1130 motion_y = motion->pmv[0][1] + get_motion_delta (picture, 1144 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
1131 motion->f_code[1]); 1145 motion->f_code[1]);
1132 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); 1146 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
1133 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; 1147 motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
1134 1148
1135 motion_block (table, motion_x, motion_y, dest, offset, 1149 motion_block (table, offset, picture->v_offset, 0, 0, 0,
1136 motion->ref[0], offset, stride, 16, 0); 1150 motion_x, motion_y, dest, motion->ref[0], stride, 16);
1137 #undef bit_buf 1151 #undef bit_buf
1138 #undef bits 1152 #undef bits
1139 #undef bit_ptr 1153 #undef bit_ptr
1140 } 1154 }
1141 1155
1162 motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (picture, 1176 motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (picture,
1163 motion->f_code[1]); 1177 motion->f_code[1]);
1164 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ 1178 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
1165 motion->pmv[0][1] = motion_y << 1; 1179 motion->pmv[0][1] = motion_y << 1;
1166 1180
1167 motion_block (table, motion_x, motion_y, dest, offset, 1181 motion_block (table, offset, picture->v_offset >> 1,
1168 motion->ref[0], offset + (field_select & stride), 1182 0, (field_select & stride), 0,
1169 stride * 2, 8, 0); 1183 motion_x, motion_y, dest, motion->ref[0], stride * 2, 8);
1170 1184
1171 NEEDBITS (bit_buf, bits, bit_ptr); 1185 NEEDBITS (bit_buf, bits, bit_ptr);
1172 field_select = SBITS (bit_buf, 1); 1186 field_select = SBITS (bit_buf, 1);
1173 DUMPBITS (bit_buf, bits, 1); 1187 DUMPBITS (bit_buf, bits, 1);
1174 1188
1181 motion_y = (motion->pmv[1][1] >> 1) + get_motion_delta (picture, 1195 motion_y = (motion->pmv[1][1] >> 1) + get_motion_delta (picture,
1182 motion->f_code[1]); 1196 motion->f_code[1]);
1183 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ 1197 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
1184 motion->pmv[1][1] = motion_y << 1; 1198 motion->pmv[1][1] = motion_y << 1;
1185 1199
1186 motion_block (table, motion_x, motion_y, dest, offset + stride, 1200 motion_block (table, offset, picture->v_offset >> 1,
1187 motion->ref[0], offset + (field_select & stride), 1201 0, (field_select & stride), stride,
1188 stride * 2, 8, 0); 1202 motion_x, motion_y, dest, motion->ref[0], stride * 2, 8);
1189 #undef bit_buf 1203 #undef bit_buf
1190 #undef bits 1204 #undef bits
1191 #undef bit_ptr 1205 #undef bit_ptr
1192 } 1206 }
1193 1207
1219 motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1; 1233 motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1;
1220 1234
1221 NEEDBITS (bit_buf, bits, bit_ptr); 1235 NEEDBITS (bit_buf, bits, bit_ptr);
1222 dmv_y = get_dmv (picture); 1236 dmv_y = get_dmv (picture);
1223 1237
1224 motion_block (mc_functions.put, motion_x, motion_y, dest, offset, 1238 motion_block (mc_functions.put, offset, picture->v_offset >> 1, 0, 0, 0,
1225 motion->ref[0], offset, stride * 2, 8, 0); 1239 motion_x, motion_y, dest, motion->ref[0], stride * 2, 8);
1226 1240
1227 m = picture->top_field_first ? 1 : 3; 1241 m = picture->top_field_first ? 1 : 3;
1228 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; 1242 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
1229 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1; 1243 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1;
1230 motion_block (mc_functions.avg, other_x, other_y, dest, offset, 1244 motion_block (mc_functions.avg, offset, picture->v_offset >> 1, 0, stride, 0,
1231 motion->ref[0], offset + stride, stride * 2, 8, 0); 1245 other_x, other_y, dest, motion->ref[0], stride * 2, 8);
1232 1246
1233 motion_block (mc_functions.put, motion_x, motion_y, dest, offset + stride, 1247 motion_block (mc_functions.put, offset, picture->v_offset >> 1,
1234 motion->ref[0], offset + stride, stride * 2, 8, 0); 1248 0, stride, stride,
1249 motion_x, motion_y, dest, motion->ref[0], stride * 2, 8);
1235 1250
1236 m = picture->top_field_first ? 3 : 1; 1251 m = picture->top_field_first ? 3 : 1;
1237 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; 1252 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
1238 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1; 1253 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1;
1239 motion_block (mc_functions.avg, other_x, other_y, dest, offset + stride, 1254 motion_block (mc_functions.avg, offset, picture->v_offset >> 1, 0, 0, stride,
1240 motion->ref[0], offset, stride * 2, 8, 0); 1255 other_x, other_y, dest, motion->ref[0], stride * 2, 8);
1241 #undef bit_buf 1256 #undef bit_buf
1242 #undef bits 1257 #undef bits
1243 #undef bit_ptr 1258 #undef bit_ptr
1244 } 1259 }
1245 1260
1246 /* like motion_frame, but reuse previous motion vectors */ 1261 /* like motion_frame, but reuse previous motion vectors */
1247 static void motion_fr_reuse (picture_t * picture, motion_t * motion, 1262 static void motion_fr_reuse (picture_t * picture, motion_t * motion,
1248 uint8_t * dest[3], int offset, int stride, 1263 uint8_t * dest[3], int offset, int stride,
1249 void (** table) (uint8_t *, uint8_t *, int, int)) 1264 void (** table) (uint8_t *, uint8_t *, int, int))
1250 { 1265 {
1251 motion_block (table, motion->pmv[0][0], motion->pmv[0][1], dest, offset, 1266 motion_block (table, offset, picture->v_offset, 0, 0, 0,
1252 motion->ref[0], offset, stride, 16, 0); 1267 motion->pmv[0][0], motion->pmv[0][1],
1268 dest, motion->ref[0], stride, 16);
1253 } 1269 }
1254 1270
1255 /* like motion_frame, but use null motion vectors */ 1271 /* like motion_frame, but use null motion vectors */
1256 static void motion_fr_zero (picture_t * picture, motion_t * motion, 1272 static void motion_fr_zero (picture_t * picture, motion_t * motion,
1257 uint8_t * dest[3], int offset, int stride, 1273 uint8_t * dest[3], int offset, int stride,
1258 void (** table) (uint8_t *, uint8_t *, int, int)) 1274 void (** table) (uint8_t *, uint8_t *, int, int))
1259 { 1275 {
1260 motion_block (table, 0, 0, dest, offset, 1276 motion_block (table, offset, picture->v_offset, 0, 0, 0, 0, 0,
1261 motion->ref[0], offset, stride, 16, 0); 1277 dest, motion->ref[0], stride, 16);
1262 } 1278 }
1263 1279
1264 /* like motion_frame, but parsing without actual motion compensation */ 1280 /* like motion_frame, but parsing without actual motion compensation */
1265 static void motion_fr_conceal (picture_t * picture) 1281 static void motion_fr_conceal (picture_t * picture)
1266 { 1282 {
1311 motion_y = motion->pmv[0][1] + get_motion_delta (picture, 1327 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
1312 motion->f_code[1]); 1328 motion->f_code[1]);
1313 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); 1329 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
1314 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; 1330 motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
1315 1331
1316 motion_block (table, motion_x, motion_y, dest, offset, 1332 motion_block (table, offset, picture->v_offset, 0, 0, 0,
1317 motion->ref[field_select], offset, stride, 16, 0); 1333 motion_x, motion_y,
1334 dest, motion->ref[field_select], stride, 16);
1318 #undef bit_buf 1335 #undef bit_buf
1319 #undef bits 1336 #undef bits
1320 #undef bit_ptr 1337 #undef bit_ptr
1321 } 1338 }
1322 1339
1344 motion_y = motion->pmv[0][1] + get_motion_delta (picture, 1361 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
1345 motion->f_code[1]); 1362 motion->f_code[1]);
1346 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); 1363 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
1347 motion->pmv[0][1] = motion_y; 1364 motion->pmv[0][1] = motion_y;
1348 1365
1349 motion_block (table, motion_x, motion_y, dest, offset, 1366 motion_block (table, offset, picture->v_offset, 0, 0, 0,
1350 motion->ref[field_select], offset, stride, 8, 0); 1367 motion_x, motion_y,
1368 dest, motion->ref[field_select], stride, 8);
1351 1369
1352 NEEDBITS (bit_buf, bits, bit_ptr); 1370 NEEDBITS (bit_buf, bits, bit_ptr);
1353 field_select = UBITS (bit_buf, 1); 1371 field_select = UBITS (bit_buf, 1);
1354 DUMPBITS (bit_buf, bits, 1); 1372 DUMPBITS (bit_buf, bits, 1);
1355 1373
1363 motion_y = motion->pmv[1][1] + get_motion_delta (picture, 1381 motion_y = motion->pmv[1][1] + get_motion_delta (picture,
1364 motion->f_code[1]); 1382 motion->f_code[1]);
1365 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); 1383 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
1366 motion->pmv[1][1] = motion_y; 1384 motion->pmv[1][1] = motion_y;
1367 1385
1368 motion_block (table, motion_x, motion_y, dest, offset, 1386 motion_block (table, offset, picture->v_offset+8, 1, 0, 0,
1369 motion->ref[field_select], offset, stride, 8, 1); 1387 motion_x, motion_y,
1388 dest, motion->ref[field_select], stride, 8);
1370 #undef bit_buf 1389 #undef bit_buf
1371 #undef bits 1390 #undef bits
1372 #undef bit_ptr 1391 #undef bit_ptr
1373 } 1392 }
1374 1393
1398 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; 1417 motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
1399 1418
1400 NEEDBITS (bit_buf, bits, bit_ptr); 1419 NEEDBITS (bit_buf, bits, bit_ptr);
1401 dmv_y = get_dmv (picture); 1420 dmv_y = get_dmv (picture);
1402 1421
1403 motion_block (mc_functions.put, motion_x, motion_y, dest, offset, 1422 motion_block (mc_functions.put, offset, picture->v_offset, 0, 0, 0,
1404 motion->ref[picture->current_field], offset, stride, 16, 0); 1423 motion_x, motion_y,
1424 dest, motion->ref[picture->current_field], stride, 16);
1405 1425
1406 motion_x = ((motion_x + (motion_x > 0)) >> 1) + dmv_x; 1426 motion_x = ((motion_x + (motion_x > 0)) >> 1) + dmv_x;
1407 motion_y = ((motion_y + (motion_y > 0)) >> 1) + dmv_y + 1427 motion_y = ((motion_y + (motion_y > 0)) >> 1) + dmv_y +
1408 2 * picture->current_field - 1; 1428 2 * picture->current_field - 1;
1409 motion_block (mc_functions.avg, motion_x, motion_y, dest, offset, 1429 motion_block (mc_functions.avg, offset, picture->v_offset, 0, 0, 0,
1410 motion->ref[!picture->current_field], offset, stride, 16, 0); 1430 motion_x, motion_y,
1431 dest, motion->ref[!picture->current_field], stride, 16);
1411 #undef bit_buf 1432 #undef bit_buf
1412 #undef bits 1433 #undef bits
1413 #undef bit_ptr 1434 #undef bit_ptr
1414 } 1435 }
1415 1436
1416 static void motion_fi_reuse (picture_t * picture, motion_t * motion, 1437 static void motion_fi_reuse (picture_t * picture, motion_t * motion,
1417 uint8_t * dest[3], int offset, int stride, 1438 uint8_t * dest[3], int offset, int stride,
1418 void (** table) (uint8_t *, uint8_t *, int, int)) 1439 void (** table) (uint8_t *, uint8_t *, int, int))
1419 { 1440 {
1420 motion_block (table, motion->pmv[0][0], motion->pmv[0][1], dest, offset, 1441 motion_block (table, offset, picture->v_offset, 0, 0, 0,
1421 motion->ref[picture->current_field], offset, stride, 16, 0); 1442 motion->pmv[0][0], motion->pmv[0][1],
1443 dest, motion->ref[picture->current_field], stride, 16);
1422 } 1444 }
1423 1445
1424 static void motion_fi_zero (picture_t * picture, motion_t * motion, 1446 static void motion_fi_zero (picture_t * picture, motion_t * motion,
1425 uint8_t * dest[3], int offset, int stride, 1447 uint8_t * dest[3], int offset, int stride,
1426 void (** table) (uint8_t *, uint8_t *, int, int)) 1448 void (** table) (uint8_t *, uint8_t *, int, int))
1427 { 1449 {
1428 motion_block (table, 0, 0, dest, offset, 1450 motion_block (table, offset, picture->v_offset, 0, 0, 0, 0, 0,
1429 motion->ref[picture->current_field], offset, stride, 16, 0); 1451 dest, motion->ref[picture->current_field], stride, 16);
1430 } 1452 }
1431 1453
1432 static void motion_fi_conceal (picture_t * picture) 1454 static void motion_fi_conceal (picture_t * picture)
1433 { 1455 {
1434 #define bit_buf (picture->bitstream_buf) 1456 #define bit_buf (picture->bitstream_buf)
1469 } while (0) 1491 } while (0)
1470 1492
1471 #define CHECK_DISPLAY \ 1493 #define CHECK_DISPLAY \
1472 do { \ 1494 do { \
1473 if (offset == picture->coded_picture_width) { \ 1495 if (offset == picture->coded_picture_width) { \
1474 picture->f_motion.ref[0][0] += 16 * stride; \
1475 picture->f_motion.ref[0][1] += 4 * stride; \
1476 picture->f_motion.ref[0][2] += 4 * stride; \
1477 picture->b_motion.ref[0][0] += 16 * stride; \
1478 picture->b_motion.ref[0][1] += 4 * stride; \
1479 picture->b_motion.ref[0][2] += 4 * stride; \
1480 do { /* just so we can use the break statement */ \ 1496 do { /* just so we can use the break statement */ \
1481 if (picture->current_frame->copy) { \ 1497 if (picture->current_frame->copy) { \
1482 picture->current_frame->copy (picture->current_frame, \ 1498 picture->current_frame->copy (picture->current_frame, \
1483 dest); \ 1499 dest); \
1484 if (picture->picture_coding_type == B_TYPE) \ 1500 if (picture->picture_coding_type == B_TYPE) \
1486 } \ 1502 } \
1487 dest[0] += 16 * stride; \ 1503 dest[0] += 16 * stride; \
1488 dest[1] += 4 * stride; \ 1504 dest[1] += 4 * stride; \
1489 dest[2] += 4 * stride; \ 1505 dest[2] += 4 * stride; \
1490 } while (0); \ 1506 } while (0); \
1507 if (! (picture->mpeg1)) \
1508 return 0; \
1509 picture->v_offset += 16; \
1510 if (picture->v_offset >= picture->coded_picture_height) \
1511 return 0; \
1491 offset = 0; ++code; \ 1512 offset = 0; ++code; \
1492 } \ 1513 } \
1493 } while (0) 1514 } while (0)
1494 1515
1495 int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer) 1516 int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer)
1503 int offset; 1524 int offset;
1504 uint8_t ** forward_ref[2]; 1525 uint8_t ** forward_ref[2];
1505 1526
1506 stride = picture->coded_picture_width; 1527 stride = picture->coded_picture_width;
1507 offset = (code - 1) * stride * 4; 1528 offset = (code - 1) * stride * 4;
1529 picture->v_offset = (code - 1) * 16;
1508 1530
1509 forward_ref[0] = picture->forward_reference_frame->base; 1531 forward_ref[0] = picture->forward_reference_frame->base;
1510 if (picture->picture_structure != FRAME_PICTURE) { 1532 if (picture->picture_structure != FRAME_PICTURE) {
1533 forward_ref[1] = picture->forward_reference_frame->base;
1511 offset <<= 1; 1534 offset <<= 1;
1512 forward_ref[1] = picture->forward_reference_frame->base;
1513 picture->current_field = (picture->picture_structure == BOTTOM_FIELD); 1535 picture->current_field = (picture->picture_structure == BOTTOM_FIELD);
1514 if ((picture->second_field) && 1536 if ((picture->second_field) &&
1515 (picture->picture_coding_type != B_TYPE)) 1537 (picture->picture_coding_type != B_TYPE))
1516 forward_ref[picture->picture_structure == TOP_FIELD] = 1538 forward_ref[picture->picture_structure == TOP_FIELD] =
1517 picture->current_frame->base; 1539 picture->current_frame->base;
1518 picture->f_motion.ref[1][0] = forward_ref[1][0] + offset * 4 + stride; 1540
1519 picture->f_motion.ref[1][1] = 1541 picture->f_motion.ref[1][0] = forward_ref[1][0] + stride;
1520 forward_ref[1][1] + offset + (stride >> 1); 1542 picture->f_motion.ref[1][1] = forward_ref[1][1] + (stride >> 1);
1521 picture->f_motion.ref[1][2] = 1543 picture->f_motion.ref[1][2] = forward_ref[1][2] + (stride >> 1);
1522 forward_ref[1][2] + offset + (stride >> 1); 1544
1523 picture->b_motion.ref[1][0] = 1545 picture->b_motion.ref[1][0] =
1524 picture->backward_reference_frame->base[0] + offset * 4 + stride; 1546 picture->backward_reference_frame->base[0] + stride;
1525 picture->b_motion.ref[1][1] = 1547 picture->b_motion.ref[1][1] =
1526 (picture->backward_reference_frame->base[1] + 1548 picture->backward_reference_frame->base[1] + (stride >> 1);
1527 offset + (stride >> 1));
1528 picture->b_motion.ref[1][2] = 1549 picture->b_motion.ref[1][2] =
1529 (picture->backward_reference_frame->base[2] + 1550 picture->backward_reference_frame->base[2] + (stride >> 1);
1530 offset + (stride >> 1));
1531 } 1551 }
1532 1552
1533 picture->f_motion.ref[0][0] = forward_ref[0][0] + offset * 4; 1553 picture->f_motion.ref[0][0] = forward_ref[0][0];
1534 picture->f_motion.ref[0][1] = forward_ref[0][1] + offset; 1554 picture->f_motion.ref[0][1] = forward_ref[0][1];
1535 picture->f_motion.ref[0][2] = forward_ref[0][2] + offset; 1555 picture->f_motion.ref[0][2] = forward_ref[0][2];
1536 picture->f_motion.f_code[0] = picture->f_code[0][0]; 1556
1537 picture->f_motion.f_code[1] = picture->f_code[0][1];
1538 picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0; 1557 picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0;
1539 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0; 1558 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0;
1540 picture->b_motion.ref[0][0] = 1559
1541 picture->backward_reference_frame->base[0] + offset * 4; 1560 picture->b_motion.ref[0][0] = picture->backward_reference_frame->base[0];
1542 picture->b_motion.ref[0][1] = 1561 picture->b_motion.ref[0][1] = picture->backward_reference_frame->base[1];
1543 picture->backward_reference_frame->base[1] + offset; 1562 picture->b_motion.ref[0][2] = picture->backward_reference_frame->base[2];
1544 picture->b_motion.ref[0][2] = 1563
1545 picture->backward_reference_frame->base[2] + offset;
1546 picture->b_motion.f_code[0] = picture->f_code[1][0];
1547 picture->b_motion.f_code[1] = picture->f_code[1][1];
1548 picture->b_motion.pmv[0][0] = picture->b_motion.pmv[0][1] = 0; 1564 picture->b_motion.pmv[0][0] = picture->b_motion.pmv[0][1] = 0;
1549 picture->b_motion.pmv[1][0] = picture->b_motion.pmv[1][1] = 0; 1565 picture->b_motion.pmv[1][0] = picture->b_motion.pmv[1][1] = 0;
1550 1566
1551 if ((picture->current_frame->copy) && 1567 if ((picture->current_frame->copy) &&
1552 (picture->picture_coding_type == B_TYPE)) 1568 (picture->picture_coding_type == B_TYPE))
1564 /* follow thru */ 1580 /* follow thru */
1565 case TOP_FIELD: 1581 case TOP_FIELD:
1566 stride <<= 1; 1582 stride <<= 1;
1567 } 1583 }
1568 1584
1569 /* reset intra dc predictor */
1570 picture->dc_dct_pred[0] = picture->dc_dct_pred[1] = 1585 picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
1571 picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision + 7); 1586 picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision + 7);
1572 1587
1573 bitstream_init (picture, buffer); 1588 bitstream_init (picture, buffer);
1574 1589
1615 } else { 1630 } else {
1616 DCT_offset = stride * 8; 1631 DCT_offset = stride * 8;
1617 DCT_stride = stride; 1632 DCT_stride = stride;
1618 } 1633 }
1619 1634
1620 /* Decode lum blocks */
1621 slice_intra_DCT (picture, 0, dest[0] + offset, DCT_stride); 1635 slice_intra_DCT (picture, 0, dest[0] + offset, DCT_stride);
1622 slice_intra_DCT (picture, 0, dest[0] + offset + 8, DCT_stride); 1636 slice_intra_DCT (picture, 0, dest[0] + offset + 8, DCT_stride);
1623 slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset, 1637 slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset,
1624 DCT_stride); 1638 DCT_stride);
1625 slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset + 8, 1639 slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset + 8,
1626 DCT_stride); 1640 DCT_stride);
1627 1641
1628 /* Decode chroma blocks */
1629 slice_intra_DCT (picture, 1, dest[1] + (offset >> 1), stride >> 1); 1642 slice_intra_DCT (picture, 1, dest[1] + (offset >> 1), stride >> 1);
1630 slice_intra_DCT (picture, 2, dest[2] + (offset >> 1), stride >> 1); 1643 slice_intra_DCT (picture, 2, dest[2] + (offset >> 1), stride >> 1);
1631 1644
1632 if (picture->picture_coding_type == D_TYPE) { 1645 if (picture->picture_coding_type == D_TYPE) {
1633 NEEDBITS (bit_buf, bits, bit_ptr); 1646 NEEDBITS (bit_buf, bits, bit_ptr);
1691 picture->f_motion.pmv[1][1] = 0; 1704 picture->f_motion.pmv[1][1] = 0;
1692 MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD); 1705 MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD);
1693 break; 1706 break;
1694 } 1707 }
1695 1708
1696 /* 6.3.17.4 Coded block pattern */
1697 if (macroblock_modes & MACROBLOCK_PATTERN) { 1709 if (macroblock_modes & MACROBLOCK_PATTERN) {
1698 int coded_block_pattern; 1710 int coded_block_pattern;
1699 int DCT_offset, DCT_stride; 1711 int DCT_offset, DCT_stride;
1700 1712
1701 if (macroblock_modes & DCT_TYPE_INTERLACED) { 1713 if (macroblock_modes & DCT_TYPE_INTERLACED) {
1705 DCT_offset = stride * 8; 1717 DCT_offset = stride * 8;
1706 DCT_stride = stride; 1718 DCT_stride = stride;
1707 } 1719 }
1708 1720
1709 coded_block_pattern = get_coded_block_pattern (picture); 1721 coded_block_pattern = get_coded_block_pattern (picture);
1710
1711 /* Decode lum blocks */
1712 1722
1713 if (coded_block_pattern & 0x20) 1723 if (coded_block_pattern & 0x20)
1714 slice_non_intra_DCT (picture, dest[0] + offset, 1724 slice_non_intra_DCT (picture, dest[0] + offset,
1715 DCT_stride); 1725 DCT_stride);
1716 if (coded_block_pattern & 0x10) 1726 if (coded_block_pattern & 0x10)
1723 if (coded_block_pattern & 0x04) 1733 if (coded_block_pattern & 0x04)
1724 slice_non_intra_DCT (picture, 1734 slice_non_intra_DCT (picture,
1725 dest[0] + offset + DCT_offset + 8, 1735 dest[0] + offset + DCT_offset + 8,
1726 DCT_stride); 1736 DCT_stride);
1727 1737
1728 /* Decode chroma blocks */
1729
1730 if (coded_block_pattern & 0x2) 1738 if (coded_block_pattern & 0x2)
1731 slice_non_intra_DCT (picture, dest[1] + (offset >> 1), 1739 slice_non_intra_DCT (picture, dest[1] + (offset >> 1),
1732 stride >> 1); 1740 stride >> 1);
1733 if (coded_block_pattern & 0x1) 1741 if (coded_block_pattern & 0x1)
1734 slice_non_intra_DCT (picture, dest[2] + (offset >> 1), 1742 slice_non_intra_DCT (picture, dest[2] + (offset >> 1),
1754 1762
1755 mba_inc = get_macroblock_address_increment (picture); 1763 mba_inc = get_macroblock_address_increment (picture);
1756 if (!mba_inc) 1764 if (!mba_inc)
1757 break; 1765 break;
1758 1766
1759 /* reset intra dc predictor on skipped block */
1760 picture->dc_dct_pred[0] = picture->dc_dct_pred[1] = 1767 picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
1761 picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision+7); 1768 picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision+7);
1762 1769
1763 /* handling of skipped mb's differs between P_TYPE and B_TYPE */
1764 /* pictures */
1765 if (picture->picture_coding_type == P_TYPE) { 1770 if (picture->picture_coding_type == P_TYPE) {
1766 picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0; 1771 picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0;
1767 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0; 1772 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0;
1768 1773
1769 do { 1774 do {