Compulsive Cleaning #
I couldn't stop myself, so I started to redo some things. First thing was my 1 bit mask generating function, which used a very messy code (it involved going through the color lookup table, which made it only work with indexed-color images, and setting all non-white colors to black). But now I've had more experience with CalcCMask system function (the lasso tool uses it), so I was able to rewrite it to be much more efficient. I also replaced some repeated code in the ImportFromClipboard function with calls to Make1BitMask, so the line size is down by quite a bit.
Then I worked on the saving functions, specifically the compression part. Until now each icon had three member variables, arrays of chars for the compressed data for all three sizes (huge, large and medium). However I realized that these were only used when saving, and were taking up memory the rest of the time. Looking around the compression code, I had also noticed that I had three special cases, for each size, when it could have obviously been turned into a generalized function. A similar thing also existed with the decompression, where I had three similar loops to decompress the data and merge the RGB channels, again one for each size. In the end I decided that what I needed were two functions, CompressPixMap and DecompressToPixMap, which would make the transitions between an uncompressed pixmap and the compressed data represented by an array of chars. I also spun-off the compression routines (the above two, plus two sub functions, PackData and UnpackData which are each called three times for each channel) into a separate file, since they make much more sense that way. When I was done everything the code looked much cleaner, and I had made each instance of the icnsClass (and thus the derived icnsEditorClass) take up around 15K less of memory.
Post a Comment