Date: Mon, 4 May 92 09:30:40 EDT From: horton@relito.medeng.wfu.edu (Roger Horton) To: wayne@zippy.nimh.nih.gov Wayne, I've just finished porting our local routines from Image 1.37 to Image 1.44. During the process, I kept a log of the various changes that were necessary. I'm using the ETO #7 release of MPW, MPW C and MPW Pascal. I'm forwarding the conversion log on to you with the hope that it may be of use to anyone porting your code to MPW. I also noted a few bugs that may be of interest. Thanks again for making this fine program available to the public. Roger A. Horton, DMD MS Department of Dentistry Bowman Gray School of Medicine Wake Forest University (919) 748-2167 horton@relito.medeng.wfu.edu P.S. Any references to IBG, scanning, Tomosynthesis, or Colorspace can essentially be ignored since they have to do with our local routines and control of the ColorSpace video boards that we are using. Log of activities for conversion from Image 1.37.BG to Image 1.44.BG Conversion started: 04/27/92 Initial port completed: 05/01/92 I. Unavoidable Alterations to native Image 1.44 source: 1. Analysis.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S ANALYSIS}. 2. Camera.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S CAMERA}. c) procedure SetVideoChannel declaration for nonexistent procedure 3. Edit.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S EDIT}. 4. Ellipse.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S ELLIPSE}. 5. File1.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S FILE1}. c) Add handle locking of srcBits.pmTable in routine BitInfo d) replace array copy loop for color table with BlockMove to avoid problem with range checking of arrays in MPW, since cTable is defined as [0..0] in MPW. e) Tried to add out-of-range element to TypeList in routine DoOpen. Expanded array by one element to accommodate. 6. File2.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S FILE2}. c) Allocate local string in routine GetWDInfo to pass into ioNamePtr member of parameter block, to avoid crashes due to use of invalid string pointer. d) had to change GetWDInfo procedure name to MyGetWDInfo to avoid conflict with declaration in PIncludes in File2.p e) add IBG variables to "settings" in routine SaveSettings f) add error checking and file closing after SetEof and fsclose in routine SaveSettings g) had to change NewPtrClear procedure name to MyNewPtrClear to avoid conflict with declaration in PIncludes in File2.p 7. Functions.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S FUNCTIONS}. c) changed routine DoOnePixel to fix problem with MPW/Think difference in assignment of byte values into arrays of 8 bit image data. Image dereferences pointers of type "ptr" to update individual pixels in an image. In MPW a "ptr" is defined as "Ptr = ^SignedByte" where "SignedByte = - 128..127". Image also typically assigns integer values to byte positions in the pixel array and depends on implicit type conversion. In MPW this causes errors whenever the 8th bit is set, because the integer values $0080 and higher convert to values above 127, which is outside the range of a SignedByte. The solution is either to use an explicit conversion to SignedByte, or to use a different pointer type to access the image data array. I have done the second, using a pointer to a packed array[0..MaxLine] of char. MPW chars are byte values in the range 0..255. This approach makes integration with C routines a little more straightforward. d) made same change to DoConvolution, which also moves a single character and shows the same error e) Replaced PlotSurface with my own version as created first in version 1.33. The stock version seems to get caught in loops and draws incorrectly when compiled in MPW. 8. Globals.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S GLOBALS}. c) add scan window selection item to windows menu d) increase number of items on windows menu to 14 e) commented out BitMapHandle declarations, these are predeclared in MPW f) add TomoScanC to CommandType set of macro language g) change TokenType type name to ImgTokenType to avoid conflict with type of same name in MPW Scripts.p interface h) add IBG setting parameters to SettingsType definition i) commented out osEvt definition since it is already defined in PInterfaces.p j) changed variable MapRect to ImgMapRect due to name conflict with predefined procedure MapRect 9. Graphics.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S GRAPHICS}. c) nonexistent procedure ShowProgress declared 10. Image.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S IMAGE}. c) change routine UpdateWindowsMenu to include scan window item d) change routine UpdateWindowsMenu to set status of scan control window menu item e) add scan control window selection to DoMenuEvent f) add additional IBG menu handling to DoMenuEvent g) change DoDrag to activate the scan display window when the scan control window is activating h) change DoDrag to redraw the ColorSpace video if a video display window is open i) change UpdateMenus to include update to IBG menus j) add DoneID constant to DoMouseDown to be used in calling tommosynthetic routines when a mouse down in the scan control window close box occurs k) add code to close the scan control window to DoMouseDown l) change DoUpdate to redraw the ColorSpace video window m) change HandleEvents to test for dialog events. IBG uses non-modal dialogs to control tomosynthetic scanning. n) add line to Shutdown to call IBG shutdown procedures o) change name of unit Init to Initialization in uses statement (see next item for explanation) 11. Init.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S INITIAL}. c) added message to indicate failure to open preferences file d) add code to routine SetupMenus to load IBG main menu e) add code to routine SetupMenus to load IBG hierarchical menus f) add InitIBG call to routine Init to initialize IBG variables g) activate PLHeapInit call in routine Init for MPW h) had to change OpenWD procedure name to MyOpenWD to avoid conflict with declaration in PIncludes in File2.p i) change name of unit from Init to Initialization to avoid conflict between unit and procedure names in MPW j) changed variable MapRect to ImgMapRect due to name conflict with predefined procedure MapRect in Quickdraw.p k) add code to load tomosynthesis globals in routine GetSettings 12. LeastSquares.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S LEASTSQRS}. c) Moved global declarations, procedures and functions into scope of routine DoSimplexFit, since there is no need to declare them globally and they cause conflicts when declared as such. Some of the variables appear to be unused. Constants and types were left as globally defined. 13. Macros1.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S MACROS1}. c) add forward definition of IBG tomosynthesis macro routine d) add SymbolToStr routine to translate a symbol string to a Str255. MPW is pickier about string types than Think. e) add SymbolToStr call to routine MacroError f) add SymbolToStr call to routine CheckForReservedWord g) add call to DoTomosynthesis to routine ExecuteCommand h) add routine DoTomosynthesis i) had to change GetString procedure name to MyGetString to avoid conflict with declaration in PIncludes in File2.p j) change TokenType type name to ImgTokenType to avoid conflict with type of same name in MPW Scripts.p interface k) had to change SetPrecision procedure name to MySetPrecision to avoid conflict with declaration in PIncludes in SANE.p l) altered routine GetArrayValue to access rgb colorspec value from the screen pixmap using pointers. Existing code leaves dereferenced handle unlocked and uses index into cSpecArray, which gives MPW heartburn since it defines a cSpecArray as [0..0] and doesn't allow indexing into array. Access is via new function GetCTabElement. m) break unit into 2 segments due to size of code 14. Macros2.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segment: {$S MACROS2}. c) add 1 to number of symbols to allow for tomoscan symbol d) add tomoscan symbol to symbol table 15. Utilities.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segments: {$S UTIL1} & {$S UTIL2} c) activate MPW code in RealToString d) change MyGetPixel to fix problems caused by differences in handling of "ptr" dereferencing in Think and MPW (see detailed explanation in Functions.p above). e) change PutPixel to fix problems caused by differences in handling of "ptr" dereferencing in Think and MPW (see detailed explanation in Functions.p above). Also added range checking to prevent errors that resulted in image artifacts. f) note that difference in handling of strings in Think and MPW can cause problems in MakeNewWindow when passing a window name longer than 30 characters. Make sure window names passed in are less than 30 characters long. g) commented out procedure UnprotectLUT declaration for nonexistent procedure h) altered routine DrawRBG to access rgb colorspec via new function GetCTabElement. 16. Background.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segments: {$S BKGRND} c) Had to simplify expressions in Background1D and Background2D involving div and mod. These caused MPW out-of-registers error. d) Change code that assigns values to image arrays via "ptr" pointer type. New code assigns pixels using pointers to a packed array of char's (see detailed explanation in Functions.p above). 17. Color.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segments: {$S COLOR} c) constant NoColor is undefined d) Much of this unit appears to be duplicated in Lut.p. Apparently it is still under constuction 18. Lut.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segments: {$S LUT} c) changed variable MapRect to ImgMapRect due to name conflict with predefined procedure MapRect d) Commented out declared but unimplemented function GetColorTable. Function exists in File1.p. 19. Projection.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segments: {$S PROJ} c) replace use of non-standard StringOf (think built-in) in routine DoProjection with calls to standard Image routine RealToString. d) Change code that assigns values to image arrays via "ptr" pointer type. New code assigns pixels using pointer to packed array of char (packChPtr) (see detailed explanation in Functions.p above). 20. Stacks.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segments: {$S STACKS} 21. User.p: a) Update "uses" for MPW: see file for details. b) Add compiler directive to name segments: {$S USER} 22. Image.r: a) Add scancontrol item to Windows menu (#138)