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