void NewImageInterface::__SetToActiveImage_Click( Button& /*sender*/, bool /*checked*/ ) { ImageWindow w = ImageWindow::ActiveWindow(); if ( !w.IsNull() ) { ImageVariant v = w.MainView().Image(); AbstractImage* img = v.AnyImage(); if ( img != 0 ) { if ( v.IsFloatSample() ) switch ( v.BitsPerSample() ) { case 32: instance.sampleFormat = NewImageSampleFormat::F32; break; case 64: instance.sampleFormat = NewImageSampleFormat::F64; break; } else switch ( v.BitsPerSample() ) { case 8: instance.sampleFormat = NewImageSampleFormat::I8; break; case 16: instance.sampleFormat = NewImageSampleFormat::I16; break; case 32: instance.sampleFormat = NewImageSampleFormat::I32; break; } instance.colorSpace = img->IsColor() ? NewImageColorSpace::RGB : NewImageColorSpace::Gray; instance.width = img->Width(); instance.height = img->Height(); instance.numberOfChannels = img->NumberOfChannels(); UpdateControls(); } } }
bool AnnotationInterface::ImportProcess( const ProcessImplementation& p ) { const AnnotationInstance* i = dynamic_cast<const AnnotationInstance*>( &p ); if ( i == 0 ) throw Error( "Not an Annotation instance." ); if ( view == 0 ) { ImageWindow w = ImageWindow::ActiveWindow(); if ( w.IsNull() ) { throw Error( "The Annotation interface requires an active image window to import a process instance." ); return false; } view = new View( w.MainView() ); view->AddToDynamicTargets(); } ClearBitmaps(); instance.Assign( *i ); annotationPlaced = false; leaderPlaced = false; if ( view->Window().CurrentView() != *view ) view->Window().SelectView( *view ); UpdateControls(); return true; }
void ProcessImplementation::LaunchOn( ImageWindow& w ) const { View mv( w.MainView() ); LaunchOn( mv ); }
ArgumentList ExtractArguments( const StringList& argv, argument_item_mode mode, ArgumentOptions options ) { bool noItems = mode == ArgumentItemMode::NoItems; bool itemsAsFiles = mode == ArgumentItemMode::AsFiles; bool itemsAsViews = mode == ArgumentItemMode::AsViews; bool allowWildcards = !noItems && options.IsFlagSet( ArgumentOption::AllowWildcards ); bool noPreviews = itemsAsViews && options.IsFlagSet( ArgumentOption::NoPreviews ); bool recursiveDirSearch = itemsAsFiles && allowWildcards && options.IsFlagSet( ArgumentOption::RecursiveDirSearch ); bool recursiveSearchArgs = recursiveDirSearch && options.IsFlagSet( ArgumentOption::RecursiveSearchArgs ); // This is the recursive search mode flag, controlled by --r[+|-] bool recursiveSearch = false; // The list of existing view identifiers, in case itemsAsViews = true. SortedStringList imageIds; // The list of extracted arguments ArgumentList arguments; for ( StringList::const_iterator i = argv.Begin(); i != argv.End(); ++i ) { if ( i->StartsWith( '-' ) ) { Argument arg( i->At( 1 ) ); if ( recursiveSearchArgs && arg.Id() == s_recursiveSearchArg ) { if ( arg.IsSwitch() ) recursiveSearch = arg.SwitchState(); else if ( arg.IsLiteral() ) recursiveSearch = true; else arguments.Add( arg ); } else arguments.Add( arg ); } else { if ( noItems ) throw ParseError( "Non-parametric arguments are not allowed", *i ); StringList items; if ( itemsAsFiles ) { String fileName = *i; if ( fileName.StartsWith( '\"' ) ) fileName.Delete( 0 ); if ( fileName.EndsWith( '\"' ) ) fileName.Delete( fileName.UpperBound() ); fileName.Trim(); if ( fileName.IsEmpty() ) throw ParseError( "Empty path specification", *i ); fileName = File::FullPath( fileName ); if ( fileName.HasWildcards() ) { if ( !allowWildcards ) throw ParseError( "Wildcards not allowed", fileName ); items = SearchDirectory( fileName, recursiveSearch ); } else items.Add( fileName ); } else if ( itemsAsViews ) { String viewId = *i; if ( !allowWildcards ) if ( viewId.HasWildcards() ) throw ParseError( "Wildcards not allowed", viewId ); size_type p = viewId.Find( "->" ); if ( p != String::notFound ) { if ( noPreviews ) throw ParseError( "Preview identifiers not allowed", viewId ); String imageId = viewId.Left( p ); if ( imageId.IsEmpty() ) throw ParseError( "Missing image identifier", viewId ); String previewId = viewId.Substring( p+2 ); if ( previewId.IsEmpty() ) throw ParseError( "Missing preview identifier", viewId ); FindPreviews( items, imageId, previewId ); } else { if ( viewId.HasWildcards() ) { Array<ImageWindow> W = ImageWindow::AllWindows(); for ( size_type i = 0; i < W.Length(); ++i ) { View v = W[i].MainView(); if ( String( v.Id() ).WildMatch( viewId ) ) AddView( items, v ); } } else { ImageWindow w = ImageWindow::WindowById( IsoString( viewId ) ); if ( w.IsNull() ) throw ParseError( "Image not found", viewId ); AddView( items, w.MainView() ); } } } else items.Add( *i ); Argument arg( *i, items ); arguments.Add( arg ); } } return arguments; }
bool ChannelCombinationInstance::ExecuteOn( View& view ) { ImageWindow sourceWindow[ 3 ]; ImageVariant sourceImage[ 3 ]; AutoViewLock lock( view ); ImageVariant image = view.Image(); if ( image.IsComplexSample() ) throw Error( "ChannelCombination cannot be executed on complex images." ); if ( image->ColorSpace() != ColorSpace::RGB ) throw Error( "ChannelCombination requires a RGB color image." ); Console().EnableAbort(); StandardStatus status; image->SetStatusCallback( &status ); String baseId; Rect r; int w0, h0; if ( view.IsPreview() ) { ImageWindow w = view.Window(); View mainView = w.MainView(); baseId = mainView.Id(); r = w.PreviewRect( view.Id() ); mainView.GetSize( w0, h0 ); } else { baseId = view.Id(); r = image->Bounds(); w0 = r.Width(); h0 = r.Height(); } int numberOfSources = 0; for ( int i = 0; i < 3; ++i ) if ( channelEnabled[i] ) { String id = channelId[i]; if ( id.IsEmpty() ) id = baseId + '_' + ColorSpaceId::ChannelId( colorSpace, i ); sourceWindow[i] = ImageWindow::WindowById( id ); if ( sourceWindow[i].IsNull() ) throw Error( "ChannelCombination: Source image not found: " + id ); sourceImage[i] = sourceWindow[i].MainView().Image(); if ( !sourceImage[i] ) throw Error( "ChannelCombination: Invalid source image: " + id ); if ( sourceImage[i]->IsColor() ) throw Error( "ChannelCombination: Invalid source color space: " + id ); if ( sourceImage[i]->Width() != w0 || sourceImage[i]->Height() != h0 ) throw Error( "ChannelCombination: Incompatible source image dimensions: " + id ); ++numberOfSources; } if ( numberOfSources == 0 ) return false; const char* what = ""; switch ( colorSpace ) { case ColorSpaceId::RGB: what = "RGB channels"; break; case ColorSpaceId::CIEXYZ: what = "normalized CIE XYZ components"; break; case ColorSpaceId::CIELab: what = "normalized CIE L*a*b* components"; break; case ColorSpaceId::CIELch: what = "normalized CIE L*c*h* components"; break; case ColorSpaceId::HSV: what = "normalized HSV components"; break; case ColorSpaceId::HSI: what = "normalized HSI components"; break; } image->Status().Initialize( String( "Combining " ) + what, image->NumberOfPixels() ); if ( image.IsFloatSample() ) switch ( image.BitsPerSample() ) { case 32: CombineChannels( static_cast<Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; case 64: CombineChannels( static_cast<DImage&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; } else switch ( image.BitsPerSample() ) { case 8: CombineChannels( static_cast<UInt8Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; case 16: CombineChannels( static_cast<UInt16Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; case 32: CombineChannels( static_cast<UInt32Image&>( *image ), colorSpace, baseId, r, sourceImage[0], sourceImage[1], sourceImage[2] ); break; } return true; }