The Spritefile Module

Home David Projects The Spritefile Module
Updated: 2009-01-11
Note: This is a work-in-progress. Many of the links given in this document lead to locations in which their targets have yet to be written.


The Spritefile format is the standard file format for storing bitmap images on the RISC OS platform. This popularity is mainly due to their use by the operating system facilities for rendering images in the desktop environment and the closeness of the stored data to the framebuffer structure on early RISC OS machines, such as the Archimedes, A3000, A540 and so on. Despite the popularity of so-called "Internet image formats", support for non-native image files within RISC OS has lagged behind the support available for toolkits such as Qt and GTK. A consequence of this is that a substantial amount of images found on a RISC OS workstation will be stored in Spritefiles. Another reason for the continued use of Spritefiles for storing images is their support for multiple images within a single file; a feature which is often neglected by some types of applications which only require a single image per file.

Available libraries and tools

The spritefile module

When writing a library of classes to interpret the contents of Drawfiles it became apparent that a substantial amount of work was required to provide support for objects containing sprites. Therefore, a separate module was created for this purpose, its interface similar to the one implemented for the Python GUI library I had been working on.

The module was initially written purely in Python but, to speed up the processing of large images, some of the methods which manipulate the image data were moved to a separate library written in Pyrex, which makes writing C extensions to Python fairly simple. However, if the compiled extension module cannot be found at runtime then the module falls back on original methods to process image data.

The Spritefile format has been modified and extended many times by many parties. It is likely that there are numerous Spritefiles in existence which will not be interpreted correctly by this module. However, the following features at least are supported:

spr2img and spr2other

These Python tools put a simple command line interface on top of the spritefile module, allowing the user to extract images in formats supported by the Python Imaging Library. The spr2img tool will extract all the images within the Spritefile in the desired format whereas the spr2other tools allows the user to extract named images to specific files of the desired format.

The pygimp-sprite plugin for The GIMP

It would be useful to be able to view and modify the images contained within Spritefiles in a popular bitmap editor rather than have to convert them to an intermediate format first. The pygimp-sprite plugin for The GIMP allows Spritefiles to be loaded directly into the editor, as shown in Figure 1.

The plugin requires that a patched version of the pygimp package be installed alongside a suitable version of The GIMP. The plugin opens an editing window for each image found in a Spritefile. Therefore, Spritefiles containing many images tend to leave the desktop in a mess.

A Spritefile opened in The GIMP Figure 1: A Spritefile as displayed by The GIMP.
[Click on the image to see it in more detail.]
Linked from: [*]

The spriteinput filter for Sketch

A description of this filter is available on the Sketch Plugins and Tools page.

A patch for version 1.2 of the pygimp package.
The spritefile module and various tools, including the pygimp-sprite plugin.