// Built by Peter A Noble November 2023 Email: panoble2017@gmail.com
// Copyright 2023

#include <fstream>
#include <string>
#include <iostream>
#include <cstdlib>
#include <float.h>
#include <cmath>

// g++ image_look.cpp -o image_look
// convert output_image.png -compress none output_image.ppm
// convert image_9994_label_1.png -compress none image_9994_label_1.ppm

// convert 3.png -compress none 3.ppm
// convert *.png -compress none *.ppm
// ./image_look *.ppm *.txt
// ./image_look 3.ppm 3_array.txt
// ./image_look 11.ppm 11_array.txt
// ./image_look image_9994_label_1.ppm image_9994_label_1.txt

// purpose is to look at the stone image 
using namespace std;

int main (int argc, char * const argv[]) {

int X=0;
int Y=0;

ifstream in(argv[1]);   	//small.txt		
ofstream out(argv[2]); 		

#define columns 4096
#define rows 4096

int** Bb= new int*[columns];
	for (int s=0;s< columns; s++)
		{
		Bb[s]= new int[rows];
		for (int t=0;t< rows; t++)
			{
			Bb[s][t]=0;
			}
		}
int** Br= new int*[columns];
	for (int s=0;s< columns; s++)
		{
		Br[s]= new int[rows];
		for (int t=0;t< rows; t++)
			{
			Br[s][t]=0;
			}
		}
int** Bg= new int*[columns];
	for (int s=0;s< columns; s++)
		{
		Bg[s]= new int[rows];
		for (int t=0;t< rows; t++)
			{
			Bg[s][t]=0;
			}
		}

int Bwidth=0;
int Bheight=0;;
int BRGB=0;;
int x=0;
int y=0;
char type[10]; 

in >> type; //if (strcmp(type,"P3")!=0) {cerr << "ERROR:Incorrect file type or missing file. File has to be P3\n"; exit(1);}
in >> Bwidth;  //x
in >> Bheight; //y
in >> BRGB;

//cout << type << "\t" << Bwidth << "\t" << Bheight << "\t" << BRGB << "\n" << flush;; exit(1);
// build large array
while(!in.eof())
	{
	for (int y=0;y<Bheight;y++)
		{ 
		for (int x=0;x<Bwidth;x++)
			{ 
			in >> Br[x][y]; //out << r[x][y] << "\t";
			in >> Bg[x][y]; //out << g[x][y] << "\t";
			in >> Bb[x][y]; //out << b[x][y] << "\t";
			}	
		}
	}
for (int y=0;y<Bheight;y++)  // outputs entire x-ray
		{ 
		for (int x=0;x<Bwidth;x++)
			{ 
			out << Br[x][y] << "\t";
			out << Bg[x][y] << "\t";
			if (x==(Bwidth-1)) {out << Bb[x][y] << "\n";}
			else {out << Bb[x][y] << "\t";}
			}
//		out << "\n";
		}

return 0;
}
