Raster Scan Displays. Framebuffer (Black and White)

Similar documents
Scan Converting Lines

CS 543: Computer Graphics. Rasterization

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

1 Introduction to Graphics

Scan Conversion. Drawing Lines Drawing Circles

Rasterization: Geometric Primitives

Topic #1: Rasterization (Scan Conversion)

Display Technologies: CRTs Raster Displays

Rendering. A simple X program to illustrate rendering

COMP371 COMPUTER GRAPHICS

Chapter 8: Implementation- Clipping and Rasterization

Overview of Computer Graphics

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

Rasterization, or What is glbegin(gl_lines) really doing?

Output Primitives. Dr. S.M. Malaek. Assistant: M. Younesi

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

? Which intermediate. Recall: Line drawing algorithm. Programmer specifies (x,y) of end pixels Need algorithm to determine pixels on line path

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

Computer Graphics Lecture Notes

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization.

From Ver(ces to Fragments: Rasteriza(on

CPSC / Scan Conversion

CS 4731/543: Computer Graphics Lecture 7 (Part I): Raster Graphics: Polygons & Antialiasing. Emmanuel Agu

Surface shading: lights and rasterization. Computer Graphics CSE 167 Lecture 6

Computer Graphics CS 543 Lecture 11 (Part 1) Polygon Filling & Antialiasing

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

Line Drawing Week 6, Lecture 9

Agenda. Polygon Terminology Types of polygons Inside Test Polygon Filling Algorithms. Scan-Line Polygon Fill Algorithm Flood-Fill Algorithm

Scan Conversion. Lines and Circles

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

Rendering. A simple X program to illustrate rendering

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

Computer Graphics. - Rasterization - Philipp Slusallek

Einführung in Visual Computing

R asterisation. Part I: Simple Lines. Affine transformation. Transform Render. Rasterisation Line Rasterisation 2/16

Points and lines. x x 1 + y 1. y = mx + b

Painter s HSR Algorithm

Graphics (Output) Primitives. Chapters 3 & 4

Computer Graphics D Graphics Algorithms

MODULE - 4. e-pg Pathshala

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

Chapter 3. Sukhwinder Singh

Computer Graphics Solved MCQs -Part 2 MCQs Questions

Rasterization. CS4620/5620: Lecture 12. Announcements. Turn in HW 1. PPA 1 out. Friday lecture. History of graphics PPA 1 in 4621.

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

(Refer Slide Time: 00:03:51)

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

CS Rasterization. Junqiao Zhao 赵君峤

Computer Graphics. Modelling in 2D. 2D primitives. Lines and Polylines. OpenGL polygon primitives. Special polygons

Graphics System. Processor. Output Display. Input Devices. Frame Buffer. Memory. Array of pixels. Resolution: # of pixels Depth: # of bits/pixel

CS602 MCQ,s for midterm paper with reference solved by Shahid

Computer Graphics D Graphics Algorithms

Rasteriza2on and Clipping

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

Department of Computer Sciences Graphics Fall 2003 (Lecture 2) Pixels

CS 130. Scan Conversion. Raster Graphics

Chapter - 2: Geometry and Line Generations

Pipeline and Rasterization. COMP770 Fall 2011

Computer Graphics and GPGPU Programming

CS488 2D Graphics. Luc RENAMBOT

Rasterization. CS4620 Lecture 13

Rasterization. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 16

Pipeline implementation II

SE Mock Online Test 1-CG

Shading Techniques Denbigh Starkey

UNIT 2 GRAPHIC PRIMITIVES

Graphics Hardware and Display Devices

Line Drawing. Foundations of Computer Graphics Torsten Möller

EF432. Introduction to spagetti and meatballs

Topic 0. Introduction: What Is Computer Graphics? CSC 418/2504: Computer Graphics EF432. Today s Topics. What is Computer Graphics?

Raster Displays and Scan Conversion. Computer Graphics, CSCD18 Fall 2008 Instructor: Leonid Sigal

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

Attributes of Graphics Primitives

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Graphics Overview ECE2893. Lecture 19. ECE2893 Graphics Overview Spring / 15

Rasterization. COMP 575/770 Spring 2013

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

(Refer Slide Time: 9:36)

Computer Graphics: 6-Rasterization

CSCI 420 Computer Graphics Lecture 14. Rasterization. Scan Conversion Antialiasing [Angel Ch. 6] Jernej Barbic University of Southern California

EF432. Introduction to spagetti and meatballs

Unit 2 Output Primitives and their Attributes

Rasterization. Rasterization (scan conversion) Digital Differential Analyzer (DDA) Rasterizing a line. Digital Differential Analyzer (DDA)

CS6504 & Computer Graphics Unit I Page 1

Programming Fundamentals

CS475m - Computer Graphics. Lecture 1 : Rasterization Basics

Solution Notes. COMP 151: Terms Test

Output Primitives Lecture: 4. Lecture 4

Fall CSCI 420: Computer Graphics. 7.1 Rasterization. Hao Li.

CS602- Computer Graphics Solved MCQS From Midterm Papers. MIDTERM EXAMINATION Spring 2013 CS602- Computer Graphics

CS 325 Computer Graphics

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

... Output System Layers. Application 2. Application 1. Application 3. Swing. UIKit SWT. Window System. Operating System

2D Image Synthesis. 2D image synthesis. Raster graphics systems. Modeling transformation. Vectorization. u x u y 0. o x o y 1

Efficient Plotting Algorithm

Computer Graphics. Chapter 4 Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

Graphics Pipeline 2D Geometric Transformations

Transcription:

Raster Scan Displays Beam of electrons deflected onto a phosphor coated screen Phosphors emit light when excited by the electrons Phosphor brightness decays -- need to refresh the display Phosphors make up screen elements called pixels CS148 Lecture 2 slide 1 Framebuffer (Black and White) Store picture of the display in a special memory called the framebuffer One bit per pixel - bit is 1 if pixel is white, 0 if it is black Display controller keeps reading from the framebuffer Turn on the electron gun if the bit is 1, don t if it s 0 000101 CS148 Lecture 2 slide 2 1

Framebuffer (Color) Use more than one bit per pixel (usually 8-32 bits, but sometimes more) Three electron guns simultaneously stimulate three kinds of phosphors: red, green, and blue How do we represent color in the framebuffer? CS148 Lecture 2 slide 3 Direct Color Framebuffer Store the actual intensities of R, G, and B individually in the framebuffer 24 bits per pixel = 8 bits red, 8 bits green, 8 bits blue 16 bits per pixel =? bits red,? bits green,? bits blue DAC CS148 Lecture 2 slide 4 2

Color Lookup Framebuffer Store indices (usually 8 bits) in framebuffer Display controller looks up the R,G,B values before triggering the electron guns DAC Color indices CS148 Lecture 2 slide 5 Drawing Most computer generated images made up of geometric primitives (polygons, lines, points) Application draws them by setting bits in the framebuffer Most graphics applications involve scene database management Scene Database Graphics Application Device Driver Framebuffer Display CS148 Lecture 2 slide 6 3

A DDA Line Drawing Function Line(int x1, int y1, int x2, int y2) int dx = x1 - x2, dy = y2 - y1; int n = max(abs(dx),abs(dy)); float dt = n, dxdt = dx/dt, dydt = dy/dt; float x = x1, y = y1; while (n--) DrawPoint( round(x), round(y) ); x += dxdt; y += dydt; What s bad about this? CS148 Lecture 2 slide 7 We Can Do Better Than That... Get rid of all those nasty floating point operations The idea: find the next pixel from the current one So which of the green pixels is next? CS148 Lecture 2 slide 8 4

The Key We re only ever going to go right one pixel, or up and right one pixel (if the slope of the line is between 0 and 1). Call these two choices E and NE Let s think of pixels as lattice points on a grid Given an X coordinate, we only need to choose between y and y+1 (y is the Y coordinate of the last pixel) CS148 Lecture 2 slide 9 The Midpoint Test Look at the vertical grid line that our line intersects On which side of the midpoint (y+1/2) does the intersection lie? If it s above the midpoint, go NE, otherwise go E CS148 Lecture 2 slide 10 5

Our Example y+3 y+2 y+1 y x x+1 x+2 x+3 x+4 x+5 x+6 x+7 CS148 Lecture 2 slide 11 Implicit Functions Normally, a line is defined as Instead, define F x, y = ax + by + be everywhere where F x, y = ( ) 0 ( ) 0 Now, if F F x, y < y = mx+ b ( ) c ( ) 0, and let the line x, y >, we re above the line, and if, we re below the line CS148 Lecture 2 slide 12 6

Who Cares? We can evaluate the implicit line function at the midpoint to figure out where to draw next! In fact, we can use the last function evaluation to find the next one cheaply! For ANY x, y: F( x + 1, y) F( x, y) = a F( x + 1, y + 1) F( x, y) = a + b CS148 Lecture 2 slide 13 Midpoint Algorithm Line(int x1, int y1, int x2, int y2) int dx = x2 - x1, dy = y2 - y1; int e = 2*dy - dx; int incre = 2*dy, incrne = 2*(dy-dx); int x = x1, y = y1; DrawPoint( x, y ); while (x < x2) x++; if ( e <= 0 ) e += incre; else y++; e += incrne; DrawPoint( x, y ); e holds the implicit function evaluation at each x value (actually, it s multiplied by 2, but all we care about is the sign). Easy extension for lines with arbitrary slopes. CS148 Lecture 2 slide 14 7

Midpoint Algorithm for Circles Only consider the second octant (the others are symmetric anyhow) Midpoint test still works: do we go right, or right and down? E SE CS148 Lecture 2 slide 15 More Midpoint Circle Drawing The circle s implicit function (r is the radius): 2 2 F( x, y) = x + y 2 r Once we know the value of the implicit function at one midpoint, we can get the value at the next midpoint by the same differencing technique: If we re going E: F ( x + 2, y) F( x + 1, y) = 2x + 3 ( ) ( ) ( ) 5 If we re going SE: F x + 2, y 1 F x + 1, y = 2 x y + CS148 Lecture 2 slide 16 8

Drawing the 2 nd Octant void Circle( int cx, int cy, int radius ) int x = 0, y = radius, e = 1-radius; DrawPoint( x + cx, y + cy ); while (y > x) if (e < 0) // Go east e += 2*x + 3; else // Go south-east e += 2*(x-y) + 5; y--; x++; DrawPoint( x + cx, y + cy ); Look at all those expensive multiplies! Can we get rid of them too? How about doing finite differencing on the e variable itself? If we go E: e new e old = 2 If we go SE: e new e = 4 old CS148 Lecture 2 slide 17 Final Circle Drawer void Circle( int cx, int cy, int radius ) int x = 0, y = radius, e = 1-radius; int incre = 3, incrse = -2*radius + 5 DrawPoint( x + cx, y + cy ); while (y > x) if (e < 0) // Go east e += incre; incre += 2; incrse += 2; else // Go south-east e += incrse; incre += 2; incrse += 4; y--; x++; DrawPoint( x + cx, y + cy ); This looks pretty fast! CS148 Lecture 2 slide 18 9

Flood Fill The idea: fill a connected region with a solid color Term definitions: 8 4 8 4 8 1 4 4 8 The center 1 pixel is 4-connected to the pixels marked 4, and 8-connected to the pixels marked 8 CS148 Lecture 2 slide 19 Simple 4-connected Fill The simplest algorithm to fill a 4-connected region is a recursive one: FloodFill( int x, int y, int inside_color, int new_color ) if (GetColor( x, y ) == inside_color) SetColor( x, y, new_color ); FloodFill( x+1, y, inside_color, new_color ); FloodFill( x-1, y, inside_color, new_color ); FloodFill( x, y+1, inside_color, new_color ); FloodFill( x, y-1, inside_color, new_color ); Surely we can do better than this! (What s the fundamental problem with this approach?) CS148 Lecture 2 slide 20 10

CS148 Lecture 2 slide 21 A Span-based Algorithm Definition: a run is a horizontal span of identically colored pixels c b h d g f e i Start at pixel s, the seed. Find the run containing s ( b to a ). Fill that run with the new color. Then search every pixel above that run, looking for other pixels of the interior color. For each one found, find the right side of that run ( c ), and push that on a stack. Do the same for the pixels below ( d ). Then pop the stack and repeat the procedure with the new seed. The algorithm finds runs ending at e, f, g, h, and i s a 11