Added option to choose output file bit depth 8-bit/16-bit from command-line, see --help. Issue 2525

This commit is contained in:
DrSlony
2014-10-21 14:24:38 +02:00
parent 823488966d
commit 1597b0b87d

View File

@@ -88,7 +88,7 @@ static void myGdkLockLeave() {
* -2 if an error occurred during processing
* -3 if at least one required procparam file was not found */
int processLineParams( int argc, char **argv );
int main(int argc, char **argv)
{
setlocale(LC_ALL,"");
@@ -152,40 +152,40 @@ int main(int argc, char **argv)
#ifdef WIN32
bool consoleOpened = false;
if (argc>1 || options.rtSettings.verbose){
if (argc>1 || options.rtSettings.verbose){
if(options.rtSettings.verbose || ( !safe_file_test( safe_filename_to_utf8(argv[1]), Glib::FILE_TEST_EXISTS ) && !safe_file_test( safe_filename_to_utf8(argv[1]), Glib::FILE_TEST_IS_DIR ))) {
bool stdoutRedirectedtoFile = (GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) == 0x0001);
bool stderrRedirectedtoFile = (GetFileType(GetStdHandle(STD_ERROR_HANDLE)) == 0x0001);
// no console, if stdout and stderr both are redirected to file
if( !(stdoutRedirectedtoFile && stderrRedirectedtoFile)) {
// check if parameter -w was passed.
// We have to do that in this step, because it controls whether to open a console to show the output of following steps
bool Console = true;
for(int i=1;i<argc;i++)
if(!strcmp(argv[i],"-w")) {
Console = false;
break;
}
if( !(stdoutRedirectedtoFile && stderrRedirectedtoFile)) {
// check if parameter -w was passed.
// We have to do that in this step, because it controls whether to open a console to show the output of following steps
bool Console = true;
for(int i=1;i<argc;i++)
if(!strcmp(argv[i],"-w")) {
Console = false;
break;
}
if(Console) {
AllocConsole();
AttachConsole( GetCurrentProcessId() ) ;
// Don't allow CTRL-C in console to terminate RT
SetConsoleCtrlHandler( NULL, true );
// Set title of console
char consoletitle[128];
sprintf(consoletitle, "RawTherapee %s Console",VERSION);
SetConsoleTitle(consoletitle);
// increase size of screen buffer
COORD c;
c.X = 200;
c.Y = 1000;
SetConsoleScreenBufferSize( GetStdHandle( STD_OUTPUT_HANDLE ), c );
// Disable console-Cursor
CONSOLE_CURSOR_INFO cursorInfo;
cursorInfo.dwSize = 100;
cursorInfo.bVisible = false;
SetConsoleCursorInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &cursorInfo );
AttachConsole( GetCurrentProcessId() ) ;
// Don't allow CTRL-C in console to terminate RT
SetConsoleCtrlHandler( NULL, true );
// Set title of console
char consoletitle[128];
sprintf(consoletitle, "RawTherapee %s Console",VERSION);
SetConsoleTitle(consoletitle);
// increase size of screen buffer
COORD c;
c.X = 200;
c.Y = 1000;
SetConsoleScreenBufferSize( GetStdHandle( STD_OUTPUT_HANDLE ), c );
// Disable console-Cursor
CONSOLE_CURSOR_INFO cursorInfo;
cursorInfo.dwSize = 100;
cursorInfo.bVisible = false;
SetConsoleCursorInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &cursorInfo );
if(!stdoutRedirectedtoFile)
freopen( "CON", "w", stdout ) ;
if(!stderrRedirectedtoFile)
@@ -197,8 +197,8 @@ int main(int argc, char **argv)
// printing RT's version in every case, particularly useful for the 'verbose' mode, but also for the batch processing
std::cout << "RawTherapee, version " << VERSION << std::endl;
std::cout << "WARNING: closing this window will close RawTherapee!" << std::endl << std::endl;
}
}
}
}
}
int ret = processLineParams( argc, argv);
@@ -209,7 +209,7 @@ int main(int argc, char **argv)
getch();
}
return ret;
}
}
}
#else
if (argc>1 || options.rtSettings.verbose){
@@ -397,9 +397,18 @@ int processLineParams( int argc, char **argv )
}
}
break;
case 'b':
sscanf(&argv[iArg][2],"%d",&bits);
if (bits != 8 && bits != 16)
{
std::cerr << "Error: specify -b8 for 8-bit or -b16 for 16-bit output." << std::endl;
deleteProcParams(processingParams);
return -3;
}
break;
case 't':
outputType = "tif";
compression = ((argv[iArg][2]!='1')?0:1);
compression = ((argv[iArg][2]!='z')?0:1);
break;
case 'n':
outputType = "png";
@@ -433,25 +442,30 @@ int processLineParams( int argc, char **argv )
inputFiles.push_back( safe_filename_to_utf8 (argv[iArg]) );
}
}
break;
break;
#ifdef WIN32
case 'w': // This case is handled outside this function
break;
case 'w': // This case is handled outside this function
break;
#endif
case 'h':
case '?':
default:
{
Glib::ustring pparamsExt = paramFileExtension.substr(1);
std::cout << "<Chevrons> indicate parameters you can change." << std::endl;
std::cout << "[Square brackets] mean the parameter is not mandatory." << std::endl;
std::cout << "The pipe symbol | indicates a choice of one or the other." << std::endl;
std::cout << "The dash symbol - denotes a range of possible values from one to the other." << std::endl;
cout << std::endl;
std::cout << "Usage:" << std::endl;
std::cout << " " << Glib::path_get_basename(argv[0]) << " [<selected dir>] Start File Browser inside directory." << std::endl;
std::cout << " " << Glib::path_get_basename(argv[0]) << " <selected dir> Start File Browser inside directory." << std::endl;
std::cout << " " << Glib::path_get_basename(argv[0]) << " <file> Start Image Editor with file." << std::endl;
std::cout << " " << Glib::path_get_basename(argv[0]) << " -c <dir>|<files> Convert files in batch with default parameters." << std::endl << std::endl;
#ifdef WIN32
std::cout << " -w Do not open the Windows console" << std::endl;
std::cout << " " << Glib::path_get_basename(argv[0]) << " -c <dir>|<files> Convert files in batch with default parameters." << std::endl << std::endl;
#ifdef WIN32
std::cout << " -w Do not open the Windows console" << std::endl;
#endif
std::cout << "Other options used with -c (-c must be the last option):" << std::endl;
std::cout << Glib::path_get_basename(argv[0]) << " [-o <output>|-O <output>] [-s|-S] [-p <files>] [-d] [-j[1-100]|-t|-t1|-n] -Y -c <input>" << std::endl;
std::cout << Glib::path_get_basename(argv[0]) << " [-o <output>|-O <output>] [-s|-S] [-p <files>] [-d] [-j[1-100] [-js<1-3>]|[-b<8|16>] <[-t[z] | [-n]]] [-Y] -c <input>" << std::endl;
std::cout << " -o <file>|<dir> Select output file or directory." << std::endl;
std::cout << " -O <file>|<dir> Select output file or directory and copy " << pparamsExt << " file into it." << std::endl;
std::cout << " -s Include the " << pparamsExt << " file next to the input file (with the same" << std::endl;
@@ -465,16 +479,17 @@ int processLineParams( int argc, char **argv )
std::cout << " You can specify as many -p options as you like (see" << std::endl;
std::cout << " description below)." << std::endl;
std::cout << " -d Use the default raw or non-raw " << pparamsExt << " file as set in" << std::endl;
std::cout << " Preferences > Image Processing > Default Image Processing Parameters" << std::endl;
std::cout << " Preferences > Image Processing > Default Processing Profile" << std::endl;
std::cout << " -j[1-100] Specify output to be JPEG (on by default). Optionally add" << std::endl;
std::cout << " compression 1-100 (default value: 100)." << std::endl;
std::cout << " -js1-3 Specify the JPEG subsampling parameter, where:" << std::endl;
std::cout << " -js<1-3> Specify the JPEG subsampling parameter, where:" << std::endl;
std::cout << " 1 = Best compression: 2x2, 1x1, 1x1 (4:1:1) - default of the JPEG library" << std::endl;
std::cout << " 2 = Widely used normal ratio: 2x1, 1x1, 1x1 (4:2:2)" << std::endl;
std::cout << " 3 = Best quality: 1x1, 1x1, 1x1 (4:4:4)" << std::endl;
std::cout << " -t Specify output to be uncompressed 16-bit TIFF." << std::endl;
std::cout << " -t1 Specify output to be compressed 16-bit TIFF (ZIP compression)." << std::endl;
std::cout << " -n Specify output to be compressed 16-bit PNG." << std::endl;
std::cout << " -b<8|16> Specify bit depth per channel (only applies to TIFF and PNG output)." << std::endl;
std::cout << " -t[z] Specify output to be TIFF (16-bit if -b8 is not set)." << std::endl;
std::cout << " Uncompressed by default, or ZIP compression with 'z'" << std::endl;
std::cout << " -n Specify output to be compressed PNG (16-bit if -b8 is not set)." << std::endl;
std::cout << " -Y Overwrite output if present." << std::endl<<std::endl;
std::cout << "Your " << pparamsExt << " files can be incomplete, RawTherapee will set the values as follows:" << std::endl;
std::cout << " 1- A new profile is created using internal default (neutral) values" <<std::endl;
@@ -523,7 +538,7 @@ int processLineParams( int argc, char **argv )
rawParams = new rtengine::procparams::PartialProfile(true);
Glib::ustring profPath = options.findProfilePath(options.defProfRaw);
if (options.is_defProfRawMissing() || profPath.empty() || rawParams->load(Glib::build_filename(profPath, Glib::path_get_basename(options.defProfRaw) + paramFileExtension))) {
std::cerr << "Error: default Raw procparams file not found" << std::endl;
std::cerr << "Error: default raw processing profile not found" << std::endl;
rawParams->deleteInstance();
delete rawParams;
deleteProcParams(processingParams);
@@ -532,7 +547,7 @@ int processLineParams( int argc, char **argv )
imgParams = new rtengine::procparams::PartialProfile(true);
profPath = options.findProfilePath(options.defProfImg);
if (options.is_defProfImgMissing() || profPath.empty() || imgParams->load(Glib::build_filename(profPath, Glib::path_get_basename(options.defProfImg) + paramFileExtension))) {
std::cerr << "Error: default Image procparams file not found" << std::endl;
std::cerr << "Error: default non-raw processing profile not found" << std::endl;
imgParams->deleteInstance();
delete imgParams;
rawParams->deleteInstance();
@@ -581,13 +596,13 @@ int processLineParams( int argc, char **argv )
continue;
}
// Load the image
isRaw = true;
// Load the image
isRaw = true;
Glib::ustring ext = getExtension (inputFile);
if (ext.lowercase()=="jpg" || ext.lowercase()=="jpeg" || ext.lowercase()=="tif" || ext.lowercase()=="tiff" || ext.lowercase()=="png")
if (ext.lowercase()=="jpg" || ext.lowercase()=="jpeg" || ext.lowercase()=="tif" || ext.lowercase()=="tiff" || ext.lowercase()=="png")
isRaw = false;
ii = rtengine::InitialImage::load ( inputFile, isRaw, &errorCode, NULL );
ii = rtengine::InitialImage::load ( inputFile, isRaw, &errorCode, NULL );
if (!ii) {
errors++;
std::cerr << "Error loading file: "<< inputFile << std::endl;
@@ -596,11 +611,11 @@ int processLineParams( int argc, char **argv )
if (useDefault) {
if (isRaw) {
std::cout << " Merging default Raw profile" << std::endl;
std::cout << " Merging default raw processing profile" << std::endl;
rawParams->applyTo(&currentParams);
}
else {
std::cout << " Merging default Image profile" << std::endl;
std::cout << " Merging default non-raw processing profile" << std::endl;
imgParams->applyTo(&currentParams);
}
}
@@ -680,4 +695,4 @@ int processLineParams( int argc, char **argv )
return errors>0?-2:0;
}