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 void FUNC(transform_add4x4)(uint8_t *_dst, int16_t *coeffs,
49 pixel *dst = (pixel *)_dst;
51 stride /= sizeof(pixel);
53 for (y = 0; y < 4; y++) {
54 for (x = 0; x < 4; x++) {
55 dst[x] = av_clip_pixel(dst[x] + *coeffs);
62 static void FUNC(transform_add8x8)(uint8_t *_dst, int16_t *coeffs,
66 pixel *dst = (pixel *)_dst;
68 stride /= sizeof(pixel);
70 for (y = 0; y < 8; y++) {
71 for (x = 0; x < 8; x++) {
72 dst[x] = av_clip_pixel(dst[x] + *coeffs);
79 static void FUNC(transform_add16x16)(uint8_t *_dst, int16_t *coeffs,
83 pixel *dst = (pixel *)_dst;
85 stride /= sizeof(pixel);
87 for (y = 0; y < 16; y++) {
88 for (x = 0; x < 16; x++) {
89 dst[x] = av_clip_pixel(dst[x] + *coeffs);
96 static void FUNC(transform_add32x32)(uint8_t *_dst, int16_t *coeffs,
100 pixel *dst = (pixel *)_dst;
102 stride /= sizeof(pixel);
104 for (y = 0; y < 32; y++) {
105 for (x = 0; x < 32; x++) {
106 dst[x] = av_clip_pixel(dst[x] + *coeffs);
113 static void FUNC(transform_skip)(int16_t *_coeffs, int16_t log2_size)
115 int shift = 15 - BIT_DEPTH - log2_size;
117 int size = 1 << log2_size;
118 int16_t *coeffs = _coeffs;
122 int offset = 1 << (shift - 1);
123 for (y = 0; y < size; y++) {
124 for (x = 0; x < size; x++) {
125 *coeffs = (*coeffs + offset) >> shift;
130 for (y = 0; y < size; y++) {
131 for (x = 0; x < size; x++) {
132 *coeffs = *coeffs << -shift;
139 #define SET(dst, x) (dst) = (x)
140 #define SCALE(dst, x) (dst) = av_clip_int16(((x) + add) >> shift)
141 #define ADD_AND_SCALE(dst, x) \
142 (dst) = av_clip_pixel((dst) + av_clip_int16(((x) + add) >> shift))
144 #define TR_4x4_LUMA(dst, src, step, assign) \
146 int c0 = src[0 * step] + src[2 * step]; \
147 int c1 = src[2 * step] + src[3 * step]; \
148 int c2 = src[0 * step] - src[3 * step]; \
149 int c3 = 74 * src[1 * step]; \
151 assign(dst[2 * step], 74 * (src[0 * step] - \
154 assign(dst[0 * step], 29 * c0 + 55 * c1 + c3); \
155 assign(dst[1 * step], 55 * c2 - 29 * c1 + c3); \
156 assign(dst[3 * step], 55 * c0 + 29 * c2 - c3); \
159 static void FUNC(transform_4x4_luma)(int16_t *coeffs)
163 int add = 1 << (shift - 1);
164 int16_t *src = coeffs;
166 for (i = 0; i < 4; i++) {
167 TR_4x4_LUMA(src, src, 4, SCALE);
171 shift = 20 - BIT_DEPTH;
172 add = 1 << (shift - 1);
173 for (i = 0; i < 4; i++) {
174 TR_4x4_LUMA(coeffs, coeffs, 1, SCALE);
181 #define TR_4(dst, src, dstep, sstep, assign, end) \
183 const int e0 = 64 * src[0 * sstep] + 64 * src[2 * sstep]; \
184 const int e1 = 64 * src[0 * sstep] - 64 * src[2 * sstep]; \
185 const int o0 = 83 * src[1 * sstep] + 36 * src[3 * sstep]; \
186 const int o1 = 36 * src[1 * sstep] - 83 * src[3 * sstep]; \
188 assign(dst[0 * dstep], e0 + o0); \
189 assign(dst[1 * dstep], e1 + o1); \
190 assign(dst[2 * dstep], e1 - o1); \
191 assign(dst[3 * dstep], e0 - o0); \
194 #define TR_8(dst, src, dstep, sstep, assign, end) \
198 int o_8[4] = { 0 }; \
199 for (i = 0; i < 4; i++) \
200 for (j = 1; j < end; j += 2) \
201 o_8[i] += transform[4 * j][i] * src[j * sstep]; \
202 TR_4(e_8, src, 1, 2 * sstep, SET, 4); \
204 for (i = 0; i < 4; i++) { \
205 assign(dst[i * dstep], e_8[i] + o_8[i]); \
206 assign(dst[(7 - i) * dstep], e_8[i] - o_8[i]); \
210 #define TR_16(dst, src, dstep, sstep, assign, end) \
214 int o_16[8] = { 0 }; \
215 for (i = 0; i < 8; i++) \
216 for (j = 1; j < end; j += 2) \
217 o_16[i] += transform[2 * j][i] * src[j * sstep]; \
218 TR_8(e_16, src, 1, 2 * sstep, SET, 8); \
220 for (i = 0; i < 8; i++) { \
221 assign(dst[i * dstep], e_16[i] + o_16[i]); \
222 assign(dst[(15 - i) * dstep], e_16[i] - o_16[i]); \
226 #define TR_32(dst, src, dstep, sstep, assign, end) \
230 int o_32[16] = { 0 }; \
231 for (i = 0; i < 16; i++) \
232 for (j = 1; j < end; j += 2) \
233 o_32[i] += transform[j][i] * src[j * sstep]; \
234 TR_16(e_32, src, 1, 2 * sstep, SET, end/2); \
236 for (i = 0; i < 16; i++) { \
237 assign(dst[i * dstep], e_32[i] + o_32[i]); \
238 assign(dst[(31 - i) * dstep], e_32[i] - o_32[i]); \
242 #define IDCT_VAR4(H) \
243 int limit2 = FFMIN(col_limit + 4, H)
244 #define IDCT_VAR8(H) \
245 int limit = FFMIN(col_limit, H); \
246 int limit2 = FFMIN(col_limit + 4, H)
247 #define IDCT_VAR16(H) IDCT_VAR8(H)
248 #define IDCT_VAR32(H) IDCT_VAR8(H)
251 static void FUNC(idct_##H ##x ##H )( \
252 int16_t *coeffs, int col_limit) { \
255 int add = 1 << (shift - 1); \
256 int16_t *src = coeffs; \
259 for (i = 0; i < H; i++) { \
260 TR_ ## H(src, src, H, H, SCALE, limit2); \
261 if (limit2 < H && i%4 == 0 && !!i) \
266 shift = 20 - BIT_DEPTH; \
267 add = 1 << (shift - 1); \
268 for (i = 0; i < H; i++) { \
269 TR_ ## H(coeffs, coeffs, 1, 1, SCALE, limit); \
275 static void FUNC(idct_##H ##x ##H ##_dc)( \
278 int shift = 14 - BIT_DEPTH; \
279 int add = 1 << (shift - 1); \
280 int coeff = (((coeffs[0] + 1) >> 1) + add) >> shift; \
282 for (j = 0; j < H; j++) { \
283 for (i = 0; i < H; i++) { \
284 coeffs[i+j*H] = coeff; \
308 static void FUNC(sao_band_filter_0)(uint8_t *_dst, uint8_t *_src,
309 ptrdiff_t stride, SAOParams *sao,
310 int *borders, int width, int height,
313 pixel *dst = (pixel *)_dst;
314 pixel *src = (pixel *)_src;
315 int offset_table[32] = { 0 };
317 int shift = BIT_DEPTH - 5;
318 int *sao_offset_val = sao->offset_val[c_idx];
319 int sao_left_class = sao->band_position[c_idx];
321 stride /= sizeof(pixel);
323 for (k = 0; k < 4; k++)
324 offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
325 for (y = 0; y < height; y++) {
326 for (x = 0; x < width; x++)
327 dst[x] = av_clip_pixel(src[x] + offset_table[av_clip_pixel(src[x] >> shift)]);
333 #define CMP(a, b) ((a) > (b) ? 1 : ((a) == (b) ? 0 : -1))
335 static void FUNC(sao_edge_filter)(uint8_t *_dst, uint8_t *_src,
336 ptrdiff_t stride, SAOParams *sao,
337 int width, int height,
338 int c_idx, int init_x, int init_y) {
340 static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
341 static const int8_t pos[4][2][2] = {
342 { { -1, 0 }, { 1, 0 } }, // horizontal
343 { { 0, -1 }, { 0, 1 } }, // vertical
344 { { -1, -1 }, { 1, 1 } }, // 45 degree
345 { { 1, -1 }, { -1, 1 } }, // 135 degree
347 int *sao_offset_val = sao->offset_val[c_idx];
348 int sao_eo_class = sao->eo_class[c_idx];
349 pixel *dst = (pixel *)_dst;
350 pixel *src = (pixel *)_src;
352 int y_stride = init_y * stride;
353 int pos_0_0 = pos[sao_eo_class][0][0];
354 int pos_0_1 = pos[sao_eo_class][0][1];
355 int pos_1_0 = pos[sao_eo_class][1][0];
356 int pos_1_1 = pos[sao_eo_class][1][1];
359 int y_stride_0_1 = (init_y + pos_0_1) * stride;
360 int y_stride_1_1 = (init_y + pos_1_1) * stride;
361 for (y = init_y; y < height; y++) {
362 for (x = init_x; x < width; x++) {
363 int diff0 = CMP(src[x + y_stride], src[x + pos_0_0 + y_stride_0_1]);
364 int diff1 = CMP(src[x + y_stride], src[x + pos_1_0 + y_stride_1_1]);
365 int offset_val = edge_idx[2 + diff0 + diff1];
366 dst[x + y_stride] = av_clip_pixel(src[x + y_stride] + sao_offset_val[offset_val]);
369 y_stride_0_1 += stride;
370 y_stride_1_1 += stride;
374 static void FUNC(sao_edge_filter_0)(uint8_t *_dst, uint8_t *_src,
375 ptrdiff_t stride, SAOParams *sao,
376 int *borders, int _width, int _height,
377 int c_idx, uint8_t *vert_edge,
378 uint8_t *horiz_edge, uint8_t *diag_edge)
381 pixel *dst = (pixel *)_dst;
382 pixel *src = (pixel *)_src;
383 int *sao_offset_val = sao->offset_val[c_idx];
384 int sao_eo_class = sao->eo_class[c_idx];
385 int init_x = 0, init_y = 0, width = _width, height = _height;
387 stride /= sizeof(pixel);
389 if (sao_eo_class != SAO_EO_VERT) {
391 int offset_val = sao_offset_val[0];
393 for (y = 0; y < height; y++) {
394 dst[y_stride] = av_clip_pixel(src[y_stride] + offset_val);
400 int offset_val = sao_offset_val[0];
401 int x_stride = width - 1;
402 for (x = 0; x < height; x++) {
403 dst[x_stride] = av_clip_pixel(src[x_stride] + offset_val);
409 if (sao_eo_class != SAO_EO_HORIZ) {
411 int offset_val = sao_offset_val[0];
412 for (x = init_x; x < width; x++)
413 dst[x] = av_clip_pixel(src[x] + offset_val);
417 int offset_val = sao_offset_val[0];
418 int y_stride = stride * (height - 1);
419 for (x = init_x; x < width; x++)
420 dst[x + y_stride] = av_clip_pixel(src[x + y_stride] + offset_val);
425 FUNC(sao_edge_filter)((uint8_t *)dst, (uint8_t *)src, stride, sao, width, height, c_idx, init_x, init_y);
428 static void FUNC(sao_edge_filter_1)(uint8_t *_dst, uint8_t *_src,
429 ptrdiff_t stride, SAOParams *sao,
430 int *borders, int _width, int _height,
431 int c_idx, uint8_t *vert_edge,
432 uint8_t *horiz_edge, uint8_t *diag_edge)
435 pixel *dst = (pixel *)_dst;
436 pixel *src = (pixel *)_src;
437 int *sao_offset_val = sao->offset_val[c_idx];
438 int sao_eo_class = sao->eo_class[c_idx];
439 int init_x = 0, init_y = 0, width = _width, height = _height;
441 stride /= sizeof(pixel);
443 if (sao_eo_class != SAO_EO_VERT) {
445 int offset_val = sao_offset_val[0];
447 for (y = 0; y < height; y++) {
448 dst[y_stride] = av_clip_pixel(src[y_stride] + offset_val);
454 int offset_val = sao_offset_val[0];
455 int x_stride = width - 1;
456 for (x = 0; x < height; x++) {
457 dst[x_stride] = av_clip_pixel(src[x_stride] + offset_val);
463 if (sao_eo_class != SAO_EO_HORIZ) {
465 int offset_val = sao_offset_val[0];
466 for (x = init_x; x < width; x++)
467 dst[x] = av_clip_pixel(src[x] + offset_val);
471 int offset_val = sao_offset_val[0];
472 int y_stride = stride * (height - 1);
473 for (x = init_x; x < width; x++)
474 dst[x + y_stride] = av_clip_pixel(src[x + y_stride] + offset_val);
479 FUNC(sao_edge_filter)((uint8_t *)dst, (uint8_t *)src, stride, sao, width, height, c_idx, init_x, init_y);
482 int save_upper_left = !diag_edge[0] && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
483 int save_upper_right = !diag_edge[1] && sao_eo_class == SAO_EO_45D && !borders[1] && !borders[2];
484 int save_lower_right = !diag_edge[2] && sao_eo_class == SAO_EO_135D && !borders[2] && !borders[3];
485 int save_lower_left = !diag_edge[3] && sao_eo_class == SAO_EO_45D && !borders[0] && !borders[3];
487 // Restore pixels that can't be modified
488 if(vert_edge[0] && sao_eo_class != SAO_EO_VERT) {
489 for(y = init_y+save_upper_left; y< height-save_lower_left; y++)
490 dst[y*stride] = src[y*stride];
492 if(vert_edge[1] && sao_eo_class != SAO_EO_VERT) {
493 for(y = init_y+save_upper_right; y< height-save_lower_right; y++)
494 dst[y*stride+width-1] = src[y*stride+width-1];
497 if(horiz_edge[0] && sao_eo_class != SAO_EO_HORIZ) {
498 for(x = init_x+save_upper_left; x < width-save_upper_right; x++)
501 if(horiz_edge[1] && sao_eo_class != SAO_EO_HORIZ) {
502 for(x = init_x+save_lower_left; x < width-save_lower_right; x++)
503 dst[(height-1)*stride+x] = src[(height-1)*stride+x];
505 if(diag_edge[0] && sao_eo_class == SAO_EO_135D)
507 if(diag_edge[1] && sao_eo_class == SAO_EO_45D)
508 dst[width-1] = src[width-1];
509 if(diag_edge[2] && sao_eo_class == SAO_EO_135D)
510 dst[stride*(height-1)+width-1] = src[stride*(height-1)+width-1];
511 if(diag_edge[3] && sao_eo_class == SAO_EO_45D)
512 dst[stride*(height-1)] = src[stride*(height-1)];
519 ////////////////////////////////////////////////////////////////////////////////
521 ////////////////////////////////////////////////////////////////////////////////
522 static void FUNC(put_hevc_pel_pixels)(int16_t *dst, ptrdiff_t dststride,
523 uint8_t *_src, ptrdiff_t _srcstride,
524 int height, intptr_t mx, intptr_t my, int width)
527 pixel *src = (pixel *)_src;
528 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
530 for (y = 0; y < height; y++) {
531 for (x = 0; x < width; x++)
532 dst[x] = src[x] << (14 - BIT_DEPTH);
538 static void FUNC(put_hevc_pel_uni_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
539 int height, intptr_t mx, intptr_t my, int width)
542 pixel *src = (pixel *)_src;
543 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
544 pixel *dst = (pixel *)_dst;
545 ptrdiff_t dststride = _dststride / sizeof(pixel);
547 for (y = 0; y < height; y++) {
548 memcpy(dst, src, width * sizeof(pixel));
554 static void FUNC(put_hevc_pel_bi_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
555 int16_t *src2, ptrdiff_t src2stride,
556 int height, intptr_t mx, intptr_t my, int width)
559 pixel *src = (pixel *)_src;
560 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
561 pixel *dst = (pixel *)_dst;
562 ptrdiff_t dststride = _dststride / sizeof(pixel);
564 int shift = 14 + 1 - BIT_DEPTH;
566 int offset = 1 << (shift - 1);
571 for (y = 0; y < height; y++) {
572 for (x = 0; x < width; x++)
573 dst[x] = av_clip_pixel(((src[x] << (14 - BIT_DEPTH)) + src2[x] + offset) >> shift);
580 static void FUNC(put_hevc_pel_uni_w_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
581 int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
584 pixel *src = (pixel *)_src;
585 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
586 pixel *dst = (pixel *)_dst;
587 ptrdiff_t dststride = _dststride / sizeof(pixel);
588 int shift = denom + 14 - BIT_DEPTH;
590 int offset = 1 << (shift - 1);
595 ox = ox * (1 << (BIT_DEPTH - 8));
596 for (y = 0; y < height; y++) {
597 for (x = 0; x < width; x++)
598 dst[x] = av_clip_pixel((((src[x] << (14 - BIT_DEPTH)) * wx + offset) >> shift) + ox);
604 static void FUNC(put_hevc_pel_bi_w_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
605 int16_t *src2, ptrdiff_t src2stride,
606 int height, int denom, int wx0, int wx1,
607 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
610 pixel *src = (pixel *)_src;
611 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
612 pixel *dst = (pixel *)_dst;
613 ptrdiff_t dststride = _dststride / sizeof(pixel);
615 int shift = 14 + 1 - BIT_DEPTH;
616 int log2Wd = denom + shift - 1;
618 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
619 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
620 for (y = 0; y < height; y++) {
621 for (x = 0; x < width; x++) {
622 dst[x] = av_clip_pixel(( (src[x] << (14 - BIT_DEPTH)) * wx1 + src2[x] * wx0 + ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
630 ////////////////////////////////////////////////////////////////////////////////
632 ////////////////////////////////////////////////////////////////////////////////
633 #define QPEL_FILTER(src, stride) \
634 (filter[0] * src[x - 3 * stride] + \
635 filter[1] * src[x - 2 * stride] + \
636 filter[2] * src[x - stride] + \
637 filter[3] * src[x ] + \
638 filter[4] * src[x + stride] + \
639 filter[5] * src[x + 2 * stride] + \
640 filter[6] * src[x + 3 * stride] + \
641 filter[7] * src[x + 4 * stride])
643 static void FUNC(put_hevc_qpel_h)(int16_t *dst, ptrdiff_t dststride,
644 uint8_t *_src, ptrdiff_t _srcstride,
645 int height, intptr_t mx, intptr_t my, int width)
648 pixel *src = (pixel*)_src;
649 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
650 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
651 for (y = 0; y < height; y++) {
652 for (x = 0; x < width; x++)
653 dst[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
659 static void FUNC(put_hevc_qpel_v)(int16_t *dst, ptrdiff_t dststride,
660 uint8_t *_src, ptrdiff_t _srcstride,
661 int height, intptr_t mx, intptr_t my, int width)
664 pixel *src = (pixel*)_src;
665 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
666 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
667 for (y = 0; y < height; y++) {
668 for (x = 0; x < width; x++)
669 dst[x] = QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8);
675 static void FUNC(put_hevc_qpel_hv)(int16_t *dst,
678 ptrdiff_t _srcstride,
679 int height, intptr_t mx,
680 intptr_t my, int width)
683 const int8_t *filter;
684 pixel *src = (pixel*)_src;
685 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
686 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
687 int16_t *tmp = tmp_array;
689 src -= QPEL_EXTRA_BEFORE * srcstride;
690 filter = ff_hevc_qpel_filters[mx - 1];
691 for (y = 0; y < height + QPEL_EXTRA; y++) {
692 for (x = 0; x < width; x++)
693 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
698 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
699 filter = ff_hevc_qpel_filters[my - 1];
700 for (y = 0; y < height; y++) {
701 for (x = 0; x < width; x++)
702 dst[x] = QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6;
708 static void FUNC(put_hevc_qpel_uni_h)(uint8_t *_dst, ptrdiff_t _dststride,
709 uint8_t *_src, ptrdiff_t _srcstride,
710 int height, intptr_t mx, intptr_t my, int width)
713 pixel *src = (pixel*)_src;
714 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
715 pixel *dst = (pixel *)_dst;
716 ptrdiff_t dststride = _dststride / sizeof(pixel);
717 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
718 int shift = 14 - BIT_DEPTH;
721 int offset = 1 << (shift - 1);
726 for (y = 0; y < height; y++) {
727 for (x = 0; x < width; x++)
728 dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + offset) >> shift);
734 static void FUNC(put_hevc_qpel_bi_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
735 int16_t *src2, ptrdiff_t src2stride,
736 int height, intptr_t mx, intptr_t my, int width)
739 pixel *src = (pixel*)_src;
740 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
741 pixel *dst = (pixel *)_dst;
742 ptrdiff_t dststride = _dststride / sizeof(pixel);
744 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
746 int shift = 14 + 1 - BIT_DEPTH;
748 int offset = 1 << (shift - 1);
753 for (y = 0; y < height; y++) {
754 for (x = 0; x < width; x++)
755 dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
762 static void FUNC(put_hevc_qpel_uni_v)(uint8_t *_dst, ptrdiff_t _dststride,
763 uint8_t *_src, ptrdiff_t _srcstride,
764 int height, intptr_t mx, intptr_t my, int width)
767 pixel *src = (pixel*)_src;
768 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
769 pixel *dst = (pixel *)_dst;
770 ptrdiff_t dststride = _dststride / sizeof(pixel);
771 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
772 int shift = 14 - BIT_DEPTH;
775 int offset = 1 << (shift - 1);
780 for (y = 0; y < height; y++) {
781 for (x = 0; x < width; x++)
782 dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + offset) >> shift);
789 static void FUNC(put_hevc_qpel_bi_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
790 int16_t *src2, ptrdiff_t src2stride,
791 int height, intptr_t mx, intptr_t my, int width)
794 pixel *src = (pixel*)_src;
795 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
796 pixel *dst = (pixel *)_dst;
797 ptrdiff_t dststride = _dststride / sizeof(pixel);
799 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
801 int shift = 14 + 1 - BIT_DEPTH;
803 int offset = 1 << (shift - 1);
808 for (y = 0; y < height; y++) {
809 for (x = 0; x < width; x++)
810 dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
817 static void FUNC(put_hevc_qpel_uni_hv)(uint8_t *_dst, ptrdiff_t _dststride,
818 uint8_t *_src, ptrdiff_t _srcstride,
819 int height, intptr_t mx, intptr_t my, int width)
822 const int8_t *filter;
823 pixel *src = (pixel*)_src;
824 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
825 pixel *dst = (pixel *)_dst;
826 ptrdiff_t dststride = _dststride / sizeof(pixel);
827 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
828 int16_t *tmp = tmp_array;
829 int shift = 14 - BIT_DEPTH;
832 int offset = 1 << (shift - 1);
837 src -= QPEL_EXTRA_BEFORE * srcstride;
838 filter = ff_hevc_qpel_filters[mx - 1];
839 for (y = 0; y < height + QPEL_EXTRA; y++) {
840 for (x = 0; x < width; x++)
841 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
846 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
847 filter = ff_hevc_qpel_filters[my - 1];
849 for (y = 0; y < height; y++) {
850 for (x = 0; x < width; x++)
851 dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + offset) >> shift);
857 static void FUNC(put_hevc_qpel_bi_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
858 int16_t *src2, ptrdiff_t src2stride,
859 int height, intptr_t mx, intptr_t my, int width)
862 const int8_t *filter;
863 pixel *src = (pixel*)_src;
864 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
865 pixel *dst = (pixel *)_dst;
866 ptrdiff_t dststride = _dststride / sizeof(pixel);
867 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
868 int16_t *tmp = tmp_array;
869 int shift = 14 + 1 - BIT_DEPTH;
871 int offset = 1 << (shift - 1);
876 src -= QPEL_EXTRA_BEFORE * srcstride;
877 filter = ff_hevc_qpel_filters[mx - 1];
878 for (y = 0; y < height + QPEL_EXTRA; y++) {
879 for (x = 0; x < width; x++)
880 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
885 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
886 filter = ff_hevc_qpel_filters[my - 1];
888 for (y = 0; y < height; y++) {
889 for (x = 0; x < width; x++)
890 dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + src2[x] + offset) >> shift);
897 static void FUNC(put_hevc_qpel_uni_w_h)(uint8_t *_dst, ptrdiff_t _dststride,
898 uint8_t *_src, ptrdiff_t _srcstride,
899 int height, int denom, int wx, int ox,
900 intptr_t mx, intptr_t my, int width)
903 pixel *src = (pixel*)_src;
904 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
905 pixel *dst = (pixel *)_dst;
906 ptrdiff_t dststride = _dststride / sizeof(pixel);
907 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
908 int shift = denom + 14 - BIT_DEPTH;
910 int offset = 1 << (shift - 1);
915 ox = ox * (1 << (BIT_DEPTH - 8));
916 for (y = 0; y < height; y++) {
917 for (x = 0; x < width; x++)
918 dst[x] = av_clip_pixel((((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
924 static void FUNC(put_hevc_qpel_bi_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
925 int16_t *src2, ptrdiff_t src2stride,
926 int height, int denom, int wx0, int wx1,
927 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
930 pixel *src = (pixel*)_src;
931 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
932 pixel *dst = (pixel *)_dst;
933 ptrdiff_t dststride = _dststride / sizeof(pixel);
935 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
937 int shift = 14 + 1 - BIT_DEPTH;
938 int log2Wd = denom + shift - 1;
940 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
941 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
942 for (y = 0; y < height; y++) {
943 for (x = 0; x < width; x++)
944 dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
945 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
952 static void FUNC(put_hevc_qpel_uni_w_v)(uint8_t *_dst, ptrdiff_t _dststride,
953 uint8_t *_src, ptrdiff_t _srcstride,
954 int height, int denom, int wx, int ox,
955 intptr_t mx, intptr_t my, int width)
958 pixel *src = (pixel*)_src;
959 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
960 pixel *dst = (pixel *)_dst;
961 ptrdiff_t dststride = _dststride / sizeof(pixel);
962 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
963 int shift = denom + 14 - BIT_DEPTH;
965 int offset = 1 << (shift - 1);
970 ox = ox * (1 << (BIT_DEPTH - 8));
971 for (y = 0; y < height; y++) {
972 for (x = 0; x < width; x++)
973 dst[x] = av_clip_pixel((((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
979 static void FUNC(put_hevc_qpel_bi_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
980 int16_t *src2, ptrdiff_t src2stride,
981 int height, int denom, int wx0, int wx1,
982 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
985 pixel *src = (pixel*)_src;
986 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
987 pixel *dst = (pixel *)_dst;
988 ptrdiff_t dststride = _dststride / sizeof(pixel);
990 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
992 int shift = 14 + 1 - BIT_DEPTH;
993 int log2Wd = denom + shift - 1;
995 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
996 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
997 for (y = 0; y < height; y++) {
998 for (x = 0; x < width; x++)
999 dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
1000 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1007 static void FUNC(put_hevc_qpel_uni_w_hv)(uint8_t *_dst, ptrdiff_t _dststride,
1008 uint8_t *_src, ptrdiff_t _srcstride,
1009 int height, int denom, int wx, int ox,
1010 intptr_t mx, intptr_t my, int width)
1013 const int8_t *filter;
1014 pixel *src = (pixel*)_src;
1015 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1016 pixel *dst = (pixel *)_dst;
1017 ptrdiff_t dststride = _dststride / sizeof(pixel);
1018 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
1019 int16_t *tmp = tmp_array;
1020 int shift = denom + 14 - BIT_DEPTH;
1022 int offset = 1 << (shift - 1);
1027 src -= QPEL_EXTRA_BEFORE * srcstride;
1028 filter = ff_hevc_qpel_filters[mx - 1];
1029 for (y = 0; y < height + QPEL_EXTRA; y++) {
1030 for (x = 0; x < width; x++)
1031 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1036 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1037 filter = ff_hevc_qpel_filters[my - 1];
1039 ox = ox * (1 << (BIT_DEPTH - 8));
1040 for (y = 0; y < height; y++) {
1041 for (x = 0; x < width; x++)
1042 dst[x] = av_clip_pixel((((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
1048 static void FUNC(put_hevc_qpel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1049 int16_t *src2, ptrdiff_t src2stride,
1050 int height, int denom, int wx0, int wx1,
1051 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1054 const int8_t *filter;
1055 pixel *src = (pixel*)_src;
1056 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1057 pixel *dst = (pixel *)_dst;
1058 ptrdiff_t dststride = _dststride / sizeof(pixel);
1059 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
1060 int16_t *tmp = tmp_array;
1061 int shift = 14 + 1 - BIT_DEPTH;
1062 int log2Wd = denom + shift - 1;
1064 src -= QPEL_EXTRA_BEFORE * srcstride;
1065 filter = ff_hevc_qpel_filters[mx - 1];
1066 for (y = 0; y < height + QPEL_EXTRA; y++) {
1067 for (x = 0; x < width; x++)
1068 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1073 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1074 filter = ff_hevc_qpel_filters[my - 1];
1076 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1077 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1078 for (y = 0; y < height; y++) {
1079 for (x = 0; x < width; x++)
1080 dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 +
1081 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1088 ////////////////////////////////////////////////////////////////////////////////
1090 ////////////////////////////////////////////////////////////////////////////////
1091 #define EPEL_FILTER(src, stride) \
1092 (filter[0] * src[x - stride] + \
1093 filter[1] * src[x] + \
1094 filter[2] * src[x + stride] + \
1095 filter[3] * src[x + 2 * stride])
1097 static void FUNC(put_hevc_epel_h)(int16_t *dst, ptrdiff_t dststride,
1098 uint8_t *_src, ptrdiff_t _srcstride,
1099 int height, intptr_t mx, intptr_t my, int width)
1102 pixel *src = (pixel *)_src;
1103 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1104 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1105 for (y = 0; y < height; y++) {
1106 for (x = 0; x < width; x++)
1107 dst[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1113 static void FUNC(put_hevc_epel_v)(int16_t *dst, ptrdiff_t dststride,
1114 uint8_t *_src, ptrdiff_t _srcstride,
1115 int height, intptr_t mx, intptr_t my, int width)
1118 pixel *src = (pixel *)_src;
1119 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1120 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1122 for (y = 0; y < height; y++) {
1123 for (x = 0; x < width; x++)
1124 dst[x] = EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8);
1130 static void FUNC(put_hevc_epel_hv)(int16_t *dst, ptrdiff_t dststride,
1131 uint8_t *_src, ptrdiff_t _srcstride,
1132 int height, intptr_t mx, intptr_t my, int width)
1135 pixel *src = (pixel *)_src;
1136 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1137 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1138 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1139 int16_t *tmp = tmp_array;
1141 src -= EPEL_EXTRA_BEFORE * srcstride;
1143 for (y = 0; y < height + EPEL_EXTRA; y++) {
1144 for (x = 0; x < width; x++)
1145 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1150 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1151 filter = ff_hevc_epel_filters[my - 1];
1153 for (y = 0; y < height; y++) {
1154 for (x = 0; x < width; x++)
1155 dst[x] = EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6;
1161 static void FUNC(put_hevc_epel_uni_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1162 int height, intptr_t mx, intptr_t my, int width)
1165 pixel *src = (pixel *)_src;
1166 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1167 pixel *dst = (pixel *)_dst;
1168 ptrdiff_t dststride = _dststride / sizeof(pixel);
1169 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1170 int shift = 14 - BIT_DEPTH;
1172 int offset = 1 << (shift - 1);
1177 for (y = 0; y < height; y++) {
1178 for (x = 0; x < width; x++)
1179 dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + offset) >> shift);
1185 static void FUNC(put_hevc_epel_bi_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1186 int16_t *src2, ptrdiff_t src2stride,
1187 int height, intptr_t mx, intptr_t my, int width)
1190 pixel *src = (pixel *)_src;
1191 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1192 pixel *dst = (pixel *)_dst;
1193 ptrdiff_t dststride = _dststride / sizeof(pixel);
1194 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1195 int shift = 14 + 1 - BIT_DEPTH;
1197 int offset = 1 << (shift - 1);
1202 for (y = 0; y < height; y++) {
1203 for (x = 0; x < width; x++) {
1204 dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
1212 static void FUNC(put_hevc_epel_uni_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1213 int height, intptr_t mx, intptr_t my, int width)
1216 pixel *src = (pixel *)_src;
1217 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1218 pixel *dst = (pixel *)_dst;
1219 ptrdiff_t dststride = _dststride / sizeof(pixel);
1220 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1221 int shift = 14 - BIT_DEPTH;
1223 int offset = 1 << (shift - 1);
1228 for (y = 0; y < height; y++) {
1229 for (x = 0; x < width; x++)
1230 dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + offset) >> shift);
1236 static void FUNC(put_hevc_epel_bi_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1237 int16_t *src2, ptrdiff_t src2stride,
1238 int height, intptr_t mx, intptr_t my, int width)
1241 pixel *src = (pixel *)_src;
1242 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1243 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1244 pixel *dst = (pixel *)_dst;
1245 ptrdiff_t dststride = _dststride / sizeof(pixel);
1246 int shift = 14 + 1 - BIT_DEPTH;
1248 int offset = 1 << (shift - 1);
1253 for (y = 0; y < height; y++) {
1254 for (x = 0; x < width; x++)
1255 dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
1262 static void FUNC(put_hevc_epel_uni_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1263 int height, intptr_t mx, intptr_t my, int width)
1266 pixel *src = (pixel *)_src;
1267 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1268 pixel *dst = (pixel *)_dst;
1269 ptrdiff_t dststride = _dststride / sizeof(pixel);
1270 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1271 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1272 int16_t *tmp = tmp_array;
1273 int shift = 14 - BIT_DEPTH;
1275 int offset = 1 << (shift - 1);
1280 src -= EPEL_EXTRA_BEFORE * srcstride;
1282 for (y = 0; y < height + EPEL_EXTRA; y++) {
1283 for (x = 0; x < width; x++)
1284 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1289 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1290 filter = ff_hevc_epel_filters[my - 1];
1292 for (y = 0; y < height; y++) {
1293 for (x = 0; x < width; x++)
1294 dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + offset) >> shift);
1300 static void FUNC(put_hevc_epel_bi_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1301 int16_t *src2, ptrdiff_t src2stride,
1302 int height, intptr_t mx, intptr_t my, int width)
1305 pixel *src = (pixel *)_src;
1306 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1307 pixel *dst = (pixel *)_dst;
1308 ptrdiff_t dststride = _dststride / sizeof(pixel);
1309 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1310 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1311 int16_t *tmp = tmp_array;
1312 int shift = 14 + 1 - BIT_DEPTH;
1314 int offset = 1 << (shift - 1);
1319 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);
1328 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1329 filter = ff_hevc_epel_filters[my - 1];
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) + src2[x] + offset) >> shift);
1340 static void FUNC(put_hevc_epel_uni_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1341 int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
1344 pixel *src = (pixel *)_src;
1345 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1346 pixel *dst = (pixel *)_dst;
1347 ptrdiff_t dststride = _dststride / sizeof(pixel);
1348 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1349 int shift = denom + 14 - BIT_DEPTH;
1351 int offset = 1 << (shift - 1);
1356 ox = ox * (1 << (BIT_DEPTH - 8));
1357 for (y = 0; y < height; y++) {
1358 for (x = 0; x < width; x++) {
1359 dst[x] = av_clip_pixel((((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
1366 static void FUNC(put_hevc_epel_bi_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1367 int16_t *src2, ptrdiff_t src2stride,
1368 int height, int denom, int wx0, int wx1,
1369 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1372 pixel *src = (pixel *)_src;
1373 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1374 pixel *dst = (pixel *)_dst;
1375 ptrdiff_t dststride = _dststride / sizeof(pixel);
1376 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1377 int shift = 14 + 1 - BIT_DEPTH;
1378 int log2Wd = denom + shift - 1;
1380 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1381 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1382 for (y = 0; y < height; y++) {
1383 for (x = 0; x < width; x++)
1384 dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
1385 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1392 static void FUNC(put_hevc_epel_uni_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1393 int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
1396 pixel *src = (pixel *)_src;
1397 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1398 pixel *dst = (pixel *)_dst;
1399 ptrdiff_t dststride = _dststride / sizeof(pixel);
1400 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1401 int shift = denom + 14 - BIT_DEPTH;
1403 int offset = 1 << (shift - 1);
1408 ox = ox * (1 << (BIT_DEPTH - 8));
1409 for (y = 0; y < height; y++) {
1410 for (x = 0; x < width; x++) {
1411 dst[x] = av_clip_pixel((((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
1418 static void FUNC(put_hevc_epel_bi_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1419 int16_t *src2, ptrdiff_t src2stride,
1420 int height, int denom, int wx0, int wx1,
1421 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1424 pixel *src = (pixel *)_src;
1425 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1426 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1427 pixel *dst = (pixel *)_dst;
1428 ptrdiff_t dststride = _dststride / sizeof(pixel);
1429 int shift = 14 + 1 - BIT_DEPTH;
1430 int log2Wd = denom + shift - 1;
1432 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1433 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1434 for (y = 0; y < height; y++) {
1435 for (x = 0; x < width; x++)
1436 dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
1437 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1444 static void FUNC(put_hevc_epel_uni_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1445 int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
1448 pixel *src = (pixel *)_src;
1449 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1450 pixel *dst = (pixel *)_dst;
1451 ptrdiff_t dststride = _dststride / sizeof(pixel);
1452 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1453 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1454 int16_t *tmp = tmp_array;
1455 int shift = denom + 14 - BIT_DEPTH;
1457 int offset = 1 << (shift - 1);
1462 src -= EPEL_EXTRA_BEFORE * srcstride;
1464 for (y = 0; y < height + EPEL_EXTRA; y++) {
1465 for (x = 0; x < width; x++)
1466 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1471 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1472 filter = ff_hevc_epel_filters[my - 1];
1474 ox = ox * (1 << (BIT_DEPTH - 8));
1475 for (y = 0; y < height; y++) {
1476 for (x = 0; x < width; x++)
1477 dst[x] = av_clip_pixel((((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
1483 static void FUNC(put_hevc_epel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1484 int16_t *src2, ptrdiff_t src2stride,
1485 int height, int denom, int wx0, int wx1,
1486 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1489 pixel *src = (pixel *)_src;
1490 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1491 pixel *dst = (pixel *)_dst;
1492 ptrdiff_t dststride = _dststride / sizeof(pixel);
1493 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1494 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1495 int16_t *tmp = tmp_array;
1496 int shift = 14 + 1 - BIT_DEPTH;
1497 int log2Wd = denom + shift - 1;
1499 src -= EPEL_EXTRA_BEFORE * srcstride;
1501 for (y = 0; y < height + EPEL_EXTRA; y++) {
1502 for (x = 0; x < width; x++)
1503 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1508 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1509 filter = ff_hevc_epel_filters[my - 1];
1511 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1512 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1513 for (y = 0; y < height; y++) {
1514 for (x = 0; x < width; x++)
1515 dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 +
1516 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1522 #define P3 pix[-4 * xstride]
1523 #define P2 pix[-3 * xstride]
1524 #define P1 pix[-2 * xstride]
1525 #define P0 pix[-1 * xstride]
1526 #define Q0 pix[0 * xstride]
1527 #define Q1 pix[1 * xstride]
1528 #define Q2 pix[2 * xstride]
1529 #define Q3 pix[3 * xstride]
1531 // line three. used only for deblocking decision
1532 #define TP3 pix[-4 * xstride + 3 * ystride]
1533 #define TP2 pix[-3 * xstride + 3 * ystride]
1534 #define TP1 pix[-2 * xstride + 3 * ystride]
1535 #define TP0 pix[-1 * xstride + 3 * ystride]
1536 #define TQ0 pix[0 * xstride + 3 * ystride]
1537 #define TQ1 pix[1 * xstride + 3 * ystride]
1538 #define TQ2 pix[2 * xstride + 3 * ystride]
1539 #define TQ3 pix[3 * xstride + 3 * ystride]
1541 static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix,
1542 ptrdiff_t _xstride, ptrdiff_t _ystride,
1543 int *_beta, int *_tc,
1544 uint8_t *_no_p, uint8_t *_no_q)
1547 pixel *pix = (pixel *)_pix;
1548 ptrdiff_t xstride = _xstride / sizeof(pixel);
1549 ptrdiff_t ystride = _ystride / sizeof(pixel);
1551 for (j = 0; j < 2; j++) {
1552 const int dp0 = abs(P2 - 2 * P1 + P0);
1553 const int dq0 = abs(Q2 - 2 * Q1 + Q0);
1554 const int dp3 = abs(TP2 - 2 * TP1 + TP0);
1555 const int dq3 = abs(TQ2 - 2 * TQ1 + TQ0);
1556 const int d0 = dp0 + dq0;
1557 const int d3 = dp3 + dq3;
1558 const int beta = _beta[j] << (BIT_DEPTH - 8);
1559 const int tc = _tc[j] << (BIT_DEPTH - 8);
1560 const int no_p = _no_p[j];
1561 const int no_q = _no_q[j];
1563 if (d0 + d3 >= beta) {
1567 const int beta_3 = beta >> 3;
1568 const int beta_2 = beta >> 2;
1569 const int tc25 = ((tc * 5 + 1) >> 1);
1571 if (abs(P3 - P0) + abs(Q3 - Q0) < beta_3 && abs(P0 - Q0) < tc25 &&
1572 abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 &&
1573 (d0 << 1) < beta_2 && (d3 << 1) < beta_2) {
1575 const int tc2 = tc << 1;
1576 for (d = 0; d < 4; d++) {
1586 P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc2, tc2);
1587 P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2);
1588 P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc2, tc2);
1591 Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc2, tc2);
1592 Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2);
1593 Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc2, tc2);
1597 } else { // normal filtering
1600 const int tc_2 = tc >> 1;
1601 if (dp0 + dp3 < ((beta + (beta >> 1)) >> 3))
1603 if (dq0 + dq3 < ((beta + (beta >> 1)) >> 3))
1606 for (d = 0; d < 4; d++) {
1613 int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4;
1614 if (abs(delta0) < 10 * tc) {
1615 delta0 = av_clip(delta0, -tc, tc);
1617 P0 = av_clip_pixel(p0 + delta0);
1619 Q0 = av_clip_pixel(q0 - delta0);
1620 if (!no_p && nd_p > 1) {
1621 const int deltap1 = av_clip((((p2 + p0 + 1) >> 1) - p1 + delta0) >> 1, -tc_2, tc_2);
1622 P1 = av_clip_pixel(p1 + deltap1);
1624 if (!no_q && nd_q > 1) {
1625 const int deltaq1 = av_clip((((q2 + q0 + 1) >> 1) - q1 - delta0) >> 1, -tc_2, tc_2);
1626 Q1 = av_clip_pixel(q1 + deltaq1);
1636 static void FUNC(hevc_loop_filter_chroma)(uint8_t *_pix, ptrdiff_t _xstride,
1637 ptrdiff_t _ystride, int *_tc,
1638 uint8_t *_no_p, uint8_t *_no_q)
1640 int d, j, no_p, no_q;
1641 pixel *pix = (pixel *)_pix;
1642 ptrdiff_t xstride = _xstride / sizeof(pixel);
1643 ptrdiff_t ystride = _ystride / sizeof(pixel);
1645 for (j = 0; j < 2; j++) {
1646 const int tc = _tc[j] << (BIT_DEPTH - 8);
1654 for (d = 0; d < 4; d++) {
1660 delta0 = av_clip((((q0 - p0) * 4) + p1 - q1 + 4) >> 3, -tc, tc);
1662 P0 = av_clip_pixel(p0 + delta0);
1664 Q0 = av_clip_pixel(q0 - delta0);
1670 static void FUNC(hevc_h_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride,
1671 int *tc, uint8_t *no_p,
1674 FUNC(hevc_loop_filter_chroma)(pix, stride, sizeof(pixel), tc, no_p, no_q);
1677 static void FUNC(hevc_v_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride,
1678 int *tc, uint8_t *no_p,
1681 FUNC(hevc_loop_filter_chroma)(pix, sizeof(pixel), stride, tc, no_p, no_q);
1684 static void FUNC(hevc_h_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride,
1685 int *beta, int *tc, uint8_t *no_p,
1688 FUNC(hevc_loop_filter_luma)(pix, stride, sizeof(pixel),
1689 beta, tc, no_p, no_q);
1692 static void FUNC(hevc_v_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride,
1693 int *beta, int *tc, uint8_t *no_p,
1696 FUNC(hevc_loop_filter_luma)(pix, sizeof(pixel), stride,
1697 beta, tc, no_p, no_q);