2019-08-15 08:01:38 +00:00
# ifndef ALF_H_
# define ALF_H_
# include "checkpoint.h"
# include "cu.h"
# include "encoder.h"
# include "encoderstate.h"
# include "global.h" // IWYU pragma: keep
# include "kvazaar.h"
# include "videoframe.h"
# include "image.h"
2020-10-01 15:57:06 +00:00
# include "nal.h"
2019-08-15 08:01:38 +00:00
//ALF applied to 4x4 luma samples
//Filtering in CTB level
//Signalled in slice header if used or not
//Signalled in CTB level if ALF used for luma (if applied, then also for both chroma samples)
//To reduce bits overhead, filter coefficients of different classification can be merged.
//In slice header, the indices of the APSs used for the current slice are signaled.
2019-09-17 05:48:59 +00:00
# define ALF_FIXED_FILTER_NUM 64
2019-08-15 08:01:38 +00:00
# define MAX_NUM_ALF_CLASSES 25
# define MAX_NUM_ALF_LUMA_COEFF 13
# define MAX_NUM_ALF_CHROMA_COEFF 7
# define MAX_ALF_FILTER_LENGTH 7
# define MAX_NUM_ALF_COEFF (MAX_ALF_FILTER_LENGTH * MAX_ALF_FILTER_LENGTH / 2 + 1)
2020-08-07 09:09:19 +00:00
# define MAX_NUM_CC_ALF_FILTERS 4
# define MAX_NUM_CC_ALF_CHROMA_COEFF 8
2019-08-15 08:01:38 +00:00
# define ALF_NUM_FIXED_FILTER_SETS 16
2020-08-07 09:09:19 +00:00
# define CC_ALF_BITS_PER_COEFF_LEVEL 3
2019-08-15 08:01:38 +00:00
# define ALF_UNUSED_CLASS_IDX 255
# define ALF_UNUSED_TRANSPOSE_IDX 255
# define REG 0.0001
# define REG_SQR 0.0000001
# define MAX_NUM_APS 32
# define CLASSIFICATION_BLK_SIZE 32
2019-09-17 05:48:59 +00:00
# define ALF_VB_POS_ABOVE_CTUROW_LUMA 4
# define ALF_VB_POS_ABOVE_CTUROW_CHMA 2
# define ALF_CTB_MAX_NUM_APS 8
# define MAX_ALF_PADDING_SIZE 4
# define MAX_ALF_NUM_CLIPPING_VALUES 4
2019-10-02 09:25:02 +00:00
# define SCALE_BITS 15
# define MAX_NUM_ALF_ALTERNATIVES_CHROMA 8
2020-11-05 13:48:14 +00:00
# define CCALF_CANDS_COEFF_NR 8
# define CCALF_DYNAMIC_RANGE 6
# define CCALF_BITS_PER_COEFF_LEVEL 3
2019-10-18 08:36:31 +00:00
# define NUM_APS_TYPE_LEN 0 //1 //3
2020-11-23 16:20:04 +00:00
# define ALF_NONE_BOUNDARY -128
# define CC_ALF_NUM_COEFF 8
2019-09-17 05:48:59 +00:00
2020-11-05 13:48:14 +00:00
static const int cc_alf_small_tab [ CCALF_CANDS_COEFF_NR ] = { 0 , 1 , 2 , 4 , 8 , 16 , 32 , 64 } ;
2019-09-17 05:48:59 +00:00
static const int g_fixed_filter_set_coeff [ ALF_FIXED_FILTER_NUM ] [ MAX_NUM_ALF_LUMA_COEFF ] =
2019-08-15 08:01:38 +00:00
{
2020-06-29 15:58:50 +00:00
{ 0 , 0 , 2 , - 3 , 1 , - 4 , 1 , 7 , - 1 , 1 , - 1 , 5 , 0 } ,
{ 0 , 0 , 0 , 0 , 0 , - 1 , 0 , 1 , 0 , 0 , - 1 , 2 , 0 } ,
{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 } ,
{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 1 , 1 , 0 } ,
2019-08-15 08:01:38 +00:00
{ 2 , 2 , - 7 , - 3 , 0 , - 5 , 13 , 22 , 12 , - 3 , - 3 , 17 , 0 } ,
2020-06-29 15:58:50 +00:00
{ - 1 , 0 , 6 , - 8 , 1 , - 5 , 1 , 23 , 0 , 2 , - 5 , 10 , 0 } ,
{ 0 , 0 , - 1 , - 1 , 0 , - 1 , 2 , 1 , 0 , 0 , - 1 , 4 , 0 } ,
2019-08-15 08:01:38 +00:00
{ 0 , 0 , 3 , - 11 , 1 , 0 , - 1 , 35 , 5 , 2 , - 9 , 9 , 0 } ,
{ 0 , 0 , 8 , - 8 , - 2 , - 7 , 4 , 4 , 2 , 1 , - 1 , 25 , 0 } ,
2020-06-29 15:58:50 +00:00
{ 0 , 0 , 1 , - 1 , 0 , - 3 , 1 , 3 , - 1 , 1 , - 1 , 3 , 0 } ,
2019-08-15 08:01:38 +00:00
{ 0 , 0 , 3 , - 3 , 0 , - 6 , 5 , - 1 , 2 , 1 , - 4 , 21 , 0 } ,
2020-06-29 15:58:50 +00:00
{ - 7 , 1 , 5 , 4 , - 3 , 5 , 11 , 13 , 12 , - 8 , 11 , 12 , 0 } ,
{ - 5 , - 3 , 6 , - 2 , - 3 , 8 , 14 , 15 , 2 , - 7 , 11 , 16 , 0 } ,
2019-08-15 08:01:38 +00:00
{ 2 , - 1 , - 6 , - 5 , - 2 , - 2 , 20 , 14 , - 4 , 0 , - 3 , 25 , 0 } ,
{ 3 , 1 , - 8 , - 4 , 0 , - 8 , 22 , 5 , - 3 , 2 , - 10 , 29 , 0 } ,
{ 2 , 1 , - 7 , - 1 , 2 , - 11 , 23 , - 5 , 0 , 2 , - 10 , 29 , 0 } ,
2020-06-29 15:58:50 +00:00
{ - 6 , - 3 , 8 , 9 , - 4 , 8 , 9 , 7 , 14 , - 2 , 8 , 9 , 0 } ,
2019-08-15 08:01:38 +00:00
{ 2 , 1 , - 4 , - 7 , 0 , - 8 , 17 , 22 , 1 , - 1 , - 4 , 23 , 0 } ,
{ 3 , 0 , - 5 , - 7 , 0 , - 7 , 15 , 18 , - 5 , 0 , - 5 , 27 , 0 } ,
{ 2 , 0 , 0 , - 7 , 1 , - 10 , 13 , 13 , - 4 , 2 , - 7 , 24 , 0 } ,
{ 3 , 3 , - 13 , 4 , - 2 , - 5 , 9 , 21 , 25 , - 2 , - 3 , 12 , 0 } ,
2020-06-29 15:58:50 +00:00
{ - 5 , - 2 , 7 , - 3 , - 7 , 9 , 8 , 9 , 16 , - 2 , 15 , 12 , 0 } ,
2019-08-15 08:01:38 +00:00
{ 0 , - 1 , 0 , - 7 , - 5 , 4 , 11 , 11 , 8 , - 6 , 12 , 21 , 0 } ,
{ 3 , - 2 , - 3 , - 8 , - 4 , - 1 , 16 , 15 , - 2 , - 3 , 3 , 26 , 0 } ,
{ 2 , 1 , - 5 , - 4 , - 1 , - 8 , 16 , 4 , - 2 , 1 , - 7 , 33 , 0 } ,
{ 2 , 1 , - 4 , - 2 , 1 , - 10 , 17 , - 2 , 0 , 2 , - 11 , 33 , 0 } ,
{ 1 , - 2 , 7 , - 15 , - 16 , 10 , 8 , 8 , 20 , 11 , 14 , 11 , 0 } ,
{ 2 , 2 , 3 , - 13 , - 13 , 4 , 8 , 12 , 2 , - 3 , 16 , 24 , 0 } ,
{ 1 , 4 , 0 , - 7 , - 8 , - 4 , 9 , 9 , - 2 , - 2 , 8 , 29 , 0 } ,
{ 1 , 1 , 2 , - 4 , - 1 , - 6 , 6 , 3 , - 1 , - 1 , - 3 , 30 , 0 } ,
2020-06-29 15:58:50 +00:00
{ - 7 , 3 , 2 , 10 , - 2 , 3 , 7 , 11 , 19 , - 7 , 8 , 10 , 0 } ,
2019-08-15 08:01:38 +00:00
{ 0 , - 2 , - 5 , - 3 , - 2 , 4 , 20 , 15 , - 1 , - 3 , - 1 , 22 , 0 } ,
{ 3 , - 1 , - 8 , - 4 , - 1 , - 4 , 22 , 8 , - 4 , 2 , - 8 , 28 , 0 } ,
{ 0 , 3 , - 14 , 3 , 0 , 1 , 19 , 17 , 8 , - 3 , - 7 , 20 , 0 } ,
{ 0 , 2 , - 1 , - 8 , 3 , - 6 , 5 , 21 , 1 , 1 , - 9 , 13 , 0 } ,
2020-06-29 15:58:50 +00:00
{ - 4 , - 2 , 8 , 20 , - 2 , 2 , 3 , 5 , 21 , 4 , 6 , 1 , 0 } ,
2019-08-15 08:01:38 +00:00
{ 2 , - 2 , - 3 , - 9 , - 4 , 2 , 14 , 16 , 3 , - 6 , 8 , 24 , 0 } ,
{ 2 , 1 , 5 , - 16 , - 7 , 2 , 3 , 11 , 15 , - 3 , 11 , 22 , 0 } ,
{ 1 , 2 , 3 , - 11 , - 2 , - 5 , 4 , 8 , 9 , - 3 , - 2 , 26 , 0 } ,
{ 0 , - 1 , 10 , - 9 , - 1 , - 8 , 2 , 3 , 4 , 0 , 0 , 29 , 0 } ,
{ 1 , 2 , 0 , - 5 , 1 , - 9 , 9 , 3 , 0 , 1 , - 7 , 20 , 0 } ,
2020-06-29 15:58:50 +00:00
{ - 2 , 8 , - 6 , - 4 , 3 , - 9 , - 8 , 45 , 14 , 2 , - 13 , 7 , 0 } ,
2019-08-15 08:01:38 +00:00
{ 1 , - 1 , 16 , - 19 , - 8 , - 4 , - 3 , 2 , 19 , 0 , 4 , 30 , 0 } ,
{ 1 , 1 , - 3 , 0 , 2 , - 11 , 15 , - 5 , 1 , 2 , - 9 , 24 , 0 } ,
{ 0 , 1 , - 2 , 0 , 1 , - 4 , 4 , 0 , 0 , 1 , - 4 , 7 , 0 } ,
{ 0 , 1 , 2 , - 5 , 1 , - 6 , 4 , 10 , - 2 , 1 , - 4 , 10 , 0 } ,
{ 3 , 0 , - 3 , - 6 , - 2 , - 6 , 14 , 8 , - 1 , - 1 , - 3 , 31 , 0 } ,
{ 0 , 1 , 0 , - 2 , 1 , - 6 , 5 , 1 , 0 , 1 , - 5 , 13 , 0 } ,
{ 3 , 1 , 9 , - 19 , - 21 , 9 , 7 , 6 , 13 , 5 , 15 , 21 , 0 } ,
{ 2 , 4 , 3 , - 12 , - 13 , 1 , 7 , 8 , 3 , 0 , 12 , 26 , 0 } ,
{ 3 , 1 , - 8 , - 2 , 0 , - 6 , 18 , 2 , - 2 , 3 , - 10 , 23 , 0 } ,
{ 1 , 1 , - 4 , - 1 , 1 , - 5 , 8 , 1 , - 1 , 2 , - 5 , 10 , 0 } ,
{ 0 , 1 , - 1 , 0 , 0 , - 2 , 2 , 0 , 0 , 1 , - 2 , 3 , 0 } ,
{ 1 , 1 , - 2 , - 7 , 1 , - 7 , 14 , 18 , 0 , 0 , - 7 , 21 , 0 } ,
{ 0 , 1 , 0 , - 2 , 0 , - 7 , 8 , 1 , - 2 , 0 , - 3 , 24 , 0 } ,
{ 0 , 1 , 1 , - 2 , 2 , - 10 , 10 , 0 , - 2 , 1 , - 7 , 23 , 0 } ,
{ 0 , 2 , 2 , - 11 , 2 , - 4 , - 3 , 39 , 7 , 1 , - 10 , 9 , 0 } ,
{ 1 , 0 , 13 , - 16 , - 5 , - 6 , - 1 , 8 , 6 , 0 , 6 , 29 , 0 } ,
{ 1 , 3 , 1 , - 6 , - 4 , - 7 , 9 , 6 , - 3 , - 2 , 3 , 33 , 0 } ,
{ 4 , 0 , - 17 , - 1 , - 1 , 5 , 26 , 8 , - 2 , 3 , - 15 , 30 , 0 } ,
{ 0 , 1 , - 2 , 0 , 2 , - 8 , 12 , - 6 , 1 , 1 , - 6 , 16 , 0 } ,
{ 0 , 0 , 0 , - 1 , 1 , - 4 , 4 , 0 , 0 , 0 , - 3 , 11 , 0 } ,
{ 0 , 1 , 2 , - 8 , 2 , - 6 , 5 , 15 , 0 , 2 , - 7 , 9 , 0 } ,
{ 1 , - 1 , 12 , - 15 , - 7 , - 2 , 3 , 6 , 6 , - 1 , 7 , 30 , 0 } ,
} ;
2019-09-17 05:48:59 +00:00
static const int g_class_to_filter_mapping [ ALF_NUM_FIXED_FILTER_SETS ] [ MAX_NUM_ALF_CLASSES ] =
2019-08-15 08:01:38 +00:00
{
{ 8 , 2 , 2 , 2 , 3 , 4 , 53 , 9 , 9 , 52 , 4 , 4 , 5 , 9 , 2 , 8 , 10 , 9 , 1 , 3 , 39 , 39 , 10 , 9 , 52 } ,
{ 11 , 12 , 13 , 14 , 15 , 30 , 11 , 17 , 18 , 19 , 16 , 20 , 20 , 4 , 53 , 21 , 22 , 23 , 14 , 25 , 26 , 26 , 27 , 28 , 10 } ,
{ 16 , 12 , 31 , 32 , 14 , 16 , 30 , 33 , 53 , 34 , 35 , 16 , 20 , 4 , 7 , 16 , 21 , 36 , 18 , 19 , 21 , 26 , 37 , 38 , 39 } ,
{ 35 , 11 , 13 , 14 , 43 , 35 , 16 , 4 , 34 , 62 , 35 , 35 , 30 , 56 , 7 , 35 , 21 , 38 , 24 , 40 , 16 , 21 , 48 , 57 , 39 } ,
{ 11 , 31 , 32 , 43 , 44 , 16 , 4 , 17 , 34 , 45 , 30 , 20 , 20 , 7 , 5 , 21 , 22 , 46 , 40 , 47 , 26 , 48 , 63 , 58 , 10 } ,
{ 12 , 13 , 50 , 51 , 52 , 11 , 17 , 53 , 45 , 9 , 30 , 4 , 53 , 19 , 0 , 22 , 23 , 25 , 43 , 44 , 37 , 27 , 28 , 10 , 55 } ,
{ 30 , 33 , 62 , 51 , 44 , 20 , 41 , 56 , 34 , 45 , 20 , 41 , 41 , 56 , 5 , 30 , 56 , 38 , 40 , 47 , 11 , 37 , 42 , 57 , 8 } ,
{ 35 , 11 , 23 , 32 , 14 , 35 , 20 , 4 , 17 , 18 , 21 , 20 , 20 , 20 , 4 , 16 , 21 , 36 , 46 , 25 , 41 , 26 , 48 , 49 , 58 } ,
{ 12 , 31 , 59 , 59 , 3 , 33 , 33 , 59 , 59 , 52 , 4 , 33 , 17 , 59 , 55 , 22 , 36 , 59 , 59 , 60 , 22 , 36 , 59 , 25 , 55 } ,
{ 31 , 25 , 15 , 60 , 60 , 22 , 17 , 19 , 55 , 55 , 20 , 20 , 53 , 19 , 55 , 22 , 46 , 25 , 43 , 60 , 37 , 28 , 10 , 55 , 52 } ,
{ 12 , 31 , 32 , 50 , 51 , 11 , 33 , 53 , 19 , 45 , 16 , 4 , 4 , 53 , 5 , 22 , 36 , 18 , 25 , 43 , 26 , 27 , 27 , 28 , 10 } ,
{ 5 , 2 , 44 , 52 , 3 , 4 , 53 , 45 , 9 , 3 , 4 , 56 , 5 , 0 , 2 , 5 , 10 , 47 , 52 , 3 , 63 , 39 , 10 , 9 , 52 } ,
{ 12 , 34 , 44 , 44 , 3 , 56 , 56 , 62 , 45 , 9 , 56 , 56 , 7 , 5 , 0 , 22 , 38 , 40 , 47 , 52 , 48 , 57 , 39 , 10 , 9 } ,
{ 35 , 11 , 23 , 14 , 51 , 35 , 20 , 41 , 56 , 62 , 16 , 20 , 41 , 56 , 7 , 16 , 21 , 38 , 24 , 40 , 26 , 26 , 42 , 57 , 39 } ,
{ 33 , 34 , 51 , 51 , 52 , 41 , 41 , 34 , 62 , 0 , 41 , 41 , 56 , 7 , 5 , 56 , 38 , 38 , 40 , 44 , 37 , 42 , 57 , 39 , 10 } ,
{ 16 , 31 , 32 , 15 , 60 , 30 , 4 , 17 , 19 , 25 , 22 , 20 , 4 , 53 , 19 , 21 , 22 , 46 , 25 , 55 , 26 , 48 , 63 , 58 , 55 } ,
} ;
2019-10-02 09:25:02 +00:00
//-------------------------typedef enums----------------------------
2019-08-15 08:01:38 +00:00
typedef enum { ALF_FILTER_5X5 = 0 , ALF_FILTER_7X7 = 1 , ALF_NUM_OF_FILTER_TYPES = 2 } alf_filter_type ;
typedef enum { ALF_LUMA = 0 , ALF_CHROMA = 1 } alf_type ;
2019-09-17 05:48:59 +00:00
typedef enum {
T_ALF_APS = 0 ,
T_LMCS_APS = 1 ,
} aps_type_values ;
2019-08-15 08:01:38 +00:00
typedef enum {
ALF_HOR = 0 ,
ALF_VER = 1 ,
ALF_DIAG0 = 2 ,
ALF_DIAG1 = 3 ,
NUM_DIRECTIONS = 4
} alf_directions ;
typedef enum {
CHANNEL_TYPE_LUMA = 0 ,
CHANNEL_TYPE_CHROMA = 1 ,
MAX_NUM_CHANNEL_TYPE = 2
} channel_type ;
typedef enum {
COMPONENT_Y = 0 ,
COMPONENT_Cb = 1 ,
COMPONENT_Cr = 2 ,
MAX_NUM_COMPONENT = 3 ,
} alf_component_id ;
2019-10-02 09:25:02 +00:00
//----------------------------------------------------------------
2019-08-15 08:01:38 +00:00
2019-10-02 09:25:02 +00:00
//-------------------------typedef structs----------------------------
2019-08-15 08:01:38 +00:00
typedef struct alf_covariance {
int num_coeff ;
2019-09-17 05:48:59 +00:00
int num_bins ;
2019-10-18 08:36:31 +00:00
double y [ MAX_ALF_NUM_CLIPPING_VALUES ] [ MAX_NUM_ALF_LUMA_COEFF ] ;
double ee [ MAX_ALF_NUM_CLIPPING_VALUES ] [ MAX_ALF_NUM_CLIPPING_VALUES ] [ MAX_NUM_ALF_LUMA_COEFF ] [ MAX_NUM_ALF_LUMA_COEFF ] ;
2019-08-15 08:01:38 +00:00
double pix_acc ;
} alf_covariance ;
typedef struct clp_rng {
int min ;
int max ;
int bd ;
int n ;
} clp_rng ;
typedef struct clp_rngs {
clp_rng comp [ MAX_NUM_COMPONENT ] ; ///< the bit depth as indicated in the SPS
bool used ;
bool chroma ;
} clp_rngs ;
clp_rngs g_clp_rngs ;
typedef struct alf_classifier {
int class_idx ;
int transpose_idx ;
} alf_classifier ;
2019-10-22 14:29:12 +00:00
typedef struct alf_info_t {
2020-12-02 16:19:49 +00:00
alf_covariance * alf_covariance ; //Covariances of each CTU for luma and chroma components //[ctu_idx][class_idx]
alf_covariance * alf_covariance_y ; //Pointer to the first luma covaraince //[ctu_idx][class_idx]
alf_covariance * alf_covariance_u ; //Pointer to the first Cb covariance //[ctu_idx][class_idx]
alf_covariance * alf_covariance_v ; //Pointer tot he first Cr covariance //[ctu_idx][class_idx]
alf_covariance alf_covariance_frame_luma [ MAX_NUM_ALF_CLASSES ] ; //[class_idx]
alf_covariance alf_covariance_frame_chroma [ MAX_NUM_ALF_ALTERNATIVES_CHROMA ] ; //[class_idx]
2020-12-03 11:01:37 +00:00
alf_covariance alf_covariance_merged [ MAX_NUM_ALF_CLASSES + 2 ] ;
bool * ctu_enable_flag [ MAX_NUM_COMPONENT + 1 ] ;
bool * ctu_enable_flag_tmp [ MAX_NUM_COMPONENT + 1 ] ;
uint8_t * ctu_alternative [ MAX_NUM_COMPONENT + 1 ] ;
uint8_t * ctu_alternative_tmp [ MAX_NUM_COMPONENT + 1 ] ;
2020-12-04 09:33:58 +00:00
double * ctb_distortion_unfilter [ MAX_NUM_COMPONENT + 1 ] ;
2020-12-03 11:01:37 +00:00
2020-12-02 16:19:49 +00:00
int aps_id_start ;
2020-12-04 09:33:58 +00:00
int alf_clip_merged [ ALF_NUM_OF_FILTER_TYPES ] [ MAX_NUM_ALF_CLASSES ] [ MAX_NUM_ALF_CLASSES ] [ MAX_NUM_ALF_LUMA_COEFF ] ;
2020-12-02 16:19:49 +00:00
int * * diff_filter_coeff ; // [lumaClassIdx][coeffIdx]
int * * filter_coeff_set ; // [lumaClassIdx][coeffIdx]
int * * filter_clipp_set ; // [lumaClassIdx][coeffIdx]
short * alf_ctb_filter_set_index_tmp ; //g_num_ctus_in_pic //voisi olla lokaali muuttuja?
short * alf_ctb_filter_index ; //g_num_ctus_in_pic
2019-10-22 14:29:12 +00:00
} alf_info_t ;
2019-08-15 08:01:38 +00:00
2020-08-07 09:09:19 +00:00
typedef struct cc_alf_filter_param {
bool cc_alf_filter_enabled [ 2 ] ;
bool cc_alf_filter_idx_enabled [ 2 ] [ MAX_NUM_CC_ALF_FILTERS ] ;
uint8_t cc_alf_filter_count [ 2 ] ;
short cc_alf_coeff [ 2 ] [ MAX_NUM_CC_ALF_FILTERS ] [ MAX_NUM_CC_ALF_CHROMA_COEFF ] ;
int new_cc_alf_filter [ 2 ] ;
int number_valid_components ;
} cc_alf_filter_param ;
2019-08-15 08:01:38 +00:00
typedef struct alf_aps {
int aps_id ;
2019-09-17 05:48:59 +00:00
int aps_type ;
2020-08-07 09:09:19 +00:00
2019-10-02 09:25:02 +00:00
//sliceparams
2019-09-17 05:48:59 +00:00
bool enabled_flag [ MAX_NUM_COMPONENT ] ; // alf_slice_enable_flag, alf_chroma_idc
2019-10-02 09:25:02 +00:00
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
bool non_linear_flag [ MAX_NUM_CHANNEL_TYPE ] [ MAX_NUM_ALF_ALTERNATIVES_CHROMA ] ; // alf_[luma/chroma]_clip_flag
/*#else
2019-09-17 05:48:59 +00:00
bool non_linear_flag [ MAX_NUM_CHANNEL_TYPE ] ; // alf_nonlinear_enable_flag[Luma/Chroma]
2019-10-02 09:25:02 +00:00
# endif* /
2019-08-15 08:01:38 +00:00
short luma_coeff [ MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF ] ; // alf_coeff_luma_delta[i][j]
2019-09-17 05:48:59 +00:00
short luma_clipp [ MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF ] ; // alf_clipp_luma_[i][j]
2019-10-02 09:25:02 +00:00
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
int num_alternatives_chroma ; // alf_chroma_num_alts_minus_one + 1
short chroma_coeff [ MAX_NUM_ALF_ALTERNATIVES_CHROMA ] [ MAX_NUM_ALF_CHROMA_COEFF ] ; // alf_coeff_chroma[i]
short chroma_clipp [ MAX_NUM_ALF_ALTERNATIVES_CHROMA ] [ MAX_NUM_ALF_CHROMA_COEFF ] ; // alf_clipp_chroma[i]
/*#else
2019-08-15 08:01:38 +00:00
short chroma_coeff [ MAX_NUM_ALF_CHROMA_COEFF ] ; // alf_coeff_chroma[i]
2019-09-17 05:48:59 +00:00
short chroma_clipp [ MAX_NUM_ALF_CHROMA_COEFF ] ; // alf_clipp_chroma[i]
2019-10-02 09:25:02 +00:00
# endif* /
2019-09-17 05:48:59 +00:00
short filter_coeff_delta_idx [ MAX_NUM_ALF_CLASSES ] ; // filter_coeff_delta[i]
bool alf_luma_coeff_flag [ MAX_NUM_ALF_CLASSES ] ; // alf_luma_coeff_flag[i]
int num_luma_filters ; // number_of_filters_minus1 + 1
bool alf_luma_coeff_delta_flag ; // alf_luma_coeff_delta_flag
/*#if !JVET_O0669_REMOVE_ALF_COEFF_PRED
bool alf_luma_coeff_delta_prediction_flag ; // alf_luma_coeff_delta_prediction_flag
2019-08-15 08:01:38 +00:00
int fixed_filter_pattern ;
int fixed_filter_idx [ MAX_NUM_ALF_CLASSES ] ;
int fixed_filter_set_index ;
2019-09-17 05:48:59 +00:00
# endif* /
//std::vector<AlfFilterShape>* filterShapes;
int t_layer ;
bool new_filter_flag [ MAX_NUM_CHANNEL_TYPE ] ;
2020-08-07 09:09:19 +00:00
struct cc_alf_filter_param cc_alf_aps_param ;
2019-08-15 08:01:38 +00:00
} alf_aps ;
typedef struct param_set_map {
bool b_changed ;
2019-08-19 12:08:27 +00:00
//uint8_t* p_nalu_data;
struct alf_aps parameter_set ;
2019-08-15 08:01:38 +00:00
} param_set_map ;
2020-11-23 10:58:02 +00:00
2020-12-04 09:33:58 +00:00
typedef struct array_variables {
short fixed_filter_set_coeff_dec [ ALF_NUM_FIXED_FILTER_SETS ] [ MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF ] ;
short chroma_coeff_final [ MAX_NUM_ALF_ALTERNATIVES_CHROMA ] [ MAX_NUM_ALF_CHROMA_COEFF ] ;
short coeff_final [ MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF ] ;
short coeff_aps_luma [ ALF_CTB_MAX_NUM_APS ] [ MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF ] ;
int16_t chroma_clipp_final [ MAX_NUM_ALF_ALTERNATIVES_CHROMA ] [ MAX_NUM_ALF_CHROMA_COEFF ] ;
int16_t clip_default [ MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF ] ;
int16_t clipp_final [ MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF ] ;
int16_t clipp_aps_luma [ ALF_CTB_MAX_NUM_APS ] [ MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF ] ;
short filter_indices [ MAX_NUM_ALF_CLASSES ] [ MAX_NUM_ALF_CLASSES ] ;
} array_variables ;
2019-10-02 09:25:02 +00:00
//---------------------------------------------------------------
//dunno
2020-11-23 16:20:04 +00:00
alf_covariance * * g_alf_covariance_cc_alf [ 2 ] ; // [compIdx-1][filterIdx][ctbAddr]
alf_covariance * g_alf_covariance_frame_cc_alf [ 2 ] ; // [compIdx-1][filterIdx]
2020-08-07 09:09:19 +00:00
uint8_t * g_training_cov_control ;
uint64_t * * g_unfiltered_distortion ; // for different block size
uint64_t * g_training_distortion [ MAX_NUM_CC_ALF_FILTERS ] ; // for current block size
uint8_t * g_filter_control ; // current iterations filter control
uint8_t * g_best_filter_control ; // best saved filter control
uint64_t * g_luma_swing_greater_than_threshold_count ;
uint64_t * g_chroma_sample_count_near_mid_point ;
2019-10-02 09:25:02 +00:00
//tarpeeton jos WSSD=0
double * g_luma_level_to_weight_plut ; //Ei anneta arvoja miss<73> <73> n
//defaults / consts
static unsigned g_bits_new_filter [ MAX_NUM_CHANNEL_TYPE ] ;
2019-10-22 14:29:12 +00:00
//once ever
static short g_alf_clipping_values [ MAX_NUM_CHANNEL_TYPE ] [ MAX_ALF_NUM_CLIPPING_VALUES ] ;
2019-10-02 09:25:02 +00:00
static alf_classifier * * g_classifier ;
static bool g_created = false ;
2020-10-15 08:47:02 +00:00
static uint32_t g_frame_count = MAX_INT ;
2020-08-07 09:09:19 +00:00
uint8_t * g_cc_alf_filter_control [ 2 ] ;
int g_aps_id_cc_alf_start [ 2 ] ;
2020-11-05 13:48:14 +00:00
int g_reuse_aps_id [ 2 ] ;
2019-10-22 14:29:12 +00:00
//once per frame
2019-10-02 09:25:02 +00:00
int * * g_diff_filter_coeff ; // [lumaClassIdx][coeffIdx]
int * * g_filter_coeff_set ; // [lumaClassIdx][coeffIdx]
2019-10-22 14:29:12 +00:00
int * * g_filter_clipp_set ; // [lumaClassIdx][coeffIdx]
2019-10-02 09:25:02 +00:00
short * g_alf_ctb_filter_set_index_tmp ; //g_num_ctus_in_pic //voisi olla lokaali muuttuja?
2019-10-22 14:29:12 +00:00
short * g_alf_ctb_filter_index ; //g_num_ctus_in_pic
2020-08-07 09:09:19 +00:00
struct cc_alf_filter_param g_cc_alf_filter_param ;
2019-10-02 09:25:02 +00:00
//temps
static alf_aps g_alf_aps_temp ;
2019-10-23 11:39:45 +00:00
//kvz_picture *tmp_rec_pic;
2020-10-26 12:28:50 +00:00
kvz_pixel * alf_fulldata_buf ;
2019-10-23 11:39:45 +00:00
kvz_pixel * alf_fulldata ;
kvz_pixel * alf_tmp_y ;
kvz_pixel * alf_tmp_u ;
kvz_pixel * alf_tmp_v ;
2019-10-18 08:36:31 +00:00
cabac_data_t cabac_estimator ;
2019-08-15 08:01:38 +00:00
2019-10-02 09:25:02 +00:00
//-------------------------init function----------------------------
2020-10-27 13:40:31 +00:00
2019-10-02 09:25:02 +00:00
//------------------------------------------------------------------
2019-08-15 08:01:38 +00:00
//-------------------------help functions---------------------------
2020-10-13 14:43:03 +00:00
2020-11-23 10:58:02 +00:00
void set_aps_map ( kvz_config * const cfg ) ;
2020-10-28 10:57:46 +00:00
void init_ctu_alternative_chroma ( uint8_t * ctu_alts [ MAX_NUM_COMPONENT ] , const int32_t num_ctus ) ;
2020-08-20 13:35:14 +00:00
int16_t clip_alf ( const int16_t clip , const int16_t ref , const int16_t val0 , const int16_t val1 ) ;
2019-10-02 09:25:02 +00:00
int alf_clip_pixel ( const int a , const clp_rng clp_rng ) ;
2020-08-20 13:35:14 +00:00
int16_t alf_clip3 ( const int16_t min_val , const int16_t max_val , const int16_t a ) ;
2020-10-26 10:38:51 +00:00
void get_clip_max ( const alf_covariance * cov , int * clip_max ) ;
void reduce_clip_cost ( const alf_covariance * cov , int * clip ) ;
void set_ey_from_clip ( const alf_covariance * cov , const int * clip , double ee [ MAX_NUM_ALF_LUMA_COEFF ] [ MAX_NUM_ALF_LUMA_COEFF ] , double y [ MAX_NUM_ALF_LUMA_COEFF ] , int siz ) ;
double optimize_filter ( const alf_covariance * cov , int * clip , double * f , bool optimize_clip ) ;
2019-10-02 09:25:02 +00:00
double optimize_filter_clip ( alf_covariance * cov , int * clip ) ;
double optimize_filter_gns_calc ( alf_covariance * cov , const int * clip , double * f , int size ) ;
void gns_backsubstitution ( double r [ MAX_NUM_ALF_LUMA_COEFF ] [ MAX_NUM_ALF_LUMA_COEFF ] , double * z , int size , double * A ) ;
void gns_transpose_backsubstitution ( double u [ MAX_NUM_ALF_LUMA_COEFF ] [ MAX_NUM_ALF_LUMA_COEFF ] , double * rhs , double * x , int order ) ;
int gns_cholesky_dec ( double inp_matr [ MAX_NUM_ALF_LUMA_COEFF ] [ MAX_NUM_ALF_LUMA_COEFF ] , double out_matr [ MAX_NUM_ALF_LUMA_COEFF ] [ MAX_NUM_ALF_LUMA_COEFF ] , int num_eq ) ;
int gns_solve_by_chol ( double lhs [ MAX_NUM_ALF_LUMA_COEFF ] [ MAX_NUM_ALF_LUMA_COEFF ] , double rhs [ MAX_NUM_ALF_LUMA_COEFF ] , double * x , int num_eq ) ;
int gns_solve_by_chol_clip_gns ( alf_covariance * cov , const int * clip , double * x , int num_eq ) ;
2020-10-26 10:38:51 +00:00
double calc_error_for_coeffs ( const alf_covariance * cov , const int * clip , const int * coeff , const int num_coeff , const int bit_depth ) ;
2019-09-17 05:48:59 +00:00
//int get_golomb_k_min(channel_type channel, const int numFilters, int kMinTab[MAX_NUM_ALF_LUMA_COEFF], int bitsCoeffScan[11/*m_MAX_SCAN_VAL*/][16/*m_MAX_EXP_GOLOMB*/]);
2019-10-02 09:25:02 +00:00
int length_golomb ( int coeff_val , int k , bool signed_coeff ) ;
double get_dist_coeff_force_0 ( bool * coded_var_bins , double error_force_0_coeff_tab [ MAX_NUM_ALF_CLASSES ] [ 2 ] , int * bits_var_bin , const int num_filters ) ;
double get_dist_force_0 ( channel_type channel , const int num_filters , double error_tab_force_0_coeff [ MAX_NUM_ALF_CLASSES ] [ 2 ] , bool * coded_var_bins ) ;
int get_cost_filter_coeff_force_0 ( channel_type channel , int * * p_diff_q_filter_coeff_int_pp , const int num_filters , bool * coded_var_bins ) ;
int get_cost_filter_coeff ( channel_type channel , int * * p_diff_q_filter_coeff_int_pp , const int num_filters ) ;
int get_cost_filter_clipp ( channel_type channel , int * * p_diff_q_filter_coeff_int_pp , const int num_filters ) ;
//int get_tb_length(int ui_symbol, const int ui_max_symbol);//#if !JVET_O0491_HLS_CLEANUP
int get_non_filter_coeff_rate ( alf_aps * aps ) ;
int length_filter_coeffs ( channel_type channel , const int num_filters , int * * filter_coeff ) ;
2020-10-26 10:38:51 +00:00
double calculate_error ( const alf_covariance * cov , const int * clip , const double * coeff ) ;
2019-10-02 09:25:02 +00:00
double calculate_error_opt_filt ( alf_covariance * cov , const int * clip ) ;
//int get_coeff_rate(alf_aps *aps, bool is_chroma);//#if !JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
int get_chroma_coeff_rate ( alf_aps * aps , int alt_idx ) ;
//int length_truncated_unary(int symbol, int max_symbol);//#if !JVET_O0491_HLS_CLEANUP
double get_filtered_distortion ( alf_covariance * cov , const int num_classes , const int num_filters_minus1 , const int num_coeff ) ;
double get_unfiltered_distortion_cov_channel ( alf_covariance * cov , channel_type channel ) ;
double get_unfiltered_distortion_cov_classes ( alf_covariance * cov , const int num_classes ) ;
2020-12-02 16:19:49 +00:00
void get_frame_stats ( alf_info_t * alf_info , channel_type channel , const int32_t num_ctus ) ;
2020-12-03 11:01:37 +00:00
void get_frame_stat ( alf_covariance * frame_cov , alf_covariance * ctb_cov , bool * ctb_enable_flags , uint8_t * ctb_alt_idx , const int num_classes , int alt_idx , const int32_t num_ctus ) ;
2019-10-18 08:36:31 +00:00
void copy_cov ( alf_covariance * dst , alf_covariance * src ) ;
2019-09-17 05:48:59 +00:00
void copy_alf_param ( alf_aps * dst , alf_aps * src ) ;
2019-10-02 09:25:02 +00:00
void copy_alf_param_w_channel ( alf_aps * dst , alf_aps * src , channel_type channel ) ;
2020-10-01 15:57:06 +00:00
void copy_aps ( alf_aps * dst , alf_aps * src ) ;
void copy_aps_to_map ( param_set_map * dst , alf_aps * src , int8_t aps_id ) ;
2019-11-25 13:04:26 +00:00
//bool compare_alf_param(const alf_aps* aps_1, const alf_aps* aps_2);
2019-09-17 05:48:59 +00:00
void reset_alf_param ( alf_aps * src ) ;
void add_alf_cov ( alf_covariance * dst , alf_covariance * src ) ;
2019-10-02 09:25:02 +00:00
void add_alf_cov_lhs_rhs ( alf_covariance * dst , alf_covariance * lhs , alf_covariance * rhs ) ;
2019-09-23 11:44:26 +00:00
void reset_alf_covariance ( alf_covariance * alf , int num_bins ) ;
2020-12-02 16:19:49 +00:00
void init_alf_covariance ( alf_covariance * alf , int num_bins ) ;
2020-08-07 09:09:19 +00:00
void reset_cc_alf_aps_param ( cc_alf_filter_param * cc_alf ) ;
2020-09-01 12:17:47 +00:00
void copy_pixels ( kvz_pixel * src , int x_src_start , int y_src_start , int src_stride ,
kvz_pixel * dst , int x_dst_start , int y_dst_start , int dst_stride ,
int width , int height ) ;
2019-10-18 08:36:31 +00:00
void adjust_pixels ( kvz_pixel * src , int x_start , int x_end , int y_start , int y_end ,
2020-09-01 12:17:47 +00:00
int stride , int pic_width , int pic_height ) ;
void adjust_pixels_CTU_plus_4_pix ( kvz_pixel * src , int x_start , int x_end , int y_start , int y_end ,
2019-10-18 08:36:31 +00:00
int stride , int pic_width , int pic_height ) ;
2020-09-01 12:17:47 +00:00
//Need to adjust
2019-11-20 13:24:44 +00:00
void adjust_pixels_chroma ( kvz_pixel * src , int x_start , int x_end , int y_start , int y_end ,
int stride , int pic_width , int pic_height ) ;
2020-09-01 12:17:47 +00:00
2020-12-03 11:01:37 +00:00
void set_ctu_enable_flag ( bool * * flags , channel_type channel , uint8_t value , const int32_t num_ctus ) ;
void copy_ctu_enable_flag ( bool * * flags_dst , bool * * flags_src , channel_type channel , const int32_t num_ctus ) ;
2019-09-23 11:44:26 +00:00
2019-08-15 08:01:38 +00:00
//-------------------------------------------------------------------
//-------------------------encoding functions------------------------
2019-09-17 05:48:59 +00:00
2019-09-23 11:44:26 +00:00
//is_crossed_by_virtual_boundaries -osuus ep<65> t<EFBFBD> ydellinen
2020-10-27 13:40:31 +00:00
void kvz_alf_enc_process ( encoder_state_t * const state ) ;
2019-10-02 09:25:02 +00:00
2019-09-17 05:48:59 +00:00
double kvz_alf_derive_ctb_alf_enable_flags ( encoder_state_t * const state ,
channel_type channel ,
double * dist_unfilter ,
2019-10-02 09:25:02 +00:00
const int num_classes ,
2020-12-04 09:33:58 +00:00
const double chroma_weight ,
array_variables * arr_vars
2019-10-02 09:25:02 +00:00
) ;
2019-09-17 05:48:59 +00:00
2020-12-02 16:19:49 +00:00
void kvz_alf_create ( videoframe_t * frame , enum kvz_chroma_format chroma_format ) ;
2020-10-26 10:38:51 +00:00
void kvz_alf_enc_create ( encoder_state_t * const state ) ;
2019-08-15 08:01:38 +00:00
2020-12-02 16:19:49 +00:00
void kvz_alf_destroy ( videoframe_t * const frame ) ;
2019-11-20 13:24:44 +00:00
void kvz_alf_enc_destroy ( videoframe_t * const frame ) ;
2019-08-15 08:01:38 +00:00
2020-10-26 10:38:51 +00:00
void kvz_alf_encoder ( encoder_state_t * const state ,
2019-08-15 08:01:38 +00:00
alf_aps * aps ,
2019-10-02 09:25:02 +00:00
channel_type channel ,
2020-12-04 09:33:58 +00:00
const double lambda_chroma_weight ,
array_variables * arr_vars
2019-10-02 09:25:02 +00:00
) ;
2019-08-15 08:01:38 +00:00
2019-09-17 05:48:59 +00:00
//isIntra, PendingRasInit, IDRorBLA <--- ? selvit<69> n<> m<EFBFBD>
2020-10-26 10:38:51 +00:00
void kvz_alf_get_avai_aps_ids_luma ( encoder_state_t * const state ,
2019-09-17 05:48:59 +00:00
int * newApsId ,
2019-10-24 15:02:47 +00:00
int * aps_ids ,
2019-09-17 05:48:59 +00:00
int * size_of_aps_ids ) ;
2019-08-15 08:01:38 +00:00
2020-10-27 13:40:31 +00:00
void kvz_alf_derive_stats_for_filtering ( encoder_state_t * const state ) ;
2019-08-15 08:01:38 +00:00
2019-09-17 05:48:59 +00:00
//mik<69> on alf_WSSD?
2020-10-26 10:38:51 +00:00
void kvz_alf_get_blk_stats ( encoder_state_t * const state ,
2019-08-15 08:01:38 +00:00
channel_type channel ,
2020-12-02 16:19:49 +00:00
alf_covariance * alfCovariace ,
2019-10-02 09:25:02 +00:00
alf_classifier * * g_classifier ,
2019-08-15 08:01:38 +00:00
kvz_pixel * org ,
int32_t org_stride ,
kvz_pixel * rec ,
int32_t rec_stride ,
const int x_pos ,
const int y_pos ,
2019-09-17 05:48:59 +00:00
const int x_dst ,
const int y_dst ,
2019-08-15 08:01:38 +00:00
const int width ,
2019-09-17 05:48:59 +00:00
const int height ,
int vb_ctu_height ,
int vb_pos ) ;
2019-08-15 08:01:38 +00:00
2020-08-20 13:35:14 +00:00
void kvz_alf_calc_covariance ( int16_t e_local [ MAX_NUM_ALF_LUMA_COEFF ] [ MAX_ALF_NUM_CLIPPING_VALUES ] ,
2019-08-15 08:01:38 +00:00
const kvz_pixel * rec ,
const int stride ,
2019-09-17 05:48:59 +00:00
const channel_type channel ,
const int transpose_idx ,
int vb_distance ) ;
2019-08-15 08:01:38 +00:00
2020-10-26 10:38:51 +00:00
double kvz_alf_get_filter_coeff_and_cost ( encoder_state_t * const state ,
2019-08-15 08:01:38 +00:00
channel_type channel ,
double dist_unfilter ,
int * ui_coeff_bits ,
bool b_re_collect_stat ,
2020-12-04 09:33:58 +00:00
bool only_filter_cost ,
array_variables * arr_vars
2020-09-25 12:36:10 +00:00
) ;
2019-08-15 08:01:38 +00:00
int kvz_alf_derive_filter_coefficients_prediction_mode ( channel_type channel ,
int * * filter_set ,
2019-09-17 05:48:59 +00:00
const int num_filters ) ;
2019-08-15 08:01:38 +00:00
void kvz_alf_merge_classes ( channel_type channel ,
alf_covariance * cov ,
alf_covariance * cov_merged ,
2019-09-17 05:48:59 +00:00
int clip_merged [ MAX_NUM_ALF_CLASSES ] [ MAX_NUM_ALF_CLASSES ] [ MAX_NUM_ALF_LUMA_COEFF ] ,
2019-08-15 08:01:38 +00:00
const int num_classes ,
short filter_indices [ MAX_NUM_ALF_CLASSES ] [ MAX_NUM_ALF_CLASSES ] ) ;
2020-10-26 10:38:51 +00:00
double kvz_alf_merge_filters_and_cost ( encoder_state_t * const state ,
2019-09-17 05:48:59 +00:00
alf_aps * alf_aps ,
2019-08-15 08:01:38 +00:00
channel_type channel ,
int * ui_coeff_bits ,
alf_covariance * cov_frame ,
2019-09-17 05:48:59 +00:00
alf_covariance * cov_merged ,
2020-12-04 09:33:58 +00:00
int clip_merged [ MAX_NUM_ALF_CLASSES ] [ MAX_NUM_ALF_CLASSES ] [ MAX_NUM_ALF_LUMA_COEFF ] ,
array_variables * arr_vars
) ;
2019-08-15 08:01:38 +00:00
double kvz_alf_derive_filter_coeffs ( alf_aps * aps ,
channel_type channel ,
alf_covariance * cov ,
alf_covariance * covMerged ,
short * filter_indices ,
int numFilters ,
2019-09-17 05:48:59 +00:00
double errorTabForce0Coeff [ MAX_NUM_ALF_CLASSES ] [ 2 ] ,
2020-10-28 10:57:46 +00:00
int clip_merged [ MAX_NUM_ALF_CLASSES ] [ MAX_NUM_ALF_CLASSES ] [ MAX_NUM_ALF_LUMA_COEFF ] ,
const int bit_depth ) ;
2019-08-15 08:01:38 +00:00
double kvz_alf_derive_coeff_quant ( channel_type channel ,
2019-09-17 05:48:59 +00:00
int * filter_clipp ,
int * filter_coeff_quant ,
const alf_covariance * cov ,
const int bit_depth ,
const bool oprimize_clip ) ;
//Muutama asia pit<69> <74> viel<65> p<> ivitt<74> <74>
//bookmarks
2020-10-26 10:38:51 +00:00
void kvz_alf_encoder_ctb ( encoder_state_t * const state ,
2019-10-02 09:25:02 +00:00
alf_aps * aps ,
2020-12-04 09:33:58 +00:00
const double lambda_chroma_weight ,
array_variables * arr_vars
2019-10-02 09:25:02 +00:00
) ;
2019-08-15 08:01:38 +00:00
2020-12-04 09:33:58 +00:00
void kvz_alf_reconstruct ( encoder_state_t * const state ,
array_variables * arr_vars
) ;
2019-08-15 08:01:38 +00:00
2020-10-26 08:09:05 +00:00
//-------------------------CC ALF encoding functions------------------------
2020-11-05 13:48:14 +00:00
void setup_cc_alf_aps ( encoder_state_t * const state ) ;
void round_filt_coeff_cc_alf ( int16_t * filter_coeff_quant ,
double * filter_coeff , const int num_coeff ,
const int factor ) ;
void derive_cc_alf_filter_coeff ( alf_component_id comp_id ,
short filter_coeff [ MAX_NUM_CC_ALF_FILTERS ] [ MAX_NUM_CC_ALF_CHROMA_COEFF ] ,
const uint8_t filter_idx ) ;
void determine_control_idc_values ( encoder_state_t * const state , const alf_component_id comp_id ,
const int ctu_width_c , const int ctu_height_c , const int pic_width_c ,
const int pic_height_c , double * * unfiltered_distortion ,
uint64_t * training_distortion [ MAX_NUM_CC_ALF_FILTERS ] ,
uint64_t * luma_swing_greater_than_threshold_count ,
uint64_t * chroma_sample_count_near_mid_point ,
bool reuse_temporal_filter_coeff , uint8_t * training_cov_control ,
uint8_t * filter_control , uint64_t * cur_total_distortion ,
double * cur_total_rate , bool filter_enabled [ MAX_NUM_CC_ALF_FILTERS ] ,
uint8_t map_filter_idx_to_filter_idc [ MAX_NUM_CC_ALF_FILTERS + 1 ] ,
uint8_t * cc_alf_filter_count ) ;
void get_available_cc_alf_aps_ids ( encoder_state_t * const state ,
alf_component_id compID , int * aps_ids_size ,
int * aps_ids ) ;
void apply_cc_alf_filter ( encoder_state_t * const state , alf_component_id comp_id , const kvz_pixel * dst_buf ,
const kvz_pixel * rec_yuv_ext , const int luma_stride , uint8_t * filter_control ,
const short filter_set [ MAX_NUM_CC_ALF_FILTERS ] [ MAX_NUM_CC_ALF_CHROMA_COEFF ] ,
const int selected_filter_idx ) ;
void derive_cc_alf_filter ( encoder_state_t * const state ,
alf_component_id comp_id , const kvz_picture * org_yuv ,
2020-11-23 10:58:02 +00:00
const kvz_picture * rec_dst_yuv ) ;
2020-11-05 13:48:14 +00:00
2020-10-26 10:38:51 +00:00
void derive_stats_for_cc_alf_filtering ( encoder_state_t * const state ,
2020-11-13 14:15:12 +00:00
const kvz_picture * org_yuv ,
2020-10-26 08:09:05 +00:00
const int comp_idx , const int mask_stride ,
const uint8_t filter_idc ) ;
2020-10-26 10:38:51 +00:00
void get_blk_stats_cc_alf ( encoder_state_t * const state ,
2020-10-26 08:09:05 +00:00
alf_covariance * alf_covariance ,
2020-11-23 10:58:02 +00:00
const kvz_picture * org_yuv ,
2020-10-26 08:09:05 +00:00
const alf_component_id comp_id ,
const int x_pos , const int y_pos ,
const int width , const int height ) ;
2020-10-28 14:54:34 +00:00
void calc_covariance_cc_alf ( int32_t e_local [ MAX_NUM_CC_ALF_CHROMA_COEFF ] [ 1 ] ,
const kvz_pixel * rec , const int stride ,
int vb_distance ) ;
2020-11-05 13:48:14 +00:00
void count_luma_swing_greater_than_threshold ( const kvz_pixel * luma , int luma_stride , int height , int width ,
int log2_block_width , int log2_block_height ,
uint64_t * luma_swing_greater_than_threshold_count ,
int luma_count_stride ,
int8_t input_bit_depth ) ;
2020-10-26 08:09:05 +00:00
2020-12-04 09:33:58 +00:00
void init_distortion_cc_alf ( double * * ctb_distortion_unfilter , const int num_ctus ) ;
2020-10-28 14:54:34 +00:00
2020-11-05 13:48:14 +00:00
void get_frame_stats_cc_alf ( alf_component_id comp_idx , int filter_idc , const int num_ctus_in_frame ) ;
void filter_blk_cc_alf ( encoder_state_t * const state ,
const kvz_pixel * dst_buf , const kvz_pixel * rec_src ,
const int rec_luma_stride ,
const alf_component_id comp_id , const int16_t * filter_coeff ,
const clp_rngs clp_rngs , int vb_ctu_height , int vb_pos ,
const int x_pos , const int y_pos ,
const int blk_width ,
const int blk_height ) ;
2020-10-26 08:09:05 +00:00
//----------------------------------------------------------------------
2019-08-15 08:01:38 +00:00
//----------------------------------------------------------------------
//-------------------------cabac writer functions------------------------
2019-10-02 09:25:02 +00:00
2019-10-18 08:36:31 +00:00
void kvz_cabac_reset_bits ( cabac_data_t * const data ) ;
void code_alf_ctu_enable_flags_channel ( encoder_state_t * const state ,
cabac_data_t * const cabac ,
channel_type channel ,
2019-09-17 05:48:59 +00:00
alf_aps * aps ) ;
2019-10-18 08:36:31 +00:00
void code_alf_ctu_enable_flags_component ( encoder_state_t * const state ,
cabac_data_t * const cabac ,
alf_component_id component_id ,
alf_aps * aps ) ;
2019-08-15 08:01:38 +00:00
void code_alf_ctu_enable_flag ( encoder_state_t * const state ,
2019-10-18 08:36:31 +00:00
cabac_data_t * const cabac ,
2019-08-15 08:01:38 +00:00
uint32_t ctu_rs_addr ,
2019-10-18 08:36:31 +00:00
alf_component_id component_id ,
2019-08-15 08:01:38 +00:00
alf_aps * aps ) ;
void code_alf_ctu_filter_index ( encoder_state_t * const state ,
2019-10-18 08:36:31 +00:00
cabac_data_t * const cabac ,
2019-08-15 08:01:38 +00:00
uint32_t ctu_rs_addr ,
bool alf_enable_luma ) ;
2019-10-02 09:25:02 +00:00
void code_alf_ctu_alternatives_channel ( encoder_state_t * const state ,
2019-10-18 08:36:31 +00:00
cabac_data_t * const cabac ,
2019-10-02 09:25:02 +00:00
channel_type channel ,
2020-09-25 12:36:10 +00:00
alf_aps * aps
) ;
2019-10-02 09:25:02 +00:00
void code_alf_ctu_alternatives_component ( encoder_state_t * const state ,
2019-10-18 08:36:31 +00:00
cabac_data_t * const cabac ,
2019-10-02 09:25:02 +00:00
alf_component_id comp_id ,
2020-09-25 12:36:10 +00:00
alf_aps * aps
) ;
2019-10-02 09:25:02 +00:00
void code_alf_ctu_alternative_ctu ( encoder_state_t * const state ,
2019-10-18 08:36:31 +00:00
cabac_data_t * const cabac ,
2019-10-02 09:25:02 +00:00
uint32_t ctu_rs_addr ,
2019-10-18 08:36:31 +00:00
const alf_component_id comp_idx ,
2019-10-02 09:25:02 +00:00
const alf_aps * aps ) ;
2020-09-25 12:36:10 +00:00
void kvz_encode_alf_bits ( encoder_state_t * const state , const int ctu_idx ) ;
2019-10-18 08:36:31 +00:00
2019-11-20 13:24:44 +00:00
void encoder_state_write_adaptation_parameter_set ( encoder_state_t * const state ,
alf_aps * aps ) ;
2020-10-01 15:57:06 +00:00
void encode_alf_aps_flags ( encoder_state_t * const state ,
2019-11-20 13:24:44 +00:00
alf_aps * aps ) ;
2020-10-01 15:57:06 +00:00
void encode_alf_aps_filter ( encoder_state_t * const state ,
2019-11-20 13:24:44 +00:00
alf_aps * aps ,
const bool is_chroma ,
const int alt_idx ) ;
2020-10-01 15:57:06 +00:00
void encode_alf_adaptive_parameter_set ( encoder_state_t * const state ) ;
void encode_alf_aps_lmcs ( encoder_state_t * const state ) ;
void encode_alf_aps_scaling_list ( encoder_state_t * const state ) ;
void encode_alf_aps ( encoder_state_t * const state ) ;
2019-11-20 13:24:44 +00:00
2020-11-05 13:48:14 +00:00
//------------------------- CC ALF cabac writer functions------------------------
void code_cc_alf_filter_control_idc ( encoder_state_t * const state ,
cabac_data_t * const cabac , uint8_t idc_val ,
const alf_component_id comp_id , const int ctu_idx ,
const uint8_t * filter_control_idc ,
const int filter_count ) ;
//---------------------------------------------------------------------
2019-08-15 08:01:38 +00:00
//---------------------------------------------------------------------
//-------------------------CTU functions--------------------------------
2019-10-02 09:25:02 +00:00
2020-10-26 10:38:51 +00:00
void kvz_alf_reconstruct_coeff_aps ( encoder_state_t * const state ,
2019-08-15 08:01:38 +00:00
bool luma ,
bool chroma ,
2020-12-04 09:33:58 +00:00
bool is_rdo ,
array_variables * arr_vars
) ;
2019-08-15 08:01:38 +00:00
2020-10-26 10:38:51 +00:00
void kvz_alf_reconstruct_coeff ( encoder_state_t * const state ,
2019-08-15 08:01:38 +00:00
alf_aps * aps ,
channel_type channel ,
const bool is_rdo ,
2020-12-04 09:33:58 +00:00
const bool is_redo ,
array_variables * arr_vars
) ;
2019-08-15 08:01:38 +00:00
2020-10-26 10:38:51 +00:00
void kvz_alf_derive_classification ( encoder_state_t * const state ,
2019-08-15 08:01:38 +00:00
const int width ,
const int height ,
int x_pos ,
2019-09-17 05:48:59 +00:00
int y_pos ,
const int blk_dst_x ,
const int blk_dst_y ) ;
2019-08-15 08:01:38 +00:00
2019-10-02 09:25:02 +00:00
/*#if !JVET_O0525_REMOVE_PCM
2019-09-17 05:48:59 +00:00
//VTM6.0 (ei muuttunut)
2019-08-15 08:01:38 +00:00
//OK
//Turha jos PCM on pois p<> <70> lt<6C> .
//cu->ipcm?
void kvz_alf_reset_pcm_blk_class_info ( encoder_state_t * const state ,
const lcu_order_element_t * const lcu ,
const int width ,
const int height ,
int x_pos ,
2019-10-02 09:25:02 +00:00
int y_pos ) ; */
2019-08-15 08:01:38 +00:00
void kvz_alf_derive_classification_blk ( encoder_state_t * const state ,
const int shift ,
const int n_height ,
const int n_width ,
2019-09-17 05:48:59 +00:00
const int blk_pos_x ,
const int blk_pos_y ,
const int blk_dst_x ,
const int blk_dst_y ,
2019-09-23 11:44:26 +00:00
const int vb_ctu_height ,
int vb_pos ) ;
2019-09-17 05:48:59 +00:00
2019-09-23 11:44:26 +00:00
//Pit<69> isi testata; x,y,pixels,toimivuus
//kvz_alf_reconstructor-funktiossa VTM:ss<73> return, pois jotta
2019-08-15 08:01:38 +00:00
//p<> <70> see t<> h<EFBFBD> n funktioon
2019-10-02 09:25:02 +00:00
//tarkista toimivuus
2020-10-26 10:38:51 +00:00
void kvz_alf_filter_block ( encoder_state_t * const state ,
2019-10-18 08:36:31 +00:00
const kvz_pixel * src_pixels ,
kvz_pixel * dst_pixels ,
const int src_stride ,
const int dst_stride ,
2019-09-17 05:48:59 +00:00
const short * filter_set ,
2020-08-20 13:35:14 +00:00
const int16_t * fClipSet ,
2019-08-15 08:01:38 +00:00
clp_rng clp_rng ,
alf_component_id component_id ,
const int width ,
const int height ,
int x_pos ,
2019-09-17 05:48:59 +00:00
int y_pos ,
int blk_dst_x ,
int blk_dst_y ,
2019-09-23 11:44:26 +00:00
int vb_pos ,
const int vb_ctu_height ) ;
2019-08-15 08:01:38 +00:00
//---------------------------------------------------------------------
//kvz_alf_filter_block funktion dst?
# endif //ALF_H_