Exemple #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;
}
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;
}
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;
}
Exemple #4
0
PixInsightX11Installer::PixInsightX11Installer( int argc, const char** argv )
{
   // Install PixInsight by default.
   m_task = InstallTask;

   // Assume that we get a path to the executable file (possibly a relative
   // path) in argv[0]. This is standard in all known unices.
   m_executablePath = Unquoted( String::UTF8ToUTF16( argv[0] ) ).Trimmed();

   // Base directory where we are running.
   m_baseDir = File::FullPath( File::ExtractDirectory( m_executablePath ) );
   if ( m_baseDir.EndsWith( '/' ) )
      m_baseDir.Delete( m_baseDir.UpperBound() );

   // Default source installation directory.
   m_sourceDir = m_baseDir + "/PixInsight";

   // Default application installation directory.
   m_installDir = "/opt/PixInsight";

   // Default desktop entry installation directory.
   m_installDesktopDir = "/usr/share/applications";
   if ( !File::DirectoryExists( m_installDesktopDir ) )
      m_installDesktopDir = "/usr/local/share/applications"; // FreeBSD

   // Default application icons installation directory.
   m_installIconsDir = "/usr/share/icons/hicolor";
   if ( !File::DirectoryExists( m_installIconsDir ) )
      m_installIconsDir = "/usr/local/share/icons/hicolor"; // FreeBSD

   // By default, we create a launcher script on /bin so one can say just
   // PixInsight from a terminal.
   m_createBinLauncher = true;

   // By default, we do not backup a previous installation.
   m_removePrevious = true;

   // Assume we are running on an UTF-8 POSIX-compliant system.
   StringList inputArgs;
   for ( int i = 1; i < argc; ++i )
      inputArgs.Add( IsoString( argv[i] ).UTF8ToUTF16() );

   // Parse the list of command-line arguments.
   ArgumentList arguments = ExtractArguments( inputArgs, ArgumentItemMode::NoItems );

   // Iterate and interpret command-line arguments.
   for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i )
   {
      if ( i->IsNumeric() )
      {
         throw Error( "Unknown numeric argument: " + i->Token() );
      }
      else if ( i->IsString() )
      {
         if ( i->Id() == "-source-dir" || i->Id() == "s" )
            m_sourceDir = i->StringValue();
         else if ( i->Id() == "-install-dir" || i->Id() == "i" )
            m_installDir = i->StringValue();
         else if ( i->Id() == "-install-desktop-dir" )
            m_installDesktopDir = i->StringValue();
         else if ( i->Id() == "-install-icons-dir" )
            m_installIconsDir = i->StringValue();
         else
            throw Error( "Unknown string argument: " + i->Token() );
      }
      else if ( i->IsSwitch() )
      {
         if ( i->Id() == "-remove" || i->Id() == "r" )
            m_removePrevious = i->SwitchState();
         else if ( i->Id() == "-bin-launcher" )
            m_createBinLauncher = i->SwitchState();
         else
            throw Error( "Unknown switch argument: " + i->Token() );
      }
      else if ( i->IsLiteral() )
      {
         if ( i->Id() == "-remove" || i->Id() == "r" )
            m_removePrevious = true;
         else if ( i->Id() == "-no-remove" || i->Id() == "r" ) // also support the --no-xxx idiom
            m_removePrevious = false;
         else if ( i->Id() == "-bin-launcher" )
            m_createBinLauncher = true;
         else if ( i->Id() == "-no-bin-launcher" )
            m_createBinLauncher = false;
         else if ( i->Id() == "-uninstall" || i->Id() == "u" )
            m_task = UninstallTask;
         else if ( i->Id() == "-version" )
            m_task = ShowVersionTask;
         else if ( i->Id() == "-help" )
            m_task = ShowHelpTask;
         else
            throw Error( "Unknown argument: " + i->Token() );
      }
      else if ( i->IsItemList() )
      {
         throw Error( "Unexpected non-parametric argument: " + i->Token() );
      }
   }

   // Sanitize working directories.
   if ( m_sourceDir.EndsWith( '/' ) )
      m_sourceDir.Delete( m_sourceDir.UpperBound() );
   if ( m_installDir.EndsWith( '/' ) )
      m_installDir.Delete( m_installDir.UpperBound() );
   if ( m_installDesktopDir.EndsWith( '/' ) )
      m_installDesktopDir.Delete( m_installDesktopDir.UpperBound() );
   if ( m_installIconsDir.EndsWith( '/' ) )
      m_installIconsDir.Delete( m_installIconsDir.UpperBound() );

   // Launcher script
   m_binLauncherFile = "/bin/PixInsight";

   // Application desktop entry file
   m_desktopEntryFile = m_installDesktopDir + "/PixInsight.desktop";

   // Application icon files
   m_icon16x16File    = m_installIconsDir + "/16x16/apps/PixInsight.png";
   m_icon24x24File    = m_installIconsDir + "/24x24/apps/PixInsight.png";
   m_icon32x32File    = m_installIconsDir + "/32x32/apps/PixInsight.png";
   m_icon48x48File    = m_installIconsDir + "/48x48/apps/PixInsight.png";
   m_icon64x64File    = m_installIconsDir + "/64x64/apps/PixInsight.png";
   m_icon128x128File  = m_installIconsDir + "/128x128/apps/PixInsight.png";
   m_icon256x256File  = m_installIconsDir + "/256x256/apps/PixInsight.png";

   // Source icon files
   m_sourceIcon16x16File   = m_sourceDir + "/rsc/icons/pixinsight-icon.16.png";
   m_sourceIcon24x24File   = m_sourceDir + "/rsc/icons/pixinsight-icon.24.png";
   m_sourceIcon32x32File   = m_sourceDir + "/rsc/icons/pixinsight-icon.32.png";
   m_sourceIcon48x48File   = m_sourceDir + "/rsc/icons/pixinsight-icon.48.png";
   m_sourceIcon64x64File   = m_sourceDir + "/rsc/icons/pixinsight-icon.64.png";
   m_sourceIcon128x128File = m_sourceDir + "/rsc/icons/pixinsight-icon.128.png";
   m_sourceIcon256x256File = m_sourceDir + "/rsc/icons/pixinsight-icon.256.png";
}
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;
}
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;
}
Exemple #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;
}
Exemple #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;
}
Exemple #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;
}
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;
}