/*
	Abigail Thornton
	November 13, 2022 Section 101
	Lab 10B
	Now that the pixel_t flag array has been filled with the pixel color values, this function prints them out. This function averages the r, g, and b pixels and then makes sure that the pixels aren't over the total area and that there is an even number of pixels.
*/
#include <stdio.h>
#include "defs.h"

void writePixels(pixel_t flag[], int width, int height) {
	int k;
	for (k = 0; k < height*width; k++) {
		fprintf(stdout,"%d %d %d\n", flag[k].r, flag[k].g, flag[k].b); 
	}
}

void writeHalfSizePixels(pixel_t flag[], int width, int height) {
	int i;
	unsigned int avgR, avgG, avgB;
	for (i = 0; i < (height*width); i+=2) {
		avgR = ((flag[i].r + flag[i+1].r + flag[i+width].r + flag[i+1+width].r)/4);
		
		avgG = ((flag[i].g + flag[i+1].g + flag[i+width].g + flag[i+1+width].g)/4);
		
		avgB = ((flag[i].b + flag[i+1].b + flag[i+width].b + flag[i+1+width].b)/4);

		if ((i + width + 1) != (height*width) - 1) {
			fprintf(stdout,"%d %d %d\n", avgR, avgG, avgB); 
		}
		if ((i/width) %2 != 0) {
			i = i + width;
		}
	}
}

