searchborder.hh

来自「Motion JPEG编解码器源代码」· HH 代码 · 共 2,118 行 · 第 1/5 页

HH
2,118
字号
	m_tnHeight = a_tnHeight;	m_tnPGW = a_tnPGW;	m_tnPGH = a_tnPGH;}// Default constructor.  Must be followed by Init().template <class PIXELINDEX, class FRAMESIZE>SearchBorder<PIXELINDEX,FRAMESIZE>::MovedRegion::MovedRegion		(typename BaseClass::Allocator &a_rAlloc)	: BaseClass (a_rAlloc){	// No motion-vector yet.	m_tnX = m_tnY = PIXELINDEX (0);	m_tnSquaredLength = FRAMESIZE (0);}// Initializing constructor.  Creates an empty region.template <class PIXELINDEX, class FRAMESIZE>SearchBorder<PIXELINDEX,FRAMESIZE>::MovedRegion::MovedRegion		(Status_t &a_reStatus, typename BaseClass::Allocator &a_rAlloc)	: BaseClass (a_rAlloc){	// Make sure they didn't start us off with an error.	assert (a_reStatus == g_kNoError);	// No motion-vector yet.	m_tnX = m_tnY = PIXELINDEX (0);	m_tnSquaredLength = FRAMESIZE (0);	// Initialize ourselves.	Init (a_reStatus);	if (a_reStatus != g_kNoError)		return;}// Copy constructor.template <class PIXELINDEX, class FRAMESIZE>SearchBorder<PIXELINDEX,FRAMESIZE>::MovedRegion::MovedRegion		(Status_t &a_reStatus, const MovedRegion &a_rOther)	: BaseClass (a_reStatus, a_rOther){	// No motion-vector yet.	m_tnX = m_tnY = PIXELINDEX (0);	m_tnSquaredLength = FRAMESIZE (0);	// If copying our base class failed, leave.	if (a_reStatus != g_kNoError)		return;	// Copy the motion vector.	m_tnX = a_rOther.m_tnX;	m_tnY = a_rOther.m_tnY;	m_tnSquaredLength = a_rOther.m_tnSquaredLength;}// Initializer.  Must be called on default-constructed regions.template <class PIXELINDEX, class FRAMESIZE>voidSearchBorder<PIXELINDEX,FRAMESIZE>::MovedRegion::Init	(Status_t &a_reStatus){	// Make sure they didn't start us off with an error.	assert (a_reStatus == g_kNoError);	// Initialize the base-class.	BaseClass::Init (a_reStatus);	if (a_reStatus != g_kNoError)		return;}// Make the current region a copy of the other region.template <class PIXELINDEX, class FRAMESIZE>voidSearchBorder<PIXELINDEX,FRAMESIZE>::MovedRegion::Assign	(Status_t &a_reStatus, const MovedRegion &a_rOther){	// Make sure they didn't start us off with an error.	assert (a_reStatus == g_kNoError);	// Assign the base class.	BaseClass::Assign (a_reStatus, a_rOther);	if (a_reStatus != g_kNoError)		return;	// Copy the motion vector.	m_tnX = a_rOther.m_tnX;	m_tnY = a_rOther.m_tnY;	m_tnSquaredLength = a_rOther.m_tnSquaredLength;}// Destructor.template <class PIXELINDEX, class FRAMESIZE>SearchBorder<PIXELINDEX,FRAMESIZE>::MovedRegion::~MovedRegion(){	// Nothing additional to do.}// Set the motion vector.template <class PIXELINDEX, class FRAMESIZE>inline voidSearchBorder<PIXELINDEX,FRAMESIZE>::MovedRegion::SetMotionVector	(PIXELINDEX a_tnX, PIXELINDEX a_tnY){	// Set the motion vector.	m_tnX = a_tnX;	m_tnY = a_tnY;	// Calculate the square of the vector's length.  (It's used for	// sorting, and we don't want to recalculate it on every	// comparison.)	m_tnSquaredLength = FRAMESIZE (m_tnX) * FRAMESIZE (m_tnX)		+ FRAMESIZE (m_tnY) * FRAMESIZE (m_tnY);}// Get the motion vector.template <class PIXELINDEX, class FRAMESIZE>inline voidSearchBorder<PIXELINDEX,FRAMESIZE>::MovedRegion::GetMotionVector	(PIXELINDEX &a_rtnX, PIXELINDEX &a_rtnY) const{	// Easy enough.	a_rtnX = m_tnX;	a_rtnY = m_tnY;}// Comparison operator.template <class PIXELINDEX, class FRAMESIZE>inline boolSearchBorder<PIXELINDEX,FRAMESIZE>::MovedRegion	::SortBySizeThenMotionVectorLength::operator()	(const MovedRegion *a_pLeft, const MovedRegion *a_pRight) const{	FRAMESIZE nLeftPoints, nRightPoints;		// The number of points in each region.	FRAMESIZE tnLeftLen, tnRightLen;		// The (squared) length of each motion vector.	// Make sure they gave us some regions to compare.	assert (a_pLeft != NULL);	assert (a_pRight != NULL);	// First, compare by the number of points in each region.	// Sort bigger regions first.	nLeftPoints = a_pLeft->NumberOfPoints();	nRightPoints = a_pRight->NumberOfPoints();	if (nLeftPoints > nRightPoints)		return true;	if (nLeftPoints < nRightPoints)		return false;	// Then compare on motion vector length.	// Sort smaller vectors first.	tnLeftLen = a_pLeft->GetSquaredMotionVectorLength();	tnRightLen = a_pRight->GetSquaredMotionVectorLength();	if (tnLeftLen < tnRightLen)		return true;	// if (tnLeftLen >= tnRightLen)		return false;}// Get the squared length of the motion vector.template <class PIXELINDEX, class FRAMESIZE>inline FRAMESIZESearchBorder<PIXELINDEX,FRAMESIZE>::MovedRegion	::GetSquaredMotionVectorLength (void) const{	// Easy enough.	return m_tnSquaredLength;}// Default constructor.template <class PIXELINDEX, class FRAMESIZE>SearchBorder<PIXELINDEX,FRAMESIZE>::RegionUnderConstruction	::RegionUnderConstruction(){#ifndef NDEBUG	// One more instance.	++sm_ulInstances;#endif // NDEBUG	// Fill in the blanks.	m_pRegion = NULL;	m_tnReferences = FRAMESIZE (0);}// Destructor.template <class PIXELINDEX, class FRAMESIZE>SearchBorder<PIXELINDEX,FRAMESIZE>::RegionUnderConstruction	::~RegionUnderConstruction(){#ifndef NDEBUG	// One less instance.	--sm_ulInstances;#endif // NDEBUG	// Make sure all references have been removed.	assert (m_pRegion == NULL);	assert (m_tnReferences == FRAMESIZE (0));}#ifndef NDEBUGtemplate <class PIXELINDEX, class FRAMESIZE>uint32_tSearchBorder<PIXELINDEX,FRAMESIZE>::RegionUnderConstruction	::sm_ulInstances;#endif // NDEBUG// Default constructor.template <class PIXELINDEX, class FRAMESIZE>SearchBorder<PIXELINDEX,FRAMESIZE>::BorderExtentBoundary	::BorderExtentBoundary(){	// Fill in the blanks.	m_tnIndex = m_tnLine = PIXELINDEX (0);	m_bIsEnding = false;	m_pCounterpart = NULL;	m_pRegion = NULL;	m_tnMotionX = m_tnMotionY = PIXELINDEX (0);}// Initializing constructor.template <class PIXELINDEX, class FRAMESIZE>SearchBorder<PIXELINDEX,FRAMESIZE>::BorderExtentBoundary	::BorderExtentBoundary (PIXELINDEX a_tnIndex,	PIXELINDEX a_tnLine, bool a_bIsEnding,	RegionUnderConstruction *a_pRegion){	// Make sure they gave us a region.	assert (a_pRegion != NULL);	assert (a_pRegion->m_pRegion != NULL);	// Fill in the blanks.	m_tnIndex = a_tnIndex;	m_tnLine = a_tnLine;	m_bIsEnding = a_bIsEnding;	m_pCounterpart = NULL;	m_pRegion = a_pRegion;	a_pRegion->m_pRegion->GetMotionVector (m_tnMotionX, m_tnMotionY);}// Destructor.template <class PIXELINDEX, class FRAMESIZE>SearchBorder<PIXELINDEX,FRAMESIZE>::BorderExtentBoundary	::~BorderExtentBoundary(){	// Nothing to do.}#ifndef NDEBUG// Equality operator.template <class PIXELINDEX, class FRAMESIZE>boolSearchBorder<PIXELINDEX,FRAMESIZE>::BorderExtentBoundary	::operator == (const BorderExtentBoundary &a_rOther) const{	// Compare ourselves, field by field.	return (m_tnIndex == a_rOther.m_tnIndex		&& m_tnLine == a_rOther.m_tnLine		&& m_bIsEnding == a_rOther.m_bIsEnding		&& m_pCounterpart == a_rOther.m_pCounterpart		&& m_pRegion == a_rOther.m_pRegion		&& m_tnMotionX == a_rOther.m_tnMotionX		&& m_tnMotionY == a_rOther.m_tnMotionY);}#endif // NDEBUG// Comparison operator.template <class PIXELINDEX, class FRAMESIZE>inline boolSearchBorder<PIXELINDEX,FRAMESIZE> ::BorderExtentBoundary	::SortByIndexThenTypeThenMotionVectorThenRegionAddress	::operator() (const BorderExtentBoundary &a_rLeft,	const BorderExtentBoundary &a_rRight) const{	// First, sort by the boundary's pixel line.	if (a_rLeft.m_tnLine < a_rRight.m_tnLine)		return true;	if (a_rLeft.m_tnLine > a_rRight.m_tnLine)		return false;	// Then sort by the boundary's pixel index.	if (a_rLeft.m_tnIndex < a_rRight.m_tnIndex)		return true;	if (a_rLeft.m_tnIndex > a_rRight.m_tnIndex)		return false;#if 0	// (Not needed: startpoints & endpoints are in separate sets now.)	// Then sort beginnings before endings.	if (!a_rLeft.m_bIsEnding && a_rRight.m_bIsEnding)		return true;	if (a_rLeft.m_bIsEnding && !a_rRight.m_bIsEnding)		return false;#endif	// Sort next by motion vector.  (It doesn't matter how the sort	// order is defined from the motion vectors, just that one is	// defined.)	if (a_rLeft.m_tnMotionX < a_rRight.m_tnMotionX)		return true;	if (a_rLeft.m_tnMotionX > a_rRight.m_tnMotionX)		return false;	if (a_rLeft.m_tnMotionY < a_rRight.m_tnMotionY)		return true;	if (a_rLeft.m_tnMotionY > a_rRight.m_tnMotionY)		return false;	// Finally, disambiguate by region address.	if (a_rLeft.m_pRegion < a_rRight.m_pRegion)		return true;	// if (a_rLeft.m_pRegion >= a_rRight.m_pRegion)		return false;}// Comparison operator.template <class PIXELINDEX, class FRAMESIZE>inline boolSearchBorder<PIXELINDEX,FRAMESIZE>::BorderExtentBoundary	::SortByMotionVectorThenTypeThenRegionAddress::operator()	(const BorderExtentBoundary &a_rLeft,	const BorderExtentBoundary &a_rRight) const{	// Sort by motion vector.  (It doesn't matter how the sort	// order is defined from the motion vectors, just that one is	// defined.)	if (a_rLeft.m_tnMotionX < a_rRight.m_tnMotionX)		return true;	if (a_rLeft.m_tnMotionX > a_rRight.m_tnMotionX)		return false;	if (a_rLeft.m_tnMotionY < a_rRight.m_tnMotionY)		return true;	if (a_rLeft.m_tnMotionY > a_rRight.m_tnMotionY)		return false;	// Next, sort beginnings before endings.	if (!a_rLeft.m_bIsEnding && a_rRight.m_bIsEnding)		return true;	if (a_rLeft.m_bIsEnding && !a_rRight.m_bIsEnding)		return false;	// Next, sort by index.  (Regions may have more than one extent	// on a border.)	if (a_rLeft.m_tnIndex < a_rRight.m_tnIndex)		return true;	if (a_rLeft.m_tnIndex > a_rRight.m_tnIndex)		return false;	// Next, sort by lines.  (The same region may have extents on	// multiple lines, and this also matches the order in the	// startpoints/endpoints sets, so that searches take maximum	// advantage of the search finger.)	if (a_rLeft.m_tnLine < a_rRight.m_tnLine)		return true;	if (a_rLeft.m_tnLine > a_rRight.m_tnLine)		return false;		// Finally, disambiguate by region address.	if (a_rLeft.m_pRegion < a_rRight.m_pRegion)		return true;	//if (a_rLeft.m_pRegion >= a_rRight.m_pRegion)		return false;}// Initialize the search-border, i.e. start in the upper-left corner.template <class PIXELINDEX, class FRAMESIZE>voidSearchBorder<PIXELINDEX,FRAMESIZE>::StartFrame (Status_t &a_reStatus){	// Make sure they didn't start us off with an error.	assert (a_reStatus == g_kNoError);	// Make sure the borders are empty.	assert (m_setBorderStartpoints.Size() == 0);	assert (m_setBorderEndpoints.Size() == 0);	assert (m_setBorderRegions.Size() == 0);	// Set up our iterators into the borders.	for (int i = 0; i <= m_tnPGH; ++i)	{		m_paitBorderStartpoints[i] = m_setBorderStartpoints.End();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?