Question
i have also attached the code that that should be improved upon. thank you. to be done in c UPDATED: EXISTING CODE IN TXT #include
i have also attached the code that that should be improved upon. thank you. to be done in c
UPDATED: EXISTING CODE IN TXT
#include
#include
typedef unsigned char byte;
typedef unsigned short WORD;
typedef unsigned int DWORD;
typedef unsigned int LONG;
struct tagBITMAPFILEHEADER
{
WORD bfType; // specifies the file type
DWORD bfSize; // specifies the size in bytes of the bitmap file
WORD bfReserved1; // reserved; must be 0
WORD bfReserved2; // reserved; must be 0
DWORD bfOffBits; // specifies the offset in bytes from the bitmapfileheader to the bitmap bits
};
struct tagBITMAPINFOHEADER
{
DWORD biSize; // specifies the number of bytes required by the struct
LONG biWidth; // specifies width in pixels
LONG biHeight; // specifies height in pixels
WORD biPlanes; // specifies the number of color planes, must be 1
WORD biBitCount; // specifies the number of bit per pixel
DWORD biCompression; // specifies the type of compression
DWORD biSizeImage; // size of image in bytes
LONG biXPelsPerMeter; // number of pixels per meter in x axis
LONG biYPelsPerMeter; // number of pixels per meter in y axis
DWORD biClrUsed; // number of colors used by the bitmap
DWORD biClrImportant; // number of colors that are important
};
int main(int argc, char *argv[])
{
//float ratio = *argv[2];
FILE *image1 = fopen("lion.bmp", "rb");
FILE *image2 = fopen("wolf.bmp", "rb");
struct tagBITMAPFILEHEADER image1FileHeader;
struct tagBITMAPINFOHEADER image1InfoHeader;
struct tagBITMAPFILEHEADER image2FileHeader;
struct tagBITMAPINFOHEADER image2InfoHeader;
if(image1 == NULL)
{
printf("Error opening image 1 ");
return 0;#include
#include
typedef unsigned char byte;
typedef unsigned short WORD;
typedef unsigned int DWORD;
typedef unsigned int LONG;
struct tagBITMAPFILEHEADER
{
WORD bfType; // specifies the file type
DWORD bfSize; // specifies the size in bytes of the bitmap file
WORD bfReserved1; // reserved; must be 0
WORD bfReserved2; // reserved; must be 0
DWORD bfOffBits; // specifies the offset in bytes from the bitmapfileheader to the bitmap bits
};
struct tagBITMAPINFOHEADER
{
DWORD biSize; // specifies the number of bytes required by the struct
LONG biWidth; // specifies width in pixels
LONG biHeight; // specifies height in pixels
WORD biPlanes; // specifies the number of color planes, must be 1
WORD biBitCount; // specifies the number of bit per pixel
DWORD biCompression; // specifies the type of compression
DWORD biSizeImage; // size of image in bytes
LONG biXPelsPerMeter; // number of pixels per meter in x axis
LONG biYPelsPerMeter; // number of pixels per meter in y axis
DWORD biClrUsed; // number of colors used by the bitmap
DWORD biClrImportant; // number of colors that are important
};
int main(int argc, char *argv[])
{
//float ratio = *argv[2];
FILE *image1 = fopen("lion.bmp", "rb");
FILE *image2 = fopen("wolf.bmp", "rb");
struct tagBITMAPFILEHEADER image1FileHeader;
struct tagBITMAPINFOHEADER image1InfoHeader;
struct tagBITMAPFILEHEADER image2FileHeader;
struct tagBITMAPINFOHEADER image2InfoHeader;
if(image1 == NULL)
{
printf("Error opening image 1 ");
return 0;
}
if(image2 == NULL)
{
printf("Error opening image 2 ");
return 0;
}
// reading in image 1 file header
fread( &(image1FileHeader.bfType), sizeof(WORD), 1, image1);
fread( &(image1FileHeader.bfSize), sizeof(DWORD), 1, image1);
fread( &(image1FileHeader.bfReserved1), sizeof(WORD), 1, image1);
fread( &(image1FileHeader.bfReserved2), sizeof(WORD), 1, image1);
fread( &(image1FileHeader.bfOffBits), sizeof(DWORD), 1, image1);
// reading in image 1 info header
fread( &(image1InfoHeader.biSize), sizeof(DWORD), 1, image1);
fread( &(image1InfoHeader.biWidth), sizeof(LONG), 1, image1);
fread( &(image1InfoHeader.biHeight), sizeof(LONG), 1, image1);
fread( &(image1InfoHeader.biPlanes), sizeof(WORD), 1, image1);
fread( &(image1InfoHeader.biBitCount), sizeof(WORD), 1, image1);
fread( &(image1InfoHeader.biCompression), sizeof(DWORD), 1, image1);
fread( &(image1InfoHeader.biSizeImage), sizeof(DWORD), 1, image1);
fread( &(image1InfoHeader.biXPelsPerMeter), sizeof(LONG), 1, image1);
fread( &(image1InfoHeader.biYPelsPerMeter), sizeof(LONG), 1, image1);
fread( &(image1InfoHeader.biClrUsed), sizeof(DWORD), 1, image1);
fread( &(image1InfoHeader.biClrImportant), sizeof(DWORD), 1, image1);
int image1Bytes = ((image1InfoHeader.biWidth) * 3) * (image1InfoHeader.biHeight);
byte* image1Color = (byte*)malloc(image1Bytes);
byte temp;
for(int i = 0; i
{
fread( &temp, sizeof(byte), 1, image1);
image1Color[i] = temp;
}
fclose(image1);
byte* resultImage = (byte*)malloc(resultBytes);
// write to a new BMP file for result image
FILE *resultImageFile = fopen("merged.bmp", "wb");
// writing image 1 file header to result file
fwrite( &(image1FileHeader.bfType), sizeof(WORD), 1, resultImageFile);
fwrite( &(image1FileHeader.bfSize), sizeof(DWORD), 1, resultImageFile);
fwrite( &(image1FileHeader.bfReserved1), sizeof(WORD), 1, resultImageFile);
fwrite( &(image1FileHeader.bfReserved2), sizeof(WORD), 1, resultImageFile);
fwrite( &(image1FileHeader.bfOffBits), sizeof(DWORD), 1, resultImageFile);
// writing image 1 info header to result file
fwrite( &(image1InfoHeader.biSize), sizeof(DWORD), 1, resultImageFile);
fwrite( &(image1InfoHeader.biWidth), sizeof(LONG), 1, resultImageFile);
fwrite( &(image1InfoHeader.biHeight), sizeof(LONG), 1, resultImageFile);
fwrite( &(image1InfoHeader.biPlanes), sizeof(WORD), 1, resultImageFile);
fwrite( &(image1InfoHeader.biBitCount), sizeof(WORD), 1, resultImageFile);
fwrite( &(image1InfoHeader.biCompression), sizeof(DWORD), 1, resultImageFile);
fwrite( &(image1InfoHeader.biSizeImage), sizeof(DWORD), 1, resultImageFile);
fwrite( &(image1InfoHeader.biXPelsPerMeter), sizeof(LONG), 1, resultImageFile);
fwrite( &(image1InfoHeader.biYPelsPerMeter), sizeof(LONG), 1, resultImageFile);
fwrite( &(image1InfoHeader.biClrUsed), sizeof(DWORD), 1, resultImageFile);
fwrite( &(image1InfoHeader.biClrImportant), sizeof(DWORD), 1, resultImageFile);
// writing image 1 to result file
byte b1;
for(int i = 0; i
{
b1 = *(image1Color + i);
fwrite( &b1, sizeof(byte), 1, resultImageFile);
}
fclose(resultImageFile);
Exercise: Lets speed up working on a file: Read ar bitmap file and change its brightness. However, do this in 2 processes to speed up the CPU worktime. Measure the time with and without forko. Howto: Similar to program 1. read a bitmap (BMP) file into the memory. Allocate your memory with mmapl) and don't forget to set the shared memory flag Fork the process with fork(). Check which process you are. Are you the parent process? Work on the upper half of all povels Child? Work on the lower half. Having an odd number of rows? Catch that problem! Measure the time with and without fork and print the result time! Program call: /yourprogram (IMAGEFILE) (BRIGHTNESS) (PARALLEL (OUTPUTRLE] [IMAGEFILE] that's your bitmap (BRIGHTNESS) a number between 0 and 1 [PARALLEL O for working without fork() and 1 with fork) OUTPUTRILE te output file For the brightness: Every color must add BRIGHTNESS 255, but make sure not to exceed 2551 How we test Very simple: We run your code with and without fork(), check the time gained and check the output image. Submission: Submit the source code file, the executable and the bitmap zipped to: fork.zip help please. i think i know how to read in the blp file but help would be much appreciated. thank you. to be done in c "sorry bmp file Cabac > 1 #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started