// imageproc_01.cpp - intro to image processing
#include <iostream>
#include <fstream>

unsigned char processPixel(unsigned char pixVal);

int main() {
  using namespace std;
  
  unsigned char pix;
  unsigned char newpix;
  
  // using dimensions for looping
  const int WIDTH = 100;
  const int HEIGHT = 100;

  char outFileName[20];
  
  // setting up input and output files
  ifstream inFile;
  inFile.open("face.raw");
  ofstream outFile;
 
  cout << "Enter a output file: ";
  cin >> outFileName;
  outFile.open(outFileName);

  // i am using a for loop here instead of a while
  // loop because if the image used is a JPG, it will
  // appear all screwed up... but still be the correct
  // dimensions.
  for(int i=0;i<WIDTH*HEIGHT;i++) {
    inFile >> pix;

    newpix = processPixel(pix);

    outFile << newpix;
  }
    
  inFile.close();
  outFile.close();
}

unsigned char processPixel(unsigned char pixVal) {

  if (pixVal > 127) return 255;
  else return 0;

}
