Unformatted text preview:

CS 686: Programming SuperVGA Graphics DevicesRaster Display TechnologySpecial “dual-ported” memoryGraphics programsHow much VRAM is needed?How ‘truecolor’ worksIntel uses “little-endian” orderSome operating system issuesVGA ROM-BIOSWhat is ‘int86.cpp’?In-class demo: ‘pcxphoto.cpp’Typical ‘program-structure’Hardware InitializationObtaining our image-dataBitMaP (.bmp) file-formatPiCture eXchange (.pcx) formatRun-Length Encoding (RLE)How RLE-compression worksDecompression AlgorithmStandard I/O LibraryWhere shall VRAM go?Virtual Memory LayoutHow to compile our demoProgramming Project #1Exercise: Color-to-GrayscaleColor-conversion AlgorithmIn-class exerciseCS 686: Programming SuperVGA Graphics DevicesIntroduction: An exercise in working with graphics file formatsRaster Display TechnologyThe graphics screen is a two-dimensional array of picture elements (‘pixels’)Each pixel’s color is an individually programmable mix of red, green, and blueThese pixels are redrawn sequentially, left-to-right, by rows from top to bottomSpecial “dual-ported” memoryVRAMRAMCPUCRT16-MB of VRAM2048-MB of RAMGraphics programs•What a graphics program must do is put appropriate bit-patterns into the correct locations in the VRAM, such that the CRT will show an array of colored dots which in some way is meaningful to the human eye •So the programmer must understand what the CRT will do with the contents of VRAMHow much VRAM is needed?•This depends on (1) the total number of pixels, and on (2) the number of bits-per-pixel •The total number of pixels is determined by the screen’s width and height (measured in pixels)•Example: when our “screen-resolution” is set to 1280-by-960, we are seeing 1,228,800 pixels•The number of bits-per-pixel (“color depth”) is a programmable parameter (varies from 1 to 32)•Certain types of applications also need to use extra VRAM (for multiple displays, or for “special effects” like computer game animations)How ‘truecolor’ worksRBGalpha red green blue081624pixellongwordThe intensity of each color-component within a pixel is an 8-bit valueIntel uses “little-endian” orderB G R B G R B G RVRAM0 1 2 3Video Screen4 5 6 7 8 9 10Some operating system issues•Linux is a “protected-mode” operating system•I/O devices normally are not directly accessible •On Pentiums: Linux uses “virtual memory” •Privileged software must “map” the VRAM•A device-driver module is needed: ‘vram.c’•We can compile it using: $ mmake vram•Device-node: # mknod /dev/vram c 99 0•Make it ‘writable’: # chmod a+w /dev/vramVGA ROM-BIOS•Our graphics hardware manufacturer has supplied accompanying code (‘firmware’) that ‘programs’ VGA device components to operate in various ‘standard’ modes•But these firmware routines were not written with Linux in mind: they’re for interfacing with ‘real-mode’ MS-DOS•So special software is needed: ‘int86.cpp’What is ‘int86.cpp’?•This is ‘boilerplate’ code that we can ‘link’ with all of our Linux graphics applications •It invokes some kernel services provided by our ‘dosio.c’ device-driver which set up a ‘pre-boot execution-environment’ (PXE) allowing Linux to run firmware-routines in ‘virtual-8086’ mode (via the ‘vm86()’ call) •Later we will discuss how it works, but for now we just use it to get on with our demoIn-class demo: ‘pcxphoto.cpp’•First: several system-setup requirements•Some steps need ‘root’ privileges (or ‘sudo’)•Create device-nodes in ‘/etc/udev/devices’: –‘/etc/udev/devices/dos’ (read-only) –‘/etc/udev/devices/vram’ (read/write)•Restart Linux in ‘text mode’ (GRUB boot-menu)•Obtain demo sources from our class website•Compile and install our character-mode Linux device-driver modules: ‘dosio.c’ and ‘vram.c’Typical ‘program-structure’Usual steps within a graphics application:– Initialize video system hardware– Display some graphical imagery– Wait for a termination condition– Restore original hardware stateHardware Initialization•The VGA system has over 300 registers •They must be individually reprogrammed •Eventually we shall study those registers•For now, we just ‘reuse’ vendor routines•Such routines are built into VGA firmware•But invoking them isn’t trivial (since they weren’t designed for a Linux environment)Obtaining our image-data•Eventually we want to ‘compute’ images•For now, we ‘reuse’ pre-computed data•Data was generated using an HP scanner•It’s stored in a standard graphic file-format•Lots of different graphic file-formats exist•Some are ‘proprietary’ (details are secret)•Other formats are public (search the web)BitMaP (.bmp) file-formatFILE HEADERINFO SECTIONOptional color paletteIMAGEDATA(usually uncompressed)This is an image-format often used by Microsoft WindowsPiCture eXchange (.pcx) format FILE HEADER (128 bytes)IMAGEDATA(compressed)COLOR PALETTE(768 bytes)Run-Length Encoding (RLE)•A simple technique for ‘data-compression’•Well-suited for compressing images, when adjacent pixels often have the same colors•Without compression, a computer graphics image-file (for SuperVGA) would be BIG!•Exact size depends on screen-resolution•Also depends on the display’s color-depth •(Those parameters are programmable)How RLE-compression worksIf multiple consecutive bytes are identical:example: 0x29 0x29 0x29 0x29 0x29(This is called a ‘run’ of five identical bytes)We “compress” five bytes into two bytes:the example compressed: 0xC5 0x29Byte-pairs are used to describe ‘runs’: Initial byte encodes a ‘repetition-count’(The following byte is the actual data)Decompression Algorithmint i = 0;do { read( fd, &dat, 1 ); if ( dat < 0xC0 ) reps = 1; else { reps = (dat & 0x3F); read( fd, &dat, 1 ); } do { image[ i++ ] = dat; } while ( --reps );}while ( i < npixels );Standard I/O Library•We call standard functions from the C/C++ runtime library to perform i/o operations on a device-file (e.g., vram): open(), read(), write(), lseek(), mmap() •The most useful operation is ‘mmap()’•It lets us ‘map’ a portion of VRAM into the address-space of our graphics application•So we can ‘draw’ directly onto the screen!Where shall VRAM go?•We decide to use graphics mode 0x0121•It’s a ‘truecolor’


View Full Document

USF CS 686 - Super VGA Graphics Devices

Documents in this Course
Load more
Download Super VGA Graphics Devices
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Super VGA Graphics Devices and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Super VGA Graphics Devices 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?