Program 2: Grayscale Converter


Summary | Instructions | PPM Format | PGM Format | Submission Instructions

Summary and Goal

Read in a PPM file and output it as grayscale in PGM format.

Instructions

  • Write a program in C to read a PPM file from standard in and output put it in grayscale using PGM format to standard out.
  • The color-to-grayscale conversion to be used is
    luminance = red * .3 + green * .59 + blue * .11 . Make sure to round.
  • To test your program, redirect a PPM file to standard in, and redirect to output to a file. e.g. grayscale < in.ppm > out.pgm
  • If you wish to reduce the file size without losing information, use IrfanView to convert your ppm file to png.
  • View the output with an image viewer.
  • You may use 101asg2in1.png and 101asg2in2.png to test your program. Be sure to convert these files to PPM format before you use them.
  • You may use 101asg2out1.png and 101asg2out2.png to compare with your results.
  • You can convert png to ppm format with IrfanView

Style

  • Use either 3 or 4 spaces for each indentation. Be consistent. Pick a number and stay with it.
  • Do not use tabs to indent because the printer does not have the same tab spacing as the computer. Use the space bar to indent.
  • Put every C statement a separate line.
  • (Optional) If the condition for execution, such as in a while or if statement can be written in the form "( constant == var )" it may not be written in the form "( var == constant )".
  • Comments must be included when they will aid the reader in understanding the program. Do not comment the obvious. Comment what you are doing, not how.
  • Use meaningful variable names. Long names are better than unclear names.
  • Do not use the single letter 'o' or the single letter 'l' for variable names.
  • Use white space to set off logical ideas. Comment logical blocks.

Assignment Credit

If you correctly complete this assignment, your maximum grade is a 95%. However, you may do any or all of the following extra credit options.
  • Turn this assignment in a full 24 hours early (to the minute) to receive an extra 5 points.
  • Do some other interesting transformation to the image and output it at PPM format. Examples are fading the image, color balancing, duotoning to a color other than gray, and changing the colors to be more cartoony.
  • For this assignment, there will be no "first in" extra credit. Instead, The best extra credit image effect will be awarded an extra 5 points. (second receives 4 points, etc.)

Submission Instructions

  • Your C program file should be named grayscale.c .
  • Hand in grayscale.c no later than 11:59 p.m. Friday, October 17th .
  • Email grayscale.c as an attachment to your lab professor. Paste into the subject line CSC 112 Program 2 grayscale.c
    1. source code attachment

    2. subject line: CSC 112 Program 2 grayscale.c

  • Keep the email submission confirmation for reference later.


Summary | Instructions | PPM Format | PGM Format | Submission Instructions