Displaying Source Code(s)
|
|
BitmapViewer (Mini Project)
--------------------------------------------------------------------------------
Description : This program is used to view the bitmap files.
/*
B.Chidhambaram
M.Sc.Software Engg, Final Year
Noorul Islam College of Engg
Mobile No : 9894586845
*/
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
#include<string.h>
/* mouse.h */
union REGS i,o;
void InitMouse();
void ShowMousePtr();
void GetMousePos(int*,int*,int*);
void HideMousePtr();
void RestoreMousePtr();
void RestrictMousePtr(int, int, int, int);
void SetMousePtr(int , int);
void InitMouse()
{
i.x.ax = 0;
int86(0x33,&i, &o);
}
void ShowMousePtr()
{
i.x.ax = 1;
int86(0x33, &i, &o);
}
void HideMousePtr()
{
i.x.ax = 2;
int86(0x33, &i, &o);
}
void GetMousePos(int button[1], int x[1], int y[1])
{
i.x.ax = 3;
int86(0x33, &i, &o);
button[0]=o.x.bx;
x[0]=o.x.cx;
y[0]=o.x.dx;
}
void RestoreMousePtr()
{
i.x.ax = 7;
i.x.cx = 0;
i.x.dx = 79*8;
int86(0x33, &i, &o);
i.x.ax = 8;
i.x.cx = 0;
i.x.dx = 24*8;
int86(0x33, &i, &o);
}
void RestrictMousePtr(int x1, int y1, int x2, int y2)
{
i.x.ax = 7;
i.x.cx = x1;
i.x.dx = x2;
int86(0x33, &i, &o);
i.x.ax = 8;
i.x.cx = y1;
i.x.dx = y2;
int86(0x33, &i, &o);
}
void SetMousePtr(int x, int y)
{
i.x.ax = 4;
i.x.cx = x;
i.x.dx = y;
int86(0x33, &i, &o);
}
/*bmps.h*/
char *FileName;
FILE *fpImage;
long Size;
unsigned char *PixelArray; //for Image pixel values
typedef struct tagBITMAPFILEHEADER
{
char bfType[2]; //Bmp File Type
long bfSize; //Total File Size
int bfReserved1; //Not For Programmers
int bfReserved2; //Not For Programmers
long bfOffBits; //Starting Position Of Data
};
typedef struct tagBITMAPINFOHEADER
{
long biSize; //Structure Size
long biWidth; //Bmp Width
long biHeight; //Bmp Height
int biPlanes;
int biBitCount; //No Of Bits Used
long biCompression;
long biSizeImage; //Bmp Total Size
long biXPelsPerMeter;
long biYPelsPerMeter;
long biClrUsed;
long biClrImportant;
};
typedef struct tagRGBQUAD
{
unsigned char rgbBlue; //Blue Color Value
unsigned char rgbGreen; //Green Color Value
unsigned char rgbRed; //Red Color Value
unsigned char rgbReserved ; //Not For Programmer's Use
};
typedef struct tagBITMAPINFO
{
struct tagBITMAPINFOHEADER bmiHeader; //Bmp Information area
struct tagRGBQUAD bmiColors[256]; //Color Table Entries
};
struct tagBITMAPFILEHEADER bmpFileHeader;
struct tagBITMAPINFO bmpInfo;
void SetGrayScale() //SetGrayScale
{
int i;
struct palettetype pal;
getpalette(&pal);
for (i=0; i<pal.size; i++)
setrgbpalette(pal.colors[i],i*4,i*4,i*4);
}
int Read(char *fname,char *oname)
{
int i,j;
FileName = (char*)malloc(strlen(fname)+1);
strcpy(FileName,fname);
//File Open
if((fpImage=fopen(FileName,"rb"))==NULL)
{
strcpy(oname,"Sorry. File not found !");
return 0;
}
//Read The BitMAP FILE HEADER
if(fread(&bmpFileHeader,sizeof(struct
tagBITMAPFILEHEADER),1,fpImage)==0)
{
strcpy(oname,"File Is A Currupted One");
return 0;
}
if(bmpFileHeader.bfType[0]!='B' || bmpFileHeader.bfType[1]!='M')
{
strcpy(oname,"File Is Not A Bitmap");
return 0;
}
//Read The BITMAP INFO HEADER
if(fread(&(bmpInfo.bmiHeader),sizeof(struct
tagBITMAPINFOHEADER),1,fpImage)==0)
{
strcpy(oname,"File Is A Corrupted One");
return 0;
}
//Reading Color Table
for(i = 0 ;i<256;i++)
if(fread(&(bmpInfo.bmiColors[i]),sizeof(struct
tagRGBQUAD),1,fpImage)==0)
{
strcpy(oname,"File Is A Currupted One");
return -1;
}
strcpy(oname,"Image File is Loaded");
return 1;
}
void Display(char fname[])
{
int i,j;
char temp[30];
cleardevice();
SetGrayScale();
Read(fname,temp);
PixelArray = (unsigned char*)malloc(sizeof(unsigned char*));
for(i=0;i<bmpInfo.bmiHeader.biHeight;i++)
for(j=0;j<bmpInfo.bmiHeader.biWidth;j++)
{
fread(PixelArray,1,1,fpImage) ;
putpixel(j,bmpInfo.bmiHeader.biHeight-i,*PixelArray/16);
}
fclose(fpImage);
}
char *Menus[]={" Load BMP File"," BMP Details"," View Image","
Exit
Program"};
int FileLoaded=0;
char *FileName;
void Box(int x1,int y1,int x2,int y2)
{
rectangle(x1,y1,x2,y2);
rectangle(x1+5,y1+5,x2-5,y2-5);
setfillstyle(SOLID_FILL, 7);
floodfill(x1+1,y2-4,8);
}
void TextBox(int x,int y,int len,char str[])
{
char ch;int curr=0;
setfillstyle(1,15);
bar(x, y-3, x+len, y+23);
setcolor(0);
rectangle(x+1, y-2, x+len-1, y+22);
settextstyle(6,0,1);
HideMousePtr();
do
{
ch=getch();
str[curr]=ch;
if(curr*14 < len)
if(isalpha(ch)||isdigit(ch) ||ch=='.')
if(curr>=0)
curr++;
if(curr > 0 && ch==8)
{
curr--;
bar(x, y-3, x+len, y+23);
rectangle(x+1, y-2, x+len-1, y+22);
}
str[curr]='
|
|
|