TweetFollow Us on Twitter

Icon Capture
Volume Number:5
Issue Number:12
Column Tag:Color Workshop

Related Info: Color Quickdraw

Capture Color Icons

By Steve and Patricia Sheets, Herdon, VA

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Color Icons: Editor and cicnCapture

This month’s Color Quickdraw column consists of less talk and more code. In the last column, the building block data structures needed in order to use and understand color icons were discussed. A new Rez/Derez resource source template was given that allowed easier creation of ‘cicn’ resource (Color Icon template resource). While the template is helpful in learning and understanding color icons, and is an excellent way to present color icons on the written page, most users would prefer to use some graphic base tool to create a color icon. This column contains a quick review of the two color icon editors freely available to the development community. Then, the column will present this months source code, ‘cicnCapture’, a FKEY utility designed to capture an image on the screen and convert it to a color icon resource.

Public Domain Color Icon Editors

There are two different color icon editors available in Public Domain. The very first editor released was the application ‘CIcon Edit’ by Ben Haller of AppleSauce Designs. ‘CIcon Edit’ allows the users to edit color icons of 32 by 32 pixels size that have up to 16 separate colors. The editor can import a ‘cicn’ resource, a ‘ICON’ resource or a ‘ICN#’ resource. This feature makes the tool exceptionally good at coloring existing icon art work. ‘CIcon Edit’ itself is the easiest to use, with a good command set to manipulate the image (move, roll, flip, rotate). This tool has been around the longest (latest version I’ve seen is 1.1) and is virtually bug proof. Unfortunately, the application is lacking in certain areas. This editor is unable to edit a color icon that is any other size than 32 by 32 pixels and 16 colors. There is no method of adjusting any other settings of the resource. ‘CIcon Edit’ does not have a palette of tools (ala MacPaint); the user draws the image a pixel at a time. Also, the load command does not give a list of all the ‘cicn’ resources of the target file. Thus, the user has to keep track of all ‘cicn’ and their ID numbers himself. To be really productive with this tool, the user needs to work ResEdit.

The other PD color icon editor solves this problem by being a ResEdit extension. ‘ResWare’ by Frédéric Miserey of None Corp in Paris consists of certain resources that the user copies into his ResEdit application (replacing some existing ones). Then the user can use ResEdit directly to observe, create and edit ‘cicn’ resources. This utility is a more powerful editor then ‘CIcon Edit’. ‘ResWare’ has a complete tool palette that includes pen, eraser, fill bucket, lasso, and other rectangle commands. The editor can use single color patterns when drawing. There is no practical limit to the size of the color icon, nor the number of colors. Also the editor allows the user to change other portions of the ‘cicn’ resource including horizontal and vertical size, component count, component size and pixmap method (Chunky, Chunky/Planar or Planar). However the editor is still in beta form (latest version I’ve seen is 1.0b4) and has caused numerous crashes. ‘ResWare’ has no import feature, and the editor, while more powerful, is not as easy to use for beginners as ‘CIcon Edit’.

Importing Images into Color Icons

While both editors are useful in creating color icons, they both suffer from a common fault. They do not allow easy import of an image on the screen into a ‘cicn’ resource. At first, it may not seem as if this is a problem. Of course, the editor will only be used to create a ‘cicn’ resource. However, this is not always the case. Look at what happened with original Quickdraw and the creation of ‘ICON’ and ‘ICN#’ resources. Even though there were a few icon editors, many non-technical users created their images with the more powerful Paint and Draw programs. Then they handed the complete art work to a programmer, expecting him to be able to use it directly. The programmer had no way to directly transfer an art document into a ‘ICON’ or ‘ICN#’ resource. In many cases, the programmer had to reenter the image into the icon editor one pixel at a time. To solve this problem, many programmers created various Icon-Grapper types of utilities. These utilities, usually Desk Accessories or FKEYs, allowed the programmer to capture any portion of the screen and convert it into an icon resource. Since it captured an image on the screen and did not need to directly convert any type of document, these utilities would work with any Paint or Draw application.

A user who wanted to convert a Pixel Paint or MacDraw // image into a ‘cicn’ resource would have the identical problem. The problem is further complicated, since the user would have to worry not only about the 32 by 32 pixel image, but would have to import a color list, a mask and a black and white icon. I had this problem. The graphic designer of my latest project presented the technical team with a group of Pixel Paint files, each one having a dozen or so images on it. It would have taken hours of work to reenter the images using one of the color icon editors. That estimate was assuming that the artwork was the finished product, and not going to be revised. This started looking like a potential nightmare.

cicnCapture

The solution to this problem is being provided as the sample source code. ‘cicnCapture’ is an FKEY utility that can capture a 32 by 32 pixel image of the screen, containing up to 256 different colors, and create a ‘cicn’ resource that contains this image. The code uses the Quickdraw call, GetCPixel, to determine the color of each pixel in the image. Since the code uses this call instead of reading the screen PixMap directly, it will work on any depth or type of screen or monitor as long as Color Quickdraw is installed. Once the image has been captured, the information is saved out to a specified resource file.

Using this utility on our software project, it took a few minutes to import all of the color images into ‘cicn’ resource. ‘CIcon Edit’ and ‘ResEdit’ were used afterward, but mainly to make sure the images had the correct ID number, and that they were centered on the 32 by 32 pixel icon.

Next Column

Anyone remember the game, ‘Daleks’? This application was one of the first, and best, Public Domain games around. Next issue’s sample code will be ‘Color Daleks’. The program will show how to directly draw and manipulate color icons. Various color drawing modes will be explained, as well as some animation speed up tricks.

{cicnCapture-  Color Icon Capture FKEY }
{by Steve Sheets for MacTutor 9/3/89 }
{FKEY is normal saved to resource type ‘FKEY’, ID = 7 }
{This FKEY captures a 32 by 32 Pixel section of the screen and converts 
it into a ‘cicn’ resource (Color Icon }
{template).   When the user activates the Function Key and click somewhere 
on the screen, that portion of the }
{screen is recorded (colors and pixels) and a cicn handle is created. 
 Remember a cicn handle is different than }
{an actual Color Icon handle. The cicn handle/resoure is a template for 
a Color Icon.  The Color Quickdraw }
{command, GetCIcon, uses the cicn resource to determine how to make a 
Color Icon. }
{FKEY is written in Think’s Lightspeed Pascal 2.0. }

unit cicnCapture;

interface

 uses
 Quickdraw, ToolIntf;

{FKEY (function key) code resources must have be an unit with a single 
externally reference procedure called }
{‘Main’.}

 procedure Main;

implementation

 procedure Main;

{The ‘cicn’ resource consists of three variable length parts.  The first 
part contains the Pixmap info, the Black }
{& White Icon and the Mask.   The second part contains the Color Lookup 
table (ie. list of colors used in the }
{cicn).  The size of this part is dependent on the number of different 
colors in the cicn.  The last part of the }
{resource is the pixel data.  The size of this is dependent on the number 
of different colors in the cicn.  If }
{there are 2 to 16 colors, the pixel info can be stored in a 4 bit pixel 
maip, if the number of colors is 17 to }
{256, then the info must be stored in a 8 bit pixel map.  Given the fact 
this FKEY only captures 32 by 32 cicn, }
{the size of the first part is fixed, while the size of the third part 
is one of two possible fixed sizes. }

 type
 IconData = packed array[0..31] of LongInt;

{First part of cicn resource for a 32 by 32 pixel cicn.}

 cicnData = record
 baseAddr: LongInt;
 rowbytes: INTEGER;
 bounds: Rect;
 pmVersion: INTEGER;
 packType: INTEGER;
 packSize: LongInt;
 hRes: LongInt;
 vRes: LongInt;
 pixelType: INTEGER;
 pixelSize: INTEGER;
 cmpCount: INTEGER;
 cmpSize: INTEGER;
 planeBytes: LongInt;
 pmTable: LongInt;
 pmReserved: LongInt;

 MaskBaseAddr: LongInt;
 MaskRowBytes: INTEGER;
 MaskBounds: Rect;

 BMapBaseAddr: LongInt;
 BMapRowBytes: INTEGER;
 BMapBounds: Rect;

 IconData: LongInt;

 theMask: IconData;

 theBMap: IconData;

 ctSeed: LongInt;
 ctFlags: INTEGER;
 ctSize: INTEGER;
 end;
 cicnPtr = ^cicnData;

{2nd part (CLUT) of cicn resource for 32 by 32 pixel cicn. }

 CTableData = packed array[0..255] of ColorSpec;
 CTablePtr = ^CTableData;

{3rd part of cicn resource for 8 bit, 32 by 32 pixel cicn. }

 pixel8Data = packed array[0..31, 0..31] of 0..255;
 pixel8Ptr = ^pixel8Data;

{3rd part of cicn resource for 4 bit, 32 by 32 pixel cicn. }

 pixel4Data = packed array[0..31, 0..15] of 0..255;
 pixel4Ptr = ^pixel4Data;

 var
 thePos: Point;
 thePixel8: pixel8Data;
 theNumColors: INTEGER;
 theIcon: IconData;
 theColorList: packed array[0..255] of RGBColor;
 theCICN: Handle;

{Tell us if Color Quickdraw is installed on machine. }

 function IsColorQuickdraw: BOOLEAN;
 const
 ROM85Loc = $28E;
 TwoHighMask = $C000;
 type
 WordPtr = ^INTEGER;
 var
 Wd: WordPtr;
 begin
 Wd := POINTER(ROM85Loc);
 IsColorQuickdraw := (BitAnd(Wd^, TwoHighMask) = 0);
 end;

{Sets cursor to show an upper left portion of a square.}

 procedure InitSquare;
 var
 count: INTEGER;
 Square: Cursor;
 begin
 with Square do
 begin
 data[0] := $FFFF;
 mask[0] := 0;
 for count := 1 to 15 do
 begin
 data[count] := $8000;
 mask[count] := 0;
 end;
 hotSpot.v := 0;
 hotspot.h := 0;
 end;
 SetCursor(Square);
 end;

{Wait until the user presses the mouse, making sure the mouse was not 
pressed to begin with.  Then stores}
{the postion of the mouse and flushes the mouse events. }

 procedure GetPos;
 begin
 while button do
 ;
 while not button do
 ;
 GetMouse(thePos);
 FlushEvents(mDownMask + mUpMask, 0);
 end;

{Given the position of the mouse, captures a 32 by 32 array of pixels 
and a list of the colors.  The}
{pixel information is not stored as RGB values, but as a number (zero 
count) that represents that }
{RGB value in the Color List (ie. value of 2 equals third color in list). 
 Thus every time a pixel on }
{the screen is looked at with the GetCPixel command, that RGB value is 
looked for in the Color List. }
{If the color is found, that number is stored in the 2 dimensional pixel 
array.  If the pixel uses a }
{new RGB color (not found in the list), that color is added to the list. 
 The number that represents }
{that new color is stored in the pixel array.  This way, at the end, 
the program knows exactly what}
{colors are used.  The code does not care about the depth of the screen 
(1, 2, 4, 8, 16 or 24 bits}
{per pixels).  However this cicn resource uses the Chunky model, thus 
only 256 colors can be used }
{(fairly safe limit).  The list will always contain black and white as 
the first two colors in the list.  }
{This procedure also creates a black and white 32 by 32 bit icon for 
the mask and the Black and}
{White icon portion of the cicn.  Any color other than white indicates 
a black bit.}

 procedure GetPixels;
 var
 h, v, theNum, count: INTEGER;
 theColor: RGBColor;
 begin
 theNumColors := 1;
 with theColorList[0] do
 begin
 red := $FFFF;
 green := $FFFF;
 blue := $FFFF;
 end;
 with theColorList[1] do
 begin
 red := 0;
 green := 0;
 blue := 0;
 end;
 for v := 0 to 31 do
 begin
 theIcon[V] := 0;
 for h := 0 to 31 do
 begin
 GetCPixel(thePos.h + h, thePos.v + v, theColor);
 theNum := -1;
 for count := 0 to theNumColors do
 if (theColor.red = theColorList[count].red) then
 if (theColor.green = theColorList[count].green) then
 if (theColor.blue = theColorList[count].blue) then
 theNum := count;
 if (theNum = -1) and (theNumColors < 255) then
 begin
 theNumColors := theNumColors + 1;
 theNum := theNumColors;
 theColorList[theNum] := theColor;
 end;
 thePixel8[v, h] := (theNum mod 256);
 if (theColor.red <> -1) or (theColor.green <> -1) or (theColor.blue 
<> -1) then
 BitSet(@theIcon[V], h);
 end;
 end;
 end;

{Having pixel infor, allocates memmory for cicn handle.}

 procedure MakeCICN;
 var
 theCICNptr: cicnPtr;
 theCTablePtr: CTablePtr;
 thePixel8Ptr: Pixel8Ptr;
 the4PixelPtr: Pixel4Ptr;
 theRect: Rect;
 count, v, h, theTableSize, theImageRowBytes, theBitsPixel, thePixelDataSize: 
INTEGER;
 begin
 SetRect(theRect, 0, 0, 32, 32);

{If number of colors is more than 16, then use 8 bit pixel map, else 
use 4 bit pixelmap (Rowbytes of pixmap is }
{diffent, bit depth is different, size of pixel data is different).  
Notice that Rowbytes must have the high bit }
{set.}

 if (theNumColors > 16) then
 begin
 theBitsPixel := 8;
 theImageRowBytes := $8020;
 thePixelDataSize := SizeOf(pixel8Data);
 end
 else
 begin
 theBitsPixel := 4;
 theImageRowBytes := $8010;
 thePixelDataSize := SizeOf(pixel8Data) div 2;
 end;
 theTableSize := (theNumColors + 1) * SizeOf(ColorSpec);

{Allocate size of handle (dependent on number of colors & 4 or 8 bit 
pixelmap. }

 theCICN := NewHandle(SizeOf(cicnData) + theTableSize + thePixelDataSize);
 HLock(theCICN);
 theCICNptr := POINTER(theCICN^);

{Stuff first part of cicn handle.  }

 with theCICNptr^ do
 begin
 baseAddr := 0;
 rowbytes := theImageRowBytes;
 bounds := theRect;
 pmVersion := 0;
 packType := 0;
 packSize := 0;
 hRes := $00480000;
 vRes := $00480000;
 pixelType := 0;
 pixelSize := theBitsPixel;
 cmpCount := 1;
 cmpSize := theBitsPixel;
 planeBytes := 0;
 pmTable := 0;
 pmReserved := 0;

 MaskBaseAddr := 0;
 MaskRowBytes := 4;
 MaskBounds := theRect;

 BMapBaseAddr := 0;
 BMapRowBytes := 4;
 BMapBounds := theRect;

 IconData := 0;

 theMask := theIcon;

 theBMap := theIcon;

 ctSeed := 0;
 ctFlags := 0;
 ctSize := theNumColors;
 end;

{Stuff second part, the Color Look Up table (color list).}

theCTablePtr := POINTER(ORD4(theCICNptr) + SizeOf(CICNData));

 for count := 0 to theNumColors do
 with theCTablePtr^[count] do
 begin
 value := count;
 rgb := theColorList[count];
 end;

{Stuff the third part of the cicn handle, the actual pixmap data.  If 
an 8 bit pixmap is used, the format of }
{the data is identical to the array used to store the pixel information 
so the data is simply moved into the }
{handle.  If the pixmap is a 4 bit one, the pixel info is moved into
 another array that has the format of a 4 }
{bit pixmap data, then that data moved into the handle. }

 if (theNumColors > 15) then
 begin
 thePixel8Ptr := POINTER(ORD4(theCTablePtr) + theTableSize);
 thePixel8Ptr^ := thePixel8;
 end
 else
 begin
 the4PixelPtr := POINTER(ORD4(theCTablePtr) + theTableSize);
 for v := 0 to 31 do
 for h := 0 to 15 do
 the4PixelPtr^[v, h] := ((thePixel8[v, (h * 2)] * 16) + thePixel8[v, 
(h * 2) + 1]) mod 256;
 end;

 HUnLock(theCICN);
 end;

{Given a cicn handle, store it into a resource file (new or existing 
one) as a ‘cicn’ resource.}

 procedure SaveCICN;
 var
 theWhere: Point;
 theRef, theVol: INTEGER;
 theE: OSErr;
 theReply: SFReply;
 begin
 theWhere.h := 40;
 theWhere.v := 40;
 SFPutFile(theWhere, ‘Save Color Icon to File:’, ‘cicn File’, nil, theReply);
 if theReply.good then
 begin
 theE := GetVol(nil, theVol);
 theE := SetVol(nil, theReply.vRefNum);
 theRef := OpenResFile(theReply.fName);
 if theRef = -1 then
 begin
 CreateResFile(theReply.fname);
 theRef := OpenResFile(theReply.fname);
 end;

 if theRef <> -1 then
 begin
 AddResource(theCICN, ‘cicn’, UniqueID(‘cicn’), ‘’);
 WriteResource(theCICN);
 ReleaseResource(theCICN);
 theCICN := nil;

 CloseResFile(theRef);
 end;
 theE := SetVol(nil, theVol);
 end;
 if theCICN <> nil then
 begin
 DisposHandle(theCICN);
 SysBeep(1);
 end;
 end;

{Main Procedure.  If there is Color Quickdraw, init the cursor to a square, 
get the position of the mouse when the }
{user clicks, the pixels at that position, convert pixels into a cicn 
handle, save the cicn handle to a resource and }
{finally reset the cursor back to an arrow.  If there is not Color Quickdraw 
on the machine, complain! }
 begin
 if IsColorQuickdraw then
 begin
 InitSquare;
 GetPos;
 GetPixels;
 MakeCICN;
 SaveCICN;
 InitCursor;
 end
 else
 SysBeep(1);
 end;
end.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.