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.
Dependencies: mbed
Fork of ll14zs by
N5110/Bitmap.h@0:2211174dee1c, 2018-04-26 (annotated)
- Committer:
- ll14zs
- Date:
- Thu Apr 26 11:21:48 2018 +0000
- Revision:
- 0:2211174dee1c
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ll14zs | 0:2211174dee1c | 1 | #ifndef BITMAP_H |
ll14zs | 0:2211174dee1c | 2 | #define BITMAP_H |
ll14zs | 0:2211174dee1c | 3 | |
ll14zs | 0:2211174dee1c | 4 | #include <vector> |
ll14zs | 0:2211174dee1c | 5 | |
ll14zs | 0:2211174dee1c | 6 | // Forward declarations |
ll14zs | 0:2211174dee1c | 7 | class N5110; |
ll14zs | 0:2211174dee1c | 8 | |
ll14zs | 0:2211174dee1c | 9 | /** |
ll14zs | 0:2211174dee1c | 10 | * @brief A black & white bitmap that can be rendered on an N5110 screen |
ll14zs | 0:2211174dee1c | 11 | * @author Alex Valavanis <a.valavanis@leeds.ac.uk> |
ll14zs | 0:2211174dee1c | 12 | * |
ll14zs | 0:2211174dee1c | 13 | * @code |
ll14zs | 0:2211174dee1c | 14 | // First declare the pixel map data using '1' for black, |
ll14zs | 0:2211174dee1c | 15 | // or '0' for white pixels |
ll14zs | 0:2211174dee1c | 16 | static int sprite_data[] = { |
ll14zs | 0:2211174dee1c | 17 | 0,0,1,0,0, |
ll14zs | 0:2211174dee1c | 18 | 0,1,1,1,0, |
ll14zs | 0:2211174dee1c | 19 | 0,0,1,0,0, |
ll14zs | 0:2211174dee1c | 20 | 0,1,1,1,0, |
ll14zs | 0:2211174dee1c | 21 | 1,1,1,1,1, |
ll14zs | 0:2211174dee1c | 22 | 1,1,1,1,1, |
ll14zs | 0:2211174dee1c | 23 | 1,1,0,1,1, |
ll14zs | 0:2211174dee1c | 24 | 1,1,0,1,1 |
ll14zs | 0:2211174dee1c | 25 | }; |
ll14zs | 0:2211174dee1c | 26 | |
ll14zs | 0:2211174dee1c | 27 | // Instantiate the Bitmap object using the data above |
ll14zs | 0:2211174dee1c | 28 | Bitmap sprite(sprite_data, 8, 5); // Specify rows and columns in sprite |
ll14zs | 0:2211174dee1c | 29 | |
ll14zs | 0:2211174dee1c | 30 | // We can render the bitmap wherever we want on the screen |
ll14zs | 0:2211174dee1c | 31 | sprite.render(lcd, 20, 6); // x and y locations for rendering |
ll14zs | 0:2211174dee1c | 32 | sprite.render(lcd, 30, 10); |
ll14zs | 0:2211174dee1c | 33 | |
ll14zs | 0:2211174dee1c | 34 | // We can also print its values to the terminal |
ll14zs | 0:2211174dee1c | 35 | sprite.print(); |
ll14zs | 0:2211174dee1c | 36 | * @endcode |
ll14zs | 0:2211174dee1c | 37 | */ |
ll14zs | 0:2211174dee1c | 38 | class Bitmap |
ll14zs | 0:2211174dee1c | 39 | { |
ll14zs | 0:2211174dee1c | 40 | private: |
ll14zs | 0:2211174dee1c | 41 | /** |
ll14zs | 0:2211174dee1c | 42 | * @brief The contents of the drawing, with pixels stored in row-major order |
ll14zs | 0:2211174dee1c | 43 | * @details '1' represents a black pixel; '0' represents white |
ll14zs | 0:2211174dee1c | 44 | */ |
ll14zs | 0:2211174dee1c | 45 | std::vector<int> _contents; |
ll14zs | 0:2211174dee1c | 46 | |
ll14zs | 0:2211174dee1c | 47 | unsigned int _height; ///< The height of the drawing in pixels |
ll14zs | 0:2211174dee1c | 48 | unsigned int _width; ///< The width of the drawing in pixels |
ll14zs | 0:2211174dee1c | 49 | |
ll14zs | 0:2211174dee1c | 50 | public: |
ll14zs | 0:2211174dee1c | 51 | Bitmap(int const *contents, |
ll14zs | 0:2211174dee1c | 52 | unsigned int const height, |
ll14zs | 0:2211174dee1c | 53 | unsigned int const width); |
ll14zs | 0:2211174dee1c | 54 | |
ll14zs | 0:2211174dee1c | 55 | int get_pixel(unsigned int const row, |
ll14zs | 0:2211174dee1c | 56 | unsigned int const column) const; |
ll14zs | 0:2211174dee1c | 57 | |
ll14zs | 0:2211174dee1c | 58 | void print() const; |
ll14zs | 0:2211174dee1c | 59 | |
ll14zs | 0:2211174dee1c | 60 | void render(N5110 &lcd, |
ll14zs | 0:2211174dee1c | 61 | unsigned int const x0, |
ll14zs | 0:2211174dee1c | 62 | unsigned int const y0) const; |
ll14zs | 0:2211174dee1c | 63 | }; |
ll14zs | 0:2211174dee1c | 64 | |
ll14zs | 0:2211174dee1c | 65 | #endif // BITMAP_H |