Du Xianjie 201089059

Dependencies:   mbed FXOS8700Q

Committer:
VivianDu
Date:
Mon May 06 04:25:09 2019 +0000
Revision:
13:9a6aff771774
Parent:
12:5846e92948ad
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
VivianDu 12:5846e92948ad 1 /** Bitmap Class
VivianDu 2:b891a5841ee2 2 * @brief Does nothing useful
VivianDu 2:b891a5841ee2 3 * @author Du Xianjie
VivianDu 2:b891a5841ee2 4 * @date May, 2019
VivianDu 2:b891a5841ee2 5 */
VivianDu 0:bc1d36f5f772 6 #ifndef BITMAP_H
VivianDu 0:bc1d36f5f772 7 #define BITMAP_H
VivianDu 0:bc1d36f5f772 8
VivianDu 0:bc1d36f5f772 9 #include <vector>
VivianDu 0:bc1d36f5f772 10
VivianDu 0:bc1d36f5f772 11 // Forward declarations
VivianDu 0:bc1d36f5f772 12 class N5110;
VivianDu 0:bc1d36f5f772 13
VivianDu 0:bc1d36f5f772 14 /**
VivianDu 0:bc1d36f5f772 15 * @brief A black & white bitmap that can be rendered on an N5110 screen
VivianDu 0:bc1d36f5f772 16 * @author Alex Valavanis <a.valavanis@leeds.ac.uk>
VivianDu 0:bc1d36f5f772 17 *
VivianDu 0:bc1d36f5f772 18 * @code
VivianDu 0:bc1d36f5f772 19 // First declare the pixel map data using '1' for black,
VivianDu 0:bc1d36f5f772 20 // or '0' for white pixels
VivianDu 0:bc1d36f5f772 21 static int sprite_data[] = {
VivianDu 0:bc1d36f5f772 22 0,0,1,0,0,
VivianDu 0:bc1d36f5f772 23 0,1,1,1,0,
VivianDu 0:bc1d36f5f772 24 0,0,1,0,0,
VivianDu 0:bc1d36f5f772 25 0,1,1,1,0,
VivianDu 0:bc1d36f5f772 26 1,1,1,1,1,
VivianDu 0:bc1d36f5f772 27 1,1,1,1,1,
VivianDu 0:bc1d36f5f772 28 1,1,0,1,1,
VivianDu 0:bc1d36f5f772 29 1,1,0,1,1
VivianDu 0:bc1d36f5f772 30 };
VivianDu 0:bc1d36f5f772 31
VivianDu 0:bc1d36f5f772 32 // Instantiate the Bitmap object using the data above
VivianDu 0:bc1d36f5f772 33 Bitmap sprite(sprite_data, 8, 5); // Specify rows and columns in sprite
VivianDu 0:bc1d36f5f772 34
VivianDu 0:bc1d36f5f772 35 // We can render the bitmap wherever we want on the screen
VivianDu 0:bc1d36f5f772 36 sprite.render(lcd, 20, 6); // x and y locations for rendering
VivianDu 0:bc1d36f5f772 37 sprite.render(lcd, 30, 10);
VivianDu 0:bc1d36f5f772 38
VivianDu 0:bc1d36f5f772 39 // We can also print its values to the terminal
VivianDu 0:bc1d36f5f772 40 sprite.print();
VivianDu 0:bc1d36f5f772 41 * @endcode
VivianDu 0:bc1d36f5f772 42 */
VivianDu 0:bc1d36f5f772 43 class Bitmap
VivianDu 0:bc1d36f5f772 44 {
VivianDu 0:bc1d36f5f772 45 private:
VivianDu 0:bc1d36f5f772 46 /**
VivianDu 0:bc1d36f5f772 47 * @brief The contents of the drawing, with pixels stored in row-major order
VivianDu 0:bc1d36f5f772 48 * @details '1' represents a black pixel; '0' represents white
VivianDu 0:bc1d36f5f772 49 */
VivianDu 0:bc1d36f5f772 50 std::vector<int> _contents;
VivianDu 0:bc1d36f5f772 51
VivianDu 0:bc1d36f5f772 52 unsigned int _height; ///< The height of the drawing in pixels
VivianDu 0:bc1d36f5f772 53 unsigned int _width; ///< The width of the drawing in pixels
VivianDu 0:bc1d36f5f772 54
VivianDu 0:bc1d36f5f772 55 public:
VivianDu 0:bc1d36f5f772 56 Bitmap(int const *contents,
VivianDu 0:bc1d36f5f772 57 unsigned int const height,
VivianDu 0:bc1d36f5f772 58 unsigned int const width);
VivianDu 0:bc1d36f5f772 59
VivianDu 0:bc1d36f5f772 60 int get_pixel(unsigned int const row,
VivianDu 0:bc1d36f5f772 61 unsigned int const column) const;
VivianDu 0:bc1d36f5f772 62
VivianDu 0:bc1d36f5f772 63 void print() const;
VivianDu 0:bc1d36f5f772 64
VivianDu 0:bc1d36f5f772 65 void render(N5110 &lcd,
VivianDu 0:bc1d36f5f772 66 unsigned int const x0,
VivianDu 0:bc1d36f5f772 67 unsigned int const y0) const;
VivianDu 0:bc1d36f5f772 68 };
VivianDu 0:bc1d36f5f772 69
VivianDu 0:bc1d36f5f772 70 #endif // BITMAP_H