Commit bb902c4a authored by Xiaozhong Xu's avatar Xiaozhong Xu Committed by Xiang Li

K0076_CPR code update

parent 7fbb4d96
......@@ -107,6 +107,10 @@ inline void dtraceModeCost(CodingStructure &cs, double lambda)
if( isIntra && intraModeC == DM_CHROMA_IDX ) intraModeC = 36;
else if( isIntra ) intraModeC = g_intraMode65to33AngMapping[intraModeC];
#endif
#endif
int imvVal = 0;
#if JVET_K0357_AMVR
imvVal = cs.cus[0]->imv;
#endif
#if JEM_TOOLS
DTRACE( g_trace_ctx, D_MODE_COST, "ModeCost: %6lld %3d @(%4d,%4d) [%2dx%2d] %d (qp%d,pm%d,ptSize%d,skip%d,mrg%d,fruc%d,obmc%d,ic%d,imv%d,affn%d,%d,%d) tempCS = %lld (%d,%d)\n",
......@@ -123,11 +127,7 @@ inline void dtraceModeCost(CodingStructure &cs, double lambda)
cs.pus[0]->frucMrgMode,
cs.cus[0]->obmcFlag,
cs.cus[0]->LICFlag,
#if JVET_K0357_AMVR
cs.cus[0]->imv,
#else
0,
#endif
imvVal,
cs.cus[0]->affine,
intraModeL, intraModeC,
tempCost, tempBits, tempDist );
......@@ -144,11 +144,7 @@ inline void dtraceModeCost(CodingStructure &cs, double lambda)
cs.cus[0]->skip,
cs.pus[0]->mergeFlag,
0, 0,
#if JVET_K0357_AMVR
cs.cus[0]->imv,
#else
0,
#endif
imvVal,
0, 0,
intraModeL, intraModeC,
tempCost, tempBits, tempDist );
......
......@@ -7,8 +7,6 @@ file( GLOB SRC_FILES "*.cpp" )
# get include files
file( GLOB INC_FILES "*.h" )
file( GLOB SSE41_SRC_FILES "IbcHashMap.cpp" )
# NATVIS files for Visual Studio
if( MSVC )
file( GLOB NATVIS_FILES "../../VisualStudio/*.natvis" )
......@@ -57,10 +55,6 @@ endif()
target_include_directories( ${LIB_NAME} PUBLIC . )
target_link_libraries( ${LIB_NAME} CommonLib Threads::Threads )
if( UNIX )
set_property( SOURCE ${SSE41_SRC_FILES} APPEND PROPERTY COMPILE_FLAGS "-msse4" )
endif()
if( CMAKE_COMPILER_IS_GNUCC )
# this is quite certainly a compiler problem
set_property( SOURCE "EncCu.cpp" APPEND PROPERTY COMPILE_FLAGS "-Wno-array-bounds" )
......
......@@ -58,9 +58,6 @@
#include "InterSearch.h"
#include "RateCtrl.h"
#include "EncModeCtrl.h"
#if JVET_K0076_CPR
#include "IbcHashMap.h"
#endif
//! \ingroup EncoderLib
//! \{
......
/* The copyright in this software is being made available under the BSD
* License, included below. This software may be subject to other third party
* and contributor rights, including patent rights, and no such rights are
* granted under this license.
*
* Copyright (c) 2010-2017, ITU/ISO/IEC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file IbcHashMap.cpp
\brief IBC hash map encoder class
*/
#include "CommonLib/dtrace_codingstruct.h"
#include "CommonLib/Picture.h"
#include "CommonLib/UnitTools.h"
#include "IbcHashMap.h"
#include <nmmintrin.h>
using namespace std;
//! \ingroup IbcHashMap
//! \{
// ====================================================================================================================
// Constructor / destructor / create / destroy
// ====================================================================================================================
IbcHashMap::IbcHashMap()
{
m_picWidth = 0;
m_picHeight = 0;
m_pos2Hash = NULL;
}
IbcHashMap::~IbcHashMap()
{
destroy();
}
void IbcHashMap::init(const int picWidth, const int picHeight)
{
if (picWidth != m_picWidth || picHeight != m_picHeight)
{
destroy();
}
m_picWidth = picWidth;
m_picHeight = picHeight;
m_pos2Hash = new unsigned int*[m_picHeight];
m_pos2Hash[0] = new unsigned int[m_picWidth * m_picHeight];
for (int n = 1; n < m_picHeight; n++)
{
m_pos2Hash[n] = m_pos2Hash[n - 1] + m_picWidth;
}
}
void IbcHashMap::destroy()
{
if (m_pos2Hash != NULL)
{
if (m_pos2Hash[0] != NULL)
{
delete[] m_pos2Hash[0];
}
delete[] m_pos2Hash;
}
m_pos2Hash = NULL;
}
template<int maskBit>
unsigned int IbcHashMap::xxCalcBlockHash(const Pel* pel, const int stride, const int width, const int height, unsigned int crc)
{
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
crc = _mm_crc32_u16(crc, pel[x] >> maskBit);
}
pel += stride;
}
return crc;
}
template<ChromaFormat chromaFormat, int maskBit>
void IbcHashMap::xxBuildPicHashMap(const PelUnitBuf& pic)
{
const int chromaScalingX = getChannelTypeScaleX(CHANNEL_TYPE_CHROMA, chromaFormat);
const int chromaScalingY = getChannelTypeScaleY(CHANNEL_TYPE_CHROMA, chromaFormat);
const int chromaMinBlkWidth = MIN_PU_SIZE >> chromaScalingX;
const int chromaMinBlkHeight = MIN_PU_SIZE >> chromaScalingY;
const Pel* pelY = NULL;
const Pel* pelCb = NULL;
const Pel* pelCr = NULL;
Position pos;
for (pos.y = 0; pos.y + MIN_PU_SIZE <= pic.Y().height; pos.y++)
{
// row pointer
pelY = pic.Y().bufAt(0, pos.y);
if (chromaFormat != CHROMA_400)
{
int chromaY = pos.y >> chromaScalingY;
pelCb = pic.Cb().bufAt(0, chromaY);
pelCr = pic.Cr().bufAt(0, chromaY);
}
for (pos.x = 0; pos.x + MIN_PU_SIZE <= pic.Y().width; pos.x++)
{
// 0x1FF is just an initial value
unsigned int hashValue = 0x1FF;
// luma part
hashValue = xxCalcBlockHash<maskBit>(&pelY[pos.x], pic.Y().stride, MIN_PU_SIZE, MIN_PU_SIZE, hashValue);
// chroma part
if (chromaFormat != CHROMA_400)
{
int chromaX = pos.x >> chromaScalingX;
hashValue = xxCalcBlockHash<maskBit>(&pelCb[chromaX], pic.Cb().stride, chromaMinBlkWidth, chromaMinBlkHeight, hashValue);
hashValue = xxCalcBlockHash<maskBit>(&pelCr[chromaX], pic.Cr().stride, chromaMinBlkWidth, chromaMinBlkHeight, hashValue);
}
// hash table
m_hash2Pos[hashValue].push_back(pos);
m_pos2Hash[pos.y][pos.x] = hashValue;
}
}
}
void IbcHashMap::rebuildPicHashMap(const PelUnitBuf& pic)
{
m_hash2Pos.clear();
switch (pic.chromaFormat)
{
case CHROMA_400:
xxBuildPicHashMap<CHROMA_400, 0>(pic);
break;
case CHROMA_420:
xxBuildPicHashMap<CHROMA_420, 0>(pic);
break;
case CHROMA_422:
xxBuildPicHashMap<CHROMA_422, 0>(pic);
break;
case CHROMA_444:
xxBuildPicHashMap<CHROMA_444, 0>(pic);
break;
default:
THROW("invalid chroma fomat");
break;
}
}
bool IbcHashMap::ibcHashMatch(const Area& lumaArea, std::vector<Position>& cand, const CodingStructure& cs, const int maxCand, const int searchRange4SmallBlk)
{
cand.clear();
// find the block with least candidates
size_t minSize = MAX_UINT;
unsigned int targetHashOneBlock = 0;
for (SizeType y = 0; y < lumaArea.height && minSize > 1; y += MIN_PU_SIZE)
{
for (SizeType x = 0; x < lumaArea.width && minSize > 1; x += MIN_PU_SIZE)
{
unsigned int hash = m_pos2Hash[lumaArea.pos().y + y][lumaArea.pos().x + x];
if (m_hash2Pos[hash].size() < minSize)
{
minSize = m_hash2Pos[hash].size();
targetHashOneBlock = hash;
}
}
}
if (m_hash2Pos[targetHashOneBlock].size() > 1)
{
std::vector<Position>& candOneBlock = m_hash2Pos[targetHashOneBlock];
// check whether whole block match
for (std::vector<Position>::iterator refBlockPos = candOneBlock.begin(); refBlockPos != candOneBlock.end(); refBlockPos++)
{
Position bottomRight = refBlockPos->offset(lumaArea.width - 1, lumaArea.height - 1);
bool wholeBlockMatch = true;
if (lumaArea.width > MIN_PU_SIZE || lumaArea.height > MIN_PU_SIZE)
{
#if JVET_K0076_CPR
if (!cs.isDecomp(bottomRight, cs.chType) || bottomRight.x >= m_picWidth || bottomRight.y >= m_picHeight)
#else
if (!cs.isDecomp(bottomRight, CHANNEL_TYPE_LUMA) || bottomRight.x >= m_picWidth || bottomRight.y >= m_picHeight)
#endif
{
continue;
}
for (SizeType y = 0; y < lumaArea.height && wholeBlockMatch; y += MIN_PU_SIZE)
{
for (SizeType x = 0; x < lumaArea.width && wholeBlockMatch; x += MIN_PU_SIZE)
{
// whether the reference block and current block has the same hash
wholeBlockMatch &= (m_pos2Hash[lumaArea.pos().y + y][lumaArea.pos().x + x] == m_pos2Hash[refBlockPos->y + y][refBlockPos->x + x]);
}
}
}
else
{
#if JVET_K0076_CPR
if (abs(refBlockPos->x - lumaArea.x) > searchRange4SmallBlk || abs(refBlockPos->y - lumaArea.y) > searchRange4SmallBlk || !cs.isDecomp(bottomRight, cs.chType))
#else
if (abs(refBlockPos->x - lumaArea.x) > searchRange4SmallBlk || abs(refBlockPos->y - lumaArea.y) > searchRange4SmallBlk || !cs.isDecomp(bottomRight, CHANNEL_TYPE_LUMA))
#endif
{
continue;
}
}
if (wholeBlockMatch)
{
cand.push_back(*refBlockPos);
if (cand.size() > maxCand)
{
break;
}
}
}
}
return cand.size() > 0;
}
int IbcHashMap::getHashHitRatio(const Area& lumaArea)
{
int maxX = std::min((int)(lumaArea.x + lumaArea.width), m_picWidth);
int maxY = std::min((int)(lumaArea.y + lumaArea.height), m_picHeight);
int hit = 0, total = 0;
for (int y = lumaArea.y; y < maxY; y += MIN_PU_SIZE)
{
for (int x = lumaArea.x; x < maxX; x += MIN_PU_SIZE)
{
const unsigned int hash = m_pos2Hash[y][x];
hit += (m_hash2Pos[hash].size() > 1);
total++;
}
}
return 100 * hit / total;
}
//! \}
/* The copyright in this software is being made available under the BSD
* License, included below. This software may be subject to other third party
* and contributor rights, including patent rights, and no such rights are
* granted under this license.
*
* Copyright (c) 2010-2017, ITU/ISO/IEC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file IbcHashMap.h
\brief IBC hash map encoder class (header)
*/
#ifndef __IBCHASHMAP__
#define __IBCHASHMAP__
// Include files
#include "CommonLib/CommonDef.h"
#include "CommonLib/IntraPrediction.h"
#include "CommonLib/InterPrediction.h"
#include "CommonLib/TrQuant.h"
#include "CommonLib/Unit.h"
#include "CommonLib/UnitPartitioner.h"
#include <unordered_map>
#include <vector>
//! \ingroup EncoderLib
//! \{
// ====================================================================================================================
// Class definition
// ====================================================================================================================
class IbcHashMap
{
private:
int m_picWidth;
int m_picHeight;
unsigned int** m_pos2Hash;
std::unordered_map<unsigned int, std::vector<Position>> m_hash2Pos;
template<int maskBit>
unsigned int xxCalcBlockHash(const Pel* pel, const int stride, const int width, const int height, unsigned int crc);
template<ChromaFormat chromaFormat, int maskBit>
void xxBuildPicHashMap(const PelUnitBuf& pic);
public:
IbcHashMap();
virtual ~IbcHashMap();
void init(const int picWidth, const int picHeight);
void destroy();
void rebuildPicHashMap(const PelUnitBuf& pic);
bool ibcHashMatch(const Area& lumaArea, std::vector<Position>& cand, const CodingStructure& cs, const int maxCand, const int searchRange4SmallBlk);
int getHashHitRatio(const Area& lumaArea);
};
//! \}
#endif // __IBCHASHMAP__
......@@ -1599,7 +1599,7 @@ void IntraSearch::xIntraCodingTUBlock(TransformUnit &tu, const ComponentID &comp
m_pcTrQuant->selectLambda(compID);
#endif
#if JEM_TOOLS||JVET_K0190
#if JEM_TOOLS&&!JVET_K0190
if( ! PU::isLMCMode(uiChFinalMode) && sps.getSpsNext().getUseLMChroma() )
{
if( compID == COMPONENT_Cb )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment