📄 estimation.c
字号:
// top
CHECK_CANDIDATE(0, -1, -stride_ref);
// top-right
CHECK_CANDIDATE(1, -1, -stride_ref + 1);
// bottom-left
CHECK_CANDIDATE(-1, 1, stride_ref - 1);
// bottom
CHECK_CANDIDATE(0, 1, stride_ref);
// bottom-right
CHECK_CANDIDATE(1, 1, stride_ref + 1);
}
mvx = better_mvx;
mvy = better_mvy;
ref_st = better_ref;
if (ABS(mvx) > limit_x || ABS(mvy) > limit_y)
{
break;
}
}
// final mv
context->vec_best.x = mvx << 2;
context->vec_best.y = mvy << 2;
// mostly we use sad as cmp function
if (t->cmp[context->mb_part] == t->sad[context->mb_part])
return sad;
ref = ref_st + mvy * stride_ref + mvx;
sad = t->cmp[context->mb_part](cur, stride_cur, ref, stride_ref) +
t->mb.lambda * (eg_size_se(t->bs, context->vec_best.x - context->vec[0].x) +
eg_size_se(t->bs, context->vec_best.y - context->vec[0].y));
return sad;
}
uint32_t
diamond_search(T264_t* t, uint8_t* cur, uint8_t* ref_st, T264_search_context_t* context, int32_t stride_cur, int32_t stride_ref, uint32_t sad)
{
int32_t limit_x = context->limit_x;
int32_t limit_y = context->limit_y;
//start mv
int32_t mvx = context->vec_best.x >> 2;
int32_t mvy = context->vec_best.y >> 2;
// sad for start mv
uint8_t* ref;
uint8_t* better_ref;
int32_t better_mvx;
int32_t better_mvy;
uint32_t cursad;
uint8_t stop = 0;
ref_st += mvy * stride_ref + mvx;
better_mvx = mvx;
better_mvy = mvy;
better_ref = ref_st;
// large diamond
while(!stop)
{
stop = 1;
// search 8 points of ldsp
{
// left
CHECK_CANDIDATE(-2, 0, -2);
// right
CHECK_CANDIDATE(2, 0, 2);
// top
CHECK_CANDIDATE(0, -2, -(stride_ref << 1));
// bottom
CHECK_CANDIDATE(0, 2, (stride_ref << 1));
// top-left
CHECK_CANDIDATE(-1, -1, -stride_ref - 1);
// top-right
CHECK_CANDIDATE(1, -1, -stride_ref + 1);
// bottom-left
CHECK_CANDIDATE(-1, 1, stride_ref - 1);
// bottom-right
CHECK_CANDIDATE(1, 1, stride_ref + 1);
}
mvx = better_mvx;
mvy = better_mvy;
ref_st = better_ref;
if (ABS(mvx) > limit_x || ABS(mvy) > limit_y)
{
break;
}
}
// small diamond
stop = 0;
while(!stop)
{
stop = 1;
// search 4 points of sdsp
{
// left
CHECK_CANDIDATE(-1, 0, -1);
// right
CHECK_CANDIDATE(1, 0, 1);
// top
CHECK_CANDIDATE(0, -1, -stride_ref);
// bottom
CHECK_CANDIDATE(0, 1, stride_ref);
}
mvx = better_mvx;
mvy = better_mvy;
ref_st = better_ref;
if (ABS(mvx) > limit_x || ABS(mvy) > limit_y)
{
break;
}
}
// final mv
context->vec_best.x = mvx << 2;
context->vec_best.y = mvy << 2;
// mostly we use sad as cmp function
if (t->cmp[context->mb_part] == t->sad[context->mb_part])
return sad;
ref = ref_st + mvy * stride_ref + mvx;
sad = t->cmp[context->mb_part](cur, stride_cur, ref, stride_ref) +
t->mb.lambda * (eg_size_se(t->bs, context->vec_best.x - context->vec[0].x) +
eg_size_se(t->bs, context->vec_best.y - context->vec[0].y));
return sad;
}
/*
* Full Search
*/
uint32_t
T264_search_full(T264_t* t, T264_search_context_t* context)
{
uint32_t sad;
uint32_t cursad;
int32_t i, j;
int16_t mb_xy = t->mb.mb_xy;
int16_t mb_x = t->mb.mb_x;
int16_t mb_y = t->mb.mb_y;
int32_t height = context->height;
int32_t width = context->width;
int32_t limit_x = context->limit_x;
int32_t limit_y = context->limit_y;
int32_t stride_cur = t->stride;
int32_t stride_ref = t->edged_stride;
int32_t list_index = context->list_index;
// start point of current and reference block
int32_t row = context->offset / t->edged_stride;
int32_t col = context->offset % t->edged_stride;
uint8_t* cur = t->cur.Y[0] + row * stride_cur + col;
uint8_t* ref_st = t->ref[list_index][0]->Y[0] + row * stride_ref + col;
uint8_t* ref;
context->vec_best.refno = 0;
// full search
sad = width * height * 255;
for(i = -limit_y + (context->vec[0].y >> 2); i <= (limit_y + (context->vec[0].y >> 2)) ; i++)
for(j = -limit_x + (context->vec[0].x >> 2); j <= (limit_x + (context->vec[0].x >> 2)) ; j++)
{
ref = ref_st + i * stride_ref + j;
cursad = t->sad[context->mb_part](cur, stride_cur, ref, stride_ref) +
t->mb.lambda * (eg_size_se(t->bs, (j << 2) - context->vec[0].x) +
eg_size_se(t->bs, (i << 2) - context->vec[0].y));
if(cursad < sad)
{
sad = cursad;
context->vec_best.y = i;
context->vec_best.x = j;
}
}
ref = ref_st + context->vec_best.y * stride_ref + context->vec_best.x;
context->vec_best.y <<= 2;
context->vec_best.x <<= 2;
sad = t->cmp[context->mb_part](cur, t->stride, ref, t->edged_stride) +
t->mb.lambda * (eg_size_se(t->bs, context->vec_best.x - context->vec[0].x) +
eg_size_se(t->bs, context->vec_best.y - context->vec[0].y));
return sad;
}
// xxx, never used, just for compare to jm80.
uint32_t
T264_spiral_search_full(T264_t* t, T264_search_context_t* context)
{
uint32_t sad;
uint32_t cursad;
int32_t i, j, k, l;
int16_t mb_xy = t->mb.mb_xy;
int16_t mb_x = t->mb.mb_x;
int16_t mb_y = t->mb.mb_y;
int32_t height = context->height;
int32_t width = context->width;
int32_t limit_x = context->limit_x;
int32_t limit_y = context->limit_y;
int32_t stride_cur = t->stride;
int32_t stride_ref = t->edged_stride;
int32_t list_index = context->list_index;
// start point of current and reference block
int32_t row = context->offset / t->edged_stride;
int32_t col = context->offset % t->edged_stride;
uint8_t* cur = t->cur.Y[0] + row * stride_cur + col;
uint8_t* ref_st = t->ref[list_index][context->vec[0].refno]->Y[0] + row * stride_ref + col;
uint8_t* ref;
int32_t spiral_search_x[33 * 33];
int32_t spiral_search_y[33 * 33];
context->vec_best.refno = context->vec[0].refno;
spiral_search_x[0] = spiral_search_y[0] = 0;
for (k=1, l=1; l<=T264_MAX(1,16); l++)
{
for (i=-l+1; i< l; i++)
{
spiral_search_x[k] = l; spiral_search_y[k++] = i;
spiral_search_x[k] = -l; spiral_search_y[k++] = i;
}
for (i=-l; i<=l; i++)
{
spiral_search_x[k] = i; spiral_search_y[k++] = l;
spiral_search_x[k] = i; spiral_search_y[k++] = -l;
}
}
// full search
sad = width * height * 255;
for(k = 0 ; k < 33 * 33 ; k ++)
{
i = (context->vec[0].y / 4) + spiral_search_y[k];
j = (context->vec[0].x / 4) + spiral_search_x[k];
ref = ref_st + i * stride_ref + j;
cursad = t->sad[context->mb_part](cur, stride_cur, ref, stride_ref) +
t->mb.lambda * (eg_size_se(t->bs, (j << 2) - context->vec[0].x) +
eg_size_se(t->bs, (i << 2) - context->vec[0].y));
if(cursad < sad)
{
sad = cursad;
context->vec_best.y = i;
context->vec_best.x = j;
}
}
ref = ref_st + context->vec_best.y * stride_ref + context->vec_best.x;
context->vec_best.y <<= 2;
context->vec_best.x <<= 2;
sad = t->cmp[context->mb_part](cur, t->stride, ref, t->edged_stride) +
t->mb.lambda * (eg_size_se(t->bs, context->vec_best.x - context->vec[0].x) +
eg_size_se(t->bs, context->vec_best.y - context->vec[0].y));
return sad;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -