0% found this document useful (0 votes)
47 views

Computer Graphics Point

This document discusses different methods for drawing pixels on a computer screen, including using video BIOS services, directly accessing video memory, and library functions. It provides code examples in assembly language and C to set a graphics mode and write pixels using each method. Key points covered include video modes, resolutions, colors, writing to text and graphics modes, and addressing video memory locations directly versus using BIOS interrupts or library functions.

Uploaded by

Nusrat Ullah
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Computer Graphics Point

This document discusses different methods for drawing pixels on a computer screen, including using video BIOS services, directly accessing video memory, and library functions. It provides code examples in assembly language and C to set a graphics mode and write pixels using each method. Key points covered include video modes, resolutions, colors, writing to text and graphics modes, and addressing video memory locations directly versus using BIOS interrupts or library functions.

Uploaded by

Nusrat Ullah
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 37

Computer Graphics

Lecture 03
Point
Pixel

The smallest dot illuminated that can be seen on screen


Picture

Composition of pixels makes picture that forms on whole


screen
Resolution
Resolution:
– Number of rows & number of columns
Each mode uses a particular resolution
For example:
– mode 19 uses 200 rows and 320 columnsi.e. 320*200
resolution
Resolution

Higher resolution:
– sharper, clearer picture, with less pronounced
‘staircase’ effect on lines drawn diagonally and better
looking text characters
– more memory requirement for the display
Text and Graphics Modes

 Video cards are responsible to send picture data


 Video cards support different text and graphics modes
 Every Mode has its own resolution, number of colors and
refresh rate
Text and Graphics Modes

The following famous video modes that we can set in today’s


video cards on different refresh rates
 25 * 80 with 16 colors support
(text mode)
 320 * 200 with 8 bit colors support (graphics mode)
Text and Graphics Modes

 640 * 480 with 16 colors support


(graphics mode)
 640 * 480 with 8, 16, 24, 32 bit colors support (graphics
mode)

 800 * 600 with 8, 16, 24, 32 bit colors support (graphics


mode)
Text and Graphics Modes Cont…

Mode No. Type Resolution Memory Required


3 Text 80 x 25 2 bytes per char
6 Graphics 640 x 200 1 bit per pixel
7 Text 80 x 25 2 bytes per char
18 Graphics640 x 480 1 bit per pixel
19 Graphics 320 x 200 1 byte per pixel
Mode 6

In mode 6 each pixel displayed on the screen occupies one


bit in VDU memory. Since this bit can take only two values,
either 0 or 1, each pixel can only be displayed in one of two
colors.
Text Mode Colors
 Character in mode 3 (two bytes)
 one containing the ASCII value of the character
 and other containing its attribute
Attribute Byte Configuration
Bits
7 6 5 4 3 2 1 0 Purpose

x x x x x x x 1 Blue component of foreground color


x x x x x x 1 x Green component of foreground color
x x x x x 1 x x Red component of foreground color
x x x x 1 x x x Intensity component of foreground color
x x x 1 x x x x Blue component of background color
x x 1 x x x x x Green component of background color
x 1 x x x x x x Red component of background color
1 x x x x x x x Blinking component
Graphics Mode Colors

 In the graphics mode each pixel on the screen has a color


associated with it
 Difference between text mode and graphics mode
 In text mode we have limitations because only text could
be displayed. There are inter-line spaces as only few
rows of the screen are used to display.
 In graphics mode we can use any pixel of the screen to
display a color. Text can also be displayed here as an
image.
Colors in VGA
 The VGA card was first introduced by IBM in April 1987
 VGA has 4 color planes:
 red, green, blue and intensity
 one bit from each of these planes contributing towards
one pixel value
Writing Pixel on Screen

 Following methods can be used to write pixel on screen:


 Using video bios services to write pixel
 Accessing memory and registers directly to write pixel on
screen.
 Using library functions to write pixel on screen
Practical Approach to Write Pixel on
Screen

The language used to write codes for graphics is Assembly


and C
Writing pixels:

Video BIOS
Writing Pixel Using Video BIOS

 The following are the steps involved in writing a pixel using


video BIOS services:
 Setting desired video mode
 Using BIOS service to set color of a screen pixel
 Calling BIOS call to execute the process of writing pixel
Source Code

Code in assembly language that can set graphics mode 19


(13h)

MOV AH,0 ;setting video service number


MOV AL,13h ;mode number from 0-19
INT 10h ;sending call to BIOS
Source Code Cont..
You can use this for assembler or you can embed this code
in C language using ‘asm’ keyword

asm {
MOV AH,0
MOV AL,13h;;mode number from 0-19
INT 10h
}
Description of Source Code

 Line #1: mov AH,0


 is the service number for setting video mode that is in
register AH

 Line #2: mov AL,13h


 is the mode number that is in register AL

 Line #3: INT 10h


 is the video BIOS interrupt number that will set mode 13h
Source Code for Writing Pixel

Code to write pixel using video BIOS interrupt 10h and


service number 0ch.

MOV AH,0Ch ; setting color service


MOV AL,COLOR_NUM ; setting color number
MOV BH,0 ; sets page number
MOV CX,ROW_NUM ; setting row num
MOV DX,COLUMN_NUM ; setting column num
INT 10h ; sending call to BIOS
Description
 Line#1: service number in register AH
 Line#2: color value, since it is 13h mode so it has 0-255
colors range. You can assign any color number between 0
to 255 to AL register. Color will be selected from default
palette setting against the number you have used
 Line#3: page number in BH register. This mode supports
only one page. So 0 is used in BH register. 0 means default
page
Description

 Line#4: column number in CX register


 Line#5: row number in DX register
 Line#6: BIOS interrupt number 10h
Writing pixels:

Accessing Video
Memory directly
Writing pixel by accessing Video
Memory directly
 So far we used BIOS to draw pixel.
 Now we will draw pixel by accessing direct pointer to the
video memory and write color value
Writing pixel by accessing Video
Memory directly
 Steps to write pixel directly (without using BIOS):
 Set video mode by using video BIOS routine as discussed
earlier
 Set any pointer to the video graphics memory address
0x0A000
 Now write any color value in the video memory address
Direct Graphics Memory Access
Example:
Mov ax,0a000h ;starting address of memory

Mov ds,ax ;segment address changed


Mov si,10 ;column number
Mov [si],COLOR_NUM ; move color
Direct Graphics Memory Access

Work to do:
 Write pixel at 12th row and 15th column
 Hint: use formula (row * 320 + column) in si register
Writing Character Directly on Screen

You can also write text directly:


 by setting any text mode using BIOS service
 and then setting direct pointer at text memory address
0x0b800
Example Writing Character Directly on
Screen
Set mode Number 3 using BIOS service and then use this
code to write character
Mov ax,0b800h ;pointing towards text memory
Mov ds,ax
Mov si,10 ; column number
Mov [si],’a’ ; character to write
Writing Pixels:

Library Functions
Using Library Functions

 While working in C language, you can use graphics library


functions to write pixel on screen
 Graphics library functions use BIOS routines or use direct
memory access drivers to draw pixel on screen
Using Library Functions
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();

if (errorcode != grOk)
/* an error occurred */
{

printf("Graphics error: %s\n", getch());


exit(1);
/* return with error code */

}
Using Library Functions
/* draw a pixel on 10th row and 10 column */
putpixel(10, 10, BLUE);
/* clean up */
closegraph();
Steps, Example in C language
 First call Initgraph() function
 then call putpixel() function to draw pixel on screen
 then use closegraph() function
Discussion on Pixel drawing Methods

 BIOS routines are quite slow


 Direct memory access method is easy and faster
 its programming is only convenient in mode 13h
 Library functions are even faster

You might also like