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 size,
31 GetBitContext *gb, int pcm_bit_depth)
34 pixel *dst = (pixel *)_dst;
36 stride /= sizeof(pixel);
38 for (y = 0; y < size; y++) {
39 for (x = 0; x < size; x++)
40 dst[x] = get_bits(gb, pcm_bit_depth) << (BIT_DEPTH - pcm_bit_depth);
45 static void FUNC(transquant_bypass4x4)(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(transquant_bypass8x8)(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(transquant_bypass16x16)(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(transquant_bypass32x32)(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)(uint8_t *_dst, int16_t *coeffs,
116 pixel *dst = (pixel *)_dst;
117 int shift = 13 - BIT_DEPTH;
119 int offset = 1 << (shift - 1);
125 stride /= sizeof(pixel);
127 for (y = 0; y < 4 * 4; y += 4) {
128 for (x = 0; x < 4; x++)
129 dst[x] = av_clip_pixel(dst[x] + ((coeffs[y + x] + offset) >> shift));
134 #define SET(dst, x) (dst) = (x)
135 #define SCALE(dst, x) (dst) = av_clip_int16(((x) + add) >> shift)
136 #define ADD_AND_SCALE(dst, x) \
137 (dst) = av_clip_pixel((dst) + av_clip_int16(((x) + add) >> shift))
139 #define TR_4x4_LUMA(dst, src, step, assign) \
141 int c0 = src[0 * step] + src[2 * step]; \
142 int c1 = src[2 * step] + src[3 * step]; \
143 int c2 = src[0 * step] - src[3 * step]; \
144 int c3 = 74 * src[1 * step]; \
146 assign(dst[2 * step], 74 * (src[0 * step] - \
149 assign(dst[0 * step], 29 * c0 + 55 * c1 + c3); \
150 assign(dst[1 * step], 55 * c2 - 29 * c1 + c3); \
151 assign(dst[3 * step], 55 * c0 + 29 * c2 - c3); \
154 static void FUNC(transform_4x4_luma_add)(uint8_t *_dst, int16_t *coeffs,
158 pixel *dst = (pixel *)_dst;
160 int add = 1 << (shift - 1);
161 int16_t *src = coeffs;
163 stride /= sizeof(pixel);
165 for (i = 0; i < 4; i++) {
166 TR_4x4_LUMA(src, src, 4, SCALE);
170 shift = 20 - BIT_DEPTH;
171 add = 1 << (shift - 1);
172 for (i = 0; i < 4; i++) {
173 TR_4x4_LUMA(dst, coeffs, 1, ADD_AND_SCALE);
181 #define TR_4(dst, src, dstep, sstep, assign) \
183 const int e0 = transform[8 * 0][0] * src[0 * sstep] + \
184 transform[8 * 2][0] * src[2 * sstep]; \
185 const int e1 = transform[8 * 0][1] * src[0 * sstep] + \
186 transform[8 * 2][1] * src[2 * sstep]; \
187 const int o0 = transform[8 * 1][0] * src[1 * sstep] + \
188 transform[8 * 3][0] * src[3 * sstep]; \
189 const int o1 = transform[8 * 1][1] * src[1 * sstep] + \
190 transform[8 * 3][1] * src[3 * sstep]; \
192 assign(dst[0 * dstep], e0 + o0); \
193 assign(dst[1 * dstep], e1 + o1); \
194 assign(dst[2 * dstep], e1 - o1); \
195 assign(dst[3 * dstep], e0 - o0); \
198 static void FUNC(transform_4x4_add)(uint8_t *_dst, int16_t *coeffs,
202 pixel *dst = (pixel *)_dst;
204 int add = 1 << (shift - 1);
205 int16_t *src = coeffs;
207 stride /= sizeof(pixel);
209 for (i = 0; i < 4; i++) {
210 TR_4(src, src, 4, 4, SCALE);
214 shift = 20 - BIT_DEPTH;
215 add = 1 << (shift - 1);
216 for (i = 0; i < 4; i++) {
217 TR_4(dst, coeffs, 1, 1, ADD_AND_SCALE);
223 #define TR_8(dst, src, dstep, sstep, assign) \
227 int o_8[4] = { 0 }; \
228 for (i = 0; i < 4; i++) \
229 for (j = 1; j < 8; j += 2) \
230 o_8[i] += transform[4 * j][i] * src[j * sstep]; \
231 TR_4(e_8, src, 1, 2 * sstep, SET); \
233 for (i = 0; i < 4; i++) { \
234 assign(dst[i * dstep], e_8[i] + o_8[i]); \
235 assign(dst[(7 - i) * dstep], e_8[i] - o_8[i]); \
239 #define TR_16(dst, src, dstep, sstep, assign) \
243 int o_16[8] = { 0 }; \
244 for (i = 0; i < 8; i++) \
245 for (j = 1; j < 16; j += 2) \
246 o_16[i] += transform[2 * j][i] * src[j * sstep]; \
247 TR_8(e_16, src, 1, 2 * sstep, SET); \
249 for (i = 0; i < 8; i++) { \
250 assign(dst[i * dstep], e_16[i] + o_16[i]); \
251 assign(dst[(15 - i) * dstep], e_16[i] - o_16[i]); \
255 #define TR_32(dst, src, dstep, sstep, assign) \
259 int o_32[16] = { 0 }; \
260 for (i = 0; i < 16; i++) \
261 for (j = 1; j < 32; j += 2) \
262 o_32[i] += transform[j][i] * src[j * sstep]; \
263 TR_16(e_32, src, 1, 2 * sstep, SET); \
265 for (i = 0; i < 16; i++) { \
266 assign(dst[i * dstep], e_32[i] + o_32[i]); \
267 assign(dst[(31 - i) * dstep], e_32[i] - o_32[i]); \
273 static void FUNC(transform_8x8_add)(uint8_t *_dst, int16_t *coeffs,
277 pixel *dst = (pixel *)_dst;
279 int add = 1 << (shift - 1);
280 int16_t *src = coeffs;
282 stride /= sizeof(pixel);
284 for (i = 0; i < 8; i++) {
285 TR_8(src, src, 8, 8, SCALE);
289 shift = 20 - BIT_DEPTH;
290 add = 1 << (shift - 1);
291 for (i = 0; i < 8; i++) {
292 TR_8(dst, coeffs, 1, 1, ADD_AND_SCALE);
298 static void FUNC(transform_16x16_add)(uint8_t *_dst, int16_t *coeffs,
302 pixel *dst = (pixel *)_dst;
304 int add = 1 << (shift - 1);
305 int16_t *src = coeffs;
307 stride /= sizeof(pixel);
309 for (i = 0; i < 16; i++) {
310 TR_16(src, src, 16, 16, SCALE);
314 shift = 20 - BIT_DEPTH;
315 add = 1 << (shift - 1);
316 for (i = 0; i < 16; i++) {
317 TR_16(dst, coeffs, 1, 1, ADD_AND_SCALE);
323 static void FUNC(transform_32x32_add)(uint8_t *_dst, int16_t *coeffs,
327 pixel *dst = (pixel *)_dst;
329 int add = 1 << (shift - 1);
330 int16_t *src = coeffs;
332 stride /= sizeof(pixel);
334 for (i = 0; i < 32; i++) {
335 TR_32(src, src, 32, 32, SCALE);
339 shift = 20 - BIT_DEPTH;
340 add = 1 << (shift - 1);
341 for (i = 0; i < 32; i++) {
342 TR_32(dst, coeffs, 1, 1, ADD_AND_SCALE);
348 static void FUNC(sao_band_filter)(uint8_t *_dst, uint8_t *_src,
349 ptrdiff_t stride, SAOParams *sao,
350 int *borders, int width, int height,
351 int c_idx, int class)
353 pixel *dst = (pixel *)_dst;
354 pixel *src = (pixel *)_src;
355 int offset_table[32] = { 0 };
357 int chroma = !!c_idx;
358 int shift = BIT_DEPTH - 5;
359 int *sao_offset_val = sao->offset_val[c_idx];
360 int sao_left_class = sao->band_position[c_idx];
361 int init_y = 0, init_x = 0;
363 stride /= sizeof(pixel);
368 width -= (8 >> chroma) + 2;
370 height -= (4 >> chroma) + 2;
373 init_y = -(4 >> chroma) - 2;
375 width -= (8 >> chroma) + 2;
376 height = (4 >> chroma) + 2;
379 init_x = -(8 >> chroma) - 2;
380 width = (8 >> chroma) + 2;
382 height -= (4 >> chroma) + 2;
385 init_y = -(4 >> chroma) - 2;
386 init_x = -(8 >> chroma) - 2;
387 width = (8 >> chroma) + 2;
388 height = (4 >> chroma) + 2;
392 dst = dst + (init_y * stride + init_x);
393 src = src + (init_y * stride + init_x);
394 for (k = 0; k < 4; k++)
395 offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];
396 for (y = 0; y < height; y++) {
397 for (x = 0; x < width; x++)
398 dst[x] = av_clip_pixel(src[x] + offset_table[src[x] >> shift]);
404 static void FUNC(sao_band_filter_0)(uint8_t *dst, uint8_t *src,
405 ptrdiff_t stride, SAOParams *sao,
406 int *borders, int width, int height,
409 FUNC(sao_band_filter)(dst, src, stride, sao, borders,
410 width, height, c_idx, 0);
413 static void FUNC(sao_band_filter_1)(uint8_t *dst, uint8_t *src,
414 ptrdiff_t stride, SAOParams *sao,
415 int *borders, int width, int height,
418 FUNC(sao_band_filter)(dst, src, stride, sao, borders,
419 width, height, c_idx, 1);
422 static void FUNC(sao_band_filter_2)(uint8_t *dst, uint8_t *src,
423 ptrdiff_t stride, SAOParams *sao,
424 int *borders, int width, int height,
427 FUNC(sao_band_filter)(dst, src, stride, sao, borders,
428 width, height, c_idx, 2);
431 static void FUNC(sao_band_filter_3)(uint8_t *_dst, uint8_t *_src,
432 ptrdiff_t stride, SAOParams *sao,
433 int *borders, int width, int height,
436 FUNC(sao_band_filter)(_dst, _src, stride, sao, borders,
437 width, height, c_idx, 3);
440 static void FUNC(sao_edge_filter_0)(uint8_t *_dst, uint8_t *_src,
441 ptrdiff_t stride, SAOParams *sao,
442 int *borders, int _width, int _height,
443 int c_idx, uint8_t vert_edge,
444 uint8_t horiz_edge, uint8_t diag_edge)
447 pixel *dst = (pixel *)_dst;
448 pixel *src = (pixel *)_src;
449 int chroma = !!c_idx;
450 int *sao_offset_val = sao->offset_val[c_idx];
451 int sao_eo_class = sao->eo_class[c_idx];
452 int init_x = 0, init_y = 0, width = _width, height = _height;
454 static const int8_t pos[4][2][2] = {
455 { { -1, 0 }, { 1, 0 } }, // horizontal
456 { { 0, -1 }, { 0, 1 } }, // vertical
457 { { -1, -1 }, { 1, 1 } }, // 45 degree
458 { { 1, -1 }, { -1, 1 } }, // 135 degree
460 static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
462 #define CMP(a, b) ((a) > (b) ? 1 : ((a) == (b) ? 0 : -1))
464 stride /= sizeof(pixel);
467 width -= (8 >> chroma) + 2;
469 height -= (4 >> chroma) + 2;
471 dst = dst + (init_y * stride + init_x);
472 src = src + (init_y * stride + init_x);
474 if (sao_eo_class != SAO_EO_VERT) {
476 int offset_val = sao_offset_val[0];
478 for (y = 0; y < height; y++) {
479 dst[y_stride] = av_clip_pixel(src[y_stride] + offset_val);
485 int offset_val = sao_offset_val[0];
486 int x_stride = width - 1;
487 for (x = 0; x < height; x++) {
488 dst[x_stride] = av_clip_pixel(src[x_stride] + offset_val);
494 if (sao_eo_class != SAO_EO_HORIZ) {
496 int offset_val = sao_offset_val[0];
497 for (x = init_x; x < width; x++)
498 dst[x] = av_clip_pixel(src[x] + offset_val);
502 int offset_val = sao_offset_val[0];
503 int y_stride = stride * (height - 1);
504 for (x = init_x; x < width; x++)
505 dst[x + y_stride] = av_clip_pixel(src[x + y_stride] + offset_val);
510 int y_stride = init_y * stride;
511 int pos_0_0 = pos[sao_eo_class][0][0];
512 int pos_0_1 = pos[sao_eo_class][0][1];
513 int pos_1_0 = pos[sao_eo_class][1][0];
514 int pos_1_1 = pos[sao_eo_class][1][1];
516 int y_stride_0_1 = (init_y + pos_0_1) * stride;
517 int y_stride_1_1 = (init_y + pos_1_1) * stride;
518 for (y = init_y; y < height; y++) {
519 for (x = init_x; x < width; x++) {
520 int diff0 = CMP(src[x + y_stride], src[x + pos_0_0 + y_stride_0_1]);
521 int diff1 = CMP(src[x + y_stride], src[x + pos_1_0 + y_stride_1_1]);
522 int offset_val = edge_idx[2 + diff0 + diff1];
523 dst[x + y_stride] = av_clip_pixel(src[x + y_stride] + sao_offset_val[offset_val]);
526 y_stride_0_1 += stride;
527 y_stride_1_1 += stride;
532 // Restore pixels that can't be modified
533 int save_upper_left = !diag_edge && sao_eo_class == SAO_EO_135D && !borders[0] && !borders[1];
534 if (vert_edge && sao_eo_class != SAO_EO_VERT)
535 for (y = init_y+save_upper_left; y< height; y++)
536 dst[y*stride] = src[y*stride];
537 if(horiz_edge && sao_eo_class != SAO_EO_HORIZ)
538 for(x = init_x+save_upper_left; x<width; x++)
540 if(diag_edge && sao_eo_class == SAO_EO_135D)
547 static void FUNC(sao_edge_filter_1)(uint8_t *_dst, uint8_t *_src,
548 ptrdiff_t stride, SAOParams *sao,
549 int *borders, int _width, int _height,
550 int c_idx, uint8_t vert_edge,
551 uint8_t horiz_edge, uint8_t diag_edge)
554 pixel *dst = (pixel *)_dst;
555 pixel *src = (pixel *)_src;
556 int chroma = !!c_idx;
557 int *sao_offset_val = sao->offset_val[c_idx];
558 int sao_eo_class = sao->eo_class[c_idx];
559 int init_x = 0, init_y = 0, width = _width, height = _height;
561 static const int8_t pos[4][2][2] = {
562 { { -1, 0 }, { 1, 0 } }, // horizontal
563 { { 0, -1 }, { 0, 1 } }, // vertical
564 { { -1, -1 }, { 1, 1 } }, // 45 degree
565 { { 1, -1 }, { -1, 1 } }, // 135 degree
567 static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
569 #define CMP(a, b) ((a) > (b) ? 1 : ((a) == (b) ? 0 : -1))
571 stride /= sizeof(pixel);
573 init_y = -(4 >> chroma) - 2;
575 width -= (8 >> chroma) + 2;
576 height = (4 >> chroma) + 2;
578 dst = dst + (init_y * stride + init_x);
579 src = src + (init_y * stride + init_x);
581 if (sao_eo_class != SAO_EO_VERT) {
583 int offset_val = sao_offset_val[0];
585 for (y = 0; y < height; y++) {
586 dst[y_stride] = av_clip_pixel(src[y_stride] + offset_val);
592 int offset_val = sao_offset_val[0];
593 int x_stride = width - 1;
594 for (x = 0; x < height; x++) {
595 dst[x_stride] = av_clip_pixel(src[x_stride] + offset_val);
602 int y_stride = init_y * stride;
603 int pos_0_0 = pos[sao_eo_class][0][0];
604 int pos_0_1 = pos[sao_eo_class][0][1];
605 int pos_1_0 = pos[sao_eo_class][1][0];
606 int pos_1_1 = pos[sao_eo_class][1][1];
608 int y_stride_0_1 = (init_y + pos_0_1) * stride;
609 int y_stride_1_1 = (init_y + pos_1_1) * stride;
610 for (y = init_y; y < height; y++) {
611 for (x = init_x; x < width; x++) {
612 int diff0 = CMP(src[x + y_stride], src[x + pos_0_0 + y_stride_0_1]);
613 int diff1 = CMP(src[x + y_stride], src[x + pos_1_0 + y_stride_1_1]);
614 int offset_val = edge_idx[2 + diff0 + diff1];
615 dst[x + y_stride] = av_clip_pixel(src[x + y_stride] + sao_offset_val[offset_val]);
618 y_stride_0_1 += stride;
619 y_stride_1_1 += stride;
624 // Restore pixels that can't be modified
625 int save_lower_left = !diag_edge && sao_eo_class == SAO_EO_45D && !borders[0];
626 if(vert_edge && sao_eo_class != SAO_EO_VERT)
627 for(y = init_y; y< height-save_lower_left; y++)
628 dst[y*stride] = src[y*stride];
629 if(horiz_edge && sao_eo_class != SAO_EO_HORIZ)
630 for(x = init_x+save_lower_left; x<width; x++)
631 dst[(height-1)*stride+x] = src[(height-1)*stride+x];
632 if(diag_edge && sao_eo_class == SAO_EO_45D)
633 dst[stride*(height-1)] = src[stride*(height-1)];
639 static void FUNC(sao_edge_filter_2)(uint8_t *_dst, uint8_t *_src,
640 ptrdiff_t stride, SAOParams *sao,
641 int *borders, int _width, int _height,
642 int c_idx, uint8_t vert_edge,
643 uint8_t horiz_edge, uint8_t diag_edge)
646 pixel *dst = (pixel *)_dst;
647 pixel *src = (pixel *)_src;
648 int chroma = !!c_idx;
649 int *sao_offset_val = sao->offset_val[c_idx];
650 int sao_eo_class = sao->eo_class[c_idx];
651 int init_x = 0, init_y = 0, width = _width, height = _height;
653 static const int8_t pos[4][2][2] = {
654 { { -1, 0 }, { 1, 0 } }, // horizontal
655 { { 0, -1 }, { 0, 1 } }, // vertical
656 { { -1, -1 }, { 1, 1 } }, // 45 degree
657 { { 1, -1 }, { -1, 1 } }, // 135 degree
659 static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
661 #define CMP(a, b) ((a) > (b) ? 1 : ((a) == (b) ? 0 : -1))
663 stride /= sizeof(pixel);
665 init_x = -(8 >> chroma) - 2;
666 width = (8 >> chroma) + 2;
668 height -= (4 >> chroma) + 2;
670 dst = dst + (init_y * stride + init_x);
671 src = src + (init_y * stride + init_x);
673 if (sao_eo_class != SAO_EO_HORIZ) {
675 int offset_val = sao_offset_val[0];
676 for (x = init_x; x < width; x++)
677 dst[x] = av_clip_pixel(src[x] + offset_val);
681 int offset_val = sao_offset_val[0];
682 int y_stride = stride * (height - 1);
683 for (x = init_x; x < width; x++)
684 dst[x + y_stride] = av_clip_pixel(src[x + y_stride] + offset_val);
689 int y_stride = init_y * stride;
690 int pos_0_0 = pos[sao_eo_class][0][0];
691 int pos_0_1 = pos[sao_eo_class][0][1];
692 int pos_1_0 = pos[sao_eo_class][1][0];
693 int pos_1_1 = pos[sao_eo_class][1][1];
695 int y_stride_0_1 = (init_y + pos_0_1) * stride;
696 int y_stride_1_1 = (init_y + pos_1_1) * stride;
697 for (y = init_y; y < height; y++) {
698 for (x = init_x; x < width; x++) {
699 int diff0 = CMP(src[x + y_stride], src[x + pos_0_0 + y_stride_0_1]);
700 int diff1 = CMP(src[x + y_stride], src[x + pos_1_0 + y_stride_1_1]);
701 int offset_val = edge_idx[2 + diff0 + diff1];
702 dst[x + y_stride] = av_clip_pixel(src[x + y_stride] + sao_offset_val[offset_val]);
705 y_stride_0_1 += stride;
706 y_stride_1_1 += stride;
711 // Restore pixels that can't be modified
712 int save_upper_right = !diag_edge && sao_eo_class == SAO_EO_45D && !borders[1];
713 if(vert_edge && sao_eo_class != SAO_EO_VERT)
714 for(y = init_y+save_upper_right; y< height; y++)
715 dst[y*stride+width-1] = src[y*stride+width-1];
716 if(horiz_edge && sao_eo_class != SAO_EO_HORIZ)
717 for(x = init_x; x<width-save_upper_right; x++)
719 if(diag_edge && sao_eo_class == SAO_EO_45D)
720 dst[width-1] = src[width-1];
725 static void FUNC(sao_edge_filter_3)(uint8_t *_dst, uint8_t *_src,
726 ptrdiff_t stride, SAOParams *sao,
727 int *borders, int _width, int _height,
728 int c_idx, uint8_t vert_edge,
729 uint8_t horiz_edge, uint8_t diag_edge)
732 pixel *dst = (pixel *)_dst;
733 pixel *src = (pixel *)_src;
734 int chroma = !!c_idx;
735 int *sao_offset_val = sao->offset_val[c_idx];
736 int sao_eo_class = sao->eo_class[c_idx];
737 int init_x = 0, init_y = 0, width = _width, height = _height;
739 static const int8_t pos[4][2][2] = {
740 { { -1, 0 }, { 1, 0 } }, // horizontal
741 { { 0, -1 }, { 0, 1 } }, // vertical
742 { { -1, -1 }, { 1, 1 } }, // 45 degree
743 { { 1, -1 }, { -1, 1 } }, // 135 degree
745 static const uint8_t edge_idx[] = { 1, 2, 0, 3, 4 };
747 #define CMP(a, b) ((a) > (b) ? 1 : ((a) == (b) ? 0 : -1))
749 stride /= sizeof(pixel);
751 init_y = -(4 >> chroma) - 2;
752 init_x = -(8 >> chroma) - 2;
753 width = (8 >> chroma) + 2;
754 height = (4 >> chroma) + 2;
757 dst = dst + (init_y * stride + init_x);
758 src = src + (init_y * stride + init_x);
762 int y_stride = init_y * stride;
763 int pos_0_0 = pos[sao_eo_class][0][0];
764 int pos_0_1 = pos[sao_eo_class][0][1];
765 int pos_1_0 = pos[sao_eo_class][1][0];
766 int pos_1_1 = pos[sao_eo_class][1][1];
768 int y_stride_0_1 = (init_y + pos_0_1) * stride;
769 int y_stride_1_1 = (init_y + pos_1_1) * stride;
771 for (y = init_y; y < height; y++) {
772 for (x = init_x; x < width; x++) {
773 int diff0 = CMP(src[x + y_stride], src[x + pos_0_0 + y_stride_0_1]);
774 int diff1 = CMP(src[x + y_stride], src[x + pos_1_0 + y_stride_1_1]);
775 int offset_val = edge_idx[2 + diff0 + diff1];
776 dst[x + y_stride] = av_clip_pixel(src[x + y_stride] + sao_offset_val[offset_val]);
779 y_stride_0_1 += stride;
780 y_stride_1_1 += stride;
785 // Restore pixels that can't be modified
786 int save_lower_right = !diag_edge && sao_eo_class == SAO_EO_135D;
787 if(vert_edge && sao_eo_class != SAO_EO_VERT)
788 for(y = init_y; y< height-save_lower_right; y++)
789 dst[y*stride+width-1] = src[y*stride+width-1];
790 if(horiz_edge && sao_eo_class != SAO_EO_HORIZ)
791 for(x = init_x; x<width-save_lower_right; x++)
792 dst[(height-1)*stride+x] = src[(height-1)*stride+x];
793 if(diag_edge && sao_eo_class == SAO_EO_135D)
794 dst[stride*(height-1)+width-1] = src[stride*(height-1)+width-1];
808 ////////////////////////////////////////////////////////////////////////////////
810 ////////////////////////////////////////////////////////////////////////////////
811 static void FUNC(put_hevc_pel_pixels)(int16_t *dst, ptrdiff_t dststride,
812 uint8_t *_src, ptrdiff_t _srcstride,
813 int height, intptr_t mx, intptr_t my, int width)
816 pixel *src = (pixel *)_src;
817 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
819 for (y = 0; y < height; y++) {
820 for (x = 0; x < width; x++)
821 dst[x] = src[x] << (14 - BIT_DEPTH);
827 static void FUNC(put_hevc_pel_uni_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
828 int height, intptr_t mx, intptr_t my, int width)
831 pixel *src = (pixel *)_src;
832 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
833 pixel *dst = (pixel *)_dst;
834 ptrdiff_t dststride = _dststride / sizeof(pixel);
836 for (y = 0; y < height; y++) {
837 memcpy(dst, src, width * sizeof(pixel));
843 static void FUNC(put_hevc_pel_bi_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
844 int16_t *src2, ptrdiff_t src2stride,
845 int height, intptr_t mx, intptr_t my, int width)
848 pixel *src = (pixel *)_src;
849 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
850 pixel *dst = (pixel *)_dst;
851 ptrdiff_t dststride = _dststride / sizeof(pixel);
853 int shift = 14 + 1 - BIT_DEPTH;
855 int offset = 1 << (shift - 1);
860 for (y = 0; y < height; y++) {
861 for (x = 0; x < width; x++)
862 dst[x] = av_clip_pixel(((src[x] << (14 - BIT_DEPTH)) + src2[x] + offset) >> shift);
869 static void FUNC(put_hevc_pel_uni_w_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
870 int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
873 pixel *src = (pixel *)_src;
874 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
875 pixel *dst = (pixel *)_dst;
876 ptrdiff_t dststride = _dststride / sizeof(pixel);
877 int shift = denom + 14 - BIT_DEPTH;
879 int offset = 1 << (shift - 1);
884 ox = ox * (1 << (BIT_DEPTH - 8));
885 for (y = 0; y < height; y++) {
886 for (x = 0; x < width; x++)
887 dst[x] = av_clip_pixel((((src[x] << (14 - BIT_DEPTH)) * wx + offset) >> shift) + ox);
893 static void FUNC(put_hevc_pel_bi_w_pixels)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
894 int16_t *src2, ptrdiff_t src2stride,
895 int height, int denom, int wx0, int wx1,
896 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
899 pixel *src = (pixel *)_src;
900 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
901 pixel *dst = (pixel *)_dst;
902 ptrdiff_t dststride = _dststride / sizeof(pixel);
904 int shift = 14 + 1 - BIT_DEPTH;
905 int log2Wd = denom + shift - 1;
907 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
908 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
909 for (y = 0; y < height; y++) {
910 for (x = 0; x < width; x++) {
911 dst[x] = av_clip_pixel(( (src[x] << (14 - BIT_DEPTH)) * wx1 + src2[x] * wx0 + ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
919 ////////////////////////////////////////////////////////////////////////////////
921 ////////////////////////////////////////////////////////////////////////////////
922 #define QPEL_FILTER(src, stride) \
923 (filter[0] * src[x - 3 * stride] + \
924 filter[1] * src[x - 2 * stride] + \
925 filter[2] * src[x - stride] + \
926 filter[3] * src[x ] + \
927 filter[4] * src[x + stride] + \
928 filter[5] * src[x + 2 * stride] + \
929 filter[6] * src[x + 3 * stride] + \
930 filter[7] * src[x + 4 * stride])
932 static void FUNC(put_hevc_qpel_h)(int16_t *dst, ptrdiff_t dststride,
933 uint8_t *_src, ptrdiff_t _srcstride,
934 int height, intptr_t mx, intptr_t my, int width)
937 pixel *src = (pixel*)_src;
938 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
939 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
940 for (y = 0; y < height; y++) {
941 for (x = 0; x < width; x++)
942 dst[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
948 static void FUNC(put_hevc_qpel_v)(int16_t *dst, ptrdiff_t dststride,
949 uint8_t *_src, ptrdiff_t _srcstride,
950 int height, intptr_t mx, intptr_t my, int width)
953 pixel *src = (pixel*)_src;
954 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
955 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
956 for (y = 0; y < height; y++) {
957 for (x = 0; x < width; x++)
958 dst[x] = QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8);
964 static void FUNC(put_hevc_qpel_hv)(int16_t *dst,
967 ptrdiff_t _srcstride,
968 int height, intptr_t mx,
969 intptr_t my, int width)
972 const int8_t *filter;
973 pixel *src = (pixel*)_src;
974 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
975 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
976 int16_t *tmp = tmp_array;
978 src -= QPEL_EXTRA_BEFORE * srcstride;
979 filter = ff_hevc_qpel_filters[mx - 1];
980 for (y = 0; y < height + QPEL_EXTRA; y++) {
981 for (x = 0; x < width; x++)
982 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
987 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
988 filter = ff_hevc_qpel_filters[my - 1];
989 for (y = 0; y < height; y++) {
990 for (x = 0; x < width; x++)
991 dst[x] = QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6;
997 static void FUNC(put_hevc_qpel_uni_h)(uint8_t *_dst, ptrdiff_t _dststride,
998 uint8_t *_src, ptrdiff_t _srcstride,
999 int height, intptr_t mx, intptr_t my, int width)
1002 pixel *src = (pixel*)_src;
1003 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1004 pixel *dst = (pixel *)_dst;
1005 ptrdiff_t dststride = _dststride / sizeof(pixel);
1006 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
1007 int shift = 14 - BIT_DEPTH;
1010 int offset = 1 << (shift - 1);
1015 for (y = 0; y < height; y++) {
1016 for (x = 0; x < width; x++)
1017 dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + offset) >> shift);
1023 static void FUNC(put_hevc_qpel_bi_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1024 int16_t *src2, ptrdiff_t src2stride,
1025 int height, intptr_t mx, intptr_t my, int width)
1028 pixel *src = (pixel*)_src;
1029 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1030 pixel *dst = (pixel *)_dst;
1031 ptrdiff_t dststride = _dststride / sizeof(pixel);
1033 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
1035 int shift = 14 + 1 - BIT_DEPTH;
1037 int offset = 1 << (shift - 1);
1042 for (y = 0; y < height; y++) {
1043 for (x = 0; x < width; x++)
1044 dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
1051 static void FUNC(put_hevc_qpel_uni_v)(uint8_t *_dst, ptrdiff_t _dststride,
1052 uint8_t *_src, ptrdiff_t _srcstride,
1053 int height, intptr_t mx, intptr_t my, int width)
1056 pixel *src = (pixel*)_src;
1057 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1058 pixel *dst = (pixel *)_dst;
1059 ptrdiff_t dststride = _dststride / sizeof(pixel);
1060 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
1061 int shift = 14 - BIT_DEPTH;
1064 int offset = 1 << (shift - 1);
1069 for (y = 0; y < height; y++) {
1070 for (x = 0; x < width; x++)
1071 dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + offset) >> shift);
1078 static void FUNC(put_hevc_qpel_bi_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1079 int16_t *src2, ptrdiff_t src2stride,
1080 int height, intptr_t mx, intptr_t my, int width)
1083 pixel *src = (pixel*)_src;
1084 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1085 pixel *dst = (pixel *)_dst;
1086 ptrdiff_t dststride = _dststride / sizeof(pixel);
1088 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
1090 int shift = 14 + 1 - BIT_DEPTH;
1092 int offset = 1 << (shift - 1);
1097 for (y = 0; y < height; y++) {
1098 for (x = 0; x < width; x++)
1099 dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
1106 static void FUNC(put_hevc_qpel_uni_hv)(uint8_t *_dst, ptrdiff_t _dststride,
1107 uint8_t *_src, ptrdiff_t _srcstride,
1108 int height, intptr_t mx, intptr_t my, int width)
1111 const int8_t *filter;
1112 pixel *src = (pixel*)_src;
1113 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1114 pixel *dst = (pixel *)_dst;
1115 ptrdiff_t dststride = _dststride / sizeof(pixel);
1116 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
1117 int16_t *tmp = tmp_array;
1118 int shift = 14 - BIT_DEPTH;
1121 int offset = 1 << (shift - 1);
1126 src -= QPEL_EXTRA_BEFORE * srcstride;
1127 filter = ff_hevc_qpel_filters[mx - 1];
1128 for (y = 0; y < height + QPEL_EXTRA; y++) {
1129 for (x = 0; x < width; x++)
1130 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1135 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1136 filter = ff_hevc_qpel_filters[my - 1];
1138 for (y = 0; y < height; y++) {
1139 for (x = 0; x < width; x++)
1140 dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + offset) >> shift);
1146 static void FUNC(put_hevc_qpel_bi_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1147 int16_t *src2, ptrdiff_t src2stride,
1148 int height, intptr_t mx, intptr_t my, int width)
1151 const int8_t *filter;
1152 pixel *src = (pixel*)_src;
1153 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1154 pixel *dst = (pixel *)_dst;
1155 ptrdiff_t dststride = _dststride / sizeof(pixel);
1156 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
1157 int16_t *tmp = tmp_array;
1158 int shift = 14 + 1 - BIT_DEPTH;
1160 int offset = 1 << (shift - 1);
1165 src -= QPEL_EXTRA_BEFORE * srcstride;
1166 filter = ff_hevc_qpel_filters[mx - 1];
1167 for (y = 0; y < height + QPEL_EXTRA; y++) {
1168 for (x = 0; x < width; x++)
1169 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1174 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1175 filter = ff_hevc_qpel_filters[my - 1];
1177 for (y = 0; y < height; y++) {
1178 for (x = 0; x < width; x++)
1179 dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + src2[x] + offset) >> shift);
1186 static void FUNC(put_hevc_qpel_uni_w_h)(uint8_t *_dst, ptrdiff_t _dststride,
1187 uint8_t *_src, ptrdiff_t _srcstride,
1188 int height, int denom, int wx, int ox,
1189 intptr_t mx, intptr_t my, int width)
1192 pixel *src = (pixel*)_src;
1193 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1194 pixel *dst = (pixel *)_dst;
1195 ptrdiff_t dststride = _dststride / sizeof(pixel);
1196 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
1197 int shift = denom + 14 - BIT_DEPTH;
1199 int offset = 1 << (shift - 1);
1204 ox = ox * (1 << (BIT_DEPTH - 8));
1205 for (y = 0; y < height; y++) {
1206 for (x = 0; x < width; x++)
1207 dst[x] = av_clip_pixel((((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
1213 static void FUNC(put_hevc_qpel_bi_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1214 int16_t *src2, ptrdiff_t src2stride,
1215 int height, int denom, int wx0, int wx1,
1216 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1219 pixel *src = (pixel*)_src;
1220 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1221 pixel *dst = (pixel *)_dst;
1222 ptrdiff_t dststride = _dststride / sizeof(pixel);
1224 const int8_t *filter = ff_hevc_qpel_filters[mx - 1];
1226 int shift = 14 + 1 - BIT_DEPTH;
1227 int log2Wd = denom + shift - 1;
1229 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1230 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1231 for (y = 0; y < height; y++) {
1232 for (x = 0; x < width; x++)
1233 dst[x] = av_clip_pixel(((QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
1234 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1241 static void FUNC(put_hevc_qpel_uni_w_v)(uint8_t *_dst, ptrdiff_t _dststride,
1242 uint8_t *_src, ptrdiff_t _srcstride,
1243 int height, int denom, int wx, int ox,
1244 intptr_t mx, intptr_t my, int width)
1247 pixel *src = (pixel*)_src;
1248 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1249 pixel *dst = (pixel *)_dst;
1250 ptrdiff_t dststride = _dststride / sizeof(pixel);
1251 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
1252 int shift = denom + 14 - BIT_DEPTH;
1254 int offset = 1 << (shift - 1);
1259 ox = ox * (1 << (BIT_DEPTH - 8));
1260 for (y = 0; y < height; y++) {
1261 for (x = 0; x < width; x++)
1262 dst[x] = av_clip_pixel((((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
1268 static void FUNC(put_hevc_qpel_bi_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1269 int16_t *src2, ptrdiff_t src2stride,
1270 int height, int denom, int wx0, int wx1,
1271 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1274 pixel *src = (pixel*)_src;
1275 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1276 pixel *dst = (pixel *)_dst;
1277 ptrdiff_t dststride = _dststride / sizeof(pixel);
1279 const int8_t *filter = ff_hevc_qpel_filters[my - 1];
1281 int shift = 14 + 1 - BIT_DEPTH;
1282 int log2Wd = denom + shift - 1;
1284 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1285 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1286 for (y = 0; y < height; y++) {
1287 for (x = 0; x < width; x++)
1288 dst[x] = av_clip_pixel(((QPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
1289 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1296 static void FUNC(put_hevc_qpel_uni_w_hv)(uint8_t *_dst, ptrdiff_t _dststride,
1297 uint8_t *_src, ptrdiff_t _srcstride,
1298 int height, int denom, int wx, int ox,
1299 intptr_t mx, intptr_t my, int width)
1302 const int8_t *filter;
1303 pixel *src = (pixel*)_src;
1304 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1305 pixel *dst = (pixel *)_dst;
1306 ptrdiff_t dststride = _dststride / sizeof(pixel);
1307 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
1308 int16_t *tmp = tmp_array;
1309 int shift = denom + 14 - BIT_DEPTH;
1311 int offset = 1 << (shift - 1);
1316 src -= QPEL_EXTRA_BEFORE * srcstride;
1317 filter = ff_hevc_qpel_filters[mx - 1];
1318 for (y = 0; y < height + QPEL_EXTRA; y++) {
1319 for (x = 0; x < width; x++)
1320 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1325 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1326 filter = ff_hevc_qpel_filters[my - 1];
1328 ox = ox * (1 << (BIT_DEPTH - 8));
1329 for (y = 0; y < height; y++) {
1330 for (x = 0; x < width; x++)
1331 dst[x] = av_clip_pixel((((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
1337 static void FUNC(put_hevc_qpel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1338 int16_t *src2, ptrdiff_t src2stride,
1339 int height, int denom, int wx0, int wx1,
1340 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1343 const int8_t *filter;
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 int16_t tmp_array[(MAX_PB_SIZE + QPEL_EXTRA) * MAX_PB_SIZE];
1349 int16_t *tmp = tmp_array;
1350 int shift = 14 + 1 - BIT_DEPTH;
1351 int log2Wd = denom + shift - 1;
1353 src -= QPEL_EXTRA_BEFORE * srcstride;
1354 filter = ff_hevc_qpel_filters[mx - 1];
1355 for (y = 0; y < height + QPEL_EXTRA; y++) {
1356 for (x = 0; x < width; x++)
1357 tmp[x] = QPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1362 tmp = tmp_array + QPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1363 filter = ff_hevc_qpel_filters[my - 1];
1365 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1366 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1367 for (y = 0; y < height; y++) {
1368 for (x = 0; x < width; x++)
1369 dst[x] = av_clip_pixel(((QPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 +
1370 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1377 ////////////////////////////////////////////////////////////////////////////////
1379 ////////////////////////////////////////////////////////////////////////////////
1380 #define EPEL_FILTER(src, stride) \
1381 (filter[0] * src[x - stride] + \
1382 filter[1] * src[x] + \
1383 filter[2] * src[x + stride] + \
1384 filter[3] * src[x + 2 * stride])
1386 static void FUNC(put_hevc_epel_h)(int16_t *dst, ptrdiff_t dststride,
1387 uint8_t *_src, ptrdiff_t _srcstride,
1388 int height, intptr_t mx, intptr_t my, int width)
1391 pixel *src = (pixel *)_src;
1392 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1393 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1394 for (y = 0; y < height; y++) {
1395 for (x = 0; x < width; x++)
1396 dst[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1402 static void FUNC(put_hevc_epel_v)(int16_t *dst, ptrdiff_t dststride,
1403 uint8_t *_src, ptrdiff_t _srcstride,
1404 int height, intptr_t mx, intptr_t my, int width)
1407 pixel *src = (pixel *)_src;
1408 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1409 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1411 for (y = 0; y < height; y++) {
1412 for (x = 0; x < width; x++)
1413 dst[x] = EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8);
1419 static void FUNC(put_hevc_epel_hv)(int16_t *dst, ptrdiff_t dststride,
1420 uint8_t *_src, ptrdiff_t _srcstride,
1421 int height, 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[mx - 1];
1427 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1428 int16_t *tmp = tmp_array;
1430 src -= EPEL_EXTRA_BEFORE * srcstride;
1432 for (y = 0; y < height + EPEL_EXTRA; y++) {
1433 for (x = 0; x < width; x++)
1434 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1439 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1440 filter = ff_hevc_epel_filters[my - 1];
1442 for (y = 0; y < height; y++) {
1443 for (x = 0; x < width; x++)
1444 dst[x] = EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6;
1450 static void FUNC(put_hevc_epel_uni_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1451 int height, intptr_t mx, intptr_t my, int width)
1454 pixel *src = (pixel *)_src;
1455 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1456 pixel *dst = (pixel *)_dst;
1457 ptrdiff_t dststride = _dststride / sizeof(pixel);
1458 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1459 int shift = 14 - BIT_DEPTH;
1461 int offset = 1 << (shift - 1);
1466 for (y = 0; y < height; y++) {
1467 for (x = 0; x < width; x++)
1468 dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + offset) >> shift);
1474 static void FUNC(put_hevc_epel_bi_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1475 int16_t *src2, ptrdiff_t src2stride,
1476 int height, intptr_t mx, intptr_t my, int width)
1479 pixel *src = (pixel *)_src;
1480 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1481 pixel *dst = (pixel *)_dst;
1482 ptrdiff_t dststride = _dststride / sizeof(pixel);
1483 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1484 int shift = 14 + 1 - BIT_DEPTH;
1486 int offset = 1 << (shift - 1);
1491 for (y = 0; y < height; y++) {
1492 for (x = 0; x < width; x++) {
1493 dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
1501 static void FUNC(put_hevc_epel_uni_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1502 int height, intptr_t mx, intptr_t my, int width)
1505 pixel *src = (pixel *)_src;
1506 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1507 pixel *dst = (pixel *)_dst;
1508 ptrdiff_t dststride = _dststride / sizeof(pixel);
1509 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1510 int shift = 14 - BIT_DEPTH;
1512 int offset = 1 << (shift - 1);
1517 for (y = 0; y < height; y++) {
1518 for (x = 0; x < width; x++)
1519 dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + offset) >> shift);
1525 static void FUNC(put_hevc_epel_bi_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1526 int16_t *src2, ptrdiff_t src2stride,
1527 int height, intptr_t mx, intptr_t my, int width)
1530 pixel *src = (pixel *)_src;
1531 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1532 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1533 pixel *dst = (pixel *)_dst;
1534 ptrdiff_t dststride = _dststride / sizeof(pixel);
1535 int shift = 14 + 1 - BIT_DEPTH;
1537 int offset = 1 << (shift - 1);
1542 for (y = 0; y < height; y++) {
1543 for (x = 0; x < width; x++)
1544 dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) + src2[x] + offset) >> shift);
1551 static void FUNC(put_hevc_epel_uni_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1552 int height, intptr_t mx, intptr_t my, int width)
1555 pixel *src = (pixel *)_src;
1556 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1557 pixel *dst = (pixel *)_dst;
1558 ptrdiff_t dststride = _dststride / sizeof(pixel);
1559 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1560 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1561 int16_t *tmp = tmp_array;
1562 int shift = 14 - BIT_DEPTH;
1564 int offset = 1 << (shift - 1);
1569 src -= EPEL_EXTRA_BEFORE * srcstride;
1571 for (y = 0; y < height + EPEL_EXTRA; y++) {
1572 for (x = 0; x < width; x++)
1573 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1578 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1579 filter = ff_hevc_epel_filters[my - 1];
1581 for (y = 0; y < height; y++) {
1582 for (x = 0; x < width; x++)
1583 dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + offset) >> shift);
1589 static void FUNC(put_hevc_epel_bi_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1590 int16_t *src2, ptrdiff_t src2stride,
1591 int height, intptr_t mx, intptr_t my, int width)
1594 pixel *src = (pixel *)_src;
1595 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1596 pixel *dst = (pixel *)_dst;
1597 ptrdiff_t dststride = _dststride / sizeof(pixel);
1598 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1599 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1600 int16_t *tmp = tmp_array;
1601 int shift = 14 + 1 - BIT_DEPTH;
1603 int offset = 1 << (shift - 1);
1608 src -= EPEL_EXTRA_BEFORE * srcstride;
1610 for (y = 0; y < height + EPEL_EXTRA; y++) {
1611 for (x = 0; x < width; x++)
1612 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1617 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1618 filter = ff_hevc_epel_filters[my - 1];
1620 for (y = 0; y < height; y++) {
1621 for (x = 0; x < width; x++)
1622 dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) + src2[x] + offset) >> shift);
1629 static void FUNC(put_hevc_epel_uni_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1630 int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
1633 pixel *src = (pixel *)_src;
1634 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1635 pixel *dst = (pixel *)_dst;
1636 ptrdiff_t dststride = _dststride / sizeof(pixel);
1637 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1638 int shift = denom + 14 - BIT_DEPTH;
1640 int offset = 1 << (shift - 1);
1645 ox = ox * (1 << (BIT_DEPTH - 8));
1646 for (y = 0; y < height; y++) {
1647 for (x = 0; x < width; x++) {
1648 dst[x] = av_clip_pixel((((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
1655 static void FUNC(put_hevc_epel_bi_w_h)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1656 int16_t *src2, ptrdiff_t src2stride,
1657 int height, int denom, int wx0, int wx1,
1658 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1661 pixel *src = (pixel *)_src;
1662 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1663 pixel *dst = (pixel *)_dst;
1664 ptrdiff_t dststride = _dststride / sizeof(pixel);
1665 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1666 int shift = 14 + 1 - BIT_DEPTH;
1667 int log2Wd = denom + shift - 1;
1669 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1670 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1671 for (y = 0; y < height; y++) {
1672 for (x = 0; x < width; x++)
1673 dst[x] = av_clip_pixel(((EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
1674 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1681 static void FUNC(put_hevc_epel_uni_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1682 int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
1685 pixel *src = (pixel *)_src;
1686 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1687 pixel *dst = (pixel *)_dst;
1688 ptrdiff_t dststride = _dststride / sizeof(pixel);
1689 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1690 int shift = denom + 14 - BIT_DEPTH;
1692 int offset = 1 << (shift - 1);
1697 ox = ox * (1 << (BIT_DEPTH - 8));
1698 for (y = 0; y < height; y++) {
1699 for (x = 0; x < width; x++) {
1700 dst[x] = av_clip_pixel((((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
1707 static void FUNC(put_hevc_epel_bi_w_v)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1708 int16_t *src2, ptrdiff_t src2stride,
1709 int height, int denom, int wx0, int wx1,
1710 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1713 pixel *src = (pixel *)_src;
1714 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1715 const int8_t *filter = ff_hevc_epel_filters[my - 1];
1716 pixel *dst = (pixel *)_dst;
1717 ptrdiff_t dststride = _dststride / sizeof(pixel);
1718 int shift = 14 + 1 - BIT_DEPTH;
1719 int log2Wd = denom + shift - 1;
1721 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1722 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1723 for (y = 0; y < height; y++) {
1724 for (x = 0; x < width; x++)
1725 dst[x] = av_clip_pixel(((EPEL_FILTER(src, srcstride) >> (BIT_DEPTH - 8)) * wx1 + src2[x] * wx0 +
1726 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1733 static void FUNC(put_hevc_epel_uni_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1734 int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width)
1737 pixel *src = (pixel *)_src;
1738 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1739 pixel *dst = (pixel *)_dst;
1740 ptrdiff_t dststride = _dststride / sizeof(pixel);
1741 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1742 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1743 int16_t *tmp = tmp_array;
1744 int shift = denom + 14 - BIT_DEPTH;
1746 int offset = 1 << (shift - 1);
1751 src -= EPEL_EXTRA_BEFORE * srcstride;
1753 for (y = 0; y < height + EPEL_EXTRA; y++) {
1754 for (x = 0; x < width; x++)
1755 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1760 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1761 filter = ff_hevc_epel_filters[my - 1];
1763 ox = ox * (1 << (BIT_DEPTH - 8));
1764 for (y = 0; y < height; y++) {
1765 for (x = 0; x < width; x++)
1766 dst[x] = av_clip_pixel((((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
1772 static void FUNC(put_hevc_epel_bi_w_hv)(uint8_t *_dst, ptrdiff_t _dststride, uint8_t *_src, ptrdiff_t _srcstride,
1773 int16_t *src2, ptrdiff_t src2stride,
1774 int height, int denom, int wx0, int wx1,
1775 int ox0, int ox1, intptr_t mx, intptr_t my, int width)
1778 pixel *src = (pixel *)_src;
1779 ptrdiff_t srcstride = _srcstride / sizeof(pixel);
1780 pixel *dst = (pixel *)_dst;
1781 ptrdiff_t dststride = _dststride / sizeof(pixel);
1782 const int8_t *filter = ff_hevc_epel_filters[mx - 1];
1783 int16_t tmp_array[(MAX_PB_SIZE + EPEL_EXTRA) * MAX_PB_SIZE];
1784 int16_t *tmp = tmp_array;
1785 int shift = 14 + 1 - BIT_DEPTH;
1786 int log2Wd = denom + shift - 1;
1788 src -= EPEL_EXTRA_BEFORE * srcstride;
1790 for (y = 0; y < height + EPEL_EXTRA; y++) {
1791 for (x = 0; x < width; x++)
1792 tmp[x] = EPEL_FILTER(src, 1) >> (BIT_DEPTH - 8);
1797 tmp = tmp_array + EPEL_EXTRA_BEFORE * MAX_PB_SIZE;
1798 filter = ff_hevc_epel_filters[my - 1];
1800 ox0 = ox0 * (1 << (BIT_DEPTH - 8));
1801 ox1 = ox1 * (1 << (BIT_DEPTH - 8));
1802 for (y = 0; y < height; y++) {
1803 for (x = 0; x < width; x++)
1804 dst[x] = av_clip_pixel(((EPEL_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx1 + src2[x] * wx0 +
1805 ((ox0 + ox1 + 1) << log2Wd)) >> (log2Wd + 1));
1811 #define P3 pix[-4 * xstride]
1812 #define P2 pix[-3 * xstride]
1813 #define P1 pix[-2 * xstride]
1814 #define P0 pix[-1 * xstride]
1815 #define Q0 pix[0 * xstride]
1816 #define Q1 pix[1 * xstride]
1817 #define Q2 pix[2 * xstride]
1818 #define Q3 pix[3 * xstride]
1820 // line three. used only for deblocking decision
1821 #define TP3 pix[-4 * xstride + 3 * ystride]
1822 #define TP2 pix[-3 * xstride + 3 * ystride]
1823 #define TP1 pix[-2 * xstride + 3 * ystride]
1824 #define TP0 pix[-1 * xstride + 3 * ystride]
1825 #define TQ0 pix[0 * xstride + 3 * ystride]
1826 #define TQ1 pix[1 * xstride + 3 * ystride]
1827 #define TQ2 pix[2 * xstride + 3 * ystride]
1828 #define TQ3 pix[3 * xstride + 3 * ystride]
1830 static void FUNC(hevc_loop_filter_luma)(uint8_t *_pix,
1831 ptrdiff_t _xstride, ptrdiff_t _ystride,
1832 int *_beta, int *_tc,
1833 uint8_t *_no_p, uint8_t *_no_q)
1836 pixel *pix = (pixel *)_pix;
1837 ptrdiff_t xstride = _xstride / sizeof(pixel);
1838 ptrdiff_t ystride = _ystride / sizeof(pixel);
1840 for (j = 0; j < 2; j++) {
1841 const int dp0 = abs(P2 - 2 * P1 + P0);
1842 const int dq0 = abs(Q2 - 2 * Q1 + Q0);
1843 const int dp3 = abs(TP2 - 2 * TP1 + TP0);
1844 const int dq3 = abs(TQ2 - 2 * TQ1 + TQ0);
1845 const int d0 = dp0 + dq0;
1846 const int d3 = dp3 + dq3;
1847 const int beta = _beta[j] << (BIT_DEPTH - 8);
1848 const int tc = _tc[j] << (BIT_DEPTH - 8);
1849 const int no_p = _no_p[j];
1850 const int no_q = _no_q[j];
1852 if (d0 + d3 >= beta) {
1856 const int beta_3 = beta >> 3;
1857 const int beta_2 = beta >> 2;
1858 const int tc25 = ((tc * 5 + 1) >> 1);
1860 if (abs(P3 - P0) + abs(Q3 - Q0) < beta_3 && abs(P0 - Q0) < tc25 &&
1861 abs(TP3 - TP0) + abs(TQ3 - TQ0) < beta_3 && abs(TP0 - TQ0) < tc25 &&
1862 (d0 << 1) < beta_2 && (d3 << 1) < beta_2) {
1864 const int tc2 = tc << 1;
1865 for (d = 0; d < 4; d++) {
1875 P0 = p0 + av_clip(((p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3) - p0, -tc2, tc2);
1876 P1 = p1 + av_clip(((p2 + p1 + p0 + q0 + 2) >> 2) - p1, -tc2, tc2);
1877 P2 = p2 + av_clip(((2 * p3 + 3 * p2 + p1 + p0 + q0 + 4) >> 3) - p2, -tc2, tc2);
1880 Q0 = q0 + av_clip(((p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3) - q0, -tc2, tc2);
1881 Q1 = q1 + av_clip(((p0 + q0 + q1 + q2 + 2) >> 2) - q1, -tc2, tc2);
1882 Q2 = q2 + av_clip(((2 * q3 + 3 * q2 + q1 + q0 + p0 + 4) >> 3) - q2, -tc2, tc2);
1886 } else { // normal filtering
1889 const int tc_2 = tc >> 1;
1890 if (dp0 + dp3 < ((beta + (beta >> 1)) >> 3))
1892 if (dq0 + dq3 < ((beta + (beta >> 1)) >> 3))
1895 for (d = 0; d < 4; d++) {
1902 int delta0 = (9 * (q0 - p0) - 3 * (q1 - p1) + 8) >> 4;
1903 if (abs(delta0) < 10 * tc) {
1904 delta0 = av_clip(delta0, -tc, tc);
1906 P0 = av_clip_pixel(p0 + delta0);
1908 Q0 = av_clip_pixel(q0 - delta0);
1909 if (!no_p && nd_p > 1) {
1910 const int deltap1 = av_clip((((p2 + p0 + 1) >> 1) - p1 + delta0) >> 1, -tc_2, tc_2);
1911 P1 = av_clip_pixel(p1 + deltap1);
1913 if (!no_q && nd_q > 1) {
1914 const int deltaq1 = av_clip((((q2 + q0 + 1) >> 1) - q1 - delta0) >> 1, -tc_2, tc_2);
1915 Q1 = av_clip_pixel(q1 + deltaq1);
1925 static void FUNC(hevc_loop_filter_chroma)(uint8_t *_pix, ptrdiff_t _xstride,
1926 ptrdiff_t _ystride, int *_tc,
1927 uint8_t *_no_p, uint8_t *_no_q)
1929 int d, j, no_p, no_q;
1930 pixel *pix = (pixel *)_pix;
1931 ptrdiff_t xstride = _xstride / sizeof(pixel);
1932 ptrdiff_t ystride = _ystride / sizeof(pixel);
1934 for (j = 0; j < 2; j++) {
1935 const int tc = _tc[j] << (BIT_DEPTH - 8);
1943 for (d = 0; d < 4; d++) {
1949 delta0 = av_clip((((q0 - p0) * 4) + p1 - q1 + 4) >> 3, -tc, tc);
1951 P0 = av_clip_pixel(p0 + delta0);
1953 Q0 = av_clip_pixel(q0 - delta0);
1959 static void FUNC(hevc_h_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride,
1960 int *tc, uint8_t *no_p,
1963 FUNC(hevc_loop_filter_chroma)(pix, stride, sizeof(pixel), tc, no_p, no_q);
1966 static void FUNC(hevc_v_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride,
1967 int *tc, uint8_t *no_p,
1970 FUNC(hevc_loop_filter_chroma)(pix, sizeof(pixel), stride, tc, no_p, no_q);
1973 static void FUNC(hevc_h_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride,
1974 int *beta, int *tc, uint8_t *no_p,
1977 FUNC(hevc_loop_filter_luma)(pix, stride, sizeof(pixel),
1978 beta, tc, no_p, no_q);
1981 static void FUNC(hevc_v_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride,
1982 int *beta, int *tc, uint8_t *no_p,
1985 FUNC(hevc_loop_filter_luma)(pix, sizeof(pixel), stride,
1986 beta, tc, no_p, no_q);