Youll write a program named imgGen that creates asimple Portable GrayMap (PGM) image file. Your program will
Question:
You’ll write a program named imgGen that creates asimple Portable GrayMap (PGM) image file.
Your program will create the file data in memory (in a2-d array) and then write it to a disk file
You’ll then view the resulting image file usingirfanview or gimp to verify it’s correct.
irfanview is an image viewer. Fairly smalldownload.
gimp is an image editor. Much largerdownload.
You can download either of those for free. Use google tofind them.
Details
The format of the PGM image file you’ll create isdescribed here:http://en.wikipedia.org/wiki/Netpbm_format#PGM_example
The image must:
be at least 300 pixels wide by 200 pixelstall
consist of grayscale values from 0 to 255
contain at least two rectangles
contain at least two circles (to have the possibility ofgetting an A).
Your program’s main will declare the array, then callthe following two functions (which you’ll write):
void createImage(unsigned char image[][WIDTH], intheight );
bool writeImage(const unsigned char image[][WIDTH], intheight, const string fileName );
The createImage() function will create all the image’spixel values. It must make use of the following function (whichyou’ll write)
void drawrect(unsigned char image[][WIDTH], intimgHeight,
intrectTop, int rectLeft, int rectHeight, int rectWidth, unsigned chargrayLevel);
And to have the possibility of getting anA:
void drawcircle(unsigned char image[][WIDTH], intheight,
intcenterX, int centerY, int radius, unsigned chargrayLevel)
The writeImage() function will write the array data tothe specified text file (along with the necessary headerlines).
Things to keep in mind about arrays
Arrays are always passed to functions by reference; no& required.
You can pass one row of a two-dimensional array to afunction that will then receive it as a single dimensional array.Again, it’s passed by reference and no & isrequired.
When things are passed by reference and are not going tobe changed), you should put const in front of the parameterdeclaration.
Arrays can be big, and the stack might not be big enoughto hold it, so if it doesn’t fit on the stack you can move it tothe heap by making the array variable static (put the word staticbefore it).