[x265] [PATCH] Modify TComYuv structure and other modificatons to support multiple color space formats
Steve Borho
steve at borho.org
Wed Jan 8 01:03:31 CET 2014
On Fri, Jan 3, 2014 at 7:12 AM, <ashok at multicorewareinc.com> wrote:
> # HG changeset patch
> # User ashok at multicorewareinc.com
> # Date 1388754730 -19800
> # Fri Jan 03 18:42:10 2014 +0530
> # Node ID a4d3275bca23ef2919b2ece1276b3cda25738077
> # Parent c33edcd92866c6cfc3f5593282ef6969e0d9a0af
> Modify TComYuv structure and other modificatons to support multiple color
> space formats
>
> diff -r c33edcd92866 -r a4d3275bca23 source/Lib/TLibCommon/TComRom.cpp
> --- a/source/Lib/TLibCommon/TComRom.cpp Fri Jan 03 18:40:41 2014 +0530
> +++ b/source/Lib/TLibCommon/TComRom.cpp Fri Jan 03 18:42:10 2014 +0530
> @@ -44,49 +44,179 @@
> //! \ingroup TLibCommon
> //! \{
>
> +// scanning order table
> +uint32_t* g_scanOrder[SCAN_NUMBER_OF_GROUP_TYPES][SCAN_NUMBER_OF_TYPES][
> MAX_CU_DEPTH ][ MAX_CU_DEPTH ];
> +
> +class ScanGenerator
> +{
> +private:
> + uint32_t m_line, m_column;
> + const uint32_t m_blockWidth, m_blockHeight;
> + const uint32_t m_stride;
> + const COEFF_SCAN_TYPE m_scanType;
> +
> +public:
> + ScanGenerator(uint32_t blockWidth, uint32_t blockHeight, uint32_t
> stride, COEFF_SCAN_TYPE scanType)
> + : m_line(0), m_column(0), m_blockWidth(blockWidth),
> m_blockHeight(blockHeight), m_stride(stride), m_scanType(scanType)
> + { }
> +
> + uint32_t GetCurrentX() const { return m_column; }
> + uint32_t GetCurrentY() const { return m_line; }
> +
> + uint32_t GetNextIndex(uint32_t blockOffsetX, uint32_t blockOffsetY)
>
methods must start with a lower case letter
> + {
> + int rtn=((m_line + blockOffsetY) * m_stride) + m_column +
> blockOffsetX;
> +
> + //advance line and column to the next position
> + switch (m_scanType)
> + {
> + case SCAN_DIAG:
> + {
>
these curly braces are unnecessary, you are not declaring any variables
> + if ((m_column == (m_blockWidth - 1)) || (m_line == 0))
> //if we reach the end of a rank, go diagonally down to the next one
> + {
> + m_line += m_column + 1;
> + m_column = 0;
> +
> + if (m_line >= m_blockHeight) //if that takes us
> outside the block, adjust so that we are back on the bottom row
> + {
> + m_column += m_line - (m_blockHeight - 1);
> + m_line = m_blockHeight - 1;
> + }
> + }
> + else
> + {
> + m_column++;
> + m_line--;
> + }
> + }
> + break;
> +
> + case SCAN_HOR:
> + {
> + if (m_column == (m_blockWidth - 1))
> + {
> + m_line++;
> + m_column = 0;
> + }
> + else m_column++;
> + }
> + break;
> +
> + case SCAN_VER:
> + {
> + if (m_line == (m_blockHeight - 1))
> + {
> + m_column++;
> + m_line = 0;
> + }
> + else m_line++;
> + }
> + break;
> +
> + default:
> + {
> + std::cerr << "ERROR: Unknown scan type \"" << m_scanType
> << "\"in ScanGenerator::GetNextIndex" << std::endl;
>
x265_log(NULL, X265_LOG_ERROR, "...")
> + exit(1);
> + }
> + break;
> + }
> + return rtn;
> + }
> +};
> +
> // initialize ROM variables
> void initROM()
> {
> - if (g_sigLastScan[0][0] == 0)
> + int i, c;
> +
> + // g_aucConvertToBit[ x ]: log2(x/4), if x=4 -> 0, x=8 -> 1, x=16 ->
> 2, ...
> + ::memset(g_convertToBit, -1, sizeof( g_convertToBit));
> + c=0;
> + for ( i=4; i<=MAX_CU_SIZE; i*=2 )
>
white-space
> {
> - int i, c;
> + g_convertToBit[i] = c;
> + c++;
> + }
>
> - // g_convertToBit[ x ]: log2(x/4), if x=4 -> 0, x=8 -> 1, x=16 ->
> 2, ...
> - ::memset(g_convertToBit, -1, sizeof(g_convertToBit));
> - c = 0;
> - for (i = 4; i < MAX_CU_SIZE; i *= 2)
> + // initialise scan orders
> + for (uint32_t log2BlockHeight = 0; log2BlockHeight < MAX_CU_DEPTH;
> log2BlockHeight++)
> + {
> + for (uint32_t log2BlockWidth = 0; log2BlockWidth < MAX_CU_DEPTH;
> log2BlockWidth++)
> {
> - g_convertToBit[i] = c;
> - c++;
> - }
> + const uint32_t blockWidth = 1 << log2BlockWidth;
> + const uint32_t blockHeight = 1 << log2BlockHeight;
> + const uint32_t totalValues = blockWidth * blockHeight;
>
> - g_convertToBit[i] = c;
> + //non-grouped scan orders
> + for (uint32_t scanTypeIndex = 0; scanTypeIndex <
> SCAN_NUMBER_OF_TYPES; scanTypeIndex++)
> + {
> + const COEFF_SCAN_TYPE scanType =
> COEFF_SCAN_TYPE(scanTypeIndex);
>
> - c = 2;
> - for (i = 0; i < MAX_CU_DEPTH; i++)
> - {
> - g_sigLastScan[0][i] = new uint32_t[c * c];
> - g_sigLastScan[1][i] = new uint32_t[c * c];
> - g_sigLastScan[2][i] = new uint32_t[c * c];
> - initSigLastScan(g_sigLastScan[0][i], g_sigLastScan[1][i],
> g_sigLastScan[2][i], c, c);
> +
> g_scanOrder[SCAN_UNGROUPED][scanType][log2BlockWidth][log2BlockHeight] =
> new uint32_t[totalValues];
>
> - c <<= 1;
> + ScanGenerator fullBlockScan(blockWidth, blockHeight,
> blockWidth, scanType);
> +
> + for (uint32_t scanPosition = 0; scanPosition <
> totalValues; scanPosition++)
> + {
> +
> g_scanOrder[SCAN_UNGROUPED][scanType][log2BlockWidth][log2BlockHeight][scanPosition]
> = fullBlockScan.GetNextIndex(0, 0);
> + }
> + }
> +
> + //grouped scan orders
> + const uint32_t groupWidth = 1 <<
> MLS_CG_LOG2_WIDTH;
> + const uint32_t groupHeight = 1 <<
> MLS_CG_LOG2_HEIGHT;
> + const uint32_t widthInGroups = blockWidth >>
> MLS_CG_LOG2_WIDTH;
> + const uint32_t heightInGroups = blockHeight >>
> MLS_CG_LOG2_HEIGHT;
> +
> + const uint32_t groupSize = groupWidth *
> groupHeight;
> + const uint32_t totalGroups = widthInGroups *
> heightInGroups;
> +
> + for (uint32_t scanTypeIndex = 0; scanTypeIndex <
> SCAN_NUMBER_OF_TYPES; scanTypeIndex++)
> + {
> + const COEFF_SCAN_TYPE scanType =
> COEFF_SCAN_TYPE(scanTypeIndex);
> +
> +
> g_scanOrder[SCAN_GROUPED_4x4][scanType][log2BlockWidth][log2BlockHeight] =
> new uint32_t[totalValues];
> +
> + ScanGenerator fullBlockScan(widthInGroups,
> heightInGroups, groupWidth, scanType);
> +
> + for (uint32_t groupIndex = 0; groupIndex < totalGroups;
> groupIndex++)
> + {
> + const uint32_t groupPositionY =
> fullBlockScan.GetCurrentY();
> + const uint32_t groupPositionX =
> fullBlockScan.GetCurrentX();
> + const uint32_t groupOffsetX = groupPositionX *
> groupWidth;
> + const uint32_t groupOffsetY = groupPositionY *
> groupHeight;
> + const uint32_t groupOffsetScan = groupIndex *
> groupSize;
> +
> + ScanGenerator groupScan(groupWidth, groupHeight,
> blockWidth, scanType);
> +
> + for (uint32_t scanPosition = 0; scanPosition <
> groupSize; scanPosition++)
> + {
> +
> g_scanOrder[SCAN_GROUPED_4x4][scanType][log2BlockWidth][log2BlockHeight][groupOffsetScan
> + scanPosition] = groupScan.GetNextIndex(groupOffsetX, groupOffsetY);
> + }
> +
> + fullBlockScan.GetNextIndex(0,0);
> + }
> + }
> +
> +
> //--------------------------------------------------------------------------------------------------
> }
> }
> }
>
> void destroyROM()
> {
> - if (g_sigLastScan[0][0])
> + for (uint32_t groupTypeIndex = 0; groupTypeIndex <
> SCAN_NUMBER_OF_GROUP_TYPES; groupTypeIndex++)
> {
> - for (int i = 0; i < MAX_CU_DEPTH; i++)
> + for (uint32_t scanOrderIndex = 0; scanOrderIndex <
> SCAN_NUMBER_OF_TYPES; scanOrderIndex++)
> {
> - delete[] g_sigLastScan[0][i];
> - delete[] g_sigLastScan[1][i];
> - delete[] g_sigLastScan[2][i];
> + for (uint32_t log2BlockWidth = 0; log2BlockWidth <
> MAX_CU_DEPTH; log2BlockWidth++)
> + {
> + for (uint32_t log2BlockHeight = 0; log2BlockHeight <
> MAX_CU_DEPTH; log2BlockHeight++)
> + {
> + delete []
> g_scanOrder[groupTypeIndex][scanOrderIndex][log2BlockWidth][log2BlockHeight];
> + }
> + }
> }
> -
> - g_sigLastScan[0][0] = NULL;
> }
> }
>
> @@ -94,15 +224,15 @@
> // Data structure related table & variable
> //
> ====================================================================================================================
>
> -int g_bitDepth = 8;
> +int g_bitDepth = 8;
> uint32_t g_maxCUWidth = MAX_CU_SIZE;
> uint32_t g_maxCUHeight = MAX_CU_SIZE;
> uint32_t g_maxCUDepth = MAX_CU_DEPTH;
> uint32_t g_addCUDepth = 0;
> uint32_t g_zscanToRaster[MAX_NUM_SPU_W * MAX_NUM_SPU_W] = { 0, };
> uint32_t g_rasterToZscan[MAX_NUM_SPU_W * MAX_NUM_SPU_W] = { 0, };
> -uint32_t g_rasterToPelX[MAX_NUM_SPU_W * MAX_NUM_SPU_W] = { 0, };
> -uint32_t g_rasterToPelY[MAX_NUM_SPU_W * MAX_NUM_SPU_W] = { 0, };
> +uint32_t g_rasterToPelX[MAX_NUM_SPU_W * MAX_NUM_SPU_W] = { 0, };
> +uint32_t g_rasterToPelY[MAX_NUM_SPU_W * MAX_NUM_SPU_W] = { 0, };
>
> uint32_t g_puOffset[8] = { 0, 8, 4, 4, 2, 10, 1, 5 };
>
> @@ -278,13 +408,12 @@
> { 4, -13, 22, -31, 38, -46, 54, -61, 67, -73, 78, -82, 85, -88, 90,
> -90, 90, -90, 88, -85, 82, -78, 73, -67, 61, -54, 46, -38, 31, -22, 13, -4 }
> };
>
> -const UChar g_chromaScale [70] =
> +const UChar g_chromaScale[NUM_CHROMA_FORMAT][chromaQPMappingTableSize]=
> {
> - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
> - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 29, 30, 31, 32,
> - 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44,
> - 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
> - 62, 63
> + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
> + { 0, 1, 2, 3, 4, 5, 6, 7, 8,
> 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,29,30,31,32,33,33,34,34,35,35,36,36,37,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51
> },
> + { 0, 1, 2, 3, 4, 5, 6, 7, 8,
> 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,32,33,34,35,36,37,37,38,39,40,40,41,42,42,43,44,44,45,45,46,47,48,49,50,51
> },
> + { 0, 1, 2, 3, 4, 5, 6, 7, 8,
> 9,10,11,12,13,14,15,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,48,49,50,51,51,51,51,51,51,51
> }
> };
>
> //
> ====================================================================================================================
> @@ -507,7 +636,7 @@
> };
> uint32_t g_scalingListSize[4] = { 16, 64, 256, 1024 };
> uint32_t g_scalingListSizeX[4] = { 4, 8, 16, 32 };
> -uint32_t g_scalingListNum[SCALING_LIST_SIZE_NUM] = { 6, 6, 6, 2 };
> +uint32_t g_scalingListNum[SCALING_LIST_SIZE_NUM] = { 6, 6, 6, 6 };
> int g_eTTable[4] = { 0, 3, 1, 2 };
>
> const int g_winUnitX[] = { 1, 2, 2, 1 };
> diff -r c33edcd92866 -r a4d3275bca23 source/Lib/TLibCommon/TComRom.h
> --- a/source/Lib/TLibCommon/TComRom.h Fri Jan 03 18:40:41 2014 +0530
> +++ b/source/Lib/TLibCommon/TComRom.h Fri Jan 03 18:42:10 2014 +0530
> @@ -57,6 +57,7 @@
> #define MAX_CU_DEPTH 6 //
> log2(LCUSize)
> #define MAX_CU_SIZE (1 << (MAX_CU_DEPTH)) // maximum
> allowable size of CU
> #define MIN_PU_SIZE 4
> +#define MIN_TU_SIZE 4
> #define MAX_NUM_SPU_W (MAX_CU_SIZE / MIN_PU_SIZE) // maximum
> number of SPU in horizontal line
> #define ADI_BUF_STRIDE (2 * MAX_CU_SIZE + 1 + 15) // alignment
> to 16 bytes
>
> @@ -69,12 +70,16 @@
> void initSigLastScan(uint32_t* buffD, uint32_t* buffH, uint32_t* buffV,
> int width, int height);
>
> //
> ====================================================================================================================
> +static const int chromaQPMappingTableSize = 58;
> +
> +extern const UChar
> g_chromaScale[NUM_CHROMA_FORMAT][chromaQPMappingTableSize];
> // Data structure related table & variable
> //
> ====================================================================================================================
>
> // flexible conversion from relative to absolute index
> extern uint32_t g_zscanToRaster[MAX_NUM_SPU_W * MAX_NUM_SPU_W];
> extern uint32_t g_rasterToZscan[MAX_NUM_SPU_W * MAX_NUM_SPU_W];
> +extern uint32_t*
> g_scanOrder[SCAN_NUMBER_OF_GROUP_TYPES][SCAN_NUMBER_OF_TYPES][
> MAX_CU_DEPTH ][ MAX_CU_DEPTH ];
>
> void initZscanToRaster(int maxDepth, int depth, uint32_t startVal,
> uint32_t*& curIdx);
> void initRasterToZscan(uint32_t maxCUWidth, uint32_t maxCUHeight,
> uint32_t maxCUDepth);
> @@ -125,12 +130,6 @@
> extern const int16_t g_chromaFilter[8][NTAPS_CHROMA]; ///< Chroma filter
> taps
>
> //
> ====================================================================================================================
> -// Luma QP to Chroma QP mapping
> -//
> ====================================================================================================================
> -
> -extern const UChar g_chromaScale[70];
> -
> -//
> ====================================================================================================================
> // Scanning order & context mapping table
> //
> ====================================================================================================================
>
> diff -r c33edcd92866 -r a4d3275bca23 source/Lib/TLibCommon/TComYuv.h
> --- a/source/Lib/TLibCommon/TComYuv.h Fri Jan 03 18:40:41 2014 +0530
> +++ b/source/Lib/TLibCommon/TComYuv.h Fri Jan 03 18:42:10 2014 +0530
> @@ -179,9 +179,9 @@
> // Access starting position of YUV partition unit buffer
> Pel* getLumaAddr(uint32_t partUnitIdx) { return m_bufY +
> getAddrOffset(partUnitIdx, m_width); }
>
> - Pel* getCbAddr(uint32_t partUnitIdx) { return m_bufU +
> (getAddrOffset(partUnitIdx, m_cwidth) >> 1); }
> + Pel* getCbAddr(uint32_t partUnitIdx) { return m_bufU +
> (getAddrOffset(partUnitIdx, m_cwidth) >> m_hChromaShift); }
>
> - Pel* getCrAddr(uint32_t partUnitIdx) { return m_bufV +
> (getAddrOffset(partUnitIdx, m_cwidth) >> 1); }
> + Pel* getCrAddr(uint32_t partUnitIdx) { return m_bufV +
> (getAddrOffset(partUnitIdx, m_cwidth) >> m_hChromaShift); }
>
> // Access starting position of YUV transform unit buffer
> Pel* getLumaAddr(uint32_t iTransUnitIdx, uint32_t iBlkSize) { return
> m_bufY + getAddrOffset(iTransUnitIdx, iBlkSize, m_width); }
> diff -r c33edcd92866 -r a4d3275bca23 source/Lib/TLibCommon/TypeDef.h
> --- a/source/Lib/TLibCommon/TypeDef.h Fri Jan 03 18:40:41 2014 +0530
> +++ b/source/Lib/TLibCommon/TypeDef.h Fri Jan 03 18:42:10 2014 +0530
> @@ -70,6 +70,10 @@
> //
> ====================================================================================================================
> // Enumeration
> //
> ====================================================================================================================
> +#define MDCS_MODE MDCS_BOTH_DIRECTIONS ///<
> Name taken from definition of MDCSMode enumeration below
> +#define MDCS_ANGLE_LIMIT 4 ///<
> (default 4) 0 = Horizontal/vertical only, 1 = Horizontal/vertical +/- 1, 2
> = Horizontal/vertical +/- 2 etc...
> +#define MDCS_MAXIMUM_WIDTH 8 ///<
> (default 8) (measured in pixels) TUs with width greater than this can only
> use diagonal scan
> +#define MDCS_MAXIMUM_HEIGHT 8 ///<
> (default 8) (measured in pixels) TUs with height greater than this can only
> use diagonal scan
>
> /// supported slice type
> enum SliceType
> @@ -79,6 +83,26 @@
> I_SLICE
> };
>
> +/// chroma formats (according to semantics of chroma_format_idc)
> +enum ChromaFormat
> +{
> + CHROMA_400 = 0,
> + CHROMA_420 = 1,
> + CHROMA_422 = 2,
> + CHROMA_444 = 3,
> + NUM_CHROMA_FORMAT = 4
> +};
> +
> +///MDCS modes
> +enum MDCSMode
> +{
> + MDCS_DISABLED = 0,
> + MDCS_HORIZONTAL_ONLY = 1,
> + MDCS_VERTICAL_ONLY = 2,
> + MDCS_BOTH_DIRECTIONS = 3,
> + MDCS_NUMBER_OF_MODES = 4
> +};
> +
> #define CHROMA_H_SHIFT(x) (x == X265_CSP_I420 || x == X265_CSP_I422)
> #define CHROMA_V_SHIFT(x) (x == X265_CSP_I420)
>
> @@ -139,9 +163,36 @@
> /// coefficient scanning type used in ACS
> enum COEFF_SCAN_TYPE
> {
> - SCAN_DIAG = 0, ///< up-right diagonal scan
> - SCAN_HOR, ///< horizontal first scan
> - SCAN_VER ///< vertical first scan
> + SCAN_DIAG = 0, ///< up-right diagonal scan
> + SCAN_HOR = 1, ///< horizontal first scan
> + SCAN_VER = 2, ///< vertical first scan
> + SCAN_NUMBER_OF_TYPES = 3
> +};
> +
> +enum SignificanceMapContextType
> +{
> + CONTEXT_TYPE_4x4 = 0,
> + CONTEXT_TYPE_8x8 = 1,
> + CONTEXT_TYPE_NxN = 2,
> + CONTEXT_NUMBER_OF_TYPES = 3
> +};
> +
> +enum COEFF_SCAN_GROUP_TYPE
> +{
> + SCAN_UNGROUPED = 0,
> + SCAN_GROUPED_4x4 = 1,
> + SCAN_NUMBER_OF_GROUP_TYPES = 2
> +};
> +
> +//TU settings for entropy encoding
> +struct TUEntropyCodingParameters
> +{
> + const uint32_t *scan;
> + const uint32_t *scanCG;
> + COEFF_SCAN_TYPE scanType;
> + uint32_t widthInGroups;
> + uint32_t heightInGroups;
> + uint32_t firstSignificanceMapContext;
> };
>
tabs?
>
> namespace Profile {
> diff -r c33edcd92866 -r a4d3275bca23 source/Lib/TLibEncoder/TEncCfg.h
> --- a/source/Lib/TLibEncoder/TEncCfg.h Fri Jan 03 18:40:41 2014 +0530
> +++ b/source/Lib/TLibEncoder/TEncCfg.h Fri Jan 03 18:42:10 2014 +0530
> @@ -113,6 +113,8 @@
> int m_gradualDecodingRefreshInfoEnabled;
> int m_decodingUnitInfoSEIEnabled;
>
> + int m_csp;
> +
> //====== Weighted Prediction ========
>
> uint32_t m_log2ParallelMergeLevelMinus2; ///<
> Parallel merge estimation region
> @@ -255,6 +257,8 @@
>
> int getVideoFormat() { return m_videoFormat; }
>
> + int getColorFormat() { return m_csp; }
> +
> bool getVideoFullRangeFlag() { return m_videoFullRangeFlag; }
>
> bool getColourDescriptionPresentFlag() { return
> m_colourDescriptionPresentFlag; }
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
--
Steve Borho
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20140107/431e0b99/attachment-0001.html>
More information about the x265-devel
mailing list