LCOV - code coverage report
Current view: top level - libavcodec - sheervideo.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 1364 0.0 %
Date: 2017-12-18 06:23:41 Functions: 0 29 0.0 %

          Line data    Source code
       1             : /*
       2             :  * BitJazz SheerVideo decoder
       3             :  * Copyright (c) 2016 Paul B Mahol
       4             :  *
       5             :  * This file is part of FFmpeg.
       6             :  *
       7             :  * FFmpeg is free software; you can redistribute it and/or
       8             :  * modify it under the terms of the GNU Lesser General Public
       9             :  * License as published by the Free Software Foundation; either
      10             :  * version 2.1 of the License, or (at your option) any later version.
      11             :  *
      12             :  * FFmpeg is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * Lesser General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU Lesser General Public
      18             :  * License along with FFmpeg; if not, write to the Free Software
      19             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      20             :  */
      21             : 
      22             : #include <stdio.h>
      23             : #include <stdlib.h>
      24             : #include <string.h>
      25             : 
      26             : #include "libavutil/intreadwrite.h"
      27             : #include "avcodec.h"
      28             : #include "get_bits.h"
      29             : #include "internal.h"
      30             : #include "thread.h"
      31             : 
      32             : typedef struct SheerVideoContext {
      33             :     unsigned format;
      34             :     int alt;
      35             :     VLC vlc[2];
      36             :     void (*decode_frame)(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb);
      37             : } SheerVideoContext;
      38             : 
      39             : static const uint8_t l_r_rgb[256] = {
      40             :      3,  3,  4,  4,  5,  5,  5,  6,  6,  6,  7,  7,  7,  7,  7,  8,
      41             :      8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10,
      42             :     10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12,
      43             :     12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
      44             :     13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
      45             :     14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
      46             :     15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      47             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      48             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      49             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15,
      50             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
      51             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13,
      52             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
      53             :     12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
      54             :     10, 10, 10, 10, 10, 10,  9,  9,  9,  9,  9,  9,  9,  8,  8,  8,
      55             :      8,  8,  8,  7,  7,  7,  7,  7,  6,  6,  6,  5,  5,  4,  4,  4,
      56             : };
      57             : 
      58             : static const uint8_t l_r_rgbi[256] = {
      59             :      3,  4,  4,  4,  5,  5,  5,  6,  6,  6,  7,  7,  7,  7,  7,  7,
      60             :      8,  8,  8,  8,  8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9,
      61             :     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11,
      62             :     11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12,
      63             :     12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
      64             :     13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14,
      65             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15,
      66             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
      67             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
      68             :     15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
      69             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13,
      70             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12,
      71             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11,
      72             :     11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10,
      73             :     10, 10,  9,  9,  9,  9,  9,  9,  9,  8,  8,  8,  8,  8,  8,  8,
      74             :      8,  7,  7,  7,  7,  7,  7,  6,  6,  6,  6,  5,  5,  4,  4,  4,
      75             : };
      76             : 
      77             : static const uint8_t l_g_rgbi[256] = {
      78             :      1,  3,  4,  5,  6,  7,  7,  8,  9,  9, 10, 10, 10, 10, 11, 11,
      79             :     11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
      80             :     14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16,
      81             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      82             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      83             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      84             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      85             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      86             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      87             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      88             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      89             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      90             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      91             :     16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14,
      92             :     14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12,
      93             :     11, 11, 11, 10, 10, 10,  9,  9,  9,  8,  8,  7,  6,  5,  5,  3,
      94             : };
      95             : 
      96             : static const uint8_t l_g_rgb[256] = {
      97             :      2,  2,  4,  4,  6,  7,  9,  9, 10, 11, 11, 11, 12, 12, 12, 13,
      98             :     13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
      99             :     15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     100             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     101             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     102             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     103             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     104             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     105             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     106             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     107             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     108             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     109             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     110             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15,
     111             :     15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
     112             :     13, 13, 12, 12, 12, 11, 11, 11, 10,  9,  9,  8,  6,  4,  3,  3,
     113             : };
     114             : 
     115             : static const uint8_t l_y_ybr[256] = {
     116             :      3,  3,  4,  4,  5,  5,  6,  6,  6,  7,  7,  7,  7,  7,  8,  8,
     117             :      8,  8,  8,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10,
     118             :     10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
     119             :     12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14,
     120             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
     121             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
     122             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     123             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     124             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     125             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     126             :     16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     127             :     15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     128             :     14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
     129             :     12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
     130             :     11, 10, 10, 10, 10, 10, 10, 10,  9,  9,  9,  9,  9,  9,  8,  8,
     131             :      8,  8,  8,  8,  7,  7,  7,  7,  6,  6,  6,  6,  5,  4,  4,  3,
     132             : };
     133             : 
     134             : static const uint8_t l_u_ybr[256] = {
     135             :      1,  2,  4,  6,  9, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14,
     136             :     14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     137             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     138             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     139             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     140             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     141             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     142             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     143             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     144             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     145             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     146             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     147             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     148             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     149             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15,
     150             :     14, 14, 14, 14, 14, 13, 13, 13, 12, 12, 11, 11, 10,  8,  5,  3,
     151             : };
     152             : 
     153             : static const uint8_t l_y_ybyr[256] = {
     154             :      3,  3,  4,  4,  5,  5,  5,  6,  6,  6,  7,  7,  7,  7,  7,  8,
     155             :      8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10,
     156             :     10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12,
     157             :     12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13,
     158             :     13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     159             :     14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     160             :     15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     161             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     162             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     163             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15,
     164             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14,
     165             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
     166             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
     167             :     12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
     168             :     10, 10, 10, 10, 10, 10,  9,  9,  9,  9,  9,  9,  9,  8,  8,  8,
     169             :      8,  8,  8,  7,  7,  7,  7,  7,  6,  6,  6,  5,  5,  4,  4,  4,
     170             : };
     171             : 
     172             : static const uint8_t l_u_ybyr[256] = {
     173             :      1,  2,  4,  6,  8,  9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14,
     174             :     14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
     175             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     176             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     177             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     178             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     179             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     180             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     181             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     182             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     183             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     184             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     185             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     186             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     187             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 14, 14,
     188             :     14, 14, 13, 13, 13, 12, 12, 11, 11, 10, 10,  9,  8,  7,  6,  3,
     189             : };
     190             : 
     191             : static const uint8_t l_y_byry[256] = {
     192             :      3,  3,  4,  4,  5,  5,  6,  6,  6,  7,  7,  7,  7,  7,  8,  8,
     193             :      8,  8,  8,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10,
     194             :     10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
     195             :     12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14,
     196             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
     197             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
     198             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     199             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     200             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     201             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     202             :     16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     203             :     15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     204             :     14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
     205             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11,
     206             :     11, 10, 10, 10, 10, 10, 10, 10,  9,  9,  9,  9,  9,  9,  8,  8,
     207             :      8,  8,  8,  8,  7,  7,  7,  7,  6,  6,  6,  6,  5,  4,  4,  3,
     208             : };
     209             : 
     210             : static const uint8_t l_u_byry[256] = {
     211             :      1,  2,  4,  6,  8,  9,  9, 10, 11, 11, 12, 12, 13, 13, 13, 14,
     212             :     14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
     213             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     214             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     215             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     216             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     217             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     218             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     219             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     220             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     221             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     222             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     223             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     224             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     225             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14,
     226             :     14, 14, 14, 13, 13, 12, 12, 12, 11, 11, 10,  9,  8,  7,  6,  3,
     227             : };
     228             : 
     229             : static const uint8_t l_y_ybr10i[1024] = {
     230             :      3,  5,  5,  5,  6,  6,  6,  6,  6,  6,  6,  6,  7,  7,  7,  7,
     231             :      7,  7,  7,  7,  7,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
     232             :      8,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
     233             :      9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
     234             :     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11,
     235             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     236             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12,
     237             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     238             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     239             :     12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     240             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     241             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     242             :     13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     243             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     244             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     245             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     246             :     14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     247             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     248             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     249             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     250             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     251             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
     252             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     253             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     254             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     255             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     256             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     257             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     258             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     259             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     260             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     261             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     262             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     263             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     264             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     265             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     266             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     267             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     268             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     269             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     270             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     271             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     272             :     16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     273             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     274             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     275             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     276             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     277             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     278             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     279             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     280             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     281             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     282             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     283             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     284             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     285             :     13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     286             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     287             :     12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
     288             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     289             :     11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
     290             :     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,  9,  9,  9,  9,
     291             :      9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
     292             :      8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  7,  7,  7,  7,
     293             :      7,  7,  7,  7,  7,  6,  6,  6,  6,  6,  6,  6,  6,  5,  5,  5,
     294             : };
     295             : 
     296             : static const uint8_t l_y_ybr10[1024] = {
     297             :      4,  5,  5,  5,  5,  5,  5,  6,  6,  6,  6,  6,  6,  7,  7,  7,
     298             :      7,  7,  7,  7,  7,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
     299             :      8,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
     300             :      9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
     301             :     10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
     302             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     303             :     11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     304             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     305             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     306             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     307             :     13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     308             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     309             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     310             :     14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     311             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     312             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     313             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     314             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
     315             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     316             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     317             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     318             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     319             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     320             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     321             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     322             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     323             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     324             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     325             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     326             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     327             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     328             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     329             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     330             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     331             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     332             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     333             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     334             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     335             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     336             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     337             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     338             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     339             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     340             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     341             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     342             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     343             :     16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15,
     344             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     345             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     346             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     347             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     348             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     349             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     350             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
     351             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     352             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     353             :     13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     354             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
     355             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     356             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10,
     357             :     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,  9,
     358             :      9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
     359             :      8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  7,  7,  7,
     360             :      7,  7,  7,  7,  6,  6,  6,  6,  6,  6,  6,  5,  5,  5,  5,  5,
     361             : };
     362             : 
     363             : static const uint8_t l_u_ybr10i[1024] = {
     364             :      2,  3,  4,  4,  5,  5,  6,  7,  7,  8,  8,  9,  9,  9,  9, 10,
     365             :     10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
     366             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14,
     367             :     14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     368             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     369             :     15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     370             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     371             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     372             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     373             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     374             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     375             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     376             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     377             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     378             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     379             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     380             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     381             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     382             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     383             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     384             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     385             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     386             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     387             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     388             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     389             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     390             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     391             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     392             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     393             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     394             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     395             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     396             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     397             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     398             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     399             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     400             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     401             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     402             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     403             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     404             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     405             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     406             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     407             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     408             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     409             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     410             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     411             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     412             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     413             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     414             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     415             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     416             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     417             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     418             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     419             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     420             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     421             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     422             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15,
     423             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     424             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14,
     425             :     14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     426             :     13, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 10, 10,
     427             :     10, 10, 10,  9,  9,  9,  8,  8,  8,  7,  6,  5,  5,  4,  4,  3,
     428             : };
     429             : 
     430             : static const uint8_t l_u_ybr10[1024] = {
     431             :      2,  3,  3,  4,  5,  5,  6,  7,  8,  9,  9, 10, 10, 10, 11, 11,
     432             :     12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
     433             :     14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     434             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
     435             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     436             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     437             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     438             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     439             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     440             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     441             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     442             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     443             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     444             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     445             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     446             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     447             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     448             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     449             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     450             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     451             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     452             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     453             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     454             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     455             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     456             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     457             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     458             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     459             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     460             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     461             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     462             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     463             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     464             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     465             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     466             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     467             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     468             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     469             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     470             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     471             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     472             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     473             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     474             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     475             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     476             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     477             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     478             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     479             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     480             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     481             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     482             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     483             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     484             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     485             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     486             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     487             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     488             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     489             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     490             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     491             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15,
     492             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
     493             :     14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 12, 12, 12,
     494             :     12, 11, 11, 11, 10, 10,  9,  9,  8,  8,  7,  6,  5,  4,  4,  3,
     495             : };
     496             : 
     497             : static const uint8_t l_r_rgbx[1024] = {
     498             :      4,  5,  5,  5,  6,  6,  6,  6,  6,  6,  6,  6,  6,  7,  7,  7,
     499             :      7,  7,  7,  7,  7,  7,  7,  8,  8,  8,  8,  8,  8,  8,  8,  8,
     500             :      8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
     501             :      9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10, 10,
     502             :     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
     503             :     10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     504             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12,
     505             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     506             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     507             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     508             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     509             :     13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14,
     510             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     511             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     512             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15,
     513             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     514             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     515             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     516             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     517             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
     518             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     519             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     520             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     521             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     522             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     523             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     524             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     525             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     526             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     527             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     528             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     529             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     530             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     531             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     532             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     533             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     534             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     535             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     536             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     537             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     538             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     539             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     540             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     541             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     542             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15,
     543             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     544             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     545             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     546             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     547             :     15, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     548             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     549             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     550             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13,
     551             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     552             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     553             :     13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     554             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     555             :     12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     556             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     557             :     11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
     558             :     10, 10, 10, 10, 10, 10, 10, 10, 10, 10,  9,  9,  9,  9,  9,  9,
     559             :      9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  8,  8,  8,
     560             :      8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  7,  7,  7,  7,  7,  7,
     561             :      7,  7,  7,  7,  6,  6,  6,  6,  6,  6,  6,  6,  5,  5,  5,  5,
     562             : };
     563             : 
     564             : static const uint8_t l_g_rgbx[1024] = {
     565             :      3,  4,  4,  5,  5,  5,  5,  5,  5,  6,  6,  6,  6,  7,  7,  7,
     566             :      8,  8,  9,  9,  9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12,
     567             :     12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     568             :     13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     569             :     14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     570             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     571             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
     572             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     573             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     574             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     575             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     576             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     577             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     578             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     579             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     580             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     581             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     582             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     583             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     584             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     585             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     586             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     587             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     588             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     589             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     590             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     591             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     592             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     593             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     594             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     595             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     596             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     597             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     598             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     599             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     600             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     601             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     602             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     603             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     604             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     605             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     606             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     607             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     608             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     609             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     610             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     611             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     612             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     613             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     614             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     615             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     616             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     617             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     618             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     619             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     620             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     621             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     622             :     16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     623             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     624             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
     625             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13,
     626             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
     627             :     12, 12, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10,  9,  9,  9,  9,
     628             :      8,  7,  7,  7,  6,  6,  6,  6,  6,  5,  5,  5,  5,  4,  4,  4,
     629             : };
     630             : 
     631             : static const uint8_t l_y_yry10[1024] = {
     632             :      4,  5,  5,  5,  5,  5,  5,  6,  6,  6,  6,  6,  6,  7,  7,  7,
     633             :      7,  7,  7,  7,  7,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
     634             :      8,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
     635             :      9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
     636             :     10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
     637             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     638             :     11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     639             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     640             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     641             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     642             :     13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     643             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     644             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     645             :     14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     646             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     647             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     648             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     649             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
     650             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     651             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     652             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     653             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     654             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     655             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     656             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     657             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     658             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     659             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     660             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     661             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     662             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     663             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     664             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     665             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     666             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     667             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     668             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     669             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     670             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     671             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     672             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     673             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     674             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     675             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     676             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     677             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     678             :     16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15,
     679             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     680             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     681             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     682             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     683             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     684             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     685             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
     686             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     687             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     688             :     13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     689             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
     690             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     691             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10,
     692             :     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,  9,
     693             :      9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
     694             :      8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  7,  7,  7,
     695             :      7,  7,  7,  7,  6,  6,  6,  6,  6,  6,  6,  5,  5,  5,  5,  5,
     696             : };
     697             : 
     698             : static const uint8_t l_y_yry10i[1024] = {
     699             :      3,  5,  5,  5,  6,  6,  6,  6,  6,  6,  6,  6,  7,  7,  7,  7,
     700             :      7,  7,  7,  7,  7,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
     701             :      8,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
     702             :      9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
     703             :     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11,
     704             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     705             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12,
     706             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     707             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     708             :     12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     709             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     710             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     711             :     13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     712             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     713             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     714             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     715             :     14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     716             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     717             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     718             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     719             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     720             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
     721             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     722             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     723             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     724             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     725             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     726             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     727             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     728             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     729             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     730             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     731             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     732             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     733             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     734             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     735             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     736             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     737             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     738             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     739             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     740             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     741             :     16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     742             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     743             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     744             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     745             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     746             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     747             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     748             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     749             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     750             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     751             :     14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     752             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     753             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     754             :     13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     755             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     756             :     12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
     757             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     758             :     11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
     759             :     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,  9,  9,  9,  9,
     760             :      9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
     761             :      8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  7,  7,  7,  7,
     762             :      7,  7,  7,  7,  7,  6,  6,  6,  6,  6,  6,  6,  6,  5,  5,  5,
     763             : };
     764             : 
     765             : static const uint8_t l_u_yry10[1024] = {
     766             :      2,  3,  3,  4,  5,  6,  7,  7,  8,  8,  8,  9,  9, 10, 10, 10,
     767             :     10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13,
     768             :     13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     769             :     14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     770             :     15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     771             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     772             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     773             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     774             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     775             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     776             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     777             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     778             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     779             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     780             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     781             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     782             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     783             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     784             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     785             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     786             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     787             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     788             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     789             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     790             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     791             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     792             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     793             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     794             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     795             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     796             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     797             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     798             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     799             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     800             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     801             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     802             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     803             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     804             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     805             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     806             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     807             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     808             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     809             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     810             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     811             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     812             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     813             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     814             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     815             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     816             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     817             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     818             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     819             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     820             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     821             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     822             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     823             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     824             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     825             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     826             :     16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     827             :     15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
     828             :     13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11,
     829             :     10, 10, 10, 10,  9,  9,  9,  8,  8,  7,  7,  6,  5,  4,  4,  3,
     830             : };
     831             : 
     832             : static const uint8_t l_u_yry10i[1024] = {
     833             :      2,  4,  4,  4,  5,  6,  6,  6,  7,  7,  7,  8,  8,  8,  9,  9,
     834             :      9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11,
     835             :     11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13,
     836             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14,
     837             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
     838             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     839             :     15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     840             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     841             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     842             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     843             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     844             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     845             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     846             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     847             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     848             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     849             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     850             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     851             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     852             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     853             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     854             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     855             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     856             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     857             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     858             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     859             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     860             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     861             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     862             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     863             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     864             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     865             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     866             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     867             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     868             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     869             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     870             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     871             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     872             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     873             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     874             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     875             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     876             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     877             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     878             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     879             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     880             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     881             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     882             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     883             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     884             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     885             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     886             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     887             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     888             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     889             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     890             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     891             :     16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     892             :     15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     893             :     14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     894             :     13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
     895             :     11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10,  9,  9,  9,
     896             :      9,  9,  8,  8,  8,  8,  7,  7,  7,  6,  6,  5,  5,  4,  4,  3,
     897             : };
     898             : 
     899             : static const uint8_t l_y_ybri[256] = {
     900             :      3,  3,  4,  4,  5,  5,  6,  6,  6,  7,  7,  7,  7,  7,  8,  8,
     901             :      8,  8,  8,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10,
     902             :     10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
     903             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
     904             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
     905             :     14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
     906             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     907             :     15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     908             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     909             :     16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     910             :     15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     911             :     14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     912             :     13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     913             :     12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
     914             :     10, 10, 10, 10, 10, 10, 10,  9,  9,  9,  9,  9,  9,  9,  8,  8,
     915             :      8,  8,  8,  7,  7,  7,  7,  7,  6,  6,  6,  5,  5,  5,  4,  3,
     916             : };
     917             : 
     918             : static const uint8_t l_u_ybri[256] = {
     919             :      1,  3,  5,  6,  8,  8,  9, 10, 10, 11, 11, 12, 12, 13, 13, 13,
     920             :     14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16,
     921             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     922             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     923             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     924             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     925             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     926             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     927             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     928             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     929             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     930             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     931             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     932             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     933             :     16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14,
     934             :     14, 13, 13, 13, 12, 12, 11, 11, 10, 10,  9,  8,  8,  6,  5,  2,
     935             : };
     936             : 
     937             : static const uint8_t l_y_byryi[256] = {
     938             :      3,  3,  4,  4,  5,  5,  6,  6,  7,  7,  7,  7,  7,  7,  8,  8,
     939             :      8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10,
     940             :     10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
     941             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13,
     942             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
     943             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15,
     944             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     945             :     15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     946             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     947             :     16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     948             :     15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     949             :     14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     950             :     13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     951             :     12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10,
     952             :     10, 10, 10, 10, 10, 10, 10,  9,  9,  9,  9,  9,  9,  9,  8,  8,
     953             :      8,  8,  8,  7,  7,  7,  7,  7,  7,  6,  6,  6,  5,  4,  4,  3,
     954             : };
     955             : 
     956             : static const uint8_t l_u_byryi[256] = {
     957             :      1,  3,  4,  6,  6,  7,  8,  8,  9,  9, 10, 10, 10, 11, 11, 11,
     958             :     12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15,
     959             :     15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     960             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     961             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     962             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     963             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     964             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     965             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     966             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     967             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     968             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     969             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     970             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15,
     971             :     15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13, 13, 12, 12, 12,
     972             :     12, 11, 11, 11, 10, 10, 10,  9,  9,  8,  8,  7,  7,  5,  4,  3,
     973             : };
     974             : 
     975             : static const uint8_t l_r_rgbxi[1024] = {
     976             :      3,  4,  4,  4,  5,  5,  6,  6,  6,  7,  7,  7,  7,  8,  8,  8,
     977             :      8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
     978             :      9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
     979             :     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
     980             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     981             :     11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     982             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
     983             :     12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
     984             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14,
     985             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
     986             :     14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     987             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     988             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     989             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     990             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
     991             :     15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     992             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     993             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     994             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     995             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     996             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     997             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     998             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
     999             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1000             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1001             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1002             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1003             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1004             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1005             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1006             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1007             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1008             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1009             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1010             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1011             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1012             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1013             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1014             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1015             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1016             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1017             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1018             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1019             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1020             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1021             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1022             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1023             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1024             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15,
    1025             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
    1026             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
    1027             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
    1028             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
    1029             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
    1030             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
    1031             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13,
    1032             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
    1033             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
    1034             :     12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11,
    1035             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
    1036             :     11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10,
    1037             :     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,  9,  9,
    1038             :      9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  8,  8,  8,
    1039             :      8,  8,  8,  8,  7,  7,  7,  7,  6,  6,  6,  5,  5,  4,  4,  4,
    1040             : };
    1041             : 
    1042             : static const uint8_t l_g_rgbxi[1024] = {
    1043             :      2,  3,  4,  4,  6,  6,  7,  7,  7,  7,  7,  7,  8,  8,  8,  8,
    1044             :      9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11,
    1045             :     11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
    1046             :     13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14,
    1047             :     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
    1048             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
    1049             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
    1050             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1051             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1052             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1053             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1054             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1055             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1056             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1057             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1058             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1059             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1060             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1061             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1062             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1063             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1064             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1065             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1066             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1067             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1068             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1069             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1070             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1071             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1072             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1073             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1074             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1075             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1076             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1077             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1078             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1079             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1080             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1081             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1082             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1083             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1084             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1085             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1086             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1087             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1088             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1089             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1090             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1091             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1092             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1093             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1094             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1095             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1096             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1097             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1098             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1099             :     16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    1100             :     16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
    1101             :     15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
    1102             :     15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
    1103             :     14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
    1104             :     13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11,
    1105             :     11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10,  9,  9,  9,
    1106             :      9,  8,  8,  8,  8,  7,  7,  7,  7,  7,  7,  6,  6,  4,  4,  3,
    1107             : };
    1108             : 
    1109           0 : static void decode_ca4i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    1110             : {
    1111           0 :     SheerVideoContext *s = avctx->priv_data;
    1112             :     uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
    1113             :     int x, y;
    1114             : 
    1115           0 :     dst_a = (uint16_t *)p->data[3];
    1116           0 :     dst_y = (uint16_t *)p->data[0];
    1117           0 :     dst_u = (uint16_t *)p->data[1];
    1118           0 :     dst_v = (uint16_t *)p->data[2];
    1119             : 
    1120           0 :     for (y = 0; y < avctx->height; y++) {
    1121           0 :         if (get_bits1(gb)) {
    1122           0 :             for (x = 0; x < avctx->width; x++) {
    1123           0 :                 dst_a[x] = get_bits(gb, 10);
    1124           0 :                 dst_y[x] = get_bits(gb, 10);
    1125           0 :                 dst_u[x] = get_bits(gb, 10);
    1126           0 :                 dst_v[x] = get_bits(gb, 10);
    1127             :             }
    1128             :         } else {
    1129           0 :             int pred[4] = { 502, 512, 512, 502 };
    1130             : 
    1131           0 :             for (x = 0; x < avctx->width; x++) {
    1132             :                 int y, u, v, a;
    1133             : 
    1134           0 :                 a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1135           0 :                 y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1136           0 :                 u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1137           0 :                 v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1138             : 
    1139           0 :                 dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
    1140           0 :                 dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
    1141           0 :                 dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
    1142           0 :                 dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
    1143             :             }
    1144             :         }
    1145             : 
    1146           0 :         dst_y += p->linesize[0] / 2;
    1147           0 :         dst_u += p->linesize[1] / 2;
    1148           0 :         dst_v += p->linesize[2] / 2;
    1149           0 :         dst_a += p->linesize[3] / 2;
    1150             :     }
    1151           0 : }
    1152             : 
    1153           0 : static void decode_ca4p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    1154             : {
    1155           0 :     SheerVideoContext *s = avctx->priv_data;
    1156             :     uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
    1157             :     int x, y;
    1158             : 
    1159           0 :     dst_a = (uint16_t *)p->data[3];
    1160           0 :     dst_y = (uint16_t *)p->data[0];
    1161           0 :     dst_u = (uint16_t *)p->data[1];
    1162           0 :     dst_v = (uint16_t *)p->data[2];
    1163             : 
    1164           0 :     if (get_bits1(gb)) {
    1165           0 :         for (x = 0; x < avctx->width; x++) {
    1166           0 :             dst_a[x] = get_bits(gb, 10);
    1167           0 :             dst_y[x] = get_bits(gb, 10);
    1168           0 :             dst_u[x] = get_bits(gb, 10);
    1169           0 :             dst_v[x] = get_bits(gb, 10);
    1170             :         }
    1171             :     } else {
    1172           0 :         int pred[4] = { 502, 512, 512, 502 };
    1173             : 
    1174           0 :         for (x = 0; x < avctx->width; x++) {
    1175             :             int y, u, v, a;
    1176             : 
    1177           0 :             a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1178           0 :             y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1179           0 :             u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1180           0 :             v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1181             : 
    1182           0 :             dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
    1183           0 :             dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
    1184           0 :             dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
    1185           0 :             dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
    1186             :         }
    1187             :     }
    1188             : 
    1189           0 :     dst_y += p->linesize[0] / 2;
    1190           0 :     dst_u += p->linesize[1] / 2;
    1191           0 :     dst_v += p->linesize[2] / 2;
    1192           0 :     dst_a += p->linesize[3] / 2;
    1193             : 
    1194           0 :     for (y = 1; y < avctx->height; y++) {
    1195           0 :         if (get_bits1(gb)) {
    1196           0 :             for (x = 0; x < avctx->width; x++) {
    1197           0 :                 dst_a[x] = get_bits(gb, 10);
    1198           0 :                 dst_y[x] = get_bits(gb, 10);
    1199           0 :                 dst_u[x] = get_bits(gb, 10);
    1200           0 :                 dst_v[x] = get_bits(gb, 10);
    1201             :             }
    1202             :         } else {
    1203             :             int pred_TL[4], pred_L[4], pred_T[4];
    1204             :             int y, u, v, a;
    1205             : 
    1206           0 :             pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
    1207           0 :             pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
    1208           0 :             pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
    1209           0 :             pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
    1210             : 
    1211           0 :             for (x = 0; x < avctx->width; x++) {
    1212           0 :                 pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
    1213           0 :                 pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
    1214           0 :                 pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
    1215           0 :                 pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
    1216             : 
    1217           0 :                 a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1218           0 :                 y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1219           0 :                 u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1220           0 :                 v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1221             : 
    1222           0 :                 dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
    1223           0 :                 dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
    1224           0 :                 dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
    1225           0 :                 dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
    1226             : 
    1227           0 :                 pred_TL[0] = pred_T[0];
    1228           0 :                 pred_TL[1] = pred_T[1];
    1229           0 :                 pred_TL[2] = pred_T[2];
    1230           0 :                 pred_TL[3] = pred_T[3];
    1231             :             }
    1232             :         }
    1233             : 
    1234           0 :         dst_y += p->linesize[0] / 2;
    1235           0 :         dst_u += p->linesize[1] / 2;
    1236           0 :         dst_v += p->linesize[2] / 2;
    1237           0 :         dst_a += p->linesize[3] / 2;
    1238             :     }
    1239           0 : }
    1240             : 
    1241           0 : static void decode_ybr10i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    1242             : {
    1243           0 :     SheerVideoContext *s = avctx->priv_data;
    1244             :     uint16_t *dst_y, *dst_u, *dst_v;
    1245             :     int x, y;
    1246             : 
    1247           0 :     dst_y = (uint16_t *)p->data[0];
    1248           0 :     dst_u = (uint16_t *)p->data[1];
    1249           0 :     dst_v = (uint16_t *)p->data[2];
    1250             : 
    1251           0 :     for (y = 0; y < avctx->height; y++) {
    1252           0 :         if (get_bits1(gb)) {
    1253           0 :             for (x = 0; x < avctx->width; x++) {
    1254           0 :                 dst_y[x] = get_bits(gb, 10);
    1255           0 :                 dst_u[x] = get_bits(gb, 10);
    1256           0 :                 dst_v[x] = get_bits(gb, 10);
    1257             :             }
    1258             :         } else {
    1259           0 :             int pred[4] = { 502, 512, 512, 512 };
    1260             : 
    1261           0 :             for (x = 0; x < avctx->width; x++) {
    1262             :                 int y, u, v;
    1263             : 
    1264           0 :                 y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1265           0 :                 u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1266           0 :                 v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1267             : 
    1268           0 :                 dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
    1269           0 :                 dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
    1270           0 :                 dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
    1271             :             }
    1272             :         }
    1273             : 
    1274           0 :         dst_y += p->linesize[0] / 2;
    1275           0 :         dst_u += p->linesize[1] / 2;
    1276           0 :         dst_v += p->linesize[2] / 2;
    1277             :     }
    1278           0 : }
    1279             : 
    1280           0 : static void decode_ybr10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    1281             : {
    1282           0 :     SheerVideoContext *s = avctx->priv_data;
    1283             :     uint16_t *dst_y, *dst_u, *dst_v;
    1284             :     int x, y;
    1285             : 
    1286           0 :     dst_y = (uint16_t *)p->data[0];
    1287           0 :     dst_u = (uint16_t *)p->data[1];
    1288           0 :     dst_v = (uint16_t *)p->data[2];
    1289             : 
    1290           0 :     if (get_bits1(gb)) {
    1291           0 :         for (x = 0; x < avctx->width; x++) {
    1292           0 :             dst_y[x] = get_bits(gb, 10);
    1293           0 :             dst_u[x] = get_bits(gb, 10);
    1294           0 :             dst_v[x] = get_bits(gb, 10);
    1295             :         }
    1296             :     } else {
    1297           0 :         int pred[4] = { 502, 512, 512, 512 };
    1298             : 
    1299           0 :         for (x = 0; x < avctx->width; x++) {
    1300             :             int y, u, v;
    1301             : 
    1302           0 :             y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1303           0 :             u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1304           0 :             v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1305             : 
    1306           0 :             dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
    1307           0 :             dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
    1308           0 :             dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
    1309             :         }
    1310             :     }
    1311             : 
    1312           0 :     dst_y += p->linesize[0] / 2;
    1313           0 :     dst_u += p->linesize[1] / 2;
    1314           0 :     dst_v += p->linesize[2] / 2;
    1315             : 
    1316           0 :     for (y = 1; y < avctx->height; y++) {
    1317           0 :         if (get_bits1(gb)) {
    1318           0 :             for (x = 0; x < avctx->width; x++) {
    1319           0 :                 dst_y[x] = get_bits(gb, 10);
    1320           0 :                 dst_u[x] = get_bits(gb, 10);
    1321           0 :                 dst_v[x] = get_bits(gb, 10);
    1322             :             }
    1323             :         } else {
    1324             :             int pred_TL[4], pred_L[4], pred_T[4];
    1325             :             int y, u, v;
    1326             : 
    1327           0 :             pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
    1328           0 :             pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
    1329           0 :             pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
    1330             : 
    1331           0 :             for (x = 0; x < avctx->width; x++) {
    1332           0 :                 pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
    1333           0 :                 pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
    1334           0 :                 pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
    1335             : 
    1336           0 :                 y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1337           0 :                 u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1338           0 :                 v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1339             : 
    1340           0 :                 dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
    1341           0 :                 dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
    1342           0 :                 dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
    1343             : 
    1344           0 :                 pred_TL[0] = pred_T[0];
    1345           0 :                 pred_TL[1] = pred_T[1];
    1346           0 :                 pred_TL[2] = pred_T[2];
    1347             :             }
    1348             :         }
    1349             : 
    1350           0 :         dst_y += p->linesize[0] / 2;
    1351           0 :         dst_u += p->linesize[1] / 2;
    1352           0 :         dst_v += p->linesize[2] / 2;
    1353             :     }
    1354           0 : }
    1355             : 
    1356           0 : static void decode_yry10i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    1357             : {
    1358           0 :     SheerVideoContext *s = avctx->priv_data;
    1359             :     uint16_t *dst_y, *dst_u, *dst_v;
    1360             :     int x, y;
    1361             : 
    1362           0 :     dst_y = (uint16_t *)p->data[0];
    1363           0 :     dst_u = (uint16_t *)p->data[1];
    1364           0 :     dst_v = (uint16_t *)p->data[2];
    1365             : 
    1366           0 :     for (y = 0; y < avctx->height; y++) {
    1367           0 :         if (get_bits1(gb)) {
    1368           0 :             for (x = 0; x < avctx->width; x += 2) {
    1369           0 :                 dst_y[x    ] = get_bits(gb, 10);
    1370           0 :                 dst_u[x / 2] = get_bits(gb, 10);
    1371           0 :                 dst_y[x + 1] = get_bits(gb, 10);
    1372           0 :                 dst_v[x / 2] = get_bits(gb, 10);
    1373             :             }
    1374             :         } else {
    1375           0 :             int pred[4] = { 502, 512, 512, 0 };
    1376             : 
    1377           0 :             for (x = 0; x < avctx->width; x += 2) {
    1378             :                 int y1, y2, u, v;
    1379             : 
    1380           0 :                 y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1381           0 :                 u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1382           0 :                 y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1383           0 :                 v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1384             : 
    1385           0 :                 dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0x3ff;
    1386           0 :                 dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0x3ff;
    1387           0 :                 dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
    1388           0 :                 dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0x3ff;
    1389             :             }
    1390             :         }
    1391             : 
    1392           0 :         dst_y += p->linesize[0] / 2;
    1393           0 :         dst_u += p->linesize[1] / 2;
    1394           0 :         dst_v += p->linesize[2] / 2;
    1395             :     }
    1396           0 : }
    1397             : 
    1398           0 : static void decode_yry10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    1399             : {
    1400           0 :     SheerVideoContext *s = avctx->priv_data;
    1401             :     uint16_t *dst_y, *dst_u, *dst_v;
    1402             :     int x, y;
    1403             : 
    1404           0 :     dst_y = (uint16_t *)p->data[0];
    1405           0 :     dst_u = (uint16_t *)p->data[1];
    1406           0 :     dst_v = (uint16_t *)p->data[2];
    1407             : 
    1408           0 :     if (get_bits1(gb)) {
    1409           0 :         for (x = 0; x < avctx->width; x += 2) {
    1410           0 :             dst_y[x    ] = get_bits(gb, 10);
    1411           0 :             dst_u[x / 2] = get_bits(gb, 10);
    1412           0 :             dst_y[x + 1] = get_bits(gb, 10);
    1413           0 :             dst_v[x / 2] = get_bits(gb, 10);
    1414             :         }
    1415             :     } else {
    1416           0 :         int pred[4] = { 502, 512, 512, 0 };
    1417             : 
    1418           0 :         for (x = 0; x < avctx->width; x += 2) {
    1419             :             int y1, y2, u, v;
    1420             : 
    1421           0 :             y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1422           0 :             u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1423           0 :             y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1424           0 :             v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1425             : 
    1426           0 :             dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0x3ff;
    1427           0 :             dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0x3ff;
    1428           0 :             dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
    1429           0 :             dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0x3ff;
    1430             :         }
    1431             :     }
    1432             : 
    1433           0 :     dst_y += p->linesize[0] / 2;
    1434           0 :     dst_u += p->linesize[1] / 2;
    1435           0 :     dst_v += p->linesize[2] / 2;
    1436             : 
    1437           0 :     for (y = 1; y < avctx->height; y++) {
    1438           0 :         if (get_bits1(gb)) {
    1439           0 :             for (x = 0; x < avctx->width; x += 2) {
    1440           0 :                 dst_y[x    ] = get_bits(gb, 10);
    1441           0 :                 dst_u[x / 2] = get_bits(gb, 10);
    1442           0 :                 dst_y[x + 1] = get_bits(gb, 10);
    1443           0 :                 dst_v[x / 2] = get_bits(gb, 10);
    1444             :             }
    1445             :         } else {
    1446             :             int pred_TL[6], pred_L[6], pred_T[6];
    1447             :             int y1, y2, u, v;
    1448             : 
    1449           0 :             pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
    1450           0 :             pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
    1451           0 :             pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
    1452             : 
    1453           0 :             for (x = 0; x < avctx->width; x += 2) {
    1454           0 :                 pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
    1455           0 :                 pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
    1456           0 :                 pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
    1457           0 :                 pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
    1458             : 
    1459           0 :                 y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1460           0 :                 u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1461           0 :                 y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1462           0 :                 v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1463             : 
    1464           0 :                 dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
    1465           0 :                 dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
    1466           0 :                 dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
    1467           0 :                 dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
    1468             : 
    1469           0 :                 pred_TL[0] = pred_T[3];
    1470           0 :                 pred_TL[1] = pred_T[1];
    1471           0 :                 pred_TL[2] = pred_T[2];
    1472             :             }
    1473             :         }
    1474             : 
    1475           0 :         dst_y += p->linesize[0] / 2;
    1476           0 :         dst_u += p->linesize[1] / 2;
    1477           0 :         dst_v += p->linesize[2] / 2;
    1478             :     }
    1479           0 : }
    1480             : 
    1481           0 : static void decode_ca2i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    1482             : {
    1483           0 :     SheerVideoContext *s = avctx->priv_data;
    1484             :     uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
    1485             :     int x, y;
    1486             : 
    1487           0 :     dst_y = (uint16_t *)p->data[0];
    1488           0 :     dst_u = (uint16_t *)p->data[1];
    1489           0 :     dst_v = (uint16_t *)p->data[2];
    1490           0 :     dst_a = (uint16_t *)p->data[3];
    1491             : 
    1492           0 :     for (y = 0; y < avctx->height; y++) {
    1493           0 :         if (get_bits1(gb)) {
    1494           0 :             for (x = 0; x < avctx->width; x += 2) {
    1495           0 :                 dst_a[x    ] = get_bits(gb, 10);
    1496           0 :                 dst_y[x    ] = get_bits(gb, 10);
    1497           0 :                 dst_u[x / 2] = get_bits(gb, 10);
    1498           0 :                 dst_a[x + 1] = get_bits(gb, 10);
    1499           0 :                 dst_y[x + 1] = get_bits(gb, 10);
    1500           0 :                 dst_v[x / 2] = get_bits(gb, 10);
    1501             :             }
    1502             :         } else {
    1503           0 :             int pred[4] = { 502, 512, 512, 502 };
    1504             : 
    1505           0 :             for (x = 0; x < avctx->width; x += 2) {
    1506             :                 int y1, y2, u, v, a1, a2;
    1507             : 
    1508           0 :                 a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1509           0 :                 y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1510           0 :                 u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1511           0 :                 a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1512           0 :                 y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1513           0 :                 v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1514             : 
    1515           0 :                 dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0x3ff;
    1516           0 :                 dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0x3ff;
    1517           0 :                 dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
    1518           0 :                 dst_a[x    ] = pred[3] = (a1 + pred[3]) & 0x3ff;
    1519           0 :                 dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0x3ff;
    1520           0 :                 dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0x3ff;
    1521             :             }
    1522             :         }
    1523             : 
    1524           0 :         dst_y += p->linesize[0] / 2;
    1525           0 :         dst_u += p->linesize[1] / 2;
    1526           0 :         dst_v += p->linesize[2] / 2;
    1527           0 :         dst_a += p->linesize[3] / 2;
    1528             :     }
    1529           0 : }
    1530             : 
    1531           0 : static void decode_ca2p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    1532             : {
    1533           0 :     SheerVideoContext *s = avctx->priv_data;
    1534             :     uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
    1535             :     int x, y;
    1536             : 
    1537           0 :     dst_y = (uint16_t *)p->data[0];
    1538           0 :     dst_u = (uint16_t *)p->data[1];
    1539           0 :     dst_v = (uint16_t *)p->data[2];
    1540           0 :     dst_a = (uint16_t *)p->data[3];
    1541             : 
    1542           0 :     if (get_bits1(gb)) {
    1543           0 :         for (x = 0; x < avctx->width; x += 2) {
    1544           0 :             dst_a[x    ] = get_bits(gb, 10);
    1545           0 :             dst_y[x    ] = get_bits(gb, 10);
    1546           0 :             dst_u[x / 2] = get_bits(gb, 10);
    1547           0 :             dst_a[x + 1] = get_bits(gb, 10);
    1548           0 :             dst_y[x + 1] = get_bits(gb, 10);
    1549           0 :             dst_v[x / 2] = get_bits(gb, 10);
    1550             :         }
    1551             :     } else {
    1552           0 :         int pred[4] = { 502, 512, 512, 502 };
    1553             : 
    1554           0 :         for (x = 0; x < avctx->width; x += 2) {
    1555             :             int y1, y2, u, v, a1, a2;
    1556             : 
    1557           0 :             a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1558           0 :             y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1559           0 :             u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1560           0 :             a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1561           0 :             y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1562           0 :             v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1563             : 
    1564           0 :             dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0x3ff;
    1565           0 :             dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0x3ff;
    1566           0 :             dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
    1567           0 :             dst_a[x    ] = pred[3] = (a1 + pred[3]) & 0x3ff;
    1568           0 :             dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0x3ff;
    1569           0 :             dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0x3ff;
    1570             :         }
    1571             :     }
    1572             : 
    1573           0 :     dst_y += p->linesize[0] / 2;
    1574           0 :     dst_u += p->linesize[1] / 2;
    1575           0 :     dst_v += p->linesize[2] / 2;
    1576           0 :     dst_a += p->linesize[3] / 2;
    1577             : 
    1578           0 :     for (y = 1; y < avctx->height; y++) {
    1579           0 :         if (get_bits1(gb)) {
    1580           0 :             for (x = 0; x < avctx->width; x += 2) {
    1581           0 :                 dst_a[x    ] = get_bits(gb, 10);
    1582           0 :                 dst_y[x    ] = get_bits(gb, 10);
    1583           0 :                 dst_u[x / 2] = get_bits(gb, 10);
    1584           0 :                 dst_a[x + 1] = get_bits(gb, 10);
    1585           0 :                 dst_y[x + 1] = get_bits(gb, 10);
    1586           0 :                 dst_v[x / 2] = get_bits(gb, 10);
    1587             :             }
    1588             :         } else {
    1589             :             int pred_TL[6], pred_L[6], pred_T[6];
    1590             :             int y1, y2, u, v, a1, a2;
    1591             : 
    1592           0 :             pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
    1593           0 :             pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
    1594           0 :             pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
    1595           0 :             pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3] / 2];
    1596             : 
    1597           0 :             for (x = 0; x < avctx->width; x += 2) {
    1598           0 :                 pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
    1599           0 :                 pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
    1600           0 :                 pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
    1601           0 :                 pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
    1602           0 :                 pred_T[4] = dst_a[-p->linesize[3] / 2 + x];
    1603           0 :                 pred_T[5] = dst_a[-p->linesize[3] / 2 + x + 1];
    1604             : 
    1605           0 :                 a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1606           0 :                 y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1607           0 :                 u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1608           0 :                 a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1609           0 :                 y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1610           0 :                 v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1611             : 
    1612           0 :                 dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
    1613           0 :                 dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
    1614           0 :                 dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
    1615           0 :                 dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
    1616           0 :                 dst_a[x    ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0x3ff;
    1617           0 :                 dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0x3ff;
    1618             : 
    1619           0 :                 pred_TL[0] = pred_T[3];
    1620           0 :                 pred_TL[1] = pred_T[1];
    1621           0 :                 pred_TL[2] = pred_T[2];
    1622           0 :                 pred_TL[4] = pred_T[5];
    1623             :             }
    1624             :         }
    1625             : 
    1626           0 :         dst_y += p->linesize[0] / 2;
    1627           0 :         dst_u += p->linesize[1] / 2;
    1628           0 :         dst_v += p->linesize[2] / 2;
    1629           0 :         dst_a += p->linesize[3] / 2;
    1630             :     }
    1631           0 : }
    1632             : 
    1633           0 : static void decode_c82i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    1634             : {
    1635           0 :     SheerVideoContext *s = avctx->priv_data;
    1636             :     uint8_t *dst_y, *dst_u, *dst_v, *dst_a;
    1637             :     int x, y;
    1638             : 
    1639           0 :     dst_y = p->data[0];
    1640           0 :     dst_u = p->data[1];
    1641           0 :     dst_v = p->data[2];
    1642           0 :     dst_a = p->data[3];
    1643             : 
    1644           0 :     for (y = 0; y < avctx->height; y += 1) {
    1645           0 :         if (get_bits1(gb)) {
    1646           0 :             for (x = 0; x < avctx->width; x += 2) {
    1647           0 :                 dst_a[x    ] = get_bits(gb, 8);
    1648           0 :                 dst_y[x    ] = get_bits(gb, 8);
    1649           0 :                 dst_u[x / 2] = get_bits(gb, 8);
    1650           0 :                 dst_a[x + 1] = get_bits(gb, 8);
    1651           0 :                 dst_y[x + 1] = get_bits(gb, 8);
    1652           0 :                 dst_v[x / 2] = get_bits(gb, 8);
    1653             :             }
    1654             :         } else {
    1655           0 :             int pred[4] = { 125, -128, -128, 125 };
    1656             : 
    1657           0 :             for (x = 0; x < avctx->width; x += 2) {
    1658             :                 int y1, y2, u, v, a1, a2;
    1659             : 
    1660           0 :                 a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1661           0 :                 y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1662           0 :                 u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1663           0 :                 a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1664           0 :                 y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1665           0 :                 v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1666             : 
    1667           0 :                 dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0xff;
    1668           0 :                 dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
    1669           0 :                 dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0xff;
    1670           0 :                 dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0xff;
    1671           0 :                 dst_a[x    ] = pred[3] = (a1 + pred[3]) & 0xff;
    1672           0 :                 dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0xff;
    1673             :             }
    1674             :         }
    1675             : 
    1676           0 :         dst_y += p->linesize[0];
    1677           0 :         dst_u += p->linesize[1];
    1678           0 :         dst_v += p->linesize[2];
    1679           0 :         dst_a += p->linesize[3];
    1680             :     }
    1681           0 : }
    1682             : 
    1683           0 : static void decode_c82p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    1684             : {
    1685           0 :     SheerVideoContext *s = avctx->priv_data;
    1686             :     uint8_t *dst_y, *dst_u, *dst_v, *dst_a;
    1687             :     int x, y;
    1688             : 
    1689           0 :     dst_y = p->data[0];
    1690           0 :     dst_u = p->data[1];
    1691           0 :     dst_v = p->data[2];
    1692           0 :     dst_a = p->data[3];
    1693             : 
    1694           0 :     if (get_bits1(gb)) {
    1695           0 :         for (x = 0; x < avctx->width; x += 2) {
    1696           0 :             dst_a[x    ] = get_bits(gb, 8);
    1697           0 :             dst_y[x    ] = get_bits(gb, 8);
    1698           0 :             dst_u[x / 2] = get_bits(gb, 8);
    1699           0 :             dst_a[x + 1] = get_bits(gb, 8);
    1700           0 :             dst_y[x + 1] = get_bits(gb, 8);
    1701           0 :             dst_v[x / 2] = get_bits(gb, 8);
    1702             :         }
    1703             :     } else {
    1704           0 :         int pred[4] = { 125, -128, -128, 125 };
    1705             : 
    1706           0 :         for (x = 0; x < avctx->width; x += 2) {
    1707             :             int y1, y2, u, v, a1, a2;
    1708             : 
    1709           0 :             a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1710           0 :             y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1711           0 :             u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1712           0 :             a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1713           0 :             y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1714           0 :             v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1715             : 
    1716           0 :             dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0xff;
    1717           0 :             dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0xff;
    1718           0 :             dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
    1719           0 :             dst_a[x    ] = pred[3] = (a1 + pred[3]) & 0xff;
    1720           0 :             dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0xff;
    1721           0 :             dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0xff;
    1722             :         }
    1723             :     }
    1724             : 
    1725           0 :     dst_y += p->linesize[0];
    1726           0 :     dst_u += p->linesize[1];
    1727           0 :     dst_v += p->linesize[2];
    1728           0 :     dst_a += p->linesize[3];
    1729             : 
    1730           0 :     for (y = 1; y < avctx->height; y++) {
    1731           0 :         if (get_bits1(gb)) {
    1732           0 :             for (x = 0; x < avctx->width; x += 2) {
    1733           0 :                 dst_a[x    ] = get_bits(gb, 8);
    1734           0 :                 dst_y[x    ] = get_bits(gb, 8);
    1735           0 :                 dst_u[x / 2] = get_bits(gb, 8);
    1736           0 :                 dst_a[x + 1] = get_bits(gb, 8);
    1737           0 :                 dst_y[x + 1] = get_bits(gb, 8);
    1738           0 :                 dst_v[x / 2] = get_bits(gb, 8);
    1739             :             }
    1740             :         } else {
    1741             :             int pred_TL[6], pred_L[6], pred_T[6];
    1742             :             int y1, y2, u, v, a1, a2;
    1743             : 
    1744           0 :             pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
    1745           0 :             pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
    1746           0 :             pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
    1747           0 :             pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3]];
    1748             : 
    1749           0 :             for (x = 0; x < avctx->width; x += 2) {
    1750           0 :                 pred_T[0] = dst_y[-p->linesize[0] + x];
    1751           0 :                 pred_T[3] = dst_y[-p->linesize[0] + x + 1];
    1752           0 :                 pred_T[1] = dst_u[-p->linesize[1] + x / 2];
    1753           0 :                 pred_T[2] = dst_v[-p->linesize[2] + x / 2];
    1754           0 :                 pred_T[4] = dst_a[-p->linesize[3] + x];
    1755           0 :                 pred_T[5] = dst_a[-p->linesize[3] + x + 1];
    1756             : 
    1757           0 :                 a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1758           0 :                 y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1759           0 :                 u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1760           0 :                 a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1761           0 :                 y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1762           0 :                 v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1763             : 
    1764           0 :                 dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
    1765           0 :                 dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
    1766           0 :                 dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
    1767           0 :                 dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
    1768           0 :                 dst_a[x    ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0xff;
    1769           0 :                 dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0xff;
    1770             : 
    1771           0 :                 pred_TL[0] = pred_T[3];
    1772           0 :                 pred_TL[1] = pred_T[1];
    1773           0 :                 pred_TL[2] = pred_T[2];
    1774           0 :                 pred_TL[4] = pred_T[5];
    1775             :             }
    1776             :         }
    1777             : 
    1778           0 :         dst_y += p->linesize[0];
    1779           0 :         dst_u += p->linesize[1];
    1780           0 :         dst_v += p->linesize[2];
    1781           0 :         dst_a += p->linesize[3];
    1782             :     }
    1783           0 : }
    1784             : 
    1785           0 : static void decode_ybyr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    1786             : {
    1787           0 :     SheerVideoContext *s = avctx->priv_data;
    1788             :     uint8_t *dst_y, *dst_u, *dst_v;
    1789             :     int x, y;
    1790             : 
    1791           0 :     dst_y = p->data[0];
    1792           0 :     dst_u = p->data[1];
    1793           0 :     dst_v = p->data[2];
    1794             : 
    1795           0 :     if (get_bits1(gb)) {
    1796           0 :         for (x = 0; x < avctx->width; x += 2) {
    1797           0 :             dst_y[x    ] = get_bits(gb, 8);
    1798           0 :             dst_u[x / 2] = get_bits(gb, 8) + 128;
    1799           0 :             dst_y[x + 1] = get_bits(gb, 8);
    1800           0 :             dst_v[x / 2] = get_bits(gb, 8) + 128;
    1801             :         }
    1802             :     } else {
    1803           0 :         int pred[4] = { -128, 128, 128, 0 };
    1804             : 
    1805           0 :         for (x = 0; x < avctx->width; x += 2) {
    1806             :             int y1, y2, u, v;
    1807             : 
    1808           0 :             y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1809           0 :             u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1810           0 :             y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1811           0 :             v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1812             : 
    1813           0 :             dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0xff;
    1814           0 :             dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0xff;
    1815           0 :             dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
    1816           0 :             dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0xff;
    1817             :         }
    1818             :     }
    1819             : 
    1820           0 :     dst_y += p->linesize[0];
    1821           0 :     dst_u += p->linesize[1];
    1822           0 :     dst_v += p->linesize[2];
    1823             : 
    1824           0 :     for (y = 1; y < avctx->height; y++) {
    1825           0 :         if (get_bits1(gb)) {
    1826           0 :             for (x = 0; x < avctx->width; x += 2) {
    1827           0 :                 dst_y[x    ] = get_bits(gb, 8);
    1828           0 :                 dst_u[x / 2] = get_bits(gb, 8) + 128;
    1829           0 :                 dst_y[x + 1] = get_bits(gb, 8);
    1830           0 :                 dst_v[x / 2] = get_bits(gb, 8) + 128;
    1831             :             }
    1832             :         } else {
    1833             :             int pred_TL[4], pred_L[4], pred_T[4];
    1834             :             int y1, y2, u, v;
    1835             : 
    1836           0 :             pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
    1837           0 :             pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
    1838           0 :             pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
    1839             : 
    1840           0 :             for (x = 0; x < avctx->width; x += 2) {
    1841           0 :                 pred_T[0] = dst_y[-p->linesize[0] + x];
    1842           0 :                 pred_T[3] = dst_y[-p->linesize[0] + x + 1];
    1843           0 :                 pred_T[1] = dst_u[-p->linesize[1] + x / 2];
    1844           0 :                 pred_T[2] = dst_v[-p->linesize[2] + x / 2];
    1845             : 
    1846           0 :                 y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1847           0 :                 u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1848           0 :                 y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1849           0 :                 v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1850             : 
    1851           0 :                 dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
    1852           0 :                 dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
    1853           0 :                 dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
    1854           0 :                 dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
    1855             : 
    1856           0 :                 pred_TL[0] = pred_T[3];
    1857           0 :                 pred_TL[1] = pred_T[1];
    1858           0 :                 pred_TL[2] = pred_T[2];
    1859             :             }
    1860             :         }
    1861             : 
    1862           0 :         dst_y += p->linesize[0];
    1863           0 :         dst_u += p->linesize[1];
    1864           0 :         dst_v += p->linesize[2];
    1865             :     }
    1866           0 : }
    1867             : 
    1868           0 : static void decode_byryi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    1869             : {
    1870           0 :     SheerVideoContext *s = avctx->priv_data;
    1871             :     uint8_t *dst_y, *dst_u, *dst_v;
    1872             :     int x, y;
    1873             : 
    1874           0 :     dst_y = p->data[0];
    1875           0 :     dst_u = p->data[1];
    1876           0 :     dst_v = p->data[2];
    1877             : 
    1878           0 :     if (get_bits1(gb)) {
    1879           0 :         for (x = 0; x < avctx->width; x += 2) {
    1880           0 :             dst_y[x    ] = get_bits(gb, 8);
    1881           0 :             dst_u[x / 2] = get_bits(gb, 8);
    1882           0 :             dst_y[x + 1] = get_bits(gb, 8);
    1883           0 :             dst_v[x / 2] = get_bits(gb, 8);
    1884             :         }
    1885             :     } else {
    1886           0 :         int pred[4] = { 125, -128, -128, 0 };
    1887             : 
    1888           0 :         for (x = 0; x < avctx->width; x += 2) {
    1889             :             int y1, y2, u, v;
    1890             : 
    1891           0 :             y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1892           0 :             u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1893           0 :             y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1894           0 :             v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1895             : 
    1896           0 :             dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0xff;
    1897           0 :             dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0xff;
    1898           0 :             dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
    1899           0 :             dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0xff;
    1900             :         }
    1901             :     }
    1902             : 
    1903           0 :     dst_y += p->linesize[0];
    1904           0 :     dst_u += p->linesize[1];
    1905           0 :     dst_v += p->linesize[2];
    1906             : 
    1907           0 :     for (y = 1; y < avctx->height; y++) {
    1908           0 :         if (get_bits1(gb)) {
    1909           0 :             for (x = 0; x < avctx->width; x += 2) {
    1910           0 :                 dst_y[x    ] = get_bits(gb, 8);
    1911           0 :                 dst_u[x / 2] = get_bits(gb, 8);
    1912           0 :                 dst_y[x + 1] = get_bits(gb, 8);
    1913           0 :                 dst_v[x / 2] = get_bits(gb, 8);
    1914             :             }
    1915             :         } else {
    1916             :             int pred_L[4];
    1917             :             int y1, y2, u, v;
    1918             : 
    1919           0 :             pred_L[0] = dst_y[-p->linesize[0]];
    1920           0 :             pred_L[1] = dst_u[-p->linesize[1]];
    1921           0 :             pred_L[2] = dst_v[-p->linesize[2]];
    1922             : 
    1923           0 :             for (x = 0; x < avctx->width; x += 2) {
    1924           0 :                 y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1925           0 :                 u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1926           0 :                 y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1927           0 :                 v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1928             : 
    1929           0 :                 dst_y[x    ] = pred_L[0] = (y1 + pred_L[0]) & 0xff;
    1930           0 :                 dst_u[x / 2] = pred_L[1] = (u  + pred_L[1]) & 0xff;
    1931           0 :                 dst_y[x + 1] = pred_L[0] = (y2 + pred_L[0]) & 0xff;
    1932           0 :                 dst_v[x / 2] = pred_L[2] = (v +  pred_L[2]) & 0xff;
    1933             :             }
    1934             :         }
    1935             : 
    1936           0 :         dst_y += p->linesize[0];
    1937           0 :         dst_u += p->linesize[1];
    1938           0 :         dst_v += p->linesize[2];
    1939             :     }
    1940           0 : }
    1941             : 
    1942           0 : static void decode_byry(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    1943             : {
    1944           0 :     SheerVideoContext *s = avctx->priv_data;
    1945             :     uint8_t *dst_y, *dst_u, *dst_v;
    1946             :     int x, y;
    1947             : 
    1948           0 :     dst_y = p->data[0];
    1949           0 :     dst_u = p->data[1];
    1950           0 :     dst_v = p->data[2];
    1951             : 
    1952           0 :     if (get_bits1(gb)) {
    1953           0 :         for (x = 0; x < avctx->width; x += 2) {
    1954           0 :             dst_y[x    ] = get_bits(gb, 8);
    1955           0 :             dst_u[x / 2] = get_bits(gb, 8);
    1956           0 :             dst_y[x + 1] = get_bits(gb, 8);
    1957           0 :             dst_v[x / 2] = get_bits(gb, 8);
    1958             :         }
    1959             :     } else {
    1960           0 :         int pred[4] = { 125, -128, -128, 0 };
    1961             : 
    1962           0 :         for (x = 0; x < avctx->width; x += 2) {
    1963             :             int y1, y2, u, v;
    1964             : 
    1965           0 :             y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1966           0 :             u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1967           0 :             y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    1968           0 :             v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    1969             : 
    1970           0 :             dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0xff;
    1971           0 :             dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0xff;
    1972           0 :             dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
    1973           0 :             dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0xff;
    1974             :         }
    1975             :     }
    1976             : 
    1977           0 :     dst_y += p->linesize[0];
    1978           0 :     dst_u += p->linesize[1];
    1979           0 :     dst_v += p->linesize[2];
    1980             : 
    1981           0 :     for (y = 1; y < avctx->height; y++) {
    1982           0 :         if (get_bits1(gb)) {
    1983           0 :             for (x = 0; x < avctx->width; x += 2) {
    1984           0 :                 dst_y[x    ] = get_bits(gb, 8);
    1985           0 :                 dst_u[x / 2] = get_bits(gb, 8);
    1986           0 :                 dst_y[x + 1] = get_bits(gb, 8);
    1987           0 :                 dst_v[x / 2] = get_bits(gb, 8);
    1988             :             }
    1989             :         } else {
    1990             :             int pred_TL[4], pred_L[4], pred_T[4];
    1991             :             int y1, y2, u, v;
    1992             : 
    1993           0 :             pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
    1994           0 :             pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
    1995           0 :             pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
    1996             : 
    1997           0 :             for (x = 0; x < avctx->width; x += 2) {
    1998           0 :                 pred_T[0] = dst_y[-p->linesize[0] + x];
    1999           0 :                 pred_T[3] = dst_y[-p->linesize[0] + x + 1];
    2000           0 :                 pred_T[1] = dst_u[-p->linesize[1] + x / 2];
    2001           0 :                 pred_T[2] = dst_v[-p->linesize[2] + x / 2];
    2002             : 
    2003           0 :                 y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2004           0 :                 u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2005           0 :                 y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2006           0 :                 v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2007             : 
    2008           0 :                 dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
    2009           0 :                 dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
    2010           0 :                 dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
    2011           0 :                 dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
    2012             : 
    2013           0 :                 pred_TL[0] = pred_T[3];
    2014           0 :                 pred_TL[1] = pred_T[1];
    2015           0 :                 pred_TL[2] = pred_T[2];
    2016             :             }
    2017             :         }
    2018             : 
    2019           0 :         dst_y += p->linesize[0];
    2020           0 :         dst_u += p->linesize[1];
    2021           0 :         dst_v += p->linesize[2];
    2022             :     }
    2023           0 : }
    2024             : 
    2025           0 : static void decode_ybri(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    2026             : {
    2027           0 :     SheerVideoContext *s = avctx->priv_data;
    2028             :     uint8_t *dst_y, *dst_u, *dst_v;
    2029             :     int x, y;
    2030             : 
    2031           0 :     dst_y = p->data[0];
    2032           0 :     dst_u = p->data[1];
    2033           0 :     dst_v = p->data[2];
    2034             : 
    2035           0 :     if (get_bits1(gb)) {
    2036           0 :         for (x = 0; x < avctx->width; x++) {
    2037           0 :             dst_y[x] = get_bits(gb, 8);
    2038           0 :             dst_u[x] = get_bits(gb, 8);
    2039           0 :             dst_v[x] = get_bits(gb, 8);
    2040             :         }
    2041             :     } else {
    2042           0 :         int pred[4] = { s->alt ? 125 : -146, -128, -128, -128 };
    2043             : 
    2044           0 :         for (x = 0; x < avctx->width; x++) {
    2045             :             int y, u, v;
    2046             : 
    2047           0 :             y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2048           0 :             u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2049           0 :             v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2050             : 
    2051           0 :             dst_y[x] = pred[0] = (y + pred[0]) & 0xff;
    2052           0 :             dst_u[x] = pred[1] = (u + pred[1]) & 0xff;
    2053           0 :             dst_v[x] = pred[2] = (v + pred[2]) & 0xff;
    2054             :         }
    2055             :     }
    2056             : 
    2057           0 :     dst_y += p->linesize[0];
    2058           0 :     dst_u += p->linesize[1];
    2059           0 :     dst_v += p->linesize[2];
    2060             : 
    2061           0 :     for (y = 1; y < avctx->height; y++) {
    2062           0 :         if (get_bits1(gb)) {
    2063           0 :             for (x = 0; x < avctx->width; x++) {
    2064           0 :                 dst_y[x] = get_bits(gb, 8);
    2065           0 :                 dst_u[x] = get_bits(gb, 8);
    2066           0 :                 dst_v[x] = get_bits(gb, 8);
    2067             :             }
    2068             :         } else {
    2069             :             int pred_L[4];
    2070             :             int y, u, v;
    2071             : 
    2072           0 :             pred_L[0] = dst_y[-p->linesize[0]];
    2073           0 :             pred_L[1] = dst_u[-p->linesize[1]];
    2074           0 :             pred_L[2] = dst_v[-p->linesize[2]];
    2075             : 
    2076           0 :             for (x = 0; x < avctx->width; x++) {
    2077           0 :                 y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2078           0 :                 u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2079           0 :                 v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2080             : 
    2081           0 :                 dst_y[x] = pred_L[0] = (y + pred_L[0]) & 0xff;
    2082           0 :                 dst_u[x] = pred_L[1] = (u + pred_L[1]) & 0xff;
    2083           0 :                 dst_v[x] = pred_L[2] = (v + pred_L[2]) & 0xff;
    2084             :             }
    2085             :         }
    2086             : 
    2087           0 :         dst_y += p->linesize[0];
    2088           0 :         dst_u += p->linesize[1];
    2089           0 :         dst_v += p->linesize[2];
    2090             :     }
    2091           0 : }
    2092             : 
    2093           0 : static void decode_ybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    2094             : {
    2095           0 :     SheerVideoContext *s = avctx->priv_data;
    2096             :     uint8_t *dst_y, *dst_u, *dst_v;
    2097             :     int x, y;
    2098             : 
    2099           0 :     dst_y = p->data[0];
    2100           0 :     dst_u = p->data[1];
    2101           0 :     dst_v = p->data[2];
    2102             : 
    2103           0 :     if (get_bits1(gb)) {
    2104           0 :         for (x = 0; x < avctx->width; x++) {
    2105           0 :             dst_y[x] = get_bits(gb, 8);
    2106           0 :             dst_u[x] = get_bits(gb, 8);
    2107           0 :             dst_v[x] = get_bits(gb, 8);
    2108             :         }
    2109             :     } else {
    2110           0 :         int pred[4] = { s->alt ? 125 : -146, -128, -128, -128 };
    2111             : 
    2112           0 :         for (x = 0; x < avctx->width; x++) {
    2113             :             int y, u, v;
    2114             : 
    2115           0 :             y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2116           0 :             u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2117           0 :             v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2118             : 
    2119           0 :             dst_y[x] = pred[0] = (y + pred[0]) & 0xff;
    2120           0 :             dst_u[x] = pred[1] = (u + pred[1]) & 0xff;
    2121           0 :             dst_v[x] = pred[2] = (v + pred[2]) & 0xff;
    2122             :         }
    2123             :     }
    2124             : 
    2125           0 :     dst_y += p->linesize[0];
    2126           0 :     dst_u += p->linesize[1];
    2127           0 :     dst_v += p->linesize[2];
    2128             : 
    2129           0 :     for (y = 1; y < avctx->height; y++) {
    2130           0 :         if (get_bits1(gb)) {
    2131           0 :             for (x = 0; x < avctx->width; x++) {
    2132           0 :                 dst_y[x] = get_bits(gb, 8);
    2133           0 :                 dst_u[x] = get_bits(gb, 8);
    2134           0 :                 dst_v[x] = get_bits(gb, 8);
    2135             :             }
    2136             :         } else {
    2137             :             int pred_TL[4], pred_L[4], pred_T[4];
    2138             :             int y, u, v;
    2139             : 
    2140           0 :             pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
    2141           0 :             pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
    2142           0 :             pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
    2143             : 
    2144           0 :             for (x = 0; x < avctx->width; x++) {
    2145           0 :                 pred_T[0] = dst_y[-p->linesize[0] + x];
    2146           0 :                 pred_T[1] = dst_u[-p->linesize[1] + x];
    2147           0 :                 pred_T[2] = dst_v[-p->linesize[2] + x];
    2148             : 
    2149           0 :                 y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2150           0 :                 u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2151           0 :                 v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2152             : 
    2153           0 :                 dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
    2154           0 :                 dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
    2155           0 :                 dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
    2156             : 
    2157           0 :                 pred_TL[0] = pred_T[0];
    2158           0 :                 pred_TL[1] = pred_T[1];
    2159           0 :                 pred_TL[2] = pred_T[2];
    2160             :             }
    2161             :         }
    2162             : 
    2163           0 :         dst_y += p->linesize[0];
    2164           0 :         dst_u += p->linesize[1];
    2165           0 :         dst_v += p->linesize[2];
    2166             :     }
    2167           0 : }
    2168             : 
    2169           0 : static void decode_aybri(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    2170             : {
    2171           0 :     SheerVideoContext *s = avctx->priv_data;
    2172             :     uint8_t *dst_a, *dst_y, *dst_u, *dst_v;
    2173             :     int x, y;
    2174             : 
    2175           0 :     dst_a = p->data[3];
    2176           0 :     dst_y = p->data[0];
    2177           0 :     dst_u = p->data[1];
    2178           0 :     dst_v = p->data[2];
    2179             : 
    2180           0 :     if (get_bits1(gb)) {
    2181           0 :         for (x = 0; x < avctx->width; x++) {
    2182           0 :             dst_a[x] = get_bits(gb, 8);
    2183           0 :             dst_y[x] = get_bits(gb, 8);
    2184           0 :             dst_u[x] = get_bits(gb, 8);
    2185           0 :             dst_v[x] = get_bits(gb, 8);
    2186             :         }
    2187             :     } else {
    2188           0 :         int pred[4] = { 125, s->alt ? 125 : -146, -128, -128 };
    2189             : 
    2190           0 :         for (x = 0; x < avctx->width; x++) {
    2191             :             int a, y, u, v;
    2192             : 
    2193           0 :             a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2194           0 :             y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2195           0 :             u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2196           0 :             v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2197             : 
    2198           0 :             dst_a[x] = pred[0] = (a + pred[0]) & 0xff;
    2199           0 :             dst_y[x] = pred[1] = (y + pred[1]) & 0xff;
    2200           0 :             dst_u[x] = pred[2] = (u + pred[2]) & 0xff;
    2201           0 :             dst_v[x] = pred[3] = (v + pred[3]) & 0xff;
    2202             :         }
    2203             :     }
    2204             : 
    2205           0 :     dst_a += p->linesize[3];
    2206           0 :     dst_y += p->linesize[0];
    2207           0 :     dst_u += p->linesize[1];
    2208           0 :     dst_v += p->linesize[2];
    2209             : 
    2210           0 :     for (y = 1; y < avctx->height; y++) {
    2211           0 :         if (get_bits1(gb)) {
    2212           0 :             for (x = 0; x < avctx->width; x++) {
    2213           0 :                 dst_a[x] = get_bits(gb, 8);
    2214           0 :                 dst_y[x] = get_bits(gb, 8);
    2215           0 :                 dst_u[x] = get_bits(gb, 8);
    2216           0 :                 dst_v[x] = get_bits(gb, 8);
    2217             :             }
    2218             :         } else {
    2219             :             int pred_L[4];
    2220             :             int a, y, u, v;
    2221             : 
    2222           0 :             pred_L[0] = dst_a[-p->linesize[3]];
    2223           0 :             pred_L[1] = dst_y[-p->linesize[0]];
    2224           0 :             pred_L[2] = dst_u[-p->linesize[1]];
    2225           0 :             pred_L[3] = dst_v[-p->linesize[2]];
    2226             : 
    2227           0 :             for (x = 0; x < avctx->width; x++) {
    2228           0 :                 a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2229           0 :                 y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2230           0 :                 u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2231           0 :                 v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2232             : 
    2233           0 :                 dst_a[x] = pred_L[0] = (a + pred_L[0]) & 0xff;
    2234           0 :                 dst_y[x] = pred_L[1] = (y + pred_L[1]) & 0xff;
    2235           0 :                 dst_u[x] = pred_L[2] = (u + pred_L[2]) & 0xff;
    2236           0 :                 dst_v[x] = pred_L[3] = (v + pred_L[3]) & 0xff;
    2237             :             }
    2238             :         }
    2239             : 
    2240           0 :         dst_a += p->linesize[3];
    2241           0 :         dst_y += p->linesize[0];
    2242           0 :         dst_u += p->linesize[1];
    2243           0 :         dst_v += p->linesize[2];
    2244             :     }
    2245           0 : }
    2246             : 
    2247           0 : static void decode_aybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    2248             : {
    2249           0 :     SheerVideoContext *s = avctx->priv_data;
    2250             :     uint8_t *dst_a, *dst_y, *dst_u, *dst_v;
    2251             :     int x, y;
    2252             : 
    2253           0 :     dst_a = p->data[3];
    2254           0 :     dst_y = p->data[0];
    2255           0 :     dst_u = p->data[1];
    2256           0 :     dst_v = p->data[2];
    2257             : 
    2258           0 :     if (get_bits1(gb)) {
    2259           0 :         for (x = 0; x < avctx->width; x++) {
    2260           0 :             dst_a[x] = get_bits(gb, 8);
    2261           0 :             dst_y[x] = get_bits(gb, 8);
    2262           0 :             dst_u[x] = get_bits(gb, 8);
    2263           0 :             dst_v[x] = get_bits(gb, 8);
    2264             :         }
    2265             :     } else {
    2266           0 :         int pred[4] = { 125, s->alt ? 125 : -146, -128, -128 };
    2267             : 
    2268           0 :         for (x = 0; x < avctx->width; x++) {
    2269             :             int a, y, u, v;
    2270             : 
    2271           0 :             a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2272           0 :             y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2273           0 :             u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2274           0 :             v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2275             : 
    2276           0 :             dst_a[x] = pred[0] = (a + pred[0]) & 0xff;
    2277           0 :             dst_y[x] = pred[1] = (y + pred[1]) & 0xff;
    2278           0 :             dst_u[x] = pred[2] = (u + pred[2]) & 0xff;
    2279           0 :             dst_v[x] = pred[3] = (v + pred[3]) & 0xff;
    2280             :         }
    2281             :     }
    2282             : 
    2283           0 :     dst_a += p->linesize[3];
    2284           0 :     dst_y += p->linesize[0];
    2285           0 :     dst_u += p->linesize[1];
    2286           0 :     dst_v += p->linesize[2];
    2287             : 
    2288           0 :     for (y = 1; y < avctx->height; y++) {
    2289           0 :         if (get_bits1(gb)) {
    2290           0 :             for (x = 0; x < avctx->width; x++) {
    2291           0 :                 dst_a[x] = get_bits(gb, 8);
    2292           0 :                 dst_y[x] = get_bits(gb, 8);
    2293           0 :                 dst_u[x] = get_bits(gb, 8);
    2294           0 :                 dst_v[x] = get_bits(gb, 8);
    2295             :             }
    2296             :         } else {
    2297             :             int pred_TL[4], pred_L[4], pred_T[4];
    2298             :             int a, y, u, v;
    2299             : 
    2300           0 :             pred_TL[0] = pred_L[0] = dst_a[-p->linesize[3]];
    2301           0 :             pred_TL[1] = pred_L[1] = dst_y[-p->linesize[0]];
    2302           0 :             pred_TL[2] = pred_L[2] = dst_u[-p->linesize[1]];
    2303           0 :             pred_TL[3] = pred_L[3] = dst_v[-p->linesize[2]];
    2304             : 
    2305           0 :             for (x = 0; x < avctx->width; x++) {
    2306           0 :                 pred_T[0] = dst_a[-p->linesize[3] + x];
    2307           0 :                 pred_T[1] = dst_y[-p->linesize[0] + x];
    2308           0 :                 pred_T[2] = dst_u[-p->linesize[1] + x];
    2309           0 :                 pred_T[3] = dst_v[-p->linesize[2] + x];
    2310             : 
    2311           0 :                 a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2312           0 :                 y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2313           0 :                 u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2314           0 :                 v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2315             : 
    2316           0 :                 dst_a[x] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
    2317           0 :                 dst_y[x] = pred_L[1] = (y + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
    2318           0 :                 dst_u[x] = pred_L[2] = (u + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
    2319           0 :                 dst_v[x] = pred_L[3] = (v + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
    2320             : 
    2321           0 :                 pred_TL[0] = pred_T[0];
    2322           0 :                 pred_TL[1] = pred_T[1];
    2323           0 :                 pred_TL[2] = pred_T[2];
    2324           0 :                 pred_TL[3] = pred_T[3];
    2325             :             }
    2326             :         }
    2327             : 
    2328           0 :         dst_a += p->linesize[3];
    2329           0 :         dst_y += p->linesize[0];
    2330           0 :         dst_u += p->linesize[1];
    2331           0 :         dst_v += p->linesize[2];
    2332             :     }
    2333           0 : }
    2334             : 
    2335           0 : static void decode_argxi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    2336             : {
    2337           0 :     SheerVideoContext *s = avctx->priv_data;
    2338             :     uint16_t *dst_r, *dst_g, *dst_b, *dst_a;
    2339             :     int x, y;
    2340             : 
    2341           0 :     dst_r = (uint16_t *)p->data[2];
    2342           0 :     dst_g = (uint16_t *)p->data[0];
    2343           0 :     dst_b = (uint16_t *)p->data[1];
    2344           0 :     dst_a = (uint16_t *)p->data[3];
    2345             : 
    2346           0 :     for (y = 0; y < avctx->height; y++) {
    2347           0 :         if (get_bits1(gb)) {
    2348           0 :             for (x = 0; x < avctx->width; x++) {
    2349           0 :                 dst_a[x] = get_bits(gb, 10);
    2350           0 :                 dst_r[x] = get_bits(gb, 10);
    2351           0 :                 dst_g[x] = get_bits(gb, 10);
    2352           0 :                 dst_b[x] = get_bits(gb, 10);
    2353             :             }
    2354             :         } else {
    2355           0 :             int pred[4] = { 512, 512, 512, 512 };
    2356             : 
    2357           0 :             for (x = 0; x < avctx->width; x++) {
    2358             :                 int r, g, b, a;
    2359             : 
    2360           0 :                 a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2361           0 :                 r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2362           0 :                 g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2363           0 :                 b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2364             : 
    2365           0 :                 dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
    2366           0 :                 dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
    2367           0 :                 dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
    2368           0 :                 dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
    2369             :             }
    2370             :         }
    2371             : 
    2372           0 :         dst_r += p->linesize[2] / 2;
    2373           0 :         dst_g += p->linesize[0] / 2;
    2374           0 :         dst_b += p->linesize[1] / 2;
    2375           0 :         dst_a += p->linesize[3] / 2;
    2376             :     }
    2377           0 : }
    2378             : 
    2379           0 : static void decode_argx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    2380             : {
    2381           0 :     SheerVideoContext *s = avctx->priv_data;
    2382             :     uint16_t *dst_r, *dst_g, *dst_b, *dst_a;
    2383             :     int x, y;
    2384             : 
    2385           0 :     dst_r = (uint16_t *)p->data[2];
    2386           0 :     dst_g = (uint16_t *)p->data[0];
    2387           0 :     dst_b = (uint16_t *)p->data[1];
    2388           0 :     dst_a = (uint16_t *)p->data[3];
    2389             : 
    2390           0 :     if (get_bits1(gb)) {
    2391           0 :         for (x = 0; x < avctx->width; x++) {
    2392           0 :             dst_a[x] = get_bits(gb, 10);
    2393           0 :             dst_r[x] = get_bits(gb, 10);
    2394           0 :             dst_g[x] = get_bits(gb, 10);
    2395           0 :             dst_b[x] = get_bits(gb, 10);
    2396             :         }
    2397             :     } else {
    2398           0 :         int pred[4] = { 512, 512, 512, 512 };
    2399             : 
    2400           0 :         for (x = 0; x < avctx->width; x++) {
    2401             :             int r, g, b, a;
    2402             : 
    2403           0 :             a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2404           0 :             r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2405           0 :             g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2406           0 :             b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2407             : 
    2408           0 :             dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
    2409           0 :             dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
    2410           0 :             dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
    2411           0 :             dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
    2412             :         }
    2413             :     }
    2414             : 
    2415           0 :     dst_r += p->linesize[2] / 2;
    2416           0 :     dst_g += p->linesize[0] / 2;
    2417           0 :     dst_b += p->linesize[1] / 2;
    2418           0 :     dst_a += p->linesize[3] / 2;
    2419             : 
    2420           0 :     for (y = 1; y < avctx->height; y++) {
    2421           0 :         if (get_bits1(gb)) {
    2422           0 :             for (x = 0; x < avctx->width; x++) {
    2423           0 :                 dst_a[x] = get_bits(gb, 10);
    2424           0 :                 dst_r[x] = get_bits(gb, 10);
    2425           0 :                 dst_g[x] = get_bits(gb, 10);
    2426           0 :                 dst_b[x] = get_bits(gb, 10);
    2427             :             }
    2428             :         } else {
    2429             :             int pred_TL[4], pred_L[4], pred_T[4];
    2430             :             int r, g, b, a;
    2431             : 
    2432           0 :             pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
    2433           0 :             pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
    2434           0 :             pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
    2435           0 :             pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
    2436             : 
    2437           0 :             for (x = 0; x < avctx->width; x++) {
    2438           0 :                 pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
    2439           0 :                 pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
    2440           0 :                 pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
    2441           0 :                 pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
    2442             : 
    2443           0 :                 a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2444           0 :                 r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2445           0 :                 g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2446           0 :                 b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2447             : 
    2448           0 :                 dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
    2449           0 :                 dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
    2450           0 :                 dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
    2451           0 :                 dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
    2452             : 
    2453           0 :                 pred_TL[0] = pred_T[0];
    2454           0 :                 pred_TL[1] = pred_T[1];
    2455           0 :                 pred_TL[2] = pred_T[2];
    2456           0 :                 pred_TL[3] = pred_T[3];
    2457             :             }
    2458             :         }
    2459             : 
    2460           0 :         dst_r += p->linesize[2] / 2;
    2461           0 :         dst_g += p->linesize[0] / 2;
    2462           0 :         dst_b += p->linesize[1] / 2;
    2463           0 :         dst_a += p->linesize[3] / 2;
    2464             :     }
    2465           0 : }
    2466             : 
    2467           0 : static void decode_rgbxi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    2468             : {
    2469           0 :     SheerVideoContext *s = avctx->priv_data;
    2470             :     uint16_t *dst_r, *dst_g, *dst_b;
    2471             :     int x, y;
    2472             : 
    2473           0 :     dst_r = (uint16_t *)p->data[2];
    2474           0 :     dst_g = (uint16_t *)p->data[0];
    2475           0 :     dst_b = (uint16_t *)p->data[1];
    2476             : 
    2477           0 :     for (y = 0; y < avctx->height; y++) {
    2478           0 :         if (get_bits1(gb)) {
    2479           0 :             for (x = 0; x < avctx->width; x++) {
    2480           0 :                 dst_r[x] = get_bits(gb, 10);
    2481           0 :                 dst_g[x] = get_bits(gb, 10);
    2482           0 :                 dst_b[x] = get_bits(gb, 10);
    2483             :             }
    2484             :         } else {
    2485           0 :             int pred[4] = { 512, 512, 512, 0 };
    2486             : 
    2487           0 :             for (x = 0; x < avctx->width; x++) {
    2488             :                 int r, g, b;
    2489             : 
    2490           0 :                 r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2491           0 :                 g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2492           0 :                 b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2493             : 
    2494           0 :                 dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
    2495           0 :                 dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
    2496           0 :                 dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
    2497             :             }
    2498             :         }
    2499             : 
    2500           0 :         dst_r += p->linesize[2] / 2;
    2501           0 :         dst_g += p->linesize[0] / 2;
    2502           0 :         dst_b += p->linesize[1] / 2;
    2503             :     }
    2504           0 : }
    2505             : 
    2506           0 : static void decode_rgbx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    2507             : {
    2508           0 :     SheerVideoContext *s = avctx->priv_data;
    2509             :     uint16_t *dst_r, *dst_g, *dst_b;
    2510             :     int x, y;
    2511             : 
    2512           0 :     dst_r = (uint16_t *)p->data[2];
    2513           0 :     dst_g = (uint16_t *)p->data[0];
    2514           0 :     dst_b = (uint16_t *)p->data[1];
    2515             : 
    2516           0 :     if (get_bits1(gb)) {
    2517           0 :         for (x = 0; x < avctx->width; x++) {
    2518           0 :             dst_r[x] = get_bits(gb, 10);
    2519           0 :             dst_g[x] = get_bits(gb, 10);
    2520           0 :             dst_b[x] = get_bits(gb, 10);
    2521             :         }
    2522             :     } else {
    2523           0 :         int pred[4] = { 512, 512, 512, 0 };
    2524             : 
    2525           0 :         for (x = 0; x < avctx->width; x++) {
    2526             :             int r, g, b;
    2527             : 
    2528           0 :             r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2529           0 :             g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2530           0 :             b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2531             : 
    2532           0 :             dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
    2533           0 :             dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
    2534           0 :             dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
    2535             :         }
    2536             :     }
    2537             : 
    2538           0 :     dst_r += p->linesize[2] / 2;
    2539           0 :     dst_g += p->linesize[0] / 2;
    2540           0 :     dst_b += p->linesize[1] / 2;
    2541             : 
    2542           0 :     for (y = 1; y < avctx->height; y++) {
    2543           0 :         if (get_bits1(gb)) {
    2544           0 :             for (x = 0; x < avctx->width; x++) {
    2545           0 :                 dst_r[x] = get_bits(gb, 10);
    2546           0 :                 dst_g[x] = get_bits(gb, 10);
    2547           0 :                 dst_b[x] = get_bits(gb, 10);
    2548             :             }
    2549             :         } else {
    2550             :             int pred_TL[4], pred_L[4], pred_T[4];
    2551             :             int r, g, b;
    2552             : 
    2553           0 :             pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
    2554           0 :             pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
    2555           0 :             pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
    2556             : 
    2557           0 :             for (x = 0; x < avctx->width; x++) {
    2558           0 :                 pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
    2559           0 :                 pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
    2560           0 :                 pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
    2561             : 
    2562           0 :                 r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2563           0 :                 g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2564           0 :                 b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2565             : 
    2566           0 :                 dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
    2567           0 :                 dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
    2568           0 :                 dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
    2569             : 
    2570           0 :                 pred_TL[0] = pred_T[0];
    2571           0 :                 pred_TL[1] = pred_T[1];
    2572           0 :                 pred_TL[2] = pred_T[2];
    2573             :             }
    2574             :         }
    2575             : 
    2576           0 :         dst_r += p->linesize[2] / 2;
    2577           0 :         dst_g += p->linesize[0] / 2;
    2578           0 :         dst_b += p->linesize[1] / 2;
    2579             :     }
    2580           0 : }
    2581             : 
    2582           0 : static void decode_argbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    2583             : {
    2584           0 :     SheerVideoContext *s = avctx->priv_data;
    2585             :     uint8_t *dst;
    2586             :     int x, y;
    2587             : 
    2588           0 :     dst = p->data[0];
    2589           0 :     if (get_bits1(gb)) {
    2590           0 :         for (x = 0; x < avctx->width; x++) {
    2591           0 :             dst[x * 4 + 0] = get_bits(gb, 8);
    2592           0 :             dst[x * 4 + 1] = get_bits(gb, 8);
    2593           0 :             dst[x * 4 + 2] = get_bits(gb, 8);
    2594           0 :             dst[x * 4 + 3] = get_bits(gb, 8);
    2595             :         }
    2596             :     } else {
    2597           0 :         int pred[4] = { -128, -128, -128, -128 };
    2598             : 
    2599           0 :         for (x = 0; x < avctx->width; x++) {
    2600             :             int a, r, g, b;
    2601             : 
    2602           0 :             a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2603           0 :             r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2604           0 :             g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2605           0 :             b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2606             : 
    2607           0 :             dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
    2608           0 :             dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
    2609           0 :             dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
    2610           0 :             dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
    2611             :         }
    2612             :     }
    2613             : 
    2614           0 :     dst += p->linesize[0];
    2615           0 :     for (y = 1; y < avctx->height; y++) {
    2616           0 :         if (get_bits1(gb)) {
    2617           0 :             for (x = 0; x < avctx->width; x++) {
    2618           0 :                 dst[x * 4 + 0] = get_bits(gb, 8);
    2619           0 :                 dst[x * 4 + 1] = get_bits(gb, 8);
    2620           0 :                 dst[x * 4 + 2] = get_bits(gb, 8);
    2621           0 :                 dst[x * 4 + 3] = get_bits(gb, 8);
    2622             :             }
    2623             :         } else {
    2624             :             int pred_L[4];
    2625             :             int a, r, g, b;
    2626             : 
    2627           0 :             pred_L[0] = dst[-p->linesize[0] + 0];
    2628           0 :             pred_L[1] = dst[-p->linesize[0] + 1];
    2629           0 :             pred_L[2] = dst[-p->linesize[0] + 2];
    2630           0 :             pred_L[3] = dst[-p->linesize[0] + 3];
    2631             : 
    2632           0 :             for (x = 0; x < avctx->width; x++) {
    2633           0 :                 a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2634           0 :                 r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2635           0 :                 g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2636           0 :                 b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2637             : 
    2638           0 :                 dst[4 * x + 0] = pred_L[0] = (a + pred_L[0]) & 0xff;
    2639           0 :                 dst[4 * x + 1] = pred_L[1] = (r + pred_L[1]) & 0xff;
    2640           0 :                 dst[4 * x + 2] = pred_L[2] = (r + g + pred_L[2]) & 0xff;
    2641           0 :                 dst[4 * x + 3] = pred_L[3] = (r + g + b + pred_L[3]) & 0xff;
    2642             :             }
    2643             :         }
    2644           0 :         dst += p->linesize[0];
    2645             :     }
    2646           0 : }
    2647             : 
    2648           0 : static void decode_argb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    2649             : {
    2650           0 :     SheerVideoContext *s = avctx->priv_data;
    2651             :     uint8_t *dst;
    2652             :     int x, y;
    2653             : 
    2654           0 :     dst = p->data[0];
    2655           0 :     if (get_bits1(gb)) {
    2656           0 :         for (x = 0; x < avctx->width; x++) {
    2657           0 :             dst[x * 4 + 0] = get_bits(gb, 8);
    2658           0 :             dst[x * 4 + 1] = get_bits(gb, 8);
    2659           0 :             dst[x * 4 + 2] = get_bits(gb, 8);
    2660           0 :             dst[x * 4 + 3] = get_bits(gb, 8);
    2661             :         }
    2662             :     } else {
    2663           0 :         int pred[4] = { -128, -128, -128, -128 };
    2664             : 
    2665           0 :         for (x = 0; x < avctx->width; x++) {
    2666             :             int a, r, g, b;
    2667             : 
    2668           0 :             a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2669           0 :             r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2670           0 :             g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2671           0 :             b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2672             : 
    2673           0 :             dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
    2674           0 :             dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
    2675           0 :             dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
    2676           0 :             dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
    2677             :         }
    2678             :     }
    2679             : 
    2680           0 :     dst += p->linesize[0];
    2681           0 :     for (y = 1; y < avctx->height; y++) {
    2682           0 :         if (get_bits1(gb)) {
    2683           0 :             for (x = 0; x < avctx->width; x++) {
    2684           0 :                 dst[x * 4 + 0] = get_bits(gb, 8);
    2685           0 :                 dst[x * 4 + 1] = get_bits(gb, 8);
    2686           0 :                 dst[x * 4 + 2] = get_bits(gb, 8);
    2687           0 :                 dst[x * 4 + 3] = get_bits(gb, 8);
    2688             :             }
    2689             :         } else {
    2690             :             int pred_TL[4], pred_L[4], pred_T[4];
    2691             :             int a, r, g, b;
    2692             : 
    2693           0 :             pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
    2694           0 :             pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
    2695           0 :             pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
    2696           0 :             pred_TL[3] = pred_L[3] = dst[-p->linesize[0] + 3];
    2697             : 
    2698           0 :             for (x = 0; x < avctx->width; x++) {
    2699           0 :                 pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
    2700           0 :                 pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
    2701           0 :                 pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
    2702           0 :                 pred_T[3] = dst[-p->linesize[0] + 4 * x + 3];
    2703             : 
    2704           0 :                 a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2705           0 :                 r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2706           0 :                 g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2707           0 :                 b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2708             : 
    2709           0 :                 dst[4 * x + 0] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
    2710           0 :                 dst[4 * x + 1] = pred_L[1] = (r + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
    2711           0 :                 dst[4 * x + 2] = pred_L[2] = (r + g + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
    2712           0 :                 dst[4 * x + 3] = pred_L[3] = (r + g + b + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
    2713             : 
    2714           0 :                 pred_TL[0] = pred_T[0];
    2715           0 :                 pred_TL[1] = pred_T[1];
    2716           0 :                 pred_TL[2] = pred_T[2];
    2717           0 :                 pred_TL[3] = pred_T[3];
    2718             :             }
    2719             :         }
    2720           0 :         dst += p->linesize[0];
    2721             :     }
    2722           0 : }
    2723             : 
    2724           0 : static void decode_rgbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    2725             : {
    2726           0 :     SheerVideoContext *s = avctx->priv_data;
    2727             :     uint8_t *dst;
    2728             :     int x, y;
    2729             : 
    2730           0 :     dst = p->data[0];
    2731           0 :     if (get_bits1(gb)) {
    2732           0 :         for (x = 0; x < avctx->width; x++) {
    2733           0 :             dst[x * 4 + 0] = get_bits(gb, 8);
    2734           0 :             dst[x * 4 + 1] = get_bits(gb, 8);
    2735           0 :             dst[x * 4 + 2] = get_bits(gb, 8);
    2736             :         }
    2737             :     } else {
    2738           0 :         int pred[4] = { -128, -128, -128, -128 };
    2739             : 
    2740           0 :         for (x = 0; x < avctx->width; x++) {
    2741             :             int r, g, b;
    2742             : 
    2743           0 :             r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2744           0 :             g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2745           0 :             b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2746             : 
    2747           0 :             dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
    2748           0 :             dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
    2749           0 :             dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
    2750             :         }
    2751             :     }
    2752             : 
    2753           0 :     dst += p->linesize[0];
    2754           0 :     for (y = 1; y < avctx->height; y++) {
    2755           0 :         if (get_bits1(gb)) {
    2756           0 :             for (x = 0; x < avctx->width; x++) {
    2757           0 :                 dst[x * 4 + 0] = get_bits(gb, 8);
    2758           0 :                 dst[x * 4 + 1] = get_bits(gb, 8);
    2759           0 :                 dst[x * 4 + 2] = get_bits(gb, 8);
    2760             :             }
    2761             :         } else {
    2762             :             int pred_L[4];
    2763             :             int r, g, b;
    2764             : 
    2765           0 :             pred_L[0] = dst[-p->linesize[0] + 0];
    2766           0 :             pred_L[1] = dst[-p->linesize[0] + 1];
    2767           0 :             pred_L[2] = dst[-p->linesize[0] + 2];
    2768             : 
    2769           0 :             for (x = 0; x < avctx->width; x++) {
    2770           0 :                 r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2771           0 :                 g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2772           0 :                 b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2773             : 
    2774           0 :                 dst[4 * x + 0] = pred_L[0] = (r + pred_L[0]) & 0xff;
    2775           0 :                 dst[4 * x + 1] = pred_L[1] = (r + g + pred_L[1]) & 0xff;
    2776           0 :                 dst[4 * x + 2] = pred_L[2] = (r + g + b + pred_L[2]) & 0xff;
    2777             :             }
    2778             :         }
    2779           0 :         dst += p->linesize[0];
    2780             :     }
    2781           0 : }
    2782             : 
    2783           0 : static void decode_rgb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
    2784             : {
    2785           0 :     SheerVideoContext *s = avctx->priv_data;
    2786             :     uint8_t *dst;
    2787             :     int x, y;
    2788             : 
    2789           0 :     dst = p->data[0];
    2790           0 :     if (get_bits1(gb)) {
    2791           0 :         for (x = 0; x < avctx->width; x++) {
    2792           0 :             dst[x * 4 + 0] = get_bits(gb, 8);
    2793           0 :             dst[x * 4 + 1] = get_bits(gb, 8);
    2794           0 :             dst[x * 4 + 2] = get_bits(gb, 8);
    2795             :         }
    2796             :     } else {
    2797           0 :         int pred[4] = { -128, -128, -128, -128 };
    2798             : 
    2799           0 :         for (x = 0; x < avctx->width; x++) {
    2800             :             int r, g, b;
    2801             : 
    2802           0 :             r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2803           0 :             g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2804           0 :             b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2805             : 
    2806           0 :             dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
    2807           0 :             dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
    2808           0 :             dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
    2809             :         }
    2810             :     }
    2811             : 
    2812           0 :     dst += p->linesize[0];
    2813           0 :     for (y = 1; y < avctx->height; y++) {
    2814           0 :         if (get_bits1(gb)) {
    2815           0 :             for (x = 0; x < avctx->width; x++) {
    2816           0 :                 dst[x * 4 + 0] = get_bits(gb, 8);
    2817           0 :                 dst[x * 4 + 1] = get_bits(gb, 8);
    2818           0 :                 dst[x * 4 + 2] = get_bits(gb, 8);
    2819             :             }
    2820             :         } else {
    2821             :             int pred_TL[4], pred_L[4], pred_T[4];
    2822             :             int r, g, b;
    2823             : 
    2824           0 :             pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
    2825           0 :             pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
    2826           0 :             pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
    2827             : 
    2828           0 :             for (x = 0; x < avctx->width; x++) {
    2829           0 :                 pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
    2830           0 :                 pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
    2831           0 :                 pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
    2832             : 
    2833           0 :                 r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
    2834           0 :                 g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2835           0 :                 b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
    2836             : 
    2837           0 :                 dst[4 * x + 0] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
    2838           0 :                 dst[4 * x + 1] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
    2839           0 :                 dst[4 * x + 2] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
    2840             : 
    2841           0 :                 pred_TL[0] = pred_T[0];
    2842           0 :                 pred_TL[1] = pred_T[1];
    2843           0 :                 pred_TL[2] = pred_T[2];
    2844             :             }
    2845             :         }
    2846           0 :         dst += p->linesize[0];
    2847             :     }
    2848           0 : }
    2849             : 
    2850           0 : static int build_vlc(VLC *vlc, const uint8_t *len, int count)
    2851             : {
    2852             :     uint32_t codes[1024];
    2853             :     uint8_t bits[1024];
    2854             :     uint16_t syms[1024];
    2855             :     uint64_t index;
    2856             :     int i;
    2857             : 
    2858           0 :     index = 0;
    2859           0 :     for (i = 0; i < count; i++) {
    2860           0 :         codes[i]  = index >> (32 - len[i]);
    2861           0 :         bits[i] = len[i];
    2862           0 :         syms[i]  = i;
    2863           0 :         index += 1ULL << (32 - len[i]);
    2864             :     }
    2865             : 
    2866           0 :     ff_free_vlc(vlc);
    2867           0 :     return ff_init_vlc_sparse(vlc, 16, count,
    2868             :                               bits,  sizeof(*bits),  sizeof(*bits),
    2869             :                               codes, sizeof(*codes), sizeof(*codes),
    2870             :                               syms,  sizeof(*syms),  sizeof(*syms), 0);
    2871             : }
    2872             : 
    2873           0 : static int decode_frame(AVCodecContext *avctx,
    2874             :                         void *data, int *got_frame,
    2875             :                         AVPacket *avpkt)
    2876             : {
    2877           0 :     SheerVideoContext *s = avctx->priv_data;
    2878           0 :     ThreadFrame frame = { .f = data };
    2879           0 :     AVFrame *p = data;
    2880             :     GetBitContext gb;
    2881             :     unsigned format;
    2882             :     int ret;
    2883             : 
    2884           0 :     if (avpkt->size <= 20)
    2885           0 :         return AVERROR_INVALIDDATA;
    2886             : 
    2887           0 :     if (AV_RL32(avpkt->data) != MKTAG('S','h','i','r') &&
    2888           0 :         AV_RL32(avpkt->data) != MKTAG('Z','w','a','k'))
    2889           0 :         return AVERROR_INVALIDDATA;
    2890             : 
    2891           0 :     s->alt = 0;
    2892           0 :     format = AV_RL32(avpkt->data + 16);
    2893           0 :     av_log(avctx, AV_LOG_DEBUG, "format: %s\n", av_fourcc2str(format));
    2894           0 :     switch (format) {
    2895           0 :     case MKTAG(' ', 'R', 'G', 'B'):
    2896           0 :         avctx->pix_fmt = AV_PIX_FMT_RGB0;
    2897           0 :         s->decode_frame = decode_rgb;
    2898           0 :         if (s->format != format) {
    2899           0 :             ret  = build_vlc(&s->vlc[0], l_r_rgb, 256);
    2900           0 :             ret |= build_vlc(&s->vlc[1], l_g_rgb, 256);
    2901             :         }
    2902           0 :         break;
    2903           0 :     case MKTAG(' ', 'r', 'G', 'B'):
    2904           0 :         avctx->pix_fmt = AV_PIX_FMT_RGB0;
    2905           0 :         s->decode_frame = decode_rgbi;
    2906           0 :         if (s->format != format) {
    2907           0 :             ret  = build_vlc(&s->vlc[0], l_r_rgbi, 256);
    2908           0 :             ret |= build_vlc(&s->vlc[1], l_g_rgbi, 256);
    2909             :         }
    2910           0 :         break;
    2911           0 :     case MKTAG('A', 'R', 'G', 'X'):
    2912           0 :         avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
    2913           0 :         s->decode_frame = decode_argx;
    2914           0 :         if (s->format != format) {
    2915           0 :             ret  = build_vlc(&s->vlc[0], l_r_rgbx, 1024);
    2916           0 :             ret |= build_vlc(&s->vlc[1], l_g_rgbx, 1024);
    2917             :         }
    2918           0 :         break;
    2919           0 :     case MKTAG('A', 'r', 'G', 'X'):
    2920           0 :         avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
    2921           0 :         s->decode_frame = decode_argxi;
    2922           0 :         if (s->format != format) {
    2923           0 :             ret  = build_vlc(&s->vlc[0], l_r_rgbxi, 1024);
    2924           0 :             ret |= build_vlc(&s->vlc[1], l_g_rgbxi, 1024);
    2925             :         }
    2926           0 :         break;
    2927           0 :     case MKTAG('R', 'G', 'B', 'X'):
    2928           0 :         avctx->pix_fmt = AV_PIX_FMT_GBRP10;
    2929           0 :         s->decode_frame = decode_rgbx;
    2930           0 :         if (s->format != format) {
    2931           0 :             ret  = build_vlc(&s->vlc[0], l_r_rgbx, 1024);
    2932           0 :             ret |= build_vlc(&s->vlc[1], l_g_rgbx, 1024);
    2933             :         }
    2934           0 :         break;
    2935           0 :     case MKTAG('r', 'G', 'B', 'X'):
    2936           0 :         avctx->pix_fmt = AV_PIX_FMT_GBRP10;
    2937           0 :         s->decode_frame = decode_rgbxi;
    2938           0 :         if (s->format != format) {
    2939           0 :             ret  = build_vlc(&s->vlc[0], l_r_rgbxi, 1024);
    2940           0 :             ret |= build_vlc(&s->vlc[1], l_g_rgbxi, 1024);
    2941             :         }
    2942           0 :         break;
    2943           0 :     case MKTAG('A', 'R', 'G', 'B'):
    2944           0 :         avctx->pix_fmt = AV_PIX_FMT_ARGB;
    2945           0 :         s->decode_frame = decode_argb;
    2946           0 :         if (s->format != format) {
    2947           0 :             ret  = build_vlc(&s->vlc[0], l_r_rgb, 256);
    2948           0 :             ret |= build_vlc(&s->vlc[1], l_g_rgb, 256);
    2949             :         }
    2950           0 :         break;
    2951           0 :     case MKTAG('A', 'r', 'G', 'B'):
    2952           0 :         avctx->pix_fmt = AV_PIX_FMT_ARGB;
    2953           0 :         s->decode_frame = decode_argbi;
    2954           0 :         if (s->format != format) {
    2955           0 :             ret  = build_vlc(&s->vlc[0], l_r_rgbi, 256);
    2956           0 :             ret |= build_vlc(&s->vlc[1], l_g_rgbi, 256);
    2957             :         }
    2958           0 :         break;
    2959           0 :     case MKTAG('A', 'Y', 'B', 'R'):
    2960           0 :         s->alt = 1;
    2961           0 :     case MKTAG('A', 'Y', 'b', 'R'):
    2962           0 :         avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
    2963           0 :         s->decode_frame = decode_aybr;
    2964           0 :         if (s->format != format) {
    2965           0 :             ret  = build_vlc(&s->vlc[0], l_y_ybr, 256);
    2966           0 :             ret |= build_vlc(&s->vlc[1], l_u_ybr, 256);
    2967             :         }
    2968           0 :         break;
    2969           0 :     case MKTAG('A', 'y', 'B', 'R'):
    2970           0 :         s->alt = 1;
    2971           0 :     case MKTAG('A', 'y', 'b', 'R'):
    2972           0 :         avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
    2973           0 :         s->decode_frame = decode_aybri;
    2974           0 :         if (s->format != format) {
    2975           0 :             ret  = build_vlc(&s->vlc[0], l_y_ybri, 256);
    2976           0 :             ret |= build_vlc(&s->vlc[1], l_u_ybri, 256);
    2977             :         }
    2978           0 :         break;
    2979           0 :     case MKTAG(' ', 'Y', 'B', 'R'):
    2980           0 :         s->alt = 1;
    2981           0 :     case MKTAG(' ', 'Y', 'b', 'R'):
    2982           0 :         avctx->pix_fmt = AV_PIX_FMT_YUV444P;
    2983           0 :         s->decode_frame = decode_ybr;
    2984           0 :         if (s->format != format) {
    2985           0 :             ret  = build_vlc(&s->vlc[0], l_y_ybr, 256);
    2986           0 :             ret |= build_vlc(&s->vlc[1], l_u_ybr, 256);
    2987             :         }
    2988           0 :         break;
    2989           0 :     case MKTAG(' ', 'y', 'B', 'R'):
    2990           0 :         s->alt = 1;
    2991           0 :     case MKTAG(' ', 'y', 'b', 'R'):
    2992           0 :         avctx->pix_fmt = AV_PIX_FMT_YUV444P;
    2993           0 :         s->decode_frame = decode_ybri;
    2994           0 :         if (s->format != format) {
    2995           0 :             ret  = build_vlc(&s->vlc[0], l_y_ybri, 256);
    2996           0 :             ret |= build_vlc(&s->vlc[1], l_u_ybri, 256);
    2997             :         }
    2998           0 :         break;
    2999           0 :     case MKTAG('Y', 'B', 'R', 0x0a):
    3000           0 :         avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
    3001           0 :         s->decode_frame = decode_ybr10;
    3002           0 :         if (s->format != format) {
    3003           0 :             ret  = build_vlc(&s->vlc[0], l_y_ybr10, 1024);
    3004           0 :             ret |= build_vlc(&s->vlc[1], l_u_ybr10, 1024);
    3005             :         }
    3006           0 :         break;
    3007           0 :     case MKTAG('y', 'B', 'R', 0x0a):
    3008           0 :         avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
    3009           0 :         s->decode_frame = decode_ybr10i;
    3010           0 :         if (s->format != format) {
    3011           0 :             ret  = build_vlc(&s->vlc[0], l_y_ybr10i, 1024);
    3012           0 :             ret |= build_vlc(&s->vlc[1], l_u_ybr10i, 1024);
    3013             :         }
    3014           0 :         break;
    3015           0 :     case MKTAG('C', 'A', '4', 'p'):
    3016           0 :         avctx->pix_fmt = AV_PIX_FMT_YUVA444P10;
    3017           0 :         s->decode_frame = decode_ca4p;
    3018           0 :         if (s->format != format) {
    3019           0 :             ret  = build_vlc(&s->vlc[0], l_y_ybr10, 1024);
    3020           0 :             ret |= build_vlc(&s->vlc[1], l_u_ybr10, 1024);
    3021             :         }
    3022           0 :         break;
    3023           0 :     case MKTAG('C', 'A', '4', 'i'):
    3024           0 :         avctx->pix_fmt = AV_PIX_FMT_YUVA444P10;
    3025           0 :         s->decode_frame = decode_ca4i;
    3026           0 :         if (s->format != format) {
    3027           0 :             ret  = build_vlc(&s->vlc[0], l_y_ybr10i, 1024);
    3028           0 :             ret |= build_vlc(&s->vlc[1], l_u_ybr10i, 1024);
    3029             :         }
    3030           0 :         break;
    3031           0 :     case MKTAG('B', 'Y', 'R', 'Y'):
    3032           0 :         avctx->pix_fmt = AV_PIX_FMT_YUV422P;
    3033           0 :         s->decode_frame = decode_byry;
    3034           0 :         if (s->format != format) {
    3035           0 :             ret  = build_vlc(&s->vlc[0], l_y_byry, 256);
    3036           0 :             ret |= build_vlc(&s->vlc[1], l_u_byry, 256);
    3037             :         }
    3038           0 :         break;
    3039           0 :     case MKTAG('B', 'Y', 'R', 'y'):
    3040           0 :         avctx->pix_fmt = AV_PIX_FMT_YUV422P;
    3041           0 :         s->decode_frame = decode_byryi;
    3042           0 :         if (s->format != format) {
    3043           0 :             ret  = build_vlc(&s->vlc[0], l_y_byryi, 256);
    3044           0 :             ret |= build_vlc(&s->vlc[1], l_u_byryi, 256);
    3045             :         }
    3046           0 :         break;
    3047           0 :     case MKTAG('Y', 'b', 'Y', 'r'):
    3048           0 :         avctx->pix_fmt = AV_PIX_FMT_YUV422P;
    3049           0 :         s->decode_frame = decode_ybyr;
    3050           0 :         if (s->format != format) {
    3051           0 :             ret  = build_vlc(&s->vlc[0], l_y_ybyr, 256);
    3052           0 :             ret |= build_vlc(&s->vlc[1], l_u_ybyr, 256);
    3053             :         }
    3054           0 :         break;
    3055           0 :     case MKTAG('C', '8', '2', 'p'):
    3056           0 :         avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
    3057           0 :         s->decode_frame = decode_c82p;
    3058           0 :         if (s->format != format) {
    3059           0 :             ret  = build_vlc(&s->vlc[0], l_y_byry, 256);
    3060           0 :             ret |= build_vlc(&s->vlc[1], l_u_byry, 256);
    3061             :         }
    3062           0 :         break;
    3063           0 :     case MKTAG('C', '8', '2', 'i'):
    3064           0 :         avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
    3065           0 :         s->decode_frame = decode_c82i;
    3066           0 :         if (s->format != format) {
    3067           0 :             ret  = build_vlc(&s->vlc[0], l_y_byryi, 256);
    3068           0 :             ret |= build_vlc(&s->vlc[1], l_u_byryi, 256);
    3069             :         }
    3070           0 :         break;
    3071           0 :     case MKTAG(0xa2, 'Y', 'R', 'Y'):
    3072           0 :         avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
    3073           0 :         s->decode_frame = decode_yry10;
    3074           0 :         if (s->format != format) {
    3075           0 :             ret  = build_vlc(&s->vlc[0], l_y_yry10, 1024);
    3076           0 :             ret |= build_vlc(&s->vlc[1], l_u_yry10, 1024);
    3077             :         }
    3078           0 :         break;
    3079           0 :     case MKTAG(0xa2, 'Y', 'R', 'y'):
    3080           0 :         avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
    3081           0 :         s->decode_frame = decode_yry10i;
    3082           0 :         if (s->format != format) {
    3083           0 :             ret  = build_vlc(&s->vlc[0], l_y_yry10i, 1024);
    3084           0 :             ret |= build_vlc(&s->vlc[1], l_u_yry10i, 1024);
    3085             :         }
    3086           0 :         break;
    3087           0 :     case MKTAG('C', 'A', '2', 'p'):
    3088           0 :         avctx->pix_fmt = AV_PIX_FMT_YUVA422P10;
    3089           0 :         s->decode_frame = decode_ca2p;
    3090           0 :         if (s->format != format) {
    3091           0 :             ret  = build_vlc(&s->vlc[0], l_y_yry10, 1024);
    3092           0 :             ret |= build_vlc(&s->vlc[1], l_u_yry10, 1024);
    3093             :         }
    3094           0 :         break;
    3095           0 :     case MKTAG('C', 'A', '2', 'i'):
    3096           0 :         avctx->pix_fmt = AV_PIX_FMT_YUVA422P10;
    3097           0 :         s->decode_frame = decode_ca2i;
    3098           0 :         if (s->format != format) {
    3099           0 :             ret  = build_vlc(&s->vlc[0], l_y_yry10i, 1024);
    3100           0 :             ret |= build_vlc(&s->vlc[1], l_u_yry10i, 1024);
    3101             :         }
    3102           0 :         break;
    3103           0 :     default:
    3104           0 :         avpriv_request_sample(avctx, "unsupported format: 0x%X", format);
    3105           0 :         return AVERROR_PATCHWELCOME;
    3106             :     }
    3107             : 
    3108           0 :     if (avpkt->size < 20 + avctx->width * avctx->height / 16) {
    3109           0 :         av_log(avctx, AV_LOG_ERROR, "Input packet too small\n");
    3110           0 :         return AVERROR_INVALIDDATA;
    3111             :     }
    3112             : 
    3113           0 :     if (s->format != format) {
    3114           0 :         if (ret < 0)
    3115           0 :             return ret;
    3116           0 :         s->format = format;
    3117             :     }
    3118             : 
    3119           0 :     p->pict_type = AV_PICTURE_TYPE_I;
    3120           0 :     p->key_frame = 1;
    3121             : 
    3122           0 :     if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
    3123           0 :         return ret;
    3124             : 
    3125           0 :     if ((ret = init_get_bits8(&gb, avpkt->data + 20, avpkt->size - 20)) < 0)
    3126           0 :         return ret;
    3127             : 
    3128           0 :     s->decode_frame(avctx, p, &gb);
    3129             : 
    3130           0 :     *got_frame = 1;
    3131             : 
    3132           0 :     return avpkt->size;
    3133             : }
    3134             : 
    3135             : #if HAVE_THREADS
    3136           0 : static int decode_init_thread_copy(AVCodecContext *avctx)
    3137             : {
    3138           0 :     SheerVideoContext *s = avctx->priv_data;
    3139             : 
    3140           0 :     s->format = 0;
    3141           0 :     memset(&s->vlc[0], 0, sizeof(s->vlc[0]));
    3142           0 :     memset(&s->vlc[1], 0, sizeof(s->vlc[1]));
    3143             : 
    3144           0 :     return 0;
    3145             : }
    3146             : #endif
    3147             : 
    3148           0 : static av_cold int decode_end(AVCodecContext *avctx)
    3149             : {
    3150           0 :     SheerVideoContext *s = avctx->priv_data;
    3151             : 
    3152           0 :     ff_free_vlc(&s->vlc[0]);
    3153           0 :     ff_free_vlc(&s->vlc[1]);
    3154             : 
    3155           0 :     return 0;
    3156             : }
    3157             : 
    3158             : AVCodec ff_sheervideo_decoder = {
    3159             :     .name             = "sheervideo",
    3160             :     .long_name        = NULL_IF_CONFIG_SMALL("BitJazz SheerVideo"),
    3161             :     .type             = AVMEDIA_TYPE_VIDEO,
    3162             :     .id               = AV_CODEC_ID_SHEERVIDEO,
    3163             :     .priv_data_size   = sizeof(SheerVideoContext),
    3164             :     .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
    3165             :     .close            = decode_end,
    3166             :     .decode           = decode_frame,
    3167             :     .capabilities     = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
    3168             : };

Generated by: LCOV version 1.13