framebuf-drawing.html
来自「ecos3.0 beta 的官方文档,html格式」· HTML 代码 · 共 921 行 · 第 1/2 页
HTML
921 行
<!-- 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 Drawing Primitives</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 Colours"
HREF="framebuf-colour.html"><LINK
REL="NEXT"
TITLE="Framebuffer Pixel Manipulation"
HREF="framebuf-iterating.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-colour.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="framebuf-iterating.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="FRAMEBUF-DRAWING"
></A
>Framebuffer Drawing Primitives</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN10679"
></A
><H2
>Name</H2
>Drawing Primitives -- updating the display</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN10682"
></A
><H2
>Synopsis</H2
><DIV
CLASS="FUNCSYNOPSIS"
><P
></P
><A
NAME="AEN10683"
></A
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="FUNCSYNOPSISINFO"
>#include <cyg/io/framebuf.h>
</PRE
></TD
></TR
></TABLE
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void cyg_fb_write_pixel</CODE
>(cyg_fb* fbdev, cyg_ucount16 x, cyg_ucount16 y, cyg_fb_colour colour);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>cyg_fb_colour cyg_fb_read_pixel</CODE
>(cyg_fb* fbdev, cyg_ucount16 x, cyg_ucount16 y);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void cyg_fb_write_hline</CODE
>(cyg_fb* fbdev, cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 len, cyg_fb_colour colour);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void cyg_fb_write_vline</CODE
>(cyg_fb* fbdev, cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 len, cyg_fb_colour colour);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void cyg_fb_fill_block</CODE
>(cyg_fb* fbdev, cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 width, cyg_ucount16 height, cyg_fb_colour colour);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void cyg_fb_write_block</CODE
>(cyg_fb* fbdev, cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 width, cyg_ucount16 height, const void* data, cyg_ucount16 offset, cyg_ucount16 stride);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void cyg_fb_read_block</CODE
>(cyg_fb* fbdev, cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 width, cyg_ucount16 height, void* data, cyg_ucount16 offset, cyg_ucount16 stride);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void cyg_fb_move_block</CODE
>(cyg_fb* fbdev, cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 width, cyg_ucount16 height, cyg_ucount16 new_x, cyg_ucount16 new_y);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void cyg_fb_synch</CODE
>(cyg_fb* fbdev, cyg_ucount16 when);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void CYG_FB_WRITE_PIXEL</CODE
>(FRAMEBUF, cyg_ucount16 x, cyg_ucount16 y, cyg_fb_colour colour);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>cyg_fb_colour CYG_FB_READ_PIXEL</CODE
>(FRAMEBUF, cyg_ucount16 x, cyg_ucount16 y);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void CYG_FB_WRITE_HLINE</CODE
>(FRAMEBUF, cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 len, cyg_fb_colour colour);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void CYG_FB_WRITE_VLINE</CODE
>(FRAMEBUF, cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 len, cyg_fb_colour colour);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void CYG_FB_FILL_BLOCK</CODE
>(FRAMEBUF, cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 width, cyg_ucount16 height, cyg_fb_colour colour);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void CYG_FB_WRITE_BLOCK</CODE
>(FRAMEBUF, cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 width, cyg_ucount16 height, const void* data, cyg_ucount16 offset, cyg_ucount16 stride);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void CYG_FB_READ_BLOCK</CODE
>(FRAMEBUF, cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 width, cyg_ucount16 height, void* data, cyg_ucount16 offset, cyg_ucount16 stride);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void CYG_FB_MOVE_BLOCK</CODE
>(FRAMEBUF, cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 width, cyg_ucount16 height, cyg_ucount16 new_x, cyg_ucount16 new_y);</CODE
></P
><P
><CODE
><CODE
CLASS="FUNCDEF"
>void CYG_FB_SYNCH</CODE
>(FRAMEBUF, cyg_ucount16 when);</CODE
></P
><P
></P
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="FRAMEBUF-DRAWING-DESCRIPTION"
></A
><H2
>Description</H2
><P
>The eCos framebuffer infrastructure defines a small number of drawing
primitives. These are not intended to provide full graphical
functionality like multiple windows, drawing text in arbitrary fonts,
or anything like that. Instead they provide building blocks for
higher-level graphical toolkits. The available primitives are:
</P
><P
></P
><OL
TYPE="1"
><LI
><P
>Manipulating individual pixels.
</P
></LI
><LI
><P
>Drawing horizontal and vertical lines.
</P
></LI
><LI
><P
>Block fills.
</P
></LI
><LI
><P
>Moving blocks between the framebuffer and main memory.
</P
></LI
><LI
><P
>Moving blocks within the framebuffer.
</P
></LI
><LI
><P
>For double-buffered devices, synchronizing the framebuffer contents
with the actual display.
</P
></LI
></OL
><P
>There are two versions for each primitive: a macro and a function. The
macro can be used if the desired framebuffer device is known at
compile-time. Its first argument should be a framebuffer identifier,
for example <TT
CLASS="LITERAL"
>320x240x16</TT
>, and must be one of the
entries in the configuration option
<CODE
CLASS="VARNAME"
>CYGDAT_IO_FRAMEBUF_DEVICES</CODE
>. In the examples below
it is assumed that <CODE
CLASS="VARNAME"
>FRAMEBUF</CODE
> has been
<TT
CLASS="LITERAL"
>#define</TT
>'d to a suitable identifier. The function
can be used if the desired framebuffer device is selected at
run-time. Its first argument should be a pointer to the appropriate
<CODE
CLASS="STRUCTNAME"
>cyg_fb</CODE
> structure.
</P
><P
>The pixel, line, and block fill primitives take a
<SPAN
CLASS="TYPE"
>cyg_fb_colour</SPAN
> argument. For details of colour handling
see <A
HREF="framebuf-colour.html"
>Framebuffer Colours</A
>. This argument should have no
more bits set than are appropriate for the display depth. For example
on a 4bpp only the bottom four bits of the colour may be set,
otherwise the behaviour is undefined.
</P
><P
>None of the primitives will perform any run-time error checking,
except possibly for some assertions in a debug build. If higher-level
code provides invalid arguments, for example trying to write a block
which extends past the right hand side of the screen, then the
system's behaviour is undefined. It is the responsibility of
higher-level code to perform clipping to the screen boundaries.
</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="FRAMEBUF-DRAWING-PIXELS"
></A
><H2
>Manipulating Individual Pixels</H2
><P
>The primitives for manipulating individual pixels are very simple: a
pixel can be written or read back. The following example shows one way
of drawing a diagonal line:
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void
draw_diagonal(cyg_fb* fb,
cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 len,
cyg_fb_colour colour)
{
while ( len-- ) {
cyg_fb_write_pixel(fb, x++, y++, colour);
}
}
</PRE
></TD
></TR
></TABLE
><P
>The next example shows how to draw a horizontal XOR line on a 1bpp
display.
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void
draw_horz_xor(cyg_ucount16 x, cyg_ucount16 y, cyg_ucount16 len)
{
cyg_fb_colour colour;
while ( len--) {
colour = CYG_FB_READ_PIXEL(FRAMEBUF, x, y);
CYG_FB_WRITE_PIXEL(FRAMEBUF, x++, y, colour ^ 0x01);
}
}
</PRE
></TD
></TR
></TABLE
><P
>The pixel macros should normally be avoided. Determining the correct
location within framebuffer memory corresponding to a set of
coordinates for each pixel is a comparatively expensive operation.
Instead there is direct support for <A
HREF="framebuf-iterating.html"
>iterating</A
> over parts of the
display, avoiding unnecessary overheads.
</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="FRAMEBUF-DRAWING-LINES"
></A
><H2
>Drawing Simple Lines</H2
><P
>Higher-level graphics code often needs to draw single-pixel horizontal
and vertical lines. If the application involves multiple windows then
these will usually have thin borders around them. Widgets such as
buttons and scrollbars also often have thin borders.
</P
><P
><CODE
CLASS="FUNCTION"
>cyg_fb_draw_hline</CODE
> and
<CODE
CLASS="FUNCTION"
>CYG_FB_DRAW_HLINE</CODE
> draw a horizontal line of the
specified <CODE
CLASS="PARAMETER"
>colour</CODE
>, starting at the
<CODE
CLASS="PARAMETER"
>x</CODE
> and <CODE
CLASS="PARAMETER"
>y</CODE
> coordinates and
extending to the right (increasing x) for a total of
<CODE
CLASS="PARAMETER"
>len</CODE
> pixels. A 50 pixel line starting at
(100,100) will end at (149,100).
</P
><P
><CODE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?