diff --git a/include/IImage.h b/include/IImage.h index 20d3d54e..2e090a2a 100644 --- a/include/IImage.h +++ b/include/IImage.h @@ -329,6 +329,12 @@ public: //! Sets a pixel virtual void setPixel(u32 x, u32 y, const SColor &color, bool blend = false ) = 0; + //! Copies this surface into another, if it has the exact same size and format. + /** NOTE: mipmaps are ignored + \return True if it was copied, false otherwise. + */ + virtual bool copyToNoScaling(void *target, u32 width, u32 height, ECOLOR_FORMAT format=ECF_A8R8G8B8, u32 pitch=0) const = 0; + //! Copies the image into the target, scaling the image to fit /** NOTE: mipmaps are ignored */ virtual void copyToScaling(void* target, u32 width, u32 height, ECOLOR_FORMAT format=ECF_A8R8G8B8, u32 pitch=0) =0; diff --git a/source/Irrlicht/CImage.cpp b/source/Irrlicht/CImage.cpp index 5d1e9fa1..5c27a77a 100644 --- a/source/Irrlicht/CImage.cpp +++ b/source/Irrlicht/CImage.cpp @@ -173,6 +173,50 @@ void CImage::copyToWithAlpha(IImage* target, const core::position2d& pos, c } +//! copies this surface into another, if it has the exact same size and format. +bool CImage::copyToNoScaling(void *target, u32 width, u32 height, ECOLOR_FORMAT format, u32 pitch) const +{ + if (IImage::isCompressedFormat(Format)) + { + os::Printer::log("IImage::copyToNoScaling method doesn't work with compressed images.", ELL_WARNING); + return false; + } + + if (!target || !width || !height || !Size.Width || !Size.Height) + return false; + + const u32 bpp=getBitsPerPixelFromFormat(format)/8; + if (0==pitch) + pitch = width*bpp; + + if (!(Format==format && Size.Width==width && Size.Height==height)) + return false; + + if (pitch==Pitch) + { + memcpy(target, Data, (size_t)height*pitch); + } + else + { + u8* tgtpos = (u8*) target; + u8* srcpos = Data; + const u32 bwidth = width*bpp; + const u32 rest = pitch-bwidth; + for (u32 y=0; y