Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
N5110/Bitmap.h@0:92b180c8d407, 2021-01-05 (annotated)
- Committer:
- jamesheavey
- Date:
- Tue Jan 05 01:14:11 2021 +0000
- Revision:
- 0:92b180c8d407
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jamesheavey | 0:92b180c8d407 | 1 | #ifndef BITMAP_H |
jamesheavey | 0:92b180c8d407 | 2 | #define BITMAP_H |
jamesheavey | 0:92b180c8d407 | 3 | |
jamesheavey | 0:92b180c8d407 | 4 | #include <vector> |
jamesheavey | 0:92b180c8d407 | 5 | |
jamesheavey | 0:92b180c8d407 | 6 | // Forward declarations |
jamesheavey | 0:92b180c8d407 | 7 | class N5110; |
jamesheavey | 0:92b180c8d407 | 8 | |
jamesheavey | 0:92b180c8d407 | 9 | /** |
jamesheavey | 0:92b180c8d407 | 10 | * @brief A black & white bitmap that can be rendered on an N5110 screen |
jamesheavey | 0:92b180c8d407 | 11 | * @author Alex Valavanis <a.valavanis@leeds.ac.uk> |
jamesheavey | 0:92b180c8d407 | 12 | * |
jamesheavey | 0:92b180c8d407 | 13 | * @code |
jamesheavey | 0:92b180c8d407 | 14 | // First declare the pixel map data using '1' for black, |
jamesheavey | 0:92b180c8d407 | 15 | // or '0' for white pixels |
jamesheavey | 0:92b180c8d407 | 16 | static int sprite_data[] = { |
jamesheavey | 0:92b180c8d407 | 17 | 0,0,1,0,0, |
jamesheavey | 0:92b180c8d407 | 18 | 0,1,1,1,0, |
jamesheavey | 0:92b180c8d407 | 19 | 0,0,1,0,0, |
jamesheavey | 0:92b180c8d407 | 20 | 0,1,1,1,0, |
jamesheavey | 0:92b180c8d407 | 21 | 1,1,1,1,1, |
jamesheavey | 0:92b180c8d407 | 22 | 1,1,1,1,1, |
jamesheavey | 0:92b180c8d407 | 23 | 1,1,0,1,1, |
jamesheavey | 0:92b180c8d407 | 24 | 1,1,0,1,1 |
jamesheavey | 0:92b180c8d407 | 25 | }; |
jamesheavey | 0:92b180c8d407 | 26 | |
jamesheavey | 0:92b180c8d407 | 27 | // Instantiate the Bitmap object using the data above |
jamesheavey | 0:92b180c8d407 | 28 | Bitmap sprite(sprite_data, 8, 5); // Specify rows and columns in sprite |
jamesheavey | 0:92b180c8d407 | 29 | |
jamesheavey | 0:92b180c8d407 | 30 | // We can render the bitmap wherever we want on the screen |
jamesheavey | 0:92b180c8d407 | 31 | sprite.render(lcd, 20, 6); // x and y locations for rendering |
jamesheavey | 0:92b180c8d407 | 32 | sprite.render(lcd, 30, 10); |
jamesheavey | 0:92b180c8d407 | 33 | |
jamesheavey | 0:92b180c8d407 | 34 | // We can also print its values to the terminal |
jamesheavey | 0:92b180c8d407 | 35 | sprite.print(); |
jamesheavey | 0:92b180c8d407 | 36 | * @endcode |
jamesheavey | 0:92b180c8d407 | 37 | */ |
jamesheavey | 0:92b180c8d407 | 38 | class Bitmap |
jamesheavey | 0:92b180c8d407 | 39 | { |
jamesheavey | 0:92b180c8d407 | 40 | private: |
jamesheavey | 0:92b180c8d407 | 41 | /** |
jamesheavey | 0:92b180c8d407 | 42 | * @brief The contents of the drawing, with pixels stored in row-major order |
jamesheavey | 0:92b180c8d407 | 43 | * @details '1' represents a black pixel; '0' represents white |
jamesheavey | 0:92b180c8d407 | 44 | */ |
jamesheavey | 0:92b180c8d407 | 45 | std::vector<int> _contents; |
jamesheavey | 0:92b180c8d407 | 46 | |
jamesheavey | 0:92b180c8d407 | 47 | unsigned int _height; ///< The height of the drawing in pixels |
jamesheavey | 0:92b180c8d407 | 48 | unsigned int _width; ///< The width of the drawing in pixels |
jamesheavey | 0:92b180c8d407 | 49 | |
jamesheavey | 0:92b180c8d407 | 50 | public: |
jamesheavey | 0:92b180c8d407 | 51 | Bitmap(int const *contents, |
jamesheavey | 0:92b180c8d407 | 52 | unsigned int const height, |
jamesheavey | 0:92b180c8d407 | 53 | unsigned int const width); |
jamesheavey | 0:92b180c8d407 | 54 | |
jamesheavey | 0:92b180c8d407 | 55 | int get_pixel(unsigned int const row, |
jamesheavey | 0:92b180c8d407 | 56 | unsigned int const column) const; |
jamesheavey | 0:92b180c8d407 | 57 | |
jamesheavey | 0:92b180c8d407 | 58 | void print() const; |
jamesheavey | 0:92b180c8d407 | 59 | |
jamesheavey | 0:92b180c8d407 | 60 | void render(N5110 &lcd, |
jamesheavey | 0:92b180c8d407 | 61 | unsigned int const x0, |
jamesheavey | 0:92b180c8d407 | 62 | unsigned int const y0) const; |
jamesheavey | 0:92b180c8d407 | 63 | }; |
jamesheavey | 0:92b180c8d407 | 64 | |
jamesheavey | 0:92b180c8d407 | 65 | #endif // BITMAP_H |