Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ONLY TWO QUESTIONS PLEASE HELP ME...THE CODE ATTATCHED IS WHAT YOU WILL NEED TO ANSWER NUMBER 2. THANK YOU! CODE FOR p04q2.c: // Project 4,

ONLY TWO QUESTIONS PLEASE HELP ME...THE CODE ATTATCHED IS WHAT YOU WILL NEED TO ANSWER NUMBER 2. THANK YOU!

image text in transcribed

CODE FOR p04q2.c:

// Project 4, Question 2 #include  #include  #define FILE_PATH "myBMP.bmp" #pragma warning(disable: 4996) // for Visual Studio Only void loadFile(const char *filename); void hexView(); void changePixelToOrange(); void saveToFile(const char *); unsigned char *fileptr = 0; //to browseavigate through the opened file. unsigned char *fileptrStart = 0; // to save the start address of the file, in case you need to go back to start of file unsigned char fileSize = 0; // stores the size of file /* Problem 1: (10 points) Implement loadfile() to open the myBMP.bmp file. By default, file name is myBMP.bmp Use dynamic memory allocation to store the entire contents of the file and let that memory be pointed by 'fileptr'. Print the size of the file by reading the appropriate byte from BITMAPFILEHEADER. */ void loadFile(const char *filename) { FILE *fp; // Enter your code here printf("File loaded. File size = 0x%x bytes ", fileSize); fclose(fp); } /* Problem 2: (10 points) Even after closing the file with fclose(), we have the contents of the file in memory pointed by 'fileptr'. Display neatly the content of myBMP.bmp file as seen in hex editor. */ void hexView() { // Enter your code here } /* Problem 3: (15 points) Ask the user for a pixel location and store the location in 'row' & 'column'. Change that pixel to orange color. Orange color should be RGB= (255, 163, 26). For instance, if user enters row=2, column=0 then change the pixel (2,0) to orange color. */ void changePixelToOrange() { unsigned int row = 0, col = 0; // Enter your code here printf("Changed pixel (%d, %d) to orange ", row, col); } /* Problem 4: (10 points) Open a new file and write that file with the modified .bmp image with the orange pixel. File name is provided as parameter when calling in main() */ void saveToFile(const char *fileName) { FILE *fp; // Enter your code here fclose(fp); printf("File %s saved. ", fileName); } int main() { printf("CSE 220 p04q2: "); printf("Problem 1: "); loadFile(FILE_PATH); printf("Problem 2: "); hexView(); printf("Problem 3: "); changePixelToOrange(); printf("Problem 4: "); saveToFile("myBMP2.bmp"); //system("pause"); return 0; } 
In this project: You will complete the following tasks. You may use any editor (in Windows or Unix/Linux) for coding and testing, but your code MUST compile and run with GCC on ASU General server 1. Create a .bmp file, called myBMP.bmp that stores the 5x5 image shown in Figure 4. You will need to calculate the number of padding bytes required for the 5 rows. Submit the memory map like Figure 3 which highlights the bitmap file header, bitmap file information header, each row and padding bytes. Submit the .bmp file (10 points) and p04q1.pdf (5 points) for highlighted memory map. Hint: You carn use a hex editor to create the .bmp file and take a screenshot of the hex editor to work on highlighting [15 points] the various sections in Paint or similar app 0 1 2 3 4 0 4 Figure 4. A 5x5 image (BGR values: yellow = (00,ff,ff), white (ff,ff,ff), green (00,ff,00), blue (ff,00,00), red(00,00,f) 2. In the attached file p04q2.c, there are coding questions which use the myBMP.bmp file that you created in the previous question. Solve the questions and submit the solution file as p04q2.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions