//==============================================================================
//
// pgmmultcs.c
//
// use:
// pgmmultcs const file.pgm result.pgm
//
//==============================================================================

#include <stdio.h>
#include "pgm.h"

int main(int nArg, char** ppArg)
{
	int i;
	int nW, nH; // image width and height
	int nBr;    // image brightness
	byte* pIm;  // pointer to image matrix
	int nSize;  // image size in bytes
	float fConst;
	int n;

	if(nArg==1) 
	{
		puts("multiplication of image onto ploating point constant");
		puts("pgmmultcs const file.pgm result.pgm");
		exit(1);
	}

	
	fConst = atof(ppArg[1]);
//	printf("%f\n", fConst);
	
	ReadPGM(ppArg[2], &pIm, &nW, &nH);
	
	nSize = nW * nH;
	
	for(i=0; i<nSize; i++)
	{
		n =(int) ((float) pIm[i]*fConst);
		if(n<0) n = 0;
		else if(n>255) n = 255;
		pIm[i] = n;
	}
	
	WritePGM(ppArg[3], pIm, nW, nH);
	
	free(pIm);
	
	return 0;
}