#ifndef BITMAP_H_ #define BITMAP_H_ #include "util.h" #include "font.h" #include #include enum bitmap_rotation { BITMAP_ROT_0DEG, BITMAP_ROT_90DEG, BITMAP_ROT_180DEG, BITMAP_ROT_270DEG, }; /** Bitmap Deskriptor */ struct bitmap { /** Breite des Bitmaps. */ uint8_t width; /** Hoehe des Bitmaps. */ uint8_t height; /** Rotation aller Zeichenoperationen. */ enum bitmap_rotation rotation; /** Datenbereich folgt dem "struct bitmap" unmittelbar. */ uint8_t data[0]; }; /** \brief Bitmap und Container definieren. * * \param _name Name des Bitmap Containers. * * \param _width Breite, in Pixeln. * * \param _height Hoehe, in Pixeln. Muss ein Vielfaches von 8 sein. */ #define DEFINE_BITMAP(_name, _width, _height) \ struct bitmap_container__##_name { \ struct bitmap bitmap; \ uint8_t data[div_round_up((_height), 8) * (_width)]; \ } _name##_container = { \ .bitmap = { \ .width = _width, \ .height = _height, \ .rotation = BITMAP_ROT_0DEG, \ }, \ .data = { }, \ } /** \brief Gibt einen "struct bitmap" pointer auf ein bitmap zurueck. * * \param _name Name des Bitmap Containers. */ #define BITMAP_PTR(_name) (&(_name##_container.bitmap)) /** \brief Gibt einen Pointer auf ein Spaltenbyte zurueck. * * \param bitmap Das Bitmap. * * \param x X Koordinate. * * \param y Y Koordinate. */ #define bitmap_column_byte(bitmap, x, y) \ (&(bitmap)->data[(y) / 8 * (bitmap)->width + (x)]) uint8_t bitmap_width(struct bitmap *bitmap); uint8_t bitmap_height(struct bitmap *bitmap); /** \brief Bitmap loeschen. * * \param bitmap Das Bitmap. */ static inline void bitmap_clear(struct bitmap *bitmap) { memset(bitmap->data, 0, div_round_up(bitmap->height, 8) * bitmap->width); } void bitmap_pixel_write(struct bitmap *bitmap, uint8_t x, uint8_t y, bool on); /** \brief Pixel in Bitmap setzen. * * \param bitmap Das Bitmap. * * \param x X Koordinate des Pixels. * * \param y Y Koordinate des Pixels. */ static inline void bitmap_pixel_set(struct bitmap *bitmap, uint8_t x, uint8_t y) { bitmap_pixel_write(bitmap, x, y, 1); } /** \brief Pixel in Bitmap loeschen. * * \param bitmap Das Bitmap. * * \param x X Koordinate des Pixels. * * \param y Y Koordinate des Pixels. */ static inline void bitmap_pixel_clear(struct bitmap *bitmap, uint8_t x, uint8_t y) { bitmap_pixel_write(bitmap, x, y, 0); } /** \brief Pixelwert aus einem Bitmap auslesen. * * \param bitmap Das Bitmap. * * \param x X Koordinate des Pixels. * * \param y Y Koordinate des Pixels. */ static inline bool bitmap_pixel_get(const struct bitmap *bitmap, uint8_t x, uint8_t y) { uint8_t y_bit = y % 8; const uint8_t b = *bitmap_column_byte(bitmap, x, y); return !!(b & BITMASK8(y_bit)); } void bitmap_area_fill(struct bitmap *bitmap, uint8_t area_x, uint8_t area_y, uint8_t area_width, uint8_t area_height, bool black); void bitmap_draw_line(struct bitmap *bitmap, uint8_t x_from, uint8_t y_from, uint8_t x_to, uint8_t y_to, bool black); void bitmap_draw_xbm(struct bitmap *bitmap, uint8_t x_pos, uint8_t y_pos, const uint8_t __flash *xbm, unsigned int xbm_width, unsigned int xbm_height); void bitmap_draw_char(struct bitmap *bitmap, uint8_t x_pos, uint8_t y_pos, const struct font_descriptor __flash *font_desc, char ascii); void bitmap_draw_string(struct bitmap *bitmap, uint8_t x_pos, uint8_t y_pos, const struct font_descriptor __flash *font_desc, const char __memx *string); #endif /* BITMAP_H_ */