/*
Bryce Metz
11/17/22
Section 001
Lab #11
*/

#include<stdio.h>
#include"defs.h"

/*void writePixels(colors colorValues[], int width, int height) {

   for (int i=0;i<width*height;i++) {
            fprintf(stdout, "%i %i %i\n", colorValues[i].r, colorValues[i].g, colorValues[i].b);
   }
}*/

void halfSizeWritePixels(colors colorValues[], FILE * outFile, int width, int height) {

//	outFile = fopen("smallerDisney.pnm", "w");

	for (int k=0;k<(width)*(height);k=k+2) {

	unsigned int averageR;
	unsigned int averageB;
	unsigned int averageG;

		averageR = (colorValues[k].r + colorValues[k+1].r + colorValues[k+width].r + colorValues[k+width+1].r) /4;

		averageG = (colorValues[k].g + colorValues[k+1].g + colorValues[k+width].g + colorValues[k+width+1].g) /4;

		averageB = (colorValues[k].b + colorValues[k+1].b + colorValues[k+width].b + colorValues[k+width+1].b) /4;
if (k+width+1 != width*height-1) {
		fprintf(outFile, "%i %i %i\n", averageR, averageG, averageB);
}
if ((k/width %2) != 0) {
	k = k+width;
}

   }
}
