33 #define GLYPH_COORD_VECT_SIZE 16 
   34 #define PALETTE_SIZE 256 
   35 #define PALETTE_DELTA 768 
   38     0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0, 1, 2, 2, 1
 
   42     0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2
 
   46     0, 2, 5, 7, 7, 7, 7, 7, 7, 5, 2, 0, 0, 0, 0, 0
 
   50     0, 0, 0, 0, 1, 3, 4, 6, 7, 7, 7, 7, 6, 4, 3, 1
 
   54 static const int8_t 
c47_mv[256][2] = {
 
   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 },
 
  110     0,   0,   1,   0,   2,   0,   3,   0,   5,   0,
 
  111     8,   0,  13,   0,  21,   0,  -1,   0,  -2,   0,
 
  112    -3,   0,  -5,   0,  -8,   0, -13,   0, -17,   0,
 
  113   -21,   0,   0,   1,   1,   1,   2,   1,   3,   1,
 
  114     5,   1,   8,   1,  13,   1,  21,   1,  -1,   1,
 
  115    -2,   1,  -3,   1,  -5,   1,  -8,   1, -13,   1,
 
  116   -17,   1, -21,   1,   0,   2,   1,   2,   2,   2,
 
  117     3,   2,   5,   2,   8,   2,  13,   2,  21,   2,
 
  118    -1,   2,  -2,   2,  -3,   2,  -5,   2,  -8,   2,
 
  119   -13,   2, -17,   2, -21,   2,   0,   3,   1,   3,
 
  120     2,   3,   3,   3,   5,   3,   8,   3,  13,   3,
 
  121    21,   3,  -1,   3,  -2,   3,  -3,   3,  -5,   3,
 
  122    -8,   3, -13,   3, -17,   3, -21,   3,   0,   5,
 
  123     1,   5,   2,   5,   3,   5,   5,   5,   8,   5,
 
  124    13,   5,  21,   5,  -1,   5,  -2,   5,  -3,   5,
 
  125    -5,   5,  -8,   5, -13,   5, -17,   5, -21,   5,
 
  126     0,   8,   1,   8,   2,   8,   3,   8,   5,   8,
 
  127     8,   8,  13,   8,  21,   8,  -1,   8,  -2,   8,
 
  128    -3,   8,  -5,   8,  -8,   8, -13,   8, -17,   8,
 
  129   -21,   8,   0,  13,   1,  13,   2,  13,   3,  13,
 
  130     5,  13,   8,  13,  13,  13,  21,  13,  -1,  13,
 
  131    -2,  13,  -3,  13,  -5,  13,  -8,  13, -13,  13,
 
  132   -17,  13, -21,  13,   0,  21,   1,  21,   2,  21,
 
  133     3,  21,   5,  21,   8,  21,  13,  21,  21,  21,
 
  134    -1,  21,  -2,  21,  -3,  21,  -5,  21,  -8,  21,
 
  135   -13,  21, -17,  21, -21,  21,   0,  -1,   1,  -1,
 
  136     2,  -1,   3,  -1,   5,  -1,   8,  -1,  13,  -1,
 
  137    21,  -1,  -1,  -1,  -2,  -1,  -3,  -1,  -5,  -1,
 
  138    -8,  -1, -13,  -1, -17,  -1, -21,  -1,   0,  -2,
 
  139     1,  -2,   2,  -2,   3,  -2,   5,  -2,   8,  -2,
 
  140    13,  -2,  21,  -2,  -1,  -2,  -2,  -2,  -3,  -2,
 
  141    -5,  -2,  -8,  -2, -13,  -2, -17,  -2, -21,  -2,
 
  142     0,  -3,   1,  -3,   2,  -3,   3,  -3,   5,  -3,
 
  143     8,  -3,  13,  -3,  21,  -3,  -1,  -3,  -2,  -3,
 
  144    -3,  -3,  -5,  -3,  -8,  -3, -13,  -3, -17,  -3,
 
  145   -21,  -3,   0,  -5,   1,  -5,   2,  -5,   3,  -5,
 
  146     5,  -5,   8,  -5,  13,  -5,  21,  -5,  -1,  -5,
 
  147    -2,  -5,  -3,  -5,  -5,  -5,  -8,  -5, -13,  -5,
 
  148   -17,  -5, -21,  -5,   0,  -8,   1,  -8,   2,  -8,
 
  149     3,  -8,   5,  -8,   8,  -8,  13,  -8,  21,  -8,
 
  150    -1,  -8,  -2,  -8,  -3,  -8,  -5,  -8,  -8,  -8,
 
  151   -13,  -8, -17,  -8, -21,  -8,   0, -13,   1, -13,
 
  152     2, -13,   3, -13,   5, -13,   8, -13,  13, -13,
 
  153    21, -13,  -1, -13,  -2, -13,  -3, -13,  -5, -13,
 
  154    -8, -13, -13, -13, -17, -13, -21, -13,   0, -17,
 
  155     1, -17,   2, -17,   3, -17,   5, -17,   8, -17,
 
  156    13, -17,  21, -17,  -1, -17,  -2, -17,  -3, -17,
 
  157    -5, -17,  -8, -17, -13, -17, -17, -17, -21, -17,
 
  158     0, -21,   1, -21,   2, -21,   3, -21,   5, -21,
 
  159     8, -21,  13, -21,  21, -21,  -1, -21,  -2, -21,
 
  160    -3, -21,  -5, -21,  -8, -21, -13, -21, -17, -21,
 
  161     0,   0,  -8, -29,   8, -29, -18, -25,  17, -25,
 
  162     0, -23,  -6, -22,   6, -22, -13, -19,  12, -19,
 
  163     0, -18,  25, -18, -25, -17,  -5, -17,   5, -17,
 
  164   -10, -15,  10, -15,   0, -14,  -4, -13,   4, -13,
 
  165    19, -13, -19, -12,  -8, -11,  -2, -11,   0, -11,
 
  166     2, -11,   8, -11, -15, -10,  -4, -10,   4, -10,
 
  167    15, -10,  -6,  -9,  -1,  -9,   1,  -9,   6,  -9,
 
  168   -29,  -8, -11,  -8,  -8,  -8,  -3,  -8,   3,  -8,
 
  169     8,  -8,  11,  -8,  29,  -8,  -5,  -7,  -2,  -7,
 
  170     0,  -7,   2,  -7,   5,  -7, -22,  -6,  -9,  -6,
 
  171    -6,  -6,  -3,  -6,  -1,  -6,   1,  -6,   3,  -6,
 
  172     6,  -6,   9,  -6,  22,  -6, -17,  -5,  -7,  -5,
 
  173    -4,  -5,  -2,  -5,   0,  -5,   2,  -5,   4,  -5,
 
  174     7,  -5,  17,  -5, -13,  -4, -10,  -4,  -5,  -4,
 
  175    -3,  -4,  -1,  -4,   0,  -4,   1,  -4,   3,  -4,
 
  176     5,  -4,  10,  -4,  13,  -4,  -8,  -3,  -6,  -3,
 
  177    -4,  -3,  -3,  -3,  -2,  -3,  -1,  -3,   0,  -3,
 
  178     1,  -3,   2,  -3,   4,  -3,   6,  -3,   8,  -3,
 
  179   -11,  -2,  -7,  -2,  -5,  -2,  -3,  -2,  -2,  -2,
 
  180    -1,  -2,   0,  -2,   1,  -2,   2,  -2,   3,  -2,
 
  181     5,  -2,   7,  -2,  11,  -2,  -9,  -1,  -6,  -1,
 
  182    -4,  -1,  -3,  -1,  -2,  -1,  -1,  -1,   0,  -1,
 
  183     1,  -1,   2,  -1,   3,  -1,   4,  -1,   6,  -1,
 
  184     9,  -1, -31,   0, -23,   0, -18,   0, -14,   0,
 
  185   -11,   0,  -7,   0,  -5,   0,  -4,   0,  -3,   0,
 
  186    -2,   0,  -1,   0,   0, -31,   1,   0,   2,   0,
 
  187     3,   0,   4,   0,   5,   0,   7,   0,  11,   0,
 
  188    14,   0,  18,   0,  23,   0,  31,   0,  -9,   1,
 
  189    -6,   1,  -4,   1,  -3,   1,  -2,   1,  -1,   1,
 
  190     0,   1,   1,   1,   2,   1,   3,   1,   4,   1,
 
  191     6,   1,   9,   1, -11,   2,  -7,   2,  -5,   2,
 
  192    -3,   2,  -2,   2,  -1,   2,   0,   2,   1,   2,
 
  193     2,   2,   3,   2,   5,   2,   7,   2,  11,   2,
 
  194    -8,   3,  -6,   3,  -4,   3,  -2,   3,  -1,   3,
 
  195     0,   3,   1,   3,   2,   3,   3,   3,   4,   3,
 
  196     6,   3,   8,   3, -13,   4, -10,   4,  -5,   4,
 
  197    -3,   4,  -1,   4,   0,   4,   1,   4,   3,   4,
 
  198     5,   4,  10,   4,  13,   4, -17,   5,  -7,   5,
 
  199    -4,   5,  -2,   5,   0,   5,   2,   5,   4,   5,
 
  200     7,   5,  17,   5, -22,   6,  -9,   6,  -6,   6,
 
  201    -3,   6,  -1,   6,   1,   6,   3,   6,   6,   6,
 
  202     9,   6,  22,   6,  -5,   7,  -2,   7,   0,   7,
 
  203     2,   7,   5,   7, -29,   8, -11,   8,  -8,   8,
 
  204    -3,   8,   3,   8,   8,   8,  11,   8,  29,   8,
 
  205    -6,   9,  -1,   9,   1,   9,   6,   9, -15,  10,
 
  206    -4,  10,   4,  10,  15,  10,  -8,  11,  -2,  11,
 
  207     0,  11,   2,  11,   8,  11,  19,  12, -19,  13,
 
  208    -4,  13,   4,  13,   0,  14, -10,  15,  10,  15,
 
  209    -5,  17,   5,  17,  25,  17, -25,  18,   0,  18,
 
  210   -12,  19,  13,  19,  -6,  22,   6,  22,   0,  23,
 
  211   -17,  25,  18,  25,  -8,  29,   8,  29,   0,  31,
 
  212     0,   0,  -6, -22,   6, -22, -13, -19,  12, -19,
 
  213     0, -18,  -5, -17,   5, -17, -10, -15,  10, -15,
 
  214     0, -14,  -4, -13,   4, -13,  19, -13, -19, -12,
 
  215    -8, -11,  -2, -11,   0, -11,   2, -11,   8, -11,
 
  216   -15, -10,  -4, -10,   4, -10,  15, -10,  -6,  -9,
 
  217    -1,  -9,   1,  -9,   6,  -9, -11,  -8,  -8,  -8,
 
  218    -3,  -8,   0,  -8,   3,  -8,   8,  -8,  11,  -8,
 
  219    -5,  -7,  -2,  -7,   0,  -7,   2,  -7,   5,  -7,
 
  220   -22,  -6,  -9,  -6,  -6,  -6,  -3,  -6,  -1,  -6,
 
  221     1,  -6,   3,  -6,   6,  -6,   9,  -6,  22,  -6,
 
  222   -17,  -5,  -7,  -5,  -4,  -5,  -2,  -5,  -1,  -5,
 
  223     0,  -5,   1,  -5,   2,  -5,   4,  -5,   7,  -5,
 
  224    17,  -5, -13,  -4, -10,  -4,  -5,  -4,  -3,  -4,
 
  225    -2,  -4,  -1,  -4,   0,  -4,   1,  -4,   2,  -4,
 
  226     3,  -4,   5,  -4,  10,  -4,  13,  -4,  -8,  -3,
 
  227    -6,  -3,  -4,  -3,  -3,  -3,  -2,  -3,  -1,  -3,
 
  228     0,  -3,   1,  -3,   2,  -3,   3,  -3,   4,  -3,
 
  229     6,  -3,   8,  -3, -11,  -2,  -7,  -2,  -5,  -2,
 
  230    -4,  -2,  -3,  -2,  -2,  -2,  -1,  -2,   0,  -2,
 
  231     1,  -2,   2,  -2,   3,  -2,   4,  -2,   5,  -2,
 
  232     7,  -2,  11,  -2,  -9,  -1,  -6,  -1,  -5,  -1,
 
  233    -4,  -1,  -3,  -1,  -2,  -1,  -1,  -1,   0,  -1,
 
  234     1,  -1,   2,  -1,   3,  -1,   4,  -1,   5,  -1,
 
  235     6,  -1,   9,  -1, -23,   0, -18,   0, -14,   0,
 
  236   -11,   0,  -7,   0,  -5,   0,  -4,   0,  -3,   0,
 
  237    -2,   0,  -1,   0,   0, -23,   1,   0,   2,   0,
 
  238     3,   0,   4,   0,   5,   0,   7,   0,  11,   0,
 
  239    14,   0,  18,   0,  23,   0,  -9,   1,  -6,   1,
 
  240    -5,   1,  -4,   1,  -3,   1,  -2,   1,  -1,   1,
 
  241     0,   1,   1,   1,   2,   1,   3,   1,   4,   1,
 
  242     5,   1,   6,   1,   9,   1, -11,   2,  -7,   2,
 
  243    -5,   2,  -4,   2,  -3,   2,  -2,   2,  -1,   2,
 
  244     0,   2,   1,   2,   2,   2,   3,   2,   4,   2,
 
  245     5,   2,   7,   2,  11,   2,  -8,   3,  -6,   3,
 
  246    -4,   3,  -3,   3,  -2,   3,  -1,   3,   0,   3,
 
  247     1,   3,   2,   3,   3,   3,   4,   3,   6,   3,
 
  248     8,   3, -13,   4, -10,   4,  -5,   4,  -3,   4,
 
  249    -2,   4,  -1,   4,   0,   4,   1,   4,   2,   4,
 
  250     3,   4,   5,   4,  10,   4,  13,   4, -17,   5,
 
  251    -7,   5,  -4,   5,  -2,   5,  -1,   5,   0,   5,
 
  252     1,   5,   2,   5,   4,   5,   7,   5,  17,   5,
 
  253   -22,   6,  -9,   6,  -6,   6,  -3,   6,  -1,   6,
 
  254     1,   6,   3,   6,   6,   6,   9,   6,  22,   6,
 
  255    -5,   7,  -2,   7,   0,   7,   2,   7,   5,   7,
 
  256   -11,   8,  -8,   8,  -3,   8,   0,   8,   3,   8,
 
  257     8,   8,  11,   8,  -6,   9,  -1,   9,   1,   9,
 
  258     6,   9, -15,  10,  -4,  10,   4,  10,  15,  10,
 
  259    -8,  11,  -2,  11,   0,  11,   2,  11,   8,  11,
 
  260    19,  12, -19,  13,  -4,  13,   4,  13,   0,  14,
 
  261   -10,  15,  10,  15,  -5,  17,   5,  17,   0,  18,
 
  262   -12,  19,  13,  19,  -6,  22,   6,  22,   0,  23,
 
  327     const int edge_max = edge_size - 1;
 
  331     else if (y == edge_max)
 
  335     else if (x == edge_max)
 
  364 static void interp_point(int8_t *points, 
int x0, 
int y0, 
int x1, 
int y1,
 
  365                          int pos, 
int npoints)
 
  368         points[0] = (x0 * 
pos + x1 * (npoints - 
pos) + (npoints >> 1)) / npoints;
 
  369         points[1] = (y0 * 
pos + y1 * (npoints - 
pos) + (npoints >> 1)) / npoints;
 
  384 static void make_glyphs(int8_t *pglyphs, 
const int8_t *xvec, 
const int8_t *yvec,
 
  385                         const int side_length)
 
  387     const int glyph_size = side_length * side_length;
 
  388     int8_t *pglyph = pglyphs;
 
  404             for (ipoint = 0; ipoint <= npoints; ipoint++) {
 
  412                     for (irow = point[1]; irow >= 0; irow--)
 
  413                         pglyph[point[0] + irow * side_length] = 1;
 
  417                     for (irow = point[1]; irow < side_length; irow++)
 
  418                         pglyph[point[0] + irow * side_length] = 1;
 
  422                     for (icol = point[0]; icol >= 0; icol--)
 
  423                         pglyph[icol + point[1] * side_length] = 1;
 
  427                     for (icol = point[0]; icol < side_length; icol++)
 
  428                         pglyph[icol + point[1] * side_length] = 1;
 
  445     ctx->buf_size = 
ctx->aligned_width * 
ctx->aligned_height * 
sizeof(
ctx->frm0[0]);
 
  471                               &
ctx->stored_frame_size, 
ctx->buf_size);
 
  475     if (!
ctx->frm0 || !
ctx->frm1 || !
ctx->frm2 ||
 
  476         (!
ctx->stored_frame && !
ctx->version)) {
 
  486     uint8_t *
dst = &(
ctx->c4tbl[0][0][0]);
 
  487     int i, j, k, l, m, n, o, 
p;
 
  489     for (
i = 0; 
i < 8; 
i++) {
 
  490         for (k = 0; k < 8; k++) {
 
  504     for (
i = 0; 
i < 8; 
i++) {
 
  505         for (k = 0; k < 8; k++) {
 
  518     for (
i = 0; 
i < 8; 
i++) {
 
  519         for (k = 0; k < 8; k++) {
 
  533     for (
i = 0; 
i < 8; 
i++) {
 
  534         for (k = 0; k < 8; k++) {
 
  550     uint8_t *
dst = &(
ctx->c4tbl[0][0][0]);
 
  551     int i, j, k, l, m, n, o;
 
  553     for (
i = 1; 
i < 16; 
i += 2) {
 
  554         for (k = 0; k < 16; k++) {
 
  560             if (j == m || l == m) {
 
  574     for (
i = 0; 
i < 16; 
i += 2) {
 
  575         for (k = 0; k < 16; k++) {
 
  581             if (m == j || m == l) {
 
  598                              uint16_t param2, uint8_t clr)
 
  600     uint8_t 
c, *
dst = (uint8_t *)&(
ctx->c4tbl[1][0][0]);
 
  601     uint32_t 
loop = param2 * 8;
 
  607         c = bytestream2_get_byteu(gb);
 
  608         *
dst++ = (
c >> 4) + clr;
 
  609         *
dst++ = (
c & 0xf) + clr;
 
  617     if (rotate_code == 2)
 
  639         ctx->have_dimensions = 0;
 
  640     } 
else if (avctx->
width > 800 || avctx->
height > 600 ||
 
  660         if (
ctx->subversion < 2)
 
  661             ctx->pal[0] = 0xFF
U << 24;
 
  663     ctx->c4param = 0xffff;
 
  678                       int w, 
int h, uint8_t param, uint16_t param2, 
int codec)
 
  682     int i, j, k, l, 
bit, 
ret, x, y;
 
  684     if (
ctx->c4param != param) {
 
  689         ctx->c4param = param;
 
  700     for (j = 0; j < 
w; j += 4) {
 
  703         for (
i = 0; 
i < 
h; 
i += 4) {
 
  709                     mask = bytestream2_get_byteu(gb);
 
  721             idx = bytestream2_get_byteu(gb);
 
  722             if ((
bit == 0) && (idx == 0x80) && (codec != 5))
 
  724             if ((y >= 
my) || ((y + 4) < 0) || ((x + 4) < 0) || (x >= 
mx))
 
  726             gs = &(
ctx->c4tbl[
bit][idx][0]);
 
  727             if ((y >= 0) && (x >= 0) && ((y + 4) < 
my) && ((x + 4) < 
mx)) {
 
  728                 for (k = 0; k < 4; k++, gs += 4)
 
  729                     memcpy(
dst + x + (y + k) * 
p, gs, 4);
 
  731                 for (k = 0; k < 4; k++) {
 
  732                     for (l = 0; l < 4; l++, gs++) {
 
  733                         const int yo = y + k, xo = x + l;
 
  734                         if ((yo >= 0) && (yo < 
my) && (xo >= 0) && (xo < 
mx))
 
  735                             *(
dst + yo * 
p + xo) = *gs;
 
  749         opcode = bytestream2_get_byte(gb);
 
  755             color = bytestream2_get_byte(gb);
 
  771                        int width, 
int height, uint8_t param, uint16_t param2)
 
  774     uint8_t 
c, lut[256], *
dst = (uint8_t *)
ctx->fbuf;
 
  775     int sk, 
i, j, ls, pc, y;
 
  777     if (
ctx->subversion < 2) {
 
  779         for (
i = 0; 
i < 256; 
i++)
 
  780             lut[
i] = (
i + param + 0xd0) & 0xff;
 
  781     } 
else if (param2 == 256) {
 
  785     } 
else if (param2 < 256) {
 
  786         for (
i = 0; 
i < 256; 
i++)
 
  787             lut[
i] = (
i + param2) & 0xff;
 
  789         memcpy(lut, 
ctx->c23lut, 256);
 
  800             ls = bytestream2_get_le16u(gb);
 
  811         ls = bytestream2_get_le16u(gb);
 
  815             j = bytestream2_get_byteu(gb);
 
  819                     if ((pc >= 0) && (pc < 
mx)) {
 
  820                         c = *(
dst + (y * 
p) + pc);
 
  821                         *(
dst + (y * 
p) + pc) = lut[
c];
 
  840     uint8_t *
dst = (uint8_t *)
ctx->fbuf, 
c;
 
  841     int j, y, pc, sk, ls;
 
  848         ls = bytestream2_get_le16u(gb);
 
  858             j = bytestream2_get_le16u(gb);
 
  865                     c = bytestream2_get_byteu(gb);
 
  866                     if ((pc >= 0) && (pc < 
mx)) {
 
  867                         *(
dst + (y * 
p) + pc) = 
c;
 
  886     int j, x, y, 
flag, dlen;
 
  894             dlen = bytestream2_get_le16u(gb);
 
  905         dlen = bytestream2_get_le16u(gb);
 
  908             code = bytestream2_get_byteu(gb);
 
  913                 c = bytestream2_get_byteu(gb);
 
  926                 for (j = 0; (j < 
code) && (
c || opaque); j++) {
 
  927                     *(
dst + (y * 
p) + x + j) = 
c;
 
  933                 for (j = 0; j < 
code; j++) {
 
  934                     c = bytestream2_get_byteu(gb);
 
  935                     if ((x >= 0) && (x < 
mx) && (
c || opaque))
 
  936                         *(
dst + (y * 
p) + x) = 
c;
 
  952     uint8_t *
dst = (uint8_t *)
ctx->fbuf, 
c;
 
  961             dlen = bytestream2_get_le16u(gb);
 
  972         dlen = bytestream2_get_le16u(gb);
 
  975             code = bytestream2_get_byteu(gb);
 
  980                 c = bytestream2_get_byteu(gb);
 
  982                 for (j = 0; (j < 
code); j++) {
 
  983                     if ((opaque || (
c & 0
xf)) && (x >= 0) && (x < 
mx))
 
  984                         *(
dst + (y * 
p) + x) = p1 + (
c & 0
xf);
 
  987                     if ((opaque || (
c >> 4)) && (x >= 0) && (x < 
mx))
 
  988                         *(
dst + (y * 
p) + x) = p1 + (
c >> 4);
 
  995                 for (j = 0; j < 
code; j++) {
 
  996                     c = bytestream2_get_byteu(gb);
 
  997                     if ((opaque || (
c & 0
xf)) && (x >= 0) && (x < 
mx))
 
  998                         *(
dst + (y * 
p) + x) = p1 + (
c & 0xf);
 
 1001                     if ((opaque || (
c >> 4)) && (x >= 0) && (x < 
mx))
 
 1002                         *(
dst + (y * 
p) + x) = p1 + (
c >> 4);
 
 1017     uint8_t *
dst = (uint8_t *)
ctx->fbuf, col;
 
 1018     int16_t xpos = 
left, ypos = top;
 
 1021         xpos += bytestream2_get_le16u(gb);
 
 1022         ypos += bytestream2_get_byteu(gb);
 
 1023         col = bytestream2_get_byteu(gb);
 
 1024         if (xpos >= 0 && ypos >= 0 &&
 
 1026                 *(
dst + xpos + ypos * 
ctx->pitch) = col;
 
 1033                       uint16_t srcxoff, uint16_t srcyoff, uint16_t srcwidth,
 
 1034                       uint16_t srcheight, 
const uint16_t srcpitch, 
const uint16_t dstpitch,
 
 1037     if ((srcwidth < 1) || (srcheight < 1) || (
size < 1))
 
 1041         if (-top >= srcheight)
 
 1045         size += (srcpitch * top);
 
 1049     if ((top + srcheight) > dstheight) {
 
 1050         int clip = (top + srcheight) - dstheight;
 
 1051         if (
clip >= srcheight)
 
 1057         if (-
left >= srcwidth)
 
 1065     if (
left + srcwidth > dstpitch) {
 
 1066         int clip = (
left + srcwidth) - dstpitch;
 
 1067         if (
clip >= srcwidth)
 
 1072     src += ((uintptr_t)srcyoff * srcpitch) + srcxoff;
 
 1073     dst += ((uintptr_t)top * dstpitch) + 
left;
 
 1074     while ((srcheight--) && (
size >= srcwidth)) {
 
 1075         memcpy(
dst, 
src, srcwidth);
 
 1080     if ((
size > 0) && (
size < srcwidth) && (srcheight > 0))
 
 1085                      uint16_t srcxoff, uint16_t srcyoff, uint16_t srcwidth,
 
 1086                      uint16_t srcheight, 
const uint16_t srcpitch, 
const uint16_t dstpitch,
 
 1087                      const uint16_t dstheight, 
int32_t size, 
const uint8_t skipcolor)
 
 1089     if ((srcwidth < 1) || (srcheight < 1) || (
size < 1))
 
 1093         if (-top >= srcheight)
 
 1097         size += (srcpitch * top);
 
 1101     if ((top + srcheight) > dstheight) {
 
 1102         int clip = (top + srcheight) - dstheight;
 
 1103         if (
clip >= srcheight)
 
 1109         if (-
left >= srcwidth)
 
 1117     if (
left + srcwidth > dstpitch) {
 
 1118         int clip = (
left + srcwidth) - dstpitch;
 
 1119         if (
clip >= srcwidth)
 
 1124     src += ((uintptr_t)srcyoff * srcpitch) + srcxoff;
 
 1125     dst += ((uintptr_t)top * dstpitch) + 
left;
 
 1126     for (
int i = 0; (
size > 0) && (
i < srcheight); 
i++) {
 
 1127         for (
int j = 0; (
size > 0) && (j < srcwidth); j++, 
size--) {
 
 1128             if (
src[j] != skipcolor)
 
 1137                      int16_t 
left, int16_t top, uint16_t srcxoff, uint16_t srcyoff,
 
 1138                      uint16_t srcwidth, uint16_t srcheight, 
const uint16_t srcpitch,
 
 1139                      const uint16_t dstpitch, 
const uint16_t dstheight, 
int32_t size,
 
 1140                      const uint8_t *itbl)
 
 1142     if ((srcwidth < 1) || (srcheight < 1) || (
size < 1))
 
 1146         if (-top >= srcheight)
 
 1150         size += (srcpitch * top);
 
 1154     if ((top + srcheight) > dstheight) {
 
 1155         int clip = (top + srcheight) - dstheight;
 
 1156         if (
clip >= srcheight)
 
 1162         if (-
left >= srcwidth)
 
 1170     if (
left + srcwidth > dstpitch) {
 
 1171         int clip = (
left + srcwidth) - dstpitch;
 
 1172         if (
clip >= srcwidth)
 
 1177     src1 += ((uintptr_t)srcyoff * srcpitch) + srcxoff;
 
 1178     src2 += ((uintptr_t)srcyoff * srcpitch) + srcxoff;
 
 1179     dst += ((uintptr_t)top * dstpitch) + 
left;
 
 1180     for (
int i = 0; (
size > 0) && (
i < srcheight); 
i++) {
 
 1181         for (
int j = 0; (
size > 0) && (j < srcwidth); j++, 
size--) {
 
 1191                        const int w, 
const int h)
 
 1193     blt_solid((uint8_t*)
ctx->fbuf, gb->
buffer, 
left, top, 0, 0, 
w, 
h, 
w, 
ctx->pitch,
 
 1205     for (j = 0; j < 4; j++) {
 
 1206         for (
i = 0; 
i < 4; 
i++) {
 
 1221     int i, j, k, l, t, 
run, 
len, 
code, 
skip, 
mx, 
my;
 
 1222     uint8_t *
dst, *prev;
 
 1232     int compr = bytestream2_get_byteu(gb);
 
 1233     int mvoff = bytestream2_get_byteu(gb);
 
 1234     int seq   = bytestream2_get_le16u(gb);
 
 1235     uint32_t decoded_size = bytestream2_get_le32u(gb);
 
 1239     flags = bytestream2_get_byteu(gb);
 
 1247     if (((seq & 1) || !(
flags & 1)) && (compr && compr != 2)) {
 
 1251     dst  = ((uint8_t*)
ctx->frm0);
 
 1252     prev = ((uint8_t*)
ctx->frm2);
 
 1264         memset(
ctx->frm2, 0, 
ctx->frm2_size);
 
 1271         for (j = 0; j < 
height; j += 4) {
 
 1276                     code = bytestream2_get_byte(gb);
 
 1287                     code = bytestream2_get_byte(gb);
 
 1290                         for (k = 0; k < 4; k++) {
 
 1291                             for (l = 0; l < 4; l++) {
 
 1295                                     code = bytestream2_get_byte(gb);
 
 1301                                         code = bytestream2_get_byte(gb);
 
 1307                                         code = bytestream2_get_byte(gb);
 
 1331         memset(
ctx->frm2, 0, 
ctx->frm2_size);
 
 1335         for (j = 0; j < 
height; j += 4) {
 
 1345                 code = bytestream2_get_byteu(gb);
 
 1349                     for (k = 0; k < 4; k++)
 
 1351                 } 
else if ((
flags & 4) && (
code == 0xFE)) {
 
 1354                     for (k = 0; k < 4; k += 2) {
 
 1355                         uint8_t 
c1 = bytestream2_get_byteu(gb);
 
 1356                         uint8_t 
c2 = bytestream2_get_byteu(gb);
 
 1357                         for (l = 0; l < 2; l++) {
 
 1364                 } 
else if ((
flags & 4) && (
code == 0xFD)) {
 
 1367                     t = bytestream2_get_byteu(gb);
 
 1368                     for (k = 0; k < 4; k++)
 
 1376                     if ((compr == 4) && (
code == 0)) {
 
 1379                         skip_run = bytestream2_get_byteu(gb);
 
 1389                                       "Subcodec 37 compression %d", compr);
 
 1393     if ((
flags & 2) == 0) {
 
 1404                          uint8_t *prev1, uint8_t *prev2, 
int stride, 
int size)
 
 1413     code = bytestream2_get_byteu(gb);
 
 1420                 dst[0]          = bytestream2_get_byteu(gb);
 
 1421                 dst[1]          = bytestream2_get_byteu(gb);
 
 1422                 dst[0 + 
stride] = bytestream2_get_byteu(gb);
 
 1423                 dst[1 + 
stride] = bytestream2_get_byteu(gb);
 
 1445             t = bytestream2_get_byteu(gb);
 
 1446             for (k = 0; k < 
size; k++)
 
 1453             code = bytestream2_get_byteu(gb);
 
 1457             for (k = 0; k < 
size; k++)
 
 1458                 for (t = 0; t < 
size; t++)
 
 1459                     dst[t + k * 
stride] = colors[!*pglyph++];
 
 1462             for (k = 0; k < 
size; k++)
 
 1466             for (k = 0; k < 
size; k++)
 
 1472         int index = prev2 - (
const uint8_t *)
ctx->frm2;
 
 1482         for (k = 0; k < 
size; k++)
 
 1494     for (
i = 0; 
i < 256; 
i++) {
 
 1496         for (j = 256 - 
i; j; j--) {
 
 1497             *p1 = *p2 = bytestream2_get_byte(gb);
 
 1506                           const int height, 
const ptrdiff_t 
stride, 
const uint8_t *itbl)
 
 1514         p1 = bytestream2_get_byte(gb);
 
 1518         for (j = 2; j < 
width; j += 2) {
 
 1519             p1 = bytestream2_get_byte(gb);
 
 1520             px = (
px << 8) | p1;
 
 1530         for (j = 0; j < 
width; j++) {
 
 1541     uint32_t decoded_size;
 
 1543     uint8_t *
dst   = (uint8_t *)
ctx->frm0;
 
 1544     uint8_t *prev1 = (uint8_t *)
ctx->frm1;
 
 1545     uint8_t *prev2 = (uint8_t *)
ctx->frm2;
 
 1555     int seq     = bytestream2_get_le16u(gb);
 
 1556     int compr   = bytestream2_get_byteu(gb);
 
 1557     int new_rot = bytestream2_get_byteu(gb);
 
 1558     int skip    = bytestream2_get_byteu(gb);
 
 1562     auxcol[0] = bytestream2_get_byteu(gb);
 
 1563     auxcol[1] = bytestream2_get_byteu(gb);
 
 1564     decoded_size = bytestream2_get_le32u(gb);
 
 1567     if (decoded_size > 
ctx->aligned_height * 
width) {
 
 1579         memset(prev1, auxcol[0], 
ctx->frm0_size);
 
 1580         memset(prev2, auxcol[1], 
ctx->frm0_size);
 
 1595         if (seq == 
ctx->prev_seq + 1) {
 
 1596             for (j = 0; j < 
height; j += 8) {
 
 1607         memcpy(
ctx->frm0, 
ctx->frm2, 
ctx->frm0_size);
 
 1610         memcpy(
ctx->frm0, 
ctx->frm1, 
ctx->frm0_size);
 
 1618                                       "Subcodec 47 compression %d", compr);
 
 1625     if ((seq == 
ctx->prev_seq + 1) && new_rot)
 
 1628     ctx->prev_seq = seq;
 
 1638     for (
int i = 0; 
i < 4; 
i++) {
 
 1639         for (
int j = 0; j < 8; j += 2) {
 
 1642             *((uint16_t *)(
dst + 
w * 0 + j)) = 
p;
 
 1643             *((uint16_t *)(
dst + 
w * 1 + j)) = 
p;
 
 1650     if (mvofs < -x + -y*
w)
 
 1653     if (mvofs > 
w-x-blocksize + 
w*(
h-y-blocksize))
 
 1660                          const uint16_t 
w, 
const int aligned_height, 
const uint8_t *itbl)
 
 1662     uint8_t opc, sb[16];
 
 1670     opc = bytestream2_get_byteu(gb);
 
 1676         if (y > 0 && x > 0) {
 
 1677             sb[15] = bytestream2_get_byteu(gb);
 
 1678             sb[ 7] = itbl[(*(
dst - 1*
w + 7) << 8) | sb[15]];
 
 1679             sb[ 3] = itbl[(*(
dst - 1*
w + 7) << 8) | sb[ 7]];
 
 1680             sb[11] = itbl[(sb[15]           << 8) | sb[ 7]];
 
 1681             sb[ 1] = itbl[(*(
dst + 0*
w - 1) << 8) | sb[ 3]];
 
 1682             sb[ 0] = itbl[(*(
dst + 0*
w - 1) << 8) | sb[ 1]];
 
 1683             sb[ 2] = itbl[(sb[ 3]           << 8) | sb[ 1]];
 
 1684             sb[ 5] = itbl[(*(
dst + 2*
w - 1) << 8) | sb[ 7]];
 
 1685             sb[ 4] = itbl[(*(
dst + 2*
w - 1) << 8) | sb[ 5]];
 
 1686             sb[ 6] = itbl[(sb[ 7]           << 8) | sb[ 5]];
 
 1687             sb[ 9] = itbl[(*(
dst + 3*
w - 1) << 8) | sb[11]];
 
 1688             sb[ 8] = itbl[(*(
dst + 3*
w - 1) << 8) | sb[ 9]];
 
 1689             sb[10] = itbl[(sb[11]           << 8) | sb[ 9]];
 
 1690             sb[13] = itbl[(*(
dst + 4*
w - 1) << 8) | sb[15]];
 
 1691             sb[12] = itbl[(*(
dst + 4*
w - 1) << 8) | sb[13]];
 
 1692             sb[14] = itbl[(sb[15]           << 8) | sb[13]];
 
 1694            opc = bytestream2_get_byteu(gb);
 
 1695            for (
i = 0; 
i < 16; 
i++)
 
 1703         mvofs =  bytestream2_get_le16(gb);
 
 1706         for (
i = 0; 
i < 8; 
i++) {
 
 1708             for (k = 0; k < 8; k++)
 
 1709                 *(
dst + ofs + k) = *(db + ofs + k + mvofs);
 
 1715         sb[ 5] =  bytestream2_get_byteu(gb);
 
 1716         sb[ 7] =  bytestream2_get_byteu(gb);
 
 1717         sb[13] =  bytestream2_get_byteu(gb);
 
 1718         sb[15] =  bytestream2_get_byteu(gb);
 
 1720         if (y > 0 && x >0) {
 
 1721             sb[ 1] = itbl[(*(
dst - 1*
w + 3) << 8) | sb[ 5]];
 
 1722             sb[ 3] = itbl[(*(
dst - 1*
w + 7) << 8) | sb[ 7]];
 
 1723             sb[ 9] = itbl[(sb[13]           << 8) | sb[ 5]];
 
 1724             sb[11] = itbl[(sb[15]           << 8) | sb[ 7]];
 
 1725             sb[ 0] = itbl[(*(
dst + 0*
w - 1) << 8) | sb[ 1]];
 
 1726             sb[ 2] = itbl[(sb[ 3]           << 8) | sb[ 1]];
 
 1727             sb[ 4] = itbl[(*(
dst + 2*
w - 1) << 8) | sb[ 5]];
 
 1728             sb[ 6] = itbl[(sb[ 7]           << 8) | sb[ 5]];
 
 1729             sb[ 8] = itbl[(*(
dst + 3*
w - 1) << 8) | sb[ 9]];
 
 1730             sb[10] = itbl[(sb[11]           << 8) | sb[ 9]];
 
 1731             sb[12] = itbl[(*(
dst + 4*
w - 1) << 8) | sb[13]];
 
 1732             sb[14] = itbl[(sb[15]           << 8) | sb[13]];
 
 1734             sb[ 0] = sb[ 1] = sb[ 4] = sb[ 5];
 
 1735             sb[ 2] = sb[ 3] = sb[ 6] = sb[ 7];
 
 1736             sb[ 8] = sb[ 9] = sb[12] = sb[13];
 
 1737             sb[10] = sb[11] = sb[14] = sb[15];
 
 1744         for (
i = 0; 
i < 8; 
i += 4) {
 
 1745             for (k = 0; k < 8; k += 4) {
 
 1746                 opc =  bytestream2_get_byteu(gb);
 
 1747                 opc = (opc == 255) ? 0 : opc;
 
 1751                 for (j = 0; j < 4; j++) {
 
 1752                     ofs = (
w * (j + 
i)) + k;
 
 1753                     for (l = 0; l < 4; l++)
 
 1754                         *(
dst + ofs + l) = *(db + ofs + l + mvofs);
 
 1762         for (
i = 0; 
i < 8; 
i += 4) {
 
 1763             for (k = 0; k < 8; k += 4) {
 
 1764                 mvofs = bytestream2_get_le16(gb);
 
 1767                 for (j = 0; j < 4; j++) {
 
 1768                     ofs = (
w * (j + 
i)) + k;
 
 1769                     for (l = 0; l < 4; l++)
 
 1770                         *(
dst + ofs + l) = *(db + ofs + l + mvofs);
 
 1784         for (
i = 0; 
i < 8; 
i += 2) {
 
 1785             for (j = 0; j < 8; j += 2) {
 
 1787                 opc = bytestream2_get_byteu(gb);
 
 1788                 opc = (opc == 255) ? 0 : opc;
 
 1792                 for (l = 0; l < 2; l++) {
 
 1793                     *(
dst + ofs + l + 0) = *(db + ofs + l + 0 + mvofs);
 
 1794                     *(
dst + ofs + l + 
w) = *(db + ofs + l + 
w + mvofs);
 
 1802         for (
i = 0; 
i < 8; 
i += 2) {
 
 1803             for (j = 0; j < 8; j += 2) {
 
 1805                 mvofs = bytestream2_get_le16(gb);
 
 1808                 for (l = 0; l < 2; l++) {
 
 1809                     *(
dst + ofs + l + 0) = *(db + ofs + l + 0 + mvofs);
 
 1810                     *(
dst + ofs + l + 
w) = *(db + ofs + l + 
w + mvofs);
 
 1818         for (
i = 0; 
i < 8; 
i++) {
 
 1820             for (l = 0; l < 8; l++)
 
 1821                 *(
dst + ofs + l) = bytestream2_get_byteu(gb);
 
 1828         for (
i = 0; 
i < 8; 
i++) {
 
 1830             for (l = 0; l < 8; l++)
 
 1831                 *(
dst + ofs + l) = *(db + ofs + l + mvofs);
 
 1841     uint8_t *
dst, *prev;
 
 1849     if (ah > 
ctx->aligned_height)
 
 1855     int compr = bytestream2_get_byteu(gb);
 
 1856     int mvidx = bytestream2_get_byteu(gb);
 
 1857     int seq   = bytestream2_get_le16u(gb);
 
 1858     uint32_t decoded_size = bytestream2_get_le32u(gb);
 
 1867     flags = bytestream2_get_byteu(gb);
 
 1876     dst  = (uint8_t*)
ctx->frm0;
 
 1877     prev = (uint8_t*)
ctx->frm2;
 
 1880         memset(
ctx->frm2, 0, 
ctx->frm2_size);
 
 1898         if ((seq == 0) || (seq == 
ctx->prev_seq + 1)) {
 
 1899             if ((seq & 1) || ((
flags & 1) == 0) || (
flags & 0x10)) {
 
 1901                 dst  = (uint8_t*)
ctx->frm0;
 
 1902                 prev = (uint8_t*)
ctx->frm2;
 
 1904             for (j = 0; j < 
height; j += 8) {
 
 1924                                       "Subcodec 48 compression %d", compr);
 
 1928     ctx->prev_seq = seq;
 
 1929     if ((
flags & 2) == 0) {
 
 1952     uint16_t 
w, 
h, parm2;
 
 1953     uint8_t codec, param;
 
 1957     codec = bytestream2_get_byteu(gb);
 
 1958     param = bytestream2_get_byteu(gb);
 
 1959     left  = bytestream2_get_le16u(gb) + xoff;
 
 1960     top   = bytestream2_get_le16u(gb) + yoff;
 
 1961     w     = bytestream2_get_le16u(gb);
 
 1962     h     = bytestream2_get_le16u(gb);
 
 1964     parm2 = bytestream2_get_le16u(gb);
 
 1966     if (
w < 1 || h < 1 || w > 640 || 
h > 480 || 
left > 640 || top > 480 || 
left + 
w <= 0 || top + 
h <= 0) {
 
 1968                "ignoring invalid fobj dimensions: c%d %d %d @ %d %d\n",
 
 1974     fsc = (codec == 37 || codec == 47 || codec == 48);
 
 1980     if ((
w == 640) && (
h == 272) && (top == 60) && (codec == 47))
 
 1983     if (!
ctx->have_dimensions) {
 
 1985         if (
ctx->subversion < 2) {
 
 1989             if (
w > xres || 
h > yres)
 
 1991             ctx->have_dimensions = 1;
 
 1996             ctx->have_dimensions = 1;
 
 2001             if (((xres == 424) && (yres == 260)) ||  
 
 2002                 ((xres == 320) && (yres == 200)) ||  
 
 2003                 ((xres == 640) && (yres == 272)) ||  
 
 2004                 ((xres == 640) && (yres == 350)) ||  
 
 2005                 ((xres == 640) && (yres == 480))) {
 
 2006                 ctx->have_dimensions = 1;
 
 2013         if ((xres < (fsc ? 8 : 1)) || (yres < (fsc ? 8 : 1)) || (xres > 640) || (yres > 480))
 
 2016         if (
ctx->width < xres || 
ctx->height < yres) {
 
 2027         if (((
w > 
ctx->width) || (
h > 
ctx->height) || (
w * 
h > 
ctx->buf_size)) && fsc) {
 
 2034                    "resizing too large fobj: c%d  %d %d @ %d %d\n", codec, 
w, 
h, 
left, top);
 
 2041     if (fsc && 
ctx->subversion < 2) {
 
 2042         ctx->subversion = 2;
 
 2047     if (
ctx->first_fob) {
 
 2050             memset(
ctx->fbuf, 0, 
ctx->frm0_size);
 
 2091     int xoff, yoff, 
ret;
 
 2097         xoff = bytestream2_get_le16u(&
ctx->gb);
 
 2098         yoff = bytestream2_get_le16u(&
ctx->gb);
 
 2099     } 
else if (
size == 12) {
 
 2102         xoff = bytestream2_get_be32u(&
ctx->gb);
 
 2103         yoff = bytestream2_get_be32u(&
ctx->gb);
 
 2107     if (
ctx->stor_size > 0) {
 
 2112         memcpy(bitstream, 
ctx->stored_frame, 
ctx->stor_size);
 
 2131     int16_t *dp = 
ctx->delta_pal;
 
 2132     uint32_t *pal = 
ctx->pal;
 
 2140     cmd = bytestream2_get_be16(&
ctx->gb);
 
 2145             for (j = 0; j < 3; j++) {
 
 2146                 ctx->shift_pal[
i + j] += dp[
i + j];
 
 2149             *pal++ = 0xFF
U << 24 | 
c[0] << 16 | 
c[1] << 8 | 
c[2];
 
 2151     } 
else if (cmd == 0 || cmd == 2) {
 
 2154                    "Incorrect palette change block size %"PRIu32
".\n", 
size);
 
 2158             dp[
i] = bytestream2_get_le16u(&
ctx->gb);
 
 2163                 ctx->pal[
i] = 0xFFU << 24 | bytestream2_get_be24u(&
ctx->gb);
 
 2164             if (
ctx->subversion < 2)
 
 2165                 ctx->pal[0] = 0xFF
U << 24;
 
 2168             ctx->shift_pal[
i + 0] = (((
ctx->pal[j]) >> 16) & 0xFF
U) << 7;
 
 2169             ctx->shift_pal[
i + 1] = (((
ctx->pal[j]) >>  8) & 0xFF
U) << 7;
 
 2170             ctx->shift_pal[
i + 2] = (((
ctx->pal[j]) >>  0) & 0xFF
U) << 7;
 
 2178     uint16_t *frm = 
ctx->frm0;
 
 2185     for (y = 0; y < 
ctx->height; y++) {
 
 2186         for (x = 0; x < 
ctx->width; x++)
 
 2187             frm[x] = bytestream2_get_le16u(&
ctx->gb);
 
 2196     return (((
c2 & 0x07e0) + (
c1 & 0x07e0)) & 0x00fc0) |
 
 2197            (((
c2 & 0xf800) + (
c1 & 0xf800)) & 0x1f000) |
 
 2198            (((
c2 & 0x001f) + (
c1 & 0x001f))) >> 1;
 
 2207     uint16_t hh, hw, 
c1, 
c2, *dst1, *dst2;
 
 2212     hh = (
ctx->height + 1) >> 1;
 
 2213     dst1 = (uint16_t *)
ctx->frm0 + 
ctx->pitch;    
 
 2215         hw = (
ctx->width - 1) >> 1;
 
 2216         c1 = bytestream2_get_le16u(&
ctx->gb);
 
 2221             c2 = bytestream2_get_le16u(&
ctx->gb);
 
 2226         dst1 += 
ctx->pitch * 2;    
 
 2234     dst1 = 
ctx->frm0 + (
ctx->pitch * 2);
 
 2235     hh = (
ctx->height - 1) >> 1;
 
 2240             c1 = *(dst2 - 
ctx->pitch);   
 
 2241             c2 = *(dst2 + 
ctx->pitch);   
 
 2244         dst1 += 
ctx->pitch * 2;
 
 2249 static void copy_block(uint16_t *pdest, uint16_t *psrc, 
int block_size, ptrdiff_t pitch)
 
 2251     uint8_t *
dst = (uint8_t *)pdest;
 
 2252     uint8_t *
src = (uint8_t *)psrc;
 
 2253     ptrdiff_t 
stride = pitch * 2;
 
 2255     switch (block_size) {
 
 2272     pitch -= block_size;
 
 2273     for (y = 0; y < block_size; y++, pdest += pitch)
 
 2274         for (x = 0; x < block_size; x++)
 
 2279                       uint16_t fg_color, uint16_t bg_color, 
int block_size,
 
 2283     uint16_t colors[2] = { fg_color, bg_color };
 
 2291     pglyph = block_size == 8 ? 
ctx->p8x8glyphs[
index] : 
ctx->p4x4glyphs[
index];
 
 2292     pitch -= block_size;
 
 2294     for (y = 0; y < block_size; y++, 
dst += pitch)
 
 2295         for (x = 0; x < block_size; x++)
 
 2296             *
dst++ = colors[*pglyph++];
 
 2302     uint16_t *
dst = 
ctx->frm0 + cx + cy * 
ctx->pitch;
 
 2304     if (block_size == 2) {
 
 2310         indices        = bytestream2_get_le32u(&
ctx->gb);
 
 2311         dst[0]         = 
ctx->codebook[indices & 0xFF];
 
 2313         dst[1]         = 
ctx->codebook[indices & 0xFF];
 
 2315         dst[pitch]     = 
ctx->codebook[indices & 0xFF];
 
 2317         dst[pitch + 1] = 
ctx->codebook[indices & 0xFF];
 
 2319         uint16_t fgcolor, bgcolor;
 
 2325         glyph   = bytestream2_get_byteu(&
ctx->gb);
 
 2326         bgcolor = 
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
 
 2327         fgcolor = 
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
 
 2336     uint16_t *
dst = 
ctx->frm0 + cx + cy * 
ctx->pitch;
 
 2338     if (block_size == 2) {
 
 2342         dst[0]         = bytestream2_get_le16u(&
ctx->gb);
 
 2343         dst[1]         = bytestream2_get_le16u(&
ctx->gb);
 
 2344         dst[pitch]     = bytestream2_get_le16u(&
ctx->gb);
 
 2345         dst[pitch + 1] = bytestream2_get_le16u(&
ctx->gb);
 
 2347         uint16_t fgcolor, bgcolor;
 
 2353         glyph   = bytestream2_get_byteu(&
ctx->gb);
 
 2354         bgcolor = bytestream2_get_le16u(&
ctx->gb);
 
 2355         fgcolor = bytestream2_get_le16u(&
ctx->gb);
 
 2365     int start_pos = cx + 
mx + (cy + 
my) * 
ctx->pitch;
 
 2366     int end_pos = start_pos + (block_size - 1) * (
ctx->pitch + 1);
 
 2368     int good = start_pos >= 0 && end_pos < (
ctx->buf_size >> 1);
 
 2372                "Ignoring invalid motion vector (%i, %i)->(%u, %u), block size = %u\n",
 
 2373                cx + 
mx, cy + 
my, cx, cy, block_size);
 
 2386     opcode = bytestream2_get_byteu(&
ctx->gb);
 
 2402         if (
ctx->width > 761) {
 
 2409                        ctx->frm2 + cx + 
mx + 
ctx->pitch * (cy + 
my),
 
 2410                        blk_size, 
ctx->pitch);
 
 2416         index = bytestream2_get_le16u(&
ctx->gb);
 
 2423                        ctx->frm2 + cx + 
mx + 
ctx->pitch * (cy + 
my),
 
 2424                        blk_size, 
ctx->pitch);
 
 2429                    ctx->frm1 + cx + 
ctx->pitch * cy,
 
 2430                    blk_size, 
ctx->pitch);
 
 2444                    ctx->small_codebook[opcode - 0xf9], blk_size, 
ctx->pitch);
 
 2450                    ctx->codebook[bytestream2_get_byteu(&
ctx->gb)], blk_size, 
ctx->pitch);
 
 2456                    bytestream2_get_le16u(&
ctx->gb), blk_size, 
ctx->pitch);
 
 2459         if (blk_size == 2) {
 
 2469             if (
bl16_block(
ctx, cx + blk_size, cy + blk_size, blk_size))
 
 2481     for (cy = 0; cy < 
ctx->aligned_height; cy += 8)
 
 2482         for (cx = 0; cx < 
ctx->aligned_width; cx += 8)
 
 2495     uint8_t *
dst = (uint8_t*)
ctx->frm0;
 
 2501     npixels = 
ctx->npixels;
 
 2514     int npixels = 
ctx->npixels;
 
 2515     uint16_t *frm = 
ctx->frm0;
 
 2522         *frm++ = 
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
 
 2534     uint16_t hh, hw, 
c1, 
c2, *dst1, *dst2;
 
 2539     hh = (
ctx->height + 1) >> 1;
 
 2540     dst1 = (uint16_t *)
ctx->frm0 + 
ctx->pitch;    
 
 2542         hw = (
ctx->width - 1) >> 1;
 
 2543         c1 = 
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
 
 2548             c2 = 
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
 
 2553         dst1 += 
ctx->pitch * 2;    
 
 2561     dst1 = 
ctx->frm0 + (
ctx->pitch * 2);
 
 2562     hh = (
ctx->height - 1) >> 1;
 
 2567             c1 = *(dst2 - 
ctx->pitch);   
 
 2568             c2 = *(dst2 + 
ctx->pitch);   
 
 2571         dst1 += 
ctx->pitch * 2;
 
 2578     uint16_t *pdest = 
ctx->frm0;
 
 2580     long npixels = 
ctx->npixels;
 
 2583     if (!
ctx->rle_buf) {
 
 2587     rsrc = 
ctx->rle_buf;
 
 2593         *pdest++ = 
ctx->codebook[*rsrc++];
 
 2609     const uint8_t *
src = sanm ? (uint8_t *)
ctx->frm0 : (uint8_t *)
ctx->fbuf;
 
 2611     ptrdiff_t dstpitch, srcpitch = 
ctx->pitch * (sanm ? 
sizeof(
ctx->frm0[0]) : 1);
 
 2616     dst      = 
ctx->frame->data[0];
 
 2617     dstpitch = 
ctx->frame->linesize[0];
 
 2620         memcpy(
dst, 
src, srcpitch);
 
 2631     int i, 
ret, 
w, 
h, seq_num, codec, bg_color, rle_output_size, rcode;
 
 2640     w = bytestream2_get_le32u(&
ctx->gb);
 
 2641     h = bytestream2_get_le32u(&
ctx->gb);
 
 2643     if (
w != 
ctx->width || 
h != 
ctx->height) {
 
 2648     seq_num     = bytestream2_get_le16u(&
ctx->gb);
 
 2649     codec       = bytestream2_get_byteu(&
ctx->gb);
 
 2650     rcode       = bytestream2_get_byteu(&
ctx->gb);
 
 2654     for (
i = 0; 
i < 4; 
i++)
 
 2655         ctx->small_codebook[
i] = bytestream2_get_le16u(&
ctx->gb);
 
 2656     bg_color = bytestream2_get_le16u(&
ctx->gb);
 
 2660     rle_output_size = bytestream2_get_le32u(&
ctx->gb);
 
 2661     if (rle_output_size > 
w * 
ctx->aligned_height * 2) {
 
 2664         rle_output_size = 
w * 
ctx->aligned_height * 2;
 
 2667     for (
i = 0; 
i < 256; 
i++)
 
 2668         ctx->codebook[
i] = bytestream2_get_le16u(&
ctx->gb);
 
 2687     case 3: memcpy(
ctx->frm0, 
ctx->frm2, 
ctx->frm2_size); 
break;
 
 2688     case 4: memcpy(
ctx->frm0, 
ctx->frm1, 
ctx->frm1_size); 
break;
 
 2700                "Subcodec %d: error decoding frame.\n", codec);
 
 2717     int i, 
ret, to_store = 0, have_img = 0;
 
 2724         sig  = bytestream2_get_be32u(&
ctx->gb);
 
 2725         size = bytestream2_get_be32u(&
ctx->gb);
 
 2733         case MKBETAG(
'N', 
'P', 
'A', 
'L'):
 
 2736                        "Incorrect palette block size %"PRIu32
".\n", 
size);
 
 2740                 ctx->pal[
i] = 0xFFU << 24 | bytestream2_get_be24u(&
ctx->gb);
 
 2741             if (
ctx->subversion < 2)
 
 2742                 ctx->pal[0] = 0xFF
U << 24;
 
 2744         case MKBETAG(
'F', 
'O', 
'B', 
'J'):
 
 2761                 if (
ctx->subversion < 2) {
 
 2762                     if (size <= ctx->stored_frame_size) {
 
 2771                     memcpy(
ctx->stored_frame, 
ctx->fbuf, 
ctx->buf_size);
 
 2772                     ctx->stor_size = 
ctx->buf_size;
 
 2777         case MKBETAG(
'X', 
'P', 
'A', 
'L'):
 
 2781         case MKBETAG(
'S', 
'T', 
'O', 
'R'):
 
 2784         case MKBETAG(
'F', 
'T', 
'C', 
'H'):
 
 2785             if (
ctx->subversion < 2) {
 
 2788                 have_img = (
ret == 0) ? 1 : 0;
 
 2790                 if (
ctx->stor_size > 0) {
 
 2791                     memcpy(
ctx->fbuf, 
ctx->stored_frame, 
ctx->buf_size);
 
 2799                    "Unknown/unsupported chunk %"PRIx32
".\n", sig);
 
 2810             if (bytestream2_peek_byte(&
ctx->gb) == 0)
 
 2818         memcpy(
ctx->frame->data[1], 
ctx->pal, 1024);
 
 2833     if (!
ctx->version) {