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.

1697 lines
63KB

  1. /*
  2. * HEVC video decoder
  3. *
  4. * Copyright (C) 2012 - 2013 Guillaume Martres
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "get_bits.h"
  23. #include "hevc.h"
  24. #include "bit_depth_template.c"
  25. #include "hevcdsp.h"
  26. static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int width, int height,
  27. GetBitContext *gb, int pcm_bit_depth)
  28. {
  29. int x, y;
  30. pixel *dst = (pixel *)_dst;
  31. stride /= sizeof(pixel);
  32. for (y = 0; y < height; y++) {
  33. for (x = 0; x < width; x++)
  34. dst[x] = get_bits(gb, pcm_bit_depth) << (BIT_DEPTH - pcm_bit_depth);
  35. dst += stride;
  36. }
  37. }
  38. static av_always_inline void FUNC(transquant_bypass)(uint8_t *_dst, int16_t *coeffs,
  39. ptrdiff_t stride, int size)
  40. {
  41. int x, y;
  42. pixel *dst = (pixel *)_dst;
  43. stride /= sizeof(pixel);
  44. for (y = 0; y < size; y++) {
  45. for (x = 0; x < size; x++) {
  46. dst[x] = av_clip_pixel(dst[x] + *coeffs);
  47. coeffs++;
  48. }
  49. dst += stride;
  50. }
  51. }
  52. static void FUNC(transform_add4x4)(uint8_t *_dst, int16_t *coeffs,
  53. ptrdiff_t stride)
  54. {
  55. FUNC(transquant_bypass)(_dst, coeffs, stride, 4);
  56. }
  57. static void FUNC(transform_add8x8)(uint8_t *_dst, int16_t *coeffs,
  58. ptrdiff_t stride)
  59. {
  60. FUNC(transquant_bypass)(_dst, coeffs, stride, 8);
  61. }
  62. static void FUNC(transform_add16x16)(uint8_t *_dst, int16_t *coeffs,
  63. ptrdiff_t stride)
  64. {
  65. FUNC(transquant_bypass)(_dst, coeffs, stride, 16);
  66. }
  67. static void FUNC(transform_add32x32)(uint8_t *_dst, int16_t *coeffs,
  68. ptrdiff_t stride)
  69. {
  70. FUNC(transquant_bypass)(_dst, coeffs, stride, 32);
  71. }
  72. static void FUNC(transform_rdpcm)(int16_t *_coeffs, int16_t log2_size, int mode)
  73. {
  74. int16_t *coeffs = (int16_t *) _coeffs;
  75. int x, y;
  76. int size = 1 << log2_size;
  77. if (mode) {
  78. coeffs += size;
  79. for (y = 0; y < size - 1; y++) {
  80. for (x = 0; x < size; x++)
  81. coeffs[x] += coeffs[x - size];
  82. coeffs += size;
  83. }
  84. } else {
  85. for (y = 0; y < size; y++) {
  86. for (x = 1; x < size; x++)
  87. coeffs[x] += coeffs[x - 1];
  88. coeffs += size;
  89. }
  90. }
  91. }
  92. static void FUNC(transform_skip)(int16_t *_coeffs, int16_t log2_size)
  93. {
  94. int shift = 15 - BIT_DEPTH - log2_size;
  95. int x, y;
  96. int size = 1 << log2_size;
  97. int16_t *coeffs = _coeffs;
  98. if (shift > 0) {
  99. int offset = 1 << (shift - 1);
  100. for (y = 0; y < size; y++) {
  101. for (x = 0; x < size; x++) {
  102. *coeffs = (*coeffs + offset) >> shift;
  103. coeffs++;
  104. }
  105. }
  106. } else {
  107. for (y = 0; y < size; y++) {
  108. for (x = 0; x < size; x++) {
  109. *coeffs = *(uint16_t*)coeffs << -shift;
  110. coeffs++;
  111. }
  112. }
  113. }
  114. }
  115. #define SET(dst, x) (dst) = (x)
  116. #define SCALE(dst, x) (dst) = av_clip_int16(((x) + add) >> shift)
  117. #define ADD_AND_SCALE(dst, x) \
  118. (dst) = av_clip_pixel((dst) + av_clip_int16(((x) + add) >> shift))
  119. #define TR_4x4_LUMA(dst, src, step, assign) \
  120. do { \
  121. int c0 = src[0 * step] + src[2 * step]; \
  122. int c1 = src[2 * step] + src[3 * step]; \
  123. int c2 = src[0 * step] - src[3 * step]; \
  124. int c3 = 74 * src[1 * step]; \
  125. \
  126. assign(dst[2 * step], 74 * (src[0 * step] - \
  127. src[2 * step] + \
  128. src[3 * step])); \
  129. assign(dst[0 * step], 29 * c0 + 55 * c1 + c3); \
  130. assign(dst[1 * step], 55 * c2 - 29 * c1 + c3); \
  131. assign(dst[3 * step], 55 * c0 + 29 * c2 - c3); \
  132. } while (0)
  133. static void FUNC(transform_4x4_luma)(int16_t *coeffs)
  134. {
  135. int i;
  136. int shift = 7;
  137. int add = 1 << (shift - 1);
  138. int16_t *src = coeffs;
  139. for (i = 0; i < 4; i++) {
  140. TR_4x4_LUMA(src, src, 4, SCALE);
  141. src++;
  142. }
  143. shift = 20 - BIT_DEPTH;
  144. add = 1 << (shift - 1);
  145. for (i = 0; i < 4; i++) {
  146. TR_4x4_LUMA(coeffs, coeffs, 1, SCALE);
  147. coeffs += 4;
  148. }
  149. }
  150. #undef TR_4x4_LUMA
  151. #define TR_4(dst, src, dstep, sstep, assign, end) \
  152. do { \
  153. const int e0 = 64 * src[0 * sstep] + 64 * src[2 * sstep]; \
  154. const int e1 = 64 * src[0 * sstep] - 64 * src[2 * sstep]; \
  155. const int o0 = 83 * src[1 * sstep] + 36 * src[3 * sstep]; \
  156. const int o1 = 36 * src[1 * sstep] - 83 * src[3 * sstep]; \
  157. \
  158. assign(dst[0 * dstep], e0 + o0); \
  159. assign(dst[1 * dstep], e1 + o1); \
  160. assign(dst[2 * dstep], e1 - o1); \
  161. assign(dst[3 * dstep], e0 - o0); \
  162. } while (0)
  163. #define TR_8(dst, src, dstep, sstep, assign, end) \
  164. do { \
  165. int i, j; \
  166. int e_8[4]; \
  167. int o_8[4] = { 0 }; \
  168. for (i = 0; i < 4; i++) \
  169. for (j = 1; j < end; j += 2) \
  170. o_8[i] += transform[4 * j][i] * src[j * sstep]; \
  171. TR_4(e_8, src, 1, 2 * sstep, SET, 4); \
  172. \
  173. for (i = 0; i < 4; i++) { \
  174. assign(dst[i * dstep], e_8[i] + o_8[i]); \
  175. assign(dst[(7 - i) * dstep], e_8[i] - o_8[i]); \
  176. } \
  177. } while (0)
  178. #define TR_16(dst, src, dstep, sstep, assign, end) \
  179. do { \
  180. int i, j; \
  181. int e_16[8]; \
  182. int o_16[8] = { 0 }; \
  183. for (i = 0; i < 8; i++) \
  184. for (j = 1; j < end; j += 2) \
  185. o_16[i] += transform[2 * j][i] * src[j * sstep]; \
  186. TR_8(e_16, src, 1, 2 * sstep, SET, 8); \
  187. \
  188. for (i = 0; i < 8; i++) { \
  189. assign(dst[i * dstep], e_16[i] + o_16[i]); \
  190. assign(dst[(15 - i) * dstep], e_16[i] - o_16[i]); \
  191. } \
  192. } while (0)
  193. #define TR_32(dst, src, dstep, sstep, assign, end) \
  194. do { \
  195. int i, j; \
  196. int e_32[16]; \
  197. int o_32[16] = { 0 }; \
  198. for (i = 0; i < 16; i++) \
  199. for (j = 1; j < end; j += 2) \
  200. o_32[i] += transform[j][i] * src[j * sstep]; \
  201. TR_16(e_32, src, 1, 2 * sstep, SET, end/2); \
  202. \
  203. for (i = 0; i < 16; i++) { \
  204. assign(dst[i * dstep], e_32[i] + o_32[i]); \
  205. assign(dst[(31 - i) * dstep], e_32[i] - o_32[i]); \
  206. } \
  207. } while (0)
  208. #define IDCT_VAR4(H) \
  209. int limit2 = FFMIN(col_limit + 4, H)
  210. #define IDCT_VAR8(H) \
  211. int limit = FFMIN(col_limit, H); \
  212. int limit2 = FFMIN(col_limit + 4, H)
  213. #define IDCT_VAR16(H) IDCT_VAR8(H)
  214. #define IDCT_VAR32(H) IDCT_VAR8(H)
  215. #define IDCT(H) \
  216. static void FUNC(idct_##H ##x ##H )( \
  217. int16_t *coeffs, int col_limit) { \
  218. int i; \
  219. int shift = 7; \
  220. int add = 1 << (shift - 1); \
  221. int16_t *src = coeffs; \
  222. IDCT_VAR ##H(H); \
  223. \
  224. for (i = 0; i < H; i++) { \
  225. TR_ ## H(src, src, H, H, SCALE, limit2); \
  226. if (limit2 < H && i%4 == 0 && !!i) \
  227. limit2 -= 4; \
  228. src++; \
  229. } \
  230. \
  231. shift = 20 - BIT_DEPTH; \
  232. add = 1 << (shift - 1); \
  233. for (i = 0; i < H; i++) { \
  234. TR_ ## H(coeffs, coeffs, 1, 1, SCALE, limit); \
  235. coeffs += H; \
  236. } \
  237. }
  238. #define IDCT_DC(H) \
  239. static void FUNC(idct_##H ##x ##H ##_dc)( \
  240. int16_t *coeffs) { \
  241. int i, j; \
  242. int shift = 14 - BIT_DEPTH; \
  243. int add = 1 << (shift - 1); \
  244. int coeff = (((coeffs[0] + 1) >> 1) + add) >> shift; \
  245. \
  246. for (j = 0; j < H; j++) { \
  247. for (i = 0; i < H; i++) { \
  248. coeffs[i+j*H] = coeff; \
  249. } \
  250. } \
  251. }
  252. IDCT( 4)
  253. IDCT( 8)
  254. IDCT(16)
  255. IDCT(32)
  256. IDCT_DC( 4)
  257. IDCT_DC( 8)
  258. IDCT_DC(16)
  259. IDCT_DC(32)
  260. #undef TR_4
  261. #undef TR_8
  262. #undef TR_16
  263. #undef TR_32
  264. #undef SET
  265. #undef SCALE
  266. #undef ADD_AND_SCALE
  267. static void FUNC(sao_band_filter)(uint8_t *_dst, uint8_t *_src,
  268. ptrdiff_t stride_dst, ptrdiff_t stride_src,
  269. int16_t *sao_offset_val, int sao_left_class,
  270. int width, int height)
  271. {
  272. pixel *dst = (pixel *)_dst;
  273. pixel *src = (pixel *)_src;
  274. int offset_table[32] = { 0 };
  275. int k, y, x;
  276. int shift = BIT_DEPTH - 5;
  277. stride_dst /= sizeof(pixel);
  278. stride_src /= sizeof(pixel);
  279. for (k = 0; k < 4; k++)
  280. offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
  281. for (y = 0; y < height; y++) {
  282. for (x = 0; x < width; x++)
  283. dst[x] = av_clip_pixel(src[x] + offset_table[src[x] >> shift]);
  284. dst += stride_dst;
  285. src += stride_src;
  286. }
  287. }
  288. #define CMP(a, b) (((a) > (b)) - ((a) < (b)))
  289. static void FUNC(sao_edge_filter)(uint8_t *_dst, uint8_t *_src, ptrdiff_t stride_dst, int16_t *sao_offset_val,
  290. int eo, int width, int height) {
  291. static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
  292. static const int8_t pos[4][2][2] = {
  293. { { -1, 0 }, { 1, 0 } }, // horizontal
  294. { { 0, -1 }, { 0, 1 } }, // vertical
  295. { { -1, -1 }, { 1, 1 } }, // 45 degree
  296. { { 1, -1 }, { -1, 1 } }, // 135 degree
  297. };
  298. pixel *dst = (pixel *)_dst;
  299. pixel *src = (pixel *)_src;
  300. int a_stride, b_stride;
  301. int x, y;
  302. ptrdiff_t stride_src = (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / sizeof(pixel);
  303. stride_dst /= sizeof(pixel);
  304. a_stride = pos[eo][0][0] + pos[eo][0][1] * stride_src;
  305. b_stride = pos[eo][1][0] + pos[eo][1][1] * stride_src;
  306. for (y = 0; y < height; y++) {
  307. for (x = 0; x < width; x++) {
  308. int diff0 = CMP(src[x], src[x + a_stride]);
  309. int diff1 = CMP(src[x], src[x + b_stride]);
  310. int offset_val = edge_idx[2 + diff0 + diff1];
  311. dst[x] = av_clip_pixel(src[x] + sao_offset_val[offset_val]);
  312. }
  313. src += stride_src;
  314. dst += stride_dst;
  315. }
  316. }
  317. static void FUNC(sao_edge_restore_0)(uint8_t *_dst, uint8_t *_src,
  318. ptrdiff_t stride_dst, ptrdiff_t stride_src, SAOParams *sao,
  319. int *borders, int _width, int _height,
  320. int c_idx, uint8_t *vert_edge,
  321. uint8_t *horiz_edge, uint8_t *diag_edge)
  322. {
  323. int x, y;
  324. pixel *dst = (pixel *)_dst;
  325. pixel *src = (pixel *)_src;
  326. int16_t *sao_offset_val = sao->offset_val[c_idx];
  327. int sao_eo_class = sao->eo_class[c_idx];
  328. int init_x = 0, width = _width, height = _height;
  329. stride_dst /= sizeof(pixel);
  330. stride_src /= sizeof(pixel);
  331. if (sao_eo_class != SAO_EO_VERT) {
  332. if (borders[0]) {
  333. int offset_val = sao_offset_val[0];
  334. for (y = 0; y < height; y++) {
  335. dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
  336. }
  337. init_x = 1;
  338. }
  339. if (borders[2]) {
  340. int offset_val = sao_offset_val[0];
  341. int offset = width - 1;
  342. for (x = 0; x < height; x++) {
  343. dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
  344. }
  345. width--;
  346. }
  347. }
  348. if (sao_eo_class != SAO_EO_HORIZ) {
  349. if (borders[1]) {
  350. int offset_val = sao_offset_val[0];
  351. for (x = init_x; x < width; x++)
  352. dst[x] = av_clip_pixel(src[x] + offset_val);
  353. }
  354. if (borders[3]) {
  355. int offset_val = sao_offset_val[0];
  356. int y_stride_dst = stride_dst * (height - 1);
  357. int y_stride_src = stride_src * (height - 1);
  358. for (x = init_x; x < width; x++)
  359. dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
  360. height--;
  361. }
  362. }
  363. }
  364. static void FUNC(sao_edge_restore_1)(uint8_t *_dst, uint8_t *_src,
  365. ptrdiff_t stride_dst, ptrdiff_t stride_src, SAOParams *sao,
  366. int *borders, int _width, int _height,
  367. int c_idx, uint8_t *vert_edge,
  368. uint8_t *horiz_edge, uint8_t *diag_edge)
  369. {
  370. int x, y;
  371. pixel *dst = (pixel *)_dst;
  372. pixel *src = (pixel *)_src;
  373. int16_t *sao_offset_val = sao->offset_val[c_idx];
  374. int sao_eo_class = sao->eo_class[c_idx];
  375. int init_x = 0, init_y = 0, width = _width, height = _height;
  376. stride_dst /= sizeof(pixel);
  377. stride_src /= sizeof(pixel);
  378. if (sao_eo_class != SAO_EO_VERT) {
  379. if (borders[0]) {
  380. int offset_val = sao_offset_val[0];
  381. for (y = 0; y < height; y++) {
  382. dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
  383. }
  384. init_x = 1;
  385. }
  386. if (borders[2]) {
  387. int offset_val = sao_offset_val[0];
  388. int offset = width - 1;
  389. for (x = 0; x < height; x++) {
  390. dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
  391. }
  392. width--;
  393. }
  394. }
  395. if (sao_eo_class != SAO_EO_HORIZ) {
  396. if (borders[1]) {
  397. int offset_val = sao_offset_val[0];
  398. for (x = init_x; x < width; x++)
  399. dst[x] = av_clip_pixel(src[x] + offset_val);
  400. init_y = 1;
  401. }
  402. if (borders[3]) {
  403. int offset_val = sao_offset_val[0];
  404. int y_stride_dst = stride_dst * (height - 1);
  405. int y_stride_src = stride_src * (height - 1);
  406. for (x = init_x; x < width; x++)
  407. dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
  408. height--;
  409. }
  410. }
  411. {
  412. int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
  413. int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2];
  414. int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3];
  415. int save_lower_left = !diag_edge[3] && sao_eo_class == SAO_EO_45D && !borders[0] && !borders[3];
  416. // Restore pixels that can't be modified
  417. if(vert_edge[0] && sao_eo_class != SAO_EO_VERT) {
  418. for(y = init_y+save_upper_left; y< height-save_lower_left; y++)
  419. dst[y*stride_dst] = src[y*stride_src];
  420. }
  421. if(vert_edge[1] && sao_eo_class != SAO_EO_VERT) {
  422. for(y = init_y+save_upper_right; y< height-save_lower_right; y++)
  423. dst[y*stride_dst+width-1] = src[y*stride_src+width-1];
  424. }
  425. if(horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) {
  426. for(x = init_x+save_upper_left; x < width-save_upper_right; x++)
  427. dst[x] = src[x];
  428. }
  429. if(horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) {
  430. for(x = init_x+save_lower_left; x < width-save_lower_right; x++)
  431. dst[(height-1)*stride_dst+x] = src[(height-1)*stride_src+x];
  432. }
  433. if(diag_edge[0] && sao_eo_class == SAO_EO_135D)
  434. dst[0] = src[0];
  435. if(diag_edge[1] && sao_eo_class == SAO_EO_45D)
  436. dst[width-1] = src[width-1];
  437. if(diag_edge[2] && sao_eo_class == SAO_EO_135D)
  438. dst[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1];
  439. if(diag_edge[3] && sao_eo_class == SAO_EO_45D)
  440. dst[stride_dst*(height-1)] = src[stride_src*(height-1)];
  441. }
  442. }
  443. #undef CMP
  444. ////////////////////////////////////////////////////////////////////////////////
  445. //
  446. ////////////////////////////////////////////////////////////////////////////////
  447. static void FUNC(put_hevc_pel_pixels)(int16_t *dst,
  448. uint8_t *_src, ptrdiff_t _srcstride,
  449. int height, intptr_t mx, intptr_t my, int width)
  450. {
  451. int x, y;
  452. pixel *src = (pixel *)_src;
  453. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  454. for (y = 0; y < height; y++) {
  455. for (x = 0; x < width; x++)
  456. dst[x] = src[x] << (14 - BIT_DEPTH);
  457. src += srcstride;
  458. dst += MAX_PB_SIZE;
  459. }
  460. }
  461. static void FUNC(put_hevc_pel_uni_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  462. int height, intptr_t mx, intptr_t my, int width)
  463. {
  464. int y;
  465. pixel *src = (pixel *)_src;
  466. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  467. pixel *dst = (pixel *)_dst;
  468. ptrdiff_t dststride = _dststride / sizeof(pixel);
  469. for (y = 0; y < height; y++) {
  470. memcpy(dst, src, width * sizeof(pixel));
  471. src += srcstride;
  472. dst += dststride;
  473. }
  474. }
  475. static void FUNC(put_hevc_pel_bi_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  476. int16_t *src2,
  477. int height, intptr_t mx, intptr_t my, int width)
  478. {
  479. int x, y;
  480. pixel *src = (pixel *)_src;
  481. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  482. pixel *dst = (pixel *)_dst;
  483. ptrdiff_t dststride = _dststride / sizeof(pixel);
  484. int shift = 14 + 1 - BIT_DEPTH;
  485. #if BIT_DEPTH < 14
  486. int offset = 1 << (shift - 1);
  487. #else
  488. int offset = 0;
  489. #endif
  490. for (y = 0; y < height; y++) {
  491. for (x = 0; x < width; x++)
  492. dst[x] = av_clip_pixel(((src[x] << (14 - BIT_DEPTH)) + src2[x] + offset) >> shift);
  493. src += srcstride;
  494. dst += dststride;
  495. src2 += MAX_PB_SIZE;
  496. }
  497. }
  498. static void FUNC(put_hevc_pel_uni_w_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  499. int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
  500. {
  501. int x, y;
  502. pixel *src = (pixel *)_src;
  503. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  504. pixel *dst = (pixel *)_dst;
  505. ptrdiff_t dststride = _dststride / sizeof(pixel);
  506. int shift = denom + 14 - BIT_DEPTH;
  507. #if BIT_DEPTH < 14
  508. int offset = 1 << (shift - 1);
  509. #else
  510. int offset = 0;
  511. #endif
  512. ox = ox * (1 << (BIT_DEPTH - 8));
  513. for (y = 0; y < height; y++) {
  514. for (x = 0; x < width; x++)
  515. dst[x] = av_clip_pixel((((src[x] << (14 - BIT_DEPTH)) * wx + offset) >> shift) + ox);
  516. src += srcstride;
  517. dst += dststride;
  518. }
  519. }
  520. static void FUNC(put_hevc_pel_bi_w_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  521. int16_t *src2,
  522. int height, int denom, int wx0, int wx1,
  523. int ox0, int ox1, intptr_t mx, intptr_t my, int width)
  524. {
  525. int x, y;
  526. pixel *src = (pixel *)_src;
  527. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  528. pixel *dst = (pixel *)_dst;
  529. ptrdiff_t dststride = _dststride / sizeof(pixel);
  530. int shift = 14 + 1 - BIT_DEPTH;
  531. int log2Wd = denom + shift - 1;
  532. ox0 = ox0 * (1 << (BIT_DEPTH - 8));
  533. ox1 = ox1 * (1 << (BIT_DEPTH - 8));
  534. for (y = 0; y < height; y++) {
  535. for (x = 0; x < width; x++) {
  536. dst[x] = av_clip_pixel(( (src[x] << (14 - BIT_DEPTH)) * wx1 + src2[x] * wx0 + (ox0 + ox1 + 1) * (1 << log2Wd)) >> (log2Wd + 1));
  537. }
  538. src += srcstride;
  539. dst += dststride;
  540. src2 += MAX_PB_SIZE;
  541. }
  542. }
  543. ////////////////////////////////////////////////////////////////////////////////
  544. //
  545. ////////////////////////////////////////////////////////////////////////////////
  546. #define QPEL_FILTER(src, stride) \
  547. (filter[0] * src[x - 3 * stride] + \
  548. filter[1] * src[x - 2 * stride] + \
  549. filter[2] * src[x - stride] + \
  550. filter[3] * src[x ] + \
  551. filter[4] * src[x + stride] + \
  552. filter[5] * src[x + 2 * stride] + \
  553. filter[6] * src[x + 3 * stride] + \
  554. filter[7] * src[x + 4 * stride])
  555. static void FUNC(put_hevc_qpel_h)(int16_t *dst,
  556. uint8_t *_src, ptrdiff_t _srcstride,
  557. int height, intptr_t mx, intptr_t my, int width)
  558. {
  559. int x, y;
  560. pixel *src = (pixel*)_src;
  561. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  562. const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
  563. for (y = 0; y < height; y++) {
  564. for (x = 0; x < width; x++)
  565. dst[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
  566. src += srcstride;
  567. dst += MAX_PB_SIZE;
  568. }
  569. }
  570. static void FUNC(put_hevc_qpel_v)(int16_t *dst,
  571. uint8_t *_src, ptrdiff_t _srcstride,
  572. int height, intptr_t mx, intptr_t my, int width)
  573. {
  574. int x, y;
  575. pixel *src = (pixel*)_src;
  576. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  577. const int8_t *filter = ff_hevc_qpel_filters[my - 1];
  578. for (y = 0; y < height; y++) {
  579. for (x = 0; x < width; x++)
  580. dst[x] = QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8);
  581. src += srcstride;
  582. dst += MAX_PB_SIZE;
  583. }
  584. }
  585. static void FUNC(put_hevc_qpel_hv)(int16_t *dst,
  586. uint8_t *_src,
  587. ptrdiff_t _srcstride,
  588. int height, intptr_t mx,
  589. intptr_t my, int width)
  590. {
  591. int x, y;
  592. const int8_t *filter;
  593. pixel *src = (pixel*)_src;
  594. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  595. int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
  596. int16_t *tmp = tmp_array;
  597. src -= QPEL_EXTRA_BEFORE * srcstride;
  598. filter = ff_hevc_qpel_filters[mx - 1];
  599. for (y = 0; y < height + QPEL_EXTRA; y++) {
  600. for (x = 0; x < width; x++)
  601. tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
  602. src += srcstride;
  603. tmp += MAX_PB_SIZE;
  604. }
  605. tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
  606. filter = ff_hevc_qpel_filters[my - 1];
  607. for (y = 0; y < height; y++) {
  608. for (x = 0; x < width; x++)
  609. dst[x] = QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6;
  610. tmp += MAX_PB_SIZE;
  611. dst += MAX_PB_SIZE;
  612. }
  613. }
  614. static void FUNC(put_hevc_qpel_uni_h)(uint8_t *_dst, ptrdiff_t _dststride,
  615. uint8_t *_src, ptrdiff_t _srcstride,
  616. int height, intptr_t mx, intptr_t my, int width)
  617. {
  618. int x, y;
  619. pixel *src = (pixel*)_src;
  620. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  621. pixel *dst = (pixel *)_dst;
  622. ptrdiff_t dststride = _dststride / sizeof(pixel);
  623. const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
  624. int shift = 14 - BIT_DEPTH;
  625. #if BIT_DEPTH < 14
  626. int offset = 1 << (shift - 1);
  627. #else
  628. int offset = 0;
  629. #endif
  630. for (y = 0; y < height; y++) {
  631. for (x = 0; x < width; x++)
  632. dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + offset) >> shift);
  633. src += srcstride;
  634. dst += dststride;
  635. }
  636. }
  637. static void FUNC(put_hevc_qpel_bi_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  638. int16_t *src2,
  639. int height, intptr_t mx, intptr_t my, int width)
  640. {
  641. int x, y;
  642. pixel *src = (pixel*)_src;
  643. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  644. pixel *dst = (pixel *)_dst;
  645. ptrdiff_t dststride = _dststride / sizeof(pixel);
  646. const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
  647. int shift = 14 + 1 - BIT_DEPTH;
  648. #if BIT_DEPTH < 14
  649. int offset = 1 << (shift - 1);
  650. #else
  651. int offset = 0;
  652. #endif
  653. for (y = 0; y < height; y++) {
  654. for (x = 0; x < width; x++)
  655. dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
  656. src += srcstride;
  657. dst += dststride;
  658. src2 += MAX_PB_SIZE;
  659. }
  660. }
  661. static void FUNC(put_hevc_qpel_uni_v)(uint8_t *_dst, ptrdiff_t _dststride,
  662. uint8_t *_src, ptrdiff_t _srcstride,
  663. int height, intptr_t mx, intptr_t my, int width)
  664. {
  665. int x, y;
  666. pixel *src = (pixel*)_src;
  667. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  668. pixel *dst = (pixel *)_dst;
  669. ptrdiff_t dststride = _dststride / sizeof(pixel);
  670. const int8_t *filter = ff_hevc_qpel_filters[my - 1];
  671. int shift = 14 - BIT_DEPTH;
  672. #if BIT_DEPTH < 14
  673. int offset = 1 << (shift - 1);
  674. #else
  675. int offset = 0;
  676. #endif
  677. for (y = 0; y < height; y++) {
  678. for (x = 0; x < width; x++)
  679. dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + offset) >> shift);
  680. src += srcstride;
  681. dst += dststride;
  682. }
  683. }
  684. static void FUNC(put_hevc_qpel_bi_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  685. int16_t *src2,
  686. int height, intptr_t mx, intptr_t my, int width)
  687. {
  688. int x, y;
  689. pixel *src = (pixel*)_src;
  690. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  691. pixel *dst = (pixel *)_dst;
  692. ptrdiff_t dststride = _dststride / sizeof(pixel);
  693. const int8_t *filter = ff_hevc_qpel_filters[my - 1];
  694. int shift = 14 + 1 - BIT_DEPTH;
  695. #if BIT_DEPTH < 14
  696. int offset = 1 << (shift - 1);
  697. #else
  698. int offset = 0;
  699. #endif
  700. for (y = 0; y < height; y++) {
  701. for (x = 0; x < width; x++)
  702. dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
  703. src += srcstride;
  704. dst += dststride;
  705. src2 += MAX_PB_SIZE;
  706. }
  707. }
  708. static void FUNC(put_hevc_qpel_uni_hv)(uint8_t *_dst, ptrdiff_t _dststride,
  709. uint8_t *_src, ptrdiff_t _srcstride,
  710. int height, intptr_t mx, intptr_t my, int width)
  711. {
  712. int x, y;
  713. const int8_t *filter;
  714. pixel *src = (pixel*)_src;
  715. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  716. pixel *dst = (pixel *)_dst;
  717. ptrdiff_t dststride = _dststride / sizeof(pixel);
  718. int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
  719. int16_t *tmp = tmp_array;
  720. int shift = 14 - BIT_DEPTH;
  721. #if BIT_DEPTH < 14
  722. int offset = 1 << (shift - 1);
  723. #else
  724. int offset = 0;
  725. #endif
  726. src -= QPEL_EXTRA_BEFORE * srcstride;
  727. filter = ff_hevc_qpel_filters[mx - 1];
  728. for (y = 0; y < height + QPEL_EXTRA; y++) {
  729. for (x = 0; x < width; x++)
  730. tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
  731. src += srcstride;
  732. tmp += MAX_PB_SIZE;
  733. }
  734. tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
  735. filter = ff_hevc_qpel_filters[my - 1];
  736. for (y = 0; y < height; y++) {
  737. for (x = 0; x < width; x++)
  738. dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + offset) >> shift);
  739. tmp += MAX_PB_SIZE;
  740. dst += dststride;
  741. }
  742. }
  743. static void FUNC(put_hevc_qpel_bi_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  744. int16_t *src2,
  745. int height, intptr_t mx, intptr_t my, int width)
  746. {
  747. int x, y;
  748. const int8_t *filter;
  749. pixel *src = (pixel*)_src;
  750. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  751. pixel *dst = (pixel *)_dst;
  752. ptrdiff_t dststride = _dststride / sizeof(pixel);
  753. int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
  754. int16_t *tmp = tmp_array;
  755. int shift = 14 + 1 - BIT_DEPTH;
  756. #if BIT_DEPTH < 14
  757. int offset = 1 << (shift - 1);
  758. #else
  759. int offset = 0;
  760. #endif
  761. src -= QPEL_EXTRA_BEFORE * srcstride;
  762. filter = ff_hevc_qpel_filters[mx - 1];
  763. for (y = 0; y < height + QPEL_EXTRA; y++) {
  764. for (x = 0; x < width; x++)
  765. tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
  766. src += srcstride;
  767. tmp += MAX_PB_SIZE;
  768. }
  769. tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
  770. filter = ff_hevc_qpel_filters[my - 1];
  771. for (y = 0; y < height; y++) {
  772. for (x = 0; x < width; x++)
  773. dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + src2[x] + offset) >> shift);
  774. tmp += MAX_PB_SIZE;
  775. dst += dststride;
  776. src2 += MAX_PB_SIZE;
  777. }
  778. }
  779. static void FUNC(put_hevc_qpel_uni_w_h)(uint8_t *_dst, ptrdiff_t _dststride,
  780. uint8_t *_src, ptrdiff_t _srcstride,
  781. int height, int denom, int wx, int ox,
  782. intptr_t mx, intptr_t my, int width)
  783. {
  784. int x, y;
  785. pixel *src = (pixel*)_src;
  786. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  787. pixel *dst = (pixel *)_dst;
  788. ptrdiff_t dststride = _dststride / sizeof(pixel);
  789. const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
  790. int shift = denom + 14 - BIT_DEPTH;
  791. #if BIT_DEPTH < 14
  792. int offset = 1 << (shift - 1);
  793. #else
  794. int offset = 0;
  795. #endif
  796. ox = ox * (1 << (BIT_DEPTH - 8));
  797. for (y = 0; y < height; y++) {
  798. for (x = 0; x < width; x++)
  799. dst[x] = av_clip_pixel((((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
  800. src += srcstride;
  801. dst += dststride;
  802. }
  803. }
  804. static void FUNC(put_hevc_qpel_bi_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  805. int16_t *src2,
  806. int height, int denom, int wx0, int wx1,
  807. int ox0, int ox1, intptr_t mx, intptr_t my, int width)
  808. {
  809. int x, y;
  810. pixel *src = (pixel*)_src;
  811. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  812. pixel *dst = (pixel *)_dst;
  813. ptrdiff_t dststride = _dststride / sizeof(pixel);
  814. const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
  815. int shift = 14 + 1 - BIT_DEPTH;
  816. int log2Wd = denom + shift - 1;
  817. ox0 = ox0 * (1 << (BIT_DEPTH - 8));
  818. ox1 = ox1 * (1 << (BIT_DEPTH - 8));
  819. for (y = 0; y < height; y++) {
  820. for (x = 0; x < width; x++)
  821. dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
  822. ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
  823. src += srcstride;
  824. dst += dststride;
  825. src2 += MAX_PB_SIZE;
  826. }
  827. }
  828. static void FUNC(put_hevc_qpel_uni_w_v)(uint8_t *_dst, ptrdiff_t _dststride,
  829. uint8_t *_src, ptrdiff_t _srcstride,
  830. int height, int denom, int wx, int ox,
  831. intptr_t mx, intptr_t my, int width)
  832. {
  833. int x, y;
  834. pixel *src = (pixel*)_src;
  835. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  836. pixel *dst = (pixel *)_dst;
  837. ptrdiff_t dststride = _dststride / sizeof(pixel);
  838. const int8_t *filter = ff_hevc_qpel_filters[my - 1];
  839. int shift = denom + 14 - BIT_DEPTH;
  840. #if BIT_DEPTH < 14
  841. int offset = 1 << (shift - 1);
  842. #else
  843. int offset = 0;
  844. #endif
  845. ox = ox * (1 << (BIT_DEPTH - 8));
  846. for (y = 0; y < height; y++) {
  847. for (x = 0; x < width; x++)
  848. dst[x] = av_clip_pixel((((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
  849. src += srcstride;
  850. dst += dststride;
  851. }
  852. }
  853. static void FUNC(put_hevc_qpel_bi_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  854. int16_t *src2,
  855. int height, int denom, int wx0, int wx1,
  856. int ox0, int ox1, intptr_t mx, intptr_t my, int width)
  857. {
  858. int x, y;
  859. pixel *src = (pixel*)_src;
  860. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  861. pixel *dst = (pixel *)_dst;
  862. ptrdiff_t dststride = _dststride / sizeof(pixel);
  863. const int8_t *filter = ff_hevc_qpel_filters[my - 1];
  864. int shift = 14 + 1 - BIT_DEPTH;
  865. int log2Wd = denom + shift - 1;
  866. ox0 = ox0 * (1 << (BIT_DEPTH - 8));
  867. ox1 = ox1 * (1 << (BIT_DEPTH - 8));
  868. for (y = 0; y < height; y++) {
  869. for (x = 0; x < width; x++)
  870. dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
  871. ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
  872. src += srcstride;
  873. dst += dststride;
  874. src2 += MAX_PB_SIZE;
  875. }
  876. }
  877. static void FUNC(put_hevc_qpel_uni_w_hv)(uint8_t *_dst, ptrdiff_t _dststride,
  878. uint8_t *_src, ptrdiff_t _srcstride,
  879. int height, int denom, int wx, int ox,
  880. intptr_t mx, intptr_t my, int width)
  881. {
  882. int x, y;
  883. const int8_t *filter;
  884. pixel *src = (pixel*)_src;
  885. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  886. pixel *dst = (pixel *)_dst;
  887. ptrdiff_t dststride = _dststride / sizeof(pixel);
  888. int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
  889. int16_t *tmp = tmp_array;
  890. int shift = denom + 14 - BIT_DEPTH;
  891. #if BIT_DEPTH < 14
  892. int offset = 1 << (shift - 1);
  893. #else
  894. int offset = 0;
  895. #endif
  896. src -= QPEL_EXTRA_BEFORE * srcstride;
  897. filter = ff_hevc_qpel_filters[mx - 1];
  898. for (y = 0; y < height + QPEL_EXTRA; y++) {
  899. for (x = 0; x < width; x++)
  900. tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
  901. src += srcstride;
  902. tmp += MAX_PB_SIZE;
  903. }
  904. tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
  905. filter = ff_hevc_qpel_filters[my - 1];
  906. ox = ox * (1 << (BIT_DEPTH - 8));
  907. for (y = 0; y < height; y++) {
  908. for (x = 0; x < width; x++)
  909. dst[x] = av_clip_pixel((((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
  910. tmp += MAX_PB_SIZE;
  911. dst += dststride;
  912. }
  913. }
  914. static void FUNC(put_hevc_qpel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  915. int16_t *src2,
  916. int height, int denom, int wx0, int wx1,
  917. int ox0, int ox1, intptr_t mx, intptr_t my, int width)
  918. {
  919. int x, y;
  920. const int8_t *filter;
  921. pixel *src = (pixel*)_src;
  922. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  923. pixel *dst = (pixel *)_dst;
  924. ptrdiff_t dststride = _dststride / sizeof(pixel);
  925. int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
  926. int16_t *tmp = tmp_array;
  927. int shift = 14 + 1 - BIT_DEPTH;
  928. int log2Wd = denom + shift - 1;
  929. src -= QPEL_EXTRA_BEFORE * srcstride;
  930. filter = ff_hevc_qpel_filters[mx - 1];
  931. for (y = 0; y < height + QPEL_EXTRA; y++) {
  932. for (x = 0; x < width; x++)
  933. tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
  934. src += srcstride;
  935. tmp += MAX_PB_SIZE;
  936. }
  937. tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
  938. filter = ff_hevc_qpel_filters[my - 1];
  939. ox0 = ox0 * (1 << (BIT_DEPTH - 8));
  940. ox1 = ox1 * (1 << (BIT_DEPTH - 8));
  941. for (y = 0; y < height; y++) {
  942. for (x = 0; x < width; x++)
  943. dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 +
  944. ((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
  945. tmp += MAX_PB_SIZE;
  946. dst += dststride;
  947. src2 += MAX_PB_SIZE;
  948. }
  949. }
  950. ////////////////////////////////////////////////////////////////////////////////
  951. //
  952. ////////////////////////////////////////////////////////////////////////////////
  953. #define EPEL_FILTER(src, stride) \
  954. (filter[0] * src[x - stride] + \
  955. filter[1] * src[x] + \
  956. filter[2] * src[x + stride] + \
  957. filter[3] * src[x + 2 * stride])
  958. static void FUNC(put_hevc_epel_h)(int16_t *dst,
  959. uint8_t *_src, ptrdiff_t _srcstride,
  960. int height, intptr_t mx, intptr_t my, int width)
  961. {
  962. int x, y;
  963. pixel *src = (pixel *)_src;
  964. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  965. const int8_t *filter = ff_hevc_epel_filters[mx - 1];
  966. for (y = 0; y < height; y++) {
  967. for (x = 0; x < width; x++)
  968. dst[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
  969. src += srcstride;
  970. dst += MAX_PB_SIZE;
  971. }
  972. }
  973. static void FUNC(put_hevc_epel_v)(int16_t *dst,
  974. uint8_t *_src, ptrdiff_t _srcstride,
  975. int height, intptr_t mx, intptr_t my, int width)
  976. {
  977. int x, y;
  978. pixel *src = (pixel *)_src;
  979. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  980. const int8_t *filter = ff_hevc_epel_filters[my - 1];
  981. for (y = 0; y < height; y++) {
  982. for (x = 0; x < width; x++)
  983. dst[x] = EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8);
  984. src += srcstride;
  985. dst += MAX_PB_SIZE;
  986. }
  987. }
  988. static void FUNC(put_hevc_epel_hv)(int16_t *dst,
  989. uint8_t *_src, ptrdiff_t _srcstride,
  990. int height, intptr_t mx, intptr_t my, int width)
  991. {
  992. int x, y;
  993. pixel *src = (pixel *)_src;
  994. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  995. const int8_t *filter = ff_hevc_epel_filters[mx - 1];
  996. int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
  997. int16_t *tmp = tmp_array;
  998. src -= EPEL_EXTRA_BEFORE * srcstride;
  999. for (y = 0; y < height + EPEL_EXTRA; y++) {
  1000. for (x = 0; x < width; x++)
  1001. tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
  1002. src += srcstride;
  1003. tmp += MAX_PB_SIZE;
  1004. }
  1005. tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
  1006. filter = ff_hevc_epel_filters[my - 1];
  1007. for (y = 0; y < height; y++) {
  1008. for (x = 0; x < width; x++)
  1009. dst[x] = EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6;
  1010. tmp += MAX_PB_SIZE;
  1011. dst += MAX_PB_SIZE;
  1012. }
  1013. }
  1014. static void FUNC(put_hevc_epel_uni_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  1015. int height, intptr_t mx, intptr_t my, int width)
  1016. {
  1017. int x, y;
  1018. pixel *src = (pixel *)_src;
  1019. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  1020. pixel *dst = (pixel *)_dst;
  1021. ptrdiff_t dststride = _dststride / sizeof(pixel);
  1022. const int8_t *filter = ff_hevc_epel_filters[mx - 1];
  1023. int shift = 14 - BIT_DEPTH;
  1024. #if BIT_DEPTH < 14
  1025. int offset = 1 << (shift - 1);
  1026. #else
  1027. int offset = 0;
  1028. #endif
  1029. for (y = 0; y < height; y++) {
  1030. for (x = 0; x < width; x++)
  1031. dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + offset) >> shift);
  1032. src += srcstride;
  1033. dst += dststride;
  1034. }
  1035. }
  1036. static void FUNC(put_hevc_epel_bi_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  1037. int16_t *src2,
  1038. int height, intptr_t mx, intptr_t my, int width)
  1039. {
  1040. int x, y;
  1041. pixel *src = (pixel *)_src;
  1042. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  1043. pixel *dst = (pixel *)_dst;
  1044. ptrdiff_t dststride = _dststride / sizeof(pixel);
  1045. const int8_t *filter = ff_hevc_epel_filters[mx - 1];
  1046. int shift = 14 + 1 - BIT_DEPTH;
  1047. #if BIT_DEPTH < 14
  1048. int offset = 1 << (shift - 1);
  1049. #else
  1050. int offset = 0;
  1051. #endif
  1052. for (y = 0; y < height; y++) {
  1053. for (x = 0; x < width; x++) {
  1054. dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
  1055. }
  1056. dst += dststride;
  1057. src += srcstride;
  1058. src2 += MAX_PB_SIZE;
  1059. }
  1060. }
  1061. static void FUNC(put_hevc_epel_uni_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  1062. int height, intptr_t mx, intptr_t my, int width)
  1063. {
  1064. int x, y;
  1065. pixel *src = (pixel *)_src;
  1066. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  1067. pixel *dst = (pixel *)_dst;
  1068. ptrdiff_t dststride = _dststride / sizeof(pixel);
  1069. const int8_t *filter = ff_hevc_epel_filters[my - 1];
  1070. int shift = 14 - BIT_DEPTH;
  1071. #if BIT_DEPTH < 14
  1072. int offset = 1 << (shift - 1);
  1073. #else
  1074. int offset = 0;
  1075. #endif
  1076. for (y = 0; y < height; y++) {
  1077. for (x = 0; x < width; x++)
  1078. dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + offset) >> shift);
  1079. src += srcstride;
  1080. dst += dststride;
  1081. }
  1082. }
  1083. static void FUNC(put_hevc_epel_bi_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  1084. int16_t *src2,
  1085. int height, intptr_t mx, intptr_t my, int width)
  1086. {
  1087. int x, y;
  1088. pixel *src = (pixel *)_src;
  1089. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  1090. const int8_t *filter = ff_hevc_epel_filters[my - 1];
  1091. pixel *dst = (pixel *)_dst;
  1092. ptrdiff_t dststride = _dststride / sizeof(pixel);
  1093. int shift = 14 + 1 - BIT_DEPTH;
  1094. #if BIT_DEPTH < 14
  1095. int offset = 1 << (shift - 1);
  1096. #else
  1097. int offset = 0;
  1098. #endif
  1099. for (y = 0; y < height; y++) {
  1100. for (x = 0; x < width; x++)
  1101. dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
  1102. dst += dststride;
  1103. src += srcstride;
  1104. src2 += MAX_PB_SIZE;
  1105. }
  1106. }
  1107. static void FUNC(put_hevc_epel_uni_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  1108. int height, intptr_t mx, intptr_t my, int width)
  1109. {
  1110. int x, y;
  1111. pixel *src = (pixel *)_src;
  1112. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  1113. pixel *dst = (pixel *)_dst;
  1114. ptrdiff_t dststride = _dststride / sizeof(pixel);
  1115. const int8_t *filter = ff_hevc_epel_filters[mx - 1];
  1116. int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
  1117. int16_t *tmp = tmp_array;
  1118. int shift = 14 - BIT_DEPTH;
  1119. #if BIT_DEPTH < 14
  1120. int offset = 1 << (shift - 1);
  1121. #else
  1122. int offset = 0;
  1123. #endif
  1124. src -= EPEL_EXTRA_BEFORE * srcstride;
  1125. for (y = 0; y < height + EPEL_EXTRA; y++) {
  1126. for (x = 0; x < width; x++)
  1127. tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
  1128. src += srcstride;
  1129. tmp += MAX_PB_SIZE;
  1130. }
  1131. tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
  1132. filter = ff_hevc_epel_filters[my - 1];
  1133. for (y = 0; y < height; y++) {
  1134. for (x = 0; x < width; x++)
  1135. dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + offset) >> shift);
  1136. tmp += MAX_PB_SIZE;
  1137. dst += dststride;
  1138. }
  1139. }
  1140. static void FUNC(put_hevc_epel_bi_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  1141. int16_t *src2,
  1142. int height, intptr_t mx, intptr_t my, int width)
  1143. {
  1144. int x, y;
  1145. pixel *src = (pixel *)_src;
  1146. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  1147. pixel *dst = (pixel *)_dst;
  1148. ptrdiff_t dststride = _dststride / sizeof(pixel);
  1149. const int8_t *filter = ff_hevc_epel_filters[mx - 1];
  1150. int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
  1151. int16_t *tmp = tmp_array;
  1152. int shift = 14 + 1 - BIT_DEPTH;
  1153. #if BIT_DEPTH < 14
  1154. int offset = 1 << (shift - 1);
  1155. #else
  1156. int offset = 0;
  1157. #endif
  1158. src -= EPEL_EXTRA_BEFORE * srcstride;
  1159. for (y = 0; y < height + EPEL_EXTRA; y++) {
  1160. for (x = 0; x < width; x++)
  1161. tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
  1162. src += srcstride;
  1163. tmp += MAX_PB_SIZE;
  1164. }
  1165. tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
  1166. filter = ff_hevc_epel_filters[my - 1];
  1167. for (y = 0; y < height; y++) {
  1168. for (x = 0; x < width; x++)
  1169. dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + src2[x] + offset) >> shift);
  1170. tmp += MAX_PB_SIZE;
  1171. dst += dststride;
  1172. src2 += MAX_PB_SIZE;
  1173. }
  1174. }
  1175. static void FUNC(put_hevc_epel_uni_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  1176. int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
  1177. {
  1178. int x, y;
  1179. pixel *src = (pixel *)_src;
  1180. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  1181. pixel *dst = (pixel *)_dst;
  1182. ptrdiff_t dststride = _dststride / sizeof(pixel);
  1183. const int8_t *filter = ff_hevc_epel_filters[mx - 1];
  1184. int shift = denom + 14 - BIT_DEPTH;
  1185. #if BIT_DEPTH < 14
  1186. int offset = 1 << (shift - 1);
  1187. #else
  1188. int offset = 0;
  1189. #endif
  1190. ox = ox * (1 << (BIT_DEPTH - 8));
  1191. for (y = 0; y < height; y++) {
  1192. for (x = 0; x < width; x++) {
  1193. dst[x] = av_clip_pixel((((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
  1194. }
  1195. dst += dststride;
  1196. src += srcstride;
  1197. }
  1198. }
  1199. static void FUNC(put_hevc_epel_bi_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  1200. int16_t *src2,
  1201. int height, int denom, int wx0, int wx1,
  1202. int ox0, int ox1, intptr_t mx, intptr_t my, int width)
  1203. {
  1204. int x, y;
  1205. pixel *src = (pixel *)_src;
  1206. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  1207. pixel *dst = (pixel *)_dst;
  1208. ptrdiff_t dststride = _dststride / sizeof(pixel);
  1209. const int8_t *filter = ff_hevc_epel_filters[mx - 1];
  1210. int shift = 14 + 1 - BIT_DEPTH;
  1211. int log2Wd = denom + shift - 1;
  1212. ox0 = ox0 * (1 << (BIT_DEPTH - 8));
  1213. ox1 = ox1 * (1 << (BIT_DEPTH - 8));
  1214. for (y = 0; y < height; y++) {
  1215. for (x = 0; x < width; x++)
  1216. dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
  1217. ((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
  1218. src += srcstride;
  1219. dst += dststride;
  1220. src2 += MAX_PB_SIZE;
  1221. }
  1222. }
  1223. static void FUNC(put_hevc_epel_uni_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  1224. int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
  1225. {
  1226. int x, y;
  1227. pixel *src = (pixel *)_src;
  1228. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  1229. pixel *dst = (pixel *)_dst;
  1230. ptrdiff_t dststride = _dststride / sizeof(pixel);
  1231. const int8_t *filter = ff_hevc_epel_filters[my - 1];
  1232. int shift = denom + 14 - BIT_DEPTH;
  1233. #if BIT_DEPTH < 14
  1234. int offset = 1 << (shift - 1);
  1235. #else
  1236. int offset = 0;
  1237. #endif
  1238. ox = ox * (1 << (BIT_DEPTH - 8));
  1239. for (y = 0; y < height; y++) {
  1240. for (x = 0; x < width; x++) {
  1241. dst[x] = av_clip_pixel((((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
  1242. }
  1243. dst += dststride;
  1244. src += srcstride;
  1245. }
  1246. }
  1247. static void FUNC(put_hevc_epel_bi_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  1248. int16_t *src2,
  1249. int height, int denom, int wx0, int wx1,
  1250. int ox0, int ox1, intptr_t mx, intptr_t my, int width)
  1251. {
  1252. int x, y;
  1253. pixel *src = (pixel *)_src;
  1254. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  1255. const int8_t *filter = ff_hevc_epel_filters[my - 1];
  1256. pixel *dst = (pixel *)_dst;
  1257. ptrdiff_t dststride = _dststride / sizeof(pixel);
  1258. int shift = 14 + 1 - BIT_DEPTH;
  1259. int log2Wd = denom + shift - 1;
  1260. ox0 = ox0 * (1 << (BIT_DEPTH - 8));
  1261. ox1 = ox1 * (1 << (BIT_DEPTH - 8));
  1262. for (y = 0; y < height; y++) {
  1263. for (x = 0; x < width; x++)
  1264. dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
  1265. ((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
  1266. src += srcstride;
  1267. dst += dststride;
  1268. src2 += MAX_PB_SIZE;
  1269. }
  1270. }
  1271. static void FUNC(put_hevc_epel_uni_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  1272. int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
  1273. {
  1274. int x, y;
  1275. pixel *src = (pixel *)_src;
  1276. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  1277. pixel *dst = (pixel *)_dst;
  1278. ptrdiff_t dststride = _dststride / sizeof(pixel);
  1279. const int8_t *filter = ff_hevc_epel_filters[mx - 1];
  1280. int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
  1281. int16_t *tmp = tmp_array;
  1282. int shift = denom + 14 - BIT_DEPTH;
  1283. #if BIT_DEPTH < 14
  1284. int offset = 1 << (shift - 1);
  1285. #else
  1286. int offset = 0;
  1287. #endif
  1288. src -= EPEL_EXTRA_BEFORE * srcstride;
  1289. for (y = 0; y < height + EPEL_EXTRA; y++) {
  1290. for (x = 0; x < width; x++)
  1291. tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
  1292. src += srcstride;
  1293. tmp += MAX_PB_SIZE;
  1294. }
  1295. tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
  1296. filter = ff_hevc_epel_filters[my - 1];
  1297. ox = ox * (1 << (BIT_DEPTH - 8));
  1298. for (y = 0; y < height; y++) {
  1299. for (x = 0; x < width; x++)
  1300. dst[x] = av_clip_pixel((((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
  1301. tmp += MAX_PB_SIZE;
  1302. dst += dststride;
  1303. }
  1304. }
  1305. static void FUNC(put_hevc_epel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
  1306. int16_t *src2,
  1307. int height, int denom, int wx0, int wx1,
  1308. int ox0, int ox1, intptr_t mx, intptr_t my, int width)
  1309. {
  1310. int x, y;
  1311. pixel *src = (pixel *)_src;
  1312. ptrdiff_t srcstride = _srcstride / sizeof(pixel);
  1313. pixel *dst = (pixel *)_dst;
  1314. ptrdiff_t dststride = _dststride / sizeof(pixel);
  1315. const int8_t *filter = ff_hevc_epel_filters[mx - 1];
  1316. int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
  1317. int16_t *tmp = tmp_array;
  1318. int shift = 14 + 1 - BIT_DEPTH;
  1319. int log2Wd = denom + shift - 1;
  1320. src -= EPEL_EXTRA_BEFORE * srcstride;
  1321. for (y = 0; y < height + EPEL_EXTRA; y++) {
  1322. for (x = 0; x < width; x++)
  1323. tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
  1324. src += srcstride;
  1325. tmp += MAX_PB_SIZE;
  1326. }
  1327. tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
  1328. filter = ff_hevc_epel_filters[my - 1];
  1329. ox0 = ox0 * (1 << (BIT_DEPTH - 8));
  1330. ox1 = ox1 * (1 << (BIT_DEPTH - 8));
  1331. for (y = 0; y < height; y++) {
  1332. for (x = 0; x < width; x++)
  1333. dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 +
  1334. ((ox0 + ox1 + 1) * (1 << log2Wd))) >> (log2Wd + 1));
  1335. tmp += MAX_PB_SIZE;
  1336. dst += dststride;
  1337. src2 += MAX_PB_SIZE;
  1338. }
  1339. }// line zero
  1340. #define P3 pix[-4 * xstride]
  1341. #define P2 pix[-3 * xstride]
  1342. #define P1 pix[-2 * xstride]
  1343. #define P0 pix[-1 * xstride]
  1344. #define Q0 pix[0 * xstride]
  1345. #define Q1 pix[1 * xstride]
  1346. #define Q2 pix[2 * xstride]
  1347. #define Q3 pix[3 * xstride]
  1348. // line three. used only for deblocking decision
  1349. #define TP3 pix[-4 * xstride + 3 * ystride]
  1350. #define TP2 pix[-3 * xstride + 3 * ystride]
  1351. #define TP1 pix[-2 * xstride + 3 * ystride]
  1352. #define TP0 pix[-1 * xstride + 3 * ystride]
  1353. #define TQ0 pix[0 * xstride + 3 * ystride]
  1354. #define TQ1 pix[1 * xstride + 3 * ystride]
  1355. #define TQ2 pix[2 * xstride + 3 * ystride]
  1356. #define TQ3 pix[3 * xstride + 3 * ystride]
  1357. static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix,
  1358. ptrdiff_t _xstride, ptrdiff_t _ystride,
  1359. int beta, int *_tc,
  1360. uint8_t *_no_p, uint8_t *_no_q)
  1361. {
  1362. int d, j;
  1363. pixel *pix = (pixel *)_pix;
  1364. ptrdiff_t xstride = _xstride / sizeof(pixel);
  1365. ptrdiff_t ystride = _ystride / sizeof(pixel);
  1366. beta <<= BIT_DEPTH - 8;
  1367. for (j = 0; j < 2; j++) {
  1368. const int dp0 = abs(P2 - 2 * P1 + P0);
  1369. const int dq0 = abs(Q2 - 2 * Q1 + Q0);
  1370. const int dp3 = abs(TP2 - 2 * TP1 + TP0);
  1371. const int dq3 = abs(TQ2 - 2 * TQ1 + TQ0);
  1372. const int d0 = dp0 + dq0;
  1373. const int d3 = dp3 + dq3;
  1374. const int tc = _tc[j] << (BIT_DEPTH - 8);
  1375. const int no_p = _no_p[j];
  1376. const int no_q = _no_q[j];
  1377. if (d0 + d3 >= beta) {
  1378. pix += 4 * ystride;
  1379. continue;
  1380. } else {
  1381. const int beta_3 = beta >> 3;
  1382. const int beta_2 = beta >> 2;
  1383. const int tc25 = ((tc * 5 + 1) >> 1);
  1384. if (abs(P3 - P0) + abs(Q3 - Q0) < beta_3 && abs(P0 - Q0) < tc25 &&
  1385. abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 &&
  1386. (d0 << 1) < beta_2 && (d3 << 1) < beta_2) {
  1387. // strong filtering
  1388. const int tc2 = tc << 1;
  1389. for (d = 0; d < 4; d++) {
  1390. const int p3 = P3;
  1391. const int p2 = P2;
  1392. const int p1 = P1;
  1393. const int p0 = P0;
  1394. const int q0 = Q0;
  1395. const int q1 = Q1;
  1396. const int q2 = Q2;
  1397. const int q3 = Q3;
  1398. if (!no_p) {
  1399. P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc2, tc2);
  1400. P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2);
  1401. P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc2, tc2);
  1402. }
  1403. if (!no_q) {
  1404. Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc2, tc2);
  1405. Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2);
  1406. Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc2, tc2);
  1407. }
  1408. pix += ystride;
  1409. }
  1410. } else { // normal filtering
  1411. int nd_p = 1;
  1412. int nd_q = 1;
  1413. const int tc_2 = tc >> 1;
  1414. if (dp0 + dp3 < ((beta + (beta >> 1)) >> 3))
  1415. nd_p = 2;
  1416. if (dq0 + dq3 < ((beta + (beta >> 1)) >> 3))
  1417. nd_q = 2;
  1418. for (d = 0; d < 4; d++) {
  1419. const int p2 = P2;
  1420. const int p1 = P1;
  1421. const int p0 = P0;
  1422. const int q0 = Q0;
  1423. const int q1 = Q1;
  1424. const int q2 = Q2;
  1425. int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4;
  1426. if (abs(delta0) < 10 * tc) {
  1427. delta0 = av_clip(delta0, -tc, tc);
  1428. if (!no_p)
  1429. P0 = av_clip_pixel(p0 + delta0);
  1430. if (!no_q)
  1431. Q0 = av_clip_pixel(q0 - delta0);
  1432. if (!no_p && nd_p > 1) {
  1433. const int deltap1 = av_clip((((p2 + p0 + 1) >> 1) - p1 + delta0) >> 1, -tc_2, tc_2);
  1434. P1 = av_clip_pixel(p1 + deltap1);
  1435. }
  1436. if (!no_q && nd_q > 1) {
  1437. const int deltaq1 = av_clip((((q2 + q0 + 1) >> 1) - q1 - delta0) >> 1, -tc_2, tc_2);
  1438. Q1 = av_clip_pixel(q1 + deltaq1);
  1439. }
  1440. }
  1441. pix += ystride;
  1442. }
  1443. }
  1444. }
  1445. }
  1446. }
  1447. static void FUNC(hevc_loop_filter_chroma)(uint8_t *_pix, ptrdiff_t _xstride,
  1448. ptrdiff_t _ystride, int *_tc,
  1449. uint8_t *_no_p, uint8_t *_no_q)
  1450. {
  1451. int d, j, no_p, no_q;
  1452. pixel *pix = (pixel *)_pix;
  1453. ptrdiff_t xstride = _xstride / sizeof(pixel);
  1454. ptrdiff_t ystride = _ystride / sizeof(pixel);
  1455. for (j = 0; j < 2; j++) {
  1456. const int tc = _tc[j] << (BIT_DEPTH - 8);
  1457. if (tc <= 0) {
  1458. pix += 4 * ystride;
  1459. continue;
  1460. }
  1461. no_p = _no_p[j];
  1462. no_q = _no_q[j];
  1463. for (d = 0; d < 4; d++) {
  1464. int delta0;
  1465. const int p1 = P1;
  1466. const int p0 = P0;
  1467. const int q0 = Q0;
  1468. const int q1 = Q1;
  1469. delta0 = av_clip((((q0 - p0) * 4) + p1 - q1 + 4) >> 3, -tc, tc);
  1470. if (!no_p)
  1471. P0 = av_clip_pixel(p0 + delta0);
  1472. if (!no_q)
  1473. Q0 = av_clip_pixel(q0 - delta0);
  1474. pix += ystride;
  1475. }
  1476. }
  1477. }
  1478. static void FUNC(hevc_h_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride,
  1479. int32_t *tc, uint8_t *no_p,
  1480. uint8_t *no_q)
  1481. {
  1482. FUNC(hevc_loop_filter_chroma)(pix, stride, sizeof(pixel), tc, no_p, no_q);
  1483. }
  1484. static void FUNC(hevc_v_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride,
  1485. int32_t *tc, uint8_t *no_p,
  1486. uint8_t *no_q)
  1487. {
  1488. FUNC(hevc_loop_filter_chroma)(pix, sizeof(pixel), stride, tc, no_p, no_q);
  1489. }
  1490. static void FUNC(hevc_h_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride,
  1491. int beta, int32_t *tc, uint8_t *no_p,
  1492. uint8_t *no_q)
  1493. {
  1494. FUNC(hevc_loop_filter_luma)(pix, stride, sizeof(pixel),
  1495. beta, tc, no_p, no_q);
  1496. }
  1497. static void FUNC(hevc_v_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride,
  1498. int beta, int32_t *tc, uint8_t *no_p,
  1499. uint8_t *no_q)
  1500. {
  1501. FUNC(hevc_loop_filter_luma)(pix, sizeof(pixel), stride,
  1502. beta, tc, no_p, no_q);
  1503. }
  1504. #undef P3
  1505. #undef P2
  1506. #undef P1
  1507. #undef P0
  1508. #undef Q0
  1509. #undef Q1
  1510. #undef Q2
  1511. #undef Q3
  1512. #undef TP3
  1513. #undef TP2
  1514. #undef TP1
  1515. #undef TP0
  1516. #undef TQ0
  1517. #undef TQ1
  1518. #undef TQ2
  1519. #undef TQ3