Subversion Repositories shark

Rev

Rev 1676 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1676 tullio 1
%----------------------------------------------------------------------------
2
\chapter{The Frame Buffer Library}
3
%----------------------------------------------------------------------------
4
 
5
The S.Ha.R.K. system provides support for all modern SVGA cards through the
6
Linux Frame Buffer driver. Using the \texttt{grx} graphic library upon it is
7
possible to draw points, lines, rectangles, boxes, circles, and text on 16 bit
8
per plane (bpp) SVGA graphic modes.
9
 
10
In order to use graphics, a program must include the
11
\texttt{drivers/shark\_fb26.h} header file. Then, it must initialize the Frame
12
Buffer using \texttt{FB26\_init()}. At this point the drawing library must be
13
connected to the frame buffer with the function \texttt{FB26\_use\_grx()}. Now a
14
graphic mode can be opened using \texttt{FB26\_setmode()}, and then the drawing
15
functions can be used. The \emph{num number}, needed as a parameter indicate
16
which frame buffer is used. At the end, the program can switch back to text mode
17
through \texttt{FB26\_close()}.
18
 
19
\vspace{7mm}
20
 
21
\begin{intest}
22
FB26\_INIT \index{FB26\_init()}
23
\end{intest}
24
 
25
\begin{description}
26
\item [\textbf{int FB26\_init(void);}]
27
\item [\textbf{Description:}] It initializes the rame buffer and internal data structures
28
to access the hardware. The function returns -1 on error, 0 otherwise. In order
29
to use the graphic primitives, a program must call this function.
30
\end{description}
31
 
32
\begin{intest}
33
FB26\_OPEN\index{fb26\_open()}
34
\end{intest}
35
 
36
\begin{description}
37
\item [\textbf{int FB26\_open(int num);}]
38
\item [\textbf{Description:}] Open the frame buffer number \texttt{num}. The function
39
returns -1 on error, 0 otherwise. The frame buffer must be already initialized
40
with \texttt{FB26\_init}.
41
\end{description}
42
 
43
\begin{intest}
44
FB26\_SETMODE\index{FB26\_setmode()}
45
\end{intest}
46
 
47
\begin{description}
48
\item [\textbf{int grx\_setmode(int num, unsigned chat *mode);}]
49
\item [\textbf{Description:}] It opens the graphic mode identified by the \texttt{mode}
50
parameter. The mode number can be obtained using \texttt{grx\_getmode()}. The
51
parameter \texttt{mode} is a string in the format
52
``\texttt{widthxheight-bpp}'' (ex. ``\texttt{640x480-16}''). If the mode is
53
supported and can be opened, the function returns 1, otherwise it returns -1.
54
\end{description}
55
 
56
\begin{intest}
57
FB26\_CLOSE\index{FB26\_close()}
58
\end{intest}
59
 
60
\begin{description}
61
\item [\textbf{int FB26\_close(int num);}]
62
\item [\textbf{Description:}] It closes the frame buffer \texttt{num} returning to text
63
mode.
64
\end{description}
65
 
66
%----------------------------------------------------------------------------
67
\section{The Frame Buffer graphics functions}
68
%----------------------------------------------------------------------------
69
 
70
The GRX library allows to use graphics with 16 bpp; the number of bits per
71
pixel, the graphic depth, determines the number of colors that can be
72
simultaneously displayed on a single screen. In 16 bpp modes, each pixel is
73
represented by two bytes. Since 16 is not divisible by 3, a component (the green
74
one) is described by 6 bits, whereas the other two are described by 5 bits. The
75
\texttt{RGB16()} macros help to code RGB values in a pixel value for all these
76
graph functions.
77
 
78
\vspace{7mm}
79
 
80
\begin{intest}
81
RGB16\index{rgb16()}
82
\end{intest}
83
 
84
\begin{description}
85
\item [\textbf{WORD rgb16(WORD r, WORD g, WORD b);}]
86
\item [\textbf{Description:}] It returns the color value defined by the 3 parameters
87
(\texttt{red}, \texttt{green} and \texttt{blue}) in the format required by
88
drawing function.
89
\end{description}
90
 
91
\begin{intest}
92
GRX\_CLEAR\index{grx\_clear()}
93
\end{intest}
94
 
95
\begin{description}
96
\item [\textbf{void grx\_clear(DWORD color);}]
97
\item [\textbf{Description:}] It clears the graphic screen by filling it with the color
98
specified in the parameter \texttt{color}.
99
\end{description}
100
 
101
\begin{intest}
102
GRX\_PLOT\index{grx\_plot()}
103
\end{intest}
104
 
105
\begin{description}
106
\item [\textbf{void grx\_plot(WORD x, WORD y, DWORD col);}]
107
\item [\textbf{Description:}] It draws a pixel of color \texttt{c} at coordinates
108
(\texttt{x},\texttt{y}) on the screen. For efficiency reasons no checks are
109
performed on \texttt{x} and \texttt{y}. Only the \texttt{bpp} less significative
110
bits of \texttt{col} are used (where \texttt{bpp} is the number of bits per
111
plane in the current graphic mode).
112
\end{description}
113
 
114
\begin{intest}
115
GRX\_GETPIXEL\index{grx\_getpixel()}
116
\end{intest}
117
 
118
\begin{description}
119
\item [\textbf{DWORD grx\_getpixel(WORD x, WORD y);}]
120
\item [\textbf{Description:}] It returns the color of pixel at coordinates
121
(\texttt{x}, \texttt{y}) on the screen. For efficiency reasons no checks are
122
performed on \texttt{x} and \texttt{y}. Only the \texttt{bpp} less significative
123
bits of the returned value are used (where \texttt{bpp} is the number of bits
124
per plane in the current graphic mode).
125
\end{description}
126
 
127
\begin{intest}
128
GRX\_PUTIMAGE\index{grx\_putimage()}
129
\end{intest}
130
 
131
\begin{description}
132
\item [\textbf{void grx\_putimage(WORD x1, WORD y1, WORD x2, WORD y2, WORD *img);}]
133
\item [\textbf{Description:}] It writes a rectangular bitmap from system memory to video
134
memory. (\texttt{x1}, \texttt{y1}) is the top left corner, while
135
(\texttt{x2},\texttt{y2}) is the right bottom corner. It fills the specified box
136
with the data in the buffer pointed by \texttt{*img}. The memory buffer must
137
contain the pixels in the same representation used in the video memory, starting
138
at the top left corner, from left to right, and then, line by line, from up to
139
down, without any gaps and interline spaces.
140
\item [See also:] \texttt{grx\_getimage()}.
141
\end{description}
142
 
143
\begin{description}
144
\item [Example:]
145
\end{description}
146
 
147
 
148
\begin{tt}
149
\begin{verbatim}
150
BYTE videobuff[200][200];
151
...
152
 
153
void *videotask(void *arg) {
154
    int done = 0;
155
    ...
156
 
157
    while (!done) {
158
        done = decodeframe(videobuff, 200, 200);
159
        grx_put(X, Y, X + 200, Y + 200, videobuff);
160
        task_endcycle();
161
    }
162
}
163
\end{verbatim}
164
\end{tt}
165
 
166
\begin{intest}
167
GRX\_GETIMAGE\index{grx\_getimage()}
168
\end{intest}
169
\begin{description}
170
\item [\textbf{void grx\_getimage(WORD x1, WORD y1, WORD x2, WORD y2, WORD *img);}]
171
\item [\textbf{Description:}] It reads a rectangular bitmap from video memory to system
172
memory. (\texttt{x1}, \texttt{y1}) is the top left corner, while
173
(\texttt{x2},\texttt{y2}) is the right bottom corner. It fills the specified
174
buffer pointed by \texttt{*img} with the data contained in the selected video
175
box. The memory buffer must be large enough to contain the box (in general, the
176
correct buffer dimension is $(y2-y1+1)*(x2-x1+1)*bpp$).
177
\item [See]\textbf{also}: \texttt{grx\_putimage()}.
178
\end{description}
179
 
180
\begin{intest}
181
GRX\_RECT\index{grx\_rect()}
182
\end{intest}
183
 
184
\begin{description}
185
\item [\textbf{int grx\_rect(WORD x1, WORD y1, WORD x2, WORD y2, DWORD col);}]
186
\item [\textbf{Description:}] It draws an empty rectangle with top left corner at
187
(\texttt{x1},\texttt{y1}) and bottom right corner at (\texttt{x2},\texttt{y2}).
188
The rectangle is drawn with color \texttt{col}.
189
\end{description}
190
 
191
\begin{intest}
192
GRX\_BOX\index{grx\_box()}
193
\end{intest}
194
 
195
\begin{description}
196
\item [\textbf{int grx\_box(WORD x1, WORD y1, WORD x2, WORD y2, DWORD col);}]
197
\item [\textbf{Description:}] It draws a filled rectangle with top left corner at
198
(\texttt{x1},\texttt{y1}) and bottom right corner at (\texttt{x2},\texttt{y2}).
199
The box is drawn with color \texttt{col}.
200
\end{description}
201
 
202
\begin{intest}
203
GRX\_LINE\index{grx\_line()}
204
\end{intest}
205
 
206
\begin{description}
207
\item [\textbf{void grx\_line(WORD x1, WORD y1, WORD x2, WORD y2, DWORD col);}]
208
\item [\textbf{Description:}] It draws a line from (\texttt{x1}, \texttt{y1}) to
209
(\texttt{x2},\texttt{y2}) using color \texttt{col}.
210
\end{description}
211
 
212
\begin{intest}
213
GRX\_TEXT\index{grx\_text()}
214
\end{intest}
215
 
216
\begin{description}
217
\item [\textbf{void grx\_text(char *text, WORD x, WORD y, DWORD fg, DWORD bg);}]
218
\item [\textbf{Description:}] It writes a 0 terminated text string in graphic mode at
219
position (\texttt{x},\texttt{y}). The string is pointed by \texttt{text},
220
\texttt{fg} is the foreground color, and \texttt{bg} is the background color.
221
\end{description}
222
 
223
\begin{intest}
224
GRX\_CIRCLE\index{grx\_circle()}
225
\end{intest}
226
 
227
\begin{description}
228
\item [\textbf{void grx\_circle(WORD x, WORD y, WORD r, DWORD col);}]
229
\item [\textbf{Description:}] It draws a circle of radius \texttt{r} and color
230
\texttt{col}, centered at (\texttt{x}, \texttt{y}).
231
\end{description}
232
 
233
\begin{intest}
234
GRX\_DISC\index{grx\_disc()}
235
\end{intest}
236
 
237
\begin{description}
238
\item [\textbf{void grx\_disc(WORD x, WORD y, WORD r, DWORD col);}]
239
\item [\textbf{Description:}] It draws a filled circle of radius \texttt{r} and color
240
\texttt{col}, centered at (\texttt{x}, \texttt{y}).
241
\end{description}