//=======================================================================================
//
// template for still image processing
//
// templ_pgm.c
//
// developer: Henry Guennadi Levkin
//
// templ_pgm file.pgm
//
// result in res.pgm
//
//=======================================================================================

#include "templ_pgm.h"

//=======================================================================================
// global variables

FILE* gFp; // logging file

int gW;      // image width
int gH;      // image height

byte* gpInp; // input image (from file)
byte* gpOut; // output image

//=======================================================================================
void AllocateMem()
{
 gpOut = malloc(gW * gH);
}

//=======================================================================================
void FreeMem()
{
 free(gpOut);
 free(gpInp);
}

//=======================================================================================
void ImageCopy(byte* pInp, byte* pOut, int nWidth, int nHeight)
{
 int i;
 int nSize = nWidth*nHeight;
 
 for(i=0; i<nSize; i++) pOut[i] = pInp[i];

}

//=======================================================================================
int main(int nArgs,char** ppArgs)
{
 char filename[256];

 puts("======================================================");
 puts("Still image processing:");
 gFp = fopen("log.txt", "w");

 strcpy(filename, ppArgs[1]);

 // read pgm image file
 if( ReadPGM(filename, &gpInp, &gW, &gH) )
 {
 	printf("Can't open file\n");
 	return 1;
 };

 //-------------
 AllocateMem();

 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 // image processing and save in gpOut

 ImageCopy(gpInp, gpOut, gW, gH);

 // write result to pgm file
 WritePGM("result.pgm", gpOut, gW, gH);

 //-------------
 FreeMem();
 fclose(gFp);

 return 0;
}

