home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-26 | 72.2 KB | 2,542 lines | [TEXT/PJMM] |
- program Image;
-
- {NIH Image is a public domain program for the Macintosh for acquiring, }
- {processing, analyzing, editing, printing, and animating 8-bit images.}
-
-
- {Version 1.58, 27 June 1995}
-
-
- {Developed using Metrowerks CodeWarrior CW6 PPC and 68K Pascal compilers.}
-
- {Author :}
- {Wayne Rasband}
- {National Institutes of Health}
-
- {Internet: wayne@helix.nih.gov}
- {Anonymous ftp: zippy.nimh.nih.gov}
- {Phone: 301-496-4957}
-
-
- uses
- Memory, QuickDraw, Packages, Menus, Events, Fonts, Scrap, ToolUtils, {}
- Resources, Errors, DiskInit, Palettes, Devices, SegLoad, Balloons, AppleEvents, timer, {}
- Globals, Utilities, Init, File1, File2, Analysis, Graphics, {}
- Edit, Filters, Camera, User, Macros1, Macros2, Stacks, Background, {,UMacroDef, UMacroRun}
- Lut, Projection, Plugins, Text, Math, Registration, {Profiler,} fft;
-
-
- {Turn off automatic toolbox initialization.}
- {$I-}
-
-
- {PROCEDURE MacsBug; inline $a9ff;}
-
-
- procedure UpdateOptionsMenu;
- var
- CheckIt: boolean;
- i: integer;
- begin
- with info^ do begin
- CheckItem(OptionsMenuH, GrayscaleItem, (LutMode = Grayscale) or (LutMode = CustomGrayscale));
- if LutMode <> PseudoColor then
- ColorTable := CustomTable;
- CheckItem(ColorTablesMenuH, SystemPaletteItem, ColorTable = AppleDefault);
- CheckItem(ColorTablesMenuH, Pseudo20Item, ColorTable = Pseudo20);
- CheckItem(ColorTablesMenuH, Pseudo32Item, ColorTable = Pseudo32);
- CheckItem(ColorTablesMenuH, RainbowItem, ColorTable = Rainbow);
- CheckItem(ColorTablesMenuH, Fire1Item, ColorTable = Fire1);
- CheckItem(ColorTablesMenuH, Fire2Item, ColorTable = Fire2);
- CheckItem(ColorTablesMenuH, IceItem, ColorTable = Ice);
- CheckItem(ColorTablesMenuH, GraysItem, ColorTable = Grays);
- CheckItem(ColorTablesMenuH, SpectrumItem, ColorTable = Spectrum);
- SetMenuItem(OptionsMenuH, ScaleToFitItem, info <> NoInfo);
- CheckIt := ScaleToFitWindow;
- CheckItem(OptionsMenuH, ScaleToFitItem, CheckIt);
- CheckItem(OptionsMenuH, ThresholdItem, Thresholding);
- CheckItem(OptionsMenuH, SliceItem, DensitySlicing);
- SetMenuItem(OptionsMenuH, PropagateItem, nPics > 1);
- end;
- end;
-
-
- procedure UpdateProcessMenu;
- var
- ShowItems: boolean;
- i: integer;
- str: str255;
- begin
- ShowItems := Info <> NoInfo;
- for i := SmoothItem to FilterItem do
- SetMenuItem(ProcessMenuH, i, ShowItems);
- with info^ do
- if (LutMode = GrayScale) or (LutMode = CustomGrayscale) or DensitySlicing then
- SetMenuItemText(ProcessMenuH, ApplyItem, 'Apply LUT')
- else
- SetMenuItemText(ProcessMenuH, ApplyItem, 'Convert to Grayscale');
- if CurrentWindow = TextKind then
- SetMenuItemText(ProcessMenuH, ConvolveItem, 'Convolve')
- else
- SetMenuItemText(ProcessMenuH, ConvolveItem, 'Convolve…');
- for i := BinaryItem to FixColorsItem do
- SetMenuItem(ProcessMenuH, i, ShowItems);
- NumToString(BinaryCount, str);
- str := concat('Set Count[', str, ']…');
- SetMenuItemText(BinaryMenuH, SetCountItem, str);
- NumToString(BinaryIterations, str);
- str := concat('Set Iterations[', str, ']…');
- SetMenuItemText(BinaryMenuH, IterationsItem, str);
- CheckItem(BackgroundMenuH, FasterItem, FasterBackgroundSubtraction);
- NumToString(BallRadius, str);
- str := concat('Set Radius[', str, ']…');
- SetMenuItemText(BackgroundMenuH, RadiusItem, str);
- end;
-
-
-
-
- procedure UpdateSpecialMenu;
- var
- ShowItems: boolean;
- begin
- ShowItems := Info <> NoInfo;
- SetMenuItem(SpecialMenuH, SaveBlankFieldItem, ShowItems);
- SetMenuItem(SpecialMenuH, PhotoModeItem, ShowItems);
- if CurrentWindow = TextKind then
- SetMenuItemText(SpecialMenuH, LoadMacrosItem, 'Load Macros from Window')
- else
- SetMenuItemText(SpecialMenuH, LoadMacrosItem, 'Load Macros…')
- end;
-
-
- procedure UpdateStacksMenu;
- var
- ShowItems: boolean;
- isStack: boolean;
- begin
- ShowItems := Info <> NoInfo;
- SetMenuItem(StacksMenuH, StackFromWindowsItem, nPics > 0);
- isStack := info^.StackInfo <> nil;
- SetMenuItem(StacksMenuH, WindowsFromStackItem, isStack);
- SetMenuItem(StacksMenuH, AddSliceItem, isStack);
- SetMenuItem(StacksMenuH, DeleteSliceItem, isStack);
- SetMenuItem(StacksMenuH, NextSliceItem, isStack);
- SetMenuItem(StacksMenuH, PreviousSliceItem, isStack);
- SetMenuItem(StacksMenuH, MakeMovieItem, ShowItems);
- SetMenuItem(StacksMenuH, CaptureFramesItem, ShowItems);
- SetMenuItem(StacksMenuH, AnimateItem, isStack);
- SetMenuItem(StacksMenuH, AverageSlicesItem, isStack);
- SetMenuItem(StacksMenuH, MakeMontageItem, isStack);
- SetMenuItem(StacksMenuH, RegisterItem, isStack);
- SetMenuItem(StacksMenuH, CaptureColorItem, ShowItems);
- SetMenuItem(StacksMenuH, RGBToColorItem, isStack);
- SetMenuItem(StacksMenuH, ColorToRGBItem, ShowItems and (not isStack));
- SetMenuItem(StacksMenuH, RGBToHSVItem, isStack);
- SetMenuItem(StacksMenuH, ProjectItem, isStack);
- SetMenuItem(StacksMenuH, ResliceItem, isStack);
- SetMenuItem(StacksMenuH, StackInfoItem, isStack);
- end;
-
-
- function AboutFilter (d: DialogPtr; var event: EventRecord; var ItemHit: integer): boolean;
- { simple filter proc for about box -- must be at top level! % }
- begin
- if (event.what in [MouseDown, KeyDown, AutoKey]) then begin
- AboutFilter := true;
- ItemHit := OK;
- end
- else begin
- AboutFilter := false;
- ItemHit := 0;
- end;
- end;
-
-
- procedure AboutUProc (d: DialogPtr; item: integer);
- { About box user proc -- must be at top level!}
- var
- s: str255;
- saveport: grafptr;
- VersInfo: str255;
- begin
- getport(saveport);
- setport(d);
- if (item = MemItem) then begin
- NumToString(FreeMem div 1024, s);
- s := concat(s, 'K free');
- DrawSItem(MemItem, Geneva, 9, d, s);
- end
- else if (item = VersItem) then begin
- RealToString(version / 100.0, 4, 2, VersInfo);
- VersInfo := concat('Version ', VersInfo);
- DrawSItem(VersItem, Geneva, 9, d, VersInfo);
- end;
- setport(saveport);
- end;
-
-
- procedure DoAbout;
- {About Box by David Powell}
- var
- i: integer;
- d: dialogptr;
- midscreen: point;
- r: rect;
- h: handle;
- itype: integer;
- begin
- if AboutBoxFilterProc=nil
- then AboutBoxFilterProc:=NewRoutineDescriptor(@AboutFilter, uppModalFilterProcInfo, GetCurrentISA);
- if AboutBoxUserProc=nil
- then AboutBoxUserProc:=NewRoutineDescriptor(@AboutUProc, uppUserItemProcInfo, GetCurrentISA);
- d := getnewdialog(AboutID, nil, pointer(-1));
- if (d <> nil) then begin
- SetPort(d);
- GetDialogItem(d, VersItem, itype, h, r);
- SetDialogItem(d, VersItem, itype, handle(AboutBoxUserProc), r);
- GetDialogItem(d, MemItem, itype, h, r);
- SetDialogItem(d, MemItem, itype, handle(AboutBoxUserProc), r);
- ShowWindow(d);
- repeat
- ModalDialog(AboutBoxFilterProc, i);
- until (i = OK);
- DisposeDialog(d);
- FlushEvents(EveryEvent, 0);
- end;
- end;
-
-
- procedure DoPreferences;
- const
- BufferSizeID = 4;
- ScaleConvolutionsID = 6;
- InvertValuesID = 7;
- InvertYID = 8;
- SwitchingID = 9;
- HighlightID = 10;
- CreatorID = 12;
- OscillatingID = 14;
- var
- mylog: DialogPtr;
- item, i: integer;
- SaveScaleC: boolean;
- SaveInvertValues, SaveInvertY, SaveMovies: boolean;
- SaveBufferSize: LongInt;
- SaveCreator: packed array[1..4] of char;
- tCreator:str255;
- SaveInfo:InfoPtr;
- begin
- InitCursor;
- if isInvertingFunction then
- InvertPixelValues:=true;
- SaveBufferSize := BufferSize;
- SaveInvertY := InvertYCoordinates;
- SaveScaleC := ScaleConvolutions;
- SaveCreator := TextCreator;
- SaveMovies := OscillatingMovies;
- mylog := GetNewDialog(6000, nil, pointer(-1));
- SetDNum(MyLog, BufferSizeID, BufferSize div 1024);
- SetDlogItem(mylog, ScaleConvolutionsID, ord(ScaleConvolutions));
- SetDlogItem(mylog, InvertYID, ord(InvertYCoordinates));
- SetDlogItem(mylog, SwitchingID, ord(SwitchLUTOnSuspend));
- SetDlogItem(mylog, HighlightID, ord(HighlightMode));
- SetDlogItem(mylog, OscillatingID, ord(OscillatingMovies));
- SaveInvertValues := InvertPixelValues;
- if InvertPixelValues then
- SetDlogItem(mylog, InvertValuesID, 1);
- tCreator:='1234';
- tCreator[1]:=TextCreator[1];
- tCreator[2]:=TextCreator[2];
- tCreator[3]:=TextCreator[3];
- tCreator[4]:=TextCreator[4];
- SetDString(mylog, CreatorID, tCreator);
- repeat
- ModalDialog(nil, item);
- if item = BufferSizeID then begin
- BufferSize := GetDNum(MyLog, BufferSizeID) * 1024;
- if BufferSize < 1 then begin
- beep;
- BufferSize := 1;
- SetDNum(MyLog, BufferSizeID, BufferSize);
- end;
- end;
- if item = ScaleConvolutionsID then begin
- ScaleConvolutions := not ScaleConvolutions;
- SetDlogItem(mylog, ScaleConvolutionsID, ord(ScaleConvolutions));
- end;
- if item = InvertValuesID then begin
- InvertPixelValues := not InvertPixelValues;
- SetDlogItem(mylog, InvertValuesID, ord(InvertPixelValues));
- end;
- if item = InvertYID then begin
- InvertYCoordinates := not InvertYCoordinates;
- SetDlogItem(mylog, InvertYID, ord(InvertYCoordinates));
- end;
- if item = SwitchingID then begin
- SwitchLUTOnSuspend := not SwitchLUTOnSuspend;
- SetDlogItem(mylog, SwitchingID, ord(SwitchLUTOnSuspend));
- end;
- if item = HighlightID then begin
- HighlightMode := not HighlightMode;
- SetDlogItem(mylog, HighlightID, ord(HighlightMode));
- LoadLUT(info^.ctable);
- end;
- if item = CreatorID then begin
- tCreator := GetDString(mylog, item);
- if length(tCreator)=4 then begin
- TextCreator[1]:=tCreator[1];
- TextCreator[2]:=tCreator[2];
- TextCreator[3]:=tCreator[3];
- TextCreator[4]:=tCreator[4];
- end;
- end;
- if item = OscillatingID then begin
- OscillatingMovies := not OscillatingMovies;
- SetDlogItem(mylog, OscillatingID, ord(OscillatingMovies));
- end;
- until (item = ok) or (item = cancel);
- DisposeDialog(mylog);
- if item = cancel then begin
- BufferSize := SaveBufferSize;
- ScaleConvolutions := SaveScaleC;
- InvertYCoordinates := SaveInvertY;
- OscillatingMovies := SaveMovies;
- if PasteControl <> nil then
- DrawPasteControl;
- TextCreator := SaveCreator;
- end
- else
- with info^ do begin
- if InvertPixelValues then begin
- SaveInfo:=info;
- for i := 1 to nPics do begin
- Info := pointer(WindowPeek(PicWindow[i])^.RefCon);
- if info^.fit=uncalibrated then
- InvertGrayLevels
- end; {for}
- info:=SaveInfo;
- end else if (InvertPixelValues = false) and SaveInvertValues then begin
- SaveInfo:=info;
- for i := 1 to nPics do begin
- Info := pointer(WindowPeek(PicWindow[i])^.RefCon);
- if isInvertingFunction then
- RemoveDensityCalibration;
- end; {for}
- info:=SaveInfo;
- end;
- end;
- if BufferSize <> SaveBufferSIze then begin
- PutError('You must quit and restart NIH Image before the Undo and Clipboard buffer size change will take effect.');
- SaveSettings;
- end;
- end;
-
-
- procedure UpdateWindowsMenu;
- var
- i, n: integer;
- begin
- for i := NextImageItem to TileImagesItem do
- SetMenuItem(WindowsMenuH, i, nPics > 1);
- for i := SelectToolsItem to SelectResultsItem do
- CheckItem(WindowsMenuH, i, false);
- SetMenuItem(WindowsMenuH, SelectHistogramItem, HistoWindow <> nil);
- SetMenuItem(WindowsMenuH, SelectPlotItem, PlotWindow <> nil);
- SetMenuItem(WindowsMenuH, SelectResultsItem, ResultsWindow <> nil);
- for i := 1 to nTextWindows do
- CheckItem(WindowsMenuH, WindowsMenuItems - 1 + i, false);
- for i := 1 to nPics do
- CheckItem(WindowsMenuH, WindowsMenuItems + nTextWindows + i, false);
- if PasteControl = nil then
- SetMenuItemText(WindowsMenuH, PasteControlItem, 'Show Paste Control')
- else
- SetMenuItemText(WindowsMenuH, PasteControlItem, 'Hide Paste Control');
- if CurrentKind < 0 then
- exit(UpdateWindowsMenu); {System Window}
- case CurrentKind of
- ToolKind:
- CheckItem(WindowsMenuH, SelectToolsItem, true);
- MapKind:
- CheckItem(WindowsMenuH, SelectGrayMapItem, true);
- LUTKind:
- CheckItem(WindowsMenuH, SelectLutItem, true);
- InfoKind:
- CheckItem(WindowsMenuH, SelectInfoItem, true);
- HistoKind:
- CheckItem(WindowsMenuH, SelectHistogramItem, true);
- ProfilePlotKind, CalibrationPLotKind:
- CheckItem(WindowsMenuH, SelectPlotItem, true);
- ResultsKind:
- CheckItem(WindowsMenuH, SelectResultsItem, true);
- TextKind: begin
- if TextInfo <> nil then
- CheckItem(WindowsMenuH, WindowsMenuItems - 1 + TextInfo^.WindowNum, true);
- end;
- PicKind:
- CheckItem(WindowsMenuH, WindowsMenuItems + nTextWindows + info^.PicNum, true);
- otherwise
- end;
- end;
-
-
-
-
- procedure CloseAll;
- FORWARD;
-
-
- procedure DoNew;
- const
- ImageID = 4;
- TextID = 5;
- WidthID = 6;
- HeightID = 7;
- TitleID = 8;
- var
- mylog: DialogPtr;
- item, i: integer;
- SaveWidth, SaveHeight: integer;
- SaveTitle: string[31];
- okay, OpenImage: boolean;
-
- procedure SetButtons;
- begin
- SetDlogItem(mylog, ImageID, ord(OpenImage));
- SetDlogItem(mylog, TextID, ord(not OpenImage));
- end;
-
- begin
- InitCursor;
- OpenImage := true;
- SaveWidth := NewPicWidth;
- SaveHeight := NewPicHeight;
- SaveTitle := NewTitle;
- mylog := GetNewDialog(180, nil, pointer(-1));
- SetButtons;
- SetDNum(MyLog, WidthID, NewPicWidth);
- SelectdialogItemText(MyLog, WidthID, 0, 32767);
- SetDNum(MyLog, HeightID, NewPicHeight);
- SetDString(MyLog, TitleID, NewTitle);
- repeat
- ModalDialog(nil, item);
- if item = ImageID then begin
- OpenImage := true;
- SetButtons;
- end;
- if item = TextID then begin
- OpenImage := false;
- SetButtons;
- end;
- if item = WidthID then begin
- NewPicWidth := GetDNum(MyLog, WidthID);
- if (NewPicWidth < 0) or (NewPicWidth > MaxPicSize) then begin
- NewPicWidth := SaveWidth;
- SetDNum(MyLog, WidthID, NewPicWidth);
- end;
- end;
- if item = HeightID then begin
- NewPicHeight := GetDNum(MyLog, HeightID);
- if (NewPicHeight < 0) or (NewPicHeight > MaxPicSize) then begin
- NewPicHeight := SaveHeight;
- SetDNum(MyLog, HeightID, NewPicHeight);
- end;
- end;
- until (item = ok) or (item = cancel);
- if item = ok then
- NewTitle := GetDString(MyLog, TitleID);
- DisposeDialog(mylog);
- if NewPicWidth < 32 then
- NewPicWidth := 32;
- if NewPicHeight < 16 then
- NewPicHeight := 16;
- if item = cancel then begin
- NewPicWidth := SaveWidth;
- NewPicHeight := SaveHeight;
- NewTitle := SaveTitle;
- exit(DoNew);
- end;
- if OpenImage then begin
- okay := NewPicWindow(NewTitle, NewPicWidth, NewPicHeight);
- if okay then
- if info^.PixMapSize > UndoBufSize then
- PutWarning;
- end
- else
- okay := MakeNewTextWindow(NewTitle, 500, 400);
- end;
-
-
- procedure DoMenuEvent (MenuChoice: LongInt);
- var
- MenuID, MenuItem, i, ignore: integer;
- name, str: str255;
- dna, RefNum: integer;
- ItemName: str255;
- FontName: str255;
- ok, isSelection: boolean;
- NewStyle: StyleItem;
- t: FateTable; {Only needed for MakeSkeleton}
- SaveBFInfo: InfoPtr;
- err: OSErr;
- begin
- MenuID := HiWrd(MenuChoice);
- MenuItem := LoWrd(MenuChoice);
- case MenuID of
-
- AppleMenu: begin
- if MenuItem = 1 then
- DoAbout
- else begin
- GetMenuItemText(GetMenuHandle(AppleMenu), MenuItem, name);
- ignore := OpenDeskAcc(name)
- end;
- end;
-
- FileMenu: begin
- StopDigitizing;
- isInsertionPoint := false;
- case MenuItem of
- NewItem:
- DoNew;
- OpenItem:
- ok := DoOpen('', 0);
- ImportItem:
- ok := ImportFile('', 0);
- {-}
- CloseItem:
- if OptionKeyWasDown and (CurrentWindow <> TextKInd) then
- CloseAll
- else
- DoClose;
- SaveItem:
- if OptionKeyWasDown and (info^.StackInfo = nil) and (CurrentWindow <> TextKind) then
- SaveAll
- else
- SaveFile;
- SaveAsItem:
- case CurrentWindow of
- TextKind:
- SaveTextAs;
- ResultsKind:
- Export('', 0);
- otherwise
- SaveAs('', 0);
- end;
- ExportItem:
- Export('', 0);
- {-}
- RecordPreferencesItem:
- SaveSettings;
- RevertItem:
- with info^ do
- if DataType = EightBits then
- RevertToSaved
- else
- RescaleToEightBits;
- DuplicateItem:
- ok := Duplicate('', false);
- GetInfoItem:
- GetInfo;
- {-}
- PageSetupItem:
- if OptionKeyDown then
- SetHalftone
- else
- DoPageSetup;
- PrintItem:
- Print(true);
- {-}
- QuitItem:
- finished := true;
- end;
- if OpeningRGB then begin
- ConvertRGBToEightBitColor(true);
- OpeningRGB := false;
- end;
- end;
-
- AcquireMenu:
- RunAcqPlugIn(MenuItem);
-
- ExportMenu:
- RunExportPlugIn(MenuItem);
-
- EditMenu: begin
- StopDigitizing;
- GetMenuItemText(GetMenuHandle(EditMenu), MenuItem, ItemName);
- if not SystemEdit(MenuItem - 1) then
- case MenuItem of
- UndoItem:
- DoUndo;
- {-}
- CutItem:
- DoCut;
- CopyItem:
- DoCopy;
- PasteItem:
- DoPaste;
- ClearItem:
- DoClear;
- {-}
- FillItem:
- if CurrentWindow = TextKind then
- DoFind
- else
- SetupOperation(FillItem);
- InvertItem, DrawBoundaryItem:
- SetupOperation(MenuItem);
- DrawScaleItem:
- DrawScale;
- {-}
- SelectAllItem:
- with info^ do
- if CurrentWindow = TextKind then
- SelectAllText
- else if RoiShowing and EqualRect(RoiRect, PicRect) then
- KillRoi
- else
- SelectAll(true);
- DeselectItem:
- KillRoi;
- ScaleAndRotateItem:
- ScaleAndRotate;
- {-}
- RotateLeftItem:
- Rotate(RotateLeft);
- RotateRightItem:
- Rotate(RotateRight);
- FlipVerticalItem:
- FlipOrRotate(FlipVertical);
- FlipHorizontalItem:
- FlipOrRotate(FlipHorizontal);
- {-}
- UnzoomItem:
- Unzoom;
- ShowClipboardItem:
- ShowClipboard;
- end;
- end;
-
- OptionsMenu: begin
- case MenuItem of
- GrayscaleItem:
- ResetGrayMap;
- LutOptionsItem:
- DoLutOptions;
- {-}
- PreferencesItem:
- DoPreferences;
- PlotOptionsItem:
- DoProfilePlotOptions;
- ScaleToFitItem:
- ScaleToFit;
- ThresholdItem: begin
- if DensitySlicing then
- DisableDensitySlice;
- if Info^.Thresholding then
- DisableThresholding
- else begin
- SetupLutUndo;
- AutoThreshold;
- end;
- end;
- SliceItem:
- if DensitySlicing then
- DisableDensitySlice
- else begin
- if info^.thresholding then
- DisableThresholding;
- EnableDensitySlice;
- end;
- end;
- end;
-
- ColorTablesMenu:
- SwitchColorTables(MenuItem, true);
-
- FontMenu: begin
- GetMenuItemText(FontMenuH, MenuItem, FontName);
- GetFNum(FontName, CurrentFontID);
- DisplayText(true);
- if CurrentWindow = TextKind then
- ChangeFontOrSize;
- end;
-
- SizeMenu: begin
- case MenuItem of
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12:
- CurrentSize := GetFontSize(MenuItem);
- end;
- DisplayText(true);
- if IsInsertionPoint then
- UpdatePicWindow;
- if CurrentWindow = TextKind then
- ChangeFontOrSize;
- end;
-
- StyleMenu: begin
- case MenuItem of
- 1:
- CurrentStyle := [];
- 2, 3, 4, 5, 6: begin
- case MenuItem of
- TxBold:
- NewStyle := Bold;
- TxItalic:
- NewStyle := Italic;
- TxUnderLine:
- NewStyle := Underline;
- TxOutLine:
- NewStyle := Outline;
- TxShadow:
- NewStyle := Shadow;
- end;
- if NewStyle in CurrentStyle then
- CurrentStyle := CurrentStyle - [NewStyle]
- else
- CurrentStyle := CurrentStyle + [NewStyle];
- end;
- LeftItem:
- TextJust := teJustLeft;
- CenterItem:
- TextJust := teJustCenter;
- RightItem:
- TextJust := teJustRight;
- NoBackgroundItem:
- TextBack := NoBack;
- WithBackgroundItem:
- TextBack := WithBack;
- end; {case}
- DisplayText(true);
- end;
-
- PropagateMenu:
- DoPropagate(MenuItem);
-
- ProcessMenu: begin
- StopDigitizing;
- SetupUndo;
- case MenuItem of
- SmoothItem:
- if OptionKeyDown then
- Filter(UnweightedAvg, 0, t)
- else
- Filter(WeightedAvg, 0, t);
- SharpenItem:
- Filter(fsharpen, 0, t);
- ShadowItem:
- DoShadowFilter;
- FindEdgesItem:
- Filter(FindEdges, 0, t);
- RankItem:
- DoRankFilter;
- DitherItem:
- Filter(Dither, 0, t);
- ConvolveItem:
- if CurrentWindow = TextKind then
- ConvolveUsingText
- else
- Convolve('', 0);
- {-}
- ImageMathItem:
- DoImageMath;
- ApplyItem:
- if CheckCalibration then
- ApplyLookupTable;
- EnhanceItem:
- EnhanceContrast;
- EqualizeItem:
- EqualizeHistogram;
- FixColorsItem:
- if not isBinaryImage then
- FixColors;
- end;
- end;
-
- FilterMenu:
- RunFilterPlugin(menuItem);
-
- BinaryMenu:
- case MenuItem of
- MakeBinaryItem:
- MakeBinary;
- ErosionItem:
- DoErosion;
- DilationItem:
- DoDilation;
- OpeningItem:
- DoOpening;
- ClosingItem:
- DoClosing;
- SetCountItem:
- SetBinaryCount;
- IterationsItem:
- SetIterations;
- OutlineItem:
- filter(OutlineFilter, 0, t);
- SkeletonizeItem:
- MakeSkeleton;
- end;
-
- ArithmeticMenu:
- DoArithmetic(MenuItem, 0);
-
- fftMenu:
- case MenuItem of
- ForewardFFTItem: doFFT(ForewardFFT);
- InverseFFTItem: doFFT(InverseFFTWithMask);
- RedisplayItem: RedisplayPowerSpectrum;
- SwapItem: doSwapQuadrants;
- end;
-
- BackgroundMenu:
- DoBackgroundMenuEvent(MenuItem);
-
- AnalyzeMenu: begin
- if MenuItem <> HistogramItem then
- StopDigitizing;
- SetupUndo;
- case MenuItem of
- MeasureItem:
- Measure;
- AnalyzeItem:
- AnalyzeParticles;
- ShowItem:
- ShowResults;
- OptionsItem:
- DoMeasurementOptions;
- HistogramItem:
- DoHistogram;
- PlotItem:
- PlotDensityProfile;
- PlotSurfaceItem:
- PlotSurface;
- {-}
- SetScaleItem:
- SetScale;
- CalibrateItem:
- Calibrate;
- RedoItem:
- RedoMeasurement;
- DeleteItem:
- DeleteMeasurement;
- ResetItem:
- ResetCounter;
- RestoreItem:
- RestoreRoi;
- MarkItem:
- MarkSelection(mCount);
- end;
- end;
-
- SpecialMenu: begin
- case MenuItem of
- StartItem:
- StartDigitizing;
- AverageItem:
- AverageFrames;
- SaveBlankFieldItem: begin
- SaveBFInfo := BlankFieldInfo;
- BlankFieldInfo := nil; {Prevents shading correction.}
- StopDigitizing;
- BlankFieldInfo := SaveBFInfo;
- SaveBlankField;
- end;
- VideoControlItem:
- ShowVideoDialog;
- PhotoModeItem:
- PhotoMode;
- LoadMacrosItem: begin
- LoadMacros;
- {$ifc not PowerPC}
- UnloadSeg(@LoadMacros);
- {$endc}
- end;
- otherwise
- if MenuItem >= FirstMacroItem then
- RunMacro(MenuItem - FirstMacroItem + 1);
- {if MenuItem >= FirstMacroItem then begin
- if ProfilerInit(collectDetailed, bestTimeBase, 50, 25) = noErr then begin
- RunMacro(MenuItem - FirstMacroItem + 1);
- err := ProfilerDump('Image.prof');
- ProfilerTerm;
- end;
- end;}
- end;
- end;
-
- StacksMenu: begin
- StopDigitizing;
- case MenuItem of
- StackFromWindowsItem:
- MakeStack;
- WindowsFromStackItem:
- MakeWindowsFromStack;
- AddSliceItem:
- ok := AddSlice(true);
- DeleteSliceItem:
- DeleteSlice;
- NextSliceItem, PreviousSliceItem:
- ShowNextSlice(MenuItem);
- MakeMovieItem:
- MakeMovie(true);
- CaptureFramesItem:
- CaptureFrames;
- AnimateItem:
- Animate;
- AverageSlicesItem:
- AverageSlices;
- MakeMontageItem:
- MakeMontage;
- CaptureColorItem:
- CaptureColor;
- RGBToColorItem:
- ConvertRGBToEightBitColor(false);
- ColorToRGBItem:
- ConvertEightBitColorToRGB;
- RGBToHSVItem:
- ConvertRGBToHSV;
- RegisterItem:
- DoRegister;
- ProjectItem:
- Project;
- ResliceItem:
- Reslice;
- StackInfoItem:
- DoStackInfo;
- otherwise
- beep
- end;
- end;
-
- WindowsMenu: begin
- if MenuItem <> PasteControlItem then
- StopDigitizing;
- case MenuItem of
- NextImageItem:
- ShowNextImage;
- CascadeImagesItem:
- CascadeImages;
- TileImagesItem:
- TileImages;
- PasteControlItem:
- if PasteControl = nil then
- ShowPasteControl
- else
- ignore := CloseAWindow(PasteControl);
- {-}
- SelectToolsItem:
- SelectWindow(ToolWindow);
- SelectGrayMapItem:
- SelectWindow(MapWindow);
- SelectLutItem:
- SelectWindow(LUTWindow);
- SelectInfoItem:
- SelectWindow(InfoWindow);
- SelectHistogramItem:
- if HistoWindow <> nil then
- SelectWindow(HistoWindow);
- SelectPlotItem:
- if PlotWindow <> nil then
- SelectWindow(PlotWindow);
- SelectResultsItem:
- if ResultsWindow <> nil then
- SelectWindow(ResultsWindow);
- {-}
- otherwise
- if MenuItem <= (WindowsMenuItems - 1 + nTextWindows) then
- SelectWindow(TextWindow[MenuItem - (WindowsMenuItems - 1)])
- else
- SelectWindow(PicWindow[MenuItem - (WindowsMenuItems + nTextWindows)]);
- end;
- end;
-
- UserMenu:
- DoUserMenuEvent(MenuItem);
- otherwise
- end;
- HiliteMenu(0);
- RoiUpdateTime := 0;
- end;
-
-
- procedure DoFreehand;
- var
- finish: point;
- event: EventRecord;
- wright, wbottom: integer;
- b: boolean;
- begin
- SetPort(info^.wptr);
- PenPat(AntPattern[PatIndex]);
- PenSize(1, 1);
- with info^.wptr^.PortRect do begin
- wright := right;
- wbottom := bottom;
- end;
- while Button do begin
- GetMouse(finish);
- with finish do begin
- if h < 0 then
- h := 0;
- if v < 0 then
- v := 0;
- if h > wright then
- h := wright;
- if v > wbottom then
- v := wbottom;
- if (xCoordinates^[nCoordinates] <> h) or (yCoordinates^[nCoordinates] <> v) then begin
- if nCoordinates < MaxCoordinates then
- nCoordinates := nCoordinates + 1
- else
- beep;
- LineTo(h, v);
- xCoordinates^[nCoordinates] := h;
- yCoordinates^[nCoordinates] := v;
- wait(1);
- end; {if mouse has moved}
- end; {with}
- end; {while Button}
- end;
-
-
- procedure DoPolygon (start: point);
- var
- Finish, OldFinish: point;
- finished, DoubleClick, done: boolean;
- ticks, MouseUpTime, LastMouseUpTime: LongInt;
- wright, wbottom: integer;
- StartRect: rect;
- MouseDown, MouseUpEvent: boolean;
- begin
- DrawLabels('DX:', 'DY:', 'Length:');
- SetPort(info^.wptr);
- PenMode(PatXor);
- PenSize(1, 1);
- if CurrentTool = PolygonTool then begin
- Pt2Rect(Start, Start, StartRect);
- InsetRect(StartRect, -4, -4);
- FrameRect(StartRect);
- end
- else
- SetRect(StartRect, 0, 0, 0, 0);
- finish := start;
- finished := false;
- with info^.wptr^.PortRect do begin
- wright := right;
- wbottom := bottom;
- end;
- MouseUpTime := 0;
- done := false;
- MouseUpEvent := false;
- MouseDown := button;
- repeat
- ShowDxDy(0, 0);
- repeat
- OldFinish := finish;
- GetMouse(finish);
- with finish do begin