mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 12:51:05 +08:00
Added Image::FlipHorizontally and Image::FlipVertically
This commit is contained in:
parent
e509f01180
commit
f5294d5342
@ -252,6 +252,18 @@ public :
|
||||
////////////////////////////////////////////////////////////
|
||||
const Uint8* GetPixelsPtr() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Flip the image horizontally (left <-> right)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void FlipHorizontally();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Flip the image vertically (top <-> bottom)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void FlipVertically();
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -263,4 +263,49 @@ const Uint8* Image::GetPixelsPtr() const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Image::FlipHorizontally()
|
||||
{
|
||||
if (!myPixels.empty())
|
||||
{
|
||||
std::vector<Uint8> before = myPixels;
|
||||
for (unsigned int y = 0; y < myHeight; ++y)
|
||||
{
|
||||
const Uint8* source = &before[y * myWidth * 4];
|
||||
Uint8* dest = &myPixels[(y + 1) * myWidth * 4 - 4];
|
||||
for (unsigned int x = 0; x < myWidth; ++x)
|
||||
{
|
||||
dest[0] = source[0];
|
||||
dest[1] = source[1];
|
||||
dest[2] = source[2];
|
||||
dest[3] = source[3];
|
||||
|
||||
source += 4;
|
||||
dest -= 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Image::FlipVertically()
|
||||
{
|
||||
if (!myPixels.empty())
|
||||
{
|
||||
std::vector<Uint8> before = myPixels;
|
||||
const Uint8* source = &before[myWidth * (myHeight - 1) * 4];
|
||||
Uint8* dest = &myPixels[0];
|
||||
std::size_t rowSize = myWidth * 4;
|
||||
|
||||
for (unsigned int y = 0; y < myHeight; ++y)
|
||||
{
|
||||
std::memcpy(dest, source, rowSize);
|
||||
source -= rowSize;
|
||||
dest += rowSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
Loading…
Reference in New Issue
Block a user