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.

92 lines
2.7KB

  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. // 0x00010001 or 0x0001000100010001 or whatever, depending on the cpu's native arithmetic size
  24. #define pw_1 (ULONG_MAX / UINT16_MAX)
  25. static void add_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, int w){
  26. long i;
  27. unsigned long pw_lsb = (mask >> 1) * pw_1;
  28. unsigned long pw_msb = pw_lsb + pw_1;
  29. for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) {
  30. long a = *(long*)(src+i);
  31. long b = *(long*)(dst+i);
  32. *(long*)(dst+i) = ((a&pw_lsb) + (b&pw_lsb)) ^ ((a^b)&pw_msb);
  33. }
  34. for(; i<w; i++)
  35. dst[i] = (dst[i] + src[i]) & mask;
  36. }
  37. static void add_hfyu_median_pred_int16_c(uint16_t *dst, const uint16_t *src, const uint16_t *diff, unsigned mask, int w, int *left, int *left_top){
  38. int i;
  39. uint16_t l, lt;
  40. l = *left;
  41. lt = *left_top;
  42. for(i=0; i<w; i++){
  43. l = (mid_pred(l, src[i], (l + src[i] - lt) & mask) + diff[i]) & mask;
  44. lt = src[i];
  45. dst[i] = l;
  46. }
  47. *left = l;
  48. *left_top = lt;
  49. }
  50. static void add_hfyu_left_pred_bgr32_c(uint8_t *dst, const uint8_t *src,
  51. intptr_t w, uint8_t *left)
  52. {
  53. int i;
  54. uint8_t r = left[R], g = left[G], b = left[B], a = left[A];
  55. for (i = 0; i < w; i++) {
  56. b += src[4 * i + B];
  57. g += src[4 * i + G];
  58. r += src[4 * i + R];
  59. a += src[4 * i + A];
  60. dst[4 * i + B] = b;
  61. dst[4 * i + G] = g;
  62. dst[4 * i + R] = r;
  63. dst[4 * i + A] = a;
  64. }
  65. left[B] = b;
  66. left[G] = g;
  67. left[R] = r;
  68. left[A] = a;
  69. }
  70. av_cold void ff_huffyuvdsp_init(HuffYUVDSPContext *c, enum AVPixelFormat pix_fmt)
  71. {
  72. c->add_int16 = add_int16_c;
  73. c->add_hfyu_median_pred_int16 = add_hfyu_median_pred_int16_c;
  74. c->add_hfyu_left_pred_bgr32 = add_hfyu_left_pred_bgr32_c;
  75. if (ARCH_X86)
  76. ff_huffyuvdsp_init_x86(c, pix_fmt);
  77. }