acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
Arduino_G.cpp (6569B)
1 #if !defined(LITTLE_FOOT_PRINT) 2 3 #include "Arduino_G.h" 4 5 /**************************************************************************/ 6 /*! 7 @brief Instatiate a GFX context for graphics! Can only be done by a superclass 8 @param w Display width, in pixels 9 @param h Display height, in pixels 10 */ 11 /**************************************************************************/ 12 Arduino_G::Arduino_G(int16_t w, int16_t h) : WIDTH(w), HEIGHT(h) 13 { 14 } 15 16 // utility functions 17 bool gfx_draw_bitmap_to_framebuffer( 18 uint16_t *from_bitmap, int16_t bitmap_w, int16_t bitmap_h, 19 uint16_t *framebuffer, int16_t x, int16_t y, int16_t framebuffer_w, int16_t framebuffer_h) 20 { 21 int16_t max_X = framebuffer_w - 1; 22 int16_t max_Y = framebuffer_h - 1; 23 if ( 24 ((x + bitmap_w - 1) < 0) || // Outside left 25 ((y + bitmap_h - 1) < 0) || // Outside top 26 (x > max_X) || // Outside right 27 (y > max_Y) // Outside bottom 28 ) 29 { 30 return false; 31 } 32 else 33 { 34 int16_t xskip = 0; 35 if ((y + bitmap_h - 1) > max_Y) 36 { 37 bitmap_h -= (y + bitmap_h - 1) - max_Y; 38 } 39 if (y < 0) 40 { 41 from_bitmap -= y * bitmap_w; 42 bitmap_h += y; 43 y = 0; 44 } 45 if ((x + bitmap_w - 1) > max_X) 46 { 47 xskip = (x + bitmap_w - 1) - max_X; 48 bitmap_w -= xskip; 49 } 50 if (x < 0) 51 { 52 from_bitmap -= x; 53 xskip -= x; 54 bitmap_w += x; 55 x = 0; 56 } 57 58 uint16_t *row = framebuffer; 59 row += y * framebuffer_w; // shift framebuffer to y offset 60 row += x; // shift framebuffer to x offset 61 if (((framebuffer_w & 1) == 0) && ((xskip & 1) == 0) && ((bitmap_w & 1) == 0)) 62 { 63 uint32_t *row2 = (uint32_t *)row; 64 uint32_t *from_bitmap2 = (uint32_t *)from_bitmap; 65 int16_t framebuffer_w2 = framebuffer_w >> 1; 66 int16_t xskip2 = xskip >> 1; 67 int16_t w2 = bitmap_w >> 1; 68 69 int16_t j = bitmap_h; 70 while (j--) 71 { 72 for (int16_t i = 0; i < w2; ++i) 73 { 74 row2[i] = *from_bitmap2++; 75 } 76 from_bitmap2 += xskip2; 77 row2 += framebuffer_w2; 78 } 79 } 80 else 81 { 82 int16_t j = bitmap_h; 83 while (j--) 84 { 85 for (int i = 0; i < bitmap_w; ++i) 86 { 87 row[i] = *from_bitmap++; 88 } 89 from_bitmap += xskip; 90 row += framebuffer_w; 91 } 92 } 93 return true; 94 } 95 } 96 97 bool gfx_draw_bitmap_to_framebuffer_rotate_1( 98 uint16_t *from_bitmap, int16_t bitmap_w, int16_t bitmap_h, 99 uint16_t *framebuffer, int16_t x, int16_t y, int16_t framebuffer_w, int16_t framebuffer_h) 100 { 101 int16_t max_X = framebuffer_w - 1; 102 int16_t max_Y = framebuffer_h - 1; 103 if ( 104 ((x + bitmap_w - 1) < 0) || // Outside left 105 ((y + bitmap_h - 1) < 0) || // Outside top 106 (x > max_X) || // Outside right 107 (y > max_Y) // Outside bottom 108 ) 109 { 110 return false; 111 } 112 else 113 { 114 int16_t xskip = 0; 115 if ((y + bitmap_h - 1) > max_Y) 116 { 117 bitmap_h -= (y + bitmap_h - 1) - max_Y; 118 } 119 if (y < 0) 120 { 121 from_bitmap -= y * bitmap_w; 122 bitmap_h += y; 123 y = 0; 124 } 125 if ((x + bitmap_w - 1) > max_X) 126 { 127 xskip = (x + bitmap_w - 1) - max_X; 128 bitmap_w -= xskip; 129 } 130 if (x < 0) 131 { 132 from_bitmap -= x; 133 xskip -= x; 134 bitmap_w += x; 135 x = 0; 136 } 137 138 uint16_t *p; 139 int16_t i; 140 for (int16_t j = 0; j < bitmap_h; j++) 141 { 142 p = framebuffer; 143 p += (x * framebuffer_h); // shift framebuffer to y offset 144 p += (framebuffer_h - y - j); // shift framebuffer to x offset 145 146 i = bitmap_w; 147 while (i--) 148 { 149 *p = *from_bitmap++; 150 p += framebuffer_h; 151 } 152 from_bitmap += xskip; 153 } 154 return true; 155 } 156 } 157 158 bool gfx_draw_bitmap_to_framebuffer_rotate_2( 159 uint16_t *from_bitmap, int16_t bitmap_w, int16_t bitmap_h, 160 uint16_t *framebuffer, int16_t x, int16_t y, int16_t framebuffer_w, int16_t framebuffer_h) 161 { 162 int16_t max_X = framebuffer_w - 1; 163 int16_t max_Y = framebuffer_h - 1; 164 if ( 165 ((x + bitmap_w - 1) < 0) || // Outside left 166 ((y + bitmap_h - 1) < 0) || // Outside top 167 (x > max_X) || // Outside right 168 (y > max_Y) // Outside bottom 169 ) 170 { 171 return false; 172 } 173 else 174 { 175 int16_t xskip = 0; 176 if ((y + bitmap_h - 1) > max_Y) 177 { 178 bitmap_h -= (y + bitmap_h - 1) - max_Y; 179 } 180 if (y < 0) 181 { 182 from_bitmap -= y * bitmap_w; 183 bitmap_h += y; 184 y = 0; 185 } 186 if ((x + bitmap_w - 1) > max_X) 187 { 188 xskip = (x + bitmap_w - 1) - max_X; 189 bitmap_w -= xskip; 190 } 191 if (x < 0) 192 { 193 from_bitmap -= x; 194 xskip -= x; 195 bitmap_w += x; 196 x = 0; 197 } 198 199 uint16_t *row = framebuffer; 200 row += (max_Y - y) * framebuffer_w; // shift framebuffer to y offset 201 row += framebuffer_w - x - bitmap_w; // shift framebuffer to x offset 202 int16_t i; 203 int16_t j = bitmap_h; 204 while (j--) 205 { 206 i = bitmap_w; 207 while (i--) 208 { 209 row[i] = *from_bitmap++; 210 } 211 from_bitmap += xskip; 212 row -= framebuffer_w; 213 } 214 return true; 215 } 216 } 217 218 bool gfx_draw_bitmap_to_framebuffer_rotate_3( 219 uint16_t *from_bitmap, int16_t bitmap_w, int16_t bitmap_h, 220 uint16_t *framebuffer, int16_t x, int16_t y, int16_t framebuffer_w, int16_t framebuffer_h) 221 { 222 int16_t max_X = framebuffer_w - 1; 223 int16_t max_Y = framebuffer_h - 1; 224 if ( 225 ((x + bitmap_w - 1) < 0) || // Outside left 226 ((y + bitmap_h - 1) < 0) || // Outside top 227 (x > max_X) || // Outside right 228 (y > max_Y) // Outside bottom 229 ) 230 { 231 return false; 232 } 233 else 234 { 235 int16_t xskip = 0; 236 if ((y + bitmap_h - 1) > max_Y) 237 { 238 bitmap_h -= (y + bitmap_h - 1) - max_Y; 239 } 240 if (y < 0) 241 { 242 from_bitmap -= y * bitmap_w; 243 bitmap_h += y; 244 y = 0; 245 } 246 if ((x + bitmap_w - 1) > max_X) 247 { 248 xskip = (x + bitmap_w - 1) - max_X; 249 bitmap_w -= xskip; 250 } 251 if (x < 0) 252 { 253 from_bitmap -= x; 254 xskip -= x; 255 bitmap_w += x; 256 x = 0; 257 } 258 259 uint16_t *p; 260 int16_t i; 261 for (int16_t j = 0; j < bitmap_h; j++) 262 { 263 p = framebuffer; 264 p += ((max_X - x) * framebuffer_h); // shift framebuffer to y offset 265 p += y + j; // shift framebuffer to x offset 266 267 i = bitmap_w; 268 while (i--) 269 { 270 *p = *from_bitmap++; 271 p -= framebuffer_h; 272 } 273 from_bitmap += xskip; 274 } 275 return true; 276 } 277 } 278 279 #endif // !defined(LITTLE_FOOT_PRINT)