You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2062 lines
90KB

  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. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include "libavutil/intreadwrite.h"
  25. #include "avcodec.h"
  26. #include "get_bits.h"
  27. #include "internal.h"
  28. #include "thread.h"
  29. typedef struct SheerVideoContext {
  30. unsigned format;
  31. VLC vlc[2];
  32. void (*decode_frame)(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb);
  33. } SheerVideoContext;
  34. static const uint8_t l_r_rgb[256] = {
  35. 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8,
  36. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
  37. 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12,
  38. 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  39. 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  40. 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  41. 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  42. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  43. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  44. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15,
  45. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
  46. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13,
  47. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
  48. 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
  49. 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  50. 8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4,
  51. };
  52. static const uint8_t l_r_rgbi[256] = {
  53. 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  54. 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  55. 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11,
  56. 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  57. 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  58. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14,
  59. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15,
  60. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  61. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  62. 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  63. 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13,
  64. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12,
  65. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11,
  66. 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10,
  67. 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8,
  68. 8, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 4, 4, 4,
  69. };
  70. static const uint8_t l_g_rgbi[256] = {
  71. 1, 3, 4, 5, 6, 7, 7, 8, 9, 9, 10, 10, 10, 10, 11, 11,
  72. 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
  73. 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16,
  74. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  75. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  76. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  77. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  78. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  79. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  80. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14,
  85. 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12,
  86. 11, 11, 11, 10, 10, 10, 9, 9, 9, 8, 8, 7, 6, 5, 5, 3,
  87. };
  88. static const uint8_t l_g_rgb[256] = {
  89. 2, 2, 4, 4, 6, 7, 9, 9, 10, 11, 11, 11, 12, 12, 12, 13,
  90. 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
  91. 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  92. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  93. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  94. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  95. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  96. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  97. 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15,
  103. 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
  104. 13, 13, 12, 12, 12, 11, 11, 11, 10, 9, 9, 8, 6, 4, 3, 3,
  105. };
  106. static const uint8_t l_y_ybr[256] = {
  107. 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8,
  108. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10,
  109. 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
  110. 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14,
  111. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
  112. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
  113. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  114. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  115. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  116. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  117. 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  118. 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  119. 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
  120. 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
  121. 11, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8,
  122. 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 4, 4, 3,
  123. };
  124. static const uint8_t l_u_ybr[256] = {
  125. 1, 2, 4, 6, 9, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14,
  126. 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  127. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  128. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  129. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  130. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  131. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  132. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  133. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  134. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  135. 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15,
  140. 14, 14, 14, 14, 14, 13, 13, 13, 12, 12, 11, 11, 10, 8, 5, 3,
  141. };
  142. static const uint8_t l_y_ybyr[256] = {
  143. 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8,
  144. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
  145. 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12,
  146. 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13,
  147. 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  148. 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  149. 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  150. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  151. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  152. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15,
  153. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14,
  154. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
  155. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
  156. 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
  157. 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  158. 8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4,
  159. };
  160. static const uint8_t l_u_ybyr[256] = {
  161. 1, 2, 4, 6, 8, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14,
  162. 14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
  163. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  164. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  165. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  166. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  167. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  168. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  169. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  170. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  171. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  172. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  173. 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 14, 14,
  176. 14, 14, 13, 13, 13, 12, 12, 11, 11, 10, 10, 9, 8, 7, 6, 3,
  177. };
  178. static const uint8_t l_y_byry[256] = {
  179. 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8,
  180. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10,
  181. 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
  182. 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14,
  183. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
  184. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16, 16,
  188. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  189. 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  190. 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  191. 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
  192. 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11,
  193. 11, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8,
  194. 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 4, 4, 3,
  195. };
  196. static const uint8_t l_u_byry[256] = {
  197. 1, 2, 4, 6, 8, 9, 9, 10, 11, 11, 12, 12, 13, 13, 13, 14,
  198. 14, 14, 14, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  203. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  204. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  205. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  206. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  207. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  208. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 14,
  212. 14, 14, 14, 13, 13, 12, 12, 12, 11, 11, 10, 9, 8, 7, 6, 3,
  213. };
  214. static const uint8_t l_y_ybr10[1024] = {
  215. 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7,
  216. 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  217. 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  218. 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
  219. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
  220. 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  221. 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  222. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  223. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  224. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  225. 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  226. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  227. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  228. 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  229. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  230. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  231. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  232. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16, 16, 16,
  238. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  239. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  240. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  241. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  242. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  243. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  244. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  245. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  246. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  247. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  248. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  249. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  250. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  251. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15,
  262. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  263. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  264. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  265. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  266. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  267. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  268. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
  269. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  270. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  271. 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  272. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
  273. 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  274. 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10,
  275. 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9,
  276. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  277. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  278. 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5,
  279. };
  280. static const uint8_t l_u_ybr10[1024] = {
  281. 2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 9, 10, 10, 10, 11, 11,
  282. 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
  283. 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  284. 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 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, 15, 15, 15, 15, 15, 15, 15,
  342. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
  343. 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 12, 12, 12,
  344. 12, 11, 11, 11, 10, 10, 9, 9, 8, 8, 7, 6, 5, 4, 4, 3,
  345. };
  346. static const uint8_t l_r_rgbx[1024] = {
  347. 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7,
  348. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  349. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  350. 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10,
  351. 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
  352. 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  353. 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12,
  354. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  355. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  356. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  357. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  358. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14,
  359. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  360. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  361. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15,
  362. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  363. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  364. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  365. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  366. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 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, 15, 15, 15, 15, 15, 15,
  392. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  393. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  394. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  395. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  396. 15, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  397. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  398. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  399. 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13,
  400. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  401. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  402. 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  403. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  404. 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  405. 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  406. 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
  407. 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9,
  408. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  409. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  410. 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5,
  411. };
  412. static const uint8_t l_g_rgbx[1024] = {
  413. 3, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7,
  414. 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12,
  415. 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  416. 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  417. 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  418. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  419. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  471. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  472. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
  473. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13,
  474. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
  475. 12, 12, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 9,
  476. 8, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4,
  477. };
  478. static const uint8_t l_y_yry10[1024] = {
  479. 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7,
  480. 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  481. 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  482. 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
  483. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
  484. 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  485. 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  486. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  487. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  488. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  489. 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  490. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  491. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  492. 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  493. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  494. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  495. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  496. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16, 16, 16,
  506. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  507. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  508. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  509. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  510. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  511. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  512. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  513. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  514. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  515. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  516. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  517. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15,
  526. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  527. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  528. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  529. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  530. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  531. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  532. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
  533. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  534. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  535. 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  536. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
  537. 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  538. 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10,
  539. 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9,
  540. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  541. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  542. 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5,
  543. };
  544. static const uint8_t l_u_yry10[1024] = {
  545. 2, 3, 3, 4, 5, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10,
  546. 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13,
  547. 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  548. 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  549. 15, 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, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  606. 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
  607. 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11,
  608. 10, 10, 10, 10, 9, 9, 9, 8, 8, 7, 7, 6, 5, 4, 4, 3,
  609. };
  610. static void decode_ca4p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  611. {
  612. SheerVideoContext *s = avctx->priv_data;
  613. uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
  614. int x, y;
  615. dst_a = (uint16_t *)p->data[3];
  616. dst_y = (uint16_t *)p->data[0];
  617. dst_u = (uint16_t *)p->data[1];
  618. dst_v = (uint16_t *)p->data[2];
  619. if (get_bits1(gb)) {
  620. for (x = 0; x < avctx->width; x++) {
  621. dst_a[x] = get_bits(gb, 10);
  622. dst_y[x] = get_bits(gb, 10);
  623. dst_u[x] = get_bits(gb, 10);
  624. dst_v[x] = get_bits(gb, 10);
  625. }
  626. } else {
  627. int pred[4] = { 502, 512, 512, 502 };
  628. for (x = 0; x < avctx->width; x++) {
  629. int y, u, v, a;
  630. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  631. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  632. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  633. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  634. dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
  635. dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
  636. dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
  637. dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
  638. }
  639. }
  640. dst_y += p->linesize[0] / 2;
  641. dst_u += p->linesize[1] / 2;
  642. dst_v += p->linesize[2] / 2;
  643. dst_a += p->linesize[3] / 2;
  644. for (y = 1; y < avctx->height; y++) {
  645. if (get_bits1(gb)) {
  646. for (x = 0; x < avctx->width; x++) {
  647. dst_a[x] = get_bits(gb, 10);
  648. dst_y[x] = get_bits(gb, 10);
  649. dst_u[x] = get_bits(gb, 10);
  650. dst_v[x] = get_bits(gb, 10);
  651. }
  652. } else {
  653. int pred_TL[4], pred_L[4], pred_T[4];
  654. int y, u, v, a;
  655. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
  656. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
  657. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
  658. pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
  659. for (x = 0; x < avctx->width; x++) {
  660. pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
  661. pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
  662. pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
  663. pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
  664. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  665. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  666. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  667. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  668. dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
  669. dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
  670. dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
  671. dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
  672. pred_TL[0] = pred_T[0];
  673. pred_TL[1] = pred_T[1];
  674. pred_TL[2] = pred_T[2];
  675. pred_TL[3] = pred_T[3];
  676. }
  677. }
  678. dst_y += p->linesize[0] / 2;
  679. dst_u += p->linesize[1] / 2;
  680. dst_v += p->linesize[2] / 2;
  681. dst_a += p->linesize[3] / 2;
  682. }
  683. }
  684. static void decode_ybr10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  685. {
  686. SheerVideoContext *s = avctx->priv_data;
  687. uint16_t *dst_y, *dst_u, *dst_v;
  688. int x, y;
  689. dst_y = (uint16_t *)p->data[0];
  690. dst_u = (uint16_t *)p->data[1];
  691. dst_v = (uint16_t *)p->data[2];
  692. if (get_bits1(gb)) {
  693. for (x = 0; x < avctx->width; x++) {
  694. dst_y[x] = get_bits(gb, 10);
  695. dst_u[x] = get_bits(gb, 10);
  696. dst_v[x] = get_bits(gb, 10);
  697. }
  698. } else {
  699. int pred[4] = { 502, 512, 512, 512 };
  700. for (x = 0; x < avctx->width; x++) {
  701. int y, u, v;
  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. dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
  706. dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
  707. dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
  708. }
  709. }
  710. dst_y += p->linesize[0] / 2;
  711. dst_u += p->linesize[1] / 2;
  712. dst_v += p->linesize[2] / 2;
  713. for (y = 1; y < avctx->height; y++) {
  714. if (get_bits1(gb)) {
  715. for (x = 0; x < avctx->width; x++) {
  716. dst_y[x] = get_bits(gb, 10);
  717. dst_u[x] = get_bits(gb, 10);
  718. dst_v[x] = get_bits(gb, 10);
  719. }
  720. } else {
  721. int pred_TL[4], pred_L[4], pred_T[4];
  722. int y, u, v;
  723. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
  724. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
  725. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
  726. for (x = 0; x < avctx->width; x++) {
  727. pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
  728. pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
  729. pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
  730. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  731. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  732. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  733. dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
  734. dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
  735. dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
  736. pred_TL[0] = pred_T[0];
  737. pred_TL[1] = pred_T[1];
  738. pred_TL[2] = pred_T[2];
  739. }
  740. }
  741. dst_y += p->linesize[0] / 2;
  742. dst_u += p->linesize[1] / 2;
  743. dst_v += p->linesize[2] / 2;
  744. }
  745. }
  746. static void decode_yry10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  747. {
  748. SheerVideoContext *s = avctx->priv_data;
  749. uint16_t *dst_y, *dst_u, *dst_v;
  750. int x, y;
  751. dst_y = (uint16_t *)p->data[0];
  752. dst_u = (uint16_t *)p->data[1];
  753. dst_v = (uint16_t *)p->data[2];
  754. if (get_bits1(gb)) {
  755. for (x = 0; x < avctx->width; x += 2) {
  756. dst_y[x ] = get_bits(gb, 10);
  757. dst_u[x / 2] = get_bits(gb, 10);
  758. dst_y[x + 1] = get_bits(gb, 10);
  759. dst_v[x / 2] = get_bits(gb, 10);
  760. }
  761. } else {
  762. int pred[4] = { 502, 512, 512, 0 };
  763. for (x = 0; x < avctx->width; x += 2) {
  764. int y1, y2, u, v;
  765. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  766. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  767. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  768. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  769. dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
  770. dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
  771. dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
  772. dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
  773. }
  774. }
  775. dst_y += p->linesize[0] / 2;
  776. dst_u += p->linesize[1] / 2;
  777. dst_v += p->linesize[2] / 2;
  778. for (y = 1; y < avctx->height; y++) {
  779. if (get_bits1(gb)) {
  780. for (x = 0; x < avctx->width; x += 2) {
  781. dst_y[x ] = get_bits(gb, 10);
  782. dst_u[x / 2] = get_bits(gb, 10);
  783. dst_y[x + 1] = get_bits(gb, 10);
  784. dst_v[x / 2] = get_bits(gb, 10);
  785. }
  786. } else {
  787. int pred_TL[6], pred_L[6], pred_T[6];
  788. int y1, y2, u, v;
  789. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
  790. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
  791. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
  792. for (x = 0; x < avctx->width; x += 2) {
  793. pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
  794. pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
  795. pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
  796. pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
  797. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  798. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  799. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  800. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  801. dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
  802. dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
  803. dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
  804. dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
  805. pred_TL[0] = pred_T[3];
  806. pred_TL[1] = pred_T[1];
  807. pred_TL[2] = pred_T[2];
  808. }
  809. }
  810. dst_y += p->linesize[0] / 2;
  811. dst_u += p->linesize[1] / 2;
  812. dst_v += p->linesize[2] / 2;
  813. }
  814. }
  815. static void decode_ca2p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  816. {
  817. SheerVideoContext *s = avctx->priv_data;
  818. uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
  819. int x, y;
  820. dst_y = (uint16_t *)p->data[0];
  821. dst_u = (uint16_t *)p->data[1];
  822. dst_v = (uint16_t *)p->data[2];
  823. dst_a = (uint16_t *)p->data[3];
  824. if (get_bits1(gb)) {
  825. for (x = 0; x < avctx->width; x += 2) {
  826. dst_y[x ] = get_bits(gb, 10);
  827. dst_u[x / 2] = get_bits(gb, 10);
  828. dst_y[x + 1] = get_bits(gb, 10);
  829. dst_a[x ] = get_bits(gb, 10);
  830. dst_v[x / 2] = get_bits(gb, 10);
  831. dst_a[x + 1] = get_bits(gb, 10);
  832. }
  833. } else {
  834. int pred[4] = { 502, 512, 512, 502 };
  835. for (x = 0; x < avctx->width; x += 2) {
  836. int y1, y2, u, v, a1, a2;
  837. a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  838. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  839. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  840. a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  841. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  842. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  843. dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
  844. dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
  845. dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
  846. dst_a[x ] = pred[3] = (a1 + pred[3]) & 0x3ff;
  847. dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
  848. dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0x3ff;
  849. }
  850. }
  851. dst_y += p->linesize[0] / 2;
  852. dst_u += p->linesize[1] / 2;
  853. dst_v += p->linesize[2] / 2;
  854. dst_a += p->linesize[3] / 2;
  855. for (y = 1; y < avctx->height; y++) {
  856. if (get_bits1(gb)) {
  857. for (x = 0; x < avctx->width; x += 2) {
  858. dst_y[x ] = get_bits(gb, 10);
  859. dst_u[x / 2] = get_bits(gb, 10);
  860. dst_y[x + 1] = get_bits(gb, 10);
  861. dst_a[x ] = get_bits(gb, 10);
  862. dst_v[x / 2] = get_bits(gb, 10);
  863. dst_a[x + 1] = get_bits(gb, 10);
  864. }
  865. } else {
  866. int pred_TL[6], pred_L[6], pred_T[6];
  867. int y1, y2, u, v, a1, a2;
  868. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
  869. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
  870. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
  871. pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3] / 2];
  872. for (x = 0; x < avctx->width; x += 2) {
  873. pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
  874. pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
  875. pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
  876. pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
  877. pred_T[4] = dst_a[-p->linesize[3] / 2 + x];
  878. pred_T[5] = dst_a[-p->linesize[3] / 2 + x + 1];
  879. a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  880. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  881. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  882. a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  883. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  884. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  885. dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
  886. dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
  887. dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
  888. dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
  889. dst_a[x ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0x3ff;
  890. dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0x3ff;
  891. pred_TL[0] = pred_T[3];
  892. pred_TL[1] = pred_T[1];
  893. pred_TL[2] = pred_T[2];
  894. pred_TL[4] = pred_T[5];
  895. }
  896. }
  897. dst_y += p->linesize[0] / 2;
  898. dst_u += p->linesize[1] / 2;
  899. dst_v += p->linesize[2] / 2;
  900. dst_a += p->linesize[3] / 2;
  901. }
  902. }
  903. static void decode_c82p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  904. {
  905. SheerVideoContext *s = avctx->priv_data;
  906. uint8_t *dst_y, *dst_u, *dst_v, *dst_a;
  907. int x, y;
  908. dst_y = p->data[0];
  909. dst_u = p->data[1];
  910. dst_v = p->data[2];
  911. dst_a = p->data[3];
  912. if (get_bits1(gb)) {
  913. for (x = 0; x < avctx->width; x += 2) {
  914. dst_y[x ] = get_bits(gb, 8);
  915. dst_u[x / 2] = get_bits(gb, 8);
  916. dst_y[x + 1] = get_bits(gb, 8);
  917. dst_a[x ] = get_bits(gb, 8);
  918. dst_v[x / 2] = get_bits(gb, 8);
  919. dst_a[x + 1] = get_bits(gb, 8);
  920. }
  921. } else {
  922. int pred[4] = { -125, 128, 128, 125 };
  923. for (x = 0; x < avctx->width; x += 2) {
  924. int y1, y2, u, v, a1, a2;
  925. a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  926. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  927. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  928. a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  929. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  930. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  931. dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
  932. dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
  933. dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
  934. dst_a[x ] = pred[3] = (a1 + pred[3]) & 0xff;
  935. dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
  936. dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0xff;
  937. }
  938. }
  939. dst_y += p->linesize[0];
  940. dst_u += p->linesize[1];
  941. dst_v += p->linesize[2];
  942. dst_a += p->linesize[3];
  943. for (y = 1; y < avctx->height; y++) {
  944. if (get_bits1(gb)) {
  945. for (x = 0; x < avctx->width; x += 2) {
  946. dst_y[x ] = get_bits(gb, 8);
  947. dst_u[x / 2] = get_bits(gb, 8);
  948. dst_y[x + 1] = get_bits(gb, 8);
  949. dst_a[x ] = get_bits(gb, 8);
  950. dst_v[x / 2] = get_bits(gb, 8);
  951. dst_a[x + 1] = get_bits(gb, 8);
  952. }
  953. } else {
  954. int pred_TL[6], pred_L[6], pred_T[6];
  955. int y1, y2, u, v, a1, a2;
  956. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
  957. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
  958. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
  959. pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3]];
  960. for (x = 0; x < avctx->width; x += 2) {
  961. pred_T[0] = dst_y[-p->linesize[0] + x];
  962. pred_T[3] = dst_y[-p->linesize[0] + x + 1];
  963. pred_T[1] = dst_u[-p->linesize[1] + x / 2];
  964. pred_T[2] = dst_v[-p->linesize[2] + x / 2];
  965. pred_T[4] = dst_a[-p->linesize[3] + x];
  966. pred_T[5] = dst_a[-p->linesize[3] + x + 1];
  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. dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  974. dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
  975. dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
  976. dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
  977. dst_a[x ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0xff;
  978. dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0xff;
  979. pred_TL[0] = pred_T[3];
  980. pred_TL[1] = pred_T[1];
  981. pred_TL[2] = pred_T[2];
  982. pred_TL[4] = pred_T[5];
  983. }
  984. }
  985. dst_y += p->linesize[0];
  986. dst_u += p->linesize[1];
  987. dst_v += p->linesize[2];
  988. dst_a += p->linesize[3];
  989. }
  990. }
  991. static void decode_ybyr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  992. {
  993. SheerVideoContext *s = avctx->priv_data;
  994. uint8_t *dst_y, *dst_u, *dst_v;
  995. int x, y;
  996. dst_y = p->data[0];
  997. dst_u = p->data[1];
  998. dst_v = p->data[2];
  999. if (get_bits1(gb)) {
  1000. for (x = 0; x < avctx->width; x += 2) {
  1001. dst_y[x ] = get_bits(gb, 8);
  1002. dst_u[x / 2] = get_bits(gb, 8);
  1003. dst_y[x + 1] = get_bits(gb, 8);
  1004. dst_v[x / 2] = get_bits(gb, 8);
  1005. }
  1006. } else {
  1007. int pred[4] = { -125, 128, 128, 0 };
  1008. for (x = 0; x < avctx->width; x += 2) {
  1009. int y1, y2, u, v;
  1010. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1011. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1012. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1013. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1014. dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
  1015. dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
  1016. dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
  1017. dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
  1018. }
  1019. }
  1020. dst_y += p->linesize[0];
  1021. dst_u += p->linesize[1];
  1022. dst_v += p->linesize[2];
  1023. for (y = 1; y < avctx->height; y++) {
  1024. if (get_bits1(gb)) {
  1025. for (x = 0; x < avctx->width; x += 2) {
  1026. dst_y[x ] = get_bits(gb, 8);
  1027. dst_u[x / 2] = get_bits(gb, 8);
  1028. dst_y[x + 1] = get_bits(gb, 8);
  1029. dst_v[x / 2] = get_bits(gb, 8);
  1030. }
  1031. } else {
  1032. int pred_TL[4], pred_L[4], pred_T[4];
  1033. int y1, y2, u, v;
  1034. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
  1035. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
  1036. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
  1037. for (x = 0; x < avctx->width; x += 2) {
  1038. pred_T[0] = dst_y[-p->linesize[0] + x];
  1039. pred_T[3] = dst_y[-p->linesize[0] + x + 1];
  1040. pred_T[1] = dst_u[-p->linesize[1] + x / 2];
  1041. pred_T[2] = dst_v[-p->linesize[2] + x / 2];
  1042. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1043. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1044. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1045. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1046. dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  1047. dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
  1048. dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
  1049. dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
  1050. pred_TL[0] = pred_T[3];
  1051. pred_TL[1] = pred_T[1];
  1052. pred_TL[2] = pred_T[2];
  1053. }
  1054. }
  1055. dst_y += p->linesize[0];
  1056. dst_u += p->linesize[1];
  1057. dst_v += p->linesize[2];
  1058. }
  1059. }
  1060. static void decode_byry(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1061. {
  1062. SheerVideoContext *s = avctx->priv_data;
  1063. uint8_t *dst_y, *dst_u, *dst_v;
  1064. int x, y;
  1065. dst_y = p->data[0];
  1066. dst_u = p->data[1];
  1067. dst_v = p->data[2];
  1068. if (get_bits1(gb)) {
  1069. for (x = 0; x < avctx->width; x += 2) {
  1070. dst_y[x ] = get_bits(gb, 8);
  1071. dst_u[x / 2] = get_bits(gb, 8);
  1072. dst_y[x + 1] = get_bits(gb, 8);
  1073. dst_v[x / 2] = get_bits(gb, 8);
  1074. }
  1075. } else {
  1076. int pred[4] = { 125, -128, -128, 0 };
  1077. for (x = 0; x < avctx->width; x += 2) {
  1078. int y1, y2, u, v;
  1079. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1080. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1081. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1082. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1083. dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
  1084. dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
  1085. dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
  1086. dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
  1087. }
  1088. }
  1089. dst_y += p->linesize[0];
  1090. dst_u += p->linesize[1];
  1091. dst_v += p->linesize[2];
  1092. for (y = 1; y < avctx->height; y++) {
  1093. if (get_bits1(gb)) {
  1094. for (x = 0; x < avctx->width; x += 2) {
  1095. dst_y[x ] = get_bits(gb, 8);
  1096. dst_u[x / 2] = get_bits(gb, 8);
  1097. dst_y[x + 1] = get_bits(gb, 8);
  1098. dst_v[x / 2] = get_bits(gb, 8);
  1099. }
  1100. } else {
  1101. int pred_TL[4], pred_L[4], pred_T[4];
  1102. int y1, y2, u, v;
  1103. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
  1104. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
  1105. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
  1106. for (x = 0; x < avctx->width; x += 2) {
  1107. pred_T[0] = dst_y[-p->linesize[0] + x];
  1108. pred_T[3] = dst_y[-p->linesize[0] + x + 1];
  1109. pred_T[1] = dst_u[-p->linesize[1] + x / 2];
  1110. pred_T[2] = dst_v[-p->linesize[2] + x / 2];
  1111. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1112. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1113. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1114. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1115. dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  1116. dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
  1117. dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
  1118. dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
  1119. pred_TL[0] = pred_T[3];
  1120. pred_TL[1] = pred_T[1];
  1121. pred_TL[2] = pred_T[2];
  1122. }
  1123. }
  1124. dst_y += p->linesize[0];
  1125. dst_u += p->linesize[1];
  1126. dst_v += p->linesize[2];
  1127. }
  1128. }
  1129. static void decode_ybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1130. {
  1131. SheerVideoContext *s = avctx->priv_data;
  1132. uint8_t *dst_y, *dst_u, *dst_v;
  1133. int x, y;
  1134. dst_y = p->data[0];
  1135. dst_u = p->data[1];
  1136. dst_v = p->data[2];
  1137. if (get_bits1(gb)) {
  1138. for (x = 0; x < avctx->width; x++) {
  1139. dst_y[x] = get_bits(gb, 8);
  1140. dst_u[x] = get_bits(gb, 8);
  1141. dst_v[x] = get_bits(gb, 8);
  1142. }
  1143. } else {
  1144. int pred[4] = { 125, -128, -128, -128 };
  1145. for (x = 0; x < avctx->width; x++) {
  1146. int y, u, v;
  1147. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1148. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1149. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1150. dst_y[x] = pred[0] = (y + pred[0]) & 0xff;
  1151. dst_u[x] = pred[1] = (u + pred[1]) & 0xff;
  1152. dst_v[x] = pred[2] = (v + pred[2]) & 0xff;
  1153. }
  1154. }
  1155. dst_y += p->linesize[0];
  1156. dst_u += p->linesize[1];
  1157. dst_v += p->linesize[2];
  1158. for (y = 1; y < avctx->height; y++) {
  1159. if (get_bits1(gb)) {
  1160. for (x = 0; x < avctx->width; x++) {
  1161. dst_y[x] = get_bits(gb, 8);
  1162. dst_u[x] = get_bits(gb, 8);
  1163. dst_v[x] = get_bits(gb, 8);
  1164. }
  1165. } else {
  1166. int pred_TL[4], pred_L[4], pred_T[4];
  1167. int y, u, v;
  1168. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
  1169. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
  1170. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
  1171. for (x = 0; x < avctx->width; x++) {
  1172. pred_T[0] = dst_y[-p->linesize[0] + x];
  1173. pred_T[1] = dst_u[-p->linesize[1] + x];
  1174. pred_T[2] = dst_v[-p->linesize[2] + x];
  1175. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1176. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1177. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1178. dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  1179. dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
  1180. dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
  1181. pred_TL[0] = pred_T[0];
  1182. pred_TL[1] = pred_T[1];
  1183. pred_TL[2] = pred_T[2];
  1184. }
  1185. }
  1186. dst_y += p->linesize[0];
  1187. dst_u += p->linesize[1];
  1188. dst_v += p->linesize[2];
  1189. }
  1190. }
  1191. static void decode_aybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1192. {
  1193. SheerVideoContext *s = avctx->priv_data;
  1194. uint8_t *dst_a, *dst_y, *dst_u, *dst_v;
  1195. int x, y;
  1196. dst_a = p->data[3];
  1197. dst_y = p->data[0];
  1198. dst_u = p->data[1];
  1199. dst_v = p->data[2];
  1200. if (get_bits1(gb)) {
  1201. for (x = 0; x < avctx->width; x++) {
  1202. dst_a[x] = get_bits(gb, 8);
  1203. dst_y[x] = get_bits(gb, 8);
  1204. dst_u[x] = get_bits(gb, 8);
  1205. dst_v[x] = get_bits(gb, 8);
  1206. }
  1207. } else {
  1208. int pred[4] = { 125, 125, -128, -128 };
  1209. for (x = 0; x < avctx->width; x++) {
  1210. int a, y, u, v;
  1211. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1212. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1213. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1214. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1215. dst_a[x] = pred[0] = (a + pred[0]) & 0xff;
  1216. dst_y[x] = pred[1] = (y + pred[1]) & 0xff;
  1217. dst_u[x] = pred[2] = (u + pred[2]) & 0xff;
  1218. dst_v[x] = pred[3] = (v + pred[3]) & 0xff;
  1219. }
  1220. }
  1221. dst_a += p->linesize[3];
  1222. dst_y += p->linesize[0];
  1223. dst_u += p->linesize[1];
  1224. dst_v += p->linesize[2];
  1225. for (y = 1; y < avctx->height; y++) {
  1226. if (get_bits1(gb)) {
  1227. for (x = 0; x < avctx->width; x++) {
  1228. dst_a[x] = get_bits(gb, 8);
  1229. dst_y[x] = get_bits(gb, 8);
  1230. dst_u[x] = get_bits(gb, 8);
  1231. dst_v[x] = get_bits(gb, 8);
  1232. }
  1233. } else {
  1234. int pred_TL[4], pred_L[4], pred_T[4];
  1235. int a, y, u, v;
  1236. pred_TL[0] = pred_L[0] = dst_a[-p->linesize[3]];
  1237. pred_TL[1] = pred_L[1] = dst_y[-p->linesize[0]];
  1238. pred_TL[2] = pred_L[2] = dst_u[-p->linesize[1]];
  1239. pred_TL[3] = pred_L[3] = dst_v[-p->linesize[2]];
  1240. for (x = 0; x < avctx->width; x++) {
  1241. pred_T[0] = dst_a[-p->linesize[3] + x];
  1242. pred_T[1] = dst_y[-p->linesize[0] + x];
  1243. pred_T[2] = dst_u[-p->linesize[1] + x];
  1244. pred_T[3] = dst_v[-p->linesize[2] + x];
  1245. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1246. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1247. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1248. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1249. dst_a[x] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  1250. dst_y[x] = pred_L[1] = (y + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
  1251. dst_u[x] = pred_L[2] = (u + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
  1252. dst_v[x] = pred_L[3] = (v + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
  1253. pred_TL[0] = pred_T[0];
  1254. pred_TL[1] = pred_T[1];
  1255. pred_TL[2] = pred_T[2];
  1256. pred_TL[3] = pred_T[3];
  1257. }
  1258. }
  1259. dst_a += p->linesize[3];
  1260. dst_y += p->linesize[0];
  1261. dst_u += p->linesize[1];
  1262. dst_v += p->linesize[2];
  1263. }
  1264. }
  1265. static void decode_argx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1266. {
  1267. SheerVideoContext *s = avctx->priv_data;
  1268. uint16_t *dst_r, *dst_g, *dst_b, *dst_a;
  1269. int x, y;
  1270. dst_r = (uint16_t *)p->data[2];
  1271. dst_g = (uint16_t *)p->data[0];
  1272. dst_b = (uint16_t *)p->data[1];
  1273. dst_a = (uint16_t *)p->data[3];
  1274. if (get_bits1(gb)) {
  1275. for (x = 0; x < avctx->width; x++) {
  1276. dst_a[x] = get_bits(gb, 10);
  1277. dst_r[x] = get_bits(gb, 10);
  1278. dst_g[x] = get_bits(gb, 10);
  1279. dst_b[x] = get_bits(gb, 10);
  1280. }
  1281. } else {
  1282. int pred[4] = { 512, 512, 512, 0 };
  1283. for (x = 0; x < avctx->width; x++) {
  1284. int r, g, b, a;
  1285. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1286. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1287. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1288. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1289. dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
  1290. dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
  1291. dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
  1292. dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
  1293. }
  1294. }
  1295. dst_r += p->linesize[2] / 2;
  1296. dst_g += p->linesize[0] / 2;
  1297. dst_b += p->linesize[1] / 2;
  1298. dst_a += p->linesize[3] / 2;
  1299. for (y = 1; y < avctx->height; y++) {
  1300. if (get_bits1(gb)) {
  1301. for (x = 0; x < avctx->width; x++) {
  1302. dst_a[x] = get_bits(gb, 10);
  1303. dst_r[x] = get_bits(gb, 10);
  1304. dst_g[x] = get_bits(gb, 10);
  1305. dst_b[x] = get_bits(gb, 10);
  1306. }
  1307. } else {
  1308. int pred_TL[4], pred_L[4], pred_T[4];
  1309. int r, g, b, a;
  1310. pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
  1311. pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
  1312. pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
  1313. pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
  1314. for (x = 0; x < avctx->width; x++) {
  1315. pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
  1316. pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
  1317. pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
  1318. pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
  1319. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1320. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1321. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1322. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1323. dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
  1324. dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
  1325. dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
  1326. dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
  1327. pred_TL[0] = pred_T[0];
  1328. pred_TL[1] = pred_T[1];
  1329. pred_TL[2] = pred_T[2];
  1330. pred_TL[3] = pred_T[3];
  1331. }
  1332. }
  1333. dst_r += p->linesize[2] / 2;
  1334. dst_g += p->linesize[0] / 2;
  1335. dst_b += p->linesize[1] / 2;
  1336. dst_a += p->linesize[3] / 2;
  1337. }
  1338. }
  1339. static void decode_rgbx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1340. {
  1341. SheerVideoContext *s = avctx->priv_data;
  1342. uint16_t *dst_r, *dst_g, *dst_b;
  1343. int x, y;
  1344. dst_r = (uint16_t *)p->data[2];
  1345. dst_g = (uint16_t *)p->data[0];
  1346. dst_b = (uint16_t *)p->data[1];
  1347. if (get_bits1(gb)) {
  1348. for (x = 0; x < avctx->width; x++) {
  1349. dst_r[x] = get_bits(gb, 10);
  1350. dst_g[x] = get_bits(gb, 10);
  1351. dst_b[x] = get_bits(gb, 10);
  1352. }
  1353. } else {
  1354. int pred[4] = { 512, 512, 512, 0 };
  1355. for (x = 0; x < avctx->width; x++) {
  1356. int r, g, b;
  1357. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1358. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1359. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1360. dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
  1361. dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
  1362. dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
  1363. }
  1364. }
  1365. dst_r += p->linesize[2] / 2;
  1366. dst_g += p->linesize[0] / 2;
  1367. dst_b += p->linesize[1] / 2;
  1368. for (y = 1; y < avctx->height; y++) {
  1369. if (get_bits1(gb)) {
  1370. for (x = 0; x < avctx->width; x++) {
  1371. dst_r[x] = get_bits(gb, 10);
  1372. dst_g[x] = get_bits(gb, 10);
  1373. dst_b[x] = get_bits(gb, 10);
  1374. }
  1375. } else {
  1376. int pred_TL[4], pred_L[4], pred_T[4];
  1377. int r, g, b;
  1378. pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
  1379. pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
  1380. pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
  1381. for (x = 0; x < avctx->width; x++) {
  1382. pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
  1383. pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
  1384. pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
  1385. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1386. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1387. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1388. dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
  1389. dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
  1390. dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
  1391. pred_TL[0] = pred_T[0];
  1392. pred_TL[1] = pred_T[1];
  1393. pred_TL[2] = pred_T[2];
  1394. }
  1395. }
  1396. dst_r += p->linesize[2] / 2;
  1397. dst_g += p->linesize[0] / 2;
  1398. dst_b += p->linesize[1] / 2;
  1399. }
  1400. }
  1401. static void decode_argbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1402. {
  1403. SheerVideoContext *s = avctx->priv_data;
  1404. uint8_t *dst;
  1405. int x, y;
  1406. dst = p->data[0];
  1407. if (get_bits1(gb)) {
  1408. for (x = 0; x < avctx->width; x++) {
  1409. dst[x * 4 + 0] = get_bits(gb, 8);
  1410. dst[x * 4 + 1] = get_bits(gb, 8);
  1411. dst[x * 4 + 2] = get_bits(gb, 8);
  1412. dst[x * 4 + 3] = get_bits(gb, 8);
  1413. }
  1414. } else {
  1415. int pred[4] = { -128, -128, -128, -128 };
  1416. for (x = 0; x < avctx->width; x++) {
  1417. int a, r, g, b;
  1418. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1419. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1420. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1421. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1422. dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
  1423. dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
  1424. dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
  1425. dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
  1426. }
  1427. }
  1428. dst += p->linesize[0];
  1429. for (y = 1; y < avctx->height; y++) {
  1430. if (get_bits1(gb)) {
  1431. for (x = 0; x < avctx->width; x++) {
  1432. dst[x * 4 + 0] = get_bits(gb, 8);
  1433. dst[x * 4 + 1] = get_bits(gb, 8);
  1434. dst[x * 4 + 2] = get_bits(gb, 8);
  1435. dst[x * 4 + 3] = get_bits(gb, 8);
  1436. }
  1437. } else {
  1438. int pred_L[4];
  1439. int a, r, g, b;
  1440. pred_L[0] = dst[-p->linesize[0] + 0];
  1441. pred_L[1] = dst[-p->linesize[0] + 1];
  1442. pred_L[2] = dst[-p->linesize[0] + 2];
  1443. pred_L[3] = dst[-p->linesize[0] + 3];
  1444. for (x = 0; x < avctx->width; x++) {
  1445. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1446. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1447. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1448. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1449. dst[4 * x + 0] = pred_L[0] = (a + pred_L[0]) & 0xff;
  1450. dst[4 * x + 1] = pred_L[1] = (r + pred_L[1]) & 0xff;
  1451. dst[4 * x + 2] = pred_L[2] = (r + g + pred_L[2]) & 0xff;
  1452. dst[4 * x + 3] = pred_L[3] = (r + g + b + pred_L[3]) & 0xff;
  1453. }
  1454. }
  1455. dst += p->linesize[0];
  1456. }
  1457. }
  1458. static void decode_argb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1459. {
  1460. SheerVideoContext *s = avctx->priv_data;
  1461. uint8_t *dst;
  1462. int x, y;
  1463. dst = p->data[0];
  1464. if (get_bits1(gb)) {
  1465. for (x = 0; x < avctx->width; x++) {
  1466. dst[x * 4 + 0] = get_bits(gb, 8);
  1467. dst[x * 4 + 1] = get_bits(gb, 8);
  1468. dst[x * 4 + 2] = get_bits(gb, 8);
  1469. dst[x * 4 + 3] = get_bits(gb, 8);
  1470. }
  1471. } else {
  1472. int pred[4] = { -128, -128, -128, -128 };
  1473. for (x = 0; x < avctx->width; x++) {
  1474. int a, r, g, b;
  1475. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1476. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1477. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1478. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1479. dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
  1480. dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
  1481. dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
  1482. dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
  1483. }
  1484. }
  1485. dst += p->linesize[0];
  1486. for (y = 1; y < avctx->height; y++) {
  1487. if (get_bits1(gb)) {
  1488. for (x = 0; x < avctx->width; x++) {
  1489. dst[x * 4 + 0] = get_bits(gb, 8);
  1490. dst[x * 4 + 1] = get_bits(gb, 8);
  1491. dst[x * 4 + 2] = get_bits(gb, 8);
  1492. dst[x * 4 + 3] = get_bits(gb, 8);
  1493. }
  1494. } else {
  1495. int pred_TL[4], pred_L[4], pred_T[4];
  1496. int a, r, g, b;
  1497. pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
  1498. pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
  1499. pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
  1500. pred_TL[3] = pred_L[3] = dst[-p->linesize[0] + 3];
  1501. for (x = 0; x < avctx->width; x++) {
  1502. pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
  1503. pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
  1504. pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
  1505. pred_T[3] = dst[-p->linesize[0] + 4 * x + 3];
  1506. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1507. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1508. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1509. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1510. dst[4 * x + 0] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  1511. dst[4 * x + 1] = pred_L[1] = (r + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
  1512. dst[4 * x + 2] = pred_L[2] = (r + g + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
  1513. dst[4 * x + 3] = pred_L[3] = (r + g + b + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
  1514. pred_TL[0] = pred_T[0];
  1515. pred_TL[1] = pred_T[1];
  1516. pred_TL[2] = pred_T[2];
  1517. pred_TL[3] = pred_T[3];
  1518. }
  1519. }
  1520. dst += p->linesize[0];
  1521. }
  1522. }
  1523. static void decode_rgbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1524. {
  1525. SheerVideoContext *s = avctx->priv_data;
  1526. uint8_t *dst;
  1527. int x, y;
  1528. dst = p->data[0];
  1529. if (get_bits1(gb)) {
  1530. for (x = 0; x < avctx->width; x++) {
  1531. dst[x * 4 + 0] = get_bits(gb, 8);
  1532. dst[x * 4 + 1] = get_bits(gb, 8);
  1533. dst[x * 4 + 2] = get_bits(gb, 8);
  1534. }
  1535. } else {
  1536. int pred[4] = { -128, -128, -128, -128 };
  1537. for (x = 0; x < avctx->width; x++) {
  1538. int r, g, b;
  1539. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1540. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1541. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1542. dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
  1543. dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
  1544. dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
  1545. }
  1546. }
  1547. dst += p->linesize[0];
  1548. for (y = 1; y < avctx->height; y++) {
  1549. if (get_bits1(gb)) {
  1550. for (x = 0; x < avctx->width; x++) {
  1551. dst[x * 4 + 0] = get_bits(gb, 8);
  1552. dst[x * 4 + 1] = get_bits(gb, 8);
  1553. dst[x * 4 + 2] = get_bits(gb, 8);
  1554. }
  1555. } else {
  1556. int pred_L[4];
  1557. int r, g, b;
  1558. pred_L[0] = dst[-p->linesize[0] + 0];
  1559. pred_L[1] = dst[-p->linesize[0] + 1];
  1560. pred_L[2] = dst[-p->linesize[0] + 2];
  1561. for (x = 0; x < avctx->width; x++) {
  1562. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1563. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1564. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1565. dst[4 * x + 0] = pred_L[0] = (r + pred_L[0]) & 0xff;
  1566. dst[4 * x + 1] = pred_L[1] = (r + g + pred_L[1]) & 0xff;
  1567. dst[4 * x + 2] = pred_L[2] = (r + g + b + pred_L[2]) & 0xff;
  1568. }
  1569. }
  1570. dst += p->linesize[0];
  1571. }
  1572. }
  1573. static void decode_rgb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1574. {
  1575. SheerVideoContext *s = avctx->priv_data;
  1576. uint8_t *dst;
  1577. int x, y;
  1578. dst = p->data[0];
  1579. if (get_bits1(gb)) {
  1580. for (x = 0; x < avctx->width; x++) {
  1581. dst[x * 4 + 0] = get_bits(gb, 8);
  1582. dst[x * 4 + 1] = get_bits(gb, 8);
  1583. dst[x * 4 + 2] = get_bits(gb, 8);
  1584. }
  1585. } else {
  1586. int pred[4] = { -128, -128, -128, -128 };
  1587. for (x = 0; x < avctx->width; x++) {
  1588. int r, g, b;
  1589. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1590. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1591. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1592. dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
  1593. dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
  1594. dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
  1595. }
  1596. }
  1597. dst += p->linesize[0];
  1598. for (y = 1; y < avctx->height; y++) {
  1599. if (get_bits1(gb)) {
  1600. for (x = 0; x < avctx->width; x++) {
  1601. dst[x * 4 + 0] = get_bits(gb, 8);
  1602. dst[x * 4 + 1] = get_bits(gb, 8);
  1603. dst[x * 4 + 2] = get_bits(gb, 8);
  1604. }
  1605. } else {
  1606. int pred_TL[4], pred_L[4], pred_T[4];
  1607. int r, g, b;
  1608. pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
  1609. pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
  1610. pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
  1611. for (x = 0; x < avctx->width; x++) {
  1612. pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
  1613. pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
  1614. pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
  1615. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1616. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1617. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1618. dst[4 * x + 0] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  1619. dst[4 * x + 1] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
  1620. dst[4 * x + 2] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
  1621. pred_TL[0] = pred_T[0];
  1622. pred_TL[1] = pred_T[1];
  1623. pred_TL[2] = pred_T[2];
  1624. }
  1625. }
  1626. dst += p->linesize[0];
  1627. }
  1628. }
  1629. static int build_vlc(VLC *vlc, const uint8_t *len, int count)
  1630. {
  1631. uint32_t codes[1024];
  1632. uint8_t bits[1024];
  1633. uint16_t syms[1024];
  1634. uint64_t index;
  1635. int i;
  1636. index = 0;
  1637. for (i = 0; i < count; i++) {
  1638. codes[i] = index >> (32 - len[i]);
  1639. bits[i] = len[i];
  1640. syms[i] = i;
  1641. index += 1ULL << (32 - len[i]);
  1642. }
  1643. ff_free_vlc(vlc);
  1644. return ff_init_vlc_sparse(vlc, 16, count,
  1645. bits, sizeof(*bits), sizeof(*bits),
  1646. codes, sizeof(*codes), sizeof(*codes),
  1647. syms, sizeof(*syms), sizeof(*syms), 0);
  1648. }
  1649. static int decode_frame(AVCodecContext *avctx,
  1650. void *data, int *got_frame,
  1651. AVPacket *avpkt)
  1652. {
  1653. SheerVideoContext *s = avctx->priv_data;
  1654. ThreadFrame frame = { .f = data };
  1655. AVFrame *p = data;
  1656. GetBitContext gb;
  1657. unsigned format;
  1658. int ret;
  1659. if (avpkt->size <= 20)
  1660. return AVERROR_INVALIDDATA;
  1661. if (AV_RL32(avpkt->data) != MKTAG('S','h','i','r') &&
  1662. AV_RL32(avpkt->data) != MKTAG('Z','w','a','k'))
  1663. return AVERROR_INVALIDDATA;
  1664. format = AV_RL32(avpkt->data + 16);
  1665. switch (format) {
  1666. case MKTAG(' ', 'R', 'G', 'B'):
  1667. avctx->pix_fmt = AV_PIX_FMT_RGB0;
  1668. s->decode_frame = decode_rgb;
  1669. if (s->format != format) {
  1670. build_vlc(&s->vlc[0], l_r_rgb, 256);
  1671. build_vlc(&s->vlc[1], l_g_rgb, 256);
  1672. }
  1673. break;
  1674. case MKTAG(' ', 'r', 'G', 'B'):
  1675. avctx->pix_fmt = AV_PIX_FMT_RGB0;
  1676. s->decode_frame = decode_rgbi;
  1677. if (s->format != format) {
  1678. build_vlc(&s->vlc[0], l_r_rgbi, 256);
  1679. build_vlc(&s->vlc[1], l_g_rgbi, 256);
  1680. }
  1681. break;
  1682. case MKTAG('A', 'R', 'G', 'X'):
  1683. avctx->pix_fmt = AV_PIX_FMT_GBRAP12;
  1684. s->decode_frame = decode_argx;
  1685. if (s->format != format) {
  1686. build_vlc(&s->vlc[0], l_r_rgbx, 1024);
  1687. build_vlc(&s->vlc[1], l_g_rgbx, 1024);
  1688. }
  1689. break;
  1690. case MKTAG('R', 'G', 'B', 'X'):
  1691. avctx->pix_fmt = AV_PIX_FMT_GBRP10;
  1692. s->decode_frame = decode_rgbx;
  1693. if (s->format != format) {
  1694. build_vlc(&s->vlc[0], l_r_rgbx, 1024);
  1695. build_vlc(&s->vlc[1], l_g_rgbx, 1024);
  1696. }
  1697. break;
  1698. case MKTAG('A', 'R', 'G', 'B'):
  1699. avctx->pix_fmt = AV_PIX_FMT_ARGB;
  1700. s->decode_frame = decode_argb;
  1701. if (s->format != format) {
  1702. build_vlc(&s->vlc[0], l_r_rgb, 256);
  1703. build_vlc(&s->vlc[1], l_g_rgb, 256);
  1704. }
  1705. break;
  1706. case MKTAG('A', 'r', 'G', 'B'):
  1707. avctx->pix_fmt = AV_PIX_FMT_ARGB;
  1708. s->decode_frame = decode_argbi;
  1709. if (s->format != format) {
  1710. build_vlc(&s->vlc[0], l_r_rgbi, 256);
  1711. build_vlc(&s->vlc[1], l_g_rgbi, 256);
  1712. }
  1713. break;
  1714. case MKTAG('A', 'Y', 'b', 'R'):
  1715. avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
  1716. s->decode_frame = decode_aybr;
  1717. if (s->format != format) {
  1718. build_vlc(&s->vlc[0], l_y_ybr, 256);
  1719. build_vlc(&s->vlc[1], l_u_ybr, 256);
  1720. }
  1721. break;
  1722. case MKTAG(' ', 'Y', 'b', 'R'):
  1723. avctx->pix_fmt = AV_PIX_FMT_YUV444P;
  1724. s->decode_frame = decode_ybr;
  1725. if (s->format != format) {
  1726. build_vlc(&s->vlc[0], l_y_ybr, 256);
  1727. build_vlc(&s->vlc[1], l_u_ybr, 256);
  1728. }
  1729. break;
  1730. case MKTAG('Y', 'B', 'R', 0x0a):
  1731. avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
  1732. s->decode_frame = decode_ybr10;
  1733. if (s->format != format) {
  1734. build_vlc(&s->vlc[0], l_y_ybr10, 1024);
  1735. build_vlc(&s->vlc[1], l_u_ybr10, 1024);
  1736. }
  1737. break;
  1738. case MKTAG('C', 'A', '4', 'p'):
  1739. avctx->pix_fmt = AV_PIX_FMT_YUVA444P10;
  1740. s->decode_frame = decode_ca4p;
  1741. if (s->format != format) {
  1742. build_vlc(&s->vlc[0], l_y_ybr10, 1024);
  1743. build_vlc(&s->vlc[1], l_u_ybr10, 1024);
  1744. }
  1745. break;
  1746. case MKTAG('B', 'Y', 'R', 'Y'):
  1747. avctx->pix_fmt = AV_PIX_FMT_YUV422P;
  1748. s->decode_frame = decode_byry;
  1749. if (s->format != format) {
  1750. build_vlc(&s->vlc[0], l_y_byry, 256);
  1751. build_vlc(&s->vlc[1], l_u_byry, 256);
  1752. }
  1753. break;
  1754. case MKTAG('Y', 'b', 'Y', 'r'):
  1755. avctx->pix_fmt = AV_PIX_FMT_YUV422P;
  1756. s->decode_frame = decode_ybyr;
  1757. if (s->format != format) {
  1758. build_vlc(&s->vlc[0], l_y_ybyr, 256);
  1759. build_vlc(&s->vlc[1], l_u_ybyr, 256);
  1760. }
  1761. break;
  1762. case MKTAG('C', '8', '2', 'p'):
  1763. avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
  1764. s->decode_frame = decode_c82p;
  1765. if (s->format != format) {
  1766. build_vlc(&s->vlc[0], l_y_byry, 256);
  1767. build_vlc(&s->vlc[1], l_u_byry, 256);
  1768. }
  1769. break;
  1770. case MKTAG(0xa2, 'Y', 'R', 'Y'):
  1771. avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
  1772. s->decode_frame = decode_yry10;
  1773. if (s->format != format) {
  1774. build_vlc(&s->vlc[0], l_y_yry10, 1024);
  1775. build_vlc(&s->vlc[1], l_u_yry10, 1024);
  1776. }
  1777. break;
  1778. case MKTAG('C', 'A', '2', 'p'):
  1779. avctx->pix_fmt = AV_PIX_FMT_YUVA422P10;
  1780. s->decode_frame = decode_ca2p;
  1781. if (s->format != format) {
  1782. build_vlc(&s->vlc[0], l_y_yry10, 1024);
  1783. build_vlc(&s->vlc[1], l_u_yry10, 1024);
  1784. }
  1785. break;
  1786. default:
  1787. avpriv_request_sample(avctx, "unsupported format: 0x%X", format);
  1788. return AVERROR_PATCHWELCOME;
  1789. }
  1790. s->format = format;
  1791. p->pict_type = AV_PICTURE_TYPE_I;
  1792. p->key_frame = 1;
  1793. if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
  1794. return ret;
  1795. if ((ret = init_get_bits8(&gb, avpkt->data + 20, avpkt->size - 20)) < 0)
  1796. return ret;
  1797. s->decode_frame(avctx, p, &gb);
  1798. *got_frame = 1;
  1799. return avpkt->size;
  1800. }
  1801. #if HAVE_THREADS
  1802. static int decode_init_thread_copy(AVCodecContext *avctx)
  1803. {
  1804. SheerVideoContext *s = avctx->priv_data;
  1805. s->format = 0;
  1806. memset(&s->vlc[0], 0, sizeof(s->vlc[0]));
  1807. memset(&s->vlc[1], 0, sizeof(s->vlc[1]));
  1808. return 0;
  1809. }
  1810. #endif
  1811. static av_cold int decode_end(AVCodecContext *avctx)
  1812. {
  1813. SheerVideoContext *s = avctx->priv_data;
  1814. ff_free_vlc(&s->vlc[0]);
  1815. ff_free_vlc(&s->vlc[1]);
  1816. return 0;
  1817. }
  1818. AVCodec ff_sheervideo_decoder = {
  1819. .name = "sheervideo",
  1820. .long_name = NULL_IF_CONFIG_SMALL("BitJazz SheerVideo"),
  1821. .type = AVMEDIA_TYPE_VIDEO,
  1822. .id = AV_CODEC_ID_SHEERVIDEO,
  1823. .priv_data_size = sizeof(SheerVideoContext),
  1824. .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
  1825. .close = decode_end,
  1826. .decode = decode_frame,
  1827. .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
  1828. };