From fc3762b5fcc2a9fea2ea53702e2b943d9e3c3cc7 Mon Sep 17 00:00:00 2001 From: Francesco Montorsi Date: Fri, 9 Jan 2009 15:35:59 +0000 Subject: [PATCH] add wxImage::Clear (patch by troelsk); closes #10141 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57946 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/image.h | 3 +++ interface/wx/image.h | 10 +++++++++- samples/console/console.cpp | 6 ++---- src/common/image.cpp | 13 ++++++++++--- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/include/wx/image.h b/include/wx/image.h index 84dcd3934d..fd76956841 100644 --- a/include/wx/image.h +++ b/include/wx/image.h @@ -240,6 +240,9 @@ public: bool Create( char** xpmData ) { return Create(const_cast(xpmData)); } #endif void Destroy(); + + // initialize the image data with zeroes + void Clear(unsigned char value = 0); // creates an identical copy of the image (the = operator // just raises the ref count) diff --git a/interface/wx/image.h b/interface/wx/image.h index 1bc3e71e6f..8c9208bf35 100644 --- a/interface/wx/image.h +++ b/interface/wx/image.h @@ -566,12 +566,20 @@ public: @param height The height of the image in pixels. @param clear - If @true, initialize the image data with zeros. + If @true, initialize the image data with zeroes. @return @true if the call succeeded, @false otherwise. */ bool Create(int width, int height, bool clear = true); + /** + Initialize the image data with zeroes (the default) or with the + byte value given as @a value. + + @since 2.9.0 + */ + void Clear(unsigned char value = 0); + /** Destroys the image data. */ diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 3858725560..134caa9449 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -50,7 +50,7 @@ // what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single // test, define it to 1 to do all tests. -#define TEST_ALL 1 +#define TEST_ALL 0 #if TEST_ALL @@ -89,7 +89,7 @@ #define TEST_WCHAR #define TEST_ZIP #else // #if TEST_ALL - #define TEST_EXECUTE + #define TEST_FTP #endif // some tests are interactive, define this to run them @@ -2405,8 +2405,6 @@ static void TestSocketClient() #include "wx/protocol/ftp.h" -static wxFTP ftp; - #define FTP_ANONYMOUS #ifdef FTP_ANONYMOUS diff --git a/src/common/image.cpp b/src/common/image.cpp index ba344445ef..b3883e6a49 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -195,13 +195,15 @@ bool wxImage::Create( int width, int height, bool clear ) return false; } - if (clear) - memset(M_IMGDATA->m_data, 0, width*height*3); - M_IMGDATA->m_width = width; M_IMGDATA->m_height = height; M_IMGDATA->m_ok = true; + if (clear) + { + Clear(); + } + return true; } @@ -246,6 +248,11 @@ void wxImage::Destroy() UnRef(); } +void wxImage::Clear(unsigned char value) +{ + memset(M_IMGDATA->m_data, value, M_IMGDATA->m_width*M_IMGDATA->m_height*3); +} + wxObjectRefData* wxImage::CreateRefData() const { return new wxImageRefData; -- 2.45.2