(MC0072)computer graphic

29
Master of Computer Application (MCA) – Semester 3 MC0072 – Computer Graphics Que 1. Describe theory of development of hardware and software for computer graphics. Ans: Development of Hardware and Software for Computer Graphics The development of hardware of computer graphics involves the development of input and output device technology. Therefore, in all development of computer graphics involves the development in three fields: 1. Output technology 2. Input technology and 3. Software technology 1.6.1 Output Technology Fig. 1.3 shows the historical development in the output technology. In early days of computer the hardcopy devices such as teletype printer and line printer were in use with computer driven CRT displays. In mid fifties command and control CRT display consoles were introduced. The more display devices developed in mid-sixties and in common use until the mid-eighties, are called vector, stroke, line drawing or calligraphic displays. The term vector is used as a synonyms for line; a stroke is a short line, and characters are made of sequence of such strokes. 1

description

download MCA 2nd sem and 3rrd sem assignment (7737397502)

Transcript of (MC0072)computer graphic

Page 1: (MC0072)computer graphic

Master of Computer Application (MCA) – Semester 3

MC0072 – Computer Graphics

Que 1. Describe theory of development of hardware and software for computer graphics.

Ans: Development of Hardware and Software for Computer Graphics

The development of hardware of computer graphics involves the development of input and output device technology. Therefore, in all development of computer graphics involves the development in three fields:

1. Output technology

2. Input technology and

3. Software technology

1.6.1 Output Technology

Fig. 1.3 shows the historical development in the output technology. In early days of computer the hardcopy devices such as teletype printer and line printer were in use with computer driven CRT displays. In mid fifties command and control CRT display consoles were introduced. The more display devices developed in mid-sixties and in common use until the mid-eighties, are called vector, stroke, line drawing or calligraphic displays. The term vector is used as a synonyms for line; a stroke is a short line, and characters are made of sequence of such strokes.

Fig. 1.3

1.6.1.1 Architecture of a Vector Display

1

Page 2: (MC0072)computer graphic

Fig. 1.4: Vector Scan CRT

As shown in Fig. 1.4 vector scan CRT display directly traces out only the desired lines on CRT i.e If we want a line connection point A with point B on the vector graphics display. We simply drive the beam deflection circuitry which will cause beam to go directly from point A to B. If we want to move the beam from point A to point B without showing a line between points, we can blank the beam as we move it. To move the beam across the CRT, the information about both, magnitude and direction is required. This information is generated with the help of vector graphics generator.

The fig. 1.5 shows the typical vector display architecture. It consists of display controller, Central Processing Unit (CPU), display buffer memory and a CRT. A display controller is connected as an I/O peripheral to the central processing unit (CPU). The display buffer memory stores the computer produced display list or display program. The program contains point and line plotting commands with (x,y) or (x,y,z) end point coordinates, as well as character plotting commands. The display controller interprets commands for plotting points, lines and characters and sends digital and point coordinates to a vector generator. The vector generator then converts the digital coordinates values to analog voltages for beam-deflection circuits that displace an electron beam writing on the CRT’s phosphor coating.

Fig.: Architecture of a vector display

In vector displays beam is deflected from end point to end point, hence this technique is also called random scan. We know as beam, strikes phosphor it emits light. But phosphor light decays after few milliseconds and therefore it is necessary to repeat through the display list to refresh the phosphor at least 30 times per second to avoid flicker. As display buffer is used to store display list and it is used for refreshing, the display buffer memory is also called refresh buffer.

2

Page 3: (MC0072)computer graphic

1.6.1.2 Architecture of a Raster Display

The fig. 1.6 shows the architecture of a raster display. It consists of display controller, central processing unit (CPU), video controller, refresh buffer, keyboard, mouse and the CRT.

Fig.: Architecture of a raster display

As shown in the Fig. 1.6, the display images stored in the form of 1s and 0s in the refresh buffer. The video controller reads this refresh buffer and produces the actual image on the screen. It does this by scanning one scan line at a time, from top to bottom and then back to the top.

Fig: Raster Scan CRT

In this method, the horizontal and vertical deflection signals are generated to move the beam all over the screen in a pattern shown in the Fig. 1.7.

Here, the beam is swept back forth from left to right across the screen. When the beam is moved from the left to right, it is ON. The beam OFF, when it is moved from right to left as shown by dotted line in Fig. 1.7

When the beam reaches the bottom of the screen, it is made OFF and rapidly retraced back to the top to start again. A display produced in this way is called raster scan display. Raster scanning process is similar to reading different lines on the page of a book. After

3

Page 4: (MC0072)computer graphic

completion of scanning of one line, the electron beam files back to the start of next line and process repeats. In the raster scan display, the screen images is maintained by repeating scanning the same image. This process is known as refreshing of screen.

Vector Scan Display Raster Scan Display

1. In vector scan display the beam is moved between the end points of the graphics primitives

1. In raster scan display the beam is moved all over the screen one scan line at a time, from top to bottom and then back to top.

2. Vector display flickers when the number of primitives in the buffer becomes too large.

2. In raster display, the refresh process is independent of the complexity of the image.

3. Scan conversion is not required.

3. Graphics primitives are specified in terms of their endpoints and must be scan converted into their corresponding pixels in the frame buffer.

4. Scan conversion hardware is not required.

4. Because each primitive must be scan converted, real time dynamics is far more computational and requires separate scan conversion hardware.

5. Vector display draws a continuous and smooth lines

5. Raster display can display mathematically smooth line, polygons and boundaries of curved primitives only by approximating them with pixels on the raster grid.

6. Cost is more. 6. Cost is low.

7. Vector display only draws lines and characters.

7. Raster display has ability to display areas filled with solid colors or patterns.

Direct-view storage tubes

In last sixties, the direct-view storage tube (DVST) was introduced in the display technology. The direct-view storage tubes (DVST) give the alternative method of maintaining the screen image. A DVST uses the storage grid which stores the picture information as a charge distribution just behind the phosphor-coated screen.

The Fig. 1.8 shows the general arrangement of the DVST. It consists of two electron guns: a primary gun and a flood gun.

4

Page 5: (MC0072)computer graphic

Fig.: Arrangement of DVST

A primary gun stores the picture pattern and the flood gun maintains the picture display. A primary gun produces high speed electrons which strike on the storage grid to draw the picture pattern. As electron beam strikes on the storage grid with high speed, it knocks out electrons from the storage grid keeping the positive charge. The knocked out electrons are attracted towards the collector. The net positive charges on the storage grid is nothing but the picture pattern. The continuous low speed electrons from flood gun pass through the control grid and are attracted to the positive charged areas of the storage grid. The low speed electrons then penetrate the storage grid and strike the phosphor coating without affecting the positive charge pattern on the storage grid. During this process the collector just behind the storage grid smooth out the flow of flood electrons.

Advantages of DVST

1. Refreshing of CRT is not required.

2. Because no refreshing is required, very complex pictures can be displayed at very high resolution without flicker.

3. It has flat screen.

Disadvantages of DVST

1. They do not display colors and are available with single level of line intensity.

2. Erasing requires removal of change on the storage grid. Thus erasing and redrawing process takes several seconds.

3. Selective or part erasing of screen is not possible.

4. Erasing of screen produces unpleasant flash over the entire screen surface which prevents its use of dynamic graphics applications.

5. It has poor contrast as a result of the comparatively low accelerating potential applied to the flood electrons.

5

Page 6: (MC0072)computer graphic

6. The performance of DVST is some what inferior to the refresh CRT.

In early seventies the inexpensive raster graphics displays were developed. Raster displays store the display primitives (such as lines, characters solid and filled patterns) in a refresh buffer in terms of their corresponding pixels.

1.6.2 Input Technology

Input technology has also improved greatly over the years. Number of input devices were developed over the years. These devices are punch cards, light pens, keyboard, tables, mouse and scanners.

1.6.3 Software Technology

Like output and input technology there is a lot of development in the software technology. In early days low level software were available. Over the years software technology moved from low level to device dependent and then to device independent packages. The device independent packages are high level packages with can drive a wide variety of display and printer devices. As a need for the device independent package a standardization is made and specification are decided. The first graphics specification to be officially standardized was GKS (the Graphical Kernel System). GKS supports the grouping of logically related primitives such as lines, polygons, and character strings and their attributes in collected form called segments. In 1988, a 3D extension of GKS, became an official standard, as did a much more sophisticated but even more complex graphics system called PHIGS (Programmer’s Hierarchical Interactive Graphics System).

PHIGS, as its name implies, supports nested hierarchical grouping of 3D primitives, called structures. In PHIGS, all primitives are subjected to geometric transformations such as scaling, rotation and translation to accomplish dynamic movement. PHIGS also supports a database of structures the programmer may edit and modify. PHIGS automatically updates the display whenever the database has been modified.

Que 2. Explain the following with the help of relevant real time applications: A) Classification of Applications B) Development of Hardware and Software for Computer Graphics

6

Page 7: (MC0072)computer graphic

Ans:

Classification of Applications

In the last section we have seen various uses of computer graphics. These uses can be classified as shown in the Fig. 1.2. As shown in the Fig. 1.2, the use of computer graphics can be classified according to dimensionality of the object to be drawn: 2D or 3D. It can also be classified according to kind of picture: Symbolic or Realistic. Many computer graphics applications are classified by the type of interaction. The type of interaction determines the user’s degree of control over the object and its image. In controllable interaction user can change the attributes of the images. Role of picture gives the another classification. Computer graphics is either used for representation or it can be an end product such as drawings. Pictorial representation gives the final classification to use computer graphics. It classifies the use of computer graphics to represent pictures such as line drawing, black and white, colour and so on.

Development of Hardware and Software for Computer Graphics

The development of hardware of computer graphics involves the development of input and output device technology. Therefore, in all development of computer graphics involves the development in three fields:

1. Output technology

2. Input technology and

3. Software technology

7

Page 8: (MC0072)computer graphic

Output Technology

historical development in the output technology. In early days of computer the hardcopy devices such as teletype printer and line printer were in use with computer driven CRT displays. In mid fifties command and control CRT display consoles were introduced. The more display devices developed in mid-sixties and in common use until the mid-eighties, are called vector, stroke, line drawing or calligraphic displays. The term vector is used as a synonyms for line; a stroke is a short line, and characters are made of sequence of such strokes.

Input Technology

Input technology has also improved greatly over the years. Number of input devices were developed over the years. These devices are punch cards, light pens, keyboard, tables, mouse and scanners.

Software Technology

Like output and input technology there is a lot of development in the software technology. In early days low level software were available. Over the years software technology moved

8

Page 9: (MC0072)computer graphic

from low level to device dependent and then to device independent packages. The device independent packages are high level packages with can drive a wide variety of display and printer devices. As a need for the device independent package a standardization is made and specification are decided. The first graphics specification to be officially standardized was GKS (the Graphical Kernel System). GKS supports the grouping of logically related primitives such as lines, polygons, and character strings and their attributes in collected form called segments. In 1988, a 3D extension of GKS, became an official standard, as did a much more sophisticated but even more complex graphics system called PHIGS (Programmer’s Hierarchical Interactive Graphics System).

PHIGS, as its name implies, supports nested hierarchical grouping of 3D primitives, called structures. In PHIGS, all primitives are subjected to geometric transformations such as scaling, rotation and translation to accomplish dynamic movement. PHIGS also supports a database of structures the programmer may edit and modify. PHIGS automatically updates the display whenever the database has been modified.

Que 3. Explain the following with respect to Graphics Hardware: A) Color and Grayscale Levels B) Video Mixing C) Random scans display processor

Ans: Color and Grayscale Levels

Various color and intensity-level options can be made available to a user, depending on the capabilities and design objectives of a particular system. General purpose raster-scan systems, for example, usually provide a wide range of colors, while random-scan monitors typically offer only a few color choices, if any. Color options are numerically coded with values ranging from 0 through the positive integers. For CRT monitors, these color codes are then converted to intensity level settings for the electron beams.

In a color raster system, the number of color choices available depends on the amount of storage provided per pixel in the frame buffer. Also, color-information can be stored in the frame buffer in two ways: We can store color codes directly in the frame buffer, or we can put the color codes in a separate table and use pixel values as an index into this table. With the direct storage scheme, whenever a particular color code is specified in an application program, the corresponding binary value is placed in the frame buffer for each-component pixel in the output primitives to be displayed in that color. A minimum number of colors can be provided in this scheme with 3 bits of storage per pixel, as shown in the table 2.5.

Video Mixing

9

Page 10: (MC0072)computer graphic

Video controller provides the facility of video mixing. In which it accepts information of two images simultaneously. One from frame buffer and other from television camera, recorder or other source. This is illustrated in fig 2.7. The video controller merges the two received images to form a composite image.

Fig: Video mixing

There are two types of video mixing. In first, a graphics image is set into a video image. Here mixing is accomplished with hardware that treats a designated pixel value in the frame buffer as a flag to indicate that the video signal should be shown instead of the signal from the frame buffer, normally the designated pixel value corresponds to the background color of the frame buffer image.

In the second type of mixing, the video image is placed on the top of the frame buffer image. Here, whenever background color of video image appears, the frame buffer is shown, otherwise the video image is shown.

Random Scan Display Processor

The fig shows the architecture of a random scan display system with display processor. This architecture is similar to the display processor based raster system architecture except the frame buffer. In random scan display no local memory is provided for scan conversion algorithms, since that functionality is typically implemented using PLAs (Programmable Logical Arrays) or microcode.

10

Page 11: (MC0072)computer graphic

Fig.: Random Scan Display System

In random scan displays, the display processor has its own instruction set and instruction address register. Hence it is also called Display Processing Unit ( DPU) or Graphics Controller. It performs instruction fetch, decode and execute cycles found in any computer. To provide a flicker free display, the display processor has to execute its program 30 to 60 times per second. The program executed by the display processor and the graphics package reside in the main memory. The main memory is shared by the general CPU and the display processor.

Each of the three bit positions is used to control the intensity level (either on or off) of the corresponding electron gun in an RGB monitor. The leftmost bit controls the red gun, the middle bit controls the green gun, and the rightmost bit controls the blue gun. Adding more bits per pixel to the frame buffer increases the number of color choices. With 6 bits per pixel, 2 bits can be used for each gun. This allows four different intensity settings for each of the three color guns, and a total of 64 color values are available for each screen pixel.

11

Page 12: (MC0072)computer graphic

With a resolution of 1024 by 1024, a full-color (24bit per pixel) RGB system needs 3 megabytes of storage for the frame buffer. Color tables are an alternate means for providing extended color capabilities to a user without requiring large frame buffers. Lower cost personal computer systems, in particular, often use color tables to reduce frame-buffer storage requirements.

Que 4. Describe the theory of scan converting circles and the corresponding algorithms.

Ans:

Scan Converting Circles

Basic Concepts in Circle Drawing

12

Page 13: (MC0072)computer graphic

Fig.: 8-way symmetry of a circle

A circle is a symmetrical figure. It has eight-way symmetry as shown in the Fig Thus, any –circle generating algorithm can take advantage of the circle symmetry to plot eight points by calculating the coordinates of any one point. For example, if point A is the Fig. is calculated with a circle algorithm, seven more points could be found just by reflection.

Representation of a Circle

There are two standard methods of mathematically representing a circle centered at the origin.

(1) Polynomial Method

Fig.: Scan converting circle using polynomial method

In this method circle is represented by a polynomial equation.

x2+y2=r2

Where x : the x coordinate

y : the y coordinate

r : radius of the circle

Here, polynomial equation can be used to find y coordinate for the known x coordinate. Therefore, the scan converting circle using polynomial method is achieved by stepping x

13

Page 14: (MC0072)computer graphic

from 0 to r , and each y coordinate is found by evaluating for each step of x. This generates the 1/8 portion (900 to 450 ) of the circle. Remaining part of the circle can be generated just by reflection.

The polynomial method of circle generation is an inefficient method. In this method for each point both x and r must be squared and x2 must be subtracted from r2, then the square root of the result must be found out.

(2) Trigonometric Method

Fig 3.14: Scan converting circle using Trigonometric method

In this method, the circle is represented by use of trigonometric functions

x= and y=

Where : current angle

r : radius of the circle

x : the x coordinate

14

Page 15: (MC0072)computer graphic

y : the y coordinate

The scan converting circle using trigonometric method is achieved by stepping q from 0 to

radians, and each value of x and y is calculated. However this method is more inefficient than the polynomial method because the computation of the values of sin q and cosq is even more time-consuming than the calculations required in the polynomial method.

Circle Drawing Algorithms

In this section we are going to discuss three efficient circle drawing algorithms :

· DDA algorithm and

· Bresenham’s algorithm:

· Midpoint circle drawing algorithm

(1) DDA Circle Drawing Algorithm

We know that, the equation of circle, with origin as the center of the circle is given as

x2+y2=r2

The digital differential analyzer algorithm can be used to draw the circle by defining circle as a differential equation. It is as given below

2xdx+2ydy=0 where r is constant

x dx + y dy=0

y dy = -x dx

From above equation we can construct the circle by using incremental x value ∆x= and incremental y value, ∆y= where έ is calculated from the radius of the circle as given below

2n-1 r 2n

=2-n

For example, if r=50 then n=6 so that 32 50 64

=2-6

15

Page 16: (MC0072)computer graphic

=0.0156

Applying these incremental steps we have

xn+1 = xn+

yn+1= yn -

The points plotted using above equations give the spiral instead of the circle. To get the circle we have to make one correction in the equation; we have to replace x n by xn+1 in the equation of yn+1

Therefore, now we have

Xn+1=xn+ yn

Yn+1=yn- xn+1

Algorithm

1. Read the radius r of the circle and calculate value of

2. Start_x=y

Start_y=r

3. X1=start_x

Y1=start_y

4. do

{

x2=x1+

y2=y1-

[ x2 represents xn+1 and x1 represents xn]

Plot(int(x2), int (y2))

x1=x2

y1=y2

[Reinitialize the current point]

16

Page 17: (MC0072)computer graphic

} while (y1-start_y) < or (start_x-x1) > )

[check if the current point in the starting point or not. If current point is not the starting point repeat step 4 otherwise stop]

5. stop

(2) Bresenham’s Circle Drawing Algorithm

Fig: 1/8 part of the circle

The Bresenham’s circle drawing algorithm considers the eight-way symmetry of the circle to generate it. It plots 1/8th part of the circle, i.e. from 900 to 450 as shown in the fig 3.15. As circle is drawn from 900 to 450 , the x moves in positive direction and y moves in the negative direction.

To achieve best approximation to the true circle we have to select those pixels in the raster that fall the least distance from the true circle. Refer Fig. 3.16. Let us observe the 900 to 450 portion of the circle. It can be found by applying either of the two options:

· Increment in positive x direction by one unit or

· Increment in positive x direction and negative y direction both by one unit

17

Page 18: (MC0072)computer graphic

Fig.: Scan conversion with Bresenham’s algorithm

Let us assume point P in Fig.3.16 as a last scan converted pixel. Now we have two options either to choose pixel A or pixel B. The closer pixel amongst these two can be determined as follows

The distances of pixels A and B from the origin are given as

DA= and

DB=

Now, the distances of pixels A and B from the true circle are given as

and

However, to avoid square root in derivation of decision variable, i.e. to simplify the

computation and to make algorithm more efficient the and are defined as

=DA2-r2

=DB2-r2

From fig. 3.16 we can observe that is always positive and is always negative. Therefore we can define decision variable di as

di= +

and we say that, if di < 0 i.e < then only x is incremented; otherwise x is incremented in positive direction and y is incremented in negative direction. In other words we can write,

for di < 0, xi+1= xi+1

for di 0, xi+1= xi+1 and yi+1=yi-1

the equation for di at starting point, i.e at x=0 and y=r can be simplified as follows

di= +

=(xi+1)2 + (yi)2 –r2 + (xi+1)2+ (yi-1)2-r2

=(0+1)2 + (r)2-r2+ (0+1)2 + (r-1)2-r2

18

Page 19: (MC0072)computer graphic

=3-2r

Similarly, the equation for di+1 for both cases are given as

For di<0, di+1=di+4xi+6 and

For di 0, di+1= di+4(xi-yi)+10

Algorithm to plot 1/8 of the circle

1. Read the radius r of the circle

2. d=3-2r [initialize the decision variable]

3. x=0, y=r [initialize starting point]

4. do

{

Plot( x , y)

If (d < 0) then

{

d=d=4x+6

}

Else

{

d=d+4(x-y)+10

y=y-1

}

x=x+1

} while (x<y)

5. stop

19

Page 20: (MC0072)computer graphic

The remaining part of circle can be drawn by reflecting point about y axis, x axis and about origin as shown in Fig. 3.17

Fig.: 8 way symmetry of the circle

Therefore by adding seven more plot commands after the plot command in the step 4 of the algorithm, the circle can be plotted. The remaining 7 plot commands are

Plot( y, x)

Plot (y, -x)

Plot(x, -y)

Plot(-x,-y)

Plot (-y, -x)

Plot (-y, x)

Plot (-x , y)

(3) Midpoint circle drawing Algorithm

The midpoint circle drawing algorithm also uses the eight-way symmetry of the circle to generate it. It plots 1/8 part of the circle i.e from 90° to 45° as shown in the figure 3.18. as circle is drawn from 90° to 45°, the x moves in the positive direction and y moves in the negative direction. To draw 1/8 part of the circle, we take unit steps in the positive x direction and make use of decision parameter to determine which of the 2 possible y position is closer to the circle path at each step.

20

Page 21: (MC0072)computer graphic

Fig: Decision parameter to select correct pixel

in circle generation algorithm

In the above figure the 2 possible y positions are y i and yi-1 at xi+1. Therefore we have to determine whether the pixel at (xi+1, yi) or at position (xi+1, yi-1) is closer to the circle. For this purpose decision parameter I used. It uses the circle function f(x,y)=x2+y2-r2 evaluated at the midpoint between these 2 pixels.

-1)

If di < 0, the midpoint is outside the circle and pixel on the scan line yi is closer to the circle boundary. If di >=0, the midpoint is outside or on thee circle boundary. And yi-1 I closer to the circle boundary. Now calculate di+1. There are 2 cases

Case 1: if di < 0 then

=

Case 2: if di >021

Page 22: (MC0072)computer graphic

If di <0 we can write

If di > 0 then we can write

The initial value of the decision parameter can be obtained by evaluating circle function at the start position (x0, y0)=(0,r)

Algorithm

1. read the radius r of the circle

2. initialize starting position as x=0, y=r

3. calculate the initial value of the decision parameter as d=1.25-r

4. do

22

Page 23: (MC0072)computer graphic

{

Plot( x, y)

If(d<0)

{

x=x+1

d=d+2x+1

}

Else

{

x=x+1

y=y-1

d=d+2x+1

} while(x < y)

5. determine symmetry points

6. stop

23