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... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.