4 * Copyright (C) 2012 - 2013 Guillaume Martres
6 * This file is part of FFmpeg.
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.
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.
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
26 #include "bit_depth_template.c"
30 static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int width, int height,
31 GetBitContext *gb, int pcm_bit_depth)
34 pixel *dst = (pixel *)_dst;
36 stride /= sizeof(pixel);
38 for (y = 0; y < height; y++) {
39 for (x = 0; x < width; x++)
40 dst[x] = get_bits(gb, pcm_bit_depth) << (BIT_DEPTH - pcm_bit_depth);
45 static av_always_inline void FUNC(transquant_bypass)(uint8_t *_dst, int16_t *coeffs,
46 ptrdiff_t stride, int size)
49 pixel *dst = (pixel *)_dst;
51 stride /= sizeof(pixel);
53 for (y = 0; y < size; y++) {
54 for (x = 0; x < size; x++) {
55 dst[x] = av_clip_pixel(dst[x] + *coeffs);
62 static void FUNC(transform_add4x4)(uint8_t *_dst, int16_t *coeffs,
65 FUNC(transquant_bypass)(_dst, coeffs, stride, 4);
68 static void FUNC(transform_add8x8)(uint8_t *_dst, int16_t *coeffs,
71 FUNC(transquant_bypass)(_dst, coeffs, stride, 8);
74 static void FUNC(transform_add16x16)(uint8_t *_dst, int16_t *coeffs,
77 FUNC(transquant_bypass)(_dst, coeffs, stride, 16);
80 static void FUNC(transform_add32x32)(uint8_t *_dst, int16_t *coeffs,
83 FUNC(transquant_bypass)(_dst, coeffs, stride, 32);
87 static void FUNC(transform_rdpcm)(int16_t *_coeffs, int16_t log2_size, int mode)
89 int16_t *coeffs = (int16_t *) _coeffs;
91 int size = 1 << log2_size;
95 for (y = 0; y < size - 1; y++) {
96 for (x = 0; x < size; x++)
97 coeffs[x] += coeffs[x - size];
101 for (y = 0; y < size; y++) {
102 for (x = 1; x < size; x++)
103 coeffs[x] += coeffs[x - 1];
109 static void FUNC(transform_skip)(int16_t *_coeffs, int16_t log2_size)
111 int shift = 15 - BIT_DEPTH - log2_size;
113 int size = 1 << log2_size;
114 int16_t *coeffs = _coeffs;
118 int offset = 1 << (shift - 1);
119 for (y = 0; y < size; y++) {
120 for (x = 0; x < size; x++) {
121 *coeffs = (*coeffs + offset) >> shift;
126 for (y = 0; y < size; y++) {
127 for (x = 0; x < size; x++) {
128 *coeffs = *coeffs << -shift;
135 #define SET(dst, x) (dst) = (x)
136 #define SCALE(dst, x) (dst) = av_clip_int16(((x) + add) >> shift)
137 #define ADD_AND_SCALE(dst, x) \
138 (dst) = av_clip_pixel((dst) + av_clip_int16(((x) + add) >> shift))
140 #define TR_4x4_LUMA(dst, src, step, assign) \
142 int c0 = src[0 * step] + src[2 * step]; \
143 int c1 = src[2 * step] + src[3 * step]; \
144 int c2 = src[0 * step] - src[3 * step]; \
145 int c3 = 74 * src[1 * step]; \
147 assign(dst[2 * step], 74 * (src[0 * step] - \
150 assign(dst[0 * step], 29 * c0 + 55 * c1 + c3); \
151 assign(dst[1 * step], 55 * c2 - 29 * c1 + c3); \
152 assign(dst[3 * step], 55 * c0 + 29 * c2 - c3); \
155 static void FUNC(transform_4x4_luma)(int16_t *coeffs)
159 int add = 1 << (shift - 1);
160 int16_t *src = coeffs;
162 for (i = 0; i < 4; i++) {
163 TR_4x4_LUMA(src, src, 4, SCALE);
167 shift = 20 - BIT_DEPTH;
168 add = 1 << (shift - 1);
169 for (i = 0; i < 4; i++) {
170 TR_4x4_LUMA(coeffs, coeffs, 1, SCALE);
177 #define TR_4(dst, src, dstep, sstep, assign, end) \
179 const int e0 = 64 * src[0 * sstep] + 64 * src[2 * sstep]; \
180 const int e1 = 64 * src[0 * sstep] - 64 * src[2 * sstep]; \
181 const int o0 = 83 * src[1 * sstep] + 36 * src[3 * sstep]; \
182 const int o1 = 36 * src[1 * sstep] - 83 * src[3 * sstep]; \
184 assign(dst[0 * dstep], e0 + o0); \
185 assign(dst[1 * dstep], e1 + o1); \
186 assign(dst[2 * dstep], e1 - o1); \
187 assign(dst[3 * dstep], e0 - o0); \
190 #define TR_8(dst, src, dstep, sstep, assign, end) \
194 int o_8[4] = { 0 }; \
195 for (i = 0; i < 4; i++) \
196 for (j = 1; j < end; j += 2) \
197 o_8[i] += transform[4 * j][i] * src[j * sstep]; \
198 TR_4(e_8, src, 1, 2 * sstep, SET, 4); \
200 for (i = 0; i < 4; i++) { \
201 assign(dst[i * dstep], e_8[i] + o_8[i]); \
202 assign(dst[(7 - i) * dstep], e_8[i] - o_8[i]); \
206 #define TR_16(dst, src, dstep, sstep, assign, end) \
210 int o_16[8] = { 0 }; \
211 for (i = 0; i < 8; i++) \
212 for (j = 1; j < end; j += 2) \
213 o_16[i] += transform[2 * j][i] * src[j * sstep]; \
214 TR_8(e_16, src, 1, 2 * sstep, SET, 8); \
216 for (i = 0; i < 8; i++) { \
217 assign(dst[i * dstep], e_16[i] + o_16[i]); \
218 assign(dst[(15 - i) * dstep], e_16[i] - o_16[i]); \
222 #define TR_32(dst, src, dstep, sstep, assign, end) \
226 int o_32[16] = { 0 }; \
227 for (i = 0; i < 16; i++) \
228 for (j = 1; j < end; j += 2) \
229 o_32[i] += transform[j][i] * src[j * sstep]; \
230 TR_16(e_32, src, 1, 2 * sstep, SET, end/2); \
232 for (i = 0; i < 16; i++) { \
233 assign(dst[i * dstep], e_32[i] + o_32[i]); \
234 assign(dst[(31 - i) * dstep], e_32[i] - o_32[i]); \
238 #define IDCT_VAR4(H) \
239 int limit2 = FFMIN(col_limit + 4, H)
240 #define IDCT_VAR8(H) \
241 int limit = FFMIN(col_limit, H); \
242 int limit2 = FFMIN(col_limit + 4, H)
243 #define IDCT_VAR16(H) IDCT_VAR8(H)
244 #define IDCT_VAR32(H) IDCT_VAR8(H)
247 static void FUNC(idct_##H ##x ##H )( \
248 int16_t *coeffs, int col_limit) { \
251 int add = 1 << (shift - 1); \
252 int16_t *src = coeffs; \
255 for (i = 0; i < H; i++) { \
256 TR_ ## H(src, src, H, H, SCALE, limit2); \
257 if (limit2 < H && i%4 == 0 && !!i) \
262 shift = 20 - BIT_DEPTH; \
263 add = 1 << (shift - 1); \
264 for (i = 0; i < H; i++) { \
265 TR_ ## H(coeffs, coeffs, 1, 1, SCALE, limit); \
271 static void FUNC(idct_##H ##x ##H ##_dc)( \
274 int shift = 14 - BIT_DEPTH; \
275 int add = 1 << (shift - 1); \
276 int coeff = (((coeffs[0] + 1) >> 1) + add) >> shift; \
278 for (j = 0; j < H; j++) { \
279 for (i = 0; i < H; i++) { \
280 coeffs[i+j*H] = coeff; \
304 static void FUNC(sao_band_filter_0)(uint8_t *_dst, uint8_t *_src,
305 ptrdiff_t stride_dst, ptrdiff_t stride_src,
306 int16_t *sao_offset_val, int sao_left_class,
307 int width, int height)
309 pixel *dst = (pixel *)_dst;
310 pixel *src = (pixel *)_src;
311 int offset_table[32] = { 0 };
313 int shift = BIT_DEPTH - 5;
315 stride_dst /= sizeof(pixel);
316 stride_src /= sizeof(pixel);
318 for (k = 0; k < 4; k++)
319 offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
320 for (y = 0; y < height; y++) {
321 for (x = 0; x < width; x++)
322 dst[x] = av_clip_pixel(src[x] + offset_table[src[x] >> shift]);
328 #define CMP(a, b) ((a) > (b) ? 1 : ((a) == (b) ? 0 : -1))
330 static void FUNC(sao_edge_filter)(uint8_t *_dst, uint8_t *_src,
331 ptrdiff_t stride_dst, ptrdiff_t stride_src, SAOParams *sao,
332 int width, int height,
333 int c_idx, int init_x, int init_y) {
335 static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
336 static const int8_t pos[4][2][2] = {
337 { { -1, 0 }, { 1, 0 } }, // horizontal
338 { { 0, -1 }, { 0, 1 } }, // vertical
339 { { -1, -1 }, { 1, 1 } }, // 45 degree
340 { { 1, -1 }, { -1, 1 } }, // 135 degree
342 int16_t *sao_offset_val = sao->offset_val[c_idx];
343 int sao_eo_class = sao->eo_class[c_idx];
344 pixel *dst = (pixel *)_dst;
345 pixel *src = (pixel *)_src;
347 int y_stride_src = init_y * stride_src;
348 int y_stride_dst = init_y * stride_dst;
349 int pos_0_0 = pos[sao_eo_class][0][0];
350 int pos_0_1 = pos[sao_eo_class][0][1];
351 int pos_1_0 = pos[sao_eo_class][1][0];
352 int pos_1_1 = pos[sao_eo_class][1][1];
355 int y_stride_0_1 = (init_y + pos_0_1) * stride_src;
356 int y_stride_1_1 = (init_y + pos_1_1) * stride_src;
357 for (y = init_y; y < height; y++) {
358 for (x = init_x; x < width; x++) {
359 int diff0 = CMP(src[x + y_stride_src], src[x + pos_0_0 + y_stride_0_1]);
360 int diff1 = CMP(src[x + y_stride_src], src[x + pos_1_0 + y_stride_1_1]);
361 int offset_val = edge_idx[2 + diff0 + diff1];
362 dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + sao_offset_val[offset_val]);
364 y_stride_src += stride_src;
365 y_stride_dst += stride_dst;
366 y_stride_0_1 += stride_src;
367 y_stride_1_1 += stride_src;
371 static void FUNC(sao_edge_filter_0)(uint8_t *_dst, uint8_t *_src,
372 ptrdiff_t stride_dst, ptrdiff_t stride_src, SAOParams *sao,
373 int *borders, int _width, int _height,
374 int c_idx, uint8_t *vert_edge,
375 uint8_t *horiz_edge, uint8_t *diag_edge)
378 pixel *dst = (pixel *)_dst;
379 pixel *src = (pixel *)_src;
380 int16_t *sao_offset_val = sao->offset_val[c_idx];
381 int sao_eo_class = sao->eo_class[c_idx];
382 int init_x = 0, init_y = 0, width = _width, height = _height;
384 stride_dst /= sizeof(pixel);
385 stride_src /= sizeof(pixel);
387 if (sao_eo_class != SAO_EO_VERT) {
389 int offset_val = sao_offset_val[0];
390 for (y = 0; y < height; y++) {
391 dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
396 int offset_val = sao_offset_val[0];
397 int offset = width - 1;
398 for (x = 0; x < height; x++) {
399 dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
404 if (sao_eo_class != SAO_EO_HORIZ) {
406 int offset_val = sao_offset_val[0];
407 for (x = init_x; x < width; x++)
408 dst[x] = av_clip_pixel(src[x] + offset_val);
412 int offset_val = sao_offset_val[0];
413 int y_stride_dst = stride_dst * (height - 1);
414 int y_stride_src = stride_src * (height - 1);
415 for (x = init_x; x < width; x++)
416 dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
421 FUNC(sao_edge_filter)((uint8_t *)dst, (uint8_t *)src, stride_dst, stride_src, sao, width, height, c_idx, init_x, init_y);
424 static void FUNC(sao_edge_filter_1)(uint8_t *_dst, uint8_t *_src,
425 ptrdiff_t stride_dst, ptrdiff_t stride_src, SAOParams *sao,
426 int *borders, int _width, int _height,
427 int c_idx, uint8_t *vert_edge,
428 uint8_t *horiz_edge, uint8_t *diag_edge)
431 pixel *dst = (pixel *)_dst;
432 pixel *src = (pixel *)_src;
433 int16_t *sao_offset_val = sao->offset_val[c_idx];
434 int sao_eo_class = sao->eo_class[c_idx];
435 int init_x = 0, init_y = 0, width = _width, height = _height;
437 stride_dst /= sizeof(pixel);
438 stride_src /= sizeof(pixel);
440 if (sao_eo_class != SAO_EO_VERT) {
442 int offset_val = sao_offset_val[0];
443 for (y = 0; y < height; y++) {
444 dst[y * stride_dst] = av_clip_pixel(src[y * stride_src] + offset_val);
449 int offset_val = sao_offset_val[0];
450 int offset = width - 1;
451 for (x = 0; x < height; x++) {
452 dst[x * stride_dst + offset] = av_clip_pixel(src[x * stride_src + offset] + offset_val);
457 if (sao_eo_class != SAO_EO_HORIZ) {
459 int offset_val = sao_offset_val[0];
460 for (x = init_x; x < width; x++)
461 dst[x] = av_clip_pixel(src[x] + offset_val);
465 int offset_val = sao_offset_val[0];
466 int y_stride_dst = stride_dst * (height - 1);
467 int y_stride_src = stride_src * (height - 1);
468 for (x = init_x; x < width; x++)
469 dst[x + y_stride_dst] = av_clip_pixel(src[x + y_stride_src] + offset_val);
474 FUNC(sao_edge_filter)((uint8_t *)dst, (uint8_t *)src, stride_dst, stride_src, sao, width, height, c_idx, init_x, init_y);
477 int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
478 int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2];
479 int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3];
480 int save_lower_left = !diag_edge[3] && sao_eo_class == SAO_EO_45D && !borders[0] && !borders[3];
482 // Restore pixels that can't be modified
483 if(vert_edge[0] && sao_eo_class != SAO_EO_VERT) {
484 for(y = init_y+save_upper_left; y< height-save_lower_left; y++)
485 dst[y*stride_dst] = src[y*stride_src];
487 if(vert_edge[1] && sao_eo_class != SAO_EO_VERT) {
488 for(y = init_y+save_upper_right; y< height-save_lower_right; y++)
489 dst[y*stride_dst+width-1] = src[y*stride_src+width-1];
492 if(horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) {
493 for(x = init_x+save_upper_left; x < width-save_upper_right; x++)
496 if(horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) {
497 for(x = init_x+save_lower_left; x < width-save_lower_right; x++)
498 dst[(height-1)*stride_dst+x] = src[(height-1)*stride_src+x];
500 if(diag_edge[0] && sao_eo_class == SAO_EO_135D)
502 if(diag_edge[1] && sao_eo_class == SAO_EO_45D)
503 dst[width-1] = src[width-1];
504 if(diag_edge[2] && sao_eo_class == SAO_EO_135D)
505 dst[stride_dst*(height-1)+width-1] = src[stride_src*(height-1)+width-1];
506 if(diag_edge[3] && sao_eo_class == SAO_EO_45D)
507 dst[stride_dst*(height-1)] = src[stride_src*(height-1)];
514 ////////////////////////////////////////////////////////////////////////////////
516 ////////////////////////////////////////////////////////////////////////////////
517 static void FUNC(put_hevc_pel_pixels)(int16_t *dst,
518 uint8_t *_src, ptrdiff_t _srcstride,
519 int height, intptr_t mx, intptr_t my, int width)
522 pixel *src = (pixel *)_src;
523 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
525 for (y = 0; y < height; y++) {
526 for (x = 0; x < width; x++)
527 dst[x] = src[x] << (14 - BIT_DEPTH);
533 static void FUNC(put_hevc_pel_uni_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
534 int height, intptr_t mx, intptr_t my, int width)
537 pixel *src = (pixel *)_src;
538 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
539 pixel *dst = (pixel *)_dst;
540 ptrdiff_t dststride = _dststride / sizeof(pixel);
542 for (y = 0; y < height; y++) {
543 memcpy(dst, src, width * sizeof(pixel));
549 static void FUNC(put_hevc_pel_bi_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
551 int height, intptr_t mx, intptr_t my, int width)
554 pixel *src = (pixel *)_src;
555 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
556 pixel *dst = (pixel *)_dst;
557 ptrdiff_t dststride = _dststride / sizeof(pixel);
559 int shift = 14 + 1 - BIT_DEPTH;
561 int offset = 1 << (shift - 1);
566 for (y = 0; y < height; y++) {
567 for (x = 0; x < width; x++)
568 dst[x] = av_clip_pixel(((src[x] << (14 - BIT_DEPTH)) + src2[x] + offset) >> shift);
575 static void FUNC(put_hevc_pel_uni_w_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
576 int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
579 pixel *src = (pixel *)_src;
580 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
581 pixel *dst = (pixel *)_dst;
582 ptrdiff_t dststride = _dststride / sizeof(pixel);
583 int shift = denom + 14 - BIT_DEPTH;
585 int offset = 1 << (shift - 1);
590 ox = ox * (1 << (BIT_DEPTH - 8));
591 for (y = 0; y < height; y++) {
592 for (x = 0; x < width; x++)
593 dst[x] = av_clip_pixel((((src[x] << (14 - BIT_DEPTH)) * wx + offset) >> shift) + ox);
599 static void FUNC(put_hevc_pel_bi_w_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
601 int height, int denom, int wx0, int wx1,
602 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
605 pixel *src = (pixel *)_src;
606 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
607 pixel *dst = (pixel *)_dst;
608 ptrdiff_t dststride = _dststride / sizeof(pixel);
610 int shift = 14 + 1 - BIT_DEPTH;
611 int log2Wd = denom + shift - 1;
613 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
614 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
615 for (y = 0; y < height; y++) {
616 for (x = 0; x < width; x++) {
617 dst[x] = av_clip_pixel(( (src[x] << (14 - BIT_DEPTH)) * wx1 + src2[x] * wx0 + ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
625 ////////////////////////////////////////////////////////////////////////////////
627 ////////////////////////////////////////////////////////////////////////////////
628 #define QPEL_FILTER(src, stride) \
629 (filter[0] * src[x - 3 * stride] + \
630 filter[1] * src[x - 2 * stride] + \
631 filter[2] * src[x - stride] + \
632 filter[3] * src[x ] + \
633 filter[4] * src[x + stride] + \
634 filter[5] * src[x + 2 * stride] + \
635 filter[6] * src[x + 3 * stride] + \
636 filter[7] * src[x + 4 * stride])
638 static void FUNC(put_hevc_qpel_h)(int16_t *dst,
639 uint8_t *_src, ptrdiff_t _srcstride,
640 int height, intptr_t mx, intptr_t my, int width)
643 pixel *src = (pixel*)_src;
644 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
645 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
646 for (y = 0; y < height; y++) {
647 for (x = 0; x < width; x++)
648 dst[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
654 static void FUNC(put_hevc_qpel_v)(int16_t *dst,
655 uint8_t *_src, ptrdiff_t _srcstride,
656 int height, intptr_t mx, intptr_t my, int width)
659 pixel *src = (pixel*)_src;
660 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
661 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
662 for (y = 0; y < height; y++) {
663 for (x = 0; x < width; x++)
664 dst[x] = QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8);
670 static void FUNC(put_hevc_qpel_hv)(int16_t *dst,
672 ptrdiff_t _srcstride,
673 int height, intptr_t mx,
674 intptr_t my, int width)
677 const int8_t *filter;
678 pixel *src = (pixel*)_src;
679 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
680 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
681 int16_t *tmp = tmp_array;
683 src -= QPEL_EXTRA_BEFORE * srcstride;
684 filter = ff_hevc_qpel_filters[mx - 1];
685 for (y = 0; y < height + QPEL_EXTRA; y++) {
686 for (x = 0; x < width; x++)
687 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
692 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
693 filter = ff_hevc_qpel_filters[my - 1];
694 for (y = 0; y < height; y++) {
695 for (x = 0; x < width; x++)
696 dst[x] = QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6;
702 static void FUNC(put_hevc_qpel_uni_h)(uint8_t *_dst, ptrdiff_t _dststride,
703 uint8_t *_src, ptrdiff_t _srcstride,
704 int height, intptr_t mx, intptr_t my, int width)
707 pixel *src = (pixel*)_src;
708 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
709 pixel *dst = (pixel *)_dst;
710 ptrdiff_t dststride = _dststride / sizeof(pixel);
711 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
712 int shift = 14 - BIT_DEPTH;
715 int offset = 1 << (shift - 1);
720 for (y = 0; y < height; y++) {
721 for (x = 0; x < width; x++)
722 dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + offset) >> shift);
728 static void FUNC(put_hevc_qpel_bi_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
730 int height, intptr_t mx, intptr_t my, int width)
733 pixel *src = (pixel*)_src;
734 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
735 pixel *dst = (pixel *)_dst;
736 ptrdiff_t dststride = _dststride / sizeof(pixel);
738 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
740 int shift = 14 + 1 - BIT_DEPTH;
742 int offset = 1 << (shift - 1);
747 for (y = 0; y < height; y++) {
748 for (x = 0; x < width; x++)
749 dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
756 static void FUNC(put_hevc_qpel_uni_v)(uint8_t *_dst, ptrdiff_t _dststride,
757 uint8_t *_src, ptrdiff_t _srcstride,
758 int height, intptr_t mx, intptr_t my, int width)
761 pixel *src = (pixel*)_src;
762 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
763 pixel *dst = (pixel *)_dst;
764 ptrdiff_t dststride = _dststride / sizeof(pixel);
765 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
766 int shift = 14 - BIT_DEPTH;
769 int offset = 1 << (shift - 1);
774 for (y = 0; y < height; y++) {
775 for (x = 0; x < width; x++)
776 dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + offset) >> shift);
783 static void FUNC(put_hevc_qpel_bi_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
785 int height, intptr_t mx, intptr_t my, int width)
788 pixel *src = (pixel*)_src;
789 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
790 pixel *dst = (pixel *)_dst;
791 ptrdiff_t dststride = _dststride / sizeof(pixel);
793 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
795 int shift = 14 + 1 - BIT_DEPTH;
797 int offset = 1 << (shift - 1);
802 for (y = 0; y < height; y++) {
803 for (x = 0; x < width; x++)
804 dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
811 static void FUNC(put_hevc_qpel_uni_hv)(uint8_t *_dst, ptrdiff_t _dststride,
812 uint8_t *_src, ptrdiff_t _srcstride,
813 int height, intptr_t mx, intptr_t my, int width)
816 const int8_t *filter;
817 pixel *src = (pixel*)_src;
818 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
819 pixel *dst = (pixel *)_dst;
820 ptrdiff_t dststride = _dststride / sizeof(pixel);
821 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
822 int16_t *tmp = tmp_array;
823 int shift = 14 - BIT_DEPTH;
826 int offset = 1 << (shift - 1);
831 src -= QPEL_EXTRA_BEFORE * srcstride;
832 filter = ff_hevc_qpel_filters[mx - 1];
833 for (y = 0; y < height + QPEL_EXTRA; y++) {
834 for (x = 0; x < width; x++)
835 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
840 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
841 filter = ff_hevc_qpel_filters[my - 1];
843 for (y = 0; y < height; y++) {
844 for (x = 0; x < width; x++)
845 dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + offset) >> shift);
851 static void FUNC(put_hevc_qpel_bi_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
853 int height, intptr_t mx, intptr_t my, int width)
856 const int8_t *filter;
857 pixel *src = (pixel*)_src;
858 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
859 pixel *dst = (pixel *)_dst;
860 ptrdiff_t dststride = _dststride / sizeof(pixel);
861 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
862 int16_t *tmp = tmp_array;
863 int shift = 14 + 1 - BIT_DEPTH;
865 int offset = 1 << (shift - 1);
870 src -= QPEL_EXTRA_BEFORE * srcstride;
871 filter = ff_hevc_qpel_filters[mx - 1];
872 for (y = 0; y < height + QPEL_EXTRA; y++) {
873 for (x = 0; x < width; x++)
874 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
879 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
880 filter = ff_hevc_qpel_filters[my - 1];
882 for (y = 0; y < height; y++) {
883 for (x = 0; x < width; x++)
884 dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + src2[x] + offset) >> shift);
891 static void FUNC(put_hevc_qpel_uni_w_h)(uint8_t *_dst, ptrdiff_t _dststride,
892 uint8_t *_src, ptrdiff_t _srcstride,
893 int height, int denom, int wx, int ox,
894 intptr_t mx, intptr_t my, int width)
897 pixel *src = (pixel*)_src;
898 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
899 pixel *dst = (pixel *)_dst;
900 ptrdiff_t dststride = _dststride / sizeof(pixel);
901 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
902 int shift = denom + 14 - BIT_DEPTH;
904 int offset = 1 << (shift - 1);
909 ox = ox * (1 << (BIT_DEPTH - 8));
910 for (y = 0; y < height; y++) {
911 for (x = 0; x < width; x++)
912 dst[x] = av_clip_pixel((((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
918 static void FUNC(put_hevc_qpel_bi_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
920 int height, int denom, int wx0, int wx1,
921 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
924 pixel *src = (pixel*)_src;
925 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
926 pixel *dst = (pixel *)_dst;
927 ptrdiff_t dststride = _dststride / sizeof(pixel);
929 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
931 int shift = 14 + 1 - BIT_DEPTH;
932 int log2Wd = denom + shift - 1;
934 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
935 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
936 for (y = 0; y < height; y++) {
937 for (x = 0; x < width; x++)
938 dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
939 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
946 static void FUNC(put_hevc_qpel_uni_w_v)(uint8_t *_dst, ptrdiff_t _dststride,
947 uint8_t *_src, ptrdiff_t _srcstride,
948 int height, int denom, int wx, int ox,
949 intptr_t mx, intptr_t my, int width)
952 pixel *src = (pixel*)_src;
953 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
954 pixel *dst = (pixel *)_dst;
955 ptrdiff_t dststride = _dststride / sizeof(pixel);
956 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
957 int shift = denom + 14 - BIT_DEPTH;
959 int offset = 1 << (shift - 1);
964 ox = ox * (1 << (BIT_DEPTH - 8));
965 for (y = 0; y < height; y++) {
966 for (x = 0; x < width; x++)
967 dst[x] = av_clip_pixel((((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
973 static void FUNC(put_hevc_qpel_bi_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
975 int height, int denom, int wx0, int wx1,
976 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
979 pixel *src = (pixel*)_src;
980 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
981 pixel *dst = (pixel *)_dst;
982 ptrdiff_t dststride = _dststride / sizeof(pixel);
984 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
986 int shift = 14 + 1 - BIT_DEPTH;
987 int log2Wd = denom + shift - 1;
989 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
990 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
991 for (y = 0; y < height; y++) {
992 for (x = 0; x < width; x++)
993 dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
994 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1001 static void FUNC(put_hevc_qpel_uni_w_hv)(uint8_t *_dst, ptrdiff_t _dststride,
1002 uint8_t *_src, ptrdiff_t _srcstride,
1003 int height, int denom, int wx, int ox,
1004 intptr_t mx, intptr_t my, int width)
1007 const int8_t *filter;
1008 pixel *src = (pixel*)_src;
1009 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1010 pixel *dst = (pixel *)_dst;
1011 ptrdiff_t dststride = _dststride / sizeof(pixel);
1012 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
1013 int16_t *tmp = tmp_array;
1014 int shift = denom + 14 - BIT_DEPTH;
1016 int offset = 1 << (shift - 1);
1021 src -= QPEL_EXTRA_BEFORE * srcstride;
1022 filter = ff_hevc_qpel_filters[mx - 1];
1023 for (y = 0; y < height + QPEL_EXTRA; y++) {
1024 for (x = 0; x < width; x++)
1025 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1030 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1031 filter = ff_hevc_qpel_filters[my - 1];
1033 ox = ox * (1 << (BIT_DEPTH - 8));
1034 for (y = 0; y < height; y++) {
1035 for (x = 0; x < width; x++)
1036 dst[x] = av_clip_pixel((((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
1042 static void FUNC(put_hevc_qpel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1044 int height, int denom, int wx0, int wx1,
1045 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1048 const int8_t *filter;
1049 pixel *src = (pixel*)_src;
1050 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1051 pixel *dst = (pixel *)_dst;
1052 ptrdiff_t dststride = _dststride / sizeof(pixel);
1053 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
1054 int16_t *tmp = tmp_array;
1055 int shift = 14 + 1 - BIT_DEPTH;
1056 int log2Wd = denom + shift - 1;
1058 src -= QPEL_EXTRA_BEFORE * srcstride;
1059 filter = ff_hevc_qpel_filters[mx - 1];
1060 for (y = 0; y < height + QPEL_EXTRA; y++) {
1061 for (x = 0; x < width; x++)
1062 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1067 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1068 filter = ff_hevc_qpel_filters[my - 1];
1070 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1071 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1072 for (y = 0; y < height; y++) {
1073 for (x = 0; x < width; x++)
1074 dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 +
1075 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1078 src2 += MAX_PB_SIZE;
1082 ////////////////////////////////////////////////////////////////////////////////
1084 ////////////////////////////////////////////////////////////////////////////////
1085 #define EPEL_FILTER(src, stride) \
1086 (filter[0] * src[x - stride] + \
1087 filter[1] * src[x] + \
1088 filter[2] * src[x + stride] + \
1089 filter[3] * src[x + 2 * stride])
1091 static void FUNC(put_hevc_epel_h)(int16_t *dst,
1092 uint8_t *_src, ptrdiff_t _srcstride,
1093 int height, intptr_t mx, intptr_t my, int width)
1096 pixel *src = (pixel *)_src;
1097 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1098 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1099 for (y = 0; y < height; y++) {
1100 for (x = 0; x < width; x++)
1101 dst[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1107 static void FUNC(put_hevc_epel_v)(int16_t *dst,
1108 uint8_t *_src, ptrdiff_t _srcstride,
1109 int height, intptr_t mx, intptr_t my, int width)
1112 pixel *src = (pixel *)_src;
1113 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1114 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1116 for (y = 0; y < height; y++) {
1117 for (x = 0; x < width; x++)
1118 dst[x] = EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8);
1124 static void FUNC(put_hevc_epel_hv)(int16_t *dst,
1125 uint8_t *_src, ptrdiff_t _srcstride,
1126 int height, intptr_t mx, intptr_t my, int width)
1129 pixel *src = (pixel *)_src;
1130 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1131 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1132 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1133 int16_t *tmp = tmp_array;
1135 src -= EPEL_EXTRA_BEFORE * srcstride;
1137 for (y = 0; y < height + EPEL_EXTRA; y++) {
1138 for (x = 0; x < width; x++)
1139 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1144 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1145 filter = ff_hevc_epel_filters[my - 1];
1147 for (y = 0; y < height; y++) {
1148 for (x = 0; x < width; x++)
1149 dst[x] = EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6;
1155 static void FUNC(put_hevc_epel_uni_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1156 int height, intptr_t mx, intptr_t my, int width)
1159 pixel *src = (pixel *)_src;
1160 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1161 pixel *dst = (pixel *)_dst;
1162 ptrdiff_t dststride = _dststride / sizeof(pixel);
1163 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1164 int shift = 14 - BIT_DEPTH;
1166 int offset = 1 << (shift - 1);
1171 for (y = 0; y < height; y++) {
1172 for (x = 0; x < width; x++)
1173 dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + offset) >> shift);
1179 static void FUNC(put_hevc_epel_bi_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1181 int height, intptr_t mx, intptr_t my, int width)
1184 pixel *src = (pixel *)_src;
1185 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1186 pixel *dst = (pixel *)_dst;
1187 ptrdiff_t dststride = _dststride / sizeof(pixel);
1188 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1189 int shift = 14 + 1 - BIT_DEPTH;
1191 int offset = 1 << (shift - 1);
1196 for (y = 0; y < height; y++) {
1197 for (x = 0; x < width; x++) {
1198 dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
1202 src2 += MAX_PB_SIZE;
1206 static void FUNC(put_hevc_epel_uni_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1207 int height, intptr_t mx, intptr_t my, int width)
1210 pixel *src = (pixel *)_src;
1211 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1212 pixel *dst = (pixel *)_dst;
1213 ptrdiff_t dststride = _dststride / sizeof(pixel);
1214 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1215 int shift = 14 - BIT_DEPTH;
1217 int offset = 1 << (shift - 1);
1222 for (y = 0; y < height; y++) {
1223 for (x = 0; x < width; x++)
1224 dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + offset) >> shift);
1230 static void FUNC(put_hevc_epel_bi_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1232 int height, intptr_t mx, intptr_t my, int width)
1235 pixel *src = (pixel *)_src;
1236 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1237 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1238 pixel *dst = (pixel *)_dst;
1239 ptrdiff_t dststride = _dststride / sizeof(pixel);
1240 int shift = 14 + 1 - BIT_DEPTH;
1242 int offset = 1 << (shift - 1);
1247 for (y = 0; y < height; y++) {
1248 for (x = 0; x < width; x++)
1249 dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
1252 src2 += MAX_PB_SIZE;
1256 static void FUNC(put_hevc_epel_uni_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1257 int height, intptr_t mx, intptr_t my, int width)
1260 pixel *src = (pixel *)_src;
1261 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1262 pixel *dst = (pixel *)_dst;
1263 ptrdiff_t dststride = _dststride / sizeof(pixel);
1264 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1265 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1266 int16_t *tmp = tmp_array;
1267 int shift = 14 - BIT_DEPTH;
1269 int offset = 1 << (shift - 1);
1274 src -= EPEL_EXTRA_BEFORE * srcstride;
1276 for (y = 0; y < height + EPEL_EXTRA; y++) {
1277 for (x = 0; x < width; x++)
1278 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1283 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1284 filter = ff_hevc_epel_filters[my - 1];
1286 for (y = 0; y < height; y++) {
1287 for (x = 0; x < width; x++)
1288 dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + offset) >> shift);
1294 static void FUNC(put_hevc_epel_bi_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1296 int height, intptr_t mx, intptr_t my, int width)
1299 pixel *src = (pixel *)_src;
1300 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1301 pixel *dst = (pixel *)_dst;
1302 ptrdiff_t dststride = _dststride / sizeof(pixel);
1303 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1304 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1305 int16_t *tmp = tmp_array;
1306 int shift = 14 + 1 - BIT_DEPTH;
1308 int offset = 1 << (shift - 1);
1313 src -= EPEL_EXTRA_BEFORE * srcstride;
1315 for (y = 0; y < height + EPEL_EXTRA; y++) {
1316 for (x = 0; x < width; x++)
1317 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1322 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1323 filter = ff_hevc_epel_filters[my - 1];
1325 for (y = 0; y < height; y++) {
1326 for (x = 0; x < width; x++)
1327 dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + src2[x] + offset) >> shift);
1330 src2 += MAX_PB_SIZE;
1334 static void FUNC(put_hevc_epel_uni_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1335 int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
1338 pixel *src = (pixel *)_src;
1339 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1340 pixel *dst = (pixel *)_dst;
1341 ptrdiff_t dststride = _dststride / sizeof(pixel);
1342 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1343 int shift = denom + 14 - BIT_DEPTH;
1345 int offset = 1 << (shift - 1);
1350 ox = ox * (1 << (BIT_DEPTH - 8));
1351 for (y = 0; y < height; y++) {
1352 for (x = 0; x < width; x++) {
1353 dst[x] = av_clip_pixel((((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
1360 static void FUNC(put_hevc_epel_bi_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1362 int height, int denom, int wx0, int wx1,
1363 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1366 pixel *src = (pixel *)_src;
1367 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1368 pixel *dst = (pixel *)_dst;
1369 ptrdiff_t dststride = _dststride / sizeof(pixel);
1370 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1371 int shift = 14 + 1 - BIT_DEPTH;
1372 int log2Wd = denom + shift - 1;
1374 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1375 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1376 for (y = 0; y < height; y++) {
1377 for (x = 0; x < width; x++)
1378 dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
1379 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1382 src2 += MAX_PB_SIZE;
1386 static void FUNC(put_hevc_epel_uni_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1387 int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
1390 pixel *src = (pixel *)_src;
1391 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1392 pixel *dst = (pixel *)_dst;
1393 ptrdiff_t dststride = _dststride / sizeof(pixel);
1394 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1395 int shift = denom + 14 - BIT_DEPTH;
1397 int offset = 1 << (shift - 1);
1402 ox = ox * (1 << (BIT_DEPTH - 8));
1403 for (y = 0; y < height; y++) {
1404 for (x = 0; x < width; x++) {
1405 dst[x] = av_clip_pixel((((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
1412 static void FUNC(put_hevc_epel_bi_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1414 int height, int denom, int wx0, int wx1,
1415 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1418 pixel *src = (pixel *)_src;
1419 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1420 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1421 pixel *dst = (pixel *)_dst;
1422 ptrdiff_t dststride = _dststride / sizeof(pixel);
1423 int shift = 14 + 1 - BIT_DEPTH;
1424 int log2Wd = denom + shift - 1;
1426 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1427 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1428 for (y = 0; y < height; y++) {
1429 for (x = 0; x < width; x++)
1430 dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
1431 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1434 src2 += MAX_PB_SIZE;
1438 static void FUNC(put_hevc_epel_uni_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1439 int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
1442 pixel *src = (pixel *)_src;
1443 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1444 pixel *dst = (pixel *)_dst;
1445 ptrdiff_t dststride = _dststride / sizeof(pixel);
1446 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1447 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1448 int16_t *tmp = tmp_array;
1449 int shift = denom + 14 - BIT_DEPTH;
1451 int offset = 1 << (shift - 1);
1456 src -= EPEL_EXTRA_BEFORE * srcstride;
1458 for (y = 0; y < height + EPEL_EXTRA; y++) {
1459 for (x = 0; x < width; x++)
1460 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1465 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1466 filter = ff_hevc_epel_filters[my - 1];
1468 ox = ox * (1 << (BIT_DEPTH - 8));
1469 for (y = 0; y < height; y++) {
1470 for (x = 0; x < width; x++)
1471 dst[x] = av_clip_pixel((((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
1477 static void FUNC(put_hevc_epel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1479 int height, int denom, int wx0, int wx1,
1480 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1483 pixel *src = (pixel *)_src;
1484 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1485 pixel *dst = (pixel *)_dst;
1486 ptrdiff_t dststride = _dststride / sizeof(pixel);
1487 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1488 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1489 int16_t *tmp = tmp_array;
1490 int shift = 14 + 1 - BIT_DEPTH;
1491 int log2Wd = denom + shift - 1;
1493 src -= EPEL_EXTRA_BEFORE * srcstride;
1495 for (y = 0; y < height + EPEL_EXTRA; y++) {
1496 for (x = 0; x < width; x++)
1497 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1502 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1503 filter = ff_hevc_epel_filters[my - 1];
1505 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1506 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1507 for (y = 0; y < height; y++) {
1508 for (x = 0; x < width; x++)
1509 dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 +
1510 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1513 src2 += MAX_PB_SIZE;
1516 #define P3 pix[-4 * xstride]
1517 #define P2 pix[-3 * xstride]
1518 #define P1 pix[-2 * xstride]
1519 #define P0 pix[-1 * xstride]
1520 #define Q0 pix[0 * xstride]
1521 #define Q1 pix[1 * xstride]
1522 #define Q2 pix[2 * xstride]
1523 #define Q3 pix[3 * xstride]
1525 // line three. used only for deblocking decision
1526 #define TP3 pix[-4 * xstride + 3 * ystride]
1527 #define TP2 pix[-3 * xstride + 3 * ystride]
1528 #define TP1 pix[-2 * xstride + 3 * ystride]
1529 #define TP0 pix[-1 * xstride + 3 * ystride]
1530 #define TQ0 pix[0 * xstride + 3 * ystride]
1531 #define TQ1 pix[1 * xstride + 3 * ystride]
1532 #define TQ2 pix[2 * xstride + 3 * ystride]
1533 #define TQ3 pix[3 * xstride + 3 * ystride]
1535 static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix,
1536 ptrdiff_t _xstride, ptrdiff_t _ystride,
1538 uint8_t *_no_p, uint8_t *_no_q)
1541 pixel *pix = (pixel *)_pix;
1542 ptrdiff_t xstride = _xstride / sizeof(pixel);
1543 ptrdiff_t ystride = _ystride / sizeof(pixel);
1545 beta <<= BIT_DEPTH - 8;
1547 for (j = 0; j < 2; j++) {
1548 const int dp0 = abs(P2 - 2 * P1 + P0);
1549 const int dq0 = abs(Q2 - 2 * Q1 + Q0);
1550 const int dp3 = abs(TP2 - 2 * TP1 + TP0);
1551 const int dq3 = abs(TQ2 - 2 * TQ1 + TQ0);
1552 const int d0 = dp0 + dq0;
1553 const int d3 = dp3 + dq3;
1554 const int tc = _tc[j] << (BIT_DEPTH - 8);
1555 const int no_p = _no_p[j];
1556 const int no_q = _no_q[j];
1558 if (d0 + d3 >= beta) {
1562 const int beta_3 = beta >> 3;
1563 const int beta_2 = beta >> 2;
1564 const int tc25 = ((tc * 5 + 1) >> 1);
1566 if (abs(P3 - P0) + abs(Q3 - Q0) < beta_3 && abs(P0 - Q0) < tc25 &&
1567 abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 &&
1568 (d0 << 1) < beta_2 && (d3 << 1) < beta_2) {
1570 const int tc2 = tc << 1;
1571 for (d = 0; d < 4; d++) {
1581 P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc2, tc2);
1582 P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2);
1583 P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc2, tc2);
1586 Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc2, tc2);
1587 Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2);
1588 Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc2, tc2);
1592 } else { // normal filtering
1595 const int tc_2 = tc >> 1;
1596 if (dp0 + dp3 < ((beta + (beta >> 1)) >> 3))
1598 if (dq0 + dq3 < ((beta + (beta >> 1)) >> 3))
1601 for (d = 0; d < 4; d++) {
1608 int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4;
1609 if (abs(delta0) < 10 * tc) {
1610 delta0 = av_clip(delta0, -tc, tc);
1612 P0 = av_clip_pixel(p0 + delta0);
1614 Q0 = av_clip_pixel(q0 - delta0);
1615 if (!no_p && nd_p > 1) {
1616 const int deltap1 = av_clip((((p2 + p0 + 1) >> 1) - p1 + delta0) >> 1, -tc_2, tc_2);
1617 P1 = av_clip_pixel(p1 + deltap1);
1619 if (!no_q && nd_q > 1) {
1620 const int deltaq1 = av_clip((((q2 + q0 + 1) >> 1) - q1 - delta0) >> 1, -tc_2, tc_2);
1621 Q1 = av_clip_pixel(q1 + deltaq1);
1631 static void FUNC(hevc_loop_filter_chroma)(uint8_t *_pix, ptrdiff_t _xstride,
1632 ptrdiff_t _ystride, int *_tc,
1633 uint8_t *_no_p, uint8_t *_no_q)
1635 int d, j, no_p, no_q;
1636 pixel *pix = (pixel *)_pix;
1637 ptrdiff_t xstride = _xstride / sizeof(pixel);
1638 ptrdiff_t ystride = _ystride / sizeof(pixel);
1640 for (j = 0; j < 2; j++) {
1641 const int tc = _tc[j] << (BIT_DEPTH - 8);
1649 for (d = 0; d < 4; d++) {
1655 delta0 = av_clip((((q0 - p0) * 4) + p1 - q1 + 4) >> 3, -tc, tc);
1657 P0 = av_clip_pixel(p0 + delta0);
1659 Q0 = av_clip_pixel(q0 - delta0);
1665 static void FUNC(hevc_h_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride,
1666 int32_t *tc, uint8_t *no_p,
1669 FUNC(hevc_loop_filter_chroma)(pix, stride, sizeof(pixel), tc, no_p, no_q);
1672 static void FUNC(hevc_v_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride,
1673 int32_t *tc, uint8_t *no_p,
1676 FUNC(hevc_loop_filter_chroma)(pix, sizeof(pixel), stride, tc, no_p, no_q);
1679 static void FUNC(hevc_h_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride,
1680 int beta, int32_t *tc, uint8_t *no_p,
1683 FUNC(hevc_loop_filter_luma)(pix, stride, sizeof(pixel),
1684 beta, tc, no_p, no_q);
1687 static void FUNC(hevc_v_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride,
1688 int beta, int32_t *tc, uint8_t *no_p,
1691 FUNC(hevc_loop_filter_luma)(pix, sizeof(pixel), stride,
1692 beta, tc, no_p, no_q);