#include "config.h"
#include "ImgLoader.h"
#include "ImgSaver.h"
#include <locale.h>
int wmain(int argc, wchar_t** argv)
{
	setlocale(LC_ALL, "chs");
	CImageFactory imgFactory;

	//加载Gdiplus上的图片编解码器
	imgFactory.RegisterLoader(TplClassOfLoader<CImgLoaderByGdiplus>());
	imgFactory.RegisterSaver(TplClassOfSaver<CImgSaverByGdiplus>());

#ifdef SUPPORT_FREEIMAGE
	//加载FreeImage图片解码器
	imgFactory.RegisterLoader(TplClassOfLoader<CImgLoaderByFreeImage>());
#endif

#ifdef SUPPORT_SVG_TYPE
	imgFactory.RegisterLoader(TplClassOfLoader<CImgLoaderByNanoSvg>());
#endif

	//处理外部传入参数
	if (argc < 3)
	{
		std::wstring szImgList;
		imgFactory.GetImgListForSaver(szImgList);
		std::wstring szTemp(L"用来指定编码器，可选参数：");
		szTemp += szImgList;
		wprintf(L"imageConverter.exe srcPath destPath [imgType]\n"
			L"%-15s%s\n"
			L"%-15s%s\n"
			L"%-15s%s\n",
			L"srcPath", L"图片输入路径，如input.png",
			L"destPath", L"图片输出路径，如output.jpg",
			L"[imgType]", szTemp.c_str()
		);
		wprintf(L"按任意键退出...");
		getchar();
		return 0;
	}

	//图片格式转换
	Gdiplus::Image *pImg = imgFactory.InvokeLoader(argv[1]);
	imgFactory.InvokeSaver(argv[2], pImg, argv[3]);
	delete pImg;
	pImg = NULL;
    return 0;
}
