Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: third_party/libwebp/dsp/upsampling_mips_dsp_r2.c

Issue 1546003002: libwebp: update to 0.5.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libwebp/dsp/upsampling.c ('k') | third_party/libwebp/dsp/upsampling_neon.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 Google Inc. All Rights Reserved. 1 // Copyright 2014 Google Inc. All Rights Reserved.
2 // 2 //
3 // Use of this source code is governed by a BSD-style license 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 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 5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may 6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree. 7 // be found in the AUTHORS file in the root of the source tree.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 // 9 //
10 // YUV to RGB upsampling functions. 10 // YUV to RGB upsampling functions.
11 // 11 //
12 // Author: somnath@google.com (Somnath Banerjee) 12 // Author(s): Branimir Vasic (branimir.vasic@imgtec.com)
13 // Djordje Pesut (djordje.pesut@imgtec.com)
13 14
14 #include "./dsp.h" 15 #include "./dsp.h"
16
17 // Code is disabled for now, in favor of the plain-C version
18 // TODO(djordje.pesut): adapt the code to reflect the C-version.
19 #if 0 // defined(WEBP_USE_MIPS_DSP_R2)
20
21 #include <assert.h>
15 #include "./yuv.h" 22 #include "./yuv.h"
16 23
17 #include <assert.h> 24 #if !defined(WEBP_YUV_USE_TABLE)
25
26 #define YUV_TO_RGB(Y, U, V, R, G, B) do { \
27 const int t1 = kYScale * Y; \
28 const int t2 = kVToG * V; \
29 R = kVToR * V; \
30 G = kUToG * U; \
31 B = kUToB * U; \
32 R = t1 + R; \
33 G = t1 - G; \
34 B = t1 + B; \
35 R = R + kRCst; \
36 G = G - t2 + kGCst; \
37 B = B + kBCst; \
38 __asm__ volatile ( \
39 "shll_s.w %[" #R "], %[" #R "], 9 \n\t" \
40 "shll_s.w %[" #G "], %[" #G "], 9 \n\t" \
41 "shll_s.w %[" #B "], %[" #B "], 9 \n\t" \
42 "precrqu_s.qb.ph %[" #R "], %[" #R "], $zero \n\t" \
43 "precrqu_s.qb.ph %[" #G "], %[" #G "], $zero \n\t" \
44 "precrqu_s.qb.ph %[" #B "], %[" #B "], $zero \n\t" \
45 "srl %[" #R "], %[" #R "], 24 \n\t" \
46 "srl %[" #G "], %[" #G "], 24 \n\t" \
47 "srl %[" #B "], %[" #B "], 24 \n\t" \
48 : [R]"+r"(R), [G]"+r"(G), [B]"+r"(B) \
49 : \
50 ); \
51 } while (0)
52
53 static WEBP_INLINE void YuvToRgb(int y, int u, int v, uint8_t* const rgb) {
54 int r, g, b;
55 YUV_TO_RGB(y, u, v, r, g, b);
56 rgb[0] = r;
57 rgb[1] = g;
58 rgb[2] = b;
59 }
60 static WEBP_INLINE void YuvToBgr(int y, int u, int v, uint8_t* const bgr) {
61 int r, g, b;
62 YUV_TO_RGB(y, u, v, r, g, b);
63 bgr[0] = b;
64 bgr[1] = g;
65 bgr[2] = r;
66 }
67 static WEBP_INLINE void YuvToRgb565(int y, int u, int v, uint8_t* const rgb) {
68 int r, g, b;
69 YUV_TO_RGB(y, u, v, r, g, b);
70 {
71 const int rg = (r & 0xf8) | (g >> 5);
72 const int gb = ((g << 3) & 0xe0) | (b >> 3);
73 #ifdef WEBP_SWAP_16BIT_CSP
74 rgb[0] = gb;
75 rgb[1] = rg;
76 #else
77 rgb[0] = rg;
78 rgb[1] = gb;
79 #endif
80 }
81 }
82 static WEBP_INLINE void YuvToRgba4444(int y, int u, int v,
83 uint8_t* const argb) {
84 int r, g, b;
85 YUV_TO_RGB(y, u, v, r, g, b);
86 {
87 const int rg = (r & 0xf0) | (g >> 4);
88 const int ba = (b & 0xf0) | 0x0f; // overwrite the lower 4 bits
89 #ifdef WEBP_SWAP_16BIT_CSP
90 argb[0] = ba;
91 argb[1] = rg;
92 #else
93 argb[0] = rg;
94 argb[1] = ba;
95 #endif
96 }
97 }
98 #endif // WEBP_YUV_USE_TABLE
99
100 //-----------------------------------------------------------------------------
101 // Alpha handling variants
102
103 static WEBP_INLINE void YuvToArgb(uint8_t y, uint8_t u, uint8_t v,
104 uint8_t* const argb) {
105 int r, g, b;
106 YUV_TO_RGB(y, u, v, r, g, b);
107 argb[0] = 0xff;
108 argb[1] = r;
109 argb[2] = g;
110 argb[3] = b;
111 }
112 static WEBP_INLINE void YuvToBgra(uint8_t y, uint8_t u, uint8_t v,
113 uint8_t* const bgra) {
114 int r, g, b;
115 YUV_TO_RGB(y, u, v, r, g, b);
116 bgra[0] = b;
117 bgra[1] = g;
118 bgra[2] = r;
119 bgra[3] = 0xff;
120 }
121 static WEBP_INLINE void YuvToRgba(uint8_t y, uint8_t u, uint8_t v,
122 uint8_t* const rgba) {
123 int r, g, b;
124 YUV_TO_RGB(y, u, v, r, g, b);
125 rgba[0] = r;
126 rgba[1] = g;
127 rgba[2] = b;
128 rgba[3] = 0xff;
129 }
18 130
19 //------------------------------------------------------------------------------ 131 //------------------------------------------------------------------------------
20 // Fancy upsampler 132 // Fancy upsampler
21 133
22 #ifdef FANCY_UPSAMPLING 134 #ifdef FANCY_UPSAMPLING
23 135
24 // Fancy upsampling functions to convert YUV to RGB
25 WebPUpsampleLinePairFunc WebPUpsamplers[MODE_LAST];
26
27 // Given samples laid out in a square as: 136 // Given samples laid out in a square as:
28 // [a b] 137 // [a b]
29 // [c d] 138 // [c d]
30 // we interpolate u/v as: 139 // we interpolate u/v as:
31 // ([9*a + 3*b + 3*c + d 3*a + 9*b + 3*c + d] + [8 8]) / 16 140 // ([9*a + 3*b + 3*c + d 3*a + 9*b + 3*c + d] + [8 8]) / 16
32 // ([3*a + b + 9*c + 3*d a + 3*b + 3*c + 9*d] [8 8]) / 16 141 // ([3*a + b + 9*c + 3*d a + 3*b + 3*c + 9*d] [8 8]) / 16
33 142
34 // We process u and v together stashed into 32bit (16bit each). 143 // We process u and v together stashed into 32bit (16bit each).
35 #define LOAD_UV(u, v) ((u) | ((v) << 16)) 144 #define LOAD_UV(u, v) ((u) | ((v) << 16))
36 145
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } \ 195 } \
87 if (bottom_y != NULL) { \ 196 if (bottom_y != NULL) { \
88 const uint32_t uv0 = (3 * l_uv + tl_uv + 0x00020002u) >> 2; \ 197 const uint32_t uv0 = (3 * l_uv + tl_uv + 0x00020002u) >> 2; \
89 FUNC(bottom_y[len - 1], uv0 & 0xff, (uv0 >> 16), \ 198 FUNC(bottom_y[len - 1], uv0 & 0xff, (uv0 >> 16), \
90 bottom_dst + (len - 1) * XSTEP); \ 199 bottom_dst + (len - 1) * XSTEP); \
91 } \ 200 } \
92 } \ 201 } \
93 } 202 }
94 203
95 // All variants implemented. 204 // All variants implemented.
96 UPSAMPLE_FUNC(UpsampleRgbLinePair, VP8YuvToRgb, 3) 205 UPSAMPLE_FUNC(UpsampleRgbLinePair, YuvToRgb, 3)
97 UPSAMPLE_FUNC(UpsampleBgrLinePair, VP8YuvToBgr, 3) 206 UPSAMPLE_FUNC(UpsampleBgrLinePair, YuvToBgr, 3)
98 UPSAMPLE_FUNC(UpsampleRgbaLinePair, VP8YuvToRgba, 4) 207 UPSAMPLE_FUNC(UpsampleRgbaLinePair, YuvToRgba, 4)
99 UPSAMPLE_FUNC(UpsampleBgraLinePair, VP8YuvToBgra, 4) 208 UPSAMPLE_FUNC(UpsampleBgraLinePair, YuvToBgra, 4)
100 UPSAMPLE_FUNC(UpsampleArgbLinePair, VP8YuvToArgb, 4) 209 UPSAMPLE_FUNC(UpsampleArgbLinePair, YuvToArgb, 4)
101 UPSAMPLE_FUNC(UpsampleRgba4444LinePair, VP8YuvToRgba4444, 2) 210 UPSAMPLE_FUNC(UpsampleRgba4444LinePair, YuvToRgba4444, 2)
102 UPSAMPLE_FUNC(UpsampleRgb565LinePair, VP8YuvToRgb565, 2) 211 UPSAMPLE_FUNC(UpsampleRgb565LinePair, YuvToRgb565, 2)
103 212
104 #undef LOAD_UV 213 #undef LOAD_UV
105 #undef UPSAMPLE_FUNC 214 #undef UPSAMPLE_FUNC
106 215
107 #endif // FANCY_UPSAMPLING 216 //------------------------------------------------------------------------------
217 // Entry point
108 218
109 //------------------------------------------------------------------------------ 219 extern void WebPInitUpsamplersMIPSdspR2(void);
110 220
111 #if !defined(FANCY_UPSAMPLING) 221 WEBP_TSAN_IGNORE_FUNCTION void WebPInitUpsamplersMIPSdspR2(void) {
112 #define DUAL_SAMPLE_FUNC(FUNC_NAME, FUNC) \ 222 WebPUpsamplers[MODE_RGB] = UpsampleRgbLinePair;
113 static void FUNC_NAME(const uint8_t* top_y, const uint8_t* bot_y, \ 223 WebPUpsamplers[MODE_RGBA] = UpsampleRgbaLinePair;
114 const uint8_t* top_u, const uint8_t* top_v, \ 224 WebPUpsamplers[MODE_BGR] = UpsampleBgrLinePair;
115 const uint8_t* bot_u, const uint8_t* bot_v, \ 225 WebPUpsamplers[MODE_BGRA] = UpsampleBgraLinePair;
116 uint8_t* top_dst, uint8_t* bot_dst, int len) { \ 226 WebPUpsamplers[MODE_ARGB] = UpsampleArgbLinePair;
117 const int half_len = len >> 1; \ 227 WebPUpsamplers[MODE_RGBA_4444] = UpsampleRgba4444LinePair;
118 int x; \ 228 WebPUpsamplers[MODE_RGB_565] = UpsampleRgb565LinePair;
119 assert(top_dst != NULL); \ 229 WebPUpsamplers[MODE_rgbA] = UpsampleRgbaLinePair;
120 { \ 230 WebPUpsamplers[MODE_bgrA] = UpsampleBgraLinePair;
121 for (x = 0; x < half_len; ++x) { \ 231 WebPUpsamplers[MODE_Argb] = UpsampleArgbLinePair;
122 FUNC(top_y[2 * x + 0], top_u[x], top_v[x], top_dst + 8 * x + 0); \ 232 WebPUpsamplers[MODE_rgbA_4444] = UpsampleRgba4444LinePair;
123 FUNC(top_y[2 * x + 1], top_u[x], top_v[x], top_dst + 8 * x + 4); \
124 } \
125 if (len & 1) FUNC(top_y[2 * x + 0], top_u[x], top_v[x], top_dst + 8 * x); \
126 } \
127 if (bot_dst != NULL) { \
128 for (x = 0; x < half_len; ++x) { \
129 FUNC(bot_y[2 * x + 0], bot_u[x], bot_v[x], bot_dst + 8 * x + 0); \
130 FUNC(bot_y[2 * x + 1], bot_u[x], bot_v[x], bot_dst + 8 * x + 4); \
131 } \
132 if (len & 1) FUNC(bot_y[2 * x + 0], bot_u[x], bot_v[x], bot_dst + 8 * x); \
133 } \
134 } 233 }
135 234
136 DUAL_SAMPLE_FUNC(DualLineSamplerBGRA, VP8YuvToBgra) 235 #endif // FANCY_UPSAMPLING
137 DUAL_SAMPLE_FUNC(DualLineSamplerARGB, VP8YuvToArgb)
138 #undef DUAL_SAMPLE_FUNC
139
140 #endif // !FANCY_UPSAMPLING
141
142 WebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last) {
143 WebPInitUpsamplers();
144 VP8YUVInit();
145 #ifdef FANCY_UPSAMPLING
146 return WebPUpsamplers[alpha_is_last ? MODE_BGRA : MODE_ARGB];
147 #else
148 return (alpha_is_last ? DualLineSamplerBGRA : DualLineSamplerARGB);
149 #endif
150 }
151 236
152 //------------------------------------------------------------------------------ 237 //------------------------------------------------------------------------------
153 // YUV444 converter 238 // YUV444 converter
154 239
155 #define YUV444_FUNC(FUNC_NAME, FUNC, XSTEP) \ 240 #define YUV444_FUNC(FUNC_NAME, FUNC, XSTEP) \
156 static void FUNC_NAME(const uint8_t* y, const uint8_t* u, const uint8_t* v, \ 241 static void FUNC_NAME(const uint8_t* y, const uint8_t* u, const uint8_t* v, \
157 uint8_t* dst, int len) { \ 242 uint8_t* dst, int len) { \
158 int i; \ 243 int i; \
159 for (i = 0; i < len; ++i) FUNC(y[i], u[i], v[i], &dst[i * XSTEP]); \ 244 for (i = 0; i < len; ++i) FUNC(y[i], u[i], v[i], &dst[i * XSTEP]); \
160 } 245 }
161 246
162 YUV444_FUNC(Yuv444ToRgb, VP8YuvToRgb, 3) 247 YUV444_FUNC(Yuv444ToRgb, YuvToRgb, 3)
163 YUV444_FUNC(Yuv444ToBgr, VP8YuvToBgr, 3) 248 YUV444_FUNC(Yuv444ToBgr, YuvToBgr, 3)
164 YUV444_FUNC(Yuv444ToRgba, VP8YuvToRgba, 4) 249 YUV444_FUNC(Yuv444ToRgba, YuvToRgba, 4)
165 YUV444_FUNC(Yuv444ToBgra, VP8YuvToBgra, 4) 250 YUV444_FUNC(Yuv444ToBgra, YuvToBgra, 4)
166 YUV444_FUNC(Yuv444ToArgb, VP8YuvToArgb, 4) 251 YUV444_FUNC(Yuv444ToArgb, YuvToArgb, 4)
167 YUV444_FUNC(Yuv444ToRgba4444, VP8YuvToRgba4444, 2) 252 YUV444_FUNC(Yuv444ToRgba4444, YuvToRgba4444, 2)
168 YUV444_FUNC(Yuv444ToRgb565, VP8YuvToRgb565, 2) 253 YUV444_FUNC(Yuv444ToRgb565, YuvToRgb565, 2)
169 254
170 #undef YUV444_FUNC 255 #undef YUV444_FUNC
171 256
172 const WebPYUV444Converter WebPYUV444Converters[MODE_LAST] = { 257 //------------------------------------------------------------------------------
173 Yuv444ToRgb, // MODE_RGB 258 // Entry point
174 Yuv444ToRgba, // MODE_RGBA
175 Yuv444ToBgr, // MODE_BGR
176 Yuv444ToBgra, // MODE_BGRA
177 Yuv444ToArgb, // MODE_ARGB
178 Yuv444ToRgba4444, // MODE_RGBA_4444
179 Yuv444ToRgb565, // MODE_RGB_565
180 Yuv444ToRgba, // MODE_rgbA
181 Yuv444ToBgra, // MODE_bgrA
182 Yuv444ToArgb, // MODE_Argb
183 Yuv444ToRgba4444 // MODE_rgbA_4444
184 };
185 259
186 //------------------------------------------------------------------------------ 260 extern void WebPInitYUV444ConvertersMIPSdspR2(void);
187 // Main calls
188 261
189 extern void WebPInitUpsamplersSSE2(void); 262 WEBP_TSAN_IGNORE_FUNCTION void WebPInitYUV444ConvertersMIPSdspR2(void) {
190 extern void WebPInitUpsamplersNEON(void); 263 WebPYUV444Converters[MODE_RGB] = Yuv444ToRgb;
191 264 WebPYUV444Converters[MODE_RGBA] = Yuv444ToRgba;
192 static volatile VP8CPUInfo upsampling_last_cpuinfo_used2 = 265 WebPYUV444Converters[MODE_BGR] = Yuv444ToBgr;
193 (VP8CPUInfo)&upsampling_last_cpuinfo_used2; 266 WebPYUV444Converters[MODE_BGRA] = Yuv444ToBgra;
194 267 WebPYUV444Converters[MODE_ARGB] = Yuv444ToArgb;
195 void WebPInitUpsamplers(void) { 268 WebPYUV444Converters[MODE_RGBA_4444] = Yuv444ToRgba4444;
196 if (upsampling_last_cpuinfo_used2 == VP8GetCPUInfo) return; 269 WebPYUV444Converters[MODE_RGB_565] = Yuv444ToRgb565;
197 270 WebPYUV444Converters[MODE_rgbA] = Yuv444ToRgba;
198 #ifdef FANCY_UPSAMPLING 271 WebPYUV444Converters[MODE_bgrA] = Yuv444ToBgra;
199 WebPUpsamplers[MODE_RGB] = UpsampleRgbLinePair; 272 WebPYUV444Converters[MODE_Argb] = Yuv444ToArgb;
200 WebPUpsamplers[MODE_RGBA] = UpsampleRgbaLinePair; 273 WebPYUV444Converters[MODE_rgbA_4444] = Yuv444ToRgba4444;
201 WebPUpsamplers[MODE_BGR] = UpsampleBgrLinePair;
202 WebPUpsamplers[MODE_BGRA] = UpsampleBgraLinePair;
203 WebPUpsamplers[MODE_ARGB] = UpsampleArgbLinePair;
204 WebPUpsamplers[MODE_RGBA_4444] = UpsampleRgba4444LinePair;
205 WebPUpsamplers[MODE_RGB_565] = UpsampleRgb565LinePair;
206 WebPUpsamplers[MODE_rgbA] = UpsampleRgbaLinePair;
207 WebPUpsamplers[MODE_bgrA] = UpsampleBgraLinePair;
208 WebPUpsamplers[MODE_Argb] = UpsampleArgbLinePair;
209 WebPUpsamplers[MODE_rgbA_4444] = UpsampleRgba4444LinePair;
210
211 // If defined, use CPUInfo() to overwrite some pointers with faster versions.
212 if (VP8GetCPUInfo != NULL) {
213 #if defined(WEBP_USE_SSE2)
214 if (VP8GetCPUInfo(kSSE2)) {
215 WebPInitUpsamplersSSE2();
216 }
217 #endif
218 #if defined(WEBP_USE_NEON)
219 if (VP8GetCPUInfo(kNEON)) {
220 WebPInitUpsamplersNEON();
221 }
222 #endif
223 }
224 #endif // FANCY_UPSAMPLING
225 upsampling_last_cpuinfo_used2 = VP8GetCPUInfo;
226 } 274 }
227 275
228 //------------------------------------------------------------------------------ 276 #else // !WEBP_USE_MIPS_DSP_R2
277
278 WEBP_DSP_INIT_STUB(WebPInitYUV444ConvertersMIPSdspR2)
279
280 #endif // WEBP_USE_MIPS_DSP_R2
281
282 #if 1 // !(defined(FANCY_UPSAMPLING) && defined(WEBP_USE_MIPS_DSP_R2))
283 WEBP_DSP_INIT_STUB(WebPInitUpsamplersMIPSdspR2)
284 #endif
OLDNEW
« no previous file with comments | « third_party/libwebp/dsp/upsampling.c ('k') | third_party/libwebp/dsp/upsampling_neon.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698