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.

85 lines
2.7KB

  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 "config.h"
  19. #include "libavutil/attributes.h"
  20. #include "huffyuvencdsp.h"
  21. #include "mathops.h"
  22. // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
  23. #define pb_7f (~0UL / 255 * 0x7f)
  24. #define pb_80 (~0UL / 255 * 0x80)
  25. static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
  26. {
  27. long i;
  28. #if !HAVE_FAST_UNALIGNED
  29. if ((long) src2 & (sizeof(long) - 1)) {
  30. for (i = 0; i + 7 < w; i += 8) {
  31. dst[i + 0] = src1[i + 0] - src2[i + 0];
  32. dst[i + 1] = src1[i + 1] - src2[i + 1];
  33. dst[i + 2] = src1[i + 2] - src2[i + 2];
  34. dst[i + 3] = src1[i + 3] - src2[i + 3];
  35. dst[i + 4] = src1[i + 4] - src2[i + 4];
  36. dst[i + 5] = src1[i + 5] - src2[i + 5];
  37. dst[i + 6] = src1[i + 6] - src2[i + 6];
  38. dst[i + 7] = src1[i + 7] - src2[i + 7];
  39. }
  40. } else
  41. #endif
  42. for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) {
  43. long a = *(long *) (src1 + i);
  44. long b = *(long *) (src2 + i);
  45. *(long *) (dst + i) = ((a | pb_80) - (b & pb_7f)) ^
  46. ((a ^ b ^ pb_80) & pb_80);
  47. }
  48. for (; i < w; i++)
  49. dst[i + 0] = src1[i + 0] - src2[i + 0];
  50. }
  51. static void sub_hfyu_median_pred_c(uint8_t *dst, const uint8_t *src1,
  52. const uint8_t *src2, int w,
  53. int *left, int *left_top)
  54. {
  55. int i;
  56. uint8_t l, lt;
  57. l = *left;
  58. lt = *left_top;
  59. for (i = 0; i < w; i++) {
  60. const int pred = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF);
  61. lt = src1[i];
  62. l = src2[i];
  63. dst[i] = l - pred;
  64. }
  65. *left = l;
  66. *left_top = lt;
  67. }
  68. av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c)
  69. {
  70. c->diff_bytes = diff_bytes_c;
  71. c->sub_hfyu_median_pred = sub_hfyu_median_pred_c;
  72. if (ARCH_X86)
  73. ff_huffyuvencdsp_init_x86(c);
  74. }