Showing posts with label clip2. Show all posts

Ressurection #

This was the first program that I released publically, it's a simple tool to insert 'cicn' (color icon) resources into Kaleidoscope schemes (Kaleidoscope uses 'cicn's as its primary storage method, and the editor that ResEdit provides is limited (can't create icons with a size bigger than 64 x 64, can't import custom color tables) and broken (it thinks resources with a size above 32K are corrupted), so I made this free insertion tool (this is all happened in the beginning of the summer of 1998). Since then it had been pretty much left alone, since it seemed to cover everyone's needs, and as a freeware niche product it had no competition and I had no incentive to add features. After I had finished the initial work on Icon Mangler (as Iconographer was then known) I decided that it had fallen behind enough that it needed an upgrade (I had created a similar program, clip2icns, designed to insert and extract 32-bit icons, this one was shareware and did have competition so it was updated more often), so I merged the source code, so that it could have the UI-style that I had create for clip2icns. I had started on this in April, but got distracted after a few days, and forgot about the whole program until I got back from Stanford in August. Then someone asked me if I could fix a bug in it, and I realized that the new version that I had been working on had that fixed, so I finished it up and released it. I had thought that this would have been the end of it, especially since I gave the source code to some else who was working on a full Kaleidoscope editor.

Then last week someone contacted me about adding a feature (extracting 'cicn's to the clipboard, essentially the opposite of the current command which took the clipboard and put it in a 'cicn' resource). Considering that clip2icns already had a similar feature, and that Iconographer included full copy and paste support, I figured that I knew enough about the Scrap Manager (that's what's used to manage the clipboard) to do this. I opened up the clip2cicn CodeWarrior and its associated resource file, and added an Extract button to the dialog (this required a reorganization of the dialog layout, since it was getting rather wide) and then the relevant code so that it would beep when clicked (as a place holder for the eventual cicn2clip funnction). Then when I tried to compile and run it, I discovered that I got all these errors about functions that didn't exist in my commonFunctions.c shared file. Then I remembered that I had begun to convert my code to Carbon (which makes some structures, e.g. dialogs and controls), and so some of those functions didn't work with the standard Toolbox. In the end I had to create a special version of the Universal Headers (I have them precompiled so compile times are faster) with the Carbon flags turned off, and include that in clip2cicn. After this little hidrance, I implemented a basic version of the cicn2clip function. My main problem was that the resource contained a normal PixMap, but I couldn't use CopyBits with it, since the pointer to the pixel data was screwed up (when the PixMap is stored, the pointer becomes meaningless, since chances are very small that it'll be loaded in the exact same location in memory). I used the function PlotCIcon to draw it into a 32-bit GWorld, and the exported that to the clipboard. I sent off the new version to the user who had requested the feature, and he liked it, except that I wasn't extracting the custom color table. In the end I figured out how to fix the pixel data pointer (the 'cicn' handle included a part where the icon data was stored, so I set the pointer to the address of the resource plus the offset to the pixel data), and did a CopyBits straight from the icon into the picture I was putting in the clipboard, and that seems to work perfectly. Another user also asked me to fix/add some IDs in the pop-up menus I provide for the easy selection of the 'cicn' that should be inserted/extracted, so I did that too.

And now that I think about it the person I gave the source code to still hasn't done anything with it. I guess the moral of this long-winded, not-very-interesting story is that you should never throw any code away, or give up any project for dead.

clip2icns pre-8.5 Hacking #

(argh, I've written this before, but I crashed, so I have to do it again)

Not much time for coding (big history rough draft was due, among other things). Major thing that happened was that I found (well, some users found, and they were registered so I had to pay attention) that clip2icns refused to work under pre 8.5 systems. It took me about a week to figure out why. The actual crash occured when I disposed of a PixMap in the Make1BitMask function. By selectively commenting out lines I had traced it to the call to CalcCMask (a system function). I beat my head against this for a few days, trying many things (including copying the source to a local PixMap, locking the source/target (again), taking out the customized color search function from CalcCMask, and other stuff). In the end I did a search at DejaNews (an archive of Usenet postings, including comp.sys.mac.programmer.*) and found my answer. It turns out that CalcCMask wants a real BitMap* for the target parameter. I was used to CopyBits, which also wants a BitMap*, but a casted PixMap* works too. Apparently this was changed in Mac OS 8.5, which is why I didn't happen while I was developing the function. And I didn't notice it before since I had used a different method of determining the mask (a much uglier one, which had been inhereted from clip2cicn, the first real (as in distributed) mac program I did, back in early June).

I also had to do a workaround, this time for a documented bug (which was fixed in Mac OS 8.5). Apparently calling CopyDeepMask when the target is a 8 bit (or less) GWorld will yield nothing in it. What I had to do was to use a temporary 32 bit GWorld which I then transferred to the 8 bit by using CopyBits. All of this went into clip2icns 1.5.1. Speaking of clip2icns, the number of registrations has topped 50, so I'm halfway to my (just established) goal of 100.

Doc Day #

Didn't get that much work done today, but I did finish the documentation and the default glyph set for Glypher. I also sent final version of the new clip2icns (1.5) and Glypher (1.0) to the beta testers, and unless major issues show up they will be released Monday.

clip2icns Reloaded #

Today I worked on redoing the interface for clip2icns. Until now the insertion dialog was modal, and after you inserted an icon it would get dismissed. So if you were trying to put more than a few icons into the same file it would get very annoying, since you had to keep choosing the file, and go to the proper ID in the menus. So I made the dialog movable (using the experience I gained from the Icon Browser in Icon Mangler), and made it so that the dialog would stay there until you clicked on the close button. Now when you want to insert more than one icon you can move switch back and forth, and not have to select the file every time, since the insertion dialog stays open. I also combined this dialog with the extraction one, since they shared 90% of the resources. Finally I added two more preference options, dithering (used when making the lower bit depths) can be turned on and off, and there is a setting to remember the last selected ID in the pop-up menu. Even though I added all these features, the source code is now 400 lines smaller (and I replaced the ugly macro that I was using for handling refreshes in the dialog with a much nicer function). I wish this could be done for all programs :p

Blast From The Past #

no work done today, other than some minor tweaks to clip2cicn, to bring it up to speed with the newest resources in the latest version of Kaleidoscope. There's a long standing bug in it which causes the last couple of pixels come up as weird colors once in a while. I've been looking into fixing it, but no luck so far...

Puzzling Refreshes #

glypher/icns class: Improved saving of the icns. If the user doesn't specify a small size, rather than generating it and saving that too, I'm going just save the large version, and let the Finder do the interpolation of the small one. Same thing when the large size isn't specified. I've also added handling of icns which only contain one size to the display function. Also cleaned up the loading code, split it up into two functions (one for loading from the icns resource, and one from loading from the old style icons, if the icns isn't present).

The messiest part of glypher (and clip2icns too) is the handling of refreshes for dialogs. Right now I have this macro set up, which is called in the beginning, when the user chooses something from a menu or when an ID is typed in. But the macro is really ugly because it's not meant to have line breaks, so I have to put in a back slash at the end of each line. Plus it's impossible to debug, since it all gets put together in one line (the backslash makes the compiler ignore the line break after it). The only reason why I didn't make it a function was because I'm using so many local variables, so passing them as parameters would be a pain. The only think I can think of right now would be to make the whole dialog handling a class, and make the refresh a function of it, and then I can just access some variables within the class. But that's really misusing classes, since each class would have to be specialized for it's particular dialog, so reuse would be kinda of hard. Perhaps I could make a generic class using inheritance, but I think that's overkill. Hopefully I'll figure something out by the time I have to make the icon editor (although there each editing window will be a class in it's own, and since I can have many of them then I'm using the class in many places, so there's no misuse).

Glypher: The Program Ra Would Endorse #

glypher: I think I know what I'll do for the icon, a hieroglyph. Did some test designs, but nothing seems to really work.

Sync-ing it Up #

glyher: I've converted the old source code (which was a few revisions behind the clip2icns one) to making it use the icns class that I developed. That way it got automatic access to the compression/decompression routines, the clipboard importing/exporting, and anything else that I might add in the future. Now I just have bring in all the other bug fixes and the registration code (although I think that I'll just make it free to clip2icns users, perhaps even make it check for the existence of the other's preference file, and make sure it contains a valid serial number/name).

Ladies and Gentlemen: Mscape Software! #

clip2icns: this program was announced on macintouch today (I've made a separate page for it at http://www.mscape.com/ (Mscape Software, my so called company)).

On the Mscape page, I also showed a preview of badger, my system folder icon generator. I got this mail from a company saying that the name was already in use. Apparently they have a photo ID system called Badger (available at http://www.badges.com/). I'm probably going to change the name to Glypher.

Attention Is Divided #

clip2icns: removed some flickering when chaging the menu (I'm not changing it unnecessarely). Also added input checking for the ID.

did the towers of hanoi recusrsion exercise. I ended up making a class, ringStack, with a few functions like TakeTopPiece and AddPiece, and using the sample recursion algorithm.

icon mangler: I think I know how I'll implement the basic framework for the editor. I'll make a new class, icnsEditor, make it inherit the stuff from the icns class I've already done. When the user selects open or new icon, I can make a new instance of it, and keep them all together in a linked list.

Creepin' Featurism #

clip2icns: fixed a very minor bug which caused the OK button not to be enabled and disabled properly. This was caused by the fact that I was opening a file, checking for the existence of a resource, enabling/disabling the button according to that result, and then closing the file. Closing the file before changing the button fixed it. I guess the dialog resource got purged from memory when the file was openened, and when it tried to redraw it, it couldn't because it couldn't get the button description.

I've made it so that when the user types in the ID, it selects the proper item in the menu, and it previews it too. I guess I'm starting to get "feature creep", I think it's time to move on to the real project, the icon editor (although in a way I've already been workin on in (ie on the icns class))

Preferentially Yours #

clip2icns: Tried to get the search function to work. I had this variable called IDLength in which I was trying to store the length of a string. Well, it was totally skipping that line. Changing the order doesn't help. In the end changing the name did it. Another weird thing is that I was using GetMenuHandle to access the menu, but that kept returning NULL. When I changed that to Get1Resource (and did a type cast of the result to MenuHandle) it worked. Anyway, the function worked, and now people can type in the IDs (how some people manage to memorize 100+ of them is beyond me tho). Since I was changing the naming function, I added another option in the preferences for turning off the resource naming. This adds another field to the preferences resource (which is stored in the "clip2icns Preferences" file in the Preferences folder in the System Folder. When I load the preferences I simply to a Get1Resource and type cast the result, so if the user had a preferences file from an older version it would try load the new field too, and since it wasn't in the file it would fill it with whatever happened to be in memory at that time. Since I didn't begin the resource with a version number (or some kind of identifier to separate the different versions) I resorted to using the resource size to separate between the different versions. Since I just added another boolean, the resource is now one byte bigger, so I check for that and if it's the old version I set the new option to the default value.

In The Name Of The... #

clip2icns: received a request to name the resources properly even when the ID typed straight in (instead of using the menus). This is a bit of a pain, since until now I was extracting the name from the menu title. I guess I'll have to do a simple search function (the menu name also contains the ID).

(later) The search function isn't working at all....very very weird...

Tester Confirmation #

clip2icns: no bug reports from the beta testers about compression bugs, so I guess I nailed that one. I better release an update soon, otherwise people will start to wonder why they're getting so many crashes when using icons done with my tool.

More Compression Nastiness #

clip2icns: found yet another bug (which I induced yesterday when I rewrote part of the compression function). The bug happened when I had large flat regions. The multiplier that came before the pixel would be one pixel more that it was supposed to be. This was especially apparent when the flat area was more than 130 pixels, because instead of the multiplied being written as FF (see the description of the format earlier) it would be represented as 00 (the multiplier is an unsigned char). This would really screw up the decompression, since it would go looking for pixels beyong the end of the resource. But it's been fixed, and hopefully this is the last compression bug.

Compression Weirdness #

clip2icns: Fixed a very weird crashing bug in clip2icns (the application itself wasn't crashing, but the finder was getting stuck once in a while while trying to display an icon). It was a compound problem in the compression routine, it was stopping too early (so the resource was too small) and it was interpreting and it had problems with compressing the last few pixels (it was interpreting them as a repeat area instead of copying them as is).

Demo Day #

no programming done today (although I did demonstrate clip2icns)

And The Money Keeps Rolling In #

clip2icns: Got another registration, still getting more than the average amount of visits. A while ago I changed the about box code, making it more effient using my newly aquired expertise with CopyDeepMask (all my icon drawing functions use that). The new version appeared to work OK, so I left it in. Unfortunately it refuses to draw with MacOS 8.1, and after fooling around with it for an hour or so I've gone back to the old code. I'll look into it when I have time.

My First Customer *sniffle* #

clip2icns: Woohoo! I have one registration (not my test order) and everything seems to work OK. I've gotten mentioned on a few sites, hopefully this (shortlived) spotlight will be enough to spread word about the program. No bug reports yet. I've started commenting the source, since part of it (the icns class) will end up in my IB Dossier project.

The Floodgates Are Open #

clip2icns: I've announced the program to the world, and did a test order using Kagi's test credit card number. I hope everything works OK (no time for programming today, had to set up a homepage, write a press release and sent it to all the major mac news homepages).