deblock.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (c) 2016 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <assert.h>
  11. #include <stdlib.h>
  12. #include "./vpx_dsp_rtcd.h"
  13. #include "vpx/vpx_integer.h"
  14. const int16_t vpx_rv[] = {
  15. 8, 5, 2, 2, 8, 12, 4, 9, 8, 3, 0, 3, 9, 0, 0, 0, 8, 3, 14,
  16. 4, 10, 1, 11, 14, 1, 14, 9, 6, 12, 11, 8, 6, 10, 0, 0, 8, 9, 0,
  17. 3, 14, 8, 11, 13, 4, 2, 9, 0, 3, 9, 6, 1, 2, 3, 14, 13, 1, 8,
  18. 2, 9, 7, 3, 3, 1, 13, 13, 6, 6, 5, 2, 7, 11, 9, 11, 8, 7, 3,
  19. 2, 0, 13, 13, 14, 4, 12, 5, 12, 10, 8, 10, 13, 10, 4, 14, 4, 10, 0,
  20. 8, 11, 1, 13, 7, 7, 14, 6, 14, 13, 2, 13, 5, 4, 4, 0, 10, 0, 5,
  21. 13, 2, 12, 7, 11, 13, 8, 0, 4, 10, 7, 2, 7, 2, 2, 5, 3, 4, 7,
  22. 3, 3, 14, 14, 5, 9, 13, 3, 14, 3, 6, 3, 0, 11, 8, 13, 1, 13, 1,
  23. 12, 0, 10, 9, 7, 6, 2, 8, 5, 2, 13, 7, 1, 13, 14, 7, 6, 7, 9,
  24. 6, 10, 11, 7, 8, 7, 5, 14, 8, 4, 4, 0, 8, 7, 10, 0, 8, 14, 11,
  25. 3, 12, 5, 7, 14, 3, 14, 5, 2, 6, 11, 12, 12, 8, 0, 11, 13, 1, 2,
  26. 0, 5, 10, 14, 7, 8, 0, 4, 11, 0, 8, 0, 3, 10, 5, 8, 0, 11, 6,
  27. 7, 8, 10, 7, 13, 9, 2, 5, 1, 5, 10, 2, 4, 3, 5, 6, 10, 8, 9,
  28. 4, 11, 14, 0, 10, 0, 5, 13, 2, 12, 7, 11, 13, 8, 0, 4, 10, 7, 2,
  29. 7, 2, 2, 5, 3, 4, 7, 3, 3, 14, 14, 5, 9, 13, 3, 14, 3, 6, 3,
  30. 0, 11, 8, 13, 1, 13, 1, 12, 0, 10, 9, 7, 6, 2, 8, 5, 2, 13, 7,
  31. 1, 13, 14, 7, 6, 7, 9, 6, 10, 11, 7, 8, 7, 5, 14, 8, 4, 4, 0,
  32. 8, 7, 10, 0, 8, 14, 11, 3, 12, 5, 7, 14, 3, 14, 5, 2, 6, 11, 12,
  33. 12, 8, 0, 11, 13, 1, 2, 0, 5, 10, 14, 7, 8, 0, 4, 11, 0, 8, 0,
  34. 3, 10, 5, 8, 0, 11, 6, 7, 8, 10, 7, 13, 9, 2, 5, 1, 5, 10, 2,
  35. 4, 3, 5, 6, 10, 8, 9, 4, 11, 14, 3, 8, 3, 7, 8, 5, 11, 4, 12,
  36. 3, 11, 9, 14, 8, 14, 13, 4, 3, 1, 2, 14, 6, 5, 4, 4, 11, 4, 6,
  37. 2, 1, 5, 8, 8, 12, 13, 5, 14, 10, 12, 13, 0, 9, 5, 5, 11, 10, 13,
  38. 9, 10, 13,
  39. };
  40. void vpx_post_proc_down_and_across_mb_row_c(unsigned char *src,
  41. unsigned char *dst, int src_pitch,
  42. int dst_pitch, int cols,
  43. unsigned char *flimits, int size) {
  44. unsigned char *p_src, *p_dst;
  45. int row;
  46. int col;
  47. unsigned char v;
  48. unsigned char d[4];
  49. assert(size >= 8);
  50. assert(cols >= 8);
  51. #ifdef __clang_analyzer__
  52. /* older clang analyzer doesnt understand asserts, insert this until we ugrade analyzer */
  53. if (cols < 8) return;
  54. #endif
  55. for (row = 0; row < size; row++) {
  56. /* post_proc_down for one row */
  57. p_src = src;
  58. p_dst = dst;
  59. for (col = 0; col < cols; col++) {
  60. unsigned char p_above2 = p_src[col - 2 * src_pitch];
  61. unsigned char p_above1 = p_src[col - src_pitch];
  62. unsigned char p_below1 = p_src[col + src_pitch];
  63. unsigned char p_below2 = p_src[col + 2 * src_pitch];
  64. v = p_src[col];
  65. if ((abs(v - p_above2) < flimits[col]) &&
  66. (abs(v - p_above1) < flimits[col]) &&
  67. (abs(v - p_below1) < flimits[col]) &&
  68. (abs(v - p_below2) < flimits[col])) {
  69. unsigned char k1, k2, k3;
  70. k1 = (p_above2 + p_above1 + 1) >> 1;
  71. k2 = (p_below2 + p_below1 + 1) >> 1;
  72. k3 = (k1 + k2 + 1) >> 1;
  73. v = (k3 + v + 1) >> 1;
  74. }
  75. p_dst[col] = v;
  76. }
  77. /* now post_proc_across */
  78. p_src = dst;
  79. p_dst = dst;
  80. p_src[-2] = p_src[-1] = p_src[0];
  81. p_src[cols] = p_src[cols + 1] = p_src[cols - 1];
  82. for (col = 0; col < cols; col++) {
  83. v = p_src[col];
  84. if ((abs(v - p_src[col - 2]) < flimits[col]) &&
  85. (abs(v - p_src[col - 1]) < flimits[col]) &&
  86. (abs(v - p_src[col + 1]) < flimits[col]) &&
  87. (abs(v - p_src[col + 2]) < flimits[col])) {
  88. unsigned char k1, k2, k3;
  89. k1 = (p_src[col - 2] + p_src[col - 1] + 1) >> 1;
  90. k2 = (p_src[col + 2] + p_src[col + 1] + 1) >> 1;
  91. k3 = (k1 + k2 + 1) >> 1;
  92. v = (k3 + v + 1) >> 1;
  93. }
  94. d[col & 3] = v;
  95. if (col >= 2) p_dst[col - 2] = d[(col - 2) & 3];
  96. }
  97. /* handle the last two pixels */
  98. p_dst[col - 2] = d[(col - 2) & 3];
  99. p_dst[col - 1] = d[(col - 1) & 3];
  100. /* next row */
  101. src += src_pitch;
  102. dst += dst_pitch;
  103. }
  104. }
  105. void vpx_mbpost_proc_across_ip_c(unsigned char *src, int pitch, int rows,
  106. int cols, int flimit) {
  107. int r, c, i;
  108. unsigned char *s = src;
  109. unsigned char d[16];
  110. for (r = 0; r < rows; r++) {
  111. int sumsq = 16;
  112. int sum = 0;
  113. for (i = -8; i < 0; i++) s[i] = s[0];
  114. /* 17 avoids valgrind warning - we buffer values in c in d
  115. * and only write them when we've read 8 ahead...
  116. */
  117. for (i = 0; i < 17; i++) s[i + cols] = s[cols - 1];
  118. for (i = -8; i <= 6; i++) {
  119. sumsq += s[i] * s[i];
  120. sum += s[i];
  121. d[i + 8] = 0;
  122. }
  123. for (c = 0; c < cols + 8; c++) {
  124. int x = s[c + 7] - s[c - 8];
  125. int y = s[c + 7] + s[c - 8];
  126. sum += x;
  127. sumsq += x * y;
  128. d[c & 15] = s[c];
  129. if (sumsq * 15 - sum * sum < flimit) {
  130. d[c & 15] = (8 + sum + s[c]) >> 4;
  131. }
  132. s[c - 8] = d[(c - 8) & 15];
  133. }
  134. s += pitch;
  135. }
  136. }
  137. void vpx_mbpost_proc_down_c(unsigned char *dst, int pitch, int rows, int cols,
  138. int flimit) {
  139. int r, c, i;
  140. for (c = 0; c < cols; c++) {
  141. unsigned char *s = &dst[c];
  142. int sumsq = 0;
  143. int sum = 0;
  144. unsigned char d[16];
  145. for (i = -8; i < 0; i++) s[i * pitch] = s[0];
  146. /* 17 avoids valgrind warning - we buffer values in c in d
  147. * and only write them when we've read 8 ahead...
  148. */
  149. for (i = 0; i < 17; i++) s[(i + rows) * pitch] = s[(rows - 1) * pitch];
  150. for (i = -8; i <= 6; i++) {
  151. sumsq += s[i * pitch] * s[i * pitch];
  152. sum += s[i * pitch];
  153. }
  154. for (r = 0; r < rows + 8; r++) {
  155. sumsq += s[7 * pitch] * s[7 * pitch] - s[-8 * pitch] * s[-8 * pitch];
  156. sum += s[7 * pitch] - s[-8 * pitch];
  157. d[r & 15] = s[0];
  158. if (sumsq * 15 - sum * sum < flimit) {
  159. d[r & 15] = (vpx_rv[(r & 127) + (c & 7)] + sum + s[0]) >> 4;
  160. }
  161. if (r >= 8) s[-8 * pitch] = d[(r - 8) & 15];
  162. s += pitch;
  163. }
  164. }
  165. }