Update for latest nazarautils

This commit is contained in:
SirLynix 2023-09-08 09:10:22 +02:00
parent aef8b01f15
commit 1009b296a1
13 changed files with 174 additions and 189 deletions

View File

@ -129,7 +129,7 @@ namespace Nz
context.FlushBits(); context.FlushBits();
if (context.endianness != Endianness::Unknown && context.endianness != GetPlatformEndianness()) if (context.endianness != Endianness::Unknown && context.endianness != GetPlatformEndianness())
SwapBytes(&value, sizeof(T)); value = ByteSwap(value);
return context.stream->Write(&value, sizeof(T)) == sizeof(T); return context.stream->Write(&value, sizeof(T)) == sizeof(T);
} }
@ -208,7 +208,7 @@ namespace Nz
if (context.stream->Read(value, sizeof(T)) == sizeof(T)) if (context.stream->Read(value, sizeof(T)) == sizeof(T))
{ {
if (context.endianness != Endianness::Unknown && context.endianness != GetPlatformEndianness()) if (context.endianness != Endianness::Unknown && context.endianness != GetPlatformEndianness())
SwapBytes(value, sizeof(T)); *value = ByteSwap(*value);
return true; return true;
} }

View File

@ -10,8 +10,6 @@
#include <NazaraUtils/Prerequisites.hpp> #include <NazaraUtils/Prerequisites.hpp>
#include <Nazara/Network/Config.hpp> #include <Nazara/Network/Config.hpp>
#include <Nazara/Network/Enums.hpp> #include <Nazara/Network/Enums.hpp>
#include <functional>
#include <tuple>
#include <type_traits> #include <type_traits>
namespace Nz namespace Nz

View File

@ -10,21 +10,13 @@ namespace Nz
template<typename T> template<typename T>
std::enable_if_t<std::is_arithmetic<T>::value, T> HostToNet(T value) std::enable_if_t<std::is_arithmetic<T>::value, T> HostToNet(T value)
{ {
#ifdef NAZARA_LITTLE_ENDIAN return HostToBigEndian(value);
return SwapBytes(value);
#else
return value;
#endif
} }
template<typename T> template<typename T>
std::enable_if_t<std::is_arithmetic<T>::value, T> NetToHost(T value) std::enable_if_t<std::is_arithmetic<T>::value, T> NetToHost(T value)
{ {
#ifdef NAZARA_LITTLE_ENDIAN return BigEndianToHost(value);
return SwapBytes(value);
#else
return value;
#endif
} }
} }

View File

@ -369,7 +369,7 @@ Nz::Result<std::shared_ptr<Nz::Animation>, Nz::ResourceLoadingError> LoadAnimati
} }
} }
for (std::size_t jointIndex = identityJoints.FindFirst(); jointIndex != identityJoints.npos; jointIndex = identityJoints.FindNext(jointIndex)) for (std::size_t jointIndex : identityJoints.IterBits())
{ {
const Nz::Joint* joint = parameters.skeleton->GetJoint(jointIndex); const Nz::Joint* joint = parameters.skeleton->GetJoint(jointIndex);

View File

@ -105,12 +105,9 @@ namespace Nz
ByteArray CRC32Hasher::End() ByteArray CRC32Hasher::End()
{ {
m_crc ^= 0xFFFFFFFF; #ifdef NAZARA_BIG_ENDIAN
m_crc = ByteSwap(m_crc ^ 0xFFFFFFFF);
#ifdef NAZARA_LITTLE_ENDIAN #endif
m_crc = SwapBytes(m_crc);
#endif
return ByteArray(reinterpret_cast<UInt8*>(&m_crc), 4); return ByteArray(reinterpret_cast<UInt8*>(&m_crc), 4);
} }

View File

@ -93,10 +93,9 @@ namespace Nz
ByteArray CRC64Hasher::End() ByteArray CRC64Hasher::End()
{ {
#ifdef NAZARA_LITTLE_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&m_crc, sizeof(UInt64)); m_crc = ByteSwap(m_crc);
#endif #endif
return ByteArray(reinterpret_cast<UInt8*>(&m_crc), 8); return ByteArray(reinterpret_cast<UInt8*>(&m_crc), 8);
} }

View File

@ -40,9 +40,9 @@ namespace Nz
UInt16 fletcher = (m_sum2 << 8) | m_sum1; UInt16 fletcher = (m_sum2 << 8) | m_sum1;
#ifdef NAZARA_LITTLE_ENDIAN #ifdef NAZARA_BIG_ENDIAN
fletcher = SwapBytes(fletcher); fletcher = ByteSwap(fletcher);
#endif #endif
return ByteArray(reinterpret_cast<UInt8*>(&fletcher), 2); return ByteArray(reinterpret_cast<UInt8*>(&fletcher), 2);
} }

View File

@ -295,21 +295,21 @@ namespace Nz
Graphics* graphics = Graphics::Instance(); Graphics* graphics = Graphics::Instance();
// Destroy instances at the end of the frame // Destroy instances at the end of the frame
for (std::size_t skeletonInstanceIndex = m_removedSkeletonInstances.FindFirst(); skeletonInstanceIndex != m_removedSkeletonInstances.npos; skeletonInstanceIndex = m_removedSkeletonInstances.FindNext(skeletonInstanceIndex)) for (std::size_t skeletonInstanceIndex : m_removedSkeletonInstances.IterBits())
{ {
renderFrame.PushForRelease(std::move(*m_skeletonInstances.RetrieveFromIndex(skeletonInstanceIndex))); renderFrame.PushForRelease(std::move(*m_skeletonInstances.RetrieveFromIndex(skeletonInstanceIndex)));
m_skeletonInstances.Free(skeletonInstanceIndex); m_skeletonInstances.Free(skeletonInstanceIndex);
} }
m_removedSkeletonInstances.Clear(); m_removedSkeletonInstances.Clear();
for (std::size_t viewerIndex = m_removedViewerInstances.FindFirst(); viewerIndex != m_removedViewerInstances.npos; viewerIndex = m_removedViewerInstances.FindNext(viewerIndex)) for (std::size_t viewerIndex : m_removedViewerInstances.IterBits())
{ {
renderFrame.PushForRelease(std::move(*m_viewerPool.RetrieveFromIndex(viewerIndex))); renderFrame.PushForRelease(std::move(*m_viewerPool.RetrieveFromIndex(viewerIndex)));
m_viewerPool.Free(viewerIndex); m_viewerPool.Free(viewerIndex);
} }
m_removedViewerInstances.Clear(); m_removedViewerInstances.Clear();
for (std::size_t worldInstanceIndex = m_removedWorldInstances.FindFirst(); worldInstanceIndex != m_removedWorldInstances.npos; worldInstanceIndex = m_removedWorldInstances.FindNext(worldInstanceIndex)) for (std::size_t worldInstanceIndex : m_removedWorldInstances.IterBits())
{ {
renderFrame.PushForRelease(std::move(*m_worldInstances.RetrieveFromIndex(worldInstanceIndex))); renderFrame.PushForRelease(std::move(*m_worldInstances.RetrieveFromIndex(worldInstanceIndex)));
m_worldInstances.Free(worldInstanceIndex); m_worldInstances.Free(worldInstanceIndex);
@ -593,7 +593,7 @@ namespace Nz
{ {
FrameGraph frameGraph; FrameGraph frameGraph;
for (std::size_t i = m_shadowCastingLights.FindFirst(); i != m_shadowCastingLights.npos; i = m_shadowCastingLights.FindNext(i)) for (std::size_t i : m_shadowCastingLights.IterBits())
{ {
LightData* lightData = m_lightPool.RetrieveFromIndex(i); LightData* lightData = m_lightPool.RetrieveFromIndex(i);
lightData->shadowData->RegisterToFrameGraph(frameGraph); lightData->shadowData->RegisterToFrameGraph(frameGraph);
@ -617,13 +617,13 @@ namespace Nz
viewerData.depthPrepass->RegisterToFrameGraph(frameGraph, viewerData.depthStencilAttachment); viewerData.depthPrepass->RegisterToFrameGraph(frameGraph, viewerData.depthStencilAttachment);
FramePass& forwardPass = viewerData.forwardPass->RegisterToFrameGraph(frameGraph, viewerData.forwardColorAttachment, viewerData.depthStencilAttachment, viewerData.depthPrepass != nullptr); FramePass& forwardPass = viewerData.forwardPass->RegisterToFrameGraph(frameGraph, viewerData.forwardColorAttachment, viewerData.depthStencilAttachment, viewerData.depthPrepass != nullptr);
for (std::size_t i = m_shadowCastingLights.FindFirst(); i != m_shadowCastingLights.npos; i = m_shadowCastingLights.FindNext(i)) for (std::size_t i : m_shadowCastingLights.IterBits())
{ {
LightData* lightData = m_lightPool.RetrieveFromIndex(i); LightData* lightData = m_lightPool.RetrieveFromIndex(i);
lightData->shadowData->RegisterPassInputs(forwardPass); lightData->shadowData->RegisterPassInputs(forwardPass);
} }
viewerData.debugDrawPass->RegisterToFrameGraph(frameGraph, viewerData.forwardColorAttachment, viewerData.debugColorAttachment); viewerData.debugDrawPass->RegisterToFrameGraph(frameGraph, viewerData.forwardColorAttachment, viewerData.depthStencilAttachment, viewerData.debugColorAttachment);
} }
using ViewerPair = std::pair<const RenderTarget*, const ViewerData*>; using ViewerPair = std::pair<const RenderTarget*, const ViewerData*>;

View File

@ -135,7 +135,7 @@ namespace Nz
for (const Layer& layer : m_layers) for (const Layer& layer : m_layers)
{ {
for (std::size_t tileIndex = layer.enabledTiles.FindFirst(); tileIndex != layer.enabledTiles.npos; tileIndex = layer.enabledTiles.FindNext(tileIndex)) for (std::size_t tileIndex : layer.enabledTiles.IterBits())
{ {
const Tile& tile = m_tiles[tileIndex]; const Tile& tile = m_tiles[tileIndex];

View File

@ -360,7 +360,7 @@ namespace Nz
bool ENetHost::DispatchIncomingCommands(ENetEvent* event) bool ENetHost::DispatchIncomingCommands(ENetEvent* event)
{ {
for (std::size_t bit = m_dispatchQueue.FindFirst(); bit != m_dispatchQueue.npos; bit = m_dispatchQueue.FindNext(bit)) for (std::size_t bit : m_dispatchQueue.IterBits())
{ {
m_dispatchQueue.Reset(bit); m_dispatchQueue.Reset(bit);

View File

@ -31,35 +31,36 @@ namespace Nz
MD2_Header header; MD2_Header header;
if (stream.Read(&header, sizeof(MD2_Header)) != sizeof(MD2_Header)) if (stream.Read(&header, sizeof(MD2_Header)) != sizeof(MD2_Header))
return Err(ResourceLoadingError::Unrecognized); return Err(ResourceLoadingError::Unrecognized);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&header.indent, sizeof(UInt32)); header.ident = ByteSwap(header.ident);
SwapBytes(&header.version, sizeof(UInt32)); header.version = ByteSwap(header.version);
#endif #endif
if (header.ident != md2Ident) if (header.ident != md2Ident)
return Err(ResourceLoadingError::Unrecognized); return Err(ResourceLoadingError::Unrecognized);
if (header.version != 8) if (header.version != 8)
return Err(ResourceLoadingError::Unsupported); return Err(ResourceLoadingError::Unsupported);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&header.skinwidth, sizeof(UInt32)); header.skinwidth = ByteSwap(header.skinwidth);
SwapBytes(&header.skinheight, sizeof(UInt32)); header.skinheight = ByteSwap(header.skinheight);
SwapBytes(&header.framesize, sizeof(UInt32)); header.framesize = ByteSwap(header.framesize);
SwapBytes(&header.num_skins, sizeof(UInt32)); header.num_skins = ByteSwap(header.num_skins);
SwapBytes(&header.num_vertices, sizeof(UInt32)); header.num_vertices = ByteSwap(header.num_vertices);
SwapBytes(&header.num_st, sizeof(UInt32)); header.num_st = ByteSwap(header.num_st);
SwapBytes(&header.num_tris, sizeof(UInt32)); header.num_tris = ByteSwap(header.num_tris);
SwapBytes(&header.num_glcmds, sizeof(UInt32)); header.num_glcmds = ByteSwap(header.num_glcmds);
SwapBytes(&header.num_frames, sizeof(UInt32)); header.num_frames = ByteSwap(header.num_frames);
SwapBytes(&header.offset_skins, sizeof(UInt32)); header.offset_skins = ByteSwap(header.offset_skins);
SwapBytes(&header.offset_st, sizeof(UInt32)); header.offset_st = ByteSwap(header.offset_st);
SwapBytes(&header.offset_tris, sizeof(UInt32)); header.offset_tris = ByteSwap(header.offset_tris);
SwapBytes(&header.offset_frames, sizeof(UInt32)); header.offset_frames = ByteSwap(header.offset_frames);
SwapBytes(&header.offset_glcmds, sizeof(UInt32)); header.offset_glcmds = ByteSwap(header.offset_glcmds);
SwapBytes(&header.offset_end, sizeof(UInt32)); header.offset_end = ByteSwap(header.offset_end);
#endif #endif
if (stream.GetSize() < header.offset_end) if (stream.GetSize() < header.offset_end)
{ {
@ -109,16 +110,14 @@ namespace Nz
for (unsigned int i = 0; i < header.num_tris; ++i) for (unsigned int i = 0; i < header.num_tris; ++i)
{ {
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&triangles[i].vertices[0], sizeof(UInt16)); triangles[i].vertices[0] = ByteSwap(triangles[i].vertices[0]);
SwapBytes(&triangles[i].texCoords[0], sizeof(UInt16)); triangles[i].texCoords[0] = ByteSwap(triangles[i].texCoords[0]);
triangles[i].vertices[1] = ByteSwap(triangles[i].vertices[1]);
SwapBytes(&triangles[i].vertices[1], sizeof(UInt16)); triangles[i].texCoords[1] = ByteSwap(triangles[i].texCoords[1]);
SwapBytes(&triangles[i].texCoords[1], sizeof(UInt16)); triangles[i].vertices[2] = ByteSwap(triangles[i].vertices[2]);
triangles[i].texCoords[2] = ByteSwap(triangles[i].texCoords[2]);
SwapBytes(&triangles[i].vertices[2], sizeof(UInt16)); #endif
SwapBytes(&triangles[i].texCoords[2], sizeof(UInt16));
#endif
// Reverse winding order // Reverse winding order
*index++ = triangles[i].vertices[0]; *index++ = triangles[i].vertices[0];
@ -138,13 +137,13 @@ namespace Nz
stream.SetCursorPos(header.offset_st); stream.SetCursorPos(header.offset_st);
stream.Read(&texCoords[0], header.num_st*sizeof(MD2_TexCoord)); stream.Read(&texCoords[0], header.num_st*sizeof(MD2_TexCoord));
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
for (unsigned int i = 0; i < header.num_st; ++i) for (unsigned int i = 0; i < header.num_st; ++i)
{ {
SwapBytes(&texCoords[i].u, sizeof(Int16)); texCoords[i].u = ByteSwap(texCoords[i].u);
SwapBytes(&texCoords[i].v, sizeof(Int16)); texCoords[i].v = ByteSwap(texCoords[i].v);
} }
#endif #endif
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, header.num_vertices, parameters.vertexBufferFlags, parameters.bufferFactory); std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, header.num_vertices, parameters.vertexBufferFlags, parameters.bufferFactory);
std::shared_ptr<StaticMesh> subMesh = std::make_shared<StaticMesh>(vertexBuffer, indexBuffer); std::shared_ptr<StaticMesh> subMesh = std::make_shared<StaticMesh>(vertexBuffer, indexBuffer);
@ -159,15 +158,15 @@ namespace Nz
stream.Read(nullptr, 16*sizeof(char)); //< Frame name, unused stream.Read(nullptr, 16*sizeof(char)); //< Frame name, unused
stream.Read(vertices.data(), header.num_vertices*sizeof(MD2_Vertex)); stream.Read(vertices.data(), header.num_vertices*sizeof(MD2_Vertex));
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&scale.x, sizeof(float)); scale.x = ByteSwap(scale.x);
SwapBytes(&scale.y, sizeof(float)); scale.y = ByteSwap(scale.y);
SwapBytes(&scale.z, sizeof(float)); scale.z = ByteSwap(scale.z);
SwapBytes(&translate.x, sizeof(float)); translate.x = ByteSwap(translate.x);
SwapBytes(&translate.y, sizeof(float)); translate.y = ByteSwap(translate.y);
SwapBytes(&translate.z, sizeof(float)); translate.z = ByteSwap(translate.z);
#endif #endif
constexpr float ScaleAdjust = 1.f / 27.8f; // Make a 50 Quake 2 units character a 1.8 unit long constexpr float ScaleAdjust = 1.f / 27.8f; // Make a 50 Quake 2 units character a 1.8 unit long

View File

@ -54,20 +54,20 @@ namespace Nz
if (header.manufacturer != 0x0a) if (header.manufacturer != 0x0a)
return Err(ResourceLoadingError::Unrecognized); return Err(ResourceLoadingError::Unrecognized);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
// Les fichiers PCX sont en little endian // PCX files are little-endian
SwapBytes(&header.xmin, sizeof(UInt16)); header.xmin = ByteSwap(header.xmin);
SwapBytes(&header.ymin, sizeof(UInt16)); header.ymin = ByteSwap(header.ymin);
SwapBytes(&header.xmax, sizeof(UInt16)); header.xmax = ByteSwap(header.xmax);
SwapBytes(&header.ymax, sizeof(UInt16)); header.ymax = ByteSwap(header.ymax);
SwapBytes(&header.horzRes, sizeof(UInt16)); header.horzRes = ByteSwap(header.horzRes);
SwapBytes(&header.vertRes, sizeof(UInt16)); header.vertRes = ByteSwap(header.vertRes);
SwapBytes(&header.bytesPerScanLine, sizeof(UInt16)); header.bytesPerScanLine = ByteSwap(header.bytesPerScanLine);
SwapBytes(&header.paletteType, sizeof(UInt16)); header.paletteType = ByteSwap(header.paletteType);
SwapBytes(&header.horzSize, sizeof(UInt16)); header.horzSize = ByteSwap(header.horzSize);
SwapBytes(&header.vertSize, sizeof(UInt16)); header.vertSize = ByteSwap(header.vertSize);
#endif #endif
unsigned int bitCount = header.bitsPerPixel * header.numColorPlanes; unsigned int bitCount = header.bitsPerPixel * header.numColorPlanes;
unsigned int width = header.xmax - header.xmin+1; unsigned int width = header.xmax - header.xmin+1;

View File

@ -95,9 +95,9 @@ namespace Nz
(static_cast<UInt16>(0x1F) << 1) | (static_cast<UInt16>(0x1F) << 1) |
((*start > 0xF) ? 1 : 0); // > 128 ((*start > 0xF) ? 1 : 0); // > 128
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 1; start += 1;
@ -114,9 +114,9 @@ namespace Nz
{ {
*ptr = 0xFFF0 | c8to4(*start); *ptr = 0xFFF0 | c8to4(*start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 1; start += 1;
@ -205,9 +205,9 @@ namespace Nz
(static_cast<UInt16>(c8to5(start[0])) << 1) | (static_cast<UInt16>(c8to5(start[0])) << 1) |
0x1; 0x1;
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 3; start += 3;
@ -242,9 +242,9 @@ namespace Nz
(static_cast<UInt16>(c8to4(start[0])) << 4) | (static_cast<UInt16>(c8to4(start[0])) << 4) |
0x0F; 0x0F;
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 3; start += 3;
@ -362,9 +362,9 @@ namespace Nz
(static_cast<UInt16>(c8to4(start[0])) << 4) | (static_cast<UInt16>(c8to4(start[0])) << 4) |
(static_cast<UInt16>(c8to4(start[3])) << 0); (static_cast<UInt16>(c8to4(start[3])) << 0);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 4; start += 4;
@ -384,9 +384,9 @@ namespace Nz
(static_cast<UInt16>(c8to5(start[0])) << 1) | (static_cast<UInt16>(c8to5(start[0])) << 1) |
((start[3] > 0xF) ? 1 : 0); // > 128 ((start[3] > 0xF) ? 1 : 0); // > 128
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 4; start += 4;
@ -502,9 +502,9 @@ namespace Nz
(l << 1) | (l << 1) |
1; 1;
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 1; start += 1;
@ -541,9 +541,9 @@ namespace Nz
(l << 4) | (l << 4) |
0x0F; 0x0F;
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 1; start += 1;
@ -653,9 +653,9 @@ namespace Nz
*ptr = (l << 11) | (l << 6) | (l << 1) | ((start[1] > 0xF) ? 1 : 0); *ptr = (l << 11) | (l << 6) | (l << 1) | ((start[1] > 0xF) ? 1 : 0);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 2; start += 2;
@ -689,9 +689,9 @@ namespace Nz
*ptr = (l << 12) | (l << 8) | (l << 4) | c8to4(SafeCast<UInt8>(start[1])); *ptr = (l << 12) | (l << 8) | (l << 4) | c8to4(SafeCast<UInt8>(start[1]));
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 2; start += 2;
@ -741,9 +741,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
*dst++ = c4to8(SafeCast<UInt8>(pixel & 0x000F)); *dst++ = c4to8(SafeCast<UInt8>(pixel & 0x000F));
@ -760,9 +760,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
*dst++ = c4to8(SafeCast<UInt8>((pixel & 0x00F0) >> 4)); *dst++ = c4to8(SafeCast<UInt8>((pixel & 0x00F0) >> 4));
*dst++ = c4to8(SafeCast<UInt8>((pixel & 0x0F00) >> 8)); *dst++ = c4to8(SafeCast<UInt8>((pixel & 0x0F00) >> 8));
@ -781,9 +781,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
*dst++ = c4to8(SafeCast<UInt8>((pixel & 0x00F0) >> 4)); *dst++ = c4to8(SafeCast<UInt8>((pixel & 0x00F0) >> 4));
*dst++ = c4to8(SafeCast<UInt8>((pixel & 0x0F00) >> 8)); *dst++ = c4to8(SafeCast<UInt8>((pixel & 0x0F00) >> 8));
@ -803,9 +803,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
UInt16 r = c4to8(SafeCast<UInt8>((pixel & 0xF000) >> 12)); UInt16 r = c4to8(SafeCast<UInt8>((pixel & 0xF000) >> 12));
UInt16 g = c4to8(SafeCast<UInt8>((pixel & 0x0F00) >> 8)); UInt16 g = c4to8(SafeCast<UInt8>((pixel & 0x0F00) >> 8));
@ -826,9 +826,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
UInt16 r = c4to8(SafeCast<UInt8>((pixel & 0xF000) >> 12)); UInt16 r = c4to8(SafeCast<UInt8>((pixel & 0xF000) >> 12));
UInt16 g = c4to8(SafeCast<UInt8>((pixel & 0x0F00) >> 8)); UInt16 g = c4to8(SafeCast<UInt8>((pixel & 0x0F00) >> 8));
@ -851,9 +851,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
UInt16 r = c4to5(SafeCast<UInt8>((pixel & 0xF000) >> 12)); UInt16 r = c4to5(SafeCast<UInt8>((pixel & 0xF000) >> 12));
UInt16 g = c4to5(SafeCast<UInt8>((pixel & 0x0F00) >> 8)); UInt16 g = c4to5(SafeCast<UInt8>((pixel & 0x0F00) >> 8));
@ -862,9 +862,9 @@ namespace Nz
*ptr = (r << 11) | (g << 6) | (b << 1) | ((a > 0x3) ? 1 : 0); *ptr = (r << 11) | (g << 6) | (b << 1) | ((a > 0x3) ? 1 : 0);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 2; start += 2;
@ -880,9 +880,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
*dst++ = c4to8(SafeCast<UInt8>((pixel & 0xF000) >> 12)); *dst++ = c4to8(SafeCast<UInt8>((pixel & 0xF000) >> 12));
*dst++ = c4to8(SafeCast<UInt8>((pixel & 0x0F00) >> 8)); *dst++ = c4to8(SafeCast<UInt8>((pixel & 0x0F00) >> 8));
@ -901,9 +901,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
*dst++ = c4to8(SafeCast<UInt8>((pixel & 0xF000) >> 12)); *dst++ = c4to8(SafeCast<UInt8>((pixel & 0xF000) >> 12));
*dst++ = c4to8(SafeCast<UInt8>((pixel & 0x0F00) >> 8)); *dst++ = c4to8(SafeCast<UInt8>((pixel & 0x0F00) >> 8));
@ -924,9 +924,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
*dst++ = SafeCast<UInt8>((pixel & 0x1) * 0xFF); *dst++ = SafeCast<UInt8>((pixel & 0x1) * 0xFF);
@ -943,9 +943,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
*dst++ = c5to8(SafeCast<UInt8>((pixel & 0x003E) >> 1)); *dst++ = c5to8(SafeCast<UInt8>((pixel & 0x003E) >> 1));
*dst++ = c5to8(SafeCast<UInt8>((pixel & 0x07C0) >> 6)); *dst++ = c5to8(SafeCast<UInt8>((pixel & 0x07C0) >> 6));
@ -964,9 +964,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
*dst++ = c5to8(SafeCast<UInt8>((pixel & 0x003E) >> 1)); *dst++ = c5to8(SafeCast<UInt8>((pixel & 0x003E) >> 1));
*dst++ = c5to8(SafeCast<UInt8>((pixel & 0x07C0) >> 6)); *dst++ = c5to8(SafeCast<UInt8>((pixel & 0x07C0) >> 6));
@ -986,9 +986,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
UInt8 r = c5to8(SafeCast<UInt8>((pixel & 0xF800) >> 11)); UInt8 r = c5to8(SafeCast<UInt8>((pixel & 0xF800) >> 11));
UInt8 g = c5to8(SafeCast<UInt8>((pixel & 0x07C0) >> 6)); UInt8 g = c5to8(SafeCast<UInt8>((pixel & 0x07C0) >> 6));
@ -1009,9 +1009,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
UInt8 r = c5to8(SafeCast<UInt8>((pixel & 0xF800) >> 11)); UInt8 r = c5to8(SafeCast<UInt8>((pixel & 0xF800) >> 11));
UInt8 g = c5to8(SafeCast<UInt8>((pixel & 0x07C0) >> 6)); UInt8 g = c5to8(SafeCast<UInt8>((pixel & 0x07C0) >> 6));
@ -1033,9 +1033,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
*dst++ = c5to8(SafeCast<UInt8>((pixel & 0xF800) >> 11)); *dst++ = c5to8(SafeCast<UInt8>((pixel & 0xF800) >> 11));
*dst++ = c5to8(SafeCast<UInt8>((pixel & 0x07C0) >> 6)); *dst++ = c5to8(SafeCast<UInt8>((pixel & 0x07C0) >> 6));
@ -1055,9 +1055,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
UInt8 r = c5to4(SafeCast<UInt8>((pixel & 0xF800) >> 11)); UInt8 r = c5to4(SafeCast<UInt8>((pixel & 0xF800) >> 11));
UInt8 g = c5to4(SafeCast<UInt8>((pixel & 0x07C0) >> 6)); UInt8 g = c5to4(SafeCast<UInt8>((pixel & 0x07C0) >> 6));
@ -1065,9 +1065,9 @@ namespace Nz
*ptr = (r << 12) | (g << 8) | (b << 4) | ((pixel & 0x1)*0x0F); *ptr = (r << 12) | (g << 8) | (b << 4) | ((pixel & 0x1)*0x0F);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 2; start += 2;
@ -1083,9 +1083,9 @@ namespace Nz
{ {
UInt16 pixel = *reinterpret_cast<const UInt16*>(start); UInt16 pixel = *reinterpret_cast<const UInt16*>(start);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(&pixel, sizeof(UInt16)); pixel = ByteSwap(pixel);
#endif #endif
*dst++ = c5to8(SafeCast<UInt8>((pixel & 0xF800) >> 11)); *dst++ = c5to8(SafeCast<UInt8>((pixel & 0xF800) >> 11));
*dst++ = c5to8(SafeCast<UInt8>((pixel & 0x07C0) >> 6)); *dst++ = c5to8(SafeCast<UInt8>((pixel & 0x07C0) >> 6));
@ -1168,9 +1168,9 @@ namespace Nz
(static_cast<UInt16>(c8to5(start[2])) << 1) | (static_cast<UInt16>(c8to5(start[2])) << 1) |
0x1; 0x1;
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 3; start += 3;
@ -1190,9 +1190,9 @@ namespace Nz
(static_cast<UInt16>(c8to4(start[2])) << 4) | (static_cast<UInt16>(c8to4(start[2])) << 4) |
0x0F; 0x0F;
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 3; start += 3;
@ -1326,9 +1326,9 @@ namespace Nz
(static_cast<UInt16>(c8to5(start[2])) << 1) | (static_cast<UInt16>(c8to5(start[2])) << 1) |
((start[3] > 0xF) ? 1 : 0); // > 128 ((start[3] > 0xF) ? 1 : 0); // > 128
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 4; start += 4;
@ -1363,9 +1363,9 @@ namespace Nz
(static_cast<UInt16>(c8to4(start[2])) << 4) | (static_cast<UInt16>(c8to4(start[2])) << 4) |
(static_cast<UInt16>(c8to4(start[3])) << 0); (static_cast<UInt16>(c8to4(start[3])) << 0);
#ifdef NAZARA_BIG_ENDIAN #ifdef NAZARA_BIG_ENDIAN
SwapBytes(ptr, sizeof(UInt16)); *ptr = ByteSwap(*ptr);
#endif #endif
ptr++; ptr++;
start += 4; start += 4;