Esempio n. 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;
      }
   }
}
Esempio n. 2
0
bool ProcessInstance::SetParameterValue( const Variant& value,
                                         const ProcessParameter& parameter, size_type rowIndex )
{
   if ( !value.IsValid() )
      return false;

   uint32 apiType = (*API->Process->GetParameterType)( parameter.Handle() ) & PTYPE_TYPE_MASK;
   if ( apiType == 0 )
      throw APIFunctionError( "GetParameterType" );

   if ( apiType == PTYPE_TABLE )
      throw Error( "ProcessInstance::SetParameterValue(): Invoked for a table parameter" );

   if ( apiType == PTYPE_STRING )
   {
      String s = value.ToString();
      return (*API->Process->SetParameterValue)( handle, parameter.Handle(), rowIndex, s.c_str(), s.Length() ) != api_false;
   }

   if ( apiType == PTYPE_BLOCK )
   {
      ByteArray a = value.ToByteArray();
      return (*API->Process->SetParameterValue)( handle, parameter.Handle(), rowIndex, a.Begin(), a.Length() ) != api_false;
   }

   union
   {
      uint32   u32;
      int32    i32;
      uint64   u64;
      int64    i64;
      float    f;
      double   d;
      api_bool b;
      api_enum e;
   }
   apiValue;

   switch ( apiType )
   {
   case PTYPE_UINT8:
   case PTYPE_UINT16:
   case PTYPE_UINT32:
      apiValue.u32 = value.ToUInt();
      break;
   case PTYPE_INT8:
   case PTYPE_INT16:
   case PTYPE_INT32:
      apiValue.i32 = value.ToInt();
      break;
   case PTYPE_UINT64:
      apiValue.u64 = value.ToUInt64();
      break;
   case PTYPE_INT64:
      apiValue.i64 = value.ToInt64();
      break;
   case PTYPE_FLOAT:
      apiValue.f = value.ToFloat();
      break;
   case PTYPE_DOUBLE:
      apiValue.d = value.ToDouble();
      break;
   case PTYPE_BOOL:
      apiValue.b = api_bool( value.ToBoolean() );
      break;
   case PTYPE_ENUM:
      apiValue.e = api_enum( value.ToInt() );
      break;
   default:
      throw Error( "ProcessParameter::SetParameterValue(): Internal error: Unknown parameter type" );
   }

   return (*API->Process->SetParameterValue)( handle, parameter.Handle(), rowIndex, &apiValue, 1 ) != api_false;
}
Esempio n. 3
0
void ExternalProcess::Write( const ByteArray& data )
{
   if ( !data.IsEmpty() )
      if ( (*API->ExternalProcess->WriteToExternalProcess)( handle, data.Begin(), data.Length() ) == api_false )
         throw APIFunctionError( "WriteToExternalProcess" );
}