11 const uint8_t *mask, uint8_t frame, uint8_t mask_frame)
13 draw(x, y, bitmap, frame, mask, mask_frame, SPRITE_MASKED);
18 draw(x, y, bitmap, frame, NULL, 0, SPRITE_OVERWRITE);
23 draw(x, y, bitmap, frame, NULL, 0, SPRITE_IS_MASK_ERASE);
28 draw(x, y, bitmap, frame, NULL, 0, SPRITE_IS_MASK);
33 draw(x, y, bitmap, frame, NULL, 0, SPRITE_PLUS_MASK);
38 void SpritesB::draw(int16_t x, int16_t y,
39 const uint8_t *bitmap, uint8_t frame,
40 const uint8_t *mask, uint8_t sprite_frame,
43 unsigned int frame_offset;
48 uint8_t width = pgm_read_byte(bitmap);
49 uint8_t height = pgm_read_byte(++bitmap);
51 if (frame > 0 || sprite_frame > 0) {
52 frame_offset = (width * ( height / 8 + ( height % 8 == 0 ? 0 : 1)));
54 if (drawMode == SPRITE_PLUS_MASK) {
56 }
else if (mask != NULL) {
57 mask += sprite_frame * frame_offset;
59 bitmap += frame * frame_offset;
64 if (drawMode == SPRITE_AUTO_MODE) {
65 drawMode = mask == NULL ? SPRITE_UNMASKED : SPRITE_MASKED;
68 drawBitmap(x, y, bitmap, mask, width, height, drawMode);
71 void SpritesB::drawBitmap(int16_t x, int16_t y,
72 const uint8_t *bitmap,
const uint8_t *mask,
73 uint8_t w, uint8_t h, uint8_t draw_mode)
76 if (x + w <= 0 || x >
WIDTH - 1 || y + h <= 0 || y >
HEIGHT - 1)
84 uint16_t xOffset, ofs;
85 int8_t yOffset = y & 7;
87 uint8_t loop_h, start_h, rendered_width;
89 if (y < 0 && yOffset > 0) {
101 if (x + w >
WIDTH - 1) {
102 rendered_width = ((
WIDTH - x) - xOffset);
104 rendered_width = (w - xOffset);
109 start_h = abs(sRow) - 1;
114 loop_h = h / 8 + (h % 8 > 0 ? 1 : 0);
117 if (sRow + loop_h > (
HEIGHT / 8)) {
118 loop_h = (
HEIGHT / 8) - sRow;
126 ofs = (sRow *
WIDTH) + x + xOffset;
128 uint8_t mul_amt = 1 << yOffset;
130 uint16_t bitmap_data;
132 const uint8_t ofs_step = draw_mode == SPRITE_PLUS_MASK ? 2 : 1;
133 const uint8_t ofs_stride = (w - rendered_width)*ofs_step;
134 const uint16_t initial_bofs = ((start_h * w) + xOffset)*ofs_step;
136 const uint8_t *bofs = bitmap + initial_bofs;
137 const uint8_t *mask_ofs = !mask ? bitmap : mask;
138 mask_ofs += initial_bofs + ofs_step - 1;
140 for (uint8_t a = 0; a < loop_h; a++) {
141 for (uint8_t iCol = 0; iCol < rendered_width; iCol++) {
144 bitmap_data = pgm_read_byte(bofs) * mul_amt;
145 mask_data = ~bitmap_data;
147 if (draw_mode == SPRITE_UNMASKED) {
148 mask_data = ~(0xFF * mul_amt);
149 }
else if (draw_mode == SPRITE_IS_MASK_ERASE) {
152 mask_data = ~(pgm_read_byte(mask_ofs) * mul_amt);
157 data &= (uint8_t)(mask_data);
158 data |= (uint8_t)(bitmap_data);
161 if (yOffset != 0 && sRow < 7) {
162 const size_t index =
static_cast<uint16_t
>(ofs +
WIDTH);
164 data &= (uint8_t)(mask_data >> 8);
165 data |= (uint8_t)(bitmap_data >> 8);
169 mask_ofs += ofs_step;
174 mask_ofs += ofs_stride;
175 ofs +=
WIDTH - rendered_width;