A bitmap in a PCL job is a sequence of rows sent with Esc*b#W, between Esc*r#A (start) and
Esc*rC (end). This page follows HP’s PCL 5 Printer Language Technical Reference Manual, chapter 15
(compression methods 0 to 3 and 5), the PCL 5 Comparison Guide (method 9) and the PCL 5 Color Technical Reference
Manual (chapter 2, colour modes).
The sequence
Esc*t300R resolution: 300 dots per inch
Esc*r256S source width in pixels (optional)
Esc*r1A start raster graphics at the cursor
Esc*b0M compression method 0 (unencoded)
Esc*b32W [32 bytes] row 1
Esc*b32W [32 bytes] row 2
...
Esc*rC end raster graphics
| Command | Meaning |
|---|---|
Esc*t#R | Resolution in dots per inch: 75 (the default), 100, 150, 200, 300 or 600. It must be sent before the image starts. |
Esc*r#F | Presentation: 0 the image follows the print direction of the logical page; 3 it is printed along the width of the physical page. |
Esc*r#T, Esc*r#S | Source height in rows and width in pixels. Rows longer than the width are cut; the width defaults to the logical page width at this resolution. |
Esc*t#H, Esc*t#V | Destination width and height in decipoints, used when raster scaling is on (Esc*r2A or 3A); with one of them the aspect ratio is kept. |
Esc*t#K | Scale algorithm for colour images shrunk: 0 for a light background, 1 for a dark one. |
Esc*r#A | Start: 0 the left graphics margin is x position 0; 1 it is the current cursor column; 2 and 3 are the same with scaling on (from the logical page left, or at the cursor). It also clears the seed row. |
Esc*b#Y | Y offset: move down # raster lines, leaving them empty; it also clears the seed row. |
Esc*b#M | Compression method, below. The method stays until changed or until the image ends. |
Esc*b#W | One row (or, with method 5, a block of rows): # bytes of data follow. |
Esc*b#V | One plane of a row, for colour data in planes; the last plane of the row is sent with Esc*b#W. |
Esc*rB, Esc*rC | End raster graphics. C is the preferred form (LaserJet IIISi and later); it also resets the compression method, the left graphics margin and the seed row, and moves the cursor below the image. |
Each row is a string of bytes, the first pixel in bit 7 of the first byte, a set bit being a printed dot. Every row advances the cursor by one raster row (1/resolution inch).
Compression methods
Method 0: unencoded
A plain binary transfer: each bit is a dot. Compression does not reduce the printer’s memory use, only the transfer.
Method 1: run-length encoding
Pairs of bytes: a repetition count and the data byte. A count of 0 means the byte occurs once, 1 twice, up to 255 for 256 times. The manual’s example:
(3)U(0)A(1)T is UUUUATT.
Method 2: TIFF revision 4.0 (PackBits)
A control byte before the data. Values 0 to 127 mean the next control + 1 bytes are literal; values 129 to 255 (−127 to −1 as a signed byte) mean the next
byte is repeated 257 − control times (so 253 repeats it 4 times in all); 128 does nothing and the byte after it is a new control byte. The manual’s
example: (−3)U(0)A(−1)T is UUUUATT.
Method 3: delta row
Only the bytes that differ from the seed row (the row before) are sent, as groups of a command byte and 1 to 8 replacement bytes:
| Bits | Meaning |
|---|---|
| 7 to 5 | The number of replacement bytes minus 1 (1 to 8 bytes). |
| 4 to 0 | The offset: how many bytes after the first untreated byte (the byte after the last replacement) the replacement starts. 0 to 30 is the offset itself; 31 means more offset bytes follow, added to 31: a byte under 255 ends the sum, a 255 is followed by another byte (so 31, 255, 128 is an offset of 414). |
The seed row is zero at the start of the image, is replaced by every row whatever its method, and is cleared by Esc*b#Y and by
cursor moves outside the image. A transfer with a count of 0 (Esc*b0W) repeats the previous row; if the byte count ends before
the replacement bytes do, the byte count wins and a last control byte is ignored. The manual’s example, three rows of five bytes:
row 1 00 FF 00 00 00 Esc*b3m2W (01)(FF)
row 2 00 FF F0 00 00 Esc*b2W (02)(F0)
row 3 0F FF F0 AA AA Esc*b5W (00)(0F)(22)(AA)(AA)
Method 5: adaptive compression
Esc*b#W is sent once and # is the size of a whole block (at most 32767 bytes of compressed data). In the block each row starts with three bytes: a
command byte, then a 16-bit big-endian number.
| Command byte | Meaning of the number |
|---|---|
| 0 to 3 | The row is coded with method 0, 1, 2 or 3 and the number is its length in bytes. |
| 4 | That many empty rows. The seed row becomes zero. |
| 5 | That many copies of the previous row. The seed row is not changed. |
Any other command byte skips the rest of the block and clears the seed row. A method cannot be mixed inside one row, and the cursor moves with every row. For method 1 an odd row length throws the row away; a row length of 0 gives an empty row. Colour data sent by plane cannot use method 5.
Method 9: replacement delta row
Described in the Comparison Guide for the DeskJet 1600C. Like method 3 but the replacement data may be run-length encoded. The command byte is a control bit, an offset count and a replacement count: with control bit 0, bits 3 to 6 are the offset and bits 0 to 2 the replacement count; with control bit 1, bits 5 to 6 are the offset and bits 0 to 4 the replacement count, and the data are run-length encoded. An offset field at its maximum (15, or 3) is followed by offset bytes and a replacement count at its maximum (7, or 31) by count bytes, each 255 meaning another byte follows. One more byte than the replacement count is replaced. The manual does not say how the run-length data are counted; this site’s viewer reads them as (count, byte) pairs and says so.
Colour: simple colour and the image configuration command
Esc*r#U (simple colour) makes a fixed palette: 1 a single plane with a black and white palette, 3 three planes with the device RGB palette (index
bit 0 red, bit 1 green, bit 2 blue: black, red, green, yellow, blue, magenta, cyan, white), −3 three planes with the CMY palette. The planes are sent
with Esc*b#V and the last with Esc*b#W.
Esc*v6W and six bytes (the configure image data command) set the colour space, how pixels are coded and the palette size:
| Byte | Field | Values |
|---|---|---|
| 0 | Colour space | 0 device RGB (default), 1 device CMY, 2 sRGB. Others are ignored. |
| 1 | Pixel encoding mode | 0 indexed by plane (bits per index 1 to 8; the planes are sent one after another for each row, the first plane holding the least significant bit of the index), 1 indexed by pixel (bits per index 1, 2, 4 or 8, the first pixel in the most significant bits), 2 direct by plane (three one-bit components, one plane each), 3 direct by pixel (three 8-bit components a pixel). Other values are ignored. |
| 2 | Bits per index | The palette has 2 to the power of this many entries. Not used by the direct modes. |
| 3, 4, 5 | Bits per component | Ignored for indexed modes; 1 each for direct by plane; 8 each for direct by pixel. |
Invalid configurations are ignored and their data discarded. Palette entries are set with Esc*v#A, B and C (the three
components, 0 to 255 for RGB) and Esc*v#I (give them to index #); Esc*v#S chooses the foreground colour by index.
The manual recommends direct by pixel with delta row compression.
In the viewer
The viewer decodes every method above, draws the image at the right size and place (averaging pixels when a page is shown smaller than the image), and handles simple colour and the four pixel encoding modes of the configure image data command in the device RGB and CMY spaces. The commands for colour lookup tables, dither matrices, viewing illuminants, gamma and render algorithms are listed and explained but have no effect on the picture.
Sources
- HP, PCL 5 Printer Language Technical Reference Manual (bpl13210), chapter 15 – read for this page: the commands, methods 0 to 3 and 5, the delta row example
- HP, PCL 5 Comparison Guide (bpl13206), printer-specific differences – method 9
- HP, PCL 5 Color Technical Reference Manual (bpl13212), chapter 2 – the configure image data command and pixel encoding modes