mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-23 18:14:06 +00:00
Added basic draft of the search functionality
This commit is contained in:
parent
a737e8660c
commit
2aa465ab40
|
@ -6,7 +6,7 @@
|
|||
/*! \file context.c
|
||||
\brief Functions for context derication
|
||||
\author Marko Viitanen
|
||||
\date 2012-08
|
||||
\date 2013-04
|
||||
This file contains context derivation functions
|
||||
*/
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -28,6 +29,7 @@
|
|||
#include "transform.h"
|
||||
#include "intra.h"
|
||||
#include "filter.h"
|
||||
#include "search.h"
|
||||
|
||||
void initSigLastScan(uint32_t* pBuffD, uint32_t* pBuffH, uint32_t* pBuffV, int32_t iWidth, int32_t iHeight)
|
||||
{
|
||||
|
@ -163,6 +165,7 @@ void initSigLastScan(uint32_t* pBuffD, uint32_t* pBuffH, uint32_t* pBuffV, int32
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void init_tables(void)
|
||||
{
|
||||
int i;
|
||||
|
@ -186,6 +189,14 @@ void init_tables(void)
|
|||
c <<= 1;
|
||||
}
|
||||
|
||||
/* Lambda cost */
|
||||
/* ToDo: cleanup */
|
||||
g_lambda_cost = (int16_t*)malloc(sizeof(int16_t)*55);
|
||||
for(i = 0; i < 55; i++)
|
||||
{
|
||||
g_lambda_cost[i] = sqrt(0.85*pow(2.0,i/3));
|
||||
}
|
||||
|
||||
}
|
||||
void init_encoder_control(encoder_control* control,bitstream* output)
|
||||
{
|
||||
|
@ -271,6 +282,7 @@ void encode_one_frame(encoder_control* encoder)
|
|||
cabac_start(&cabac);
|
||||
encoder->in.cur_pic.slicetype = SLICE_I;
|
||||
encoder->in.cur_pic.type = NAL_IDR_SLICE;
|
||||
search_slice_data(encoder);
|
||||
encode_slice_header(encoder);
|
||||
bitstream_align(encoder->stream);
|
||||
encode_slice_data(encoder);
|
||||
|
@ -287,6 +299,7 @@ void encode_one_frame(encoder_control* encoder)
|
|||
cabac_start(&cabac);
|
||||
encoder->in.cur_pic.slicetype = SLICE_I;
|
||||
encoder->in.cur_pic.type = 0;
|
||||
search_slice_data(encoder);
|
||||
encode_slice_header(encoder);
|
||||
bitstream_align(encoder->stream);
|
||||
encode_slice_data(encoder);
|
||||
|
|
|
@ -104,8 +104,9 @@ void encode_CoeffNxN(encoder_control* encoder,int16_t* coeff, uint8_t width, uin
|
|||
void encode_transform_tree(encoder_control* encoder,transform_info* ti,uint8_t depth);
|
||||
void encode_transform_coeff(encoder_control* encoder,transform_info* ti,int8_t depth, int8_t trDepth);
|
||||
|
||||
static int16_t* g_lambda_cost;
|
||||
static uint32_t* g_auiSigLastScan[3][7];
|
||||
int8_t g_aucConvertToBit[LCU_WIDTH+1];
|
||||
int8_t g_aucConvertToBit[LCU_WIDTH+1];
|
||||
static int8_t g_bitDepth = 8;
|
||||
static int8_t g_uiBitIncrement = 0;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/*! \file picture.c
|
||||
\brief Functions to handle pictures
|
||||
\author Marko Viitanen
|
||||
\date 2012-06
|
||||
\date 2013-04
|
||||
|
||||
This file contains all the needed functions to handle pictures
|
||||
|
||||
|
|
139
src/search.c
139
src/search.c
|
@ -19,6 +19,143 @@
|
|||
#include "config.h"
|
||||
#include "bitstream.h"
|
||||
#include "picture.h"
|
||||
#include "cabac.h"
|
||||
#include "intra.h"
|
||||
#include "encoder.h"
|
||||
#include "filter.h"
|
||||
#include "search.h"
|
||||
|
||||
|
||||
|
||||
void search_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, uint8_t depth)
|
||||
{
|
||||
uint8_t border_x = ((encoder->in.width)<( xCtb*(LCU_WIDTH>>MAX_DEPTH) + (LCU_WIDTH>>depth) ))?1:0;
|
||||
uint8_t border_y = ((encoder->in.height)<( yCtb*(LCU_WIDTH>>MAX_DEPTH) + (LCU_WIDTH>>depth) ))?1:0;
|
||||
uint8_t border = border_x | border_y; /*!< are we in any border CU */
|
||||
CU_info *cur_CU = &encoder->in.cur_pic.CU[depth][(xCtb>>(MAX_DEPTH-depth))+(yCtb>>(MAX_DEPTH-depth))*(encoder->in.width_in_LCU<<MAX_DEPTH)];
|
||||
|
||||
cur_CU->intra.cost = (uint32_t)-1;
|
||||
|
||||
/* Force split on border */
|
||||
if(depth != MAX_DEPTH)
|
||||
{
|
||||
if(border)
|
||||
{
|
||||
/* Split blocks and remember to change x and y block positions */
|
||||
uint8_t change = 1<<(MAX_DEPTH-1-depth);
|
||||
SET_SPLITDATA(cur_CU,1);
|
||||
search_tree(encoder,xCtb,yCtb,depth+1);
|
||||
if(!border_x)
|
||||
{
|
||||
search_tree(encoder,xCtb+change,yCtb,depth+1);
|
||||
}
|
||||
if(!border_y)
|
||||
{
|
||||
search_tree(encoder,xCtb,yCtb+change,depth+1);
|
||||
}
|
||||
if(!border)
|
||||
{
|
||||
search_tree(encoder,xCtb+change,yCtb+change,depth+1);
|
||||
}
|
||||
/* We don't need to do anything else here */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(encoder->in.cur_pic.slicetype != SLICE_I)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* INTRA SEARCH */
|
||||
if(depth > 0)
|
||||
{
|
||||
uint8_t *base = &encoder->in.cur_pic.yData[xCtb*(LCU_WIDTH>>(MAX_DEPTH)) + (yCtb*(LCU_WIDTH>>(MAX_DEPTH))) *encoder->in.width];
|
||||
uint8_t *baseU = &encoder->in.cur_pic.uData[xCtb*(LCU_WIDTH>>(MAX_DEPTH+1)) + (yCtb*(LCU_WIDTH>>(MAX_DEPTH+1)))*(encoder->in.width>>1)];
|
||||
uint8_t *baseV = &encoder->in.cur_pic.vData[xCtb*(LCU_WIDTH>>(MAX_DEPTH+1)) + (yCtb*(LCU_WIDTH>>(MAX_DEPTH+1)))*(encoder->in.width>>1)];
|
||||
uint32_t width = LCU_WIDTH>>depth;
|
||||
|
||||
/* INTRAPREDICTION */
|
||||
/* ToDo: split to a function */
|
||||
int16_t pred[LCU_WIDTH*LCU_WIDTH];
|
||||
int16_t predU[LCU_WIDTH*LCU_WIDTH>>2];
|
||||
int16_t predV[LCU_WIDTH*LCU_WIDTH>>2];
|
||||
|
||||
int16_t rec[(LCU_WIDTH*2+8)*(LCU_WIDTH*2+8)];
|
||||
int16_t *recShift = &rec[(LCU_WIDTH>>(depth))*2+8+1];
|
||||
int16_t *recShiftU = &rec[(LCU_WIDTH>>(depth+1))*2+8+1];
|
||||
uint8_t *recbase = &encoder->in.cur_pic.yRecData[xCtb*(LCU_WIDTH>>(MAX_DEPTH)) + (yCtb*(LCU_WIDTH>>(MAX_DEPTH))) *encoder->in.width];
|
||||
uint8_t *recbaseU = &encoder->in.cur_pic.uRecData[xCtb*(LCU_WIDTH>>(MAX_DEPTH+1)) + (yCtb*(LCU_WIDTH>>(MAX_DEPTH+1)))*(encoder->in.width>>1)];
|
||||
uint8_t *recbaseV = &encoder->in.cur_pic.vRecData[xCtb*(LCU_WIDTH>>(MAX_DEPTH+1)) + (yCtb*(LCU_WIDTH>>(MAX_DEPTH+1)))*(encoder->in.width>>1)];
|
||||
|
||||
/* Build reconstructed block to use in prediction with extrapolated borders */
|
||||
intra_buildReferenceBorder(&encoder->in.cur_pic, xCtb, yCtb,(LCU_WIDTH>>(depth))*2+8, rec, (LCU_WIDTH>>(depth))*2+8, 0);
|
||||
cur_CU->intra.mode = (uint8_t)intra_prediction(encoder->in.cur_pic.yData,encoder->in.width,recShift,(LCU_WIDTH>>(depth))*2+8,xCtb*(LCU_WIDTH>>(MAX_DEPTH)),yCtb*(LCU_WIDTH>>(MAX_DEPTH)),width,pred,width,&cur_CU->intra.cost);
|
||||
}
|
||||
|
||||
/* Split and search to max_depth */
|
||||
if(depth != 2)
|
||||
{
|
||||
/* Split blocks and remember to change x and y block positions */
|
||||
uint8_t change = 1<<(MAX_DEPTH-1-depth);
|
||||
search_tree(encoder,xCtb,yCtb,depth+1);
|
||||
search_tree(encoder,xCtb+change,yCtb,depth+1);
|
||||
search_tree(encoder,xCtb,yCtb+change,depth+1);
|
||||
search_tree(encoder,xCtb+change,yCtb+change,depth+1);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t search_best_mode(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, uint8_t depth)
|
||||
{
|
||||
CU_info *cur_CU = &encoder->in.cur_pic.CU[depth][(xCtb>>(MAX_DEPTH-depth))+(yCtb>>(MAX_DEPTH-depth))*(encoder->in.width_in_LCU<<MAX_DEPTH)];
|
||||
uint32_t bestCost = cur_CU->intra.cost;
|
||||
int8_t bestMode = cur_CU->type;
|
||||
uint32_t cost = 0;
|
||||
|
||||
/* Split and search to max_depth */
|
||||
if(depth != MAX_DEPTH)
|
||||
{
|
||||
/* Split blocks and remember to change x and y block positions */
|
||||
uint8_t change = 1<<(MAX_DEPTH-1-depth);
|
||||
cost = 4*g_lambda_cost[encoder->QP];
|
||||
cost += search_best_mode(encoder,xCtb,yCtb,depth+1);
|
||||
cost += search_best_mode(encoder,xCtb+change,yCtb,depth+1);
|
||||
cost += search_best_mode(encoder,xCtb,yCtb+change,depth+1);
|
||||
cost += search_best_mode(encoder,xCtb+change,yCtb+change,depth+1);
|
||||
|
||||
if(cost != 0 && cost < bestCost)
|
||||
{
|
||||
cur_CU->split = 1;
|
||||
bestCost = cost;
|
||||
}
|
||||
else
|
||||
{
|
||||
cur_CU->split = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return bestCost;
|
||||
}
|
||||
|
||||
void search_slice_data(encoder_control* encoder)
|
||||
{
|
||||
uint16_t xCtb,yCtb;
|
||||
|
||||
/* Loop through every LCU in the slice */
|
||||
for(yCtb = 0; yCtb < encoder->in.height_in_LCU; yCtb++)
|
||||
{
|
||||
uint8_t lastCUy = (yCtb == (encoder->in.height_in_LCU-1))?1:0;
|
||||
for(xCtb = 0; xCtb < encoder->in.width_in_LCU; xCtb++)
|
||||
{
|
||||
uint8_t lastCUx = (xCtb == (encoder->in.width_in_LCU-1))?1:0;
|
||||
uint8_t depth = 0;
|
||||
|
||||
/* Recursive function for looping through all the sub-blocks */
|
||||
search_tree(encoder, xCtb<<MAX_DEPTH,yCtb<<MAX_DEPTH, depth);
|
||||
|
||||
/* Decide actual coding modes */
|
||||
search_best_mode(encoder, xCtb<<MAX_DEPTH,yCtb<<MAX_DEPTH, depth);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,5 +14,7 @@
|
|||
#ifndef __SEARCH_H
|
||||
#define __SEARCH_H
|
||||
|
||||
void search_slice_data(encoder_control* encoder);
|
||||
void search_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, uint8_t depth);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue