Friday, February 5, 2010

Bitmap Image file Validator/Checker

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
#include
#include
#include
#include
#include
#include
#include
#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]);
}
}
//fpath=inname;
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..");
getch();
//main();
// exit(1);
}
printf("Verifying file....");
delay(1000);
bmp(infp);
fclose(infp);
printf("\nPress any key to exit\n");
getch();
// exit(0);
}


No comments:

Popular Posts