This document describes several icon tools for the Amiga which are Copyright © 1994 by Tobias Ferber.

GNU GENERAL PUBLIC LICENSE
**************************

gpl.texinfo

Introduction
************

The IconTools are a collection of commands for creating and manipulating Workbench icon images.  Before I started calling this project IconTools there had been several OptIcon archives with other tools like Icon2c or IconMaker included into it. The reason for the the tools included here being so widely spread is last but not least due to the success of Martin Huttenloher's great MagicWB icon collection.

OptIcon
*******

Abstract
========

Even if some users claim OptIcon being the tool of their choice for changing the number of bitplanes in their MagicWB icons, the main idea behind OptIcon is and was to optimize icons for size and speed. OptIcon reads .info files and scans the icon image in order to optimize the PlanePick and PlaneOnOff fields in the icon's Image structure.  This is a space-saving mechanism for image data.

     struct Image {

         /* ... */

         UBYTE PlanePick, PlaneOnOff;

         /* ... */
     };

Rather than defining the image data for every plane of the RastPort, you need define data only for the planes that are not entirely zero or one.  As you define your imagery, you will often find that most of the planes are just as color selectors.  For instance, if you're designing a two-color icon to use colors one and three, and the icon will reside in a five-plane display, bit plane zero of your imagery would be all ones, bit plane one would have data that describes the imagery, and bit planes two through four would be all zeroes.  Using these flags avoids wasting all that memory in this way:  first, you specify which planes you want your data to appear in using the PlanePick variable.  For each bit set in the variable, the next `plane' of your image data is blitted to the display.  For each bit clear in this variable, the corresponding bit in PlaneOnOff is examined.  If that bit is clear, a `plane' of zeroes will be used.  If the bit is set, ones will go out instead. Note that if you want an Image that is only a filled rectangle, you can get this by setting PlanePick to zero (pick no planes of data) and set PlaneOnOff to describe the pen color of the rectangle.

Installing OptIcon
==================

The OptIcon executable comes in two versions: OptIcon.000 for all Amigas and OptIcon.030 for Amigas with a MC-68030 processor. You simply have to copy one of those into your path (e.g. to C:) and rename it to OptIcon:

     Copy CLONE FROM OptIcon.030 TO C:OptIcon

If you want to make use of the recursive-descent ablility of the OptIcon.rexx script then you should copy this into your rexx: drawer and make sure the script-flag s ist set:

     Copy CLONE FROM OptIcon.rexx TO rexx:
     Protect FILE rexx:OptIcon.rexx ADD s

Invoking OptIcon
================

OptIcon uses ReadArgs() to parse the command line arguments with the following template:

     FROM=NAME/A/M,DEPTH=PLANES/N,NOEXPAND/S,CRITICAL/S,REMAPV37/S,VERBOSE/S,SMART/S,ALL/S

FROM=NAME/A/M (required, multiple)
     The name of the icon image file.  A trailing .info is optional but not required.  Several icon image files can be specified. If the ALL switch is given, then OptIcon recursively enters all directories passed via FROM, collecting all icons.

DEPTH=PLANES/N (numeric)
     With this option you can specify the number of bitplanes to save.

NOEXPAND/S (switch)
     If the NOEXPAND keyword is not present in the command line, then OptIcon will always write as many bitplanes as specified with the DEPTH=PLANES/N option, even if bitplanes have to be added. With the NOEXPAND switch given, OptIcon will not add any new planes.

CRITICAL/S (switch)
     Commodore's PutDiskObject() currently [icon.library 40.1 (15.2.93)] re-expands icon images using the PlanePick/PlaneOnOff mechanism and in fact PutDiskObject() has quite a lot of problems doing so! For this reason OptIcon will perform the PlanePick/PlaneOnOff optimization only if the keyword CRITICAL is given in the command line!

REMAPV37/S (switch)
     If the REMAPV37 switch is given in the command line, OptIcon will map the colors 4--7 to the last 4 in the palette using the following algorithm:

      1. A bitplane mask is generated from all planes > 2 via OR. (This mask has ones at those positions where any of the bitplanes > 2 has a 1 and has zeros only at those positions where all bitplanes > 2 have zeros.)

      2. The result is inverted and

      3. stamped with plane 2 via AND.

      4. The resulting mask is set via OR in all planes > 2

     There is obviously no need to expand the image data if the following expression is true for the PlaneOnOff value p10:

          p10 &~ %111 != 0

     When expanding an icon without the REMAPV37 keyword given in the command line, the last 4 colors of the input image i are mapped to the last 4 colors of the output image o as follows:

      1. A bitplane mask is generated by an OR of all bitplanes but the last. (This mask has zeros only at those positions where all bitplanes but the last have zeros and has ones otherwise.)

      2. The resulting mask is stamped via AND with the last bitplane

      3. The result is set in all new bitplanes

     If any plane of i but the last is entirely 1 then we can simply copy the last plane of i to all new planes in o

VERBOSE/S (switch)
     This switch tells OptIcon to print out some information about each icon and what OptIcon is about to do with it.

SMART/S (switch)
     With this switch, OptIcon will examine WBDRAWER and WBGARBAGE icons more closely and if there is not really a drawer (or a file) behind the icon then the icon type is changed into WBTOOL. This is a great help if you want to use some drag'n drop application to update icon images which would have problems otherwise (bug? feature? hmmm...).

     Caution: It is dangerous to call opticon ALL SMART on ENV: or ENVARC: because this would change the type of the default icons sys/def_drawer.info and sys/def_trashcan.info (and perhaps some more) making them unusable for their initial purpose!

ALL/S (switch)
     If this switch is given, OptIcon recursively enters all subdirectories given via FROM, collecting icons.

Example: In order to remove all but the first 3 planes of the icon image for the disk in drive DF0: without adding any bitplanes you can invoke OptIcon as follows:

     OptIcon DF0:Disk PLANES=3 NOEXPAND

Notes
=====

Since the IconEdit from Commodore will always save 8 bitplane icons the above example might be of great use to you. (Note that 3 plane images are not only smaller but also faster!) Coming with OptIcon is the script PatchIcons which will recursively descend all subdirectories of a given path deleting all but the first 3 planes of all icon images in that path.

OptIcon now also allows you to expand your 8 or more color icons for the use on a 16 or more color Workbench.  This is important due to the new color system under OS3.x which always shifts the second four colors to the end of the system palette.  Therefore you might want to adapt an icon's color depth to the actual screenmode it is used on.

Note also: OptIcon will always overwrite your icon and does not support a recursive descent. This is why we wrote the ARexx script OptIcon.rexx which offers all this to you. Some people might never even want to use OptIcon directly but will always use OptIcon.rexx.

Example: I only have 8 colors on my Workbench and I often find icon collections which come up with full 8 bitplane icons and image drawers with no real drawer behind them. Now on the one hand I don't want to waste space and time for 5 bitplanes which I don't really need and on the other hand I want to be able to use MH's drag'n drop tool IconUpdate to change my drawer images without having to care about whether these are really drawers or not.

Okay, I've downloaded pix/mwb/TobiIcons-2.0.lha from the Aminet and extracted it into my ram: disk.  A drawer ram:Tobi-Icons/ had been created there. What I do now is I invoke my OptIcon.rexx script and change all the icons there into 3 plane icons and I change all the faked DRAWER icons into TOOL icons:

     rx rexx:OptIcon.rexx FROM ram:Tobi-Icons ALL SMART PLANES 3

The magic happening there can also be achived without the .rexx script like that:

     List >ram:doit ALL FILES DIR ram:Tobi-Icons PAT #?.info +
       LFORMAT "OptIcon *"%p%n*" PLANES=3 NOEXPAND SMART"
     Execute ram:doit

OptIcon and MagicWB
===================

In these days, OptIcon has become more and more used by people who use Martin Huttenloher's MagicWB icon collection i.e. on Workbench screens with more than only two bitplanes.  Due to the problems resulting from the new coloring scheme (first-4/last-4 colors) as introduced with OS3.x these icons look wrong if the number of bitplanes in the icon is less than the number of bitplanes on the Workbench screen.  Of course one could avoid this problem by giving each icon all eight bitplanes (this is what Commodore's IconEdit does) but this is a waste of space and time since larger icons do not only eat up more disk space but are also much slower!

An easy way for solving this problem is OptIcon on a ToolManager Dock or AppIcon.  (Thanks to Mark Rose, who contributed his nice `Plane' icon for the OptIcon distribution.)

Example: Suppose you have a 16 color Workbench and you find an 8 color icon which looks wrong then you can simply call OptIcon PLANES=4 from within ToolManager by simply dropping the icon on the dock.

Icon2c
******

Abstract
========

Tools which manipulate existing icon images are widely spread but actually when it comes to the point there most often is exactly one switch missing: the one you need ;-). Icon2c reads a given .info file and writes out well documented and directly compilable C code.  This code if compiled with a symbol TEST defined (usual compiler option: -DTEST) will generate an executable which writes back the icon image file to disk. This allows you to modify any icon to your own needs -- with a text editor and a C compiler of your choice.

Installing Icon2c
=================

The Icon2c executable comes in two versions: Icon2c.000 for all Amigas and Icon2c.030 for Amigas with a MC-68030 processor. You simply have to copy one of those into your path (e.g. to C:) and rename it to Icon2c:

     Copy CLONE FROM Icon2c.030 TO C:Icon2c

Invoking Icon2c
===============

Icon2c uses ReadArgs() to parse the command line arguments with the following template:

     NAME/A,QUIET/S,TO/K

NAME/A (required)
     Name of the icon image file.  A trailing .info is optional but not required.

QUIET/S (switch)
     If this switch is given then Icon2c will not print any warnings. (More information about Icon2c's warnings can be found in the DrawerData discussion further down.) Note: Warnings are allways directed to stderr so that they always appear on the console (and not in the source code) even if the output is redirected from stdout via > or |.

TO/K (keyword required)
     This option allows you to specify the name of the generated C code file. If not specified the standard output stream will be used which allows piping in a shell. E.g.:

          icon2c ram:disk.info | more

Example: Suppose you want to generate C code from the disk icon of the disk in DF0::

     Icon2c DF0:Disk QUIET TO RAM:diskicon.c

The Code Generated by Icon2c
============================

The code generated by Icon2c always begins with some #includes, which define the structures and constants needed.

     #include <intuition/intuition.h>
     #include <workbench/workbench.h>
     #include <workbench/icon.h>

We will now discuss the generated output using a WBDISK icon with two images: one for the `normal' state and one for the `selected' state of the icon. The icon type WBDISK is quite suitable for this tutorial purpose because it needs all the structures an icon can have.  I've created the code in the following examples by invoking Icon2c like that:

     icon2c ram:disk.info >ram:diskinfo.c

The Image Data
--------------

For the `normal' icon image image (the one which we see if the icon is not selected), an array gr_data is generated. Each line in the code represents one line of pixels in the image. As usual in the image data, bitplanes are stored in ascending order:

     UWORD gr_data[] = {

       /* plane 0 */

       0x0000, 0x0000, 0x0000, ...
       0x0000, 0x0000, 0x0000, ...
       ...

       /* plane 1 */

       ...
     };

This array gr_data is pointed to by the Image structure gr which -- as we will see later -- is pointed to by the do_Gadget.GadgetRender field of the DiskObject structure.  (This is why we use gr here.)

     struct Image gr = {
       0,0,         /* LeftEdge, TopEdge     */
       47,36,3,     /* Width, Height, Depth  */
       gr_data,     /* ImageData             */
       7,0,         /* PlanePick, PlaneOnOff */
       NULL,        /* NextImage             */
     };

If the given icon has an alternate image, an array sr_data and it's Image structure sr are generated analog to gr_data and gr. The sr structure is pointed to by the do_Gadget.SelectRender field of the DiskObject structure.

The ToolTypes Array
-------------------

The icon ToolTypes are stored into tt, a (char *)NULL-terminated array of strings. Since our WBDISK icon does not really need ToolTypes, we only have a dummy here:

     char *tt[] = {
       "»»»» Icon by Martin Huttenloher ««««",
       NULL
     };

If there are no ToolTypes at all in the given icon, both is possible: The tt array is created and containes only one NULL entry or the do_ToolTypes field in the DiskObject structure contains a NULL pointer.

The DrawerData structure
------------------------

Icons of type WBDISK, WBDRAWER and WBGARBAGE have a DrawerData structure which holds the information about the window which opens when double-clicking the icon. Icons of a different type do not have such a structure but a NULL pointer in the DiskObject's do_DrawerData field.

The dd_NewWindow.FirstGadget field holds a non-NULL pointer every now and then. Icon2c will print a warning message in these cases and initialize the dd.dd_NewWindow.FirstGadget field to NULL in the generated code. The Gadget structure will be included into the generated code like this:

     #ifdef UNDEFINED
       struct Gadget <unknown> = {

         /* ... some strange stuff in here ... */

       };
     #endif /* UNDEFINED */

There also happens to be a non-NULL pointer in the dd_NewWindow.Title field every now and then.  In this case as well a warning message will be printed and the field in the generated code will be initialized to NULL. However, the original string value will be available in a comment if it is printable.

Here is the DrawerData structure of our WBDISK icon:

     struct DrawerData dd = {
       151,                  /* dd_NewWindow.LeftEdge    */
       54,                   /* dd_NewWindow.TopEdge     */
       347,                  /* dd_NewWindow.Width       */
       150,                  /* dd_NewWindow.Height      */
       255,                  /* dd_NewWindow.DetailPen   */
       255,                  /* dd_NewWindow.BlockPen    */
       NULL,                 /* dd_NewWindow.IDCMPFlags  */
       WFLG_SIZEGADGET
       | WFLG_DRAGBAR
       | WFLG_DEPTHGADGET
       | WFLG_CLOSEGADGET
       | WFLG_SIZEBRIGHT
       | WFLG_SIZEBBOTTOM
       | WFLG_SIMPLE_REFRESH
       | WFLG_REPORTMOUSE
       | WFLG_ACTIVATE
       | WFLG_WBENCHWINDOW,  /* dd_NewWindow.Flags       */
       NULL,                 /* dd_NewWindow.FirstGadget */
       NULL,                 /* dd_NewWindow.CheckMark   */
       NULL,                 /* dd_NewWindow.Title       */
       NULL,                 /* dd_NewWindow.Screen      */
       NULL,                 /* dd_NewWindow.BitMap      */
       92,                   /* dd_NewWindow.MinWidth    */
       68,                   /* dd_NewWindow.MinHeight   */
       65535,                /* dd_NewWindow.MaxWidth    */
       92,                   /* dd_NewWindow.MaxHeight   */
       WBENCHSCREEN,         /* dd_NewWindow.Type        */
       0,                    /* dd_CurrentX              */
       0,                    /* dd_CurrentY              */
       3,                    /* dd_Flags                 */
       0,                    /* dd_ViewModes             */
     };

The values of the dd_Flags and dd_ViewModes fields are not documented in the includes. Playing around with these values however has revealed some information. The dd_Flags field is usually set to one of the following:

1
     If only files with an icon should be visible in this window.

2 or 3
     If all files should be visible, using the def_#?.info default icons from env:sys/.

The dd_ViewModes field represents the sorting criteria of the files and drawers listed in the window:

1
     Graphical, view by icon

2
     Textual, lexicographically sorted by name

3
     Textual, sorted by date

4
     Textual, sorted by size

The DiskObject structure
------------------------

The DiskObject structure icon is the holder of all the other data.

     struct DiskObject icon = {
       WB_DISKMAGIC,                     /* do_Magic                */
       WB_DISKVERSION,                   /* do_Version              */
       NULL,                             /* do_Gadget.NextGadget    */
       5,                                /* do_Gadget.LeftEdge      */
       7,                                /* do_Gadget.TopEdge       */
       47,                               /* do_Gadget.Width         */
       37,                               /* do_Gadget.Height        */
       GFLG_GADGHIMAGE|GFLG_GADGIMAGE,   /* do_Gadget.Flags         */
       GACT_RELVERIFY|GACT_IMMEDIATE,    /* do_Gadget.Activation    */
       GTYP_BOOLGADGET,                  /* do_Gadget.GadgetType    */
       (APTR)&gr,                        /* do_Gadget.GadgetRender  */
       (APTR)&sr,                        /* do_Gadget.SelectRender  */
       NULL,                             /* do_Gadget.GadgetText    */
       0,                                /* do_Gadget.MutualExclude */
       NULL,                             /* do_Gadget.SpecialInfo   */
       0,                                /* do_Gadget.GadgetID      */
       (APTR)WB_DISKREVISION,            /* do_Gadget.UserData      */
       WBDISK,                           /* do_Type                 */
       "SYS:System/DiskCopy",            /* do_DefaultTool          */
       &tt[0],                           /* do_ToolTypes            */
       NO_ICON_POSITION,                 /* do_CurrentX             */
       NO_ICON_POSITION,                 /* do_CurrentY             */
       &dd,                              /* do_DrawerData           */
       NULL,                             /* do_ToolWindow           */
       8192,                             /* do_StackSize            */
     };

The TEST code
-------------

When compiling the generated code with a symbol TEST defined, then an executable will be generated which writes the icon to disk via PutDiskObject(). Together with a C compiler and a text editor of your choice we now have the most powerful tool for manipulating Workbench icons you can think of. (-:

Example: Let's assume you called Icon2c and saved your Ram Disk icon to ram:foo.c:

     Icon2c ram:disk.info >ram:foo.c

Now you compile the file foo.c with Dice C:

     dcc -2.0 -DTEST ram:foo.c

and the resulting executable ram:foo can be used to write the icon back to ram:disk.info

     ram:foo ram:disk

Here is the main() procedure of foo.c:

     #ifdef TEST
     #include <intuition/intuitionbase.h>
     #include <stdlib.h>
     #include <stdio.h>

     extern struct Library *OpenLibrary(STRPTR, ULONG);
     extern void CloseLibrary(struct Library *);
     extern LONG IoErr(void);
     extern BOOL PrintFault(LONG, STRPTR);
     extern BOOL PutDiskObject(char *, struct DiskObject *);

     struct IconBase *IconBase;

     int main(int argc, char **argv)
     {
       if(argc == 2)
       {
         if( (IconBase= (struct IconBase *)OpenLibrary(ICONNAME,36)) )
         {
           if( !PutDiskObject(argv[1],&icon) )
             PrintFault(IoErr(),argv[1]);
           CloseLibrary(IconBase);
         }
         else printf("%s: no %s.\n",*argv,ICONNAME);
       }
       else printf("usage: %s <filename>\n",*argv);

       return IoErr();
     }
     #endif /* TEST */

IconMaker
*********

Abstract
========

Suppose you painted some brushes and now you want to make icons from them. Or let's assume you've downloaded some brushes and you don't know how they look like.  This is where it comes to IM -- the IconMaker. IM creates icons from brushes and offers you the best possibility for a preview: the Workbench with all its functions!  (-:

Installing IconMaker
====================

Simply copy IM.000 (or IM.030 if you have a MC-68030 Amiga) somewhere into your path (e.g. to C:) and rename it to IM. For example:

     Copy im.030 TO c:im

Invoking IconMaker
==================

IconMaker uses ReadArgs() to parse the command line arguments with the following template:

     FROM=NORMAL/K/A,SELECTED/K,
     IW=ICONWIDTH/K/N,IH=ICONHEIGHT/K/N,MINSIZE/S,
     TYPE/K,HIGHLIGHT/K,
     IX=ICONX/K/N,IY=ICONY/K/N,
     TOOLTYPES/K/M,STACKSIZE/K/N,DEFAULTTOOL/K,
     WX=WINDOWX/K/N,WY=WINDOWY/K/N,WW=WINDOWWIDTH/K/N,WH=WINDOWHEIGHT/K/N,
     TO/K/A

FROM=NORMAL/K/A (required, keyword required)
     The specified IFF/ILBM brush will be used for the normal image of the icon. This argument must be present in the command line.

SELECTED/K (keyword required)
     The specified IFF/ILBM brush will be used for the selected image of the icon. If present in the command line, an implicit HIGHLIGHT=IMAGE is used.

TO/K/A (required, keyword required)
     The name of the icon without the trailing .info which is appended automatically by PutDiskObject().

IW=ICONWIDTH/K/N (numeric, keyword required)
IH=ICONHEIGHT/K/N (numeric, keyword required)
     The dimensions of the icon image.  Smaller values than those of the brush(es) will use the top/left corner of the image, larger values will fill up the icon image's bottom/right border with 0's

MINSIZE/S (switch)
     If the two IFF/ILBM brushes differ in size then the resulting icon image normally has the dimensions of the larger brush. However, if the MINSIZE switch is present in the command line, the dimensions of the smaller brush are used.

TYPE/K (keyword required)
     By default, IM will use TYPE=PROJECT and create a project icon with the default tool MultiView. The TYPE parameter is parsed with the following template:

          DISK/S,DRAWER/S,TOOL/S,PROJECT/S,GARBAGE/S

HIGHLIGHT/K (keyword required)
     This argument specifies the highlighting method of the icon, i.e. what happens when the icon is selected.  If a SELECTED image is specified, then IM implicitly assumes HIGHLIGHT=IMAGE. The HIGHLIGHT parameter is parsed with the following template:

          COMPLEMENT/S,BACKFILL/S,IMAGE/S

IX=ICONX/K/N (numeric, keyword required)
IY=ICONY/K/N (numeric, keyword required)
     By default the created icon has no fix position. These two options allow an exact positioning of the created icon.

TOOLTYPES/K/M (keyword required, multiple)
     Any number of ToolTypes can be specified.  By default, IM uses

          TOOLTYPES "FILETYPE=ILBM"

STACKSIZE/K/N (numeric, keyword required)
     The default stack size for TYPE=TOOL icons.

DEFAULTTOOL/K (keyword required)
     The default tool for TYPE=PROJECT and TYPE=DISK icons.

WX=WINDOWX/K/N (numeric, keyword required)
WY=WINDOWY/K/N (numeric, keyword required)
WW=WINDOWWIDTH/K/N (numeric, keyword required)
WH=WINDOWHEIGHT/K/N (numeric, keyword required)
     The window parameters for TYPE=DRAWER, TYPE=DISK or TYPE=GARBAGE icons.

Example: Let's assume you have DOpus5 and you want to see all brushes in the Images/ and Images2/ drawer.  You simply have to do the following:

     List >RAM:doit ALL FILES DIR DOpus5:Images/ DOpus5:Images2/ +
       PAT ~(#?.info) LFORMAT "IM FROM *"%p%n*" TO *"%p%n*""

     Execute RAM:doit

By default, IM creates a project icon with the default tool MultiView and ToolType FILETYPE=ILBM.  This is what I need in most cases when using IM for the above purpose.

Bugs
====

IM does not remap the colors in your brushes to Workbench colors.  This may or may not be implemented in the future.  Please mail me if you really need such a feature.