// imageproc_03.cpp - image processing +++++++
#include <iostream>
#include <fstream>
const int WIDTH = 100;
const int HEIGHT = 100;

void processPixel(unsigned char arr[], unsigned char val, int pos);

int main() {
  using namespace std;
  
  unsigned char pix = 0;
  
  char outFileName[20];

  unsigned char imgArray[WIDTH*HEIGHT];
  unsigned char imgArray2[WIDTH*HEIGHT];

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

  // reading image into imgArray + initializing 
  // imgArray2 in same loop
  for(int i=0;i<WIDTH*HEIGHT;i++) {
    inFile >> imgArray[i];
    imgArray2[i] = pix;
  }

  // process image
  for(int i=0;i<WIDTH*HEIGHT;i++)
    processPixel(imgArray2, imgArray[i], i);

  // output new array to image
  for(int i=0;i<WIDTH*HEIGHT;i++)
    outFile << imgArray2[i];
    
  inFile.close();
  outFile.close();
}

void processPixel(unsigned char arr[], unsigned char val, int pos) {
  int xVal = pos % WIDTH;
  int yVal = pos / HEIGHT;

  if (xVal%4 == 2 && yVal%4 == 2) {
    arr[pos-WIDTH] = val;
    arr[pos+WIDTH] = val;
    arr[pos+1] = val;
    arr[pos-1] = val;
    arr[pos] = val;
  }

}
