You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.1KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <stdint.h>
  19. #include "config.h"
  20. #include "libavutil/attributes.h"
  21. #include "mathops.h"
  22. #include "huffyuvdsp.h"
  23. // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
  24. #define pb_7f (~0UL / 255 * 0x7f)
  25. #define pb_80 (~0UL / 255 * 0x80)
  26. static void add_bytes_c(uint8_t *dst, uint8_t *src, intptr_t w)
  27. {
  28. long i;
  29. for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) {
  30. long a = *(long *) (src + i);
  31. long b = *(long *) (dst + i);
  32. *(long *) (dst + i) = ((a & pb_7f) + (b & pb_7f)) ^ ((a ^ b) & pb_80);
  33. }
  34. for (; i < w; i++)
  35. dst[i + 0] += src[i + 0];
  36. }
  37. static void add_hfyu_median_pred_c(uint8_t *dst, const uint8_t *src1,
  38. const uint8_t *diff, intptr_t w,
  39. int *left, int *left_top)
  40. {
  41. int i;
  42. uint8_t l, lt;
  43. l = *left;
  44. lt = *left_top;
  45. for (i = 0; i < w; i++) {
  46. l = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF) + diff[i];
  47. lt = src1[i];
  48. dst[i] = l;
  49. }
  50. *left = l;
  51. *left_top = lt;
  52. }
  53. static int add_hfyu_left_pred_c(uint8_t *dst, const uint8_t *src, intptr_t w,
  54. int acc)
  55. {
  56. int i;
  57. for (i = 0; i < w - 1; i++) {
  58. acc += src[i];
  59. dst[i] = acc;
  60. i++;
  61. acc += src[i];
  62. dst[i] = acc;
  63. }
  64. for (; i < w; i++) {
  65. acc += src[i];
  66. dst[i] = acc;
  67. }
  68. return acc;
  69. }
  70. static void add_hfyu_left_pred_bgr32_c(uint8_t *dst, const uint8_t *src,
  71. intptr_t w, uint8_t *left)
  72. {
  73. int i;
  74. uint8_t r = left[R], g = left[G], b = left[B], a = left[A];
  75. for (i = 0; i < w; i++) {
  76. b += src[4 * i + B];
  77. g += src[4 * i + G];
  78. r += src[4 * i + R];
  79. a += src[4 * i + A];
  80. dst[4 * i + B] = b;
  81. dst[4 * i + G] = g;
  82. dst[4 * i + R] = r;
  83. dst[4 * i + A] = a;
  84. }
  85. left[B] = b;
  86. left[G] = g;
  87. left[R] = r;
  88. left[A] = a;
  89. }
  90. av_cold void ff_huffyuvdsp_init(HuffYUVDSPContext *c)
  91. {
  92. c->add_bytes = add_bytes_c;
  93. c->add_hfyu_median_pred = add_hfyu_median_pred_c;
  94. c->add_hfyu_left_pred = add_hfyu_left_pred_c;
  95. c->add_hfyu_left_pred_bgr32 = add_hfyu_left_pred_bgr32_c;
  96. if (ARCH_X86)
  97. ff_huffyuvdsp_init_x86(c);
  98. }