Esempio n. 1
0
int FITSHeaderProcess::ProcessCommandLine( const StringList& argv ) const
{
   ArgumentList arguments =
   ExtractArguments( argv, ArgumentItemMode::AsViews,
                     ArgumentOption::AllowWildcards|ArgumentOption::NoPreviews );

   FITSHeaderInstance instance( this );

   bool launchInterface = false;
   int count = 0;

   for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i )
   {
      const Argument& arg = *i;

      if ( arg.IsNumeric() )
         throw Error( "Unknown numeric argument: " + arg.Token() );
      else if ( arg.IsString() )
         throw Error( "Unknown string argument: " + arg.Token() );
      else if ( arg.IsSwitch() )
         throw Error( "Unknown switch argument: " + arg.Token() );
      else if ( arg.IsLiteral() )
         throw Error( "Unknown argument: " + arg.Token() );
      else if ( arg.IsItemList() )
      {
         ++count;

         if ( arg.Items().IsEmpty() )
         {
            Console().WriteLn( "No view(s) found: " + arg.Token() );
            continue;
         }

         for ( StringList::const_iterator j = arg.Items().Begin(); j != arg.Items().End(); ++j )
         {
            View v = View::ViewById( *j );
            if ( v.IsNull() )
               throw Error( "No such view: " + *j );
            instance.LaunchOn( v );
         }
      }
   }

   if ( launchInterface )
      instance.LaunchInterface();
   else if ( count == 0 )
   {
      if ( ImageWindow::ActiveWindow().IsNull() )
         throw Error( "There is no active image window." );
      instance.LaunchOnCurrentWindow();
   }

   return 0;
}
Esempio n. 2
0
int PreferencesProcess::ProcessCommandLine( const StringList& argv ) const
{
   ArgumentList arguments = ExtractArguments( argv, ArgumentItemMode::NoItems );

   PreferencesInstance instance( this );
   bool launchInterface = false;

   for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i )
   {
      const Argument& arg = *i;

      if ( arg.IsNumeric() )
      {
         throw Error( "Unknown numeric argument: " + arg.Token() );
      }
      else if ( arg.IsString() )
      {
         throw Error( "Unknown string argument: " + arg.Token() );
      }
      else if ( arg.IsSwitch() )
      {
         throw Error( "Unknown switch argument: " + arg.Token() );
      }
      else if ( arg.IsLiteral() )
      {
         if ( arg.Id() == "-interface" )
            launchInterface = true;
         else if ( arg.Id() == "-help" )
         {
            ShowHelp();
            return 0;
         }
         else
            throw Error( "Unknown argument: " + arg.Token() );
      }
      else if ( arg.IsItemList() )
         throw Error( "Invalid non-parametric argument: " + arg.Token() );
   }

   if ( launchInterface || arguments.IsEmpty() )
      instance.LaunchInterface();
   else
      instance.LaunchGlobal();

   return 0;
}
Esempio n. 3
0
int MaskedStretchProcess::ProcessCommandLine( const StringList& argv ) const
{
   ArgumentList arguments =
   ExtractArguments( argv, ArgumentItemMode::AsViews, ArgumentOption::AllowWildcards );

   MaskedStretchInstance instance( this );

   bool launchInterface = false;
   int count = 0;

   for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i )
   {
      const Argument& arg = *i;

      if ( arg.IsNumeric() )
      {
         if ( arg.Id() == "b" || arg.Id() == "-background" )
         {
            double b = arg.NumericValue();
            if ( b < TheMSTargetBackgroundParameter->MinimumValue() ||
                 b > TheMSTargetBackgroundParameter->MaximumValue() )
               throw Error( "Target background parameter out of range" );
            instance.p_targetBackground = b;
         }
         else if ( arg.Id() == "n" || arg.Id() == "-iterations" )
         {
            int n = TruncInt( arg.NumericValue() );
            if ( n < int( TheMSNumberOfIterationsParameter->MinimumValue() ) ||
                 n > int( TheMSNumberOfIterationsParameter->MaximumValue() ) )
               throw Error( "Number of iterations parameter out of range" );
            instance.p_numberOfIterations = n;
         }
         else
            throw Error( "Unknown numeric argument: " + arg.Token() );
      }
      else if ( arg.IsString() )
      {
         if ( arg.Id() == "m" || arg.Id() == "-mask-type" )
         {
            if ( arg.StringValue() == "I" || arg.StringValue() == "intensity" )
               instance.p_maskType = MSMaskType::Intensity;
            else if ( arg.StringValue() == "V" || arg.StringValue() == "value" )
               instance.p_maskType = MSMaskType::Value;
         }
         else
            throw Error( "Unknown string argument: " + arg.Token() );
      }
      else if ( arg.IsSwitch() )
      {
         throw Error( "Unknown switch argument: " + arg.Token() );
      }
      else if ( arg.IsLiteral() )
      {
         if ( arg.Id() == "-interface" )
            launchInterface = true;
         else if ( arg.Id() == "-help" )
         {
            ShowHelp();
            return 0;
         }
         else
            throw Error( "Unknown argument: " + arg.Token() );
      }
      else if ( arg.IsItemList() )
      {
         ++count;

         if ( arg.Items().IsEmpty() )
         {
            Console().WriteLn( "No view(s) found: " + arg.Token() );
            continue;
         }

         for ( StringList::const_iterator j = arg.Items().Begin(); j != arg.Items().End(); ++j )
         {
            View v = View::ViewById( *j );
            if ( v.IsNull() )
               throw Error( "No such view: " + *j );
            instance.LaunchOn( v );
         }
      }
   }

   if ( launchInterface )
      instance.LaunchInterface();
   else if ( count == 0 )
   {
      if ( ImageWindow::ActiveWindow().IsNull() )
         throw Error( "There is no active image window." );
      instance.LaunchOnCurrentView();
   }

   return 0;
}
int ColorManagementSetupProcess::ProcessCommandLine( const StringList& argv ) const
{
   ArgumentList arguments = ExtractArguments( argv, ArgumentItemMode::NoItems );

   ColorManagementSetupInstance instance( this );
   bool launchInterface = false;

   for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i )
   {
      const Argument& arg = *i;

      if ( arg.IsNumeric() )
      {
         throw Error( "Unknown numeric argument: " + arg.Token() );
      }
      else if ( arg.IsString() )
      {
         if ( arg.Id() == "rgb-profile" )
         {
            instance.defaultRGBProfile = arg.StringValue();
            instance.defaultRGBProfile.Trim();
            if ( instance.defaultRGBProfile.IsEmpty() )
               throw Error( "Empty RGB profile: " + arg.Token() );
         }
         else if ( arg.Id() == "grayscale-profile" )
         {
            instance.defaultGrayProfile = arg.StringValue();
            instance.defaultGrayProfile.Trim();
            if ( instance.defaultGrayProfile.IsEmpty() )
               throw Error( "Empty grayscale profile: " + arg.Token() );
         }
         else if ( arg.Id() == "proofing-profile" )
         {
            instance.proofingProfile = arg.StringValue();
            instance.proofingProfile.Trim();
            if ( instance.proofingProfile.IsEmpty() )
               throw Error( "Empty proofing profile: " + arg.Token() );
         }
         else if ( arg.Id() == "rendering-intent" || arg.Id() == "proofing-intent" )
         {
            pcl_enum intent;
            if ( arg.StringValue() == "perceptual" )
               intent = CMSDefaultRenderingIntent::Perceptual;
            else if ( arg.StringValue() == "saturation" )
               intent = CMSDefaultRenderingIntent::Saturation;
            else if ( arg.StringValue() == "relative" || arg.StringValue() == "relativeColorimetric" )
               intent = CMSDefaultRenderingIntent::RelativeColorimetric;
            else if ( arg.StringValue() == "absolute" || arg.StringValue() == "absoluteColorimetric" )
               intent = CMSDefaultRenderingIntent::AbsoluteColorimetric;
            else
               throw Error( "Invalid rendering intent: " + arg.Token() );

            if ( arg.Id() == "rendering-intent" )
               instance.defaultRenderingIntent = intent;
            else
               instance.proofingIntent = intent;
         }
         else if ( arg.Id() == "on-profile-mismatch" )
         {
            if ( arg.StringValue() == "ask" )
               instance.onProfileMismatch = CMSOnProfileMismatch::AskUser;
            else if ( arg.StringValue() == "keep" )
               instance.onProfileMismatch = CMSOnProfileMismatch::KeepEmbedded;
            else if ( arg.StringValue() == "convert" )
               instance.onProfileMismatch = CMSOnProfileMismatch::ConvertToDefault;
            else if ( arg.StringValue() == "discard" )
               instance.onProfileMismatch = CMSOnProfileMismatch::DiscardEmbedded;
            else if ( arg.StringValue() == "disable" )
               instance.onProfileMismatch = CMSOnProfileMismatch::DisableCM;
            else
               throw Error( "Invalid profile mismatch policy: " + arg.Token() );
         }
         else if ( arg.Id() == "on-missing-profile" )
         {
            if ( arg.StringValue() == "ask" )
               instance.onMissingProfile = CMSOnMissingProfile::AskUser;
            else if ( arg.StringValue() == "default" )
               instance.onMissingProfile = CMSOnMissingProfile::AssignDefault;
            else if ( arg.StringValue() == "ignore" )
               instance.onMissingProfile = CMSOnMissingProfile::LeaveUntagged;
            else if ( arg.StringValue() == "disable" )
               instance.onMissingProfile = CMSOnMissingProfile::DisableCM;
            else
               throw Error( "Invalid missing profile policy: " + arg.Token() );
         }
         else if ( arg.Id() == "gamut-warning-color" )
         {
            instance.gamutWarningColor = RGBAColor( arg.StringValue() );
         }
         else
            throw Error( "Unknown string argument: " + arg.Token() );
      }
      else if ( arg.IsSwitch() )
      {
         if ( arg.Id() == "embed-rgb" )
            instance.defaultEmbedProfilesInRGBImages = arg.SwitchState();
         else if ( arg.Id() == "embed-grayscale" )
            instance.defaultEmbedProfilesInGrayscaleImages = arg.SwitchState();
         else if ( arg.Id() == "proofing-bpc" )
            instance.useProofingBPC = arg.SwitchState();
         else if ( arg.Id() == "default-proofing" )
            instance.defaultProofingEnabled = arg.SwitchState();
         else if ( arg.Id() == "default-gamut-check" )
            instance.defaultGamutCheckEnabled = arg.SwitchState();
         else
            throw Error( "Unknown switch argument: " + arg.Token() );
      }
      else if ( arg.IsLiteral() )
      {
         if ( arg.Id() == "enable" )
            instance.enabled = true;
         else if ( arg.Id() == "disable" )
            instance.enabled = false;
         if ( arg.Id() == "embed-rgb" )
            instance.defaultEmbedProfilesInRGBImages = true;
         else if ( arg.Id() == "embed-grayscale" )
            instance.defaultEmbedProfilesInGrayscaleImages = true;
         else if ( arg.Id() == "-load" )
            instance.LoadCurrentSettings();
         else if ( arg.Id() == "-interface" )
            launchInterface = true;
         else if ( arg.Id() == "-help" )
         {
            ShowHelp();
            return 0;
         }
         else
            throw Error( "Unknown argument: " + arg.Token() );
      }
      else if ( arg.IsItemList() )
         throw Error( "Invalid non-parametric argument: " + arg.Token() );
   }

   if ( launchInterface || arguments.IsEmpty() )
      instance.LaunchInterface();
   else
      instance.LaunchGlobal();

   return 0;
}
PGresult * PostgreSQLInterface::QueryVariadic( const char * input, ... )
{
	RakNet::RakString query;
	PGresult *result;
	DataStructures::List<VariadicSQLParser::IndexAndType> indices;
	if ( input==0 || input[0]==0 )
		return 0;

	// Lookup this query in the stored query table. If it doesn't exist, prepare it.
	RakNet::RakString inputStr;
	inputStr=input;
	unsigned int preparedQueryIndex;
	for (preparedQueryIndex=0; preparedQueryIndex < preparedQueries.Size(); preparedQueryIndex++)
	{
		if (preparedQueries[preparedQueryIndex].StrICmp(inputStr)==0)
			break;
	}

	// Find out how many params there are
	// Find out the type of each param (%f, %s)
	indices.Clear(false, _FILE_AND_LINE_);
	GetTypeMappingIndices( input, indices );

	if (preparedQueryIndex==preparedQueries.Size())
	{
//		if (indices.Size()>0)
//			query += " (";
		RakNet::RakString formatCopy;
		RakNet::RakString insertion;
		formatCopy=input;
		unsigned int i;
		unsigned int indexOffset=0;
		for (i=0; i < indices.Size(); i++)
		{
//			if (i!=0)
//				query += ",";
//			query+=typeMappings[indices[i].typeMappingIndex].type;
			formatCopy.SetChar(indices[i].strIndex+indexOffset, '$');
//			if (i < 9)
//				formatCopy.SetChar(indices[i].strIndex+1, i+1+'0');
//			else
			insertion=RakNet::RakString("%i::%s", i+1, VariadicSQLParser::GetTypeMappingAtIndex(indices[i].typeMappingIndex));
			formatCopy.SetChar(indices[i].strIndex+1+indexOffset, insertion);
			indexOffset+=(unsigned int) insertion.GetLength()-1;
		}
//		if (indices.Size()>0)
//			query += ")";
//		query += " AS ";
		query += formatCopy;
	//	query += ";\n";
		formatCopy+= ";\n";
		result = PQprepare(pgConn, RakNet::RakString("PGSQL_ExecuteVariadic_%i", preparedQueries.Size()), formatCopy.C_String(), indices.Size(), NULL);
		if (IsResultSuccessful(result, false))
		{
			PQclear(result);
			preparedQueries.Insert(inputStr, _FILE_AND_LINE_);
		}
		else
		{
			printf(formatCopy.C_String());
			printf("\n");
			printf(lastError);
			RakAssert(0);
			PQclear(result);
			return 0;
		}
	}

//	char *paramData[512];
//	int paramLength[512];
//	int paramFormat[512];

	va_list argptr;
	va_start(argptr, input);
	char **paramData;
	int *paramLength;
	int *paramFormat;
	ExtractArguments(argptr, indices, &paramData, &paramLength);
	paramFormat=RakNet::OP_NEW_ARRAY<int>(indices.Size(),_FILE_AND_LINE_);
	for (unsigned int i=0; i < indices.Size(); i++)
		paramFormat[i]=PQEXECPARAM_FORMAT_BINARY;
	result = PQexecPrepared(pgConn, RakNet::RakString("PGSQL_ExecuteVariadic_%i", preparedQueryIndex), indices.Size(), paramData, paramLength, paramFormat, PQEXECPARAM_FORMAT_BINARY );
	VariadicSQLParser::FreeArguments(indices, paramData, paramLength);
	RakNet::OP_DELETE_ARRAY(paramFormat,_FILE_AND_LINE_);
	va_end(argptr);

	if (IsResultSuccessful(result, false)==false)
	{
		printf(lastError);
		PQclear(result);
		return 0;
	}
	return result;
}
Esempio n. 6
0
int ReadoutOptionsProcess::ProcessCommandLine( const StringList& argv ) const
{
   ArgumentList arguments = ExtractArguments( argv, ArgumentItemMode::NoItems );

   ReadoutOptions options;
   bool launchInterface = false;

   for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i )
   {
      const Argument& arg = *i;

      if ( arg.IsNumeric() )
      {
         if ( arg.Id() == "s" || arg.Id() == "size" )
         {
            int sz = int( arg.NumericValue() );
            if ( (sz & 1) == 0 || sz < 1 || sz > ReadoutOptions::MaxProbeSize )
               throw Error( "Invalid readout probe size: " + arg.Token() );
            options.SetProbeSize( sz );
         }
         else if ( arg.Id() == "ps" || arg.Id() == "preview-size" )
         {
            int sz = int( arg.NumericValue() );
            if ( (sz & 1) == 0 || sz < ReadoutOptions::MinPreviewSize || sz > ReadoutOptions::MaxPreviewSize )
               throw Error( "Invalid readout preview size: " + arg.Token() );
            options.SetPreviewSize( sz );
         }
         else if ( arg.Id() == "pz" || arg.Id() == "preview-zoom" )
         {
            int sz = int( arg.NumericValue() );
            if ( sz < 1 || sz > ReadoutOptions::MaxPreviewZoomFactor )
               throw Error( "Invalid readout preview zoom factor: " + arg.Token() );
            options.SetPreviewZoomFactor( sz );
         }
         else if ( arg.Id() == "r" || arg.Id() == "real" )
         {
            options.SetReal();
            int n = int( arg.NumericValue() );
            if ( n < 0 || n > ReadoutOptions::MaxPrecision )
               throw Error( "Invalid readout real precision: " + arg.Token() );
            options.SetPrecision( n );
         }
         else if ( arg.Id() == "i" || arg.Id() == "integer" )
         {
            options.SetInteger();
            double n = arg.NumericValue();
            if ( n < 1 || n > uint32_max )
               throw Error( "Invalid integer readout range: " + arg.Token() );
            options.SetIntegerRange( unsigned( n ) );
         }
         else
            throw Error( "Unknown numeric argument: " + arg.Token() );
      }
      else if ( arg.IsString() )
         throw Error( "Unknown string argument: " + arg.Token() );
      else if ( arg.IsSwitch() )
      {
         if ( arg.Id() == "alpha" )
            options.EnableAlphaChannel( arg.SwitchState() );
         else if ( arg.Id() == "mask" )
            options.EnableMaskChannel( arg.SwitchState() );
         else if ( arg.Id() == "preview" )
            options.EnablePreview( arg.SwitchState() );
         else if ( arg.Id() == "preview-center" )
            options.EnablePreviewCenter( arg.SwitchState() );
         else if ( arg.Id() == "broadcast" )
            options.EnableBroadcast( arg.SwitchState() );
         else
            throw Error( "Unknown switch argument: " + arg.Token() );
      }
      else if ( arg.IsLiteral() )
      {
         if ( arg.Id() == "m" || arg.Id() == "mean" )
            options.SetMode( ReadoutMode::Mean );
         else if ( arg.Id() == "n" || arg.Id() == "median" )
            options.SetMode( ReadoutMode::Median );
         else if ( arg.Id() == "M" || arg.Id() == "max" || arg.Id() == "maximum" )
            options.SetMode( ReadoutMode::Maximum );
         else if ( arg.Id() == "N" || arg.Id() == "min" || arg.Id() == "minimum" )
            options.SetMode( ReadoutMode::Minimum );
         else if ( arg.Id() == "rgb" || arg.Id() == "RGB" )
            options.SetData( ReadoutData::RGBK );
         else if ( arg.Id() == "rgbl" || arg.Id() == "RGBL" )
            options.SetData( ReadoutData::RGBL );
         else if ( arg.Id() == "rgby" || arg.Id() == "RGBY" )
            options.SetData( ReadoutData::RGBY );
         else if ( arg.Id() == "xyz" || arg.Id() == "XYZ" )
            options.SetData( ReadoutData::CIEXYZ );
         else if ( arg.Id() == "lab" || arg.Id() == "Lab" )
            options.SetData( ReadoutData::CIELab );
         else if ( arg.Id() == "lch" || arg.Id() == "Lch" )
            options.SetData( ReadoutData::CIELch );
         else if ( arg.Id() == "hsv" || arg.Id() == "HSV" )
            options.SetData( ReadoutData::HSV );
         else if ( arg.Id() == "hsi" || arg.Id() == "HSI" || arg.Id() == "HSL" )
            options.SetData( ReadoutData::HSI );
         else if ( arg.Id() == "i8" )
         {
            options.SetInteger();
            options.SetIntegerRange( 255 );
         }
         else if ( arg.Id() == "i10" )
         {
            options.SetInteger();
            options.SetIntegerRange( 1023 );
         }
         else if ( arg.Id() == "i12" )
         {
            options.SetInteger();
            options.SetIntegerRange( 4095 );
         }
         else if ( arg.Id() == "i14" )
         {
            options.SetInteger();
            options.SetIntegerRange( 16383 );
         }
         else if ( arg.Id() == "i16" )
         {
            options.SetInteger();
            options.SetIntegerRange( 65535 );
         }
         else if ( arg.Id() == "i32" )
         {
            options.SetInteger();
            options.SetIntegerRange( 4294967295ul );
         }
         else if ( arg.Id() == "alpha" )
            options.EnableAlphaChannel();
         else if ( arg.Id() == "mask" )
            options.EnableMaskChannel();
         else if ( arg.Id() == "preview" )
            options.EnablePreview();
         else if ( arg.Id() == "preview-center" )
            options.EnablePreviewCenter();
         else if ( arg.Id() == "broadcast" )
            options.EnableBroadcast();
         else if ( arg.Id() == "-load" )
            options = ReadoutOptions::GetCurrentOptions();
         else if ( arg.Id() == "-interface" )
            launchInterface = true;
         else if ( arg.Id() == "-help" )
         {
            ShowHelp();
            return 0;
         }
         else
            throw Error( "Unknown argument: " + arg.Token() );
      }
      else if ( arg.IsItemList() )
         throw Error( "Invalid non-parametric argument: " + arg.Token() );
   }

   ReadoutOptionsInstance instance( this );

   instance.SetOptions( options );

   if ( launchInterface || arguments.IsEmpty() )
      instance.LaunchInterface();
   else
      instance.LaunchGlobal();

   return 0;
}
int FluxCalibrationProcess::ProcessCommandLine( const StringList& argv ) const
{
   ArgumentList arguments =
      ExtractArguments( argv, ArgumentItemMode::AsViews, ArgumentOption::AllowWildcards );

   FluxCalibrationInstance instance( this );

   bool launchInterface = false;
   int count = 0;

   for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i )
   {
      const Argument& arg = *i;

      if ( arg.IsNumeric() )
      {
         if ( arg.Id() == "l" || arg.Id() == "-wavelength" )
            instance.p_wavelength = arg.NumericValue();
         else if ( arg.Id() == "tr" || arg.Id() == "-transmissivity" )
            instance.p_transmissivity = arg.NumericValue();
         else if ( arg.Id() == "w" || arg.Id() == "-filter-width" )
            instance.p_filterWidth = arg.NumericValue();
         else if ( arg.Id() == "a" || arg.Id() == "-aperture" )
            instance.p_aperture = arg.NumericValue();
         else if ( arg.Id() == "o" || arg.Id() == "-central-obstruction" )
            instance.p_centralObstruction = arg.NumericValue();
         else if ( arg.Id() == "t" || arg.Id() == "-exposure-time" )
            instance.p_exposureTime = arg.NumericValue();
         else if ( arg.Id() == "e" || arg.Id() == "-atmospheric-extinction" )
            instance.p_atmosphericExtinction = arg.NumericValue();
         else if ( arg.Id() == "G" || arg.Id() == "-sensor-gain" )
            instance.p_sensorGain = arg.NumericValue();
         else if ( arg.Id() == "qe" || arg.Id() == "-quantum-efficiency" )
            instance.p_quantumEfficiency = arg.NumericValue();
         else
            throw Error( "Unknown numeric argument: " + arg.Token() );
      }
      else if ( arg.IsString() )
      {
            throw Error( "Unknown string argument: " + arg.Token() );
      }
      else if ( arg.IsSwitch() )
      {
            throw Error( "Unknown switch argument: " + arg.Token() );
      }
      else if ( arg.IsLiteral() )
      {
         // These are standard parameters that all processes should provide.
         if ( arg.Id() == "-interface" )
            launchInterface = true;
         else if ( arg.Id() == "-help" )
         {
            ShowHelp();
            return 0;
         }
         else
            throw Error( "Unknown argument: " + arg.Token() );
      }
      else if ( arg.IsItemList() )
      {
         ++count;

         if ( arg.Items().IsEmpty() )
         {
            Console().WriteLn( "No view(s) found: " + arg.Token() );
            throw;
         }

         for ( StringList::const_iterator j = arg.Items().Begin(); j != arg.Items().End(); ++j )
         {
            View v = View::ViewById( *j );
            if ( v.IsNull() )
               throw Error( "No such view: " + *j );
            instance.LaunchOn( v );
         }
      }
   }

   if ( launchInterface )
      instance.LaunchInterface();
   else if ( count == 0 )
   {
      if ( ImageWindow::ActiveWindow().IsNull() )
         throw Error( "There is no active image window." );
      instance.LaunchOnCurrentView();
   }

   return 0;
}
Esempio n. 8
0
int BinarizeProcess::ProcessCommandLine( const StringList& argv ) const
{
   ArgumentList arguments =
   ExtractArguments( argv, ArgumentItemMode::AsViews, ArgumentOption::AllowWildcards );

   BinarizeInstance instance( this );

   bool launchInterface = false;
   int count = 0;

   for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i )
   {
      const Argument& arg = *i;

      if ( arg.IsNumeric() )
      {
         if ( arg.Id() == "t" || arg.Id() == "threshold" )
         {
            instance.level[0] = instance.level[1] = instance.level[2] = ArgumentThresholdValue( arg );
            instance.isGlobal = true;
         }
         else if ( arg.Id() == "tR" || arg.Id() == "thresholdR" )
         {
            instance.level[0] = ArgumentThresholdValue( arg );
            instance.isGlobal = false;
         }
         else if ( arg.Id() == "tG" || arg.Id() == "thresholdG" )
         {
            instance.level[1] = ArgumentThresholdValue( arg );
            instance.isGlobal = false;
         }
         else if ( arg.Id() == "tB" || arg.Id() == "thresholdB" )
         {
            instance.level[2] = ArgumentThresholdValue( arg );
            instance.isGlobal = false;
         }
         else
            throw Error( "Unknown numeric argument: " + arg.Token() );
      }
      else if ( arg.IsString() )
         throw Error( "Unknown string argument: " + arg.Token() );
      else if ( arg.IsSwitch() )
         throw Error( "Unknown switch argument: " + arg.Token() );
      else if ( arg.IsLiteral() )
      {
         if ( arg.Id() == "-interface" )
            launchInterface = true;
         else if ( arg.Id() == "-help" )
         {
            ShowHelp();
            return 0;
         }
         else
            throw Error( "Unknown argument: " + arg.Token() );
      }
      else if ( arg.IsItemList() )
      {
         ++count;

         if ( arg.Items().IsEmpty() )
         {
            Console().WriteLn( "No view(s) found: " + arg.Token() );
            continue;
         }

         for ( StringList::const_iterator j = arg.Items().Begin(); j != arg.Items().End(); ++j )
         {
            View v = View::ViewById( *j );
            if ( v.IsNull() )
               throw Error( "No such view: " + *j );
            instance.LaunchOn( v );
         }
      }
   }

   if ( launchInterface )
      instance.LaunchInterface();
   else if ( count == 0 )
   {
      if ( ImageWindow::ActiveWindow().IsNull() )
         throw Error( "There is no active image window." );
      instance.LaunchOnCurrentView();
   }

   return 0;
}
Esempio n. 9
0
int B3EProcess::ProcessCommandLine( const StringList& argv ) const
{
   ArgumentList arguments =
      ExtractArguments( argv, ArgumentItemMode::AsViews, ArgumentOption::AllowWildcards );

   B3EInstance instance( this );

   bool launchInterface = false;
   int count = 0;

   for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i )
   {
      const Argument& arg = *i;

      if ( arg.IsNumeric() )
      {
         throw Error( "Unknown numeric argument: " + arg.Token() );
      }
      else if ( arg.IsString() )
      {
         throw Error( "Unknown string argument: " + arg.Token() );
      }
      else if ( arg.IsSwitch() )
      {
         throw Error( "Unknown switch argument: " + arg.Token() );
      }
      else if ( arg.IsLiteral() )
      {
         // These are standard parameters that all processes should provide.
         if ( arg.Id() == "-interface" )
            launchInterface = true;
         else if ( arg.Id() == "-help" )
         {
            ShowHelp();
            return 0;
         }
         else
            throw Error( "Unknown argument: " + arg.Token() );
      }
      else if ( arg.IsItemList() )
      {
         ++count;

         if ( arg.Items().IsEmpty() )
         {
            Console().WriteLn( "No view(s) found: " + arg.Token() );
            throw;
         }

         for ( StringList::const_iterator j = arg.Items().Begin(); j != arg.Items().End(); ++j )
         {
            View v = View::ViewById( *j );
            if ( v.IsNull() )
               throw Error( "No such view: " + *j );
            instance.LaunchOn( v );
         }
      }
   }

   if ( launchInterface )
      instance.LaunchInterface();
   else if ( count == 0 )
   {
      if ( ImageWindow::ActiveWindow().IsNull() )
         throw Error( "There is no active image window." );
      instance.LaunchOnCurrentView();
   }

   return 0;
}
int LocalHistogramEqualizationProcess::ProcessCommandLine( const StringList& argv ) const
{
   ArgumentList arguments =
      ExtractArguments( argv, ArgumentItemMode::AsViews, ArgumentOption::AllowWildcards );

   LocalHistogramEqualizationInstance instance( this );

   bool launchInterface = false;
   int count = 0;

   for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i )
   {
      const Argument& arg = *i;

      if ( arg.IsNumeric() )
      {
         if (arg.Id() == "r" || arg.Id() == "-radius") instance.radius = (int)arg.NumericValue();
         else if (arg.Id() == "l" || arg.Id() == "-limit") instance.slopeLimit = arg.NumericValue();
         else if (arg.Id() == "a" || arg.Id() == "-amount") instance.amount = arg.NumericValue();
         else if (arg.Id() == "h" || arg.Id() == "-hist")
         {
            int bins = (int)arg.NumericValue();
            if (bins == 8) instance.histogramBins = LHEHistogramBins::Bit8;
            else if (bins == 10) instance.histogramBins = LHEHistogramBins::Bit10;
            else if (bins == 12) instance.histogramBins = LHEHistogramBins::Bit12;
            else throw Error( "Invalid value for '-h' argument. Allowed values are 8, 10 or 12" );
         }
         else throw Error( "Unknown numeric argument: " + arg.Token() );
      }
      else if ( arg.IsString() )
      {
         throw Error( "Unknown string argument: " + arg.Token() );
      }
      else if ( arg.IsSwitch() )
      {
         if (arg.Id() == "c" || arg.Id() == "-circular") instance.circularKernel = arg.SwitchState();
         else throw Error( "Unknown switch argument: " + arg.Token() );
      }
      else if ( arg.IsLiteral() )
      {
         if (arg.Id() == "c" || arg.Id() == "-circular") instance.circularKernel = true;
         // These are standard parameters that all processes should provide.
         else if ( arg.Id() == "-interface" )
            launchInterface = true;
         else if ( arg.Id() == "-help" )
         {
            ShowHelp();
            return 0;
         }
         else
            throw Error( "Unknown argument: " + arg.Token() );
      }
      else if ( arg.IsItemList() )
      {
         ++count;

         if ( arg.Items().IsEmpty() )
         {
            Console().WriteLn( "No view(s) found: " + arg.Token() );
            throw;
         }

         for ( StringList::const_iterator j = arg.Items().Begin(); j != arg.Items().End(); ++j )
         {
            View v = View::ViewById( *j );
            if ( v.IsNull() )
               throw Error( "No such view: " + *j );
            instance.LaunchOn( v );
         }
      }
   }

   if ( launchInterface )
      instance.LaunchInterface();
   else if ( count == 0 )
   {
      if ( ImageWindow::ActiveWindow().IsNull() )
         throw Error( "There is no active image window." );
      instance.LaunchOnCurrentView();
   }

   return 0;
}
Esempio n. 11
0
int LinearFitProcess::ProcessCommandLine( const StringList& argv ) const
{
   ArgumentList arguments =
   ExtractArguments( argv, ArgumentItemMode::AsViews, ArgumentOption::AllowWildcards );

   LinearFitInstance instance( this );

   bool launchInterface = false;
   int count = 0;

   for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i )
   {
      const Argument& arg = *i;

      if ( arg.IsNumeric() )
      {
         if ( arg.Id() == "r0" || arg.Id() == "reject-low" )
         {
            CHECK_IN_NORM_RANGE;
            instance.rejectLow = arg.NumericValue();
         }
         else if ( arg.Id() == "r1" || arg.Id() == "reject-high" )
         {
            CHECK_IN_NORM_RANGE;
            instance.rejectHigh = arg.NumericValue();
         }
         else
            throw Error( "Unknown numeric argument: " + arg.Token() );
      }
      else if ( arg.IsString() )
      {
         if ( arg.Id() == "v" || arg.Id() == "reference-view" )
            instance.referenceViewId = arg.StringValue();
         else
            throw Error( "Unknown string argument: " + arg.Token() );
      }
      else if ( arg.IsSwitch() )
      {
         throw Error( "Unknown switch argument: " + arg.Token() );
      }
      else if ( arg.IsLiteral() )
      {
         if ( arg.Id() == "-interface" )
            launchInterface = true;
         else if ( arg.Id() == "-help" )
         {
            ShowHelp();
            return 0;
         }
         else
            throw Error( "Unknown argument: " + arg.Token() );
      }
      else if ( arg.IsItemList() )
      {
         ++count;

         if ( arg.Items().IsEmpty() )
         {
            Console().WriteLn( "No view(s) found: " + arg.Token() );
            throw;
         }

         for ( StringList::const_iterator j = arg.Items().Begin(); j != arg.Items().End(); ++j )
         {
            View v = View::ViewById( *j );
            if ( v.IsNull() )
               throw Error( "No such view: " + *j );
            if ( v.FullId() != IsoString( instance.referenceViewId ).Trimmed() )
               instance.LaunchOn( v );
            else
               Console().WarningLn( "<end><cbr>** Skipping reference view: " + v.FullId() );
         }
      }
   }

   if ( launchInterface )
      instance.LaunchInterface();
   else if ( count == 0 )
   {
      if ( ImageWindow::ActiveWindow().IsNull() )
         throw Error( "There is no active image window." );
      instance.LaunchOnCurrentView();
   }

   return 0;
}
Esempio n. 12
0
int AssignICCProfileProcess::ProcessCommandLine( const StringList& argv ) const
{
   ArgumentList arguments =
   ExtractArguments( argv,
                     ArgumentItemMode::AsViews,
                     ArgumentOption::AllowWildcards|ArgumentOption::NoPreviews );

   AssignICCProfileInstance instance( this );

   bool launchInterface = false;
   int count = 0;

   for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i )
   {
      const Argument& arg = *i;

      if ( arg.IsNumeric() )
         throw Error( "Unknown numeric argument: " + arg.Token() );
      else if ( arg.IsString() )
      {
         if ( arg.Id() == "profile" )
         {
            instance.targetProfile = arg.StringValue();
            instance.targetProfile.Trim();
            if ( instance.targetProfile.IsEmpty() )
               throw Error( "Empty profile identifier: " + arg.Token() );
         }
         else if ( arg.Id() == "filename" )
         {
            String filename = arg.StringValue();
            filename.Trim();
            if ( filename.IsEmpty() )
               throw Error( "Empty file name: " + arg.Token() );

            instance.targetProfile.Clear();

            StringList dirs = ICCProfile::ProfileDirectories();
            for ( StringList::const_iterator i = dirs.Begin(); i != dirs.End(); ++i )
            {
               String path = *i + '/' + filename;
               if ( File::Exists( path ) )
               {
                  ICCProfile icc( path );
                  if ( icc.IsProfile() )
                  {
                     instance.targetProfile = icc.Description();
                     break;
                  }
               }
            }

            if ( instance.targetProfile.IsEmpty() )
               throw Error( "The specified file name does not correspond to a valid ICC profile: " + filename );
         }
         else
            throw Error( "Unknown string argument: " + arg.Token() );
      }
      else if ( arg.IsSwitch() )
      {
         if ( arg.Id() == "default" )
            instance.mode = arg.SwitchState() ? AssignMode::AssignDefaultProfile : AssignMode::AssignNewProfile;
         else if ( arg.Id() == "untag" )
            instance.mode = arg.SwitchState() ? AssignMode::LeaveUntagged : AssignMode::AssignNewProfile;
         else
            throw Error( "Unknown switch argument: " + arg.Token() );
      }
      else if ( arg.IsLiteral() )
      {
         if ( arg.Id() == "default" )
            instance.mode = AssignMode::AssignDefaultProfile;
         else if ( arg.Id() == "untag" )
            instance.mode = AssignMode::LeaveUntagged;
         else if ( arg.Id() == "-interface" )
            launchInterface = true;
         else if ( arg.Id() == "-help" )
         {
            ShowHelp();
            return 0;
         }
         else
            throw Error( "Unknown argument: " + arg.Token() );
      }
      else if ( arg.IsItemList() )
      {
         ++count;

         if ( arg.Items().IsEmpty() )
         {
            Console().WriteLn( "No view(s) found: " + arg.Token() );
            continue;
         }

         for ( StringList::const_iterator j = arg.Items().Begin(); j != arg.Items().End(); ++j )
         {
            View v = View::ViewById( *j );
            if ( v.IsNull() )
               throw Error( "No such view: " + *j );
            instance.LaunchOn( v );
         }
      }
   }

   if ( launchInterface )
      instance.LaunchInterface();
   else if ( count == 0 )
   {
      if ( ImageWindow::ActiveWindow().IsNull() )
         throw Error( "There is no active image window." );
      instance.LaunchOnCurrentWindow();
   }

   return 0;
}
int ICCProfileTransformationProcess::ProcessCommandLine( const StringList& argv ) const
{
   ArgumentList arguments =
   ExtractArguments( argv,
                     ArgumentItemMode::AsViews,
                     ArgumentOption::AllowWildcards|ArgumentOption::NoPreviews );

   ICCProfileTransformationInstance instance( this );

   bool launchInterface = false;
   int count = 0;

   for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i )
   {
      const Argument& arg = *i;

      if ( arg.IsNumeric() )
      {
         throw Error( "Unknown numeric argument: " + arg.Token() );
      }
      else if ( arg.IsString() )
      {
         if ( arg.Id() == "profile" )
         {
            instance.targetProfile = arg.StringValue();
            instance.targetProfile.Trim();
            if ( instance.targetProfile.IsEmpty() )
               throw Error( "Empty profile identifier: " + arg.Token() );
         }
         else if ( arg.Id() == "filename" )
         {
            String filename = arg.StringValue();
            filename.Trim();
            if ( filename.IsEmpty() )
               throw Error( "Empty file name: " + arg.Token() );

            instance.targetProfile.Clear();

            StringList dirs = ICCProfile::ProfileDirectories();
            for ( StringList::const_iterator i = dirs.Begin(); i != dirs.End(); ++i )
            {
               String path = *i + '/' + filename;
               if ( File::Exists( path ) )
               {
                  ICCProfile icc( path );
                  if ( icc.IsProfile() )
                  {
                     instance.targetProfile = icc.Description();
                     break;
                  }
               }
            }

            if ( instance.targetProfile.IsEmpty() )
               throw Error( "The specified file name does not correspond to a valid ICC profile: " + filename );
         }
         else if ( arg.Id() == "rendering-intent" )
         {
            if ( arg.StringValue() == "perceptual" )
               instance.renderingIntent = ICCTRenderingIntent::Perceptual;
            else if ( arg.StringValue() == "saturation" )
               instance.renderingIntent = ICCTRenderingIntent::Saturation;
            else if ( arg.StringValue() == "relative" || arg.StringValue() == "relative-colorimetric" )
               instance.renderingIntent = ICCTRenderingIntent::RelativeColorimetric;
            else if ( arg.StringValue() == "absolute" || arg.StringValue() == "absolute-colorimetric" )
               instance.renderingIntent = ICCTRenderingIntent::AbsoluteColorimetric;
            else
               throw Error( "Invalid rendering intent: " + arg.Token() );
         }
         else
            throw Error( "Unknown string argument: " + arg.Token() );
      }
      else if ( arg.IsSwitch() )
      {
         if ( arg.Id() == "to-default-profile" )
            instance.toDefaultProfile = arg.SwitchState();
         else if ( arg.Id() == "black-point-compensation" )
            instance.useBlackPointCompensation = arg.SwitchState();
         else if ( arg.Id() == "floating-point-transform" )
            instance.useFloatingPointTransformation = arg.SwitchState();
         else
            throw Error( "Unknown switch argument: " + arg.Token() );
      }
      else if ( arg.IsLiteral() )
      {
         if ( arg.Id() == "to-default-profile" )
            instance.toDefaultProfile = true;
         else if ( arg.Id() == "black-point-compensation" )
            instance.useBlackPointCompensation = true;
         else if ( arg.Id() == "floating-point-transform" )
            instance.useFloatingPointTransformation = true;
         else if ( arg.Id() == "-interface" )
            launchInterface = true;
         else if ( arg.Id() == "-help" )
         {
            ShowHelp();
            return 0;
         }
         else
            throw Error( "Unknown argument: " + arg.Token() );
      }
      else if ( arg.IsItemList() )
      {
         ++count;

         if ( arg.Items().IsEmpty() )
         {
            Console().WriteLn( "No view(s) found: " + arg.Token() );
            continue;
         }

         for ( StringList::const_iterator j = arg.Items().Begin(); j != arg.Items().End(); ++j )
         {
            View v = View::ViewById( *j );
            if ( v.IsNull() )
               throw Error( "No such view: " + *j );
            instance.LaunchOn( v );
         }
      }
   }

   if ( launchInterface )
      instance.LaunchInterface();
   else if ( count == 0 )
   {
      if ( ImageWindow::ActiveWindow().IsNull() )
         throw Error( "There is no active image window." );
      instance.LaunchOnCurrentWindow();
   }

   return 0;
}