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