![](/html/d9/d923/d923a87bc604745dc418cda2421b9f7dc9fe182bd044ea775026e049d8935570/bg1.png)
AN-05 (LP)
September 23, 2005
HOW TO PRINT RLE COMPRESSED GRAPHICS IN LINE PRINTER MODE
Overview
The O’Neil printers have several graphics modes that allow graphics to either be
repeatedly upon demand (useful for logos or icons), or sent to the printer and printed one time only (useful for signatures
or transient images). Graphics sent to be printed one time only can be sent in their full bitmap form, or they can be
compressed using a Run Length Encoding scheme (RLE). This document de scribes how to encode a graphic image
using RLE.
Graphic images are formed of line after line of individual dots, like tiny slice
each of those lines is .005” tall, and each dot is .005” wide. A single byte then can represent an area only .005 inches tall
and .040 inches wide (8 dots). It takes approximately 5000 bytes to represent a single square inch of graphic data. But
most images contain large white or black areas. For example, a signature is mainly white space. Since this white space
data is the same byte repeated, over and over, large horizontal areas across one dotline can be compressed into only two
bytes – one byte contains the graphics information and the second byte contains the number of times that byte is
repeated (called Run Length Encoding or RLE). A similar technique can compress multiple horizontal white lines into only
two bytes – one of which is a command to advance paper and the other is the number of lines to advance. Using these
techniques, the total data is usually reduced to ½ or less of its original size (many signatures can come down to 1/3 to ¼
of their original size). RLE does not compress well when the graphic is very “busy”. So the O’Neil implementation allows
the application to determine on a DOTLINE BY DOTLINE basis whether the line is best sent using compression or not.
Compressing the image using RLE
All RLE images begin with the two-character escape sequence ESC B (0x1B, 0x42) and e
escape sequence ESC E (0x1B, 0x45). If a series of dotlines are all whitespace, the vertical white space can be
compressed by sending a two-character sequence consisting of an ‘A’ (0x41) followed by a single byte containing the
number of blank dotlines to advance. Each non white-space dotline must represent enough bytes for the total width of the
printer (4” is 832 bits or 104 bytes, 3” is 576 bits or 72 bytes, and 2” are 384 bits or 48 bytes). The first bit printed is the
MSbit of the first byte received. Each dotline is preceded by a ‘U’ (0x55) if that dotline is sent Uncompressed, or a ‘G’
(0x47) if that dotline is sent Compressed. If the dotline is compressed, then that dotline will consist of a series of byte
pairs after the G. The first byte in the pair is the graphics byte; the second byte is the number of times to repeat that byte.
stored in the printer’s Flash and printed
s across the image. For the O’Neil printers,
nd with the two-character
The following example will show how a simple, contrived image can be compressed. We will use a mythical printhead
that is 20 bytes wi
represents one byte in Hex of our graphic:
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 0F 80 00 00 00 00 FF FF D2 00 00 00 00 00 00 00
00 00 00 0F FF FF C2 00 00 78 45 45 D2 D2 D2 F9 F9 00 00 00
00 0F F8 00 0E E0 00 00 FF FF 01 E0 FF D2 00 88 73 FC C7 00
00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
de and a graphics image 10 dotlines tall (200 bytes total before compression. Each pair below
![](/html/d9/d923/d923a87bc604745dc418cda2421b9f7dc9fe182bd044ea775026e049d8935570/bg2.png)
We begin the compression with the first two bytes of ESC B (telling the printe
1B 42
The first three dotlines in our example are all white space. So this
Advance and 03 for 3 dotlines:
41 03
The next line contains graphics information, so we will need to use either comp
graphics. We will try compressed first:
Four 00’s will compress to the byte pair 00 04 (repeat 00 four times)
One 0F stands alone but still requires the byte pair 0F 01
Similarly, 80 requires 80 01, the four 00’s compress to 00 04, the two FF’s a
01, then we have 7 00’s which compress to 00 07, making the entire string 00 04 0F 01 80 01 00 04 FF 02 D2 01 00 07.
Note that if you add up all of the byte counts (4+1+1+4+2+1+7), it totals 20, the width of the printhead. We represent this
as compressed graphics by preceding it with a ‘G’ (0x47):
47 00 04 0F 01 80 01 00 04 FF 02 D2 01 00 07
Similarly, the next line could be represented as compressed:
47 00 03 0F 01 FF 02 C2 01 00 02 78 01 45 02 D2 03 F9 02 00 03
or non-compressed (preceded with a ‘U’ (0x55) u
55 00 00 00 0F FF FF C2 00 00 78 45 45 D2 D2 D2 F9 F9 00 00 00
Since the next line is “busier” than the preceding line, using RLE wil
does):
00 01 0F 01 F8 01 00 01 0E 01 E0 01 00 02 FF 02 01 01 E0 01 FF 01 D2 01… etc.,
sing the same number of bytes.
can be compressed into two bytes, ‘A’ or 0x41 for
l probably make it longer (and we can see that it
r we are using compressed graphics):
ressed graphics or non-compressed
re represented by FF 02, the D2 requires D2
so it is best represented as uncompressed:
55 00 0F F8
The next two lines can each best be represented using a comp
47 00 01 FF 13
47 00 01 FF 13
And, the last two lines again can b
41 02
This is followed by the end code (pri
1B 45
And finally, we have the final compressed graphic ready to send to our mythical 20 byte wide
arranged to show each line on a separate line, but this is really one continuous string of 75 bytes):
1B 42
41 03
47 00 04 0F 01 80 01 00 04 FF 02 D2 01 00 07
47 00 03 0F 01 FF 02 C2 01 00 02 78 01 45 02 D2 03 F9 02 00 03
55 00 0F F8 00 0E E0 00 00 FF FF 01 E0 FF D2 00 88 73 FC C7 00
47 00 01 FF 13
47 00 01 FF 13
41 02
1B 45
00 0E E0 00 00 FF FF 01 E0 FF D2 00 88 73 FC C7 00
ressed line (note that 0x13 is 19 decimal):
e compressed to only two bytes:
nter returns to normal ASCII):
printer (the example is