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.

135 lines
3.3KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav 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. * Libav 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 Libav; 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, int 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, int 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, int 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. #if HAVE_BIGENDIAN
  71. #define B 3
  72. #define G 2
  73. #define R 1
  74. #define A 0
  75. #else
  76. #define B 0
  77. #define G 1
  78. #define R 2
  79. #define A 3
  80. #endif
  81. static void add_hfyu_left_pred_bgr32_c(uint8_t *dst, const uint8_t *src,
  82. int w, int *red, int *green,
  83. int *blue, int *alpha)
  84. {
  85. int i, r = *red, g = *green, b = *blue, a = *alpha;
  86. for (i = 0; i < w; i++) {
  87. b += src[4 * i + B];
  88. g += src[4 * i + G];
  89. r += src[4 * i + R];
  90. a += src[4 * i + A];
  91. dst[4 * i + B] = b;
  92. dst[4 * i + G] = g;
  93. dst[4 * i + R] = r;
  94. dst[4 * i + A] = a;
  95. }
  96. *red = r;
  97. *green = g;
  98. *blue = b;
  99. *alpha = a;
  100. }
  101. #undef B
  102. #undef G
  103. #undef R
  104. #undef A
  105. av_cold void ff_huffyuvdsp_init(HuffYUVDSPContext *c)
  106. {
  107. c->add_bytes = add_bytes_c;
  108. c->add_hfyu_median_pred = add_hfyu_median_pred_c;
  109. c->add_hfyu_left_pred = add_hfyu_left_pred_c;
  110. c->add_hfyu_left_pred_bgr32 = add_hfyu_left_pred_bgr32_c;
  111. if (ARCH_PPC)
  112. ff_huffyuvdsp_init_ppc(c);
  113. if (ARCH_X86)
  114. ff_huffyuvdsp_init_x86(c);
  115. }