From 18a5e074e70fb7151127bb6430c5c11f624bbc14 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 24 Nov 2017 07:17:10 -0600 Subject: [PATCH] apps/graphics/pdcurs34: Fixes calculation of the final byte position of the case of BPP < 8. --- graphics/pdcurs34/nuttx/pdcdisp.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/graphics/pdcurs34/nuttx/pdcdisp.c b/graphics/pdcurs34/nuttx/pdcdisp.c index 765bad82d..5acc4f296 100644 --- a/graphics/pdcurs34/nuttx/pdcdisp.c +++ b/graphics/pdcurs34/nuttx/pdcdisp.c @@ -237,7 +237,7 @@ static inline void PDC_set_bg(FAR struct pdc_fbstate_s *fbstate, /* If the first or last bytes may require read, modify, write operations. */ #if PDCURSES_BPP == 1 - /* Get the start and end colum in pixels (relative to the start position) */ + /* Get the start and end column in pixels (relative to the start position) */ startcol = col & 7; endcol = startcol + fbstate->fwidth - 1; @@ -254,9 +254,11 @@ static inline void PDC_set_bg(FAR struct pdc_fbstate_s *fbstate, rmask = 0xff << (endcol & 7); #endif - /* Convert endcol to a byte offset */ + /* Convert endcol to a byte offset (taking the ceiling so that includes + * the final byte than may have fewer than 8 pixels in it). + */ - endcol >>= 3; + endcol = (endcol + 7) >> 3; #elif PDCURSES_BPP == 2 /* Get the start and end colum in pixels (relative to the start position) */ @@ -276,9 +278,11 @@ static inline void PDC_set_bg(FAR struct pdc_fbstate_s *fbstate, rmask = 0xff << ((endcol & 3) << 1); #endif - /* Convert endcol to a byte offset */ + /* Convert endcol to a byte offset (taking the ceiling so that includes + * the final byte than may have fewer than 4 pixels in it). + */ - endcol >>= 2; + endcol = (endcol + 3) >> 3; #elif PDCURSES_BPP == 4 /* Get the start and end colum in pixels (relative to the start position) */ @@ -298,9 +302,11 @@ static inline void PDC_set_bg(FAR struct pdc_fbstate_s *fbstate, rmask = ((endcol & 1) == 0) ? 0x00 ? 0xf0; #endif - /* Convert endcol to a byte offset */ + /* Convert endcol to a byte offset (taking the ceiling so that includes + * the final byte than may have only one pixels in it). + */ - endcol >>= 1; + endcol = (endcol + 1) >> 3; #endif /* Now copy the color into the entire glyph region */