@@ -143,23 +143,29 @@ void rotate_8bpp(uint8_t *src, uint8_t *dst, mp_lcd_sw_rotation_data_t *copy_dat
143143
144144 switch (copy_data -> rotation ) {
145145 case LCD_ROTATION_90 :
146+ uint32_t src_line_bytes ;
147+ dst_height -= 1 ;
148+
146149 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
150+ src_line_bytes = (y * src_bytes_per_line ) - offset ;
151+
147152 for (uint32_t x = x_start ; x < x_end ; x ++ ) {
148- i = y * src_bytes_per_line + x - offset ;
149- j = (dst_height - 1 - x ) * dst_width + y ;
153+ i = src_line_bytes + x ;
154+ j = (( dst_height - x ) * dst_width ) + y ;
150155 copy_8bpp (src + i , dst + j );
151156 }
152157 }
153158 break ;
154159
155160 // MIRROR_X MIRROR_Y
156161 case LCD_ROTATION_180 :
157- LCD_UNUSED ( j ) ;
162+ j = dst_width - 1 - x_start ;
158163 LCD_UNUSED (src_bytes_per_line );
159164 LCD_UNUSED (offset );
165+ dst_height -= 1 ;
160166
161167 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
162- i = (dst_height - 1 - y ) * dst_width + ( dst_width - 1 - x_start ) ;
168+ i = (( dst_height - y ) * dst_width ) + j ;
163169 for (uint32_t x = x_start ; x < x_end ; x ++ ) {
164170 copy_8bpp (src , dst + i );
165171 src ++ ;
@@ -170,10 +176,16 @@ void rotate_8bpp(uint8_t *src, uint8_t *dst, mp_lcd_sw_rotation_data_t *copy_dat
170176
171177 // SWAP_XY MIRROR_X
172178 case LCD_ROTATION_270 :
179+ uint32_t m ;
180+ uint32_t o ;
181+
173182 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
183+ m = y * src_bytes_per_line ;
184+ o = dst_width - 1 - y ;
185+
174186 for (uint32_t x = x_start ; x < x_end ; x ++ ) {
175- i = y * src_bytes_per_line + x - offset ;
176- j = x * dst_width + dst_width - 1 - y ;
187+ i = m + x ;
188+ j = ( x * dst_width ) + o ;
177189 copy_8bpp (src + i , dst + j );
178190 }
179191 }
@@ -219,10 +231,14 @@ void rotate_16bpp_swap_dither(uint16_t *src, uint16_t *dst, mp_lcd_sw_rotation_d
219231 break ;
220232
221233 case LCD_ROTATION_90 :
234+ uint32_t src_line_bytes ;
235+ dst_height -= 1 ;
236+
222237 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
238+ src_line_bytes = (y * src_bytes_per_line ) - offset ;
223239 for (uint32_t x = x_start ; x < x_end ; x ++ ) {
224- i = y * src_bytes_per_line + x - offset ;
225- j = (dst_height - 1 - x ) * dst_width + y ;
240+ i = src_line_bytes + x ;
241+ j = (( dst_height - x ) * dst_width ) + y ;
226242 rgb565_dither_byte_swap_pixel (CALC_THRESHOLD (x , y ), src + i , dst + j );
227243 // copy_16bpp(src + i, dst + j);
228244 }
@@ -231,12 +247,13 @@ void rotate_16bpp_swap_dither(uint16_t *src, uint16_t *dst, mp_lcd_sw_rotation_d
231247
232248 // MIRROR_X MIRROR_Y
233249 case LCD_ROTATION_180 :
234- LCD_UNUSED ( j ) ;
250+ j = dst_width - 1 - x_start ;
235251 LCD_UNUSED (src_bytes_per_line );
236252 LCD_UNUSED (offset );
253+ dst_height -= 1 ;
237254
238255 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
239- i = (dst_height - 1 - y ) * dst_width + ( dst_width - 1 - x_start ) ;
256+ i = (( dst_height - y ) * dst_width ) + j ;
240257 for (uint32_t x = x_start ; x < x_end ; x ++ ) {
241258 rgb565_dither_byte_swap_pixel (CALC_THRESHOLD (x , y ), src , dst + i );
242259
@@ -249,10 +266,16 @@ void rotate_16bpp_swap_dither(uint16_t *src, uint16_t *dst, mp_lcd_sw_rotation_d
249266
250267 // SWAP_XY MIRROR_X
251268 case LCD_ROTATION_270 :
269+ uint32_t m ;
270+ uint32_t o ;
271+
252272 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
273+ m = (y * src_bytes_per_line ) - offset ;
274+ o = dst_width - 1 - y ;
275+
253276 for (uint32_t x = x_start ; x < x_end ; x ++ ) {
254- i = y * src_bytes_per_line + x - offset ;
255- j = (x * dst_width + dst_width - 1 - y ) ;
277+ i = m + x ;
278+ j = (x * dst_width ) + o ;
256279 rgb565_dither_byte_swap_pixel (CALC_THRESHOLD (x , y ), src + i , dst + j );
257280
258281 // copy_16bpp(src + i, dst + j);
@@ -300,10 +323,15 @@ void rotate_16bpp_dither(uint16_t *src, uint16_t *dst, mp_lcd_sw_rotation_data_t
300323 break ;
301324
302325 case LCD_ROTATION_90 :
326+ uint32_t src_line_bytes ;
327+ dst_height -= 1 ;
328+
303329 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
330+ src_line_bytes = (y * src_bytes_per_line ) - offset ;
331+
304332 for (uint32_t x = x_start ; x < x_end ; x ++ ) {
305- i = y * src_bytes_per_line + x - offset ;
306- j = (dst_height - 1 - x ) * dst_width + y ;
333+ i = src_line_bytes + x ;
334+ j = (( dst_height - x ) * dst_width ) + y ;
307335 rgb565_dither_pixel (CALC_THRESHOLD (x , y ), src + i , dst + j );
308336
309337 // copy_16bpp(src + i, dst + j);
@@ -313,12 +341,13 @@ void rotate_16bpp_dither(uint16_t *src, uint16_t *dst, mp_lcd_sw_rotation_data_t
313341
314342 // MIRROR_X MIRROR_Y
315343 case LCD_ROTATION_180 :
316- LCD_UNUSED ( j ) ;
344+ j = dst_width - 1 - x_start ;
317345 LCD_UNUSED (src_bytes_per_line );
318346 LCD_UNUSED (offset );
347+ dst_height -= 1 ;
319348
320349 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
321- i = (dst_height - 1 - y ) * dst_width + ( dst_width - 1 - x_start ) ;
350+ i = (( dst_height - y ) * dst_width ) + j ;
322351 for (uint32_t x = x_start ; x < x_end ; x ++ ) {
323352 rgb565_dither_pixel (CALC_THRESHOLD (x , y ), src , dst + i );
324353
@@ -331,10 +360,16 @@ void rotate_16bpp_dither(uint16_t *src, uint16_t *dst, mp_lcd_sw_rotation_data_t
331360
332361 // SWAP_XY MIRROR_X
333362 case LCD_ROTATION_270 :
363+ uint32_t m ;
364+ uint32_t o ;
365+
334366 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
367+ m = (y * src_bytes_per_line ) - offset ;
368+ o = dst_width - 1 - y ;
369+
335370 for (uint32_t x = x_start ; x < x_end ; x ++ ) {
336- i = y * src_bytes_per_line + x - offset ;
337- j = (x * dst_width + dst_width - 1 - y ) ;
371+ i = m + x ;
372+ j = (x * dst_width ) + o ;
338373 rgb565_dither_pixel (CALC_THRESHOLD (x , y ), src + i , dst + j );
339374
340375 // copy_16bpp(src + i, dst + j);
@@ -382,11 +417,13 @@ void rotate_16bpp_swap(uint16_t *src, uint16_t *dst, mp_lcd_sw_rotation_data_t *
382417 break ;
383418
384419 case LCD_ROTATION_90 :
420+ uint32_t src_line_bytes ;
421+ dst_height -= 1 ;
422+
385423 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
386424 for (uint32_t x = x_start ; x < x_end ; x ++ ) {
387- i = y * src_bytes_per_line + x - offset ;
388- j = (dst_height - 1 - x ) * dst_width + y ;
389-
425+ i = src_line_bytes + x ;
426+ j = ((dst_height - x ) * dst_width ) + y ;
390427 * (dst + j ) = (* (src + i ) << 8 ) | (* (src + i ) >> 8 );
391428
392429 // copy_16bpp(src + i, dst + j);
@@ -396,13 +433,14 @@ void rotate_16bpp_swap(uint16_t *src, uint16_t *dst, mp_lcd_sw_rotation_data_t *
396433
397434 // MIRROR_X MIRROR_Y
398435 case LCD_ROTATION_180 :
399- LCD_UNUSED ( j ) ;
436+ j = dst_width - 1 - x_start ;
400437 LCD_UNUSED (src_bytes_per_line );
401438 LCD_UNUSED (offset );
439+ dst_height -= 1 ;
402440
403441 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
404- i = (dst_height - 1 - y ) * dst_width + ( dst_width - 1 - x_start ) ;
405- for (uint32_t x = x_start ; x < x_end ; x ++ ) {
442+ i = (( dst_height - y ) * dst_width ) + j ;
443+ for (uint32_t x = x_start ; x < x_end ; x ++ ) {
406444 * (dst + i ) = (* src << 8 ) | (* src >> 8 );
407445
408446 // copy_16bpp(src, dst + i);
@@ -414,11 +452,16 @@ void rotate_16bpp_swap(uint16_t *src, uint16_t *dst, mp_lcd_sw_rotation_data_t *
414452
415453 // SWAP_XY MIRROR_X
416454 case LCD_ROTATION_270 :
455+ uint32_t m ;
456+ uint32_t o ;
457+
417458 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
459+ m = (y * src_bytes_per_line ) - offset ;
460+ o = dst_width - 1 - y ;
461+
418462 for (uint32_t x = x_start ; x < x_end ; x ++ ) {
419- i = y * src_bytes_per_line + x - offset ;
420- j = (x * dst_width + dst_width - 1 - y );
421-
463+ i = m + x ;
464+ j = (x * dst_width ) + o ;
422465 * (dst + j ) = (* (src + i ) << 8 ) | (* (src + i ) >> 8 );
423466
424467 // copy_16bpp(src + i, dst + j);
@@ -469,24 +512,29 @@ void rotate_16bpp(uint16_t *src, uint16_t *dst, mp_lcd_sw_rotation_data_t *copy_
469512 break ;
470513
471514 case LCD_ROTATION_90 :
515+ uint32_t src_line_bytes ;
516+ dst_height -= 1 ;
517+
472518 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
473- for (uint32_t x = x_start ; x < x_end ; x ++ ) {
474- i = y * src_bytes_per_line + x - offset ;
475- j = (dst_height - 1 - x ) * dst_width + y ;
519+ src_line_bytes = (y * src_bytes_per_line ) - offset ;
476520
521+ for (uint32_t x = x_start ; x < x_end ; x ++ ) {
522+ i = src_line_bytes + x ;
523+ j = ((dst_height - x ) * dst_width ) + y ;
477524 copy_16bpp (src + i , dst + j );
478525 }
479526 }
480527 break ;
481528
482529 // MIRROR_X MIRROR_Y
483530 case LCD_ROTATION_180 :
484- LCD_UNUSED ( j ) ;
531+ j = dst_width - 1 - x_start ;
485532 LCD_UNUSED (src_bytes_per_line );
486533 LCD_UNUSED (offset );
534+ dst_height -= 1 ;
487535
488536 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
489- i = (dst_height - 1 - y ) * dst_width + ( dst_width - 1 - x_start ) ;
537+ i = (( dst_height - y ) * dst_width ) + j ;
490538 for (uint32_t x = x_start ; x < x_end ; x ++ ) {
491539 copy_16bpp (src , dst + i );
492540 src ++ ;
@@ -497,11 +545,16 @@ void rotate_16bpp(uint16_t *src, uint16_t *dst, mp_lcd_sw_rotation_data_t *copy_
497545
498546 // SWAP_XY MIRROR_X
499547 case LCD_ROTATION_270 :
548+ uint32_t m ;
549+ uint32_t o ;
550+
500551 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
501- for (uint32_t x = x_start ; x < x_end ; x ++ ) {
502- i = y * src_bytes_per_line + x - offset ;
503- j = (x * dst_width + dst_width - 1 - y );
552+ m = (y * src_bytes_per_line ) - offset ;
553+ o = dst_width - 1 - y ;
504554
555+ for (uint32_t x = x_start ; x < x_end ; x ++ ) {
556+ i = m + x ;
557+ j = (x * dst_width ) + o ;
505558 copy_16bpp (src + i , dst + j );
506559 }
507560 }
@@ -535,24 +588,29 @@ void rotate_24bpp(uint8_t *src, uint8_t *dst, mp_lcd_sw_rotation_data_t *copy_da
535588
536589 switch (copy_data -> rotation ) {
537590 case LCD_ROTATION_90 :
591+ uint32_t src_line_bytes ;
592+ dst_height -= 1 ;
593+
538594 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
539- for (uint32_t x = x_start ; x < x_end ; x ++ ) {
540- i = y * src_bytes_per_line + x * 3 - offset ;
541- j = ((dst_height - 1 - x ) * dst_width + y ) * 3 ;
595+ src_line_bytes = (y * src_bytes_per_line ) - offset ;
542596
597+ for (uint32_t x = x_start ; x < x_end ; x ++ ) {
598+ i = src_line_bytes + (x * 3 );
599+ j = (((dst_height - x ) * dst_width ) + y ) * 3 ;
543600 copy_24bpp (src + i , dst + j );
544601 }
545602 }
546603 break ;
547604
548605 // MIRROR_X MIRROR_Y
549606 case LCD_ROTATION_180 :
550- LCD_UNUSED ( j ) ;
607+ j = dst_width - 1 - x_start ;
551608 LCD_UNUSED (src_bytes_per_line );
552609 LCD_UNUSED (offset );
610+ dst_height -= 1 ;
553611
554612 for (int y = y_start ; y < y_end ; y ++ ) {
555- i = ((dst_height - 1 - y ) * dst_width + ( dst_width - 1 - x_start ) ) * 3 ;
613+ i = ((( dst_height - y ) * dst_width ) + j ) * 3 ;
556614 for (size_t x = x_start ; x < x_end ; x ++ ) {
557615 copy_24bpp (src , dst + i );
558616 src += 3 ;
@@ -563,11 +621,16 @@ void rotate_24bpp(uint8_t *src, uint8_t *dst, mp_lcd_sw_rotation_data_t *copy_da
563621
564622 // SWAP_XY MIRROR_X
565623 case LCD_ROTATION_270 :
624+ uint32_t m ;
625+ uint32_t o ;
626+
566627 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
567- for (uint32_t x = x_start ; x < x_end ; x ++ ) {
568- i = y * src_bytes_per_line + x * 3 - offset ;
569- j = (x * dst_width + dst_width - 1 - y ) * 3 ;
628+ m = (y * src_bytes_per_line ) - offset ;
629+ o = dst_width - 1 - y ;
570630
631+ for (uint32_t x = x_start ; x < x_end ; x ++ ) {
632+ i = m + (x * 3 );
633+ j = ((x * dst_width ) + o ) * 3 ;
571634 copy_24bpp (src + i , dst + j );
572635 }
573636 }
@@ -601,24 +664,30 @@ void rotate_32bpp(uint32_t *src, uint32_t *dst, mp_lcd_sw_rotation_data_t *copy_
601664
602665 switch (copy_data -> rotation ) {
603666 case LCD_ROTATION_90 :
667+ uint32_t src_line_bytes ;
668+ dst_height -= 1 ;
669+
604670 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
605- for (uint32_t x = x_start ; x < x_end ; x ++ ) {
606- i = y * src_bytes_per_line + x - offset ;
607- j = (dst_height - 1 - x ) * dst_width + y ;
671+ src_line_bytes = (y * src_bytes_per_line ) - offset ;
608672
673+ for (uint32_t x = x_start ; x < x_end ; x ++ ) {
674+ i = src_line_bytes + x ;
675+ j = ((dst_height - x ) * dst_width ) + y ;
609676 copy_32bpp (src + i , dst + j );
610677 }
611678 }
612679 break ;
613680
614681 // MIRROR_X MIRROR_Y
615682 case LCD_ROTATION_180 :
616- LCD_UNUSED ( j ) ;
683+ j = dst_width - 1 - x_start ;
617684 LCD_UNUSED (src_bytes_per_line );
618685 LCD_UNUSED (offset );
686+ dst_height -= 1 ;
619687
620688 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
621- i = (dst_height - 1 - y ) * dst_width + (dst_width - 1 - x_start );
689+ i = ((dst_height - y ) * dst_width ) + j ;
690+
622691 for (uint32_t x = x_start ; x < x_end ; x ++ ) {
623692 copy_32bpp (src , dst + i );
624693 src ++ ;
@@ -629,11 +698,16 @@ void rotate_32bpp(uint32_t *src, uint32_t *dst, mp_lcd_sw_rotation_data_t *copy_
629698
630699 // SWAP_XY MIRROR_X
631700 case LCD_ROTATION_270 :
701+ uint32_t m ;
702+ uint32_t o ;
703+
632704 for (uint32_t y = y_start ; y < y_end ; y ++ ) {
633- for (uint32_t x = x_start ; x < x_end ; x ++ ) {
634- i = y * src_bytes_per_line + x - offset ;
635- j = x * dst_width + dst_width - 1 - y ;
705+ m = (y * src_bytes_per_line ) - offset ;
706+ o = dst_width - 1 - y ;
636707
708+ for (uint32_t x = x_start ; x < x_end ; x ++ ) {
709+ i = m + x ;
710+ j = (x * dst_width ) + o ;
637711 copy_32bpp (src + i , dst + j );
638712 }
639713 }
0 commit comments