METHOD AND APPARATUS FOR COMPRESSING AND DECOMPRESSING IMAGE DATA

Abstract: Image data such as text or half-tone images is compressed and decompressed. A compressor has three phases: a bit-run length phase (32) that counts the length of each run of consecutive identical pixels; a pairs-repetition phase (36) that compresses repeated pairs of pixel run values to one copy of the repeated pair and a repeat count; and an optional dictionary-based micro-table encoder (50). The micro-table (80), which may be used in any application calling for a least recently used (LRU) mechanism, has multiple qualification layers (82, 84, and 86), with elements within a qualification layer being promoted to the next higher qualification layer upon the occurrence of a table hit for that element, and being demoted to the next lower qualification layer by being bumped by elements promoted up from below. The result is a table that is weighted both by frequency and recency of hits.

Description: METHOD AND APPARATUS FOR COMPRESSING AND DECOMPRESSING IMAGE DATA BACKGROUND OF THE INVENTION Field of the Invention The present invention generally relates to the art of data compression, and more specifically to lossless image data compression and decompression. Description of the Related Art Transmission and storage of image data information is becoming increasingly important in today's computerized world. Image scanners, photocopy machines, telephone facsimile machines, and the like, digitize an image such as a sheet of printed text or a drawing and then store or transmit that image as a bitmap. When such image data is digitized, it is desirable to compress the data to increase the throughput rate, decrease the amount of memory storage or transmission bandwidth required, increase the resolution of the stored image, or some combination of these. Because image data typically includes large amounts of redundant information, it is often possible to remove much of the redundant information, thereby reducing the number of bits required to represent the image. Compression is the process of removing the redundant information. Decompression is the process of reconstructing the original data from the compressed data. Existing techniques provide many useful data compression for various applications. For example, ISO/IEC Standard 11172-3, known as MPEG, is optimized to balance picture quality and compression ratio for a moving color video image. This is a "lossy" compression technique, meaning that at least in some circumstances information is lost in the encoding process, and the image cannot be reconstructed completely accurately. A lossless compression technique, known as the "LZ" system is described by Lempel and Ziv in their paper, "A Universal Algorithm for Sequential Data Compression," IEEE Transactions on Information Theory, Volume IT-23, No. 3, May 1977. The LZ system uses fixed length code values which represent input data symbol strings of varying length. The system attempts to use a single code value to represent as many data symbols as possible. The LZ system employs a table, variously known as a translation table, history array, or dictionary, in which blocks of code symbols are stored into the history array as they are processed. Future occurrences of the same blocks of data values are replaced by an index, which points to the location within the history table in which that block is stored. The LZ algorithm is therefore "adaptive," yielding increasingly greater compression ratios as the history array is built up and modified. A variation on the LZ algorithm is disclosed in U.S. Patent No. 4,881,075, issued to Weng. This system employs two translation tables, one being used to compress and decompress data, while the other is being built, so that encoding is always being performed with a full history table. One significant disadvantage with dictionary-based encoding methods is that such techniques typically require large amounts of memory. For example, the preferred embodiment in Weng's compressor uses a dictionary with 4096 entries. The large table size is typically needed because unless a dictionary contains a large number of entries, or the input stream contains a small number of possible symbols and symbol combinations, the resulting compression ratio will be small and therefore of minimal value. Large dictionaries, where implemented in hardware, require large amounts of memory to implement and are therefore costly in terms of both circuit real estate, search times, and dollars. Larger dictionaries implemented in software also generally suffer from longer access times. A need exists therefore for a lossless image compression technique that achieves high compression ratios for image data, and can be implemented with a relatively small dictionary, if any. SUMMARY OF THE INVENTION The present invention provides a lossless data compression method and apparatus that achieves high compression ratios, requires only a small dictionary if any, and is particularly well suited to compressing image data that represents printed text, line drawings, and half-tones. In one aspect of the present invention, an encoder has multiple coding phases, where each stage is particularly well suited for compressing the output data from the prior phase. The first phase is bit-run length coding. The input data stream is examined, and runs of consecutive values are replaced with the number of values in that run, and the compressed data passed along to a second phase for further compression. The second phase is pairs repetition ("pairs-rep") coding. Consecutively repeating pairs of values are replaced with one copy of the repeated pairs, and a repetition count. A further aspect of the present invention lies in the implementation of a dictionary-based encoding phase. This encoding phase forms a third and optional phase of the multiple phase encoder. In this third phase, an adaptive dictionary is used to further eliminate remaining redundancies. Because the first two phases of encoding extract out much of the redundancies existing in the initial data stream, the dictionary can be implemented using a very small table called a micro-table, thus greatly decreasing the amount of circuitry required in a hardware implementation. The micro-table is weighted, meaning that when a new element is added to the table, the element to be pushed off the micro-table is the element of lowest priority, where priority is assigned on the basis of frequency and recency of use. Within the overall encoder, the bit-run encoder is more than merely one type of compression mechanism. The bit-run encoder changes the nature of the data. By encoding the bitmap as its bit-run lengths, the bit-run phase produces a data stream that is usually easier to compress than the raw bitmap. Image components are resolved at the pixel level so that byte boundary positions within the bitmap are no longer important. Many simple patterns, including solid color halftones, become encoded as a repeated pair of run counts, the first count indicating the white run length and the second indicating the black run length, or vice versa. Because the second encoding phase is optimized to compress repeated pair data, a unique synergism exists between the decoder phases. None of the three phases implemented individually is capable of achieving consistently high compression ratios. It is the combination of these phases that produces a result that is greater than the sum of the individual phases, yielding effective compression across a wide variety of documents. Accordingly, one feature of the present invention is to provide multiple phase encoding, with the first phase being bit-run length encoding. Another feature of the present invention is to provide multiple phase encoding, including a bit-run compressor, a pairs-repetition compressor, and a dictionary-based compressor. Still another feature of the present invention is to provide a multiple phase encoder, the final phase being dictionary-based compression using a very small dictionary. Yet another feature of the present invention is to provide a micro-table having multiple tiers, wherein an element that has been repeated a number of times is given priority over an element that has been repeated a fewer number of times. Still another feature of the present invention is to provide a simple method of updating and weighting a micro- table having multiple tiers. These and other features and advantages of the present invention will be apparent to those skilled in the art from the following detailed description, taken together with the accompanying drawings, in which like reference numerals refer to like parts. DESCRIPTION OF THE DRAWINGS FIG. 1 is an overall block diagram of the image data compressor of the present invention. FIG. 2 is an example of the encoding process according to one illustrative embodiment of the present invention. FIG. 3 illustrates the physical organization of a single-tier micro-table according to the present invention. FIG. 3A illustrates the logical organization of the micro-table of FIG. 3. FIG. 4 illustrates the physical effect of a micro- table hit. FIG. 4A illustrates the logical organization of the micro-table of FIG. 4 before a micro-table hit. FIG. 4B illustrates the logical organization of the micro-table of FIG. 4 after a micro-table hit. FIG. 5 illustrates the physical effect of a micro- table miss on the micro-table of FIG. 4. FIG. 5A illustrates the conceptual effect of a micro- table miss on the micro-table of FIG. 4. FIG. 6 illustrates a micro-table having three tiers. FIG. 7 illustrates the physical effect of a micro- table hit on a multiple-tiered micro-table, according to a simple swap micro-table update technique. FIG. 8 illustrates the conceptual effect of the micro-table hit illustrated in FIG. 7. FIG. 9 illustrates the physical effect of a micro- table hit on a multiple-tiered micro-table, according to a move-to-top micro-table update technique. FIG. 10 illustrates the conceptual effect of the micro-table hit illustrated in FIG. 9. FIG. 11 illustrates a micro-table implemented in hardware, with a hardware comparator that searches all locations within the micro-table concurrently. FIG. 12 illustrates a data decompressor according to the present invention. FIG. 13 depicts a software implementation of a bit- run compression phase. FIG. 14 depicts a software implementation of a pairs- rep compression phase. FIG. 15 depicts a software implementation of a micro- table compression phase. FIG. 16 depicts a software implementation of a micro- table decompression phase. FIG. 17 depicts a software implementation of a pairs- rep decompression phase. FIG. 18 depicts a software implementation of a bit- run decompression phase. DETAILED DESCRIPTION OF THE INVENTION The following discussion makes reference to a specific embodiment used for illustrative purposes. As those skilled in the art will appreciate, many of the parameters used in the following discussion, such as code word length and dictionary address range and data depth, may be changed without departing from the scope of the present invention. I. COMPRESSION FIG. 1 presents an overview of a data compressor according to the present invention. A scanning device 12 (not part of the present invention) scans an image 10 and converts the image into a stream of raw image data. The scanning device may be a hand-held scanner such as used with personal computers, or may be embedded in a facsimile machine, photocopier, or the like. The raw image data is compressed using a bit-run length compression algorithm implemented in a bit-run compressor 16; further compressed using a pairs-repetition compression algorithm implemented in a pairs-rep compressor 20; and, optionally, further compressed using a dictionary-based micro-table compression algorithm in a micro-table compressor 24. Where the compressor is implemented in hardware, optional First-In-First-Out (FIFO) memories 18 and 22 are used to pass data between successive compression phases. The FIFOs increase throughput by eliminating latencies between successive compression phases. Where the compressor is implemented in software, FIFO_top and FIFO_bottom pointers emulate FIFO operation. Code packer 26 switches either pairs-rep data, or pairs-rep data further compressed by the micro-table, to the output depending on which is the denser. The compressed output data may be stored into permanent memory such as magnetic hard disk 28, stored into temporary memory such as RAM, or transmitted to a remote location. The benefits of compressing the data may be correspondingly realized as smaller memory requirements or shorter transmission times. FIG. 2 illustrates how the image data is compressed at each phase in the compression process in the preferred embodiment. Data representing a scanned image comprises binary data stream 30, with "0" representing white bits and "1" representing black bits, or vice versa. When the scanned image is a printed page containing text or line drawings, data stream 30 will contain large runs of consecutive l , s or consecutive O's. A. BIT-RUN COMPRESSION Bit-run compressor 32 counts the length of each run and generates a data stream 34 that is a series of run length values. The polarity of each run is the opposite of the previous run's polarity. In the preferred embodiment, run values are encoded as nibbles (4 bits) . However, as those skilled in the art will appreciate, run-length values could alternatively be represented as bytes (8 bits) , words (16 bits) , long words (32 bits) , or any length desired to achieve the best compression ratio for the particular data to be compressed. Longer run length values may be more suitable for a particular implementation such as processing high resolution (e.g., 1200 dots per inch) data. Conversely, short run length values will more efficiently encode data which contains only short runs. In the preferred embodiment, 4-bit values are used. Nibble values of 1 to 15 indicate run lengths of 1 to 15, respectively. A nibble value of 0 indicates a partial run length of 15 in the current polarity and that the run is continued in the following nibble. Thus, runs equal to or longer than 16 bits are encoded by outputting a nibble value of zero for each 15 bits of the run, followed by a final nibble with a value between 1 and 15 that indicates the remaining run length. The following table shows examples of bit-run encoding. TABLE 1 Bit- -Run Lenσth Nibble Encodinσ 1 1 15 F 16 01 30 OF 31 001 The following table illustrates how a stream of raw pixel data is encoded by the bit-run length compressor. Bit-Run Length Compression Input daU stream 1111111101111111(XX)111111100011111110001111(XXX)0111100000 Compressed string 1000 0001 0111 0011 0111 0011 0111 0011 0100 0101 0100 0101 using nibbles Decimal representation 8 1 7 3 7 3 7 3 4 5 4 5 In FIG. 2, input data stream 30 will be encoded as shown in bit-run length compressed stream 34. FIG. 13 depicts the software implementation of the bit-run encoder. A first bit is read at block 200, and the bit-run count is set to 1. At block 202, if the data bit is not the last bit in a transmission or record, then the next bit is read in at block 204. If the bits are the same, as determined by block 206, the run count is incremented at block 208. If the run count is less than the maximum (the maximum being 15 in the preferred embodiment) , then unless the end of the data has been reached at block 202, the next bit is read in at block 204 again. On the other hand, if the count exceeds the maximum permissible count, then the count is reset to 1 and a "0" is written to the output, denoting that the run count exceeds 15. If the bits compared at block 206 were different, then the run has come to an end, the current count is written to the output, the count is reset to 1, and the bit fetch and count process is begun again. When the end of a data transmission or record is encountered at block 202, the run count up to that point is output at block 216 and the bit-run encoder is finished. In the preferred embodiment using nibble values, the maximum run that can be compressed into a 4-bit code value is 15 bits. Therefore, the maximum compression ratio achievable in this first phase is 15:4, or 3.75:1. Even if larger codes were used to store the run counts consistently good ratios could not be expected. To improve on bit-run compression a second compression phase is added. B. PAIRS-REP COMPRESSION The second compression phase is a pairs-repetition (pairs-rep) compressor 36. It compresses repeating pairs of bit-run codes. There are various specific encoding schemes that could be used for the pairs-rep phase. In the preferred embodiment, pairs-rep compressor 36 identifies repeating patterns and encodes them with a repeat count specifier and one copy of the repeating values. Any data that is not encoded as part of pairs- repetition is left unchanged. Pairs-Rep Compression Bit-Run data 8 1 7 3 7 3 7 3 4 5 4 5 Pairs-Rep Compressed Data 1 8 1 3 7 3 2 4 5 Output 38 of pairs-rep compressor 36 is organized into bytes. Each byte is either a code or data. The first byte must be a code. Each code indicates how many bytes of data follow it. When the data for a code haε been exhausted, another code value is output. The high order bit of a code indicates its type and the low order 7 bits indicate a count. If the type bit is clear, then the count indicates the number of literal (unpaired) data bytes to follow. For example, in data stream 38 in FIG. 2, the first 2-byte word contains the following information: a 0 bit in type field 44 denotes that the data to follow will be a literal; the value of 1 in the count field 46 denotes that the literal data will be one byte long (two nibbles) ; and the value of 81 (hex) in data field 48 represents the run- length data (8 bits of one polarity, followed by 1 bit of the opposite polarity) . In scanned text, blank horizontal scan lines and margins appear as long strings of consecutive white bits. These will be encoded by the bit-run encoder as a series of nibble values equal to 0, as illustrated in Table 1. These data will be further encoded by the pairs-rep encoder as a series of blocks, each block containing the values "7F 0 0" (hex) . The 7-bit value "7F" denotes 127 repetitions, and the "0 0" denotes 15 white and 15 more white. Each block of 16 bits will therefore represent 127 x 30 = 3810 consecutive white pixels, yielding a maximum compression ratio of 3810:16 (238:1). FIG. 14 depicts the software implementation of the pairs-rep encoder. At block 220, the first byte is read in from the previous (bit-run) phase. If this byte is not the end of the transmission or record, then pairε count is set equal to zero at block 224. Blocks 226, 228, and 230 together count the number of non-repeating bytes in the data stream; control falls out of this loop only when two identical consecutive bytes are detected by block 228. Once that happens, the non-repeating byte count (literal count) is output at block 232, and the literals are repeatedly shifted out at block 236 until the literal stream is exhausted, as determined by block 234. Once the literals have been shifted out in response to a repeated byte having been detected at 228, then the repeat count is set to 2 at block 238, and the number of times the byte is repeated is counted in the loop consisting of blocks 240, 242, and 244. As soon as block 242 detectε that the byte (nibble pair) haε ceased repeating, then the repeat count and corresponding nibble pair is output at block 246, and the procesε begun over again, until block 222 detectε that the end of the tranεmiεsion or record has been encountered. Although the first two phaseε will have eliminated much of the redundancy in the εcanned data, some redundancy will remain in many cases. C. MICRO-TABLE COMPRESSION The third compression phase, the micro-table dictionary encoder 50 (FIG. 2) , is used to seek out redundancies that remain after the bit-run and pairs-rep phases are completed. The data passed to the final phase will not be very compresεible. The key to εuccess in this third phase is to compresε the portions of the data that can be compresεed without expanding the portions that are not compressed. Because the final compression phase will be operating on data that is already compressed, the amount of data operated on is therefore smaller, thus reducing the requirements for this final phase. Less speed is required since the third phase . will operate on lesε data. Furthermore, only a εmall compreεεion ratio iε needed to achieve a good overall compreεεion ratio, becauεe the ratio of the third phase will be multiplied by the ratio of the prior two phases. For example, if the prior two phaseε achieve a 5:1 compreεsion, then a mere 2:1 compression in the third phase will produce an overall syεtem compression of 10:1. This allows the table to be implemented in hardware at a cost much less than if the table had to operate on raw, uncompressed data. Micro-table 50 works by storing data patterns that were encountered in data εtream 38. When a pattern match occurs between data stream 38 and a string previously stored in micro-table 50, micro-table 50 outputs a code with a "l" in its most significant bit (MSB) position, and the remaining bits representing an index into micro-table 50 where that pattern was previously stored. In the example depicted in FIG. 2, micro-table 50 containε 2 5 =32 locationε of 16 bitε each. Code 56 conεiεts of 6 bits: a 1-bit flag in the MSB poεition and 5 remaining index bits. When there is no pattern match between the data stream and the table, a 9-bit value 58 is output with a "0" in its MSB position indicating a literal, and the remaining 8 bits equal to the literal data. In FIG. 2, the pattern 3,7,3 had been previously encountered and stored at location ID (hex) within the micro-table, so when that pattern iε encountered again the micro-table compreεsor replaces that pattern with the index value ID in output code 56. As discussed above, where a line of the image being scanned iε all white, a εingle 16-bit block of data from the pairε-rep encoder will repreεent 3810 all white bits. This 16-bit block of data will be further compresεed by the micro-table into a 6-bit code word, yielding a maximum overall compression ratio of 3810:6 (635:1) for blank lines. The table is considered a weighted Most Recently Used (MRU) table. It stores the patterns that have occurred most recently and removes patterns that have not occurred recently. The mechaniεm is weighted such that the frequency of a pattern's occurrence is taken into consideration. A pattern that occurred more than once will be kept in the table longer than a pattern that occurred only a single time. It is this weighted MRU mechanism that allows the encoder to work with a very small number of table entries. The micro-table iε maintained in εuch a way that entries that are frequently used are given priority over entries that are not frequently used when removing an entry from the table to make room for a new entry. 1. Single Qualification Layer Micro-table 50 can be constructed in variouε wayε. A firεt and εimpler micro-table embodiment, having only a single qualification layer, is shown in FIGS. 3 to 5B. FIG. 3 shows the micro-table physical (actual) organization, and FIG 3A shows the logical (conceptual) organization. Referring to FIG. 3, micro-table 60 is comprised of a εtack having eight locationε. A stack pointer bottom_ptr 62, implemented in either software or hardware, containε an index into the εtack. The location pointed to by bottom_ptr 62 is defined as the logical bottom of the stack, with the physical bottom wrapping around to the physical top of the stack. Incrementing bottom_ptr 62 has the logical effect of shifting the stack downward, with the bottom value being bumped off the bottom and placed onto the top. Table Hit Referring to FIG. 4, when a search of the table results in a match (table hit) , hit element 68 is moved to the logical top of the table to indicate that it is the most recently used. This is accomplished physically by performing a swap of hit element 68 with the element pointed to by bottom_ptr 62, then incrementing bottom_ptr 62. Referring to FIG. 4A, the logical effect of incrementing bottom__ptr 62 is that the data in the location it previously pointed to - in this case the hit element 68 (after the swap) - becomes the new logical top element. Advancing bottom_ptr 62 also has the effect of decreasing the priority of every other element in the table. The one aspect of this mechanism that differs from pure least recently used (LRU) functionality is that, as a result of the swap operation, whatever element was previously at the logical bottom of the table is moved up to fill the slot vacated by the hit element, which was moved to the logical top. The effect of this is that, for every table hit, the elementε in the table below the hit element will be cycled. The element at the bottom of the table will, at any given time, not necessarily be the least recently used. However, while the bottom element can artificially have its priority boosted by a large amount, other elements will only decreaεe in priority at a rate of one element per table access. As long aε an element iε frequently hit, it will never reach the bottom of the table. Alternatively, thiε mechaniεm can be enhanced by handling hits very near the top of the micro-table specially. For example, if a hit occurs on the top element no action is needed, and if a hit occurs on the second element all that is needed is a swap of the first two elements to move the εecond element to the top. Handling theεe aε εpecial caεeε may εerve to improve the functionality of the micro-table in cases where the bottom element would have been moved to very near the top. Table Miss The phyεical and logical effectε of a table miεε are shown in FIGS. 5 and 5A, respectively. When a search of the table does not result in a match (table miss) the new (search) element 72 is inserted at the logical top of the table and the element 74 at the bottom of the table is removed to make room for it. This is accomplished physically by replacing the element 74 pointed to by bottom_ >tr 62 with new element 72, then adjusting bottom_ptr 62 to point to the next higher priority element 76. Just as it does on a table hit, advancing the position pointed to by bottom_ptr 62 makes hit element 72, which replaced bottom element 74, the new top and decreaseε the priority of all the other elementε. When adding a new element to the micro-table aε the reεult of a miss, the MRU mechanism employed functions the same as a LRU mechaniεm. Although the micro-table could be implemented using a LRU mechaniεm, with very εimilar reεultε, uεing the MRU mechanism disclosed is considerably more efficient, especially when the encoder is implemented in software. The recently used pattern preservation characteristicε of the MRU mechaniεm makeε it useful aε a compreεεion dictionary in its own right. However, extending the MRU mechanism, as disclosed below, results in even greater utilization of a very small amount of table space. 2. Multiple Qualification Layers A second micro-table embodiment, having multiple qualification layerε, iε εhown in FIG 6. Thiε embodiment repreεentε an extension of the MRU mechanism that results in even greater utilization of a very small amount of table space. A qualification layer is simply a section (tier) of the table which is given a separate qualification status (weight) . Micro-table 80 is composed of multiple tiers which are stacked one on top of the other where the bottom tier is given the lowest qualification status and each subεequent tier has a greater status than the one below it. In the preferred embodiment, micro-table 80 is divided into three qualification layers. Top layer 86 and middle layer 84 each contain 8 locations, and bottom layer 82 contains 16 locations, for a total of 32 locations. Each tier of the micro-table 80 is maintained as a separate MRU mechanism. An element within a tier is promoted to the next higher tier when a "hit" of that element occurs. An element is demoted to the next lower tier by being bumped off, as a result of other elements being promoted up to its level. For purposes of the discuεεion below, references to searching micro-table 80 refer to the collective table. In other words, each element in each tier of micro-table 80 iε searched for the target pattern until either the pattern is found or all of the elements in all of the tiers 82, 84, and 86, have been checked. When, as a reεult of a table εearch, a match is found, the hit element is removed from its current position and inεerted at the top of the next higher tier uεing the MRU add proceεε previouεly deεcribed. The element removed from the bottom of the higher tier iε placed in the original tier of the hit element uεing one of the following two methodε. Table Hit FIGS. 7 and 8 illustrate a first (simple swap) method. Referring to FIG. 7, physically when a hit occurs, matched element 90 within lower tier 92 is swapped with bottom element 96 within higher tier 94, and the higher tier'ε bottom_ptr 98 is incremented. Referring to FIG. 8, conceptually when a hit occurs, hit element 90 within lower tier 92 is moved up to the top of higher tier 94, and all the remaining elements within upper tier 94 bumped down by one position; what had been the bottom element of higher tier 94, after being bumped off the higher tier, gets put into the position within the lower tier that was vacated by hit element 90. One advantage to the εingle εwap method iε that it iε eaεy and simple to implement. FIGS. 9 and 10 illustrate a second (move-to-top) method. Referring to FIG. 9, phyεically when a hit occurs, hit element 90 is moved into the bottom spot of higher tier 94; element 102 removed from the bottom of higher tier 94 is inserted at the top of the lower (hit) tier 92; the spot vacated by the hit element 90 is replaced by the logical bottom element of the same tier 92; and both bottom_ptrs 98 and 100 for the two tierε are incremented. Referring to FIG. 10, conceptually this move-to-top comprises the following stepε: hit element 90 iε moved to the top of the next higher tier 94, bumping down all elements within that tier; and the element 96 that had been at the bottom of upper tier 94 gets bumped off the bottom and moved to the top position of tier 92. Conceptually, this can be thought of as performing the previously described simple swap method followed by a MRU update of the original tier to move the value from the hit position (now the element from the bottom of the higher tier) to the logical top of the original tier. When a match is found in the highest tier of the micro-table, a MRU update can be performed to move the hit element to the top of that tier. Alternatively, the encoder may perform no action at all, leaving the micro- table unchanged εimply because the hit element is already in the highest tier and the exact position within that tier is of limited importance. Table Miss When a search of the micro-table does not result in a match (i.e., the target pattern is not in any tier of the table) , the target pattern is simply added to the bottom tier using the MRU add operation. FIG. 15 depicts the software implementation of a micro-table encoder having two tiers. A first 16-bit symbol from the pairε-rep encoder is read in at block 250. If this symbol is not the end of the transmiεεion or record, then a micro-table εearch iε conducted at block 254 to determine whether thiε symbol has previously been stored in the micro-table dictionary. If the symbol is found within the micro-table, then the table index pointing to that symbol is output at block 258. If the table hit occurred in a lower tier, then a multi-tier table hit update operation is performed at block 262; otherwise, the table is left unchanged. If the symbol is not found in the table at block 256, then the εymbol (literal) iε output directly and a table miεs update operation is performed at block 266. The effect of using a multi-tiered micro-table is as follows. Each time an element is hit and moved up to the next higher tier it becomes more entrenched in the micro- table, i.e., more heavily weighted. Because of the multiple tiers, an element can not be removed as a result of simple disuse. An element which has climbed into the upper tiers of the micro-table will only be removed if some other element reaches the same level and replaces it. When the micro-table encoder encounters a long series of unencodable data it adds an element to its bottom tier for each input pattern. As long as none of the patterns are hit again, none of them will climb to higher tiers of the table. This is how patterns which have reached the higher tiers are preserved even if they have not been hit recently. An important and useful result is that bursts of unencodable (single-occurrence) data can not displace patterns in the upper tiers of the micro-table. Likewise, data which occurs only twice and therefore reaches the second tier can not displace patterns in the third tier. Because the encoder uses such a small table, it is important that the quality of patterns stored in the table (with respect to the input data) makes up for the lack of quantity. Using the MRU mechanism provides for a good degree of quality in the patterns and storing the data in multiple tiers reduces the ability of low-occurrence patterns to replace the more useful patternε in the micro- table. One advantage of using a small table is that the hardware required to implement it will be inexpensive relative to a larger table. A secondary benefit iε that since there are fewer table entries, the table can be indexed by a small regiεter. Likewise, the index, which is used as the code in the compresεed data εtream, will contain a small number of bitε. Thiε translates into a compact encoding scheme, i.e., good compression. There are various posεible ways to εearch the micro- table. When the micro-table iε implemented in hardware, one method iε simply to sequentially enable each table location output onto a common bus, and compare that value to the search value. Thiε iε slow. A much faster method, albeit one requiring a more complex architecture, is to implement a hardware comparator for each table location, with the search value being compared to every location within the table simultaneouεly. Thiε method is shown in FIG. 11. The search value is loaded into search register 100 and simultaneouεly compared to the hiεtory data εtored at each dictionary location within micro-table 108. If, for example, the search data matches the data εtored at top location 102, then the correεponding 5-bit hardwired index value IF (hex) within hardwired register 104 will be output onto the table_index bus. This 5-bit value, combined with a MSB 106 of 1, will become the 6-bit code value 110 output from the micro-table compreεεor. Alternatively, the micro-table may be implemented in εoftware. When the micro-table is implemented in software, a hash table may be used to increase the table search speed. A haεh table is a Random Accesε Memory (RAM) wherein every poεεible data value that can be εtored in the micro-table has a corresponding address within the hash table. For example, a 16-bit deep micro-table will require a hash table having 64k (2 16 = 65,536 locations) addresses. If 16-bit data value 8373 (hex) is to be stored into location ID (hex) into the micro-table, then the value ID is stored at address 8373 within the hash table. The next time that the micro-table encoder performs a table search to see if the code value 8373 has been stored within the micro-table, it simply accesses address 8373 within the hash table. The haεh data at that addreεs is ID, so the encoder knows that the search data (8373) can be found at address ID within the micro-table. Whenever a value is bumped off of the micro-table, the addresε within the haεh table correεponding to the bumped data must be written to and an appropriate flag set at that location to indicate that the hash data at that location is no longer valid. Before the hash table is used, all locations must be initialized to a reserved value. This reserved value, when read by the micro-table compressor, denotes that no valid pattern equal to that hash table addresε haε yet been εtored in the micro-table. Whenever a new compreεεed record iε to be generated or tranεmitted, and a haεh table is not being used, the micro-table must be initialized with an initialization value at each location before encoding can begin. In the foregoing discussion, the micro-table mechanism of the present invention haε been used for purposes of compression and decompression. However, as those skilled in the art will appreciate, the same mechaniεm may be applied in place of a leaεt recently uεed (LRU) εtack in numerouε real-world applications. These include, but are not limited to, cache mechanisms such as disk caches and memory caches, LRU mechanisms which are used in other types of compressors and decompresεors, and virtual memory mechanisms. The effect on the elements of the stack are slightly different from that of a typical LRU. However, many applications may benefit from the micro-table's simplicity which will result in a low cost of implementation in hardware or a high performance implementation in εoftware. D. CODE PACKER Referring once more to FIG. 1, depending on the characteristics of the image being scanned and whether micro-table 24 has a sufficient data history built up within it, micro-table compresεor 24 might actually expand the data from pairs-rep compresεor 20 rather than compresε it. Thus, it may be more efficient to disable micro-table 24. Also, where micro-table 24 is implemented in software, there will be an overhead asεociated with performing the micro-table compreεεion. Still further, in εome εyεtemε in which data tranεfer timeε are already very high, micro-table 24 might not be required. For theεe reasons, it may actually improve total εystem throughput to disable micro-table 24 when compresεing typical documentε. But becauεe there will be εome pages that will not compresε acceptably without micro-table phaεe 24, it should be selectable when needed. Code packer 26 determines whether or not micro-table 24 will be enabled. In a hardware implementation as shown in FIG. 2, code packer 26 will either use the pairs-rep compreεεor 20 output, or will use the micro-table compressor 24 output. In a software implementation, code packer 26 will enable or disable the micro-table compresεor 24. There are variouε poεεible algorithmε by which code packer 26 could operate. In a first method, code packer 26 will use the micro-table 24 output only if the compression ratio generated by the firεt two phaseε, 16 and 20, does not meet some pre-selected threshold level. At that point, since the page was complicated to compress, it is likely that rasterization was slow anyway so compresεion time will be leεs significant. In a second method, code packer 26 will use the micro-table 24 output whenever the compression ratio generated by the first two phases, 20 and 16, is significantly different than for the previous band (indicating a change in the nature of the bitmap data) . If it produces significant gains for the test band, then apply the final phase to subsequent bands as well. Other algorithms on which code packer 26 could operate will be obvious to those skilled in the art. II. DECOMPRESSION Referring to FIG. 12, decompression according to the present invention is basically the inverse of compression. A data stream representing a compresεed bitmap iε received from a data εource such as magnetic disk 120. The data is first decompressed by micro-table decompresεor 122, then by pairε-rep decompressor 126, and finally by bit-run decompressor 130 before being passed to an output device such as laser printer 132. As with the compresεor of FIG. 1, optional FIFO'ε 124 and 128 buffer the data between εuccessive decompressor phaseε εo aε to eliminate latency and therefore increase throughput speed. The various phaseε of decompreεεion are deεcribed more fully below. A. MICRO-TABLE DECOMPRESSION In micro-table decompreεsion phase 122, the compresεed data εtream iε proceεεed in the εame order it was output from the compressor and the data is parsed to distinguish match codes from literal values. As the data is processed, the table information is reconstructed so that the decompressor will know what pattern value should correspond to each poεεible input code value. During micro-table decompression 122, the table is manipulated in much the same way as in compression. The primary difference is that each, input value indicates directly if a match has occurred and, if so, at what table position (instead of requiring a search as in compression) . If there is a table match, micro-table decompressor 122 updates the table the same way micro- table compresεor 24 (FIG. 1) doeε for a match at the εame poεition. Likewise, for a table miss the bottom tier of the micro-table iε updated with a MRU-add operation εimilar to the one performed during compreεεion. By reproducing the table manipulationε performed by micro-table compreεsor 24, micro-table decompresεor 122 produces an equivalent table. Therefore, when micro-table compressor 24 findε a match and outputs a code indicating the table position, micro-table decompresεor 122 can find out what the matching pattern waε by looking at that poεition in itε own copy of the table. There iε one complication to micro-table decompreεεion. When micro-table compreεεor 24 can not find a match for a pattern it only outputs a portion of that pattern as a literal value. The remainder is appended with additional data from the input data stream and the table is again searched. Since literals only represent a portion of the original pattern, micro-table decompressor 122 can not immediately εtore the entire pattern in the MRU when a literal iε encountered. Inεtead micro-table decompreεεor 122 waitε until it receiveε the εubεequent code or character which will reveal the remainder of the pattern to be added to the micro-table with the previouε literal. Alternatively, micro-table compreεεor 24 (FIG. 1) could be conεtructed εuch that the entire literal pattern iε encoded in the compressor's output stream when a table miss occurs. In that caεe, the pattern would be immediately available to micro-table decompreεεor 122 and could therefore be added to the table as soon as it is received. FIG. 16 depicts the software implementation of a micro-table decompressor have a two-tiered dictionary. A block of code is read in at block 272. If the code representε a table hit at block 274 (e.g., if MSB of code word 56 or 58 in FIG. 2 iε a "1"), then control passes to block 276. If the prior code had represented a table miss (i.e., flag prev had not been set to -1) , then insert the code as the least significant byte of the top of the lower table at block 278; either way, output the hit element and set the prev flag to indicate a table hit. If the hit is within the top tier at block 282, then do nothing. If the hit is in the bottom tier at block, then move the hit element to the top of the top tier at block 284, and read in the next byte. If, on the other hand, the code represents a table miss, then control passes to block 286. If the prior code had represented a table miss, then insert the code at the top of the lower table at block 288; either way, insert the code as the most significant byte of the top element in the lower table, at block 290, and read in the next byte. B. PAIRS-REP DECOMPRESSION Pairs-rep decompressor 126 replicates the repeated pair the number of times specified by the count indicator. Non-repeating data is simply transferred to the output of the pairs-rep decompressor unaltered. FIG. 17 depicts the software implementation of pairs- rep decompresεor 126. The firεt code byte from a micro- table decompressor is read at block 294. If the code byte indicates that it representε repeated data at block 296 (e.g., if the code'ε MSB 44 iε a "1" in FIG. 2) then the next byte (which iε the repeated data) iε read in at block 298, and iε output at block 302 the appropriate number of timeε, where this number of times is specified by the 7 least significant bits (LSB's) of the first code byte, and counted down in block 300. If the code byte indicates that the data to follow is literal data (e.g., if the code's LSB 44 is a "0" in FIG. 2) , then the appropriate number of bytes is read and output at block 306, while block 304 counts down the literal data byte count. C. BIT-RUN DECOMPRESSION Bit-run decompreεεor 130 converts the stream of run length indicatorε from pairs-rep decompresεor 126 into a stream of 1's and O's. For each run count, that number of bitε of the current polarity are output and the polarity iε toggled. If the count iε zero then the maximum run length iε output and the polarity is not toggled. FIG. 18 depicts the εoftware implementation of bit- run decompreεεor 130. A nibble of code iε read in at block 312. If the code nibble is not 0, then the run length is the value of the nibble, at block 318; if the nibble is equal to 0, then the run length is greater than 15 and continues to the next nibble, at 316. At blocks 320 and 322, a "1" or a "0" iε output the number of timeε equal to the run length. At block 324, if the code waε not equal to 0 (data run doeε not continue to the next nibble) then the polarity of the output bit is changed from 0 to 1, or vice versa. The procesε then εtartε over again at block 310 for the next nibble. The invention haε been described with reference to monochrome image data, comprising a εtream of bitε that repreεent black bitε and white bitε. However, the preεent invention iε in no way limited to the compreεεion and decompression of monochrome image data. A stream of bitmap data may be uεed not only to repreεent black-and-white pixel data, but may alεo represent one channel of color pixel data, such as one component of RGB color data or one component of luminance/chrominance color data, with corresponding increases in storage or transmission efficiencies. The invention haε been alεo deεcribed with reference to a dictionary having elements of fixed length of 16 bits. However, dictionaries may be constructed which encode variable length strings. For example, U.S. Patent No. 5,179,378, isεued to Ranganathan et al. , diεcloses one method of using code words to represent data εtrings within a dictionary table, where the data strings encoded are of variable length. As those skilled in the art will appreciate, many such variable length encoding techniques may be used in combination with the present invention. Although the present invention has thus been described in detail with regard to the preferred embodiments and drawings thereof, it should be apparent to those skilled in the art that various adaptations and modifications of the present invention may be accomplished without departing from the εpirit and the εcope of the invention. Accordingly, it iε to be understood that the detailed description and the accompanying drawings as set for hereinabove are not intended to limit the breadth of the present invention, which should be inferred only from the following claims and their appropriately construed equivalents.

Claims: WE CLAIM: 1. A method of compressing an input data stream, compriεing the εteps of: (a) run-length compressing the input data stream to produce a first compressed data stream; and (b) pairs-rep compressing the first compressed data stream to produce a εecond compreεsed data stream. 2. A method as in claim 1, in which step (b) comprises the substeps of: (c) identifying consecutively repeating pairs of values in the first compressed data stream; (d) determining numbers of times the pairs of values consecutively repeat respectively; and (e) generating first values corresponding to the repeating pairs and the numbers respectively. 3. A method as in claim 1, further comprising the step of: (c) compressing the second compressed data stream using dictionary-based compression to produce a third compressed data stream. 4. A method as in claim 3, in which step (c) comprises the substeps of: (d) storing dictionary elements in locations within a dictionary, the dictionary elements corresponding to the first values respectively; and (e) generating second values corresponding to the locations respectively. 5. A method of decompressing a compressed first data stream, comprising the steps of: (a) pairs-rep decompressing said compressed first data stream to produce a second data stream; and (b) run-length decompressing the second data stream to produce a decompressed data stream. 6. A method of updating a leaεt recently uεed (LRU) stack in which the LRU stack contains elements therein, and a pointer indicates a loweεt priority element in the LRU stack, the method comprising the steps of: (a) demoting elements in the LRU stack by replacing the lowest priority element with a most recently used element; and (b) advancing the pointer. 7. A method as in claim 6, in which the LRU stack is a dictionary in a dictionary-based data compression process. 8. A method as in claim 7, further comprising the step of: (c) locating an element within the dictionary by using an element value as a hash table address, in which a value stored at the hash table address indicates where the element resides within the dictionary. 9. A method of updating a least recently used (LRU) stack having a first sub-stack and second sub-stack, each sub-stack containing elements therein, the method comprising the steps of: promoting an element by moving said promoted element from εaid first sub-stack to said second sub-stack; and demoting an element by moving said demoted element from said second sub-stack to said first sub-stack. 10. A method as in claim 9 , where each sub-stack includes a corresponding pointer which indicates a lowest priority element within the sub-stack, the method further comprising the steps of: replacing the lowest priority element with a most recently uεed element; and incrementing the pointer. 11. A method as in claim 9, in which the LRU stack is a dictionary in a dictionary-based data compreεεion proceεε. 12. An apparatuε for compreεεing digital image data, comprising: bit-run compressor means for successively counting a number of consecutive identical bits in an input binary data stream, and generating a εtream of values representing the numbers of consecutive identical bits respectively; and pairs-repetition compresεor meanε for successively identifying repeated pairs of values in the stream of values, and replacing the repeated pairs with values representing repeat counts and the repeating pairs respectively. 13. An apparatus as in claim 12, further comprising: dictionary-based compressor means for replacing segments of the stream of values with index values, each index value pointing to an element within a dictionary, each element corresponding to a replaced segment. 14. An apparatus as in claim 13, in which the dictionary contains a maximum of 32 elements. 15. An apparatus as in claim 13, further comprising switching means for enabling and disabling the dictionary- based compressor means. 16. An apparatus as in claim 15, in which the switching means is responsive to a compression ratio achieved by at least one of said compressor means. 17. An apparatus for decompressing digital image data, comprising: pairε-repetition decompreεεor means for replacing a repetition count and a pair of values in a data stream with the pair of values repeated a number of times corresponding to the repetition count; and bit-run decompressor means for replacing a bit-run count in the stream of valueε with a εtring conεiεting of a number of succesεive identical bitε, the number of εucceεsive identical bits corresponding to the bit-run count. 18. An apparatus as in claim 17, further comprising: dictionary-based decompresεor means for replacing values within the data stream with elements previously stored within a dictionary, the replaced valueε indicating locations within the dictionary where the elements are stored.

Inventors: BRADBURN BRENT M, FRAZIER ALLEN L, BRADBURN, BRENT, M., FRAZIER, ALLEN, L.
Applicants: DP TEK DEV COMPANY L L C, DP-TEK DEVELOPMENT COMPANY L.L.C.
Application year: 1996
Main classification: G06F
IPC codes: G06T9, H03M7, H04N1