mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-18 06:55:48 +03:00
Added cImage::Crop.
Some minor fixes in cImage and cTexture.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <eepp/base.hpp>
|
||||
|
||||
#include <eepp/math/size.hpp>
|
||||
#include <eepp/math/rect.hpp>
|
||||
using namespace EE::Math;
|
||||
|
||||
#include <eepp/system/colors.hpp>
|
||||
@@ -152,6 +153,9 @@ class EE_API cImage {
|
||||
/** Create a thumnail of the image */
|
||||
cImage * Thumbnail( const Uint32& maxWidth, const Uint32& maxHeight, EE_RESAMPLER_FILTER filter = RESAMPLER_LANCZOS4 );
|
||||
|
||||
/** Creates a cropped image from the current image */
|
||||
cImage * Crop( eeRecti rect );
|
||||
|
||||
/** Set as true if you dont want to free the image data in the cImage destruction ( false as default ). */
|
||||
void AvoidFreeImage( const bool& AvoidFree );
|
||||
|
||||
|
||||
@@ -77,7 +77,10 @@ class EE_API cTexture : public cImage, private NonCopyable {
|
||||
void FillWithColor( const eeColorA& Color );
|
||||
|
||||
/** Resize the texture */
|
||||
void Resize( const Uint32& newWidth, const Uint32& newHeight );
|
||||
void Resize( const Uint32& newWidth, const Uint32& newHeight, EE_RESAMPLER_FILTER filter = RESAMPLER_LANCZOS4 );
|
||||
|
||||
/** Scale the texture */
|
||||
void Scale( const eeFloat& scale, EE_RESAMPLER_FILTER filter = RESAMPLER_LANCZOS4 );
|
||||
|
||||
/** Copy an image inside the texture */
|
||||
void CopyImage( cImage * image, const Uint32& x, const Uint32& y );
|
||||
|
||||
@@ -611,13 +611,31 @@ cImage * cImage::Thumbnail( const Uint32& maxWidth, const Uint32& maxHeight, EE_
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cImage * cImage::Crop( eeRecti rect ) {
|
||||
if ( rect.Left >= 0 && rect.Right <= (Int32)mWidth && rect.Top >= 0 && rect.Bottom <= (Int32)mHeight ) {
|
||||
cImage * img = eeNew( cImage, ( rect.Size().Width(), rect.Size().Height(), mChannels ) );
|
||||
|
||||
// Copy per row
|
||||
for ( eeUint ty = 0; ty < img->mHeight; ty++ ) {
|
||||
Uint8 * pDst = &img->mPixels[ ( ty * img->mWidth ) * mChannels ];
|
||||
const Uint8 * pSrc = &mPixels[ ( rect.Left + ( ( ty + rect.Top ) * mWidth ) ) * mChannels ];
|
||||
|
||||
memcpy( pDst, pSrc, mChannels * img->mWidth );
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void cImage::Flip() {
|
||||
if ( NULL != mPixels ) {
|
||||
cImage tImg( mHeight, mWidth, mChannels );
|
||||
|
||||
for ( eeUint y = 0; y < mHeight; y++ )
|
||||
for ( eeUint x = 0; x < mWidth; x++ )
|
||||
tImg.SetPixel( y, x, GetPixel( x, y ) );
|
||||
tImg.SetPixel( y, x, GetPixel( x, mHeight - 1 - y ) );
|
||||
|
||||
ClearCache();
|
||||
|
||||
|
||||
@@ -262,10 +262,18 @@ void cTexture::FillWithColor( const eeColorA& Color ) {
|
||||
Unlock( false, true );
|
||||
}
|
||||
|
||||
void cTexture::Resize(const Uint32& newWidth, const Uint32& newHeight ) {
|
||||
void cTexture::Resize( const Uint32& newWidth, const Uint32& newHeight , EE_RESAMPLER_FILTER filter ) {
|
||||
Lock();
|
||||
|
||||
cImage::Resize( newWidth, newHeight );
|
||||
cImage::Resize( newWidth, newHeight, filter );
|
||||
|
||||
Unlock( false, true );
|
||||
}
|
||||
|
||||
void cTexture::Scale( const eeFloat& scale, EE_RESAMPLER_FILTER filter ) {
|
||||
Lock();
|
||||
|
||||
cImage::Scale( scale, filter );
|
||||
|
||||
Unlock( false, true );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user