]> git.saurik.com Git - wxWidgets.git/blob - tests/image/rawbmp.cpp
proper default for iphone
[wxWidgets.git] / tests / image / rawbmp.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/image/rawbmp.cpp
3 // Purpose: Test for using raw bitmap access classes with wxImage
4 // Author: Vadim Zeitlin
5 // Created: 2008-05-30
6 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifdef wxHAS_RAW_BITMAP
21
22 #ifndef WX_PRECOMP
23 #endif // WX_PRECOMP
24
25 #include "wx/image.h"
26 #include "wx/rawbmp.h"
27
28 namespace
29 {
30 const int WIDTH = 10;
31 const int HEIGHT = 10;
32 }
33
34 #define ASSERT_COL_EQUAL(x, y) \
35 CPPUNIT_ASSERT_EQUAL( (unsigned char)(x), (y) )
36
37 // ----------------------------------------------------------------------------
38 // test class
39 // ----------------------------------------------------------------------------
40
41 class ImageRawTestCase : public CppUnit::TestCase
42 {
43 public:
44 ImageRawTestCase() { }
45
46 private:
47 CPPUNIT_TEST_SUITE( ImageRawTestCase );
48 CPPUNIT_TEST( RGBImage );
49 CPPUNIT_TEST_SUITE_END();
50
51 void RGBImage();
52
53 DECLARE_NO_COPY_CLASS(ImageRawTestCase)
54 };
55
56 CPPUNIT_TEST_SUITE_REGISTRATION( ImageRawTestCase );
57 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ImageRawTestCase, "ImageRawTestCase" );
58
59 void ImageRawTestCase::RGBImage()
60 {
61 // create a check board image
62 wxImage image(WIDTH, HEIGHT);
63
64 wxImagePixelData data(image);
65 wxImagePixelData::Iterator p(data);
66 for ( int y = 0; y < HEIGHT; y++ )
67 {
68 const wxImagePixelData::Iterator rowStart = p;
69
70 for ( int x = 0; x < WIDTH; x++ )
71 {
72 p.Red() =
73 p.Green() =
74 p.Blue() = (x + y) % 2 ? 0 : -1;
75 ++p;
76 }
77
78 p = rowStart;
79 p.OffsetY(data, 1);
80 }
81
82 // test a few pixels
83 ASSERT_COL_EQUAL( 0xff, image.GetRed(0, 0) );
84 ASSERT_COL_EQUAL( 0xff, image.GetBlue(1, 1) );
85 ASSERT_COL_EQUAL( 0, image.GetGreen(0, 1) );
86 ASSERT_COL_EQUAL( 0, image.GetGreen(1, 0) );
87 }
88
89 #endif // wxHAS_RAW_BITMAP