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