Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Remy Foray
VVCSoftware_VTM
Commits
3190db94
Commit
3190db94
authored
Apr 17, 2019
by
Muhammed Coban
Browse files
RDPCM intergration JVET-N0413/N0214
parent
da553044
Changes
28
Hide whitespace changes
Inline
Side-by-side
source/App/EncoderApp/EncApp.cpp
View file @
3190db94
...
...
@@ -291,6 +291,9 @@ void EncApp::xInitLibCfg()
#endif
#if JVET_N0449_MMVD_SIMP
m_cEncLib
.
setMmvdDisNum
(
m_MmvdDisNum
);
#endif
#if JVET_N0413_RDPCM
m_cEncLib
.
setRDPCM
(
m_RdpcmMode
);
#endif
m_cEncLib
.
setIBCMode
(
m_IBCMode
);
m_cEncLib
.
setIBCLocalSearchRangeX
(
m_IBCLocalSearchRangeX
);
...
...
source/App/EncoderApp/EncAppCfg.cpp
View file @
3190db94
...
...
@@ -885,6 +885,9 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
(
"DMVR"
,
m_DMVR
,
false
,
"Decoder-side Motion Vector Refinement"
)
#if JVET_N0449_MMVD_SIMP
(
"MmvdDisNum"
,
m_MmvdDisNum
,
8
,
"Number of MMVD Distance Entries"
)
#endif
#if JVET_N0413_RDPCM
(
"RDPCM"
,
m_RdpcmMode
,
false
,
"RDPCM"
)
#endif
(
"IBC"
,
m_IBCMode
,
0u
,
"IBCMode (0x1:enabled, 0x0:disabled) [default: disabled]"
)
(
"IBCLocalSearchRangeX"
,
m_IBCLocalSearchRangeX
,
128u
,
"Search range of IBC local search in x direction"
)
...
...
@@ -1983,6 +1986,9 @@ bool EncAppCfg::xCheckParameter()
xConfirmPara
(
m_DMVR
,
"DMVR only allowed with NEXT profile"
);
#if JVET_N0449_MMVD_SIMP
xConfirmPara
(
m_MmvdDisNum
,
"Number of distance MMVD entry setting only allowed with NEXT profile"
);
#endif
#if JVET_N0413_RDPCM
xConfirmPara
(
m_RdpcmMode
,
"RDPCM only allowed with NEXT profile"
);
#endif
// ADD_NEW_TOOL : (parameter check) add a check for next tools here
}
...
...
@@ -3183,6 +3189,9 @@ void EncAppCfg::xPrintParameter()
msg
(
VERBOSE
,
"DMVR:%d "
,
m_DMVR
);
#if JVET_N0449_MMVD_SIMP
msg
(
VERBOSE
,
"MmvdDisNum:%d "
,
m_MmvdDisNum
);
#endif
#if JVET_N0413_RDPCM
msg
(
VERBOSE
,
"RDPCM:%d "
,
m_RdpcmMode
);
#endif
}
msg
(
VERBOSE
,
"IBC:%d "
,
m_IBCMode
);
...
...
source/App/EncoderApp/EncAppCfg.h
View file @
3190db94
...
...
@@ -275,6 +275,9 @@ protected:
#endif
#if JVET_N0449_MMVD_SIMP
int
m_MmvdDisNum
;
#endif
#if JVET_N0413_RDPCM
bool
m_RdpcmMode
;
#endif
unsigned
m_IBCMode
;
unsigned
m_IBCLocalSearchRangeX
;
...
...
source/Lib/CommonLib/CommonDef.h
View file @
3190db94
...
...
@@ -219,6 +219,9 @@ static const int HOR_IDX = (1 * (NUM_DIR - 1) + 2); ///< inde
static
const
int
DIA_IDX
=
(
2
*
(
NUM_DIR
-
1
)
+
2
);
///< index for intra DIAGONAL mode
static
const
int
VER_IDX
=
(
3
*
(
NUM_DIR
-
1
)
+
2
);
///< index for intra VERTICAL mode
static
const
int
VDIA_IDX
=
(
4
*
(
NUM_DIR
-
1
)
+
2
);
///< index for intra VDIAGONAL mode
#if JVET_N0413_RDPCM
static
const
int
BDPCM_IDX
=
(
5
*
(
NUM_DIR
-
1
)
+
2
);
///< index for intra VDIAGONAL mode
#endif
static
const
int
NOMODE_IDX
=
MAX_UCHAR
;
///< indicating uninitialized elements
static
const
int
NUM_CHROMA_MODE
=
(
5
+
NUM_LMC_MODE
);
///< total number of chroma modes
...
...
@@ -346,6 +349,9 @@ static const int DMVR_SUBCU_WIDTH_LOG2 = 4;
static
const
int
DMVR_SUBCU_HEIGHT_LOG2
=
4
;
static
const
int
MAX_NUM_SUBCU_DMVR
=
((
MAX_CU_SIZE
*
MAX_CU_SIZE
)
>>
(
DMVR_SUBCU_WIDTH_LOG2
+
DMVR_SUBCU_HEIGHT_LOG2
));
static
const
int
DMVR_NUM_ITERATION
=
2
;
#if JVET_N0413_RDPCM
static
const
int
BDPCM_MAX_CU_SIZE
=
32
;
///< maximum CU size for RDPCM mode
#endif
//QTBT high level parameters
//for I slice luma CTB configuration para.
...
...
source/Lib/CommonLib/ContextModelling.cpp
View file @
3190db94
...
...
@@ -42,7 +42,11 @@
#if HEVC_USE_SIGN_HIDING
#if JVET_N0413_RDPCM
CoeffCodingContext
::
CoeffCodingContext
(
const
TransformUnit
&
tu
,
ComponentID
component
,
bool
signHide
,
bool
bdpcm
)
#else
CoeffCodingContext
::
CoeffCodingContext
(
const
TransformUnit
&
tu
,
ComponentID
component
,
bool
signHide
)
#endif
#else
CoeffCodingContext
::
CoeffCodingContext
(
const
TransformUnit
&
tu
,
ComponentID
component
)
#endif
...
...
@@ -109,6 +113,9 @@ CoeffCodingContext::CoeffCodingContext(const TransformUnit& tu, ComponentID comp
,
m_tsGtxFlagCtxSet
(
Ctx
::
TsGtxFlag
)
#endif
,
m_sigCoeffGroupFlag
()
#if JVET_N0413_RDPCM
,
m_bdpcm
(
bdpcm
)
#endif
{
// LOGTODO
unsigned
log2sizeX
=
m_log2BlockWidth
;
...
...
source/Lib/CommonLib/ContextModelling.h
View file @
3190db94
...
...
@@ -52,7 +52,11 @@ struct CoeffCodingContext
{
public:
#if HEVC_USE_SIGN_HIDING
#if JVET_N0413_RDPCM
CoeffCodingContext
(
const
TransformUnit
&
tu
,
ComponentID
component
,
bool
signHide
,
bool
bdpcm
=
false
);
#else
CoeffCodingContext
(
const
TransformUnit
&
tu
,
ComponentID
component
,
bool
signHide
);
#endif
#else
CoeffCodingContext
(
const
TransformUnit
&
tu
,
ComponentID
component
);
#endif
...
...
@@ -110,7 +114,9 @@ public:
#else
unsigned
sigGroupCtxId
()
const
{
return
m_sigGroupCtxId
;
}
#endif
#if JVET_N0413_RDPCM
bool
bdpcm
()
const
{
return
m_bdpcm
;
}
#endif
unsigned
sigCtxIdAbs
(
int
scanPos
,
const
TCoeff
*
coeff
,
const
int
state
)
{
const
uint32_t
posY
=
m_scan
[
scanPos
].
y
;
...
...
@@ -306,6 +312,9 @@ private:
int
m_remainingContextBins
;
#endif
std
::
bitset
<
MLS_GRP_NUM
>
m_sigCoeffGroupFlag
;
#if JVET_N0413_RDPCM
const
bool
m_bdpcm
;
#endif
};
...
...
source/Lib/CommonLib/Contexts.cpp
View file @
3190db94
...
...
@@ -409,6 +409,16 @@ const CtxSet ContextSetCfg::Mvd = ContextSetCfg::addCtxSet
{
9
,
5
,
},
});
#if JVET_N0413_RDPCM
const
CtxSet
ContextSetCfg
::
BDPCMMode
=
ContextSetCfg
::
addCtxSet
({
{
CNU
,
CNU
,
},
{
CNU
,
CNU
,
},
{
CNU
,
CNU
,
},
{
DWS
,
DWS
,
},
});
#endif
const
CtxSet
ContextSetCfg
::
QtRootCbf
=
ContextSetCfg
::
addCtxSet
({
{
109
,
},
...
...
@@ -419,6 +429,15 @@ const CtxSet ContextSetCfg::QtRootCbf = ContextSetCfg::addCtxSet
const
CtxSet
ContextSetCfg
::
QtCbf
[]
=
{
#if JVET_N0413_RDPCM
ContextSetCfg
::
addCtxSet
({
{
141
,
127
,
139
,
140
,
CNU
},
{
142
,
127
,
139
,
140
,
CNU
},
{
CNU
,
111
,
124
,
111
,
CNU
},
{
1
,
5
,
9
,
8
,
DWS
},
}),
#else
ContextSetCfg
::
addCtxSet
({
{
141
,
127
,
139
,
140
,
},
...
...
@@ -426,6 +445,7 @@ const CtxSet ContextSetCfg::QtCbf[] =
{
CNU
,
111
,
124
,
111
,
},
{
1
,
5
,
9
,
8
,
},
}),
#endif
ContextSetCfg
::
addCtxSet
({
{
163
,
154
,
CNU
,
CNU
,
CNU
,
},
...
...
@@ -870,10 +890,17 @@ const CtxSet ContextSetCfg::TsResidualSign =
{
ContextSetCfg
::
addCtxSet
({
#if JVET_N0413_RDPCM
{
CNU
,
CNU
,
},
{
CNU
,
CNU
,
},
{
CNU
,
CNU
,
},
{
DWS
,
DWS
,
},
#else
{
CNU
,
},
{
CNU
,
},
{
CNU
,
},
{
DWS
,
},
#endif
}),
};
#endif
...
...
source/Lib/CommonLib/Contexts.h
View file @
3190db94
...
...
@@ -223,6 +223,9 @@ public:
static
const
CtxSet
AffineType
;
static
const
CtxSet
AffMergeIdx
;
static
const
CtxSet
Mvd
;
#if JVET_N0413_RDPCM
static
const
CtxSet
BDPCMMode
;
#endif
static
const
CtxSet
QtRootCbf
;
static
const
CtxSet
QtCbf
[
3
];
// [ channel ]
static
const
CtxSet
SigCoeffGroup
[
4
];
// [ ChannelType ]
...
...
source/Lib/CommonLib/IntraPrediction.cpp
View file @
3190db94
...
...
@@ -294,9 +294,11 @@ void IntraPrediction::predIntraAng( const ComponentID compId, PelBuf &piPred, co
const
ChannelType
channelType
=
toChannelType
(
compID
);
const
int
iWidth
=
piPred
.
width
;
const
int
iHeight
=
piPred
.
height
;
#if JVET_N0413_RDPCM
const
uint32_t
uiDirMode
=
isLuma
(
compId
)
&&
pu
.
cu
->
bdpcmMode
?
BDPCM_IDX
:
PU
::
getFinalIntraMode
(
pu
,
channelType
);
#else
const
uint32_t
uiDirMode
=
PU
::
getFinalIntraMode
(
pu
,
channelType
);
#endif
CHECK
(
g_aucLog2
[
iWidth
]
<
2
&&
pu
.
cs
->
pcv
->
noChroma2x2
,
"Size not allowed"
);
CHECK
(
g_aucLog2
[
iWidth
]
>
7
,
"Size not allowed"
);
...
...
@@ -315,6 +317,9 @@ void IntraPrediction::predIntraAng( const ComponentID compId, PelBuf &piPred, co
{
case
(
PLANAR_IDX
):
xPredIntraPlanar
(
srcBuf
,
piPred
);
break
;
case
(
DC_IDX
):
xPredIntraDc
(
srcBuf
,
piPred
,
channelType
,
false
);
break
;
#if JVET_N0413_RDPCM
case
(
BDPCM_IDX
):
xPredIntraBDPCM
(
srcBuf
,
piPred
,
pu
.
cu
->
bdpcmMode
,
clpRng
);
break
;
#endif
default:
xPredIntraAng
(
srcBuf
,
piPred
,
channelType
,
clpRng
);
break
;
}
...
...
@@ -853,6 +858,44 @@ void IntraPrediction::xPredIntraAng( const CPelBuf &pSrc, PelBuf &pDst, const Ch
}
}
#if JVET_N0413_RDPCM
void
IntraPrediction
::
xPredIntraBDPCM
(
const
CPelBuf
&
pSrc
,
PelBuf
&
pDst
,
const
uint32_t
dirMode
,
const
ClpRng
&
clpRng
)
{
const
int
wdt
=
pDst
.
width
;
const
int
hgt
=
pDst
.
height
;
const
int
strideP
=
pDst
.
stride
;
const
int
strideS
=
pSrc
.
stride
;
CHECK
(
!
(
dirMode
==
1
||
dirMode
==
2
),
"Incorrect BDPCM mode parameter."
);
Pel
*
pPred
=
&
pDst
.
buf
[
0
];
if
(
dirMode
==
1
)
{
Pel
val
;
for
(
int
y
=
0
;
y
<
hgt
;
y
++
)
{
val
=
pSrc
.
buf
[(
y
+
1
)
*
strideS
];
for
(
int
x
=
0
;
x
<
wdt
;
x
++
)
{
pPred
[
x
]
=
val
;
}
pPred
+=
strideP
;
}
}
else
{
for
(
int
y
=
0
;
y
<
hgt
;
y
++
)
{
for
(
int
x
=
0
;
x
<
wdt
;
x
++
)
{
pPred
[
x
]
=
pSrc
.
buf
[
x
+
1
];
}
pPred
+=
strideP
;
}
}
}
#endif
bool
IntraPrediction
::
useDPCMForFirstPassIntraEstimation
(
const
PredictionUnit
&
pu
,
const
uint32_t
&
uiDirMode
)
{
...
...
@@ -1349,6 +1392,9 @@ bool IntraPrediction::useFilteredIntraRefSamples( const ComponentID &compID, con
#else
if
(
!
isLuma
(
chType
)
&&
pu
.
chromaFormat
!=
CHROMA_444
)
{
return
false
;
}
#endif
#if JVET_N0413_RDPCM
if
(
isLuma
(
chType
)
&&
pu
.
cu
->
bdpcmMode
)
{
return
false
;
}
#endif
if
(
pu
.
cu
->
ispMode
&&
isLuma
(
compID
)
)
{
return
false
;
}
...
...
source/Lib/CommonLib/IntraPrediction.h
View file @
3190db94
...
...
@@ -121,6 +121,9 @@ protected:
static
bool
isIntegerSlope
(
const
int
absAng
)
{
return
(
0
==
(
absAng
&
0x1F
))
&&
absAng
<=
32
;
}
// integer-slope modes 2, DIA_IDX and VDIA_IDX. "absAng <=32" restricts wide-angle integer modes
#endif
#if JVET_N0413_RDPCM
void
xPredIntraBDPCM
(
const
CPelBuf
&
pSrc
,
PelBuf
&
pDst
,
const
uint32_t
dirMode
,
const
ClpRng
&
clpRng
);
#endif
Pel
xGetPredValDc
(
const
CPelBuf
&
pSrc
,
const
Size
&
dstSize
);
void
xFillReferenceSamples
(
const
CPelBuf
&
recoBuf
,
Pel
*
refBufUnfiltered
,
const
CompArea
&
area
,
const
CodingUnit
&
cu
);
...
...
source/Lib/CommonLib/LoopFilter.cpp
View file @
3190db94
...
...
@@ -749,6 +749,13 @@ unsigned LoopFilter::xGetBoundaryStrengthSingle ( const CodingUnit& cu, const De
const
CodingUnit
&
cuQ
=
cu
;
const
CodingUnit
&
cuP
=
*
cu
.
cs
->
getCU
(
posP
,
cu
.
chType
);
#if JVET_N0413_RDPCM
if
(
(
MODE_INTRA
==
cuP
.
predMode
&&
cuP
.
bdpcmMode
)
&&
(
MODE_INTRA
==
cuQ
.
predMode
&&
cuQ
.
bdpcmMode
)
)
{
return
0
;
}
#endif
//-- Set BS for Intra MB : BS = 4 or 3
if
(
(
MODE_INTRA
==
cuP
.
predMode
)
||
(
MODE_INTRA
==
cuQ
.
predMode
)
)
{
...
...
source/Lib/CommonLib/Quant.cpp
View file @
3190db94
...
...
@@ -141,6 +141,82 @@ Quant::~Quant()
#endif
}
#if JVET_N0413_RDPCM
void
invResDPCM
(
const
TransformUnit
&
tu
,
const
ComponentID
&
compID
,
CoeffBuf
&
dstBuf
)
{
const
CompArea
&
rect
=
tu
.
blocks
[
compID
];
const
int
wdt
=
rect
.
width
;
const
int
hgt
=
rect
.
height
;
const
CCoeffBuf
pcCoeff
=
tu
.
getCoeffs
(
compID
);
const
TCoeff
*
pcCoef
=
&
pcCoeff
.
buf
[
0
];
TCoeff
*
pDst
=
&
dstBuf
.
buf
[
0
];
if
(
tu
.
cu
->
bdpcmMode
==
1
)
{
for
(
int
y
=
0
;
y
<
hgt
;
y
++
)
{
pDst
[
0
]
=
pcCoef
[
0
];
for
(
int
x
=
1
;
x
<
wdt
;
x
++
)
{
pDst
[
x
]
=
pDst
[
x
-
1
]
+
pcCoef
[
x
];
}
pcCoef
+=
pcCoeff
.
stride
;
pDst
+=
dstBuf
.
stride
;
}
}
else
{
for
(
int
x
=
0
;
x
<
wdt
;
x
++
)
{
pDst
[
x
]
=
pcCoef
[
x
];
}
for
(
int
y
=
0
;
y
<
hgt
-
1
;
y
++
)
{
for
(
int
x
=
0
;
x
<
wdt
;
x
++
)
{
pDst
[
dstBuf
.
stride
+
x
]
=
pDst
[
x
]
+
pcCoef
[
pcCoeff
.
stride
+
x
];
}
pcCoef
+=
pcCoeff
.
stride
;
pDst
+=
dstBuf
.
stride
;
}
}
}
void
fwdResDPCM
(
TransformUnit
&
tu
,
const
ComponentID
&
compID
)
{
const
CompArea
&
rect
=
tu
.
blocks
[
compID
];
const
int
wdt
=
rect
.
width
;
const
int
hgt
=
rect
.
height
;
CoeffBuf
piQCoef
=
tu
.
getCoeffs
(
compID
);
TCoeff
*
pCoef
=
&
piQCoef
.
buf
[
0
];
if
(
tu
.
cu
->
bdpcmMode
==
1
)
{
for
(
int
y
=
0
;
y
<
hgt
;
y
++
)
{
for
(
int
x
=
wdt
-
1
;
x
>
0
;
x
--
)
{
pCoef
[
x
]
-=
pCoef
[
x
-
1
];
}
pCoef
+=
piQCoef
.
stride
;
}
}
else
{
pCoef
+=
piQCoef
.
stride
*
(
hgt
-
1
);
for
(
int
y
=
0
;
y
<
hgt
-
1
;
y
++
)
{
for
(
int
x
=
0
;
x
<
wdt
;
x
++
)
{
pCoef
[
x
]
-=
pCoef
[
x
-
piQCoef
.
stride
];
}
pCoef
-=
piQCoef
.
stride
;
}
}
}
#endif
#if HEVC_USE_SIGN_HIDING
// To minimize the distortion only. No rate is considered.
...
...
@@ -288,7 +364,9 @@ void Quant::dequant(const TransformUnit &tu,
const
CompArea
&
area
=
tu
.
blocks
[
compID
];
const
uint32_t
uiWidth
=
area
.
width
;
const
uint32_t
uiHeight
=
area
.
height
;
#if !JVET_N0413_RDPCM
const
TCoeff
*
const
piQCoef
=
tu
.
getCoeffs
(
compID
).
buf
;
#endif
TCoeff
*
const
piCoef
=
dstCoeff
.
buf
;
const
uint32_t
numSamplesInBlock
=
uiWidth
*
uiHeight
;
const
int
maxLog2TrDynamicRange
=
sps
->
getMaxLog2TrDynamicRange
(
toChannelType
(
compID
));
...
...
@@ -301,6 +379,19 @@ void Quant::dequant(const TransformUnit &tu,
#endif
const
int
channelBitDepth
=
sps
->
getBitDepth
(
toChannelType
(
compID
));
#if JVET_N0413_RDPCM
const
TCoeff
*
pInput
;
if
(
tu
.
cu
->
bdpcmMode
&&
isLuma
(
compID
)
)
{
invResDPCM
(
tu
,
compID
,
dstCoeff
);
pInput
=
piCoef
;
}
else
{
pInput
=
tu
.
getCoeffs
(
compID
).
buf
;
}
const
TCoeff
*
const
piQCoef
=
pInput
;
#endif
#if HEVC_USE_SCALING_LISTS
CHECK
(
scalingListType
>=
SCALING_LIST_NUM
,
"Invalid scaling list"
);
#endif
...
...
@@ -853,6 +944,12 @@ void Quant::quant(TransformUnit &tu, const ComponentID &compID, const CCoeffBuf
piQCoef
.
buf
[
uiBlockPos
]
=
Clip3
<
TCoeff
>
(
entropyCodingMinimum
,
entropyCodingMaximum
,
quantisedCoefficient
);
}
// for n
#if JVET_N0413_RDPCM
if
(
tu
.
cu
->
bdpcmMode
&&
isLuma
(
compID
)
)
{
fwdResDPCM
(
tu
,
compID
);
}
#endif
#if HEVC_USE_SIGN_HIDING
if
(
cctx
.
signHiding
()
&&
uiWidth
>=
4
&&
uiHeight
>=
4
)
{
...
...
source/Lib/CommonLib/Quant.h
View file @
3190db94
...
...
@@ -58,6 +58,13 @@
// ====================================================================================================================
// Class definition
// ====================================================================================================================
#if JVET_N0413_RDPCM
struct
TrQuantParams
{
int
rightShift
;
int
qScale
;
};
#endif
/// QP struct
struct
QpParam
...
...
source/Lib/CommonLib/QuantRDOQ.cpp
View file @
3190db94
...
...
@@ -579,7 +579,18 @@ void QuantRDOQ::quant(TransformUnit &tu, const ComponentID &compID, const CCoeff
#if JVET_N0280_RESIDUAL_CODING_TS
if
(
isLuma
(
compID
)
&&
useTransformSkip
)
{
#if JVET_N0413_RDPCM
if
(
tu
.
cu
->
bdpcmMode
&&
isLuma
(
compID
)
)
{
forwardRDPCM
(
tu
,
compID
,
pSrc
,
uiAbsSum
,
cQP
,
ctx
);
}
else
{
xRateDistOptQuantTS
(
tu
,
compID
,
pSrc
,
uiAbsSum
,
cQP
,
ctx
);
}
#else
xRateDistOptQuantTS
(
tu
,
compID
,
pSrc
,
uiAbsSum
,
cQP
,
ctx
);
#endif
}
else
{
...
...
@@ -1487,6 +1498,247 @@ void QuantRDOQ::xRateDistOptQuantTS( TransformUnit &tu, const ComponentID &compI
}
}
#if JVET_N0413_RDPCM
void
QuantRDOQ
::
forwardRDPCM
(
TransformUnit
&
tu
,
const
ComponentID
&
compID
,
const
CCoeffBuf
&
coeffs
,
TCoeff
&
absSum
,
const
QpParam
&
qp
,
const
Ctx
&
ctx
)
{
const
FracBitsAccess
&
fracBits
=
ctx
.
getFracBitsAcess
();
const
SPS
&
sps
=
*
tu
.
cs
->
sps
;
const
CompArea
&
rect
=
tu
.
blocks
[
compID
];
const
uint32_t
width
=
rect
.
width
;
const
uint32_t
height
=
rect
.
height
;
const
ChannelType
chType
=
toChannelType
(
compID
);
const
int
channelBitDepth
=
sps
.
getBitDepth
(
chType
);
const
bool
extendedPrecision
=
sps
.
getSpsRangeExtension
().
getExtendedPrecisionProcessingFlag
();
const
int
maxLog2TrDynamicRange
=
sps
.
getMaxLog2TrDynamicRange
(
chType
);
const
int
dirMode
=
tu
.
cu
->
bdpcmMode
;
int
transformShift
=
getTransformShift
(
channelBitDepth
,
rect
.
size
(),
maxLog2TrDynamicRange
);
if
(
extendedPrecision
)
{
transformShift
=
std
::
max
<
int
>
(
0
,
transformShift
);
}
double
blockUncodedCost
=
0
;
#if HEVC_USE_SCALING_LISTS
const
uint32_t
log2BlockHeight
=
g_aucLog2
[
height
];
#endif
const
uint32_t
maxNumCoeff
=
rect
.
area
();
CHECK
(
compID
>=
MAX_NUM_TBLOCKS
,
"Invalid component ID"
);
#if HEVC_USE_SCALING_LISTS
int
scalingListType
=
getScalingListType
(
tu
.
cu
->
predMode
,
compID
);
CHECK
(
scalingListType
>=
SCALING_LIST_NUM
,
"Invalid scaling list"
);
#endif
const
TCoeff
*
srcCoeff
=
coeffs
.
buf
;
TCoeff
*
dstCoeff
=
tu
.
getCoeffs
(
compID
).
buf
;
double
*
costCoeff
=
m_pdCostCoeff
;
double
*
costSig
=
m_pdCostSig
;
double
*
costCoeff0
=
m_pdCostCoeff0
;
memset
(
m_pdCostCoeff
,
0
,
sizeof
(
double
)
*
maxNumCoeff
);
memset
(
m_pdCostSig
,
0
,
sizeof
(
double
)
*
maxNumCoeff
);
memset
(
m_fullCoeff
,
0
,
sizeof
(
TCoeff
)
*
maxNumCoeff
);
#if JVET_N0246_MODIFIED_QUANTSCALES
const
bool
needsSqrt2Scale
=
TU
::
needsSqrt2Scale
(
tu
,
compID
);
// should always be false - transform-skipped blocks don't require sqrt(2) compensation.
const
int
qBits
=
QUANT_SHIFT
+
qp
.
per
+
transformShift
+
(
needsSqrt2Scale
?
-
1
:
0
);
// Right shift of non-RDOQ quantizer; level = (coeff*uiQ + offset)>>q_bits
const
int
quantisationCoefficient
=
g_quantScales
[
needsSqrt2Scale
?
1
:
0
][
qp
.
rem
];
const
double
errorScale
=
xGetErrScaleCoeff
(
TU
::
needsSqrt2Scale
(
tu
,
compID
),
width
,
height
,
qp
.
rem
,
maxLog2TrDynamicRange
,
channelBitDepth
);
TrQuantParams
trQuantParams
;
trQuantParams
.
rightShift
=
(
IQUANT_SHIFT
-
(
transformShift
+
qp
.
per
));
trQuantParams
.
qScale
=
g_invQuantScales
[
needsSqrt2Scale
?
1
:
0
][
qp
.
rem
];
#else
const
int
qBits
=
QUANT_SHIFT
+
qp
.
per
+
transformShift
;
// Right shift of non-RDOQ quantizer; level = (coeff*uiQ + offset)>>q_bits
#if HM_QTBT_AS_IN_JEM_QUANT
const
int
quantisationCoefficient
=
(
TU
::
needsSqrt2Scale
(
tu
,
compID
)
?
(
g_quantScales
[
qp
.
rem
]
*
181
)
>>
7
:
g_quantScales
[
qp
.
rem
]);
const
double
errorScale
=
xGetErrScaleCoeff
(
TU
::
needsSqrt2Scale
(
tu
,
compID
),
width
,
height
,
qp
.
rem
,
maxLog2TrDynamicRange
,
channelBitDepth
);
#else
const
double
blkErrScale
=
(
TU
::
needsQP3Offset
(
tu
,
compID
)
?
2.0
:
1.0
);
const
int
quantisationCoefficient
=
g_quantScales
[
qp
.
rem
];
const
double
errorScale
=
blkErrScale
*
xGetErrScaleCoeff
(
width
,
height
,
qp
.
rem
,
maxLog2TrDynamicRange
,
channelBitDepth
);
#endif
#endif
const
TCoeff
entropyCodingMaximum
=
(
1
<<
maxLog2TrDynamicRange
)
-
1
;
#if HEVC_USE_SIGN_HIDING
CoeffCodingContext
cctx
(
tu
,
compID
,
tu
.
cs
->
slice
->
getSignDataHidingEnabledFlag
());
#else
CoeffCodingContext
cctx
(
tu
,
compID
);
#endif
const
int
sbSizeM1
=
(
1
<<
cctx
.
log2CGSize
())
-
1
;
double
baseCost
=
0
;
uint32_t
goRiceParam
=
0
;
double
*
costSigSubBlock
=
m_pdCostCoeffGroupSig
;
memset
(
costSigSubBlock
,
0
,
(
maxNumCoeff
>>
cctx
.
log2CGSize
())
*
sizeof
(
double
));
const
int
sbNum
=
width
*
height
>>
cctx
.
log2CGSize
();
int
scanPos
;
coeffGroupRDStats
rdStats
;
bool
anySigCG
=
false
;
for
(
int
sbId
=
0
;
sbId
<
sbNum
;
sbId
++
)
{
cctx
.
initSubblock
(
sbId
);
memset
(
&
rdStats
,
0
,
sizeof
(
coeffGroupRDStats
));
for
(
int
scanPosInSB
=
0
;
scanPosInSB
<=
sbSizeM1
;
scanPosInSB
++
)
{
scanPos
=
cctx
.
minSubPos
()
+
scanPosInSB
;
//===== quantization =====
uint32_t
blkPos
=
cctx
.
blockPos
(
scanPos
);
const
int
posX
=
cctx
.
posX
(
scanPos
);
const
int
posY
=
cctx
.
posY
(
scanPos
);
const
int
posS
=
(
1
==
dirMode
)
?
posX
:
posY
;
const
int
posNb
=
(
1
==
dirMode
)
?
(
posX
-
1
)
+
posY
*
coeffs
.
stride
:
posX
+
(
posY
-
1
)
*
coeffs
.
stride
;
TCoeff
predCoeff
=
(
0
!=
posS
)
?
m_fullCoeff
[
posNb
]
:
0
;
// set coeff
const
int64_t
tmpLevel
=
int64_t
(
abs
(
srcCoeff
[
blkPos
]
-
predCoeff
))
*
quantisationCoefficient
;
const
Intermediate_Int
levelDouble
=
(
Intermediate_Int
)
std
::
min
<
int64_t
>
(
tmpLevel
,
std
::
numeric_limits
<
Intermediate_Int
>::
max
()
-
(
Intermediate_Int
(
1
)
<<
(
qBits
-
1
)));
uint32_t
maxAbsLevel
=
std
::
min
<
uint32_t
>
(
uint32_t
(
entropyCodingMaximum
),
uint32_t
((
levelDouble
+
(
Intermediate_Int
(
1
)
<<
(
qBits
-
1
)))
>>
qBits
));
const
double
err
=
double
(
levelDouble
);
costCoeff0
[
scanPos
]
=
err
*
err
*
errorScale
;
blockUncodedCost
+=
costCoeff0
[
scanPos
];
dstCoeff
[
blkPos
]
=
maxAbsLevel
;
//===== coefficient level estimation =====
unsigned
ctxIdSig
=
cctx
.
sigCtxIdAbsTS
(
scanPos
,
dstCoeff
);
uint32_t
cLevel
;
const
BinFracBits
fracBitsPar
=
fracBits
.
getFracBitsArray
(
cctx
.
parityCtxIdAbsTS
());
goRiceParam
=
cctx
.
templateAbsSumTS
(
scanPos
,
dstCoeff
);
const
BinFracBits
fracBitsSign
=
fracBits
.
getFracBitsArray
(
Ctx
::
TsResidualSign
(
toChannelType
(
compID
)));
const
uint8_t
sign
=
srcCoeff
[
blkPos
]
-
predCoeff
<
0
?
1
:
0
;
DTRACE_COND
((
maxAbsLevel
!=
0
),
g_trace_ctx
,
D_RDOQ_MORE
,
" uiCtxSig=%d"
,
ctxIdSig
);
const
BinFracBits
fracBitsSig
=
fracBits
.
getFracBitsArray
(
ctxIdSig
);
cLevel
=
xGetCodedLevelTS
(
costCoeff
[
scanPos
],
costCoeff0
[
scanPos
],
costSig
[
scanPos
],