1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.6 [en] (X11; I; Linux 2.2.9-19mdk i586) [Netscape]">
</head>
<body>
<center><font size=+2>MiGS Overview</font>
<br><font size=+2>A Minimalist Graphics Subsystem</font>
<p>
<hr WIDTH="100%"></center>
<h1>
<font size=+0>Introduction</font></h1>
<blockquote>This document details the design and implementation of MiGS,
the minimalist graphics subsystem used by the FreeType 2 demonstration
programs. Its purpose is mainly to help writers of new demo programs, as
well as developers who would like port the subsystem to other platforms.</blockquote>
<hr WIDTH="100%">
<h1>
I - Design goals</h1>
<blockquote>MiGS is a tiny graphics subsystem used to demo text rendering
through the FreeType library. It was mainly written to provide the abilities
to :</blockquote>
<ul>
<ul>
<li>
draw a monochrome glyph bitmap to many kinds of target surfaces (i.e. really
bitmaps/pixmaps)</li>
<li>
draw an anti-aliased glyph bitmap, with any level of grays, to many kinds
of target surfaces</li>
<li>
display a simple window on many systems like X11, OS/2 and Windows</li>
<li>
accept simple events (keypresses and mouse buttons) in this window.</li>
<li>
to be portable and present a unified API on all running systems</li>
</ul>
<p><br>MiGS uses system-specific "drivers" in order to perform display
and event handling. The blitting functions are not device-specific. MiGS
can be built and/or used with no system-specific features, like for example,
to generate simple GIF, PNG, TIFF, etc.. images without ever needing to
display them.</ul>
<h1>
<hr WIDTH="100%"></h1>
<h1>
II - Surfaces, bitmaps and windows</h1>
<blockquote>A surface in MiGS models a drawable region where glyph images
can be rendered, a surface always contains a bitmap descriptor as well
as a few other things that will be described later in this section.
<p>Some surfaces can be displayed, they are then either called <i>windowed
surfaces</i> or <i>screen surfaces</i> depending on the nature of the <i>device</i>
used to display them. Each <i>device</i> is implemented by a very simple
<i>driver</i> in the MiGS code. Here are a few example devices that are
or could be written to display surfaces :
<p>- an X11 device
<br>- a Win 32 GDI device
<br>- an OS/2 Presentation Manager device
<br>- a fullscreen SVGALib device on Linux
<br>- a GGI visual device
<br>- an OS/2 "Dive" device, or the equivalent Win32 "DirectX" device
<p>etc..
<p><b>NOTE: </b>For now, only the X11 device was written and tested.. More
devices should come later
<p>Before explaining how to create a surface, we need to explain how MiGS
manages bitmaps and renders glyph images to them.
<h3>
1. Bitmaps :</h3>
<blockquote>A bitmap in MiGS features the following things :
<ul>
<li>
a <b><i>width</i></b> in pixels</li>
<li>
a <b><i>height</i></b> in pixels</li>
<li>
a <b><i>pixel mode</i></b>, which indicates how the pixels are stored in
the surface's buffer</li>
<li>
a <b><i>pitch</i></b>, whose absolute values is the number of bytes taken
by each surface row</li>
<li>
a <b><i>number</i></b> of valid <b><i>gray</i></b> levels (see below)</li>
<li>
a <b><i>buffer</i></b>, holding the surface's pixels</li>
</ul>
<p><br>MiGS uses the <i>"Y downwards"</i> convention, which means that
<i>increasing
Y</i> coordinates correspond to <i>lower rows</i> of the bitmap. Hence,
the coordinate <i>(0,0)</i> always corresponds to the bitmap's
<i>top-left
pixel</i>.
<p>The bitmap's rows can be stored either <i>"downwards"</i> or <i>"upwards"</i>
in the pixel buffer.
<p>In the first case (<i>downwards</i>), increasing memory addresses in
the pixel buffer correspond to lower rows of the bitmap(e.g. PC video modes),
and the <b><i>pitch</i></b> should be equal to <b><i>the number of bytes
taken by each row</i></b>. The first pixel buffer byte corresponds to the
upper row.
<p>In the second case (<i>upwards</i>), increasing memory addresses in
the pixel buffer correspond to upper rows of the bitmap and the <b><i>pitch</i></b>
should be equal to the <b><i>opposite</i></b> of <i>the number of bytes
taken by each row</i>. The first pixel buffer byte corresponds to the lower
row.
<p>In all cases, the <b><i>pitch</i></b> is the <i>increment to be used
to go from one bitmap row to the one below it</i>.
<p>The supported pixel modes are :
<ul>
<li>
1-bit monochrome bitmaps. With "0" as the background, and "1" as the foreground.</li>
<li>
4-bit color bitmaps, using an arbitrary palette.</li>
<li>
8-bit color bitmaps, using an arbitrary palette.</li>
<li>
8-bit gray bitmaps, using a given N number of gray levels in the range
0..N-1.</li>
<li>
15-bit color bitmaps, also known as RGB555</li>
<li>
16-bit color bitmaps, also known as RGB565</li>
<li>
24-bit color bitmaps, also known as RGB</li>
<li>
32-bit color bitmaps, also known as RGBA (though the A is ignored by MiGS)</li>
</ul>
The bitmap's <b><i>number of gray levels</i></b> is only relevant for <b><i>8-bit
gray bitmaps</i></b>, and indicates the range of gray levels that can be
found in the bitmap. If a bitmap as N gray levels, it is said to be <i>N-grayscales</i>,
and the pixels within it must all have values between 0, considered as
the <i>background</i> color, and N-1, considered as the <i>foreground</i>
color.
<p>N-grayscale bitmaps are crucial for the rendering of anti-aliased text.
<br> </blockquote>
<h3>
2. Glyph images :</h3>
<blockquote>The glyph images that can be drawn on bitmaps through MiGS
are bitmaps themselves, though limited to the following pixel modes :
<p><b>1-bit monochrome glyph bitmaps</b>
<blockquote>These can be drawn on any kind of bitmap. Note that <i>only
the "lit" pixels</i> (i.e. the bits set to 1) are effectively drawn to
the target, as opaque blitting isn't supported (remember, it's a minimalist
library !)</blockquote>
<p><br><b>N-grayscales glyph images </b>(with any value of N >= 2)
<blockquote>These can be drawn to <i>all RGB bitmaps</i> (15, 16, 24 &
32 bits/pixel), as well as any other M-grayscales bitmaps. In the latter
case, the values of N and M <i>need not be equal</i>, as the library is
able to perform automatic conversions <i>on the fly</i>.
<p>For example, it is possible to render a 5-grayscales glyph image into
a 128-grayscales bitmap. Moreover, it is also possible to render a 17-grayscales
glyph image into a 5-grayscales bitmap, even if this will result in <i>a
loss of quality</i>. This feature is crucial in order to experiment easily
with other anti-aliasing algorithms for FreeType
<br> </blockquote>
Note that you can <i>only</i> draw <i>monochrome</i> bitmaps to the following
pixel modes : monochrome, 4-bit color and 8-bit color.</blockquote>
<h3>
3. Windows and Screens:</h3>
<blockquote>In order to debug FreeType, displaying a surface in a window
or in full-screen mode, is required. MiGS thus makes a difference between
<i>simple
surfaces</i>, which only contain a bitmap, <i>windowed surfaces</i>, which
are used to display their content in a window, and <i>screen surfaces</i>,
which are used to display their content in a full-screen mode (SVGAlib,
DirectX, GGI or wathever).
<p>A few important things must be said about non-simple surfaces.
<br>
<ul>
<li>
First, they might contain some system-specific data which is used to manage
the display in a window or on the screen. This must be <i>completely hidden</i>
to MiGS clients. Indeed, rendering to any kind of surface is achieved through
<i>exactly
the same function calls</i>.</li>
</ul>
<ul>
<li>
Second, they may contain a bitmap whose pixel mode doesn't correspond to
the screen's depth used to display it. For example, the surface might contain
an 128-grayscale bitmap, while the screen is in RGB24 mode. Some conversion
must be performed to display the surface. This can either happen in the
system-specific graphics library (e.g. on OS/2, a single Presentation Manager
call is used to blit a N-grayscale image to <i>any</i> kind of window)
or in the system-specific part of MiGS (e.g. the X11 MiGS driver must convert
the surface's bitmap into the appropriate <i>X11 image</i> each time a
repaint is requested). Again this must be completely hidden to MiGS clients</li>
</ul>
Surfaces have also a few fields that are only used when displaying them
in Windows :
<p><b>a title string</b>
<blockquote>This is simply a text string that is displayed on the title
bar of the surface's window. It can also appear at the top or bottom of
full-screen surfaces if the MiGS driver supports it. The title string can
be changed with a call to <tt>grSetTitle</tt>, and is ignored for simple
surfaces.</blockquote>
<p><br><b>a refresh flag</b>
<blockquote>This boolean flag is only used for window surfaces, and some
fullscreen ones (depending on the driver implementation). When set, it
indicates that each glyph image blit must be displayed immediately. By
default, this flag is set to False, which means that demo programs must
call the <tt>grRefreshSurface(surface)</tt> function to display the whole
contents of a surface one it has been updated.
<p>The refresh flag can be set with <tt>grSetSurfaceRefresh(surface,flag)</tt>.
Note that a single surface rectangle can be forced to be displayed with
a call to <tt>grRefreshRectangle(surface,x,y,w,h)</tt> at any time.</blockquote>
</blockquote>
<h3>
4. Devices :</h3>
<blockquote>As said before, each device is in charge of displaying a surface
in a given window or screen. Each device is managed through a very simple
driver, described to MiGS through a very simple "grDevice" structure.
<p>A grDevice contains, among other things, pointers to the functions used
to:
<p>- refresh/display a given rectangle of the surface to the window/screen
<br>- listen events (key presses and mouse) and send them back to client
apps.
<br>- for windowed devices, update the title bar.
<p>As said before, this is a highly minimalist system..
<br> </blockquote>
</blockquote>
<hr WIDTH="100%">
<h1>
III - Important implementation issues :</h1>
<blockquote>
<h3>
1. Display surface negociation :</h3>
<blockquote>A display surface is created with the function grNewScreenSurface
which takes parameters indicating which device should be used, the pixel
dimensions of the requested surface, as well as its pixel mode.
<p>Because of some device-specific limitations, the resulting surface's
properties might not match exactly those requested for the call. Hence,
a developper should <b>always take care </b>of reading a new display surface's
<b>bitmap</b> descriptor in order to get its <i>real</i> dimensions, pixel
mode and eventually number of grays.
<p>The function grNewSurface will create a memory surface with the corresponding
bitmap.
<br>The function grNewBitmapSurface will create a surface from a pre-existing
bitmap. This is useful to draw text on loaded images, for example.
<p>Any surface (display or not) is destroyed with grDoneSurface.</blockquote>
<h3>
</h3>
<h3>
2. Supporting 8-bit grayscale mode :</h3>
<blockquote>It is important, for the debugging of FreeType anti-aliased
renderer(s), that <b><i>_all_ devices should support the 8-bit gray mode</i></b>.
The number of gray levels can be fixed or negociated as required by implementation-specific
issues.
<p>As most existing devices do not provide direct support for such a mode,
each 8-bit surface must thus contain :
<p>- an internal N-grayscale bitmap, used as the target of all glyph drawings
<br>- its own device-specific "image", which matches the display depth.
<p>Each time the device's "refresh_rect" function is called, it should
then :
<br>- convert the grayscales within the bitmap's rectangle into the image's
buffer and format.
<br>- display the corresponding image rectangle.
<p>This scheme is used, for example, by the X11 device.</blockquote>
</blockquote>
</body>
</html>