1 // Copyright 2014 Google Inc. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the COPYING file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 // -----------------------------------------------------------------------------
9 //
10 // MIPS version of YUV to RGB upsampling functions.
11 //
12 // Author(s):  Djordje Pesut    (djordje.pesut@imgtec.com)
13 //             Jovan Zelincevic (jovan.zelincevic@imgtec.com)
14 
15 #include "src/dsp/dsp.h"
16 
17 #if defined(WEBP_USE_MIPS32)
18 
19 #include "src/dsp/yuv.h"
20 
21 //------------------------------------------------------------------------------
22 // simple point-sampling
23 
24 #define ROW_FUNC(FUNC_NAME, XSTEP, R, G, B, A)                                 \
25 static void FUNC_NAME(const uint8_t* y,                                        \
26                       const uint8_t* u, const uint8_t* v,                      \
27                       uint8_t* dst, int len) {                                 \
28   int i, r, g, b;                                                              \
29   int temp0, temp1, temp2, temp3, temp4;                                       \
30   for (i = 0; i < (len >> 1); i++) {                                           \
31     temp1 = MultHi(v[0], 26149);                                               \
32     temp3 = MultHi(v[0], 13320);                                               \
33     temp2 = MultHi(u[0], 6419);                                                \
34     temp4 = MultHi(u[0], 33050);                                               \
35     temp0 = MultHi(y[0], 19077);                                               \
36     temp1 -= 14234;                                                            \
37     temp3 -= 8708;                                                             \
38     temp2 += temp3;                                                            \
39     temp4 -= 17685;                                                            \
40     r = VP8Clip8(temp0 + temp1);                                               \
41     g = VP8Clip8(temp0 - temp2);                                               \
42     b = VP8Clip8(temp0 + temp4);                                               \
43     temp0 = MultHi(y[1], 19077);                                               \
44     dst[R] = r;                                                                \
45     dst[G] = g;                                                                \
46     dst[B] = b;                                                                \
47     if (A) dst[A] = 0xff;                                                      \
48     r = VP8Clip8(temp0 + temp1);                                               \
49     g = VP8Clip8(temp0 - temp2);                                               \
50     b = VP8Clip8(temp0 + temp4);                                               \
51     dst[R + XSTEP] = r;                                                        \
52     dst[G + XSTEP] = g;                                                        \
53     dst[B + XSTEP] = b;                                                        \
54     if (A) dst[A + XSTEP] = 0xff;                                              \
55     y += 2;                                                                    \
56     ++u;                                                                       \
57     ++v;                                                                       \
58     dst += 2 * XSTEP;                                                          \
59   }                                                                            \
60   if (len & 1) {                                                               \
61     temp1 = MultHi(v[0], 26149);                                               \
62     temp3 = MultHi(v[0], 13320);                                               \
63     temp2 = MultHi(u[0], 6419);                                                \
64     temp4 = MultHi(u[0], 33050);                                               \
65     temp0 = MultHi(y[0], 19077);                                               \
66     temp1 -= 14234;                                                            \
67     temp3 -= 8708;                                                             \
68     temp2 += temp3;                                                            \
69     temp4 -= 17685;                                                            \
70     r = VP8Clip8(temp0 + temp1);                                               \
71     g = VP8Clip8(temp0 - temp2);                                               \
72     b = VP8Clip8(temp0 + temp4);                                               \
73     dst[R] = r;                                                                \
74     dst[G] = g;                                                                \
75     dst[B] = b;                                                                \
76     if (A) dst[A] = 0xff;                                                      \
77   }                                                                            \
78 }
79 
80 ROW_FUNC(YuvToRgbRow_MIPS32,      3, 0, 1, 2, 0)
81 ROW_FUNC(YuvToRgbaRow_MIPS32,     4, 0, 1, 2, 3)
82 ROW_FUNC(YuvToBgrRow_MIPS32,      3, 2, 1, 0, 0)
83 ROW_FUNC(YuvToBgraRow_MIPS32,     4, 2, 1, 0, 3)
84 
85 #undef ROW_FUNC
86 
87 //------------------------------------------------------------------------------
88 // Entry point
89 
90 extern void WebPInitSamplersMIPS32(void);
91 
WebPInitSamplersMIPS32(void)92 WEBP_TSAN_IGNORE_FUNCTION void WebPInitSamplersMIPS32(void) {
93   WebPSamplers[MODE_RGB]  = YuvToRgbRow_MIPS32;
94   WebPSamplers[MODE_RGBA] = YuvToRgbaRow_MIPS32;
95   WebPSamplers[MODE_BGR]  = YuvToBgrRow_MIPS32;
96   WebPSamplers[MODE_BGRA] = YuvToBgraRow_MIPS32;
97 }
98 
99 #else  // !WEBP_USE_MIPS32
100 
101 WEBP_DSP_INIT_STUB(WebPInitSamplersMIPS32)
102 
103 #endif  // WEBP_USE_MIPS32
104