@@ -62,21 +62,57 @@ void EPaper::update()
6262#ifdef USE_PARTIAL_EPAPER
6363void EPaper::updataPartial (uint16_t x, uint16_t y, uint16_t w, uint16_t h)
6464{
65- uint16_t x0 = x & ~7 ;
66- uint16_t x1 = (x + w + 7 ) & ~7 ;
65+ int32_t bx = x;
66+ int32_t by = y;
67+ int32_t bw = w;
68+ int32_t bh = h;
69+
70+ // Map the rotated coordinate space back to the backing buffer.
71+ switch (rotation & 3 )
72+ {
73+ case 1 :
74+ bx = (int32_t )_width - y - h;
75+ by = x;
76+ bw = h;
77+ bh = w;
78+ break ;
79+ case 2 :
80+ bx = (int32_t )_width - x - w;
81+ by = (int32_t )_height - y - h;
82+ break ;
83+ case 3 :
84+ bx = y;
85+ by = (int32_t )_height - x - w;
86+ bw = h;
87+ bh = w;
88+ break ;
89+ default :
90+ break ;
91+ }
92+
93+ if (bx < 0 ) { bw += bx; bx = 0 ; }
94+ if (by < 0 ) { bh += by; by = 0 ; }
95+ if ((bx + bw) > (int32_t )_width) bw = (int32_t )_width - bx;
96+ if ((by + bh) > (int32_t )_height) bh = (int32_t )_height - by;
97+ if (bw < 1 || bh < 1 ) return ;
98+
99+ uint16_t x0 = (uint16_t )bx & ~7 ;
100+ uint16_t x1 = (uint16_t )(bx + bw + 7 ) & ~7 ;
67101 uint16_t w_aligned = x1 - x0;
102+ uint16_t yy = (uint16_t )by;
103+ uint16_t hh = (uint16_t )bh;
68104
69105 uint16_t stride = _width >> 3 ;
70106 uint16_t win_bytes_per_row = w_aligned >> 3 ;
71107
72- const uint8_t * src0 = _img8 + (y * stride) + (x0 >> 3 );
108+ const uint8_t * src0 = _img8 + (yy * stride) + (x0 >> 3 );
73109
74- size_t win_size = (size_t )win_bytes_per_row * h ;
110+ size_t win_size = (size_t )win_bytes_per_row * hh ;
75111 uint8_t * winbuf = (uint8_t *)malloc (win_size);
76112 if (!winbuf) return ;
77113
78114
79- for (uint16_t row = 0 ; row < h ; row++) {
115+ for (uint16_t row = 0 ; row < hh ; row++) {
80116 memcpy (winbuf + row * win_bytes_per_row,
81117 src0 + row * stride,
82118 win_bytes_per_row);
@@ -85,11 +121,11 @@ void EPaper::updataPartial(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
85121 if (_sleep) { EPD_WAKEUP_PARTIAL (); _sleep = false ; }
86122
87123#ifdef EPD_HORIZONTAL_MIRROR
88- EPD_SET_WINDOW (x0, y , x0 + w_aligned - 1 , y + h - 1 );
89- EPD_PUSH_NEW_COLORS_PART_FLIP (w_aligned, h , winbuf);
124+ EPD_SET_WINDOW (x0, yy , x0 + w_aligned - 1 , yy + hh - 1 );
125+ EPD_PUSH_NEW_COLORS_PART_FLIP (w_aligned, hh , winbuf);
90126#else
91- EPD_SET_WINDOW (x0, y , x0 + w_aligned - 1 , y + h - 1 );
92- EPD_PUSH_NEW_COLORS_PART (w_aligned, h , winbuf);
127+ EPD_SET_WINDOW (x0, yy , x0 + w_aligned - 1 , yy + hh - 1 );
128+ EPD_PUSH_NEW_COLORS_PART (w_aligned, hh , winbuf);
93129#endif
94130 EPD_UPDATE ();
95131
0 commit comments