TUT HEVC Encoder
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
cu.h File Reference

Coding Unit data structure and related functions. More...

#include "global.h"
#include "image.h"
#include "kvazaar.h"
Include dependency graph for cu.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  vector2d_t
 
struct  cu_info_t
 Struct for CU info. More...
 
struct  cu_array_t
 
struct  lcu_ref_px_t
 Top and left intra reference pixels for LCU. More...
 
struct  lcu_t
 

Macros

#define PU_GET_X(part_mode, cu_width, cu_x, i)    ((cu_x) + kvz_part_mode_offsets[(part_mode)][(i)][0] * (cu_width) / 4)
 Get the x coordinate of a PU. More...
 
#define PU_GET_Y(part_mode, cu_width, cu_y, i)    ((cu_y) + kvz_part_mode_offsets[(part_mode)][(i)][1] * (cu_width) / 4)
 Get the y coordinate of a PU. More...
 
#define PU_GET_W(part_mode, cu_width, i)    (kvz_part_mode_sizes[(part_mode)][(i)][0] * (cu_width) / 4)
 Get the width of a PU. More...
 
#define PU_GET_H(part_mode, cu_width, i)    (kvz_part_mode_sizes[(part_mode)][(i)][1] * (cu_width) / 4)
 Get the height of a PU. More...
 
#define CU_GET_MV_CAND(cu_info_ptr, reflist)    (((reflist) == 0) ? (cu_info_ptr)->inter.mv_cand0 : (cu_info_ptr)->inter.mv_cand1)
 
#define CU_SET_MV_CAND(cu_info_ptr, reflist, value)
 
#define CHECKPOINT_CU(prefix_str, cu)
 
#define SUB_SCU(xy)   ((xy) & (LCU_WIDTH - 1))
 Return the 7 lowest-order bits of the pixel coordinate. More...
 
#define LCU_CU_WIDTH   16
 
#define LCU_T_CU_WIDTH   (LCU_CU_WIDTH + 1)
 
#define LCU_CU_OFFSET   (LCU_T_CU_WIDTH + 1)
 
#define SCU_WIDTH   (LCU_WIDTH / LCU_CU_WIDTH)
 
#define LCU_REF_PX_WIDTH   (LCU_WIDTH + LCU_WIDTH / 2)
 
#define LCU_GET_TOP_RIGHT_CU(lcu)    (&(lcu)->cu[LCU_T_CU_WIDTH * LCU_T_CU_WIDTH])
 Return pointer to the top right reference CU. More...
 
#define LCU_GET_CU_AT_PX(lcu, x_px, y_px)    (&(lcu)->cu[LCU_CU_OFFSET + ((x_px) >> 2) + ((y_px) >> 2) * LCU_T_CU_WIDTH])
 Return pointer to the CU containing a given pixel. More...
 
#define CHECKPOINT_LCU(prefix_str, lcu)
 
#define NUM_CBF_DEPTHS   5
 
#define GET_SPLITDATA(CU, curDepth)   ((CU)->depth > curDepth)
 
#define SET_SPLITDATA(CU, flag)   { (CU)->split=(flag); }
 

Typedefs

typedef struct cu_array_t cu_array_t
 

Enumerations

enum  cu_type_t { CU_NOTSET = 0 , CU_INTRA = 1 , CU_INTER = 2 , CU_PCM = 3 }
 
enum  part_mode_t {
  SIZE_2Nx2N = 0 , SIZE_2NxN = 1 , SIZE_Nx2N = 2 , SIZE_NxN = 3 ,
  SIZE_2NxnU = 4 , SIZE_2NxnD = 5 , SIZE_nLx2N = 6 , SIZE_nRx2N = 7
}
 

Functions

cu_info_tkvz_cu_array_at (cu_array_t *cua, unsigned x_px, unsigned y_px)
 
const cu_info_tkvz_cu_array_at_const (const cu_array_t *cua, unsigned x_px, unsigned y_px)
 
cu_array_tkvz_cu_array_alloc (const int width, const int height)
 Allocate a CU array. More...
 
cu_array_tkvz_cu_subarray (cu_array_t *base, const unsigned x_offset, const unsigned y_offset, const unsigned width, const unsigned height)
 
void kvz_cu_array_free (cu_array_t **cua_ptr)
 
cu_array_tkvz_cu_array_copy_ref (cu_array_t *cua)
 Get a new pointer to a cu array. More...
 
typedef __attribute__ ((aligned(8))) struct
 Coefficients of an LCU. More...
 
void kvz_cu_array_copy_from_lcu (cu_array_t *dst, int dst_x, int dst_y, const lcu_t *src)
 Copy an lcu to a cu array. More...
 
static void copy_coeffs (const coeff_t *__restrict src, coeff_t *__restrict dest, size_t width)
 Copy a part of a coeff_t array to another. More...
 
static unsigned xy_to_zorder (unsigned width, unsigned x, unsigned y)
 Convert (x, y) coordinates to z-order index. More...
 
static int cbf_is_set (uint16_t cbf, int depth, color_t plane)
 Check if CBF in a given level >= depth is true. More...
 
static int cbf_is_set_any (uint16_t cbf, int depth)
 Check if CBF in a given level >= depth is true. More...
 
static void cbf_set (uint16_t *cbf, int depth, color_t plane)
 Set CBF in a level to true. More...
 
static void cbf_set_conditionally (uint16_t *cbf, uint16_t child_cbfs[3], int depth, color_t plane)
 Set CBF in a level to true if it is set at a lower level in any of the child_cbfs. More...
 
static void cbf_clear (uint16_t *cbf, int depth, color_t plane)
 Set CBF in a levels <= depth to false. More...
 
static void cbf_copy (uint16_t *cbf, uint16_t src, color_t plane)
 Copy cbf flags. More...
 

Variables

const uint8_t kvz_part_mode_num_parts []
 Number of PUs in a CU. More...
 
const uint8_t kvz_part_mode_offsets [][4][2]
 PU offsets. More...
 
const uint8_t kvz_part_mode_sizes [][4][2]
 PU sizes. More...
 
 lcu_coeff_t
 
static const uint16_t cbf_masks [5] = { 0x1f, 0x0f, 0x07, 0x03, 0x1 }
 

Macro Definition Documentation

◆ CHECKPOINT_CU

#define CHECKPOINT_CU (   prefix_str,
  cu 
)
Value:
CHECKPOINT(prefix_str " type=%d depth=%d part_size=%d tr_depth=%d coded=%d " \
"skipped=%d merged=%d merge_idx=%d cbf.y=%d cbf.u=%d cbf.v=%d " \
"intra[0].cost=%u intra[0].bitcost=%u intra[0].mode=%d intra[0].mode_chroma=%d intra[0].tr_skip=%d " \
"intra[1].cost=%u intra[1].bitcost=%u intra[1].mode=%d intra[1].mode_chroma=%d intra[1].tr_skip=%d " \
"intra[2].cost=%u intra[2].bitcost=%u intra[2].mode=%d intra[2].mode_chroma=%d intra[2].tr_skip=%d " \
"intra[3].cost=%u intra[3].bitcost=%u intra[3].mode=%d intra[3].mode_chroma=%d intra[3].tr_skip=%d " \
"inter.cost=%u inter.bitcost=%u inter.mv[0]=%d inter.mv[1]=%d inter.mvd[0]=%d inter.mvd[1]=%d " \
"inter.mv_cand=%d inter.mv_ref=%d inter.mv_dir=%d inter.mode=%d" \
, (cu).type, (cu).depth, (cu).part_size, (cu).tr_depth, (cu).coded, \
(cu).skipped, (cu).merged, (cu).merge_idx, (cu).cbf.y, (cu).cbf.u, (cu).cbf.v, \
(cu).intra[0].cost, (cu).intra[0].bitcost, (cu).intra[0].mode, (cu).intra[0].mode_chroma, (cu).intra[0].tr_skip, \
(cu).intra[1].cost, (cu).intra[1].bitcost, (cu).intra[1].mode, (cu).intra[1].mode_chroma, (cu).intra[1].tr_skip, \
(cu).intra[2].cost, (cu).intra[2].bitcost, (cu).intra[2].mode, (cu).intra[2].mode_chroma, (cu).intra[2].tr_skip, \
(cu).intra[3].cost, (cu).intra[3].bitcost, (cu).intra[3].mode, (cu).intra[3].mode_chroma, (cu).intra[3].tr_skip, \
(cu).inter.cost, (cu).inter.bitcost, (cu).inter.mv[0], (cu).inter.mv[1], (cu).inter.mvd[0], (cu).inter.mvd[1], \
(cu).inter.mv_cand, (cu).inter.mv_ref, (cu).inter.mv_dir, (cu).inter.mode)
#define CHECKPOINT(str,...)
Definition: checkpoint.h:117

◆ CHECKPOINT_LCU

#define CHECKPOINT_LCU (   prefix_str,
  lcu 
)

◆ CU_GET_MV_CAND

#define CU_GET_MV_CAND (   cu_info_ptr,
  reflist 
)     (((reflist) == 0) ? (cu_info_ptr)->inter.mv_cand0 : (cu_info_ptr)->inter.mv_cand1)

◆ CU_SET_MV_CAND

#define CU_SET_MV_CAND (   cu_info_ptr,
  reflist,
  value 
)
Value:
do { \
if ((reflist) == 0) { \
(cu_info_ptr)->inter.mv_cand0 = (value); \
} else { \
(cu_info_ptr)->inter.mv_cand1 = (value); \
} \
} while (0)

◆ GET_SPLITDATA

#define GET_SPLITDATA (   CU,
  curDepth 
)    ((CU)->depth > curDepth)

◆ LCU_CU_OFFSET

#define LCU_CU_OFFSET   (LCU_T_CU_WIDTH + 1)

◆ LCU_CU_WIDTH

#define LCU_CU_WIDTH   16

◆ LCU_GET_CU_AT_PX

#define LCU_GET_CU_AT_PX (   lcu,
  x_px,
  y_px 
)     (&(lcu)->cu[LCU_CU_OFFSET + ((x_px) >> 2) + ((y_px) >> 2) * LCU_T_CU_WIDTH])
Parameters
lcupointer to the containing LCU
x_pxx-coordinate relative to the upper left corner of the LCU
y_pxy-coordinate relative to the upper left corner of the LCU
Returns
pointer to the CU at coordinates (x_px, y_px)

◆ LCU_GET_TOP_RIGHT_CU

#define LCU_GET_TOP_RIGHT_CU (   lcu)     (&(lcu)->cu[LCU_T_CU_WIDTH * LCU_T_CU_WIDTH])

◆ LCU_REF_PX_WIDTH

#define LCU_REF_PX_WIDTH   (LCU_WIDTH + LCU_WIDTH / 2)

◆ LCU_T_CU_WIDTH

#define LCU_T_CU_WIDTH   (LCU_CU_WIDTH + 1)

◆ NUM_CBF_DEPTHS

#define NUM_CBF_DEPTHS   5

◆ PU_GET_H

#define PU_GET_H (   part_mode,
  cu_width,
 
)     (kvz_part_mode_sizes[(part_mode)][(i)][1] * (cu_width) / 4)
Parameters
part_modepartition mode of the containing CU
cu_widthwidth of the containing CU
inumber of the PU
Returns
height of the PU

◆ PU_GET_W

#define PU_GET_W (   part_mode,
  cu_width,
 
)     (kvz_part_mode_sizes[(part_mode)][(i)][0] * (cu_width) / 4)
Parameters
part_modepartition mode of the containing CU
cu_widthwidth of the containing CU
inumber of the PU
Returns
width of the PU

◆ PU_GET_X

#define PU_GET_X (   part_mode,
  cu_width,
  cu_x,
 
)     ((cu_x) + kvz_part_mode_offsets[(part_mode)][(i)][0] * (cu_width) / 4)
Parameters
part_modepartition mode of the containing CU
cu_widthwidth of the containing CU
cu_xx coordinate of the containing CU
inumber of the PU
Returns
location of the left edge of the PU

◆ PU_GET_Y

#define PU_GET_Y (   part_mode,
  cu_width,
  cu_y,
 
)     ((cu_y) + kvz_part_mode_offsets[(part_mode)][(i)][1] * (cu_width) / 4)
Parameters
part_modepartition mode of the containing CU
cu_widthwidth of the containing CU
cu_yy coordinate of the containing CU
inumber of the PU
Returns
location of the top edge of the PU

◆ SCU_WIDTH

#define SCU_WIDTH   (LCU_WIDTH / LCU_CU_WIDTH)

◆ SET_SPLITDATA

#define SET_SPLITDATA (   CU,
  flag 
)    { (CU)->split=(flag); }

◆ SUB_SCU

#define SUB_SCU (   xy)    ((xy) & (LCU_WIDTH - 1))

The 7 lower-order bits correspond to the distance from the left or top edge of the containing LCU.

Typedef Documentation

◆ cu_array_t

typedef struct cu_array_t cu_array_t

Enumeration Type Documentation

◆ cu_type_t

enum cu_type_t
Enumerator
CU_NOTSET 
CU_INTRA 
CU_INTER 
CU_PCM 

◆ part_mode_t

Enumerator
SIZE_2Nx2N 
SIZE_2NxN 
SIZE_Nx2N 
SIZE_NxN 
SIZE_2NxnU 
SIZE_2NxnD 
SIZE_nLx2N 
SIZE_nRx2N 

Function Documentation

◆ __attribute__()

typedef __attribute__ ( (aligned(8))  )

Coefficients inside a single TU are stored in row-major order. TUs themselves are stored in a zig-zag order, so that the coefficients of a TU are contiguous in memory.

Example storage order for a 32x32 pixel TU tree

  +------+------+------+------+---------------------------+
  |   0  |  16  |  64  |  80  |                           |
  |   -  |   -  |   -  |   -  |                           |
  |  15  |  31  |  79  |  95  |                           |
  +------+------+------+------+                           |
  |  32  |  48  |  96  | 112  |                           |
  |   -  |   -  |   -  |   -  |                           |
  |  47  |  63  | 111  | 127  |                           |
  +------+------+------+------+         256 - 511         |
  | 128  | 144  | 192  | 208  |                           |
  |   -  |   -  |   -  |   -  |                           |
  | 143  | 159  | 207  | 223  |                           |
  +------+------+------+------+                           |
  | 160  | 176  | 224  | 240  |                           |
  |   -  |   -  |   -  |   -  |                           |
  | 175  | 191  | 239  | 255  |                           |
  +------+------+------+------+-------------+------+------+
  | 512  | 528  |             |             | 832  | 848  |
  |   -  |   -  |             |             |   -  |   -  |
  | 527  | 543  |             |             | 847  | 863  |
  +------+------+  576 - 639  |  768 - 831  +------+------+
  | 544  | 560  |             |             | 864  | 880  |
  |   -  |   -  |             |             |   -  |   -  |
  | 559  | 575  |             |             | 879  | 895  |
  +------+------+-------------+-------------+------+------+
  |             |             |             |             |
  |             |             |             |             |
  |             |             |             |             |
  |  640 - 703  |  704 - 767  |  896 - 959  |  960 - 1023 |
  |             |             |             |             |
  |             |             |             |             |
  |             |             |             |             |
  +-------------+-------------+-------------+-------------+

◆ cbf_clear()

static void cbf_clear ( uint16_t *  cbf,
int  depth,
color_t  plane 
)
inlinestatic
Here is the caller graph for this function:

◆ cbf_copy()

static void cbf_copy ( uint16_t *  cbf,
uint16_t  src,
color_t  plane 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cbf_is_set()

static int cbf_is_set ( uint16_t  cbf,
int  depth,
color_t  plane 
)
inlinestatic
Here is the caller graph for this function:

◆ cbf_is_set_any()

static int cbf_is_set_any ( uint16_t  cbf,
int  depth 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cbf_set()

static void cbf_set ( uint16_t *  cbf,
int  depth,
color_t  plane 
)
inlinestatic
Here is the caller graph for this function:

◆ cbf_set_conditionally()

static void cbf_set_conditionally ( uint16_t *  cbf,
uint16_t  child_cbfs[3],
int  depth,
color_t  plane 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_coeffs()

static void copy_coeffs ( const coeff_t *__restrict  src,
coeff_t *__restrict  dest,
size_t  width 
)
inlinestatic
Parameters
widthSize of the block to be copied in pixels.
srcPointer to the source array.
destPointer to the destination array.
Here is the caller graph for this function:

◆ kvz_cu_array_alloc()

cu_array_t * kvz_cu_array_alloc ( const int  width,
const int  height 
)
Parameters
widthwidth of the array in luma pixels
heightheight of the array in luma pixels
Here is the caller graph for this function:

◆ kvz_cu_array_at()

cu_info_t * kvz_cu_array_at ( cu_array_t cua,
unsigned  x_px,
unsigned  y_px 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_cu_array_at_const()

const cu_info_t * kvz_cu_array_at_const ( const cu_array_t cua,
unsigned  x_px,
unsigned  y_px 
)
Here is the caller graph for this function:

◆ kvz_cu_array_copy_from_lcu()

void kvz_cu_array_copy_from_lcu ( cu_array_t dst,
int  dst_x,
int  dst_y,
const lcu_t src 
)

All values are in luma pixels.

Parameters
dstdestination array
dst_xx-coordinate of the left edge of the copied area in dst
dst_yy-coordinate of the top edge of the copied area in dst
srcsource lcu
Here is the caller graph for this function:

◆ kvz_cu_array_copy_ref()

cu_array_t * kvz_cu_array_copy_ref ( cu_array_t cua)

Increment reference count and return the cu array.

Here is the caller graph for this function:

◆ kvz_cu_array_free()

void kvz_cu_array_free ( cu_array_t **  cua_ptr)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvz_cu_subarray()

cu_array_t * kvz_cu_subarray ( cu_array_t base,
const unsigned  x_offset,
const unsigned  y_offset,
const unsigned  width,
const unsigned  height 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ xy_to_zorder()

static unsigned xy_to_zorder ( unsigned  width,
unsigned  x,
unsigned  y 
)
inlinestatic

Only works for widths and coordinates divisible by four. Width must be a power of two in range [4..64].

Parameters
widthsize of the containing block
xx-coordinate
yy-coordinate
Returns
index in z-order
Here is the caller graph for this function:

Variable Documentation

◆ cbf_masks

const uint16_t cbf_masks[5] = { 0x1f, 0x0f, 0x07, 0x03, 0x1 }
static

◆ kvz_part_mode_num_parts

const uint8_t kvz_part_mode_num_parts[]
extern

Indexed by part_mode_t values.

◆ kvz_part_mode_offsets

const uint8_t kvz_part_mode_offsets[][4][2]
extern

Indexed by [part mode][PU number][axis].

Units are 1/4 of the width of the CU.

◆ kvz_part_mode_sizes

const uint8_t kvz_part_mode_sizes[][4][2]
extern

Indexed by [part mode][PU number][axis].

Units are 1/4 of the width of the CU.

◆ lcu_coeff_t

lcu_coeff_t