fixed wxImagePixelData compilation (ticket #3003); added a unit test for it (to be extended to cover more wxImage methods...)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2008-05-30 19:30:23 +00:00
parent 8aa6162938
commit 3e50a139b4
12 changed files with 126 additions and 7 deletions

View File

@ -270,7 +270,7 @@ All:
wxQueueEvent() replacing wxPostEvent().
- wxString now uses std::[w]string internally by default, meaning that it is
now thread-safe if the standard library provided with your compiler is.
- Added wxCmdLineParser::AddUsageText() (Marcin 'Malcom' Malich)
- Added wxCmdLineParser::AddUsageText() (Marcin 'Malcom' Malich).
All (Unix):
@ -348,6 +348,7 @@ All (GUI):
- Allow having menu separators with ids != wxID_SEPARATOR (Jeff Tupper)
- Fix appending items to sorted wxComboCtrl after creation (Jaakko Salli)
- Don't blit area larger than necessary in wxBufferedDC::UnMask (Liang Jian)
- Fixed wxPixelData<wxImage> compilation (Leonardo Fernandes).
wxGTK:

View File

@ -309,7 +309,7 @@ struct wxPixelDataOut<wxImage>
typedef wxImagePixelFormat PixelFormat;
// the type of the pixel components
typedef typename dummyPixelFormat::ChannelType ChannelType;
typedef typename PixelFormat::ChannelType ChannelType;
// the pixel data we're working with
typedef
@ -405,12 +405,16 @@ struct wxPixelDataOut<wxImage>
// data access
// -----------
// access to invidividual colour components
// access to individual colour components
ChannelType& Red() { return m_pRGB[PixelFormat::RED]; }
ChannelType& Green() { return m_pRGB[PixelFormat::GREEN]; }
ChannelType& Blue() { return m_pRGB[PixelFormat::BLUE]; }
ChannelType& Alpha() { return *m_pAlpha; }
// address the pixel contents directly (always RGB, without alpha)
typename PixelFormat::PixelType& Data()
{ return *(typename PixelFormat::PixelType *)m_pRGB; }
// private: -- see comment in the beginning of the file
// pointer into RGB buffer
@ -425,7 +429,7 @@ struct wxPixelDataOut<wxImage>
{
m_width = image.GetWidth();
m_height = image.GetHeight();
m_stride = Iterator::SizePixel * m_width;
m_stride = Iterator::PixelFormat::SizePixel * m_width;
}
// initializes us with the given region of the specified image
@ -433,7 +437,7 @@ struct wxPixelDataOut<wxImage>
const wxPoint& pt,
const wxSize& sz) : m_image(image), m_pixels(image)
{
m_stride = Iterator::SizePixel * m_width;
m_stride = Iterator::PixelFormat::SizePixel * m_width;
InitRect(pt, sz);
}
@ -442,7 +446,7 @@ struct wxPixelDataOut<wxImage>
wxPixelDataIn(ImageType& image,
const wxRect& rect) : m_image(image), m_pixels(image)
{
m_stride = Iterator::SizePixel * m_width;
m_stride = Iterator::PixelFormat::SizePixel * m_width;
InitRect(rect.GetPosition(), rect.GetSize());
}
@ -675,7 +679,7 @@ struct wxPixelDataOut<wxBitmap>
#endif //wxUSE_GUI
template <class Image, class PixelFormat = wxPixelFormatFor<Image> >
template <class Image, class PixelFormat = typename wxPixelFormatFor<Image>::Format >
class wxPixelData :
public wxPixelDataOut<Image>::template wxPixelDataIn<PixelFormat>
{

View File

@ -117,6 +117,7 @@ TEST_GUI_OBJECTS = \
test_gui_point.o \
test_gui_config.o \
test_gui_textctrltest.o \
test_gui_rawbmp.o \
test_gui_selstoretest.o \
test_gui_clientsize.o \
test_gui_setsize.o
@ -505,6 +506,9 @@ test_gui_config.o: $(srcdir)/config/config.cpp $(TEST_GUI_ODEP)
test_gui_textctrltest.o: $(srcdir)/controls/textctrltest.cpp $(TEST_GUI_ODEP)
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/controls/textctrltest.cpp
test_gui_rawbmp.o: $(srcdir)/image/rawbmp.cpp $(TEST_GUI_ODEP)
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/image/rawbmp.cpp
test_gui_selstoretest.o: $(srcdir)/misc/selstoretest.cpp $(TEST_GUI_ODEP)
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/misc/selstoretest.cpp

84
tests/image/rawbmp.cpp Normal file
View File

@ -0,0 +1,84 @@
///////////////////////////////////////////////////////////////////////////////
// Name: tests/image/rawbmp.cpp
// Purpose: Test for using raw bitmap access classes with wxImage
// Author: Vadim Zeitlin
// Created: 2008-05-30
// RCS-ID: $Id$
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "testprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#endif // WX_PRECOMP
#include "wx/image.h"
#include "wx/rawbmp.h"
namespace
{
const int WIDTH = 10;
const int HEIGHT = 10;
}
#define ASSERT_COL_EQUAL(x, y) \
CPPUNIT_ASSERT_EQUAL( (unsigned char)(x), (y) )
// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------
class ImageRawTestCase : public CppUnit::TestCase
{
public:
ImageRawTestCase() { }
private:
CPPUNIT_TEST_SUITE( ImageRawTestCase );
CPPUNIT_TEST( RGBImage );
CPPUNIT_TEST_SUITE_END();
void RGBImage();
DECLARE_NO_COPY_CLASS(ImageRawTestCase)
};
CPPUNIT_TEST_SUITE_REGISTRATION( ImageRawTestCase );
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ImageRawTestCase, "ImageRawTestCase" );
void ImageRawTestCase::RGBImage()
{
// create a check board image
wxImage image(WIDTH, HEIGHT);
wxImagePixelData data(image);
wxImagePixelData::Iterator p(data);
for ( int y = 0; y < HEIGHT; y++ )
{
const wxImagePixelData::Iterator rowStart = p;
for ( int x = 0; x < WIDTH; x++ )
{
p.Data() = (x + y) % 2 ? 0 : -1;
++p;
}
p = rowStart;
p.OffsetY(data, 1);
}
// test a few pixels
ASSERT_COL_EQUAL( 0xff, image.GetRed(0, 0) );
ASSERT_COL_EQUAL( 0xff, image.GetBlue(1, 1) );
ASSERT_COL_EQUAL( 0, image.GetGreen(0, 1) );
ASSERT_COL_EQUAL( 0, image.GetGreen(1, 0) );
}

View File

@ -104,6 +104,7 @@ TEST_GUI_OBJECTS = \
$(OBJS)\test_gui_point.obj \
$(OBJS)\test_gui_config.obj \
$(OBJS)\test_gui_textctrltest.obj \
$(OBJS)\test_gui_rawbmp.obj \
$(OBJS)\test_gui_selstoretest.obj \
$(OBJS)\test_gui_clientsize.obj \
$(OBJS)\test_gui_setsize.obj
@ -540,6 +541,9 @@ $(OBJS)\test_gui_config.obj: .\config\config.cpp
$(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\controls\textctrltest.cpp
$(OBJS)\test_gui_rawbmp.obj: .\image\rawbmp.cpp
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\image\rawbmp.cpp
$(OBJS)\test_gui_selstoretest.obj: .\misc\selstoretest.cpp
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\misc\selstoretest.cpp

View File

@ -97,6 +97,7 @@ TEST_GUI_OBJECTS = \
$(OBJS)\test_gui_point.o \
$(OBJS)\test_gui_config.o \
$(OBJS)\test_gui_textctrltest.o \
$(OBJS)\test_gui_rawbmp.o \
$(OBJS)\test_gui_selstoretest.o \
$(OBJS)\test_gui_clientsize.o \
$(OBJS)\test_gui_setsize.o
@ -518,6 +519,9 @@ $(OBJS)\test_gui_config.o: ./config/config.cpp
$(OBJS)\test_gui_textctrltest.o: ./controls/textctrltest.cpp
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\test_gui_rawbmp.o: ./image/rawbmp.cpp
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\test_gui_selstoretest.o: ./misc/selstoretest.cpp
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<

View File

@ -100,6 +100,7 @@ TEST_GUI_OBJECTS = \
$(OBJS)\test_gui_point.obj \
$(OBJS)\test_gui_config.obj \
$(OBJS)\test_gui_textctrltest.obj \
$(OBJS)\test_gui_rawbmp.obj \
$(OBJS)\test_gui_selstoretest.obj \
$(OBJS)\test_gui_clientsize.obj \
$(OBJS)\test_gui_setsize.obj
@ -625,6 +626,9 @@ $(OBJS)\test_gui_config.obj: .\config\config.cpp
$(OBJS)\test_gui_textctrltest.obj: .\controls\textctrltest.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\controls\textctrltest.cpp
$(OBJS)\test_gui_rawbmp.obj: .\image\rawbmp.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\image\rawbmp.cpp
$(OBJS)\test_gui_selstoretest.obj: .\misc\selstoretest.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\misc\selstoretest.cpp

View File

@ -309,6 +309,7 @@ TEST_GUI_OBJECTS = &
$(OBJS)\test_gui_point.obj &
$(OBJS)\test_gui_config.obj &
$(OBJS)\test_gui_textctrltest.obj &
$(OBJS)\test_gui_rawbmp.obj &
$(OBJS)\test_gui_selstoretest.obj &
$(OBJS)\test_gui_clientsize.obj &
$(OBJS)\test_gui_setsize.obj
@ -571,6 +572,9 @@ $(OBJS)\test_gui_config.obj : .AUTODEPEND .\config\config.cpp
$(OBJS)\test_gui_textctrltest.obj : .AUTODEPEND .\controls\textctrltest.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
$(OBJS)\test_gui_rawbmp.obj : .AUTODEPEND .\image\rawbmp.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
$(OBJS)\test_gui_selstoretest.obj : .AUTODEPEND .\misc\selstoretest.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<

View File

@ -96,6 +96,7 @@
geometry/point.cpp
config/config.cpp
controls/textctrltest.cpp
image/rawbmp.cpp
misc/selstoretest.cpp
window/clientsize.cpp
window/setsize.cpp

View File

@ -253,6 +253,10 @@ SOURCE=.\geometry\point.cpp
# End Source File
# Begin Source File
SOURCE=.\image\rawbmp.cpp
# End Source File
# Begin Source File
SOURCE=.\geometry\rect.cpp
# End Source File
# Begin Source File

View File

@ -706,6 +706,8 @@
</File>
<File
RelativePath=".\geometry\point.cpp"/>
<File
RelativePath=".\image\rawbmp.cpp"/>
<File
RelativePath=".\geometry\rect.cpp"/>
<File

View File

@ -884,6 +884,9 @@
<File
RelativePath=".\geometry\point.cpp"
/>
<File
RelativePath=".\image\rawbmp.cpp"
/>
<File
RelativePath=".\geometry\rect.cpp"
/>