Bitsnap, a screenshot capture tool for Medley Interlisp
I wrote Bitsnap, a tool in Interlisp for capturing screenshots on the Medley environment. It can capture and optionally save to a file the full screen, a window with or without title bar and borders, or an arbitrary area.
This project helped me learn the internals of Medley, such as extending the background menu, and produced a tool I wanted. For example, with Bitsnap I can capture some areas like specific windows without manually framing them; or the full screen of Medley excluding the title bar and borders of the operating systems that hosts Medley, Linux in my case.
Medley can natively capture various portions of the screen. These facilities produce 1-bit images as instances of BITMAP
, an image data structure Medley uses for everything from bit patterns, to icons, to actual images. Some Lisp functions manipulate bitmaps.
Bitsnap glues together these facilities and packages them in an interactive interface accessible as a submenu of the background menu as well as a programmatic interface, the Interlisp function SNAP
.
To provide feedback after a capture Bitsnap displays in a window the area just captured, as shown here along with the Bitsnap menu.
The tool works by copying to a new bitmap the system bitmap that holds the designated area of the screen. Which is straighforward as there are Interlisp functions for accessing the source bitmaps. These functions return a BITMAP
and capture:
SCREENBITMAP
: the full screenWINDOW.BITMAP
: a window including the title bar and borderBITMAPCOPY
: the interior of a window with no title bar and borderSNAPW
: an arbitrary area
The slightly more involved part is bringing captured bitmaps out of Medley in a format today's systems and tools understand. Some Interlisp functions can save a BITMAP
to disk in text and binary encodings, none of which are modern standards.
The only Medley tool to export to a modern — or less ancient — format less bound to Lisp is the xerox-to-xbm module which converts a BITMAP
to the Unix XBM (X BitMap) format. However, xerox-to-xbm can't process large bitmaps.
To work around the issue I wrote the function BMTOPBM
that saves a BITMAP
to a file in a slightly more modern and popular format, PBM (Portable BitMap). I can't think of anything simpler and, indeed, it took me just half a dozen minutes to write the function. Linux and other modern operating systems can natively display PBM files and Netpbm converts PBM to PNG and other widely used standards. For example, this Netpbm pipeline converts to PNG:
$ pbmtopnm screenshot.pbm | pnmtopng > screenshot.png
BMTOPBM
can handle bitmaps of any size but its simple algorithm is inefficient. However, on my PC the function takes about 5 seconds to save a 1920x1080 bitmap, which is the worst case as this is the maximum screen size Medley allows. Good enough for the time being.
Bitsnap does pretty much all I want and doesn't need major new features. Still, I may optimize BMTOPBM
or save directly to PNG.
Discuss... Email | Reply @amoroso@fosstodon.org