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