Home | History | Annotate | Download | only in dec
      1 /* Copyright 2015 Google Inc. All Rights Reserved.
      2 
      3    Distributed under MIT license.
      4    See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
      5 */
      6 
      7 package org.brotli.dec;
      8 
      9 /**
     10  * Common context lookup table for all context modes.
     11  */
     12 final class Context {
     13 
     14   static final int[] LOOKUP = new int[2048];
     15 
     16   private static final String UTF_MAP = "         !!  !                  \"#$##%#$&'##(#)#+++++++++"
     17       + "+((&*'##,---,---,-----,-----,-----&#'###.///.///./////./////./////&#'# ";
     18   private static final String UTF_RLE = "A/*  ':  & : $  \u0081 @";
     19 
     20   private static void unpackLookupTable(int[] lookup, String map, String rle) {
     21     // LSB6, MSB6, SIGNED
     22     for (int i = 0; i < 256; ++i) {
     23       lookup[i] = i & 0x3F;
     24       lookup[512 + i] = i >> 2;
     25       lookup[1792 + i] = 2 + (i >> 6);
     26     }
     27     // UTF8
     28     for (int i = 0; i < 128; ++i) {
     29       lookup[1024 + i] = 4 * (map.charAt(i) - 32);
     30     }
     31     for (int i = 0; i < 64; ++i) {
     32       lookup[1152 + i] = i & 1;
     33       lookup[1216 + i] = 2 + (i & 1);
     34     }
     35     int offset = 1280;
     36     for (int k = 0; k < 19; ++k) {
     37       int value = k & 3;
     38       int rep = rle.charAt(k) - 32;
     39       for (int i = 0; i < rep; ++i) {
     40         lookup[offset++] = value;
     41       }
     42     }
     43     // SIGNED
     44     for (int i = 0; i < 16; ++i) {
     45       lookup[1792 + i] = 1;
     46       lookup[2032 + i] = 6;
     47     }
     48     lookup[1792] = 0;
     49     lookup[2047] = 7;
     50     for (int i = 0; i < 256; ++i) {
     51       lookup[1536 + i] = lookup[1792 + i] << 3;
     52     }
     53   }
     54 
     55   static {
     56     unpackLookupTable(LOOKUP, UTF_MAP, UTF_RLE);
     57   }
     58 }
     59