Sei sulla pagina 1di 22

BMP Utility for DOS

Introduction

BMP stands for Bit Map Pictures:


They are various formats to represent difficult pictures viz. JPG, BMP, Gif,
PNG etc. this formats has got different ways to represent images. An image is
defined as combination of pixel over an area where the intensity of the pixel
represents the color of the point of that particular area. There are 2 types of
images:
 Analog image.
 Digital image.
An Analog image is one which is achieved capturing a view through
manual camera. When the analog picture is scanned into the digital device, the
resulting image is called digital image. Any digital image informed by sampling
the analog image pixel and then quantizing them. Hence digital image requires
lesser bits to represents an image. Though in the process of digitalization, the
image loses some of its information because of the quantization error. A digital
image is a 3 dimensional image with first 2 dimensions representing the co
ordinates of the position of the pixel where as the 3rd entity represents the digital
representation of the intensity level of the pixel. Hence the images are
characterized into 8-bit, 16-bit, 32-bit images. An eight bit image represents the
entire intensity level of the image by numbers from 0 to 28. Similarly the 16-bit
image represents the intensity level by number from 0 to 216.

A digital image is of 3 dimensional images with 2 dimensions representing


the coordinate of the position of the pixel where as the 3rd entity represents the
digital representation of the intensity level of the pixel. Hence the images are
characterized into 8-bit, 16-bit, 32-bit images. An 8-bit image represents the
entire intensity level of the image by numbers from 0 to 28. Similarly the 16-bit

Department Of Computer Science, 1


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

Image represents the intensity level by numbers from 0 to 2 16 and so on. There
are 2 types of images based on intensity variation viz.

 Monochrome Image.
 Color Image.

A monochrome image is also called a black and white image or a grey


scale image because the image is achieved by various mixing of black and white
colors. The color image, where as represent the image through intensities having
all the seven colors existing. As all these colors can be achieved by mixing
shades of red, green, blue, this is also called a RGB image.
There are 2 types of images depending upon the information they
represent viz.
 2D image.
 3D image.

Once any image is digitally converted the information is saved in a binary format
in an image file. An image file consist of 2 sectors such as.
 A header field
 The data field

The data field recedes the header field. The converted data is stored in
the data field. All the images require a huge set of memory for storing display
purpose. Memory is an expensive issue for the software developers. Hence all
the images are first compressed and then stored into the file. After compression
the image loses some of the information. An image format is said to be a good
format if it achieves higher compression ratio without losing much information.
Viewing any image requires the decompression of the file and glow the points on
the screen suitably by reading the intensity information from the file. A header

Department Of Computer Science, 2


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

comprises of all the information required by a decoder which should enable the
decoder to decode the image or display the image. The BMP file format achieves
very minimum compression ratio in comparison with the other formats. Hence the
processing speed requires to display the BMP images is bit lesser in comparison
with the other methods. We have tried to develop a BMP utility for DOS which
would display a BMP file into the DOS. There has been no such utility available
in DOS. Hence the technology is a great achiever in terms of crossing the
limitations of text based operating system and enhances its features to display
complex objects like images into the screen.

System Design and Analysis:

Present System:
As we all know that DOS is a text operating system; hence it doesn’t
provide a capability of displaying the image. The image viewers that are available
in the market today are all for windows services. Some of them are product
picture viewer, MS-Paint etc. All of them are capable of displaying complicated
and rich images because windows and other major operating system support
high density pixel and 32 bit quantization. Hence it was important to develop an
image viewer which would be able to display the images in DOS.

Proposed System:
The system that we are proposing here in our project is an ultimate utility
in DOS. It reads the header of the image file first and finds out the number of
rows and the columns that it needs to read out from the date segment of the
image file. It than starts reading the data from the file byte by byte and glow the
corresponding pixel in the screen with the intensity that is been read from the
image file. Hence it also needs to have the information about the byte format and
quantization factor of the encoder. Once the information of the pixel is available it
is put in the screen by assigning it to the AX register of the CPU and by

Department Of Computer Science, 3


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

generating video interrupt. With this all the pixels are read, the image is displayed
in the screen. Time is a major factor over here as number of pixels needs to be
read, is quite high. Hence this system works best with advanced processors with
high memory support.

Implementation:
The project provides 2 different utility services:
 To view all the BMP files as a graphical files present in the current
directory.
 A system which accepts the file name as the input & draw the image.

The file display utility is enabled by initializing an ffblk structure with


current directory name and path. Then using the functions findfirst and findnext,
all the files in the directory are found out. The findfirst and findnext function
requires a wild card entry to know what kind of files to display. We have passed
“Start.BMP” as the wild card entry for the mentioned functions. Now the function
finds out all the BMP files present in the current directory. User may select from
any of this files to display that. As the user selects the filename, it is passed to a
function which would display the image. This function would open the passed
filename in the binary mode and read 0 to 55 bytes. Bytes from 0 to 55 contain
the header information. From the header information number of rows and
columns that must be read is found out. Now the control goes inside a loop which
would be continued till all the rows and columns are read out. As the rows and
columns are read they would be assigned AX and BX register of the CPU
through Union REGS structure. Now the video interrupt is generated through
int86 functions which display the image in the screen.

Department Of Computer Science, 4


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

System Requirement:
Functional Requirement:
The BMP utility displays the BMP images into the screen. Hence the most
functional and basic requirement of the system is BMP file which would be
displayed. The next thing that is important over here is the processing speed and
the processing capability of the processor to be very high and the parallel.
Processing must be fast. The RAM requirement over here is also very high
because the buffer size needed to hold the image is very high. Hence even
though the system is designed predominantly for DOS users this will not be
supported by low configuration PCs. The other requirements include:
 To understand the image information: The current system cannot display
3D images. Hence the user must not pass any 3D images to the display
routine.
 To have accelerated graphics card in the system. Th accelerated graphics
card are electronics devices or peripherals which present tremendous
capability to the video by providing the video driver with a memory of
above 5K. Higher the memory of the card, better the speed of the display
becomes. Without the presence of the card it would it long period to
display any image.

Department Of Computer Science, 5


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

Software and Hardware Requirement:

Hardware Requirement: 64 KB Hard disk, 16 MB RAM.

Software Requirement: DOS, C, C-Graphics.

Non-Functional Requirement:

 Testability: The system is capable of supporting various testing models


such as manual testing and the automatic testing.
 Predominantly monochrome images are required for the display purpose.
 Supporting utilities: The software must support various utilities like
zoom, rotation, color blurring, compression etc.

Advantages:
 It is first of its kind to show any images into DOS.
 Can read image of any size lesser than 1024 by 1024 size.
 Can be used to display various drives folders.
 It using direct user memory hence serialization problem is removed.

Department Of Computer Science, 6


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

Disadvantages:
 View port transformation problem may cause information lose
which results in image distortion.
 High memory requirement.
 High processing speed is required.
 Image manipulations are not possible.

Application:

 It may be used to see images in DOS.


 Drive information can be retrieved.
 Image array extracted can be manually operated on, to give various
mathematical modifications over the image.
 It may be used in PPT like package in DOS to represent various
images.
 With further improvement in the hardware and graphics drivers the
same concept can be used to develop a movie player in DOS in
near future.

Department Of Computer Science, 7


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

Conclusion:

The project has been one of the premature efforts to display BMP images
in DOS. The system is not a perfect one as memory optimization is not been
looked after. Beside the system is too dependent on configuration of the system.
Hence the performance cannot be optimal in various PCs. It is strongly a
hardware dependent system. For more adoptivating the logic must be improved
so that the result must be same for almost all the configuration.

Department Of Computer Science, 8


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

Bibliography:

Let us C by Yashwanth Kanitkar.

TSR Programming by yashwanth Kanitkar.

Department Of Computer Science, 9


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

#include<process.h>
#include <stdio.h>
#include <string.h>
#include <graphics.h>
#include <dir.h>
#include <dos.h>
#include <conio.h>
#define FILE1 1
#define FOLDER 2
#define EXE 3
#define BAT 4
#define COM 5
//**********************************************************************
********// FUNCTION PROTOTYPES
//**********************************************************************
********//
struct BMPHeader
{
unsigned short bfType;
long bfSize, bfReserved, bfOffBits, biSize, biWidth, biHeight;
unsigned short biPlanes, biBitCount;
long biCompression, biSizeImage, biXPelsPerMeter,
biYPelsPerMeter;
long biClrUsed, biClrImportant;
} Header;
FILE * gInpFile;

Department Of Computer Science, 10


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

void ReadDirc();
void Icon(int x,int y,int of);
void Show(int,int,char *,int);
int Extension(char *in);
void Init();
void func1(char*);
void win(int sx,int sy,int ex,int ey,int ck);
void InitScreen(void);
void ReadHeader(void);
void ReadImg(void);

//BMP Header structure

//File handle
//FILE * gInpFile;

//Required for palette


unsigned char c;
//**********************************************************************
********//
SOME GLOBAL VARIABLES
//**********************************************************************
********//
int startx,starty,endx,endy;
char *get_direc(char *);
char text[MAXPATH];
//**********************************************************************
********//
MAIN FUNCTION

Department Of Computer Science, 11


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

//**********************************************************************
********//
void main()
{
Init();
ReadDirc();
char* argv=" ";
getch();
cleardevice();
closegraph();
printf("Enter File Name\n");
scanf("%s",argv);
func1(argv);
closegraph();
}
//**********************************************************************
********/// SWITCH INTO GRAPHICS & SETS THE BACKGROUND
//**********************************************************************
********//
void Init()
{
int d=DETECT,m;
// for stand alone
/*
registerfarbgidriver(EGAVGA_driver_far);
registerfarbgifont(sansserif_font_far);
registerfarbgifont(small_font_far);
registerfarbgifont(gothic_font_far);
registerfarbgifont(triplex_font_far);
*/

Department Of Computer Science, 12


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

get_direc(text);
printf("\ncurrent directory is : %s",text);
printf("\nPress any Key to see files (*.*)...\n");
getch();
initgraph(&d,&m,"d:\\tc\\bgi");
startx=50;
starty=60;
endx=600;
endy=380;
setfillstyle(1,15);
bar(0,0,640,480);
setfillstyle(1,7);
bar(0,endy+50,640,480);
win(0,0,640,starty-11,1);
setcolor(0);
rectangle(startx-49,starty-12,endx+39,endy+51);
settextstyle(2,0,4);
setcolor(15);

}
//**********************************************************************
********//
READ CURRENT DIRECTORY & DISPLAY FILES,FOLDERS
//**********************************************************************
********//
void ReadDirc()
{
struct ffblk ffblk;
char *Wildcard;
int done,x,y,dx,dy;

Department Of Computer Science, 13


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

x=startx;y=starty;
dx=80;
dy=50;
Wildcard="*.bmp";// change wildcard (like : *.exe, *.cpp,a*.c?? etc)
done = findfirst(Wildcard,&ffblk,FA_DIREC);
while (!done)
{
if(ffblk.ff_name[0]!='.')
{
if(ffblk.ff_attrib==FA_DIREC)
Show(x,y,ffblk.ff_name,FOLDER);
else
Show(x,y,ffblk.ff_name,FILE1);
x+=dx;
if(x>=endx)
{
y+=dy;
x=startx;
}
if(y>=endy)
{
getch();
y=starty;
x=startx;
setfillstyle(1,15);
bar(startx-25,starty-10,endx+35,endy+35);
}
}
done = findnext(&ffblk);
}

Department Of Computer Science, 14


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

}
//**********************************************************************
********//
DISPLAY SPECIFIED ICON
//**********************************************************************
********//
void Icon(int x,int y,int type)
{
unsigned color,size,i;
char *ext;
color=14;
size=25;
if(type==FOLDER)
{
setcolor(color);
for(i=1;i<=4;i++)
line(x+3-i,y+i,x+10+i,y+i);
setcolor(0);
line(x+3,y,x+10,y);
line(x+3,y,x,y+4);
line(x+10,y,x+14,y+4);
y+=4;
setfillstyle(1,color);
bar(x,y,x+size,y+size-(size/3));
setcolor(0);
rectangle(x,y,x+size,y+size-(size/3));
}
else if(type==FILE1)
{
setfillstyle(1,15);

Department Of Computer Science, 15


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

bar(x+2,y+2,x+size-2,y+size-2);
setcolor(0);
rectangle(x+2,y+2,x+size-2,y+size-2);
setcolor(15);
line(x+2,y+2,x+6,y+2);// --
line(x+2,y+2,x+2,y+6);// |
setcolor(0);
line(x+6,y+2,x+2,y+6);// /
line(x+2,y+6,x+6,y+6);// --
line(x+6,y+2,x+6,y+6);// |
for(i=0;i<8;i++) line(x+6,y+5+i*2,x+size-6,y+5+i*2);
}
else if(type==EXE || type==COM || type==BAT)
{
if(type==EXE) ext="exe";
else if(type==COM) ext="com";
else ext="bat";
setfillstyle(1,1);
bar(x,y,x+size,y+size);
setfillstyle(1,15);
bar(x+2,y+8,x+size-2,y+size-2);
setcolor(7);
rectangle(x+2,y+1,x+size-2,y+6);
setcolor(9);
settextstyle(2,0,4);
settextjustify(LEFT_TEXT,RIGHT_TEXT);
outtextxy(x+5,y+10,ext);
putpixel(x+size-5,y+3,14);
putpixel(x+size-7,y+3,14);
putpixel(x+size-9,y+3,14);

Department Of Computer Science, 16


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

setcolor(0);
}
}
//**********************************************************************
********//
DISPLAY ICON & SHOW FILE NAME
//**********************************************************************
********//
void InitScreen(void)
{
union REGS r;
r.h.ah = 0;
r.h.al = 0x13;
int86(0x10, &r, &r);
return;
}

void ReadHeader(void)
{
int i,red[256],green[256],blue[256];
union REGS rin,rout;
//Read in header information
fread (&Header, 54, 1, gInpFile);
//Read in palette information
if(Header.bfOffBits==1078)
for(i=0;i<1024;i++)
c=fgetc(gInpFile);
return;
}

Department Of Computer Science, 17


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

void ReadImg(void)
{
union REGS rin,rout;
int i,j;
/* displaying the original image */

for(i = (int)((int)Header.biHeight+20) ; i >20 ; i--){


for(j = 10 ; j<(int)((int)Header.biWidth+10) ; j++){
rin.h.ah = 0x10; /* call Int 10H Function 10H */
rin.h.al = 0x10; /* Subfunction 10H, SET COLOR
REGISTER */

c =(unsigned char)(fgetc(gInpFile)/4); /* for original image */


rin.h.cl = (unsigned char)c;
c =(unsigned char)(fgetc(gInpFile)/4);
rin.h.ch = (unsigned char)c;
c =(unsigned char)(fgetc(gInpFile)/4);
rin.h.dh = (unsigned char)c;
rin.x.bx = (int)c;
int86(0x10,&rin,&rout);
rin.h.ah = 0x0c;
rin.h.bh = 0;
rin.h.al = c;
rin.x.dx = i;
rin.x.cx = j;
int86(0x10,&rin,&rout);
}
}
return;

Department Of Computer Science, 18


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

void Show(int x,int y,char *name,int type)


{
int T;
if(type==FILE1)
{
T=Extension(name);
if(T!=0) type=T;
}
Icon(x,y,type);
settextjustify(CENTER_TEXT,RIGHT_TEXT);
settextstyle(2,0,4);
outtextxy(x+15,y+26,name);
}
//**********************************************************************
********//
RETURNS EXTENSION OF GIVEN INPUT
//**********************************************************************
********//
int Extension(char *in)
{
int t,s;
char ext[3],fn1[13];
s=strlen(in);
for(t=0;t<=s;t++)
{
fn1[t]=in[s-t];
}
for(t=0;t<=3;t++)

Department Of Computer Science, 19


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

{
ext[t]=fn1[3-t];
}
if(strcmpi("exe",ext)==0) return EXE;
if(strcmpi("bat",ext)==0) return BAT;
if(strcmpi("com",ext)==0) return COM;
//like this more extensions can be added
return 0;
}
//**********************************************************************
********//
DISPLAY WINDOW
//**********************************************************************
********//
void win(int sx,int sy,int ex,int ey,int ck)
{
setfillstyle(1,7);
bar(sx,sy,ex,ey);
setfillstyle(1,7);
setcolor(15);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
setcolor(0);
line(ex,sy,ex,ey);
line(ex,sy,ex,ey);
line(sx,ey,ex,ey);
line(sx,ey,ex,ey);
if(ck==1)

Department Of Computer Science, 20


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

{
settextstyle(0,0,0);
setfillstyle(1,1);
bar(sx+2,sy+2,ex-2,sy+17);
setcolor(15);
outtextxy(sx+4,sy+4,text);
//for x
setfillstyle(1,7);
bar(ex-15,sy+4,ex-4,sy+15);
setcolor(15);
line(ex-15,sy+4,ex-4,sy+4);
line(ex-15,sy+4,ex-15,sy+15);
setcolor(0);
line(ex-15,sy+15,ex-4,sy+15);
line(ex-4,sy+4,ex-4,sy+15);
setcolor(1);
outtextxy(ex-13,sy+5,"x");
setfillstyle(1,7);
}
}
//**********************************************************************
********//
GET CURRENT DIRECTORY
//**********************************************************************
********//
char *get_direc(char *tgt)
{
strcpy(tgt, "X:\\");
tgt[0] = 'A' + getdisk();
getcurdir(0,tgt+3);

Department Of Computer Science, 21


KBN. College Of Engineering, Gulbarga.
BMP Utility for DOS

return(tgt);
}
void func1(char* argv)
{ clrscr();
printf("********************************************************\n");
printf("\t\tDISPLAYING A BMP FILE\n");
printf("********************************************************\n\n");

gInpFile = fopen(argv,"rb");
if(gInpFile==NULL)
{
printf("File not found.");
getch();
exit(0);
}
printf("Press any key to view %s",argv[1]);
getch();
InitScreen();
ReadHeader();
ReadImg();
getch();
}

Department Of Computer Science, 22


KBN. College Of Engineering, Gulbarga.

Potrebbero piacerti anche