rawbmp.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. // headers
  11. // ----------------------------------------------------------------------------
  12. #include "testprec.h"
  13. #ifdef __BORLANDC__
  14. #pragma hdrstop
  15. #endif
  16. #ifdef wxHAS_RAW_BITMAP
  17. #ifndef WX_PRECOMP
  18. #endif // WX_PRECOMP
  19. #include "wx/image.h"
  20. #include "wx/rawbmp.h"
  21. namespace
  22. {
  23. const int WIDTH = 10;
  24. const int HEIGHT = 10;
  25. }
  26. #define ASSERT_COL_EQUAL(x, y) \
  27. CPPUNIT_ASSERT_EQUAL( (unsigned char)(x), (y) )
  28. // ----------------------------------------------------------------------------
  29. // test class
  30. // ----------------------------------------------------------------------------
  31. class ImageRawTestCase : public CppUnit::TestCase
  32. {
  33. public:
  34. ImageRawTestCase() { }
  35. private:
  36. CPPUNIT_TEST_SUITE( ImageRawTestCase );
  37. CPPUNIT_TEST( RGBImage );
  38. CPPUNIT_TEST_SUITE_END();
  39. void RGBImage();
  40. DECLARE_NO_COPY_CLASS(ImageRawTestCase)
  41. };
  42. CPPUNIT_TEST_SUITE_REGISTRATION( ImageRawTestCase );
  43. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ImageRawTestCase, "ImageRawTestCase" );
  44. void ImageRawTestCase::RGBImage()
  45. {
  46. // create a check board image
  47. wxImage image(WIDTH, HEIGHT);
  48. wxImagePixelData data(image);
  49. wxImagePixelData::Iterator p(data);
  50. for ( int y = 0; y < HEIGHT; y++ )
  51. {
  52. const wxImagePixelData::Iterator rowStart = p;
  53. for ( int x = 0; x < WIDTH; x++ )
  54. {
  55. p.Red() =
  56. p.Green() =
  57. p.Blue() = (x + y) % 2 ? 0 : -1;
  58. ++p;
  59. }
  60. p = rowStart;
  61. p.OffsetY(data, 1);
  62. }
  63. // test a few pixels
  64. ASSERT_COL_EQUAL( 0xff, image.GetRed(0, 0) );
  65. ASSERT_COL_EQUAL( 0xff, image.GetBlue(1, 1) );
  66. ASSERT_COL_EQUAL( 0, image.GetGreen(0, 1) );
  67. ASSERT_COL_EQUAL( 0, image.GetGreen(1, 0) );
  68. }
  69. #endif // wxHAS_RAW_BITMAP