A roll image file consists of a byte stream that represents a scan of the roll from bass to treble, and from beginning to end. We compress the file using the scheme described below, because uncompressed files can be quite large.
For example, an uncompressed scan of a roll 10 meters in length with 1800 pixels across its width and a scan-line spacing of 0.1 mm along the length of the roll is 67.5 MB in size (assuming 8 grey levels). The compression scheme yields a file on the order of 2.5 MB in size, a reduction of 27:1.
The compression scheme used here uses run-length encoding along the length of the roll. This in turn means that when we want to write a line to disk we must have both the current line and the previous one, to allow forming the difference between them; this complicates the code. A simpler scheme would use run-length encoding across the width of the roll (with each line independent of the others). This is an appealing alternative, but we find by experiment that the resulting compressed files are nearly twice the size of those produced by the method used here.
To write a compressed image file, first write an 8-byte file header that consists of the following items:
Then proceed as follows whenever a new scan line becomes available:
Number the pixels in each scan line 0,1,2,... from bass to treble (left to right).
Reduce the number of grey levels per pixel from 256 to 8 using an appropriate reduction method (discussed separately). This results in an intensity described by the integers in the range 0-7, where 0 denotes blank paper and 7 denotes a perforation. (Whether 0 is "light" or "dark" depends on whether the roll is illuminated from the front or the rear.)
Working from bass to treble (left to right) compare the intensity of each pixel (in the range 0-7) with the intensity of the corresponding pixel in the previous scan line (the scan line closer to the start of the roll). If the intensities match, move on to the next pixel on the right without taking any action. For the first scan line assume the intensity of each pixel in the (nonexistent) previous scan line to be 0.
If the intensities do not match, subtract the number of the nearest pixel on the left for which the intensities did not match. (This gives the distance, in pixels, for which no information has been written into the compressed file.) For the leftmost pixel (pixel 0), assume that the number of the nearest such pixel on the left is -1. The result will be an integer between 1 and the number of pixels in the scan line (called the "differential distance").
If the differential distance is in the range 1,2,...,15 write a byte to the compressed file that looks like this:
| 0 | i2 | i1 | i0 | d3 | d2 | d1 | d0 |
|---|
where i2,i1,i0 are the bits in the intensity and d3,d2,d1,d0 are the bits in the differential distance. Note that this byte is never zero.
If the differential distance is greater than 15 write a byte to the compressed file that looks like this:
| 1 | i2 | i1 | i0 | d3 | d2 | d1 | d0 |
|---|
where the definitions are as before. Now if the differential distance is less than 2048 write a byte that looks like this:
| 0 | d10 | d9 | d8 | d7 | d6 | d5 | d4 |
|---|
otherwise, write the a byte just like the one above, but with an MSB of 1. Then write another byte that looks like this:
| 0 | d17 | d16 | d15 | d14 | d13 | d12 | d11 |
|---|
This table gives the number of bytes required for differential distances:
| Distance | Bytes |
|---|---|
| 1-15 | 1 |
| 16-2047 | 2 |
| 2048-262143 | 3 |
The following special bytes can be inserted anywhere within a scan line to represent special events:
| 00010000 | Roll Defect |
| 00100000 | (Reserved) |
| 00110000 | (Reserved) |
| 01000000 | (Reserved) |
| 01010000 | Cue Mark |
| 01100000 | End of Selection |
| 01110000 | End of Performance |
These special events are created by having the scanner operator strike a key during the scanning process. The special events are then placed in the compressed file in the appropriate scan line for subsequent use.
At the end of the scan line write a byte consisting of all zeros. Note that all of the bytes written so far cannot be zero, so a zero byte uniquely identifies end of line.
Repeat this procedure for each scan line in the roll from start to finish.
Wayne Stahnke
October 18, 2002