
AUTOMATIC GENERATION OF C++/JAVA CODE FOR BINARY ARITHMETIC CODING Danny Hong and Alexandros Eleftheriadis Columbia University Dept. of Electrical Engineering New York, NY 10027, USA ABSTRACT used. Despite such wide use of BACs, different BACs are gener- ally incompatible with each other (e.g., the code string generated by Binary arithmetic coding is, compression-wise, the most effective sta- an arithmetic encoder specified in JBIG cannot be correctly decoded tistical coding method used in image and video compression. It is be- by an arithmetic decoder specified for MPEG-4 shape coding); as a ing used for compressing bi-level images (JBIG, JBIG2, and MPEG- remedy, we present a unique solution that unifies binary arithmetic 4 shape coding) and is also being utilized (optionally) for coding of coders (BACs). We define a set of parameters that can be used to continuous-tone images (JPEG) and videos (H.264). Despite its wide automatically generate different variants of BACs. use, different arithmetic coders are incompatible with each other and Arithmetic coding can be separated into two main parts: mod- application developers are faced with the difficult task of understand- eling and coding. The modeling part appropriately selects one or ing and building each coder. We present a set of simple parameters more structures for conditioning events, and gathers the relative fre- that can be used to describe any binary arithmetic coder that is cur- quencies of the conditioned events [9, 19], which correspond to the rently being deployed, and we also introduce a software tool for au- event probabilities. Modeling, by itself, is a huge topic and there tomatically generating C++/Java code for binary arithmetic coding are numerous effective models that have been introduced. The H.264 according to the description. standard alone defines more than 300 models to account for different structures each bit of the binarized syntactic elements might have. Consequently, unifying modeling is an extremely difficult task (if not 1. INTRODUCTION impossible), and we focus only on the coding part. Flavor [20, 21] is a language that has been developed to describe Huffman coding [1] is arguably the most widely used statistical com- the syntax of any compressed bitstream so that the bitstream parsing pression mechanism for media representation (e.g., Group 3 [2] and and generation code can be automatically generated. Flavor already Group 4 [3] fax, MPEG-1 [4], MPEG-2 [5], and etc.). It is proven has constructs for describing variable-length codes and we comple- to be optimal among instantaneous (prefix) codes as it can repre- ment it by introducing a set of new constructs for describing binary sent any given random variable within 1 bit of its entropy. Arith- arithmetic codes. Using Flavor with the new constructs, the cod- metic coding [6, 7], derived from Elias coding [8], is another statis- ing part of any BAC can be easily described and the corresponding tical coding method proven to yield better compression than Huff- C++/Java code can be automatically generated. As a result, applica- man coding; however, it has not been widely used for media cod- tion developers can solely concentrate on the modeling part, which ing due to its complexity and patent issues. The very first, practical has been shown to have a very high impact on the compression effec- arithmetic coder was developed for compressing bi-level images (the tiveness of the BAC compared to the coding part. Skew coder [9, 10] and the Q-Coder [11]), as Huffman coding can- The next section briefly describes the main concept behind binary not compress binary symbols, unless groups of symbols are coded at arithmetic coding, Sections 3 and 4 present the constructs needed to a time. Run-length coding (e.g., Golomb coding [12]) is a good al- describe practical BACs, and we conclude with Section 5. ternative coding method for binary symbols, when the probability of one symbol is much higher than the other. Nevertheless it is a static coding method and for the best result for all possible binary source 2. BACKGROUND sequences, using an adaptive binary arithmetic coder (BAC) yields better compression. A high-level pseudo-code describing the basic concept of binary arith- Even today, most of the practical arithmetic coders deal solely metic coding is depicted in Figure 1. The variable R represents the with binary alphabets: binary arithmetic coding is computationally current interval (initially 1) and the interval is divided into two subin- simple and it makes using higher-order conditioning models feasi- tervals (R0 and R1) according to the probabilities of the two possible ble. In some cases it is only natural to assume a binary source. For symbols (P0 and P1=1-P0). The variable L represents the lower instance, JBIG [13], JBIG2 [14], and MPEG-4 shape coding [15] fo- bound of the current interval (the interval is represented as [L, L+R)) cus on coding of bi-level images (JBIG and JBIG2 can also be used and if the symbol 0 is being coded, then, assuming that R0 is al- for grayscale images where bit-plane by bit-plane coding is applied), ways above R1, the new interval is [L+R1, L+R1+R0); likewise, for and for JPEG2000 [16] and MPEG-4 texture coding [15], bit-plane symbol 1, the new interval is [L, L+R1). For coding of each sym- coding is ultimately applied. On the other hand, arithmetic coding bol, the current interval gets subdivided and at the end, the minimum can optionally be used in JPEG [17] and H.264 [18], and in these number of bits that can uniquely represent the final interval gets out- cases, each syntactic element is first binarized so that a BAC can be put as the code string. For decoding, the variable V represents the code string and the decoder essentially mimics the encoding process This material is based upon work supported in part by the National Sci- to deduce the original symbols. X represents the current symbol en- ence Foundation under Grant ACI-0313116. coded/decoded. the upper subinterval to the symbol 0 and the lower subinterval to 1) R0 = R*P0 1) R0 = R*P0 1 (0 over 1 SOC) as shown in Figure 2. Alternatively, it has been 2) R1 = R-R0 2) R1 = R-R0 shown to be optimal (computation-wise), for software arithmetic cod- 3) if (X == 0) R = R0, L = L+R1 3) if (V-L >= R1) R = R0, L = L+R1, X = 0 ing, to have the upper subinterval assigned to the least probable sym- else R = R1 else R = R1, X = 1 bol (LPS) and the lower one to the most probable symbol (MPS) [11]. (a) Encoding (b) Decoding This results in one less operation when coding an MPS than coding an LPS. On the other hand, when parallel processing is possible, the MPS over LPS SOC is more efficient. In Flavor, the SOC keyword Fig. 1. Binary Elias coding. can be set to one of the four options: 1) LM – LPS over MPS, 2) ML – MPS over LPS, 3) 01 – 0 over 1, and 4) 10 – 1 over 0. Another possibility is to have any mixture of the above four options; as long The current interval of an arithmetic coder is referred to as the as both the encoder and decoder follow the same SOC, there will be state (or internal state) of the coder, and there are many ways to rep- no ambiguity; however, all of the currently available BACs use one of resent it. As in the above example, we can use L and R. Alternatively, the four simple SOCs listed above, and there is no inherent advantage let H be the upper (higher) bound of the current interval, and the inter- of using any combination of the four options. val can be represented by [L, H). There are also other representations 4) Truncation excess (TE). In Figure 2, due to the integer di- but as long as the intervals do not overlap, the decoder can yield cor- vision applied, R0 gets truncated and the excess range is assigned rect symbols. Additionally, all units of the current interval should to R1. The best way to distribute the truncation excess (TE) due to be assigned to any one of the subintervals to maximize compression. integer arithmetic is to assign the TE to the two subintervals accord- The Flavor-generated code uses the [L, L+R) interval convention. ing to the corresponding symbol probabilities. However, this can be too complex (none of the currently availabe BACs supports this), and 3. INTEGER ARITHMETIC CODING the next best choice is to assign the TE to the MPS. Although it is very simple to assign the TE to the MPS when SOC=LM or ML,an To overcome the precision problem inherent in Elias coding, most of extra comparison is required (per symbol) when SOC=01 or 10.As the practical arithmetic coders are implemented using integer arith- a result, Flavor supports four options MPS, LPS, 0, 1 for the TE metic with renormalization [7, 11]. Though it is possible to use keyword (e.g., TE=0 assigns the TE to the symbol 0). floating-point numbers, integer arithmetic is preferred for its simplic- 5) When to renormalize (R). Using a fixed-precision arithmetic ity and better portability. As a consequence of using integer arith- coding requires a renormalization process, which prevents R from metic, the probabilities of the symbols are represented by respective getting too small (so that R can be represented by a fixed-bit integer counts (C0and C1), and the corresponding integer, binary arithmetic and that underflow can be prevented).
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages4 Page
-
File Size-