156 lines
4.9 KiB
C++
156 lines
4.9 KiB
C++
#include <common/purehdc.hpp>
|
|
#include <common/pathfnd.hpp>
|
|
#include <common/profile.hpp>
|
|
#include <common/console.hpp>
|
|
#include <common/diskinfo.hpp>
|
|
#include <common/file.hpp>
|
|
#include <common/except.hpp>
|
|
#include <jpeg-6b/bmpjpg.hpp>
|
|
#include <jpgimg/jpgimg.hpp>
|
|
#include <proto/options.hpp>
|
|
|
|
void convert(const String &strPathFileName,const String &strPathSaveFile,int width);
|
|
|
|
Console console(Console::ConsoleType(Console::Write|Console::Read));
|
|
Options getOptions(int argc,char **argv);
|
|
|
|
void main(int argc,char **argv)
|
|
{
|
|
Block<String> entryList;
|
|
PathFind pathFind;
|
|
String strExtension(".jpg");
|
|
String strMask("*");
|
|
String strPathDirectory;
|
|
String strPathDestination;
|
|
String strPathHTML("index.html");
|
|
File outFile;
|
|
Profile profile;
|
|
DiskInfo diskInfo;
|
|
Options options;
|
|
|
|
options=getOptions(argc,argv);
|
|
if(1==argc||options.getHelp())
|
|
{
|
|
console.writeLine("USAGE -s <sourcedir> -d <destinationdir> -iw <imagewidth> -tw <thumbnailwidth> -q <quality>");
|
|
console.read();
|
|
return;
|
|
}
|
|
console.writeLine("2001 diversified software solutions \"http://www.diversified-software.com\"");
|
|
console.writeLine(String("source-path:")+options.getInputPath());
|
|
console.writeLine(String("destination-path:")+options.getOutputPath());
|
|
console.writeLine(String("thumbnail-width:")+String().fromInt(options.getThumbnailWidth()));
|
|
console.writeLine(String("image-width:")+String().fromInt(options.getImageWidth()));
|
|
console.writeLine(String("quality:")+String().fromInt(options.getQuality()));
|
|
strPathDirectory=options.getInputPath()+String("\\");
|
|
strPathDestination=options.getOutputPath()+String("\\");
|
|
pathFind.fileList(strPathDirectory+strMask+strExtension,entryList);
|
|
if(!entryList.size())return;
|
|
if(!outFile.open(strPathDestination+strPathHTML,"wb"))return;
|
|
outFile.writeLine("<HTML>");
|
|
outFile.writeLine("<HEAD>");
|
|
outFile.writeLine("<TITLE>Image</TITLE>");
|
|
outFile.writeLine("</HEAD>");
|
|
outFile.writeLine("<BODY>");
|
|
outFile.writeLine("<P> </P>");
|
|
|
|
diskInfo.createDirectory(strPathDestination);
|
|
for(int index=0;index<entryList.size();index++)
|
|
{
|
|
String strPathFileName=strPathDirectory+entryList[index];
|
|
String strPathImageSmall=entryList[index];
|
|
String strPathImageLarge=entryList[index];
|
|
profile.makeFileName(strPathImageSmall);
|
|
profile.makeFileName(strPathImageLarge);
|
|
profile.removeExtension(strPathImageSmall);
|
|
profile.removeExtension(strPathImageLarge);
|
|
strPathImageSmall+=String("_s")+strExtension;
|
|
strPathImageLarge+=String("_l")+strExtension;
|
|
console.writeLine(String("converting ")+strPathFileName+String(" ")+String().fromInt(index+1)+String(" of ")+String().fromInt(entryList.size()));
|
|
convert(strPathDirectory+entryList[index],strPathDestination+strPathImageLarge,options.getImageWidth());
|
|
convert(strPathDirectory+entryList[index],strPathDestination+strPathImageSmall,options.getThumbnailWidth());
|
|
outFile.writeLine(String("<A HREF=\"")+strPathImageLarge+String("\"><IMG BORDER=\"2\" SRC=\"")+strPathImageSmall+String("\">"));
|
|
}
|
|
outFile.writeLine("</BODY>");
|
|
outFile.writeLine("</HTML>");
|
|
}
|
|
|
|
void convert(const String &strPathFileName,const String &strPathSaveFile,int width)
|
|
{
|
|
JPGImage jpgImage;
|
|
PureDevice screenDevice;
|
|
Profile profile;
|
|
String strSaveFileName;
|
|
String strPathDirectory;
|
|
DiskInfo diskInfo;
|
|
|
|
strPathDirectory=strPathFileName;
|
|
profile.makeFileName(strPathFileName,strSaveFileName);
|
|
strSaveFileName=strSaveFileName.betweenString(0,'.');
|
|
strSaveFileName+=".bmp";
|
|
profile.makeDirectoryName(strPathDirectory);
|
|
strPathDirectory+=String("\\")+strSaveFileName;
|
|
screenDevice.screenDevice();
|
|
jpgImage.decode(strPathFileName,screenDevice);
|
|
jpgImage.resample(screenDevice,width);
|
|
jpgImage.saveBitmap(strPathDirectory);
|
|
ImageConverter::convert(strPathDirectory,strPathSaveFile,100);
|
|
diskInfo.unlink(strPathDirectory);
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
-s sourcedir
|
|
-d destination
|
|
-iw imagewidth
|
|
-tw thumbnailwidth
|
|
-q quality
|
|
-? display help
|
|
|
|
|
|
*/
|
|
|
|
Options getOptions(int argc,char **argv)
|
|
{
|
|
Options options;
|
|
for(int arg=1;arg<argc;arg+=2)
|
|
{
|
|
String argument(argv[arg]);
|
|
argument.lower();
|
|
if(argument=="-s")
|
|
{
|
|
try{options.setInputPath(argv[arg+1]);}
|
|
catch(...){}
|
|
}
|
|
else if(argument=="-d")
|
|
{
|
|
try{options.setOutputPath(argv[arg+1]);}
|
|
catch(...){}
|
|
}
|
|
else if(argument=="-iw")
|
|
{
|
|
try{options.setImageWidth(String(argv[arg+1]).toInt());}
|
|
catch(...){options.setImageWidth(640);}
|
|
}
|
|
else if(argument=="-tw")
|
|
{
|
|
try{options.setThumbnailWidth(String(argv[arg+1]).toInt());}
|
|
catch(...){options.setThumbnailWidth(220);}
|
|
}
|
|
else if(argument=="-q")
|
|
{
|
|
try{options.setQuality(String(argv[arg+1]).toInt());}
|
|
catch(...){options.setQuality(100);}
|
|
}
|
|
else if(argument=="-?")
|
|
{
|
|
options.setHelp(true);
|
|
}
|
|
else console.writeLine(String("invalid argument '")+String(argv[arg])+String("'"));
|
|
}
|
|
if(options.getInputPath().isNull())options.setInputPath(".");
|
|
if(options.getOutputPath().isNull())options.setOutputPath(".");
|
|
|
|
return options;
|
|
}
|