Graphics Dr. Dimitrios S. Nikolopoulos CSL/UIUC

Slides:



Advertisements
Similar presentations
Information Representation
Advertisements

DOS and BIOS Interrupts DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from.
Dale & Lewis Chapter 3 Data Representation. Representing color Similarly to how color is perceived in the human eye, color information is encoded in combinations.
Bits are Not just for Numbers or Characters Computers store characters as bits or binary digits. Characters from the English-language keyboard can be represented.
Bits are Not just for Numbers Computers store characters as bits or binary digits. Characters from the English-language keyboard are represented in ASCII.
Graphics File Formats. 2 Graphics Data n Vector data –Lines –Polygons –Curves n Bitmap data –Array of pixels –Numerical values corresponding to gray-
Images: Pixels and Resolution Monica A. Stoica, Boston University Books used: “The Essential Guide to Computing” by E. Garrison Walters.
Image Representation CS105. Data Representation Text representation – ASCII character set – Unicode – Data compression Images!
Introduction to Computer Graphics
How Images are Represented Bitmap images (Dots used to draw the image) Monochrome images 8 bit grey scale images 24 bit colour Colour lookup tables Vector.
File Formats By Jack Turner. Raster (Bitmap) Raster or bitmap is a dot matrix data structure, containing columns of dots and rows, of a graphics image.
09/12/02 (C) 2002, University of Wisconsin, CS 559 Last Time Color and Color Spaces –Recall RGB and XYZ Programming assignment 2.
1 Internet Graphics. 2 Representing Images  Raster Image: Images consist of “dots” of color, not lines  Pixel: Picture element-tiny rectangle  Resolution:
Digital Media Dr. Jim Rowan ITEC 2110 Color. COLOR Is a mess It’s a subjective sensation PRODUCED in the brain Color differs for light and paint/ink Printing.
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.
CS559-Computer Graphics Copyright Stephen Chenney Image File Formats How big is the image? –All files in some way store width and height How is the image.
Media File Formats Jon Ivins, DMU. Text Files n Two types n 1. Plain text (unformatted) u ASCII Character set is most common u 7 bits are used u This.
WEB GRAPHICS. The Pixel Computer displays are comprised of rows and columns of pixels. Pixels are indivisible. Some common screen resolutions are:, 600.
CS 1308 Computer Literacy and the Internet. Creating Digital Pictures  A traditional photograph is an analog representation of an image.  Digitizing.
COMP Bitmapped and Vector Graphics Pages Using Qwizdom.
Basics of a Computer Graphics System Introduction to Computer Graphics CSE 470/598 Arizona State University Dianne Hansford.
File Formats About graphic file formats And image compression.
ORG ; FOUR INT 21H and INT 10H Programming and Macros Dec Hex Bin
Module Code: CU0001NI Technical Information on Digital Images Week -2.
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.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 Adding some light to computing ….
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.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 14 Introduction to Computer Graphics.
Text-mode Video Dr. Dimitrios S. Nikolopoulos CSL/UIUC
Digital Media Dr. Jim Rowan ITEC 2110 Color. Question! Inside Photoshop and Gimp there are image filters that, among other things, allow you to blur the.
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.
Lab 8 Bit-Mapped Graphics Moving from text-based graphics to bit- mapped graphics. Easy to draw graphic points and lines using INT 10h, Function 0Ch (write.
Lecture 4 Pixels, Images and Image Files 1. In this Lecture, you will learn the following concepts: Image files (in particular, the BMP file format) How.
Text-Mode Programming Question #1 What are the three levels of access to the video display when writing characters on the screen in text mode?
Images 01/29/04 Resources: Yale Web Style Guide The GIF Controversy Unisys - lzw.
Information Processes and Technology Multimedia: Graphics.
1 Image Formats. 2 Color representation An image = a collection of picture elements (pixels) Each pixel has a “color” Different types of pixels Binary.
Introduction to Graphical Hardware Display Technologies
ECE291 Lecture 12 Mode 13h Graphics. ECE 291 Lecture 12Page 2 of 27 Lecture outline Color theory Video Hardware Mode 13h Graphics File Formats.
Optimizing Web Graphics Session #6 INP150. Image Types Types  Bitmap / Raster---dots  Bitmap images are made of individual pixels arranged in patterns.
Quiz # 1 Chapters 1,2, & 3.
ECE291 Computer Engineering II Lecture 15 Josh Potts University of Illinois at Urbana- Champaign.
Multimedia Basics (1) Hongli Luo CEIT, IPFW. Topics r Image data type r Color Model : m RGB, CMY, CMYK, YUV, YIQ, YCbCr r Analog Video – NTSC, PAL r Digital.
Video systems. Lesson plan Review the code for the previous exercise Video systems Review for midterm exam.
Lecture 7: Intro to Computer Graphics. Remember…… DIGITAL - Digital means discrete. DIGITAL - Digital means discrete. Digital representation is comprised.
DIGITAL IMAGE. Basic Image Concepts An image is a spatial representation of an object An image can be thought of as a function with resulting values of.
10H Interrupt. Option 0H – Sets video mode. Registers used: – AH = 0H – AL = Video Mode. 3H - CGA Color text of 80X25 7H - Monochrome text of 80X25 Ex:
Digital Images are represented by manipulating this…
4. Kernel and VGA ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  None.
Intelligent Robotics Today: Vision & Time & Space Complexity.
Image File Formats Harrow Computer Club – Wed, 1 Dec 2010 Bob Watson MA CMath MIMA MBCS.
Week 9 Monitors and output to the screen. Monitors, also known as Visual display units (V.D.Us) Desktop computers contain a Cathode Ray Tube (C.R.T.)
Chapter 3 Color Objectives Identify the color systems and resolution Clarify category of colors.
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
Lecture 11 Text mode video
Information in Computers. Remember Computers Execute algorithms Need to be told what to do And to whom to do it.
Computer Graphics CC416 Lecture 02: Overview of Graphics Systems: Raster & Random Displays – Chapter 2 Dr. Manal Helal – Fall 2014.
8th Lecture – Intro to Bitmap or Raster Images
Computer Graphics Lecture 3 Computer Graphics Hardware
Binary Notation and Intro to Computer Graphics
Vocabulary byte - The technical term for 8 bits of data.
Binary Representation in Audio and Images
Computer Science Higher
Vocabulary byte - The technical term for 8 bits of data.
Microprocessor and Assembly Language
MED 2001 Advanced Media Production
Digital Media Dr. Jim Rowan ITEC 2110 Color.
COMS 161 Introduction to Computing
COMS 161 Introduction to Computing
Presentation transcript:

Graphics Dr. Dimitrios S. Nikolopoulos CSL/UIUC Lecture 14 Graphics Dr. Dimitrios S. Nikolopoulos CSL/UIUC

Outline Color theory Video Hardware Mode 13h Graphics File Formats ECE291 Lecture 13

Color theory TV’s, Computer Monitors, Projectors… It’s all Red, Green, Blue Why RGB? These are the primary colors for visible light. You can get all the colors by mixing them. Red + Green = Yellow Green + Blue = Cyan Blue + Red = Purple ECE291 Lecture 13

Color Theory - Biology How can mixing a Low Frequency (red) with High Frequency (blue) make Really High Frequency (purple) ? It can’t according to the principles of signal processing. It is a biological phenomenon Our eyes have RGB sensors. These are the frequencies we can see best The people who invented color photography and color TV used this fact. ECE291 Lecture 13

Color Theory - Biology If three-eyed aliens with different color receptors visited us, they’d “see” the same three frequencies coming from the monitor, but they wouldn’t be able to see any pictures. Most SciFi movies forget that… The same goes for your dog that wonders why you spend hours looking at a blank screen. ECE291 Lecture 13

Full Color Images Each pixel has a RGB value. Color depth is defined by the number of bits used to assign colors to pixels Full color is when we use a given number of bits to specify the intensity of each color component. 24-bit color means 1 R byte, 1 G byte, 1 B byte. Each determines the color intensity (0 = none, 255 = full) 16-bit color means 5 bits red, 5 bits green, 5 bits blue. The extra bit is system-dependent. ECE291 Lecture 13

24-bit Full Color Images 24-bit color allows 256 different intensities for each color component. This allows for 224 or 16,777,216 different colors. That’s way more than our eyes can distinguish. You don’t need 16M colors to enjoy all this beauty in the world no matter what the produces of consumer electronics tell you… This 24-bit color is sometimes called Full or True color. True color requires 3 bytes for every pixel. ECE291 Lecture 13

16-bit Full Color Images 16-bit color allows 32 different intensities for each color component. This allows for 215 or 32,768 different colors (assuming 5 bits green) Not quite as good as True color, 16-bit color is also referred to as High color. High color requires 2 bytes for every pixel. ECE291 Lecture 13

Full Color Images Positives of high and true color images More colors means higher quality pictures Easier to do image manipulation (math) Make everything a little redder Blur an image by averaging RGB values of adjacent pixels Negatives of high and true color images Take up a lot more memory Ex: A 320x200 pixel image with 24-bit color needs 320 x 200 x 3 = 192,000 bytes of memory ECE291 Lecture 13

Color Palettes Unfortunately we’re still in real mode (1 Megabyte of memory no matter what…) While we’d like to do everything in full color, in real mode we need to reduce the amount of memory our images use. The color palette contains the 3-byte RGB values of 256 different colors. The image data is then just a bunch of indexes into this palette. It’s a look-up table! ECE291 Lecture 13

Color Palettes Positives of palettes Less memory and bandwidth needed to store and move pictures You can do some cool stuff with palettes Invisible pixels – assign one palette entry to be “clear” and when you’re copying one image over another, don’t copy the “clear” pixels. You can cycle the palette for 60’s psychedelic effects. You can fade out a screen just by subtracting from each entry in the palette table until they’re all zero ECE291 Lecture 13

Color Palettes Negatives of palettes Fewer colors (at most 256) mean lower quality pictures Harder to do manipulation Average blurring is harder because new color isn’t in palette All “real” pictures come in full color and have to be converted This is hard because you have to choose a good palette For each “full color” pixel, find closest palette entry When you put images together, they share the same palette ECE291 Lecture 13

Examples of using Palettes 8-bit (256-color) bitmap image (BMP) Each file has a specific format 56 bytes header 256*4 bytes color palette Each color has 3 RGB bytes and one clearness or unused byte 640*480*1 bytes of data 308,280 bytes 4-bit (16-color) bitmap image (BMP) 54 byte header 16*4 bytes color palette 640*480*0.5 bytes image data 153,720 bytes ECE291 Lecture 13

Text Mode Video Revisited Text mode video is like a form of palette Each ASCII byte is an index into a font table with a bitmap for each character Each Mode Byte is an index into a type of palette Or you can think of the mode byte as 3-bit full color (kind of) ECE291 Lecture 13

Video Hardware You’ve got a chunk of memory You write to the memory through memory mapped I/O (MP3) In a analog RGB monitor, three electron beams sweep across all rows 60 to 85 times a second to zap the phosphor elements to make them glow The video card adjusts the intensity of the three electron beams in real time as they are sweeping to correspond to the intensities specified in the VRAM ECE291 Lecture 13

Video Hardware To do this, the video card reads out a whole row of RGB values in the VRAM and shifts them “out” in a big shift register. The byte that “falls off the edge” gets converted into an intensity for the electron beam. With a palette, there is an additional step. Before data shifts out, it looks up the “real” RGB value in palette memory. Take a look at Windows->Control Panel->Display ECE291 Lecture 13

Mode 13h In mode 13h you draw graphics using palettes Mode 13h is a 320 x 200 x 256-color graphics display mode that was very popular for DOS programming due to its relatively high number of colors (256 vs 16 for other VGA modes) and simple addressing. 320 x 200 = 64000 pixels. With 1 byte per pixel this easily fits in a single real-mode segment. It’s linear just like text mode. The pixels increase in memory as you go from left to right, while each row immediately follows the previous one. Offset = row*320 + col ECE291 Lecture 13

Mode 13h - How to get there The following instructions get you into Mode 13h video mov ah, 0 ; int 10h’s set mode subfunction mov al, 13h ; The aptly named Mode 13h int 10h ; Call the Video BIOS interrupt ECE291 Lecture 13

Mode 13h How to draw a pixel The following instructions draw a pixel on the screen VidGrSeg equ 0A000h Location dw (200/2)*320+(320/2) ; Center Color db 98 ; Some random palette index mov ax, VidGrSeg mov es, ax ; Use extra segment to address VRAM mov bx, [Location] ; Offset to center of screen mov al, [Color] ; Palette Entry Number mov [es:bx], al ; Write it to the screen ECE291 Lecture 13

Default Palette Entries 0-15 are RGB colors [0,0,0,0,I,R,G,B] Entries 16-31 grayscale [0,0,0,1,g3,g2,g1,g0] Entries 32-255 contain user-defined colors ECE291 Lecture 13

Mode 13h How to change the palette Method 1: Load an entire palette Write 0 to port 3C7h Write red, green, blue bytes to port 3C9h for all 256 colors Method 2: Change just one palette entry using VBIOS call BX = Palette Number (0 – 255) CH = Green (0 – 63) CL = Blue (0 – 63) DH = Red (0 – 63) AX = 1010h ; Set VGA Palette Registers command INT 10h ; vBIOS call ECE291 Lecture 13

Mode 13h How to change the palette ; Change a palette entry to light purple Red db 39 Green db 0 Blue db 63 Mov bx, 0 ; changing palette entry 0 Mov ch, [Green] Mov cl, [Blue] Mov dh, [Red] Mov ax, 1010h Int 10h ECE291 Lecture 13

Notes on graphics modes Mode 13h is outdated but remained popular due to its advantages (standardized, linear accessing, does not consume a lot of memory etc.) Some efforts to standardize more high-resolution graphics did not succeed (VESA, DirectX) 13h appears to be your only option in real-mode for graphics ECE291 Lecture 13

Notes on graphics modes In protected mode you will be able to work with high-resolution graphics Although it would be possible to use one of the standards (VESA) it is much more convenient to use the ECE291 libraries (pmodelib) Many advantages Designed to work with protected mode Support for true color resolutions available on the video card Linear addressing, just like what you’ve learned in text-mode video and mode 13h ECE291 Lecture 13

Graphics File Formats Raster Formats Arrays of pixels (what we’ve been talking about) Raw pixels (.bmp) Run-Length encoding (.pcx) LZW encoding (.gif) Transform encoding (.jpg) Deflate (zip) compression (.png) ECE291 Lecture 13

Graphics File Formats Vector Formats Like PostScript or CorelDraw A vector file might have something like: “Draw line from (24, 56) to (87, 12)” “Here’s what an ‘A’ looks like….” “Not draw an ‘A’ at (75, 96)” Eventually converted to raster format by using a rasterizer Printers are very high resolution rasterizers (for example) ECE291 Lecture 13

Graphics File Formats Included in image files… Header: Most file formats start out with some kind of info about the image. For graphics files this info could be: Size (horizontal and vertical pixels) Color depth (bits per pixel) Version (makes life difficult…GIF89A, GIF97A, …) Compression Technique Palette: If you’re not using true color, you must include a palette for the image in the image file Data: Raw or compressed, raster or vector information. ECE291 Lecture 13

BMP 16 colors Header 118 bytes (54 for attributes, 64 for colors,4 per color) Example: 32x32 pixel image 118 bytes header 32x32x0.5 bytes per pixel=512 bytes data Image data goes backwards from bottom to top ECE291 Lecture 13

GIF and PNG GIF uses a compression algorithm patented by UNISYS If a program uses GIF compression it must get a license from UNISYS PNG requires no license, it uses the not patented ZIP compression format ECE291 Lecture 13

PCX Originally used for the PC paintbrush Run-length encoding Idea: Exploit the fact that many pictures have blobs of the same color We can encode by storing the color and how many times it is repeated on the screen (run length) Algorithm Read a byte If its two h.o bits are set it’s a length byte, read the length Next byte is a color byte so copy it length times to the screen Else, it is a color byte, copy it to the screen ECE291 Lecture 13

PCX problems What if you have a picture with a single color which starts with a 11 (like the length byte) You have to use the length byte (length=1) and then the color code So you actually occupy more room than needed Solution, put the colors that tend to be used as single colors towards the beginning of the palette in memory, so that their h.o. bits are 00 Read the lab manual ECE291 Lecture 13