Пример #1
0
ImageDescriptionArray JPEGInstance::Open( const String& filePath, const IsoString& hints )
{
   Close();

   try
   {
      Exception::EnableConsoleOutput();

      JPEGImageOptions jpegOptions = JPEGFormat::DefaultOptions();
      IsoStringList theHints;
      hints.Break( theHints, ' ', true/*trim*/ );
      theHints.Remove( IsoString() );
      for ( IsoStringList::const_iterator i = theHints.Begin(); i < theHints.End(); ++i )
         if ( *i == "verbosity" )
         {
            if ( ++i == theHints.End() )
               break;
            int n;
            if ( i->TryToInt( n ) )
               jpegOptions.verbosity = Range( n, 0, 3 );
         }

      m_reader = new JPEGReader;
      m_reader->SetJPEGOptions( jpegOptions );
      m_reader->Open( filePath );
      return ImageDescriptionArray() << ImageDescription( m_reader->Info(), m_reader->Options() );
   }
   catch ( ... )
   {
      Close();
      throw;
   }
}
Пример #2
0
void JPEGInstance::Create( const String& filePath, int numberOfImages, const IsoString& hints )
{
   Close();

   Exception::EnableConsoleOutput();

   m_writer = new JPEGWriter;
   m_writer->Create( filePath );

   JPEGImageOptions jpegOptions = JPEGFormat::DefaultOptions();

   IsoStringList theHints;
   hints.Break( theHints, ' ', true/*trim*/ );
   theHints.Remove( IsoString() );
   for ( IsoStringList::const_iterator i = theHints.Begin(); i < theHints.End(); ++i )
   {
      if ( *i == "quality" )
      {
         if ( ++i == theHints.End() )
            break;
         int q = jpegOptions.quality;
         if ( i->TryToInt( q ) )
            jpegOptions.quality = Range( q, 0, 100 );
      }
      else if ( *i == "optimized" )
         jpegOptions.optimizedCoding = true;
      else if ( *i == "no-optimized" )
         jpegOptions.optimizedCoding = false;
      else if ( *i == "arithmetic" )
         jpegOptions.arithmeticCoding = true;
      else if ( *i == "huffman" )
         jpegOptions.arithmeticCoding = false;
      else if ( *i == "progressive" )
         jpegOptions.progressive = true;
      else if ( *i == "no-progressive" )
         jpegOptions.progressive = false;
      else if ( *i == "verbosity" )
      {
         if ( ++i == theHints.End() )
            break;
         int n;
         if ( i->TryToInt( n ) )
            jpegOptions.verbosity = Range( n, 0, 3 );
      }
   }

   m_writer->SetJPEGOptions( jpegOptions );
}
Пример #3
0
FilterParser::token_list FilterParser::Tokenize( const IsoStringList& linesUTF8 )
{
   token_list tokenList;
   bool blockComment = false;
   int row = 0;
   for ( IsoStringList::const_iterator i = linesUTF8.Begin(); i < linesUTF8.End(); ++i, ++row )
   {
      IsoString token;
      int tokenCol = 0;
      for ( IsoString::const_iterator j = i->Begin(); j < i->End(); ++j )
      {
         if ( blockComment )
         {
            if ( *j == '*' )
               if ( ++j < i->End() )
                  if ( *j == '/' )
                  {
                     blockComment = false;
                     /*
                      * Uncomment the next line to turn block comments into
                      * separators.
                      *
                     tokenCol = j - i->Begin() + 1;
                      */
                  }
         }
         else
         {
            bool lineComment = false;
            switch ( *j )
            {
            case ' ':
            case '\t':
               if ( !token.IsEmpty() )
               {
                  tokenList.Add( Token( token, row, tokenCol ) );
                  token.Clear();
               }
               for ( IsoString::const_iterator k = j; ++k < i->End(); ++j )
                  if ( *k != ' ' && *k != '\t' )
                     break;
               tokenCol = j - i->Begin() + 1;
               break;
               /*
            case ',':
               if ( token.IsEmpty() )
                  throw SourceCodeError( "Expected a token before ','", row+1, int( j - i->Begin() + 1 ) );
               tokenList.Add( Token( token, row, tokenCol ) );
               token.Clear();
               tokenCol = j - i->Begin() + 1;
               break;
               */
            case '{':
            case '}':
               if ( !token.IsEmpty() )
               {
                  tokenList.Add( Token( token, row, tokenCol ) );
                  token.Clear();
               }
               tokenList.Add( Token( IsoString( *j ), row, int( j - i->Begin() ) ) );
               tokenCol = j - i->Begin() + 1;
               break;
            case '/':
               if ( ++j < i->End() )
               {
                  if ( *j == '/' )
                     lineComment = true;
                  else if ( *j == '*' )
                  {
                     blockComment = true;
                     /*
                      * Uncomment the next lines to turn block comments into
                      * separators.
                      *
                     if ( !token.IsEmpty() )
                     {
                        tokenList.Add( Token( token, row, tokenCol ) );
                        token.Clear();
                     }
                      */
                  }
                  else
                     token += *--j;
               }
               break;
            default:
               token += *j;
               break;
            }
            if ( lineComment )
               break;
         }
      }

      if ( !token.IsEmpty() )
         tokenList.Add( Token( token, row, tokenCol ) );
   }
   return tokenList;
}
Пример #4
0
void JPCInstance::Create( const String& filePath, int/*numberOfImages*/, const IsoString& hints )
{
   Close();

   Exception::EnableConsoleOutput();

   m_path = filePath;

   IsoStringList theHints;
   hints.Break( theHints, ' ', true/*trim*/ );
   theHints.Remove( IsoString() );
   for ( IsoStringList::const_iterator i = theHints.Begin(); i < theHints.End(); ++i )
   {
      if ( *i == "lossy" )
         m_jp2Options.lossyCompression = true;
      else if ( *i == "lossless" )
         m_jp2Options.lossyCompression = false;
      else if ( *i == "compression-rate" )
      {
         if ( ++i == theHints.End() )
            break;
         if ( i->TryToFloat( m_jp2Options.compressionRate ) )
            m_jp2Options.compressionRate = Range( m_jp2Options.compressionRate, 0.01F, 0.99F );
      }
      else if ( *i == "signed" )
         m_jp2Options.signedSample = true;
      else if ( *i == "unsigned" )
         m_jp2Options.signedSample = false;
      else if ( *i == "tiled" )
         m_jp2Options.tiledImage = true;
      else if ( *i == "untiled" )
         m_jp2Options.tiledImage = true;
      else if ( *i == "tile-width" )
      {
         if ( ++i == theHints.End() )
            break;
         if ( i->TryToInt( m_jp2Options.tileWidth ) )
            m_jp2Options.tileWidth = Range( m_jp2Options.tileWidth, 16, 8192 );
      }
      else if ( *i == "tile-height" )
      {
         if ( ++i == theHints.End() )
            break;
         if ( i->TryToInt( m_jp2Options.tileHeight ) )
            m_jp2Options.tileHeight = Range( m_jp2Options.tileHeight, 16, 8192 );
      }
      else if ( *i == "layers" )
      {
         if ( ++i == theHints.End() )
            break;
         if ( i->TryToInt( m_jp2Options.numberOfLayers ) )
            m_jp2Options.numberOfLayers = Range( m_jp2Options.numberOfLayers, 1, 10 );
      }
      else if ( *i == "lrcp" )
         m_jp2Options.progressionOrder = JPEG2000ProgressionOrder::LRCP;
      else if ( *i == "rlcp" )
         m_jp2Options.progressionOrder = JPEG2000ProgressionOrder::RLCP;
      else if ( *i == "rpcl" )
         m_jp2Options.progressionOrder = JPEG2000ProgressionOrder::RPCL;
      else if ( *i == "pcrl" )
         m_jp2Options.progressionOrder = JPEG2000ProgressionOrder::PCRL;
      else if ( *i == "cprl" )
         m_jp2Options.progressionOrder = JPEG2000ProgressionOrder::CPRL;
   }
}