diff --git a/src/encmain.c b/src/encmain.c index 4f3955a0..eab56eb6 100644 --- a/src/encmain.c +++ b/src/encmain.c @@ -214,6 +214,16 @@ PSNR[1]+=temp_PSNR[1]; PSNR[2]+=temp_PSNR[2]; } + + /* TODO: add more than one reference */ + + /* Remove the ref pic (if present) */ + picture_list_rem(encoder->ref, 0, 1); + /* Add current picture as reference */ + picture_list_add(encoder->ref, encoder->in.cur_pic); + /* Allocate new memory to current picture */ + encoder->in.cur_pic = picture_init(encoder->in.width, encoder->in.height, encoder->in.width_in_LCU, encoder->in.height_in_LCU); + encoder->frame++; } /* Coding finished */ diff --git a/src/encoder.c b/src/encoder.c index b03884f4..26e3daab 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -29,6 +29,7 @@ #include "context.h" #include "transform.h" #include "intra.h" +#include "inter.h" #include "filter.h" #include "search.h" @@ -367,23 +368,16 @@ void encode_one_frame(encoder_control* encoder) #endif /* Filtering */ - if(encoder->deblock_enable) + /* TODO: Check for correct deblock condition on inter blocks */ + if(encoder->deblock_enable && encoder->in.cur_pic->slicetype == SLICE_I) { filter_deblock(encoder); } + /* Calculate checksum */ add_checksum(encoder); - /* TODO: add more than one reference */ - - /* Remove the ref pic (if present) */ - picture_list_rem(encoder->ref, 0, 1); - /* Add current picture as reference */ - picture_list_add(encoder->ref, encoder->in.cur_pic); - /* Allocate new memory to current picture */ - encoder->in.cur_pic = picture_init(encoder->in.width, encoder->in.height, encoder->in.width_in_LCU, encoder->in.height_in_LCU); - } void read_one_frame(FILE* file, encoder_control* encoder) @@ -1027,6 +1021,9 @@ void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, ui } CABAC_BIN_EP(&cabac, (mvd_ver>0)?0:1, "mvd_sign_flag_ver"); } + + /* Inter reconstruction */ + inter_recon(encoder->ref->pics[0],xCtb*CU_MIN_SIZE_PIXELS,yCtb*CU_MIN_SIZE_PIXELS,LCU_WIDTH>>depth,cur_CU->inter.mv,encoder->in.cur_pic); } { diff --git a/src/inter.c b/src/inter.c index b344cc85..12a3c5ea 100644 --- a/src/inter.c +++ b/src/inter.c @@ -20,7 +20,6 @@ #include "picture.h" #include "inter.h" - /*! \brief Set block mode (and init typedata) \param pic picture to use @@ -54,4 +53,114 @@ void inter_setBlockMode(picture* pic,uint32_t xCtb, uint32_t yCtb, uint8_t depth } } +/*! + \brief Reconstruct inter block + \param ref picture to copy the data from + \param xpos block x position + \param ypos block y position + \param width block width + \param mv[2] motion vector + \param dst destination picture + \returns Void +*/ +void inter_recon(picture* ref,int32_t xpos, int32_t ypos,int32_t width, int16_t mv[2], picture* dst) +{ + int x,y,coord_x,coord_y; + /* negative overflow present */ + int8_t overflow_neg_x = (xpos+mv[0] < 0)?1:0; + int8_t overflow_neg_y = (ypos+mv[1] < 0)?1:0; + + /* positive overflow present */ + int8_t overflow_pos_x = (xpos+mv[0]+width > ref->width )?1:0; + int8_t overflow_pos_y = (ypos+mv[1]+width > ref->height)?1:0; + + /* TODO: Fractional pixel support */ + mv[0] = mv[0]>>2; + mv[1] = mv[1]>>2; + + /* With overflow present, more checking */ + if(overflow_neg_x || overflow_neg_y || overflow_pos_x || overflow_pos_y) + { + /* Copy Luma with boundary checking */ + for(y = ypos; y < ypos+width; y++) + { + for(x = xpos; x < xpos+width; x++) + { + coord_x = x; + coord_y = y; + overflow_neg_x = (x < 0)?1:0; + overflow_neg_y = (y < 0)?1:0; + + overflow_pos_x = (x >= ref->width )?1:0; + overflow_pos_y = (y >= ref->height)?1:0; + + if(overflow_neg_x) { + coord_x = 0; + } else if(overflow_pos_x) { + coord_x = ref->width-1; + } + + if(overflow_neg_y) { + coord_y = 0; + } else if(overflow_pos_y) { + coord_y = ref->height-1; + } + + dst->yRecData[y*dst->width+x] = ref->yRecData[(coord_y+mv[1])*ref->width+(coord_x+mv[0])]; + } + } + + /* Copy Chroma with boundary checking */ + for(y = ypos>>1; y < (ypos+width)>>1; y++) + { + for(x = xpos>>1; x < (xpos+width)>>1; x++) + { + coord_x = x; + coord_y = y; + overflow_neg_x = (x < 0)?1:0; + overflow_neg_y = (y < 0)?1:0; + + overflow_pos_x = (x >= ref->width>>1 )?1:0; + overflow_pos_y = (y >= ref->height>>1)?1:0; + + if(overflow_neg_x) { + coord_x = 0; + } else if(overflow_pos_x) { + coord_x = (ref->width>>1)-1; + } + + if(overflow_neg_y) { + coord_y = 0; + } else if(overflow_pos_y) { + coord_y = (ref->height>>1)-1; + } + + dst->uRecData[y*(dst->width>>1)+x] = ref->uRecData[(coord_y+(mv[1]>>1))*ref->width+(coord_x+(mv[0]>>1))]; + dst->vRecData[y*(dst->width>>1)+x] = ref->vRecData[(coord_y+(mv[1]>>1))*ref->width+(coord_x+(mv[0]>>1))]; + } + } + } + else + { + /* Copy Luma */ + for(y = ypos; y < ypos+width; y++) + { + for(x = xpos; x < xpos+width; x++) + { + dst->yRecData[y*dst->width+x] = ref->yRecData[(y+mv[1])*ref->width+x+mv[0]]; + } + } + + /* Copy Chroma */ + for(y = ypos>>1; y < (ypos+width)>>1; y++) + { + for(x = xpos>>1; x < (xpos+width)>>1; x++) + { + dst->uRecData[y*(dst->width>>1)+x] = ref->uRecData[(y+(mv[1]>>1))*(ref->width>>1)+x+(mv[0]>>1)]; + dst->vRecData[y*(dst->width>>1)+x] = ref->vRecData[(y+(mv[1]>>1))*(ref->width>>1)+x+(mv[0]>>1)]; + } + } + } + +} \ No newline at end of file diff --git a/src/inter.h b/src/inter.h index 3773fd6c..d2bc807b 100644 --- a/src/inter.h +++ b/src/inter.h @@ -14,5 +14,5 @@ #define __INTER_H void inter_setBlockMode(picture* pic,uint32_t xCtb, uint32_t yCtb, uint8_t depth, CU_info* cur_cu); - +void inter_recon(picture* ref,int32_t xpos, int32_t ypos,int32_t width, int16_t mv[2], picture* dst); #endif diff --git a/src/search.c b/src/search.c index 92f9d299..695acb77 100644 --- a/src/search.c +++ b/src/search.c @@ -170,7 +170,7 @@ void search_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, uint8_t d cur_CU->inter.mv[1] = 0<<2; if(xCtb == 0 && yCtb == 0) { - cur_CU->inter.mv[1] = 20<<2; + cur_CU->inter.mv[1] = 0<<2; } cur_CU->inter.cost = 10; cur_CU->inter.mv_dir = 1;