/*
Sloane McNelly
11/13/22
CPSC 1011
Section 5
Lab 10
Read in an Image & Modify the Image & Write it Back Out
*/

#include "defs.h"

int main (void){
    
        ppmHeader inputHeader = getHeader();  // read a header from the input file
        ppmHeader halfSizeHeader;
        strcpy(halfSizeHeader.type, inputHeader.type);
        halfSizeHeader.width = inputHeader.width / 2;
        halfSizeHeader.height = inputHeader.height / 2;
        halfSizeHeader.maxColor = inputHeader.maxColor;
		       
        // ppmPixel flagPixels[height*width];
       
        void * pixelsPointer = NULL;
        pixelsPointer = (ppmPixel *)malloc(sizeof(ppmPixel) * inputHeader.height * inputHeader.width);

    
        if (pixelsPointer == NULL) { 
              printf("ERROR");
	      exit(1);
         }

        int num_pix;
        num_pix = inputHeader.height * inputHeader.width;
        fillImageArray(pixelsPointer, num_pix);    // fill our newly allocated memory with pixels

        writeHeader(halfSizeHeader);
        // writePixels(pixelsPointer, inputHeader.width, inputHeader.height);
	halfSizeWritePixels(pixelsPointer, halfSizeHeader.width, halfSizeHeader.height);

   return 0;
}
