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