A two dimensional method and system for compressing bi-level images

Abstract: A two-dimensional compression method and system for compressing a bi-level bit-mapped image. The compression system reads a current row of data from the bit-mapped image and compares the current row with the row immediately preceding the current row, called the reference row. If a byte in the current row is equal to a corresponding byte in the reference row, then the byte is represented by a COPY mode and the byte is copied from the reference row to a compressed row. If the byte is not equal to the byte in the reference row, then the next byte in the current row is read and compared with the preceding byte. If the current byte equals the preceding byte, then the byte is represented by a REPEAT mode and copied to the compressed row along with a count of how many times to repeat the byte. If the current byte is not equal to preceding byte, then the byte is represented by a LITERAL mode and the byte is copied directly to the compressed row along with a count of how many bytes are to be copied. Each transition from one mode to another in the compressed row is assigned a variable-length mode code, and each count in the compressed row is assigned a variable-length count code. The current row, once compressed, contains sequences of triplets comprising a mode code followed by a length code, and optionally followed by one or more data bytes.

Description: The present invention relates to data compression, and more specifically to a two-dimensional compression method and system for compressing bi-level bit-mapped images. Rasterization is the process of converting data, such as ASCII text, into what is known as a bit-mapped image, which is a sequential collection of bits representing an image to be displayed on a computer screen. Each bit in a bit-mapped image corresponds to one pixel location on the screen, and each horizontal line of bit values in a bit-mapped image is known as a rasterline. Output devices capable of reproducing a bit-mapped image, such as line printers and pen plotters for example, are known as bi-level devices because these devices are capable of producing only two levels of gray at a single pixel location; white (or light grey) to represent paper, and black (or dark grey) to represent ink on the paper. The bit values in bi-level bit-mapped images are either 0, to display white, or 1, to display black. Bit-mapped images are stored in a contiguous piece of computer memory called a frame buffer. The frame buffer is an array containing one memory bit for each pixel that the raster device is capable of printing. For example, for a 1024 x 1024 pixel image, the frame buffer requires 1,048,576 bits of memory. Although the cost of memory has decreased, the cost of memory continues to add significantly to the total cost of an output processing device, such as a conventional printer for instance. A conventional printer is equipped with sufficient memory and processing power to rasterize incoming data within the printer. Because of the added memory and processing power, a conventional printer is generally expensive. By reducing the size of the frame buffer, however, the total cost of a conventional printer may also be reduced. One method for reducing the size of the frame buffer is to compress an incoming bit-mapped image inside the printer before storing the image in the frame buffer. In this method, the incoming bit-mapped image is first compressed by what is known as an encoder, and then stored in smaller version of the frame buffer. Before the data in the frame buffer is printed, the data is decompressed by what is known as a decoder. The encoder and decoder are either implemented in software or hardware within the printer. In prior methods where the printer includes a hardware implementation of the encoder/decoder, the cost of the encoder/decoder is generally the same as the frame buffer memory that is saved. Therefore, such methods fail to reduce the total cost of the printer. Another type of printer, which is much less expensive than a conventional printer, is referred to as a "dumb" printer. In a dumb printer, most if not all, of the rasterization of an incoming image is performed by a host device, such as a personal computer (PC). After a bit-mapped image is rasterized by the PC, the PC sends the bit-mapped image to the dumb printer via the PC's parallel port, and the dumb printer is only responsible for printing the bit-mapped image. A dumb printer is less expensive than a conventional printer because of the savings realized from using less memory and a smaller microprocessor (if one is used at all). Since one bit corresponding to each pixel location in a bit-mapped image must be sent from the PC to the printer, one major issue concerning the use of a dumb printer is throughput between the PC and the printer. Since a bit-mapped image is sent over a parallel port to the printer, the speed at which data is printed can be bound by the speed of input/output devices of the PC. One method for increasing the throughput between the PC and the printer is to compress the amount of data that must pass through the parallel port of the PC. This may be accomplished by using an encoder to compress bit-mapped images in the PC, rather than the printer, and using a hardware implemented decoder in the printer to decompress the images before the images are printed. In one method, the encoder is implemented as an add-on board that is inserted in the PC. This method has not been widely used due to the disadvantages associated with the use of add-on PC boards. Furthermore, the printer containing the decoder is incompatible with Pcs that do not contain the add-on encoder board. Besides implementation issues associated with compression methods, the following aspects of compression methods must also be examined: the speed at which a compression method compresses data; the compression ratio, which is the size of the compressed data compared with the size of the original data; and the complexity of the compression method. Many well-known compression methods exist. However, each method usually performs well either with byte-oriented data, such as ASCII text, or with bit-mapped images. For byte-oriented data, the Lempel-Ziv algorithms "LZ1" and "LZ2", and Huffman coding compression methods are widely used. The LZ1 and LZ2 algorithms assign fixed-length codes to variable size input strings. LZ1 and LZ2 are used in the Consultative Committee for International Telephone and Telegraph (CCITT) V.42 data compression standard for use in switched network modems. LZ1 and LZ2 are also used for data storage, i.e. in tape drives and hard disk drives. Huffman coding is another method for compressing data in which individual elements found in the data are assigned a code based on the relative frequency of the elements where the most frequently occurring elements are assigned a code with the smallest number of bits. Usually, Huffman coding is used to compress text, with the coding based on letter frequency. A drawback to Huffman coding is that it requires two passes of the data to generate statistics and to create a table containing the assigned codes (which is later used for decompression). EP 034041A2 discloses a method for image data compression which uses a copy codeword for encoding of already encountered patterns and a literal codeword for encoding of new patterns. When increased compression is desired the codewords can be made of variable length, balanced with the average length of matching symbol strings found in the original data. Furthermore, variable length coding may be utilised for various types of run length or string length dependent data compression for capturing the length of the data over which compressible coherency exists. Additionally, the code used may also be made dependent upon already used or preceding codes. For bit-mapped images, compression methods known as Run-length coding, and CCITT G3 and G4 algorithms are widely used. Run-length coding is a compression scheme that has long been used for facsimile and photo transmission to reduce the amount of data in a bit-mapped image. Run-length coding eliminates repetitive sequences of equal pixel values in each horizontal rasterline by partitioning each rasterline into a series of runs of pixels that have the same values. When images are made up of a few long length runs, run-length encoding can substantially reduce the amount of memory needed to store images. However, as the average run length decreases, the image storage size increases rapidly. Both CCITT G3 and G4 were designed mainly for telecommunication where CCITT G4 is a one-dimensional compression algorithm and CCITT G3 is a two-dimensional compression algorithm. In one-dimensional compression methods, each row of bit-mapped image is compressed independently, while in two-dimensional compression methods, each row of the bit-mapped image is compressed as a function of the data contained in adjacent rows. CCITT G3 and G4 provide adequate compression ratios for bit-mapped images, but because both G3 and G4 operate on individual bits rather than bytes, the CCITT G3 and G4 algorithms are in general, quite complex and slow. Due to the disadvantages of the compression methods described above, a well known compression scheme for bit-mapped images was developed specifically for printers. This compression scheme is referred to as delta-row compression. In delta-row compression, each rasterline in a bit-mapped image is compressed by identifying a section of bytes in a row that is different from the preceding row. The section of bytes that differ from the preceding row are called delta data. A rasterline is then decompressed by a printer by using the immediately preceding row, which is called the reference row, and the delta data. The reference row is changed as indicated by the delta data to recreate a new row. This new decompressed row is then printed and becomes the new reference row. In delta-row compression, a compressed rasterline is output as a sequence of command bytes and the delta (replacement) bytes. Each command contains the following: 1) the number of bytes to replace in the reference row, 2) the relative offset from the last unchanged byte in the reference row where the replacement bytes are to be positioned, and 3) the replacement bytes themselves. The command byte typically consists of eight bits, 0-7, where the upper three bits identify the number of replacement bytes and the lower five bits identify the offset. For example, assume a command byte contains the following data: 010 00111 11111111 The first three bits are the number of bytes to replace in the reference row (two), the next five bits indicate the offset (seven), and the following two bytes are replacement bytes. Thus, the replacement bytes will replace bytes 7 and 8 in the reference row when the new row is created. Although delta-row compression is an improvement over other forms of compression when used with printer control language, delta-row compression uses a fixed format and therefore introduces unnecessary overhead. For example, in delta row compression, if a row is completely different from the reference row, then the entire row must be transmitted. Also, where the first byte of a row is different from the first byte of the reference row, the five-bit offset field is still used to indicate a relative offset of zero bytes. Furthermore, delta row compression uses a fixed bit field to represent the number of bytes to replace, and a separate replacement byte is included in the command even where the replacement bytes are identical. Accordingly, it is an object of the present invention which is set out in the appended claims to provide an improved two-dimensional compression method and system for compressing bi-level bit-mapped images into variable-length mode codes and variable-length-count codes. According to one aspect of the present invention as defined in claim 1, there is provided a computer-based method for compressing bit-mapped data arranged in rows of bytes including a current row and a reference row, wherein each of the bytes in the current row is compared with a corresponding byte in the reference row, the method comprising identifying each of the bytes in the current row as being in a copy mode if the byte is equal to the corresponding byte in the reference row, each of the bytes in the current row as being in a repeat mode if the byte does not equal the corresponding byte in the reference row and the byte equals the next byte in the current row, each of the bytes in the current row as being in a literal mode if the byte does not equal the corresponding byte in the reference row and the byte does not equal the next byte in the current row, assigning a variable-length mode code to each transition from one of the modes to another one of the modes, and representing the current row by one or more of the variable-length mode codes to provide a compressed row of the data. According to another aspect of the present invention as defined in claim 7, there is provided a system for compressing bit-mapped data arranged in rows of bytes including a current row and a reference row, wherein each of the bytes in the current row is compared with a corresponding byte in the reference row, the system comprising: mode setting means for setting either a copy mode, a repeat mode, or a literal mode based on a comparison of each of the bytes in the current row with the corresponding byte in the reference row, the mode setting means including mode transition means for recording each mode transition from one of the modes to another of the modes in the current row; count means for providing a count of how many of the bytes are associated with each of the modes set by the mode setting means in the current row; mode encoding means for encoding each of the mode transitions as a variable-length mode code; count encoding means for encoding each of the counts as a variable-length count code; format means for creating a mode sequence for the bytes in the current row, each of the mode sequences comprising one of the variable-length mode codes, one of the variable- length count codes, and, at least one of the bytes from the current row, if the at least one of the bytes are copied from the current row; and output means for creating a compressed row of the data from the mode sequences. In an alternative embodiment of the present invention, the system is located in a host computer having a parallel interface for transmitting the compressed data. Preferably, the system is characterised by decompressing means for decompressing the compressed row of the data, a frame buffer memory, and wherein the bit-mapped data is a bi-level bit-mapped image which is compressed in a host computer, further characterised in that the decompressing means and the frame buffer memory are located in a printer and in that the compressed bi-level bit-mapped image is transferred to the printer over a parallel interface. and decompressed by the decompression means in the printer, thereby enabling increased data throughput over the parallel interface. The present invention also provides a printer comprising a system for compressing bit-mapped data arranged in rows of bytes including a current row and a reference row, wherein each of the bytes in the current row is compared with a corresponding byte in the reference row, the system being characterised by comprising: mode setting means for setting either a copy mode, a repeat mode, or a literal mode based on a comparison of each of the bytes in the current row with the corresponding byte in the reference row, the mode setting means including mode transition means for recording each mode transition from one of the modes to another of the modes in the current row; count means for providing a count of how many of the bytes are associated with each of the modes set by the mode setting means in the current row; mode encoding means for encoding each of the mode transitions as a variable-length mode code; count encoding means for encoding each of the counts as a variable-length count code; format means for creating a mode sequence for the bytes in the current row, each of the mode sequences comprising one of the variable-length mode codes, one of the variable-length count codes, and, at least one of the bytes from the current row, if the at least one of the bytes are copied from the current row; and output means for creating a compressed row of the data from the mode sequences. Other objects, features and advantages of the present invention will become apparent from the following detailed description when taken in conjunction with the accompanying drawings. The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments of the invention and, together with the following detailed description, serve to explain the principles of the invention: FIG. 1 is a block diagram depicting a data compression algorithm according to a preferred embodiment of the present invention. FIG. 2 is a block diagram depicting a data compression algorithm according to a second preferred embodiment of the present invention. FIG. 3 is a flow chart of the compression process of the compression algorithm. FIG. 4 is a state diagram showing compression transitions between a COPY mode, a REPEAT mode, and a LITERAL mode. FIG. 5 is a table depicting a mode transition encoding scheme according to the present invention. FIG. 6 is a table depicting a count encoding scheme according to the present invention. FIG. 7 is an illustrative example of how the encoder of the present invention compresses a current row of a bit-mapped image into a compressed row given a reference row. FIG. 8 is an illustrative example of how the decoder decompresses a compressed row back into the original decompressed row. Reference will now be made in detail to the preferred embodiments of the invention, examples of which are illustrated in the accompanying drawings. While the invention will be described in conjunction with the preferred embodiments, it will be understood that they are not intended to limit the invention to those embodiments. On the contrary, the invention is intended to cover alternatives, modifications and equivalents, which may be included within the spirit and scope of the invention as defined by the appended claims. FIG. 1 is a block diagram depicting a data compression algorithm 10 of the present invention, which, in a preferred embodiment, is utilized for printer frame memory compression. The data compression algorithm 10 is located within a conventional printer 12, which contains a frame buffer 14 for the temporary storage of an incoming bit-mapped image 16. The compression algorithm 10 includes two pans, an encoder 10a for compressing data, and a decoder 10b for decompressing data. The purpose of the compression algorithm 10 is to reduce the memory requirement of the frame buffer 14 by using the encoder 10a to compress the bit-mapped image 16 before the bit-mapped image 16 is stored in the frame buffer 14. The encoder 10a compresses the bit-mapped image 16, using methods explained below, to create a compressed image 18. The compressed image 18 is then transferred from the frame buffer 14 to the decoder 10b where the compressed image 18 is decompressed to recreate the bit-mapped image 16. After the compressed image 18 has been decompressed, the printer 12 prints the bit-mapped image 16. The compression algorithm 10 may be implemented in the hardware of printer 12 or alternatively, implemented in software, which is executed on a standard processing device within the printer (not shown), such as a microprocessor, for instance. The compression algorithm 10 of the present invention is simple to implement in hardware because it requires few gates, as explained further below, and is less expensive than the memory saved by the smaller frame buffer 14. Thus, the overall cost of the printer 12 is reduced. Referring to FIG. 2, a second preferred embodiment of the compression algorithm is shown. In this embodiment, the compression algorithm 10 is used with a "dumb" printer 30 which lacks sufficient processing power to rasterize data before the data is printed. Therefore, the encoder 10a is located on a host processing device, such a PC 32, for example, and the encoder 10b is located in the dumb printer 30. A bit-mapped image 16 which is to be printed, is compressed by the encoder 10a to produce a compressed image 18. Compressed image 18 is then transferred by the PC 32 to the dumb printer 30 via a parallel interface 38 between the PC 32 and the dumb printer 30. Once the compressed image 18 reaches the dumb printer 30, the decoder 10b decompresses the compressed image 18 back into the bit-mapped image 16 which is then printed by the dumb printer 30. In a preferred embodiment, the encoder 10a is implemented in software and is executed in within the PC 32. The decoder 10b may either be implemented in hardware within the printer 30, or alternatively, implemented in firmware, assuming of course; that the printer 30 contains some form of processor. In contrast with prior art techniques, the simplicity of the encoder 10a dispenses with the requirement for an add-on compression board inside the PC 32. The lack of an add-on compression board reduces the complexity of the compression system and increases compatibility between the printer 30 and the PC 32. Although the present invention is described herein as relating to printer technology and bit-mapped images, the present invention is also applicable to other areas such as I/O compression, bitmap font compression, and outline font caching, for example. The compression and decompression methods of the compression algorithm 10 will now be explained in detail below. The compression algorithm 10 reads a rasterline of an input bit-mapped image 16 and compares the rasterline with the immediately preceding rasterline to check for commonly occurring sequences of bytes. The rasterline currently being read by the compression algorithm 10 is referred to as the current row, and the preceding rasterline to which it is compared is referred to as the reference row. According to the present invention, the current row is compressed by not only identifying a section of bytes in the row that are different from the reference row, as in delta row compression, but also by identifying a section of bytes that are the same as the reference row. Each input byte in the current row is then represented in the compressed image 18 by one of the following three modes: 1) COPY, 2) REPEAT, or 3) LITERAL mode.. The COPY (C) mode indicates that the input byte of the current row is equal to the corresponding byte in the reference row. The REPEAT (R) mode indicates that the input byte of the current row is equal to the previous input byte in the current row. The LITERAL (L) mode indicates that the input byte is not in the above two modes and must therefore be copied as is to the compressed image 18. Referring to FIG. 3, a flow chart of the compression modes of the encoder 10a is shown. The flow chart of FIG. 3 is explained' along with reference to FIGS. 1 and 2. For a given current row in a bit-mapped image 16, the encoder 10a begins compressing the row by reading each byte in the current row, and each corresponding byte in the reference row in sequence (step 40). (If the current row is the first row read from the bit-mapped image 16, then the encoder 10a initializes the reference row to all 0's). The encoder 10a then compares the byte from the current row with the corresponding byte in the reference row (step 41). If the byte from the current row is the same as the byte in the reference row, then the encoder 10a encodes the byte as being in the COPY mode (step 42). If the byte is not the same as the byte in the reference row, then the encoder 10a reads the next byte in the current row (step 43), and compares it with the previous byte in the current row (step 44). If the current byte is equal the previous byte, then the encoder 10a encodes the byte as being in the REPEAT mode (step 45). If the current byte is not equal the previous byte, then the encoder 10a encodes the byte as being in the LITERAL mode (step 46). The mode which is used to encode the current byte, as described above, is the current mode. The current mode continues (Step 47) until a different mode is set. The COPY Mode (Step 42) continues while each byte in the current row matches the corresponding byte in the reference row. The REPEAT mode (Step 45) continues while each byte in the current row matches the preceding byte in the current row. The LITERAL MODE (Step 46) continues while each byte in the current row fails to match the corresponding byte in the reference row and the preceding byte in the current row. Each time a byte is read from the current row, the encoder checks if the byte is the last byte in the current row. If the byte is the last byte in the current row, then the current row becomes the reference row, and the encoder 10a reads the next row, which becomes the new current row. The process above continues until each rasterline in the bit-mapped image 16 is read and compressed. According the present invention, for all bytes encoded as being in the COPY mode, the encoder 10a encodes the bytes according to the following mode format: <COPY mode> <n> where COPY mode is the current mode, and n is a count of the number of data bytes to be copied from the reference row. For all bytes encoded as being in the REPEAT mode, the encoder 10a encodes the bytes according to the following format: <REPEAT mode> <n> <data bytes> where REPEAT mode is the current mode, n is a count indicating that the following data byte is to be repeated <n> + 1 times, and the data byte is the byte to be repeated. For all bytes encoded as being in the LITERAL mode, the encoder 10a encodes the bytes according to the following format: <LITERAL mode> <n> <data bytes> where LITERAL is the current mode, n is a count indicating how many data bytes follow, and the data bytes are the bytes of data to be copied. The current row, once compressed contains sequences of such triplets; a mode code followed by a length code, and optionally followed by one or more data bytes. Below, are example mode sequences: C 12 - indicates that 12 bytes are to be copied from reference row when a new row is created from the reference row; R 27 'A' - indicates that the byte 'A' is to be repeated 28 times in the new row; and L 7 'ABCDEFG' - indicates that the seven bytes 'ABCDEFG' are to be written directly to the new row. As stated above, a compressed rasterline will include a sequence of mode triplets, one following another. Since the modes freely change from one to another in a row, the transition between each pair of modes in a row is called a mode transition. FIG. 4 is a state diagram showing the possible free mode transitions between the COPY mode 50, the REPEAT mode 52, and the LITERAL mode 54. The COPY mode 50 may transition either to the REPEAT mode 52, shown by the arrow 60, or to the LITERAL mode 54, shown by the arrow 62. The LITERAL mode 54 may transition either to the COPY mode 50, shown by arrow 64, or to the REPEAT mode 52, shown by the arrow 66. The REPEAT mode 52 may transition to the COPY mode 50, shown by the arrow 68; the LITERAL mode 54, shown by the arrow 70; and to itself, shown by the loop arrow 72. Note that a mode transition from the COPY mode 50 to the COPY mode 50, and a transition from the LITERAL mode 54 to the LITERAL mode 54, will not occur. The COPY mode 50 will not follow a previous COPY mode 50 because a COPY sequence of two differing sets of bytes will be combined to form one COPY sequence. Similarly, a LITERAL sequence of two differing sets of bytes will also combined to form one LITERAL sequence. Thus, the only way to terminate the COPY mode 50 and the LITERAL mode 54 is to change to another mode. This is different from the REPEAT mode 52 in which a REPEAT of one sequence can be followed by another. For example, the byte sequence "AAAABB" would berepresented as R 4 'A' followed by R 2 'B'. According to the present invention, rather than encoding the modes (COPY, REPEAT, LITERAL) directly in the compressed rasterline, further compression is achieved by only encoding the transitions between a current mode and a previous mode. In the mode transition encoding scheme of the present invention, a variable length mode code is assigned to each mode transition. Referring to FIG. 5, a preferred embodiment of the mode transition encoding scheme of the present invention is shown. Mode transitions between a current mode 82 and a previous mode 80, are shown generally at 78, and correspond to the mode transitions shown in FIG. 4. The mode transitions 78 may be divided into categories based on the value of the previous mode in each mode transition. For example, all mode transitions where the previous mode is COPY, is one transition category; all mode transitions where the previous mode is REPEAT, is a second transition category; and all mode transitions where the previous mode is LITERAL, is a third transition category. According to the present invention, each mode transition in a category is assigned a unique corresponding mode code 84. For the transition category where the previous mode is COPY, a mode code of '0' is assigned when the current mode is REPEAT, and a mode code of '1' is assigned when the current mode is LITERAL. For the transition category where previous mode is REPEAT, a mode code of '0' is assigned when the current mode is REPEAT, a mode code of '10' is assigned when the current mode is LITERAL, and a mode code of '11' is assigned when the current mode is COPY. For the transition category where previous mode is LITERAL, a mode code of '0' is assigned when the current mode is COPY, and a mode code of '1' is assigned to when the current mode is REPEAT. In a preferred embodiment, the mode codes 84 are not explicitly set in the compression algorithm 10, but are rather numerically derived. The mode codes 84 are numerically derived by first enumerating the modes COPY, REPEAT, and LITERAL in order. For example, the COPY mode may be made equal to '0',the REPEAT mode may be made equal to '1', and the LITERAL mode may be made equal to '2'. After the modes are enumerated, mode transitions are classified, using what is called a mode bit, by calculating a modulo function between a previous mode 80 and a current mode 82 in a given mode transition 78. A modulo function is a arithmetic operation whose result is the remainder of a division operation. For example, the equation "2 modulo 3" equals 2, because 2 divided by 3 yields a remainder of 2. In a preferred embodiment, the mode bit is set to either '0' or '1' according the following: When the first rasterline of a bit-mapped image 16 is read, the REPEAT mode is set as the initial previous mode, since the REPEAT mode is the only mode that can transition to all three modes. In addition, the continuity of a mode will not be interrupted by the end of the current row. That is, row boundaries do not affect the compression process except to signal the reading of a new row and to update the reference row. As stated above, each mode code may be followed by a count <n> of the number of data bytes which follow. According the present invention, the counts are also represented in a compressed rasterline as a variable-length code. Referring to FIG. 6, a preferred embodiment of the count encoding scheme of the present invention is shown. Each count <n> 90, representing the number of data bytes in a mode, is encoded by a variable-length count code 92. For example, in the mode triplet R 5 'A',the count five represents that the date byte 'A' is to be repeated six times (n + 1), and the count would be replaced with the count code of '11110.' As shown, when the count 90 is greater than seven and less than 255, a count code of '1110' followed by a count byte (the actual number of bytes) is used to represent the count 90. When the count 90 is greater than or equal to 255, n/255+1 bytes are used to represent the count 90, among which, the first n/255 bytes are 0xff (hexadecimal 255) and the sum of all bytes is n. Referring again to FIGS. I and 2, during compression, the encoder 10a arranges the compressed data such that the decoder 10b can fetch the next byte in a compressed rasterline whenever the encoder 10b requires a byte for decoding. In the compressed rasterline, the variable-length mode codes 84 and the variable-length count codes 92 are grouped into bytes while data bytes follow in natural order. The variable-length mode codes 84 include the bits (0, 1, 10, 11), and the variable-length count codes 92 include the set (0, 10, 1100, 1101, 1110, 11110, 111110, 111111). The data bytes include the following: 1) the bytes following a REPEAT mode code, 2) the bytes following a LITERAL mode code, and 3) the count bytes following the count code 1110 (when the count is greater than 7 and less than 255). FIG. 7 is an example of how the encoder 10a of the present invention compresses a current row 102 of a bit-mapped image into a compressed row 104 given a reference row 100. For the purpose of this example, the reference row 102 contains all zeros and only six bytes (0, 1, 2 ,3,4, 5,) in the current row 100 and reference row 102 are shown. The commas shown in the compressed row 104 are for reference only, and delimit separate mode sequences. Since the first two bytes in the current row 102 are the same as the corresponding bytes in the reference row 100, the current mode is COPY. As stated above, the default previous mode is REPEAT mode, therefore the first set of bits '11' in the compressed row 104 is a mode code indicating a mode transition from REPEAT to COPY. The following set of bits '10' is a count code, indicating that two bytes are to by copied from the reference row 100. Because byte two in the current row 102 is different than the byte three in the reference row 100, and is the same as byte 3 in the current row 102, byte two in the current row 102 may be repeated. The second mode code '0' in the compressed row 104 indicates a mode transition from COPY to REPEAT (see FIG. 5). The next set of bits '0' is a count code indicating that the following data byte '1111111', is to be repeated twice (n + 1). Byte four in the current row 102 is not the same as byte four in the reference row 100, and does not repeat, so the byte four must be copied directly to the compressed row 104. The mode code '10' represents the mode transition from REPEAT to LITERAL (see FIG. 5), and the next bit '0' is a count code indicating the following byte '10101101' is to be copied directly when the compressed row 104 is decompressed. Byte five in the compressed row 102 is identical to the corresponding byte in the reference row 100 and may be copied from the reference row 100. The bit '0' is a mode code indicating a transition from LITERAL to COPY mode (see FIG. 5), and the next bit '0' is count code indicating that one byte from the reference row 100 is to be copied twice (n + 1). The present invention provides compression ratios which are better than delta row compression. The set of variable-length mode codes and count codes described above in a preferred embodiment of the present invention are not optimal for all images. However, they have been found to be quite effective for images that are likely to be printed on a printer including text and graphics. Other sets of codes may be used for different images. Furthermore, an image can be divided into bands such that each band uses one set of codes. A code index at the beginning of the decompressed row for a band can then be used to indicate the variable-length codes. The worst compression case for the compression algorithm 10 is when all bytes in the current row are in the LITERAL mode. In this case n bytes are expanded to n + 0.5 + (n / 255) + 1 bytes, representing a size increase over the reference row by approximately about 0.4 percent. Referring to FIG. 8, an example of how the decoder 10b (FIG. 1) decompresses a compressed row 110 into a decompressed row 112. The data bytes in this example are shown in hexadecimal and, although not shown, the reference row is all zeros, as in the previous example. Also, as in FIG. 7, each mode sequence in the compressed row 110 is separated by a comma for reference. The first mode sequence contains a '10' mode code and a count code of '0' (1 byte). Since previous mode is initially set to REPEAT, the mode code '10' indicates a mode transition from REPEAT to LITERAL mode (see FIG. 5). This mode sequence instructs the decoder to copy the single data byte '1101 1011', which is db in hexadecimal, directly to the decompressed row 112. The second mode sequence contains a '0'mode code and a count code of '10'(2 bytes). Since the previous mode was LITERAL, the mode code '0' indicates a mode transition from LITERAL to COPY (see FIG. 5). This mode sequence instructs the decoder to copy two bytes from the reference row, which are all zero, to the decompressed row 112. The third mode sequence contains a '0' mode code and a count code of '1100' (3 bytes). Since the previous mode was COPY, the mode code '0' indicates a mode transition from COPY to REPEAT mode (see FIG. 5). This mode sequence instructs the decoder to copy the data byte '1100 0010', which is c3 in hexadecimal, to the decompressed row 112 four times. The fourth mode sequence contains a '0' mode code and a count code of '1111111'(7 bytes). Since the previous mode was REPEAT, the mode code '0' indicates a mode transition from REPEAT to REPEAT mode (see FIG. 5). This mode sequence instructs the decoder to copy the data byte '1110 0011', which is e3 in hexadecimal, to the decompressed row eight times. Referring again to FIGS. 1 and 2, the decoder 10b, which decodes mode codes and count codes, can be implemented easily in hardware with very few gates (because there are not many states). The decompression speed is mainly bounded by the memory access time. Therefore, the compression algorithm 10 of the present invention should render slightly faster decompression rates than Delta Row compression. This is due in part because the compression algorithm 10 has a higher compression ratio and thus fewer memory accesses. The compression algorithm 10 also includes a fast compression rate. On a Pentium processor manufactured by Intel Corporation, for example, the compression algorithm 10 is capable of compressing three Megabytes of data per second. In sum, a compression method and system has been disclosed that provides fast compression and decompression rates due to byte-oriented processing, is simple to implement in software or hardware, and has a worst case expansion is only 1/255 or 0.4%. The foregoing descriptions of specific embodiments of the present invention have been presented for purposes of illustration and description. They are not intended to be exhaustive or to limit the invention to the precise forms disclosed, and it should be understood that many modifications and variations are possible in light of the above teaching. The embodiments were chosen and described in order to best explain the principles of the invention and its practical application, to thereby enable others skilled in the art to best utilize the invention and various embodiments with various modifications as are suited to the particular use contemplated. It is intended that the scope of the invention be defined by the Claims appended hereto.

Claims: A computer-based method for compressing bit-mapped data arranged in rows of bytes including a current row and a reference row, the method comprising comparing (40) each of said bytes in said current row with a corresponding byte in said reference row, identifying each of said bytes in said current row as being in a copy mode if said byte is equal to said corresponding byte in said reference row (41, 42), identifying each of said bytes in said current row as being in a repeat mode if said byte does not equal said corresponding byte in said reference row and said byte equals the next byte in said current row (44, 45), identifying each of said bytes in said current row as being in a literal mode if said byte does not equal said corresponding byte in said reference row and said byte does not equal the next byte in said current row (44, 46), assigning a variable-length mode code (84) to each transition (78) from one of said modes (80) to another one of said modes (82), and representing said current row by one or more of said variable-length mode codes to provide a compressed row of said data. A method as in claim 1 characterised in that successive bytes in the current row identified as being in the literal mode are grouped in the compressed row of said data. A method as in claim 1 or claim 2 characterised in that the compressed row of said data further includes, for each variable length mode code a count (90) indicating how many of said bytes are associated with each variable length mode code. A method as in claim 3 characterised in that sad count is provided as a variable length count code (92) after each one of said variable length mode codes for representing how many of said bytes are associated with each variable length mode code. A method as in claim 4 characterised by the step of representing said compressed row of data as a plurality of mode sequences wherein each of said mode sequences includes one of said variable-length mode codes followed by one of said variable-length count codes followed by particular ones of said bytes from said current row. A method as in any one of claims 1 to 5 characterised in that said step of assigning said variable-length mode codes includes assigning one of said variable-length mode codes to each transition between: said copy mode to said repeat mode, said copy mode to said literal mode, said repeat mode to said repeat mode, said repeat mode to said literal mode, said repeat mode to said copy mode, said literal mode to said copy mode, and said literal mode to said repeat mode. A system for compressing bit-mapped data arranged in rows of bytes including a current row and a reference row, wherein each of said bytes in said current row is compared with a corresponding byte in said reference row, said system comprising: mode setting means for setting either a copy mode (42), a repeat mode (45), or a literal mode (46) based on a comparison (41) of said each of said bytes with said corresponding byte in said reference row, said mode setting means including mode transition means for recording each mode transition from one of said modes to another of said modes in said current row; count means for providing a count of how many of said bytes are associated with each of said modes set by said mode setting means in said current row; mode encoding means for encoding each of said mode transitions as a variable-length mode code (84); count encoding means for encoding each of said counts as a variable-length count code (92); format means for creating a mode sequence for said bytes in said current row, each of said mode sequences comprising one of said variable-length mode codes, one of said variable-length count codes, and, at least one of said bytes from said current row, if said at least one of said bytes are copied from said current row; and output means for creating a compressed row of said data (18) from said mode sequences. A system as in claim 7 characterised by storage means and wherein said bit-mapped data is a bi-level bit-mapped image, said system functioning to compress said bit-mapped image before storage of said bit-mapped image in said storage means, thereby reducing the memory requirement of said storage means. A system as in claim 8 characterised in that said storage means comprises a frame buffer memory (14). A system as in claim 7, 8 or 9 characterised by decompressing means (10b) for decompressing said compressed row of data. A printer characterised by a system as in any one of claims 7 to 10. A system as in claim 7 characterised in that the system is located in a host computer (32) having a parallel interface (38) for transmitting said compressed data (18). A system as in claim 12 characterised by decompressing means (10b) for decompressing said compressed row (18) of said data, a frame buffer memory, and wherein said bit-mapped data is a bi-level bit-mapped image which is compressed in said host computer (32), further characterised in that said decompressing means (10b) and said frame buffer memory are located in a printer (30) and in that the compressed bi-level bit-mapped image is transferred to said printer over said parallel interface (38) and decompressed by said decompression means (10b) in said printer (30), thereby enabling increased data throughput over said parallel interface (38).

Inventors: CHI SHAN, CHI, SHAN, Chi, Shan, c/o S-MOS Systems Inc,
Applicants: SEIKO EPSON CORP, SEIKO EPSON CORPORATION
Application year: 1995
Main classification: G06T9
IPC codes: H03M7, H04N1, G06T9