2008-05-30 15:30:23 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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
|
|
|
|
|
2008-06-01 14:42:33 -04:00
|
|
|
#ifdef wxHAS_RAW_BITMAP
|
|
|
|
|
2008-05-30 15:30:23 -04:00
|
|
|
#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++ )
|
|
|
|
{
|
2008-07-23 19:23:23 -04:00
|
|
|
p.Red() =
|
|
|
|
p.Green() =
|
|
|
|
p.Blue() = (x + y) % 2 ? 0 : -1;
|
2008-05-30 15:30:23 -04:00
|
|
|
++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) );
|
|
|
|
}
|
2008-06-01 14:42:33 -04:00
|
|
|
|
|
|
|
#endif // wxHAS_RAW_BITMAP
|