Pixel Mapper Source Code

By Matthew Ford

Originally published in EUG #19

Anyone who continued their subscription to the The Micro User long enough to see the change of name to Acorn Computing may have noticed that Pixel Mapper, a program published for the BBC in October/November 1992 did not work on the Electron. This was a shame, as it was actually a very clever program to distort pictures into virtually any shape you wanted. I have now found and sorted out the incompatibility problem (a minor difference in the address of a look-up table in the OS ROM) and added a few new facilities (including a simple menu) to the program.

The program is in two main parts, a Shaper and a Mapper. The first is basically a simple art program. Using this, you design the shape you want your picture to fit into. Then Mapper converts your picture (which can be a screen file of any size in any graphics mode!) line-by-line to fit the shape designed.

The Shaper is different from many art programs as it is object-orientated. This means its files are stored as a series of shapes in the order you drew them, rather than an ordinary pixel-based screen file. This has the advatage that the files are very small, and also they can be re-drawn in any screen mode. However, it does mean that mistakes can be difficult to correct. For this reason, the original version had no facility to re-load a saved shape file, or to delete a shape drawn in the wrong place. (It was assumed that the shapes used for the Pixel Mapper would be very simple so there would be nothing to lose by clearing the screen and starting again if the result was not satisfactory). I have added these two facilities. Unfortunately, the new program would not run with ADFS in Mode 1 as it was supposed to (Most BBC owners use DFS keeping PAGE set at &1900, not &1D00). To get round this, I have provided the option of running it in either Mode 4 or 5 (with the obvious advantages/disadvantages).

The controls for the Shaper are as follows:

G Lock cursor to grid
(You are given the option to choose the size of the grid, and whether or not to display it, when the program is run)
N Unlock cursor from grid
O Return cursor to origin
F Select foreground colour
B Select background colour (Erase)
T Draw triangle (Use SPACE to fix other two points)
R Draw rectangle (Use SPACE to fix opposite point)
C Make n-sided polygon (use a large value to draw a circle)
SPACE BAR Fix corner of object
Arrow keys Move cursor
Arrow keys with SHIFT Move cursor faster*
Arrow keys with CTRL Move cursor very fast*
FUNC with ',' Load shape file
FUNC with '.' Save shape file
SHIFT with D Delete last object drawn/Cancel current one
ESCAPE Cancel current operation
L Display number of objects left (This was included due to memory being very tight in the original Mode 1 version. However there is now room for 300, not 15, so you probably will not need to use it
Q Quit program and return to menu

* Not if the cursor is locked to grid

The operation of the Mapper program is fairly self-explanatory. You are first asked to enter the mode of the screen file you wish to distort. In some cases, you can also select the destination mode. You are then asked for the vertical height of the picture - this enables you to enlarge a small picture to fill the whole screen!

I have also included a new option - to select between a shape file (one designed using Shaper) and an ordinary screen file. If you choose to map onto a screen designed using an art program (such as Electron User's Elkpaint) then all colours except colour 0 will be treated as foreground. However, bear in mind that a screen file will only work in its original mode, and will use up a lot of disk space. It is possible to use the Mapper to change the Mode of a screen file, by simply mapping it onto a large box filling the whole screen.

Again memory is very tight if you are running Mapper from ADFS so you may have to cut down the REM statements at the start if you make any changes. I have unfortunately had to join many of the lines together to make it run.

Acorn Computing published four sample shape files. These are saved in this disk's F directory under the filenames DISTANC, HOURGLA, WOBBLE and WRAP. You might like to try them out using the title screens from a few games - most Superior Software title screens are in Mode 5 and have a vertical length of 208 pixels. Best results are usually achieved using Mode 1 as a destination mode (although this does take considerably longer than Mode 5). Acorn Computing illustrated their article by mapping the title screen from Barbarian onto the shape of a Polo mint.

Matthew Ford

This is really interesting. I was one of those who stopped buying most of the computing magazines and after reading this article I might just buy a copy of Acorn Computing. Perhaps it's worth another look!

If you do decide to use Elkpaint to design shapes, remember there was a much improved version of it in EUG #18.

Gus Donnachaidh, EUG #19