add_noise_msa.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2015 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 <stdlib.h>
  11. #include "./vpx_dsp_rtcd.h"
  12. #include "vpx_dsp/mips/macros_msa.h"
  13. void vpx_plane_add_noise_msa(uint8_t *start_ptr, const int8_t *noise,
  14. int blackclamp, int whiteclamp, int width,
  15. int height, int32_t pitch) {
  16. int i, j;
  17. v16u8 pos0, pos1, ref0, ref1;
  18. v16i8 black_clamp, white_clamp, both_clamp;
  19. black_clamp = __msa_fill_b(blackclamp);
  20. white_clamp = __msa_fill_b(whiteclamp);
  21. both_clamp = black_clamp + white_clamp;
  22. both_clamp = -both_clamp;
  23. for (i = 0; i < height / 2; ++i) {
  24. uint8_t *pos0_ptr = start_ptr + (2 * i) * pitch;
  25. const int8_t *ref0_ptr = noise + (rand() & 0xff);
  26. uint8_t *pos1_ptr = start_ptr + (2 * i + 1) * pitch;
  27. const int8_t *ref1_ptr = noise + (rand() & 0xff);
  28. for (j = width / 16; j--;) {
  29. pos0 = LD_UB(pos0_ptr);
  30. ref0 = LD_UB(ref0_ptr);
  31. pos1 = LD_UB(pos1_ptr);
  32. ref1 = LD_UB(ref1_ptr);
  33. pos0 = __msa_subsus_u_b(pos0, black_clamp);
  34. pos1 = __msa_subsus_u_b(pos1, black_clamp);
  35. pos0 = __msa_subsus_u_b(pos0, both_clamp);
  36. pos1 = __msa_subsus_u_b(pos1, both_clamp);
  37. pos0 = __msa_subsus_u_b(pos0, white_clamp);
  38. pos1 = __msa_subsus_u_b(pos1, white_clamp);
  39. pos0 += ref0;
  40. ST_UB(pos0, pos0_ptr);
  41. pos1 += ref1;
  42. ST_UB(pos1, pos1_ptr);
  43. pos0_ptr += 16;
  44. pos1_ptr += 16;
  45. ref0_ptr += 16;
  46. ref1_ptr += 16;
  47. }
  48. }
  49. }