/*
*Madison Noyce
*11/17/22
*Lab Section 1011-007
*Lab 11
*This program will take pixels from a source and send them along with an
*image header to an outside source such as Gimp but in a smaller size with
*file pointers.
*/

#include "defs.h"

//Prints the original pixels to stdout
void writePixels(pixelValues picture[], int width, int height, FILE *outFile) {
        int h;
	for (h = 0; h < width * height; h++) {
                fprintf(outFile, "%d %d %d\n", picture[h].r, picture[h].g,
                picture[h].b);
        }
}

//Prints the shrunken image
void halfSizeWritePixels(pixelValues smallPicture[], int width, int height, FILE *outFile) {
        int h, w, i = 0;
	for (h = 0; h < height; h += 2) {
		for (w = 0; w < width; w += 2) {
			pixelValues average;
                	average.r = (smallPicture[i].r + 
			smallPicture[i+1].r + smallPicture[i+width].r + 
			smallPicture[i+width+1].r) / 4;
                	average.g = (smallPicture[i].g + 
			smallPicture[i+1].g + smallPicture[i+width].g + 
			smallPicture[i+width+1].g) / 4;
                	average.b = (smallPicture[i].b + 
			smallPicture[i+1].b + smallPicture[i+width].b + 
			smallPicture[i+width+1].b) / 4;
			fprintf(outFile, "%d %d %d\n", average.r, 
			average.g, average.b);
			average.r = 0;
			average.g = 0;
			average.b = 0;
			i += 2;
		}
		i += width;
	}
}
