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 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 (int **m7, int block_y, int block_x)
int allocate_block_mem (void)
void free_block_mem (void)
void intrapred_4x4 (Macroblock *currMB, ColorPlane pl, int img_x, int img_y, int *left_available, int *up_available, int *all_available)
void intrapred_16x16 (Macroblock *currMB, ColorPlane pl)
int dct_16x16 (Macroblock *currMB, ColorPlane pl, int new_intra_mode, int is_cavlc)
int dct_16x16_ls (Macroblock *currMB, ColorPlane pl, int new_intra_mode, int is_cavlc)
int dct_4x4 (Macroblock *currMB, ColorPlane pl, int block_x, int block_y, int *coeff_cost, int intra, int is_cavlc)
int dct_4x4_ls (Macroblock *currMB, ColorPlane pl, int block_x, int block_y, int *coeff_cost, int intra, int is_cavlc)
int dct_chroma (Macroblock *currMB, int uv, int cr_cbp, int is_cavlc)
int dct_chroma_ls (Macroblock *currMB, int uv, int cr_cbp, int is_cavlc)
int dct_4x4_sp (Macroblock *currMB, ColorPlane pl, int block_x, int block_y, int *coeff_cost, int intra, int is_cavlc)
int dct_chroma_sp (Macroblock *currMB, int uv, int cr_cbp, int is_cavlc)
int dct_chroma_sp_old (Macroblock *currMB, int uv, int cr_cbp, int is_cavlc)
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 is_cavlc)
int dct_chroma_sp2 (Macroblock *currMB, int uv, int cr_cbp, int is_cavlc)
void select_dct (ImageParameters *img, 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 unsigned char cbp_blk_chroma [8][4]
const byte SNGL_SCAN [16][2]
const byte FIELD_SCAN [16][2]
int **** ptLevelOffset4x4
static int ** levelscale = NULL
static int ** leveloffset = NULL
static int ** invlevelscale = NULL
static int ** levelscale_sp = NULL
static int ** leveloffset_sp = NULL
static int ** invlevelscale_sp = NULL
static int ** fadjust4x4 = NULL
static int ** fadjust2x2 = NULL
static int ** fadjust4x2 = NULL
static int ** levelscaleDC = NULL
static int ** leveloffsetDC = NULL
static int ** invlevelscaleDC = NULL
static int ** M1 = NULL
static int ** M4 = NULL


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 2456 of file block.c.

References ImageParameters::bitdepth_luma_qp_scale, ImageParameters::max_imgpel_value, ImageParameters::mb_ores, ImageParameters::mb_pred, ImageParameters::mb_rres, storable_picture::p_curr_img, ImageParameters::pix_x, ImageParameters::pix_y, and macroblock::qpsp.

Referenced by LumaResidualCoding(), and LumaResidualCoding8x8().

int dct_16x16 ( Macroblock *  currMB,
ColorPlane  pl,
int  new_intra_mode,
int  is_cavlc 
)

int dct_16x16_ls ( Macroblock *  currMB,
ColorPlane  pl,
int  new_intra_mode,
int  is_cavlc 
)

For new intra pred routines.

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

For residual DPCM. inv. residual DCPM

Definition at line 819 of file block.c.

References ImageParameters::cofAC, ImageParameters::cofDC, FIELD_SCAN, Inv_Residual_DPCM_4x4_for_Intra16x16(), macroblock::is_field_mode, ImageParameters::mpr_16x16, ImageParameters::opix_x, ImageParameters::opix_y, storable_picture::p_curr_img, pCurImg, ImageParameters::pix_x, ImageParameters::pix_y, Residual_DPCM_4x4_for_Intra16x16(), SNGL_SCAN, and ImageParameters::type.

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,
int  is_cavlc 
)

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 977 of file block.c.

References ImageParameters::AdaptiveRounding, macroblock::ar_mode, ImageParameters::ARCofAdj4x4, COEFF_COST4x4, ImageParameters::cofAC, InputParameters::disthres, FIELD_SCAN, macroblock::is_field_mode, ImageParameters::max_imgpel_value, ImageParameters::mb_ores, ImageParameters::mb_pred, ImageParameters::mb_rres, storable_picture::p_curr_img, ImageParameters::pix_x, ImageParameters::pix_y, macroblock::qp_scaled, SNGL_SCAN, ImageParameters::subblock_x, and ImageParameters::subblock_y.

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

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 1059 of file block.c.

References ImageParameters::AdaptiveRounding, macroblock::ar_mode, ImageParameters::ARCofAdj4x4, ImageParameters::cofAC, FIELD_SCAN, Inv_Residual_DPCM_4x4(), macroblock::is_field_mode, MAX_VALUE, ImageParameters::mb_ores, ImageParameters::mb_pred, ImageParameters::mb_rres, storable_picture::p_curr_img, ImageParameters::pix_x, ImageParameters::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,
int  is_cavlc 
)

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 1778 of file block.c.

References COEFF_COST4x4, ImageParameters::cofAC, InputParameters::disthres, FIELD_SCAN, macroblock::is_field_mode, levrun_linfo_inter(), ImageParameters::max_imgpel_value, MAX_VALUE, ImageParameters::mb_ores, ImageParameters::mb_pred, ImageParameters::mb_rres, storable_picture::p_curr_img, ImageParameters::pix_x, ImageParameters::pix_y, macroblock::qp_scaled, macroblock::qpsp, and SNGL_SCAN.

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,
int  is_cavlc 
)

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 2537 of file block.c.

References COEFF_COST4x4, ImageParameters::cofAC, InputParameters::disthres, FIELD_SCAN, macroblock::is_field_mode, ImageParameters::max_imgpel_value, MAX_VALUE, ImageParameters::mb_pred, ImageParameters::mb_rres, storable_picture::p_curr_img, ImageParameters::pix_x, ImageParameters::pix_y, macroblock::qpsp, and SNGL_SCAN.

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

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

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 1579 of file block.c.

References ImageParameters::AdaptiveRounding, macroblock::ar_mode, ImageParameters::ARCofAdj4x4, macroblock::cbp_blk, ImageParameters::cofAC, ImageParameters::cofDC, FIELD_SCAN, hor_offset, storable_picture::imgUV, macroblock::is_field_mode, macroblock::luma_transform_size_8x8_flag, MAX_VALUE, ImageParameters::mb_cr_size_x, ImageParameters::mb_cr_size_y, ImageParameters::mb_ores, ImageParameters::mb_pred, ImageParameters::mb_rres, macroblock::mb_type, ImageParameters::num_blk8x8_uv, ImageParameters::pix_c_x, ImageParameters::pix_c_y, SCAN_YUV422, SNGL_SCAN, YUV420, YUV422, and ImageParameters::yuv_format.

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

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 1958 of file block.c.

References _CHROMA_COEFF_COST_, ImageParameters::AdaptiveRounding, macroblock::ar_mode, ImageParameters::ARCofAdj4x4, ImageParameters::bitdepth_chroma_qp_scale, macroblock::cbp_blk, COEFF_COST4x4, ImageParameters::cofAC, ImageParameters::cofDC, InputParameters::disthres, FIELD_SCAN, hor_offset, storable_picture::imgUV, macroblock::is_field_mode, macroblock::luma_transform_size_8x8_flag, ImageParameters::max_imgpel_value_comp, ImageParameters::mb_cr_size_x, ImageParameters::mb_cr_size_y, ImageParameters::mb_ores, ImageParameters::mb_pred, ImageParameters::mb_rres, macroblock::mb_type, ImageParameters::num_blk8x8_uv, ImageParameters::pix_c_x, ImageParameters::pix_c_y, macroblock::qpc, SCAN_YUV422, SNGL_SCAN, YUV420, YUV422, and ImageParameters::yuv_format.

Referenced by ChromaResidualCoding().

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

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 2657 of file block.c.

References ImageParameters::bitdepth_chroma_qp_scale, macroblock::cbp_blk, COEFF_COST4x4, ImageParameters::cofAC, ImageParameters::cofDC, InputParameters::disthres, FIELD_SCAN, storable_picture::imgUV, macroblock::is_field_mode, ImageParameters::max_imgpel_value, MAX_VALUE, ImageParameters::mb_pred, ImageParameters::mb_rres, ImageParameters::pix_c_x, ImageParameters::pix_c_y, macroblock::qpc, macroblock::qpsp, and SNGL_SCAN.

Referenced by ChromaResidualCoding().

void intrapred_16x16 ( Macroblock *  currMB,
ColorPlane  pl 
)

void intrapred_4x4 ( Macroblock *  currMB,
ColorPlane  pl,
int  img_x,
int  img_y,
int *  left_available,
int *  up_available,
int *  all_available 
)

Make intra 4x4 prediction according to all 9 prediction modes. The routine uses left and upper neighbouring points from previous coded blocks to do this (if available). Notice that inaccessible neighbouring points are signalled with a negative value in the predmode array .

Input:
Starting point of current 4x4 block image posision
Output:
none

Definition at line 233 of file block.c.

References pix_pos::available, ImageParameters::dc_pred_value, ImageParameters::intra_block, pix_pos::mb_addr, ImageParameters::mb_size, ImageParameters::mpr_4x4, storable_picture::p_curr_img, pix_pos::pos_x, pix_pos::pos_y, and InputParameters::UseConstrainedIntraPred.

Referenced by Mode_Decision_for_4x4IntraBlocks_JM_High(), and Mode_Decision_for_4x4IntraBlocks_JM_Low().

static int Inv_Residual_DPCM_4x4 ( 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 1203 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 1286 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 1149 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 1252 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 145 of file block.c.

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 152 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 67 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]

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 173 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 91 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 73 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 82 of file block.c.

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

const byte SNGL_SCAN[16][2]

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 164 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 118 of file block.c.


Documentation generated with DoxyGen