Example macro #1. Nested macros
Macro ``beep.macro''
Line # Command
1 beep;
2 beep;
3 beep;
Note: the words ``Line #'' and ``Command'' and the numbers 1,2, and 3 are not part of the macro. In this example, the macro would consist of only 3 words (``beep''), one on each line.
Macro ``test.macro''
Line # Command
1 macro(beep.macro);
2 beep;
Executing ``test.macro'' should cause a total of 4 beeps. A macro must never call itself - this would cause an infinite loop.
Example macro #2. Converting GIF image to TIFF format interactively
Line # Command
1 a=getstring("What is the filename?");
2 messages(0);
3 fileformat(0);
4 save(a);
5 messages(1);
6 goto(1);
Line 1 - Prompts you for a filename each time
Line 2 - Resets default file format to 0 (TIF). If this line is omitted, the file format would default to the original format of each image.
Line 4 - Saves the image in TIFF format. Don't forget to rename the file extension to TIFF later.
Line 5 - Resume error messages
Line 6 - Unconditional loop back to line 1. Press ESC to stop.
Example macro #3. Converting GIF image to TIFF format in batch mode
Line # Command
1 messages(0);
2 load(*.gif);
3 file_format(0);
4 save;
In the DOS version, this macro could be executed at 3 a.m. by setting the following timed events in tnshell or other command scheduler:
Line # Command
Event 1: cd c:tnimage 3:00am
Event 2: tnimage -macro convert.macro 3:01am
Event 3: ren *.gif *.tif 4:00am
Event 4: cd c:4:01am
Event 3 could also be replaced by a new line in the macro:
dos ren *.gif *.tif
Make sure there is enough free disk space before starting this macro.
Example macro #4. Subtracting two images
Line # Command
1 pixel_interact_mode(1);
2 load cells.tif(0,0,1,1);
3 pixel_interact_mode(5);
4 load cells.tif(1,1,1,1);
5 pixel_interact_mode(1);
6 intensity(185);
This macro loads an image, then subtracts the same image after offsetting it
by (1,1), then increases the intensity. All 6 lines are essential for a good
macro.
Line 1: The pixel interaction mode is set to 1 (overwrite) in case a previous operation changed it.
Line 2: All 4 parameters (x offset, y offset, x size, and y size) must be given. Otherwise, if the macro was executed again, the default parameters would be 1,1,1,1 because of line 4. This would cause the image to be placed at (1,1) and then subtracted from itself, giving solid black.
Line 3: The pixel interaction mode is set to 5 (subtract). It is usually helpful to change the screen background color to 0 (black) before doing this.
Line 4: Load the image to subtract.
Line 5: Reset the pixel interaction mode to overwrite.
Line 6: Increase the intensity by a factor of 1.85.
Be careful using ``DOS command'' in combination with ``messages 0''.
If there is insufficient low DOS memory to execute the command,
``messages 0'' may cause you to miss the fact that the command was not executed.
Example macro #5. Multiple image math formulas
Line # Command
1 selectregion(50,50,100,100);
2 i=i+5;
3 i=i+image[2][0][x][y];
4 r=r*1.23;
5 i=i-5;
Line 1: Select a region to modify. If this line is omitted,
it would modify the entire image.
Line 2: Lighten the image by 5 intensity units.
Line 3: Add the corresponding region from image #2.
Line 4: Increase the red contrast by 1.23 fold.
Line 5: Subtract 5 intensity units from the selected region.