📄 framebuf-colour.html
字号:
<!-- Copyright (C) 2009 Free Software Foundation, Inc. -->
<!-- This material may be distributed only subject to the terms -->
<!-- and conditions set forth in the Open Publication License, v1.0 -->
<!-- or later (the latest version is presently available at -->
<!-- http://www.opencontent.org/openpub/). -->
<!-- Distribution of the work or derivative of the work in any -->
<!-- standard (paper) book form is prohibited unless prior -->
<!-- permission is obtained from the copyright holder. -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Framebuffer Colours</TITLE
><meta name="MSSmartTagsPreventParsing" content="TRUE">
<META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="eCos Reference Manual"
HREF="ecos-ref.html"><LINK
REL="UP"
TITLE="Framebuffer Support"
HREF="io-framebuf.html"><LINK
REL="PREVIOUS"
TITLE="Framebuffer Control Operations"
HREF="framebuf-control.html"><LINK
REL="NEXT"
TITLE="Framebuffer Drawing Primitives"
HREF="framebuf-drawing.html"></HEAD
><BODY
CLASS="REFENTRY"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>eCos Reference Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="framebuf-control.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="framebuf-drawing.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="FRAMEBUF-COLOUR"
></A
>Framebuffer Colours</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN10412"
></A
><H2
>Name</H2
>Colours -- formats and palette management</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN10415"
></A
><H2
>Synopsis</H2
><DIV
CLASS="FUNCSYNOPSIS"
><P
></P
><A
NAME="AEN10416"
></A
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="FUNCSYNOPSISINFO"
>#include <cyg/io/framebuf.h>
typedef struct cyg_fb {
cyg_ucount16 fb_depth;
cyg_ucount16 fb_format;
cyg_uint32 fb_flags0;
…
} cyg_fb;
extern const cyg_uint8 cyg_fb_palette_ega[16 * 3];
extern const cyg_uint8 cyg_fb_palette_vga[256 * 3];
#define CYG_FB_DEFAULT_PALETTE_BLACK 0x00
#define CYG_FB_DEFAULT_PALETTE_BLUE 0x01
#define CYG_FB_DEFAULT_PALETTE_GREEN 0x02
#define CYG_FB_DEFAULT_PALETTE_CYAN 0x03
#define CYG_FB_DEFAULT_PALETTE_RED 0x04
#define CYG_FB_DEFAULT_PALETTE_MAGENTA 0x05
#define CYG_FB_DEFAULT_PALETTE_BROWN 0x06
#define CYG_FB_DEFAULT_PALETTE_LIGHTGREY 0x07
#define CYG_FB_DEFAULT_PALETTE_LIGHTGRAY 0x07
#define CYG_FB_DEFAULT_PALETTE_DARKGREY 0x08
#define CYG_FB_DEFAULT_PALETTE_DARKGRAY 0x08
#define CYG_FB_DEFAULT_PALETTE_LIGHTBLUE 0x09
#define CYG_FB_DEFAULT_PALETTE_LIGHTGREEN 0x0A
#define CYG_FB_DEFAULT_PALETTE_LIGHTCYAN 0x0B
#define CYG_FB_DEFAULT_PALETTE_LIGHTRED 0x0C
#define CYG_FB_DEFAULT_PALETTE_LIGHTMAGENTA 0x0D
#define CYG_FB_DEFAULT_PALETTE_YELLOW 0x0E
#define CYG_FB_DEFAULT_PALETTE_WHITE 0x0F
</PRE
></TD
></TR
></TABLE
><P
><CODE
><CODE
CLASS="FUNCDEF"
>cyg_ucount16 CYG_FB_FORMAT</CODE
>(framebuf);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void cyg_fb_read_palette</CODE
>(cyg_fb* fb, cyg_ucount32 first, cyg_ucount32 count, void* data);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void cyg_fb_write_palette</CODE
>(cyg_fb* fb, cyg_ucount32 first, cyg_ucount32 count, const void* data, cyg_ucount16 when);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>cyg_fb_colour cyg_fb_make_colour</CODE
>(cyg_fb* fb, cyg_ucount8 r, cyg_ucount8 g, cyg_ucount8 b);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void cyg_fb_break_colour</CODE
>(cyg_fb* fb, cyg_fb_colour colour, cyg_ucount8* r, cyg_ucount8* g, cyg_ucount8* b);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void CYG_FB_READ_PALETTE</CODE
>(FRAMEBUF, cyg_ucount32 first, cyg_ucount32 count, void* data);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void CYG_FB_WRITE_PALETTE</CODE
>(FRAMEBUF, cyg_ucount32 first, cyg_ucount32 count, const void* data, cyg_ucount16 when);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>cyg_fb_colour CYG_FB_MAKE_COLOUR</CODE
>(FRAMEBUF, cyg_ucount8 r, cyg_ucount8 g, cyg_ucount8 b);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void CYG_FB_BREAK_COLOUR</CODE
>(FRAMEBUF, cyg_fb_colour colour, cyg_ucount8* r, cyg_ucount8* g, cyg_ucount8* b);</CODE
></P
><P
></P
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="FRAMEBUF-COLOUR-DESCRIPTION"
></A
><H2
>Description</H2
><P
>Managing colours can be one of the most difficult aspects of writing
graphics code, especially if that code is intended to be portable to
many different platforms. Displays can vary from 1bpp monochrome, via
2bpp and 4bpp greyscale, through 4bpp and 8bpp paletted, and up to
16bpp and 32bpp true colour - and those are just the more common
scenarios. The various <A
HREF="framebuf-drawing.html"
>drawing
primitives</A
> like <CODE
CLASS="FUNCTION"
>cyg_fb_write_pixel</CODE
> work in
terms of <SPAN
CLASS="TYPE"
>cyg_fb_colour</SPAN
> values, usually an unsigned
integer. Exactly how the hardware interprets a
<SPAN
CLASS="TYPE"
>cyg_fb_colour</SPAN
> depends on the format.
</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="FRAMEBUF-COLOUR-FORMATS"
></A
><H2
>Colour Formats</H2
><P
>There are a number of ways of finding out how these values will be
interpreted by the hardware:
</P
><P
></P
><OL
TYPE="1"
><LI
><P
>The <TT
CLASS="LITERAL"
>CYG_FB_FLAGS0_TRUE_COLOUR</TT
> flag is set for all
true colour displays. The format parameter can be examined for more
details but this is not usually necessary. Instead code can use
<A
HREF="framebuf-colour.html#FRAMEBUF-COLOUR-TRUE"
><CODE
CLASS="FUNCTION"
>cyg_fb_make_colour</CODE
></A
>
or <A
HREF="framebuf-colour.html#FRAMEBUF-COLOUR-TRUE"
><CODE
CLASS="FUNCTION"
>CYG_FB_MAKE_COLOUR</CODE
></A
>
to construct a <SPAN
CLASS="TYPE"
>cyg_fb_colour</SPAN
> value from red, green and
blue components.
</P
></LI
><LI
><P
>If the <TT
CLASS="LITERAL"
>CYG_FB_FLAGS0_WRITEABLE_PALETTE</TT
> flag is set
then a <SPAN
CLASS="TYPE"
>cyg_fb_colour</SPAN
> value is an index into a lookup
table known as the palette, and this table contains red, green and
blue components. The size of the palette is determined by the display
depth, so 16 entries for a 4bpp display and 256 entries for an 8bpp
display. Application code or a graphics library can <A
HREF="framebuf-colour.html#FRAMEBUF-COLOUR-PALETTE"
>install</A
> its own palette so
can control exactly what colour each <SPAN
CLASS="TYPE"
>cyg_fb_colour</SPAN
> value
corresponds to. Alternatively there is support for installing a
default palette.
</P
></LI
><LI
><P
>If <TT
CLASS="LITERAL"
>CYG_FB_FLAGS0_PALETTE</TT
> is set but
<TT
CLASS="LITERAL"
>CYG_FB_FLAGS0_WRITEABLE_PALETTE</TT
> is clear then the
hardware uses a fixed palette. There is no easy way for portable
software to handle this case. The palette can be read at run-time,
allowing the application's desired colours to be mapped to whichever
palette entry provides the best match. However normally it will be
necessary to write code specifically for the fixed palette.
</P
></LI
><LI
><P
>Otherwise the display is monochrome or greyscale, depending on the
depth. There are still variations, for example on a monochrome display
colour 0 can be either white or black.
</P
></LI
></OL
><P
>As an alternative or to provide additional information, the exact
colour format is provided by the <CODE
CLASS="STRUCTFIELD"
>fb_format</CODE
>
field of the <CODE
CLASS="STRUCTNAME"
>cyg_fb</CODE
> structure or by the
<CODE
CLASS="FUNCTION"
>CYG_FB_FORMAT</CODE
> macro. It can be one of the
following (more entries may be added in future):
</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="LITERAL"
>CYG_FB_FORMAT_1BPP_MONO_0_BLACK</TT
></DT
><DD
><P
>simple 1bpp monochrome display, with 0 as black or the darker of the
two colours, and 1 as white or the ligher colour.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>CYG_FB_FORMAT_1BPP_MONO_0_WHITE</TT
></DT
><DD
><P
>simple 1bpp monochrome display, with 0 as white or the lighter of the
two colours, and 1 as black or the darker colour.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>CYG_FB_FORMAT_1BPP_PAL888</TT
></DT
><DD
><P
>a 1bpp display which cannot easily be described as monochrome. This is
unusual and not readily supported by portable code. It can happen if
the framebuffer normally runs at a higher depth, for example 4bpp or
8bpp paletted, but is run at only 1bpp to save memory. Hence only two
of the palette entries are used, but can be set to arbitrary colours.
The palette may be read-only or read-write.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>CYG_FB_FORMAT_2BPP_GREYSCALE_0_BLACK</TT
></DT
><DD
><P
>a 2bpp display offering four shades of grey, with 0 as black or the
darkest of the four shades, and 3 as white or the lightest.
</P
></DD
><DT
><TT
CLASS="LITERAL"
>CYG_FB_FORMAT_2BPP_GREYSCALE_0_WHITE</TT
></DT
><DD
><P
>a 2bpp display offering four shades of grey, with 0 as white or the
lightest of the four shades, and 3 as black or the darkest.
</P
></DD
><DT
><TT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -