BMP Utility for DOS

download BMP Utility for DOS

of 22

Transcript of BMP Utility for DOS

  • 8/7/2019 BMP Utility for DOS

    1/22

  • 8/7/2019 BMP Utility for DOS

    2/22

    BMP Utility for DOS

    Image represents the intensity level by numbers from 0 to 216 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,KBN. College Of Engineering, Gulbarga.

    2

  • 8/7/2019 BMP Utility for DOS

    3/22

    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 comparisonwith 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 doesnt

    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,KBN. College Of Engineering, Gulbarga.

    3

  • 8/7/2019 BMP Utility for DOS

    4/22

    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,KBN. College Of Engineering, Gulbarga.

    4

  • 8/7/2019 BMP Utility for DOS

    5/22

    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,KBN. College Of Engineering, Gulbarga.

    5

  • 8/7/2019 BMP Utility for DOS

    6/22

    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 modelssuch 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,KBN. College Of Engineering, Gulbarga.

    6

  • 8/7/2019 BMP Utility for DOS

    7/22

    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,KBN. College Of Engineering, Gulbarga.

    7

  • 8/7/2019 BMP Utility for DOS

    8/22

    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,KBN. College Of Engineering, Gulbarga.

    8

  • 8/7/2019 BMP Utility for DOS

    9/22

    BMP Utility for DOS

    Bibliography:

    Let us Cby Yashwanth Kanitkar.

    TSR Programming by yashwanth Kanitkar.

    Department Of Computer Science,KBN. College Of Engineering, Gulbarga.

    9

  • 8/7/2019 BMP Utility for DOS

    10/22

  • 8/7/2019 BMP Utility for DOS

    11/22

  • 8/7/2019 BMP Utility for DOS

    12/22

    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,KBN. College Of Engineering, Gulbarga.

    12

  • 8/7/2019 BMP Utility for DOS

    13/22

    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,KBN. College Of Engineering, Gulbarga.

    13

  • 8/7/2019 BMP Utility for DOS

    14/22

    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,KBN. College Of Engineering, Gulbarga.

    14

  • 8/7/2019 BMP Utility for DOS

    15/22

    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

  • 8/7/2019 BMP Utility for DOS

    16/22

    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/7/2019 BMP Utility for DOS

    17/22

    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

  • 8/7/2019 BMP Utility for DOS

    18/22

    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

  • 8/7/2019 BMP Utility for DOS

    19/22

    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

  • 8/7/2019 BMP Utility for DOS

    20/22

    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,KBN. College Of Engineering, Gulbarga.

    20

  • 8/7/2019 BMP Utility for DOS

    21/22

    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,KBN. College Of Engineering, Gulbarga.

    21

  • 8/7/2019 BMP Utility for DOS

    22/22

    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,KBN C ll Of E i i G lb

    22