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