]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed wxImagePixelData compilation (ticket #3003); added a unit test for it (to be...
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 30 May 2008 19:30:23 +0000 (19:30 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 30 May 2008 19:30:23 +0000 (19:30 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

12 files changed:
docs/changes.txt
include/wx/rawbmp.h
tests/Makefile.in
tests/image/rawbmp.cpp [new file with mode: 0644]
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/test.bkl
tests/test_test_gui.dsp
tests/test_vc7_test_gui.vcproj
tests/test_vc8_test_gui.vcproj

index fdd806b24b3771b387829b004cd85976cbeb2ab8..9e6b8e30c6aceb07d8158b59da24acaf07a5d323 100644 (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:
 
index 9de976c0eaedf497921a1fd6f93d588d00e6f125..df5db7d23e79888b6598259f3f602376fb54cbb9 100644 (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>
 {
index cdc0b755f14b1cfe85b1152b698d38dbda975c17..945554e88f583075cc9c0f4b9044d5d3fefd3cc5 100644 (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
 
diff --git a/tests/image/rawbmp.cpp b/tests/image/rawbmp.cpp
new file mode 100644 (file)
index 0000000..be37a83
--- /dev/null
@@ -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) );
+}
index 232de8819409e2626e5f4d41782e150ca03098e0..5e211db3be546628f9655a4f29ce8ef6d3cdf356 100644 (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
 
index 0d9e1d3186779aa94e3e26f769bcd8ff3c383e8a..920221b1fd53373d215679fb61312a1aa4a49f60 100644 (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) $<
 
index 08d5e1ede0aaddf9ecf980ec16bef38629bd6780..67b4f4e8a7a6a88f2e20217e78feaf79c6247798 100644 (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
 
index ec777b57b1f17886bb9a671ad9e9461df8fa81ed..5093a6e9b23a3889564f8c6c213420827e5ef4e4 100644 (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) $<
 
index 292779bcaca54c905c67ddac86acce5a44641bb0..8fa1ac432fce403dc005ba23f3451a5603398f13 100644 (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
index 55dd1d27d1909eaa238cfc9a9103af855a3ab99a..807fa7ad9413ba3f09cf0abd7c1a5b0b732e5a4d 100644 (file)
@@ -253,6 +253,10 @@ SOURCE=.\geometry\point.cpp
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\image\rawbmp.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\geometry\rect.cpp\r
 # End Source File\r
 # Begin Source File\r
index 99c8d2cd077b4fb31fb45d2bb383ea890053b9fd..9969813b0fd5b57ec6cb76bae93f827d2ef041b5 100644 (file)
                        </File>\r
                        <File\r
                                RelativePath=".\geometry\point.cpp"/>\r
+                       <File\r
+                               RelativePath=".\image\rawbmp.cpp"/>\r
                        <File\r
                                RelativePath=".\geometry\rect.cpp"/>\r
                        <File\r
index 15347d1ebc61edc6b89faad4bccf8f2af7b87573..6a94cea24da19c3b58e3aacf57bb061e2799613e 100644 (file)
                        <File\r
                                RelativePath=".\geometry\point.cpp"\r
                        />\r
+                       <File\r
+                               RelativePath=".\image\rawbmp.cpp"\r
+                       />\r
                        <File\r
                                RelativePath=".\geometry\rect.cpp"\r
                        />\r