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

void Image::writePPM(char *filename) {
  FILE *out;
  out = fopen(filename, "wb");
  if (!out) {
    fprintf(stderr, "Can't open output file %s\n", filename);
    return;
  }
  fprintf(out, "P6\n");   // color rawbits format
  fprintf(out, "%d %d\n%d\n", hReso, vReso, 100); 
  
  unsigned char r, g, b;
  for (int y = 0; y < vReso; y++) { //down
      for (int x = 0; x < hReso; x++) { //across
	  r = (unsigned char) 100*(*this)[vReso-y-1][x][0];  
	  g = (unsigned char) 100*(*this)[vReso-y-1][x][1];  
	  b = (unsigned char) 100*(*this)[vReso-y-1][x][2];  
	  fprintf(out, "%c%c%c", r, g, b);
      }
  }
  fprintf(out, "\n");
  fclose(out);
}

