refactor(pixel): add nameless namespace to CalypPixel
This commit is contained in:
+26
-40
@@ -31,22 +31,26 @@
|
|||||||
#include "PixelFormats.h"
|
#include "PixelFormats.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
constexpr auto kMinPixelValue{ 0 };
|
constexpr auto kMinPixelValue{ 0 };
|
||||||
constexpr auto kMaxPixelValue{ 255 };
|
constexpr auto kMaxPixelValue{ 255 };
|
||||||
|
|
||||||
static inline void yuvToRgb( const int& iY, const int& iU, const int& iV, int& iR, int& iG, int& iB )
|
inline void yuvToRgb( int iY, int iU, int iV, int& iR, int& iG, int& iB )
|
||||||
{
|
{
|
||||||
iR = std::clamp( iY + ( ( 1436 * ( iV - 128 ) ) >> 10 ), kMinPixelValue, kMaxPixelValue ); // NOLINT
|
iR = std::clamp( iY + ( ( 1436 * ( iV - 128 ) ) >> 10 ), kMinPixelValue, kMaxPixelValue ); // NOLINT
|
||||||
iG = std::clamp( iY - ( ( 352 * ( iU - 128 ) + 731 * ( iV - 128 ) ) >> 10 ), kMinPixelValue, kMaxPixelValue ); // NOLINT
|
iG = std::clamp( iY - ( ( 352 * ( iU - 128 ) + 731 * ( iV - 128 ) ) >> 10 ), kMinPixelValue,
|
||||||
iB = std::clamp( iY + ( ( 1812 * ( iU - 128 ) ) >> 10 ), kMinPixelValue, kMaxPixelValue ); // NOLINT
|
kMaxPixelValue ); // NOLINT
|
||||||
|
iB = std::clamp( iY + ( ( 1812 * ( iU - 128 ) ) >> 10 ), kMinPixelValue, kMaxPixelValue ); // NOLINT
|
||||||
}
|
}
|
||||||
|
inline void rgbToYuv( int iR, int iG, int iB, int& iY, int& iU, int& iV )
|
||||||
static inline void rgbToYuv( const int& iR, const int& iG, const int& iB, int& iY, int& iU, int& iV )
|
|
||||||
{
|
{
|
||||||
iY = ( 299 * iR + 587 * iG + 114 * iB + 500 ) / 1000; // NOLINT
|
iY = ( 299 * iR + 587 * iG + 114 * iB + 500 ) / 1000; // NOLINT
|
||||||
iU = ( 1000 * ( iB - iY ) + 226816 ) / 1772; // NOLINT
|
iU = ( 1000 * ( iB - iY ) + 226816 ) / 1772; // NOLINT
|
||||||
iV = ( 1000 * ( iR - iY ) + 179456 ) / 1402; // NOLINT
|
iV = ( 1000 * ( iR - iY ) + 179456 ) / 1402; // NOLINT
|
||||||
}
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
CalypPixel::CalypPixel( const int ColorSpace, const ClpPel c0 )
|
CalypPixel::CalypPixel( const int ColorSpace, const ClpPel c0 )
|
||||||
{
|
{
|
||||||
@@ -75,10 +79,7 @@ CalypPixel& CalypPixel::operator+=( const CalypPixel& in )
|
|||||||
{
|
{
|
||||||
assert( in.colorSpace() == m_colorSpace );
|
assert( in.colorSpace() == m_colorSpace );
|
||||||
const auto& other_comp = in.components();
|
const auto& other_comp = in.components();
|
||||||
std::transform( other_comp.begin(),
|
std::transform( other_comp.begin(), other_comp.end(), m_pelComp.begin(), m_pelComp.begin(),
|
||||||
other_comp.end(),
|
|
||||||
m_pelComp.begin(),
|
|
||||||
m_pelComp.begin(),
|
|
||||||
[]( auto& p1, auto& p2 ) { return p1 + p2; } );
|
[]( auto& p1, auto& p2 ) { return p1 + p2; } );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -87,20 +88,14 @@ CalypPixel& CalypPixel::operator-=( const CalypPixel& in )
|
|||||||
{
|
{
|
||||||
assert( in.colorSpace() == m_colorSpace );
|
assert( in.colorSpace() == m_colorSpace );
|
||||||
const auto& other_comp = in.components();
|
const auto& other_comp = in.components();
|
||||||
std::transform( other_comp.begin(),
|
std::transform( other_comp.begin(), other_comp.end(), m_pelComp.begin(), m_pelComp.begin(),
|
||||||
other_comp.end(),
|
|
||||||
m_pelComp.begin(),
|
|
||||||
m_pelComp.begin(),
|
|
||||||
[]( auto& p1, auto& p2 ) { return p1 - p2; } );
|
[]( auto& p1, auto& p2 ) { return p1 - p2; } );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CalypPixel& CalypPixel::operator*=( const double op )
|
CalypPixel& CalypPixel::operator*=( const double op )
|
||||||
{
|
{
|
||||||
std::transform( m_pelComp.begin(),
|
std::transform( m_pelComp.begin(), m_pelComp.end(), m_pelComp.begin(), [&op]( auto& p1 ) { return p1 * op; } );
|
||||||
m_pelComp.end(),
|
|
||||||
m_pelComp.begin(),
|
|
||||||
[&op]( auto& p1 ) { return p1 * op; } );
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,10 +104,7 @@ CalypPixel CalypPixel::operator+( const CalypPixel& in ) const
|
|||||||
assert( in.colorSpace() == m_colorSpace );
|
assert( in.colorSpace() == m_colorSpace );
|
||||||
const auto& other_comp = in.components();
|
const auto& other_comp = in.components();
|
||||||
CalypPixel result{ m_colorSpace };
|
CalypPixel result{ m_colorSpace };
|
||||||
std::transform( other_comp.begin(),
|
std::transform( other_comp.begin(), other_comp.end(), m_pelComp.begin(), result.components().begin(),
|
||||||
other_comp.end(),
|
|
||||||
m_pelComp.begin(),
|
|
||||||
result.components().begin(),
|
|
||||||
[]( auto& p1, auto& p2 ) { return p1 + p2; } );
|
[]( auto& p1, auto& p2 ) { return p1 + p2; } );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -122,10 +114,7 @@ CalypPixel CalypPixel::operator-( const CalypPixel& in ) const
|
|||||||
assert( in.colorSpace() == m_colorSpace );
|
assert( in.colorSpace() == m_colorSpace );
|
||||||
const auto& other_comp = in.components();
|
const auto& other_comp = in.components();
|
||||||
CalypPixel result{ m_colorSpace };
|
CalypPixel result{ m_colorSpace };
|
||||||
std::transform( other_comp.begin(),
|
std::transform( other_comp.begin(), other_comp.end(), m_pelComp.begin(), result.components().begin(),
|
||||||
other_comp.end(),
|
|
||||||
m_pelComp.begin(),
|
|
||||||
result.components().begin(),
|
|
||||||
[]( auto& p1, auto& p2 ) { return p1 - p2; } );
|
[]( auto& p1, auto& p2 ) { return p1 - p2; } );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -134,10 +123,7 @@ CalypPixel CalypPixel::operator*( const double op ) const
|
|||||||
{
|
{
|
||||||
CalypPixel result{ m_colorSpace };
|
CalypPixel result{ m_colorSpace };
|
||||||
auto& comp = result.components();
|
auto& comp = result.components();
|
||||||
std::transform( comp.begin(),
|
std::transform( comp.begin(), comp.end(), comp.begin(), [&op]( auto& p1 ) { return p1 * op; } );
|
||||||
comp.end(),
|
|
||||||
comp.begin(),
|
|
||||||
[&op]( auto& p1 ) { return p1 * op; } );
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,16 +135,16 @@ auto CalypPixel::operator==( const CalypPixel& other ) const -> bool
|
|||||||
|
|
||||||
std::ostream& operator<<( std::ostream& os, const CalypPixel& p )
|
std::ostream& operator<<( std::ostream& os, const CalypPixel& p )
|
||||||
{
|
{
|
||||||
#ifdef CLP_DEBUG
|
// #ifdef CLP_DEBUG
|
||||||
if( p.colorSpace() == CLP_COLOR_RGB || p.colorSpace() == CLP_COLOR_YUV )
|
// if( p.colorSpace() == CLP_COLOR_RGB || p.colorSpace() == CLP_COLOR_YUV )
|
||||||
{
|
// {
|
||||||
os << "(" << p[0] << ", " << p[1] << ", " << p[2] << ")";
|
// os << "(" << p[0] << ", " << p[1] << ", " << p[2] << ")";
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
os << "(" << p[0] << ", " << p[1] << ", " << p[2] << ", " << p[3] << ")";
|
// os << "(" << p[0] << ", " << p[1] << ", " << p[2] << ", " << p[3] << ")";
|
||||||
}
|
// }
|
||||||
#endif
|
// #endif
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user