Implementation notes A program is complete when the schedule dictates that it's done. ---------------------------------------------------------------------- 0. Concept Kanna is a command line utility for getting size of images. This is inspired by Kanna from "Tamako Market", who is always seen measuring things. I have been writing ad-hoc scripts for doing this task, but I figured I will get it all in one utility this time. ---------------------------------------------------------------------- 1. Image formats Depending on the list of formats supported, this kind of program can either be very large or very small. I have decided to make Kanna support only the formats I used frequently, which comes down to GIF/PNG/JPEG and the NetPBM formats. This excludes some formats which would have been easy to support, such as BMP and TGA. The one format that I do use very often but decided not to support is NEF (Nikon Electronic Format). To start, it's a proprietary and poorly documented format. The next closest thing is TIFF. After reading much of the 120+ page spec on TIFF 6.0, I have concluded that it's totally a writer-friendly and reader-hostile format, and not worth the effort. At this point I stopped looking for formats that I might support (such as WebP) and just started coding. ---------------------------------------------------------------------- 2. Image decoder This was totally straightforward: check the first few bytes to see what format the input is, then collect the bytes from the various offsets to get the image size. Some care was taken to make sure Kanna outputs "0 0" on truncated inputs, but mostly there is nothing excessively clever about decoding file formats, especially since we only care about the header part and not the pixel data. ---------------------------------------------------------------------- 3. Image generator After implementing the image decoder and formatting the source into ASCII art, I still have ~168 bytes left to spare. Usually I would embed a BF program in the spare bytes, which I have done (and it took only 148 bytes). This time around, because Kanna is relatively low-resolution, the BF program stood out too much with its distinctively low entropy character set. Since 168 bytes is actually quite a few bytes to spare, I threw away the BF program and embedded a Perl program instead. Because the main program is an utility for determining image dimensions, it's only fitting to have the secondary program be one that generates images of user-specified dimensions. This was fairly easy with Perl outputting PBM, I was even able to fit in some random dithering stuff in it. ---------------------------------------------------------------------- 4. Finally... This was a fairly straightforward program to write, from initial idea to the final completed ASCII art. Nonetheless it took months to complete. This was totally a problem with coding time and not with coding skills. Though I always feared that if I stop doing something, I will lose those skills and never do those things again. Eventually I made time to complete this ASCII art, and felt a lot better since. Now I can go back to re-watching Tamako Market without feeling that the time was wasted.