apps/graphics/pdcurs34: Add support for greylevels vs. RGB.
This commit is contained in:
parent
49dab79a30
commit
24dc1b42e4
@ -37,6 +37,7 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include "pdcnuttx.h"
|
||||
|
||||
/****************************************************************************
|
||||
@ -151,7 +152,9 @@ static inline uintptr_t PDC_fbmem_y(FAR struct pdc_fbstate_s *fbstate,
|
||||
static inline pdc_color_t PDC_color(FAR struct pdc_fbstate_s *fbstate,
|
||||
short color)
|
||||
{
|
||||
#if defined(CONFIG_PDCURSES_COLORFMT_RGB332)
|
||||
#if defined(CONFIG_PDCURSES_COLORFMT_Y1)
|
||||
return fbstate->greylevel > 0 ? 1 : 0;
|
||||
#elif defined(CONFIG_PDCURSES_COLORFMT_RGB332)
|
||||
return RGBTO8(fbstate->rgbcolor[color].red,
|
||||
fbstate->rgbcolor[color].green,
|
||||
fbstate->rgbcolor[color].blue);
|
||||
@ -253,12 +256,12 @@ static void PDC_update(FAR struct pdc_fbstate_s *fbstate, int row, int col,
|
||||
rect.pt1.x = PDC_pixel_x(FAR fbstate, col);
|
||||
rect.pt1.y = PDC_pixel_x(FAR fbstate, row);
|
||||
rect.pt2.x = rect.pt1.x + nchars * fbstate->fwidth - 1;
|
||||
rect.pt2.y = y + fbstate->fheight - 1;
|
||||
rect.pt2.y = rect.pt1.y + fbstate->fheight - 1;
|
||||
|
||||
/* Then perfom the update via IOCTL */
|
||||
|
||||
ret = ioctl(fbstate->fbfd, FBIO_UPDATE,
|
||||
(unsigned long)((uintptr_t)rect));
|
||||
(unsigned long)((uintptr_t)&rect));
|
||||
if (ret < 0)
|
||||
{
|
||||
PDC_LOG(("ERROR: ioctl(FBIO_UPDATE) failed: %d\n", errno));
|
||||
@ -495,7 +498,7 @@ void PDC_clear_screen(FAR struct pdc_fbstate_s *fbstate)
|
||||
|
||||
/* Then perfom the update via IOCTL */
|
||||
|
||||
ret = ioctl(fbstate->fbfd, FBIO_UPDATE, (unsigned long)((uintptr_t)rect));
|
||||
ret = ioctl(fbstate->fbfd, FBIO_UPDATE, (unsigned long)((uintptr_t)&rect));
|
||||
if (ret < 0)
|
||||
{
|
||||
PDC_LOG(("ERROR: ioctl(FBIO_UPDATE) failed: %d\n", errno));
|
||||
|
@ -107,10 +107,13 @@
|
||||
# error No fixed width font selected
|
||||
#endif
|
||||
|
||||
#undef PDCURSES_MONOCHROME
|
||||
|
||||
#if defined(CONFIG_PDCURSES_COLORFMT_Y1)
|
||||
# define PDCURSES_COLORFMT FB_FMT_Y1
|
||||
# define PDCURSES_BPP 1
|
||||
# define PDCURSES_INIT_COLOR PDCURSES_BGCOLOR_GREYLEVEL
|
||||
# define PDCURSES_INIT_COLOR CONFIG_PDCURSES_BGCOLOR_GREYLEVEL
|
||||
# define PDCURSES_MONOCHROME 1
|
||||
#elif defined(CONFIG_PDCURSES_COLORFMT_RGB332)
|
||||
# define PDCURSES_COLORFMT FB_FMT_RGB8_332
|
||||
# define PDCURSES_BPP 8
|
||||
@ -243,7 +246,11 @@ struct pdc_fbstate_s
|
||||
/* Colors */
|
||||
|
||||
struct pdc_colorpair_s colorpair[PDC_COLOR_PAIRS];
|
||||
#ifdef PDCURSES_MONOCHROME
|
||||
uint8_t greylevel[16];
|
||||
#else
|
||||
struct pdc_rgbcolor_s rgbcolor[16];
|
||||
#endif
|
||||
};
|
||||
|
||||
/* This structure contains the framebuffer device structure and is a cast
|
||||
|
@ -135,7 +135,9 @@ int PDC_scr_open(int argc, char **argv)
|
||||
SP = &fbscreen->screen;
|
||||
fbstate = &fbscreen->fbstate;
|
||||
|
||||
/* Number of RGB colors (dimension of rgbcolor[]) */
|
||||
/* Number of RGB colors/greyscale levels. This is the same as the
|
||||
* dimension of rgbcolor[] or greylevel[]).
|
||||
*/
|
||||
|
||||
COLORS = 16;
|
||||
|
||||
@ -143,6 +145,16 @@ int PDC_scr_open(int argc, char **argv)
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
#ifdef PDCURSES_MONOCHROME
|
||||
uint8_t greylevel;
|
||||
|
||||
greylevel = (i & COLOR_RED) ? 0x40 : 0;
|
||||
greylevel += (i & COLOR_GREEN) ? 0x40 : 0;
|
||||
greylevel += (i & COLOR_BLUE) ? 0x40 : 0;
|
||||
|
||||
fbstate->greylevel[i] = greylevel;
|
||||
fbstate->greylevel[i+8] = greylevel | 0x3f;
|
||||
#else
|
||||
fbstate->rgbcolor[i].red = (i & COLOR_RED) ? 0xc0 : 0;
|
||||
fbstate->rgbcolor[i].green = (i & COLOR_GREEN) ? 0xc0 : 0;
|
||||
fbstate->rgbcolor[i].blue = (i & COLOR_BLUE) ? 0xc0 : 0;
|
||||
@ -150,6 +162,7 @@ int PDC_scr_open(int argc, char **argv)
|
||||
fbstate->rgbcolor[i + 8].red = (i & COLOR_RED) ? 0xff : 0x40;
|
||||
fbstate->rgbcolor[i + 8].green = (i & COLOR_GREEN) ? 0xff : 0x40;
|
||||
fbstate->rgbcolor[i + 8].blue = (i & COLOR_BLUE) ? 0xff : 0x40;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Open the framebuffer driver */
|
||||
@ -189,7 +202,7 @@ int PDC_scr_open(int argc, char **argv)
|
||||
goto errout_with_fbfd;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PDCURSES_COLORFMT_Y1
|
||||
#ifdef PDCURSES_MONOCHROME
|
||||
/* Remember if we are using a monochrome framebuffer */
|
||||
|
||||
SP->mono = true;
|
||||
@ -487,9 +500,15 @@ int PDC_color_content(short color, short *red, short *green, short *blue)
|
||||
DEBUGASSERT(fbscreen != NULL);
|
||||
fbstate = &fbscreen->fbstate;
|
||||
|
||||
#ifdef PDCURSES_MONOCHROME
|
||||
*red = DIVROUND(fbstate->greylevel[color] * 1000, 255);
|
||||
*green = DIVROUND(fbstate->greylevel[color] * 1000, 255);
|
||||
*blue = DIVROUND(fbstate->greylevel[color] * 1000, 255);
|
||||
#else
|
||||
*red = DIVROUND(fbstate->rgbcolor[color].red * 1000, 255);
|
||||
*green = DIVROUND(fbstate->rgbcolor[color].green * 1000, 255);
|
||||
*blue = DIVROUND(fbstate->rgbcolor[color].blue * 1000, 255);
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
@ -507,6 +526,9 @@ int PDC_init_color(short color, short red, short green, short blue)
|
||||
{
|
||||
FAR struct pdc_fbscreen_s *fbscreen = (FAR struct pdc_fbscreen_s *)SP;
|
||||
FAR struct pdc_fbstate_s *fbstate;
|
||||
#ifdef PDCURSES_MONOCHROME
|
||||
uint16_t greylevel;
|
||||
#endif
|
||||
|
||||
PDC_LOG(("PDC_init_color(). color=%d, red=%d, green=%d, blue=%d\n",
|
||||
color, red, green, blue));
|
||||
@ -514,9 +536,16 @@ int PDC_init_color(short color, short red, short green, short blue)
|
||||
DEBUGASSERT(fbscreen != NULL);
|
||||
fbstate = &fbscreen->fbstate;
|
||||
|
||||
#ifdef PDCURSES_MONOCHROME
|
||||
greylevel = (DIVROUND(red * 255, 1000) +
|
||||
DIVROUND(green * 255, 1000) +
|
||||
DIVROUND(blue * 255, 1000)) / 3;
|
||||
fbstate->greylevel[color] = (uint8_t)greylevel;
|
||||
#else
|
||||
fbstate->rgbcolor[color].red = DIVROUND(red * 255, 1000);
|
||||
fbstate->rgbcolor[color].green = DIVROUND(green * 255, 1000);
|
||||
fbstate->rgbcolor[color].blue = DIVROUND(blue * 255, 1000);
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user