diff --git a/src/global.h b/src/global.h index 463835b2..89ef57f4 100644 --- a/src/global.h +++ b/src/global.h @@ -47,6 +47,7 @@ #define MIN(a,b) (((a)<(b))?(a):(b)) #define CLIP(low,high,value) MAX((low),MIN((high),(value))) #define SWAP(a,b,swaptype) { swaptype tempval; tempval = a; a = b; b = tempval; } +#define LCU_WIDTH_FROM_DEPTH(depth) (LCU_WIDTH >> depth) #define VERSION_STRING "0.2 " #define VERSION 0.2 diff --git a/src/picture.c b/src/picture.c index 9a25b653..9e667998 100644 --- a/src/picture.c +++ b/src/picture.c @@ -436,23 +436,6 @@ uint32_t Hadamard8x8(int16_t *piOrg, int32_t iStrideOrg, int16_t *piCur, int32_t return sad; } - -//Sum of Absolute Difference for block -uint32_t SAD(uint8_t *block,uint8_t* block2, uint32_t x, uint32_t y) -{ - uint32_t i; - uint32_t sum=0; - for(i=0;idepth); + unsigned block_height = block_width; + + // TODO: Inter: Calculating error outside picture borders. + // This prevents choosing vectors that need interpolating of borders to work. + if (x < 0 || y < 0 || x < pic->width - LCU_WIDTH || pic->height - LCU_WIDTH) return; + + cur_cu->inter.mv[0] = x; + cur_cu->inter.mv[1] = y; + cur_cu->inter.cost = SAD(pic_data, &ref_data[y * pic->width + x], block_width, block_height, pic->width); + + step /= 2; + if (step > 0) { + search_motion_vector(pic, pic_data, ref_data, cur_cu, step, x, y - step); + search_motion_vector(pic, pic_data, ref_data, cur_cu, step, x - step, y); + search_motion_vector(pic, pic_data, ref_data, cur_cu, step, x + step, y); + search_motion_vector(pic, pic_data, ref_data, cur_cu, step, x, y + step); + } +} + void search_buildReferenceBorder(picture* pic, int32_t xCtb, int32_t yCtb,int16_t outwidth, int16_t* dst, int32_t dststride, int8_t chroma) { int32_t leftColumn; /*!< left column iterator */ @@ -165,14 +197,17 @@ void search_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, uint8_t d } - cur_CU->type = CU_INTER; - cur_CU->inter.mv[0] = 0<<2; - cur_CU->inter.mv[1] = 0<<2; - if(xCtb == 0 && yCtb == 0) { - cur_CU->inter.mv[1] = 0<<2; + unsigned mv[2] = { 0, 0 }; // TODO: Take initial MV from adjacent blocks. + picture *cur_pic = encoder->in.cur_pic; + uint8_t *cur_data = &cur_pic->yData[(mv[1] * cur_pic->width) + mv[0]]; + + picture *ref_pic = encoder->ref->pics[0]; + + search_motion_vector(cur_pic, cur_data, ref_pic->yData, cur_CU, cur_pic->width >> 1, mv[0], mv[1]); } - cur_CU->inter.cost = 10; + + cur_CU->type = CU_INTER; cur_CU->inter.mv_dir = 1; inter_setBlockMode(encoder->in.cur_pic,xCtb,yCtb,depth,cur_CU); } @@ -291,4 +326,4 @@ void search_slice_data(encoder_control* encoder) search_best_mode(encoder, xCtb<