The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 2 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
#c code only. not java or c++.
Â
Hi, can you please code this in c and make sure it pass all the given tests provided in the doc. thanks
Colour Palette
You are tasked with writing a program that will discover and index the colour palette of an image by iterating through image data and extract the colour value. The colour value is represented by an unsignedinteger value. It is recommended you use stdint.h and utilise uint8_t or uint32_t for reading in the data. We also recommend you implement this program using a linked list or use realloc.
Â
The program will take in a filename from the command line.
./index image
Â
If no argument is specified, the program should respond with:
No Filename Specified
Â
If the file does not exist, your program needs to respond with:
File Does Not Exist
Â
The file format is a type of bitmap image in binary format. The top of the file will specify the width and height of the image as well as a 2 byte magic number to confirm that it is a valid type. Each 4 bytes in the image data corresponds to 1 pixel in the image.

The magic number in decimal form is: 60535
If the magic number does not match with the file specified. The program respond:
Invalid Image Header
and terminate with exit code 1
Â
If the number of pixels in the image do no match the width * height then the program should respond with:
Invalid Image Data
and terminate with exit code 1
Â
Each 4 bytes of the image data contains (Red, Green, Blue, and 1byte of 0 Padding).
When you encounter a new pixel, you are to record it into your own 2d array of width * height.
Â
The next time you see the same pixel value again, your program is to identify that it exists in your list and use the same index.
Â
All image files have been included for you to test your code on.
Â
Example1 (5x5):
./index imgd.b
Â
[ 0, 0, 1, 1, 0 ]
[ 1, 2, 1, 1, 0 ]
[ 2, 1, 2, 1, 2 ]
[ 1, 0, 0, 0, 0 ]
[ 2, 0, 2, 1, 0 ]
Â
Example2 (2x2 image):
./index imge.b
Â
[ 0, 0 ]
[ 1, 1 ]
Â
Â
index.c:
Â
Â
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
Â
//You may modify/add/remove structs
Â
typedef struct pixel_tpixel_t;
Â
struct pixel_t {
               uint8_t red;
               uint8_t green;
               uint8_t blue;
               uint8_t empty;
};
Â
intmain(intargc, char** argv) {
              Â
               return 0;
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly