Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write code in C to apply the following items to each of the files given below: Read a gif file, and store the data into

Write code in C to apply the following items to each of the files given below:

Read a gif file, and store the data into an unsigned char array (unsigned char [4000]) and the data size in an int variable.

Print the width and height, and color table data in the format described below.

Modify the color table based on the rules listed below.

Do #2 again to show the changes

Write the data to a new file.

The code must have the following functions:

int printinfor(unsigned char []); prints out the required information

int readfile(unsigned char [], int*, char []); reads a gif file and stores data into an array Tip: To read binary data from a file, use the fread() function

int writefile(unsigned char [], int, char []); writes image data from an array into a file Tip: To write binary data to a file, use the fwrite() function

----------------------------------------------------------------------------

Format to print a header

You must print the following information in a GIF file. The image width, height, and all the four colors in the color table. The width and height must be printed in unsigned decimal. The colors must be printed as RGB values in hexadecimal.

Width (unsigned decimal)

Height (unsigned decimal)

Color 1 through 4

R value (hexadecimal)

G value (hexadecimal)

B value (hexadecimal)

------------------------------------------------------------------------------

Rules to modify a color table

Apply these rules to each color

By using bitwise operators, check if every RGB value is greater than BF (191 in decimal), but don't use ">", "<", ">=", or "<=".

If it is true, use bitwise operator(s) and divide the RGB values by 2. Don't use "/" or "*".

e.g., F3 will be 79

Otherwise, do the following by bitwise operators (don't use any arithmetic operators such as "+", "-", "++", "--", "*", "/", and "%"):

1. in the R value, raise the 4 lower bits. (The resulted bits will be XXXX1111 where X represents an unchanged bit)

e.g., 31 will be 3F.

2. in the G value, flip the second bit. (The resulted bits will be X*XXXXXX where * is the bit to flip)

e.g., 05 will be 45, and F3 will be B3.

3. in the B value, clear the third and forth bits. (The resulted bits will be XX00XXXX)

e.g., 7A will be 4A.

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

Students also viewed these Databases questions