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

Call of Duty Warzone is a Waiting Simula...
It's always fun when a splashy multiplayer game comes to mobile because they are few and far between, so I was excited to see the notification about Call of Duty: Warzone Mobile (finally) launching last week and wanted to try it out. As someone who... | Read more »
Albion Online introduces some massive ne...
Sandbox Interactive has announced an upcoming update to its flagship MMORPG Albion Online, containing massive updates to its existing guild Vs guild systems. Someone clearly rewatched the Helms Deep battle in Lord of the Rings and spent the next... | Read more »
Chucklefish announces launch date of the...
Chucklefish, the indie London-based team we probably all know from developing Terraria or their stint publishing Stardew Valley, has revealed the mobile release date for roguelike deck-builder Wildfrost. Developed by Gaziter and Deadpan Games, the... | Read more »
Netmarble opens pre-registration for act...
It has been close to three years since Netmarble announced they would be adapting the smash series Solo Leveling into a video game, and at last, they have announced the opening of pre-orders for Solo Leveling: Arise. [Read more] | Read more »
PUBG Mobile celebrates sixth anniversary...
For the past six years, PUBG Mobile has been one of the most popular shooters you can play in the palm of your hand, and Krafton is celebrating this milestone and many years of ups by teaming up with hit music man JVKE to create a special song for... | Read more »
ASTRA: Knights of Veda refuse to pump th...
In perhaps the most recent example of being incredibly eager, ASTRA: Knights of Veda has dropped its second collaboration with South Korean boyband Seventeen, named so as it consists of exactly thirteen members and a video collaboration with Lee... | Read more »
Collect all your cats and caterpillars a...
If you are growing tired of trying to build a town with your phone by using it as a tiny, ineffectual shover then fear no longer, as Independent Arts Software has announced the upcoming release of Construction Simulator 4, from the critically... | Read more »
Backbone complete its lineup of 2nd Gene...
With all the ports of big AAA games that have been coming to mobile, it is becoming more convenient than ever to own a good controller, and to help with this Backbone has announced the completion of their 2nd generation product lineup with their... | Read more »
Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »
Live, Playdate, Live! – The TouchArcade...
In this week’s episode of The TouchArcade Show we kick things off by talking about all the games I splurged on during the recent Playdate Catalog one-year anniversary sale, including the new Lucas Pope jam Mars After Midnight. We haven’t played any... | Read more »

Price Scanner via MacPrices.net

Deal Alert! B&H Photo has Apple’s 14-inch...
B&H Photo has new Gray and Black 14″ M3, M3 Pro, and M3 Max MacBook Pros on sale for $200-$300 off MSRP, starting at only $1399. B&H offers free 1-2 day delivery to most US addresses: – 14″ 8... Read more
Department Of Justice Sets Sights On Apple In...
NEWS – The ball has finally dropped on the big Apple. The ball (metaphorically speaking) — an antitrust lawsuit filed in the U.S. on March 21 by the Department of Justice (DOJ) — came down following... Read more
New 13-inch M3 MacBook Air on sale for $999,...
Amazon has Apple’s new 13″ M3 MacBook Air on sale for $100 off MSRP for the first time, now just $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD/Space Gray): $999 $100 off MSRP... Read more
Amazon has Apple’s 9th-generation WiFi iPads...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Discounted 14-inch M3 MacBook Pros with 16GB...
Apple retailer Expercom has 14″ MacBook Pros with M3 CPUs and 16GB of standard memory discounted by up to $120 off Apple’s MSRP: – 14″ M3 MacBook Pro (16GB RAM/256GB SSD): $1691.06 $108 off MSRP – 14... Read more
Clearance 15-inch M2 MacBook Airs on sale for...
B&H Photo has Apple’s 15″ MacBook Airs with M2 CPUs (8GB RAM/256GB SSD) in stock today and on clearance sale for $999 in all four colors. Free 1-2 delivery is available to most US addresses.... Read more
Clearance 13-inch M1 MacBook Airs drop to onl...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray, Silver, & Gold) in stock and on clearance sale today for $300 off MSRP, only $699. Free 1-2 day shipping is available to most addresses in... Read more
New promo at Visible: Buy a new iPhone, get $...
Switch to Visible, and buy a new iPhone, and Visible will take $10 off their monthly Visible+ service for 24 months. Visible+ is normally $45 per month. With this promotion, the cost of Visible+ is... Read more
B&H has Apple’s 13-inch M2 MacBook Airs o...
B&H Photo has 13″ MacBook Airs with M2 CPUs and 256GB of storage in stock and on sale for $100 off Apple’s new MSRP, only $899. Free 1-2 day delivery is available to most US addresses. Their... Read more
Take advantage of Apple’s steep discounts on...
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

Jobs Board

Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple 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
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Business Analyst | *Apple* Pay - Banco Popu...
Business Analyst | Apple PayApply now " Apply now + Apply Now + Start applying with LinkedIn Start + Please wait Date:Mar 19, 2024 Location: San Juan-Cupey, PR Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.