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

Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Netflix Games expands its catalogue with...
It is a good time to be a Netflix subscriber this month. I presume there's a good show or two, but we are, of course, talking about their gaming service that seems to be picking up steam lately. May is adding five new titles, and there are some... | Read more »
Pokemon Go takes a step closer to real P...
When Pokemon Go was first announced, one of the best concepts of the whole thing was having your favourite Pokemon follow you in the real world and be able to interact with them. To be frank, the AR Snapshot tool could have done a lot more to help... | Read more »
Seven Knights Idle Adventure drafts in a...
Seven Knights Idle Adventure is opening up more stages, passing the 15k mark, and players may find themselves in need of more help to clear these higher stages. Well, the cavalry has arrived with the introduction of the Legendary Hero Iris, as... | Read more »
AFK Arena celebrates five years of 100 m...
Lilith Games is quite the behemoth when it comes to mobile games, with Rise of Kingdom and Dislyte firmly planting them as a bit name. Also up there is AFK Arena, which is celebrating a double whammy of its 5th anniversary, as well as blazing past... | Read more »
Fallout Shelter pulls in ten times its u...
When the Fallout TV series was announced I, like I assume many others, assumed it was going to be an utter pile of garbage. Well, as we now know that couldn't be further from the truth. It was a smash hit, and this success has of course given the... | Read more »
Recruit two powerful-sounding students t...
I am a fan of anime, and I hear about a lot that comes through, but one that escaped my attention until now is A Certain Scientific Railgun T, and that name is very enticing. If it's new to you too, then players of Blue Archive can get a hands-on... | Read more »
Top Hat Studios unveils a new gameplay t...
There are a lot of big games coming that you might be excited about, but one of those I am most interested in is Athenian Rhapsody because it looks delightfully silly. The developers behind this project, the rather fancy-sounding Top Hat Studios,... | Read more »
Bound through time on the hunt for sneak...
Have you ever sat down and wondered what would happen if Dr Who and Sherlock Holmes went on an adventure? Well, besides probably being the best mash-up of English fiction, you'd get the Hidden Through Time series, and now Rogueside has announced... | Read more »
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 »

Price Scanner via MacPrices.net

Apple Studio Display with Standard Glass on s...
Best Buy has the standard-glass Apple Studio Display on sale for $300 off MSRP for a limited time. Their price is the lowest available for a Studio Display among Apple’s retailers. Shipping is free... Read more
AirPods Max headphones back on sale for $449,...
Amazon has Apple AirPods Max headphones in stock and on sale for $100 off MSRP, only $449. The sale price is valid for all colors at the time of this post. Shipping is free: – AirPods Max: $449.99 $... Read more
Deal Alert! 13-inch M2 MacBook Airs on record...
Amazon has 13″ MacBook Airs with M2 CPUs in stock and on sale this week for only $829 in Space Gray, Silver, Starlight, and Midnight colors. Their price is $170 off Apple’s MSRP, and it’s the lowest... Read more
Apple Watch Ultra 2 on sale for $50 off MSRP
Best Buy is offering Apple Watch Ultra 2 models for $50 off MSRP on their online store this week. Sale prices available for online orders only, in-store prices may vary. Order online, and choose free... Read more
Apple introduces the new M4-powered 11-inch a...
Today, Apple revealed the new 2024 M4 iPad Pro series, boasting a surprisingly thin and light design that pushes the boundaries of portability and performance. Offered in silver and space black... Read more
Apple introduces the new 2024 11-inch and 13-...
Apple has unveiled the revamped 11-inch and brand-new 13-inch iPad Air models, upgraded with the M2 chip. Marking the first time it’s offered in two sizes, the 11-inch iPad Air retains its super-... Read more
Apple discontinues 9th-gen iPad, drops prices...
With today’s introduction of the new 2024 iPad Airs and iPad Pros, Apple has (finally) discontinued the older 9th-generation iPad with a home button. In response, they also dropped prices on 10th-... Read more
Apple AirPods on sale for record-low prices t...
Best Buy has Apple AirPods on sale for record-low prices today starting at only $79. Buy online and choose free shipping or free local store pickup (if available). Sale price for online orders only,... Read more
13-inch M3 MacBook Airs on sale for $100 off...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices, along with Amazon’s, are the lowest currently available for new 13″... Read more
Amazon is offering a $100 discount on every 1...
Amazon has every configuration and color of Apple’s 13″ M3 MacBook Air on sale for $100 off MSRP, now starting at $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD): $999 $100 off... Read more

Jobs Board

Retail Assistant Manager- *Apple* Blossom Ma...
Retail Assistant Manager- APPLE BLOSSOM MALL Brand: Bath & Body Works Location: Winchester, VA, US Location Type: On-site Job ID: 04225 Job Area: Store: Management Read more
Licensed Practical Nurse - Womens Imaging *A...
Licensed Practical Nurse - Womens Imaging Apple Hill - Full time Location: York Hospital, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Read more
IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: May 8, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
Nurse Anesthetist - *Apple* Hill Surgery Ce...
Nurse Anesthetist - Apple Hill Surgery Center Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
LPN-Physician Office Nurse - Orthopedics- *Ap...
LPN-Physician Office Nurse - Orthopedics- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.