This commit is contained in:
2024-08-07 09:16:27 -04:00
parent fdfadd5c7e
commit 5f971cf684
5200 changed files with 731717 additions and 0 deletions

168
thumbnail/Main.cpp Normal file
View File

@@ -0,0 +1,168 @@
#include <common/purehdc.hpp>
#include <common/pathfnd.hpp>
#include <common/profile.hpp>
#include <common/diskinfo.hpp>
#include <common/file.hpp>
#include <common/except.hpp>
#include <jpeg-6b/bmpjpg.hpp>
#include <jpgimg/jpgimg.hpp>
#include <thumbnail/options.hpp>
void convert(const String &strPathFileName,const String &strPathSaveFile,int width);
//Console console(Console::ConsoleType(Console::Write|Console::Read),false);
void writeLine(const String &string);
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())
{
writeLine("USAGE -s <sourcedir> -d <destinationdir> -iw <imagewidth> -tw <thumbnailwidth> -q <quality>");
return;
}
writeLine("2001 diversified software solutions \"http://www.diversified-software.com\"");
writeLine(String("source-path:")+options.getInputPath());
writeLine(String("destination-path:")+options.getOutputPath());
writeLine(String("thumbnail-width:")+String().fromInt(options.getThumbnailWidth()));
writeLine(String("image-width:")+String().fromInt(options.getImageWidth()));
writeLine(String("quality:")+String().fromInt(options.getQuality()));
strPathDirectory=options.getInputPath()+String("\\");
strPathDestination=options.getOutputPath()+String("\\");
pathFind.fileList(strPathDirectory+strMask+strExtension,entryList);
if(!entryList.size())
{
writeLine("No entries found.");
return;
}
if(!outFile.open(strPathDestination+strPathHTML,"wb"))
{
writeLine(String("Unable to create ")+String("'")+strPathDestination+strPathHTML+String("'."));
return;
}
outFile.writeLine("<HTML>");
outFile.writeLine("<HEAD>");
outFile.writeLine("<TITLE>Image</TITLE>");
outFile.writeLine("</HEAD>");
outFile.writeLine("<BODY>");
outFile.writeLine("<P>&nbsp;</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;
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 writeLine(String("invalid argument '")+String(argv[arg])+String("'"));
}
if(options.getInputPath().isNull())options.setInputPath(".");
if(options.getOutputPath().isNull())options.setOutputPath(".");
return options;
}
void writeLine(const String &string)
{
::printf("%s\n",string.str());
}