OLD | NEW |
1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 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 // NEON version of YUV to RGB upsampling functions. | 10 // NEON version of YUV to RGB upsampling functions. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 memcpy(r2, (bb), (num_pixels)); \ | 82 memcpy(r2, (bb), (num_pixels)); \ |
83 /* replicate last byte */ \ | 83 /* replicate last byte */ \ |
84 memset(r1 + (num_pixels), r1[(num_pixels) - 1], 9 - (num_pixels)); \ | 84 memset(r1 + (num_pixels), r1[(num_pixels) - 1], 9 - (num_pixels)); \ |
85 memset(r2 + (num_pixels), r2[(num_pixels) - 1], 9 - (num_pixels)); \ | 85 memset(r2 + (num_pixels), r2[(num_pixels) - 1], 9 - (num_pixels)); \ |
86 Upsample16Pixels(r1, r2, out); \ | 86 Upsample16Pixels(r1, r2, out); \ |
87 } | 87 } |
88 | 88 |
89 //----------------------------------------------------------------------------- | 89 //----------------------------------------------------------------------------- |
90 // YUV->RGB conversion | 90 // YUV->RGB conversion |
91 | 91 |
92 static const int16_t kCoeffs[4] = { kYScale, kVToR, kUToG, kVToG }; | 92 // note: we represent the 33050 large constant as 32768 + 282 |
| 93 static const int16_t kCoeffs1[4] = { 19077, 26149, 6419, 13320 }; |
93 | 94 |
94 #define v255 vdup_n_u8(255) | 95 #define v255 vdup_n_u8(255) |
| 96 #define v_0x0f vdup_n_u8(15) |
95 | 97 |
96 #define STORE_Rgb(out, r, g, b) do { \ | 98 #define STORE_Rgb(out, r, g, b) do { \ |
97 uint8x8x3_t r_g_b; \ | 99 uint8x8x3_t r_g_b; \ |
98 INIT_VECTOR3(r_g_b, r, g, b); \ | 100 INIT_VECTOR3(r_g_b, r, g, b); \ |
99 vst3_u8(out, r_g_b); \ | 101 vst3_u8(out, r_g_b); \ |
100 } while (0) | 102 } while (0) |
101 | 103 |
102 #define STORE_Bgr(out, r, g, b) do { \ | 104 #define STORE_Bgr(out, r, g, b) do { \ |
103 uint8x8x3_t b_g_r; \ | 105 uint8x8x3_t b_g_r; \ |
104 INIT_VECTOR3(b_g_r, b, g, r); \ | 106 INIT_VECTOR3(b_g_r, b, g, r); \ |
105 vst3_u8(out, b_g_r); \ | 107 vst3_u8(out, b_g_r); \ |
106 } while (0) | 108 } while (0) |
107 | 109 |
108 #define STORE_Rgba(out, r, g, b) do { \ | 110 #define STORE_Rgba(out, r, g, b) do { \ |
109 uint8x8x4_t r_g_b_v255; \ | 111 uint8x8x4_t r_g_b_v255; \ |
110 INIT_VECTOR4(r_g_b_v255, r, g, b, v255); \ | 112 INIT_VECTOR4(r_g_b_v255, r, g, b, v255); \ |
111 vst4_u8(out, r_g_b_v255); \ | 113 vst4_u8(out, r_g_b_v255); \ |
112 } while (0) | 114 } while (0) |
113 | 115 |
114 #define STORE_Bgra(out, r, g, b) do { \ | 116 #define STORE_Bgra(out, r, g, b) do { \ |
115 uint8x8x4_t b_g_r_v255; \ | 117 uint8x8x4_t b_g_r_v255; \ |
116 INIT_VECTOR4(b_g_r_v255, b, g, r, v255); \ | 118 INIT_VECTOR4(b_g_r_v255, b, g, r, v255); \ |
117 vst4_u8(out, b_g_r_v255); \ | 119 vst4_u8(out, b_g_r_v255); \ |
118 } while (0) | 120 } while (0) |
119 | 121 |
120 #define CONVERT8(FMT, XSTEP, N, src_y, src_uv, out, cur_x) { \ | 122 #define STORE_Argb(out, r, g, b) do { \ |
| 123 uint8x8x4_t v255_r_g_b; \ |
| 124 INIT_VECTOR4(v255_r_g_b, v255, r, g, b); \ |
| 125 vst4_u8(out, v255_r_g_b); \ |
| 126 } while (0) |
| 127 |
| 128 #if !defined(WEBP_SWAP_16BIT_CSP) |
| 129 #define ZIP_U8(lo, hi) vzip_u8((lo), (hi)) |
| 130 #else |
| 131 #define ZIP_U8(lo, hi) vzip_u8((hi), (lo)) |
| 132 #endif |
| 133 |
| 134 #define STORE_Rgba4444(out, r, g, b) do { \ |
| 135 const uint8x8_t r1 = vshl_n_u8(vshr_n_u8(r, 4), 4); /* 4bits */ \ |
| 136 const uint8x8_t g1 = vshr_n_u8(g, 4); \ |
| 137 const uint8x8_t ba = vorr_u8(b, v_0x0f); \ |
| 138 const uint8x8_t rg = vorr_u8(r1, g1); \ |
| 139 const uint8x8x2_t rgba4444 = ZIP_U8(rg, ba); \ |
| 140 vst1q_u8(out, vcombine_u8(rgba4444.val[0], rgba4444.val[1])); \ |
| 141 } while (0) |
| 142 |
| 143 #define STORE_Rgb565(out, r, g, b) do { \ |
| 144 const uint8x8_t r1 = vshl_n_u8(vshr_n_u8(r, 3), 3); /* 5bits */ \ |
| 145 const uint8x8_t g1 = vshr_n_u8(g, 5); /* upper 3bits */\ |
| 146 const uint8x8_t g2 = vshl_n_u8(vshr_n_u8(g, 2), 5); /* lower 3bits */\ |
| 147 const uint8x8_t b1 = vshr_n_u8(b, 3); /* 5bits */ \ |
| 148 const uint8x8_t rg = vorr_u8(r1, g1); \ |
| 149 const uint8x8_t gb = vorr_u8(g2, b1); \ |
| 150 const uint8x8x2_t rgb565 = ZIP_U8(rg, gb); \ |
| 151 vst1q_u8(out, vcombine_u8(rgb565.val[0], rgb565.val[1])); \ |
| 152 } while (0) |
| 153 |
| 154 #define CONVERT8(FMT, XSTEP, N, src_y, src_uv, out, cur_x) do { \ |
121 int i; \ | 155 int i; \ |
122 for (i = 0; i < N; i += 8) { \ | 156 for (i = 0; i < N; i += 8) { \ |
123 const int off = ((cur_x) + i) * XSTEP; \ | 157 const int off = ((cur_x) + i) * XSTEP; \ |
124 uint8x8_t y = vld1_u8((src_y) + (cur_x) + i); \ | 158 const uint8x8_t y = vld1_u8((src_y) + (cur_x) + i); \ |
125 uint8x8_t u = vld1_u8((src_uv) + i); \ | 159 const uint8x8_t u = vld1_u8((src_uv) + i + 0); \ |
126 uint8x8_t v = vld1_u8((src_uv) + i + 16); \ | 160 const uint8x8_t v = vld1_u8((src_uv) + i + 16); \ |
127 const int16x8_t yy = vreinterpretq_s16_u16(vsubl_u8(y, u16)); \ | 161 const int16x8_t Y0 = vreinterpretq_s16_u16(vshll_n_u8(y, 7)); \ |
128 const int16x8_t uu = vreinterpretq_s16_u16(vsubl_u8(u, u128)); \ | 162 const int16x8_t U0 = vreinterpretq_s16_u16(vshll_n_u8(u, 7)); \ |
129 const int16x8_t vv = vreinterpretq_s16_u16(vsubl_u8(v, u128)); \ | 163 const int16x8_t V0 = vreinterpretq_s16_u16(vshll_n_u8(v, 7)); \ |
130 int32x4_t yl = vmull_lane_s16(vget_low_s16(yy), cf16, 0); \ | 164 const int16x8_t Y1 = vqdmulhq_lane_s16(Y0, coeff1, 0); \ |
131 int32x4_t yh = vmull_lane_s16(vget_high_s16(yy), cf16, 0); \ | 165 const int16x8_t R0 = vqdmulhq_lane_s16(V0, coeff1, 1); \ |
132 const int32x4_t rl = vmlal_lane_s16(yl, vget_low_s16(vv), cf16, 1);\ | 166 const int16x8_t G0 = vqdmulhq_lane_s16(U0, coeff1, 2); \ |
133 const int32x4_t rh = vmlal_lane_s16(yh, vget_high_s16(vv), cf16, 1);\ | 167 const int16x8_t G1 = vqdmulhq_lane_s16(V0, coeff1, 3); \ |
134 int32x4_t gl = vmlsl_lane_s16(yl, vget_low_s16(uu), cf16, 2); \ | 168 const int16x8_t B0 = vqdmulhq_n_s16(U0, 282); \ |
135 int32x4_t gh = vmlsl_lane_s16(yh, vget_high_s16(uu), cf16, 2); \ | 169 const int16x8_t R1 = vqaddq_s16(Y1, R_Rounder); \ |
136 const int32x4_t bl = vmovl_s16(vget_low_s16(uu)); \ | 170 const int16x8_t G2 = vqaddq_s16(Y1, G_Rounder); \ |
137 const int32x4_t bh = vmovl_s16(vget_high_s16(uu)); \ | 171 const int16x8_t B1 = vqaddq_s16(Y1, B_Rounder); \ |
138 gl = vmlsl_lane_s16(gl, vget_low_s16(vv), cf16, 3); \ | 172 const int16x8_t R2 = vqaddq_s16(R0, R1); \ |
139 gh = vmlsl_lane_s16(gh, vget_high_s16(vv), cf16, 3); \ | 173 const int16x8_t G3 = vqaddq_s16(G0, G1); \ |
140 yl = vmlaq_lane_s32(yl, bl, cf32, 0); \ | 174 const int16x8_t B2 = vqaddq_s16(B0, B1); \ |
141 yh = vmlaq_lane_s32(yh, bh, cf32, 0); \ | 175 const int16x8_t G4 = vqsubq_s16(G2, G3); \ |
142 /* vrshrn_n_s32() already incorporates the rounding constant */ \ | 176 const int16x8_t B3 = vqaddq_s16(B2, U0); \ |
143 y = vqmovun_s16(vcombine_s16(vrshrn_n_s32(rl, YUV_FIX2), \ | 177 const uint8x8_t R = vqshrun_n_s16(R2, YUV_FIX2); \ |
144 vrshrn_n_s32(rh, YUV_FIX2))); \ | 178 const uint8x8_t G = vqshrun_n_s16(G4, YUV_FIX2); \ |
145 u = vqmovun_s16(vcombine_s16(vrshrn_n_s32(gl, YUV_FIX2), \ | 179 const uint8x8_t B = vqshrun_n_s16(B3, YUV_FIX2); \ |
146 vrshrn_n_s32(gh, YUV_FIX2))); \ | 180 STORE_ ## FMT(out + off, R, G, B); \ |
147 v = vqmovun_s16(vcombine_s16(vrshrn_n_s32(yl, YUV_FIX2), \ | |
148 vrshrn_n_s32(yh, YUV_FIX2))); \ | |
149 STORE_ ## FMT(out + off, y, u, v); \ | |
150 } \ | 181 } \ |
151 } | 182 } while (0) |
152 | 183 |
153 #define CONVERT1(FUNC, XSTEP, N, src_y, src_uv, rgb, cur_x) { \ | 184 #define CONVERT1(FUNC, XSTEP, N, src_y, src_uv, rgb, cur_x) { \ |
154 int i; \ | 185 int i; \ |
155 for (i = 0; i < N; i++) { \ | 186 for (i = 0; i < N; i++) { \ |
156 const int off = ((cur_x) + i) * XSTEP; \ | 187 const int off = ((cur_x) + i) * XSTEP; \ |
157 const int y = src_y[(cur_x) + i]; \ | 188 const int y = src_y[(cur_x) + i]; \ |
158 const int u = (src_uv)[i]; \ | 189 const int u = (src_uv)[i]; \ |
159 const int v = (src_uv)[i + 16]; \ | 190 const int v = (src_uv)[i + 16]; \ |
160 FUNC(y, u, v, rgb + off); \ | 191 FUNC(y, u, v, rgb + off); \ |
161 } \ | 192 } \ |
162 } | 193 } |
163 | 194 |
164 #define CONVERT2RGB_8(FMT, XSTEP, top_y, bottom_y, uv, \ | 195 #define CONVERT2RGB_8(FMT, XSTEP, top_y, bottom_y, uv, \ |
165 top_dst, bottom_dst, cur_x, len) { \ | 196 top_dst, bottom_dst, cur_x, len) { \ |
166 CONVERT8(FMT, XSTEP, len, top_y, uv, top_dst, cur_x) \ | 197 CONVERT8(FMT, XSTEP, len, top_y, uv, top_dst, cur_x); \ |
167 if (bottom_y != NULL) { \ | 198 if (bottom_y != NULL) { \ |
168 CONVERT8(FMT, XSTEP, len, bottom_y, (uv) + 32, bottom_dst, cur_x) \ | 199 CONVERT8(FMT, XSTEP, len, bottom_y, (uv) + 32, bottom_dst, cur_x); \ |
169 } \ | 200 } \ |
170 } | 201 } |
171 | 202 |
172 #define CONVERT2RGB_1(FUNC, XSTEP, top_y, bottom_y, uv, \ | 203 #define CONVERT2RGB_1(FUNC, XSTEP, top_y, bottom_y, uv, \ |
173 top_dst, bottom_dst, cur_x, len) { \ | 204 top_dst, bottom_dst, cur_x, len) { \ |
174 CONVERT1(FUNC, XSTEP, len, top_y, uv, top_dst, cur_x); \ | 205 CONVERT1(FUNC, XSTEP, len, top_y, uv, top_dst, cur_x); \ |
175 if (bottom_y != NULL) { \ | 206 if (bottom_y != NULL) { \ |
176 CONVERT1(FUNC, XSTEP, len, bottom_y, (uv) + 32, bottom_dst, cur_x); \ | 207 CONVERT1(FUNC, XSTEP, len, bottom_y, (uv) + 32, bottom_dst, cur_x); \ |
177 } \ | 208 } \ |
178 } | 209 } |
179 | 210 |
180 #define NEON_UPSAMPLE_FUNC(FUNC_NAME, FMT, XSTEP) \ | 211 #define NEON_UPSAMPLE_FUNC(FUNC_NAME, FMT, XSTEP) \ |
181 static void FUNC_NAME(const uint8_t *top_y, const uint8_t *bottom_y, \ | 212 static void FUNC_NAME(const uint8_t *top_y, const uint8_t *bottom_y, \ |
182 const uint8_t *top_u, const uint8_t *top_v, \ | 213 const uint8_t *top_u, const uint8_t *top_v, \ |
183 const uint8_t *cur_u, const uint8_t *cur_v, \ | 214 const uint8_t *cur_u, const uint8_t *cur_v, \ |
184 uint8_t *top_dst, uint8_t *bottom_dst, int len) { \ | 215 uint8_t *top_dst, uint8_t *bottom_dst, int len) { \ |
185 int block; \ | 216 int block; \ |
186 /* 16 byte aligned array to cache reconstructed u and v */ \ | 217 /* 16 byte aligned array to cache reconstructed u and v */ \ |
187 uint8_t uv_buf[2 * 32 + 15]; \ | 218 uint8_t uv_buf[2 * 32 + 15]; \ |
188 uint8_t *const r_uv = (uint8_t*)((uintptr_t)(uv_buf + 15) & ~15); \ | 219 uint8_t *const r_uv = (uint8_t*)((uintptr_t)(uv_buf + 15) & ~15); \ |
189 const int uv_len = (len + 1) >> 1; \ | 220 const int uv_len = (len + 1) >> 1; \ |
190 /* 9 pixels must be read-able for each block */ \ | 221 /* 9 pixels must be read-able for each block */ \ |
191 const int num_blocks = (uv_len - 1) >> 3; \ | 222 const int num_blocks = (uv_len - 1) >> 3; \ |
192 const int leftover = uv_len - num_blocks * 8; \ | 223 const int leftover = uv_len - num_blocks * 8; \ |
193 const int last_pos = 1 + 16 * num_blocks; \ | 224 const int last_pos = 1 + 16 * num_blocks; \ |
194 \ | 225 \ |
195 const int u_diag = ((top_u[0] + cur_u[0]) >> 1) + 1; \ | 226 const int u_diag = ((top_u[0] + cur_u[0]) >> 1) + 1; \ |
196 const int v_diag = ((top_v[0] + cur_v[0]) >> 1) + 1; \ | 227 const int v_diag = ((top_v[0] + cur_v[0]) >> 1) + 1; \ |
197 \ | 228 \ |
198 const int16x4_t cf16 = vld1_s16(kCoeffs); \ | 229 const int16x4_t coeff1 = vld1_s16(kCoeffs1); \ |
199 const int32x2_t cf32 = vdup_n_s32(kUToB); \ | 230 const int16x8_t R_Rounder = vdupq_n_s16(-14234); \ |
200 const uint8x8_t u16 = vdup_n_u8(16); \ | 231 const int16x8_t G_Rounder = vdupq_n_s16(8708); \ |
201 const uint8x8_t u128 = vdup_n_u8(128); \ | 232 const int16x8_t B_Rounder = vdupq_n_s16(-17685); \ |
202 \ | 233 \ |
203 /* Treat the first pixel in regular way */ \ | 234 /* Treat the first pixel in regular way */ \ |
204 assert(top_y != NULL); \ | 235 assert(top_y != NULL); \ |
205 { \ | 236 { \ |
206 const int u0 = (top_u[0] + u_diag) >> 1; \ | 237 const int u0 = (top_u[0] + u_diag) >> 1; \ |
207 const int v0 = (top_v[0] + v_diag) >> 1; \ | 238 const int v0 = (top_v[0] + v_diag) >> 1; \ |
208 VP8YuvTo ## FMT(top_y[0], u0, v0, top_dst); \ | 239 VP8YuvTo ## FMT(top_y[0], u0, v0, top_dst); \ |
209 } \ | 240 } \ |
210 if (bottom_y != NULL) { \ | 241 if (bottom_y != NULL) { \ |
211 const int u0 = (cur_u[0] + u_diag) >> 1; \ | 242 const int u0 = (cur_u[0] + u_diag) >> 1; \ |
(...skipping 16 matching lines...) Expand all Loading... |
228 UPSAMPLE_LAST_BLOCK(top_v, cur_v, leftover, r_uv + 16); \ | 259 UPSAMPLE_LAST_BLOCK(top_v, cur_v, leftover, r_uv + 16); \ |
229 CONVERT2RGB_1(VP8YuvTo ## FMT, XSTEP, top_y, bottom_y, r_uv, \ | 260 CONVERT2RGB_1(VP8YuvTo ## FMT, XSTEP, top_y, bottom_y, r_uv, \ |
230 top_dst, bottom_dst, last_pos, len - last_pos); \ | 261 top_dst, bottom_dst, last_pos, len - last_pos); \ |
231 } | 262 } |
232 | 263 |
233 // NEON variants of the fancy upsampler. | 264 // NEON variants of the fancy upsampler. |
234 NEON_UPSAMPLE_FUNC(UpsampleRgbLinePair, Rgb, 3) | 265 NEON_UPSAMPLE_FUNC(UpsampleRgbLinePair, Rgb, 3) |
235 NEON_UPSAMPLE_FUNC(UpsampleBgrLinePair, Bgr, 3) | 266 NEON_UPSAMPLE_FUNC(UpsampleBgrLinePair, Bgr, 3) |
236 NEON_UPSAMPLE_FUNC(UpsampleRgbaLinePair, Rgba, 4) | 267 NEON_UPSAMPLE_FUNC(UpsampleRgbaLinePair, Rgba, 4) |
237 NEON_UPSAMPLE_FUNC(UpsampleBgraLinePair, Bgra, 4) | 268 NEON_UPSAMPLE_FUNC(UpsampleBgraLinePair, Bgra, 4) |
238 | 269 NEON_UPSAMPLE_FUNC(UpsampleArgbLinePair, Argb, 4) |
239 #endif // FANCY_UPSAMPLING | 270 NEON_UPSAMPLE_FUNC(UpsampleRgba4444LinePair, Rgba4444, 2) |
240 | 271 NEON_UPSAMPLE_FUNC(UpsampleRgb565LinePair, Rgb565, 2) |
241 #endif // WEBP_USE_NEON | |
242 | 272 |
243 //------------------------------------------------------------------------------ | 273 //------------------------------------------------------------------------------ |
| 274 // Entry point |
| 275 |
| 276 extern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */]; |
244 | 277 |
245 extern void WebPInitUpsamplersNEON(void); | 278 extern void WebPInitUpsamplersNEON(void); |
246 | 279 |
247 #ifdef FANCY_UPSAMPLING | 280 WEBP_TSAN_IGNORE_FUNCTION void WebPInitUpsamplersNEON(void) { |
248 | |
249 extern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */]; | |
250 | |
251 void WebPInitUpsamplersNEON(void) { | |
252 #if defined(WEBP_USE_NEON) | |
253 WebPUpsamplers[MODE_RGB] = UpsampleRgbLinePair; | 281 WebPUpsamplers[MODE_RGB] = UpsampleRgbLinePair; |
254 WebPUpsamplers[MODE_RGBA] = UpsampleRgbaLinePair; | 282 WebPUpsamplers[MODE_RGBA] = UpsampleRgbaLinePair; |
255 WebPUpsamplers[MODE_BGR] = UpsampleBgrLinePair; | 283 WebPUpsamplers[MODE_BGR] = UpsampleBgrLinePair; |
256 WebPUpsamplers[MODE_BGRA] = UpsampleBgraLinePair; | 284 WebPUpsamplers[MODE_BGRA] = UpsampleBgraLinePair; |
| 285 WebPUpsamplers[MODE_ARGB] = UpsampleArgbLinePair; |
257 WebPUpsamplers[MODE_rgbA] = UpsampleRgbaLinePair; | 286 WebPUpsamplers[MODE_rgbA] = UpsampleRgbaLinePair; |
258 WebPUpsamplers[MODE_bgrA] = UpsampleBgraLinePair; | 287 WebPUpsamplers[MODE_bgrA] = UpsampleBgraLinePair; |
259 #endif // WEBP_USE_NEON | 288 WebPUpsamplers[MODE_Argb] = UpsampleArgbLinePair; |
| 289 WebPUpsamplers[MODE_RGB_565] = UpsampleRgb565LinePair; |
| 290 WebPUpsamplers[MODE_RGBA_4444] = UpsampleRgba4444LinePair; |
| 291 WebPUpsamplers[MODE_rgbA_4444] = UpsampleRgba4444LinePair; |
260 } | 292 } |
261 | 293 |
262 #else | 294 #endif // FANCY_UPSAMPLING |
263 | 295 |
264 // this empty function is to avoid an empty .o | 296 #endif // WEBP_USE_NEON |
265 void WebPInitUpsamplersNEON(void) {} | |
266 | 297 |
267 #endif // FANCY_UPSAMPLING | 298 #if !(defined(FANCY_UPSAMPLING) && defined(WEBP_USE_NEON)) |
| 299 WEBP_DSP_INIT_STUB(WebPInitUpsamplersNEON) |
| 300 #endif |
OLD | NEW |