block.c File Reference

Process one block. More...

#include "contributors.h"
#include <math.h>
#include "global.h"
#include "enc_statistics.h"
#include "memalloc.h"
#include "image.h"
#include "mb_access.h"
#include "block.h"
#include "vlc.h"
#include "transform.h"
#include "mc_prediction.h"
#include "q_offsets.h"
#include "q_matrix.h"
#include "quant4x4.h"
#include "quantChroma.h"
#include "md_common.h"
#include "transform8x8.h"

Include dependency graph for block.c:

Go to the source code of this file.

Defines

#define P_X   (PredPel[0])
#define P_A   (PredPel[1])
#define P_B   (PredPel[2])
#define P_C   (PredPel[3])
#define P_D   (PredPel[4])
#define P_E   (PredPel[5])
#define P_F   (PredPel[6])
#define P_G   (PredPel[7])
#define P_H   (PredPel[8])
#define P_I   (PredPel[9])
#define P_J   (PredPel[10])
#define P_K   (PredPel[11])
#define P_L   (PredPel[12])

Functions

static int Residual_DPCM_4x4_for_Intra16x16 (int **m7, int ipmode)
static int Inv_Residual_DPCM_4x4_for_Intra16x16 (int **m7, int ipmode)
static int Residual_DPCM_4x4 (int ipmode, int **mb_ores, int **mb_rres, int block_y, int block_x)
static int Inv_Residual_DPCM_4x4 (Macroblock *currMB, int **m7, int block_y, int block_x)
void intrapred_16x16 (Macroblock *currMB, ColorPlane pl)
int dct_16x16 (Macroblock *currMB, ColorPlane pl)
int dct_16x16_ls (Macroblock *currMB, ColorPlane pl)
static int check_zero (int **mb_ores, int block_x)
int dct_4x4 (Macroblock *currMB, ColorPlane pl, int block_x, int block_y, int *coeff_cost, int intra)
int dct_4x4_ls (Macroblock *currMB, ColorPlane pl, int block_x, int block_y, int *coeff_cost, int intra)
int dct_chroma (Macroblock *currMB, int uv, int cr_cbp)
int dct_chroma_ls (Macroblock *currMB, int uv, int cr_cbp)
int dct_4x4_sp (Macroblock *currMB, ColorPlane pl, int block_x, int block_y, int *coeff_cost, int intra)
int dct_chroma_sp (Macroblock *currMB, int uv, int cr_cbp)
int dct_chroma_sp_old (Macroblock *currMB, int uv, int cr_cbp)
void copyblock_sp (Macroblock *currMB, ColorPlane pl, int block_x, int block_y)
int dct_4x4_sp2 (Macroblock *currMB, ColorPlane pl, int block_x, int block_y, int *coeff_cost, int intra)
int dct_chroma_sp2 (Macroblock *currMB, int uv, int cr_cbp)
void select_dct (Macroblock *currMB)

Variables

static const byte COEFF_COST4x4 [2][16]
static const byte SCAN_YUV420 [4][2]
static const byte SCAN_YUV422 [8][2]
static const unsigned char hor_offset [4][4][4]
static const unsigned char ver_offset [4][4][4]
static const int A [4][4]
static const unsigned char cbp_blk_chroma [8][4]
static const byte SNGL_SCAN [16][2]
static const byte FIELD_SCAN [16][2]


Detailed Description

Process one block.

Author:
Main contributors (see contributors.h for copyright, address and affiliation details)

Definition in file block.c.


Function Documentation

void copyblock_sp ( Macroblock currMB,
ColorPlane  pl,
int  block_x,
int  block_y 
)

The routine performs transform,quantization,inverse transform, adds the diff. to the prediction and writes the result to the decoded luma frame. Includes the RD constrained quantization also.

Input:
block_x,block_y: Block position inside a macro block (0,4,8,12).
Output:
nonzero: 0 if no levels are nonzero. 1 if there are nonzero levels.
coeff_cost: Counter for nonzero coefficients, used to discard expensive levels.

Definition at line 2205 of file block.c.

References img_par::max_imgpel_value, slice::mb_ores, slice::mb_pred, slice::mb_rres, storable_picture::p_curr_img, macroblock::p_slice, macroblock::pix_x, macroblock::pix_y, and slice::tblk16x16.

Referenced by luma_residual_coding(), luma_residual_coding_16x16(), luma_residual_coding_8x8(), luma_residual_coding_p444(), luma_residual_coding_p444_16x16(), and luma_residual_coding_p444_8x8().

int dct_16x16 ( Macroblock currMB,
ColorPlane  pl 
)

int dct_16x16_ls ( Macroblock currMB,
ColorPlane  pl 
)

For new intra pred routines.

Input:
Image par, 16x16 based intra mode
Output:
none

For residual DPCM. inv. residual DCPM

Definition at line 508 of file block.c.

References slice::cofAC, slice::cofDC, FIELD_SCAN, Inv_Residual_DPCM_4x4_for_Intra16x16(), slice::mpr_16x16, macroblock::opix_y, storable_picture::p_curr_img, macroblock::p_slice, img_par::pCurImg, macroblock::pix_x, macroblock::pix_y, Residual_DPCM_4x4_for_Intra16x16(), slice::slice_type, SNGL_SCAN, slice::tblk16x16, and slice::tblk4x4.

Here is the call graph for this function:

int dct_4x4 ( Macroblock currMB,
ColorPlane  pl,
int  block_x,
int  block_y,
int *  coeff_cost,
int  intra 
)

The routine performs transform,quantization,inverse transform, adds the diff to the prediction and writes the result to the decoded luma frame.

Input:
currMB: Current macroblock. pl: Color plane for 4:4:4 coding. block_x,block_y: Block position inside a macro block (0,4,8,12). intra: Intra block indicator.
Output_
nonzero: 0 if no levels are nonzero.
1 if there are nonzero levels.
coeff_cost: Coeff coding cost for thresholding consideration.

Definition at line 686 of file block.c.

References img_par::AdaptiveRounding, macroblock::ar_mode, img_par::ARCofAdj4x4, COEFF_COST4x4, slice::cofAC, copy_image_data_4x4(), FIELD_SCAN, img_par::max_imgpel_value, slice::mb_ores, slice::mb_pred, slice::mb_rres, storable_picture::p_curr_img, macroblock::p_slice, macroblock::pix_x, macroblock::pix_y, macroblock::qp_scaled, SNGL_SCAN, macroblock::subblock_x, macroblock::subblock_y, and slice::tblk16x16.

Here is the call graph for this function:

int dct_4x4_ls ( Macroblock currMB,
ColorPlane  pl,
int  block_x,
int  block_y,
int *  coeff_cost,
int  intra 
)

Process for lossless coding of coefficients. The routine performs transform, quantization,inverse transform, adds the diff to the prediction and writes the result to the decoded luma frame.

Input:
currMB: Current macroblock. pl: Color plane for 4:4:4 coding. block_x,block_y: Block position inside a macro block (0,4,8,12). intra: Intra block indicator.
Output_
nonzero: 0 if no levels are nonzero.
1 if there are nonzero levels.
coeff_cost: Coeff coding cost for thresholding consideration.

Definition at line 776 of file block.c.

References img_par::AdaptiveRounding, macroblock::ar_mode, img_par::ARCofAdj4x4, slice::cofAC, FIELD_SCAN, Inv_Residual_DPCM_4x4(), MAX_VALUE, slice::mb_ores, slice::mb_pred, slice::mb_rres, storable_picture::p_curr_img, macroblock::p_slice, macroblock::pix_x, macroblock::pix_y, Residual_DPCM_4x4(), and SNGL_SCAN.

Here is the call graph for this function:

int dct_4x4_sp ( Macroblock currMB,
ColorPlane  pl,
int  block_x,
int  block_y,
int *  coeff_cost,
int  intra 
)

The routine performs transform,quantization,inverse transform, adds the diff. to the prediction and writes the result to the decoded luma frame. Includes the RD constrained quantization also.

Input:
block_x,block_y: Block position inside a macro block (0,4,8,12).
Output:
nonzero: 0 if no levels are nonzero. 1 if there are nonzero levels.
coeff_cost: Counter for nonzero coefficients, used to discard expensive levels.

Definition at line 1514 of file block.c.

References COEFF_COST4x4, slice::cofAC, FIELD_SCAN, levrun_linfo_inter(), img_par::max_imgpel_value, MAX_VALUE, slice::mb_ores, slice::mb_pred, slice::mb_rres, storable_picture::p_curr_img, macroblock::p_Img, macroblock::p_slice, macroblock::pix_x, macroblock::pix_y, macroblock::qp_scaled, SNGL_SCAN, and slice::tblk16x16.

Here is the call graph for this function:

int dct_4x4_sp2 ( Macroblock currMB,
ColorPlane  pl,
int  block_x,
int  block_y,
int *  coeff_cost,
int  intra 
)

Eric Setton Encoding of a secondary SP / SI frame. For an SI frame the predicted block should only come from spatial pred. The original image signal is the error coefficients of a primary SP in the raw data stream the difference with the primary SP are :

  • the prediction signal is transformed and quantized (qpsp) but not dequantized
  • only one kind of prediction is considered and not two
  • the resulting error coefficients are not quantized before being sent to the VLC.

Input:
block_x,block_y: Block position inside a macro block (0,4,8,12).
Output:
nonzero: 0 if no levels are nonzero. 1 if there are nonzero levels. coeff_cost: Counter for nonzero coefficients, used to discard expensive levels.

Definition at line 2286 of file block.c.

References COEFF_COST4x4, slice::cofAC, FIELD_SCAN, img_par::max_imgpel_value, MAX_VALUE, slice::mb_pred, slice::mb_rres, storable_picture::p_curr_img, macroblock::p_slice, macroblock::pix_x, macroblock::pix_y, SNGL_SCAN, and slice::tblk16x16.

int dct_chroma ( Macroblock currMB,
int  uv,
int  cr_cbp 
)

Transform,quantization,inverse transform for chroma. The main reason why this is done in a separate routine is the additional 2x2 transform of DC-coeffs. This routine is called once for each of the chroma components.

Input:
uv : Make difference between the U and V chroma component
cr_cbp: chroma coded block pattern
Output:
cr_cbp: Updated chroma coded block pattern.

Definition at line 1063 of file block.c.

References _CHROMA_COEFF_COST_, img_par::AdaptiveRounding, macroblock::ar_mode, img_par::ARCofAdj4x4, macroblock::cbp_blk, COEFF_COST4x4, slice::cofAC, slice::cofDC, copy_image_data(), FIELD_SCAN, hor_offset, storable_picture::imgUV, img_par::max_pel_value_comp, slice::mb_ores, slice::mb_pred, slice::mb_rres, macroblock::mb_type, macroblock::p_slice, macroblock::pix_c_x, macroblock::pix_c_y, macroblock::qpc, SCAN_YUV422, SNGL_SCAN, subblk_offset_x, macroblock::subblock_x, macroblock::subblock_y, slice::tblk4x4, YUV420, and YUV422.

Here is the call graph for this function:

int dct_chroma_ls ( Macroblock currMB,
int  uv,
int  cr_cbp 
)

Transform,quantization,inverse transform for chroma. The main reason why this is done in a separate routine is the additional 2x2 transform of DC-coeffs. This routine is called once for each of the chroma components.

Input:
uv : Make difference between the U and V chroma component
cr_cbp: chroma coded block pattern
Output:
cr_cbp: Updated chroma coded block pattern.

Definition at line 1318 of file block.c.

References img_par::AdaptiveRounding, macroblock::ar_mode, img_par::ARCofAdj4x4, macroblock::cbp_blk, slice::cofAC, slice::cofDC, FIELD_SCAN, hor_offset, storable_picture::imgUV, MAX_VALUE, slice::mb_ores, slice::mb_pred, slice::mb_rres, macroblock::mb_type, macroblock::p_slice, macroblock::pix_c_x, macroblock::pix_c_y, SCAN_YUV422, SNGL_SCAN, slice::tblk4x4, YUV420, and YUV422.

int dct_chroma_sp ( Macroblock currMB,
int  uv,
int  cr_cbp 
)

Transform,quantization,inverse transform for chroma. The main reason why this is done in a separate routine is the additional 2x2 transform of DC-coeffs. This routine is called once for each of the chroma components.

Input:
uv : Make difference between the U and V chroma component cr_cbp: chroma coded block pattern
Output:
cr_cbp: Updated chroma coded block pattern.

Definition at line 1691 of file block.c.

References _CHROMA_COEFF_COST_, img_par::AdaptiveRounding, macroblock::ar_mode, img_par::ARCofAdj4x4, macroblock::cbp_blk, COEFF_COST4x4, slice::cofAC, slice::cofDC, copy_image_data(), FIELD_SCAN, hor_offset, storable_picture::imgUV, img_par::max_pel_value_comp, slice::mb_ores, slice::mb_pred, slice::mb_rres, macroblock::mb_type, macroblock::p_slice, macroblock::pix_c_x, macroblock::pix_c_y, macroblock::qpc, SCAN_YUV422, SNGL_SCAN, slice::tblk4x4, YUV420, and YUV422.

Referenced by chroma_residual_coding().

Here is the call graph for this function:

int dct_chroma_sp2 ( Macroblock currMB,
int  uv,
int  cr_cbp 
)

Eric Setton Encoding of the chroma of a secondary SP / SI frame. For an SI frame the predicted block should only come from spatial pred. The original image signal is the error coefficients of a primary SP in the raw data stream the difference with the primary SP are :

  • the prediction signal is transformed and quantized (qpsp) but not dequantized
  • the resulting error coefficients are not quantized before being sent to the VLC.

Input:
uv : Make difference between the U and V chroma component cr_cbp: chroma coded block pattern
Output:
cr_cbp: Updated chroma coded block pattern.

Definition at line 2404 of file block.c.

References macroblock::cbp_blk, COEFF_COST4x4, slice::cofAC, slice::cofDC, FIELD_SCAN, storable_picture::imgUV, img_par::max_imgpel_value, MAX_VALUE, slice::mb_pred, slice::mb_rres, macroblock::p_slice, macroblock::pix_c_x, macroblock::pix_c_y, macroblock::qpc, SNGL_SCAN, and slice::tblk16x16.

Referenced by chroma_residual_coding().

void intrapred_16x16 ( Macroblock currMB,
ColorPlane  pl 
)

16x16 based luma prediction

Input:
Image parameters
Output:
none

< pixel position p(0,-1)

< pixel positions p(-1, -1..15)

Definition at line 205 of file block.c.

References img_par::dc_pred_value, img_par::max_imgpel_value, slice::mpr_16x16, storable_picture::p_curr_img, macroblock::p_slice, and inp_par_enc::UseConstrainedIntraPred.

Referenced by encode_one_macroblock_low(), Intra16x16_Mode_Decision444(), Intra16x16_Mode_Decision_RDopt(), and Intra16x16_Mode_Decision_SAD().

static int Inv_Residual_DPCM_4x4 ( Macroblock currMB,
int **  m7,
int  block_y,
int  block_x 
) [static]

Inverse residual DPCM for Intra lossless coding.

Input:
block_x,block_y: Block position inside a macro block (0,4,8,12).

Definition at line 923 of file block.c.

Referenced by dct_4x4_ls().

static int Inv_Residual_DPCM_4x4_for_Intra16x16 ( int **  mb_ores,
int  ipmode 
) [static]

Inverse residual DPCM for Intra lossless coding.

Definition at line 1006 of file block.c.

Referenced by dct_16x16_ls().

static int Residual_DPCM_4x4 ( int  ipmode,
int **  mb_ores,
int **  mb_rres,
int  block_y,
int  block_x 
) [static]

Residual DPCM for Intra lossless coding.

Input:
block_x,block_y: Block position inside a macro block (0,4,8,12).

Definition at line 869 of file block.c.

Referenced by dct_4x4_ls().

static int Residual_DPCM_4x4_for_Intra16x16 ( int **  mb_ores,
int  ipmode 
) [static]

Residual DPCM for Intra lossless coding.

Definition at line 972 of file block.c.

Referenced by dct_16x16_ls().


Variable Documentation

const int A[4][4] [static]

Initial value:

 {
  { 16, 20, 16, 20},
  { 20, 25, 20, 25},
  { 16, 20, 16, 20},
  { 20, 25, 20, 25}
}

Definition at line 149 of file block.c.

const unsigned char cbp_blk_chroma[8][4] [static]

Initial value:

 {
  {16, 17, 18, 19},
  {20, 21, 22, 23},
  {24, 25, 26, 27},
  {28, 29, 30, 31},
  {32, 33, 34, 35},
  {36, 37, 38, 39},
  {40, 41, 42, 43},
  {44, 45, 46, 47} 
}

Definition at line 156 of file block.c.

const byte COEFF_COST4x4[2][16] [static]

Initial value:

{
  {3,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0},
  {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9}
}
array used to find expencive coefficients

Definition at line 71 of file block.c.

Referenced by dct_16x16(), dct_4x4(), dct_4x4_sp(), dct_4x4_sp2(), dct_chroma(), dct_chroma_sp(), and dct_chroma_sp2().

const byte FIELD_SCAN[16][2] [static]

Initial value:

{
  {0,0},{0,1},{1,0},{0,2},
  {0,3},{1,1},{1,2},{1,3},
  {2,0},{2,1},{2,2},{2,3},
  {3,0},{3,1},{3,2},{3,3}
}
field scan pattern

Definition at line 177 of file block.c.

Referenced by dct_16x16(), dct_16x16_ls(), dct_4x4(), dct_4x4_ls(), dct_4x4_sp(), dct_4x4_sp2(), dct_chroma(), dct_chroma_ls(), dct_chroma_sp(), and dct_chroma_sp2().

const unsigned char hor_offset[4][4][4] [static]

Initial value:

  {
  {
    {0, 0, 0, 0},
    {0, 0, 0, 0},
    {0, 0, 0, 0},
    {0, 0, 0, 0}
  },
  {
    {0, 4, 0, 4},
    {0, 0, 0, 0},
    {0, 0, 0, 0},
    {0, 0, 0, 0}
  },
  {
    {0, 4, 0, 4},
    {0, 4, 0, 4},
    {0, 0, 0, 0},
    {0, 0, 0, 0}
  },
  {
    {0, 4, 0, 4},
    {8,12, 8,12},
    {0, 4, 0, 4},
    {8,12, 8,12}
  }
}
look up tables for FRExt-chroma support

Definition at line 95 of file block.c.

Referenced by dct_chroma(), dct_chroma_ls(), and dct_chroma_sp().

const byte SCAN_YUV420[4][2] [static]

Initial value:

{
  {0,0},
  {0,1},
  {0,2},
  {0,3}
}

Definition at line 77 of file block.c.

const byte SCAN_YUV422[8][2] [static]

Initial value:

{
  {0,0},{0,1},
  {1,0},{0,2},
  {0,3},{1,1},
  {1,2},{1,3}
}
single scan pattern

Definition at line 86 of file block.c.

Referenced by dct_chroma(), dct_chroma_ls(), and dct_chroma_sp().

const byte SNGL_SCAN[16][2] [static]

Initial value:

{
  {0,0},{1,0},{0,1},{0,2},
  {1,1},{2,0},{3,0},{2,1},
  {1,2},{0,3},{1,3},{2,2},
  {3,1},{3,2},{2,3},{3,3}
}
single scan pattern

Definition at line 168 of file block.c.

Referenced by dct_16x16(), dct_16x16_ls(), dct_4x4(), dct_4x4_ls(), dct_4x4_sp(), dct_4x4_sp2(), dct_chroma(), dct_chroma_ls(), dct_chroma_sp(), and dct_chroma_sp2().

const unsigned char ver_offset[4][4][4] [static]

Initial value:

  { 
  {
    {0, 0, 0, 0},
    {0, 0, 0, 0},
    {0, 0, 0, 0},
    {0, 0, 0, 0}
  },
  {
    {0, 0, 4, 4},
    {0, 0, 0, 0},
    {0, 0, 0, 0},
    {0, 0, 0, 0}
  },
  {
    {0, 0, 4, 4},
    {8, 8,12,12},
    {0, 0, 0, 0},
    {0, 0, 0, 0}
  },
  {
    {0, 0, 4, 4},
    {0, 0, 4, 4},
    {8, 8,12,12},
    {8, 8,12,12}
  }
}

Definition at line 122 of file block.c.


Documentation generated with DoxyGen