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.

2262 lines
97KB

  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 const uint8_t l_y_ybri[256] = {
  611. 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8,
  612. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10,
  613. 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
  614. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  615. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
  616. 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  617. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  618. 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  619. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  620. 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  621. 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  622. 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  623. 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  624. 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
  625. 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8,
  626. 8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 3,
  627. };
  628. static const uint8_t l_u_ybri[256] = {
  629. 1, 3, 5, 6, 8, 8, 9, 10, 10, 11, 11, 12, 12, 13, 13, 13,
  630. 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16,
  631. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  632. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  633. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  634. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  635. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  636. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  637. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  638. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  639. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  640. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  641. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  642. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  643. 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14,
  644. 14, 13, 13, 13, 12, 12, 11, 11, 10, 10, 9, 8, 8, 6, 5, 2,
  645. };
  646. static void decode_ca4p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  647. {
  648. SheerVideoContext *s = avctx->priv_data;
  649. uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
  650. int x, y;
  651. dst_a = (uint16_t *)p->data[3];
  652. dst_y = (uint16_t *)p->data[0];
  653. dst_u = (uint16_t *)p->data[1];
  654. dst_v = (uint16_t *)p->data[2];
  655. if (get_bits1(gb)) {
  656. for (x = 0; x < avctx->width; x++) {
  657. dst_a[x] = get_bits(gb, 10);
  658. dst_y[x] = get_bits(gb, 10);
  659. dst_u[x] = get_bits(gb, 10);
  660. dst_v[x] = get_bits(gb, 10);
  661. }
  662. } else {
  663. int pred[4] = { 502, 512, 512, 502 };
  664. for (x = 0; x < avctx->width; x++) {
  665. int y, u, v, a;
  666. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  667. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  668. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  669. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  670. dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
  671. dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
  672. dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
  673. dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
  674. }
  675. }
  676. dst_y += p->linesize[0] / 2;
  677. dst_u += p->linesize[1] / 2;
  678. dst_v += p->linesize[2] / 2;
  679. dst_a += p->linesize[3] / 2;
  680. for (y = 1; y < avctx->height; y++) {
  681. if (get_bits1(gb)) {
  682. for (x = 0; x < avctx->width; x++) {
  683. dst_a[x] = get_bits(gb, 10);
  684. dst_y[x] = get_bits(gb, 10);
  685. dst_u[x] = get_bits(gb, 10);
  686. dst_v[x] = get_bits(gb, 10);
  687. }
  688. } else {
  689. int pred_TL[4], pred_L[4], pred_T[4];
  690. int y, u, v, a;
  691. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
  692. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
  693. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
  694. pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
  695. for (x = 0; x < avctx->width; x++) {
  696. pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
  697. pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
  698. pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
  699. pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
  700. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  701. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  702. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  703. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  704. dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
  705. dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
  706. dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
  707. dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
  708. pred_TL[0] = pred_T[0];
  709. pred_TL[1] = pred_T[1];
  710. pred_TL[2] = pred_T[2];
  711. pred_TL[3] = pred_T[3];
  712. }
  713. }
  714. dst_y += p->linesize[0] / 2;
  715. dst_u += p->linesize[1] / 2;
  716. dst_v += p->linesize[2] / 2;
  717. dst_a += p->linesize[3] / 2;
  718. }
  719. }
  720. static void decode_ybr10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  721. {
  722. SheerVideoContext *s = avctx->priv_data;
  723. uint16_t *dst_y, *dst_u, *dst_v;
  724. int x, y;
  725. dst_y = (uint16_t *)p->data[0];
  726. dst_u = (uint16_t *)p->data[1];
  727. dst_v = (uint16_t *)p->data[2];
  728. if (get_bits1(gb)) {
  729. for (x = 0; x < avctx->width; x++) {
  730. dst_y[x] = get_bits(gb, 10);
  731. dst_u[x] = get_bits(gb, 10);
  732. dst_v[x] = get_bits(gb, 10);
  733. }
  734. } else {
  735. int pred[4] = { 502, 512, 512, 512 };
  736. for (x = 0; x < avctx->width; x++) {
  737. int y, u, v;
  738. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  739. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  740. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  741. dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
  742. dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
  743. dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
  744. }
  745. }
  746. dst_y += p->linesize[0] / 2;
  747. dst_u += p->linesize[1] / 2;
  748. dst_v += p->linesize[2] / 2;
  749. for (y = 1; y < avctx->height; y++) {
  750. if (get_bits1(gb)) {
  751. for (x = 0; x < avctx->width; x++) {
  752. dst_y[x] = get_bits(gb, 10);
  753. dst_u[x] = get_bits(gb, 10);
  754. dst_v[x] = get_bits(gb, 10);
  755. }
  756. } else {
  757. int pred_TL[4], pred_L[4], pred_T[4];
  758. int y, u, v;
  759. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
  760. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
  761. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
  762. for (x = 0; x < avctx->width; x++) {
  763. pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
  764. pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
  765. pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
  766. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  767. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  768. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  769. dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
  770. dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
  771. dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
  772. pred_TL[0] = pred_T[0];
  773. pred_TL[1] = pred_T[1];
  774. pred_TL[2] = pred_T[2];
  775. }
  776. }
  777. dst_y += p->linesize[0] / 2;
  778. dst_u += p->linesize[1] / 2;
  779. dst_v += p->linesize[2] / 2;
  780. }
  781. }
  782. static void decode_yry10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  783. {
  784. SheerVideoContext *s = avctx->priv_data;
  785. uint16_t *dst_y, *dst_u, *dst_v;
  786. int x, y;
  787. dst_y = (uint16_t *)p->data[0];
  788. dst_u = (uint16_t *)p->data[1];
  789. dst_v = (uint16_t *)p->data[2];
  790. if (get_bits1(gb)) {
  791. for (x = 0; x < avctx->width; x += 2) {
  792. dst_y[x ] = get_bits(gb, 10);
  793. dst_u[x / 2] = get_bits(gb, 10);
  794. dst_y[x + 1] = get_bits(gb, 10);
  795. dst_v[x / 2] = get_bits(gb, 10);
  796. }
  797. } else {
  798. int pred[4] = { 502, 512, 512, 0 };
  799. for (x = 0; x < avctx->width; x += 2) {
  800. int y1, y2, u, v;
  801. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  802. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  803. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  804. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  805. dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
  806. dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
  807. dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
  808. dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
  809. }
  810. }
  811. dst_y += p->linesize[0] / 2;
  812. dst_u += p->linesize[1] / 2;
  813. dst_v += p->linesize[2] / 2;
  814. for (y = 1; y < avctx->height; y++) {
  815. if (get_bits1(gb)) {
  816. for (x = 0; x < avctx->width; x += 2) {
  817. dst_y[x ] = get_bits(gb, 10);
  818. dst_u[x / 2] = get_bits(gb, 10);
  819. dst_y[x + 1] = get_bits(gb, 10);
  820. dst_v[x / 2] = get_bits(gb, 10);
  821. }
  822. } else {
  823. int pred_TL[6], pred_L[6], pred_T[6];
  824. int y1, y2, u, v;
  825. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
  826. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
  827. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
  828. for (x = 0; x < avctx->width; x += 2) {
  829. pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
  830. pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
  831. pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
  832. pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
  833. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  834. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  835. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  836. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  837. dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
  838. dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
  839. dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
  840. dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
  841. pred_TL[0] = pred_T[3];
  842. pred_TL[1] = pred_T[1];
  843. pred_TL[2] = pred_T[2];
  844. }
  845. }
  846. dst_y += p->linesize[0] / 2;
  847. dst_u += p->linesize[1] / 2;
  848. dst_v += p->linesize[2] / 2;
  849. }
  850. }
  851. static void decode_ca2p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  852. {
  853. SheerVideoContext *s = avctx->priv_data;
  854. uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
  855. int x, y;
  856. dst_y = (uint16_t *)p->data[0];
  857. dst_u = (uint16_t *)p->data[1];
  858. dst_v = (uint16_t *)p->data[2];
  859. dst_a = (uint16_t *)p->data[3];
  860. if (get_bits1(gb)) {
  861. for (x = 0; x < avctx->width; x += 2) {
  862. dst_a[x ] = get_bits(gb, 10);
  863. dst_y[x ] = get_bits(gb, 10);
  864. dst_u[x / 2] = get_bits(gb, 10);
  865. dst_a[x + 1] = get_bits(gb, 10);
  866. dst_y[x + 1] = get_bits(gb, 10);
  867. dst_v[x / 2] = get_bits(gb, 10);
  868. }
  869. } else {
  870. int pred[4] = { 502, 512, 512, 502 };
  871. for (x = 0; x < avctx->width; x += 2) {
  872. int y1, y2, u, v, a1, a2;
  873. a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  874. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  875. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  876. a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  877. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  878. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  879. dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
  880. dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
  881. dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
  882. dst_a[x ] = pred[3] = (a1 + pred[3]) & 0x3ff;
  883. dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
  884. dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0x3ff;
  885. }
  886. }
  887. dst_y += p->linesize[0] / 2;
  888. dst_u += p->linesize[1] / 2;
  889. dst_v += p->linesize[2] / 2;
  890. dst_a += p->linesize[3] / 2;
  891. for (y = 1; y < avctx->height; y++) {
  892. if (get_bits1(gb)) {
  893. for (x = 0; x < avctx->width; x += 2) {
  894. dst_a[x ] = get_bits(gb, 10);
  895. dst_y[x ] = get_bits(gb, 10);
  896. dst_u[x / 2] = get_bits(gb, 10);
  897. dst_a[x + 1] = get_bits(gb, 10);
  898. dst_y[x + 1] = get_bits(gb, 10);
  899. dst_v[x / 2] = get_bits(gb, 10);
  900. }
  901. } else {
  902. int pred_TL[6], pred_L[6], pred_T[6];
  903. int y1, y2, u, v, a1, a2;
  904. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
  905. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
  906. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
  907. pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3] / 2];
  908. for (x = 0; x < avctx->width; x += 2) {
  909. pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
  910. pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
  911. pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
  912. pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
  913. pred_T[4] = dst_a[-p->linesize[3] / 2 + x];
  914. pred_T[5] = dst_a[-p->linesize[3] / 2 + x + 1];
  915. a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  916. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  917. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  918. a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  919. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  920. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  921. dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
  922. dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
  923. dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
  924. dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
  925. dst_a[x ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0x3ff;
  926. dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0x3ff;
  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. dst_y += p->linesize[0] / 2;
  934. dst_u += p->linesize[1] / 2;
  935. dst_v += p->linesize[2] / 2;
  936. dst_a += p->linesize[3] / 2;
  937. }
  938. }
  939. static void decode_c82p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  940. {
  941. SheerVideoContext *s = avctx->priv_data;
  942. uint8_t *dst_y, *dst_u, *dst_v, *dst_a;
  943. int x, y;
  944. dst_y = p->data[0];
  945. dst_u = p->data[1];
  946. dst_v = p->data[2];
  947. dst_a = p->data[3];
  948. if (get_bits1(gb)) {
  949. for (x = 0; x < avctx->width; x += 2) {
  950. dst_a[x ] = get_bits(gb, 8);
  951. dst_y[x ] = get_bits(gb, 8);
  952. dst_u[x / 2] = get_bits(gb, 8);
  953. dst_a[x + 1] = get_bits(gb, 8);
  954. dst_y[x + 1] = get_bits(gb, 8);
  955. dst_v[x / 2] = get_bits(gb, 8);
  956. }
  957. } else {
  958. int pred[4] = { -125, 128, 128, 125 };
  959. for (x = 0; x < avctx->width; x += 2) {
  960. int y1, y2, u, v, a1, a2;
  961. a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  962. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  963. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  964. a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  965. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  966. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  967. dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
  968. dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
  969. dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
  970. dst_a[x ] = pred[3] = (a1 + pred[3]) & 0xff;
  971. dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
  972. dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0xff;
  973. }
  974. }
  975. dst_y += p->linesize[0];
  976. dst_u += p->linesize[1];
  977. dst_v += p->linesize[2];
  978. dst_a += p->linesize[3];
  979. for (y = 1; y < avctx->height; y++) {
  980. if (get_bits1(gb)) {
  981. for (x = 0; x < avctx->width; x += 2) {
  982. dst_a[x ] = get_bits(gb, 8);
  983. dst_y[x ] = get_bits(gb, 8);
  984. dst_u[x / 2] = get_bits(gb, 8);
  985. dst_a[x + 1] = get_bits(gb, 8);
  986. dst_y[x + 1] = get_bits(gb, 8);
  987. dst_v[x / 2] = get_bits(gb, 8);
  988. }
  989. } else {
  990. int pred_TL[6], pred_L[6], pred_T[6];
  991. int y1, y2, u, v, a1, a2;
  992. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
  993. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
  994. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
  995. pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3]];
  996. for (x = 0; x < avctx->width; x += 2) {
  997. pred_T[0] = dst_y[-p->linesize[0] + x];
  998. pred_T[3] = dst_y[-p->linesize[0] + x + 1];
  999. pred_T[1] = dst_u[-p->linesize[1] + x / 2];
  1000. pred_T[2] = dst_v[-p->linesize[2] + x / 2];
  1001. pred_T[4] = dst_a[-p->linesize[3] + x];
  1002. pred_T[5] = dst_a[-p->linesize[3] + x + 1];
  1003. a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1004. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1005. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1006. a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1007. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1008. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1009. dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  1010. dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
  1011. dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
  1012. dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
  1013. dst_a[x ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0xff;
  1014. dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0xff;
  1015. pred_TL[0] = pred_T[3];
  1016. pred_TL[1] = pred_T[1];
  1017. pred_TL[2] = pred_T[2];
  1018. pred_TL[4] = pred_T[5];
  1019. }
  1020. }
  1021. dst_y += p->linesize[0];
  1022. dst_u += p->linesize[1];
  1023. dst_v += p->linesize[2];
  1024. dst_a += p->linesize[3];
  1025. }
  1026. }
  1027. static void decode_ybyr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1028. {
  1029. SheerVideoContext *s = avctx->priv_data;
  1030. uint8_t *dst_y, *dst_u, *dst_v;
  1031. int x, y;
  1032. dst_y = p->data[0];
  1033. dst_u = p->data[1];
  1034. dst_v = p->data[2];
  1035. if (get_bits1(gb)) {
  1036. for (x = 0; x < avctx->width; x += 2) {
  1037. dst_y[x ] = get_bits(gb, 8);
  1038. dst_u[x / 2] = get_bits(gb, 8);
  1039. dst_y[x + 1] = get_bits(gb, 8);
  1040. dst_v[x / 2] = get_bits(gb, 8);
  1041. }
  1042. } else {
  1043. int pred[4] = { -125, 128, 128, 0 };
  1044. for (x = 0; x < avctx->width; x += 2) {
  1045. int y1, y2, u, v;
  1046. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1047. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1048. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1049. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1050. dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
  1051. dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
  1052. dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
  1053. dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
  1054. }
  1055. }
  1056. dst_y += p->linesize[0];
  1057. dst_u += p->linesize[1];
  1058. dst_v += p->linesize[2];
  1059. for (y = 1; y < avctx->height; y++) {
  1060. if (get_bits1(gb)) {
  1061. for (x = 0; x < avctx->width; x += 2) {
  1062. dst_y[x ] = get_bits(gb, 8);
  1063. dst_u[x / 2] = get_bits(gb, 8);
  1064. dst_y[x + 1] = get_bits(gb, 8);
  1065. dst_v[x / 2] = get_bits(gb, 8);
  1066. }
  1067. } else {
  1068. int pred_TL[4], pred_L[4], pred_T[4];
  1069. int y1, y2, u, v;
  1070. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
  1071. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
  1072. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
  1073. for (x = 0; x < avctx->width; x += 2) {
  1074. pred_T[0] = dst_y[-p->linesize[0] + x];
  1075. pred_T[3] = dst_y[-p->linesize[0] + x + 1];
  1076. pred_T[1] = dst_u[-p->linesize[1] + x / 2];
  1077. pred_T[2] = dst_v[-p->linesize[2] + x / 2];
  1078. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1079. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1080. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1081. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1082. dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  1083. dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
  1084. dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
  1085. dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
  1086. pred_TL[0] = pred_T[3];
  1087. pred_TL[1] = pred_T[1];
  1088. pred_TL[2] = pred_T[2];
  1089. }
  1090. }
  1091. dst_y += p->linesize[0];
  1092. dst_u += p->linesize[1];
  1093. dst_v += p->linesize[2];
  1094. }
  1095. }
  1096. static void decode_byry(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1097. {
  1098. SheerVideoContext *s = avctx->priv_data;
  1099. uint8_t *dst_y, *dst_u, *dst_v;
  1100. int x, y;
  1101. dst_y = p->data[0];
  1102. dst_u = p->data[1];
  1103. dst_v = p->data[2];
  1104. if (get_bits1(gb)) {
  1105. for (x = 0; x < avctx->width; x += 2) {
  1106. dst_y[x ] = get_bits(gb, 8);
  1107. dst_u[x / 2] = get_bits(gb, 8);
  1108. dst_y[x + 1] = get_bits(gb, 8);
  1109. dst_v[x / 2] = get_bits(gb, 8);
  1110. }
  1111. } else {
  1112. int pred[4] = { 125, -128, -128, 0 };
  1113. for (x = 0; x < avctx->width; x += 2) {
  1114. int y1, y2, u, v;
  1115. y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1116. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1117. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1118. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1119. dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
  1120. dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
  1121. dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
  1122. dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
  1123. }
  1124. }
  1125. dst_y += p->linesize[0];
  1126. dst_u += p->linesize[1];
  1127. dst_v += p->linesize[2];
  1128. for (y = 1; y < avctx->height; y++) {
  1129. if (get_bits1(gb)) {
  1130. for (x = 0; x < avctx->width; x += 2) {
  1131. dst_y[x ] = get_bits(gb, 8);
  1132. dst_u[x / 2] = get_bits(gb, 8);
  1133. dst_y[x + 1] = get_bits(gb, 8);
  1134. dst_v[x / 2] = get_bits(gb, 8);
  1135. }
  1136. } else {
  1137. int pred_TL[4], pred_L[4], pred_T[4];
  1138. int y1, y2, u, v;
  1139. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
  1140. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
  1141. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
  1142. for (x = 0; x < avctx->width; x += 2) {
  1143. pred_T[0] = dst_y[-p->linesize[0] + x];
  1144. pred_T[3] = dst_y[-p->linesize[0] + x + 1];
  1145. pred_T[1] = dst_u[-p->linesize[1] + x / 2];
  1146. pred_T[2] = dst_v[-p->linesize[2] + x / 2];
  1147. y1 = 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. y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1150. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1151. dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  1152. dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
  1153. dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
  1154. dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
  1155. pred_TL[0] = pred_T[3];
  1156. pred_TL[1] = pred_T[1];
  1157. pred_TL[2] = pred_T[2];
  1158. }
  1159. }
  1160. dst_y += p->linesize[0];
  1161. dst_u += p->linesize[1];
  1162. dst_v += p->linesize[2];
  1163. }
  1164. }
  1165. static void decode_ybri(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1166. {
  1167. SheerVideoContext *s = avctx->priv_data;
  1168. uint8_t *dst_y, *dst_u, *dst_v;
  1169. int x, y;
  1170. dst_y = p->data[0];
  1171. dst_u = p->data[1];
  1172. dst_v = p->data[2];
  1173. if (get_bits1(gb)) {
  1174. for (x = 0; x < avctx->width; x++) {
  1175. dst_y[x] = get_bits(gb, 8);
  1176. dst_u[x] = get_bits(gb, 8);
  1177. dst_v[x] = get_bits(gb, 8);
  1178. }
  1179. } else {
  1180. int pred[4] = { 125, -128, -128, -128 };
  1181. for (x = 0; x < avctx->width; x++) {
  1182. int y, u, v;
  1183. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1184. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1185. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1186. dst_y[x] = pred[0] = (y + pred[0]) & 0xff;
  1187. dst_u[x] = pred[1] = (u + pred[1]) & 0xff;
  1188. dst_v[x] = pred[2] = (v + pred[2]) & 0xff;
  1189. }
  1190. }
  1191. dst_y += p->linesize[0];
  1192. dst_u += p->linesize[1];
  1193. dst_v += p->linesize[2];
  1194. for (y = 1; y < avctx->height; y++) {
  1195. if (get_bits1(gb)) {
  1196. for (x = 0; x < avctx->width; x++) {
  1197. dst_y[x] = get_bits(gb, 8);
  1198. dst_u[x] = get_bits(gb, 8);
  1199. dst_v[x] = get_bits(gb, 8);
  1200. }
  1201. } else {
  1202. int pred_L[4];
  1203. int y, u, v;
  1204. pred_L[0] = dst_y[-p->linesize[0]];
  1205. pred_L[1] = dst_u[-p->linesize[1]];
  1206. pred_L[2] = dst_v[-p->linesize[2]];
  1207. for (x = 0; x < avctx->width; x++) {
  1208. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1209. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1210. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1211. dst_y[x] = pred_L[0] = (y + pred_L[0]) & 0xff;
  1212. dst_u[x] = pred_L[1] = (u + pred_L[1]) & 0xff;
  1213. dst_v[x] = pred_L[2] = (v + pred_L[2]) & 0xff;
  1214. }
  1215. }
  1216. dst_y += p->linesize[0];
  1217. dst_u += p->linesize[1];
  1218. dst_v += p->linesize[2];
  1219. }
  1220. }
  1221. static void decode_ybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1222. {
  1223. SheerVideoContext *s = avctx->priv_data;
  1224. uint8_t *dst_y, *dst_u, *dst_v;
  1225. int x, y;
  1226. dst_y = p->data[0];
  1227. dst_u = p->data[1];
  1228. dst_v = p->data[2];
  1229. if (get_bits1(gb)) {
  1230. for (x = 0; x < avctx->width; x++) {
  1231. dst_y[x] = get_bits(gb, 8);
  1232. dst_u[x] = get_bits(gb, 8);
  1233. dst_v[x] = get_bits(gb, 8);
  1234. }
  1235. } else {
  1236. int pred[4] = { 125, -128, -128, -128 };
  1237. for (x = 0; x < avctx->width; x++) {
  1238. int y, u, v;
  1239. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1240. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1241. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1242. dst_y[x] = pred[0] = (y + pred[0]) & 0xff;
  1243. dst_u[x] = pred[1] = (u + pred[1]) & 0xff;
  1244. dst_v[x] = pred[2] = (v + pred[2]) & 0xff;
  1245. }
  1246. }
  1247. dst_y += p->linesize[0];
  1248. dst_u += p->linesize[1];
  1249. dst_v += p->linesize[2];
  1250. for (y = 1; y < avctx->height; y++) {
  1251. if (get_bits1(gb)) {
  1252. for (x = 0; x < avctx->width; x++) {
  1253. dst_y[x] = get_bits(gb, 8);
  1254. dst_u[x] = get_bits(gb, 8);
  1255. dst_v[x] = get_bits(gb, 8);
  1256. }
  1257. } else {
  1258. int pred_TL[4], pred_L[4], pred_T[4];
  1259. int y, u, v;
  1260. pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
  1261. pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
  1262. pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
  1263. for (x = 0; x < avctx->width; x++) {
  1264. pred_T[0] = dst_y[-p->linesize[0] + x];
  1265. pred_T[1] = dst_u[-p->linesize[1] + x];
  1266. pred_T[2] = dst_v[-p->linesize[2] + x];
  1267. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1268. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1269. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1270. dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  1271. dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
  1272. dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
  1273. pred_TL[0] = pred_T[0];
  1274. pred_TL[1] = pred_T[1];
  1275. pred_TL[2] = pred_T[2];
  1276. }
  1277. }
  1278. dst_y += p->linesize[0];
  1279. dst_u += p->linesize[1];
  1280. dst_v += p->linesize[2];
  1281. }
  1282. }
  1283. static void decode_aybri(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1284. {
  1285. SheerVideoContext *s = avctx->priv_data;
  1286. uint8_t *dst_a, *dst_y, *dst_u, *dst_v;
  1287. int x, y;
  1288. dst_a = p->data[3];
  1289. dst_y = p->data[0];
  1290. dst_u = p->data[1];
  1291. dst_v = p->data[2];
  1292. if (get_bits1(gb)) {
  1293. for (x = 0; x < avctx->width; x++) {
  1294. dst_a[x] = get_bits(gb, 8);
  1295. dst_y[x] = get_bits(gb, 8);
  1296. dst_u[x] = get_bits(gb, 8);
  1297. dst_v[x] = get_bits(gb, 8);
  1298. }
  1299. } else {
  1300. int pred[4] = { 125, 125, -128, -128 };
  1301. for (x = 0; x < avctx->width; x++) {
  1302. int a, y, u, v;
  1303. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1304. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1305. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1306. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1307. dst_a[x] = pred[0] = (a + pred[0]) & 0xff;
  1308. dst_y[x] = pred[1] = (y + pred[1]) & 0xff;
  1309. dst_u[x] = pred[2] = (u + pred[2]) & 0xff;
  1310. dst_v[x] = pred[3] = (v + pred[3]) & 0xff;
  1311. }
  1312. }
  1313. dst_a += p->linesize[3];
  1314. dst_y += p->linesize[0];
  1315. dst_u += p->linesize[1];
  1316. dst_v += p->linesize[2];
  1317. for (y = 1; y < avctx->height; y++) {
  1318. if (get_bits1(gb)) {
  1319. for (x = 0; x < avctx->width; x++) {
  1320. dst_a[x] = get_bits(gb, 8);
  1321. dst_y[x] = get_bits(gb, 8);
  1322. dst_u[x] = get_bits(gb, 8);
  1323. dst_v[x] = get_bits(gb, 8);
  1324. }
  1325. } else {
  1326. int pred_L[4];
  1327. int a, y, u, v;
  1328. pred_L[0] = dst_a[-p->linesize[3]];
  1329. pred_L[1] = dst_y[-p->linesize[0]];
  1330. pred_L[2] = dst_u[-p->linesize[1]];
  1331. pred_L[3] = dst_v[-p->linesize[2]];
  1332. for (x = 0; x < avctx->width; x++) {
  1333. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1334. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1335. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1336. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1337. dst_a[x] = pred_L[0] = (a + pred_L[0]) & 0xff;
  1338. dst_y[x] = pred_L[1] = (y + pred_L[1]) & 0xff;
  1339. dst_u[x] = pred_L[2] = (u + pred_L[2]) & 0xff;
  1340. dst_v[x] = pred_L[3] = (v + pred_L[3]) & 0xff;
  1341. }
  1342. }
  1343. dst_a += p->linesize[3];
  1344. dst_y += p->linesize[0];
  1345. dst_u += p->linesize[1];
  1346. dst_v += p->linesize[2];
  1347. }
  1348. }
  1349. static void decode_aybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1350. {
  1351. SheerVideoContext *s = avctx->priv_data;
  1352. uint8_t *dst_a, *dst_y, *dst_u, *dst_v;
  1353. int x, y;
  1354. dst_a = p->data[3];
  1355. dst_y = p->data[0];
  1356. dst_u = p->data[1];
  1357. dst_v = p->data[2];
  1358. if (get_bits1(gb)) {
  1359. for (x = 0; x < avctx->width; x++) {
  1360. dst_a[x] = get_bits(gb, 8);
  1361. dst_y[x] = get_bits(gb, 8);
  1362. dst_u[x] = get_bits(gb, 8);
  1363. dst_v[x] = get_bits(gb, 8);
  1364. }
  1365. } else {
  1366. int pred[4] = { 125, 125, -128, -128 };
  1367. for (x = 0; x < avctx->width; x++) {
  1368. int a, y, u, v;
  1369. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1370. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1371. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1372. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1373. dst_a[x] = pred[0] = (a + pred[0]) & 0xff;
  1374. dst_y[x] = pred[1] = (y + pred[1]) & 0xff;
  1375. dst_u[x] = pred[2] = (u + pred[2]) & 0xff;
  1376. dst_v[x] = pred[3] = (v + pred[3]) & 0xff;
  1377. }
  1378. }
  1379. dst_a += p->linesize[3];
  1380. dst_y += p->linesize[0];
  1381. dst_u += p->linesize[1];
  1382. dst_v += p->linesize[2];
  1383. for (y = 1; y < avctx->height; y++) {
  1384. if (get_bits1(gb)) {
  1385. for (x = 0; x < avctx->width; x++) {
  1386. dst_a[x] = get_bits(gb, 8);
  1387. dst_y[x] = get_bits(gb, 8);
  1388. dst_u[x] = get_bits(gb, 8);
  1389. dst_v[x] = get_bits(gb, 8);
  1390. }
  1391. } else {
  1392. int pred_TL[4], pred_L[4], pred_T[4];
  1393. int a, y, u, v;
  1394. pred_TL[0] = pred_L[0] = dst_a[-p->linesize[3]];
  1395. pred_TL[1] = pred_L[1] = dst_y[-p->linesize[0]];
  1396. pred_TL[2] = pred_L[2] = dst_u[-p->linesize[1]];
  1397. pred_TL[3] = pred_L[3] = dst_v[-p->linesize[2]];
  1398. for (x = 0; x < avctx->width; x++) {
  1399. pred_T[0] = dst_a[-p->linesize[3] + x];
  1400. pred_T[1] = dst_y[-p->linesize[0] + x];
  1401. pred_T[2] = dst_u[-p->linesize[1] + x];
  1402. pred_T[3] = dst_v[-p->linesize[2] + x];
  1403. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1404. y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1405. u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1406. v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1407. dst_a[x] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  1408. dst_y[x] = pred_L[1] = (y + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
  1409. dst_u[x] = pred_L[2] = (u + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
  1410. dst_v[x] = pred_L[3] = (v + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
  1411. pred_TL[0] = pred_T[0];
  1412. pred_TL[1] = pred_T[1];
  1413. pred_TL[2] = pred_T[2];
  1414. pred_TL[3] = pred_T[3];
  1415. }
  1416. }
  1417. dst_a += p->linesize[3];
  1418. dst_y += p->linesize[0];
  1419. dst_u += p->linesize[1];
  1420. dst_v += p->linesize[2];
  1421. }
  1422. }
  1423. static void decode_argx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1424. {
  1425. SheerVideoContext *s = avctx->priv_data;
  1426. uint16_t *dst_r, *dst_g, *dst_b, *dst_a;
  1427. int x, y;
  1428. dst_r = (uint16_t *)p->data[2];
  1429. dst_g = (uint16_t *)p->data[0];
  1430. dst_b = (uint16_t *)p->data[1];
  1431. dst_a = (uint16_t *)p->data[3];
  1432. if (get_bits1(gb)) {
  1433. for (x = 0; x < avctx->width; x++) {
  1434. dst_a[x] = get_bits(gb, 10);
  1435. dst_r[x] = get_bits(gb, 10);
  1436. dst_g[x] = get_bits(gb, 10);
  1437. dst_b[x] = get_bits(gb, 10);
  1438. }
  1439. } else {
  1440. int pred[4] = { 512, 512, 512, 0 };
  1441. for (x = 0; x < avctx->width; x++) {
  1442. int r, g, b, a;
  1443. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1444. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1445. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1446. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1447. dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
  1448. dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
  1449. dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
  1450. dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
  1451. }
  1452. }
  1453. dst_r += p->linesize[2] / 2;
  1454. dst_g += p->linesize[0] / 2;
  1455. dst_b += p->linesize[1] / 2;
  1456. dst_a += p->linesize[3] / 2;
  1457. for (y = 1; y < avctx->height; y++) {
  1458. if (get_bits1(gb)) {
  1459. for (x = 0; x < avctx->width; x++) {
  1460. dst_a[x] = get_bits(gb, 10);
  1461. dst_r[x] = get_bits(gb, 10);
  1462. dst_g[x] = get_bits(gb, 10);
  1463. dst_b[x] = get_bits(gb, 10);
  1464. }
  1465. } else {
  1466. int pred_TL[4], pred_L[4], pred_T[4];
  1467. int r, g, b, a;
  1468. pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
  1469. pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
  1470. pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
  1471. pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
  1472. for (x = 0; x < avctx->width; x++) {
  1473. pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
  1474. pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
  1475. pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
  1476. pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
  1477. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1478. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1479. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1480. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1481. dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
  1482. dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
  1483. dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
  1484. dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
  1485. pred_TL[0] = pred_T[0];
  1486. pred_TL[1] = pred_T[1];
  1487. pred_TL[2] = pred_T[2];
  1488. pred_TL[3] = pred_T[3];
  1489. }
  1490. }
  1491. dst_r += p->linesize[2] / 2;
  1492. dst_g += p->linesize[0] / 2;
  1493. dst_b += p->linesize[1] / 2;
  1494. dst_a += p->linesize[3] / 2;
  1495. }
  1496. }
  1497. static void decode_rgbx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1498. {
  1499. SheerVideoContext *s = avctx->priv_data;
  1500. uint16_t *dst_r, *dst_g, *dst_b;
  1501. int x, y;
  1502. dst_r = (uint16_t *)p->data[2];
  1503. dst_g = (uint16_t *)p->data[0];
  1504. dst_b = (uint16_t *)p->data[1];
  1505. if (get_bits1(gb)) {
  1506. for (x = 0; x < avctx->width; x++) {
  1507. dst_r[x] = get_bits(gb, 10);
  1508. dst_g[x] = get_bits(gb, 10);
  1509. dst_b[x] = get_bits(gb, 10);
  1510. }
  1511. } else {
  1512. int pred[4] = { 512, 512, 512, 0 };
  1513. for (x = 0; x < avctx->width; x++) {
  1514. int r, g, b;
  1515. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1516. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1517. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1518. dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
  1519. dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
  1520. dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
  1521. }
  1522. }
  1523. dst_r += p->linesize[2] / 2;
  1524. dst_g += p->linesize[0] / 2;
  1525. dst_b += p->linesize[1] / 2;
  1526. for (y = 1; y < avctx->height; y++) {
  1527. if (get_bits1(gb)) {
  1528. for (x = 0; x < avctx->width; x++) {
  1529. dst_r[x] = get_bits(gb, 10);
  1530. dst_g[x] = get_bits(gb, 10);
  1531. dst_b[x] = get_bits(gb, 10);
  1532. }
  1533. } else {
  1534. int pred_TL[4], pred_L[4], pred_T[4];
  1535. int r, g, b;
  1536. pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
  1537. pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
  1538. pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
  1539. for (x = 0; x < avctx->width; x++) {
  1540. pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
  1541. pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
  1542. pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
  1543. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1544. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1545. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1546. dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
  1547. dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
  1548. dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
  1549. pred_TL[0] = pred_T[0];
  1550. pred_TL[1] = pred_T[1];
  1551. pred_TL[2] = pred_T[2];
  1552. }
  1553. }
  1554. dst_r += p->linesize[2] / 2;
  1555. dst_g += p->linesize[0] / 2;
  1556. dst_b += p->linesize[1] / 2;
  1557. }
  1558. }
  1559. static void decode_argbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1560. {
  1561. SheerVideoContext *s = avctx->priv_data;
  1562. uint8_t *dst;
  1563. int x, y;
  1564. dst = p->data[0];
  1565. if (get_bits1(gb)) {
  1566. for (x = 0; x < avctx->width; x++) {
  1567. dst[x * 4 + 0] = get_bits(gb, 8);
  1568. dst[x * 4 + 1] = get_bits(gb, 8);
  1569. dst[x * 4 + 2] = get_bits(gb, 8);
  1570. dst[x * 4 + 3] = get_bits(gb, 8);
  1571. }
  1572. } else {
  1573. int pred[4] = { -128, -128, -128, -128 };
  1574. for (x = 0; x < avctx->width; x++) {
  1575. int a, r, g, b;
  1576. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1577. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1578. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1579. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1580. dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
  1581. dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
  1582. dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
  1583. dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
  1584. }
  1585. }
  1586. dst += p->linesize[0];
  1587. for (y = 1; y < avctx->height; y++) {
  1588. if (get_bits1(gb)) {
  1589. for (x = 0; x < avctx->width; x++) {
  1590. dst[x * 4 + 0] = get_bits(gb, 8);
  1591. dst[x * 4 + 1] = get_bits(gb, 8);
  1592. dst[x * 4 + 2] = get_bits(gb, 8);
  1593. dst[x * 4 + 3] = get_bits(gb, 8);
  1594. }
  1595. } else {
  1596. int pred_L[4];
  1597. int a, r, g, b;
  1598. pred_L[0] = dst[-p->linesize[0] + 0];
  1599. pred_L[1] = dst[-p->linesize[0] + 1];
  1600. pred_L[2] = dst[-p->linesize[0] + 2];
  1601. pred_L[3] = dst[-p->linesize[0] + 3];
  1602. for (x = 0; x < avctx->width; x++) {
  1603. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1604. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1605. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1606. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1607. dst[4 * x + 0] = pred_L[0] = (a + pred_L[0]) & 0xff;
  1608. dst[4 * x + 1] = pred_L[1] = (r + pred_L[1]) & 0xff;
  1609. dst[4 * x + 2] = pred_L[2] = (r + g + pred_L[2]) & 0xff;
  1610. dst[4 * x + 3] = pred_L[3] = (r + g + b + pred_L[3]) & 0xff;
  1611. }
  1612. }
  1613. dst += p->linesize[0];
  1614. }
  1615. }
  1616. static void decode_argb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1617. {
  1618. SheerVideoContext *s = avctx->priv_data;
  1619. uint8_t *dst;
  1620. int x, y;
  1621. dst = p->data[0];
  1622. if (get_bits1(gb)) {
  1623. for (x = 0; x < avctx->width; x++) {
  1624. dst[x * 4 + 0] = get_bits(gb, 8);
  1625. dst[x * 4 + 1] = get_bits(gb, 8);
  1626. dst[x * 4 + 2] = get_bits(gb, 8);
  1627. dst[x * 4 + 3] = get_bits(gb, 8);
  1628. }
  1629. } else {
  1630. int pred[4] = { -128, -128, -128, -128 };
  1631. for (x = 0; x < avctx->width; x++) {
  1632. int a, r, g, b;
  1633. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1634. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1635. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1636. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1637. dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
  1638. dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
  1639. dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
  1640. dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
  1641. }
  1642. }
  1643. dst += p->linesize[0];
  1644. for (y = 1; y < avctx->height; y++) {
  1645. if (get_bits1(gb)) {
  1646. for (x = 0; x < avctx->width; x++) {
  1647. dst[x * 4 + 0] = get_bits(gb, 8);
  1648. dst[x * 4 + 1] = get_bits(gb, 8);
  1649. dst[x * 4 + 2] = get_bits(gb, 8);
  1650. dst[x * 4 + 3] = get_bits(gb, 8);
  1651. }
  1652. } else {
  1653. int pred_TL[4], pred_L[4], pred_T[4];
  1654. int a, r, g, b;
  1655. pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
  1656. pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
  1657. pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
  1658. pred_TL[3] = pred_L[3] = dst[-p->linesize[0] + 3];
  1659. for (x = 0; x < avctx->width; x++) {
  1660. pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
  1661. pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
  1662. pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
  1663. pred_T[3] = dst[-p->linesize[0] + 4 * x + 3];
  1664. a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1665. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1666. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1667. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1668. dst[4 * x + 0] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  1669. dst[4 * x + 1] = pred_L[1] = (r + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
  1670. dst[4 * x + 2] = pred_L[2] = (r + g + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
  1671. dst[4 * x + 3] = pred_L[3] = (r + g + b + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
  1672. pred_TL[0] = pred_T[0];
  1673. pred_TL[1] = pred_T[1];
  1674. pred_TL[2] = pred_T[2];
  1675. pred_TL[3] = pred_T[3];
  1676. }
  1677. }
  1678. dst += p->linesize[0];
  1679. }
  1680. }
  1681. static void decode_rgbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1682. {
  1683. SheerVideoContext *s = avctx->priv_data;
  1684. uint8_t *dst;
  1685. int x, y;
  1686. dst = p->data[0];
  1687. if (get_bits1(gb)) {
  1688. for (x = 0; x < avctx->width; x++) {
  1689. dst[x * 4 + 0] = get_bits(gb, 8);
  1690. dst[x * 4 + 1] = get_bits(gb, 8);
  1691. dst[x * 4 + 2] = get_bits(gb, 8);
  1692. }
  1693. } else {
  1694. int pred[4] = { -128, -128, -128, -128 };
  1695. for (x = 0; x < avctx->width; x++) {
  1696. int r, g, b;
  1697. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1698. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1699. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1700. dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
  1701. dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
  1702. dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
  1703. }
  1704. }
  1705. dst += p->linesize[0];
  1706. for (y = 1; y < avctx->height; y++) {
  1707. if (get_bits1(gb)) {
  1708. for (x = 0; x < avctx->width; x++) {
  1709. dst[x * 4 + 0] = get_bits(gb, 8);
  1710. dst[x * 4 + 1] = get_bits(gb, 8);
  1711. dst[x * 4 + 2] = get_bits(gb, 8);
  1712. }
  1713. } else {
  1714. int pred_L[4];
  1715. int r, g, b;
  1716. pred_L[0] = dst[-p->linesize[0] + 0];
  1717. pred_L[1] = dst[-p->linesize[0] + 1];
  1718. pred_L[2] = dst[-p->linesize[0] + 2];
  1719. for (x = 0; x < avctx->width; x++) {
  1720. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1721. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1722. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1723. dst[4 * x + 0] = pred_L[0] = (r + pred_L[0]) & 0xff;
  1724. dst[4 * x + 1] = pred_L[1] = (r + g + pred_L[1]) & 0xff;
  1725. dst[4 * x + 2] = pred_L[2] = (r + g + b + pred_L[2]) & 0xff;
  1726. }
  1727. }
  1728. dst += p->linesize[0];
  1729. }
  1730. }
  1731. static void decode_rgb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
  1732. {
  1733. SheerVideoContext *s = avctx->priv_data;
  1734. uint8_t *dst;
  1735. int x, y;
  1736. dst = p->data[0];
  1737. if (get_bits1(gb)) {
  1738. for (x = 0; x < avctx->width; x++) {
  1739. dst[x * 4 + 0] = get_bits(gb, 8);
  1740. dst[x * 4 + 1] = get_bits(gb, 8);
  1741. dst[x * 4 + 2] = get_bits(gb, 8);
  1742. }
  1743. } else {
  1744. int pred[4] = { -128, -128, -128, -128 };
  1745. for (x = 0; x < avctx->width; x++) {
  1746. int r, g, b;
  1747. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1748. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1749. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1750. dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
  1751. dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
  1752. dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
  1753. }
  1754. }
  1755. dst += p->linesize[0];
  1756. for (y = 1; y < avctx->height; y++) {
  1757. if (get_bits1(gb)) {
  1758. for (x = 0; x < avctx->width; x++) {
  1759. dst[x * 4 + 0] = get_bits(gb, 8);
  1760. dst[x * 4 + 1] = get_bits(gb, 8);
  1761. dst[x * 4 + 2] = get_bits(gb, 8);
  1762. }
  1763. } else {
  1764. int pred_TL[4], pred_L[4], pred_T[4];
  1765. int r, g, b;
  1766. pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
  1767. pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
  1768. pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
  1769. for (x = 0; x < avctx->width; x++) {
  1770. pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
  1771. pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
  1772. pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
  1773. r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
  1774. g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1775. b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
  1776. dst[4 * x + 0] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
  1777. dst[4 * x + 1] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
  1778. dst[4 * x + 2] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
  1779. pred_TL[0] = pred_T[0];
  1780. pred_TL[1] = pred_T[1];
  1781. pred_TL[2] = pred_T[2];
  1782. }
  1783. }
  1784. dst += p->linesize[0];
  1785. }
  1786. }
  1787. static int build_vlc(VLC *vlc, const uint8_t *len, int count)
  1788. {
  1789. uint32_t codes[1024];
  1790. uint8_t bits[1024];
  1791. uint16_t syms[1024];
  1792. uint64_t index;
  1793. int i;
  1794. index = 0;
  1795. for (i = 0; i < count; i++) {
  1796. codes[i] = index >> (32 - len[i]);
  1797. bits[i] = len[i];
  1798. syms[i] = i;
  1799. index += 1ULL << (32 - len[i]);
  1800. }
  1801. ff_free_vlc(vlc);
  1802. return ff_init_vlc_sparse(vlc, 16, count,
  1803. bits, sizeof(*bits), sizeof(*bits),
  1804. codes, sizeof(*codes), sizeof(*codes),
  1805. syms, sizeof(*syms), sizeof(*syms), 0);
  1806. }
  1807. static int decode_frame(AVCodecContext *avctx,
  1808. void *data, int *got_frame,
  1809. AVPacket *avpkt)
  1810. {
  1811. SheerVideoContext *s = avctx->priv_data;
  1812. ThreadFrame frame = { .f = data };
  1813. AVFrame *p = data;
  1814. GetBitContext gb;
  1815. unsigned format;
  1816. int ret;
  1817. if (avpkt->size <= 20)
  1818. return AVERROR_INVALIDDATA;
  1819. if (AV_RL32(avpkt->data) != MKTAG('S','h','i','r') &&
  1820. AV_RL32(avpkt->data) != MKTAG('Z','w','a','k'))
  1821. return AVERROR_INVALIDDATA;
  1822. format = AV_RL32(avpkt->data + 16);
  1823. switch (format) {
  1824. case MKTAG(' ', 'R', 'G', 'B'):
  1825. avctx->pix_fmt = AV_PIX_FMT_RGB0;
  1826. s->decode_frame = decode_rgb;
  1827. if (s->format != format) {
  1828. build_vlc(&s->vlc[0], l_r_rgb, 256);
  1829. build_vlc(&s->vlc[1], l_g_rgb, 256);
  1830. }
  1831. break;
  1832. case MKTAG(' ', 'r', 'G', 'B'):
  1833. avctx->pix_fmt = AV_PIX_FMT_RGB0;
  1834. s->decode_frame = decode_rgbi;
  1835. if (s->format != format) {
  1836. build_vlc(&s->vlc[0], l_r_rgbi, 256);
  1837. build_vlc(&s->vlc[1], l_g_rgbi, 256);
  1838. }
  1839. break;
  1840. case MKTAG('A', 'R', 'G', 'X'):
  1841. avctx->pix_fmt = AV_PIX_FMT_GBRAP12;
  1842. s->decode_frame = decode_argx;
  1843. if (s->format != format) {
  1844. build_vlc(&s->vlc[0], l_r_rgbx, 1024);
  1845. build_vlc(&s->vlc[1], l_g_rgbx, 1024);
  1846. }
  1847. break;
  1848. case MKTAG('R', 'G', 'B', 'X'):
  1849. avctx->pix_fmt = AV_PIX_FMT_GBRP10;
  1850. s->decode_frame = decode_rgbx;
  1851. if (s->format != format) {
  1852. build_vlc(&s->vlc[0], l_r_rgbx, 1024);
  1853. build_vlc(&s->vlc[1], l_g_rgbx, 1024);
  1854. }
  1855. break;
  1856. case MKTAG('A', 'R', 'G', 'B'):
  1857. avctx->pix_fmt = AV_PIX_FMT_ARGB;
  1858. s->decode_frame = decode_argb;
  1859. if (s->format != format) {
  1860. build_vlc(&s->vlc[0], l_r_rgb, 256);
  1861. build_vlc(&s->vlc[1], l_g_rgb, 256);
  1862. }
  1863. break;
  1864. case MKTAG('A', 'r', 'G', 'B'):
  1865. avctx->pix_fmt = AV_PIX_FMT_ARGB;
  1866. s->decode_frame = decode_argbi;
  1867. if (s->format != format) {
  1868. build_vlc(&s->vlc[0], l_r_rgbi, 256);
  1869. build_vlc(&s->vlc[1], l_g_rgbi, 256);
  1870. }
  1871. break;
  1872. case MKTAG('A', 'Y', 'b', 'R'):
  1873. avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
  1874. s->decode_frame = decode_aybr;
  1875. if (s->format != format) {
  1876. build_vlc(&s->vlc[0], l_y_ybr, 256);
  1877. build_vlc(&s->vlc[1], l_u_ybr, 256);
  1878. }
  1879. break;
  1880. case MKTAG('A', 'y', 'b', 'R'):
  1881. avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
  1882. s->decode_frame = decode_aybri;
  1883. if (s->format != format) {
  1884. build_vlc(&s->vlc[0], l_y_ybri, 256);
  1885. build_vlc(&s->vlc[1], l_u_ybri, 256);
  1886. }
  1887. break;
  1888. case MKTAG(' ', 'Y', 'b', 'R'):
  1889. avctx->pix_fmt = AV_PIX_FMT_YUV444P;
  1890. s->decode_frame = decode_ybr;
  1891. if (s->format != format) {
  1892. build_vlc(&s->vlc[0], l_y_ybr, 256);
  1893. build_vlc(&s->vlc[1], l_u_ybr, 256);
  1894. }
  1895. break;
  1896. case MKTAG(' ', 'y', 'b', 'R'):
  1897. avctx->pix_fmt = AV_PIX_FMT_YUV444P;
  1898. s->decode_frame = decode_ybri;
  1899. if (s->format != format) {
  1900. build_vlc(&s->vlc[0], l_y_ybri, 256);
  1901. build_vlc(&s->vlc[1], l_u_ybri, 256);
  1902. }
  1903. break;
  1904. case MKTAG('Y', 'B', 'R', 0x0a):
  1905. avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
  1906. s->decode_frame = decode_ybr10;
  1907. if (s->format != format) {
  1908. build_vlc(&s->vlc[0], l_y_ybr10, 1024);
  1909. build_vlc(&s->vlc[1], l_u_ybr10, 1024);
  1910. }
  1911. break;
  1912. case MKTAG('C', 'A', '4', 'p'):
  1913. avctx->pix_fmt = AV_PIX_FMT_YUVA444P10;
  1914. s->decode_frame = decode_ca4p;
  1915. if (s->format != format) {
  1916. build_vlc(&s->vlc[0], l_y_ybr10, 1024);
  1917. build_vlc(&s->vlc[1], l_u_ybr10, 1024);
  1918. }
  1919. break;
  1920. case MKTAG('B', 'Y', 'R', 'Y'):
  1921. avctx->pix_fmt = AV_PIX_FMT_YUV422P;
  1922. s->decode_frame = decode_byry;
  1923. if (s->format != format) {
  1924. build_vlc(&s->vlc[0], l_y_byry, 256);
  1925. build_vlc(&s->vlc[1], l_u_byry, 256);
  1926. }
  1927. break;
  1928. case MKTAG('Y', 'b', 'Y', 'r'):
  1929. avctx->pix_fmt = AV_PIX_FMT_YUV422P;
  1930. s->decode_frame = decode_ybyr;
  1931. if (s->format != format) {
  1932. build_vlc(&s->vlc[0], l_y_ybyr, 256);
  1933. build_vlc(&s->vlc[1], l_u_ybyr, 256);
  1934. }
  1935. break;
  1936. case MKTAG('C', '8', '2', 'p'):
  1937. avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
  1938. s->decode_frame = decode_c82p;
  1939. if (s->format != format) {
  1940. build_vlc(&s->vlc[0], l_y_byry, 256);
  1941. build_vlc(&s->vlc[1], l_u_byry, 256);
  1942. }
  1943. break;
  1944. case MKTAG(0xa2, 'Y', 'R', 'Y'):
  1945. avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
  1946. s->decode_frame = decode_yry10;
  1947. if (s->format != format) {
  1948. build_vlc(&s->vlc[0], l_y_yry10, 1024);
  1949. build_vlc(&s->vlc[1], l_u_yry10, 1024);
  1950. }
  1951. break;
  1952. case MKTAG('C', 'A', '2', 'p'):
  1953. avctx->pix_fmt = AV_PIX_FMT_YUVA422P10;
  1954. s->decode_frame = decode_ca2p;
  1955. if (s->format != format) {
  1956. build_vlc(&s->vlc[0], l_y_yry10, 1024);
  1957. build_vlc(&s->vlc[1], l_u_yry10, 1024);
  1958. }
  1959. break;
  1960. default:
  1961. avpriv_request_sample(avctx, "unsupported format: 0x%X", format);
  1962. return AVERROR_PATCHWELCOME;
  1963. }
  1964. s->format = format;
  1965. p->pict_type = AV_PICTURE_TYPE_I;
  1966. p->key_frame = 1;
  1967. if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
  1968. return ret;
  1969. if ((ret = init_get_bits8(&gb, avpkt->data + 20, avpkt->size - 20)) < 0)
  1970. return ret;
  1971. s->decode_frame(avctx, p, &gb);
  1972. *got_frame = 1;
  1973. return avpkt->size;
  1974. }
  1975. #if HAVE_THREADS
  1976. static int decode_init_thread_copy(AVCodecContext *avctx)
  1977. {
  1978. SheerVideoContext *s = avctx->priv_data;
  1979. s->format = 0;
  1980. memset(&s->vlc[0], 0, sizeof(s->vlc[0]));
  1981. memset(&s->vlc[1], 0, sizeof(s->vlc[1]));
  1982. return 0;
  1983. }
  1984. #endif
  1985. static av_cold int decode_end(AVCodecContext *avctx)
  1986. {
  1987. SheerVideoContext *s = avctx->priv_data;
  1988. ff_free_vlc(&s->vlc[0]);
  1989. ff_free_vlc(&s->vlc[1]);
  1990. return 0;
  1991. }
  1992. AVCodec ff_sheervideo_decoder = {
  1993. .name = "sheervideo",
  1994. .long_name = NULL_IF_CONFIG_SMALL("BitJazz SheerVideo"),
  1995. .type = AVMEDIA_TYPE_VIDEO,
  1996. .id = AV_CODEC_ID_SHEERVIDEO,
  1997. .priv_data_size = sizeof(SheerVideoContext),
  1998. .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
  1999. .close = decode_end,
  2000. .decode = decode_frame,
  2001. .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
  2002. };