Merge remote-tracking branch 'refs/remotes/origin/master' into enet_wip_nothing_to_see_here
This commit is contained in:
commit
a8fe5f4539
|
|
@ -54,6 +54,11 @@ namespace Nz
|
||||||
private:
|
private:
|
||||||
BitField m_value;
|
BitField m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator~(E lhs);
|
||||||
|
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator|(E lhs, E rhs);
|
||||||
|
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator&(E lhs, E rhs);
|
||||||
|
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator^(E lhs, E rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator~(E lhs);
|
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator~(E lhs);
|
||||||
|
|
|
||||||
|
|
@ -209,6 +209,68 @@ namespace Nz
|
||||||
{
|
{
|
||||||
return 1U << static_cast<BitField>(enumValue);
|
return 1U << static_cast<BitField>(enumValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Override binary NOT operator on enum to turns into a Flags object.
|
||||||
|
* \return A Flags object with reversed bits.
|
||||||
|
*
|
||||||
|
* \param lhs Enumeration value to reverse.
|
||||||
|
*
|
||||||
|
* Returns a Flags object with all state enabled except for the enum one.
|
||||||
|
*/
|
||||||
|
template<typename E>
|
||||||
|
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator~(E lhs)
|
||||||
|
{
|
||||||
|
return ~Flags<E>(lhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Override binary OR operator on enum to turns into a Flags object.
|
||||||
|
* \return A Flags object with combined enum states.
|
||||||
|
*
|
||||||
|
* \param lhs First enumeration value to combine.
|
||||||
|
* \param rhs Second enumeration value to combine.
|
||||||
|
*
|
||||||
|
* Returns a Flags object with combined states from the two enumeration values.
|
||||||
|
*/
|
||||||
|
template<typename E>
|
||||||
|
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator|(E lhs, E rhs)
|
||||||
|
{
|
||||||
|
return Flags<E>(lhs) | rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Override binary AND operator on enum to turns into a Flags object.
|
||||||
|
* \return A Flags object with compare enum states.
|
||||||
|
*
|
||||||
|
* \param lhs First enumeration value to compare.
|
||||||
|
* \param rhs Second enumeration value to compare.
|
||||||
|
*
|
||||||
|
* Returns a Flags object with compared states from the two enumeration values.
|
||||||
|
* In this case, only one flag will be enabled if both enumeration values are the same.
|
||||||
|
*/
|
||||||
|
template<typename E>
|
||||||
|
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator&(E lhs, E rhs)
|
||||||
|
{
|
||||||
|
return Flags<E>(lhs) & rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Override binary XOR operator on enum to turns into a Flags object.
|
||||||
|
* \return A Flags object with XORed enum states.
|
||||||
|
*
|
||||||
|
* \param lhs First enumeration value to compare.
|
||||||
|
* \param rhs Second enumeration value to compare.
|
||||||
|
*
|
||||||
|
* Returns a Flags object with XORed states from the two enumeration values.
|
||||||
|
* In this case, two flags will be enabled if both the enumeration values are different.
|
||||||
|
*/
|
||||||
|
template<typename E>
|
||||||
|
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator^(E lhs, E rhs)
|
||||||
|
{
|
||||||
|
return Flags<E>(lhs) ^ rhs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ namespace Nz
|
||||||
static inline bool Convert(PixelFormatType srcFormat, PixelFormatType dstFormat, const void* src, void* dst);
|
static inline bool Convert(PixelFormatType srcFormat, PixelFormatType dstFormat, const void* src, void* dst);
|
||||||
static inline bool Convert(PixelFormatType srcFormat, PixelFormatType dstFormat, const void* start, const void* end, void* dst);
|
static inline bool Convert(PixelFormatType srcFormat, PixelFormatType dstFormat, const void* start, const void* end, void* dst);
|
||||||
|
|
||||||
static inline bool Flip(PixelFlipping flipping, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst);
|
static bool Flip(PixelFlipping flipping, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst);
|
||||||
|
|
||||||
static inline UInt8 GetBitsPerPixel(PixelFormatType format);
|
static inline UInt8 GetBitsPerPixel(PixelFormatType format);
|
||||||
static inline PixelFormatContent GetContent(PixelFormatType format);
|
static inline PixelFormatContent GetContent(PixelFormatType format);
|
||||||
|
|
|
||||||
|
|
@ -227,102 +227,6 @@ namespace Nz
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool PixelFormat::Flip(PixelFlipping flipping, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst)
|
|
||||||
{
|
|
||||||
#if NAZARA_UTILITY_SAFE
|
|
||||||
if (!IsValid(format))
|
|
||||||
{
|
|
||||||
NazaraError("Invalid pixel format");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
auto it = s_flipFunctions[flipping].find(format);
|
|
||||||
if (it != s_flipFunctions[flipping].end())
|
|
||||||
it->second(width, height, depth, reinterpret_cast<const UInt8*>(src), reinterpret_cast<UInt8*>(dst));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Flipping générique
|
|
||||||
|
|
||||||
#if NAZARA_UTILITY_SAFE
|
|
||||||
if (IsCompressed(format))
|
|
||||||
{
|
|
||||||
NazaraError("No function to flip compressed format");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
UInt8 bpp = GetBytesPerPixel(format);
|
|
||||||
unsigned int lineStride = width*bpp;
|
|
||||||
switch (flipping)
|
|
||||||
{
|
|
||||||
case PixelFlipping_Horizontally:
|
|
||||||
{
|
|
||||||
if (src == dst)
|
|
||||||
{
|
|
||||||
for (unsigned int z = 0; z < depth; ++z)
|
|
||||||
{
|
|
||||||
UInt8* ptr = reinterpret_cast<UInt8*>(dst) + width*height*z;
|
|
||||||
for (unsigned int y = 0; y < height/2; ++y)
|
|
||||||
std::swap_ranges(&ptr[y*lineStride], &ptr[(y+1)*lineStride-1], &ptr[(height-y-1)*lineStride]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (unsigned int z = 0; z < depth; ++z)
|
|
||||||
{
|
|
||||||
const UInt8* srcPtr = reinterpret_cast<const UInt8*>(src);
|
|
||||||
UInt8* dstPtr = reinterpret_cast<UInt8*>(dst) + (width-1)*height*depth*bpp;
|
|
||||||
for (unsigned int y = 0; y < height; ++y)
|
|
||||||
{
|
|
||||||
std::memcpy(dstPtr, srcPtr, lineStride);
|
|
||||||
|
|
||||||
srcPtr += lineStride;
|
|
||||||
dstPtr -= lineStride;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case PixelFlipping_Vertically:
|
|
||||||
{
|
|
||||||
if (src == dst)
|
|
||||||
{
|
|
||||||
for (unsigned int z = 0; z < depth; ++z)
|
|
||||||
{
|
|
||||||
UInt8* ptr = reinterpret_cast<UInt8*>(dst) + width*height*z;
|
|
||||||
for (unsigned int y = 0; y < height; ++y)
|
|
||||||
{
|
|
||||||
for (unsigned int x = 0; x < width/2; ++x)
|
|
||||||
std::swap_ranges(&ptr[x*bpp], &ptr[(x+1)*bpp], &ptr[(width-x)*bpp]);
|
|
||||||
|
|
||||||
ptr += lineStride;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (unsigned int z = 0; z < depth; ++z)
|
|
||||||
{
|
|
||||||
UInt8* ptr = reinterpret_cast<UInt8*>(dst) + width*height*z;
|
|
||||||
for (unsigned int y = 0; y < height; ++y)
|
|
||||||
{
|
|
||||||
for (unsigned int x = 0; x < width; ++x)
|
|
||||||
std::memcpy(&ptr[x*bpp], &ptr[(width-x)*bpp], bpp);
|
|
||||||
|
|
||||||
ptr += lineStride;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline UInt8 PixelFormat::GetBitsPerPixel(PixelFormatType format)
|
inline UInt8 PixelFormat::GetBitsPerPixel(PixelFormatType format)
|
||||||
{
|
{
|
||||||
return s_pixelFormatInfos[format].bitsPerPixel;
|
return s_pixelFormatInfos[format].bitsPerPixel;
|
||||||
|
|
|
||||||
|
|
@ -1268,6 +1268,102 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PixelFormat::Flip(PixelFlipping flipping, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst)
|
||||||
|
{
|
||||||
|
#if NAZARA_UTILITY_SAFE
|
||||||
|
if (!IsValid(format))
|
||||||
|
{
|
||||||
|
NazaraError("Invalid pixel format");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
auto it = s_flipFunctions[flipping].find(format);
|
||||||
|
if (it != s_flipFunctions[flipping].end())
|
||||||
|
it->second(width, height, depth, reinterpret_cast<const UInt8*>(src), reinterpret_cast<UInt8*>(dst));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Flipping générique
|
||||||
|
|
||||||
|
#if NAZARA_UTILITY_SAFE
|
||||||
|
if (IsCompressed(format))
|
||||||
|
{
|
||||||
|
NazaraError("No function to flip compressed format");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
UInt8 bpp = GetBytesPerPixel(format);
|
||||||
|
unsigned int lineStride = width*bpp;
|
||||||
|
switch (flipping)
|
||||||
|
{
|
||||||
|
case PixelFlipping_Horizontally:
|
||||||
|
{
|
||||||
|
if (src == dst)
|
||||||
|
{
|
||||||
|
for (unsigned int z = 0; z < depth; ++z)
|
||||||
|
{
|
||||||
|
UInt8* ptr = reinterpret_cast<UInt8*>(dst) + width*height*z;
|
||||||
|
for (unsigned int y = 0; y < height / 2; ++y)
|
||||||
|
std::swap_ranges(&ptr[y*lineStride], &ptr[(y + 1)*lineStride - 1], &ptr[(height - y - 1)*lineStride]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (unsigned int z = 0; z < depth; ++z)
|
||||||
|
{
|
||||||
|
const UInt8* srcPtr = reinterpret_cast<const UInt8*>(src);
|
||||||
|
UInt8* dstPtr = reinterpret_cast<UInt8*>(dst) + (width - 1)*height*depth*bpp;
|
||||||
|
for (unsigned int y = 0; y < height; ++y)
|
||||||
|
{
|
||||||
|
std::memcpy(dstPtr, srcPtr, lineStride);
|
||||||
|
|
||||||
|
srcPtr += lineStride;
|
||||||
|
dstPtr -= lineStride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case PixelFlipping_Vertically:
|
||||||
|
{
|
||||||
|
if (src == dst)
|
||||||
|
{
|
||||||
|
for (unsigned int z = 0; z < depth; ++z)
|
||||||
|
{
|
||||||
|
UInt8* ptr = reinterpret_cast<UInt8*>(dst) + width*height*z;
|
||||||
|
for (unsigned int y = 0; y < height; ++y)
|
||||||
|
{
|
||||||
|
for (unsigned int x = 0; x < width / 2; ++x)
|
||||||
|
std::swap_ranges(&ptr[x*bpp], &ptr[(x + 1)*bpp], &ptr[(width - x)*bpp]);
|
||||||
|
|
||||||
|
ptr += lineStride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (unsigned int z = 0; z < depth; ++z)
|
||||||
|
{
|
||||||
|
UInt8* ptr = reinterpret_cast<UInt8*>(dst) + width*height*z;
|
||||||
|
for (unsigned int y = 0; y < height; ++y)
|
||||||
|
{
|
||||||
|
for (unsigned int x = 0; x < width; ++x)
|
||||||
|
std::memcpy(&ptr[x*bpp], &ptr[(width - x)*bpp], bpp);
|
||||||
|
|
||||||
|
ptr += lineStride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
PixelFormatType PixelFormat::IdentifyFormat(const PixelFormatInfo& info)
|
PixelFormatType PixelFormat::IdentifyFormat(const PixelFormatInfo& info)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i <= PixelFormatType_Max; ++i)
|
for (unsigned int i = 0; i <= PixelFormatType_Max; ++i)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue