CS 686: Programming SuperVGA Graphics Devices Introduction: An exercise in working with graphics file formats.

Slides:



Advertisements
Similar presentations
Lecture 2 Concepts, Terms and Definitions. Display Devices They are divided into a lot of small squares called pixels (“PICture ELements”). Each pixel.
Advertisements

Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
VGA Text Mode An introduction to font selection and to reprogramming of the Character Generator ram.
Operating-System Structures
CS 686: Programming SuperVGA Graphics Devices Introduction: An exercise in working with graphics file formats.
Programming Super-VGA Graphics Devices Introduction to VESA graphics modes and to organization of the linear frame-buffer memory.
The Linux PCI Interface An introduction to the PCI configuration space registers.
SiS 315 Graphics Engine Introduction to some capabilities of graphics accelerator hardware.
The CRT Controller How to modify CRTC registers to achieve a non-standard horizontal and vertical screen resolution.
Access to video memory We create a Linux device-driver that gives applications access to our graphics frame-buffer.
Direct I/O Programming An introduction to the Pentium’s mechanism for programming peripheral hardware components.
Graphics Bitmaps Drawing characters glyphs and multicolor patterns.
The ‘ioctl’ driver-function On implementing a way to query and modify our UART’s baudrate via the ‘device-file’ abstraction.
A device-driver for Video Memory Introduction to basic principles of the PC’s graphics display.
VGA Color Registers How we can reprogram the Digital-to-Analog Converter’s 256 color-table registers.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphicsIntroduction Dr. Eng. Farag Elnagahy
Image Representation.
Ch 1 Intro to Graphics page 1CS 367 First Day Agenda Best course you have ever had (survey) Info Cards Name, , Nickname C / C++ experience, EOS experience.
Last time 3 main components to a computer system Types of computers Talked about software – task oriented What are some kinds of data that a computer works.
Introduction to Computer Graphics
Digital Images. Scanned or digitally captured image Image created on computer using graphics software.
 Scanned or digitally captured image  Image created on computer using graphics software.
An Introduction to Scanning and Storing Photographs and Graphics Bryn Jones Aug 2002
1 Internet Graphics. 2 Representing Images  Raster Image: Images consist of “dots” of color, not lines  Pixel: Picture element-tiny rectangle  Resolution:
Data starts with width and height of image Then an array of pixel values (colors) The number of elements in this array is width times height Colors can.
Peripherals and Storage Looking at: Scanners Printers Why do we need storage devices anyway? What are magnetic disks? How do magnetic disks physically.
IE433 CAD/CAM Computer Aided Design and Computer Aided Manufacturing Part-2 CAD Systems Industrial Engineering Department King Saud University.
Prepared by George Holt Digital Photography BITMAP GRAPHIC ESSENTIALS.
Digital Images The digital representation of visual information.
1 Bitmap Graphics It is represented by a dot pattern in which each dot is called a pixel. Each pixel can be in any one of the colors available and the.
Unit 30 P1 – Hardware & Software Required For Use In Digital Graphics
COMP Bitmapped and Vector Graphics Pages Using Qwizdom.
File Formats About graphic file formats And image compression.
Lab #5-6 Follow-Up: More Python; Images Images ● A signal (e.g. sound, temperature infrared sensor reading) is a single (one- dimensional) quantity that.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Video Monitor Uses raster scanning to display images –Beam of electrons illuminates phosphorus dots on the screen called pixels. Starting at the top of.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
Bit-Mapped Graphic Data: Input (Capture) Hardware Multimedia – Section 2.
Laface Operating System Design Booting a PC to run a kernel from Low memory VGA display.
Digital Cameras And Digital Information. How a Camera works Light passes through the lens Shutter opens for an instant Film is exposed to light Film is.
Digital Darkroom I Theresa L. Ford. Objectives Basic Digital Image Terminology Screen Display of Pictures –Why are pictures too big for the screen? –Why.
Using HiColor graphics
Section 8.1 Create a custom theme Design a color scheme Use shared borders Section 8.2 Identify types of graphics Identify and compare graphic formats.
Information Processes and Technology Multimedia: Graphics.
GRAPHICS. Topic Outline What is graphic. Resolution. Types of graphics. Using graphic in multimedia applications.
CS- 375 Graphics and Human Computer Interaction Lecture 1: 12/4/1435 Fundamental Techniques in Graphics Lecturer: Kawther Abas.
ECE291 Lecture 12 Mode 13h Graphics. ECE 291 Lecture 12Page 2 of 27 Lecture outline Color theory Video Hardware Mode 13h Graphics File Formats.
1 © 2010 Cengage Learning Engineering. All Rights Reserved. 1 Introduction to Digital Image Processing with MATLAB ® Asia Edition McAndrew ‧ Wang ‧ Tseng.
ECE291 Computer Engineering II Lecture 15 Josh Potts University of Illinois at Urbana- Champaign.
Graphics An image is made up of tiny dots called pixels (“picture elements”) The resolution determines the.
 Scanned or digitally captured image  Image created on computer using graphics software.
Lecture 7: Intro to Computer Graphics. Remember…… DIGITAL - Digital means discrete. DIGITAL - Digital means discrete. Digital representation is comprised.
Digression on r/w ‘/proc’ files An application of kernel module programming to Super VGA graphics device control.
Image File Formats. What is an Image File Format? Image file formats are standard way of organizing and storing of image files. Image files are composed.
Image File Formats By Dr. Rajeev Srivastava 1. Image File Formats Header and Image data. A typical image file format contains two fields namely Dr. Rajeev.
Image Editing Vocabulary Words Pioneer Library System Norman Public Library Nancy Rimassa, Trainer Thanks to Wikipedia ( help.
Chapter 1 Definitions & Basics of Digital Image 1.Image 2.Digital Image 3.Raster 4. Vector 5.Image Editing 1.
Scanner Scanner Introduction: Scanner is an input device. It reads the graphical images or line art or text from the source and converts.
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
Lecture 11 Text mode video
By tom squire.  Graphic cards are made of millions of dots called pixels. Graphic cards take data from the CPU and turn it into a picture. At most common.
Software Design and Development Storing Data Part 2 Text, sound and video Computing Science.
8th Lecture – Intro to Bitmap or Raster Images
Hardware research By Hollie Willis.
Binary Representation in Audio and Images
Microprocessor and Assembly Language
LET’S LEARN ABOUT GRAPHICS!
Digital Images.
An Introduction to Scanning and Storing Photographs and Graphics
Multimedia System Image
Presentation transcript:

CS 686: Programming SuperVGA Graphics Devices Introduction: An exercise in working with graphics file formats

Raster Display Technology The graphics screen is a two-dimensional array of picture elements (‘pixels’) Each pixel’s color is an individually programmable mix of red, green, and blue These pixels are redrawn sequentially, left-to-right, by rows from top to bottom

Special “dual-ported” memory VRAM RAM CPU CRT 16-MB of VRAM 2048-MB of RAM

Graphics 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 VRAM

How 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’ works R B G alpharedgreenblue pixel longword The intensity of each color-component within a pixel is an 8-bit value

Intel uses “little-endian” order BGRBGRBGR VRAM Video Screen

Some 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/vram

VGA 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 demo

In-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 state

Hardware 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-format FILE HEADER INFO SECTION Optional color palette IMAGE DATA (usually uncompressed) This is an image-format often used by Microsoft Windows

PiCture eXchange (.pcx) format FILE HEADER (128 bytes) IMAGE DATA (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 works If 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 0x29 Byte-pairs are used to describe ‘runs’: Initial byte encodes a ‘repetition-count’ (The following byte is the actual data)

Decompression Algorithm inti = 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’ mode: 32 bits-per-pixel It uses a screen-resolution of 640x480 Size of VRAM needed: 640*480*4 bytes So we ‘map’ 2-MB of VRAM to user-space We can map it to this user address-range: 0xA xA

Virtual Memory Layout Linux kernel stack VRAM code and data runtime library 0x x xA xC user space (3GB) kernel space (1GB)

How to compile our demo The demo program is ‘pcxphoto.cpp’ It needs to include a header: ‘pcx.h’ It needs to read a datafile: ‘issxmas.pcx’ It needs to be linked with ‘int86.cpp’ It needs to include the header: ‘int86.h’ Compile it with the GNU C++ compiler: $ g++ pcxphoto.cpp int86.cpp –o pcxphoto

Programming Project #1 Write an analagous demo-program that will display an image in.bmp file-format The image-file is named ‘fwright.bmp’ You will need to utilize a different graphics display mode: 1024-by-768 (mode 0x123) You will need a different header: ‘bmp.h’ You will need a different image-algorithm

Exercise: Color-to-Grayscale Sometimes a color image needs to be converted into a ‘grayscale’ format Example: print a newspaper photograph (the printing press only uses ‘black’ ink) How can we ‘transform’ color photos into black-and-white format (shades of gray)? ‘gray’ colors use a mix of red+green+blue, these components have EQUAL intensity

Color-conversion Algorithm struct { unsigned char r, g, b; } color; int avg = ( 30*r + 49*g + 11*b )/100; color.r = avg; color.g = avg; color.b = avg; longpixel = 0; pixel |= ( avg << 16 );// r-component pixel |= ( avg << 8 );// g-component pixel |= ( avg << 0);// b-component vram[ address ] = pixel; // write to screen

In-class exercise Revise the ‘pcxphoto.cpp’ program so that it will display (1) the ‘color-table’, and then (2) the scanned photograph, as ‘grayscale’ images (i.e., different intensities of gray)