+ /* Clone the clut if indexed color; allocate a dummy clut if direct color*/
+ if (depth <= 8)
+ {
+ newColors = colors;
+ error = HandToHand((Handle *) &newColors);
+ }
+ else
+ {
+ newColors = (CTabHandle) NewHandle(sizeof(ColorTable) -
+ sizeof(CSpecArray));
+ error = MemError();
+ }
+ if (error == noErr)
+ {
+ /* Allocate pixel image; long integer multiplication avoids overflow */
+ (**icon).iconData = NewHandle((unsigned long) bytesPerRow * (bounds->bottom -
+ bounds->top));
+ if ((**icon).iconData != nil)
+ {
+ /* Initialize fields common to indexed and direct PixMaps */
+ (**icon).iconPMap.baseAddr = 0; /* Point to image */
+ (**icon).iconPMap.rowBytes = bytesPerRow | /* MSB set for PixMap */
+ 0x8000;
+ (**icon).iconPMap.bounds = *bounds; /* Use given bounds */
+ (**icon).iconPMap.pmVersion = 0; /* No special stuff */
+ (**icon).iconPMap.packType = 0; /* Default PICT pack */
+ (**icon).iconPMap.packSize = 0; /* Always zero in mem */
+ (**icon).iconPMap.hRes = kDefaultRes; /* 72 DPI default res */
+ (**icon).iconPMap.vRes = kDefaultRes; /* 72 DPI default res */
+ (**icon).iconPMap.pixelSize = depth; /* Set # bits/pixel */
+
+ /* Initialize fields specific to indexed and direct PixMaps */
+ if (depth <= 8)
+ {
+ /* PixMap is indexed */
+ (**icon).iconPMap.pixelType = 0; /* Indicates indexed */
+ (**icon).iconPMap.cmpCount = 1; /* Have 1 component */
+ (**icon).iconPMap.cmpSize = depth; /* Component size=depth */
+ (**icon).iconPMap.pmTable = newColors; /* Handle to CLUT */
+ }
+ else
+ {
+ /* PixMap is direct */
+ (**icon).iconPMap.pixelType = RGBDirect; /* Indicates direct */
+ (**icon).iconPMap.cmpCount = 3; /* Have 3 components */
+ if (depth == 16)
+ (**icon).iconPMap.cmpSize = 5; /* 5 bits/component */
+ else
+ (**icon).iconPMap.cmpSize = 8; /* 8 bits/component */
+ (**newColors).ctSeed = 3 * (**icon).iconPMap.cmpSize;
+ (**newColors).ctFlags = 0;
+ (**newColors).ctSize = 0;
+ (**icon).iconPMap.pmTable = newColors;
+ }
+ }
+ else
+ error = MemError();
+ }
+ else
+ newColors = nil;