unit Initialization; interface uses QuickDraw, Palettes, PrintTraps, Slots, globals, Utilities, Graphics; procedure Init; procedure AllocateBuffers; procedure AllocateArrays; procedure SetupMenus; procedure GetSettings; implementation procedure MakeCursors; {Generates tool cursors from tool font. Thanks to Borland for "OffScreenDrawing"} {and "MysteryCursor" examples in "Turbo Pascal Tutor".} var TempPort: GrafPort; tPort: GrafPtr; aRect, bRect: Rect; OffScreenBitMap: BitMap; BlankMask: Bits16; tool: ToolType; i: integer; TempCurH: CursHandle; begin GetPort(tPort); OpenPort(@TempPort); with OffScreenBitMap do begin baseAddr := NewPtr(2 * 16); { allocate a bit image for 16x16 cursor} rowBytes := 2; { 2 bytes per row} SetRect(bounds, 0, 0, 16, 16); { define usable area and coordinate systme } end; SetPortBits(OffscreenBitMap); for i := 0 to 15 do BlankMask[i] := 0; TextFont(ToolFont); TextSize(12); for tool := FirstTool to LastTool do begin EraseRect(OffscreenBitMap.bounds); MoveTo(0, 0); DrawChar(ToolCursorChar[tool]); with ToolCursor[tool] do begin BlockMove(OffscreenBitMap.BaseAddr, @data, 32); hotspot.h := 8; hotspot.v := 8; mask := BlankMask; end; end; ClosePort(@TempPort); SetPort(tPort); TempCurH := GetCursor(PickerCursorID); if TempCurH <> nil then begin PickerCursor := TempCurH^^; ToolCursor[PickerTool] := PickerCursor; ReleaseResource(handle(TempCurH)); end; TempCurH := GetCursor(CrossCursorPlusID); if TempCurH <> nil then begin CrossPlusCursor := TempCurH^^; ReleaseResource(handle(TempCurH)); end; TempCurH := GetCursor(CrossCursorMinusID); if TempCurH <> nil then begin CrossMinusCursor := TempCurH^^; ReleaseResource(handle(TempCurH)); end; TempCurH := GetCursor(CrossCursorID); if TempCurH <> nil then begin ToolCursor[SelectionTool] := TempCurH^^; ToolCursor[FreehandTool] := TempCurH^^; ToolCursor[PolygonTool] := TempCurH^^; ToolCursor[ruler] := TempCurH^^; ToolCursor[PlotTool] := TempCurH^^; ToolCursor[OvalSelectionTool] := TempCurH^^; ToolCursor[LineTool] := TempCurH^^; ToolCursor[AngleTool] := TempCurH^^; ToolCursor[CrossHairTool] := TempCurH^^; ReleaseResource(handle(TempCurH)); end; TempCurH := GetCursor(LUTCursorID); if TempCurH <> nil then begin LUTCursor := TempCurH^^; ReleaseResource(handle(TempCurH)); end; TempCurH := GetCursor(gmCursorID); if TempCurH <> nil then begin gmCursor := TempCurH^^; ReleaseResource(handle(TempCurH)); end; TempCurH := GetCursor(GrabberCursorID); if TempCurH <> nil then begin ToolCursor[Grabber] := TempCurH^^; ReleaseResource(handle(TempCurH)); end; TempCurH := GetCursor(PencilCursorID); if TempCurH <> nil then begin ToolCursor[Pencil] := TempCurH^^; ReleaseResource(handle(TempCurH)); end; TempCurH := GetCursor(GlassCursorPlusID); if TempCurH <> nil then begin ToolCursor[MagnifyingGlass] := TempCurH^^; ReleaseResource(handle(TempCurH)); end; TempCurH := GetCursor(GlassCursorMinusID); if TempCurH <> nil then begin GlassMinusCursor := TempCurH^^; ReleaseResource(handle(TempCurH)); end; TempCurH := GetCursor(BucketCursorID); if TempCurH <> nil then begin ToolCursor[PaintBucket] := TempCurH^^; ReleaseResource(handle(TempCurH)); end; TempCurH := GetCursor(WandCursorID); if TempCurH <> nil then begin ToolCursor[Wand] := TempCurH^^; ReleaseResource(handle(TempCurH)); end; TempCurH := GetCursor(WatchCursor); if TempCurH <> nil then begin watch := TempCurH^^; ReleaseResource(handle(TempCurH)); end; end; procedure InitTools; var ToolTop, LinesTop, i: integer; Tool: ToolType; begin FirstTool := MagnifyingGlass; LastTool := CrossHairTool; CurrentTool := SelectionTool; isSelectionTool := true; PreviousTool := CurrentTool; ToolTop := 0; for tool := FirstTool to LastTool do with ToolRect[tool] do begin top := ToolTop; bottom := top + tmiddle; if odd(ord(tool) + 1) then left := 0 else begin left := tmiddle; ToolTop := ToolTop + tmiddle; end; right := left + tmiddle; end; ToolChar[Pencil] := chr(76); ToolChar[SelectionTool] := chr(70); ToolChar[MagnifyingGlass] := chr(66); ToolChar[TextTool] := chr(72); ToolChar[Grabber] := chr(71); ToolChar[Brush] := chr(75); ToolChar[ruler] := chr(112); ToolChar[PaintBucket] := chr(104); ToolChar[AirBrushTool] := chr(74); ToolChar[PlotTool] := chr(94); ToolChar[Wand] := chr(101); ToolChar[Eraser] := chr(78); ToolChar[FreehandTool] := chr(69); ToolChar[PolygonTool] := chr(87); ToolChar[OvalSelectionTool] := chr(83); ToolChar[PickerTool] := chr(77); ToolChar[LineTool] := chr(97); ToolChar[LUTTool] := chr(86); ToolChar[AngleTool] := chr(106); ToolChar[CrossHairTool] := chr(113); ToolCursorChar[SelectionTool] := chr(89); ToolCursorChar[Pencil] := chr(76); ToolCursorChar[MagnifyingGlass] := chr(66); ToolCursorChar[TextTool] := chr(110); ToolCursorChar[Grabber] := chr(71); ToolCursorChar[brush] := chr(103); ToolCursorChar[ruler] := chr(89); ToolCursorChar[PaintBucket] := chr(89); ToolCursorChar[LineTool] := chr(89); ToolCursorChar[LUTTool] := chr(86); ToolCursorChar[FreehandTool] := chr(89); ToolCursorChar[AirbrushTool] := chr(100); ToolCursorChar[PolygonTool] := chr(89); ToolCursorChar[PlotTool] := chr(89); ToolCursorChar[Wand] := chr(100); ToolCursorChar[Eraser] := chr(68); ToolCursorChar[OvalSelectionTool] := chr(89); ToolCursorChar[PickerTool] := chr(77); ToolCursorChar[AngleTool] := chr(89); ToolCursorChar[CrossHairTool] := chr(89); ToolTime := 0; LutTime := 0; StartOfLines := ToolRect[LastTool].bottom - 1; LinesTop := StartOfLines + 10; for i := 1 to nLineTypes do with lines[i] do begin left := LinesLeft; top := LinesTop; right := LinesRight; case i of 1, 2, 3, 4: bottom := top + i; 5: bottom := top + 6; 6: bottom := top + 8 end; LinesTop := bottom + 4; end; LineWidth := 1; LineIndex := 1; with CheckRect do begin left := 0; top := StartOfLines; right := LinesLeft; bottom := theight; end; end; procedure AllocateBuffers; var tPort: GrafPtr; err: OSErr; BufSizeStr: str255; atemp: integer; begin GetPort(tPort); NumToString(BufferSize div 1024, BufSizeStr); BigBufSize := BufferSize * 2; if FreeMem > (BigBufSize + 300000) then BigBuf := NewPtr(BigBufSize) else BigBuf := nil; if BigBuf = nil then BigBufSize := 0; if BigBuf <> nil then UndoBuf := BigBuf else begin if FreeMem > (BufferSize + 200000) then UndoBuf := NewPtr(BufferSize) else UndoBuf := nil; end; if UndoBuf <> nil then UndoBufSize := BufferSize else begin PutMessage(concat('There is not enough memory available to allocate the ', BufSizeStr, 'K Undo buffer. Many operations may fail or be Undoable.')); UndoBufSize := 0; end; if BigBuf <> nil then ClipBuf := ptr(ord4(BigBuf) + BufferSize) else begin if FreeMem > (BufferSize + 300000) then ClipBuf := NewPtr(BufferSize) else ClipBuf := nil; end; if UndoBuf <> nil then begin UndoInfoRec := NoInfo^; UndoInfo := @UndoInfoRec; with UndoInfo^ do begin roiRgn := NewRgn; PicBaseAddr := UndoBuf; new(osPort); OpenCPort(osPort); osPort^.portPixMap^^.BaseAddr := PicBaseAddr; SetPalette(WindowPtr(osPort), ExplicitPalette, false); end; end; if ClipBuf <> nil then begin ClipBufSize := BufferSize; ClipBufInfoRec := NoInfo^; ClipBufInfo := @ClipBufInfoRec; with ClipBufInfo^ do begin roiRgn := NewRgn; PicBaseAddr := ClipBuf; new(osPort); OpenCPort(osPort); osPort^.portPixMap^^.BaseAddr := PicBaseAddr; BytesPerRow := 0; SetPalette(WindowPtr(osPort), ExplicitPalette, false); end; end else begin PutMessage(concat('There is not enough memory available to allocate the ', BufSizeStr, 'K Clipboard Buffer. Many operations, including Copy and Paste, may fail.')); ClipBufSize := 0; end; SetPort(tPort); end; procedure AllocateArrays; var nItems: LongInt; procedure Abort; begin PutMessage('Not enough memory available to allocate the arrays used to store measurements.'); ExitToShell; end; begin nItems := MaxRegions + 1; mean := meanPtr(NewPtr(nItems * SizeOf(real))); if mean = nil then abort; sd := sdPtr(NewPtr(nItems * SizeOf(real))); if sd = nil then abort; PixelCount := PixelCountPtr(NewPtr(nItems * SizeOf(LongInt))); if PixelCount = nil then abort; mArea := AreaPtr(NewPtr(nItems * SizeOf(real))); if mArea = nil then abort; mode := modePtr(NewPtr(nItems * SizeOf(real))); if mode = nil then abort; IntegratedDensity := IntegratedDensityPtr(NewPtr(nItems * SizeOf(real))); if IntegratedDensity = nil then abort; idBackground := idBackgroundPtr(NewPtr(nItems * SizeOf(real))); if idBackground = nil then abort; xcenter := xcenterPtr(NewPtr(nItems * SizeOf(real))); if xcenter = nil then abort; ycenter := ycenterPtr(NewPtr(nItems * SizeOf(real))); if ycenter = nil then abort; MajorAxis := MajorAxisPtr(NewPtr(nItems * SizeOf(real))); if MajorAxis = nil then abort; MinorAxis := MinorAxisPtr(NewPtr(nItems * SizeOf(real))); if MinorAxis = nil then abort; orientation := orientationPtr(NewPtr(nItems * SizeOf(real))); if orientation = nil then abort; mMin := MinPtr(NewPtr(nItems * SizeOf(real))); if mMin = nil then abort; mMax := MaxPtr(NewPtr(nItems * SizeOf(real))); if mMax = nil then abort; plength := plengthPtr(NewPtr(nItems * SizeOf(real))); if plength = nil then abort; ClearResults(0); if FreeMem < 100000 then Abort; end; function OpenWD (vRefNum: integer; dirID: LongInt; procID: LongInt; var wdRefNum: integer): OSErr; {Converts a volume reference number and directory ID into a working directory reference number. See TN 218.} var theWD: WDPBRec; err: OSErr; begin with theWD do begin ioCompletion := nil; ioNamePtr := nil; ioVRefNum := VRefNum; ioWDProcID := 0; ioWDDirID := DirID; err := PBOpenWD(@theWD, false); if err = NoErr then wdRefNum := ioVRefNum; OpenWD := err; end; {with} end; procedure GetKernelsWorkingDir; var wdRefNum: integer; err: OSErr; begin with settings do if sKernelsVRefNum <> 0 then begin err := OpenWD(sKernelsVRefNum, sKernelsDirID, 0, wdRefNum); if err = NoErr then KernelsRefNum := wdRefNum; {ShowMessage(concat('KernelsRefNum=', long2str(KernelsRefNum), cr, 'vRefNum=', long2str(sKernelsVRefNum), cr, 'DirID=', long2str(sKernelsDirID)));} end; end; procedure GetDefaultWorkingDir; var wdRefNum: integer; err: OSErr; begin with settings do if sDefaultVRefNum <> 0 then begin err := OpenWD(sDefaultVRefNum, sDefaultDirID, 0, wdRefNum); if err = NoErr then DefaultRefNum := wdRefNum; end; end; procedure GetSettings; var err: OSErr; f: integer; ByteCount: LongInt; ok: boolean; begin err := fsopen(PrefsName, SystemRefNum, f); if err <> NoErr then exit(GetSettings); err := GetEof(f, ByteCount); if ByteCount > SizeOf(settings) then ByteCount := SizeOf(settings); err := fsRead(f, ByteCount, @settings); if err <> NoErr then exit(GetSettings); err := fsClose(f); with settings, info^ do begin if sID <> 'IMAG' then begin PutMessage('The Image Prefs file in the System folder is corrupted. Please delete it and try again.'); exitToShell; end; if (ForegroundIndex <> sForegroundIndex) or (BackgroundIndex <> sBackgroundIndex) then begin SetForegroundColor(sForegroundIndex); SetBackgroundColor(sBackgroundIndex); end; BrushHeight := sBrushHeight; BrushWidth := sBrushWidth; AirbrushDiameter := sAirbrushDiameter; AirbrushRadius := AirbrushDiameter div 2; AirbrushRadius2 := AirbrushRadius * AirbrushRadius; LUTMode := sLUTMode; ColorStart := sColorStart; ColorWidth := sColorWidth; CurrentFontID := sCurrentFontID; CurrentStyle := SCurrentStyle; CurrentSize := sCurrentSize; TextJust := sTextJust; TextBack := sTextBack; nExtraColors := sNExtraColors; ExtraColors := sExtraColors; InvertVideo := sInvertVideo; Measurements := sMeasurements; InvertPlots := sInvertPlots; AutoScalePlots := sAutoScalePlots; LinePlot := sLinePlot; DrawPlotLabels := sDrawPlotLabels; ProfilePlotMin := sProfilePlotMin; ProfilePlotMax := sProfilePlotMax; FixedSizePlot := sFixedSizePlot; ProfilePlotWidth := sProfilePlotWidth; ProfilePlotHeight := sProfilePlotHeight; FramesToAverage := sFramesToAverage; NewPicWidth := sNewPicWidth; NewPicHeight := sNewPicHeight; BufferSize := sBufferSize; MaxScionWidth := sMaxScionWidth; ThresholdToForeground := sThresholdToForeground; NonThresholdToBackground := sNonThresholdToBackground; VideoChannel := sVideoChannel; WhatToImport := sWhatToImport; ImportCustomWidth := sImportCustomWidth; ImportCustomHeight := sImportCustomHeight; ImportCustomOffset := sImportCustomOffset; WandAutoMeasure := sWandAutoMeasure; WandAdjustAreas := sWandAdjustAreas; BinaryIterations := sBinaryIterations; ScaleArithmetic := sScaleArithmetic; UseZeroForBlack := sUseZeroForBlack; InvertYCoordinates := sInvertYCoordinates; FieldWidth := sFieldWidth; precision := sPrecision; MinParticleSize := sMinParticleSize; MaxParticleSize := sMaxParticleSize; IgnoreParticlesTouchingEdge := sIgnoreParticlesTouchingEdge; LabelParticles := sLabelParticles; OutlineParticles := sOutlineParticles; IncludeHoles := sIncludeHoles; ShowReversingMovies := sShowReversingMovies; UsingLaserWriter6 := sUsingLaserWriter6; MaxRegions := sMaxRegions; ImportCustomDepth := sImportCustomDepth; ImportSwapBytes := sImportSwapBytes; ImportCalibrate := sImportCalibrate; ImportAutoscale := sImportAutoscale; ImportMin := sImportMin; ImportMax := sImportMax; ShowHeadings := sShowHeadings; GetKernelsWorkingDir; GetDefaultWorkingDir; UpdateFitEllipse; end; {with settings, info^} case info^.LUTMode of PseudoColor32, custom, CustomGrayscale: UpdateColors; AppleDefault: ok := LoadCLUTResource(AppleDefaultCLUT); Spectrum: Load256ColorCLUT; end; if nExtraColors > 0 then RedrawLUTWindow; if UseZeroForBlack then InvertGrayLevels; UpdateTextMenu; end; procedure MakePatterns; {Creates the patterns used to create the "marching ants". Thanks to} { Seth Snyder on CompuServe for the example.} var i, j: Integer; begin j := 0; for i := 0 to 7 do begin pat[i][(j + 0) mod 8] := $1F; pat[i][(j + 1) mod 8] := $3E; pat[i][(j + 2) mod 8] := $7C; pat[i][(j + 3) mod 8] := $F8; pat[i][(j + 4) mod 8] := $F1; pat[i][(j + 5) mod 8] := $E3; pat[i][(j + 6) mod 8] := $C7; pat[i][(j + 7) mod 8] := $8F; j := j + 1; end; PatIndex := 0; end; procedure InitExtraColors; var i, j, ctop, cbottom, entry: integer; tRect: rect; begin with ExtraColors[1] do begin red := -1; green := 0; blue := 0; end; with ExtraColors[2] do begin red := 0; green := -1; blue := 0; end; with ExtraColors[3] do begin red := 0; green := 0; blue := -1; end; with ExtraColors[4] do begin red := -1; green := -1; blue := 0; end; with ExtraColors[5] do begin red := 0; green := -1; blue := -1; end; with ExtraColors[6] do begin red := -1; green := 0; blue := -1; end; ctop := 256; cbottom := ctop + ExtraColorsHeight; for i := 1 to MaxExtraPlus2 do begin SetRect(tRect, 0, ctop, cwidth, cbottom); ExtraColorsRect[i] := tRect; ctop := ctop + ExtraColorsHeight; cbottom := cbottom + ExtraColorsHeight; end; ExtraColorsEntry[1] := WhiteIndex; ExtraColorsEntry[2] := BlackIndex; entry := FirstExtraColorsEntry; j := 3; for i := 1 to MaxExtraColors do begin ExtraColorsEntry[j] := entry; j := j + 1; Entry := Entry + 1; end; end; function GetSlotBase (id: integer): LongInt; {Returns the slot base address of the NuBus card with the specified id. The address} {returned is in the form $Fss00000, which is valid in both 24 and 32-bit modes.} {Returns 0 if a card with the given id is not found.} type SPRAMRecord = packed record BoardId: integer; VenderUse: packed array[1..6] of SignedByte; end; var SlotBlock: SpBlock; sparm: SPRAMRecord; SparmAddr: LongInt; i: integer; err: OSErr; begin with SlotBlock do begin SparmAddr := LongInt(@sparm); spResult := SparmAddr; for i := 9 to 15 do begin spSlot := i; err := sReadPRAMRec(@SlotBlock); if sparm.BoardID = id then begin GetSlotBase := bor($F0000000, spSlot * $100000 + spSlot * $1000000); exit(GetSlotBase) end; end; GetSlotBase := 0; end; end; procedure SetupQCPort; {So we can use CopyBits, this routine sets up a color graf port that} {uses the memory on the QuickCapture board as the PixMap.} const baseAddr32 = 4; var tPort: GrafPtr; trect: rect; begin GetPort(tPort); new(qcPort); OpenCPort(qcPort); SetRect(trect, 0, 0, qcwidth, qcheight); with qcPort^ do begin with PortPixMap^^ do begin BaseAddr := ptr(DTSlotBase); bounds := trect; RowBytes := BitOr(qcRowBytes, $8000); pmVersion := baseAddr32; {Needed for 8*24 GC card. See TN 275.} end; PortRect := trect; RectRgn(visRgn, trect); end; SetPort(tPort); SetPalette(WindowPtr(qcPort), ExplicitPalette, false); end; procedure LookForFrameGrabbers; const ControlRegOffset = $80000; ChannelRegOffset = $80004; DT2255id = $11A; Scion1000id = $14B; Scion1200id = $222; PalBufferSize = 393216; {768 x 512} var err: OSErr; tPort: GrafPtr; SlotBase: LongInt; OptionKeyIsDown: boolean; begin OptionKeyIsDown := OptionKeyDown; FrameGrabber := NoFrameGrabber; qcPort := nil; SlotBase := GetSlotBase(Scion1000id); if (SlotBase <> 0) and not OptionKeyIsDown then begin FrameGrabber := Scion; ScionSlotBase := SlotBase; exit(LookForFrameGrabbers); end; SlotBase := GetSlotBase(Scion1200id); if (SlotBase <> 0) and not OptionKeyIsDown then begin FrameGrabber := Scion; ScionSlotBase := SlotBase; exit(LookForFrameGrabbers); end; SlotBase := GetSlotBase(DT2255id); if SlotBase <> 0 then begin FrameGrabber := QuickCapture; DTSlotBase := SlotBase end; qcWidth := 640; qcHeight := 480; if FrameGrabber = QuickCapture then begin ControlReg := ptr(DTSlotBase + ControlRegOffset); ChannelReg := ptr(DTSlotBase + ControlRegOffset + 4); if band(ChannelReg^, 8) = 8 then begin {Check for 50Hz(PAL) card} qcWidth := 768; qcHeight := 512; if BufferSize < PalBufferSize then BufferSize := PalBufferSize; end; SetupQCPort; ResetQuickCapture; end; end; procedure MakeTiffDirectory; var i: integer; begin with TiffInfo do begin with header do begin ByteOrder := 'MM'; Version := 42; FirstIFDOffset := 8; end; nEntries := 7; for i := 1 to nEntries do with directory[i] do begin ftype := 3; length := 1 end; with directory[1] do begin TagField := SubFileType; offset := bsl(1, 16); end; with directory[2] do begin TagField := ImageWidth; offset := 0; end; with directory[3] do begin TagField := ImageLength; offset := 0; end; with directory[4] do begin TagField := BitsPerSample; offset := bsl(8, 16); end; with directory[5] do begin TagField := PhotoInterp; offset := 0; end; with directory[6] do begin TagField := StripOffsets; ftype := 4; offset := TiffDirSize + HeaderSize; end; with directory[7] do begin TagField := ImageHdrTag; ftype := 4; offset := TiffDirSize; end; NextIFD := 0; for i := 1 to TiffFillerSize do filler[i] := 0; end; end; procedure CheckBits; const QD32Trap = $AB03; UnimplementedTrap = $A89F; var MainDevice: GDHandle; ScreenPixMap: PixMapHandle; myEnvRec: SysEnvRec; err: OSErr; begin err := SysEnvirons(1, myEnvRec); if err <> envNotPresent then with MyEnvRec do begin if not HasColorQD then begin PutMessage('Sorry, Image requires a Macintosh with Color QuickDraw.'); ExitToShell; end; if not HasFPU then begin PutMessage('Image requires a floating-point coprocessor or the PseudoFPU INIT.'); ExitToShell; end; OldSystem := systemVersion < $0605; SystemRefNum := sysVRefNum; end; Has32BitQuickDraw := nGetTrapAddress(QD32Trap, ToolTrap) <> nGetTrapAddress(UnimplementedTrap, ToolTrap); MainDevice := GetMainDevice; if MainDevice^^.gdPmap^^.PixelSize <> 8 then begin PutMessage('To run Image, the main monitor(the one with the menu bar) must be set to 256 colors or 256 gray levels.'); ExitToShell; end; ScreenPixMap := MainDevice^^.gdPMap; ScreenRowBytes := BitAnd(ScreenPixMap^^.rowBytes, $1fff); ScreenBase := ScreenPixMap^^.baseAddr; end; procedure SetupMenus; var i: integer; begin AppleMenuH := GetMenu(AppleMenu); InsertMenu(AppleMenuH, 0); FileMenuH := GetMenu(FileMenu); InsertMenu(FileMenuH, 0); EditMenuH := GetMenu(EditMenu); InsertMenu(EditMenuH, 0); OptionsMenuH := GetMenu(OptionsMenu); InsertMenu(OptionsMenuH, 0); EnhanceMenuH := GetMenu(EnhanceMenu); InsertMenu(EnhanceMenuH, 0); AnalyzemenuH := GetMenu(AnalyzeMenu); InsertMenu(AnalyzemenuH, 0); SpecialMenuH := GetMenu(SpecialMenu); InsertMenu(SpecialMenuH, 0); TextMenuH := GetMenu(TextMenu); InsertMenu(TextMenuH, 0); WindowsMenuH := GetMenu(WindowsMenu); InsertMenu(WindowsMenuH, 0); FontMenuH := GetMenu(FontMenu); InsertMenu(FontMenuH, -1); SizeMenuH := GetMenu(SizeMenu); InsertMenu(SizeMenuH, -1); StyleMenuH := GetMenu(StyleMenu); InsertMenu(StyleMenuH, -1); BinaryMenuH := GetMenu(BinaryMenu); InsertMenu(BinaryMenuH, -1); ArithmeticMenuH := GetMenu(ArithmeticMenu); InsertMenu(ArithmeticMenuH, -1); SortPaletteMenuH := GetMenu(SortPaletteMenu); InsertMenu(SortPaletteMenuH, -1); PropagateMenuH := GetMenu(PropagateMenu); InsertMenu(PropagateMenuH, -1); TransferModeMenuH := GetMenu(TransferModeMenu); InsertMenu(TransferModeMenuH, -1); LineToolMenuH := GetMenu(LineToolMenu); InsertMenu(LineToolMenuH, -1); DrawMenuBar; AddResMenu(AppleMenuH, 'DRVR'); AddResMenu(FontMenuH, 'FONT'); NumFontItems := CountMItems(FontMenuH); SetMenuItem(SpecialMenuH, SetVideoItem, FrameGrabber <> NoFrameGrabber); end; procedure FindMonitors; {Generate a list of monitors so we can update the color tables of multiple monitors.} {This wouldn't be necessary if we were using the Palette Manager.} var nextDevice: GDHandle; begin nMonitors := 0; nextDevice := GetDeviceList; while nextDevice <> nil do begin if TestDeviceAttribute(nextDevice, screenDevice) and TestDeviceAttribute(nextDevice, screenActive) then if nextDevice^^.gdPmap^^.PixelSize = 8 then begin nMonitors := nMonitors + 1; Monitors[nMonitors] := nextDevice; end; nextDevice := GetNextDevice(nextDevice); end; {while} end; procedure Init; var i: integer; p: SyspPtr; mbhp: ^integer; str: str255; err: OSErr; begin SetApplLimit(ptr(LongInt(GetApplLimit) - StackSize)); MaxApplZone; InitGraf(@ThePort); InitFonts; InitWindows; InitCursor; {PLHeapInit(100000,5000,Nil,true,true)-Needed for MPW} TEInit; InitDialogs(@SysResume); CheckBits; FindMonitors; new(ScreenPort); OpenPort(ScreenPort); NoInfo := @NoInfoRec; Info := NoInfo; ResultsWindow := nil; with NoInfo^ do begin nlines := 0; PixelsPerLine := 0; ImageSize := 0; PixMapSize := 0; PicBaseAddr := nil; PicBaseHandle := nil; osPort := nil; RoiShowing := false; RoiType := NoRoi; RoiRect := SrcRect; roiRgn := NewRgn; title := 'NoInfo'; Magnification := 1.0; PictureType := NullPicture; wptr := nil; Changes := false; BytesPerRow := 0; SetRect(SrcRect, 0, 0, 0, 0); PicRect := SrcRect; wrect := SrcRect; initwrect := wrect; savewrect := wrect; SaveSrcRect := SrcRect; SaveMagnification := magnification; savehloc := 0; savevloc := 0; ScaleToFitWindow := false; ColorStart := 30; ColorWidth := 8; LUTMode := GrayScale; units := ' '; FullUnits := 'Pixel'; UnitsID := pixels; RawSpatialScale := 0.0; ScaleMagnification := 1.0; SpatialScale := RawSpatialScale * ScaleMagnification; PixelsPerCM := 0.0; UnitsPerCM := 0.0; UnitOfMeasure := ''; PicNum := 1; HeaderOffset := -1; ImageDataOffset := -1; for i := 0 to 255 do ctable[i].value := 0; Fit := Poly3; Calibrated := false; nCoefficients := 0; for i := 1 to 6 do Coefficient[i] := 0.0; p1x := 0; p1y := 0; p2x := 255; p2y := 255; deltax := 255; deltay := 255; BinaryPic := false; WindowState := NormalWindow; FileDepth := EightBits; Revertable := false; x_range := 1; y_range := 1; z_range := 1; end; ExplicitPalette := NewPalette(256, nil, pmExplicit, 0); new(CScreenPort); OpenCPort(CScreenPort); SetPalette(WindowPtr(CScreenPort), ExplicitPalette, false); finished := false; FlushEvents(EveryEvent, 0); for i := 1 to 10 do MoreMasters; mbhp := pointer(MBarHeight); MenuBarHeight := mbhp^; SetRect(trect, tleft, ttop, tleft + twidth, ttop + theight); ToolWindow := NewCWindow(nil, trect, 'Tools', true, NoGrowDocProc, nil, false, 0); SetPalette(ToolWindow, ExplicitPalette, false); WindowPeek(ToolWindow)^.WindowKind := ToolKind; BringToFront(ToolWindow); ScreenWidth := ScreenBits.Bounds.right; ScreenHeight := ScreenBits.Bounds.bottom; with BlackRGB do begin red := 0; blue := 0; green := 0; end; with WhiteRGB do begin red := -1; blue := -1; green := -1; end; SliceStart := 100; SliceEnd := 150; with SliceColor do begin red := -1; green := 0; blue := 0; end; DensitySlicing := false; nExtraColors := 0; GrayMapReady := false; ResetGrayMap; {LUT must be setup before InitMenus} InitMenus; SetRect(gmrect, gmleft, gmtop, gmleft + gmwidth, gmtop + gmheight); SetRect(gmSlide1, gmrectleft, gmrectbottom + gmSlide1Offset, gmrectleft + gmSlideWidth, gmrectbottom + gmSlide1Offset + gmSlideHeight); gmSlide1i := gmSlide1; InsetRect(gmSlide1i, 1, 1); SetRect(gmSlide2, gmrectleft, gmrectbottom + gmSlide2Offset, gmrectleft + gmSlideWidth, gmrectbottom + gmSlide2Offset + gmSlideHeight); gmSlide2i := gmSlide2; gmFixedSlope := false; InsetRect(gmSlide2i, 1, 1); SetRect(gmIcon1, gmIcon1left, gmrectbottom + gmIconOffset, gmIcon1left + gmIconWidth, gmrectbottom + gmIconOffset + gmIconHeight); SetRect(gmIcon2, gmIcon2left, gmrectbottom + gmIconOffset, gmIcon2left + gmIconWidth, gmrectbottom + gmIconOffset + gmIconHeight); GrayMapWindow := NewWindow(nil, gmrect, ' Gray Map ', true, NoGrowDocProc, nil, false, 0); WindowPeek(GrayMapWindow)^.WindowKind := GrayMapKind; SetRect(GrayMapRect, gmRectLeft, gmRectTop, gmRectRight, gmRectBottom); GrayMapRect2 := GrayMapRect; InsetRect(GrayMapRect2, -2, -2); cheight := 256 + (2 + nExtraColors) * ExtraColorsHeight; SetRect(crect, cleft, ctop, cleft + cwidth, ctop + cheight); LUTWindow := NewCWindow(nil, crect, 'LUT', true, NoGrowDocProc, nil, false, 0); SetPalette(LUTWindow, ExplicitPalette, false); WindowPeek(LUTWindow)^.WindowKind := LUTKind; rleft := 2; if ScreenHeight > 480 then rtop := ScreenHeight - rheight - 5 else rtop := 358; SetRect(trect, rleft, rtop, rleft + rwidth, rtop + rheight); ResultsWindow := NewWindow(nil, trect, 'Results', true, NoGrowDocProc, nil, false, 0); BringToFront(ResultsWindow); WindowPeek(ResultsWindow)^.WindowKind := ResultsKind; BuggyWatch := GetCursor(WatchCursor); InitTools; MakeCursors; nPics := 0; HistoWindow := nil; PlotWindow := nil; IsInsertionPoint := false; MaskRgn := NewRgn; PlotPICT := nil; AutoscalePlots := true; InvertPlots := false; LinePlot := true; DrawPlotLabels := true; FixedSizePlot := false; ProfilePlotMin := 0; ProfilePlotMax := 255; ProfilePlotWidth := 300; ProfilePlotHeight := 150; AirbrushDiameter := 32; AirbrushRadius := 16; AirbrushRadius2 := 256; BrushWidth := 14; BrushHeight := 14; CurrentUndoSize := 0; p := GetSyspPtr; BlinkTime := BitAnd($000F, p^.volclik) * 4; MakePatterns; InitColor('Default', 0); info^.LUTMode := GrayScale; PaletteName := ''; PicLeftBase := twidth + cwidth + 10; PicTopBase := MenuBarHeight + 20; PicLeft := PicLeftBase; PicTop := PicTopBase; CurrentColorIndex := NoColor; CurrentFontID := Helvetica; CurrentStyle := []; {plain} CurrentSize := 12; TextJust := teJustLeft; TextBack := NoBack; MouseState := NotInRoi; WhatsOnClip := Nothing; InitExtraColors; OldScrapCount := GetScrapCount; ClipboardConverted := false; results.PixelLength := 0.0; BufferSize := DefaultBufferSize; LookForFrameGrabbers; VideoChannel := 0; Digitizing := false; debugging := false; BlankFieldInfo := nil; QuickCaptureInfo := nil; ScionInfo := nil; InvertVideo := false; PlotCount := 0; ClipTextInBuffer := false; TextBufP := TextBufPtr(NewPtr(SizeOf(TextBufType))); if TextBufP = nil then ExitToShell; MacrosP := MacrosPtr(NewPtr(SizeOf(MacrosRec))); if MacrosP = nil then ExitToShell; mCount := 0; mCount2 := 0; nPoints := 0; nLengths := 0; nAngles := 0; for i := 1 to MaxStandards do StandardValues[i] := BadReal; nStandards := 0; for i := 0 to 255 do cvalue[i] := i; WhatToUndo := NothingToUndo; WhatToCopy := NothingToCopy; PrintRecord := nil; printing := false; HalftoneFrequency := 53; HalftoneAngle := 45; HalftoneDotFunction := true; cr := chr(13); tab := chr(9); BackSpace := chr(8); eof := chr(4); measuring := false; measurements := [AreaM, MeanM]; UpdateFitEllipse; nListColumns := 0; FramesToAverage := 16; NewPicWidth := 552; NewPicHeight := 436; RestoreUndoBuf := true; MakeTiffDirectory; MaxScionWidth := 600; ThresholdToForeground := true; NonThresholdToBackground := true; SelectionMode := NewSelection; RoiMovementState := Unconstrained; PasteControl := nil; PasteTransferMode := SrcCopy; WhatToImport := ImportTIFF; ImportCustomWidth := 512; ImportCustomHeight := 512; ImportCustomOffset := 0; ImportCustomDepth := EightBits; ImportSwapBytes := false; ImportCalibrate := true; ImportAll := false; RoiNudged := false; ForegroundIndex := BlackIndex; BackgroundIndex := WhiteIndex; for i := 0 to MaxPixelsPerLine - 1 do BlankLine[i] := WhiteIndex; OpPending := false; RedoSelection := false; WandAutoMeasure := false; WandAdjustAreas := false; OptionKeyWasDown := false; BinaryIterations := 1; ScaleArithmetic := true; ResultsMessage := ''; SaveAsWhat := asTIFF; ExportAsWhat := asRaw; AnalyzingParticles := false; RedirectSampling := false; MinParticleSize := 1; MaxParticleSize := 999999; LabelParticles := true; OutlineParticles := false; IgnoreParticlesTouchingEdge := false; IncludeHoles := false; SaveAllState := NoSaveAll; InvertYCoordinates := true; ContinuousHistogram := false; DrawLabels(' ', '', ''); HistogramSliceStart := 0; HistogramSliceEnd := 255; RoiUpdateTime := 0; FieldWidth := 9; precision := 2; MeasurementToRedo := 0; nMacros := 0; macro := false; KernelsRefNum := 0; DefaultRefNum := 0; DefaultFileName := ''; rsHScale := 1.0; rsVScale := 1.0; rsAngle := 0.0; rsMethod := NearestNeighbor; rsCreateNewWindow := true; rsInteractive := false; ImportAutoScale := true; ImportMin := 0.0; ImportMax := 255.0; UseZeroForBlack := false; x1 := -1; y1 := -1; x2 := -1; y2 := -1; ShowReversingMovies := false; UsingLaserWriter6 := false; LivePasteMode := false; ShowCount := true; PasteControlLeft := ScreenWidth - pcwidth - 10; PasteControlTop := ScreenHeight - pcheight - 10; MaxRegions := 200; MeasLeft := 50; MeasTop := 50; UnsavedResults := false; MajorLabel := 'Major'; MinorLabel := 'Minor'; ShowHeadings := false; end; end.