34 #define GLYPH_COORD_VECT_SIZE 16 
   35 #define PALETTE_SIZE 256 
   36 #define PALETTE_DELTA 768 
   39     0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0, 1, 2, 2, 1
 
   43     0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2
 
   47     0, 2, 5, 7, 7, 7, 7, 7, 7, 5, 2, 0, 0, 0, 0, 0
 
   51     0, 0, 0, 0, 1, 3, 4, 6, 7, 7, 7, 7, 6, 4, 3, 1
 
   55     {   0,   0 }, {  -1, -43 }, {   6, -43 }, {  -9, -42 }, {  13, -41 },
 
   56     { -16, -40 }, {  19, -39 }, { -23, -36 }, {  26, -34 }, {  -2, -33 },
 
   57     {   4, -33 }, { -29, -32 }, {  -9, -32 }, {  11, -31 }, { -16, -29 },
 
   58     {  32, -29 }, {  18, -28 }, { -34, -26 }, { -22, -25 }, {  -1, -25 },
 
   59     {   3, -25 }, {  -7, -24 }, {   8, -24 }, {  24, -23 }, {  36, -23 },
 
   60     { -12, -22 }, {  13, -21 }, { -38, -20 }, {   0, -20 }, { -27, -19 },
 
   61     {  -4, -19 }, {   4, -19 }, { -17, -18 }, {  -8, -17 }, {   8, -17 },
 
   62     {  18, -17 }, {  28, -17 }, {  39, -17 }, { -12, -15 }, {  12, -15 },
 
   63     { -21, -14 }, {  -1, -14 }, {   1, -14 }, { -41, -13 }, {  -5, -13 },
 
   64     {   5, -13 }, {  21, -13 }, { -31, -12 }, { -15, -11 }, {  -8, -11 },
 
   65     {   8, -11 }, {  15, -11 }, {  -2, -10 }, {   1, -10 }, {  31, -10 },
 
   66     { -23,  -9 }, { -11,  -9 }, {  -5,  -9 }, {   4,  -9 }, {  11,  -9 },
 
   67     {  42,  -9 }, {   6,  -8 }, {  24,  -8 }, { -18,  -7 }, {  -7,  -7 },
 
   68     {  -3,  -7 }, {  -1,  -7 }, {   2,  -7 }, {  18,  -7 }, { -43,  -6 },
 
   69     { -13,  -6 }, {  -4,  -6 }, {   4,  -6 }, {   8,  -6 }, { -33,  -5 },
 
   70     {  -9,  -5 }, {  -2,  -5 }, {   0,  -5 }, {   2,  -5 }, {   5,  -5 },
 
   71     {  13,  -5 }, { -25,  -4 }, {  -6,  -4 }, {  -3,  -4 }, {   3,  -4 },
 
   72     {   9,  -4 }, { -19,  -3 }, {  -7,  -3 }, {  -4,  -3 }, {  -2,  -3 },
 
   73     {  -1,  -3 }, {   0,  -3 }, {   1,  -3 }, {   2,  -3 }, {   4,  -3 },
 
   74     {   6,  -3 }, {  33,  -3 }, { -14,  -2 }, { -10,  -2 }, {  -5,  -2 },
 
   75     {  -3,  -2 }, {  -2,  -2 }, {  -1,  -2 }, {   0,  -2 }, {   1,  -2 },
 
   76     {   2,  -2 }, {   3,  -2 }, {   5,  -2 }, {   7,  -2 }, {  14,  -2 },
 
   77     {  19,  -2 }, {  25,  -2 }, {  43,  -2 }, {  -7,  -1 }, {  -3,  -1 },
 
   78     {  -2,  -1 }, {  -1,  -1 }, {   0,  -1 }, {   1,  -1 }, {   2,  -1 },
 
   79     {   3,  -1 }, {  10,  -1 }, {  -5,   0 }, {  -3,   0 }, {  -2,   0 },
 
   80     {  -1,   0 }, {   1,   0 }, {   2,   0 }, {   3,   0 }, {   5,   0 },
 
   81     {   7,   0 }, { -10,   1 }, {  -7,   1 }, {  -3,   1 }, {  -2,   1 },
 
   82     {  -1,   1 }, {   0,   1 }, {   1,   1 }, {   2,   1 }, {   3,   1 },
 
   83     { -43,   2 }, { -25,   2 }, { -19,   2 }, { -14,   2 }, {  -5,   2 },
 
   84     {  -3,   2 }, {  -2,   2 }, {  -1,   2 }, {   0,   2 }, {   1,   2 },
 
   85     {   2,   2 }, {   3,   2 }, {   5,   2 }, {   7,   2 }, {  10,   2 },
 
   86     {  14,   2 }, { -33,   3 }, {  -6,   3 }, {  -4,   3 }, {  -2,   3 },
 
   87     {  -1,   3 }, {   0,   3 }, {   1,   3 }, {   2,   3 }, {   4,   3 },
 
   88     {  19,   3 }, {  -9,   4 }, {  -3,   4 }, {   3,   4 }, {   7,   4 },
 
   89     {  25,   4 }, { -13,   5 }, {  -5,   5 }, {  -2,   5 }, {   0,   5 },
 
   90     {   2,   5 }, {   5,   5 }, {   9,   5 }, {  33,   5 }, {  -8,   6 },
 
   91     {  -4,   6 }, {   4,   6 }, {  13,   6 }, {  43,   6 }, { -18,   7 },
 
   92     {  -2,   7 }, {   0,   7 }, {   2,   7 }, {   7,   7 }, {  18,   7 },
 
   93     { -24,   8 }, {  -6,   8 }, { -42,   9 }, { -11,   9 }, {  -4,   9 },
 
   94     {   5,   9 }, {  11,   9 }, {  23,   9 }, { -31,  10 }, {  -1,  10 },
 
   95     {   2,  10 }, { -15,  11 }, {  -8,  11 }, {   8,  11 }, {  15,  11 },
 
   96     {  31,  12 }, { -21,  13 }, {  -5,  13 }, {   5,  13 }, {  41,  13 },
 
   97     {  -1,  14 }, {   1,  14 }, {  21,  14 }, { -12,  15 }, {  12,  15 },
 
   98     { -39,  17 }, { -28,  17 }, { -18,  17 }, {  -8,  17 }, {   8,  17 },
 
   99     {  17,  18 }, {  -4,  19 }, {   0,  19 }, {   4,  19 }, {  27,  19 },
 
  100     {  38,  20 }, { -13,  21 }, {  12,  22 }, { -36,  23 }, { -24,  23 },
 
  101     {  -8,  24 }, {   7,  24 }, {  -3,  25 }, {   1,  25 }, {  22,  25 },
 
  102     {  34,  26 }, { -18,  28 }, { -32,  29 }, {  16,  29 }, { -11,  31 },
 
  103     {   9,  32 }, {  29,  32 }, {  -4,  33 }, {   2,  33 }, { -26,  34 },
 
  104     {  23,  36 }, { -19,  39 }, {  16,  40 }, { -13,  41 }, {   9,  42 },
 
  105     {  -6,  43 }, {   1,  43 }, {   0,   0 }, {   0,   0 }, {   0,   0 },
 
  109     0,   0,   1,   0,   2,   0,   3,   0,   5,   0,
 
  110     8,   0,  13,   0,  21,   0,  -1,   0,  -2,   0,
 
  111    -3,   0,  -5,   0,  -8,   0, -13,   0, -17,   0,
 
  112   -21,   0,   0,   1,   1,   1,   2,   1,   3,   1,
 
  113     5,   1,   8,   1,  13,   1,  21,   1,  -1,   1,
 
  114    -2,   1,  -3,   1,  -5,   1,  -8,   1, -13,   1,
 
  115   -17,   1, -21,   1,   0,   2,   1,   2,   2,   2,
 
  116     3,   2,   5,   2,   8,   2,  13,   2,  21,   2,
 
  117    -1,   2,  -2,   2,  -3,   2,  -5,   2,  -8,   2,
 
  118   -13,   2, -17,   2, -21,   2,   0,   3,   1,   3,
 
  119     2,   3,   3,   3,   5,   3,   8,   3,  13,   3,
 
  120    21,   3,  -1,   3,  -2,   3,  -3,   3,  -5,   3,
 
  121    -8,   3, -13,   3, -17,   3, -21,   3,   0,   5,
 
  122     1,   5,   2,   5,   3,   5,   5,   5,   8,   5,
 
  123    13,   5,  21,   5,  -1,   5,  -2,   5,  -3,   5,
 
  124    -5,   5,  -8,   5, -13,   5, -17,   5, -21,   5,
 
  125     0,   8,   1,   8,   2,   8,   3,   8,   5,   8,
 
  126     8,   8,  13,   8,  21,   8,  -1,   8,  -2,   8,
 
  127    -3,   8,  -5,   8,  -8,   8, -13,   8, -17,   8,
 
  128   -21,   8,   0,  13,   1,  13,   2,  13,   3,  13,
 
  129     5,  13,   8,  13,  13,  13,  21,  13,  -1,  13,
 
  130    -2,  13,  -3,  13,  -5,  13,  -8,  13, -13,  13,
 
  131   -17,  13, -21,  13,   0,  21,   1,  21,   2,  21,
 
  132     3,  21,   5,  21,   8,  21,  13,  21,  21,  21,
 
  133    -1,  21,  -2,  21,  -3,  21,  -5,  21,  -8,  21,
 
  134   -13,  21, -17,  21, -21,  21,   0,  -1,   1,  -1,
 
  135     2,  -1,   3,  -1,   5,  -1,   8,  -1,  13,  -1,
 
  136    21,  -1,  -1,  -1,  -2,  -1,  -3,  -1,  -5,  -1,
 
  137    -8,  -1, -13,  -1, -17,  -1, -21,  -1,   0,  -2,
 
  138     1,  -2,   2,  -2,   3,  -2,   5,  -2,   8,  -2,
 
  139    13,  -2,  21,  -2,  -1,  -2,  -2,  -2,  -3,  -2,
 
  140    -5,  -2,  -8,  -2, -13,  -2, -17,  -2, -21,  -2,
 
  141     0,  -3,   1,  -3,   2,  -3,   3,  -3,   5,  -3,
 
  142     8,  -3,  13,  -3,  21,  -3,  -1,  -3,  -2,  -3,
 
  143    -3,  -3,  -5,  -3,  -8,  -3, -13,  -3, -17,  -3,
 
  144   -21,  -3,   0,  -5,   1,  -5,   2,  -5,   3,  -5,
 
  145     5,  -5,   8,  -5,  13,  -5,  21,  -5,  -1,  -5,
 
  146    -2,  -5,  -3,  -5,  -5,  -5,  -8,  -5, -13,  -5,
 
  147   -17,  -5, -21,  -5,   0,  -8,   1,  -8,   2,  -8,
 
  148     3,  -8,   5,  -8,   8,  -8,  13,  -8,  21,  -8,
 
  149    -1,  -8,  -2,  -8,  -3,  -8,  -5,  -8,  -8,  -8,
 
  150   -13,  -8, -17,  -8, -21,  -8,   0, -13,   1, -13,
 
  151     2, -13,   3, -13,   5, -13,   8, -13,  13, -13,
 
  152    21, -13,  -1, -13,  -2, -13,  -3, -13,  -5, -13,
 
  153    -8, -13, -13, -13, -17, -13, -21, -13,   0, -17,
 
  154     1, -17,   2, -17,   3, -17,   5, -17,   8, -17,
 
  155    13, -17,  21, -17,  -1, -17,  -2, -17,  -3, -17,
 
  156    -5, -17,  -8, -17, -13, -17, -17, -17, -21, -17,
 
  157     0, -21,   1, -21,   2, -21,   3, -21,   5, -21,
 
  158     8, -21,  13, -21,  21, -21,  -1, -21,  -2, -21,
 
  159    -3, -21,  -5, -21,  -8, -21, -13, -21, -17, -21,
 
  160     0,   0,  -8, -29,   8, -29, -18, -25,  17, -25,
 
  161     0, -23,  -6, -22,   6, -22, -13, -19,  12, -19,
 
  162     0, -18,  25, -18, -25, -17,  -5, -17,   5, -17,
 
  163   -10, -15,  10, -15,   0, -14,  -4, -13,   4, -13,
 
  164    19, -13, -19, -12,  -8, -11,  -2, -11,   0, -11,
 
  165     2, -11,   8, -11, -15, -10,  -4, -10,   4, -10,
 
  166    15, -10,  -6,  -9,  -1,  -9,   1,  -9,   6,  -9,
 
  167   -29,  -8, -11,  -8,  -8,  -8,  -3,  -8,   3,  -8,
 
  168     8,  -8,  11,  -8,  29,  -8,  -5,  -7,  -2,  -7,
 
  169     0,  -7,   2,  -7,   5,  -7, -22,  -6,  -9,  -6,
 
  170    -6,  -6,  -3,  -6,  -1,  -6,   1,  -6,   3,  -6,
 
  171     6,  -6,   9,  -6,  22,  -6, -17,  -5,  -7,  -5,
 
  172    -4,  -5,  -2,  -5,   0,  -5,   2,  -5,   4,  -5,
 
  173     7,  -5,  17,  -5, -13,  -4, -10,  -4,  -5,  -4,
 
  174    -3,  -4,  -1,  -4,   0,  -4,   1,  -4,   3,  -4,
 
  175     5,  -4,  10,  -4,  13,  -4,  -8,  -3,  -6,  -3,
 
  176    -4,  -3,  -3,  -3,  -2,  -3,  -1,  -3,   0,  -3,
 
  177     1,  -3,   2,  -3,   4,  -3,   6,  -3,   8,  -3,
 
  178   -11,  -2,  -7,  -2,  -5,  -2,  -3,  -2,  -2,  -2,
 
  179    -1,  -2,   0,  -2,   1,  -2,   2,  -2,   3,  -2,
 
  180     5,  -2,   7,  -2,  11,  -2,  -9,  -1,  -6,  -1,
 
  181    -4,  -1,  -3,  -1,  -2,  -1,  -1,  -1,   0,  -1,
 
  182     1,  -1,   2,  -1,   3,  -1,   4,  -1,   6,  -1,
 
  183     9,  -1, -31,   0, -23,   0, -18,   0, -14,   0,
 
  184   -11,   0,  -7,   0,  -5,   0,  -4,   0,  -3,   0,
 
  185    -2,   0,  -1,   0,   0, -31,   1,   0,   2,   0,
 
  186     3,   0,   4,   0,   5,   0,   7,   0,  11,   0,
 
  187    14,   0,  18,   0,  23,   0,  31,   0,  -9,   1,
 
  188    -6,   1,  -4,   1,  -3,   1,  -2,   1,  -1,   1,
 
  189     0,   1,   1,   1,   2,   1,   3,   1,   4,   1,
 
  190     6,   1,   9,   1, -11,   2,  -7,   2,  -5,   2,
 
  191    -3,   2,  -2,   2,  -1,   2,   0,   2,   1,   2,
 
  192     2,   2,   3,   2,   5,   2,   7,   2,  11,   2,
 
  193    -8,   3,  -6,   3,  -4,   3,  -2,   3,  -1,   3,
 
  194     0,   3,   1,   3,   2,   3,   3,   3,   4,   3,
 
  195     6,   3,   8,   3, -13,   4, -10,   4,  -5,   4,
 
  196    -3,   4,  -1,   4,   0,   4,   1,   4,   3,   4,
 
  197     5,   4,  10,   4,  13,   4, -17,   5,  -7,   5,
 
  198    -4,   5,  -2,   5,   0,   5,   2,   5,   4,   5,
 
  199     7,   5,  17,   5, -22,   6,  -9,   6,  -6,   6,
 
  200    -3,   6,  -1,   6,   1,   6,   3,   6,   6,   6,
 
  201     9,   6,  22,   6,  -5,   7,  -2,   7,   0,   7,
 
  202     2,   7,   5,   7, -29,   8, -11,   8,  -8,   8,
 
  203    -3,   8,   3,   8,   8,   8,  11,   8,  29,   8,
 
  204    -6,   9,  -1,   9,   1,   9,   6,   9, -15,  10,
 
  205    -4,  10,   4,  10,  15,  10,  -8,  11,  -2,  11,
 
  206     0,  11,   2,  11,   8,  11,  19,  12, -19,  13,
 
  207    -4,  13,   4,  13,   0,  14, -10,  15,  10,  15,
 
  208    -5,  17,   5,  17,  25,  17, -25,  18,   0,  18,
 
  209   -12,  19,  13,  19,  -6,  22,   6,  22,   0,  23,
 
  210   -17,  25,  18,  25,  -8,  29,   8,  29,   0,  31,
 
  211     0,   0,  -6, -22,   6, -22, -13, -19,  12, -19,
 
  212     0, -18,  -5, -17,   5, -17, -10, -15,  10, -15,
 
  213     0, -14,  -4, -13,   4, -13,  19, -13, -19, -12,
 
  214    -8, -11,  -2, -11,   0, -11,   2, -11,   8, -11,
 
  215   -15, -10,  -4, -10,   4, -10,  15, -10,  -6,  -9,
 
  216    -1,  -9,   1,  -9,   6,  -9, -11,  -8,  -8,  -8,
 
  217    -3,  -8,   0,  -8,   3,  -8,   8,  -8,  11,  -8,
 
  218    -5,  -7,  -2,  -7,   0,  -7,   2,  -7,   5,  -7,
 
  219   -22,  -6,  -9,  -6,  -6,  -6,  -3,  -6,  -1,  -6,
 
  220     1,  -6,   3,  -6,   6,  -6,   9,  -6,  22,  -6,
 
  221   -17,  -5,  -7,  -5,  -4,  -5,  -2,  -5,  -1,  -5,
 
  222     0,  -5,   1,  -5,   2,  -5,   4,  -5,   7,  -5,
 
  223    17,  -5, -13,  -4, -10,  -4,  -5,  -4,  -3,  -4,
 
  224    -2,  -4,  -1,  -4,   0,  -4,   1,  -4,   2,  -4,
 
  225     3,  -4,   5,  -4,  10,  -4,  13,  -4,  -8,  -3,
 
  226    -6,  -3,  -4,  -3,  -3,  -3,  -2,  -3,  -1,  -3,
 
  227     0,  -3,   1,  -3,   2,  -3,   3,  -3,   4,  -3,
 
  228     6,  -3,   8,  -3, -11,  -2,  -7,  -2,  -5,  -2,
 
  229    -4,  -2,  -3,  -2,  -2,  -2,  -1,  -2,   0,  -2,
 
  230     1,  -2,   2,  -2,   3,  -2,   4,  -2,   5,  -2,
 
  231     7,  -2,  11,  -2,  -9,  -1,  -6,  -1,  -5,  -1,
 
  232    -4,  -1,  -3,  -1,  -2,  -1,  -1,  -1,   0,  -1,
 
  233     1,  -1,   2,  -1,   3,  -1,   4,  -1,   5,  -1,
 
  234     6,  -1,   9,  -1, -23,   0, -18,   0, -14,   0,
 
  235   -11,   0,  -7,   0,  -5,   0,  -4,   0,  -3,   0,
 
  236    -2,   0,  -1,   0,   0, -23,   1,   0,   2,   0,
 
  237     3,   0,   4,   0,   5,   0,   7,   0,  11,   0,
 
  238    14,   0,  18,   0,  23,   0,  -9,   1,  -6,   1,
 
  239    -5,   1,  -4,   1,  -3,   1,  -2,   1,  -1,   1,
 
  240     0,   1,   1,   1,   2,   1,   3,   1,   4,   1,
 
  241     5,   1,   6,   1,   9,   1, -11,   2,  -7,   2,
 
  242    -5,   2,  -4,   2,  -3,   2,  -2,   2,  -1,   2,
 
  243     0,   2,   1,   2,   2,   2,   3,   2,   4,   2,
 
  244     5,   2,   7,   2,  11,   2,  -8,   3,  -6,   3,
 
  245    -4,   3,  -3,   3,  -2,   3,  -1,   3,   0,   3,
 
  246     1,   3,   2,   3,   3,   3,   4,   3,   6,   3,
 
  247     8,   3, -13,   4, -10,   4,  -5,   4,  -3,   4,
 
  248    -2,   4,  -1,   4,   0,   4,   1,   4,   2,   4,
 
  249     3,   4,   5,   4,  10,   4,  13,   4, -17,   5,
 
  250    -7,   5,  -4,   5,  -2,   5,  -1,   5,   0,   5,
 
  251     1,   5,   2,   5,   4,   5,   7,   5,  17,   5,
 
  252   -22,   6,  -9,   6,  -6,   6,  -3,   6,  -1,   6,
 
  253     1,   6,   3,   6,   6,   6,   9,   6,  22,   6,
 
  254    -5,   7,  -2,   7,   0,   7,   2,   7,   5,   7,
 
  255   -11,   8,  -8,   8,  -3,   8,   0,   8,   3,   8,
 
  256     8,   8,  11,   8,  -6,   9,  -1,   9,   1,   9,
 
  257     6,   9, -15,  10,  -4,  10,   4,  10,  15,  10,
 
  258    -8,  11,  -2,  11,   0,  11,   2,  11,   8,  11,
 
  259    19,  12, -19,  13,  -4,  13,   4,  13,   0,  14,
 
  260   -10,  15,  10,  15,  -5,  17,   5,  17,   0,  18,
 
  261   -12,  19,  13,  19,  -6,  22,   6,  22,   0,  23,
 
  329     const int edge_max = edge_size - 1;
 
  333     else if (y == edge_max)
 
  337     else if (x == edge_max)
 
  366 static void interp_point(int8_t *points, 
int x0, 
int y0, 
int x1, 
int y1,
 
  367                          int pos, 
int npoints)
 
  370         points[0] = (x0 * 
pos + x1 * (npoints - 
pos) + (npoints >> 1)) / npoints;
 
  371         points[1] = (y0 * 
pos + y1 * (npoints - 
pos) + (npoints >> 1)) / npoints;
 
  386 static void make_glyphs(int8_t *pglyphs, 
const int8_t *xvec, 
const int8_t *yvec,
 
  387                         const int side_length)
 
  389     const int glyph_size = side_length * side_length;
 
  390     int8_t *pglyph = pglyphs;
 
  406             for (ipoint = 0; ipoint <= npoints; ipoint++) {
 
  414                     for (irow = point[1]; irow >= 0; irow--)
 
  415                         pglyph[point[0] + irow * side_length] = 1;
 
  419                     for (irow = point[1]; irow < side_length; irow++)
 
  420                         pglyph[point[0] + irow * side_length] = 1;
 
  424                     for (icol = point[0]; icol >= 0; icol--)
 
  425                         pglyph[icol + point[1] * side_length] = 1;
 
  429                     for (icol = point[0]; icol < side_length; icol++)
 
  430                         pglyph[icol + point[1] * side_length] = 1;
 
  447     ctx->buf_size = 
ctx->aligned_width * 
ctx->aligned_height * 
sizeof(
ctx->frm0[0]);
 
  471                               &
ctx->stored_frame_size, 
ctx->buf_size);
 
  473     if (!
ctx->frm0 || !
ctx->frm1 || !
ctx->frm2 ||
 
  474         (!
ctx->stored_frame && !
ctx->version)) {
 
  484     if (rotate_code == 2)
 
  537         opcode = bytestream2_get_byte(&
ctx->gb);
 
  543             color = bytestream2_get_byte(&
ctx->gb);
 
  561     uint8_t *dst = ((uint8_t *)
ctx->frm0) + 
left + top * 
ctx->pitch;
 
  570         len = bytestream2_get_le16u(&
ctx->gb);
 
  577             code = bytestream2_get_byteu(&
ctx->gb);
 
  583                 val = bytestream2_get_byteu(&
ctx->gb);
 
  590                 for (j = 0; j < 
code; j++) {
 
  591                     val = bytestream2_get_byteu(&
ctx->gb);
 
  600     ctx->rotate_code = 0;
 
  611     for (j = 0; j < 4; j++) {
 
  612         for (
i = 0; 
i < 4; 
i++) {
 
  631     int compr = bytestream2_get_byte(&
ctx->gb);
 
  632     int mvoff = bytestream2_get_byte(&
ctx->gb);
 
  633     int seq   = bytestream2_get_le16(&
ctx->gb);
 
  634     uint32_t decoded_size = bytestream2_get_le32(&
ctx->gb);
 
  638     flags = bytestream2_get_byte(&
ctx->gb);
 
  646     ctx->rotate_code = 0;
 
  648     if (((seq & 1) || !(
flags & 1)) && (compr && compr != 2))
 
  671         memset(
ctx->frm1, 0, 
ctx->frm1_size);
 
  672         memset(
ctx->frm2, 0, 
ctx->frm2_size);
 
  677             for (j = 0; j < 
height; j += 4) {
 
  687                     code = bytestream2_get_byteu(&
ctx->gb);
 
  692                         for (k = 0; k < 4; k++)
 
  698                         for (k = 0; k < 4; k++)
 
  699                             memset(dst + 
i + k * 
stride, bytestream2_get_byteu(&
ctx->gb), 4);
 
  704                         t = bytestream2_get_byteu(&
ctx->gb);
 
  705                         for (k = 0; k < 4; k++)
 
  706                             memset(dst + 
i + k * 
stride, t, 4);
 
  709                         if (compr == 4 && !
code) {
 
  712                             skip_run = bytestream2_get_byteu(&
ctx->gb) + 1;
 
  728             for (j = 0; j < 
height; j += 4) {
 
  736                     code = bytestream2_get_byte(&
ctx->gb);
 
  740                         for (k = 0; k < 4; k++)
 
  742                     } 
else if (compr == 4 && !
code) {
 
  745                         skip_run = bytestream2_get_byteu(&
ctx->gb) + 1;
 
  763                                       "Subcodec 37 compression %d", compr);
 
  771                          uint8_t *prev2, 
int stride, 
int tbl, 
int size)
 
  780     code = bytestream2_get_byteu(&
ctx->gb);
 
  787                 dst[0]          = bytestream2_get_byteu(&
ctx->gb);
 
  788                 dst[1]          = bytestream2_get_byteu(&
ctx->gb);
 
  789                 dst[0 + 
stride] = bytestream2_get_byteu(&
ctx->gb);
 
  790                 dst[1 + 
stride] = bytestream2_get_byteu(&
ctx->gb);
 
  812             t = bytestream2_get_byteu(&
ctx->gb);
 
  813             for (k = 0; k < 
size; k++)
 
  820             code = bytestream2_get_byteu(&
ctx->gb);
 
  824             for (k = 0; k < 
size; k++)
 
  825                 for (t = 0; t < 
size; t++)
 
  826                     dst[t + k * 
stride] = colors[!*pglyph++];
 
  829             for (k = 0; k < 
size; k++)
 
  835             t = bytestream2_get_byte(&
ctx->gb);
 
  837             for (k = 0; k < 
size; k++)
 
  843         int index = prev2 - (
const uint8_t *)
ctx->frm2;
 
  853         for (k = 0; k < 
size; k++)
 
  863     uint32_t decoded_size;
 
  867     uint8_t *prev1 = (uint8_t *)
ctx->frm1;
 
  868     uint8_t *prev2 = (uint8_t *)
ctx->frm2;
 
  870     int seq     = bytestream2_get_le16(&
ctx->gb);
 
  871     int compr   = bytestream2_get_byte(&
ctx->gb);
 
  872     int new_rot = bytestream2_get_byte(&
ctx->gb);
 
  873     int skip    = bytestream2_get_byte(&
ctx->gb);
 
  876     decoded_size = bytestream2_get_le32(&
ctx->gb);
 
  896         for (j = 0; j < 
height; j++) {
 
  904         for (j = 0; j < 
height; j += 2) {
 
  909                 dst[
stride + 
i + 1] = bytestream2_get_byteu(&
ctx->gb);
 
  915         if (seq == 
ctx->prev_seq + 1) {
 
  916             for (j = 0; j < 
height; j += 8) {
 
  939                                       "Subcodec 47 compression %d", compr);
 
  942     if (seq == 
ctx->prev_seq + 1)
 
  943         ctx->rotate_code = new_rot;
 
  945         ctx->rotate_code = 0;
 
  953     uint16_t codec = bytestream2_get_le16u(&
ctx->gb);
 
  954     uint16_t 
left  = bytestream2_get_le16u(&
ctx->gb);
 
  955     uint16_t top   = bytestream2_get_le16u(&
ctx->gb);
 
  956     uint16_t 
w     = bytestream2_get_le16u(&
ctx->gb);
 
  957     uint16_t 
h     = bytestream2_get_le16u(&
ctx->gb);
 
  994     uint16_t *frm = 
ctx->frm0;
 
 1001     for (y = 0; y < 
ctx->height; y++) {
 
 1002         for (x = 0; x < 
ctx->width; x++)
 
 1003             frm[x] = bytestream2_get_le16u(&
ctx->gb);
 
 1015 static void copy_block(uint16_t *pdest, uint16_t *psrc, 
int block_size, ptrdiff_t pitch)
 
 1017     uint8_t *dst = (uint8_t *)pdest;
 
 1018     uint8_t *
src = (uint8_t *)psrc;
 
 1019     ptrdiff_t 
stride = pitch * 2;
 
 1021     switch (block_size) {
 
 1038     pitch -= block_size;
 
 1039     for (y = 0; y < block_size; y++, pdest += pitch)
 
 1040         for (x = 0; x < block_size; x++)
 
 1045                       uint16_t fg_color, uint16_t bg_color, 
int block_size,
 
 1049     uint16_t colors[2] = { fg_color, bg_color };
 
 1057     pglyph = block_size == 8 ? 
ctx->p8x8glyphs[
index] : 
ctx->p4x4glyphs[
index];
 
 1058     pitch -= block_size;
 
 1060     for (y = 0; y < block_size; y++, dst += pitch)
 
 1061         for (x = 0; x < block_size; x++)
 
 1062             *dst++ = colors[*pglyph++];
 
 1068     uint16_t *dst = 
ctx->frm0 + cx + cy * 
ctx->pitch;
 
 1070     if (block_size == 2) {
 
 1076         indices        = bytestream2_get_le32u(&
ctx->gb);
 
 1077         dst[0]         = 
ctx->codebook[indices & 0xFF];
 
 1079         dst[1]         = 
ctx->codebook[indices & 0xFF];
 
 1081         dst[pitch]     = 
ctx->codebook[indices & 0xFF];
 
 1083         dst[pitch + 1] = 
ctx->codebook[indices & 0xFF];
 
 1085         uint16_t fgcolor, bgcolor;
 
 1091         glyph   = bytestream2_get_byteu(&
ctx->gb);
 
 1092         bgcolor = 
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
 
 1093         fgcolor = 
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
 
 1095         draw_glyph(
ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
 
 1102     uint16_t *dst = 
ctx->frm0 + cx + cy * 
ctx->pitch;
 
 1104     if (block_size == 2) {
 
 1108         dst[0]         = bytestream2_get_le16u(&
ctx->gb);
 
 1109         dst[1]         = bytestream2_get_le16u(&
ctx->gb);
 
 1110         dst[pitch]     = bytestream2_get_le16u(&
ctx->gb);
 
 1111         dst[pitch + 1] = bytestream2_get_le16u(&
ctx->gb);
 
 1113         uint16_t fgcolor, bgcolor;
 
 1119         glyph   = bytestream2_get_byteu(&
ctx->gb);
 
 1120         bgcolor = bytestream2_get_le16u(&
ctx->gb);
 
 1121         fgcolor = bytestream2_get_le16u(&
ctx->gb);
 
 1123         draw_glyph(
ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
 
 1131     int start_pos = cx + mx + (cy + my) * 
ctx->pitch;
 
 1132     int end_pos = start_pos + (block_size - 1) * (
ctx->pitch + 1);
 
 1134     int good = start_pos >= 0 && end_pos < (
ctx->buf_size >> 1);
 
 1138                "Ignoring invalid motion vector (%i, %i)->(%u, %u), block size = %u\n",
 
 1139                cx + mx, cy + my, cx, cy, block_size);
 
 1146     int16_t mx, my, 
index;
 
 1152     opcode = bytestream2_get_byteu(&
ctx->gb);
 
 1161                        ctx->frm2 + cx + mx + 
ctx->pitch * (cy + my),
 
 1162                        blk_size, 
ctx->pitch);
 
 1168         index = bytestream2_get_le16u(&
ctx->gb);
 
 1175                        ctx->frm2 + cx + mx + 
ctx->pitch * (cy + my),
 
 1176                        blk_size, 
ctx->pitch);
 
 1181                    ctx->frm1 + cx + 
ctx->pitch * cy,
 
 1182                    blk_size, 
ctx->pitch);
 
 1196                    ctx->small_codebook[opcode - 0xf9], blk_size, 
ctx->pitch);
 
 1202                    ctx->codebook[bytestream2_get_byteu(&
ctx->gb)], blk_size, 
ctx->pitch);
 
 1208                    bytestream2_get_le16u(&
ctx->gb), blk_size, 
ctx->pitch);
 
 1211         if (blk_size == 2) {
 
 1233     for (cy = 0; cy < 
ctx->aligned_height; cy += 8)
 
 1234         for (cx = 0; cx < 
ctx->aligned_width; cx += 8)
 
 1243     memcpy(
ctx->frm0, 
ctx->frm2, 
ctx->frm2_size);
 
 1249     memcpy(
ctx->frm0, 
ctx->frm1, 
ctx->frm1_size);
 
 1259     uint8_t *dst = (uint8_t*)
ctx->frm0;
 
 1265     npixels = 
ctx->npixels;
 
 1278     int npixels = 
ctx->npixels;
 
 1279     uint16_t *frm = 
ctx->frm0;
 
 1286         *frm++ = 
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
 
 1293     uint16_t *pdest = 
ctx->frm0;
 
 1295     long npixels = 
ctx->npixels;
 
 1298     if (!
ctx->rle_buf) {
 
 1302     rsrc = 
ctx->rle_buf;
 
 1308         *pdest++ = 
ctx->codebook[*rsrc++];
 
 1331     hdr->
width  = bytestream2_get_le32u(&
ctx->gb);
 
 1332     hdr->
height = bytestream2_get_le32u(&
ctx->gb);
 
 1339     hdr->
seq_num     = bytestream2_get_le16u(&
ctx->gb);
 
 1340     hdr->
codec       = bytestream2_get_byteu(&
ctx->gb);
 
 1345     for (
i = 0; 
i < 4; 
i++)
 
 1346         ctx->small_codebook[
i] = bytestream2_get_le16u(&
ctx->gb);
 
 1352     for (
i = 0; 
i < 256; 
i++)
 
 1353         ctx->codebook[
i] = bytestream2_get_le16u(&
ctx->gb);
 
 1371     const uint8_t *
src = (uint8_t*) 
ctx->frm0;
 
 1373     ptrdiff_t dstpitch, srcpitch = 
ctx->pitch * (hdr ? 
sizeof(
ctx->frm0[0]) : 1);
 
 1378     dst      = 
ctx->frame->data[0];
 
 1379     dstpitch = 
ctx->frame->linesize[0];
 
 1382         memcpy(dst, 
src, srcpitch);
 
 1399     if (!
ctx->version) {
 
 1406             sig  = bytestream2_get_be32u(&
ctx->gb);
 
 1407             size = bytestream2_get_be32u(&
ctx->gb);
 
 1415             case MKBETAG(
'N', 
'P', 
'A', 
'L'):
 
 1418                            "Incorrect palette block size %"PRIu32
".\n", 
size);
 
 1422                     ctx->pal[
i] = 0xFFU << 24 | bytestream2_get_be24u(&
ctx->gb);
 
 1424             case MKBETAG(
'F', 
'O', 
'B', 
'J'):
 
 1430             case MKBETAG(
'X', 
'P', 
'A', 
'L'):
 
 1436                         for (j = 0; j < 3; j++) {
 
 1437                             int t = (
ctx->pal[
i] >> (16 - j * 8)) & 0xFF;
 
 1445                                "Incorrect palette change block size %"PRIu32
".\n",
 
 1451                         ctx->delta_pal[
i] = bytestream2_get_le16u(&
ctx->gb);
 
 1454                             ctx->pal[
i] = 0xFFU << 24 | bytestream2_get_be24u(&
ctx->gb);
 
 1456                         memset(
ctx->pal, 0, 
sizeof(
ctx->pal));
 
 1460             case MKBETAG(
'S', 
'T', 
'O', 
'R'):
 
 1463             case MKBETAG(
'F', 
'T', 
'C', 
'H'):
 
 1464                 memcpy(
ctx->frm0, 
ctx->stored_frame, 
ctx->buf_size);
 
 1469                        "Unknown/unsupported chunk %"PRIx32
".\n", sig);
 
 1478             memcpy(
ctx->stored_frame, 
ctx->frm0, 
ctx->buf_size);
 
 1481         memcpy(
ctx->frame->data[1], 
ctx->pal, 1024);
 
 1489         if ((
ctx->frame->key_frame = !
header.seq_num)) {
 
 1500                        "Subcodec %d: error decoding frame.\n", 
header.codec);
 
 1511     if (
ctx->rotate_code)