Пример #1
0
void JP2Instance::WriteICCProfile( const ICCProfile& icc )
{
   CheckOpenStream( !m_path.IsEmpty(), "WriteICCProfile" );

   if ( m_jp2CMProfile != nullptr )
      jas_cmprof_destroy( m_jp2CMProfile ), m_jp2CMProfile = nullptr;

   if ( icc.IsProfile() )
   {
      jas_iccprof_t* jp2ICCProfile = nullptr;

      try
      {
         ByteArray iccData = icc.ProfileData();
         iccData.EnsureUnique();

         jp2ICCProfile = jas_iccprof_createfrombuf( iccData.Begin(), int( icc.ProfileSize() ) );
         if ( jp2ICCProfile == nullptr )
            JP2KERROR( "Unable to generate embedded ICC profile in JPEG2000 image" );

         m_jp2CMProfile = jas_cmprof_createfromiccprof( jp2ICCProfile );
         if ( m_jp2CMProfile == nullptr )
            JP2KERROR( "Unable to embed ICC profile in JPEG2000 image" );

         jas_iccprof_destroy( jp2ICCProfile ), jp2ICCProfile = nullptr;

         Console().WriteLn( "<end><cbr>ICC profile embedded: \'" + icc.Description() + "\', " + String( icc.ProfileSize() ) + " bytes." );
      }
      catch ( ... )
      {
         if ( jp2ICCProfile != nullptr )
            jas_iccprof_destroy( jp2ICCProfile );
         Close();
         throw;
      }
   }
}