bool FileFormatInstance::WriteColorFilterArray( const ColorFilterArray& cfa ) { try { if ( (*API->FileFormat->BeginColorFilterArrayEmbedding)( handle ) == api_false ) return false; IsoString pattern = cfa.Pattern(); pattern.EnsureUnique(); String name = cfa.Name(); name.EnsureUnique(); bool ok = (*API->FileFormat->SetImageColorFilterArray)( handle, pattern.c_str(), cfa.Width(), cfa.Height(), name.c_str() ) != api_false; if ( cfa.Pattern() != pattern || cfa.Name() != name ) APIHackingAttempt( "WriteColorFilterArray" ); (*API->FileFormat->EndColorFilterArrayEmbedding)( handle ); return ok; } catch ( ... ) { (*API->FileFormat->EndColorFilterArrayEmbedding)( handle ); throw; } }
bool FileFormatInstance::Open( ImageDescriptionArray& images, const String& filePath, const IsoString& hints ) { images.Clear(); if ( (*API->FileFormat->OpenImageFileEx)( handle, filePath.c_str(), hints.c_str(), 0/*flags*/ ) == api_false ) return false; for ( uint32 i = 0, n = (*API->FileFormat->GetImageCount)( handle ); i < n; ++i ) { IsoString id; size_type len = 0; (*API->FileFormat->GetImageId)( handle, 0, &len, i ); if ( len > 0 ) { id.SetLength( len ); if ( (*API->FileFormat->GetImageId)( handle, id.Begin(), &len, i ) == api_false ) throw APIFunctionError( "GetImageId" ); id.ResizeToNullTerminated(); } api_image_info info; api_image_options options; if ( (*API->FileFormat->GetImageDescription)( handle, &info, &options, i ) == api_false ) throw APIFunctionError( "GetImageDescription" ); ImageDescription d; d.id = id; APIImageInfoToPCL( d.info, info ); APIImageOptionsToPCL( d.options, options ); images.Add( d ); } return true; }
static IsoString GetDemangledFunctionName( const char* symbol, IsoString& addrStr ) { IsoString symbolStr( symbol ); addrStr.Clear(); // Get mangled function name. Example: // /opt/PixInsight/bin/lib/libQtGui.so.4(_ZN7QWidget5eventEP6QEvent+0x411) [0x7fa271347811] StringList tokens; symbolStr.Break( tokens, '(' , true/*trim*/ ); if ( tokens.Length() != 2 ) return symbolStr; // Take second token and split again. StringList tokens2; tokens[1].Break( tokens2, '+' , true/*trim*/ ); if ( tokens2.Length() != 2 ) return symbolStr; // If there is no function name, do not set the addr string. if ( !tokens2[0].IsEmpty() ) { addrStr = tokens2[1]; addrStr.DeleteChar( '(' ); addrStr.DeleteChar( ')' ); } // The first token of tokens2 contains the mangled string. Demangle it. size_t funcnameSize = 256; char funcname[ funcnameSize ]; int status; IsoString token( tokens2[0] ); const char* demangledFuncname = abi::__cxa_demangle( token.c_str(), funcname, &funcnameSize, &status ); return (status == 0) ? IsoString( demangledFuncname ) : symbolStr; }
void FileDataCache::Purge() const { IsoString key = m_keyPrefix; if ( key.EndsWith( '/' ) ) key.DeleteRight( key.UpperBound() ); Settings::Remove( key ); }
String ProcessInstance::ToSource( const IsoString& language, const IsoString& varId, int indent ) const { char16_type* s = (*API->Process->GetProcessInstanceSourceCode)( ModuleHandle(), handle, language.c_str(), varId.c_str(), indent ); if ( s == 0 ) throw APIFunctionError( "GetProcessInstanceSourceCode" ); String source( s ); Module->Deallocate( s ); return source; }
void SwitchProperty::addElement(IsoString elementName, IsoString value){ ISwitch* sp = ((ISwitchVectorProperty*) m_property->getProperty())->sp; int nsp = ((ISwitchVectorProperty*) m_property->getProperty())->nsp; sp = (ISwitch*) realloc(sp, (nsp+1) * sizeof(ISwitch)); CHECK_POINTER(sp); strcpy(sp->name, elementName.c_str()); sp->s = (strcmp(value.c_str(),"ON")==0) ? ISS_ON : ISS_OFF ; sp->svp =(ISwitchVectorProperty*) m_property->getProperty(); ((ISwitchVectorProperty*) m_property->getProperty())->nsp++; ((ISwitchVectorProperty*) m_property->getProperty())->sp = sp; }
void NumberProperty::addElement(IsoString elementName, IsoString value){ INumber* np = ((INumberVectorProperty*) m_property->getProperty())->np; int nnp = ((INumberVectorProperty*) m_property->getProperty())->nnp; np = (INumber*) realloc(np, (nnp+1) * sizeof(INumber)); CHECK_POINTER(np); strcpy(np->name, elementName.c_str()); np->value = value.ToDouble(); np->nvp=(INumberVectorProperty*) m_property->getProperty(); ((INumberVectorProperty*) m_property->getProperty())->nnp++; ((INumberVectorProperty*) m_property->getProperty())->np = np; }
void FileFormatImplementation::SetImageProperty( const IsoString& id, const Variant& value ) { IsoString tid = id.Trimmed(); if ( !tid.IsEmpty() && value.IsValid() ) { FileFormatPropertyArray::iterator i = m_data->properties.Search( tid ); if ( i != m_data->properties.End() ) i->value = value; else m_data->properties.Append( FileFormatProperty( tid, value ) ); } }
void TextProperty::addElement(IsoString elementName, IsoString value) { IText* tp = ((ITextVectorProperty*) m_property->getProperty())->tp; int ntp = ((ITextVectorProperty*) m_property->getProperty())->ntp; tp = (IText*) realloc(tp, (ntp + 1) * sizeof(IText)); CHECK_POINTER(tp); strcpy(tp->name, elementName.c_str()); //FIXME Leaks memory? tp->text = (char*) malloc(sizeof(value.c_str())); strcpy(tp->text, value.c_str()); tp->tvp = (ITextVectorProperty*) m_property->getProperty(); ((ITextVectorProperty*) m_property->getProperty())->ntp++; ((ITextVectorProperty*) m_property->getProperty())->tp = tp; }
void TextProperty::addElement( IsoString elementName, IsoString value ) { ITextVectorProperty* tvp = m_property->getText(); IText* tp = tvp->tp; int ntp = tvp->ntp; tp = reinterpret_cast<IText*>( realloc( tp, (ntp + 1)* sizeof( IText ) ) ); if ( tp == nullptr ) throw std::bad_alloc(); strcpy( tp->name, elementName.c_str() ); tp->text = value.Release(); // N.B.: Can do this because value is being passed by value, so we have a local copy. tp->tvp = tvp; tvp->ntp++; tvp->tp = tp; }
ProcessParameter::ProcessParameter( const Process& process, const IsoString& paramId ) { m_data = new ProcessParameterPrivate( (*API->Process->GetParameterByName)( process.Handle(), paramId.c_str() ) ); if ( m_data->handle == nullptr ) { if ( paramId.IsEmpty() ) throw Error( "ProcessParameter: Empty process parameter identifier specified" ); if ( !paramId.IsValidIdentifier() ) throw Error( "ProcessParameter: Invalid process parameter identifier specified: \'" + paramId + '\'' ); throw Error( "ProcessParameter: No parameter was found " "with the specified identifier \'" + paramId + "\' for process \'" + process.Id() + '\'' ); } }
ImagePropertyDescriptionArray FileFormatInstance::Properties() { ImagePropertyDescriptionArray properties; IsoString id; size_type len = 0; (*API->FileFormat->EnumerateImageProperties)( handle, 0, 0, &len, 0 ); // 1st call to get max identifier length if ( len > 0 ) { id.Reserve( len ); if ( (*API->FileFormat->EnumerateImageProperties)( handle, APIPropertyEnumerationCallback, id.Begin(), &len, &properties ) == api_false ) throw APIFunctionError( "EnumerateImageProperties" ); } return properties; }
IsoString View::FullId() const { size_type len = 0; (*API->View->GetViewFullId)( handle, 0, &len ); IsoString id; if ( len > 0 ) { id.SetLength( len ); if ( (*API->View->GetViewFullId)( handle, id.c_str(), &len ) == api_false ) throw APIFunctionError( "GetViewFullId" ); id.ResizeToNullTerminated(); } return id; }
IsoString ProcessParameter::Id() const { size_type len = 0; (*API->Process->GetParameterIdentifier)( m_data->handle, 0, &len ); IsoString id; if ( len > 0 ) { id.SetLength( len ); if ( (*API->Process->GetParameterIdentifier)( m_data->handle, id.c_str(), &len ) == api_false ) throw APIFunctionError( "GetParameterIdentifier" ); id.ResizeToNullTerminated(); } return id; }
IsoString FileFormat::Name() const { size_type len = 0; (*API->FileFormat->GetFileFormatName)( m_data->handle, 0, &len ); IsoString name; if ( len > 0 ) { name.SetLength( len ); if ( (*API->FileFormat->GetFileFormatName)( m_data->handle, name.c_str(), &len ) == api_false ) throw APIFunctionError( "GetFileFormatName" ); name.ResizeToNullTerminated(); } return name; }
void MetaModule::GetVersion( int& major, int& minor, int& release, int& build, IsoString& language, IsoString& status ) const { // Set undefined states for all variables, in case of error. major = minor = release = build = 0; language.Clear(); status.Clear(); IsoString vs( Version() ); // A version string must begin with a version marker if ( vs.Length() < LengthOfVersionMarker ) return; // Split the string of version numbers into tokens separated by dots StringList tokens; vs.Break( tokens, '.', false/*trim*/, LengthOfVersionMarker ); // Required: MM.mm.rr.bbbb.LLL // Optional: .<status> if ( tokens.Length() < 5 || tokens.Length() > 6 ) return; // Extract version numbers try { int MM = tokens[0].ToInt( 10 ); int mm = tokens[1].ToInt( 10 ); int rr = tokens[2].ToInt( 10 ); int bbbb = tokens[3].ToInt( 10 ); major = MM; minor = mm; release = rr; build = bbbb; } catch ( ... ) // silently eat all parse exceptions here { return; } // Language code language = tokens[4]; // ### TODO: Verify validity of ISO 639.2 code // Optional status word if ( tokens.Length() == 6 ) status = tokens[5]; // ### TODO: Verify validity of the status word }
Variant View::ComputeProperty( const IsoString& property, bool notify ) { api_property_value value; if ( (*API->View->ComputeViewProperty)( ModuleHandle(), handle, property.c_str(), notify, &value ) == api_false ) throw APIFunctionError( "ComputeViewProperty" ); return VariantFromAPIPropertyValue( value ); }
Variant::data_type View::PropertyType( const IsoString& property ) const { uint64 type = 0; if ( (*API->View->GetViewPropertyAttributes)( ModuleHandle(), handle, property.c_str(), 0/*flags*/, &type ) == api_false ) throw APIFunctionError( "GetViewPropertyAttributes" ); return VariantTypeFromAPIPropertyType( type ); }
bool FileFormatInstance::WriteProperty( const IsoString& property, const Variant& value ) { try { if ( (*API->FileFormat->BeginPropertyEmbedding)( handle ) == api_false ) return false; bool ok = true; if ( value.IsValid() ) { api_property_value apiValue; APIPropertyValueFromVariant( apiValue, value ); api_property_value safeCopy = apiValue; ok = (*API->FileFormat->SetImageProperty)( handle, property.c_str(), &safeCopy ) != api_false; if ( safeCopy.data.blockValue != apiValue.data.blockValue || safeCopy.dimX != apiValue.dimX || safeCopy.dimY != apiValue.dimY || safeCopy.dimZ != apiValue.dimZ || safeCopy.dimT != apiValue.dimT || safeCopy.type != apiValue.type ) { APIHackingAttempt( "WriteProperty" ); } } (*API->FileFormat->EndPropertyEmbedding)( handle ); return ok; } catch ( ... ) { (*API->FileFormat->EndPropertyEmbedding)( handle ); throw; } }
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; } }
void View::SetPropertyValue( const IsoString& property, const Variant& value, bool notify, ViewPropertyAttributes attributes ) { api_property_value apiValue; APIPropertyValueFromVariant( apiValue, value ); if ( (*API->View->SetViewPropertyValue)( ModuleHandle(), handle, property.c_str(), &apiValue, attributes, notify ) == api_false ) throw APIFunctionError( "SetViewPropertyValue" ); }
ViewPropertyAttributes View::PropertyAttributes( const IsoString& property ) const { uint32 flags = 0; if ( (*API->View->GetViewPropertyAttributes)( ModuleHandle(), handle, property.c_str(), &flags, 0/*type*/ ) == api_false ) throw APIFunctionError( "GetViewPropertyAttributes" ); return ViewPropertyAttributes( ViewPropertyAttribute::mask_type( flags ) ); }
Variant View::PropertyValue( const IsoString& property ) const { api_property_value value; if ( (*API->View->GetViewPropertyValue)( ModuleHandle(), handle, property.c_str(), &value ) == api_false ) throw APIFunctionError( "GetViewPropertyValue" ); return VariantFromAPIPropertyValue( value ); }
IsoStringList ProcessParameter::Aliases() const { size_type len = 0; (*API->Process->GetParameterAliasIdentifiers)( m_data->handle, 0, &len ); IsoStringList aliases; if ( len > 0 ) { IsoString csAliases; csAliases.SetLength( len ); if ( (*API->Process->GetParameterAliasIdentifiers)( m_data->handle, csAliases.c_str(), &len ) == api_false ) throw APIFunctionError( "GetParameterAliasIdentifiers" ); csAliases.ResizeToNullTerminated(); csAliases.Break( aliases, ',' ); } return aliases; }
void NumberProperty::addElement( IsoString elementName, IsoString value ) { if ( !value.IsEmpty() ) { INumberVectorProperty* nvp = m_property->getNumber(); INumber* np = nvp->np; int nnp = nvp->nnp; np = reinterpret_cast<INumber*>( realloc( np, (nnp + 1)*sizeof( INumber ) ) ); if ( np == nullptr ) throw std::bad_alloc(); strcpy( np->name, elementName.c_str() ); value.TryToDouble( np->value ); np->nvp = nvp; nvp->nnp++; nvp->np = np; } }
IsoString Filter::ToSource() const { IsoString s; if ( IsValid() ) { if ( IsSeparable() ) { s += "SeparableFilter {\n"; s += " name { " + Separable().Name().ToUTF8() + " }\n"; s += " row-vector { "; SeparableFilter::coefficient_vector H = Separable().RowFilter(); for ( int i = 0; i < H.Length(); ++i ) s.AppendFormat( ( H[i] < 0 ) ? "%.6f " : " %.6f ", H[i] ); s += "}\n"; s += " col-vector { "; SeparableFilter::coefficient_vector V = Separable().ColFilter(); for ( int i = 0; i < V.Length(); ++i ) s.AppendFormat( ( V[i] < 0 ) ? "%.6f " : " %.6f ", V[i] ); s += "}\n"; } else { s += "KernelFilter {\n"; s += " name { " + Kernel().Name().ToUTF8() + " }\n"; s += " coefficients {\n"; KernelFilter::coefficient_matrix M = Kernel().Coefficients(); for ( int i = 0; i < M.Rows(); ++i ) { s += " "; for ( int j = 0; ; ) { s.AppendFormat( ( M[i][j] < 0 ) ? "%.6f " : " %.6f ", M[i][j] ); if ( ++j == M.Cols() ) break; s += ' '; } s += '\n'; } s += " }\n"; } s += "}\n"; } return s; }
Filter Filter::FromSource( const IsoString& src ) { IsoStringList lines; src.Break( lines, '\n' ); FilterParser P( lines ); if ( P.Filters().IsEmpty() ) return Filter(); return P.Filters()[0]; }
IsoStringList ProcessInstance::Icons() { size_type len = 0; (*API->Process->EnumerateProcessIcons)( 0, 0, &len, 0 ); IsoStringList icons; if ( len != 0 ) { IsoString iconId; iconId.Reserve( len ); if ( (*API->Process->EnumerateProcessIcons)( InternalIconEnumerator::IconCallback, iconId.c_str(), &len, &icons ) == api_false ) throw APIFunctionError( "EnumerateProcessIcons" ); } return icons; }
IsoStringList ProcessInstance::IconsByProcessId( const IsoString& processId ) { size_type len = 0; (*API->Process->EnumerateProcessIcons)( 0, 0, &len, 0 ); ProcessIconsByProcessIdEnumerationData data( processId ); if ( len != 0 ) { IsoString iconId; iconId.Reserve( len ); if ( (*API->Process->EnumerateProcessIcons)( InternalIconEnumerator::ProcessCallback, iconId.c_str(), &len, &data ) == api_false ) throw APIFunctionError( "EnumerateProcessIcons" ); } return data.icons; }
ProcessParameter::ProcessParameter( const ProcessParameter& table, const IsoString& colId ) { m_data = new ProcessParameterPrivate( (*API->Process->GetTableColumnByName)( table.m_data->handle, colId.c_str() ) ); if ( m_data->handle == nullptr ) { if ( table.IsNull() ) throw Error( "ProcessParameter: Null table parameter" ); if ( colId.IsEmpty() ) throw Error( "ProcessParameter: Empty table column parameter identifier specified" ); if ( !colId.IsValidIdentifier() ) throw Error( "ProcessParameter: Invalid table column parameter identifier specified: \'" + colId + '\'' ); if ( !table.IsTable() ) throw Error( "ProcessParameter: The specified parameter \'" + table.Id() + "\' is not a table parameter" ); throw Error( "ProcessParameter: No table column parameter was found " "with the specified identifier \'" + colId + "\' " "for table parameter \'" + table.Id() + "\' " "of process \'" + table.ParentProcess().Id() + '\'' ); } }