File: rawbmp.cpp

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (89 lines) | stat: -rw-r--r-- 2,277 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
///////////////////////////////////////////////////////////////////////////////
// Name:        tests/image/rawbmp.cpp
// Purpose:     Test for using raw bitmap access classes with wxImage
// Author:      Vadim Zeitlin
// Created:     2008-05-30
// Copyright:   (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence:     wxWindows licence
///////////////////////////////////////////////////////////////////////////////

// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------

#include "testprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifdef wxHAS_RAW_BITMAP

#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.Red() =
            p.Green() =
            p.Blue() = (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) );
}

#endif // wxHAS_RAW_BITMAP