#define __VERSION__ 	"39"
#define __REVISION__ 	"1"
#define __NAME__			"ScalePicture"
#define __AUTHOR__		"Markus Hillenbrand"

#include <stream.h>

#include "GUICINCLUDE:GUIC_ProgramArgs.hpp"
#include "GUICINCLUDE:GUIC_Exceptions.hpp"
#include "GUICINCLUDE:GUIC_GGFXPicture.hpp"
#include "GUICINCLUDE:GUIC_System.hpp"

/*********************************************************************************************************/

STRPTR V = "$VER: " __NAME__ " " __VERSION__ "." __REVISION__ " (" __DATE__ ")";

/*********************************************************************************************************/

VOID main (LONG argc, STRPTR argv[])
{
	LONG result[] = { 0,0,0,0 };
	STRPTR templ = "FILENAME/A,WIDTH/N/A,HEIGHT/N/A,DESTINATIONFILE=DF/A";
	GUIC_ProgramArgsC args;
	if (! args.fit(templ, result)) { cerr << "Usage: " << templ << endl; return; }
		
	STRPTR	fileName	= (STRPTR) result[0];
	LONG		width		= *(LONG *) result[1];
	LONG		height		= *(LONG *) result[2];
	STRPTR	destFile	= (STRPTR) result[3];
	
	try
		{
		GUIC_GGFXPictureC pic (fileName);
		
		cout << "Loading picture " << fileName << endl;

		LONG pWidth = pic.getWidth();
		LONG pHeight = pic.getHeight();
		
		cout << "Picture Dimensions: " << pWidth << " x " << pHeight << endl;
		
		if (pWidth > width || pHeight > height)
			{
			cout << "Scaling picture" << endl;
			pic.scaleToBox (width, height);
			cout << "Saving picture as JPEG (90%)" << endl;
			pic.saveJPEG(destFile, 90);
			}
			
		}
	catch (GUIC_Exception &x) { cerr << x.getMessage() << endl; }
}

