ZB64 Encoding and Compression. Zebra ZPL II
Reklāma
Reklāma
E
ZB64 Encoding and
Compression
This section describes the Base 64 MIME (ZB64) encoding and compression. This is the same type of MIME encoding that is used in e-mail.
Contents
5/17/07 ZPL II Programming Guide 13979L-005 Rev. A
574
ZB64 Encoding and Compression
Introduction to B64 and Z64
Introduction to B64 and Z64
The first encoding, known as B64, encodes the data using the MIME Base64 scheme. Base64 is used to encode e-mail attachments and is specifically designed to address communications path limitations, such as control characters and 7-bit data links. It encodes the data using only the printable ASCII characters:
13979L-005 Rev. A
With the use of ZPL, this has the added benefit of avoiding the caret (^) and tilde (~) characters. Base64 encodes six bits to the byte, for an expansion of 33 percent over the unenclosed data. This is much better than the 100 percent expansion given by the existing ASCII hexadecimal encoding.
The second encoding, known as Z64, first compresses the data using the LZ77 algorithm to reduce its size. (This algorithm is used by the PKWARE
®
compression program PKZIP™ and is integral to the PNG graphics format.) The compressed data is then encoded using the MIME
Base64 scheme as described above.
A CRC is calculated across the Base64-encoded data. If the CRC-check fails or the download is aborted, the object can be invalidated by the printer.
The robust encodings can be piggybacked on the existing download commands with full backward compatibility. This is done by prefacing the new encodings with a header that uniquely identifies them. The download routines in the printer firmware can key-off the header to determine whether the data is in the old ASCII hexadecimal encoding or one of the new encodings. This allows existing downloadable objects to be used in their present format, while new objects can be created using the same download commands with the new encodings for increased integrity and reduced download times.
For easy reference, B64 and Z64 are referred to as ZB64. In any reference to the ZB64 encoding, assume that both Base64-only (B64) and LZ77/Base64 (Z64) encodings are accepted.
Example •
The following is an example of an existing download command using the new encoding:
~DTARIAL,59494,:Z64:H4sICMB8+DMAC0FSSUFMLlRURgDsmnd8VEW7x5+ZO edsyibZNNJhlyWhbEJIwYSwJDGNkmwghJIgJYEEEhQIPSggKAjEAiIiVaSoIJ
YNBAkIGgGxUBVUUCGU0JQSC0WFnPvbE+SF18+9H+8f973X+3Jm93umzzNznvn
NSSFGRJ6ARAVZvXK7XDaXLyTiR5B7ontuZPQ824I5RKIa6ew+aba8+pU1rVDZ iciv
[multiple lines deleted]
/O6DU5wZ7ie2+g4xzDPwCpwm3nqW2GAPcdclxF4fIP66jHjncmKvKzh/ZUNCx l9/QQx2HXHYB4m/PkQcdCdx2G7OYt+mszkMh4iZxoifvkh89BFipo87kwD/Bf
/dOcycAAEA:a1b2
ZPL II Programming Guide 5/17/07
ZB64 Encoding and Compression
Introduction to B64 and Z64
575
The parameters are identical to the existing ~DT command:
Parameter
o = font name s = font size data = data string
Table 33 • ~DT Command Parameters
Details
Accepted Values: any valid TrueType name, up to 8 characters
Default Value: if a name is not specified, UNKNOWN is used
In this example, Arial is the specified font.
Accepted Values: the number of memory bytes required to hold the Zebra-downloadable format of the font
Default Value: if an incorrect value or no value is entered, the command is ignored
In this example, 59494 is the size.
To maintain compatibility with the existing ASCII hexadecimal encoding, this field must contain the size of the un-enclosed and uncompressed object — the number of bytes that are finally placed into the printer’s memory, not the number of bytes downloaded.
Accepted Values: a string of ASCII hexadecimal values (two hexadecimal digits/byte). The total number of two-digit values must match parameter s .
Default Value: if no data is entered, the command is ignored
Everything following the size field is data. The new encoding imposes a header with a unique signature. The new encoding must start with the characters :B64: (data encoded in Base-64 only) or
:Z64: (data compressed with LZ77, then encoded in Base-64) followed by the encoded data.
After the data is presented, another colon (:) and four hexadecimal digits comprise the CRC. The Base64 standard allows new-line characters (carriage returns and line feeds) to be inserted into the encoded data for clarity. These characters are ignored by the printer.
When downloading graphics, the colon is used in the current ASCII hexadecimal encoding indicate “repeat the previous dot row.” Since this shorthand is invalid for the first character of data (no previous dot row has been downloaded), it is safe for the printer to detect the leading colon character as the lead-in for the new encodings.
5/17/07 ZPL II Programming Guide 13979L-005 Rev. A
576
ZB64 Encoding and Compression
B64 and Z64 Encoding
B64 and Z64 Encoding
These download encodings, B64 and Z64, are created as drop-in replacements for the existing
ASCII hexadecimal encoding.
B64 encoding do the following:
• Encode the compressed data using the MIME Base64 algorithm.
• Calculate a CRC across the encoded data.
• Add a unique header to differentiate the new format from the existing ASCII hex encoding.
Z64 encoding do the following:
• Compress the data using the LZ77 algorithm.
• Encode the compressed data using the MIME Base64 algorithm.
• Calculate a CRC across the encoded data.
• Add a unique header to differentiate the new format from the existing ASCII hexadecimal encoding.
The data field have this format:
:id:encoded_data:crc
This table identifies the parameters for this format:
Parameter
:id
:iencoded_data
:crc
Table 34 • Format Parameters
Details
the identifying string B64 or Z64 data to download, compressed with LZ77 (if the id parameter is set to Z64) and encoded with Base64.
four hexadecimal digits representing the CRC calculated over the
:encoded_data field.
13979L-005 Rev. A
The printer calculates a CRC across the received data bytes and compare this to the CRC in the header. A CRC mismatch is treated as an aborted download.
The B64 and Z64 encodings can be used in place of the ASCII hexadecimal encoding in any download command. The commands are:
~DB – Download Bitmap Font
~DE – Download Encoding
~DG – Download Graphic
~DL – Download Unicode Bitmap Font
~DS – Download Scalable Font
~DT – Download TrueType Font
~DU – Download Unbounded TrueType Font
^GF – Graphic Field (with compression type set to “ASCII hex”)
ZPL II Programming Guide 5/17/07
ZB64 Encoding and Compression
B64 and Z64 Encoding
577
The ~DB (Download Bitmap Font) command can use the new encodings in place of the ASCII hexadecimal encoding in data sub-fields. Each character is encoded individually. However, for small amounts of data, the identifying B64 or Z64 header and trailing CRC may negate any gains made by using the new format.
For backward compatibility, the ^HG (Host Graphic) command uses the ASCII hexadecimal encoding. It does not use the new encodings.
5/17/07 ZPL II Programming Guide 13979L-005 Rev. A
578
ZB64 Encoding and Compression
B64 and Z64 Encoding
Notes •
___________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
13979L-005 Rev. A ZPL II Programming Guide 5/17/07
Lejupielādēt
Reklāma