38 int scaledvalue, refdist;
39 int scalesame1, scalesame2;
40 int scalezone1_x, zone1offset_x;
57 if (
FFABS(n) < scalezone1_x)
58 scaledvalue = (n * scalesame1) >> 8;
61 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_x;
63 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_x;
71 int scaledvalue, refdist;
72 int scalesame1, scalesame2;
73 int scalezone1_y, zone1offset_y;
90 if (
FFABS(n) < scalezone1_y)
91 scaledvalue = (n * scalesame1) >> 8;
94 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_y;
96 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_y;
108 int scalezone1_x, zone1offset_x;
109 int scaleopp1, scaleopp2, brfd;
121 if (
FFABS(n) < scalezone1_x)
122 scaledvalue = (n * scaleopp1) >> 8;
125 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_x;
127 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_x;
135 int scalezone1_y, zone1offset_y;
136 int scaleopp1, scaleopp2, brfd;
148 if (
FFABS(n) < scalezone1_y)
149 scaledvalue = (n * scaleopp1) >> 8;
152 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_y;
154 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_y;
181 n = (n * scalesame >> 8) * (1 << hpel);
188 int refdist, scaleopp;
203 refdist =
FFMIN(refdist, 3);
206 n = (n * scaleopp >> 8) * (1 << hpel);
213 int mv1,
int r_x,
int r_y,
uint8_t* is_intra,
214 int pred_flag,
int dir)
217 int xy,
wrap, off = 0;
221 int mixedmv_pic, num_samefield = 0, num_oppfield = 0;
222 int opposite, a_f, b_f, c_f;
223 int16_t field_predA[2];
224 int16_t field_predB[2];
225 int16_t field_predC[2];
226 int a_valid, b_valid, c_valid;
227 int hybridmv_thresh, y_bias = 0;
277 off = (s->
mb_x > 0) ? -1 : 1;
292 b_valid = a_valid && (s->
mb_width > 1);
293 c_valid = s->
mb_x || (n == 1 || n == 3);
295 a_valid = a_valid && !is_intra[xy -
wrap];
296 b_valid = b_valid && !is_intra[xy - wrap + off];
297 c_valid = c_valid && !is_intra[xy - 1];
303 num_samefield += 1 - a_f;
304 field_predA[0] = A[0];
305 field_predA[1] = A[1];
307 field_predA[0] = field_predA[1] = 0;
313 num_samefield += 1 - b_f;
314 field_predB[0] = B[0];
315 field_predB[1] = B[1];
317 field_predB[0] = field_predB[1] = 0;
323 num_samefield += 1 - c_f;
324 field_predC[0] = C[0];
325 field_predC[1] = C[1];
327 field_predC[0] = field_predC[1] = 0;
337 if (num_samefield <= num_oppfield)
338 opposite = 1 - pred_flag;
340 opposite = pred_flag;
345 if (a_valid && !a_f) {
346 field_predA[0] =
scaleforopp(v, field_predA[0], 0, dir);
347 field_predA[1] =
scaleforopp(v, field_predA[1], 1, dir);
349 if (b_valid && !b_f) {
350 field_predB[0] =
scaleforopp(v, field_predB[0], 0, dir);
351 field_predB[1] =
scaleforopp(v, field_predB[1], 1, dir);
353 if (c_valid && !c_f) {
354 field_predC[0] =
scaleforopp(v, field_predC[0], 0, dir);
355 field_predC[1] =
scaleforopp(v, field_predC[1], 1, dir);
360 if (a_valid && a_f) {
361 field_predA[0] =
scaleforsame(v, n, field_predA[0], 0, dir);
362 field_predA[1] =
scaleforsame(v, n, field_predA[1], 1, dir);
364 if (b_valid && b_f) {
365 field_predB[0] =
scaleforsame(v, n, field_predB[0], 0, dir);
366 field_predB[1] =
scaleforsame(v, n, field_predB[1], 1, dir);
368 if (c_valid && c_f) {
369 field_predC[0] =
scaleforsame(v, n, field_predC[0], 0, dir);
370 field_predC[1] =
scaleforsame(v, n, field_predC[1], 1, dir);
379 }
else if (c_valid) {
382 }
else if (b_valid) {
390 if (num_samefield + num_oppfield > 1) {
391 px =
mid_pred(field_predA[0], field_predB[0], field_predC[0]);
392 py =
mid_pred(field_predA[1], field_predB[1], field_predC[1]);
398 int MV = mv1 ? -60 : -28;
399 qx = (s->
mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0);
400 qy = (s->
mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0);
403 if (qx + px < MV) px = MV - qx;
404 if (qy + py < MV) py = MV - qy;
405 if (qx + px > X) px = X - qx;
406 if (qy + py > Y) py = Y - qy;
411 hybridmv_thresh = 32;
412 if (a_valid && c_valid) {
413 if (is_intra[xy - wrap])
416 sum =
FFABS(px - field_predA[0]) +
FFABS(py - field_predA[1]);
417 if (sum > hybridmv_thresh) {
426 if (is_intra[xy - 1])
429 sum =
FFABS(px - field_predC[0]) +
FFABS(py - field_predC[1]);
430 if (sum > hybridmv_thresh) {
465 int mvn,
int r_x,
int r_y,
uint8_t* is_intra,
int dir)
468 int xy,
wrap, off = 0;
469 int A[2],
B[2],
C[2];
471 int a_valid = 0, b_valid = 0, c_valid = 0;
472 int field_a, field_b, field_c;
473 int total_valid, num_samefield, num_oppfield;
474 int pos_c, pos_b, n_adj;
502 off = ((n == 0) || (n == 1)) ? 1 : -1;
504 if (s->
mb_x || (n == 1) || (n == 3)) {
524 B[0] = B[1] = C[0] = C[1] = 0;
532 n_adj = (n & 2) | (n & 1);
586 total_valid = a_valid + b_valid + c_valid;
588 if (!s->
mb_x && !(n == 1 || n == 3)) {
593 B[0] = B[1] = C[0] = C[1] = 0;
600 if (total_valid >= 2) {
603 }
else if (total_valid) {
604 if (a_valid) { px = A[0]; py = A[1]; }
605 else if (b_valid) { px = B[0]; py = B[1]; }
606 else { px = C[0]; py = C[1]; }
611 field_a = (A[1] & 4) ? 1 : 0;
615 field_b = (B[1] & 4) ? 1 : 0;
619 field_c = (C[1] & 4) ? 1 : 0;
623 num_oppfield = field_a + field_b + field_c;
624 num_samefield = total_valid - num_oppfield;
625 if (total_valid == 3) {
626 if ((num_samefield == 3) || (num_oppfield == 3)) {
629 }
else if (num_samefield >= num_oppfield) {
632 px = !field_a ? A[0] : B[0];
633 py = !field_a ? A[1] : B[1];
635 px = field_a ? A[0] : B[0];
636 py = field_a ? A[1] : B[1];
638 }
else if (total_valid == 2) {
639 if (num_samefield >= num_oppfield) {
640 if (!field_a && a_valid) {
643 }
else if (!field_b && b_valid) {
652 if (field_a && a_valid) {
661 }
else if (total_valid == 1) {
662 px = (a_valid) ? A[0] : ((b_valid) ? B[0] : C[0]);
663 py = (a_valid) ? A[1] : ((b_valid) ? B[1] : C[1]);
677 }
else if (mvn == 2) {
680 s->
mv[dir][n + 1][0] = s->
mv[dir][
n][0];
681 s->
mv[dir][n + 1][1] = s->
mv[dir][
n][1];
686 int direct,
int mvtype)
689 int xy,
wrap, off = 0;
727 s->
mv[0][0][0] = av_clip(s->
mv[0][0][0], -60 - (s->
mb_x << 6), (s->
mb_width << 6) - 4 - (s->
mb_x << 6));
728 s->
mv[0][0][1] = av_clip(s->
mv[0][0][1], -60 - (s->
mb_y << 6), (s->
mb_height << 6) - 4 - (s->
mb_y << 6));
729 s->
mv[1][0][0] = av_clip(s->
mv[1][0][0], -60 - (s->
mb_x << 6), (s->
mb_width << 6) - 4 - (s->
mb_x << 6));
730 s->
mv[1][0][1] = av_clip(s->
mv[1][0][1], -60 - (s->
mb_y << 6), (s->
mb_height << 6) - 4 - (s->
mb_y << 6));
745 if (!s->
mb_x) C[0] = C[1] = 0;
754 }
else if (s->
mb_x) {
764 int MV = 4 - (1 << sh);
765 qx = (s->
mb_x << sh);
766 qy = (s->
mb_y << sh);
769 if (qx + px < MV) px = MV - qx;
770 if (qy + py < MV) py = MV - qy;
771 if (qx + px > X) px = X - qx;
772 if (qy + py > Y) py = Y - qy;
776 if (is_intra[xy - wrap])
789 if (is_intra[xy - 2])
805 s->
mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
806 s->
mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
824 }
else if (s->
mb_x) {
834 int MV = 4 - (1 << sh);
835 qx = (s->
mb_x << sh);
836 qy = (s->
mb_y << sh);
839 if (qx + px < MV) px = MV - qx;
840 if (qy + py < MV) py = MV - qy;
841 if (qx + px > X) px = X - qx;
842 if (qy + py > Y) py = Y - qy;
846 if (is_intra[xy - wrap])
859 if (is_intra[xy - 2])
876 s->
mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
877 s->
mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
886 int mv1,
int *pred_flag)
908 f = (total_opp > 2) ? 1 : 0;
910 s->
mv[0][0][0] = s->
mv[0][0][1] = 0;
911 s->
mv[1][0][0] = s->
mv[1][0][1] = 0;
915 for (k = 0; k < 4; k++) {
void ff_vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y, int mv1, int r_x, int r_y, uint8_t *is_intra, int pred_flag, int dir)
Predict and set motion vector.
int reffield
if numref = 0 (1 reference) then reffield decides which
static av_always_inline int scaleforopp_x(VC1Context *v, int n)
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_always_inline int scaleforsame(VC1Context *v, int i, int n, int dim, int dir)
int field_picture
whether or not the picture was encoded in separate fields
uint8_t * mv_f[2]
0: MV obtained from same field, 1: opposite field
const uint16_t ff_vc1_b_field_mvpred_scales[7][4]
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int refdist
distance of the current picture from reference
void ff_vc1_pred_b_mv_intfi(VC1Context *v, int n, int *dmv_x, int *dmv_y, int mv1, int *pred_flag)
static av_always_inline int scaleforopp_y(VC1Context *v, int n, int dir)
Picture current_picture
copy of the current picture structure.
int16_t bfraction
Relative position % anchors=> how to scale MVs.
int profile
Sequence header data for all Profiles TODO: choose between ints, uint8_ts and monobit flags...
int mb_height
number of MBs horizontally & vertically
static av_always_inline int scaleforsame_y(VC1Context *v, int i, int n, int dir)
int quarter_sample
1->qpel, 0->half pel ME/MC
uint8_t * blk_mv_type
0: frame MV, 1: field MV (interlaced frame)
int cur_field_type
0: top, 1: bottom
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int field_mode
1 for interlaced field pictures
uint8_t mv_mode
Frame decoding info for all profiles.
int16_t(*[2] motion_val)[2]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
const uint16_t ff_vc1_field_mvpred_scales[2][7][4]
int block_index[6]
index to current MB in block based arrays with edges
int first_slice_line
used in MPEG-4 too to handle resync markers
static av_always_inline int scaleforsame_x(VC1Context *v, int n, int dir)
void ff_vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mvtype)
static unsigned int get_bits1(GetBitContext *s)
int ref_field_type[2]
forward and backward reference field type (top or bottom)
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
int numref
number of past field pictures used as reference
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
int b8_stride
2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
Picture * next_picture_ptr
pointer to the next picture (for bidir pred)
struct AVCodecContext * avctx
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
void ff_vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y, int mvn, int r_x, int r_y, uint8_t *is_intra, int dir)
Predict and set motion vector for interlaced frame picture MBs.
Picture next_picture
copy of the next picture structure.
int brfd
reference frame distance (forward or backward)
uint32_t * mb_type
types and macros are defined in mpegutils.h
uint8_t mv_mode2
Secondary MV coding mode (B-frames)
static av_always_inline int scaleforopp(VC1Context *v, int n, int dim, int dir)