📄 inter_test.c
字号:
/*****************************************************************************
*
* T264 AVC CODEC
*
* Copyright(C) 2004-2005 llcc <lcgate1@yahoo.com.cn>
* 2004-2005 visionany <visionany@yahoo.com.cn>
*
* llcc 2004-9-23
*
* Test for sub-pel search after integer pel search in mode dicision(call mode1)
* vs only integer search in mode dicision in orgin design(call mode2).
* test result(jm80 have modified to conform to our condition):
* (1I + 299P), foreman.cif, qp = 30, no i16x16
* 8x16(bytes) 16x8(bytes)
* jm80 743430 750905
* t264 746615 756162
* (mode1+spiral full search)
* t264 745866 755622
* (mode2+spiral full search)
* t264 792700 801691
* (mode1+pmvfast)
* t264 793219 804540
* (mode2+pmvfast)
* NOTE: if u want to test this file, please change pred_p16x16[16 * 16] in t264.h
* to pred_p16x16[4][16 * 16].
* Yes, we will keep our older design.
*
* This program is free software ; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
****************************************************************************/
#include "stdio.h"
#include "memory.h"
#include "T264.h"
#include "inter.h"
#include "intra.h"
#include "estimation.h"
#include "utility.h"
#include "interpolate.h"
void
T264_predict_mv(T264_t* t, int32_t list, int32_t i, int32_t width, T264_vector_t* vec)
{
int32_t n;
int32_t count = 0;
int32_t idx;
int32_t row;
int32_t col;
int32_t org;
T264_vector_t vec_n[3];
n = vec->refno;
org = i;
i = luma_index[i];
col = org % 4;
row = org / 4;
vec_n[0] = t->mb.vec_ref[VEC_LUMA - 1 + row * 8 + col].vec;
vec_n[1] = t->mb.vec_ref[VEC_LUMA - 8 + row * 8 + col].vec;
vec_n[2] = t->mb.vec_ref[VEC_LUMA - 8 + row * 8 + col + width].vec;
if (vec_n[2].refno == -2)
{
vec_n[2] = t->mb.vec_ref[VEC_LUMA - 8 + row * 8 + col - 1].vec;
}
if (((i & 3) == 3) || ((i & 3) == 2 && width == 2))
{
vec_n[2] = t->mb.vec_ref[VEC_LUMA - 8 + row * 8 + col - 1].vec;
}
if (t->mb.mb_part == MB_16x8)
{
if (i == 0 && n == vec_n[1].refno)
{
vec[0] = vec_n[1];
return;
}
else if (i != 0 && n == vec_n[0].refno)
{
vec[0] = vec_n[0];
return;
}
}
else if (t->mb.mb_part == MB_8x16)
{
if (i == 0 && n == vec_n[0].refno)
{
vec[0] = vec_n[0];
return;
}
else if (i != 0 && n == vec_n[2].refno)
{
vec[0] = vec_n[2];
return;
}
}
if (vec_n[0].refno == n)
{
count ++;
idx = 0;
}
if (vec_n[1].refno == n)
{
count ++;
idx = 1;
}
if (vec_n[2].refno == n)
{
count ++;
idx = 2;
}
if (count > 1)
{
vec[0].x = T264_median(vec_n[0].x, vec_n[1].x, vec_n[2].x);
vec[0].y = T264_median(vec_n[0].y, vec_n[1].y, vec_n[2].y);
return;
}
else if (count == 1)
{
vec[0] = vec_n[idx];
return;
}
else if (vec_n[1].refno == -2 && vec_n[2].refno == -2 && vec_n[0].refno != -2)
{
vec[0] = vec_n[0];
}
else
{
vec[0].x = T264_median(vec_n[0].x, vec_n[1].x, vec_n[2].x);
vec[0].y = T264_median(vec_n[0].y, vec_n[1].y, vec_n[2].y);
return;
}
}
int32_t
T264_median(int32_t x, int32_t y, int32_t z)
{
int32_t min, max;
if (x < y)
{
min = x;
max = y;
}
else
{
min = y;
max = x;
}
if (z < min)
{
min = z;
}
else if (z > max)
{
max = z;
}
return x + y + z - min - max;
}
void
copy_nvec(T264_vector_t* src, T264_vector_t* dst, int32_t width, int32_t height, int32_t stride)
{
int32_t i, j;
for(i = 0 ; i < height ; i ++)
{
for(j = 0 ; j < width ; j ++)
{
dst[j] = src[0];
}
dst += stride;
}
}
void
T264_inter_p16x16_mode_available(T264_t* t, int32_t preds[], int32_t* modes)
{
if (t->flags & USE_FORCEBLOCKSIZE)
{
*modes = 0;
if (t->param.block_size & SEARCH_16x16P)
preds[(*modes) ++] = MB_16x16;
if (t->param.block_size & SEARCH_16x8P)
preds[(*modes) ++] = MB_16x8;
if (t->param.block_size & SEARCH_8x16P)
preds[(*modes) ++] = MB_8x16;
return ;
}
if ((t->mb.mb_neighbour & (MB_LEFT | MB_TOP)) == (MB_LEFT | MB_TOP))
{
*modes = 0;
preds[(*modes) ++] = MB_16x16;
if (t->mb.vec_ref[VEC_LUMA - 1].part == MB_16x8)
{
preds[(*modes) ++] = MB_16x8;
}
if (t->mb.vec_ref[VEC_LUMA - 8].part == MB_8x16)
{
preds[(*modes) ++] = MB_8x16;
}
}
else
{
// try all
preds[0] = MB_16x16;
preds[1] = MB_16x8;
preds[2] = MB_8x16;
*modes = 3;
}
}
void
T264_inter_p8x8_mode_available(T264_t* t, int32_t preds[], int32_t* modes, int32_t sub_no)
{
static const int32_t neighbour[] =
{
0, MB_LEFT, MB_TOP, MB_LEFT| MB_TOP
};
int32_t mb_neighbour = t->mb.mb_neighbour| neighbour[sub_no];
if (t->flags & USE_FORCEBLOCKSIZE)
{
*modes = 0;
if (t->param.block_size & SEARCH_8x8P)
preds[(*modes) ++] = MB_8x8;
if (t->param.block_size & SEARCH_8x4P)
preds[(*modes) ++] = MB_8x4;
if (t->param.block_size & SEARCH_4x8P)
preds[(*modes) ++] = MB_4x8;
if (t->param.block_size & SEARCH_4x4P)
preds[(*modes) ++] = MB_4x4;
return ;
}
if ((mb_neighbour & (MB_LEFT | MB_TOP)) == (MB_LEFT | MB_TOP))
{
*modes = 0;
preds[*modes ++] = MB_8x8;
if (t->mb.vec_ref[VEC_LUMA - 8 + sub_no / 2 * 16 + sub_no % 2 * 4].part == MB_8x4)
{
preds[*modes ++] = MB_8x4;
}
if (t->mb.vec_ref[VEC_LUMA - 1 + sub_no / 2 * 16 + sub_no % 2 * 4].part == MB_4x8)
{
preds[*modes ++] = MB_4x8;
}
if (t->mb.vec_ref[VEC_LUMA - 8 + sub_no / 2 * 16 + sub_no % 2 * 4].part == MB_4x4 ||
t->mb.vec_ref[VEC_LUMA - 1 + sub_no / 2 * 16 + sub_no % 2 * 4].part == MB_4x4)
{
preds[*modes ++] = MB_4x4;
}
}
else
{
// try all
preds[0] = MB_8x8;
preds[1] = MB_8x4;
preds[2] = MB_4x8;
preds[3] = MB_4x4;
*modes = 4;
}
}
uint32_t
T264_mode_decision_inter_y(_RW T264_t* t)
{
uint32_t sad;
uint32_t sad_min = -1;
uint8_t best_mode;
uint8_t part;
int32_t i, n;
int32_t preds[7];
int32_t modes;
search_data_t s0;
subpart_search_data_t s1;
T264_vector_t vec_bak[16 * 16];
typedef uint32_t (*p16x16_function_t)(T264_t*, search_data_t* s);
static p16x16_function_t p16x16_function[] =
{
T264_mode_decision_inter_16x16p,
T264_mode_decision_inter_16x8p,
T264_mode_decision_inter_8x16p
};
T264_inter_p16x16_mode_available(t, preds, &modes);
best_mode = P_L0;
//SKIP
/* if(modes > 0)
{
sad = p16x16_function[0](t, &s0);
if(t->mb.mb_mode == P_SKIP)
{
sad_min = sad;
return sad_min;
}
else
{
sad_min = sad;
part = 0;
}
}
*/
for(n = 0 ; n < modes ; n ++)
{
int32_t mode = preds[n];
memcpy(vec_bak, t->mb.vec, sizeof(vec_bak));
sad = p16x16_function[mode](t, &s0);
if (sad < sad_min)
{
part = mode;
sad_min = sad;
}
else
{
memcpy(t->mb.vec, vec_bak, sizeof(vec_bak));
}
}
if (t->flags & USE_SUBBLOCK)
{
uint32_t sub_sad_all = 0;
typedef uint32_t (*p8x8_function_t)(T264_t*, int32_t, subpart_search_data_t* s);
static p8x8_function_t p8x8_function[] =
{
T264_mode_decision_inter_8x8p,
T264_mode_decision_inter_8x8p,
T264_mode_decision_inter_8x4p,
T264_mode_decision_inter_4x8p,
T264_mode_decision_inter_4x4p
};
for(i = 0 ; i < 4 ; i ++)
{
uint32_t sub_sad;
uint32_t sub_sad_min = -1;
T264_inter_p8x8_mode_available(t, preds, &modes, i);
for(n = 0 ; n < modes ; n ++)
{
int32_t mode = preds[n];
T264_vector_t vec_bak[4];
vec_bak[0] = t->mb.vec[0][i / 2 * 8 + i % 2 * 2 + 0];
vec_bak[1] = t->mb.vec[0][i / 2 * 8 + i % 2 * 2 + 1];
vec_bak[2] = t->mb.vec[0][i / 2 * 8 + i % 2 * 2 + 4];
vec_bak[3] = t->mb.vec[0][i / 2 * 8 + i % 2 * 2 + 5];
sub_sad = p8x8_function[mode - MB_8x8](t, i, &s1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -