Fixed pixel flipping (ex:horizontal was vertical)

Former-commit-id: 8fb8e6949ae1d2c3d53e42b979f1716e25d3bba9
This commit is contained in:
Lynix
2013-03-22 11:14:11 +01:00
parent ccea00b12e
commit 5390bd49f0
2 changed files with 47 additions and 47 deletions

View File

@@ -98,6 +98,35 @@ inline bool NzPixelFormat::Flip(nzPixelFlipping flipping, nzPixelFormat format,
switch (flipping)
{
case nzPixelFlipping_Horizontally:
{
if (src == dst)
{
for (unsigned int z = 0; z < depth; ++z)
{
nzUInt8* ptr = reinterpret_cast<nzUInt8*>(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 nzUInt8* srcPtr = reinterpret_cast<const nzUInt8*>(src);
nzUInt8* dstPtr = reinterpret_cast<nzUInt8*>(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 nzPixelFlipping_Vertically:
{
if (src == dst)
{
@@ -129,35 +158,6 @@ inline bool NzPixelFormat::Flip(nzPixelFlipping flipping, nzPixelFormat format,
}
break;
}
case nzPixelFlipping_Vertically:
{
if (src == dst)
{
for (unsigned int z = 0; z < depth; ++z)
{
nzUInt8* ptr = reinterpret_cast<nzUInt8*>(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 nzUInt8* srcPtr = reinterpret_cast<const nzUInt8*>(src);
nzUInt8* dstPtr = reinterpret_cast<nzUInt8*>(dst) + (width-1)*height*depth*bpp;
for (unsigned int y = 0; y < height; ++y)
{
std::memcpy(dstPtr, srcPtr, lineStride);
srcPtr += lineStride;
dstPtr -= lineStride;
}
}
}
break;
}
}
}