Exemplo n.º 1
0
bool FileDataCacheItem::FromString( const String& s )
{
   path.Clear();
   lastUsed = 0;
   time.year = 0;

   StringList tokens;
   s.Break( tokens, char16_type( '\n' ) );

   for ( StringList::const_iterator i = tokens.Begin(); i != tokens.End(); )
   {
      if ( *i == "path" )
      {
         if ( ++i == tokens.End() )
            return false;
         path = i->Trimmed();
         ++i;
      }
      else if ( *i == "lastUsed" )
      {
         if ( ++i == tokens.End() )
            return false;
         lastUsed = i->ToUInt();
         ++i;
      }
      else if ( *i == "time" )
      {
         if ( tokens.End() - i < 3 )
            return false;
         int y, m, d; double f;
         JDToComplexTime( y, m, d, f, i[1].ToUInt()+0.5 );
         unsigned t = i[2].ToUInt();
         time.year = y;
         time.month = m;
         time.day = d;
         time.milliseconds = t - 86399000;
         time.hour = TruncI( (t = TruncI( t/1000.0 ))/3600.0 );
         time.minute = TruncI( (t -= time.hour*3600)/60.0 );
         time.second = t - time.minute*60;
         i += 3;
      }
      else if ( *i == "data" )
      {
         if ( !GetDataFromTokens( tokens ) )
            return false;
         ++i;
      }
      else
      {
         ++i;
      }
   }

   return !path.IsEmpty() && lastUsed > 0 && time.year > 0 && ValidateData();
}
Exemplo n.º 2
0
void NumericControl::__ValueUpdated( Slider& sender, int v )
{
   int i0, i1;
   sender.GetRange( i0, i1 );
   double d = i1 - i0;
   double newValue = Round( lowerBound + (upperBound - lowerBound)*((v - i0)/d),
                            isReal ? Max( 0, TruncI( Log( d ) ) ) : 0 );

   if ( newValue != value )
   {
      value = newValue;

      edit.SetText( ValueAsString() );

      if ( onValueUpdated != 0 )
         (onValueUpdatedReceiver->*onValueUpdated)( *this, value );
   }
}
Exemplo n.º 3
0
void FilterParser::Parse( const token_list& tokens )
{
   filters.Clear();

   int filterType = UnknownFilterType;
   String filterName;
   int filterSize = 0;
   KernelFilter::coefficient_matrix    filterMatrix;
   SeparableFilter::coefficient_vector rowVector, colVector;

   int state = FilterTypeState;

   for ( token_list::const_iterator i = tokens.Begin(); i != tokens.End(); )
   {
      switch ( state )
      {
      case FilterTypeState:
         {
            if ( i->token == "KernelFilter" )
               filterType = KernelFilterType;
            else if ( i->token == "SeparableFilter" )
               filterType = SeparableFilterType;
            else if ( i->token == '{' || i->token == '}' )
               PARSE_ERROR( "Misplaced bracket", i );
            else if ( !i->token.IsValidIdentifier() )
               PARSE_ERROR( "Invalid filter type \'" + i->token + '\'', i );
            else
               PARSE_ERROR( "Unknown filter type \'" + i->token + '\'', i );

            if ( ++i == tokens.End() || i->token != '{' )
               PARSE_ERROR( "Expected left bracket", i );
            state = FilterParameterState;

            ++i;
         }
         break;

      case FilterParameterState:
         {
            if ( i->token == '}' )
            {
               if ( filterName.IsEmpty() )
                  PARSE_ERROR( "Missing filter name", i );
               if ( filterSize == 0 )
                  PARSE_ERROR( "Empty filter definition", i );

               if ( filterType == KernelFilterType )
               {
                  if ( filterMatrix.IsEmpty() )
                     PARSE_ERROR( "Missing kernel filter coefficients", i );

                  filters.Add( Filter( KernelFilter( filterMatrix, filterName ) ) );
               }
               else if ( filterType == SeparableFilterType )
               {
                  if ( rowVector.IsEmpty() || colVector.IsEmpty() )
                     PARSE_ERROR( "Missing separable filter coefficients", i );

                  filters.Add( Filter( SeparableFilter( rowVector, colVector, filterName ) ) );
               }
               else
                  PARSE_ERROR( "Internal parser error", i );

               filterName.Clear();
               filterSize = 0;
               filterMatrix = KernelFilter::coefficient_matrix();
               rowVector = colVector = SeparableFilter::coefficient_vector();

               state = FilterTypeState;
               ++i;
            }
            else
            {
               token_list::const_iterator j = i; ++j;
               token_list::const_iterator k = tokens.End();
               CaptureParameterValueTokens( j, k );
               int n = Distance( j, k );

               if ( i->token == "name" )
               {
                  if ( n == 0 )
                     PARSE_ERROR( "Expected a filter name", i );
                  if ( !filterName.IsEmpty() )
                     PARSE_ERROR( "Duplicate filter name", i );
                  filterName = j->token;
                  for ( ; ++j < k; )
                     filterName += ' ' + j->token;
               }
               else if ( i->token == "coefficients" )
               {
                  if ( filterType != KernelFilterType )
                     PARSE_ERROR( "Invalid kernel filter parameter", i );
                  if ( !filterMatrix.IsEmpty() )
                     PARSE_ERROR( "Duplicate kernel filter coefficients", i );

                  token_list::const_iterator p = j;
                  GenericVector<KernelFilter::coefficient> C( n );
                  for ( KernelFilter::coefficient* c = C.Begin(); c < C.End(); ++c, ++p )
                     *c = p->token.ToFloat();

                  int numberOfCoefficients = filterSize*filterSize;
                  if ( numberOfCoefficients != 0 )
                  {
                     if ( numberOfCoefficients != n )
                        PARSE_ERROR( "Incongruent kernel filter size; expected " + String( numberOfCoefficients ) + " coefficients", j );
                  }
                  else
                  {
                     filterSize = TruncI( Sqrt( double( n ) ) );
                     if ( filterSize*filterSize != n )
                        PARSE_ERROR( "Non-square kernel filter defined", j );
                     if ( filterSize < 3 )
                        PARSE_ERROR( "The kernel filter is too small - 3x3 is the minimum required", j );
                     if ( (filterSize & 0x01) == 0 )
                        PARSE_ERROR( "Invalid even kernel filter dimension (" + String( filterSize ) + ')', j );
                  }

                  filterMatrix = KernelFilter::coefficient_matrix( C.Begin(), filterSize, filterSize );
                  j = p;
               }
               else if ( i->token == "row-vector" )
               {
                  if ( filterType != SeparableFilterType )
                     PARSE_ERROR( "Invalid separable filter parameter", i );
                  if ( !rowVector.IsEmpty() )
                     PARSE_ERROR( "Duplicate row vector specification", i );

                  token_list::const_iterator p = j;
                  rowVector = SeparableFilter::coefficient_vector( n );
                  for ( SeparableFilter::coefficient* c = rowVector.Begin(); c < rowVector.End(); ++c, ++p )
                     *c = p->token.ToFloat();

                  if ( filterSize != 0 )
                  {
                     if ( filterSize != n )
                        PARSE_ERROR( "Incongruent separable row filter length; expected " + String( filterSize ) + " coefficients", j );
                  }
                  else
                  {
                     if ( n < 3 )
                        PARSE_ERROR( "Too few row filter coefficients specified - three or more coefficients are required", j );
                     if ( (n & 0x01) == 0 )
                        PARSE_ERROR( "Invalid even row filter length (" + String( n ) + ')', j );
                     filterSize = n;
                  }

                  j = p;
               }
               else if ( i->token == "col-vector" || i->token == "column-vector" )
               {
                  if ( filterType != SeparableFilterType )
                     PARSE_ERROR( "Invalid separable filter parameter", i );
                  if ( !colVector.IsEmpty() )
                     PARSE_ERROR( "Duplicate column vector specification", i );

                  token_list::const_iterator p = j;
                  colVector = SeparableFilter::coefficient_vector( n );
                  for ( SeparableFilter::coefficient* c = colVector.Begin(); c != colVector.End(); ++c, ++p )
                     *c = p->token.ToFloat();

                  if ( filterSize != 0 )
                  {
                     if ( filterSize != n )
                        PARSE_ERROR( "Incongruent separable column filter length; expected " + String( filterSize ) + " coefficients", j );
                  }
                  else
                  {
                     if ( n < 3 )
                        PARSE_ERROR( "Too few column filter coefficients specified - three or more coefficients are required", j );
                     if ( (n & 0x01) == 0 )
                        PARSE_ERROR( "Invalid even column filter length (" + String( n ) + ')', j );
                     filterSize = n;
                  }

                  j = p;
               }
               else
                  PARSE_ERROR( "Unknown filter parameter '" + i->token + '\'', i );

               int d = Distance( i, j );
               i = k;
               if ( d > 1 ) // j-i > 1 if and only if value is enclosed by brackets
                  ++i;
            }
         }
         break;

      default:
         PARSE_ERROR( "Internal parser error", i );
      }
   }

   if ( state != FilterTypeState )
      PARSE_ERROR( "Missing right bracket", tokens.At(tokens.UpperBound()));
}
Exemplo n.º 4
0
bool RotationInstance::ExecuteOn( View& view )
{
   if ( !view.IsMainView() )
      return false;  // should never reach this point!

   AutoViewLock lock( view );

   ImageVariant image = view.Image();

   if ( image.IsComplexSample() )
      return false;

   double degrees = Round( Deg( p_angle ), 4 );
   if ( degrees == 0 )
   {
      Console().WriteLn( "<end><cbr>&lt;* Identity *&gt;" );
      return true;
   }

   ImageWindow window = view.Window();

   window.RemoveMaskReferences();
   window.RemoveMask();
   window.DeletePreviews();

   Console().EnableAbort();

   StandardStatus status;
   image.SetStatusCallback( &status );

   if ( p_optimizeFast )
      switch ( TruncI( degrees ) )
      {
      case 90:
         Rotate90CCW() >> image;
         return true;
      case -90:
         Rotate90CW() >> image;
         return true;
      case 180:
      case -180:
         Rotate180() >> image;
         return true;
      default:
         break;
      }

   AutoPointer<PixelInterpolation> interpolation( NewInterpolation(
         p_interpolation, 1, 1, 1, 1, true, p_clampingThreshold, p_smoothness, image ) );

   Rotation T( *interpolation, p_angle );

   /*
    * On 32-bit systems, make sure the resulting image requires less than 4 GB.
    */
   if ( sizeof( void* ) == sizeof( uint32 ) )
   {
      int width = image.Width(), height = image.Height();
      T.GetNewSizes( width, height );
      uint64 sz = uint64( width )*uint64( height )*image.NumberOfChannels()*image.BytesPerSample();
      if ( sz > uint64( uint32_max-256 ) )
         throw Error( "Rotation: Invalid operation: Target image dimensions would exceed four gigabytes" );
   }

   T.SetFillValues( p_fillColor );
   T >> image;

   return true;
}