[x265] [PATCH 6 of 8] encoder: modify encoder to support 400 color space
mahesh at multicorewareinc.com
mahesh at multicorewareinc.com
Mon Dec 14 20:30:12 CET 2015
# HG changeset patch
# User Mahesh Pittala <mahesh at multicorewareinc.com>
# Date 1450019760 -19800
# Sun Dec 13 20:46:00 2015 +0530
# Node ID baaed1362ececcd0d9f38720d1462f815c47165e
# Parent ef775a0a83f65e1dd1bb51c9e3d56206e4c2aaf1
encoder: modify encoder to support 400 color space
diff -r ef775a0a83f6 -r baaed1362ece source/common/predict.cpp
--- a/source/common/predict.cpp Sun Dec 13 20:38:37 2015 +0530
+++ b/source/common/predict.cpp Sun Dec 13 20:46:00 2015 +0530
@@ -99,7 +99,7 @@
if (cu.m_slice->m_pps->bUseWeightPred && wp0->bPresentFlag)
{
- for (int plane = 0; plane < 3; plane++)
+ for (int plane = 0; plane < (bChroma ? 3 : 1); plane++)
{
wv0[plane].w = wp0[plane].inputWeight;
wv0[plane].offset = wp0[plane].inputOffset * (1 << (X265_DEPTH - 8));
@@ -142,7 +142,7 @@
if (pwp0 && pwp1 && (pwp0->bPresentFlag || pwp1->bPresentFlag))
{
/* biprediction weighting */
- for (int plane = 0; plane < 3; plane++)
+ for (int plane = 0; plane < (bChroma ? 3 : 1); plane++)
{
wv0[plane].w = pwp0[plane].inputWeight;
wv0[plane].o = pwp0[plane].inputOffset * (1 << (X265_DEPTH - 8));
@@ -159,7 +159,7 @@
{
/* uniprediction weighting, always outputs to wv0 */
const WeightParam* pwp = (refIdx0 >= 0) ? pwp0 : pwp1;
- for (int plane = 0; plane < 3; plane++)
+ for (int plane = 0; plane < (bChroma ? 3 : 1); plane++)
{
wv0[plane].w = pwp[plane].inputWeight;
wv0[plane].offset = pwp[plane].inputOffset * (1 << (X265_DEPTH - 8));
diff -r ef775a0a83f6 -r baaed1362ece source/common/quant.cpp
--- a/source/common/quant.cpp Sun Dec 13 20:38:37 2015 +0530
+++ b/source/common/quant.cpp Sun Dec 13 20:46:00 2015 +0530
@@ -223,8 +223,11 @@
{
m_nr = m_frameNr ? &m_frameNr[ctu.m_encData->m_frameEncoderID] : NULL;
m_qpParam[TEXT_LUMA].setQpParam(qp + QP_BD_OFFSET);
- setChromaQP(qp + ctu.m_slice->m_pps->chromaQpOffset[0], TEXT_CHROMA_U, ctu.m_chromaFormat);
- setChromaQP(qp + ctu.m_slice->m_pps->chromaQpOffset[1], TEXT_CHROMA_V, ctu.m_chromaFormat);
+ if (ctu.m_chromaFormat != X265_CSP_I400)
+ {
+ setChromaQP(qp + ctu.m_slice->m_pps->chromaQpOffset[0], TEXT_CHROMA_U, ctu.m_chromaFormat);
+ setChromaQP(qp + ctu.m_slice->m_pps->chromaQpOffset[1], TEXT_CHROMA_V, ctu.m_chromaFormat);
+ }
}
void Quant::setChromaQP(int qpin, TextType ttype, int chFmt)
diff -r ef775a0a83f6 -r baaed1362ece source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Sun Dec 13 20:38:37 2015 +0530
+++ b/source/encoder/encoder.cpp Sun Dec 13 20:46:00 2015 +0530
@@ -533,10 +533,13 @@
* allocated by this top level encoder */
if (m_sps.cuOffsetY)
{
- inFrame->m_fencPic->m_cuOffsetC = m_sps.cuOffsetC;
inFrame->m_fencPic->m_cuOffsetY = m_sps.cuOffsetY;
- inFrame->m_fencPic->m_buOffsetC = m_sps.buOffsetC;
inFrame->m_fencPic->m_buOffsetY = m_sps.buOffsetY;
+ if (pic_in->colorSpace != X265_CSP_I400)
+ {
+ inFrame->m_fencPic->m_cuOffsetC = m_sps.cuOffsetC;
+ inFrame->m_fencPic->m_buOffsetC = m_sps.buOffsetC;
+ }
}
else
{
@@ -550,10 +553,15 @@
}
else
{
- m_sps.cuOffsetC = inFrame->m_fencPic->m_cuOffsetC;
m_sps.cuOffsetY = inFrame->m_fencPic->m_cuOffsetY;
- m_sps.buOffsetC = inFrame->m_fencPic->m_buOffsetC;
m_sps.buOffsetY = inFrame->m_fencPic->m_buOffsetY;
+ if (pic_in->colorSpace != X265_CSP_I400)
+ {
+ m_sps.cuOffsetC = inFrame->m_fencPic->m_cuOffsetC;
+ m_sps.cuOffsetY = inFrame->m_fencPic->m_cuOffsetY;
+ m_sps.buOffsetC = inFrame->m_fencPic->m_buOffsetC;
+ m_sps.buOffsetY = inFrame->m_fencPic->m_buOffsetY;
+ }
}
}
}
@@ -692,10 +700,13 @@
pic_out->planes[0] = recpic->m_picOrg[0];
pic_out->stride[0] = (int)(recpic->m_stride * sizeof(pixel));
- pic_out->planes[1] = recpic->m_picOrg[1];
- pic_out->stride[1] = (int)(recpic->m_strideC * sizeof(pixel));
- pic_out->planes[2] = recpic->m_picOrg[2];
- pic_out->stride[2] = (int)(recpic->m_strideC * sizeof(pixel));
+ if (m_param->internalCsp != X265_CSP_I400)
+ {
+ pic_out->planes[1] = recpic->m_picOrg[1];
+ pic_out->stride[1] = (int)(recpic->m_strideC * sizeof(pixel));
+ pic_out->planes[2] = recpic->m_picOrg[2];
+ pic_out->stride[2] = (int)(recpic->m_strideC * sizeof(pixel));
+ }
/* Dump analysis data from pic_out to file in save mode and free */
if (m_param->analysisMode == X265_ANALYSIS_SAVE)
@@ -712,32 +723,53 @@
freeAnalysis(&pic_out->analysisData);
}
}
- if (slice->m_sliceType == P_SLICE)
+ if (m_param->internalCsp == X265_CSP_I400)
{
- if (slice->m_weightPredTable[0][0][0].bPresentFlag)
- m_numLumaWPFrames++;
- if (slice->m_weightPredTable[0][0][1].bPresentFlag ||
- slice->m_weightPredTable[0][0][2].bPresentFlag)
- m_numChromaWPFrames++;
+ if (slice->m_sliceType == P_SLICE)
+ {
+ if (slice->m_weightPredTable[0][0][0].bPresentFlag)
+ m_numLumaWPFrames++;
+ }
+ else if (slice->m_sliceType == B_SLICE)
+ {
+ bool bLuma = false;
+ for (int l = 0; l < 2; l++)
+ {
+ if (slice->m_weightPredTable[l][0][0].bPresentFlag)
+ bLuma = true;
+ }
+ if (bLuma)
+ m_numLumaWPBiFrames++;
+ }
}
- else if (slice->m_sliceType == B_SLICE)
+ else
{
- bool bLuma = false, bChroma = false;
- for (int l = 0; l < 2; l++)
+ if (slice->m_sliceType == P_SLICE)
{
- if (slice->m_weightPredTable[l][0][0].bPresentFlag)
- bLuma = true;
- if (slice->m_weightPredTable[l][0][1].bPresentFlag ||
- slice->m_weightPredTable[l][0][2].bPresentFlag)
- bChroma = true;
+ if (slice->m_weightPredTable[0][0][0].bPresentFlag)
+ m_numLumaWPFrames++;
+ if (slice->m_weightPredTable[0][0][1].bPresentFlag ||
+ slice->m_weightPredTable[0][0][2].bPresentFlag)
+ m_numChromaWPFrames++;
}
+ else if (slice->m_sliceType == B_SLICE)
+ {
+ bool bLuma = false, bChroma = false;
+ for (int l = 0; l < 2; l++)
+ {
+ if (slice->m_weightPredTable[l][0][0].bPresentFlag)
+ bLuma = true;
+ if (slice->m_weightPredTable[l][0][1].bPresentFlag ||
+ slice->m_weightPredTable[l][0][2].bPresentFlag)
+ bChroma = true;
+ }
- if (bLuma)
- m_numLumaWPBiFrames++;
- if (bChroma)
- m_numChromaWPBiFrames++;
+ if (bLuma)
+ m_numLumaWPBiFrames++;
+ if (bChroma)
+ m_numChromaWPBiFrames++;
+ }
}
-
if (m_aborted)
return -1;
diff -r ef775a0a83f6 -r baaed1362ece source/encoder/motion.cpp
--- a/source/encoder/motion.cpp Sun Dec 13 20:38:37 2015 +0530
+++ b/source/encoder/motion.cpp Sun Dec 13 20:46:00 2015 +0530
@@ -189,11 +189,12 @@
satd = primitives.pu[partEnum].satd;
sad_x3 = primitives.pu[partEnum].sad_x3;
sad_x4 = primitives.pu[partEnum].sad_x4;
+
chromaSatd = primitives.chroma[fencPUYuv.m_csp].pu[partEnum].satd;
/* Enable chroma residual cost if subpelRefine level is greater than 2 and chroma block size
* is an even multiple of 4x4 pixels (indicated by non-null chromaSatd pointer) */
- bChromaSATD = subpelRefine > 2 && chromaSatd;
+ bChromaSATD = subpelRefine > 2 && chromaSatd && (srcFencYuv.m_csp != X265_CSP_I400);
X265_CHECK(!(bChromaSATD && !workload[subpelRefine].hpel_satd), "Chroma SATD cannot be used with SAD hpel\n");
ctuAddr = _ctuAddr;
diff -r ef775a0a83f6 -r baaed1362ece source/encoder/reference.cpp
--- a/source/encoder/reference.cpp Sun Dec 13 20:38:37 2015 +0530
+++ b/source/encoder/reference.cpp Sun Dec 13 20:46:00 2015 +0530
@@ -68,7 +68,7 @@
intptr_t stride = reconPic->m_stride;
int cuHeight = g_maxCUSize;
- for (int c = 0; c < numInterpPlanes; c++)
+ for (int c = 0; c < (p.internalCsp != X265_CSP_I400 ? numInterpPlanes : 1); c++)
{
if (c == 1)
{
diff -r ef775a0a83f6 -r baaed1362ece source/encoder/sei.h
--- a/source/encoder/sei.h Sun Dec 13 20:38:37 2015 +0530
+++ b/source/encoder/sei.h Sun Dec 13 20:46:00 2015 +0530
@@ -189,29 +189,31 @@
uint8_t m_digest[3][16];
- void write(Bitstream& bs, const SPS&)
+ void write(Bitstream& bs, const SPS& sps)
{
m_bitIf = &bs;
+ int planes = (sps.chromaFormatIdc != X265_CSP_I400) ? 3 : 1;
+
WRITE_CODE(DECODED_PICTURE_HASH, 8, "payload_type");
switch (m_method)
{
case MD5:
- WRITE_CODE(1 + 16 * 3, 8, "payload_size");
+ WRITE_CODE(1 + 16 * planes, 8, "payload_size");
WRITE_CODE(MD5, 8, "hash_type");
break;
case CRC:
- WRITE_CODE(1 + 2 * 3, 8, "payload_size");
+ WRITE_CODE(1 + 2 * planes, 8, "payload_size");
WRITE_CODE(CRC, 8, "hash_type");
break;
case CHECKSUM:
- WRITE_CODE(1 + 4 * 3, 8, "payload_size");
+ WRITE_CODE(1 + 4 * planes, 8, "payload_size");
WRITE_CODE(CHECKSUM, 8, "hash_type");
break;
}
- for (int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
+ for (int yuvIdx = 0; yuvIdx < planes; yuvIdx++)
{
if (m_method == MD5)
{
diff -r ef775a0a83f6 -r baaed1362ece source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp Sun Dec 13 20:38:37 2015 +0530
+++ b/source/encoder/slicetype.cpp Sun Dec 13 20:46:00 2015 +0530
@@ -83,8 +83,11 @@
uint32_t var;
var = acEnergyPlane(curFrame, curFrame->m_fencPic->m_picOrg[0] + blockOffsetLuma, stride, 0, csp);
- var += acEnergyPlane(curFrame, curFrame->m_fencPic->m_picOrg[1] + blockOffsetChroma, cStride, 1, csp);
- var += acEnergyPlane(curFrame, curFrame->m_fencPic->m_picOrg[2] + blockOffsetChroma, cStride, 2, csp);
+ if (csp != X265_CSP_I400)
+ {
+ var += acEnergyPlane(curFrame, curFrame->m_fencPic->m_picOrg[1] + blockOffsetChroma, cStride, 1, csp);
+ var += acEnergyPlane(curFrame, curFrame->m_fencPic->m_picOrg[2] + blockOffsetChroma, cStride, 2, csp);
+ }
x265_emms();
return var;
}
diff -r ef775a0a83f6 -r baaed1362ece source/encoder/weightPrediction.cpp
--- a/source/encoder/weightPrediction.cpp Sun Dec 13 20:38:37 2015 +0530
+++ b/source/encoder/weightPrediction.cpp Sun Dec 13 20:46:00 2015 +0530
@@ -266,7 +266,7 @@
/* prepare estimates */
float guessScale[3], fencMean[3], refMean[3];
- for (int plane = 0; plane < 3; plane++)
+ for (int plane = 0; plane < (param.internalCsp != X265_CSP_I400 ? 3 : 1); plane++)
{
SET_WEIGHT(weights[plane], false, 1, 0, 0);
uint64_t fencVar = fenc.wp_ssd[plane] + !refLowres.wp_ssd[plane];
@@ -290,7 +290,7 @@
MV *mvs = NULL;
- for (int plane = 0; plane < 3; plane++)
+ for (int plane = 0; plane < (param.internalCsp != X265_CSP_I400 ? 3 : 1); plane++)
{
denom = plane ? chromaDenom : lumaDenom;
if (plane && !weights[0].bPresentFlag)
@@ -329,7 +329,7 @@
{
/* reference chroma planes must be extended prior to being
* used as motion compensation sources */
- if (!refFrame->m_bChromaExtended)
+ if (!refFrame->m_bChromaExtended && param.internalCsp != X265_CSP_I400)
{
refFrame->m_bChromaExtended = true;
PicYuv *refPic = refFrame->m_fencPic;
More information about the x265-devel
mailing list