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

The secrets of Penacony might soon come...
Version 2.2 of Honkai: Star Rail is on the horizon and brings the culmination of the Penacony adventure after quite the escalation in the latest story quests. To help you through this new expansion is the introduction of two powerful new... | Read more »
The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »

Price Scanner via MacPrices.net

Sunday Sale: Apple Studio Display with Standa...
Amazon has the standard-glass Apple Studio Display on sale for $300 off MSRP for a limited time. Shipping is free: – Studio Display (Standard glass): $1299.97 $300 off MSRP For the latest prices and... Read more
Apple is offering significant discounts on 16...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more
Apple HomePods on sale for $30-$50 off MSRP t...
Best Buy is offering a $30-$50 discount on Apple HomePods this weekend on their online store. The HomePod mini is on sale for $69.99, $30 off MSRP, while Best Buy has the full-size HomePod on sale... Read more
Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more

Jobs Board

Licensed Practical Nurse - Womens Imaging *A...
Licensed Practical Nurse - Womens Imaging Apple Hill - PRN Location: York Hospital, York, PA Schedule: PRN/Per Diem Sign-On Bonus Eligible Remote/Hybrid Regular Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Operating Room Assistant - *Apple* Hill Sur...
Operating Room Assistant - Apple Hill Surgical Center - Day Location: WellSpan Health, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.