From 3ad07543beadb4fa292422bcace54918b00adf7b Mon Sep 17 00:00:00 2001 From: cutealien Date: Tue, 8 Mar 2022 18:44:23 +0000 Subject: [PATCH] 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 --- changes.txt | 1 + include/IImage.h | 6 ++++- source/Irrlicht/CImage.cpp | 54 ++++++++++++++++++++++++++++++++++++++ source/Irrlicht/CImage.h | 3 +++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/changes.txt b/changes.txt index b9b3b27f..91007b75 100644 --- a/changes.txt +++ b/changes.txt @@ -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). diff --git a/include/IImage.h b/include/IImage.h index 92029b2f..b09d3c26 100644 --- a/include/IImage.h +++ b/include/IImage.h @@ -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; diff --git a/source/Irrlicht/CImage.cpp b/source/Irrlicht/CImage.cpp index 753262b7..182623d0 100644 --- a/source/Irrlicht/CImage.cpp +++ b/source/Irrlicht/CImage.cpp @@ -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