Add IGUIImage::flip to allow flipping/mirroring images.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6301 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2022-03-08 18:44:23 +00:00
parent 3da5987f4b
commit 3ad07543be
4 changed files with 63 additions and 1 deletions

View File

@ -1,5 +1,6 @@
--------------------------
Changes in 1.9 (not yet released)
- Add IGUIImage::flip to flip/mirror images
- IBillboardSceneNode got functions to access meshbuffers. So uv-coordinates can now be modified directly (previously only possible via texture matrix).
- vector3d scalar operator/ and operator/= no longer multiply by the inverse but use the expected division.
Costs some speed, but fixes floating point troubles caused by this optimization (like x/x no longer being 1.0).

View File

@ -74,7 +74,6 @@ public:
//! Returns bits per pixel.
u32 getBitsPerPixel() const
{
return getBitsPerPixelFromFormat(Format);
}
@ -359,6 +358,11 @@ public:
/** NOTE: mipmaps are ignored */
virtual void copyToScalingBoxFilter(IImage* target, s32 bias = 0, bool blend = false) = 0;
//! Flips (mirrors) the image in one or two directions
/** \param topBottom Flip around central x-axis (vertical flipping)
\param leftRight Flip around central y-axis (typical mirror, horizontal flipping) */
virtual void flip(bool topBottom, bool leftRight) = 0;
//! fills the surface with given color
virtual void fill(const SColor &color) =0;

View File

@ -347,6 +347,60 @@ void CImage::fill(const SColor &color)
memset32( Data, c, getImageDataSizeInBytes() );
}
void CImage::flip(bool topBottom, bool leftRight)
{
if ( !topBottom && !leftRight)
return;
const core::dimension2du dim(getDimension());
if ( dim.Width == 0 || dim.Height == 0 )
return;
u8* data = (u8*)getData();
if (!data)
return;
const u32 bpp = getBytesPerPixel();
const u32 pitch = getPitch();
if ( topBottom )
{
for ( u32 i=0; i<dim.Height/2; ++i)
{
// Reverse bottom/top lines
u8* l1 = data+i*pitch;
u8* l2 = data+(dim.Height-1-i)*pitch;
for ( u32 b=0; b<pitch; ++b)
{
irr::u8 dummy = *l1;
*l1 = *l2;
*l2 = dummy;
++l1;
++l2;
}
}
}
if ( leftRight )
{
for ( u32 i=0; i<dim.Height; ++i)
{
// Reverse left/right for each line
u8* l1 = data+i*pitch;
u8* l2 = l1+(dim.Width-1)*bpp;
for ( u32 p=0; p<dim.Width/2; ++p)
{
for ( u32 b=0; b<bpp; ++b)
{
irr::u8 dummy = l1[b];
l1[b] = l2[b];
l2[b] = dummy;
}
l1 += bpp;
l2 -= bpp;
}
}
}
}
//! get a filtered pixel
inline SColor CImage::getPixelBox( s32 x, s32 y, s32 fx, s32 fy, s32 bias ) const

View File

@ -55,6 +55,9 @@ public:
//! copies this surface into another, scaling it to fit, applying a box filter
virtual void copyToScalingBoxFilter(IImage* target, s32 bias = 0, bool blend = false) IRR_OVERRIDE;
//! Flips (mirrors) the image in one or two directions
virtual void flip(bool topBottom, bool leftRight) IRR_OVERRIDE;
//! fills the surface with given color
virtual void fill(const SColor &color) IRR_OVERRIDE;