Bitmap Image file Validator/Checker

5 Feb

I’ve created this program as a part of a project ‘Image Enhancer’. This Program can be used

//Checking and validation of an BMP ImageFile
#define BMPTYPE (((WORD) ‘M’ << 8) | ‘B’) /* 1st 2bytes must==’BM’ */ typedef unsigned char BYTE; typedef unsigned short WORD; typedef unsigned long DWORD; typedef struct tagBMPFILEHEADER { WORD bfType; WORD bfSize; } BMPFILEHEADER; typedef struct tagBMPINFOHEADER { DWORD biSize; DWORD biWidth; DWORD biHeight; WORD bibitCount; DWORD biSizeImage; DWORD biClrUsed; } BMPINFOHEADER; void bmp( FILE *bmpfp) { BMPFILEHEADER bmfh; BMPINFOHEADER bmih; int i, j; printf(“\nReading file.\n”); delay(2000); if( fread( &bmfh, sizeof( BMPFILEHEADER), 1, bmpfp) != 1) { printf(“Error reading file.\n”); printf(“Try again..”); getch(); }else { printf(“\nHeader Reading Successfully Completed.\n”); delay(2000); if( fread( &bmih, sizeof( BMPINFOHEADER), 1, bmpfp) != 1) { printf(“Error reading file info header…\n”); printf(“Try again..”); getch(); } else { printf(“\nChecking the file # 1.\n”); if( bmfh.bfType != BMPTYPE) { printf(“.BMP is not a valid bitmap.\n”); return; } else { printf(“\nSuccessfully Completed file type checking.\n”); // printf(“bfType Value:%d”,bmfh.bfType); } printf(“\nChecking the file # 2.\n”); delay(2000); if( bmih.bibitCount != 24) { printf(“Not a valid 24bit BMP file.\nPress to Exit”); } else { printf(“\nSuccessfully completed bitcount check.\n”); // printf(“BitCount Value:%d”,bmih.bibitCount); printf(“\nThis is a valid BMP Image File..\nFile Details are…”); } // printf(“Header: %ld bytes\nImage: %ld bytes\n”, // bmih.biSize, bmfh.biSizeImage); // printf(“Pixels %ld x %ld\n Colors: %ld\n”, // bmih.biWidth, bmih.biHeight, bmih.biClrUsed); return; } }} void main()//( int argc, char **argv) { clrscr(); char inname[100]; int i,length; printf(“* * * * * * BMP Image Validator * * * * *\n”); printf(“_________________________________________\n\n\n\n”); printf(“\nEnter the file path(Ex=c:\tc\text.bmp):”); scanf(“%s”,&inname); length = strlen(inname); for (i = 0; i < length; i++) { if ((inname[i] >= ‘a’) && (inname[i] <= ‘z’)){
inname[i] = toupper(inname[i]);
FILE *infp;
//strcpy( inname, argv[1]);
infp = fopen( inname, “r”);
if( ! infp)
printf(“\n Unable to open %s for input\n”, inname);
printf(“Try again..”);
// exit(1);
printf(“Verifying file….”);
printf(“\nPress any key to exit\n”);
// exit(0);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: