## Printer Device Driver

[prev][next][parent][TOC]

### GplCompressChooseMode

Description

This function uses a semi-intelligent algorithm to select the compression mode that will most likely give the best compression for the row of data.

RLL Delta Row is currently chosen if this method best and if the printer supports this compression. Delta Row is chosen if most of the bytes are the same as the corresponding bytes in the previous row. TIFF is chosen if most of the bytes are repeated within this row. RLL is chosen if most of the bytes are repeated within this row and the printer does not support TIFF PackBits. No compression (value of 0) is chosen of most bytes are neither repeats within the row nor duplicates of the previous row.

Note: The function GplCompressChooseMode() must be run before either of the delta-compression functions GplCompressDeltaRow() or GplCompressRLLDeltaRow(). This function must be run first because pDelta is filled in by GplCompressChooseMode() while it is reading pbRow and pbLast_ Row. Performance is increased by combining GplCompressChooseMode() with either GplCompressDeltaRow() or GplCompressRLLDeltaRow().

Format

    INT APIENTRY GplCompressChooseMode( PBYTE    pbRow,

                                        PBYTE    pbLast_Row,

                                        INT      usRow_Length,

                                        ULONG    CompressModes,

                                        PUSHORT  pDelta );

Parameters

pbRow (PBYTE) Pointer to the current row's data.

pbLast_Row (PBYTE) Pointer to the last row's data.

usRow_Length (INT) The number of bytes in the row. Note that both the previous row and the current row are equal in size.

CompressModes (ULONG) Compression modes supported.

This is a ULONG with the follow bit positions used to represent compress modes that this printer supports:

GPLCOMPRESS_NONE
GPLCOMPRESS_RLL
GPLCOMPRESS_TIFF
GPLCOMPRESS_DELTAROW
GPLCOMPRESS_RLLDELTAROW

These values may be logically ORed together to create a bitfield of all compression methods to consider. For example,

        CompressModes = GPLCOMPRESS_RLL | GPLCOMPRESS_TIFF

This tells the routine to only choose between the RLL and TIFF compression routines and GPLCOMPRESS_NONE.

pDelta (PUSHORT) Array of unsigned shorts to hold the offsets from the beginning of pbRow that differ from pbLast_Row. This data will be used by GplCompressDeltaRow and GplCompressRLLDeltaRow. Note that pDelta must have a length equal to two times usRow_Length plus one to hold the pDelta output . There is no check on the size of pDelta. You must supply a size of a minimum of two times usRow_Length plus one. This is because the maximum number of differences occur when every other byte differs from the preceding row.

Returns

The mode that will probably compress the best:

0 No compression
1 RLL (run-length limited) compression
2 TIFF (tagged image file format) compression
3 Delta-row compression
9 RLL delta-row compression

Notes

For GplCompressDeltaRow and GplCompressRLLDeltaRow, pDelta is filled with the start and end of the difference fragments. Note that a difference fragment is defined as a contiguous group of bytes in the current row that differ from those in the previous row. For example:

    /-----------------------------------------------------------------------\

    |Column Number  |1  |2  |3  |4  |5  |6  |7  |8  |9  |10 |11 |12 |13 |14 |

    |---------------+---+---+---+---+---+---+---+---+---+---+---+---+---+---|

    |Current Row    |7  |8  |1  |0  |4  |5  |6  |7  |23 |128|257|1  |7  |8  |

    |Byte Value     |   |   |   |   |   |   |   |   |   |   |   |   |   |   |

    |---------------+---+---+---+---+---+---+---+---+---+---+---+---+---+---|

    |Previous Row   |7  |1  |3  |1  |4  |5  |9  |7  |23 |128|7  |9  |7  |8  |

    |Byte Value     |   |   |   |   |   |   |   |   |   |   |   |   |   |   |

    \-----------------------------------------------------------------------/

There are three difference fragments:

Fragment one begins at column 2 and ends at column 4.
Fragment two begins at column 7 and ends at column 7.
Fragment three begins at column 11 and ends at column 12.

The output in pDelta will be 2 4 7 7 11 12 0. Note that these are unsigned shorts and the difference array is null-terminated. If no difference fragments are found (the previous and current buffers are the same) the first unsigned short in pDelta will be 0.

pDelta above will point to a array of the indexes stored to used by GplCompressDeltaRow() and GplCompressRLLDeltaRow().

Example Code

Following is an example of GplCompressChooseMode usage from the Omni driver for a typical inkjet device:

    iNewMode = GplCompressChooseMode(

                     pbBuffer,             // Contains current row of data

                     pbLastLine,           // Contains previous row of data

                     iBytesInRow,          // Number of bytes in output row (pbBuffer)

                     GPLCOMPRESS_RLL |     // All compression modes supported

                     GPLCOMPRESS_TIFF,

                     pDelta );             // Offsets into pbBuffer ((2 x pbBuffer) + 1)

      if( iNewMode != iCurrentMode )

      {

        // Send command to printer to set new mode

        iCurrentMode = iNewMode;

      } /* end if */

      switch( iNewMode )

      {

         case 0:                           // No Compression

         break;

         case 1: iCompressed = GplCompressRLL();

         break;

         case 2: iCompressed = GplCompressTIFF();

         break;

         case 3: iCompressed = GplCompressDeltaRow();

         break;

         case 9: iCompressed = GplCompressRLLDeltaRow();

         break;

      } /* end switch */

      // Write raster data transfer command and compressed data