History

avcodec: add BitJazz SheerVideo decoder

Paul B Mahol committed 10 years ago

Commit fdf832a1 parent c36fc859 files · +1905 −2Browse files

Unified · Split

9 files
  1. Changelog +1 −0
  2. doc/general.texi +1 −0
  3. libavcodec/Makefile +1 −0
  4. libavcodec/allcodecs.c +1 −0
  5. libavcodec/avcodec.h +1 −0
  6. libavcodec/codec_desc.c +7 −0
  7. libavcodec/sheervideo.c +1882 −0
  8. libavcodec/version.h +2 −2
  9. libavformat/isom.c +9 −0
Changelog+1−0
@@ -39,6 +39,7 @@ version <next>: · 38 unmodified lines
3939 - MTAF demuxer and decoder
4040 - MagicYUV decoder
4141 - OpenExr improvements (tile data and B44/B44A support)
42+- BitJazz SheerVideo decoder
4243
4344 version 3.0:
4445 - Common Encryption (CENC) MP4 encoding and decoding support
doc/general.texi+1−0
@@ -644,6 +644,7 @@ following image formats are supported: · 643 unmodified lines
644644 @item Bethesda VID video @tab @tab X
645645 @tab Used in some games from Bethesda Softworks.
646646 @item Bink Video @tab @tab X
647+@item BitJazz SheerVideo @tab @tab X
647648 @item Bitmap Brothers JV video @tab @tab X
648649 @item y41p Brooktree uncompressed 4:1:1 12-bit @tab X @tab X
649650 @item Brute Force & Ignorance @tab @tab X
libavcodec/Makefile+1−0
@@ -474,6 +474,7 @@ OBJS-$(CONFIG_SDX2_DPCM_DECODER) += dpcm.o · 473 unmodified lines
474474 OBJS-$(CONFIG_SGI_DECODER) += sgidec.o
475475 OBJS-$(CONFIG_SGI_ENCODER) += sgienc.o rle.o
476476 OBJS-$(CONFIG_SGIRLE_DECODER) += sgirledec.o
477+OBJS-$(CONFIG_SHEERVIDEO_DECODER) += sheervideo.o
477478 OBJS-$(CONFIG_SHORTEN_DECODER) += shorten.o
478479 OBJS-$(CONFIG_SIPR_DECODER) += sipr.o acelp_pitch_delay.o \
479480 celp_math.o acelp_vectors.o \
libavcodec/allcodecs.c+1−0
@@ -294,6 +294,7 @@ void avcodec_register_all(void) · 293 unmodified lines
294294 REGISTER_DECODER(SDX2_DPCM, sdx2_dpcm);
295295 REGISTER_ENCDEC (SGI, sgi);
296296 REGISTER_DECODER(SGIRLE, sgirle);
297+ REGISTER_DECODER(SHEERVIDEO, sheervideo);
297298 REGISTER_DECODER(SMACKER, smacker);
298299 REGISTER_DECODER(SMC, smc);
299300 REGISTER_DECODER(SMVJPEG, smvjpeg);
libavcodec/avcodec.h+1−0
@@ -407,6 +407,7 @@ enum AVCodecID { · 406 unmodified lines
407407 AV_CODEC_ID_TRUEMOTION2RT,
408408 AV_CODEC_ID_M101,
409409 AV_CODEC_ID_MAGICYUV,
410+ AV_CODEC_ID_SHEERVIDEO,
410411
411412 /* various PCM "codecs" */
412413 AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
libavcodec/codec_desc.c+7−0
@@ -1549,6 +1549,13 @@ static const AVCodecDescriptor codec_descriptors[] = { · 1548 unmodified lines
15491549 .long_name = NULL_IF_CONFIG_SMALL("MagicYUV Lossless Video"),
15501550 .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
15511551 },
1552+ {
1553+ .id = AV_CODEC_ID_SHEERVIDEO,
1554+ .type = AVMEDIA_TYPE_VIDEO,
1555+ .name = "sheervideo",
1556+ .long_name = NULL_IF_CONFIG_SMALL("BitJazz SheerVideo"),
1557+ .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
1558+ },
15521559
15531560 /* various PCM "codecs" */
15541561 {
libavcodec/sheervideo.c+1882−0
@@ -0,0 +1,1882 @@
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+ VLC vlc[2];
35+ void (*decode_frame)(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb);
36+} SheerVideoContext;
37+
38+static const uint8_t l_r_rgb[256] = {
39+ 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8,
40+ 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
41+ 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12,
42+ 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
43+ 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
44+ 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
45+ 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
46+ 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15,
49+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
50+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13,
51+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
52+ 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
53+ 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
54+ 8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4,
55+};
56+
57+static const uint8_t l_g_rgb[256] = {
58+ 2, 2, 4, 4, 6, 7, 9, 9, 10, 11, 11, 11, 12, 12, 12, 13,
59+ 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
60+ 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
61+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
62+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
63+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
64+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
65+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
66+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
67+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
68+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
69+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
70+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
71+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15,
72+ 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
73+ 13, 13, 12, 12, 12, 11, 11, 11, 10, 9, 9, 8, 6, 4, 3, 3,
74+};
75+
76+static const uint8_t l_y_ybr[256] = {
77+ 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8,
78+ 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10,
79+ 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
80+ 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14,
81+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
82+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
88+ 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
89+ 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
90+ 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
91+ 11, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8,
92+ 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 4, 4, 3,
93+};
94+
95+static const uint8_t l_u_ybr[256] = {
96+ 1, 2, 4, 6, 9, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14,
97+ 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
98+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
99+ 16, 16, 16, 16, 16, 16, 16, 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+ 14, 14, 14, 14, 14, 13, 13, 13, 12, 12, 11, 11, 10, 8, 5, 3,
112+};
113+
114+static const uint8_t l_y_ybyr[256] = {
115+ 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8,
116+ 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
117+ 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12,
118+ 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13,
119+ 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
120+ 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
121+ 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15,
125+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14,
126+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
127+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
128+ 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
129+ 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
130+ 8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4,
131+};
132+
133+static const uint8_t l_u_ybyr[256] = {
134+ 1, 2, 4, 6, 8, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14,
135+ 14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
136+ 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 14, 14,
149+ 14, 14, 13, 13, 13, 12, 12, 11, 11, 10, 10, 9, 8, 7, 6, 3,
150+};
151+
152+static const uint8_t l_y_byry[256] = {
153+ 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8,
154+ 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10,
155+ 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
156+ 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14,
157+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
158+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
159+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
160+ 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
164+ 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
165+ 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
166+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11,
167+ 11, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8,
168+ 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 4, 4, 3,
169+};
170+
171+static const uint8_t l_u_byry[256] = {
172+ 1, 2, 4, 6, 8, 9, 9, 10, 11, 11, 12, 12, 13, 13, 13, 14,
173+ 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
174+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 14,
187+ 14, 14, 14, 13, 13, 12, 12, 12, 11, 11, 10, 9, 8, 7, 6, 3,
188+};
189+
190+static const uint8_t l_y_ybr10[1024] = {
191+ 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7,
192+ 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
193+ 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
194+ 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
195+ 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
196+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
197+ 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
198+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
199+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
200+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
201+ 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
202+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
203+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
204+ 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
205+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
206+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
207+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
208+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
209+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
210+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
211+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
212+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 16, 16, 16, 16, 16, 16, 16,
226+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
227+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
228+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
229+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
230+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
231+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
232+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
233+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
234+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
235+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
236+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
237+ 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15,
238+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
239+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
240+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
241+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
242+ 14, 14, 14, 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, 13, 13,
245+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
246+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
247+ 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
248+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
249+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
250+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10,
251+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9,
252+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
253+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
254+ 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5,
255+};
256+
257+static const uint8_t l_u_ybr10[1024] = {
258+ 2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 9, 10, 10, 10, 11, 11,
259+ 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
260+ 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
261+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16, 16, 16, 16,
273+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
274+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
275+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
276+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
277+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
278+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
279+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
280+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
281+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
282+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
283+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
284+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
285+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
286+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
287+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
288+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
289+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
290+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
291+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
292+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
293+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
294+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
295+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
296+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
297+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
298+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
299+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
300+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
301+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
302+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
303+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
304+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
305+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
306+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
307+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
308+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
309+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
310+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
311+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
312+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
313+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
314+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15,
319+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
320+ 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 12, 12, 12,
321+ 12, 11, 11, 11, 10, 10, 9, 9, 8, 8, 7, 6, 5, 4, 4, 3,
322+};
323+
324+static const uint8_t l_r_rgbx[1024] = {
325+ 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7,
326+ 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
327+ 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
328+ 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10,
329+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
330+ 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
331+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12,
332+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
333+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
334+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
335+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
336+ 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14,
337+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
338+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
339+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15,
340+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
341+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
342+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
343+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
344+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
345+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
346+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
347+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
348+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
349+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
350+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
351+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
352+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
353+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
354+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
355+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
356+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
357+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
358+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
359+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
360+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
361+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
362+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
363+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
364+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
365+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
366+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
367+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
368+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
369+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15,
370+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
371+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
372+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
373+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
374+ 15, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14,
375+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
376+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
377+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13,
378+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
379+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
380+ 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
381+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
382+ 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
383+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
384+ 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
385+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9,
386+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
387+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7,
388+ 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5,
389+};
390+
391+static const uint8_t l_g_rgbx[1024] = {
392+ 3, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7,
393+ 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12,
394+ 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
395+ 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
396+ 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
397+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
398+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 16, 16,
423+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
424+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
425+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
426+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
427+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
428+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
429+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
430+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
431+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
432+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
433+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
434+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
450+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
451+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
452+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13,
453+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
454+ 12, 12, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 9,
455+ 8, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4,
456+};
457+
458+static const uint8_t l_y_yry10[1024] = {
459+ 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7,
460+ 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
461+ 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
462+ 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
463+ 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
464+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
465+ 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
466+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
467+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
468+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
469+ 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
470+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
471+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
472+ 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
473+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
474+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
475+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
476+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16, 16,
492+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
493+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
494+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
495+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
496+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
497+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
498+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
499+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
500+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
501+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
502+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
503+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
504+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
505+ 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15,
506+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
507+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
508+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
509+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
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, 14, 13, 13,
513+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
514+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
515+ 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
516+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
517+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
518+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10,
519+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9,
520+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
521+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
522+ 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5,
523+};
524+
525+static const uint8_t l_u_yry10[1024] = {
526+ 2, 3, 3, 4, 5, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10,
527+ 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13,
528+ 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
529+ 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
530+ 15, 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, 16, 16, 16, 16, 16, 16,
543+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
544+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
545+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
546+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
547+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
548+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
549+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
550+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
551+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
552+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
553+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
554+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
555+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
556+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
557+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
558+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
559+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
560+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
561+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
562+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
563+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
564+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
565+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
566+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
567+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
568+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
569+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
570+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
571+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
587+ 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
588+ 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11,
589+ 10, 10, 10, 10, 9, 9, 9, 8, 8, 7, 7, 6, 5, 4, 4, 3,
590+};
591+
592+static void decode_ca4p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
593+{
594+ SheerVideoContext *s = avctx->priv_data;
595+ uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
596+ int x, y;
597+
598+ dst_a = (uint16_t *)p->data[3];
599+ dst_y = (uint16_t *)p->data[0];
600+ dst_u = (uint16_t *)p->data[1];
601+ dst_v = (uint16_t *)p->data[2];
602+
603+ if (get_bits1(gb)) {
604+ for (x = 0; x < avctx->width; x++) {
605+ dst_a[x] = get_bits(gb, 10);
606+ dst_y[x] = get_bits(gb, 10);
607+ dst_u[x] = get_bits(gb, 10);
608+ dst_v[x] = get_bits(gb, 10);
609+ }
610+ } else {
611+ int pred[4] = { 502, 512, 512, 502 };
612+
613+ for (x = 0; x < avctx->width; x++) {
614+ int y, u, v, a;
615+
616+ a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
617+ y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
618+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
619+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
620+
621+ dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
622+ dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
623+ dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
624+ dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
625+ }
626+ }
627+
628+ dst_y += p->linesize[0] / 2;
629+ dst_u += p->linesize[1] / 2;
630+ dst_v += p->linesize[2] / 2;
631+ dst_a += p->linesize[3] / 2;
632+
633+ for (y = 1; y < avctx->height; y++) {
634+ if (get_bits1(gb)) {
635+ for (x = 0; x < avctx->width; x++) {
636+ dst_a[x] = get_bits(gb, 10);
637+ dst_y[x] = get_bits(gb, 10);
638+ dst_u[x] = get_bits(gb, 10);
639+ dst_v[x] = get_bits(gb, 10);
640+ }
641+ } else {
642+ int pred_TL[4], pred_L[4], pred_T[4];
643+ int y, u, v, a;
644+
645+ pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
646+ pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
647+ pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
648+ pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
649+
650+ for (x = 0; x < avctx->width; x++) {
651+ pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
652+ pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
653+ pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
654+ pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
655+
656+ a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
657+ y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
658+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
659+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
660+
661+ dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
662+ dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
663+ dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
664+ dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
665+
666+ pred_TL[0] = pred_T[0];
667+ pred_TL[1] = pred_T[1];
668+ pred_TL[2] = pred_T[2];
669+ pred_TL[3] = pred_T[3];
670+ }
671+ }
672+
673+ dst_y += p->linesize[0] / 2;
674+ dst_u += p->linesize[1] / 2;
675+ dst_v += p->linesize[2] / 2;
676+ dst_a += p->linesize[3] / 2;
677+ }
678+}
679+
680+static void decode_ybr10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
681+{
682+ SheerVideoContext *s = avctx->priv_data;
683+ uint16_t *dst_y, *dst_u, *dst_v;
684+ int x, y;
685+
686+ dst_y = (uint16_t *)p->data[0];
687+ dst_u = (uint16_t *)p->data[1];
688+ dst_v = (uint16_t *)p->data[2];
689+
690+ if (get_bits1(gb)) {
691+ for (x = 0; x < avctx->width; x++) {
692+ dst_y[x] = get_bits(gb, 10);
693+ dst_u[x] = get_bits(gb, 10);
694+ dst_v[x] = get_bits(gb, 10);
695+ }
696+ } else {
697+ int pred[4] = { 502, 512, 512, 512 };
698+
699+ for (x = 0; x < avctx->width; x++) {
700+ int y, u, v;
701+
702+ y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
703+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
704+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
705+
706+ dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
707+ dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
708+ dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
709+ }
710+ }
711+
712+ dst_y += p->linesize[0] / 2;
713+ dst_u += p->linesize[1] / 2;
714+ dst_v += p->linesize[2] / 2;
715+
716+ for (y = 1; y < avctx->height; y++) {
717+ if (get_bits1(gb)) {
718+ for (x = 0; x < avctx->width; x++) {
719+ dst_y[x] = get_bits(gb, 10);
720+ dst_u[x] = get_bits(gb, 10);
721+ dst_v[x] = get_bits(gb, 10);
722+ }
723+ } else {
724+ int pred_TL[4], pred_L[4], pred_T[4];
725+ int y, u, v;
726+
727+ pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
728+ pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
729+ pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
730+
731+ for (x = 0; x < avctx->width; x++) {
732+ pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
733+ pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
734+ pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
735+
736+ y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
737+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
738+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
739+
740+ dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
741+ dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
742+ dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
743+
744+ pred_TL[0] = pred_T[0];
745+ pred_TL[1] = pred_T[1];
746+ pred_TL[2] = pred_T[2];
747+ }
748+ }
749+
750+ dst_y += p->linesize[0] / 2;
751+ dst_u += p->linesize[1] / 2;
752+ dst_v += p->linesize[2] / 2;
753+ }
754+}
755+
756+static void decode_yry10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
757+{
758+ SheerVideoContext *s = avctx->priv_data;
759+ uint16_t *dst_y, *dst_u, *dst_v;
760+ int x, y;
761+
762+ dst_y = (uint16_t *)p->data[0];
763+ dst_u = (uint16_t *)p->data[1];
764+ dst_v = (uint16_t *)p->data[2];
765+
766+ if (get_bits1(gb)) {
767+ for (x = 0; x < avctx->width; x += 2) {
768+ dst_y[x ] = get_bits(gb, 10);
769+ dst_u[x / 2] = get_bits(gb, 10);
770+ dst_y[x + 1] = get_bits(gb, 10);
771+ dst_v[x / 2] = get_bits(gb, 10);
772+ }
773+ } else {
774+ int pred[4] = { 502, 512, 512, 0 };
775+
776+ for (x = 0; x < avctx->width; x += 2) {
777+ int y1, y2, u, v;
778+
779+ y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
780+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
781+ y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
782+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
783+
784+ dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
785+ dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
786+ dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
787+ dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
788+ }
789+ }
790+
791+ dst_y += p->linesize[0] / 2;
792+ dst_u += p->linesize[1] / 2;
793+ dst_v += p->linesize[2] / 2;
794+
795+ for (y = 1; y < avctx->height; y++) {
796+ if (get_bits1(gb)) {
797+ for (x = 0; x < avctx->width; x += 2) {
798+ dst_y[x ] = get_bits(gb, 10);
799+ dst_u[x / 2] = get_bits(gb, 10);
800+ dst_y[x + 1] = get_bits(gb, 10);
801+ dst_v[x / 2] = get_bits(gb, 10);
802+ }
803+ } else {
804+ int pred_TL[6], pred_L[6], pred_T[6];
805+ int y1, y2, u, v;
806+
807+ pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
808+ pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
809+ pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
810+
811+ for (x = 0; x < avctx->width; x += 2) {
812+ pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
813+ pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
814+ pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
815+ pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
816+
817+ y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
818+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
819+ y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
820+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
821+
822+ dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
823+ dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
824+ dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
825+ dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
826+
827+ pred_TL[0] = pred_T[3];
828+ pred_TL[1] = pred_T[1];
829+ pred_TL[2] = pred_T[2];
830+ }
831+ }
832+
833+ dst_y += p->linesize[0] / 2;
834+ dst_u += p->linesize[1] / 2;
835+ dst_v += p->linesize[2] / 2;
836+ }
837+}
838+
839+static void decode_ca2p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
840+{
841+ SheerVideoContext *s = avctx->priv_data;
842+ uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
843+ int x, y;
844+
845+ dst_y = (uint16_t *)p->data[0];
846+ dst_u = (uint16_t *)p->data[1];
847+ dst_v = (uint16_t *)p->data[2];
848+ dst_a = (uint16_t *)p->data[3];
849+
850+ if (get_bits1(gb)) {
851+ for (x = 0; x < avctx->width; x += 2) {
852+ dst_y[x ] = get_bits(gb, 10);
853+ dst_u[x / 2] = get_bits(gb, 10);
854+ dst_y[x + 1] = get_bits(gb, 10);
855+ dst_a[x ] = get_bits(gb, 10);
856+ dst_v[x / 2] = get_bits(gb, 10);
857+ dst_a[x + 1] = get_bits(gb, 10);
858+ }
859+ } else {
860+ int pred[4] = { 502, 512, 512, 502 };
861+
862+ for (x = 0; x < avctx->width; x += 2) {
863+ int y1, y2, u, v, a1, a2;
864+
865+ a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
866+ y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
867+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
868+ a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
869+ y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
870+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
871+
872+ dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
873+ dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
874+ dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
875+ dst_a[x ] = pred[3] = (a1 + pred[3]) & 0x3ff;
876+ dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
877+ dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0x3ff;
878+ }
879+ }
880+
881+ dst_y += p->linesize[0] / 2;
882+ dst_u += p->linesize[1] / 2;
883+ dst_v += p->linesize[2] / 2;
884+ dst_a += p->linesize[3] / 2;
885+
886+ for (y = 1; y < avctx->height; y++) {
887+ if (get_bits1(gb)) {
888+ for (x = 0; x < avctx->width; x += 2) {
889+ dst_y[x ] = get_bits(gb, 10);
890+ dst_u[x / 2] = get_bits(gb, 10);
891+ dst_y[x + 1] = get_bits(gb, 10);
892+ dst_a[x ] = get_bits(gb, 10);
893+ dst_v[x / 2] = get_bits(gb, 10);
894+ dst_a[x + 1] = get_bits(gb, 10);
895+ }
896+ } else {
897+ int pred_TL[6], pred_L[6], pred_T[6];
898+ int y1, y2, u, v, a1, a2;
899+
900+ pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
901+ pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
902+ pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
903+ pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3] / 2];
904+
905+ for (x = 0; x < avctx->width; x += 2) {
906+ pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
907+ pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
908+ pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
909+ pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
910+ pred_T[4] = dst_a[-p->linesize[3] / 2 + x];
911+ pred_T[5] = dst_a[-p->linesize[3] / 2 + x + 1];
912+
913+ a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
914+ y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
915+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
916+ a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
917+ y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
918+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
919+
920+ dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
921+ dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
922+ dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
923+ dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
924+ dst_a[x ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0x3ff;
925+ dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0x3ff;
926+
927+ pred_TL[0] = pred_T[3];
928+ pred_TL[1] = pred_T[1];
929+ pred_TL[2] = pred_T[2];
930+ pred_TL[4] = pred_T[5];
931+ }
932+ }
933+
934+ dst_y += p->linesize[0] / 2;
935+ dst_u += p->linesize[1] / 2;
936+ dst_v += p->linesize[2] / 2;
937+ dst_a += p->linesize[3] / 2;
938+ }
939+}
940+
941+static void decode_c82p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
942+{
943+ SheerVideoContext *s = avctx->priv_data;
944+ uint8_t *dst_y, *dst_u, *dst_v, *dst_a;
945+ int x, y;
946+
947+ dst_y = p->data[0];
948+ dst_u = p->data[1];
949+ dst_v = p->data[2];
950+ dst_a = p->data[3];
951+
952+ if (get_bits1(gb)) {
953+ for (x = 0; x < avctx->width; x += 2) {
954+ dst_y[x ] = get_bits(gb, 8);
955+ dst_u[x / 2] = get_bits(gb, 8);
956+ dst_y[x + 1] = get_bits(gb, 8);
957+ dst_a[x ] = get_bits(gb, 8);
958+ dst_v[x / 2] = get_bits(gb, 8);
959+ dst_a[x + 1] = get_bits(gb, 8);
960+ }
961+ } else {
962+ int pred[4] = { -125, 128, 128, 125 };
963+
964+ for (x = 0; x < avctx->width; x += 2) {
965+ int y1, y2, u, v, a1, a2;
966+
967+ a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
968+ y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
969+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
970+ a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
971+ y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
972+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
973+
974+ dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
975+ dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
976+ dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
977+ dst_a[x ] = pred[3] = (a1 + pred[3]) & 0xff;
978+ dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
979+ dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0xff;
980+ }
981+ }
982+
983+ dst_y += p->linesize[0];
984+ dst_u += p->linesize[1];
985+ dst_v += p->linesize[2];
986+ dst_a += p->linesize[3];
987+
988+ for (y = 1; y < avctx->height; y++) {
989+ if (get_bits1(gb)) {
990+ for (x = 0; x < avctx->width; x += 2) {
991+ dst_y[x ] = get_bits(gb, 8);
992+ dst_u[x / 2] = get_bits(gb, 8);
993+ dst_y[x + 1] = get_bits(gb, 8);
994+ dst_a[x ] = get_bits(gb, 8);
995+ dst_v[x / 2] = get_bits(gb, 8);
996+ dst_a[x + 1] = get_bits(gb, 8);
997+ }
998+ } else {
999+ int pred_TL[6], pred_L[6], pred_T[6];
1000+ int y1, y2, u, v, a1, a2;
1001+
1002+ pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1003+ pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1004+ pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1005+ pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3]];
1006+
1007+ for (x = 0; x < avctx->width; x += 2) {
1008+ pred_T[0] = dst_y[-p->linesize[0] + x];
1009+ pred_T[3] = dst_y[-p->linesize[0] + x + 1];
1010+ pred_T[1] = dst_u[-p->linesize[1] + x / 2];
1011+ pred_T[2] = dst_v[-p->linesize[2] + x / 2];
1012+ pred_T[4] = dst_a[-p->linesize[3] + x];
1013+ pred_T[5] = dst_a[-p->linesize[3] + x + 1];
1014+
1015+ a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1016+ y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1017+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1018+ a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1019+ y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1020+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1021+
1022+ dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1023+ dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
1024+ dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
1025+ dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
1026+ dst_a[x ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0xff;
1027+ dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0xff;
1028+
1029+ pred_TL[0] = pred_T[3];
1030+ pred_TL[1] = pred_T[1];
1031+ pred_TL[2] = pred_T[2];
1032+ pred_TL[4] = pred_T[5];
1033+ }
1034+ }
1035+
1036+ dst_y += p->linesize[0];
1037+ dst_u += p->linesize[1];
1038+ dst_v += p->linesize[2];
1039+ dst_a += p->linesize[3];
1040+ }
1041+}
1042+
1043+static void decode_ybyr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1044+{
1045+ SheerVideoContext *s = avctx->priv_data;
1046+ uint8_t *dst_y, *dst_u, *dst_v;
1047+ int x, y;
1048+
1049+ dst_y = p->data[0];
1050+ dst_u = p->data[1];
1051+ dst_v = p->data[2];
1052+
1053+ if (get_bits1(gb)) {
1054+ for (x = 0; x < avctx->width; x += 2) {
1055+ dst_y[x ] = get_bits(gb, 8);
1056+ dst_u[x / 2] = get_bits(gb, 8);
1057+ dst_y[x + 1] = get_bits(gb, 8);
1058+ dst_v[x / 2] = get_bits(gb, 8);
1059+ }
1060+ } else {
1061+ int pred[4] = { -125, 128, 128, 0 };
1062+
1063+ for (x = 0; x < avctx->width; x += 2) {
1064+ int y1, y2, u, v;
1065+
1066+ y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1067+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1068+ y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1069+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1070+
1071+ dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
1072+ dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
1073+ dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1074+ dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
1075+ }
1076+ }
1077+
1078+ dst_y += p->linesize[0];
1079+ dst_u += p->linesize[1];
1080+ dst_v += p->linesize[2];
1081+
1082+ for (y = 1; y < avctx->height; y++) {
1083+ if (get_bits1(gb)) {
1084+ for (x = 0; x < avctx->width; x += 2) {
1085+ dst_y[x ] = get_bits(gb, 8);
1086+ dst_u[x / 2] = get_bits(gb, 8);
1087+ dst_y[x + 1] = get_bits(gb, 8);
1088+ dst_v[x / 2] = get_bits(gb, 8);
1089+ }
1090+ } else {
1091+ int pred_TL[4], pred_L[4], pred_T[4];
1092+ int y1, y2, u, v;
1093+
1094+ pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1095+ pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1096+ pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1097+
1098+ for (x = 0; x < avctx->width; x += 2) {
1099+ pred_T[0] = dst_y[-p->linesize[0] + x];
1100+ pred_T[3] = dst_y[-p->linesize[0] + x + 1];
1101+ pred_T[1] = dst_u[-p->linesize[1] + x / 2];
1102+ pred_T[2] = dst_v[-p->linesize[2] + x / 2];
1103+
1104+ y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1105+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1106+ y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1107+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1108+
1109+ dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1110+ dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
1111+ dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
1112+ dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
1113+
1114+ pred_TL[0] = pred_T[3];
1115+ pred_TL[1] = pred_T[1];
1116+ pred_TL[2] = pred_T[2];
1117+ }
1118+ }
1119+
1120+ dst_y += p->linesize[0];
1121+ dst_u += p->linesize[1];
1122+ dst_v += p->linesize[2];
1123+ }
1124+}
1125+
1126+static void decode_byry(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1127+{
1128+ SheerVideoContext *s = avctx->priv_data;
1129+ uint8_t *dst_y, *dst_u, *dst_v;
1130+ int x, y;
1131+
1132+ dst_y = p->data[0];
1133+ dst_u = p->data[1];
1134+ dst_v = p->data[2];
1135+
1136+ if (get_bits1(gb)) {
1137+ for (x = 0; x < avctx->width; x += 2) {
1138+ dst_y[x ] = get_bits(gb, 8);
1139+ dst_u[x / 2] = get_bits(gb, 8);
1140+ dst_y[x + 1] = get_bits(gb, 8);
1141+ dst_v[x / 2] = get_bits(gb, 8);
1142+ }
1143+ } else {
1144+ int pred[4] = { 125, -128, -128, 0 };
1145+
1146+ for (x = 0; x < avctx->width; x += 2) {
1147+ int y1, y2, u, v;
1148+
1149+ y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1150+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1151+ y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1152+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1153+
1154+ dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
1155+ dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
1156+ dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1157+ dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
1158+ }
1159+ }
1160+
1161+ dst_y += p->linesize[0];
1162+ dst_u += p->linesize[1];
1163+ dst_v += p->linesize[2];
1164+
1165+ for (y = 1; y < avctx->height; y++) {
1166+ if (get_bits1(gb)) {
1167+ for (x = 0; x < avctx->width; x += 2) {
1168+ dst_y[x ] = get_bits(gb, 8);
1169+ dst_u[x / 2] = get_bits(gb, 8);
1170+ dst_y[x + 1] = get_bits(gb, 8);
1171+ dst_v[x / 2] = get_bits(gb, 8);
1172+ }
1173+ } else {
1174+ int pred_TL[4], pred_L[4], pred_T[4];
1175+ int y1, y2, u, v;
1176+
1177+ pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1178+ pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1179+ pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1180+
1181+ for (x = 0; x < avctx->width; x += 2) {
1182+ pred_T[0] = dst_y[-p->linesize[0] + x];
1183+ pred_T[3] = dst_y[-p->linesize[0] + x + 1];
1184+ pred_T[1] = dst_u[-p->linesize[1] + x / 2];
1185+ pred_T[2] = dst_v[-p->linesize[2] + x / 2];
1186+
1187+ y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1188+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1189+ y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1190+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1191+
1192+ dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1193+ dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
1194+ dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
1195+ dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
1196+
1197+ pred_TL[0] = pred_T[3];
1198+ pred_TL[1] = pred_T[1];
1199+ pred_TL[2] = pred_T[2];
1200+ }
1201+ }
1202+
1203+ dst_y += p->linesize[0];
1204+ dst_u += p->linesize[1];
1205+ dst_v += p->linesize[2];
1206+ }
1207+}
1208+
1209+static void decode_ybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1210+{
1211+ SheerVideoContext *s = avctx->priv_data;
1212+ uint8_t *dst_y, *dst_u, *dst_v;
1213+ int x, y;
1214+
1215+ dst_y = p->data[0];
1216+ dst_u = p->data[1];
1217+ dst_v = p->data[2];
1218+
1219+ if (get_bits1(gb)) {
1220+ for (x = 0; x < avctx->width; x++) {
1221+ dst_y[x] = get_bits(gb, 8);
1222+ dst_u[x] = get_bits(gb, 8);
1223+ dst_v[x] = get_bits(gb, 8);
1224+ }
1225+ } else {
1226+ int pred[4] = { 125, -128, -128, -128 };
1227+
1228+ for (x = 0; x < avctx->width; x++) {
1229+ int y, u, v;
1230+
1231+ y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1232+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1233+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1234+
1235+ dst_y[x] = pred[0] = (y + pred[0]) & 0xff;
1236+ dst_u[x] = pred[1] = (u + pred[1]) & 0xff;
1237+ dst_v[x] = pred[2] = (v + pred[2]) & 0xff;
1238+ }
1239+ }
1240+
1241+ dst_y += p->linesize[0];
1242+ dst_u += p->linesize[1];
1243+ dst_v += p->linesize[2];
1244+
1245+ for (y = 1; y < avctx->height; y++) {
1246+ if (get_bits1(gb)) {
1247+ for (x = 0; x < avctx->width; x++) {
1248+ dst_y[x] = get_bits(gb, 8);
1249+ dst_u[x] = get_bits(gb, 8);
1250+ dst_v[x] = get_bits(gb, 8);
1251+ }
1252+ } else {
1253+ int pred_TL[4], pred_L[4], pred_T[4];
1254+ int y, u, v;
1255+
1256+ pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1257+ pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1258+ pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1259+
1260+ for (x = 0; x < avctx->width; x++) {
1261+ pred_T[0] = dst_y[-p->linesize[0] + x];
1262+ pred_T[1] = dst_u[-p->linesize[1] + x];
1263+ pred_T[2] = dst_v[-p->linesize[2] + x];
1264+
1265+ y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1266+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1267+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1268+
1269+ dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1270+ dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
1271+ dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
1272+
1273+ pred_TL[0] = pred_T[0];
1274+ pred_TL[1] = pred_T[1];
1275+ pred_TL[2] = pred_T[2];
1276+ }
1277+ }
1278+
1279+ dst_y += p->linesize[0];
1280+ dst_u += p->linesize[1];
1281+ dst_v += p->linesize[2];
1282+ }
1283+}
1284+
1285+static void decode_aybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1286+{
1287+ SheerVideoContext *s = avctx->priv_data;
1288+ uint8_t *dst_a, *dst_y, *dst_u, *dst_v;
1289+ int x, y;
1290+
1291+ dst_a = p->data[3];
1292+ dst_y = p->data[0];
1293+ dst_u = p->data[1];
1294+ dst_v = p->data[2];
1295+
1296+ if (get_bits1(gb)) {
1297+ for (x = 0; x < avctx->width; x++) {
1298+ dst_a[x] = get_bits(gb, 8);
1299+ dst_y[x] = get_bits(gb, 8);
1300+ dst_u[x] = get_bits(gb, 8);
1301+ dst_v[x] = get_bits(gb, 8);
1302+ }
1303+ } else {
1304+ int pred[4] = { 125, 125, -128, -128 };
1305+
1306+ for (x = 0; x < avctx->width; x++) {
1307+ int a, y, u, v;
1308+
1309+ a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1310+ y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1311+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1312+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1313+
1314+ dst_a[x] = pred[0] = (a + pred[0]) & 0xff;
1315+ dst_y[x] = pred[1] = (y + pred[1]) & 0xff;
1316+ dst_u[x] = pred[2] = (u + pred[2]) & 0xff;
1317+ dst_v[x] = pred[3] = (v + pred[3]) & 0xff;
1318+ }
1319+ }
1320+
1321+ dst_a += p->linesize[3];
1322+ dst_y += p->linesize[0];
1323+ dst_u += p->linesize[1];
1324+ dst_v += p->linesize[2];
1325+
1326+ for (y = 1; y < avctx->height; y++) {
1327+ if (get_bits1(gb)) {
1328+ for (x = 0; x < avctx->width; x++) {
1329+ dst_a[x] = get_bits(gb, 8);
1330+ dst_y[x] = get_bits(gb, 8);
1331+ dst_u[x] = get_bits(gb, 8);
1332+ dst_v[x] = get_bits(gb, 8);
1333+ }
1334+ } else {
1335+ int pred_TL[4], pred_L[4], pred_T[4];
1336+ int a, y, u, v;
1337+
1338+ pred_TL[0] = pred_L[0] = dst_a[-p->linesize[3]];
1339+ pred_TL[1] = pred_L[1] = dst_y[-p->linesize[0]];
1340+ pred_TL[2] = pred_L[2] = dst_u[-p->linesize[1]];
1341+ pred_TL[3] = pred_L[3] = dst_v[-p->linesize[2]];
1342+
1343+ for (x = 0; x < avctx->width; x++) {
1344+ pred_T[0] = dst_a[-p->linesize[3] + x];
1345+ pred_T[1] = dst_y[-p->linesize[0] + x];
1346+ pred_T[2] = dst_u[-p->linesize[1] + x];
1347+ pred_T[3] = dst_v[-p->linesize[2] + x];
1348+
1349+ a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1350+ y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1351+ u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1352+ v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1353+
1354+ dst_a[x] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1355+ dst_y[x] = pred_L[1] = (y + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
1356+ dst_u[x] = pred_L[2] = (u + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
1357+ dst_v[x] = pred_L[3] = (v + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
1358+
1359+ pred_TL[0] = pred_T[0];
1360+ pred_TL[1] = pred_T[1];
1361+ pred_TL[2] = pred_T[2];
1362+ pred_TL[3] = pred_T[3];
1363+ }
1364+ }
1365+
1366+ dst_a += p->linesize[3];
1367+ dst_y += p->linesize[0];
1368+ dst_u += p->linesize[1];
1369+ dst_v += p->linesize[2];
1370+ }
1371+}
1372+
1373+static void decode_argx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1374+{
1375+ SheerVideoContext *s = avctx->priv_data;
1376+ uint16_t *dst_r, *dst_g, *dst_b, *dst_a;
1377+ int x, y;
1378+
1379+ dst_r = (uint16_t *)p->data[2];
1380+ dst_g = (uint16_t *)p->data[0];
1381+ dst_b = (uint16_t *)p->data[1];
1382+ dst_a = (uint16_t *)p->data[3];
1383+
1384+ if (get_bits1(gb)) {
1385+ for (x = 0; x < avctx->width; x++) {
1386+ dst_a[x] = get_bits(gb, 10);
1387+ dst_r[x] = get_bits(gb, 10);
1388+ dst_g[x] = get_bits(gb, 10);
1389+ dst_b[x] = get_bits(gb, 10);
1390+ }
1391+ } else {
1392+ int pred[4] = { 512, 512, 512, 0 };
1393+
1394+ for (x = 0; x < avctx->width; x++) {
1395+ int r, g, b, a;
1396+
1397+ a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1398+ r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1399+ g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1400+ b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1401+
1402+ dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
1403+ dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
1404+ dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
1405+ dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
1406+ }
1407+ }
1408+
1409+ dst_r += p->linesize[2] / 2;
1410+ dst_g += p->linesize[0] / 2;
1411+ dst_b += p->linesize[1] / 2;
1412+ dst_a += p->linesize[3] / 2;
1413+
1414+ for (y = 1; y < avctx->height; y++) {
1415+ if (get_bits1(gb)) {
1416+ for (x = 0; x < avctx->width; x++) {
1417+ dst_a[x] = get_bits(gb, 10);
1418+ dst_r[x] = get_bits(gb, 10);
1419+ dst_g[x] = get_bits(gb, 10);
1420+ dst_b[x] = get_bits(gb, 10);
1421+ }
1422+ } else {
1423+ int pred_TL[4], pred_L[4], pred_T[4];
1424+ int r, g, b, a;
1425+
1426+ pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
1427+ pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
1428+ pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
1429+ pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
1430+
1431+ for (x = 0; x < avctx->width; x++) {
1432+ pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
1433+ pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
1434+ pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
1435+ pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
1436+
1437+ a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1438+ r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1439+ g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1440+ b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1441+
1442+ dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
1443+ dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1444+ dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
1445+ dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
1446+
1447+ pred_TL[0] = pred_T[0];
1448+ pred_TL[1] = pred_T[1];
1449+ pred_TL[2] = pred_T[2];
1450+ pred_TL[3] = pred_T[3];
1451+ }
1452+ }
1453+
1454+ dst_r += p->linesize[2] / 2;
1455+ dst_g += p->linesize[0] / 2;
1456+ dst_b += p->linesize[1] / 2;
1457+ dst_a += p->linesize[3] / 2;
1458+ }
1459+}
1460+
1461+static void decode_rgbx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1462+{
1463+ SheerVideoContext *s = avctx->priv_data;
1464+ uint16_t *dst_r, *dst_g, *dst_b;
1465+ int x, y;
1466+
1467+ dst_r = (uint16_t *)p->data[2];
1468+ dst_g = (uint16_t *)p->data[0];
1469+ dst_b = (uint16_t *)p->data[1];
1470+
1471+ if (get_bits1(gb)) {
1472+ for (x = 0; x < avctx->width; x++) {
1473+ dst_r[x] = get_bits(gb, 10);
1474+ dst_g[x] = get_bits(gb, 10);
1475+ dst_b[x] = get_bits(gb, 10);
1476+ }
1477+ } else {
1478+ int pred[4] = { 512, 512, 512, 0 };
1479+
1480+ for (x = 0; x < avctx->width; x++) {
1481+ int r, g, b;
1482+
1483+ r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1484+ g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1485+ b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1486+
1487+ dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
1488+ dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
1489+ dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
1490+ }
1491+ }
1492+
1493+ dst_r += p->linesize[2] / 2;
1494+ dst_g += p->linesize[0] / 2;
1495+ dst_b += p->linesize[1] / 2;
1496+
1497+ for (y = 1; y < avctx->height; y++) {
1498+ if (get_bits1(gb)) {
1499+ for (x = 0; x < avctx->width; x++) {
1500+ dst_r[x] = get_bits(gb, 10);
1501+ dst_g[x] = get_bits(gb, 10);
1502+ dst_b[x] = get_bits(gb, 10);
1503+ }
1504+ } else {
1505+ int pred_TL[4], pred_L[4], pred_T[4];
1506+ int r, g, b;
1507+
1508+ pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
1509+ pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
1510+ pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
1511+
1512+ for (x = 0; x < avctx->width; x++) {
1513+ pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
1514+ pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
1515+ pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
1516+
1517+ r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1518+ g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1519+ b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1520+
1521+ dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1522+ dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
1523+ dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
1524+
1525+ pred_TL[0] = pred_T[0];
1526+ pred_TL[1] = pred_T[1];
1527+ pred_TL[2] = pred_T[2];
1528+ }
1529+ }
1530+
1531+ dst_r += p->linesize[2] / 2;
1532+ dst_g += p->linesize[0] / 2;
1533+ dst_b += p->linesize[1] / 2;
1534+ }
1535+}
1536+
1537+static void decode_argb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1538+{
1539+ SheerVideoContext *s = avctx->priv_data;
1540+ uint8_t *dst;
1541+ int x, y;
1542+
1543+ dst = p->data[0];
1544+ if (get_bits1(gb)) {
1545+ for (x = 0; x < avctx->width; x++) {
1546+ dst[x * 4 + 0] = get_bits(gb, 8);
1547+ dst[x * 4 + 1] = get_bits(gb, 8);
1548+ dst[x * 4 + 2] = get_bits(gb, 8);
1549+ dst[x * 4 + 3] = get_bits(gb, 8);
1550+ }
1551+ } else {
1552+ int pred[4] = { -128, -128, -128, -128 };
1553+
1554+ for (x = 0; x < avctx->width; x++) {
1555+ int a, r, g, b;
1556+
1557+ a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1558+ r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1559+ g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1560+ b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1561+
1562+ dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
1563+ dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
1564+ dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
1565+ dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
1566+ }
1567+ }
1568+
1569+ dst += p->linesize[0];
1570+ for (y = 1; y < avctx->height; y++) {
1571+ if (get_bits1(gb)) {
1572+ for (x = 0; x < avctx->width; x++) {
1573+ dst[x * 4 + 0] = get_bits(gb, 8);
1574+ dst[x * 4 + 1] = get_bits(gb, 8);
1575+ dst[x * 4 + 2] = get_bits(gb, 8);
1576+ dst[x * 4 + 3] = get_bits(gb, 8);
1577+ }
1578+ } else {
1579+ int pred_TL[4], pred_L[4], pred_T[4];
1580+ int a, r, g, b;
1581+
1582+ pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
1583+ pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
1584+ pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
1585+ pred_TL[3] = pred_L[3] = dst[-p->linesize[0] + 3];
1586+
1587+ for (x = 0; x < avctx->width; x++) {
1588+ pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
1589+ pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
1590+ pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
1591+ pred_T[3] = dst[-p->linesize[0] + 4 * x + 3];
1592+
1593+ a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1594+ r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1595+ g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1596+ b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1597+
1598+ dst[4 * x + 0] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1599+ dst[4 * x + 1] = pred_L[1] = (r + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
1600+ dst[4 * x + 2] = pred_L[2] = (r + g + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
1601+ dst[4 * x + 3] = pred_L[3] = (r + g + b + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
1602+
1603+ pred_TL[0] = pred_T[0];
1604+ pred_TL[1] = pred_T[1];
1605+ pred_TL[2] = pred_T[2];
1606+ pred_TL[3] = pred_T[3];
1607+ }
1608+ }
1609+ dst += p->linesize[0];
1610+ }
1611+}
1612+
1613+static void decode_rgb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1614+{
1615+ SheerVideoContext *s = avctx->priv_data;
1616+ uint8_t *dst;
1617+ int x, y;
1618+
1619+ dst = p->data[0];
1620+ if (get_bits1(gb)) {
1621+ for (x = 0; x < avctx->width; x++) {
1622+ dst[x * 4 + 0] = get_bits(gb, 8);
1623+ dst[x * 4 + 1] = get_bits(gb, 8);
1624+ dst[x * 4 + 2] = get_bits(gb, 8);
1625+ }
1626+ } else {
1627+ int pred[4] = { -128, -128, -128, -128 };
1628+
1629+ for (x = 0; x < avctx->width; x++) {
1630+ int r, g, b;
1631+
1632+ r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1633+ g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1634+ b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1635+
1636+ dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
1637+ dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
1638+ dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
1639+ }
1640+ }
1641+
1642+ dst += p->linesize[0];
1643+ for (y = 1; y < avctx->height; y++) {
1644+ if (get_bits1(gb)) {
1645+ for (x = 0; x < avctx->width; x++) {
1646+ dst[x * 4 + 0] = get_bits(gb, 8);
1647+ dst[x * 4 + 1] = get_bits(gb, 8);
1648+ dst[x * 4 + 2] = get_bits(gb, 8);
1649+ }
1650+ } else {
1651+ int pred_TL[4], pred_L[4], pred_T[4];
1652+ int r, g, b;
1653+
1654+ pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
1655+ pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
1656+ pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
1657+
1658+ for (x = 0; x < avctx->width; x++) {
1659+ pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
1660+ pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
1661+ pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
1662+
1663+ r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1664+ g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1665+ b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1666+
1667+ dst[4 * x + 0] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1668+ dst[4 * x + 1] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
1669+ dst[4 * x + 2] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
1670+
1671+ pred_TL[0] = pred_T[0];
1672+ pred_TL[1] = pred_T[1];
1673+ pred_TL[2] = pred_T[2];
1674+ }
1675+ }
1676+ dst += p->linesize[0];
1677+ }
1678+}
1679+
1680+static int build_vlc(VLC *vlc, const uint8_t *len, int count)
1681+{
1682+ uint32_t codes[1024];
1683+ uint8_t bits[1024];
1684+ uint16_t syms[1024];
1685+ uint64_t index;
1686+ int i;
1687+
1688+ index = 0;
1689+ for (i = 0; i < count; i++) {
1690+ codes[i] = index >> (32 - len[i]);
1691+ bits[i] = len[i];
1692+ syms[i] = i;
1693+ index += 1ULL << (32 - len[i]);
1694+ }
1695+
1696+ ff_free_vlc(vlc);
1697+ return ff_init_vlc_sparse(vlc, 16, count,
1698+ bits, sizeof(*bits), sizeof(*bits),
1699+ codes, sizeof(*codes), sizeof(*codes),
1700+ syms, sizeof(*syms), sizeof(*syms), 0);
1701+}
1702+
1703+static int decode_frame(AVCodecContext *avctx,
1704+ void *data, int *got_frame,
1705+ AVPacket *avpkt)
1706+{
1707+ SheerVideoContext *s = avctx->priv_data;
1708+ ThreadFrame frame = { .f = data };
1709+ AVFrame *p = data;
1710+ GetBitContext gb;
1711+ unsigned format;
1712+ int ret;
1713+
1714+ if (avpkt->size <= 20)
1715+ return AVERROR_INVALIDDATA;
1716+
1717+ if (AV_RL32(avpkt->data) != MKTAG('S','h','i','r') &&
1718+ AV_RL32(avpkt->data) != MKTAG('Z','w','a','k'))
1719+ return AVERROR_INVALIDDATA;
1720+
1721+ format = AV_RL32(avpkt->data + 16);
1722+ switch (format) {
1723+ case MKTAG(' ', 'R', 'G', 'B'):
1724+ avctx->pix_fmt = AV_PIX_FMT_RGB0;
1725+ s->decode_frame = decode_rgb;
1726+ if (s->format != format) {
1727+ build_vlc(&s->vlc[0], l_r_rgb, 256);
1728+ build_vlc(&s->vlc[1], l_g_rgb, 256);
1729+ }
1730+ break;
1731+ case MKTAG('A', 'R', 'G', 'X'):
1732+ avctx->pix_fmt = AV_PIX_FMT_GBRAP12;
1733+ s->decode_frame = decode_argx;
1734+ if (s->format != format) {
1735+ build_vlc(&s->vlc[0], l_r_rgbx, 1024);
1736+ build_vlc(&s->vlc[1], l_g_rgbx, 1024);
1737+ }
1738+ break;
1739+ case MKTAG('R', 'G', 'B', 'X'):
1740+ avctx->pix_fmt = AV_PIX_FMT_GBRP10;
1741+ s->decode_frame = decode_rgbx;
1742+ if (s->format != format) {
1743+ build_vlc(&s->vlc[0], l_r_rgbx, 1024);
1744+ build_vlc(&s->vlc[1], l_g_rgbx, 1024);
1745+ }
1746+ break;
1747+ case MKTAG('A', 'R', 'G', 'B'):
1748+ avctx->pix_fmt = AV_PIX_FMT_ARGB;
1749+ s->decode_frame = decode_argb;
1750+ if (s->format != format) {
1751+ build_vlc(&s->vlc[0], l_r_rgb, 256);
1752+ build_vlc(&s->vlc[1], l_g_rgb, 256);
1753+ }
1754+ break;
1755+ case MKTAG('A', 'Y', 'b', 'R'):
1756+ avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
1757+ s->decode_frame = decode_aybr;
1758+ if (s->format != format) {
1759+ build_vlc(&s->vlc[0], l_y_ybr, 256);
1760+ build_vlc(&s->vlc[1], l_u_ybr, 256);
1761+ }
1762+ break;
1763+ case MKTAG(' ', 'Y', 'b', 'R'):
1764+ avctx->pix_fmt = AV_PIX_FMT_YUV444P;
1765+ s->decode_frame = decode_ybr;
1766+ if (s->format != format) {
1767+ build_vlc(&s->vlc[0], l_y_ybr, 256);
1768+ build_vlc(&s->vlc[1], l_u_ybr, 256);
1769+ }
1770+ break;
1771+ case MKTAG('Y', 'B', 'R', 0x0a):
1772+ avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
1773+ s->decode_frame = decode_ybr10;
1774+ if (s->format != format) {
1775+ build_vlc(&s->vlc[0], l_y_ybr10, 1024);
1776+ build_vlc(&s->vlc[1], l_u_ybr10, 1024);
1777+ }
1778+ break;
1779+ case MKTAG('C', 'A', '4', 'p'):
1780+ avctx->pix_fmt = AV_PIX_FMT_YUVA444P10;
1781+ s->decode_frame = decode_ca4p;
1782+ if (s->format != format) {
1783+ build_vlc(&s->vlc[0], l_y_ybr10, 1024);
1784+ build_vlc(&s->vlc[1], l_u_ybr10, 1024);
1785+ }
1786+ break;
1787+ case MKTAG('B', 'Y', 'R', 'Y'):
1788+ avctx->pix_fmt = AV_PIX_FMT_YUV422P;
1789+ s->decode_frame = decode_byry;
1790+ if (s->format != format) {
1791+ build_vlc(&s->vlc[0], l_y_byry, 256);
1792+ build_vlc(&s->vlc[1], l_u_byry, 256);
1793+ }
1794+ break;
1795+ case MKTAG('Y', 'b', 'Y', 'r'):
1796+ avctx->pix_fmt = AV_PIX_FMT_YUV422P;
1797+ s->decode_frame = decode_ybyr;
1798+ if (s->format != format) {
1799+ build_vlc(&s->vlc[0], l_y_ybyr, 256);
1800+ build_vlc(&s->vlc[1], l_u_ybyr, 256);
1801+ }
1802+ break;
1803+ case MKTAG('C', '8', '2', 'p'):
1804+ avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
1805+ s->decode_frame = decode_c82p;
1806+ if (s->format != format) {
1807+ build_vlc(&s->vlc[0], l_y_byry, 256);
1808+ build_vlc(&s->vlc[1], l_u_byry, 256);
1809+ }
1810+ break;
1811+ case MKTAG(0xa2, 'Y', 'R', 'Y'):
1812+ avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
1813+ s->decode_frame = decode_yry10;
1814+ if (s->format != format) {
1815+ build_vlc(&s->vlc[0], l_y_yry10, 1024);
1816+ build_vlc(&s->vlc[1], l_u_yry10, 1024);
1817+ }
1818+ break;
1819+ case MKTAG('C', 'A', '2', 'p'):
1820+ avctx->pix_fmt = AV_PIX_FMT_YUVA422P10;
1821+ s->decode_frame = decode_ca2p;
1822+ if (s->format != format) {
1823+ build_vlc(&s->vlc[0], l_y_yry10, 1024);
1824+ build_vlc(&s->vlc[1], l_u_yry10, 1024);
1825+ }
1826+ break;
1827+ default:
1828+ avpriv_request_sample(avctx, "unsupported format: 0x%X", format);
1829+ return AVERROR_PATCHWELCOME;
1830+ }
1831+ s->format = format;
1832+
1833+ p->pict_type = AV_PICTURE_TYPE_I;
1834+ p->key_frame = 1;
1835+
1836+ if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
1837+ return ret;
1838+
1839+ if ((ret = init_get_bits8(&gb, avpkt->data + 20, avpkt->size - 20)) < 0)
1840+ return ret;
1841+
1842+ s->decode_frame(avctx, p, &gb);
1843+
1844+ *got_frame = 1;
1845+
1846+ return avpkt->size;
1847+}
1848+
1849+#if HAVE_THREADS
1850+static int decode_init_thread_copy(AVCodecContext *avctx)
1851+{
1852+ SheerVideoContext *s = avctx->priv_data;
1853+
1854+ s->format = 0;
1855+ memset(&s->vlc[0], 0, sizeof(s->vlc[0]));
1856+ memset(&s->vlc[1], 0, sizeof(s->vlc[1]));
1857+
1858+ return 0;
1859+}
1860+#endif
1861+
1862+static av_cold int decode_end(AVCodecContext *avctx)
1863+{
1864+ SheerVideoContext *s = avctx->priv_data;
1865+
1866+ ff_free_vlc(&s->vlc[0]);
1867+ ff_free_vlc(&s->vlc[1]);
1868+
1869+ return 0;
1870+}
1871+
1872+AVCodec ff_sheervideo_decoder = {
1873+ .name = "sheervideo",
1874+ .long_name = NULL_IF_CONFIG_SMALL("BitJazz SheerVideo"),
1875+ .type = AVMEDIA_TYPE_VIDEO,
1876+ .id = AV_CODEC_ID_SHEERVIDEO,
1877+ .priv_data_size = sizeof(SheerVideoContext),
1878+ .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
1879+ .close = decode_end,
1880+ .decode = decode_frame,
1881+ .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1882+};
libavcodec/version.h+2−2
@@ -28,8 +28,8 @@ · 27 unmodified lines
2828 #include "libavutil/version.h"
2929
3030 #define LIBAVCODEC_VERSION_MAJOR 57
31−#define LIBAVCODEC_VERSION_MINOR 44
32−#define LIBAVCODEC_VERSION_MICRO 101
31+#define LIBAVCODEC_VERSION_MINOR 45
32+#define LIBAVCODEC_VERSION_MICRO 100
3333
3434 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
3535 LIBAVCODEC_VERSION_MINOR, \
libavformat/isom.c+9−0
@@ -277,6 +277,15 @@ const AVCodecTag ff_codec_movvideo_tags[] = { · 276 unmodified lines
277277 { AV_CODEC_ID_MAGICYUV, MKTAG('M', '8', 'Y', '4') },
278278 { AV_CODEC_ID_MAGICYUV, MKTAG('M', '8', 'Y', 'A') },
279279
280+ { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '0') },
281+ { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '1') },
282+ { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '2') },
283+ { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '3') },
284+ { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '4') },
285+ { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '5') },
286+ { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '6') },
287+ { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '7') },
288+
280289 { AV_CODEC_ID_NONE, 0 },
281290 };
282291

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t