COMPUTER GRAPHICS - Implement Character Generation Methods

 A.1 Aim:

Character Generation : Bit Map method and Stroke Method


A.2 Prerequisite:

1. C Language.

2. Geometric Concepts.

3. Concept of 2D and 3D basic Transformations.

4. Projection Concepts.


A.3 Outcome:

After successful completion of this experiment students will be able to,

Apply Character Generation techniques


A.4 Theory and Procedure:

Bitmap Font/ Bitmapped Font: Character Generation

A simple method for representing the character shapes in a particular typeface is to

use rectangular grid patterns.

The figure below shows the pattern for the particular letter.

Bitmap Font/ Bitmapped Font: Character Generation

When the pattern in the figure copied to the area of the frame buffer, the 1 bits

designate which pixel positions to displayed on the monitor.

Bitmap fonts the simplest to define and display as character grid only need to be

mapped to a framebuffer position.

Bitmap fonts require more space because each variation (size and format) must

stored in a font cache.

It possible to generate different size and other variation from one set but this usually

does not produce the good result.

Outline Font: Character Generation

Outline Font: Character Generation

In this Character Generation method, a character generated using curve section

and straight line as combine assembly. The figure shows how it generated.

To display the character shown in the figure we need to fill interior region of the

character.

This method requires less storage since each variation does not require a distinct

font cache.

We can produce boldface, italic, or different sizes by manipulating the curve

definitions for the character outlines.

But this will take more time to process the outline fonts because they must scan

converted into the frame buffer.


Stroke Method: Character Generation


It uses small line segments to generate a character.

The small series of line segments drawn like a stroke of a pen to form a character

as shown in the figure.

We can generate our own stroke method by calling line drawing algorithm.


Here it is necessary to decide which line segments are needs for each character

and then draw that line to display character.

It supports scaling by changing a length of the line segment.


Starburst Method: Character Generation

Starburst Method: Character Generation

In this Character Generation method, a fixed pattern of line segments used to

generate characters.

As shown in the figure there are 24 line segments.

We highlight those lines which are necessary to draw a particular character.

The pattern for the particular character stored in the form of 24-bit code. In which

each bit represents the corresponding line having that number.

That code contains 0 or 1 based online segment need to highlight. We put bit value

1 for highlighted line and 0 for other lines.

Code for letter V is

1 0 0 1 1 1 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0

This technique not used now a days because:

It requires more memory to store 24 bit code for single character.

Moreover, It requires conversion from code to character.

It doesn’t provide curve shapes.

For example :

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd=DETECT,gm,i,j;

int a[20][20]=

{{0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0}, 

{0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0}, 

{0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1}, 

{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0}, 

{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0}, 

{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,0}, 

{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0}, 

{0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0}, 

{0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0}, 

{0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0}};

initgraph(&gd,&gm,"c:\\tc\\bgi");

for(i=0;i<19;i++)

for(j=0;j<19;j++)

if(a[i][j]==1) 

putpixel(100+j,200+i,WHITE); 

getch();

}


CODE :

BITMAP METHOD

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd=DETECT,gm,i,j;

int a[20][20]=

{{0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0},

{0,0,0,0,0,1,1,0,0,0,0,0,0,1,0,0,0,1,0,0},

{0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0},

{0,0,0,1,0,0,0,0,1,0,0,0,0,1,1,1,1,1,0,0},

{0,0,1,1,1,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0},

{0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0},

{1,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0},

{1,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0},

{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},

{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};

initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");

for(i=0;i<19;i++)

{

for(j=0;j<19;j++)

{

if(a[i][j]==1)


putpixel(100+j,200+i,15*a[i][j]);

}

}

getch();

}


STROKE METHOD

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd=DETECT,gm;

initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");

line(50,100,80,200);

line(50,100,20,200);

line(70,150,35,150);

line(150,200,150,100);

arc(150,130,270,90,30);

getch();

}


Outputs:

OUTPUT FOR BITMAP METHOD:-

OUTPUT FOR BITMAP METHOD:-

OUTPUT FOR STROKE METHOD:-

OUTPUT FOR STROKE METHOD:-


In BitMap Method 1 is displayed as a pixel in the output. So any figure or character can be created.

In Stroke Method we use the small line and arc segments to create character in the output.


Question of Curiosity

Q.1]Discuss different advantages and disadvantages of character generation techniques.

ANS :      Bitmap Method

      Advantages

  • Various Characters can be produced by using Bitmap Method.

  • Font size can be increased by increasing size of array.

      Disadvantages

  • Produce Aliased Character.


Stroke Method

       Advantages

  • We can generate our own stroke method by calling line drawing algorithm.

  • It supports scaling by changing a length of the line segment.

       Disadvantages

  • Produce Aliased Character.

Comments