Question: using C language with comments answer the following programming question Please write a C program brightness, which should print the average brightness of a grayscale
using C language with comments answer the following programming question


Please write a C program brightness, which should print the average brightness of a grayscale image. Every pixel in a grayscale image has a brightness between 0 and 1, where 0 is black and 1 is as bright as possible. Print the average brightness using decimal notation with exactly one digit before the decimal point and three digits after the decimal point. Print only the brightness. The program takes at most one argument: If an argument is given, it should be the name of a portable graymap file (in pgm format). If no argument is given, brightness reads from standard input, which should contain a portable graymap. If more than one argument is given, brightness halts with an error message. If a portable graymap is promised but not delivered, brightness should halt with some sort of error message on stderr. (Any message will do, but do print a message on standard error, and don't produce anything on standard output especially not a senseless answer.) Examples: Here are two photos: Black cat in a coal cellar Polar bear in a snowstorm . If cellar.pgm is a picture of a black cat in a coal cellar at midnight, and if bear.jpg is a picture of a polar bear in an snowstorm, then output should look something like this: homework{ndaniels}: brightness cellar.pgm 0.000 homework{ndaniels}: djpeg -grayscale bear.jpg | brightness 0.972 The first example takes its input from a file named on the command line, and the second example takes its input from standard input, as part of a Unix pipeline. My solution to this problem takes fewer than 35 lines of C code. Help with image files We provide code to help you read image files; you will find the Pnmrdr interface in /usr/local/include/pnmrdr.h and the implementation in /usr/local/lib/libpnmrdr.a. Creating a Pnmrdr_T will read the graymap header for you, and from the header you can compute how many pixels are in the image. (You should read exactly as many pixels as are there no more, no fewer.) Don't forget that the brightness of each pixel is represented as a scaled integer, as described in the Pnmrdr interface. Getting images You can get images to play with by using one or more of the following programs: djpeg (use the -grayscale option) pngtopnm pstopnm ppmtopgm . . 0 Problem analysis and advice The main issues here are: In place of much of the C++ technique you already know, you have new C technique to learn. The ideas are all similar
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
