you are going to implement an image manipulation sowtware.
The software you will implement will be able to read and write windows BMP color image files.
The required operations that you need to implement is shown in the following sample menu of the program:
WELCOME TO PICTURE APPLICATION
PLEASE SELECT FROM FOLLOWING:
1- LOAD BMP FILE
2- STORE BMP FILE
3- INSERT NAME WATERMARK
4- ROTATE 90 DEGREE CLOCKWISE
5- FLIP HORIZONTAL
6- FLIP VERTICAL
7- DARKEN 10%
First two operations are used to load bitmap file to memory and store file to disk, both with asking filename within program directory.
Third operation, inserts your name to the bottom of files by changing relevant pixels.
Corresponding logo pixel matrix would be constructed as follows (use your name etc.):
After running the code, BMP file should contain your logo at its bottom right corner.
Rotation of 90 degree should rotate the image to its right.
Flipping both horizontal and vertical are also necessary. You may start by writing flipping function.
Darkening 10% requires each RGB component will be multiplied by 0.9 and written back.
This will reduce brightness of the image. You may add extra features for menus 8 and 9 if you like, however it’s not obligatory.
NOTE: You are not going to display the image on screen. No windows is necessary. Use Paint or photoshop to view files.
The BITMAP image file can be of “any” height and width, and the information is stored within the file itself.
You may use 640x480 images to start with. Use attached sample to learn how to read BMP files.
Your program should include all necessary error checking.
/* A SAMPLE PROGRAM DEMONSTRATING HOW TO READ A BITMAP FILE */
/* Structures */
int rows; int cols; unsigned char* data;
/* Functions */
long getImageInfo(FILE*, long, int);
int main(int argc, char * argv)
char signature; /* Signature of the Image File BM = BMP */
int nRows, nCols; /* Row and Column size of the Image */
int xpixpeRm, ypixpeRm; /* Pixel/m */
long nColors; /* BMP number of colors */
long fileSize; /* BMP file size */
long vectorSize; /* BMP's raster data in number of bytes */
int nBits; /* # of BIts per Pixel */
int rasterOffset; /* Beginning of the Raster Data */
printf("Usage: %s bmpInput.bmp\n", argv);
printf("Reading filename %s\n", argv);
if ((bmpInput = fopen(argv, "rb")) == NULL)
printf("Can not read BMP file");
} /* Read BMP input file */
fseek(bmpInput, 0L, SEEK_SET); /* File pointer at byte #0 */
/* Signature of the File BM = BMP at byte # 0*/
for(i=0; i<2; i++)
signature[i] = (char)getImageInfo(bmpInput, i, 1);
if ((signature == 'B') && (signature == 'M')) printf("It is verified that the Image is in Bitmap format\n");
printf("The image is not a bitmap format, quitting....\n");
/* Read BMP bits/pixel at byte #28 */
nBits = (int)getImageInfo(bmpInput, 28, 2);
printf("The Image is \t%d-bit\n", nBits);
/* Position of First Raster Data at byte # 10*/
rasterOffset = (int)getImageInfo(bmpInput, 10, 4);
printf("The beginning of the Raster Data \nis at \t\t%d byte\n", rasterOffset);
/* Read BMP file size at byte # 2 */
fileSize = getImageInfo(bmpInput, 2, 4);
printf("File size is \t%ld byte\n", fileSize);
/* Read BMP width at byte #18 */
nCols = (int)getImageInfo(bmpInput, 18, 4);
printf("Width: \t\t%d\n", nCols);
/* Read BMP height at byte #22 */
nRows = (int)getImageInfo(bmpInput, 22, 4);
printf("Height: \t%d\n", nRows);
/* # of Pixels in a meter in x direction at byte # 38 */
xpixpeRm = (int)getImageInfo(bmpInput, 38, 4);
printf("Image has \t%d pixels per m in x-dir.\n", xpixpeRm);
/* # of Pixels in a meter in y direction at byte # 42 */
ypixpeRm = getImageInfo(bmpInput, 42, 4);
printf("Image has \t%d pixels per m in y-dir.\n", ypixpeRm);
/* Read number of colors at byte #46 */
nColors = pow(2L,nBits);
printf("There are \t%ld number of Colors \n", nColors);
vectorSize = (long)((long)nCols*(long)nRows);
printf("Vector Size is \t%ld\n", vectorSize);
} /* end of main */
long getImageInfo(FILE* inputFile, long offset, int numberOfChars)
unsigned char *ptrC;
unsigned char dummy;
dummy = '0'; ptrC = &dummy;
fseek(inputFile, offset, SEEK_SET);
for(i=1; i<=numberOfChars; i++)
fread(ptrC, sizeof(char), 1, inputFile);
value = (long)(value + (*ptrC)*(pow(256, (i-1))));
} /* end of getImageInfo */
/******************* END *********************/