/src/libavif/ext/libyuv/source/convert_argb.cc
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2011 The LibYuv 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 "libyuv/convert_argb.h" |
12 | | |
13 | | #include <assert.h> |
14 | | #include <limits.h> |
15 | | #include <string.h> // For memcpy. |
16 | | |
17 | | #include "libyuv/convert_from_argb.h" |
18 | | #include "libyuv/cpu_id.h" |
19 | | #include "libyuv/planar_functions.h" // For CopyPlane and ARGBShuffle. |
20 | | #include "libyuv/rotate_argb.h" |
21 | | #include "libyuv/row.h" |
22 | | #include "libyuv/scale_row.h" // For ScaleRowUp2_Linear and ScaleRowUp2_Bilinear |
23 | | #include "libyuv/video_common.h" |
24 | | |
25 | | #ifdef __cplusplus |
26 | | namespace libyuv { |
27 | | extern "C" { |
28 | | #endif |
29 | | |
30 | | // Copy ARGB with optional flipping |
31 | | LIBYUV_API |
32 | | int ARGBCopy(const uint8_t* src_argb, |
33 | | int src_stride_argb, |
34 | | uint8_t* dst_argb, |
35 | | int dst_stride_argb, |
36 | | int width, |
37 | 0 | int height) { |
38 | 0 | if (!src_argb || !dst_argb || width <= 0 || height == 0 || |
39 | 0 | height == INT_MIN) { |
40 | 0 | return -1; |
41 | 0 | } |
42 | | // Negative height means invert the image. |
43 | 0 | if (height < 0) { |
44 | 0 | height = -height; |
45 | 0 | src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; |
46 | 0 | src_stride_argb = -src_stride_argb; |
47 | 0 | } |
48 | |
|
49 | 0 | CopyPlane(src_argb, src_stride_argb, dst_argb, dst_stride_argb, width * 4, |
50 | 0 | height); |
51 | 0 | return 0; |
52 | 0 | } |
53 | | |
54 | | // Convert I420 to ARGB with matrix. |
55 | | LIBYUV_API |
56 | | int I420ToARGBMatrix(const uint8_t* src_y, |
57 | | int src_stride_y, |
58 | | const uint8_t* src_u, |
59 | | int src_stride_u, |
60 | | const uint8_t* src_v, |
61 | | int src_stride_v, |
62 | | uint8_t* dst_argb, |
63 | | int dst_stride_argb, |
64 | | const struct YuvConstants* yuvconstants, |
65 | | int width, |
66 | 178 | int height) { |
67 | 178 | int y; |
68 | 178 | void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, |
69 | 178 | const uint8_t* v_buf, uint8_t* rgb_buf, |
70 | 178 | const struct YuvConstants* yuvconstants, int width) = |
71 | 178 | I422ToARGBRow_C; |
72 | 178 | assert(yuvconstants); |
73 | 178 | if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || |
74 | 178 | height == INT_MIN) { |
75 | 0 | return -1; |
76 | 0 | } |
77 | | // Negative height means invert the image. |
78 | 178 | if (height < 0) { |
79 | 0 | height = -height; |
80 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
81 | 0 | dst_stride_argb = -dst_stride_argb; |
82 | 0 | } |
83 | 178 | #if defined(HAS_I422TOARGBROW_SSSE3) |
84 | 178 | if (TestCpuFlag(kCpuHasSSSE3)) { |
85 | 178 | I422ToARGBRow = I422ToARGBRow_Any_SSSE3; |
86 | 178 | if (IS_ALIGNED(width, 8)) { |
87 | 34 | I422ToARGBRow = I422ToARGBRow_SSSE3; |
88 | 34 | } |
89 | 178 | } |
90 | 178 | #endif |
91 | 178 | #if defined(HAS_I422TOARGBROW_AVX2) |
92 | 178 | if (TestCpuFlag(kCpuHasAVX2)) { |
93 | 178 | I422ToARGBRow = I422ToARGBRow_Any_AVX2; |
94 | 178 | if (IS_ALIGNED(width, 16)) { |
95 | 17 | I422ToARGBRow = I422ToARGBRow_AVX2; |
96 | 17 | } |
97 | 178 | } |
98 | 178 | #endif |
99 | 178 | #if defined(HAS_I422TOARGBROW_AVX512BW) |
100 | 178 | if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) == |
101 | 178 | (kCpuHasAVX512BW | kCpuHasAVX512VL)) { |
102 | 0 | I422ToARGBRow = I422ToARGBRow_Any_AVX512BW; |
103 | 0 | if (IS_ALIGNED(width, 32)) { |
104 | 0 | I422ToARGBRow = I422ToARGBRow_AVX512BW; |
105 | 0 | } |
106 | 0 | } |
107 | 178 | #endif |
108 | | #if defined(HAS_I422TOARGBROW_NEON) |
109 | | if (TestCpuFlag(kCpuHasNEON)) { |
110 | | I422ToARGBRow = I422ToARGBRow_Any_NEON; |
111 | | if (IS_ALIGNED(width, 8)) { |
112 | | I422ToARGBRow = I422ToARGBRow_NEON; |
113 | | } |
114 | | } |
115 | | #endif |
116 | | #if defined(HAS_I422TOARGBROW_SVE2) |
117 | | if (TestCpuFlag(kCpuHasSVE2)) { |
118 | | I422ToARGBRow = I422ToARGBRow_SVE2; |
119 | | } |
120 | | #endif |
121 | | #if defined(HAS_I422TOARGBROW_SME) |
122 | | if (TestCpuFlag(kCpuHasSME)) { |
123 | | I422ToARGBRow = I422ToARGBRow_SME; |
124 | | } |
125 | | #endif |
126 | | #if defined(HAS_I422TOARGBROW_LSX) |
127 | | if (TestCpuFlag(kCpuHasLSX)) { |
128 | | I422ToARGBRow = I422ToARGBRow_Any_LSX; |
129 | | if (IS_ALIGNED(width, 16)) { |
130 | | I422ToARGBRow = I422ToARGBRow_LSX; |
131 | | } |
132 | | } |
133 | | #endif |
134 | | #if defined(HAS_I422TOARGBROW_LASX) |
135 | | if (TestCpuFlag(kCpuHasLASX)) { |
136 | | I422ToARGBRow = I422ToARGBRow_Any_LASX; |
137 | | if (IS_ALIGNED(width, 32)) { |
138 | | I422ToARGBRow = I422ToARGBRow_LASX; |
139 | | } |
140 | | } |
141 | | #endif |
142 | | #if defined(HAS_I422TOARGBROW_RVV) |
143 | | if (TestCpuFlag(kCpuHasRVV)) { |
144 | | I422ToARGBRow = I422ToARGBRow_RVV; |
145 | | } |
146 | | #endif |
147 | | |
148 | 2.93k | for (y = 0; y < height; ++y) { |
149 | 2.75k | I422ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); |
150 | 2.75k | dst_argb += dst_stride_argb; |
151 | 2.75k | src_y += src_stride_y; |
152 | 2.75k | if (y & 1) { |
153 | 1.36k | src_u += src_stride_u; |
154 | 1.36k | src_v += src_stride_v; |
155 | 1.36k | } |
156 | 2.75k | } |
157 | 178 | return 0; |
158 | 178 | } |
159 | | |
160 | | // Convert I420 to ARGB. |
161 | | LIBYUV_API |
162 | | int I420ToARGB(const uint8_t* src_y, |
163 | | int src_stride_y, |
164 | | const uint8_t* src_u, |
165 | | int src_stride_u, |
166 | | const uint8_t* src_v, |
167 | | int src_stride_v, |
168 | | uint8_t* dst_argb, |
169 | | int dst_stride_argb, |
170 | | int width, |
171 | 0 | int height) { |
172 | 0 | return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
173 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
174 | 0 | &kYuvI601Constants, width, height); |
175 | 0 | } |
176 | | |
177 | | // Convert I420 to ABGR. |
178 | | LIBYUV_API |
179 | | int I420ToABGR(const uint8_t* src_y, |
180 | | int src_stride_y, |
181 | | const uint8_t* src_u, |
182 | | int src_stride_u, |
183 | | const uint8_t* src_v, |
184 | | int src_stride_v, |
185 | | uint8_t* dst_abgr, |
186 | | int dst_stride_abgr, |
187 | | int width, |
188 | 0 | int height) { |
189 | 0 | return I420ToARGBMatrix(src_y, src_stride_y, src_v, |
190 | 0 | src_stride_v, // Swap U and V |
191 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
192 | 0 | &kYvuI601Constants, // Use Yvu matrix |
193 | 0 | width, height); |
194 | 0 | } |
195 | | |
196 | | // Convert J420 to ARGB. |
197 | | LIBYUV_API |
198 | | int J420ToARGB(const uint8_t* src_y, |
199 | | int src_stride_y, |
200 | | const uint8_t* src_u, |
201 | | int src_stride_u, |
202 | | const uint8_t* src_v, |
203 | | int src_stride_v, |
204 | | uint8_t* dst_argb, |
205 | | int dst_stride_argb, |
206 | | int width, |
207 | 0 | int height) { |
208 | 0 | return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
209 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
210 | 0 | &kYuvJPEGConstants, width, height); |
211 | 0 | } |
212 | | |
213 | | // Convert J420 to ABGR. |
214 | | LIBYUV_API |
215 | | int J420ToABGR(const uint8_t* src_y, |
216 | | int src_stride_y, |
217 | | const uint8_t* src_u, |
218 | | int src_stride_u, |
219 | | const uint8_t* src_v, |
220 | | int src_stride_v, |
221 | | uint8_t* dst_abgr, |
222 | | int dst_stride_abgr, |
223 | | int width, |
224 | 0 | int height) { |
225 | 0 | return I420ToARGBMatrix(src_y, src_stride_y, src_v, |
226 | 0 | src_stride_v, // Swap U and V |
227 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
228 | 0 | &kYvuJPEGConstants, // Use Yvu matrix |
229 | 0 | width, height); |
230 | 0 | } |
231 | | |
232 | | // Convert H420 to ARGB. |
233 | | LIBYUV_API |
234 | | int H420ToARGB(const uint8_t* src_y, |
235 | | int src_stride_y, |
236 | | const uint8_t* src_u, |
237 | | int src_stride_u, |
238 | | const uint8_t* src_v, |
239 | | int src_stride_v, |
240 | | uint8_t* dst_argb, |
241 | | int dst_stride_argb, |
242 | | int width, |
243 | 0 | int height) { |
244 | 0 | return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
245 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
246 | 0 | &kYuvH709Constants, width, height); |
247 | 0 | } |
248 | | |
249 | | // Convert H420 to ABGR. |
250 | | LIBYUV_API |
251 | | int H420ToABGR(const uint8_t* src_y, |
252 | | int src_stride_y, |
253 | | const uint8_t* src_u, |
254 | | int src_stride_u, |
255 | | const uint8_t* src_v, |
256 | | int src_stride_v, |
257 | | uint8_t* dst_abgr, |
258 | | int dst_stride_abgr, |
259 | | int width, |
260 | 0 | int height) { |
261 | 0 | return I420ToARGBMatrix(src_y, src_stride_y, src_v, |
262 | 0 | src_stride_v, // Swap U and V |
263 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
264 | 0 | &kYvuH709Constants, // Use Yvu matrix |
265 | 0 | width, height); |
266 | 0 | } |
267 | | |
268 | | // Convert U420 to ARGB. |
269 | | LIBYUV_API |
270 | | int U420ToARGB(const uint8_t* src_y, |
271 | | int src_stride_y, |
272 | | const uint8_t* src_u, |
273 | | int src_stride_u, |
274 | | const uint8_t* src_v, |
275 | | int src_stride_v, |
276 | | uint8_t* dst_argb, |
277 | | int dst_stride_argb, |
278 | | int width, |
279 | 0 | int height) { |
280 | 0 | return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
281 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
282 | 0 | &kYuv2020Constants, width, height); |
283 | 0 | } |
284 | | |
285 | | // Convert U420 to ABGR. |
286 | | LIBYUV_API |
287 | | int U420ToABGR(const uint8_t* src_y, |
288 | | int src_stride_y, |
289 | | const uint8_t* src_u, |
290 | | int src_stride_u, |
291 | | const uint8_t* src_v, |
292 | | int src_stride_v, |
293 | | uint8_t* dst_abgr, |
294 | | int dst_stride_abgr, |
295 | | int width, |
296 | 0 | int height) { |
297 | 0 | return I420ToARGBMatrix(src_y, src_stride_y, src_v, |
298 | 0 | src_stride_v, // Swap U and V |
299 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
300 | 0 | &kYvu2020Constants, // Use Yvu matrix |
301 | 0 | width, height); |
302 | 0 | } |
303 | | |
304 | | // Convert I422 to ARGB with matrix. |
305 | | LIBYUV_API |
306 | | int I422ToARGBMatrix(const uint8_t* src_y, |
307 | | int src_stride_y, |
308 | | const uint8_t* src_u, |
309 | | int src_stride_u, |
310 | | const uint8_t* src_v, |
311 | | int src_stride_v, |
312 | | uint8_t* dst_argb, |
313 | | int dst_stride_argb, |
314 | | const struct YuvConstants* yuvconstants, |
315 | | int width, |
316 | 120 | int height) { |
317 | 120 | int y; |
318 | 120 | void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, |
319 | 120 | const uint8_t* v_buf, uint8_t* rgb_buf, |
320 | 120 | const struct YuvConstants* yuvconstants, int width) = |
321 | 120 | I422ToARGBRow_C; |
322 | 120 | assert(yuvconstants); |
323 | 120 | if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || |
324 | 120 | height == INT_MIN) { |
325 | 0 | return -1; |
326 | 0 | } |
327 | | // Negative height means invert the image. |
328 | 120 | if (height < 0) { |
329 | 0 | height = -height; |
330 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
331 | 0 | dst_stride_argb = -dst_stride_argb; |
332 | 0 | } |
333 | | // Coalesce rows. |
334 | 120 | if (src_stride_y == width && src_stride_u * 2 == width && |
335 | 60 | src_stride_v * 2 == width && dst_stride_argb == width * 4 && |
336 | 60 | (ptrdiff_t)width * height <= INT_MAX) { |
337 | 60 | width *= height; |
338 | 60 | height = 1; |
339 | 60 | src_stride_y = src_stride_u = src_stride_v = dst_stride_argb = 0; |
340 | 60 | } |
341 | 120 | #if defined(HAS_I422TOARGBROW_SSSE3) |
342 | 120 | if (TestCpuFlag(kCpuHasSSSE3)) { |
343 | 120 | I422ToARGBRow = I422ToARGBRow_Any_SSSE3; |
344 | 120 | if (IS_ALIGNED(width, 8)) { |
345 | 38 | I422ToARGBRow = I422ToARGBRow_SSSE3; |
346 | 38 | } |
347 | 120 | } |
348 | 120 | #endif |
349 | 120 | #if defined(HAS_I422TOARGBROW_AVX2) |
350 | 120 | if (TestCpuFlag(kCpuHasAVX2)) { |
351 | 120 | I422ToARGBRow = I422ToARGBRow_Any_AVX2; |
352 | 120 | if (IS_ALIGNED(width, 16)) { |
353 | 17 | I422ToARGBRow = I422ToARGBRow_AVX2; |
354 | 17 | } |
355 | 120 | } |
356 | 120 | #endif |
357 | 120 | #if defined(HAS_I422TOARGBROW_AVX512BW) |
358 | 120 | if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) == |
359 | 120 | (kCpuHasAVX512BW | kCpuHasAVX512VL)) { |
360 | 0 | I422ToARGBRow = I422ToARGBRow_Any_AVX512BW; |
361 | 0 | if (IS_ALIGNED(width, 32)) { |
362 | 0 | I422ToARGBRow = I422ToARGBRow_AVX512BW; |
363 | 0 | } |
364 | 0 | } |
365 | 120 | #endif |
366 | | #if defined(HAS_I422TOARGBROW_NEON) |
367 | | if (TestCpuFlag(kCpuHasNEON)) { |
368 | | I422ToARGBRow = I422ToARGBRow_Any_NEON; |
369 | | if (IS_ALIGNED(width, 8)) { |
370 | | I422ToARGBRow = I422ToARGBRow_NEON; |
371 | | } |
372 | | } |
373 | | #endif |
374 | | #if defined(HAS_I422TOARGBROW_SVE2) |
375 | | if (TestCpuFlag(kCpuHasSVE2)) { |
376 | | I422ToARGBRow = I422ToARGBRow_SVE2; |
377 | | } |
378 | | #endif |
379 | | #if defined(HAS_I422TOARGBROW_SME) |
380 | | if (TestCpuFlag(kCpuHasSME)) { |
381 | | I422ToARGBRow = I422ToARGBRow_SME; |
382 | | } |
383 | | #endif |
384 | | #if defined(HAS_I422TOARGBROW_LSX) |
385 | | if (TestCpuFlag(kCpuHasLSX)) { |
386 | | I422ToARGBRow = I422ToARGBRow_Any_LSX; |
387 | | if (IS_ALIGNED(width, 16)) { |
388 | | I422ToARGBRow = I422ToARGBRow_LSX; |
389 | | } |
390 | | } |
391 | | #endif |
392 | | #if defined(HAS_I422TOARGBROW_LASX) |
393 | | if (TestCpuFlag(kCpuHasLASX)) { |
394 | | I422ToARGBRow = I422ToARGBRow_Any_LASX; |
395 | | if (IS_ALIGNED(width, 32)) { |
396 | | I422ToARGBRow = I422ToARGBRow_LASX; |
397 | | } |
398 | | } |
399 | | #endif |
400 | | #if defined(HAS_I422TOARGBROW_RVV) |
401 | | if (TestCpuFlag(kCpuHasRVV)) { |
402 | | I422ToARGBRow = I422ToARGBRow_RVV; |
403 | | } |
404 | | #endif |
405 | | |
406 | 1.54k | for (y = 0; y < height; ++y) { |
407 | 1.42k | I422ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); |
408 | 1.42k | dst_argb += dst_stride_argb; |
409 | 1.42k | src_y += src_stride_y; |
410 | 1.42k | src_u += src_stride_u; |
411 | 1.42k | src_v += src_stride_v; |
412 | 1.42k | } |
413 | 120 | return 0; |
414 | 120 | } |
415 | | |
416 | | // Convert I422 to ARGB. |
417 | | LIBYUV_API |
418 | | int I422ToARGB(const uint8_t* src_y, |
419 | | int src_stride_y, |
420 | | const uint8_t* src_u, |
421 | | int src_stride_u, |
422 | | const uint8_t* src_v, |
423 | | int src_stride_v, |
424 | | uint8_t* dst_argb, |
425 | | int dst_stride_argb, |
426 | | int width, |
427 | 0 | int height) { |
428 | 0 | return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
429 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
430 | 0 | &kYuvI601Constants, width, height); |
431 | 0 | } |
432 | | |
433 | | // Convert I422 to ABGR. |
434 | | LIBYUV_API |
435 | | int I422ToABGR(const uint8_t* src_y, |
436 | | int src_stride_y, |
437 | | const uint8_t* src_u, |
438 | | int src_stride_u, |
439 | | const uint8_t* src_v, |
440 | | int src_stride_v, |
441 | | uint8_t* dst_abgr, |
442 | | int dst_stride_abgr, |
443 | | int width, |
444 | 0 | int height) { |
445 | 0 | return I422ToARGBMatrix(src_y, src_stride_y, src_v, |
446 | 0 | src_stride_v, // Swap U and V |
447 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
448 | 0 | &kYvuI601Constants, // Use Yvu matrix |
449 | 0 | width, height); |
450 | 0 | } |
451 | | |
452 | | // Convert J422 to ARGB. |
453 | | LIBYUV_API |
454 | | int J422ToARGB(const uint8_t* src_y, |
455 | | int src_stride_y, |
456 | | const uint8_t* src_u, |
457 | | int src_stride_u, |
458 | | const uint8_t* src_v, |
459 | | int src_stride_v, |
460 | | uint8_t* dst_argb, |
461 | | int dst_stride_argb, |
462 | | int width, |
463 | 0 | int height) { |
464 | 0 | return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
465 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
466 | 0 | &kYuvJPEGConstants, width, height); |
467 | 0 | } |
468 | | |
469 | | // Convert J422 to ABGR. |
470 | | LIBYUV_API |
471 | | int J422ToABGR(const uint8_t* src_y, |
472 | | int src_stride_y, |
473 | | const uint8_t* src_u, |
474 | | int src_stride_u, |
475 | | const uint8_t* src_v, |
476 | | int src_stride_v, |
477 | | uint8_t* dst_abgr, |
478 | | int dst_stride_abgr, |
479 | | int width, |
480 | 0 | int height) { |
481 | 0 | return I422ToARGBMatrix(src_y, src_stride_y, src_v, |
482 | 0 | src_stride_v, // Swap U and V |
483 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
484 | 0 | &kYvuJPEGConstants, // Use Yvu matrix |
485 | 0 | width, height); |
486 | 0 | } |
487 | | |
488 | | // Convert H422 to ARGB. |
489 | | LIBYUV_API |
490 | | int H422ToARGB(const uint8_t* src_y, |
491 | | int src_stride_y, |
492 | | const uint8_t* src_u, |
493 | | int src_stride_u, |
494 | | const uint8_t* src_v, |
495 | | int src_stride_v, |
496 | | uint8_t* dst_argb, |
497 | | int dst_stride_argb, |
498 | | int width, |
499 | 0 | int height) { |
500 | 0 | return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
501 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
502 | 0 | &kYuvH709Constants, width, height); |
503 | 0 | } |
504 | | |
505 | | // Convert H422 to ABGR. |
506 | | LIBYUV_API |
507 | | int H422ToABGR(const uint8_t* src_y, |
508 | | int src_stride_y, |
509 | | const uint8_t* src_u, |
510 | | int src_stride_u, |
511 | | const uint8_t* src_v, |
512 | | int src_stride_v, |
513 | | uint8_t* dst_abgr, |
514 | | int dst_stride_abgr, |
515 | | int width, |
516 | 0 | int height) { |
517 | 0 | return I422ToARGBMatrix(src_y, src_stride_y, src_v, |
518 | 0 | src_stride_v, // Swap U and V |
519 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
520 | 0 | &kYvuH709Constants, // Use Yvu matrix |
521 | 0 | width, height); |
522 | 0 | } |
523 | | |
524 | | // Convert U422 to ARGB. |
525 | | LIBYUV_API |
526 | | int U422ToARGB(const uint8_t* src_y, |
527 | | int src_stride_y, |
528 | | const uint8_t* src_u, |
529 | | int src_stride_u, |
530 | | const uint8_t* src_v, |
531 | | int src_stride_v, |
532 | | uint8_t* dst_argb, |
533 | | int dst_stride_argb, |
534 | | int width, |
535 | 0 | int height) { |
536 | 0 | return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
537 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
538 | 0 | &kYuv2020Constants, width, height); |
539 | 0 | } |
540 | | |
541 | | // Convert U422 to ABGR. |
542 | | LIBYUV_API |
543 | | int U422ToABGR(const uint8_t* src_y, |
544 | | int src_stride_y, |
545 | | const uint8_t* src_u, |
546 | | int src_stride_u, |
547 | | const uint8_t* src_v, |
548 | | int src_stride_v, |
549 | | uint8_t* dst_abgr, |
550 | | int dst_stride_abgr, |
551 | | int width, |
552 | 0 | int height) { |
553 | 0 | return I422ToARGBMatrix(src_y, src_stride_y, src_v, |
554 | 0 | src_stride_v, // Swap U and V |
555 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
556 | 0 | &kYvu2020Constants, // Use Yvu matrix |
557 | 0 | width, height); |
558 | 0 | } |
559 | | |
560 | | // Convert I444 to ARGB with matrix. |
561 | | LIBYUV_API |
562 | | int I444ToARGBMatrix(const uint8_t* src_y, |
563 | | int src_stride_y, |
564 | | const uint8_t* src_u, |
565 | | int src_stride_u, |
566 | | const uint8_t* src_v, |
567 | | int src_stride_v, |
568 | | uint8_t* dst_argb, |
569 | | int dst_stride_argb, |
570 | | const struct YuvConstants* yuvconstants, |
571 | | int width, |
572 | 113 | int height) { |
573 | 113 | int y; |
574 | 113 | void (*I444ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, |
575 | 113 | const uint8_t* v_buf, uint8_t* rgb_buf, |
576 | 113 | const struct YuvConstants* yuvconstants, int width) = |
577 | 113 | I444ToARGBRow_C; |
578 | 113 | assert(yuvconstants); |
579 | 113 | if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || |
580 | 113 | height == INT_MIN) { |
581 | 0 | return -1; |
582 | 0 | } |
583 | | // Negative height means invert the image. |
584 | 113 | if (height < 0) { |
585 | 0 | height = -height; |
586 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
587 | 0 | dst_stride_argb = -dst_stride_argb; |
588 | 0 | } |
589 | | // Coalesce rows. |
590 | 113 | if (src_stride_y == width && src_stride_u == width && src_stride_v == width && |
591 | 113 | dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { |
592 | 113 | width *= height; |
593 | 113 | height = 1; |
594 | 113 | src_stride_y = src_stride_u = src_stride_v = dst_stride_argb = 0; |
595 | 113 | } |
596 | 113 | #if defined(HAS_I444TOARGBROW_SSSE3) |
597 | 113 | if (TestCpuFlag(kCpuHasSSSE3)) { |
598 | 113 | I444ToARGBRow = I444ToARGBRow_Any_SSSE3; |
599 | 113 | if (IS_ALIGNED(width, 8)) { |
600 | 45 | I444ToARGBRow = I444ToARGBRow_SSSE3; |
601 | 45 | } |
602 | 113 | } |
603 | 113 | #endif |
604 | 113 | #if defined(HAS_I444TOARGBROW_AVX2) |
605 | 113 | if (TestCpuFlag(kCpuHasAVX2)) { |
606 | 113 | I444ToARGBRow = I444ToARGBRow_Any_AVX2; |
607 | 113 | if (IS_ALIGNED(width, 16)) { |
608 | 25 | I444ToARGBRow = I444ToARGBRow_AVX2; |
609 | 25 | } |
610 | 113 | } |
611 | 113 | #endif |
612 | | #if defined(HAS_I444TOARGBROW_NEON) |
613 | | if (TestCpuFlag(kCpuHasNEON)) { |
614 | | I444ToARGBRow = I444ToARGBRow_Any_NEON; |
615 | | if (IS_ALIGNED(width, 8)) { |
616 | | I444ToARGBRow = I444ToARGBRow_NEON; |
617 | | } |
618 | | } |
619 | | #endif |
620 | | #if defined(HAS_I444TOARGBROW_SVE2) |
621 | | if (TestCpuFlag(kCpuHasSVE2)) { |
622 | | I444ToARGBRow = I444ToARGBRow_SVE2; |
623 | | } |
624 | | #endif |
625 | | #if defined(HAS_I444TOARGBROW_SME) |
626 | | if (TestCpuFlag(kCpuHasSME)) { |
627 | | I444ToARGBRow = I444ToARGBRow_SME; |
628 | | } |
629 | | #endif |
630 | | #if defined(HAS_I444TOARGBROW_LSX) |
631 | | if (TestCpuFlag(kCpuHasLSX)) { |
632 | | I444ToARGBRow = I444ToARGBRow_Any_LSX; |
633 | | if (IS_ALIGNED(width, 16)) { |
634 | | I444ToARGBRow = I444ToARGBRow_LSX; |
635 | | } |
636 | | } |
637 | | #endif |
638 | | #if defined(HAS_I444TOARGBROW_RVV) |
639 | | if (TestCpuFlag(kCpuHasRVV)) { |
640 | | I444ToARGBRow = I444ToARGBRow_RVV; |
641 | | } |
642 | | #endif |
643 | | |
644 | 226 | for (y = 0; y < height; ++y) { |
645 | 113 | I444ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); |
646 | 113 | dst_argb += dst_stride_argb; |
647 | 113 | src_y += src_stride_y; |
648 | 113 | src_u += src_stride_u; |
649 | 113 | src_v += src_stride_v; |
650 | 113 | } |
651 | 113 | return 0; |
652 | 113 | } |
653 | | |
654 | | // Convert I444 to ARGB. |
655 | | LIBYUV_API |
656 | | int I444ToARGB(const uint8_t* src_y, |
657 | | int src_stride_y, |
658 | | const uint8_t* src_u, |
659 | | int src_stride_u, |
660 | | const uint8_t* src_v, |
661 | | int src_stride_v, |
662 | | uint8_t* dst_argb, |
663 | | int dst_stride_argb, |
664 | | int width, |
665 | 0 | int height) { |
666 | 0 | return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
667 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
668 | 0 | &kYuvI601Constants, width, height); |
669 | 0 | } |
670 | | |
671 | | // Convert I444 to ABGR. |
672 | | LIBYUV_API |
673 | | int I444ToABGR(const uint8_t* src_y, |
674 | | int src_stride_y, |
675 | | const uint8_t* src_u, |
676 | | int src_stride_u, |
677 | | const uint8_t* src_v, |
678 | | int src_stride_v, |
679 | | uint8_t* dst_abgr, |
680 | | int dst_stride_abgr, |
681 | | int width, |
682 | 0 | int height) { |
683 | 0 | return I444ToARGBMatrix(src_y, src_stride_y, src_v, |
684 | 0 | src_stride_v, // Swap U and V |
685 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
686 | 0 | &kYvuI601Constants, // Use Yvu matrix |
687 | 0 | width, height); |
688 | 0 | } |
689 | | |
690 | | // Convert J444 to ARGB. |
691 | | LIBYUV_API |
692 | | int J444ToARGB(const uint8_t* src_y, |
693 | | int src_stride_y, |
694 | | const uint8_t* src_u, |
695 | | int src_stride_u, |
696 | | const uint8_t* src_v, |
697 | | int src_stride_v, |
698 | | uint8_t* dst_argb, |
699 | | int dst_stride_argb, |
700 | | int width, |
701 | 0 | int height) { |
702 | 0 | return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
703 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
704 | 0 | &kYuvJPEGConstants, width, height); |
705 | 0 | } |
706 | | |
707 | | // Convert J444 to ABGR. |
708 | | LIBYUV_API |
709 | | int J444ToABGR(const uint8_t* src_y, |
710 | | int src_stride_y, |
711 | | const uint8_t* src_u, |
712 | | int src_stride_u, |
713 | | const uint8_t* src_v, |
714 | | int src_stride_v, |
715 | | uint8_t* dst_abgr, |
716 | | int dst_stride_abgr, |
717 | | int width, |
718 | 0 | int height) { |
719 | 0 | return I444ToARGBMatrix(src_y, src_stride_y, src_v, |
720 | 0 | src_stride_v, // Swap U and V |
721 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
722 | 0 | &kYvuJPEGConstants, // Use Yvu matrix |
723 | 0 | width, height); |
724 | 0 | } |
725 | | |
726 | | // Convert H444 to ARGB. |
727 | | LIBYUV_API |
728 | | int H444ToARGB(const uint8_t* src_y, |
729 | | int src_stride_y, |
730 | | const uint8_t* src_u, |
731 | | int src_stride_u, |
732 | | const uint8_t* src_v, |
733 | | int src_stride_v, |
734 | | uint8_t* dst_argb, |
735 | | int dst_stride_argb, |
736 | | int width, |
737 | 0 | int height) { |
738 | 0 | return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
739 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
740 | 0 | &kYuvH709Constants, width, height); |
741 | 0 | } |
742 | | |
743 | | // Convert H444 to ABGR. |
744 | | LIBYUV_API |
745 | | int H444ToABGR(const uint8_t* src_y, |
746 | | int src_stride_y, |
747 | | const uint8_t* src_u, |
748 | | int src_stride_u, |
749 | | const uint8_t* src_v, |
750 | | int src_stride_v, |
751 | | uint8_t* dst_abgr, |
752 | | int dst_stride_abgr, |
753 | | int width, |
754 | 0 | int height) { |
755 | 0 | return I444ToARGBMatrix(src_y, src_stride_y, src_v, |
756 | 0 | src_stride_v, // Swap U and V |
757 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
758 | 0 | &kYvuH709Constants, // Use Yvu matrix |
759 | 0 | width, height); |
760 | 0 | } |
761 | | |
762 | | // Convert U444 to ARGB. |
763 | | LIBYUV_API |
764 | | int U444ToARGB(const uint8_t* src_y, |
765 | | int src_stride_y, |
766 | | const uint8_t* src_u, |
767 | | int src_stride_u, |
768 | | const uint8_t* src_v, |
769 | | int src_stride_v, |
770 | | uint8_t* dst_argb, |
771 | | int dst_stride_argb, |
772 | | int width, |
773 | 0 | int height) { |
774 | 0 | return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
775 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
776 | 0 | &kYuv2020Constants, width, height); |
777 | 0 | } |
778 | | |
779 | | // Convert U444 to ABGR. |
780 | | LIBYUV_API |
781 | | int U444ToABGR(const uint8_t* src_y, |
782 | | int src_stride_y, |
783 | | const uint8_t* src_u, |
784 | | int src_stride_u, |
785 | | const uint8_t* src_v, |
786 | | int src_stride_v, |
787 | | uint8_t* dst_abgr, |
788 | | int dst_stride_abgr, |
789 | | int width, |
790 | 0 | int height) { |
791 | 0 | return I444ToARGBMatrix(src_y, src_stride_y, src_v, |
792 | 0 | src_stride_v, // Swap U and V |
793 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
794 | 0 | &kYvu2020Constants, // Use Yvu matrix |
795 | 0 | width, height); |
796 | 0 | } |
797 | | |
798 | | // Convert I444 to RGB24 with matrix. |
799 | | LIBYUV_API |
800 | | int I444ToRGB24Matrix(const uint8_t* src_y, |
801 | | int src_stride_y, |
802 | | const uint8_t* src_u, |
803 | | int src_stride_u, |
804 | | const uint8_t* src_v, |
805 | | int src_stride_v, |
806 | | uint8_t* dst_rgb24, |
807 | | int dst_stride_rgb24, |
808 | | const struct YuvConstants* yuvconstants, |
809 | | int width, |
810 | 127 | int height) { |
811 | 127 | int y; |
812 | 127 | void (*I444ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf, |
813 | 127 | const uint8_t* v_buf, uint8_t* rgb_buf, |
814 | 127 | const struct YuvConstants* yuvconstants, int width) = |
815 | 127 | I444ToRGB24Row_C; |
816 | 127 | assert(yuvconstants); |
817 | 127 | if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || |
818 | 127 | height == INT_MIN) { |
819 | 0 | return -1; |
820 | 0 | } |
821 | | // Negative height means invert the image. |
822 | 127 | if (height < 0) { |
823 | 0 | height = -height; |
824 | 0 | dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; |
825 | 0 | dst_stride_rgb24 = -dst_stride_rgb24; |
826 | 0 | } |
827 | | // Coalesce rows. |
828 | 127 | if (src_stride_y == width && src_stride_u == width && src_stride_v == width && |
829 | 127 | dst_stride_rgb24 == width * 3 && (ptrdiff_t)width * height <= INT_MAX) { |
830 | 127 | width *= height; |
831 | 127 | height = 1; |
832 | 127 | src_stride_y = src_stride_u = src_stride_v = dst_stride_rgb24 = 0; |
833 | 127 | } |
834 | 127 | #if defined(HAS_I444TORGB24ROW_SSSE3) |
835 | 127 | if (TestCpuFlag(kCpuHasSSSE3)) { |
836 | 127 | I444ToRGB24Row = I444ToRGB24Row_Any_SSSE3; |
837 | 127 | if (IS_ALIGNED(width, 16)) { |
838 | 50 | I444ToRGB24Row = I444ToRGB24Row_SSSE3; |
839 | 50 | } |
840 | 127 | } |
841 | 127 | #endif |
842 | 127 | #if defined(HAS_I444TORGB24ROW_AVX2) |
843 | 127 | if (TestCpuFlag(kCpuHasAVX2)) { |
844 | 127 | I444ToRGB24Row = I444ToRGB24Row_Any_AVX2; |
845 | 127 | if (IS_ALIGNED(width, 32)) { |
846 | 31 | I444ToRGB24Row = I444ToRGB24Row_AVX2; |
847 | 31 | } |
848 | 127 | } |
849 | 127 | #endif |
850 | | #if defined(HAS_I444TORGB24ROW_NEON) |
851 | | if (TestCpuFlag(kCpuHasNEON)) { |
852 | | I444ToRGB24Row = I444ToRGB24Row_Any_NEON; |
853 | | if (IS_ALIGNED(width, 8)) { |
854 | | I444ToRGB24Row = I444ToRGB24Row_NEON; |
855 | | } |
856 | | } |
857 | | #endif |
858 | | #if defined(HAS_I444TORGB24ROW_SVE2) |
859 | | if (TestCpuFlag(kCpuHasSVE2)) { |
860 | | I444ToRGB24Row = I444ToRGB24Row_SVE2; |
861 | | } |
862 | | #endif |
863 | | #if defined(HAS_I444TORGB24ROW_SME) |
864 | | if (TestCpuFlag(kCpuHasSME)) { |
865 | | I444ToRGB24Row = I444ToRGB24Row_SME; |
866 | | } |
867 | | #endif |
868 | | #if defined(HAS_I444TORGB24ROW_LSX) |
869 | | if (TestCpuFlag(kCpuHasLSX)) { |
870 | | I444ToRGB24Row = I444ToRGB24Row_Any_LSX; |
871 | | if (IS_ALIGNED(width, 16)) { |
872 | | I444ToRGB24Row = I444ToRGB24Row_LSX; |
873 | | } |
874 | | } |
875 | | #endif |
876 | | #if defined(HAS_I444TORGB24ROW_RVV) |
877 | | if (TestCpuFlag(kCpuHasRVV)) { |
878 | | I444ToRGB24Row = I444ToRGB24Row_RVV; |
879 | | } |
880 | | #endif |
881 | | |
882 | 254 | for (y = 0; y < height; ++y) { |
883 | 127 | I444ToRGB24Row(src_y, src_u, src_v, dst_rgb24, yuvconstants, width); |
884 | 127 | dst_rgb24 += dst_stride_rgb24; |
885 | 127 | src_y += src_stride_y; |
886 | 127 | src_u += src_stride_u; |
887 | 127 | src_v += src_stride_v; |
888 | 127 | } |
889 | 127 | return 0; |
890 | 127 | } |
891 | | |
892 | | // Convert I444 to RGB24. |
893 | | LIBYUV_API |
894 | | int I444ToRGB24(const uint8_t* src_y, |
895 | | int src_stride_y, |
896 | | const uint8_t* src_u, |
897 | | int src_stride_u, |
898 | | const uint8_t* src_v, |
899 | | int src_stride_v, |
900 | | uint8_t* dst_rgb24, |
901 | | int dst_stride_rgb24, |
902 | | int width, |
903 | 0 | int height) { |
904 | 0 | return I444ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
905 | 0 | src_stride_v, dst_rgb24, dst_stride_rgb24, |
906 | 0 | &kYuvI601Constants, width, height); |
907 | 0 | } |
908 | | |
909 | | // Convert I444 to RAW. |
910 | | LIBYUV_API |
911 | | int I444ToRAW(const uint8_t* src_y, |
912 | | int src_stride_y, |
913 | | const uint8_t* src_u, |
914 | | int src_stride_u, |
915 | | const uint8_t* src_v, |
916 | | int src_stride_v, |
917 | | uint8_t* dst_raw, |
918 | | int dst_stride_raw, |
919 | | int width, |
920 | 0 | int height) { |
921 | 0 | return I444ToRGB24Matrix(src_y, src_stride_y, src_v, |
922 | 0 | src_stride_v, // Swap U and V |
923 | 0 | src_u, src_stride_u, dst_raw, dst_stride_raw, |
924 | 0 | &kYvuI601Constants, // Use Yvu matrix |
925 | 0 | width, height); |
926 | 0 | } |
927 | | |
928 | | // Convert 10 bit YUV to ARGB with matrix. |
929 | | // TODO(fbarchard): Consider passing scale multiplier to I210ToARGB to |
930 | | // multiply 10 bit yuv into high bits to allow any number of bits. |
931 | | LIBYUV_API |
932 | | int I010ToAR30Matrix(const uint16_t* src_y, |
933 | | int src_stride_y, |
934 | | const uint16_t* src_u, |
935 | | int src_stride_u, |
936 | | const uint16_t* src_v, |
937 | | int src_stride_v, |
938 | | uint8_t* dst_ar30, |
939 | | int dst_stride_ar30, |
940 | | const struct YuvConstants* yuvconstants, |
941 | | int width, |
942 | 0 | int height) { |
943 | 0 | int y; |
944 | 0 | void (*I210ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf, |
945 | 0 | const uint16_t* v_buf, uint8_t* rgb_buf, |
946 | 0 | const struct YuvConstants* yuvconstants, int width) = |
947 | 0 | I210ToAR30Row_C; |
948 | 0 | assert(yuvconstants); |
949 | 0 | if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || |
950 | 0 | height == INT_MIN) { |
951 | 0 | return -1; |
952 | 0 | } |
953 | | // Negative height means invert the image. |
954 | 0 | if (height < 0) { |
955 | 0 | height = -height; |
956 | 0 | dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; |
957 | 0 | dst_stride_ar30 = -dst_stride_ar30; |
958 | 0 | } |
959 | | #if defined(HAS_I210TOAR30ROW_NEON) |
960 | | if (TestCpuFlag(kCpuHasNEON)) { |
961 | | I210ToAR30Row = I210ToAR30Row_Any_NEON; |
962 | | if (IS_ALIGNED(width, 8)) { |
963 | | I210ToAR30Row = I210ToAR30Row_NEON; |
964 | | } |
965 | | } |
966 | | #endif |
967 | | #if defined(HAS_I210TOAR30ROW_SVE2) |
968 | | if (TestCpuFlag(kCpuHasSVE2)) { |
969 | | I210ToAR30Row = I210ToAR30Row_SVE2; |
970 | | } |
971 | | #endif |
972 | | #if defined(HAS_I210TOAR30ROW_SME) |
973 | | if (TestCpuFlag(kCpuHasSME)) { |
974 | | I210ToAR30Row = I210ToAR30Row_SME; |
975 | | } |
976 | | #endif |
977 | 0 | #if defined(HAS_I210TOAR30ROW_SSSE3) |
978 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
979 | 0 | I210ToAR30Row = I210ToAR30Row_Any_SSSE3; |
980 | 0 | if (IS_ALIGNED(width, 8)) { |
981 | 0 | I210ToAR30Row = I210ToAR30Row_SSSE3; |
982 | 0 | } |
983 | 0 | } |
984 | 0 | #endif |
985 | 0 | #if defined(HAS_I210TOAR30ROW_AVX2) |
986 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
987 | 0 | I210ToAR30Row = I210ToAR30Row_Any_AVX2; |
988 | 0 | if (IS_ALIGNED(width, 16)) { |
989 | 0 | I210ToAR30Row = I210ToAR30Row_AVX2; |
990 | 0 | } |
991 | 0 | } |
992 | 0 | #endif |
993 | 0 | for (y = 0; y < height; ++y) { |
994 | 0 | I210ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width); |
995 | 0 | dst_ar30 += dst_stride_ar30; |
996 | 0 | src_y += src_stride_y; |
997 | 0 | if (y & 1) { |
998 | 0 | src_u += src_stride_u; |
999 | 0 | src_v += src_stride_v; |
1000 | 0 | } |
1001 | 0 | } |
1002 | 0 | return 0; |
1003 | 0 | } |
1004 | | |
1005 | | // Convert I010 to AR30. |
1006 | | LIBYUV_API |
1007 | | int I010ToAR30(const uint16_t* src_y, |
1008 | | int src_stride_y, |
1009 | | const uint16_t* src_u, |
1010 | | int src_stride_u, |
1011 | | const uint16_t* src_v, |
1012 | | int src_stride_v, |
1013 | | uint8_t* dst_ar30, |
1014 | | int dst_stride_ar30, |
1015 | | int width, |
1016 | 0 | int height) { |
1017 | 0 | return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
1018 | 0 | src_stride_v, dst_ar30, dst_stride_ar30, |
1019 | 0 | &kYuvI601Constants, width, height); |
1020 | 0 | } |
1021 | | |
1022 | | // Convert H010 to AR30. |
1023 | | LIBYUV_API |
1024 | | int H010ToAR30(const uint16_t* src_y, |
1025 | | int src_stride_y, |
1026 | | const uint16_t* src_u, |
1027 | | int src_stride_u, |
1028 | | const uint16_t* src_v, |
1029 | | int src_stride_v, |
1030 | | uint8_t* dst_ar30, |
1031 | | int dst_stride_ar30, |
1032 | | int width, |
1033 | 0 | int height) { |
1034 | 0 | return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
1035 | 0 | src_stride_v, dst_ar30, dst_stride_ar30, |
1036 | 0 | &kYuvH709Constants, width, height); |
1037 | 0 | } |
1038 | | |
1039 | | // Convert U010 to AR30. |
1040 | | LIBYUV_API |
1041 | | int U010ToAR30(const uint16_t* src_y, |
1042 | | int src_stride_y, |
1043 | | const uint16_t* src_u, |
1044 | | int src_stride_u, |
1045 | | const uint16_t* src_v, |
1046 | | int src_stride_v, |
1047 | | uint8_t* dst_ar30, |
1048 | | int dst_stride_ar30, |
1049 | | int width, |
1050 | 0 | int height) { |
1051 | 0 | return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
1052 | 0 | src_stride_v, dst_ar30, dst_stride_ar30, |
1053 | 0 | &kYuv2020Constants, width, height); |
1054 | 0 | } |
1055 | | |
1056 | | // Convert I010 to AB30. |
1057 | | LIBYUV_API |
1058 | | int I010ToAB30(const uint16_t* src_y, |
1059 | | int src_stride_y, |
1060 | | const uint16_t* src_u, |
1061 | | int src_stride_u, |
1062 | | const uint16_t* src_v, |
1063 | | int src_stride_v, |
1064 | | uint8_t* dst_ab30, |
1065 | | int dst_stride_ab30, |
1066 | | int width, |
1067 | 0 | int height) { |
1068 | 0 | return I010ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, |
1069 | 0 | src_stride_u, dst_ab30, dst_stride_ab30, |
1070 | 0 | &kYvuI601Constants, width, height); |
1071 | 0 | } |
1072 | | |
1073 | | // Convert H010 to AB30. |
1074 | | LIBYUV_API |
1075 | | int H010ToAB30(const uint16_t* src_y, |
1076 | | int src_stride_y, |
1077 | | const uint16_t* src_u, |
1078 | | int src_stride_u, |
1079 | | const uint16_t* src_v, |
1080 | | int src_stride_v, |
1081 | | uint8_t* dst_ab30, |
1082 | | int dst_stride_ab30, |
1083 | | int width, |
1084 | 0 | int height) { |
1085 | 0 | return I010ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, |
1086 | 0 | src_stride_u, dst_ab30, dst_stride_ab30, |
1087 | 0 | &kYvuH709Constants, width, height); |
1088 | 0 | } |
1089 | | |
1090 | | // Convert U010 to AB30. |
1091 | | LIBYUV_API |
1092 | | int U010ToAB30(const uint16_t* src_y, |
1093 | | int src_stride_y, |
1094 | | const uint16_t* src_u, |
1095 | | int src_stride_u, |
1096 | | const uint16_t* src_v, |
1097 | | int src_stride_v, |
1098 | | uint8_t* dst_ab30, |
1099 | | int dst_stride_ab30, |
1100 | | int width, |
1101 | 0 | int height) { |
1102 | 0 | return I010ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, |
1103 | 0 | src_stride_u, dst_ab30, dst_stride_ab30, |
1104 | 0 | &kYuv2020Constants, width, height); |
1105 | 0 | } |
1106 | | |
1107 | | // Convert 12 bit YUV to ARGB with matrix. |
1108 | | // TODO(fbarchard): Consider passing scale multiplier to I212ToARGB to |
1109 | | // multiply 12 bit yuv into high bits to allow any number of bits. |
1110 | | LIBYUV_API |
1111 | | int I012ToAR30Matrix(const uint16_t* src_y, |
1112 | | int src_stride_y, |
1113 | | const uint16_t* src_u, |
1114 | | int src_stride_u, |
1115 | | const uint16_t* src_v, |
1116 | | int src_stride_v, |
1117 | | uint8_t* dst_ar30, |
1118 | | int dst_stride_ar30, |
1119 | | const struct YuvConstants* yuvconstants, |
1120 | | int width, |
1121 | 0 | int height) { |
1122 | 0 | int y; |
1123 | 0 | void (*I212ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf, |
1124 | 0 | const uint16_t* v_buf, uint8_t* rgb_buf, |
1125 | 0 | const struct YuvConstants* yuvconstants, int width) = |
1126 | 0 | I212ToAR30Row_C; |
1127 | 0 | assert(yuvconstants); |
1128 | 0 | if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || |
1129 | 0 | height == INT_MIN) { |
1130 | 0 | return -1; |
1131 | 0 | } |
1132 | | // Negative height means invert the image. |
1133 | 0 | if (height < 0) { |
1134 | 0 | height = -height; |
1135 | 0 | dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; |
1136 | 0 | dst_stride_ar30 = -dst_stride_ar30; |
1137 | 0 | } |
1138 | 0 | #if defined(HAS_I212TOAR30ROW_SSSE3) |
1139 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
1140 | 0 | I212ToAR30Row = I212ToAR30Row_Any_SSSE3; |
1141 | 0 | if (IS_ALIGNED(width, 8)) { |
1142 | 0 | I212ToAR30Row = I212ToAR30Row_SSSE3; |
1143 | 0 | } |
1144 | 0 | } |
1145 | 0 | #endif |
1146 | 0 | #if defined(HAS_I212TOAR30ROW_AVX2) |
1147 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
1148 | 0 | I212ToAR30Row = I212ToAR30Row_Any_AVX2; |
1149 | 0 | if (IS_ALIGNED(width, 16)) { |
1150 | 0 | I212ToAR30Row = I212ToAR30Row_AVX2; |
1151 | 0 | } |
1152 | 0 | } |
1153 | 0 | #endif |
1154 | | #if defined(HAS_I212TOAR30ROW_NEON) |
1155 | | if (TestCpuFlag(kCpuHasNEON)) { |
1156 | | I212ToAR30Row = I212ToAR30Row_Any_NEON; |
1157 | | if (IS_ALIGNED(width, 8)) { |
1158 | | I212ToAR30Row = I212ToAR30Row_NEON; |
1159 | | } |
1160 | | } |
1161 | | #endif |
1162 | | #if defined(HAS_I212TOAR30ROW_SVE2) |
1163 | | if (TestCpuFlag(kCpuHasSVE2)) { |
1164 | | I212ToAR30Row = I212ToAR30Row_SVE2; |
1165 | | } |
1166 | | #endif |
1167 | | #if defined(HAS_I212TOAR30ROW_SME) |
1168 | | if (TestCpuFlag(kCpuHasSME)) { |
1169 | | I212ToAR30Row = I212ToAR30Row_SME; |
1170 | | } |
1171 | | #endif |
1172 | 0 | for (y = 0; y < height; ++y) { |
1173 | 0 | I212ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width); |
1174 | 0 | dst_ar30 += dst_stride_ar30; |
1175 | 0 | src_y += src_stride_y; |
1176 | 0 | if (y & 1) { |
1177 | 0 | src_u += src_stride_u; |
1178 | 0 | src_v += src_stride_v; |
1179 | 0 | } |
1180 | 0 | } |
1181 | 0 | return 0; |
1182 | 0 | } |
1183 | | |
1184 | | // Convert 10 bit YUV to ARGB with matrix. |
1185 | | // TODO(fbarchard): Consider passing scale multiplier to I210ToARGB to |
1186 | | // multiply 10 bit yuv into high bits to allow any number of bits. |
1187 | | LIBYUV_API |
1188 | | int I210ToAR30Matrix(const uint16_t* src_y, |
1189 | | int src_stride_y, |
1190 | | const uint16_t* src_u, |
1191 | | int src_stride_u, |
1192 | | const uint16_t* src_v, |
1193 | | int src_stride_v, |
1194 | | uint8_t* dst_ar30, |
1195 | | int dst_stride_ar30, |
1196 | | const struct YuvConstants* yuvconstants, |
1197 | | int width, |
1198 | 0 | int height) { |
1199 | 0 | int y; |
1200 | 0 | void (*I210ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf, |
1201 | 0 | const uint16_t* v_buf, uint8_t* rgb_buf, |
1202 | 0 | const struct YuvConstants* yuvconstants, int width) = |
1203 | 0 | I210ToAR30Row_C; |
1204 | 0 | assert(yuvconstants); |
1205 | 0 | if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || |
1206 | 0 | height == INT_MIN) { |
1207 | 0 | return -1; |
1208 | 0 | } |
1209 | | // Negative height means invert the image. |
1210 | 0 | if (height < 0) { |
1211 | 0 | height = -height; |
1212 | 0 | dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; |
1213 | 0 | dst_stride_ar30 = -dst_stride_ar30; |
1214 | 0 | } |
1215 | | #if defined(HAS_I210TOAR30ROW_NEON) |
1216 | | if (TestCpuFlag(kCpuHasNEON)) { |
1217 | | I210ToAR30Row = I210ToAR30Row_Any_NEON; |
1218 | | if (IS_ALIGNED(width, 8)) { |
1219 | | I210ToAR30Row = I210ToAR30Row_NEON; |
1220 | | } |
1221 | | } |
1222 | | #endif |
1223 | | #if defined(HAS_I210TOAR30ROW_SVE2) |
1224 | | if (TestCpuFlag(kCpuHasSVE2)) { |
1225 | | I210ToAR30Row = I210ToAR30Row_SVE2; |
1226 | | } |
1227 | | #endif |
1228 | | #if defined(HAS_I210TOAR30ROW_SME) |
1229 | | if (TestCpuFlag(kCpuHasSME)) { |
1230 | | I210ToAR30Row = I210ToAR30Row_SME; |
1231 | | } |
1232 | | #endif |
1233 | 0 | #if defined(HAS_I210TOAR30ROW_SSSE3) |
1234 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
1235 | 0 | I210ToAR30Row = I210ToAR30Row_Any_SSSE3; |
1236 | 0 | if (IS_ALIGNED(width, 8)) { |
1237 | 0 | I210ToAR30Row = I210ToAR30Row_SSSE3; |
1238 | 0 | } |
1239 | 0 | } |
1240 | 0 | #endif |
1241 | 0 | #if defined(HAS_I210TOAR30ROW_AVX2) |
1242 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
1243 | 0 | I210ToAR30Row = I210ToAR30Row_Any_AVX2; |
1244 | 0 | if (IS_ALIGNED(width, 16)) { |
1245 | 0 | I210ToAR30Row = I210ToAR30Row_AVX2; |
1246 | 0 | } |
1247 | 0 | } |
1248 | 0 | #endif |
1249 | 0 | for (y = 0; y < height; ++y) { |
1250 | 0 | I210ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width); |
1251 | 0 | dst_ar30 += dst_stride_ar30; |
1252 | 0 | src_y += src_stride_y; |
1253 | 0 | src_u += src_stride_u; |
1254 | 0 | src_v += src_stride_v; |
1255 | 0 | } |
1256 | 0 | return 0; |
1257 | 0 | } |
1258 | | |
1259 | | // Convert I210 to AR30. |
1260 | | LIBYUV_API |
1261 | | int I210ToAR30(const uint16_t* src_y, |
1262 | | int src_stride_y, |
1263 | | const uint16_t* src_u, |
1264 | | int src_stride_u, |
1265 | | const uint16_t* src_v, |
1266 | | int src_stride_v, |
1267 | | uint8_t* dst_ar30, |
1268 | | int dst_stride_ar30, |
1269 | | int width, |
1270 | 0 | int height) { |
1271 | 0 | return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
1272 | 0 | src_stride_v, dst_ar30, dst_stride_ar30, |
1273 | 0 | &kYuvI601Constants, width, height); |
1274 | 0 | } |
1275 | | |
1276 | | // Convert H210 to AR30. |
1277 | | LIBYUV_API |
1278 | | int H210ToAR30(const uint16_t* src_y, |
1279 | | int src_stride_y, |
1280 | | const uint16_t* src_u, |
1281 | | int src_stride_u, |
1282 | | const uint16_t* src_v, |
1283 | | int src_stride_v, |
1284 | | uint8_t* dst_ar30, |
1285 | | int dst_stride_ar30, |
1286 | | int width, |
1287 | 0 | int height) { |
1288 | 0 | return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
1289 | 0 | src_stride_v, dst_ar30, dst_stride_ar30, |
1290 | 0 | &kYuvH709Constants, width, height); |
1291 | 0 | } |
1292 | | |
1293 | | // Convert U210 to AR30. |
1294 | | LIBYUV_API |
1295 | | int U210ToAR30(const uint16_t* src_y, |
1296 | | int src_stride_y, |
1297 | | const uint16_t* src_u, |
1298 | | int src_stride_u, |
1299 | | const uint16_t* src_v, |
1300 | | int src_stride_v, |
1301 | | uint8_t* dst_ar30, |
1302 | | int dst_stride_ar30, |
1303 | | int width, |
1304 | 0 | int height) { |
1305 | 0 | return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
1306 | 0 | src_stride_v, dst_ar30, dst_stride_ar30, |
1307 | 0 | &kYuv2020Constants, width, height); |
1308 | 0 | } |
1309 | | |
1310 | | // Convert I210 to AB30. |
1311 | | LIBYUV_API |
1312 | | int I210ToAB30(const uint16_t* src_y, |
1313 | | int src_stride_y, |
1314 | | const uint16_t* src_u, |
1315 | | int src_stride_u, |
1316 | | const uint16_t* src_v, |
1317 | | int src_stride_v, |
1318 | | uint8_t* dst_ab30, |
1319 | | int dst_stride_ab30, |
1320 | | int width, |
1321 | 0 | int height) { |
1322 | 0 | return I210ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, |
1323 | 0 | src_stride_u, dst_ab30, dst_stride_ab30, |
1324 | 0 | &kYvuI601Constants, width, height); |
1325 | 0 | } |
1326 | | |
1327 | | // Convert H210 to AB30. |
1328 | | LIBYUV_API |
1329 | | int H210ToAB30(const uint16_t* src_y, |
1330 | | int src_stride_y, |
1331 | | const uint16_t* src_u, |
1332 | | int src_stride_u, |
1333 | | const uint16_t* src_v, |
1334 | | int src_stride_v, |
1335 | | uint8_t* dst_ab30, |
1336 | | int dst_stride_ab30, |
1337 | | int width, |
1338 | 0 | int height) { |
1339 | 0 | return I210ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, |
1340 | 0 | src_stride_u, dst_ab30, dst_stride_ab30, |
1341 | 0 | &kYvuH709Constants, width, height); |
1342 | 0 | } |
1343 | | |
1344 | | // Convert U210 to AB30. |
1345 | | LIBYUV_API |
1346 | | int U210ToAB30(const uint16_t* src_y, |
1347 | | int src_stride_y, |
1348 | | const uint16_t* src_u, |
1349 | | int src_stride_u, |
1350 | | const uint16_t* src_v, |
1351 | | int src_stride_v, |
1352 | | uint8_t* dst_ab30, |
1353 | | int dst_stride_ab30, |
1354 | | int width, |
1355 | 0 | int height) { |
1356 | 0 | return I210ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, |
1357 | 0 | src_stride_u, dst_ab30, dst_stride_ab30, |
1358 | 0 | &kYuv2020Constants, width, height); |
1359 | 0 | } |
1360 | | |
1361 | | LIBYUV_API |
1362 | | int I410ToAR30Matrix(const uint16_t* src_y, |
1363 | | int src_stride_y, |
1364 | | const uint16_t* src_u, |
1365 | | int src_stride_u, |
1366 | | const uint16_t* src_v, |
1367 | | int src_stride_v, |
1368 | | uint8_t* dst_ar30, |
1369 | | int dst_stride_ar30, |
1370 | | const struct YuvConstants* yuvconstants, |
1371 | | int width, |
1372 | 0 | int height) { |
1373 | 0 | int y; |
1374 | 0 | void (*I410ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf, |
1375 | 0 | const uint16_t* v_buf, uint8_t* rgb_buf, |
1376 | 0 | const struct YuvConstants* yuvconstants, int width) = |
1377 | 0 | I410ToAR30Row_C; |
1378 | 0 | assert(yuvconstants); |
1379 | 0 | if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || |
1380 | 0 | height == INT_MIN) { |
1381 | 0 | return -1; |
1382 | 0 | } |
1383 | | // Negative height means invert the image. |
1384 | 0 | if (height < 0) { |
1385 | 0 | height = -height; |
1386 | 0 | dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; |
1387 | 0 | dst_stride_ar30 = -dst_stride_ar30; |
1388 | 0 | } |
1389 | | #if defined(HAS_I410TOAR30ROW_NEON) |
1390 | | if (TestCpuFlag(kCpuHasNEON)) { |
1391 | | I410ToAR30Row = I410ToAR30Row_Any_NEON; |
1392 | | if (IS_ALIGNED(width, 8)) { |
1393 | | I410ToAR30Row = I410ToAR30Row_NEON; |
1394 | | } |
1395 | | } |
1396 | | #endif |
1397 | | #if defined(HAS_I410TOAR30ROW_SVE2) |
1398 | | if (TestCpuFlag(kCpuHasSVE2)) { |
1399 | | I410ToAR30Row = I410ToAR30Row_SVE2; |
1400 | | } |
1401 | | #endif |
1402 | | #if defined(HAS_I410TOAR30ROW_SME) |
1403 | | if (TestCpuFlag(kCpuHasSME)) { |
1404 | | I410ToAR30Row = I410ToAR30Row_SME; |
1405 | | } |
1406 | | #endif |
1407 | 0 | #if defined(HAS_I410TOAR30ROW_SSSE3) |
1408 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
1409 | 0 | I410ToAR30Row = I410ToAR30Row_Any_SSSE3; |
1410 | 0 | if (IS_ALIGNED(width, 8)) { |
1411 | 0 | I410ToAR30Row = I410ToAR30Row_SSSE3; |
1412 | 0 | } |
1413 | 0 | } |
1414 | 0 | #endif |
1415 | 0 | #if defined(HAS_I410TOAR30ROW_AVX2) |
1416 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
1417 | 0 | I410ToAR30Row = I410ToAR30Row_Any_AVX2; |
1418 | 0 | if (IS_ALIGNED(width, 16)) { |
1419 | 0 | I410ToAR30Row = I410ToAR30Row_AVX2; |
1420 | 0 | } |
1421 | 0 | } |
1422 | 0 | #endif |
1423 | 0 | for (y = 0; y < height; ++y) { |
1424 | 0 | I410ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width); |
1425 | 0 | dst_ar30 += dst_stride_ar30; |
1426 | 0 | src_y += src_stride_y; |
1427 | 0 | src_u += src_stride_u; |
1428 | 0 | src_v += src_stride_v; |
1429 | 0 | } |
1430 | 0 | return 0; |
1431 | 0 | } |
1432 | | |
1433 | | // Convert 10 bit YUV to ARGB with matrix. |
1434 | | LIBYUV_API |
1435 | | int I010ToARGBMatrix(const uint16_t* src_y, |
1436 | | int src_stride_y, |
1437 | | const uint16_t* src_u, |
1438 | | int src_stride_u, |
1439 | | const uint16_t* src_v, |
1440 | | int src_stride_v, |
1441 | | uint8_t* dst_argb, |
1442 | | int dst_stride_argb, |
1443 | | const struct YuvConstants* yuvconstants, |
1444 | | int width, |
1445 | 110 | int height) { |
1446 | 110 | int y; |
1447 | 110 | void (*I210ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, |
1448 | 110 | const uint16_t* v_buf, uint8_t* rgb_buf, |
1449 | 110 | const struct YuvConstants* yuvconstants, int width) = |
1450 | 110 | I210ToARGBRow_C; |
1451 | 110 | assert(yuvconstants); |
1452 | 110 | if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || |
1453 | 110 | height == INT_MIN) { |
1454 | 0 | return -1; |
1455 | 0 | } |
1456 | | // Negative height means invert the image. |
1457 | 110 | if (height < 0) { |
1458 | 0 | height = -height; |
1459 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
1460 | 0 | dst_stride_argb = -dst_stride_argb; |
1461 | 0 | } |
1462 | 110 | #if defined(HAS_I210TOARGBROW_SSSE3) |
1463 | 110 | if (TestCpuFlag(kCpuHasSSSE3)) { |
1464 | 110 | I210ToARGBRow = I210ToARGBRow_Any_SSSE3; |
1465 | 110 | if (IS_ALIGNED(width, 8)) { |
1466 | 34 | I210ToARGBRow = I210ToARGBRow_SSSE3; |
1467 | 34 | } |
1468 | 110 | } |
1469 | 110 | #endif |
1470 | | #if defined(HAS_I210TOARGBROW_NEON) |
1471 | | if (TestCpuFlag(kCpuHasNEON)) { |
1472 | | I210ToARGBRow = I210ToARGBRow_Any_NEON; |
1473 | | if (IS_ALIGNED(width, 8)) { |
1474 | | I210ToARGBRow = I210ToARGBRow_NEON; |
1475 | | } |
1476 | | } |
1477 | | #endif |
1478 | | #if defined(HAS_I210TOARGBROW_SVE2) |
1479 | | if (TestCpuFlag(kCpuHasSVE2)) { |
1480 | | I210ToARGBRow = I210ToARGBRow_SVE2; |
1481 | | } |
1482 | | #endif |
1483 | | #if defined(HAS_I210TOARGBROW_SME) |
1484 | | if (TestCpuFlag(kCpuHasSME)) { |
1485 | | I210ToARGBRow = I210ToARGBRow_SME; |
1486 | | } |
1487 | | #endif |
1488 | 110 | #if defined(HAS_I210TOARGBROW_AVX2) |
1489 | 110 | if (TestCpuFlag(kCpuHasAVX2)) { |
1490 | 110 | I210ToARGBRow = I210ToARGBRow_Any_AVX2; |
1491 | 110 | if (IS_ALIGNED(width, 16)) { |
1492 | 17 | I210ToARGBRow = I210ToARGBRow_AVX2; |
1493 | 17 | } |
1494 | 110 | } |
1495 | 110 | #endif |
1496 | 1.63k | for (y = 0; y < height; ++y) { |
1497 | 1.52k | I210ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); |
1498 | 1.52k | dst_argb += dst_stride_argb; |
1499 | 1.52k | src_y += src_stride_y; |
1500 | 1.52k | if (y & 1) { |
1501 | 748 | src_u += src_stride_u; |
1502 | 748 | src_v += src_stride_v; |
1503 | 748 | } |
1504 | 1.52k | } |
1505 | 110 | return 0; |
1506 | 110 | } |
1507 | | |
1508 | | // Convert I010 to ARGB. |
1509 | | LIBYUV_API |
1510 | | int I010ToARGB(const uint16_t* src_y, |
1511 | | int src_stride_y, |
1512 | | const uint16_t* src_u, |
1513 | | int src_stride_u, |
1514 | | const uint16_t* src_v, |
1515 | | int src_stride_v, |
1516 | | uint8_t* dst_argb, |
1517 | | int dst_stride_argb, |
1518 | | int width, |
1519 | 0 | int height) { |
1520 | 0 | return I010ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
1521 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
1522 | 0 | &kYuvI601Constants, width, height); |
1523 | 0 | } |
1524 | | |
1525 | | // Convert I010 to ABGR. |
1526 | | LIBYUV_API |
1527 | | int I010ToABGR(const uint16_t* src_y, |
1528 | | int src_stride_y, |
1529 | | const uint16_t* src_u, |
1530 | | int src_stride_u, |
1531 | | const uint16_t* src_v, |
1532 | | int src_stride_v, |
1533 | | uint8_t* dst_abgr, |
1534 | | int dst_stride_abgr, |
1535 | | int width, |
1536 | 0 | int height) { |
1537 | 0 | return I010ToARGBMatrix(src_y, src_stride_y, src_v, |
1538 | 0 | src_stride_v, // Swap U and V |
1539 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
1540 | 0 | &kYvuI601Constants, // Use Yvu matrix |
1541 | 0 | width, height); |
1542 | 0 | } |
1543 | | |
1544 | | // Convert H010 to ARGB. |
1545 | | LIBYUV_API |
1546 | | int H010ToARGB(const uint16_t* src_y, |
1547 | | int src_stride_y, |
1548 | | const uint16_t* src_u, |
1549 | | int src_stride_u, |
1550 | | const uint16_t* src_v, |
1551 | | int src_stride_v, |
1552 | | uint8_t* dst_argb, |
1553 | | int dst_stride_argb, |
1554 | | int width, |
1555 | 0 | int height) { |
1556 | 0 | return I010ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
1557 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
1558 | 0 | &kYuvH709Constants, width, height); |
1559 | 0 | } |
1560 | | |
1561 | | // Convert H010 to ABGR. |
1562 | | LIBYUV_API |
1563 | | int H010ToABGR(const uint16_t* src_y, |
1564 | | int src_stride_y, |
1565 | | const uint16_t* src_u, |
1566 | | int src_stride_u, |
1567 | | const uint16_t* src_v, |
1568 | | int src_stride_v, |
1569 | | uint8_t* dst_abgr, |
1570 | | int dst_stride_abgr, |
1571 | | int width, |
1572 | 0 | int height) { |
1573 | 0 | return I010ToARGBMatrix(src_y, src_stride_y, src_v, |
1574 | 0 | src_stride_v, // Swap U and V |
1575 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
1576 | 0 | &kYvuH709Constants, // Use Yvu matrix |
1577 | 0 | width, height); |
1578 | 0 | } |
1579 | | |
1580 | | // Convert U010 to ARGB. |
1581 | | LIBYUV_API |
1582 | | int U010ToARGB(const uint16_t* src_y, |
1583 | | int src_stride_y, |
1584 | | const uint16_t* src_u, |
1585 | | int src_stride_u, |
1586 | | const uint16_t* src_v, |
1587 | | int src_stride_v, |
1588 | | uint8_t* dst_argb, |
1589 | | int dst_stride_argb, |
1590 | | int width, |
1591 | 0 | int height) { |
1592 | 0 | return I010ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
1593 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
1594 | 0 | &kYuv2020Constants, width, height); |
1595 | 0 | } |
1596 | | |
1597 | | // Convert U010 to ABGR. |
1598 | | LIBYUV_API |
1599 | | int U010ToABGR(const uint16_t* src_y, |
1600 | | int src_stride_y, |
1601 | | const uint16_t* src_u, |
1602 | | int src_stride_u, |
1603 | | const uint16_t* src_v, |
1604 | | int src_stride_v, |
1605 | | uint8_t* dst_abgr, |
1606 | | int dst_stride_abgr, |
1607 | | int width, |
1608 | 0 | int height) { |
1609 | 0 | return I010ToARGBMatrix(src_y, src_stride_y, src_v, |
1610 | 0 | src_stride_v, // Swap U and V |
1611 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
1612 | 0 | &kYvu2020Constants, // Use Yvu matrix |
1613 | 0 | width, height); |
1614 | 0 | } |
1615 | | |
1616 | | // Convert 12 bit YUV to ARGB with matrix. |
1617 | | LIBYUV_API |
1618 | | int I012ToARGBMatrix(const uint16_t* src_y, |
1619 | | int src_stride_y, |
1620 | | const uint16_t* src_u, |
1621 | | int src_stride_u, |
1622 | | const uint16_t* src_v, |
1623 | | int src_stride_v, |
1624 | | uint8_t* dst_argb, |
1625 | | int dst_stride_argb, |
1626 | | const struct YuvConstants* yuvconstants, |
1627 | | int width, |
1628 | 131 | int height) { |
1629 | 131 | int y; |
1630 | 131 | void (*I212ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, |
1631 | 131 | const uint16_t* v_buf, uint8_t* rgb_buf, |
1632 | 131 | const struct YuvConstants* yuvconstants, int width) = |
1633 | 131 | I212ToARGBRow_C; |
1634 | 131 | assert(yuvconstants); |
1635 | 131 | if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || |
1636 | 131 | height == INT_MIN) { |
1637 | 0 | return -1; |
1638 | 0 | } |
1639 | | // Negative height means invert the image. |
1640 | 131 | if (height < 0) { |
1641 | 0 | height = -height; |
1642 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
1643 | 0 | dst_stride_argb = -dst_stride_argb; |
1644 | 0 | } |
1645 | 131 | #if defined(HAS_I212TOARGBROW_SSSE3) |
1646 | 131 | if (TestCpuFlag(kCpuHasSSSE3)) { |
1647 | 131 | I212ToARGBRow = I212ToARGBRow_Any_SSSE3; |
1648 | 131 | if (IS_ALIGNED(width, 8)) { |
1649 | 36 | I212ToARGBRow = I212ToARGBRow_SSSE3; |
1650 | 36 | } |
1651 | 131 | } |
1652 | 131 | #endif |
1653 | 131 | #if defined(HAS_I212TOARGBROW_AVX2) |
1654 | 131 | if (TestCpuFlag(kCpuHasAVX2)) { |
1655 | 131 | I212ToARGBRow = I212ToARGBRow_Any_AVX2; |
1656 | 131 | if (IS_ALIGNED(width, 16)) { |
1657 | 19 | I212ToARGBRow = I212ToARGBRow_AVX2; |
1658 | 19 | } |
1659 | 131 | } |
1660 | 131 | #endif |
1661 | | #if defined(HAS_I212TOARGBROW_NEON) |
1662 | | if (TestCpuFlag(kCpuHasNEON)) { |
1663 | | I212ToARGBRow = I212ToARGBRow_Any_NEON; |
1664 | | if (IS_ALIGNED(width, 8)) { |
1665 | | I212ToARGBRow = I212ToARGBRow_NEON; |
1666 | | } |
1667 | | } |
1668 | | #endif |
1669 | | #if defined(HAS_I212TOARGBROW_SVE2) |
1670 | | if (TestCpuFlag(kCpuHasSVE2)) { |
1671 | | I212ToARGBRow = I212ToARGBRow_SVE2; |
1672 | | } |
1673 | | #endif |
1674 | | #if defined(HAS_I212TOARGBROW_SME) |
1675 | | if (TestCpuFlag(kCpuHasSME)) { |
1676 | | I212ToARGBRow = I212ToARGBRow_SME; |
1677 | | } |
1678 | | #endif |
1679 | 5.13k | for (y = 0; y < height; ++y) { |
1680 | 5.00k | I212ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); |
1681 | 5.00k | dst_argb += dst_stride_argb; |
1682 | 5.00k | src_y += src_stride_y; |
1683 | 5.00k | if (y & 1) { |
1684 | 2.47k | src_u += src_stride_u; |
1685 | 2.47k | src_v += src_stride_v; |
1686 | 2.47k | } |
1687 | 5.00k | } |
1688 | 131 | return 0; |
1689 | 131 | } |
1690 | | |
1691 | | // Convert 10 bit 422 YUV to ARGB with matrix. |
1692 | | LIBYUV_API |
1693 | | int I210ToARGBMatrix(const uint16_t* src_y, |
1694 | | int src_stride_y, |
1695 | | const uint16_t* src_u, |
1696 | | int src_stride_u, |
1697 | | const uint16_t* src_v, |
1698 | | int src_stride_v, |
1699 | | uint8_t* dst_argb, |
1700 | | int dst_stride_argb, |
1701 | | const struct YuvConstants* yuvconstants, |
1702 | | int width, |
1703 | 73 | int height) { |
1704 | 73 | int y; |
1705 | 73 | void (*I210ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, |
1706 | 73 | const uint16_t* v_buf, uint8_t* rgb_buf, |
1707 | 73 | const struct YuvConstants* yuvconstants, int width) = |
1708 | 73 | I210ToARGBRow_C; |
1709 | 73 | assert(yuvconstants); |
1710 | 73 | if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || |
1711 | 73 | height == INT_MIN) { |
1712 | 0 | return -1; |
1713 | 0 | } |
1714 | | // Negative height means invert the image. |
1715 | 73 | if (height < 0) { |
1716 | 0 | height = -height; |
1717 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
1718 | 0 | dst_stride_argb = -dst_stride_argb; |
1719 | 0 | } |
1720 | 73 | #if defined(HAS_I210TOARGBROW_SSSE3) |
1721 | 73 | if (TestCpuFlag(kCpuHasSSSE3)) { |
1722 | 72 | I210ToARGBRow = I210ToARGBRow_Any_SSSE3; |
1723 | 72 | if (IS_ALIGNED(width, 8)) { |
1724 | 34 | I210ToARGBRow = I210ToARGBRow_SSSE3; |
1725 | 34 | } |
1726 | 72 | } |
1727 | 73 | #endif |
1728 | | #if defined(HAS_I210TOARGBROW_NEON) |
1729 | | if (TestCpuFlag(kCpuHasNEON)) { |
1730 | | I210ToARGBRow = I210ToARGBRow_Any_NEON; |
1731 | | if (IS_ALIGNED(width, 8)) { |
1732 | | I210ToARGBRow = I210ToARGBRow_NEON; |
1733 | | } |
1734 | | } |
1735 | | #endif |
1736 | | #if defined(HAS_I210TOARGBROW_SVE2) |
1737 | | if (TestCpuFlag(kCpuHasSVE2)) { |
1738 | | I210ToARGBRow = I210ToARGBRow_SVE2; |
1739 | | } |
1740 | | #endif |
1741 | | #if defined(HAS_I210TOARGBROW_SME) |
1742 | | if (TestCpuFlag(kCpuHasSME)) { |
1743 | | I210ToARGBRow = I210ToARGBRow_SME; |
1744 | | } |
1745 | | #endif |
1746 | 73 | #if defined(HAS_I210TOARGBROW_AVX2) |
1747 | 73 | if (TestCpuFlag(kCpuHasAVX2)) { |
1748 | 72 | I210ToARGBRow = I210ToARGBRow_Any_AVX2; |
1749 | 72 | if (IS_ALIGNED(width, 16)) { |
1750 | 17 | I210ToARGBRow = I210ToARGBRow_AVX2; |
1751 | 17 | } |
1752 | 72 | } |
1753 | 73 | #endif |
1754 | 1.53k | for (y = 0; y < height; ++y) { |
1755 | 1.45k | I210ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); |
1756 | 1.45k | dst_argb += dst_stride_argb; |
1757 | 1.45k | src_y += src_stride_y; |
1758 | 1.45k | src_u += src_stride_u; |
1759 | 1.45k | src_v += src_stride_v; |
1760 | 1.45k | } |
1761 | 73 | return 0; |
1762 | 73 | } |
1763 | | |
1764 | | // Convert I210 to ARGB. |
1765 | | LIBYUV_API |
1766 | | int I210ToARGB(const uint16_t* src_y, |
1767 | | int src_stride_y, |
1768 | | const uint16_t* src_u, |
1769 | | int src_stride_u, |
1770 | | const uint16_t* src_v, |
1771 | | int src_stride_v, |
1772 | | uint8_t* dst_argb, |
1773 | | int dst_stride_argb, |
1774 | | int width, |
1775 | 0 | int height) { |
1776 | 0 | return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
1777 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
1778 | 0 | &kYuvI601Constants, width, height); |
1779 | 0 | } |
1780 | | |
1781 | | // Convert I210 to ABGR. |
1782 | | LIBYUV_API |
1783 | | int I210ToABGR(const uint16_t* src_y, |
1784 | | int src_stride_y, |
1785 | | const uint16_t* src_u, |
1786 | | int src_stride_u, |
1787 | | const uint16_t* src_v, |
1788 | | int src_stride_v, |
1789 | | uint8_t* dst_abgr, |
1790 | | int dst_stride_abgr, |
1791 | | int width, |
1792 | 0 | int height) { |
1793 | 0 | return I210ToARGBMatrix(src_y, src_stride_y, src_v, |
1794 | 0 | src_stride_v, // Swap U and V |
1795 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
1796 | 0 | &kYvuI601Constants, // Use Yvu matrix |
1797 | 0 | width, height); |
1798 | 0 | } |
1799 | | |
1800 | | // Convert H210 to ARGB. |
1801 | | LIBYUV_API |
1802 | | int H210ToARGB(const uint16_t* src_y, |
1803 | | int src_stride_y, |
1804 | | const uint16_t* src_u, |
1805 | | int src_stride_u, |
1806 | | const uint16_t* src_v, |
1807 | | int src_stride_v, |
1808 | | uint8_t* dst_argb, |
1809 | | int dst_stride_argb, |
1810 | | int width, |
1811 | 0 | int height) { |
1812 | 0 | return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
1813 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
1814 | 0 | &kYuvH709Constants, width, height); |
1815 | 0 | } |
1816 | | |
1817 | | // Convert H210 to ABGR. |
1818 | | LIBYUV_API |
1819 | | int H210ToABGR(const uint16_t* src_y, |
1820 | | int src_stride_y, |
1821 | | const uint16_t* src_u, |
1822 | | int src_stride_u, |
1823 | | const uint16_t* src_v, |
1824 | | int src_stride_v, |
1825 | | uint8_t* dst_abgr, |
1826 | | int dst_stride_abgr, |
1827 | | int width, |
1828 | 0 | int height) { |
1829 | 0 | return I210ToARGBMatrix(src_y, src_stride_y, src_v, |
1830 | 0 | src_stride_v, // Swap U and V |
1831 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
1832 | 0 | &kYvuH709Constants, // Use Yvu matrix |
1833 | 0 | width, height); |
1834 | 0 | } |
1835 | | |
1836 | | // Convert U210 to ARGB. |
1837 | | LIBYUV_API |
1838 | | int U210ToARGB(const uint16_t* src_y, |
1839 | | int src_stride_y, |
1840 | | const uint16_t* src_u, |
1841 | | int src_stride_u, |
1842 | | const uint16_t* src_v, |
1843 | | int src_stride_v, |
1844 | | uint8_t* dst_argb, |
1845 | | int dst_stride_argb, |
1846 | | int width, |
1847 | 0 | int height) { |
1848 | 0 | return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
1849 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
1850 | 0 | &kYuv2020Constants, width, height); |
1851 | 0 | } |
1852 | | |
1853 | | // Convert U210 to ABGR. |
1854 | | LIBYUV_API |
1855 | | int U210ToABGR(const uint16_t* src_y, |
1856 | | int src_stride_y, |
1857 | | const uint16_t* src_u, |
1858 | | int src_stride_u, |
1859 | | const uint16_t* src_v, |
1860 | | int src_stride_v, |
1861 | | uint8_t* dst_abgr, |
1862 | | int dst_stride_abgr, |
1863 | | int width, |
1864 | 0 | int height) { |
1865 | 0 | return I210ToARGBMatrix(src_y, src_stride_y, src_v, |
1866 | 0 | src_stride_v, // Swap U and V |
1867 | 0 | src_u, src_stride_u, dst_abgr, dst_stride_abgr, |
1868 | 0 | &kYvu2020Constants, // Use Yvu matrix |
1869 | 0 | width, height); |
1870 | 0 | } |
1871 | | |
1872 | | LIBYUV_API |
1873 | | int I410ToARGBMatrix(const uint16_t* src_y, |
1874 | | int src_stride_y, |
1875 | | const uint16_t* src_u, |
1876 | | int src_stride_u, |
1877 | | const uint16_t* src_v, |
1878 | | int src_stride_v, |
1879 | | uint8_t* dst_argb, |
1880 | | int dst_stride_argb, |
1881 | | const struct YuvConstants* yuvconstants, |
1882 | | int width, |
1883 | 64 | int height) { |
1884 | 64 | int y; |
1885 | 64 | void (*I410ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, |
1886 | 64 | const uint16_t* v_buf, uint8_t* rgb_buf, |
1887 | 64 | const struct YuvConstants* yuvconstants, int width) = |
1888 | 64 | I410ToARGBRow_C; |
1889 | 64 | assert(yuvconstants); |
1890 | 64 | if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || |
1891 | 64 | height == INT_MIN) { |
1892 | 0 | return -1; |
1893 | 0 | } |
1894 | | // Negative height means invert the image. |
1895 | 64 | if (height < 0) { |
1896 | 0 | height = -height; |
1897 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
1898 | 0 | dst_stride_argb = -dst_stride_argb; |
1899 | 0 | } |
1900 | 64 | #if defined(HAS_I410TOARGBROW_SSSE3) |
1901 | 64 | if (TestCpuFlag(kCpuHasSSSE3)) { |
1902 | 64 | I410ToARGBRow = I410ToARGBRow_Any_SSSE3; |
1903 | 64 | if (IS_ALIGNED(width, 8)) { |
1904 | 35 | I410ToARGBRow = I410ToARGBRow_SSSE3; |
1905 | 35 | } |
1906 | 64 | } |
1907 | 64 | #endif |
1908 | | #if defined(HAS_I410TOARGBROW_NEON) |
1909 | | if (TestCpuFlag(kCpuHasNEON)) { |
1910 | | I410ToARGBRow = I410ToARGBRow_Any_NEON; |
1911 | | if (IS_ALIGNED(width, 8)) { |
1912 | | I410ToARGBRow = I410ToARGBRow_NEON; |
1913 | | } |
1914 | | } |
1915 | | #endif |
1916 | | #if defined(HAS_I410TOARGBROW_SVE2) |
1917 | | if (TestCpuFlag(kCpuHasSVE2)) { |
1918 | | I410ToARGBRow = I410ToARGBRow_SVE2; |
1919 | | } |
1920 | | #endif |
1921 | | #if defined(HAS_I410TOARGBROW_SME) |
1922 | | if (TestCpuFlag(kCpuHasSME)) { |
1923 | | I410ToARGBRow = I410ToARGBRow_SME; |
1924 | | } |
1925 | | #endif |
1926 | 64 | #if defined(HAS_I410TOARGBROW_AVX2) |
1927 | 64 | if (TestCpuFlag(kCpuHasAVX2)) { |
1928 | 64 | I410ToARGBRow = I410ToARGBRow_Any_AVX2; |
1929 | 64 | if (IS_ALIGNED(width, 16)) { |
1930 | 18 | I410ToARGBRow = I410ToARGBRow_AVX2; |
1931 | 18 | } |
1932 | 64 | } |
1933 | 64 | #endif |
1934 | 553 | for (y = 0; y < height; ++y) { |
1935 | 489 | I410ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); |
1936 | 489 | dst_argb += dst_stride_argb; |
1937 | 489 | src_y += src_stride_y; |
1938 | 489 | src_u += src_stride_u; |
1939 | 489 | src_v += src_stride_v; |
1940 | 489 | } |
1941 | 64 | return 0; |
1942 | 64 | } |
1943 | | |
1944 | | LIBYUV_API |
1945 | | int P010ToARGBMatrix(const uint16_t* src_y, |
1946 | | int src_stride_y, |
1947 | | const uint16_t* src_uv, |
1948 | | int src_stride_uv, |
1949 | | uint8_t* dst_argb, |
1950 | | int dst_stride_argb, |
1951 | | const struct YuvConstants* yuvconstants, |
1952 | | int width, |
1953 | 0 | int height) { |
1954 | 0 | int y; |
1955 | 0 | void (*P210ToARGBRow)( |
1956 | 0 | const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, |
1957 | 0 | const struct YuvConstants* yuvconstants, int width) = P210ToARGBRow_C; |
1958 | 0 | assert(yuvconstants); |
1959 | 0 | if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || |
1960 | 0 | height == INT_MIN) { |
1961 | 0 | return -1; |
1962 | 0 | } |
1963 | | // Negative height means invert the image. |
1964 | 0 | if (height < 0) { |
1965 | 0 | height = -height; |
1966 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
1967 | 0 | dst_stride_argb = -dst_stride_argb; |
1968 | 0 | } |
1969 | 0 | #if defined(HAS_P210TOARGBROW_SSSE3) |
1970 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
1971 | 0 | P210ToARGBRow = P210ToARGBRow_Any_SSSE3; |
1972 | 0 | if (IS_ALIGNED(width, 8)) { |
1973 | 0 | P210ToARGBRow = P210ToARGBRow_SSSE3; |
1974 | 0 | } |
1975 | 0 | } |
1976 | 0 | #endif |
1977 | 0 | #if defined(HAS_P210TOARGBROW_AVX2) |
1978 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
1979 | 0 | P210ToARGBRow = P210ToARGBRow_Any_AVX2; |
1980 | 0 | if (IS_ALIGNED(width, 16)) { |
1981 | 0 | P210ToARGBRow = P210ToARGBRow_AVX2; |
1982 | 0 | } |
1983 | 0 | } |
1984 | 0 | #endif |
1985 | | #if defined(HAS_P210TOARGBROW_NEON) |
1986 | | if (TestCpuFlag(kCpuHasNEON)) { |
1987 | | P210ToARGBRow = P210ToARGBRow_Any_NEON; |
1988 | | if (IS_ALIGNED(width, 8)) { |
1989 | | P210ToARGBRow = P210ToARGBRow_NEON; |
1990 | | } |
1991 | | } |
1992 | | #endif |
1993 | | #if defined(HAS_P210TOARGBROW_SVE2) |
1994 | | if (TestCpuFlag(kCpuHasSVE2)) { |
1995 | | P210ToARGBRow = P210ToARGBRow_SVE2; |
1996 | | } |
1997 | | #endif |
1998 | | #if defined(HAS_P210TOARGBROW_SME) |
1999 | | if (TestCpuFlag(kCpuHasSME)) { |
2000 | | P210ToARGBRow = P210ToARGBRow_SME; |
2001 | | } |
2002 | | #endif |
2003 | 0 | for (y = 0; y < height; ++y) { |
2004 | 0 | P210ToARGBRow(src_y, src_uv, dst_argb, yuvconstants, width); |
2005 | 0 | dst_argb += dst_stride_argb; |
2006 | 0 | src_y += src_stride_y; |
2007 | 0 | if (y & 1) { |
2008 | 0 | src_uv += src_stride_uv; |
2009 | 0 | } |
2010 | 0 | } |
2011 | 0 | return 0; |
2012 | 0 | } |
2013 | | |
2014 | | LIBYUV_API |
2015 | | int P210ToARGBMatrix(const uint16_t* src_y, |
2016 | | int src_stride_y, |
2017 | | const uint16_t* src_uv, |
2018 | | int src_stride_uv, |
2019 | | uint8_t* dst_argb, |
2020 | | int dst_stride_argb, |
2021 | | const struct YuvConstants* yuvconstants, |
2022 | | int width, |
2023 | 0 | int height) { |
2024 | 0 | int y; |
2025 | 0 | void (*P210ToARGBRow)( |
2026 | 0 | const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, |
2027 | 0 | const struct YuvConstants* yuvconstants, int width) = P210ToARGBRow_C; |
2028 | 0 | assert(yuvconstants); |
2029 | 0 | if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || |
2030 | 0 | height == INT_MIN) { |
2031 | 0 | return -1; |
2032 | 0 | } |
2033 | | // Negative height means invert the image. |
2034 | 0 | if (height < 0) { |
2035 | 0 | height = -height; |
2036 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
2037 | 0 | dst_stride_argb = -dst_stride_argb; |
2038 | 0 | } |
2039 | 0 | #if defined(HAS_P210TOARGBROW_SSSE3) |
2040 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
2041 | 0 | P210ToARGBRow = P210ToARGBRow_Any_SSSE3; |
2042 | 0 | if (IS_ALIGNED(width, 8)) { |
2043 | 0 | P210ToARGBRow = P210ToARGBRow_SSSE3; |
2044 | 0 | } |
2045 | 0 | } |
2046 | 0 | #endif |
2047 | 0 | #if defined(HAS_P210TOARGBROW_AVX2) |
2048 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
2049 | 0 | P210ToARGBRow = P210ToARGBRow_Any_AVX2; |
2050 | 0 | if (IS_ALIGNED(width, 16)) { |
2051 | 0 | P210ToARGBRow = P210ToARGBRow_AVX2; |
2052 | 0 | } |
2053 | 0 | } |
2054 | 0 | #endif |
2055 | | #if defined(HAS_P210TOARGBROW_NEON) |
2056 | | if (TestCpuFlag(kCpuHasNEON)) { |
2057 | | P210ToARGBRow = P210ToARGBRow_Any_NEON; |
2058 | | if (IS_ALIGNED(width, 8)) { |
2059 | | P210ToARGBRow = P210ToARGBRow_NEON; |
2060 | | } |
2061 | | } |
2062 | | #endif |
2063 | | #if defined(HAS_P210TOARGBROW_SVE2) |
2064 | | if (TestCpuFlag(kCpuHasSVE2)) { |
2065 | | P210ToARGBRow = P210ToARGBRow_SVE2; |
2066 | | } |
2067 | | #endif |
2068 | | #if defined(HAS_P210TOARGBROW_SME) |
2069 | | if (TestCpuFlag(kCpuHasSME)) { |
2070 | | P210ToARGBRow = P210ToARGBRow_SME; |
2071 | | } |
2072 | | #endif |
2073 | 0 | for (y = 0; y < height; ++y) { |
2074 | 0 | P210ToARGBRow(src_y, src_uv, dst_argb, yuvconstants, width); |
2075 | 0 | dst_argb += dst_stride_argb; |
2076 | 0 | src_y += src_stride_y; |
2077 | 0 | src_uv += src_stride_uv; |
2078 | 0 | } |
2079 | 0 | return 0; |
2080 | 0 | } |
2081 | | |
2082 | | LIBYUV_API |
2083 | | int P010ToAR30Matrix(const uint16_t* src_y, |
2084 | | int src_stride_y, |
2085 | | const uint16_t* src_uv, |
2086 | | int src_stride_uv, |
2087 | | uint8_t* dst_ar30, |
2088 | | int dst_stride_ar30, |
2089 | | const struct YuvConstants* yuvconstants, |
2090 | | int width, |
2091 | 0 | int height) { |
2092 | 0 | int y; |
2093 | 0 | void (*P210ToAR30Row)( |
2094 | 0 | const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, |
2095 | 0 | const struct YuvConstants* yuvconstants, int width) = P210ToAR30Row_C; |
2096 | 0 | assert(yuvconstants); |
2097 | 0 | if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0 || |
2098 | 0 | height == INT_MIN) { |
2099 | 0 | return -1; |
2100 | 0 | } |
2101 | | // Negative height means invert the image. |
2102 | 0 | if (height < 0) { |
2103 | 0 | height = -height; |
2104 | 0 | dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; |
2105 | 0 | dst_stride_ar30 = -dst_stride_ar30; |
2106 | 0 | } |
2107 | 0 | #if defined(HAS_P210TOAR30ROW_SSSE3) |
2108 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
2109 | 0 | P210ToAR30Row = P210ToAR30Row_Any_SSSE3; |
2110 | 0 | if (IS_ALIGNED(width, 8)) { |
2111 | 0 | P210ToAR30Row = P210ToAR30Row_SSSE3; |
2112 | 0 | } |
2113 | 0 | } |
2114 | 0 | #endif |
2115 | 0 | #if defined(HAS_P210TOAR30ROW_AVX2) |
2116 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
2117 | 0 | P210ToAR30Row = P210ToAR30Row_Any_AVX2; |
2118 | 0 | if (IS_ALIGNED(width, 16)) { |
2119 | 0 | P210ToAR30Row = P210ToAR30Row_AVX2; |
2120 | 0 | } |
2121 | 0 | } |
2122 | 0 | #endif |
2123 | | #if defined(HAS_P210TOAR30ROW_NEON) |
2124 | | if (TestCpuFlag(kCpuHasNEON)) { |
2125 | | P210ToAR30Row = P210ToAR30Row_Any_NEON; |
2126 | | if (IS_ALIGNED(width, 8)) { |
2127 | | P210ToAR30Row = P210ToAR30Row_NEON; |
2128 | | } |
2129 | | } |
2130 | | #endif |
2131 | | #if defined(HAS_P210TOAR30ROW_SVE2) |
2132 | | if (TestCpuFlag(kCpuHasSVE2)) { |
2133 | | P210ToAR30Row = P210ToAR30Row_SVE2; |
2134 | | } |
2135 | | #endif |
2136 | | #if defined(HAS_P210TOAR30ROW_SME) |
2137 | | if (TestCpuFlag(kCpuHasSME)) { |
2138 | | P210ToAR30Row = P210ToAR30Row_SME; |
2139 | | } |
2140 | | #endif |
2141 | 0 | for (y = 0; y < height; ++y) { |
2142 | 0 | P210ToAR30Row(src_y, src_uv, dst_ar30, yuvconstants, width); |
2143 | 0 | dst_ar30 += dst_stride_ar30; |
2144 | 0 | src_y += src_stride_y; |
2145 | 0 | if (y & 1) { |
2146 | 0 | src_uv += src_stride_uv; |
2147 | 0 | } |
2148 | 0 | } |
2149 | 0 | return 0; |
2150 | 0 | } |
2151 | | |
2152 | | LIBYUV_API |
2153 | | int P210ToAR30Matrix(const uint16_t* src_y, |
2154 | | int src_stride_y, |
2155 | | const uint16_t* src_uv, |
2156 | | int src_stride_uv, |
2157 | | uint8_t* dst_ar30, |
2158 | | int dst_stride_ar30, |
2159 | | const struct YuvConstants* yuvconstants, |
2160 | | int width, |
2161 | 0 | int height) { |
2162 | 0 | int y; |
2163 | 0 | void (*P210ToAR30Row)( |
2164 | 0 | const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, |
2165 | 0 | const struct YuvConstants* yuvconstants, int width) = P210ToAR30Row_C; |
2166 | 0 | assert(yuvconstants); |
2167 | 0 | if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0 || |
2168 | 0 | height == INT_MIN) { |
2169 | 0 | return -1; |
2170 | 0 | } |
2171 | | // Negative height means invert the image. |
2172 | 0 | if (height < 0) { |
2173 | 0 | height = -height; |
2174 | 0 | dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; |
2175 | 0 | dst_stride_ar30 = -dst_stride_ar30; |
2176 | 0 | } |
2177 | 0 | #if defined(HAS_P210TOAR30ROW_SSSE3) |
2178 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
2179 | 0 | P210ToAR30Row = P210ToAR30Row_Any_SSSE3; |
2180 | 0 | if (IS_ALIGNED(width, 8)) { |
2181 | 0 | P210ToAR30Row = P210ToAR30Row_SSSE3; |
2182 | 0 | } |
2183 | 0 | } |
2184 | 0 | #endif |
2185 | 0 | #if defined(HAS_P210TOAR30ROW_AVX2) |
2186 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
2187 | 0 | P210ToAR30Row = P210ToAR30Row_Any_AVX2; |
2188 | 0 | if (IS_ALIGNED(width, 16)) { |
2189 | 0 | P210ToAR30Row = P210ToAR30Row_AVX2; |
2190 | 0 | } |
2191 | 0 | } |
2192 | 0 | #endif |
2193 | | #if defined(HAS_P210TOAR30ROW_NEON) |
2194 | | if (TestCpuFlag(kCpuHasNEON)) { |
2195 | | P210ToAR30Row = P210ToAR30Row_Any_NEON; |
2196 | | if (IS_ALIGNED(width, 8)) { |
2197 | | P210ToAR30Row = P210ToAR30Row_NEON; |
2198 | | } |
2199 | | } |
2200 | | #endif |
2201 | | #if defined(HAS_P210TOAR30ROW_SVE2) |
2202 | | if (TestCpuFlag(kCpuHasSVE2)) { |
2203 | | P210ToAR30Row = P210ToAR30Row_SVE2; |
2204 | | } |
2205 | | #endif |
2206 | | #if defined(HAS_P210TOAR30ROW_SME) |
2207 | | if (TestCpuFlag(kCpuHasSME)) { |
2208 | | P210ToAR30Row = P210ToAR30Row_SME; |
2209 | | } |
2210 | | #endif |
2211 | 0 | for (y = 0; y < height; ++y) { |
2212 | 0 | P210ToAR30Row(src_y, src_uv, dst_ar30, yuvconstants, width); |
2213 | 0 | dst_ar30 += dst_stride_ar30; |
2214 | 0 | src_y += src_stride_y; |
2215 | 0 | src_uv += src_stride_uv; |
2216 | 0 | } |
2217 | 0 | return 0; |
2218 | 0 | } |
2219 | | |
2220 | | // Convert I420 with Alpha to preattenuated ARGB with matrix. |
2221 | | LIBYUV_API |
2222 | | int I420AlphaToARGBMatrix(const uint8_t* src_y, |
2223 | | int src_stride_y, |
2224 | | const uint8_t* src_u, |
2225 | | int src_stride_u, |
2226 | | const uint8_t* src_v, |
2227 | | int src_stride_v, |
2228 | | const uint8_t* src_a, |
2229 | | int src_stride_a, |
2230 | | uint8_t* dst_argb, |
2231 | | int dst_stride_argb, |
2232 | | const struct YuvConstants* yuvconstants, |
2233 | | int width, |
2234 | | int height, |
2235 | 132 | int attenuate) { |
2236 | 132 | int y; |
2237 | 132 | void (*I422AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, |
2238 | 132 | const uint8_t* v_buf, const uint8_t* a_buf, |
2239 | 132 | uint8_t* dst_argb, |
2240 | 132 | const struct YuvConstants* yuvconstants, |
2241 | 132 | int width) = I422AlphaToARGBRow_C; |
2242 | 132 | void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, |
2243 | 132 | int width) = ARGBAttenuateRow_C; |
2244 | 132 | assert(yuvconstants); |
2245 | 132 | if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || |
2246 | 132 | height == 0 || height == INT_MIN) { |
2247 | 0 | return -1; |
2248 | 0 | } |
2249 | | // Negative height means invert the image. |
2250 | 132 | if (height < 0) { |
2251 | 0 | height = -height; |
2252 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
2253 | 0 | dst_stride_argb = -dst_stride_argb; |
2254 | 0 | } |
2255 | 132 | #if defined(HAS_I422ALPHATOARGBROW_SSSE3) |
2256 | 132 | if (TestCpuFlag(kCpuHasSSSE3)) { |
2257 | 132 | I422AlphaToARGBRow = I422AlphaToARGBRow_Any_SSSE3; |
2258 | 132 | if (IS_ALIGNED(width, 8)) { |
2259 | 35 | I422AlphaToARGBRow = I422AlphaToARGBRow_SSSE3; |
2260 | 35 | } |
2261 | 132 | } |
2262 | 132 | #endif |
2263 | 132 | #if defined(HAS_I422ALPHATOARGBROW_AVX2) |
2264 | 132 | if (TestCpuFlag(kCpuHasAVX2)) { |
2265 | 132 | I422AlphaToARGBRow = I422AlphaToARGBRow_Any_AVX2; |
2266 | 132 | if (IS_ALIGNED(width, 16)) { |
2267 | 18 | I422AlphaToARGBRow = I422AlphaToARGBRow_AVX2; |
2268 | 18 | } |
2269 | 132 | } |
2270 | 132 | #endif |
2271 | | #if defined(HAS_I422ALPHATOARGBROW_NEON) |
2272 | | if (TestCpuFlag(kCpuHasNEON)) { |
2273 | | I422AlphaToARGBRow = I422AlphaToARGBRow_Any_NEON; |
2274 | | if (IS_ALIGNED(width, 8)) { |
2275 | | I422AlphaToARGBRow = I422AlphaToARGBRow_NEON; |
2276 | | } |
2277 | | } |
2278 | | #endif |
2279 | | #if defined(HAS_I422ALPHATOARGBROW_SVE2) |
2280 | | if (TestCpuFlag(kCpuHasSVE2)) { |
2281 | | I422AlphaToARGBRow = I422AlphaToARGBRow_SVE2; |
2282 | | } |
2283 | | #endif |
2284 | | #if defined(HAS_I422ALPHATOARGBROW_SME) |
2285 | | if (TestCpuFlag(kCpuHasSME)) { |
2286 | | I422AlphaToARGBRow = I422AlphaToARGBRow_SME; |
2287 | | } |
2288 | | #endif |
2289 | | #if defined(HAS_I422ALPHATOARGBROW_LSX) |
2290 | | if (TestCpuFlag(kCpuHasLSX)) { |
2291 | | I422AlphaToARGBRow = I422AlphaToARGBRow_Any_LSX; |
2292 | | if (IS_ALIGNED(width, 16)) { |
2293 | | I422AlphaToARGBRow = I422AlphaToARGBRow_LSX; |
2294 | | } |
2295 | | } |
2296 | | #endif |
2297 | | #if defined(HAS_I422ALPHATOARGBROW_LASX) |
2298 | | if (TestCpuFlag(kCpuHasLASX)) { |
2299 | | I422AlphaToARGBRow = I422AlphaToARGBRow_Any_LASX; |
2300 | | if (IS_ALIGNED(width, 16)) { |
2301 | | I422AlphaToARGBRow = I422AlphaToARGBRow_LASX; |
2302 | | } |
2303 | | } |
2304 | | #endif |
2305 | | #if defined(HAS_I422ALPHATOARGBROW_RVV) |
2306 | | if (TestCpuFlag(kCpuHasRVV)) { |
2307 | | I422AlphaToARGBRow = I422AlphaToARGBRow_RVV; |
2308 | | } |
2309 | | #endif |
2310 | 132 | #if defined(HAS_ARGBATTENUATEROW_SSSE3) |
2311 | 132 | if (TestCpuFlag(kCpuHasSSSE3)) { |
2312 | 132 | ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; |
2313 | 132 | if (IS_ALIGNED(width, 4)) { |
2314 | 53 | ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; |
2315 | 53 | } |
2316 | 132 | } |
2317 | 132 | #endif |
2318 | 132 | #if defined(HAS_ARGBATTENUATEROW_AVX2) |
2319 | 132 | if (TestCpuFlag(kCpuHasAVX2)) { |
2320 | 132 | ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; |
2321 | 132 | if (IS_ALIGNED(width, 8)) { |
2322 | 35 | ARGBAttenuateRow = ARGBAttenuateRow_AVX2; |
2323 | 35 | } |
2324 | 132 | } |
2325 | 132 | #endif |
2326 | | #if defined(HAS_ARGBATTENUATEROW_NEON) |
2327 | | if (TestCpuFlag(kCpuHasNEON)) { |
2328 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; |
2329 | | if (IS_ALIGNED(width, 8)) { |
2330 | | ARGBAttenuateRow = ARGBAttenuateRow_NEON; |
2331 | | } |
2332 | | } |
2333 | | #endif |
2334 | | #if defined(HAS_ARGBATTENUATEROW_RVV) |
2335 | | if (TestCpuFlag(kCpuHasRVV)) { |
2336 | | ARGBAttenuateRow = ARGBAttenuateRow_RVV; |
2337 | | } |
2338 | | #endif |
2339 | | #if defined(HAS_ARGBATTENUATEROW_LSX) |
2340 | | if (TestCpuFlag(kCpuHasLSX)) { |
2341 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; |
2342 | | if (IS_ALIGNED(width, 8)) { |
2343 | | ARGBAttenuateRow = ARGBAttenuateRow_LSX; |
2344 | | } |
2345 | | } |
2346 | | #endif |
2347 | | #if defined(HAS_ARGBATTENUATEROW_LASX) |
2348 | | if (TestCpuFlag(kCpuHasLASX)) { |
2349 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; |
2350 | | if (IS_ALIGNED(width, 16)) { |
2351 | | ARGBAttenuateRow = ARGBAttenuateRow_LASX; |
2352 | | } |
2353 | | } |
2354 | | #endif |
2355 | | |
2356 | 2.73k | for (y = 0; y < height; ++y) { |
2357 | 2.60k | I422AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, |
2358 | 2.60k | width); |
2359 | 2.60k | if (attenuate) { |
2360 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
2361 | 0 | } |
2362 | 2.60k | dst_argb += dst_stride_argb; |
2363 | 2.60k | src_a += src_stride_a; |
2364 | 2.60k | src_y += src_stride_y; |
2365 | 2.60k | if (y & 1) { |
2366 | 1.28k | src_u += src_stride_u; |
2367 | 1.28k | src_v += src_stride_v; |
2368 | 1.28k | } |
2369 | 2.60k | } |
2370 | 132 | return 0; |
2371 | 132 | } |
2372 | | |
2373 | | // Convert I422 with Alpha to preattenuated ARGB with matrix. |
2374 | | LIBYUV_API |
2375 | | int I422AlphaToARGBMatrix(const uint8_t* src_y, |
2376 | | int src_stride_y, |
2377 | | const uint8_t* src_u, |
2378 | | int src_stride_u, |
2379 | | const uint8_t* src_v, |
2380 | | int src_stride_v, |
2381 | | const uint8_t* src_a, |
2382 | | int src_stride_a, |
2383 | | uint8_t* dst_argb, |
2384 | | int dst_stride_argb, |
2385 | | const struct YuvConstants* yuvconstants, |
2386 | | int width, |
2387 | | int height, |
2388 | 88 | int attenuate) { |
2389 | 88 | int y; |
2390 | 88 | void (*I422AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, |
2391 | 88 | const uint8_t* v_buf, const uint8_t* a_buf, |
2392 | 88 | uint8_t* dst_argb, |
2393 | 88 | const struct YuvConstants* yuvconstants, |
2394 | 88 | int width) = I422AlphaToARGBRow_C; |
2395 | 88 | void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, |
2396 | 88 | int width) = ARGBAttenuateRow_C; |
2397 | 88 | assert(yuvconstants); |
2398 | 88 | if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || |
2399 | 88 | height == 0 || height == INT_MIN) { |
2400 | 0 | return -1; |
2401 | 0 | } |
2402 | | // Negative height means invert the image. |
2403 | 88 | if (height < 0) { |
2404 | 0 | height = -height; |
2405 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
2406 | 0 | dst_stride_argb = -dst_stride_argb; |
2407 | 0 | } |
2408 | 88 | #if defined(HAS_I422ALPHATOARGBROW_SSSE3) |
2409 | 88 | if (TestCpuFlag(kCpuHasSSSE3)) { |
2410 | 88 | I422AlphaToARGBRow = I422AlphaToARGBRow_Any_SSSE3; |
2411 | 88 | if (IS_ALIGNED(width, 8)) { |
2412 | 34 | I422AlphaToARGBRow = I422AlphaToARGBRow_SSSE3; |
2413 | 34 | } |
2414 | 88 | } |
2415 | 88 | #endif |
2416 | 88 | #if defined(HAS_I422ALPHATOARGBROW_AVX2) |
2417 | 88 | if (TestCpuFlag(kCpuHasAVX2)) { |
2418 | 88 | I422AlphaToARGBRow = I422AlphaToARGBRow_Any_AVX2; |
2419 | 88 | if (IS_ALIGNED(width, 16)) { |
2420 | 17 | I422AlphaToARGBRow = I422AlphaToARGBRow_AVX2; |
2421 | 17 | } |
2422 | 88 | } |
2423 | 88 | #endif |
2424 | | #if defined(HAS_I422ALPHATOARGBROW_NEON) |
2425 | | if (TestCpuFlag(kCpuHasNEON)) { |
2426 | | I422AlphaToARGBRow = I422AlphaToARGBRow_Any_NEON; |
2427 | | if (IS_ALIGNED(width, 8)) { |
2428 | | I422AlphaToARGBRow = I422AlphaToARGBRow_NEON; |
2429 | | } |
2430 | | } |
2431 | | #endif |
2432 | | #if defined(HAS_I422ALPHATOARGBROW_SVE2) |
2433 | | if (TestCpuFlag(kCpuHasSVE2)) { |
2434 | | I422AlphaToARGBRow = I422AlphaToARGBRow_SVE2; |
2435 | | } |
2436 | | #endif |
2437 | | #if defined(HAS_I422ALPHATOARGBROW_SME) |
2438 | | if (TestCpuFlag(kCpuHasSME)) { |
2439 | | I422AlphaToARGBRow = I422AlphaToARGBRow_SME; |
2440 | | } |
2441 | | #endif |
2442 | | #if defined(HAS_I422ALPHATOARGBROW_LSX) |
2443 | | if (TestCpuFlag(kCpuHasLSX)) { |
2444 | | I422AlphaToARGBRow = I422AlphaToARGBRow_Any_LSX; |
2445 | | if (IS_ALIGNED(width, 16)) { |
2446 | | I422AlphaToARGBRow = I422AlphaToARGBRow_LSX; |
2447 | | } |
2448 | | } |
2449 | | #endif |
2450 | | #if defined(HAS_I422ALPHATOARGBROW_LASX) |
2451 | | if (TestCpuFlag(kCpuHasLASX)) { |
2452 | | I422AlphaToARGBRow = I422AlphaToARGBRow_Any_LASX; |
2453 | | if (IS_ALIGNED(width, 16)) { |
2454 | | I422AlphaToARGBRow = I422AlphaToARGBRow_LASX; |
2455 | | } |
2456 | | } |
2457 | | #endif |
2458 | | #if defined(HAS_I422ALPHATOARGBROW_RVV) |
2459 | | if (TestCpuFlag(kCpuHasRVV)) { |
2460 | | I422AlphaToARGBRow = I422AlphaToARGBRow_RVV; |
2461 | | } |
2462 | | #endif |
2463 | 88 | #if defined(HAS_ARGBATTENUATEROW_SSSE3) |
2464 | 88 | if (TestCpuFlag(kCpuHasSSSE3)) { |
2465 | 88 | ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; |
2466 | 88 | if (IS_ALIGNED(width, 4)) { |
2467 | 51 | ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; |
2468 | 51 | } |
2469 | 88 | } |
2470 | 88 | #endif |
2471 | 88 | #if defined(HAS_ARGBATTENUATEROW_AVX2) |
2472 | 88 | if (TestCpuFlag(kCpuHasAVX2)) { |
2473 | 88 | ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; |
2474 | 88 | if (IS_ALIGNED(width, 8)) { |
2475 | 34 | ARGBAttenuateRow = ARGBAttenuateRow_AVX2; |
2476 | 34 | } |
2477 | 88 | } |
2478 | 88 | #endif |
2479 | | #if defined(HAS_ARGBATTENUATEROW_NEON) |
2480 | | if (TestCpuFlag(kCpuHasNEON)) { |
2481 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; |
2482 | | if (IS_ALIGNED(width, 8)) { |
2483 | | ARGBAttenuateRow = ARGBAttenuateRow_NEON; |
2484 | | } |
2485 | | } |
2486 | | #endif |
2487 | | #if defined(HAS_ARGBATTENUATEROW_RVV) |
2488 | | if (TestCpuFlag(kCpuHasRVV)) { |
2489 | | ARGBAttenuateRow = ARGBAttenuateRow_RVV; |
2490 | | } |
2491 | | #endif |
2492 | | #if defined(HAS_ARGBATTENUATEROW_LSX) |
2493 | | if (TestCpuFlag(kCpuHasLSX)) { |
2494 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; |
2495 | | if (IS_ALIGNED(width, 8)) { |
2496 | | ARGBAttenuateRow = ARGBAttenuateRow_LSX; |
2497 | | } |
2498 | | } |
2499 | | #endif |
2500 | | #if defined(HAS_ARGBATTENUATEROW_LASX) |
2501 | | if (TestCpuFlag(kCpuHasLASX)) { |
2502 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; |
2503 | | if (IS_ALIGNED(width, 16)) { |
2504 | | ARGBAttenuateRow = ARGBAttenuateRow_LASX; |
2505 | | } |
2506 | | } |
2507 | | #endif |
2508 | | |
2509 | 487 | for (y = 0; y < height; ++y) { |
2510 | 399 | I422AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, |
2511 | 399 | width); |
2512 | 399 | if (attenuate) { |
2513 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
2514 | 0 | } |
2515 | 399 | dst_argb += dst_stride_argb; |
2516 | 399 | src_a += src_stride_a; |
2517 | 399 | src_y += src_stride_y; |
2518 | 399 | src_u += src_stride_u; |
2519 | 399 | src_v += src_stride_v; |
2520 | 399 | } |
2521 | 88 | return 0; |
2522 | 88 | } |
2523 | | |
2524 | | // Convert I444 with Alpha to preattenuated ARGB with matrix. |
2525 | | LIBYUV_API |
2526 | | int I444AlphaToARGBMatrix(const uint8_t* src_y, |
2527 | | int src_stride_y, |
2528 | | const uint8_t* src_u, |
2529 | | int src_stride_u, |
2530 | | const uint8_t* src_v, |
2531 | | int src_stride_v, |
2532 | | const uint8_t* src_a, |
2533 | | int src_stride_a, |
2534 | | uint8_t* dst_argb, |
2535 | | int dst_stride_argb, |
2536 | | const struct YuvConstants* yuvconstants, |
2537 | | int width, |
2538 | | int height, |
2539 | 112 | int attenuate) { |
2540 | 112 | int y; |
2541 | 112 | void (*I444AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, |
2542 | 112 | const uint8_t* v_buf, const uint8_t* a_buf, |
2543 | 112 | uint8_t* dst_argb, |
2544 | 112 | const struct YuvConstants* yuvconstants, |
2545 | 112 | int width) = I444AlphaToARGBRow_C; |
2546 | 112 | void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, |
2547 | 112 | int width) = ARGBAttenuateRow_C; |
2548 | 112 | assert(yuvconstants); |
2549 | 112 | if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || |
2550 | 112 | height == 0 || height == INT_MIN) { |
2551 | 0 | return -1; |
2552 | 0 | } |
2553 | | // Negative height means invert the image. |
2554 | 112 | if (height < 0) { |
2555 | 0 | height = -height; |
2556 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
2557 | 0 | dst_stride_argb = -dst_stride_argb; |
2558 | 0 | } |
2559 | 112 | #if defined(HAS_I444ALPHATOARGBROW_SSSE3) |
2560 | 112 | if (TestCpuFlag(kCpuHasSSSE3)) { |
2561 | 112 | I444AlphaToARGBRow = I444AlphaToARGBRow_Any_SSSE3; |
2562 | 112 | if (IS_ALIGNED(width, 8)) { |
2563 | 37 | I444AlphaToARGBRow = I444AlphaToARGBRow_SSSE3; |
2564 | 37 | } |
2565 | 112 | } |
2566 | 112 | #endif |
2567 | 112 | #if defined(HAS_I444ALPHATOARGBROW_AVX2) |
2568 | 112 | if (TestCpuFlag(kCpuHasAVX2)) { |
2569 | 112 | I444AlphaToARGBRow = I444AlphaToARGBRow_Any_AVX2; |
2570 | 112 | if (IS_ALIGNED(width, 16)) { |
2571 | 20 | I444AlphaToARGBRow = I444AlphaToARGBRow_AVX2; |
2572 | 20 | } |
2573 | 112 | } |
2574 | 112 | #endif |
2575 | | #if defined(HAS_I444ALPHATOARGBROW_NEON) |
2576 | | if (TestCpuFlag(kCpuHasNEON)) { |
2577 | | I444AlphaToARGBRow = I444AlphaToARGBRow_Any_NEON; |
2578 | | if (IS_ALIGNED(width, 8)) { |
2579 | | I444AlphaToARGBRow = I444AlphaToARGBRow_NEON; |
2580 | | } |
2581 | | } |
2582 | | #endif |
2583 | | #if defined(HAS_I444ALPHATOARGBROW_SVE2) |
2584 | | if (TestCpuFlag(kCpuHasSVE2)) { |
2585 | | I444AlphaToARGBRow = I444AlphaToARGBRow_SVE2; |
2586 | | } |
2587 | | #endif |
2588 | | #if defined(HAS_I444ALPHATOARGBROW_SME) |
2589 | | if (TestCpuFlag(kCpuHasSME)) { |
2590 | | I444AlphaToARGBRow = I444AlphaToARGBRow_SME; |
2591 | | } |
2592 | | #endif |
2593 | | #if defined(HAS_I444ALPHATOARGBROW_RVV) |
2594 | | if (TestCpuFlag(kCpuHasRVV)) { |
2595 | | I444AlphaToARGBRow = I444AlphaToARGBRow_RVV; |
2596 | | } |
2597 | | #endif |
2598 | 112 | #if defined(HAS_ARGBATTENUATEROW_SSSE3) |
2599 | 112 | if (TestCpuFlag(kCpuHasSSSE3)) { |
2600 | 112 | ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; |
2601 | 112 | if (IS_ALIGNED(width, 4)) { |
2602 | 55 | ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; |
2603 | 55 | } |
2604 | 112 | } |
2605 | 112 | #endif |
2606 | 112 | #if defined(HAS_ARGBATTENUATEROW_AVX2) |
2607 | 112 | if (TestCpuFlag(kCpuHasAVX2)) { |
2608 | 112 | ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; |
2609 | 112 | if (IS_ALIGNED(width, 8)) { |
2610 | 37 | ARGBAttenuateRow = ARGBAttenuateRow_AVX2; |
2611 | 37 | } |
2612 | 112 | } |
2613 | 112 | #endif |
2614 | | #if defined(HAS_ARGBATTENUATEROW_NEON) |
2615 | | if (TestCpuFlag(kCpuHasNEON)) { |
2616 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; |
2617 | | if (IS_ALIGNED(width, 8)) { |
2618 | | ARGBAttenuateRow = ARGBAttenuateRow_NEON; |
2619 | | } |
2620 | | } |
2621 | | #endif |
2622 | | #if defined(HAS_ARGBATTENUATEROW_RVV) |
2623 | | if (TestCpuFlag(kCpuHasRVV)) { |
2624 | | ARGBAttenuateRow = ARGBAttenuateRow_RVV; |
2625 | | } |
2626 | | #endif |
2627 | | #if defined(HAS_ARGBATTENUATEROW_LSX) |
2628 | | if (TestCpuFlag(kCpuHasLSX)) { |
2629 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; |
2630 | | if (IS_ALIGNED(width, 8)) { |
2631 | | ARGBAttenuateRow = ARGBAttenuateRow_LSX; |
2632 | | } |
2633 | | } |
2634 | | #endif |
2635 | | #if defined(HAS_ARGBATTENUATEROW_LASX) |
2636 | | if (TestCpuFlag(kCpuHasLASX)) { |
2637 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; |
2638 | | if (IS_ALIGNED(width, 16)) { |
2639 | | ARGBAttenuateRow = ARGBAttenuateRow_LASX; |
2640 | | } |
2641 | | } |
2642 | | #endif |
2643 | | |
2644 | 2.05k | for (y = 0; y < height; ++y) { |
2645 | 1.94k | I444AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, |
2646 | 1.94k | width); |
2647 | 1.94k | if (attenuate) { |
2648 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
2649 | 0 | } |
2650 | 1.94k | dst_argb += dst_stride_argb; |
2651 | 1.94k | src_a += src_stride_a; |
2652 | 1.94k | src_y += src_stride_y; |
2653 | 1.94k | src_u += src_stride_u; |
2654 | 1.94k | src_v += src_stride_v; |
2655 | 1.94k | } |
2656 | 112 | return 0; |
2657 | 112 | } |
2658 | | |
2659 | | // Convert I420 with Alpha to ARGB. |
2660 | | LIBYUV_API |
2661 | | int I420AlphaToARGB(const uint8_t* src_y, |
2662 | | int src_stride_y, |
2663 | | const uint8_t* src_u, |
2664 | | int src_stride_u, |
2665 | | const uint8_t* src_v, |
2666 | | int src_stride_v, |
2667 | | const uint8_t* src_a, |
2668 | | int src_stride_a, |
2669 | | uint8_t* dst_argb, |
2670 | | int dst_stride_argb, |
2671 | | int width, |
2672 | | int height, |
2673 | 0 | int attenuate) { |
2674 | 0 | return I420AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
2675 | 0 | src_stride_v, src_a, src_stride_a, dst_argb, |
2676 | 0 | dst_stride_argb, &kYuvI601Constants, width, |
2677 | 0 | height, attenuate); |
2678 | 0 | } |
2679 | | |
2680 | | // Convert I420 with Alpha to ABGR. |
2681 | | LIBYUV_API |
2682 | | int I420AlphaToABGR(const uint8_t* src_y, |
2683 | | int src_stride_y, |
2684 | | const uint8_t* src_u, |
2685 | | int src_stride_u, |
2686 | | const uint8_t* src_v, |
2687 | | int src_stride_v, |
2688 | | const uint8_t* src_a, |
2689 | | int src_stride_a, |
2690 | | uint8_t* dst_abgr, |
2691 | | int dst_stride_abgr, |
2692 | | int width, |
2693 | | int height, |
2694 | 0 | int attenuate) { |
2695 | 0 | return I420AlphaToARGBMatrix( |
2696 | 0 | src_y, src_stride_y, src_v, src_stride_v, // Swap U and V |
2697 | 0 | src_u, src_stride_u, src_a, src_stride_a, dst_abgr, dst_stride_abgr, |
2698 | 0 | &kYvuI601Constants, // Use Yvu matrix |
2699 | 0 | width, height, attenuate); |
2700 | 0 | } |
2701 | | |
2702 | | // Convert I422 with Alpha to ARGB. |
2703 | | LIBYUV_API |
2704 | | int I422AlphaToARGB(const uint8_t* src_y, |
2705 | | int src_stride_y, |
2706 | | const uint8_t* src_u, |
2707 | | int src_stride_u, |
2708 | | const uint8_t* src_v, |
2709 | | int src_stride_v, |
2710 | | const uint8_t* src_a, |
2711 | | int src_stride_a, |
2712 | | uint8_t* dst_argb, |
2713 | | int dst_stride_argb, |
2714 | | int width, |
2715 | | int height, |
2716 | 0 | int attenuate) { |
2717 | 0 | return I422AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
2718 | 0 | src_stride_v, src_a, src_stride_a, dst_argb, |
2719 | 0 | dst_stride_argb, &kYuvI601Constants, width, |
2720 | 0 | height, attenuate); |
2721 | 0 | } |
2722 | | |
2723 | | // Convert I422 with Alpha to ABGR. |
2724 | | LIBYUV_API |
2725 | | int I422AlphaToABGR(const uint8_t* src_y, |
2726 | | int src_stride_y, |
2727 | | const uint8_t* src_u, |
2728 | | int src_stride_u, |
2729 | | const uint8_t* src_v, |
2730 | | int src_stride_v, |
2731 | | const uint8_t* src_a, |
2732 | | int src_stride_a, |
2733 | | uint8_t* dst_abgr, |
2734 | | int dst_stride_abgr, |
2735 | | int width, |
2736 | | int height, |
2737 | 0 | int attenuate) { |
2738 | 0 | return I422AlphaToARGBMatrix( |
2739 | 0 | src_y, src_stride_y, src_v, src_stride_v, // Swap U and V |
2740 | 0 | src_u, src_stride_u, src_a, src_stride_a, dst_abgr, dst_stride_abgr, |
2741 | 0 | &kYvuI601Constants, // Use Yvu matrix |
2742 | 0 | width, height, attenuate); |
2743 | 0 | } |
2744 | | |
2745 | | // Convert I444 with Alpha to ARGB. |
2746 | | LIBYUV_API |
2747 | | int I444AlphaToARGB(const uint8_t* src_y, |
2748 | | int src_stride_y, |
2749 | | const uint8_t* src_u, |
2750 | | int src_stride_u, |
2751 | | const uint8_t* src_v, |
2752 | | int src_stride_v, |
2753 | | const uint8_t* src_a, |
2754 | | int src_stride_a, |
2755 | | uint8_t* dst_argb, |
2756 | | int dst_stride_argb, |
2757 | | int width, |
2758 | | int height, |
2759 | 0 | int attenuate) { |
2760 | 0 | return I444AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
2761 | 0 | src_stride_v, src_a, src_stride_a, dst_argb, |
2762 | 0 | dst_stride_argb, &kYuvI601Constants, width, |
2763 | 0 | height, attenuate); |
2764 | 0 | } |
2765 | | |
2766 | | // Convert I444 with Alpha to ABGR. |
2767 | | LIBYUV_API |
2768 | | int I444AlphaToABGR(const uint8_t* src_y, |
2769 | | int src_stride_y, |
2770 | | const uint8_t* src_u, |
2771 | | int src_stride_u, |
2772 | | const uint8_t* src_v, |
2773 | | int src_stride_v, |
2774 | | const uint8_t* src_a, |
2775 | | int src_stride_a, |
2776 | | uint8_t* dst_abgr, |
2777 | | int dst_stride_abgr, |
2778 | | int width, |
2779 | | int height, |
2780 | 0 | int attenuate) { |
2781 | 0 | return I444AlphaToARGBMatrix( |
2782 | 0 | src_y, src_stride_y, src_v, src_stride_v, // Swap U and V |
2783 | 0 | src_u, src_stride_u, src_a, src_stride_a, dst_abgr, dst_stride_abgr, |
2784 | 0 | &kYvuI601Constants, // Use Yvu matrix |
2785 | 0 | width, height, attenuate); |
2786 | 0 | } |
2787 | | |
2788 | | // Convert I010 with Alpha to preattenuated ARGB with matrix. |
2789 | | LIBYUV_API |
2790 | | int I010AlphaToARGBMatrix(const uint16_t* src_y, |
2791 | | int src_stride_y, |
2792 | | const uint16_t* src_u, |
2793 | | int src_stride_u, |
2794 | | const uint16_t* src_v, |
2795 | | int src_stride_v, |
2796 | | const uint16_t* src_a, |
2797 | | int src_stride_a, |
2798 | | uint8_t* dst_argb, |
2799 | | int dst_stride_argb, |
2800 | | const struct YuvConstants* yuvconstants, |
2801 | | int width, |
2802 | | int height, |
2803 | 124 | int attenuate) { |
2804 | 124 | int y; |
2805 | 124 | void (*I210AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, |
2806 | 124 | const uint16_t* v_buf, const uint16_t* a_buf, |
2807 | 124 | uint8_t* dst_argb, |
2808 | 124 | const struct YuvConstants* yuvconstants, |
2809 | 124 | int width) = I210AlphaToARGBRow_C; |
2810 | 124 | void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, |
2811 | 124 | int width) = ARGBAttenuateRow_C; |
2812 | 124 | assert(yuvconstants); |
2813 | 124 | if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || |
2814 | 124 | height == 0 || height == INT_MIN) { |
2815 | 0 | return -1; |
2816 | 0 | } |
2817 | | // Negative height means invert the image. |
2818 | 124 | if (height < 0) { |
2819 | 0 | height = -height; |
2820 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
2821 | 0 | dst_stride_argb = -dst_stride_argb; |
2822 | 0 | } |
2823 | | #if defined(HAS_I210ALPHATOARGBROW_NEON) |
2824 | | if (TestCpuFlag(kCpuHasNEON)) { |
2825 | | I210AlphaToARGBRow = I210AlphaToARGBRow_Any_NEON; |
2826 | | if (IS_ALIGNED(width, 8)) { |
2827 | | I210AlphaToARGBRow = I210AlphaToARGBRow_NEON; |
2828 | | } |
2829 | | } |
2830 | | #endif |
2831 | | #if defined(HAS_I210ALPHATOARGBROW_SVE2) |
2832 | | if (TestCpuFlag(kCpuHasSVE2)) { |
2833 | | I210AlphaToARGBRow = I210AlphaToARGBRow_SVE2; |
2834 | | } |
2835 | | #endif |
2836 | | #if defined(HAS_I210ALPHATOARGBROW_SME) |
2837 | | if (TestCpuFlag(kCpuHasSME)) { |
2838 | | I210AlphaToARGBRow = I210AlphaToARGBRow_SME; |
2839 | | } |
2840 | | #endif |
2841 | 124 | #if defined(HAS_I210ALPHATOARGBROW_SSSE3) |
2842 | 124 | if (TestCpuFlag(kCpuHasSSSE3)) { |
2843 | 124 | I210AlphaToARGBRow = I210AlphaToARGBRow_Any_SSSE3; |
2844 | 124 | if (IS_ALIGNED(width, 8)) { |
2845 | 35 | I210AlphaToARGBRow = I210AlphaToARGBRow_SSSE3; |
2846 | 35 | } |
2847 | 124 | } |
2848 | 124 | #endif |
2849 | 124 | #if defined(HAS_I210ALPHATOARGBROW_AVX2) |
2850 | 124 | if (TestCpuFlag(kCpuHasAVX2)) { |
2851 | 124 | I210AlphaToARGBRow = I210AlphaToARGBRow_Any_AVX2; |
2852 | 124 | if (IS_ALIGNED(width, 16)) { |
2853 | 18 | I210AlphaToARGBRow = I210AlphaToARGBRow_AVX2; |
2854 | 18 | } |
2855 | 124 | } |
2856 | 124 | #endif |
2857 | 124 | #if defined(HAS_ARGBATTENUATEROW_SSSE3) |
2858 | 124 | if (TestCpuFlag(kCpuHasSSSE3)) { |
2859 | 124 | ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; |
2860 | 124 | if (IS_ALIGNED(width, 4)) { |
2861 | 52 | ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; |
2862 | 52 | } |
2863 | 124 | } |
2864 | 124 | #endif |
2865 | 124 | #if defined(HAS_ARGBATTENUATEROW_AVX2) |
2866 | 124 | if (TestCpuFlag(kCpuHasAVX2)) { |
2867 | 124 | ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; |
2868 | 124 | if (IS_ALIGNED(width, 8)) { |
2869 | 35 | ARGBAttenuateRow = ARGBAttenuateRow_AVX2; |
2870 | 35 | } |
2871 | 124 | } |
2872 | 124 | #endif |
2873 | | #if defined(HAS_ARGBATTENUATEROW_NEON) |
2874 | | if (TestCpuFlag(kCpuHasNEON)) { |
2875 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; |
2876 | | if (IS_ALIGNED(width, 8)) { |
2877 | | ARGBAttenuateRow = ARGBAttenuateRow_NEON; |
2878 | | } |
2879 | | } |
2880 | | #endif |
2881 | | #if defined(HAS_ARGBATTENUATEROW_RVV) |
2882 | | if (TestCpuFlag(kCpuHasRVV)) { |
2883 | | ARGBAttenuateRow = ARGBAttenuateRow_RVV; |
2884 | | } |
2885 | | #endif |
2886 | | #if defined(HAS_ARGBATTENUATEROW_LSX) |
2887 | | if (TestCpuFlag(kCpuHasLSX)) { |
2888 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; |
2889 | | if (IS_ALIGNED(width, 8)) { |
2890 | | ARGBAttenuateRow = ARGBAttenuateRow_LSX; |
2891 | | } |
2892 | | } |
2893 | | #endif |
2894 | | #if defined(HAS_ARGBATTENUATEROW_LASX) |
2895 | | if (TestCpuFlag(kCpuHasLASX)) { |
2896 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; |
2897 | | if (IS_ALIGNED(width, 16)) { |
2898 | | ARGBAttenuateRow = ARGBAttenuateRow_LASX; |
2899 | | } |
2900 | | } |
2901 | | #endif |
2902 | | |
2903 | 2.21k | for (y = 0; y < height; ++y) { |
2904 | 2.08k | I210AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, |
2905 | 2.08k | width); |
2906 | 2.08k | if (attenuate) { |
2907 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
2908 | 0 | } |
2909 | 2.08k | dst_argb += dst_stride_argb; |
2910 | 2.08k | src_a += src_stride_a; |
2911 | 2.08k | src_y += src_stride_y; |
2912 | 2.08k | if (y & 1) { |
2913 | 1.03k | src_u += src_stride_u; |
2914 | 1.03k | src_v += src_stride_v; |
2915 | 1.03k | } |
2916 | 2.08k | } |
2917 | 124 | return 0; |
2918 | 124 | } |
2919 | | |
2920 | | // Convert I210 with Alpha to preattenuated ARGB with matrix. |
2921 | | LIBYUV_API |
2922 | | int I210AlphaToARGBMatrix(const uint16_t* src_y, |
2923 | | int src_stride_y, |
2924 | | const uint16_t* src_u, |
2925 | | int src_stride_u, |
2926 | | const uint16_t* src_v, |
2927 | | int src_stride_v, |
2928 | | const uint16_t* src_a, |
2929 | | int src_stride_a, |
2930 | | uint8_t* dst_argb, |
2931 | | int dst_stride_argb, |
2932 | | const struct YuvConstants* yuvconstants, |
2933 | | int width, |
2934 | | int height, |
2935 | 81 | int attenuate) { |
2936 | 81 | int y; |
2937 | 81 | void (*I210AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, |
2938 | 81 | const uint16_t* v_buf, const uint16_t* a_buf, |
2939 | 81 | uint8_t* dst_argb, |
2940 | 81 | const struct YuvConstants* yuvconstants, |
2941 | 81 | int width) = I210AlphaToARGBRow_C; |
2942 | 81 | void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, |
2943 | 81 | int width) = ARGBAttenuateRow_C; |
2944 | 81 | assert(yuvconstants); |
2945 | 81 | if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || |
2946 | 81 | height == 0 || height == INT_MIN) { |
2947 | 0 | return -1; |
2948 | 0 | } |
2949 | | // Negative height means invert the image. |
2950 | 81 | if (height < 0) { |
2951 | 0 | height = -height; |
2952 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
2953 | 0 | dst_stride_argb = -dst_stride_argb; |
2954 | 0 | } |
2955 | | #if defined(HAS_I210ALPHATOARGBROW_NEON) |
2956 | | if (TestCpuFlag(kCpuHasNEON)) { |
2957 | | I210AlphaToARGBRow = I210AlphaToARGBRow_Any_NEON; |
2958 | | if (IS_ALIGNED(width, 8)) { |
2959 | | I210AlphaToARGBRow = I210AlphaToARGBRow_NEON; |
2960 | | } |
2961 | | } |
2962 | | #endif |
2963 | | #if defined(HAS_I210ALPHATOARGBROW_SVE2) |
2964 | | if (TestCpuFlag(kCpuHasSVE2)) { |
2965 | | I210AlphaToARGBRow = I210AlphaToARGBRow_SVE2; |
2966 | | } |
2967 | | #endif |
2968 | | #if defined(HAS_I210ALPHATOARGBROW_SME) |
2969 | | if (TestCpuFlag(kCpuHasSME)) { |
2970 | | I210AlphaToARGBRow = I210AlphaToARGBRow_SME; |
2971 | | } |
2972 | | #endif |
2973 | 81 | #if defined(HAS_I210ALPHATOARGBROW_SSSE3) |
2974 | 81 | if (TestCpuFlag(kCpuHasSSSE3)) { |
2975 | 81 | I210AlphaToARGBRow = I210AlphaToARGBRow_Any_SSSE3; |
2976 | 81 | if (IS_ALIGNED(width, 8)) { |
2977 | 34 | I210AlphaToARGBRow = I210AlphaToARGBRow_SSSE3; |
2978 | 34 | } |
2979 | 81 | } |
2980 | 81 | #endif |
2981 | 81 | #if defined(HAS_I210ALPHATOARGBROW_AVX2) |
2982 | 81 | if (TestCpuFlag(kCpuHasAVX2)) { |
2983 | 81 | I210AlphaToARGBRow = I210AlphaToARGBRow_Any_AVX2; |
2984 | 81 | if (IS_ALIGNED(width, 16)) { |
2985 | 17 | I210AlphaToARGBRow = I210AlphaToARGBRow_AVX2; |
2986 | 17 | } |
2987 | 81 | } |
2988 | 81 | #endif |
2989 | 81 | #if defined(HAS_ARGBATTENUATEROW_SSSE3) |
2990 | 81 | if (TestCpuFlag(kCpuHasSSSE3)) { |
2991 | 81 | ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; |
2992 | 81 | if (IS_ALIGNED(width, 4)) { |
2993 | 52 | ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; |
2994 | 52 | } |
2995 | 81 | } |
2996 | 81 | #endif |
2997 | 81 | #if defined(HAS_ARGBATTENUATEROW_AVX2) |
2998 | 81 | if (TestCpuFlag(kCpuHasAVX2)) { |
2999 | 81 | ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; |
3000 | 81 | if (IS_ALIGNED(width, 8)) { |
3001 | 34 | ARGBAttenuateRow = ARGBAttenuateRow_AVX2; |
3002 | 34 | } |
3003 | 81 | } |
3004 | 81 | #endif |
3005 | | #if defined(HAS_ARGBATTENUATEROW_NEON) |
3006 | | if (TestCpuFlag(kCpuHasNEON)) { |
3007 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; |
3008 | | if (IS_ALIGNED(width, 8)) { |
3009 | | ARGBAttenuateRow = ARGBAttenuateRow_NEON; |
3010 | | } |
3011 | | } |
3012 | | #endif |
3013 | | #if defined(HAS_ARGBATTENUATEROW_RVV) |
3014 | | if (TestCpuFlag(kCpuHasRVV)) { |
3015 | | ARGBAttenuateRow = ARGBAttenuateRow_RVV; |
3016 | | } |
3017 | | #endif |
3018 | | #if defined(HAS_ARGBATTENUATEROW_LSX) |
3019 | | if (TestCpuFlag(kCpuHasLSX)) { |
3020 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; |
3021 | | if (IS_ALIGNED(width, 8)) { |
3022 | | ARGBAttenuateRow = ARGBAttenuateRow_LSX; |
3023 | | } |
3024 | | } |
3025 | | #endif |
3026 | | #if defined(HAS_ARGBATTENUATEROW_LASX) |
3027 | | if (TestCpuFlag(kCpuHasLASX)) { |
3028 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; |
3029 | | if (IS_ALIGNED(width, 16)) { |
3030 | | ARGBAttenuateRow = ARGBAttenuateRow_LASX; |
3031 | | } |
3032 | | } |
3033 | | #endif |
3034 | | |
3035 | 758 | for (y = 0; y < height; ++y) { |
3036 | 677 | I210AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, |
3037 | 677 | width); |
3038 | 677 | if (attenuate) { |
3039 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
3040 | 0 | } |
3041 | 677 | dst_argb += dst_stride_argb; |
3042 | 677 | src_a += src_stride_a; |
3043 | 677 | src_y += src_stride_y; |
3044 | 677 | src_u += src_stride_u; |
3045 | 677 | src_v += src_stride_v; |
3046 | 677 | } |
3047 | 81 | return 0; |
3048 | 81 | } |
3049 | | |
3050 | | // Convert I410 with Alpha to preattenuated ARGB with matrix. |
3051 | | LIBYUV_API |
3052 | | int I410AlphaToARGBMatrix(const uint16_t* src_y, |
3053 | | int src_stride_y, |
3054 | | const uint16_t* src_u, |
3055 | | int src_stride_u, |
3056 | | const uint16_t* src_v, |
3057 | | int src_stride_v, |
3058 | | const uint16_t* src_a, |
3059 | | int src_stride_a, |
3060 | | uint8_t* dst_argb, |
3061 | | int dst_stride_argb, |
3062 | | const struct YuvConstants* yuvconstants, |
3063 | | int width, |
3064 | | int height, |
3065 | 80 | int attenuate) { |
3066 | 80 | int y; |
3067 | 80 | void (*I410AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, |
3068 | 80 | const uint16_t* v_buf, const uint16_t* a_buf, |
3069 | 80 | uint8_t* dst_argb, |
3070 | 80 | const struct YuvConstants* yuvconstants, |
3071 | 80 | int width) = I410AlphaToARGBRow_C; |
3072 | 80 | void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, |
3073 | 80 | int width) = ARGBAttenuateRow_C; |
3074 | 80 | assert(yuvconstants); |
3075 | 80 | if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || |
3076 | 80 | height == 0 || height == INT_MIN) { |
3077 | 0 | return -1; |
3078 | 0 | } |
3079 | | // Negative height means invert the image. |
3080 | 80 | if (height < 0) { |
3081 | 0 | height = -height; |
3082 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
3083 | 0 | dst_stride_argb = -dst_stride_argb; |
3084 | 0 | } |
3085 | | #if defined(HAS_I410ALPHATOARGBROW_NEON) |
3086 | | if (TestCpuFlag(kCpuHasNEON)) { |
3087 | | I410AlphaToARGBRow = I410AlphaToARGBRow_Any_NEON; |
3088 | | if (IS_ALIGNED(width, 8)) { |
3089 | | I410AlphaToARGBRow = I410AlphaToARGBRow_NEON; |
3090 | | } |
3091 | | } |
3092 | | #endif |
3093 | | #if defined(HAS_I410ALPHATOARGBROW_SVE2) |
3094 | | if (TestCpuFlag(kCpuHasSVE2)) { |
3095 | | I410AlphaToARGBRow = I410AlphaToARGBRow_SVE2; |
3096 | | } |
3097 | | #endif |
3098 | | #if defined(HAS_I410ALPHATOARGBROW_SME) |
3099 | | if (TestCpuFlag(kCpuHasSME)) { |
3100 | | I410AlphaToARGBRow = I410AlphaToARGBRow_SME; |
3101 | | } |
3102 | | #endif |
3103 | 80 | #if defined(HAS_I410ALPHATOARGBROW_SSSE3) |
3104 | 80 | if (TestCpuFlag(kCpuHasSSSE3)) { |
3105 | 80 | I410AlphaToARGBRow = I410AlphaToARGBRow_Any_SSSE3; |
3106 | 80 | if (IS_ALIGNED(width, 8)) { |
3107 | 34 | I410AlphaToARGBRow = I410AlphaToARGBRow_SSSE3; |
3108 | 34 | } |
3109 | 80 | } |
3110 | 80 | #endif |
3111 | 80 | #if defined(HAS_I410ALPHATOARGBROW_AVX2) |
3112 | 80 | if (TestCpuFlag(kCpuHasAVX2)) { |
3113 | 80 | I410AlphaToARGBRow = I410AlphaToARGBRow_Any_AVX2; |
3114 | 80 | if (IS_ALIGNED(width, 16)) { |
3115 | 17 | I410AlphaToARGBRow = I410AlphaToARGBRow_AVX2; |
3116 | 17 | } |
3117 | 80 | } |
3118 | 80 | #endif |
3119 | 80 | #if defined(HAS_ARGBATTENUATEROW_SSSE3) |
3120 | 80 | if (TestCpuFlag(kCpuHasSSSE3)) { |
3121 | 80 | ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; |
3122 | 80 | if (IS_ALIGNED(width, 4)) { |
3123 | 51 | ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; |
3124 | 51 | } |
3125 | 80 | } |
3126 | 80 | #endif |
3127 | 80 | #if defined(HAS_ARGBATTENUATEROW_AVX2) |
3128 | 80 | if (TestCpuFlag(kCpuHasAVX2)) { |
3129 | 80 | ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; |
3130 | 80 | if (IS_ALIGNED(width, 8)) { |
3131 | 34 | ARGBAttenuateRow = ARGBAttenuateRow_AVX2; |
3132 | 34 | } |
3133 | 80 | } |
3134 | 80 | #endif |
3135 | | #if defined(HAS_ARGBATTENUATEROW_NEON) |
3136 | | if (TestCpuFlag(kCpuHasNEON)) { |
3137 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; |
3138 | | if (IS_ALIGNED(width, 8)) { |
3139 | | ARGBAttenuateRow = ARGBAttenuateRow_NEON; |
3140 | | } |
3141 | | } |
3142 | | #endif |
3143 | | #if defined(HAS_ARGBATTENUATEROW_RVV) |
3144 | | if (TestCpuFlag(kCpuHasRVV)) { |
3145 | | ARGBAttenuateRow = ARGBAttenuateRow_RVV; |
3146 | | } |
3147 | | #endif |
3148 | | #if defined(HAS_ARGBATTENUATEROW_LSX) |
3149 | | if (TestCpuFlag(kCpuHasLSX)) { |
3150 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; |
3151 | | if (IS_ALIGNED(width, 8)) { |
3152 | | ARGBAttenuateRow = ARGBAttenuateRow_LSX; |
3153 | | } |
3154 | | } |
3155 | | #endif |
3156 | | #if defined(HAS_ARGBATTENUATEROW_LASX) |
3157 | | if (TestCpuFlag(kCpuHasLASX)) { |
3158 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; |
3159 | | if (IS_ALIGNED(width, 16)) { |
3160 | | ARGBAttenuateRow = ARGBAttenuateRow_LASX; |
3161 | | } |
3162 | | } |
3163 | | #endif |
3164 | | |
3165 | 1.24k | for (y = 0; y < height; ++y) { |
3166 | 1.16k | I410AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, |
3167 | 1.16k | width); |
3168 | 1.16k | if (attenuate) { |
3169 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
3170 | 0 | } |
3171 | 1.16k | dst_argb += dst_stride_argb; |
3172 | 1.16k | src_a += src_stride_a; |
3173 | 1.16k | src_y += src_stride_y; |
3174 | 1.16k | src_u += src_stride_u; |
3175 | 1.16k | src_v += src_stride_v; |
3176 | 1.16k | } |
3177 | 80 | return 0; |
3178 | 80 | } |
3179 | | |
3180 | | // Convert I400 to ARGB with matrix. |
3181 | | LIBYUV_API |
3182 | | int I400ToARGBMatrix(const uint8_t* src_y, |
3183 | | int src_stride_y, |
3184 | | uint8_t* dst_argb, |
3185 | | int dst_stride_argb, |
3186 | | const struct YuvConstants* yuvconstants, |
3187 | | int width, |
3188 | 325 | int height) { |
3189 | 325 | int y; |
3190 | 325 | void (*I400ToARGBRow)(const uint8_t* y_buf, uint8_t* rgb_buf, |
3191 | 325 | const struct YuvConstants* yuvconstants, int width) = |
3192 | 325 | I400ToARGBRow_C; |
3193 | 325 | assert(yuvconstants); |
3194 | 326 | if (!src_y || !dst_argb || width <= 0 || height == 0 || height == INT_MIN) { |
3195 | 0 | return -1; |
3196 | 0 | } |
3197 | | // Negative height means invert the image. |
3198 | 325 | if (height < 0) { |
3199 | 0 | height = -height; |
3200 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
3201 | 0 | dst_stride_argb = -dst_stride_argb; |
3202 | 0 | } |
3203 | | // Coalesce rows. |
3204 | 326 | if (src_stride_y == width && dst_stride_argb == width * 4 && |
3205 | 326 | (ptrdiff_t)width * height <= INT_MAX) { |
3206 | 326 | width *= height; |
3207 | 326 | height = 1; |
3208 | 326 | src_stride_y = dst_stride_argb = 0; |
3209 | 326 | } |
3210 | 325 | #if defined(HAS_I400TOARGBROW_SSE2) |
3211 | 326 | if (TestCpuFlag(kCpuHasSSE2)) { |
3212 | 326 | I400ToARGBRow = I400ToARGBRow_Any_SSE2; |
3213 | 326 | if (IS_ALIGNED(width, 8)) { |
3214 | 71 | I400ToARGBRow = I400ToARGBRow_SSE2; |
3215 | 71 | } |
3216 | 326 | } |
3217 | 325 | #endif |
3218 | 325 | #if defined(HAS_I400TOARGBROW_AVX2) |
3219 | 325 | if (TestCpuFlag(kCpuHasAVX2)) { |
3220 | 324 | I400ToARGBRow = I400ToARGBRow_Any_AVX2; |
3221 | 324 | if (IS_ALIGNED(width, 16)) { |
3222 | 38 | I400ToARGBRow = I400ToARGBRow_AVX2; |
3223 | 38 | } |
3224 | 324 | } |
3225 | 325 | #endif |
3226 | | #if defined(HAS_I400TOARGBROW_NEON) |
3227 | | if (TestCpuFlag(kCpuHasNEON)) { |
3228 | | I400ToARGBRow = I400ToARGBRow_Any_NEON; |
3229 | | if (IS_ALIGNED(width, 8)) { |
3230 | | I400ToARGBRow = I400ToARGBRow_NEON; |
3231 | | } |
3232 | | } |
3233 | | #endif |
3234 | | #if defined(HAS_I400TOARGBROW_SVE2) |
3235 | | if (TestCpuFlag(kCpuHasSVE2)) { |
3236 | | I400ToARGBRow = I400ToARGBRow_SVE2; |
3237 | | } |
3238 | | #endif |
3239 | | #if defined(HAS_I400TOARGBROW_SME) |
3240 | | if (TestCpuFlag(kCpuHasSME)) { |
3241 | | I400ToARGBRow = I400ToARGBRow_SME; |
3242 | | } |
3243 | | #endif |
3244 | | #if defined(HAS_I400TOARGBROW_LSX) |
3245 | | if (TestCpuFlag(kCpuHasLSX)) { |
3246 | | I400ToARGBRow = I400ToARGBRow_Any_LSX; |
3247 | | if (IS_ALIGNED(width, 16)) { |
3248 | | I400ToARGBRow = I400ToARGBRow_LSX; |
3249 | | } |
3250 | | } |
3251 | | #endif |
3252 | | #if defined(HAS_I400TOARGBROW_RVV) |
3253 | | if (TestCpuFlag(kCpuHasRVV)) { |
3254 | | I400ToARGBRow = I400ToARGBRow_RVV; |
3255 | | } |
3256 | | #endif |
3257 | | |
3258 | 649 | for (y = 0; y < height; ++y) { |
3259 | 324 | I400ToARGBRow(src_y, dst_argb, yuvconstants, width); |
3260 | 324 | dst_argb += dst_stride_argb; |
3261 | 324 | src_y += src_stride_y; |
3262 | 324 | } |
3263 | 325 | return 0; |
3264 | 325 | } |
3265 | | |
3266 | | // Convert I400 to ARGB. |
3267 | | LIBYUV_API |
3268 | | int I400ToARGB(const uint8_t* src_y, |
3269 | | int src_stride_y, |
3270 | | uint8_t* dst_argb, |
3271 | | int dst_stride_argb, |
3272 | | int width, |
3273 | 0 | int height) { |
3274 | 0 | return I400ToARGBMatrix(src_y, src_stride_y, dst_argb, dst_stride_argb, |
3275 | 0 | &kYuvI601Constants, width, height); |
3276 | 0 | } |
3277 | | |
3278 | | // Convert J400 to ARGB. |
3279 | | LIBYUV_API |
3280 | | int J400ToARGB(const uint8_t* src_y, |
3281 | | int src_stride_y, |
3282 | | uint8_t* dst_argb, |
3283 | | int dst_stride_argb, |
3284 | | int width, |
3285 | 0 | int height) { |
3286 | 0 | int y; |
3287 | 0 | void (*J400ToARGBRow)(const uint8_t* src_y, uint8_t* dst_argb, int width) = |
3288 | 0 | J400ToARGBRow_C; |
3289 | 0 | if (!src_y || !dst_argb || width <= 0 || height == 0 || height == INT_MIN) { |
3290 | 0 | return -1; |
3291 | 0 | } |
3292 | | // Negative height means invert the image. |
3293 | 0 | if (height < 0) { |
3294 | 0 | height = -height; |
3295 | 0 | src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; |
3296 | 0 | src_stride_y = -src_stride_y; |
3297 | 0 | } |
3298 | | // Coalesce rows. |
3299 | 0 | if (src_stride_y == width && dst_stride_argb == width * 4 && |
3300 | 0 | (ptrdiff_t)width * height <= INT_MAX) { |
3301 | 0 | width *= height; |
3302 | 0 | height = 1; |
3303 | 0 | src_stride_y = dst_stride_argb = 0; |
3304 | 0 | } |
3305 | |
|
3306 | 0 | #if defined(HAS_J400TOARGBROW_AVX2) |
3307 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
3308 | 0 | J400ToARGBRow = J400ToARGBRow_Any_AVX2; |
3309 | 0 | if (IS_ALIGNED(width, 16)) { |
3310 | 0 | J400ToARGBRow = J400ToARGBRow_AVX2; |
3311 | 0 | } |
3312 | 0 | } |
3313 | 0 | #endif |
3314 | 0 | #if defined(HAS_J400TOARGBROW_AVX512BW) |
3315 | 0 | if (TestCpuFlag(kCpuHasAVX512BW)) { |
3316 | 0 | J400ToARGBRow = J400ToARGBRow_Any_AVX512BW; |
3317 | 0 | if (IS_ALIGNED(width, 32)) { |
3318 | 0 | J400ToARGBRow = J400ToARGBRow_AVX512BW; |
3319 | 0 | } |
3320 | 0 | } |
3321 | 0 | #endif |
3322 | | #if defined(HAS_J400TOARGBROW_NEON) |
3323 | | if (TestCpuFlag(kCpuHasNEON)) { |
3324 | | J400ToARGBRow = J400ToARGBRow_Any_NEON; |
3325 | | if (IS_ALIGNED(width, 8)) { |
3326 | | J400ToARGBRow = J400ToARGBRow_NEON; |
3327 | | } |
3328 | | } |
3329 | | #endif |
3330 | | #if defined(HAS_J400TOARGBROW_LSX) |
3331 | | if (TestCpuFlag(kCpuHasLSX)) { |
3332 | | J400ToARGBRow = J400ToARGBRow_Any_LSX; |
3333 | | if (IS_ALIGNED(width, 16)) { |
3334 | | J400ToARGBRow = J400ToARGBRow_LSX; |
3335 | | } |
3336 | | } |
3337 | | #endif |
3338 | | #if defined(HAS_J400TOARGBROW_RVV) |
3339 | | if (TestCpuFlag(kCpuHasRVV)) { |
3340 | | J400ToARGBRow = J400ToARGBRow_RVV; |
3341 | | } |
3342 | | #endif |
3343 | |
|
3344 | 0 | for (y = 0; y < height; ++y) { |
3345 | 0 | J400ToARGBRow(src_y, dst_argb, width); |
3346 | 0 | src_y += src_stride_y; |
3347 | 0 | dst_argb += dst_stride_argb; |
3348 | 0 | } |
3349 | 0 | return 0; |
3350 | 0 | } |
3351 | | |
3352 | | #ifndef __riscv |
3353 | | // Shuffle table for converting BGRA to ARGB. |
3354 | | static const uvec8 kShuffleMaskBGRAToARGB = { |
3355 | | 3u, 2u, 1u, 0u, 7u, 6u, 5u, 4u, 11u, 10u, 9u, 8u, 15u, 14u, 13u, 12u}; |
3356 | | |
3357 | | // Shuffle table for converting ABGR to ARGB. |
3358 | | static const uvec8 kShuffleMaskABGRToARGB = { |
3359 | | 2u, 1u, 0u, 3u, 6u, 5u, 4u, 7u, 10u, 9u, 8u, 11u, 14u, 13u, 12u, 15u}; |
3360 | | |
3361 | | // Shuffle table for converting RGBA to ARGB. |
3362 | | static const uvec8 kShuffleMaskRGBAToARGB = { |
3363 | | 1u, 2u, 3u, 0u, 5u, 6u, 7u, 4u, 9u, 10u, 11u, 8u, 13u, 14u, 15u, 12u}; |
3364 | | |
3365 | | // Shuffle table for converting AR64 to AB64. |
3366 | | static const uvec8 kShuffleMaskAR64ToAB64 = { |
3367 | | 4u, 5u, 2u, 3u, 0u, 1u, 6u, 7u, 12u, 13u, 10u, 11u, 8u, 9u, 14u, 15u}; |
3368 | | |
3369 | | // Convert BGRA to ARGB. |
3370 | | LIBYUV_API |
3371 | | int BGRAToARGB(const uint8_t* src_bgra, |
3372 | | int src_stride_bgra, |
3373 | | uint8_t* dst_argb, |
3374 | | int dst_stride_argb, |
3375 | | int width, |
3376 | 0 | int height) { |
3377 | 0 | return ARGBShuffle(src_bgra, src_stride_bgra, dst_argb, dst_stride_argb, |
3378 | 0 | (const uint8_t*)&kShuffleMaskBGRAToARGB, width, height); |
3379 | 0 | } |
3380 | | |
3381 | | // Convert ARGB to BGRA (same as BGRAToARGB). |
3382 | | LIBYUV_API |
3383 | | int ARGBToBGRA(const uint8_t* src_argb, |
3384 | | int src_stride_argb, |
3385 | | uint8_t* dst_bgra, |
3386 | | int dst_stride_bgra, |
3387 | | int width, |
3388 | 0 | int height) { |
3389 | 0 | return ARGBShuffle(src_argb, src_stride_argb, dst_bgra, dst_stride_bgra, |
3390 | 0 | (const uint8_t*)&kShuffleMaskBGRAToARGB, width, height); |
3391 | 0 | } |
3392 | | |
3393 | | // Convert ABGR to ARGB. |
3394 | | LIBYUV_API |
3395 | | int ABGRToARGB(const uint8_t* src_abgr, |
3396 | | int src_stride_abgr, |
3397 | | uint8_t* dst_argb, |
3398 | | int dst_stride_argb, |
3399 | | int width, |
3400 | 0 | int height) { |
3401 | 0 | return ARGBShuffle(src_abgr, src_stride_abgr, dst_argb, dst_stride_argb, |
3402 | 0 | (const uint8_t*)&kShuffleMaskABGRToARGB, width, height); |
3403 | 0 | } |
3404 | | |
3405 | | // Convert ARGB to ABGR to (same as ABGRToARGB). |
3406 | | LIBYUV_API |
3407 | | int ARGBToABGR(const uint8_t* src_argb, |
3408 | | int src_stride_argb, |
3409 | | uint8_t* dst_abgr, |
3410 | | int dst_stride_abgr, |
3411 | | int width, |
3412 | 0 | int height) { |
3413 | 0 | return ARGBShuffle(src_argb, src_stride_argb, dst_abgr, dst_stride_abgr, |
3414 | 0 | (const uint8_t*)&kShuffleMaskABGRToARGB, width, height); |
3415 | 0 | } |
3416 | | |
3417 | | // Convert RGBA to ARGB. |
3418 | | LIBYUV_API |
3419 | | int RGBAToARGB(const uint8_t* src_rgba, |
3420 | | int src_stride_rgba, |
3421 | | uint8_t* dst_argb, |
3422 | | int dst_stride_argb, |
3423 | | int width, |
3424 | 0 | int height) { |
3425 | 0 | return ARGBShuffle(src_rgba, src_stride_rgba, dst_argb, dst_stride_argb, |
3426 | 0 | (const uint8_t*)&kShuffleMaskRGBAToARGB, width, height); |
3427 | 0 | } |
3428 | | |
3429 | | // Convert AR64 To AB64. |
3430 | | LIBYUV_API |
3431 | | int AR64ToAB64(const uint16_t* src_ar64, |
3432 | | int src_stride_ar64, |
3433 | | uint16_t* dst_ab64, |
3434 | | int dst_stride_ab64, |
3435 | | int width, |
3436 | 0 | int height) { |
3437 | 0 | return AR64Shuffle(src_ar64, src_stride_ar64, dst_ab64, dst_stride_ab64, |
3438 | 0 | (const uint8_t*)&kShuffleMaskAR64ToAB64, width, height); |
3439 | 0 | } |
3440 | | #else |
3441 | | // Convert BGRA to ARGB (same as ARGBToBGRA). |
3442 | | LIBYUV_API |
3443 | | int BGRAToARGB(const uint8_t* src_bgra, |
3444 | | int src_stride_bgra, |
3445 | | uint8_t* dst_argb, |
3446 | | int dst_stride_argb, |
3447 | | int width, |
3448 | | int height) { |
3449 | | return ARGBToBGRA(src_bgra, src_stride_bgra, dst_argb, dst_stride_argb, width, |
3450 | | height); |
3451 | | } |
3452 | | |
3453 | | // Convert ARGB to BGRA. |
3454 | | LIBYUV_API |
3455 | | int ARGBToBGRA(const uint8_t* src_argb, |
3456 | | int src_stride_argb, |
3457 | | uint8_t* dst_bgra, |
3458 | | int dst_stride_bgra, |
3459 | | int width, |
3460 | | int height) { |
3461 | | int y; |
3462 | | void (*ARGBToBGRARow)(const uint8_t* src_argb, uint8_t* dst_bgra, int width) = |
3463 | | ARGBToBGRARow_C; |
3464 | | if (!src_argb || !dst_bgra || width <= 0 || height == 0 || |
3465 | | height == INT_MIN) { |
3466 | | return -1; |
3467 | | } |
3468 | | // Negative height means invert the image. |
3469 | | if (height < 0) { |
3470 | | height = -height; |
3471 | | src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; |
3472 | | src_stride_argb = -src_stride_argb; |
3473 | | } |
3474 | | // Coalesce rows. |
3475 | | if (src_stride_argb == width * 4 && dst_stride_bgra == width * 4 && |
3476 | | (ptrdiff_t)width * height <= INT_MAX) { |
3477 | | width *= height; |
3478 | | height = 1; |
3479 | | src_stride_argb = dst_stride_bgra = 0; |
3480 | | } |
3481 | | |
3482 | | #if defined(HAS_ARGBTOBGRAROW_RVV) |
3483 | | if (TestCpuFlag(kCpuHasRVV)) { |
3484 | | ARGBToBGRARow = ARGBToBGRARow_RVV; |
3485 | | } |
3486 | | #endif |
3487 | | |
3488 | | for (y = 0; y < height; ++y) { |
3489 | | ARGBToBGRARow(src_argb, dst_bgra, width); |
3490 | | src_argb += src_stride_argb; |
3491 | | dst_bgra += dst_stride_bgra; |
3492 | | } |
3493 | | return 0; |
3494 | | } |
3495 | | |
3496 | | // Convert ARGB to ABGR. |
3497 | | LIBYUV_API |
3498 | | int ARGBToABGR(const uint8_t* src_argb, |
3499 | | int src_stride_argb, |
3500 | | uint8_t* dst_abgr, |
3501 | | int dst_stride_abgr, |
3502 | | int width, |
3503 | | int height) { |
3504 | | int y; |
3505 | | void (*ARGBToABGRRow)(const uint8_t* src_argb, uint8_t* dst_abgr, int width) = |
3506 | | ARGBToABGRRow_C; |
3507 | | if (!src_argb || !dst_abgr || width <= 0 || height == 0 || |
3508 | | height == INT_MIN) { |
3509 | | return -1; |
3510 | | } |
3511 | | // Negative height means invert the image. |
3512 | | if (height < 0) { |
3513 | | height = -height; |
3514 | | src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; |
3515 | | src_stride_argb = -src_stride_argb; |
3516 | | } |
3517 | | // Coalesce rows. |
3518 | | if (src_stride_argb == width * 4 && dst_stride_abgr == width * 4 && |
3519 | | (ptrdiff_t)width * height <= INT_MAX) { |
3520 | | width *= height; |
3521 | | height = 1; |
3522 | | src_stride_argb = dst_stride_abgr = 0; |
3523 | | } |
3524 | | |
3525 | | #if defined(HAS_ARGBTOABGRROW_RVV) |
3526 | | if (TestCpuFlag(kCpuHasRVV)) { |
3527 | | ARGBToABGRRow = ARGBToABGRRow_RVV; |
3528 | | } |
3529 | | #endif |
3530 | | |
3531 | | for (y = 0; y < height; ++y) { |
3532 | | ARGBToABGRRow(src_argb, dst_abgr, width); |
3533 | | src_argb += src_stride_argb; |
3534 | | dst_abgr += dst_stride_abgr; |
3535 | | } |
3536 | | return 0; |
3537 | | } |
3538 | | |
3539 | | // Convert ABGR to ARGB (same as ARGBToABGR). |
3540 | | LIBYUV_API |
3541 | | int ABGRToARGB(const uint8_t* src_abgr, |
3542 | | int src_stride_abgr, |
3543 | | uint8_t* dst_argb, |
3544 | | int dst_stride_argb, |
3545 | | int width, |
3546 | | int height) { |
3547 | | return ARGBToABGR(src_abgr, src_stride_abgr, dst_argb, dst_stride_argb, width, |
3548 | | height); |
3549 | | } |
3550 | | |
3551 | | // Convert RGBA to ARGB. |
3552 | | LIBYUV_API |
3553 | | int RGBAToARGB(const uint8_t* src_rgba, |
3554 | | int src_stride_rgba, |
3555 | | uint8_t* dst_argb, |
3556 | | int dst_stride_argb, |
3557 | | int width, |
3558 | | int height) { |
3559 | | int y; |
3560 | | void (*RGBAToARGBRow)(const uint8_t* src_rgba, uint8_t* dst_argb, int width) = |
3561 | | RGBAToARGBRow_C; |
3562 | | if (!src_rgba || !dst_argb || width <= 0 || height == 0 || |
3563 | | height == INT_MIN) { |
3564 | | return -1; |
3565 | | } |
3566 | | // Negative height means invert the image. |
3567 | | if (height < 0) { |
3568 | | height = -height; |
3569 | | src_rgba = src_rgba + (ptrdiff_t)(height - 1) * src_stride_rgba; |
3570 | | src_stride_rgba = -src_stride_rgba; |
3571 | | } |
3572 | | // Coalesce rows. |
3573 | | if (src_stride_rgba == width * 4 && dst_stride_argb == width * 4 && |
3574 | | (ptrdiff_t)width * height <= INT_MAX) { |
3575 | | width *= height; |
3576 | | height = 1; |
3577 | | src_stride_rgba = dst_stride_argb = 0; |
3578 | | } |
3579 | | |
3580 | | #if defined(HAS_RGBATOARGBROW_RVV) |
3581 | | if (TestCpuFlag(kCpuHasRVV)) { |
3582 | | RGBAToARGBRow = RGBAToARGBRow_RVV; |
3583 | | } |
3584 | | #endif |
3585 | | |
3586 | | for (y = 0; y < height; ++y) { |
3587 | | RGBAToARGBRow(src_rgba, dst_argb, width); |
3588 | | src_rgba += src_stride_rgba; |
3589 | | dst_argb += dst_stride_argb; |
3590 | | } |
3591 | | return 0; |
3592 | | } |
3593 | | |
3594 | | // Convert AR64 To AB64. |
3595 | | LIBYUV_API |
3596 | | int AR64ToAB64(const uint16_t* src_ar64, |
3597 | | int src_stride_ar64, |
3598 | | uint16_t* dst_ab64, |
3599 | | int dst_stride_ab64, |
3600 | | int width, |
3601 | | int height) { |
3602 | | int y; |
3603 | | void (*AR64ToAB64Row)(const uint16_t* src_ar64, uint16_t* dst_ab64, |
3604 | | int width) = AR64ToAB64Row_C; |
3605 | | if (!src_ar64 || !dst_ab64 || width <= 0 || height == 0 || |
3606 | | height == INT_MIN) { |
3607 | | return -1; |
3608 | | } |
3609 | | // Negative height means invert the image. |
3610 | | if (height < 0) { |
3611 | | height = -height; |
3612 | | src_ar64 = src_ar64 + (ptrdiff_t)(height - 1) * src_stride_ar64; |
3613 | | src_stride_ar64 = -src_stride_ar64; |
3614 | | } |
3615 | | // Coalesce rows. |
3616 | | if (src_stride_ar64 == width * 4 && dst_stride_ab64 == width * 4 && |
3617 | | (ptrdiff_t)width * height <= INT_MAX) { |
3618 | | width *= height; |
3619 | | height = 1; |
3620 | | src_stride_ar64 = dst_stride_ab64 = 0; |
3621 | | } |
3622 | | |
3623 | | #if defined(HAS_AR64TOAB64ROW_RVV) |
3624 | | if (TestCpuFlag(kCpuHasRVV)) { |
3625 | | AR64ToAB64Row = AR64ToAB64Row_RVV; |
3626 | | } |
3627 | | #endif |
3628 | | |
3629 | | for (y = 0; y < height; ++y) { |
3630 | | AR64ToAB64Row(src_ar64, dst_ab64, width); |
3631 | | src_ar64 += src_stride_ar64; |
3632 | | dst_ab64 += dst_stride_ab64; |
3633 | | } |
3634 | | return 0; |
3635 | | } |
3636 | | #endif |
3637 | | |
3638 | | // Convert RGB24 to ARGB. |
3639 | | LIBYUV_API |
3640 | | int RGB24ToARGB(const uint8_t* src_rgb24, |
3641 | | int src_stride_rgb24, |
3642 | | uint8_t* dst_argb, |
3643 | | int dst_stride_argb, |
3644 | | int width, |
3645 | 0 | int height) { |
3646 | 0 | int y; |
3647 | 0 | void (*RGB24ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = |
3648 | 0 | RGB24ToARGBRow_C; |
3649 | 0 | if (!src_rgb24 || !dst_argb || width <= 0 || height == 0 || |
3650 | 0 | height == INT_MIN) { |
3651 | 0 | return -1; |
3652 | 0 | } |
3653 | | // Negative height means invert the image. |
3654 | 0 | if (height < 0) { |
3655 | 0 | height = -height; |
3656 | 0 | src_rgb24 = src_rgb24 + (ptrdiff_t)(height - 1) * src_stride_rgb24; |
3657 | 0 | src_stride_rgb24 = -src_stride_rgb24; |
3658 | 0 | } |
3659 | | // Coalesce rows. |
3660 | 0 | if (src_stride_rgb24 == width * 3 && dst_stride_argb == width * 4 && |
3661 | 0 | (ptrdiff_t)width * height <= INT_MAX) { |
3662 | 0 | width *= height; |
3663 | 0 | height = 1; |
3664 | 0 | src_stride_rgb24 = dst_stride_argb = 0; |
3665 | 0 | } |
3666 | 0 | #if defined(HAS_RGB24TOARGBROW_SSSE3) |
3667 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
3668 | 0 | RGB24ToARGBRow = RGB24ToARGBRow_Any_SSSE3; |
3669 | 0 | if (IS_ALIGNED(width, 16)) { |
3670 | 0 | RGB24ToARGBRow = RGB24ToARGBRow_SSSE3; |
3671 | 0 | } |
3672 | 0 | } |
3673 | 0 | #endif |
3674 | 0 | #if defined(HAS_RGB24TOARGBROW_AVX2) |
3675 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
3676 | 0 | RGB24ToARGBRow = RGB24ToARGBRow_Any_AVX2; |
3677 | 0 | if (IS_ALIGNED(width, 32)) { |
3678 | 0 | RGB24ToARGBRow = RGB24ToARGBRow_AVX2; |
3679 | 0 | } |
3680 | 0 | } |
3681 | 0 | #endif |
3682 | 0 | #if defined(HAS_RGB24TOARGBROW_AVX512BW) |
3683 | 0 | if (TestCpuFlag(kCpuHasAVX512BW)) { |
3684 | 0 | RGB24ToARGBRow = RGB24ToARGBRow_Any_AVX512BW; |
3685 | 0 | if (IS_ALIGNED(width, 64)) { |
3686 | 0 | RGB24ToARGBRow = RGB24ToARGBRow_AVX512BW; |
3687 | 0 | } |
3688 | 0 | } |
3689 | 0 | #endif |
3690 | | #if defined(HAS_RGB24TOARGBROW_NEON) |
3691 | | if (TestCpuFlag(kCpuHasNEON)) { |
3692 | | RGB24ToARGBRow = RGB24ToARGBRow_Any_NEON; |
3693 | | if (IS_ALIGNED(width, 8)) { |
3694 | | RGB24ToARGBRow = RGB24ToARGBRow_NEON; |
3695 | | } |
3696 | | } |
3697 | | #endif |
3698 | | #if defined(HAS_RGB24TOARGBROW_SVE2) |
3699 | | if (TestCpuFlag(kCpuHasSVE2)) { |
3700 | | RGB24ToARGBRow = RGB24ToARGBRow_SVE2; |
3701 | | } |
3702 | | #endif |
3703 | | #if defined(HAS_RGB24TOARGBROW_LSX) |
3704 | | if (TestCpuFlag(kCpuHasLSX)) { |
3705 | | RGB24ToARGBRow = RGB24ToARGBRow_Any_LSX; |
3706 | | if (IS_ALIGNED(width, 16)) { |
3707 | | RGB24ToARGBRow = RGB24ToARGBRow_LSX; |
3708 | | } |
3709 | | } |
3710 | | #endif |
3711 | | #if defined(HAS_RGB24TOARGBROW_LASX) |
3712 | | if (TestCpuFlag(kCpuHasLASX)) { |
3713 | | RGB24ToARGBRow = RGB24ToARGBRow_Any_LASX; |
3714 | | if (IS_ALIGNED(width, 32)) { |
3715 | | RGB24ToARGBRow = RGB24ToARGBRow_LASX; |
3716 | | } |
3717 | | } |
3718 | | #endif |
3719 | | #if defined(HAS_RGB24TOARGBROW_RVV) |
3720 | | if (TestCpuFlag(kCpuHasRVV)) { |
3721 | | RGB24ToARGBRow = RGB24ToARGBRow_RVV; |
3722 | | } |
3723 | | #endif |
3724 | 0 | for (y = 0; y < height; ++y) { |
3725 | 0 | RGB24ToARGBRow(src_rgb24, dst_argb, width); |
3726 | 0 | src_rgb24 += src_stride_rgb24; |
3727 | 0 | dst_argb += dst_stride_argb; |
3728 | 0 | } |
3729 | 0 | return 0; |
3730 | 0 | } |
3731 | | |
3732 | | // Convert RAW to ARGB. |
3733 | | LIBYUV_API |
3734 | | int RAWToARGB(const uint8_t* src_raw, |
3735 | | int src_stride_raw, |
3736 | | uint8_t* dst_argb, |
3737 | | int dst_stride_argb, |
3738 | | int width, |
3739 | 228k | int height) { |
3740 | 228k | int y; |
3741 | 228k | void (*RAWToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = |
3742 | 228k | RAWToARGBRow_C; |
3743 | 228k | if (!src_raw || !dst_argb || width <= 0 || height == 0 || height == INT_MIN) { |
3744 | 0 | return -1; |
3745 | 0 | } |
3746 | | // Negative height means invert the image. |
3747 | 228k | if (height < 0) { |
3748 | 0 | height = -height; |
3749 | 0 | src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; |
3750 | 0 | src_stride_raw = -src_stride_raw; |
3751 | 0 | } |
3752 | | // Coalesce rows. |
3753 | 228k | if (src_stride_raw == width * 3 && dst_stride_argb == width * 4 && |
3754 | 228k | (ptrdiff_t)width * height <= INT_MAX) { |
3755 | 228k | width *= height; |
3756 | 228k | height = 1; |
3757 | 228k | src_stride_raw = dst_stride_argb = 0; |
3758 | 228k | } |
3759 | 228k | #if defined(HAS_RAWTOARGBROW_SSSE3) |
3760 | 228k | if (TestCpuFlag(kCpuHasSSSE3)) { |
3761 | 228k | RAWToARGBRow = RAWToARGBRow_Any_SSSE3; |
3762 | 228k | if (IS_ALIGNED(width, 16)) { |
3763 | 25.9k | RAWToARGBRow = RAWToARGBRow_SSSE3; |
3764 | 25.9k | } |
3765 | 228k | } |
3766 | 228k | #endif |
3767 | 228k | #if defined(HAS_RAWTOARGBROW_AVX2) |
3768 | 228k | if (TestCpuFlag(kCpuHasAVX2)) { |
3769 | 228k | RAWToARGBRow = RAWToARGBRow_Any_AVX2; |
3770 | 228k | if (IS_ALIGNED(width, 32)) { |
3771 | 25.0k | RAWToARGBRow = RAWToARGBRow_AVX2; |
3772 | 25.0k | } |
3773 | 228k | } |
3774 | 228k | #endif |
3775 | 228k | #if defined(HAS_RAWTOARGBROW_AVX512BW) |
3776 | 228k | if (TestCpuFlag(kCpuHasAVX512BW)) { |
3777 | 0 | RAWToARGBRow = RAWToARGBRow_Any_AVX512BW; |
3778 | 0 | if (IS_ALIGNED(width, 64)) { |
3779 | 0 | RAWToARGBRow = RAWToARGBRow_AVX512BW; |
3780 | 0 | } |
3781 | 0 | } |
3782 | 228k | #endif |
3783 | | #if defined(HAS_RAWTOARGBROW_NEON) |
3784 | | if (TestCpuFlag(kCpuHasNEON)) { |
3785 | | RAWToARGBRow = RAWToARGBRow_Any_NEON; |
3786 | | if (IS_ALIGNED(width, 8)) { |
3787 | | RAWToARGBRow = RAWToARGBRow_NEON; |
3788 | | } |
3789 | | } |
3790 | | #endif |
3791 | | #if defined(HAS_RAWTOARGBROW_SVE2) |
3792 | | if (TestCpuFlag(kCpuHasSVE2)) { |
3793 | | RAWToARGBRow = RAWToARGBRow_SVE2; |
3794 | | } |
3795 | | #endif |
3796 | | #if defined(HAS_RAWTOARGBROW_LSX) |
3797 | | if (TestCpuFlag(kCpuHasLSX)) { |
3798 | | RAWToARGBRow = RAWToARGBRow_Any_LSX; |
3799 | | if (IS_ALIGNED(width, 16)) { |
3800 | | RAWToARGBRow = RAWToARGBRow_LSX; |
3801 | | } |
3802 | | } |
3803 | | #endif |
3804 | | #if defined(HAS_RAWTOARGBROW_LASX) |
3805 | | if (TestCpuFlag(kCpuHasLASX)) { |
3806 | | RAWToARGBRow = RAWToARGBRow_Any_LASX; |
3807 | | if (IS_ALIGNED(width, 32)) { |
3808 | | RAWToARGBRow = RAWToARGBRow_LASX; |
3809 | | } |
3810 | | } |
3811 | | #endif |
3812 | | #if defined(HAS_RAWTOARGBROW_RVV) |
3813 | | if (TestCpuFlag(kCpuHasRVV)) { |
3814 | | RAWToARGBRow = RAWToARGBRow_RVV; |
3815 | | } |
3816 | | #endif |
3817 | | |
3818 | 457k | for (y = 0; y < height; ++y) { |
3819 | 228k | RAWToARGBRow(src_raw, dst_argb, width); |
3820 | 228k | src_raw += src_stride_raw; |
3821 | 228k | dst_argb += dst_stride_argb; |
3822 | 228k | } |
3823 | 228k | return 0; |
3824 | 228k | } |
3825 | | |
3826 | | // Convert RAW to RGBA. |
3827 | | LIBYUV_API |
3828 | | int RAWToRGBA(const uint8_t* src_raw, |
3829 | | int src_stride_raw, |
3830 | | uint8_t* dst_rgba, |
3831 | | int dst_stride_rgba, |
3832 | | int width, |
3833 | 0 | int height) { |
3834 | 0 | int y; |
3835 | 0 | void (*RAWToRGBARow)(const uint8_t* src_rgb, uint8_t* dst_rgba, int width) = |
3836 | 0 | RAWToRGBARow_C; |
3837 | 0 | if (!src_raw || !dst_rgba || width <= 0 || height == 0 || height == INT_MIN) { |
3838 | 0 | return -1; |
3839 | 0 | } |
3840 | | // Negative height means invert the image. |
3841 | 0 | if (height < 0) { |
3842 | 0 | height = -height; |
3843 | 0 | src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; |
3844 | 0 | src_stride_raw = -src_stride_raw; |
3845 | 0 | } |
3846 | | // Coalesce rows. |
3847 | 0 | if (src_stride_raw == width * 3 && dst_stride_rgba == width * 4 && |
3848 | 0 | (ptrdiff_t)width * height <= INT_MAX) { |
3849 | 0 | width *= height; |
3850 | 0 | height = 1; |
3851 | 0 | src_stride_raw = dst_stride_rgba = 0; |
3852 | 0 | } |
3853 | 0 | #if defined(HAS_RAWTORGBAROW_SSSE3) |
3854 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
3855 | 0 | RAWToRGBARow = RAWToRGBARow_Any_SSSE3; |
3856 | 0 | if (IS_ALIGNED(width, 16)) { |
3857 | 0 | RAWToRGBARow = RAWToRGBARow_SSSE3; |
3858 | 0 | } |
3859 | 0 | } |
3860 | 0 | #endif |
3861 | | #if defined(HAS_RAWTORGBAROW_NEON) |
3862 | | if (TestCpuFlag(kCpuHasNEON)) { |
3863 | | RAWToRGBARow = RAWToRGBARow_Any_NEON; |
3864 | | if (IS_ALIGNED(width, 8)) { |
3865 | | RAWToRGBARow = RAWToRGBARow_NEON; |
3866 | | } |
3867 | | } |
3868 | | #endif |
3869 | | #if defined(HAS_RAWTORGBAROW_SVE2) |
3870 | | if (TestCpuFlag(kCpuHasSVE2)) { |
3871 | | RAWToRGBARow = RAWToRGBARow_SVE2; |
3872 | | } |
3873 | | #endif |
3874 | | #if defined(HAS_RAWTORGBAROW_RVV) |
3875 | | if (TestCpuFlag(kCpuHasRVV)) { |
3876 | | RAWToRGBARow = RAWToRGBARow_RVV; |
3877 | | } |
3878 | | #endif |
3879 | |
|
3880 | 0 | for (y = 0; y < height; ++y) { |
3881 | 0 | RAWToRGBARow(src_raw, dst_rgba, width); |
3882 | 0 | src_raw += src_stride_raw; |
3883 | 0 | dst_rgba += dst_stride_rgba; |
3884 | 0 | } |
3885 | 0 | return 0; |
3886 | 0 | } |
3887 | | |
3888 | | // Convert RGB565 to ARGB. |
3889 | | LIBYUV_API |
3890 | | int RGB565ToARGB(const uint8_t* src_rgb565, |
3891 | | int src_stride_rgb565, |
3892 | | uint8_t* dst_argb, |
3893 | | int dst_stride_argb, |
3894 | | int width, |
3895 | 0 | int height) { |
3896 | 0 | int y; |
3897 | 0 | void (*RGB565ToARGBRow)(const uint8_t* src_rgb565, uint8_t* dst_argb, |
3898 | 0 | int width) = RGB565ToARGBRow_C; |
3899 | 0 | if (!src_rgb565 || !dst_argb || width <= 0 || height == 0 || |
3900 | 0 | height == INT_MIN) { |
3901 | 0 | return -1; |
3902 | 0 | } |
3903 | | // Negative height means invert the image. |
3904 | 0 | if (height < 0) { |
3905 | 0 | height = -height; |
3906 | 0 | src_rgb565 = src_rgb565 + (ptrdiff_t)(height - 1) * src_stride_rgb565; |
3907 | 0 | src_stride_rgb565 = -src_stride_rgb565; |
3908 | 0 | } |
3909 | | // Coalesce rows. |
3910 | 0 | if (src_stride_rgb565 == width * 2 && dst_stride_argb == width * 4 && |
3911 | 0 | (ptrdiff_t)width * height <= INT_MAX) { |
3912 | 0 | width *= height; |
3913 | 0 | height = 1; |
3914 | 0 | src_stride_rgb565 = dst_stride_argb = 0; |
3915 | 0 | } |
3916 | |
|
3917 | 0 | #if defined(HAS_RGB565TOARGBROW_AVX2) |
3918 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
3919 | 0 | RGB565ToARGBRow = RGB565ToARGBRow_Any_AVX2; |
3920 | 0 | if (IS_ALIGNED(width, 16)) { |
3921 | 0 | RGB565ToARGBRow = RGB565ToARGBRow_AVX2; |
3922 | 0 | } |
3923 | 0 | } |
3924 | 0 | #endif |
3925 | | #if defined(HAS_RGB565TOARGBROW_NEON) |
3926 | | if (TestCpuFlag(kCpuHasNEON)) { |
3927 | | RGB565ToARGBRow = RGB565ToARGBRow_Any_NEON; |
3928 | | if (IS_ALIGNED(width, 16)) { |
3929 | | RGB565ToARGBRow = RGB565ToARGBRow_NEON; |
3930 | | } |
3931 | | } |
3932 | | #endif |
3933 | | #if defined(HAS_RGB565TOARGBROW_LSX) |
3934 | | if (TestCpuFlag(kCpuHasLSX)) { |
3935 | | RGB565ToARGBRow = RGB565ToARGBRow_Any_LSX; |
3936 | | if (IS_ALIGNED(width, 16)) { |
3937 | | RGB565ToARGBRow = RGB565ToARGBRow_LSX; |
3938 | | } |
3939 | | } |
3940 | | #endif |
3941 | | #if defined(HAS_RGB565TOARGBROW_LASX) |
3942 | | if (TestCpuFlag(kCpuHasLASX)) { |
3943 | | RGB565ToARGBRow = RGB565ToARGBRow_Any_LASX; |
3944 | | if (IS_ALIGNED(width, 32)) { |
3945 | | RGB565ToARGBRow = RGB565ToARGBRow_LASX; |
3946 | | } |
3947 | | } |
3948 | | #endif |
3949 | |
|
3950 | 0 | for (y = 0; y < height; ++y) { |
3951 | 0 | RGB565ToARGBRow(src_rgb565, dst_argb, width); |
3952 | 0 | src_rgb565 += src_stride_rgb565; |
3953 | 0 | dst_argb += dst_stride_argb; |
3954 | 0 | } |
3955 | 0 | return 0; |
3956 | 0 | } |
3957 | | |
3958 | | // Convert ARGB1555 to ARGB. |
3959 | | LIBYUV_API |
3960 | | int ARGB1555ToARGB(const uint8_t* src_argb1555, |
3961 | | int src_stride_argb1555, |
3962 | | uint8_t* dst_argb, |
3963 | | int dst_stride_argb, |
3964 | | int width, |
3965 | 0 | int height) { |
3966 | 0 | int y; |
3967 | 0 | void (*ARGB1555ToARGBRow)(const uint8_t* src_argb1555, uint8_t* dst_argb, |
3968 | 0 | int width) = ARGB1555ToARGBRow_C; |
3969 | 0 | if (!src_argb1555 || !dst_argb || width <= 0 || height == 0 || |
3970 | 0 | height == INT_MIN) { |
3971 | 0 | return -1; |
3972 | 0 | } |
3973 | | // Negative height means invert the image. |
3974 | 0 | if (height < 0) { |
3975 | 0 | height = -height; |
3976 | 0 | src_argb1555 = src_argb1555 + (ptrdiff_t)(height - 1) * src_stride_argb1555; |
3977 | 0 | src_stride_argb1555 = -src_stride_argb1555; |
3978 | 0 | } |
3979 | | // Coalesce rows. |
3980 | 0 | if (src_stride_argb1555 == width * 2 && dst_stride_argb == width * 4 && |
3981 | 0 | (ptrdiff_t)width * height <= INT_MAX) { |
3982 | 0 | width *= height; |
3983 | 0 | height = 1; |
3984 | 0 | src_stride_argb1555 = dst_stride_argb = 0; |
3985 | 0 | } |
3986 | |
|
3987 | 0 | #if defined(HAS_ARGB1555TOARGBROW_AVX2) |
3988 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
3989 | 0 | ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_AVX2; |
3990 | 0 | if (IS_ALIGNED(width, 16)) { |
3991 | 0 | ARGB1555ToARGBRow = ARGB1555ToARGBRow_AVX2; |
3992 | 0 | } |
3993 | 0 | } |
3994 | 0 | #endif |
3995 | | #if defined(HAS_ARGB1555TOARGBROW_NEON) |
3996 | | if (TestCpuFlag(kCpuHasNEON)) { |
3997 | | ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_NEON; |
3998 | | if (IS_ALIGNED(width, 16)) { |
3999 | | ARGB1555ToARGBRow = ARGB1555ToARGBRow_NEON; |
4000 | | } |
4001 | | } |
4002 | | #endif |
4003 | | #if defined(HAS_ARGB1555TOARGBROW_SVE2) |
4004 | | if (TestCpuFlag(kCpuHasSVE2)) { |
4005 | | ARGB1555ToARGBRow = ARGB1555ToARGBRow_SVE2; |
4006 | | } |
4007 | | #endif |
4008 | | #if defined(HAS_ARGB1555TOARGBROW_LSX) |
4009 | | if (TestCpuFlag(kCpuHasLSX)) { |
4010 | | ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_LSX; |
4011 | | if (IS_ALIGNED(width, 16)) { |
4012 | | ARGB1555ToARGBRow = ARGB1555ToARGBRow_LSX; |
4013 | | } |
4014 | | } |
4015 | | #endif |
4016 | | #if defined(HAS_ARGB1555TOARGBROW_LASX) |
4017 | | if (TestCpuFlag(kCpuHasLASX)) { |
4018 | | ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_LASX; |
4019 | | if (IS_ALIGNED(width, 32)) { |
4020 | | ARGB1555ToARGBRow = ARGB1555ToARGBRow_LASX; |
4021 | | } |
4022 | | } |
4023 | | #endif |
4024 | |
|
4025 | 0 | for (y = 0; y < height; ++y) { |
4026 | 0 | ARGB1555ToARGBRow(src_argb1555, dst_argb, width); |
4027 | 0 | src_argb1555 += src_stride_argb1555; |
4028 | 0 | dst_argb += dst_stride_argb; |
4029 | 0 | } |
4030 | 0 | return 0; |
4031 | 0 | } |
4032 | | |
4033 | | // Convert ARGB4444 to ARGB. |
4034 | | LIBYUV_API |
4035 | | int ARGB4444ToARGB(const uint8_t* src_argb4444, |
4036 | | int src_stride_argb4444, |
4037 | | uint8_t* dst_argb, |
4038 | | int dst_stride_argb, |
4039 | | int width, |
4040 | 0 | int height) { |
4041 | 0 | int y; |
4042 | 0 | void (*ARGB4444ToARGBRow)(const uint8_t* src_argb4444, uint8_t* dst_argb, |
4043 | 0 | int width) = ARGB4444ToARGBRow_C; |
4044 | 0 | if (!src_argb4444 || !dst_argb || width <= 0 || height == 0 || |
4045 | 0 | height == INT_MIN) { |
4046 | 0 | return -1; |
4047 | 0 | } |
4048 | | // Negative height means invert the image. |
4049 | 0 | if (height < 0) { |
4050 | 0 | height = -height; |
4051 | 0 | src_argb4444 = src_argb4444 + (ptrdiff_t)(height - 1) * src_stride_argb4444; |
4052 | 0 | src_stride_argb4444 = -src_stride_argb4444; |
4053 | 0 | } |
4054 | | // Coalesce rows. |
4055 | 0 | if (src_stride_argb4444 == width * 2 && dst_stride_argb == width * 4 && |
4056 | 0 | (ptrdiff_t)width * height <= INT_MAX) { |
4057 | 0 | width *= height; |
4058 | 0 | height = 1; |
4059 | 0 | src_stride_argb4444 = dst_stride_argb = 0; |
4060 | 0 | } |
4061 | |
|
4062 | 0 | #if defined(HAS_ARGB4444TOARGBROW_AVX2) |
4063 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
4064 | 0 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_AVX2; |
4065 | 0 | if (IS_ALIGNED(width, 16)) { |
4066 | 0 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_AVX2; |
4067 | 0 | } |
4068 | 0 | } |
4069 | 0 | #endif |
4070 | | #if defined(HAS_ARGB4444TOARGBROW_NEON) |
4071 | | if (TestCpuFlag(kCpuHasNEON)) { |
4072 | | ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_NEON; |
4073 | | if (IS_ALIGNED(width, 8)) { |
4074 | | ARGB4444ToARGBRow = ARGB4444ToARGBRow_NEON; |
4075 | | } |
4076 | | } |
4077 | | #endif |
4078 | | #if defined(HAS_ARGB4444TOARGBROW_LSX) |
4079 | | if (TestCpuFlag(kCpuHasLSX)) { |
4080 | | ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_LSX; |
4081 | | if (IS_ALIGNED(width, 16)) { |
4082 | | ARGB4444ToARGBRow = ARGB4444ToARGBRow_LSX; |
4083 | | } |
4084 | | } |
4085 | | #endif |
4086 | | #if defined(HAS_ARGB4444TOARGBROW_LASX) |
4087 | | if (TestCpuFlag(kCpuHasLASX)) { |
4088 | | ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_LASX; |
4089 | | if (IS_ALIGNED(width, 32)) { |
4090 | | ARGB4444ToARGBRow = ARGB4444ToARGBRow_LASX; |
4091 | | } |
4092 | | } |
4093 | | #endif |
4094 | |
|
4095 | 0 | for (y = 0; y < height; ++y) { |
4096 | 0 | ARGB4444ToARGBRow(src_argb4444, dst_argb, width); |
4097 | 0 | src_argb4444 += src_stride_argb4444; |
4098 | 0 | dst_argb += dst_stride_argb; |
4099 | 0 | } |
4100 | 0 | return 0; |
4101 | 0 | } |
4102 | | |
4103 | | // Convert AR30 to ARGB. |
4104 | | LIBYUV_API |
4105 | | int AR30ToARGB(const uint8_t* src_ar30, |
4106 | | int src_stride_ar30, |
4107 | | uint8_t* dst_argb, |
4108 | | int dst_stride_argb, |
4109 | | int width, |
4110 | 0 | int height) { |
4111 | 0 | int y; |
4112 | 0 | if (!src_ar30 || !dst_argb || width <= 0 || height == 0 || |
4113 | 0 | height == INT_MIN) { |
4114 | 0 | return -1; |
4115 | 0 | } |
4116 | | // Negative height means invert the image. |
4117 | 0 | if (height < 0) { |
4118 | 0 | height = -height; |
4119 | 0 | src_ar30 = src_ar30 + (ptrdiff_t)(height - 1) * src_stride_ar30; |
4120 | 0 | src_stride_ar30 = -src_stride_ar30; |
4121 | 0 | } |
4122 | | // Coalesce rows. |
4123 | 0 | if (src_stride_ar30 == width * 4 && dst_stride_argb == width * 4 && |
4124 | 0 | (ptrdiff_t)width * height <= INT_MAX) { |
4125 | 0 | width *= height; |
4126 | 0 | height = 1; |
4127 | 0 | src_stride_ar30 = dst_stride_argb = 0; |
4128 | 0 | } |
4129 | 0 | for (y = 0; y < height; ++y) { |
4130 | 0 | AR30ToARGBRow_C(src_ar30, dst_argb, width); |
4131 | 0 | src_ar30 += src_stride_ar30; |
4132 | 0 | dst_argb += dst_stride_argb; |
4133 | 0 | } |
4134 | 0 | return 0; |
4135 | 0 | } |
4136 | | |
4137 | | // Convert AR30 to ABGR. |
4138 | | LIBYUV_API |
4139 | | int AR30ToABGR(const uint8_t* src_ar30, |
4140 | | int src_stride_ar30, |
4141 | | uint8_t* dst_abgr, |
4142 | | int dst_stride_abgr, |
4143 | | int width, |
4144 | 0 | int height) { |
4145 | 0 | int y; |
4146 | 0 | if (!src_ar30 || !dst_abgr || width <= 0 || height == 0 || |
4147 | 0 | height == INT_MIN) { |
4148 | 0 | return -1; |
4149 | 0 | } |
4150 | | // Negative height means invert the image. |
4151 | 0 | if (height < 0) { |
4152 | 0 | height = -height; |
4153 | 0 | src_ar30 = src_ar30 + (ptrdiff_t)(height - 1) * src_stride_ar30; |
4154 | 0 | src_stride_ar30 = -src_stride_ar30; |
4155 | 0 | } |
4156 | | // Coalesce rows. |
4157 | 0 | if (src_stride_ar30 == width * 4 && dst_stride_abgr == width * 4 && |
4158 | 0 | (ptrdiff_t)width * height <= INT_MAX) { |
4159 | 0 | width *= height; |
4160 | 0 | height = 1; |
4161 | 0 | src_stride_ar30 = dst_stride_abgr = 0; |
4162 | 0 | } |
4163 | 0 | for (y = 0; y < height; ++y) { |
4164 | 0 | AR30ToABGRRow_C(src_ar30, dst_abgr, width); |
4165 | 0 | src_ar30 += src_stride_ar30; |
4166 | 0 | dst_abgr += dst_stride_abgr; |
4167 | 0 | } |
4168 | 0 | return 0; |
4169 | 0 | } |
4170 | | |
4171 | | // Convert AR30 to AB30. |
4172 | | LIBYUV_API |
4173 | | int AR30ToAB30(const uint8_t* src_ar30, |
4174 | | int src_stride_ar30, |
4175 | | uint8_t* dst_ab30, |
4176 | | int dst_stride_ab30, |
4177 | | int width, |
4178 | 0 | int height) { |
4179 | 0 | int y; |
4180 | 0 | if (!src_ar30 || !dst_ab30 || width <= 0 || height == 0 || |
4181 | 0 | height == INT_MIN) { |
4182 | 0 | return -1; |
4183 | 0 | } |
4184 | | // Negative height means invert the image. |
4185 | 0 | if (height < 0) { |
4186 | 0 | height = -height; |
4187 | 0 | src_ar30 = src_ar30 + (ptrdiff_t)(height - 1) * src_stride_ar30; |
4188 | 0 | src_stride_ar30 = -src_stride_ar30; |
4189 | 0 | } |
4190 | | // Coalesce rows. |
4191 | 0 | if (src_stride_ar30 == width * 4 && dst_stride_ab30 == width * 4 && |
4192 | 0 | (ptrdiff_t)width * height <= INT_MAX) { |
4193 | 0 | width *= height; |
4194 | 0 | height = 1; |
4195 | 0 | src_stride_ar30 = dst_stride_ab30 = 0; |
4196 | 0 | } |
4197 | 0 | for (y = 0; y < height; ++y) { |
4198 | 0 | AR30ToAB30Row_C(src_ar30, dst_ab30, width); |
4199 | 0 | src_ar30 += src_stride_ar30; |
4200 | 0 | dst_ab30 += dst_stride_ab30; |
4201 | 0 | } |
4202 | 0 | return 0; |
4203 | 0 | } |
4204 | | |
4205 | | // Convert AR64 to ARGB. |
4206 | | LIBYUV_API |
4207 | | int AR64ToARGB(const uint16_t* src_ar64, |
4208 | | int src_stride_ar64, |
4209 | | uint8_t* dst_argb, |
4210 | | int dst_stride_argb, |
4211 | | int width, |
4212 | 0 | int height) { |
4213 | 0 | int y; |
4214 | 0 | void (*AR64ToARGBRow)(const uint16_t* src_ar64, uint8_t* dst_argb, |
4215 | 0 | int width) = AR64ToARGBRow_C; |
4216 | 0 | if (!src_ar64 || !dst_argb || width <= 0 || height == 0 || |
4217 | 0 | height == INT_MIN) { |
4218 | 0 | return -1; |
4219 | 0 | } |
4220 | | // Negative height means invert the image. |
4221 | 0 | if (height < 0) { |
4222 | 0 | height = -height; |
4223 | 0 | src_ar64 = src_ar64 + (ptrdiff_t)(height - 1) * src_stride_ar64; |
4224 | 0 | src_stride_ar64 = -src_stride_ar64; |
4225 | 0 | } |
4226 | | // Coalesce rows. |
4227 | 0 | if (src_stride_ar64 == width * 4 && dst_stride_argb == width * 4 && |
4228 | 0 | (ptrdiff_t)width * height <= INT_MAX) { |
4229 | 0 | width *= height; |
4230 | 0 | height = 1; |
4231 | 0 | src_stride_ar64 = dst_stride_argb = 0; |
4232 | 0 | } |
4233 | 0 | #if defined(HAS_AR64TOARGBROW_SSSE3) |
4234 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
4235 | 0 | AR64ToARGBRow = AR64ToARGBRow_Any_SSSE3; |
4236 | 0 | if (IS_ALIGNED(width, 4)) { |
4237 | 0 | AR64ToARGBRow = AR64ToARGBRow_SSSE3; |
4238 | 0 | } |
4239 | 0 | } |
4240 | 0 | #endif |
4241 | 0 | #if defined(HAS_AR64TOARGBROW_AVX2) |
4242 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
4243 | 0 | AR64ToARGBRow = AR64ToARGBRow_Any_AVX2; |
4244 | 0 | if (IS_ALIGNED(width, 8)) { |
4245 | 0 | AR64ToARGBRow = AR64ToARGBRow_AVX2; |
4246 | 0 | } |
4247 | 0 | } |
4248 | 0 | #endif |
4249 | | #if defined(HAS_AR64TOARGBROW_NEON) |
4250 | | if (TestCpuFlag(kCpuHasNEON)) { |
4251 | | AR64ToARGBRow = AR64ToARGBRow_Any_NEON; |
4252 | | if (IS_ALIGNED(width, 8)) { |
4253 | | AR64ToARGBRow = AR64ToARGBRow_NEON; |
4254 | | } |
4255 | | } |
4256 | | #endif |
4257 | | #if defined(HAS_AR64TOARGBROW_RVV) |
4258 | | if (TestCpuFlag(kCpuHasRVV)) { |
4259 | | AR64ToARGBRow = AR64ToARGBRow_RVV; |
4260 | | } |
4261 | | #endif |
4262 | |
|
4263 | 0 | for (y = 0; y < height; ++y) { |
4264 | 0 | AR64ToARGBRow(src_ar64, dst_argb, width); |
4265 | 0 | src_ar64 += src_stride_ar64; |
4266 | 0 | dst_argb += dst_stride_argb; |
4267 | 0 | } |
4268 | 0 | return 0; |
4269 | 0 | } |
4270 | | |
4271 | | // Convert AB64 to ARGB. |
4272 | | LIBYUV_API |
4273 | | int AB64ToARGB(const uint16_t* src_ab64, |
4274 | | int src_stride_ab64, |
4275 | | uint8_t* dst_argb, |
4276 | | int dst_stride_argb, |
4277 | | int width, |
4278 | 0 | int height) { |
4279 | 0 | int y; |
4280 | 0 | void (*AB64ToARGBRow)(const uint16_t* src_ar64, uint8_t* dst_argb, |
4281 | 0 | int width) = AB64ToARGBRow_C; |
4282 | 0 | if (!src_ab64 || !dst_argb || width <= 0 || height == 0 || |
4283 | 0 | height == INT_MIN) { |
4284 | 0 | return -1; |
4285 | 0 | } |
4286 | | // Negative height means invert the image. |
4287 | 0 | if (height < 0) { |
4288 | 0 | height = -height; |
4289 | 0 | src_ab64 = src_ab64 + (ptrdiff_t)(height - 1) * src_stride_ab64; |
4290 | 0 | src_stride_ab64 = -src_stride_ab64; |
4291 | 0 | } |
4292 | | // Coalesce rows. |
4293 | 0 | if (src_stride_ab64 == width * 4 && dst_stride_argb == width * 4 && |
4294 | 0 | (ptrdiff_t)width * height <= INT_MAX) { |
4295 | 0 | width *= height; |
4296 | 0 | height = 1; |
4297 | 0 | src_stride_ab64 = dst_stride_argb = 0; |
4298 | 0 | } |
4299 | 0 | #if defined(HAS_AB64TOARGBROW_SSSE3) |
4300 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
4301 | 0 | AB64ToARGBRow = AB64ToARGBRow_Any_SSSE3; |
4302 | 0 | if (IS_ALIGNED(width, 4)) { |
4303 | 0 | AB64ToARGBRow = AB64ToARGBRow_SSSE3; |
4304 | 0 | } |
4305 | 0 | } |
4306 | 0 | #endif |
4307 | 0 | #if defined(HAS_AB64TOARGBROW_AVX2) |
4308 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
4309 | 0 | AB64ToARGBRow = AB64ToARGBRow_Any_AVX2; |
4310 | 0 | if (IS_ALIGNED(width, 8)) { |
4311 | 0 | AB64ToARGBRow = AB64ToARGBRow_AVX2; |
4312 | 0 | } |
4313 | 0 | } |
4314 | 0 | #endif |
4315 | | #if defined(HAS_AB64TOARGBROW_NEON) |
4316 | | if (TestCpuFlag(kCpuHasNEON)) { |
4317 | | AB64ToARGBRow = AB64ToARGBRow_Any_NEON; |
4318 | | if (IS_ALIGNED(width, 8)) { |
4319 | | AB64ToARGBRow = AB64ToARGBRow_NEON; |
4320 | | } |
4321 | | } |
4322 | | #endif |
4323 | | #if defined(HAS_AB64TOARGBROW_RVV) |
4324 | | if (TestCpuFlag(kCpuHasRVV)) { |
4325 | | AB64ToARGBRow = AB64ToARGBRow_RVV; |
4326 | | } |
4327 | | #endif |
4328 | |
|
4329 | 0 | for (y = 0; y < height; ++y) { |
4330 | 0 | AB64ToARGBRow(src_ab64, dst_argb, width); |
4331 | 0 | src_ab64 += src_stride_ab64; |
4332 | 0 | dst_argb += dst_stride_argb; |
4333 | 0 | } |
4334 | 0 | return 0; |
4335 | 0 | } |
4336 | | |
4337 | | // Convert NV12 to ARGB with matrix. |
4338 | | LIBYUV_API |
4339 | | int NV12ToARGBMatrix(const uint8_t* src_y, |
4340 | | int src_stride_y, |
4341 | | const uint8_t* src_uv, |
4342 | | int src_stride_uv, |
4343 | | uint8_t* dst_argb, |
4344 | | int dst_stride_argb, |
4345 | | const struct YuvConstants* yuvconstants, |
4346 | | int width, |
4347 | 0 | int height) { |
4348 | 0 | int y; |
4349 | 0 | void (*NV12ToARGBRow)( |
4350 | 0 | const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, |
4351 | 0 | const struct YuvConstants* yuvconstants, int width) = NV12ToARGBRow_C; |
4352 | 0 | assert(yuvconstants); |
4353 | 0 | if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || |
4354 | 0 | height == INT_MIN) { |
4355 | 0 | return -1; |
4356 | 0 | } |
4357 | | // Negative height means invert the image. |
4358 | 0 | if (height < 0) { |
4359 | 0 | height = -height; |
4360 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
4361 | 0 | dst_stride_argb = -dst_stride_argb; |
4362 | 0 | } |
4363 | 0 | #if defined(HAS_NV12TOARGBROW_SSSE3) |
4364 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
4365 | 0 | NV12ToARGBRow = NV12ToARGBRow_Any_SSSE3; |
4366 | 0 | if (IS_ALIGNED(width, 8)) { |
4367 | 0 | NV12ToARGBRow = NV12ToARGBRow_SSSE3; |
4368 | 0 | } |
4369 | 0 | } |
4370 | 0 | #endif |
4371 | 0 | #if defined(HAS_NV12TOARGBROW_AVX2) |
4372 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
4373 | 0 | NV12ToARGBRow = NV12ToARGBRow_Any_AVX2; |
4374 | 0 | if (IS_ALIGNED(width, 16)) { |
4375 | 0 | NV12ToARGBRow = NV12ToARGBRow_AVX2; |
4376 | 0 | } |
4377 | 0 | } |
4378 | 0 | #endif |
4379 | | #if defined(HAS_NV12TOARGBROW_NEON) |
4380 | | if (TestCpuFlag(kCpuHasNEON)) { |
4381 | | NV12ToARGBRow = NV12ToARGBRow_Any_NEON; |
4382 | | if (IS_ALIGNED(width, 8)) { |
4383 | | NV12ToARGBRow = NV12ToARGBRow_NEON; |
4384 | | } |
4385 | | } |
4386 | | #endif |
4387 | | #if defined(HAS_NV12TOARGBROW_SVE2) |
4388 | | if (TestCpuFlag(kCpuHasSVE2)) { |
4389 | | NV12ToARGBRow = NV12ToARGBRow_SVE2; |
4390 | | } |
4391 | | #endif |
4392 | | #if defined(HAS_NV12TOARGBROW_SME) |
4393 | | if (TestCpuFlag(kCpuHasSME)) { |
4394 | | NV12ToARGBRow = NV12ToARGBRow_SME; |
4395 | | } |
4396 | | #endif |
4397 | | #if defined(HAS_NV12TOARGBROW_LSX) |
4398 | | if (TestCpuFlag(kCpuHasLSX)) { |
4399 | | NV12ToARGBRow = NV12ToARGBRow_Any_LSX; |
4400 | | if (IS_ALIGNED(width, 8)) { |
4401 | | NV12ToARGBRow = NV12ToARGBRow_LSX; |
4402 | | } |
4403 | | } |
4404 | | #endif |
4405 | | #if defined(HAS_NV12TOARGBROW_LASX) |
4406 | | if (TestCpuFlag(kCpuHasLASX)) { |
4407 | | NV12ToARGBRow = NV12ToARGBRow_Any_LASX; |
4408 | | if (IS_ALIGNED(width, 16)) { |
4409 | | NV12ToARGBRow = NV12ToARGBRow_LASX; |
4410 | | } |
4411 | | } |
4412 | | #endif |
4413 | | #if defined(HAS_NV12TOARGBROW_RVV) |
4414 | | if (TestCpuFlag(kCpuHasRVV)) { |
4415 | | NV12ToARGBRow = NV12ToARGBRow_RVV; |
4416 | | } |
4417 | | #endif |
4418 | |
|
4419 | 0 | for (y = 0; y < height; ++y) { |
4420 | 0 | NV12ToARGBRow(src_y, src_uv, dst_argb, yuvconstants, width); |
4421 | 0 | dst_argb += dst_stride_argb; |
4422 | 0 | src_y += src_stride_y; |
4423 | 0 | if (y & 1) { |
4424 | 0 | src_uv += src_stride_uv; |
4425 | 0 | } |
4426 | 0 | } |
4427 | 0 | return 0; |
4428 | 0 | } |
4429 | | |
4430 | | // Convert NV21 to ARGB with matrix. |
4431 | | LIBYUV_API |
4432 | | int NV21ToARGBMatrix(const uint8_t* src_y, |
4433 | | int src_stride_y, |
4434 | | const uint8_t* src_vu, |
4435 | | int src_stride_vu, |
4436 | | uint8_t* dst_argb, |
4437 | | int dst_stride_argb, |
4438 | | const struct YuvConstants* yuvconstants, |
4439 | | int width, |
4440 | 0 | int height) { |
4441 | 0 | int y; |
4442 | 0 | void (*NV21ToARGBRow)( |
4443 | 0 | const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, |
4444 | 0 | const struct YuvConstants* yuvconstants, int width) = NV21ToARGBRow_C; |
4445 | 0 | assert(yuvconstants); |
4446 | 0 | if (!src_y || !src_vu || !dst_argb || width <= 0 || height == 0 || |
4447 | 0 | height == INT_MIN) { |
4448 | 0 | return -1; |
4449 | 0 | } |
4450 | | // Negative height means invert the image. |
4451 | 0 | if (height < 0) { |
4452 | 0 | height = -height; |
4453 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
4454 | 0 | dst_stride_argb = -dst_stride_argb; |
4455 | 0 | } |
4456 | 0 | #if defined(HAS_NV21TOARGBROW_SSSE3) |
4457 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
4458 | 0 | NV21ToARGBRow = NV21ToARGBRow_Any_SSSE3; |
4459 | 0 | if (IS_ALIGNED(width, 8)) { |
4460 | 0 | NV21ToARGBRow = NV21ToARGBRow_SSSE3; |
4461 | 0 | } |
4462 | 0 | } |
4463 | 0 | #endif |
4464 | 0 | #if defined(HAS_NV21TOARGBROW_AVX2) |
4465 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
4466 | 0 | NV21ToARGBRow = NV21ToARGBRow_Any_AVX2; |
4467 | 0 | if (IS_ALIGNED(width, 16)) { |
4468 | 0 | NV21ToARGBRow = NV21ToARGBRow_AVX2; |
4469 | 0 | } |
4470 | 0 | } |
4471 | 0 | #endif |
4472 | | #if defined(HAS_NV21TOARGBROW_NEON) |
4473 | | if (TestCpuFlag(kCpuHasNEON)) { |
4474 | | NV21ToARGBRow = NV21ToARGBRow_Any_NEON; |
4475 | | if (IS_ALIGNED(width, 8)) { |
4476 | | NV21ToARGBRow = NV21ToARGBRow_NEON; |
4477 | | } |
4478 | | } |
4479 | | #endif |
4480 | | #if defined(HAS_NV21TOARGBROW_SVE2) |
4481 | | if (TestCpuFlag(kCpuHasSVE2)) { |
4482 | | NV21ToARGBRow = NV21ToARGBRow_SVE2; |
4483 | | } |
4484 | | #endif |
4485 | | #if defined(HAS_NV21TOARGBROW_SME) |
4486 | | if (TestCpuFlag(kCpuHasSME)) { |
4487 | | NV21ToARGBRow = NV21ToARGBRow_SME; |
4488 | | } |
4489 | | #endif |
4490 | | #if defined(HAS_NV21TOARGBROW_LSX) |
4491 | | if (TestCpuFlag(kCpuHasLSX)) { |
4492 | | NV21ToARGBRow = NV21ToARGBRow_Any_LSX; |
4493 | | if (IS_ALIGNED(width, 8)) { |
4494 | | NV21ToARGBRow = NV21ToARGBRow_LSX; |
4495 | | } |
4496 | | } |
4497 | | #endif |
4498 | | #if defined(HAS_NV21TOARGBROW_LASX) |
4499 | | if (TestCpuFlag(kCpuHasLASX)) { |
4500 | | NV21ToARGBRow = NV21ToARGBRow_Any_LASX; |
4501 | | if (IS_ALIGNED(width, 16)) { |
4502 | | NV21ToARGBRow = NV21ToARGBRow_LASX; |
4503 | | } |
4504 | | } |
4505 | | #endif |
4506 | | #if defined(HAS_NV21TOARGBROW_RVV) |
4507 | | if (TestCpuFlag(kCpuHasRVV)) { |
4508 | | NV21ToARGBRow = NV21ToARGBRow_RVV; |
4509 | | } |
4510 | | #endif |
4511 | |
|
4512 | 0 | for (y = 0; y < height; ++y) { |
4513 | 0 | NV21ToARGBRow(src_y, src_vu, dst_argb, yuvconstants, width); |
4514 | 0 | dst_argb += dst_stride_argb; |
4515 | 0 | src_y += src_stride_y; |
4516 | 0 | if (y & 1) { |
4517 | 0 | src_vu += src_stride_vu; |
4518 | 0 | } |
4519 | 0 | } |
4520 | 0 | return 0; |
4521 | 0 | } |
4522 | | |
4523 | | // Convert NV12 to ARGB. |
4524 | | LIBYUV_API |
4525 | | int NV12ToARGB(const uint8_t* src_y, |
4526 | | int src_stride_y, |
4527 | | const uint8_t* src_uv, |
4528 | | int src_stride_uv, |
4529 | | uint8_t* dst_argb, |
4530 | | int dst_stride_argb, |
4531 | | int width, |
4532 | 0 | int height) { |
4533 | 0 | return NV12ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv, dst_argb, |
4534 | 0 | dst_stride_argb, &kYuvI601Constants, width, height); |
4535 | 0 | } |
4536 | | |
4537 | | // Convert NV21 to ARGB. |
4538 | | LIBYUV_API |
4539 | | int NV21ToARGB(const uint8_t* src_y, |
4540 | | int src_stride_y, |
4541 | | const uint8_t* src_vu, |
4542 | | int src_stride_vu, |
4543 | | uint8_t* dst_argb, |
4544 | | int dst_stride_argb, |
4545 | | int width, |
4546 | 0 | int height) { |
4547 | 0 | return NV21ToARGBMatrix(src_y, src_stride_y, src_vu, src_stride_vu, dst_argb, |
4548 | 0 | dst_stride_argb, &kYuvI601Constants, width, height); |
4549 | 0 | } |
4550 | | |
4551 | | // Convert NV12 to ABGR. |
4552 | | // To output ABGR instead of ARGB swap the UV and use a mirrored yuv matrix. |
4553 | | // To swap the UV use NV12 instead of NV21.LIBYUV_API |
4554 | | LIBYUV_API |
4555 | | int NV12ToABGR(const uint8_t* src_y, |
4556 | | int src_stride_y, |
4557 | | const uint8_t* src_uv, |
4558 | | int src_stride_uv, |
4559 | | uint8_t* dst_abgr, |
4560 | | int dst_stride_abgr, |
4561 | | int width, |
4562 | 0 | int height) { |
4563 | 0 | return NV21ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv, dst_abgr, |
4564 | 0 | dst_stride_abgr, &kYvuI601Constants, width, height); |
4565 | 0 | } |
4566 | | |
4567 | | // Convert NV21 to ABGR. |
4568 | | LIBYUV_API |
4569 | | int NV21ToABGR(const uint8_t* src_y, |
4570 | | int src_stride_y, |
4571 | | const uint8_t* src_vu, |
4572 | | int src_stride_vu, |
4573 | | uint8_t* dst_abgr, |
4574 | | int dst_stride_abgr, |
4575 | | int width, |
4576 | 0 | int height) { |
4577 | 0 | return NV12ToARGBMatrix(src_y, src_stride_y, src_vu, src_stride_vu, dst_abgr, |
4578 | 0 | dst_stride_abgr, &kYvuI601Constants, width, height); |
4579 | 0 | } |
4580 | | |
4581 | | // TODO(fbarchard): Consider SSSE3 2 step conversion. |
4582 | | // Convert NV12 to RGB24 with matrix. |
4583 | | LIBYUV_API |
4584 | | int NV12ToRGB24Matrix(const uint8_t* src_y, |
4585 | | int src_stride_y, |
4586 | | const uint8_t* src_uv, |
4587 | | int src_stride_uv, |
4588 | | uint8_t* dst_rgb24, |
4589 | | int dst_stride_rgb24, |
4590 | | const struct YuvConstants* yuvconstants, |
4591 | | int width, |
4592 | 0 | int height) { |
4593 | 0 | int y; |
4594 | 0 | void (*NV12ToRGB24Row)( |
4595 | 0 | const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, |
4596 | 0 | const struct YuvConstants* yuvconstants, int width) = NV12ToRGB24Row_C; |
4597 | 0 | assert(yuvconstants); |
4598 | 0 | if (!src_y || !src_uv || !dst_rgb24 || width <= 0 || height == 0 || |
4599 | 0 | height == INT_MIN) { |
4600 | 0 | return -1; |
4601 | 0 | } |
4602 | | // Negative height means invert the image. |
4603 | 0 | if (height < 0) { |
4604 | 0 | height = -height; |
4605 | 0 | dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; |
4606 | 0 | dst_stride_rgb24 = -dst_stride_rgb24; |
4607 | 0 | } |
4608 | | #if defined(HAS_NV12TORGB24ROW_NEON) |
4609 | | if (TestCpuFlag(kCpuHasNEON)) { |
4610 | | NV12ToRGB24Row = NV12ToRGB24Row_Any_NEON; |
4611 | | if (IS_ALIGNED(width, 8)) { |
4612 | | NV12ToRGB24Row = NV12ToRGB24Row_NEON; |
4613 | | } |
4614 | | } |
4615 | | #endif |
4616 | | #if defined(HAS_NV12TORGB24ROW_SVE2) |
4617 | | if (TestCpuFlag(kCpuHasSVE2)) { |
4618 | | NV12ToRGB24Row = NV12ToRGB24Row_SVE2; |
4619 | | } |
4620 | | #endif |
4621 | | #if defined(HAS_NV12TORGB24ROW_SME) |
4622 | | if (TestCpuFlag(kCpuHasSME)) { |
4623 | | NV12ToRGB24Row = NV12ToRGB24Row_SME; |
4624 | | } |
4625 | | #endif |
4626 | 0 | #if defined(HAS_NV12TORGB24ROW_SSSE3) |
4627 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
4628 | 0 | NV12ToRGB24Row = NV12ToRGB24Row_Any_SSSE3; |
4629 | 0 | if (IS_ALIGNED(width, 16)) { |
4630 | 0 | NV12ToRGB24Row = NV12ToRGB24Row_SSSE3; |
4631 | 0 | } |
4632 | 0 | } |
4633 | 0 | #endif |
4634 | 0 | #if defined(HAS_NV12TORGB24ROW_AVX2) |
4635 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
4636 | 0 | NV12ToRGB24Row = NV12ToRGB24Row_Any_AVX2; |
4637 | 0 | if (IS_ALIGNED(width, 32)) { |
4638 | 0 | NV12ToRGB24Row = NV12ToRGB24Row_AVX2; |
4639 | 0 | } |
4640 | 0 | } |
4641 | 0 | #endif |
4642 | | #if defined(HAS_NV12TORGB24ROW_RVV) |
4643 | | if (TestCpuFlag(kCpuHasRVV)) { |
4644 | | NV12ToRGB24Row = NV12ToRGB24Row_RVV; |
4645 | | } |
4646 | | #endif |
4647 | |
|
4648 | 0 | for (y = 0; y < height; ++y) { |
4649 | 0 | NV12ToRGB24Row(src_y, src_uv, dst_rgb24, yuvconstants, width); |
4650 | 0 | dst_rgb24 += dst_stride_rgb24; |
4651 | 0 | src_y += src_stride_y; |
4652 | 0 | if (y & 1) { |
4653 | 0 | src_uv += src_stride_uv; |
4654 | 0 | } |
4655 | 0 | } |
4656 | 0 | return 0; |
4657 | 0 | } |
4658 | | |
4659 | | // Convert NV21 to RGB24 with matrix. |
4660 | | LIBYUV_API |
4661 | | int NV21ToRGB24Matrix(const uint8_t* src_y, |
4662 | | int src_stride_y, |
4663 | | const uint8_t* src_vu, |
4664 | | int src_stride_vu, |
4665 | | uint8_t* dst_rgb24, |
4666 | | int dst_stride_rgb24, |
4667 | | const struct YuvConstants* yuvconstants, |
4668 | | int width, |
4669 | 0 | int height) { |
4670 | 0 | int y; |
4671 | 0 | void (*NV21ToRGB24Row)( |
4672 | 0 | const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, |
4673 | 0 | const struct YuvConstants* yuvconstants, int width) = NV21ToRGB24Row_C; |
4674 | 0 | assert(yuvconstants); |
4675 | 0 | if (!src_y || !src_vu || !dst_rgb24 || width <= 0 || height == 0 || |
4676 | 0 | height == INT_MIN) { |
4677 | 0 | return -1; |
4678 | 0 | } |
4679 | | // Negative height means invert the image. |
4680 | 0 | if (height < 0) { |
4681 | 0 | height = -height; |
4682 | 0 | dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; |
4683 | 0 | dst_stride_rgb24 = -dst_stride_rgb24; |
4684 | 0 | } |
4685 | | #if defined(HAS_NV21TORGB24ROW_NEON) |
4686 | | if (TestCpuFlag(kCpuHasNEON)) { |
4687 | | NV21ToRGB24Row = NV21ToRGB24Row_Any_NEON; |
4688 | | if (IS_ALIGNED(width, 8)) { |
4689 | | NV21ToRGB24Row = NV21ToRGB24Row_NEON; |
4690 | | } |
4691 | | } |
4692 | | #endif |
4693 | | #if defined(HAS_NV21TORGB24ROW_SVE2) |
4694 | | if (TestCpuFlag(kCpuHasSVE2)) { |
4695 | | NV21ToRGB24Row = NV21ToRGB24Row_SVE2; |
4696 | | } |
4697 | | #endif |
4698 | | #if defined(HAS_NV21TORGB24ROW_SME) |
4699 | | if (TestCpuFlag(kCpuHasSME)) { |
4700 | | NV21ToRGB24Row = NV21ToRGB24Row_SME; |
4701 | | } |
4702 | | #endif |
4703 | 0 | #if defined(HAS_NV21TORGB24ROW_SSSE3) |
4704 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
4705 | 0 | NV21ToRGB24Row = NV21ToRGB24Row_Any_SSSE3; |
4706 | 0 | if (IS_ALIGNED(width, 16)) { |
4707 | 0 | NV21ToRGB24Row = NV21ToRGB24Row_SSSE3; |
4708 | 0 | } |
4709 | 0 | } |
4710 | 0 | #endif |
4711 | 0 | #if defined(HAS_NV21TORGB24ROW_AVX2) |
4712 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
4713 | 0 | NV21ToRGB24Row = NV21ToRGB24Row_Any_AVX2; |
4714 | 0 | if (IS_ALIGNED(width, 32)) { |
4715 | 0 | NV21ToRGB24Row = NV21ToRGB24Row_AVX2; |
4716 | 0 | } |
4717 | 0 | } |
4718 | 0 | #endif |
4719 | | #if defined(HAS_NV21TORGB24ROW_RVV) |
4720 | | if (TestCpuFlag(kCpuHasRVV)) { |
4721 | | NV21ToRGB24Row = NV21ToRGB24Row_RVV; |
4722 | | } |
4723 | | #endif |
4724 | |
|
4725 | 0 | for (y = 0; y < height; ++y) { |
4726 | 0 | NV21ToRGB24Row(src_y, src_vu, dst_rgb24, yuvconstants, width); |
4727 | 0 | dst_rgb24 += dst_stride_rgb24; |
4728 | 0 | src_y += src_stride_y; |
4729 | 0 | if (y & 1) { |
4730 | 0 | src_vu += src_stride_vu; |
4731 | 0 | } |
4732 | 0 | } |
4733 | 0 | return 0; |
4734 | 0 | } |
4735 | | |
4736 | | // Convert NV12 to RGB24. |
4737 | | LIBYUV_API |
4738 | | int NV12ToRGB24(const uint8_t* src_y, |
4739 | | int src_stride_y, |
4740 | | const uint8_t* src_uv, |
4741 | | int src_stride_uv, |
4742 | | uint8_t* dst_rgb24, |
4743 | | int dst_stride_rgb24, |
4744 | | int width, |
4745 | 0 | int height) { |
4746 | 0 | return NV12ToRGB24Matrix(src_y, src_stride_y, src_uv, src_stride_uv, |
4747 | 0 | dst_rgb24, dst_stride_rgb24, &kYuvI601Constants, |
4748 | 0 | width, height); |
4749 | 0 | } |
4750 | | |
4751 | | // Convert NV21 to RGB24. |
4752 | | LIBYUV_API |
4753 | | int NV21ToRGB24(const uint8_t* src_y, |
4754 | | int src_stride_y, |
4755 | | const uint8_t* src_vu, |
4756 | | int src_stride_vu, |
4757 | | uint8_t* dst_rgb24, |
4758 | | int dst_stride_rgb24, |
4759 | | int width, |
4760 | 0 | int height) { |
4761 | 0 | return NV21ToRGB24Matrix(src_y, src_stride_y, src_vu, src_stride_vu, |
4762 | 0 | dst_rgb24, dst_stride_rgb24, &kYuvI601Constants, |
4763 | 0 | width, height); |
4764 | 0 | } |
4765 | | |
4766 | | // Convert NV12 to RAW. |
4767 | | LIBYUV_API |
4768 | | int NV12ToRAW(const uint8_t* src_y, |
4769 | | int src_stride_y, |
4770 | | const uint8_t* src_uv, |
4771 | | int src_stride_uv, |
4772 | | uint8_t* dst_raw, |
4773 | | int dst_stride_raw, |
4774 | | int width, |
4775 | 0 | int height) { |
4776 | 0 | return NV21ToRGB24Matrix(src_y, src_stride_y, src_uv, src_stride_uv, dst_raw, |
4777 | 0 | dst_stride_raw, &kYvuI601Constants, width, height); |
4778 | 0 | } |
4779 | | |
4780 | | // Convert NV21 to RAW. |
4781 | | LIBYUV_API |
4782 | | int NV21ToRAW(const uint8_t* src_y, |
4783 | | int src_stride_y, |
4784 | | const uint8_t* src_vu, |
4785 | | int src_stride_vu, |
4786 | | uint8_t* dst_raw, |
4787 | | int dst_stride_raw, |
4788 | | int width, |
4789 | 0 | int height) { |
4790 | 0 | return NV12ToRGB24Matrix(src_y, src_stride_y, src_vu, src_stride_vu, dst_raw, |
4791 | 0 | dst_stride_raw, &kYvuI601Constants, width, height); |
4792 | 0 | } |
4793 | | |
4794 | | // Convert NV21 to YUV24 |
4795 | | int NV21ToYUV24(const uint8_t* src_y, |
4796 | | int src_stride_y, |
4797 | | const uint8_t* src_vu, |
4798 | | int src_stride_vu, |
4799 | | uint8_t* dst_yuv24, |
4800 | | int dst_stride_yuv24, |
4801 | | int width, |
4802 | 0 | int height) { |
4803 | 0 | int y; |
4804 | 0 | void (*NV21ToYUV24Row)(const uint8_t* src_y, const uint8_t* src_vu, |
4805 | 0 | uint8_t* dst_yuv24, int width) = NV21ToYUV24Row_C; |
4806 | 0 | if (!src_y || !src_vu || !dst_yuv24 || width <= 0 || height == 0 || |
4807 | 0 | height == INT_MIN) { |
4808 | 0 | return -1; |
4809 | 0 | } |
4810 | | // Negative height means invert the image. |
4811 | 0 | if (height < 0) { |
4812 | 0 | height = -height; |
4813 | 0 | dst_yuv24 = dst_yuv24 + (ptrdiff_t)(height - 1) * dst_stride_yuv24; |
4814 | 0 | dst_stride_yuv24 = -dst_stride_yuv24; |
4815 | 0 | } |
4816 | | #if defined(HAS_NV21TOYUV24ROW_NEON) |
4817 | | if (TestCpuFlag(kCpuHasNEON)) { |
4818 | | NV21ToYUV24Row = NV21ToYUV24Row_Any_NEON; |
4819 | | if (IS_ALIGNED(width, 16)) { |
4820 | | NV21ToYUV24Row = NV21ToYUV24Row_NEON; |
4821 | | } |
4822 | | } |
4823 | | #endif |
4824 | 0 | #if defined(HAS_NV21TOYUV24ROW_SSSE3) |
4825 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
4826 | 0 | NV21ToYUV24Row = NV21ToYUV24Row_Any_SSSE3; |
4827 | 0 | if (IS_ALIGNED(width, 16)) { |
4828 | 0 | NV21ToYUV24Row = NV21ToYUV24Row_SSSE3; |
4829 | 0 | } |
4830 | 0 | } |
4831 | 0 | #endif |
4832 | 0 | #if defined(HAS_NV21TOYUV24ROW_AVX2) |
4833 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
4834 | 0 | NV21ToYUV24Row = NV21ToYUV24Row_Any_AVX2; |
4835 | 0 | if (IS_ALIGNED(width, 32)) { |
4836 | 0 | NV21ToYUV24Row = NV21ToYUV24Row_AVX2; |
4837 | 0 | } |
4838 | 0 | } |
4839 | 0 | #endif |
4840 | 0 | for (y = 0; y < height; ++y) { |
4841 | 0 | NV21ToYUV24Row(src_y, src_vu, dst_yuv24, width); |
4842 | 0 | dst_yuv24 += dst_stride_yuv24; |
4843 | 0 | src_y += src_stride_y; |
4844 | 0 | if (y & 1) { |
4845 | 0 | src_vu += src_stride_vu; |
4846 | 0 | } |
4847 | 0 | } |
4848 | 0 | return 0; |
4849 | 0 | } |
4850 | | |
4851 | | // Convert YUY2 to ARGB with matrix. |
4852 | | LIBYUV_API |
4853 | | int YUY2ToARGBMatrix(const uint8_t* src_yuy2, |
4854 | | int src_stride_yuy2, |
4855 | | uint8_t* dst_argb, |
4856 | | int dst_stride_argb, |
4857 | | const struct YuvConstants* yuvconstants, |
4858 | | int width, |
4859 | 0 | int height) { |
4860 | 0 | int y; |
4861 | 0 | void (*YUY2ToARGBRow)(const uint8_t* src_yuy2, uint8_t* dst_argb, |
4862 | 0 | const struct YuvConstants* yuvconstants, int width) = |
4863 | 0 | YUY2ToARGBRow_C; |
4864 | 0 | if (!src_yuy2 || !dst_argb || width <= 0 || height == 0 || |
4865 | 0 | height == INT_MIN) { |
4866 | 0 | return -1; |
4867 | 0 | } |
4868 | | // Negative height means invert the image. |
4869 | 0 | if (height < 0) { |
4870 | 0 | height = -height; |
4871 | 0 | src_yuy2 = src_yuy2 + (ptrdiff_t)(height - 1) * src_stride_yuy2; |
4872 | 0 | src_stride_yuy2 = -src_stride_yuy2; |
4873 | 0 | } |
4874 | | // Coalesce rows. |
4875 | 0 | if (src_stride_yuy2 == width * 2 && dst_stride_argb == width * 4 && |
4876 | 0 | (ptrdiff_t)width * height <= INT_MAX) { |
4877 | 0 | width *= height; |
4878 | 0 | height = 1; |
4879 | 0 | src_stride_yuy2 = dst_stride_argb = 0; |
4880 | 0 | } |
4881 | 0 | #if defined(HAS_YUY2TOARGBROW_SSSE3) |
4882 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
4883 | 0 | YUY2ToARGBRow = YUY2ToARGBRow_Any_SSSE3; |
4884 | 0 | if (IS_ALIGNED(width, 16)) { |
4885 | 0 | YUY2ToARGBRow = YUY2ToARGBRow_SSSE3; |
4886 | 0 | } |
4887 | 0 | } |
4888 | 0 | #endif |
4889 | 0 | #if defined(HAS_YUY2TOARGBROW_AVX2) |
4890 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
4891 | 0 | YUY2ToARGBRow = YUY2ToARGBRow_Any_AVX2; |
4892 | 0 | if (IS_ALIGNED(width, 32)) { |
4893 | 0 | YUY2ToARGBRow = YUY2ToARGBRow_AVX2; |
4894 | 0 | } |
4895 | 0 | } |
4896 | 0 | #endif |
4897 | | #if defined(HAS_YUY2TOARGBROW_NEON) |
4898 | | if (TestCpuFlag(kCpuHasNEON)) { |
4899 | | YUY2ToARGBRow = YUY2ToARGBRow_Any_NEON; |
4900 | | if (IS_ALIGNED(width, 8)) { |
4901 | | YUY2ToARGBRow = YUY2ToARGBRow_NEON; |
4902 | | } |
4903 | | } |
4904 | | #endif |
4905 | | #if defined(HAS_YUY2TOARGBROW_SVE2) |
4906 | | if (TestCpuFlag(kCpuHasSVE2)) { |
4907 | | YUY2ToARGBRow = YUY2ToARGBRow_SVE2; |
4908 | | } |
4909 | | #endif |
4910 | | #if defined(HAS_YUY2TOARGBROW_SME) |
4911 | | if (TestCpuFlag(kCpuHasSME)) { |
4912 | | YUY2ToARGBRow = YUY2ToARGBRow_SME; |
4913 | | } |
4914 | | #endif |
4915 | | #if defined(HAS_YUY2TOARGBROW_LSX) |
4916 | | if (TestCpuFlag(kCpuHasLSX)) { |
4917 | | YUY2ToARGBRow = YUY2ToARGBRow_Any_LSX; |
4918 | | if (IS_ALIGNED(width, 8)) { |
4919 | | YUY2ToARGBRow = YUY2ToARGBRow_LSX; |
4920 | | } |
4921 | | } |
4922 | | #endif |
4923 | 0 | for (y = 0; y < height; ++y) { |
4924 | 0 | YUY2ToARGBRow(src_yuy2, dst_argb, yuvconstants, width); |
4925 | 0 | src_yuy2 += src_stride_yuy2; |
4926 | 0 | dst_argb += dst_stride_argb; |
4927 | 0 | } |
4928 | 0 | return 0; |
4929 | 0 | } |
4930 | | |
4931 | | // Convert YUY2 to ARGB. |
4932 | | LIBYUV_API |
4933 | | int YUY2ToARGB(const uint8_t* src_yuy2, |
4934 | | int src_stride_yuy2, |
4935 | | uint8_t* dst_argb, |
4936 | | int dst_stride_argb, |
4937 | | int width, |
4938 | 0 | int height) { |
4939 | 0 | return YUY2ToARGBMatrix(src_yuy2, src_stride_yuy2, dst_argb, dst_stride_argb, |
4940 | 0 | &kYuvI601Constants, width, height); |
4941 | 0 | } |
4942 | | |
4943 | | // Convert UYVY to ARGB with matrix. |
4944 | | LIBYUV_API |
4945 | | int UYVYToARGBMatrix(const uint8_t* src_uyvy, |
4946 | | int src_stride_uyvy, |
4947 | | uint8_t* dst_argb, |
4948 | | int dst_stride_argb, |
4949 | | const struct YuvConstants* yuvconstants, |
4950 | | int width, |
4951 | 0 | int height) { |
4952 | 0 | int y; |
4953 | 0 | void (*UYVYToARGBRow)(const uint8_t* src_uyvy, uint8_t* dst_argb, |
4954 | 0 | const struct YuvConstants* yuvconstants, int width) = |
4955 | 0 | UYVYToARGBRow_C; |
4956 | 0 | if (!src_uyvy || !dst_argb || width <= 0 || height == 0 || |
4957 | 0 | height == INT_MIN) { |
4958 | 0 | return -1; |
4959 | 0 | } |
4960 | | // Negative height means invert the image. |
4961 | 0 | if (height < 0) { |
4962 | 0 | height = -height; |
4963 | 0 | src_uyvy = src_uyvy + (ptrdiff_t)(height - 1) * src_stride_uyvy; |
4964 | 0 | src_stride_uyvy = -src_stride_uyvy; |
4965 | 0 | } |
4966 | | // Coalesce rows. |
4967 | 0 | if (src_stride_uyvy == width * 2 && dst_stride_argb == width * 4 && |
4968 | 0 | (ptrdiff_t)width * height <= INT_MAX) { |
4969 | 0 | width *= height; |
4970 | 0 | height = 1; |
4971 | 0 | src_stride_uyvy = dst_stride_argb = 0; |
4972 | 0 | } |
4973 | 0 | #if defined(HAS_UYVYTOARGBROW_SSSE3) |
4974 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
4975 | 0 | UYVYToARGBRow = UYVYToARGBRow_Any_SSSE3; |
4976 | 0 | if (IS_ALIGNED(width, 16)) { |
4977 | 0 | UYVYToARGBRow = UYVYToARGBRow_SSSE3; |
4978 | 0 | } |
4979 | 0 | } |
4980 | 0 | #endif |
4981 | 0 | #if defined(HAS_UYVYTOARGBROW_AVX2) |
4982 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
4983 | 0 | UYVYToARGBRow = UYVYToARGBRow_Any_AVX2; |
4984 | 0 | if (IS_ALIGNED(width, 32)) { |
4985 | 0 | UYVYToARGBRow = UYVYToARGBRow_AVX2; |
4986 | 0 | } |
4987 | 0 | } |
4988 | 0 | #endif |
4989 | | #if defined(HAS_UYVYTOARGBROW_NEON) |
4990 | | if (TestCpuFlag(kCpuHasNEON)) { |
4991 | | UYVYToARGBRow = UYVYToARGBRow_Any_NEON; |
4992 | | if (IS_ALIGNED(width, 8)) { |
4993 | | UYVYToARGBRow = UYVYToARGBRow_NEON; |
4994 | | } |
4995 | | } |
4996 | | #endif |
4997 | | #if defined(HAS_UYVYTOARGBROW_SVE2) |
4998 | | if (TestCpuFlag(kCpuHasSVE2)) { |
4999 | | UYVYToARGBRow = UYVYToARGBRow_SVE2; |
5000 | | } |
5001 | | #endif |
5002 | | #if defined(HAS_UYVYTOARGBROW_SME) |
5003 | | if (TestCpuFlag(kCpuHasSME)) { |
5004 | | UYVYToARGBRow = UYVYToARGBRow_SME; |
5005 | | } |
5006 | | #endif |
5007 | | #if defined(HAS_UYVYTOARGBROW_LSX) |
5008 | | if (TestCpuFlag(kCpuHasLSX)) { |
5009 | | UYVYToARGBRow = UYVYToARGBRow_Any_LSX; |
5010 | | if (IS_ALIGNED(width, 8)) { |
5011 | | UYVYToARGBRow = UYVYToARGBRow_LSX; |
5012 | | } |
5013 | | } |
5014 | | #endif |
5015 | 0 | for (y = 0; y < height; ++y) { |
5016 | 0 | UYVYToARGBRow(src_uyvy, dst_argb, yuvconstants, width); |
5017 | 0 | src_uyvy += src_stride_uyvy; |
5018 | 0 | dst_argb += dst_stride_argb; |
5019 | 0 | } |
5020 | 0 | return 0; |
5021 | 0 | } |
5022 | | |
5023 | | // Convert UYVY to ARGB. |
5024 | | LIBYUV_API |
5025 | | int UYVYToARGB(const uint8_t* src_uyvy, |
5026 | | int src_stride_uyvy, |
5027 | | uint8_t* dst_argb, |
5028 | | int dst_stride_argb, |
5029 | | int width, |
5030 | 0 | int height) { |
5031 | 0 | return UYVYToARGBMatrix(src_uyvy, src_stride_uyvy, dst_argb, dst_stride_argb, |
5032 | 0 | &kYuvI601Constants, width, height); |
5033 | 0 | } |
5034 | | |
5035 | | static void WeavePixels(const uint8_t* src_u, |
5036 | | const uint8_t* src_v, |
5037 | | int src_pixel_stride_uv, |
5038 | | uint8_t* dst_uv, |
5039 | 0 | int width) { |
5040 | 0 | int i; |
5041 | 0 | for (i = 0; i < width; ++i) { |
5042 | 0 | dst_uv[0] = *src_u; |
5043 | 0 | dst_uv[1] = *src_v; |
5044 | 0 | dst_uv += 2; |
5045 | 0 | src_u += src_pixel_stride_uv; |
5046 | 0 | src_v += src_pixel_stride_uv; |
5047 | 0 | } |
5048 | 0 | } |
5049 | | |
5050 | | // Convert Android420 to ARGB with matrix. |
5051 | | LIBYUV_API |
5052 | | int Android420ToARGBMatrix(const uint8_t* src_y, |
5053 | | int src_stride_y, |
5054 | | const uint8_t* src_u, |
5055 | | int src_stride_u, |
5056 | | const uint8_t* src_v, |
5057 | | int src_stride_v, |
5058 | | int src_pixel_stride_uv, |
5059 | | uint8_t* dst_argb, |
5060 | | int dst_stride_argb, |
5061 | | const struct YuvConstants* yuvconstants, |
5062 | | int width, |
5063 | 0 | int height) { |
5064 | 0 | int y; |
5065 | 0 | uint8_t* dst_uv; |
5066 | 0 | const ptrdiff_t vu_off = src_v - src_u; |
5067 | 0 | int halfwidth = (width + 1) >> 1; |
5068 | 0 | int halfheight = (height + 1) >> 1; |
5069 | 0 | assert(yuvconstants); |
5070 | 0 | if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || |
5071 | 0 | height == INT_MIN) { |
5072 | 0 | return -1; |
5073 | 0 | } |
5074 | | // Negative height means invert the image. |
5075 | 0 | if (height < 0) { |
5076 | 0 | height = -height; |
5077 | 0 | halfheight = (height + 1) >> 1; |
5078 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
5079 | 0 | dst_stride_argb = -dst_stride_argb; |
5080 | 0 | } |
5081 | | |
5082 | | // I420 |
5083 | 0 | if (src_pixel_stride_uv == 1) { |
5084 | 0 | return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
5085 | 0 | src_stride_v, dst_argb, dst_stride_argb, |
5086 | 0 | yuvconstants, width, height); |
5087 | | // NV21 |
5088 | 0 | } |
5089 | 0 | if (src_pixel_stride_uv == 2 && vu_off == -1 && |
5090 | 0 | src_stride_u == src_stride_v) { |
5091 | 0 | return NV21ToARGBMatrix(src_y, src_stride_y, src_v, src_stride_v, dst_argb, |
5092 | 0 | dst_stride_argb, yuvconstants, width, height); |
5093 | | // NV12 |
5094 | 0 | } |
5095 | 0 | if (src_pixel_stride_uv == 2 && vu_off == 1 && src_stride_u == src_stride_v) { |
5096 | 0 | return NV12ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, dst_argb, |
5097 | 0 | dst_stride_argb, yuvconstants, width, height); |
5098 | 0 | } |
5099 | | |
5100 | | // General case fallback creates NV12 |
5101 | 0 | const uint64_t uv_size = (uint64_t)halfwidth * 2 * halfheight; |
5102 | 0 | if (uv_size > SIZE_MAX) |
5103 | 0 | return 1; |
5104 | 0 | align_buffer_64(plane_uv, (size_t)uv_size); |
5105 | 0 | if (!plane_uv) |
5106 | 0 | return 1; |
5107 | 0 | dst_uv = plane_uv; |
5108 | 0 | for (y = 0; y < halfheight; ++y) { |
5109 | 0 | WeavePixels(src_u, src_v, src_pixel_stride_uv, dst_uv, halfwidth); |
5110 | 0 | src_u += src_stride_u; |
5111 | 0 | src_v += src_stride_v; |
5112 | 0 | dst_uv += halfwidth * 2; |
5113 | 0 | } |
5114 | 0 | NV12ToARGBMatrix(src_y, src_stride_y, plane_uv, halfwidth * 2, dst_argb, |
5115 | 0 | dst_stride_argb, yuvconstants, width, height); |
5116 | 0 | free_aligned_buffer_64(plane_uv); |
5117 | 0 | return 0; |
5118 | 0 | } |
5119 | | |
5120 | | // Convert Android420 to ARGB. |
5121 | | LIBYUV_API |
5122 | | int Android420ToARGB(const uint8_t* src_y, |
5123 | | int src_stride_y, |
5124 | | const uint8_t* src_u, |
5125 | | int src_stride_u, |
5126 | | const uint8_t* src_v, |
5127 | | int src_stride_v, |
5128 | | int src_pixel_stride_uv, |
5129 | | uint8_t* dst_argb, |
5130 | | int dst_stride_argb, |
5131 | | int width, |
5132 | 0 | int height) { |
5133 | 0 | return Android420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
5134 | 0 | src_stride_v, src_pixel_stride_uv, dst_argb, |
5135 | 0 | dst_stride_argb, &kYuvI601Constants, width, |
5136 | 0 | height); |
5137 | 0 | } |
5138 | | |
5139 | | // Convert Android420 to ABGR. |
5140 | | LIBYUV_API |
5141 | | int Android420ToABGR(const uint8_t* src_y, |
5142 | | int src_stride_y, |
5143 | | const uint8_t* src_u, |
5144 | | int src_stride_u, |
5145 | | const uint8_t* src_v, |
5146 | | int src_stride_v, |
5147 | | int src_pixel_stride_uv, |
5148 | | uint8_t* dst_abgr, |
5149 | | int dst_stride_abgr, |
5150 | | int width, |
5151 | 0 | int height) { |
5152 | 0 | return Android420ToARGBMatrix(src_y, src_stride_y, src_v, src_stride_v, src_u, |
5153 | 0 | src_stride_u, src_pixel_stride_uv, dst_abgr, |
5154 | 0 | dst_stride_abgr, &kYvuI601Constants, width, |
5155 | 0 | height); |
5156 | 0 | } |
5157 | | |
5158 | | // Convert I422 to RGBA with matrix. |
5159 | | LIBYUV_API |
5160 | | int I422ToRGBAMatrix(const uint8_t* src_y, |
5161 | | int src_stride_y, |
5162 | | const uint8_t* src_u, |
5163 | | int src_stride_u, |
5164 | | const uint8_t* src_v, |
5165 | | int src_stride_v, |
5166 | | uint8_t* dst_rgba, |
5167 | | int dst_stride_rgba, |
5168 | | const struct YuvConstants* yuvconstants, |
5169 | | int width, |
5170 | 58 | int height) { |
5171 | 58 | int y; |
5172 | 58 | void (*I422ToRGBARow)(const uint8_t* y_buf, const uint8_t* u_buf, |
5173 | 58 | const uint8_t* v_buf, uint8_t* rgb_buf, |
5174 | 58 | const struct YuvConstants* yuvconstants, int width) = |
5175 | 58 | I422ToRGBARow_C; |
5176 | 58 | assert(yuvconstants); |
5177 | 58 | if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0 || |
5178 | 58 | height == INT_MIN) { |
5179 | 0 | return -1; |
5180 | 0 | } |
5181 | | // Negative height means invert the image. |
5182 | 58 | if (height < 0) { |
5183 | 0 | height = -height; |
5184 | 0 | dst_rgba = dst_rgba + (ptrdiff_t)(height - 1) * dst_stride_rgba; |
5185 | 0 | dst_stride_rgba = -dst_stride_rgba; |
5186 | 0 | } |
5187 | | #if defined(HAS_I422TORGBAROW_SSSE3) |
5188 | | if (TestCpuFlag(kCpuHasSSSE3)) { |
5189 | | I422ToRGBARow = I422ToRGBARow_Any_SSSE3; |
5190 | | if (IS_ALIGNED(width, 8)) { |
5191 | | I422ToRGBARow = I422ToRGBARow_SSSE3; |
5192 | | } |
5193 | | } |
5194 | | #endif |
5195 | 58 | #if defined(HAS_I422TORGBAROW_AVX2) |
5196 | 58 | if (TestCpuFlag(kCpuHasAVX2)) { |
5197 | 58 | I422ToRGBARow = I422ToRGBARow_Any_AVX2; |
5198 | 58 | if (IS_ALIGNED(width, 16)) { |
5199 | 17 | I422ToRGBARow = I422ToRGBARow_AVX2; |
5200 | 17 | } |
5201 | 58 | } |
5202 | 58 | #endif |
5203 | | #if defined(HAS_I422TORGBAROW_NEON) |
5204 | | if (TestCpuFlag(kCpuHasNEON)) { |
5205 | | I422ToRGBARow = I422ToRGBARow_Any_NEON; |
5206 | | if (IS_ALIGNED(width, 8)) { |
5207 | | I422ToRGBARow = I422ToRGBARow_NEON; |
5208 | | } |
5209 | | } |
5210 | | #endif |
5211 | | #if defined(HAS_I422TORGBAROW_SVE2) |
5212 | | if (TestCpuFlag(kCpuHasSVE2)) { |
5213 | | I422ToRGBARow = I422ToRGBARow_SVE2; |
5214 | | } |
5215 | | #endif |
5216 | | #if defined(HAS_I422TORGBAROW_SME) |
5217 | | if (TestCpuFlag(kCpuHasSME)) { |
5218 | | I422ToRGBARow = I422ToRGBARow_SME; |
5219 | | } |
5220 | | #endif |
5221 | | #if defined(HAS_I422TORGBAROW_LSX) |
5222 | | if (TestCpuFlag(kCpuHasLSX)) { |
5223 | | I422ToRGBARow = I422ToRGBARow_Any_LSX; |
5224 | | if (IS_ALIGNED(width, 16)) { |
5225 | | I422ToRGBARow = I422ToRGBARow_LSX; |
5226 | | } |
5227 | | } |
5228 | | #endif |
5229 | | #if defined(HAS_I422TORGBAROW_LASX) |
5230 | | if (TestCpuFlag(kCpuHasLASX)) { |
5231 | | I422ToRGBARow = I422ToRGBARow_Any_LASX; |
5232 | | if (IS_ALIGNED(width, 32)) { |
5233 | | I422ToRGBARow = I422ToRGBARow_LASX; |
5234 | | } |
5235 | | } |
5236 | | #endif |
5237 | | #if defined(HAS_I422TORGBAROW_RVV) |
5238 | | if (TestCpuFlag(kCpuHasRVV)) { |
5239 | | I422ToRGBARow = I422ToRGBARow_RVV; |
5240 | | } |
5241 | | #endif |
5242 | | |
5243 | 1.53k | for (y = 0; y < height; ++y) { |
5244 | 1.47k | I422ToRGBARow(src_y, src_u, src_v, dst_rgba, yuvconstants, width); |
5245 | 1.47k | dst_rgba += dst_stride_rgba; |
5246 | 1.47k | src_y += src_stride_y; |
5247 | 1.47k | src_u += src_stride_u; |
5248 | 1.47k | src_v += src_stride_v; |
5249 | 1.47k | } |
5250 | 58 | return 0; |
5251 | 58 | } |
5252 | | |
5253 | | // Convert I422 to RGBA. |
5254 | | LIBYUV_API |
5255 | | int I422ToRGBA(const uint8_t* src_y, |
5256 | | int src_stride_y, |
5257 | | const uint8_t* src_u, |
5258 | | int src_stride_u, |
5259 | | const uint8_t* src_v, |
5260 | | int src_stride_v, |
5261 | | uint8_t* dst_rgba, |
5262 | | int dst_stride_rgba, |
5263 | | int width, |
5264 | 0 | int height) { |
5265 | 0 | return I422ToRGBAMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
5266 | 0 | src_stride_v, dst_rgba, dst_stride_rgba, |
5267 | 0 | &kYuvI601Constants, width, height); |
5268 | 0 | } |
5269 | | |
5270 | | // Convert I422 to BGRA. |
5271 | | LIBYUV_API |
5272 | | int I422ToBGRA(const uint8_t* src_y, |
5273 | | int src_stride_y, |
5274 | | const uint8_t* src_u, |
5275 | | int src_stride_u, |
5276 | | const uint8_t* src_v, |
5277 | | int src_stride_v, |
5278 | | uint8_t* dst_bgra, |
5279 | | int dst_stride_bgra, |
5280 | | int width, |
5281 | 0 | int height) { |
5282 | 0 | return I422ToRGBAMatrix(src_y, src_stride_y, src_v, |
5283 | 0 | src_stride_v, // Swap U and V |
5284 | 0 | src_u, src_stride_u, dst_bgra, dst_stride_bgra, |
5285 | 0 | &kYvuI601Constants, // Use Yvu matrix |
5286 | 0 | width, height); |
5287 | 0 | } |
5288 | | |
5289 | | // Convert NV12 to RGB565 with matrix. |
5290 | | LIBYUV_API |
5291 | | int NV12ToRGB565Matrix(const uint8_t* src_y, |
5292 | | int src_stride_y, |
5293 | | const uint8_t* src_uv, |
5294 | | int src_stride_uv, |
5295 | | uint8_t* dst_rgb565, |
5296 | | int dst_stride_rgb565, |
5297 | | const struct YuvConstants* yuvconstants, |
5298 | | int width, |
5299 | 0 | int height) { |
5300 | 0 | int y; |
5301 | 0 | void (*NV12ToRGB565Row)( |
5302 | 0 | const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, |
5303 | 0 | const struct YuvConstants* yuvconstants, int width) = NV12ToRGB565Row_C; |
5304 | 0 | assert(yuvconstants); |
5305 | 0 | if (!src_y || !src_uv || !dst_rgb565 || width <= 0 || height == 0 || |
5306 | 0 | height == INT_MIN) { |
5307 | 0 | return -1; |
5308 | 0 | } |
5309 | | // Negative height means invert the image. |
5310 | 0 | if (height < 0) { |
5311 | 0 | height = -height; |
5312 | 0 | dst_rgb565 = dst_rgb565 + (ptrdiff_t)(height - 1) * dst_stride_rgb565; |
5313 | 0 | dst_stride_rgb565 = -dst_stride_rgb565; |
5314 | 0 | } |
5315 | | #if defined(HAS_NV12TORGB565ROW_SSSE3) |
5316 | | if (TestCpuFlag(kCpuHasSSSE3)) { |
5317 | | NV12ToRGB565Row = NV12ToRGB565Row_Any_SSSE3; |
5318 | | if (IS_ALIGNED(width, 8)) { |
5319 | | NV12ToRGB565Row = NV12ToRGB565Row_SSSE3; |
5320 | | } |
5321 | | } |
5322 | | #endif |
5323 | | #if defined(HAS_NV12TORGB565ROW_AVX2) |
5324 | | if (TestCpuFlag(kCpuHasAVX2)) { |
5325 | | NV12ToRGB565Row = NV12ToRGB565Row_Any_AVX2; |
5326 | | if (IS_ALIGNED(width, 16)) { |
5327 | | NV12ToRGB565Row = NV12ToRGB565Row_AVX2; |
5328 | | } |
5329 | | } |
5330 | | #endif |
5331 | | #if defined(HAS_NV12TORGB565ROW_NEON) |
5332 | | if (TestCpuFlag(kCpuHasNEON)) { |
5333 | | NV12ToRGB565Row = NV12ToRGB565Row_Any_NEON; |
5334 | | if (IS_ALIGNED(width, 8)) { |
5335 | | NV12ToRGB565Row = NV12ToRGB565Row_NEON; |
5336 | | } |
5337 | | } |
5338 | | #endif |
5339 | | #if defined(HAS_NV12TORGB565ROW_LSX) |
5340 | | if (TestCpuFlag(kCpuHasLSX)) { |
5341 | | NV12ToRGB565Row = NV12ToRGB565Row_Any_LSX; |
5342 | | if (IS_ALIGNED(width, 8)) { |
5343 | | NV12ToRGB565Row = NV12ToRGB565Row_LSX; |
5344 | | } |
5345 | | } |
5346 | | #endif |
5347 | | #if defined(HAS_NV12TORGB565ROW_LASX) |
5348 | | if (TestCpuFlag(kCpuHasLASX)) { |
5349 | | NV12ToRGB565Row = NV12ToRGB565Row_Any_LASX; |
5350 | | if (IS_ALIGNED(width, 16)) { |
5351 | | NV12ToRGB565Row = NV12ToRGB565Row_LASX; |
5352 | | } |
5353 | | } |
5354 | | #endif |
5355 | |
|
5356 | 0 | for (y = 0; y < height; ++y) { |
5357 | 0 | NV12ToRGB565Row(src_y, src_uv, dst_rgb565, yuvconstants, width); |
5358 | 0 | dst_rgb565 += dst_stride_rgb565; |
5359 | 0 | src_y += src_stride_y; |
5360 | 0 | if (y & 1) { |
5361 | 0 | src_uv += src_stride_uv; |
5362 | 0 | } |
5363 | 0 | } |
5364 | 0 | return 0; |
5365 | 0 | } |
5366 | | |
5367 | | // Convert NV12 to RGB565. |
5368 | | LIBYUV_API |
5369 | | int NV12ToRGB565(const uint8_t* src_y, |
5370 | | int src_stride_y, |
5371 | | const uint8_t* src_uv, |
5372 | | int src_stride_uv, |
5373 | | uint8_t* dst_rgb565, |
5374 | | int dst_stride_rgb565, |
5375 | | int width, |
5376 | 0 | int height) { |
5377 | 0 | return NV12ToRGB565Matrix(src_y, src_stride_y, src_uv, src_stride_uv, |
5378 | 0 | dst_rgb565, dst_stride_rgb565, &kYuvI601Constants, |
5379 | 0 | width, height); |
5380 | 0 | } |
5381 | | |
5382 | | // Convert I422 to RGBA with matrix. |
5383 | | LIBYUV_API |
5384 | | int I420ToRGBAMatrix(const uint8_t* src_y, |
5385 | | int src_stride_y, |
5386 | | const uint8_t* src_u, |
5387 | | int src_stride_u, |
5388 | | const uint8_t* src_v, |
5389 | | int src_stride_v, |
5390 | | uint8_t* dst_rgba, |
5391 | | int dst_stride_rgba, |
5392 | | const struct YuvConstants* yuvconstants, |
5393 | | int width, |
5394 | 133 | int height) { |
5395 | 133 | int y; |
5396 | 133 | void (*I422ToRGBARow)(const uint8_t* y_buf, const uint8_t* u_buf, |
5397 | 133 | const uint8_t* v_buf, uint8_t* rgb_buf, |
5398 | 133 | const struct YuvConstants* yuvconstants, int width) = |
5399 | 133 | I422ToRGBARow_C; |
5400 | 133 | assert(yuvconstants); |
5401 | 133 | if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0 || |
5402 | 133 | height == INT_MIN) { |
5403 | 0 | return -1; |
5404 | 0 | } |
5405 | | // Negative height means invert the image. |
5406 | 133 | if (height < 0) { |
5407 | 0 | height = -height; |
5408 | 0 | dst_rgba = dst_rgba + (ptrdiff_t)(height - 1) * dst_stride_rgba; |
5409 | 0 | dst_stride_rgba = -dst_stride_rgba; |
5410 | 0 | } |
5411 | | #if defined(HAS_I422TORGBAROW_SSSE3) |
5412 | | if (TestCpuFlag(kCpuHasSSSE3)) { |
5413 | | I422ToRGBARow = I422ToRGBARow_Any_SSSE3; |
5414 | | if (IS_ALIGNED(width, 8)) { |
5415 | | I422ToRGBARow = I422ToRGBARow_SSSE3; |
5416 | | } |
5417 | | } |
5418 | | #endif |
5419 | 133 | #if defined(HAS_I422TORGBAROW_AVX2) |
5420 | 133 | if (TestCpuFlag(kCpuHasAVX2)) { |
5421 | 133 | I422ToRGBARow = I422ToRGBARow_Any_AVX2; |
5422 | 133 | if (IS_ALIGNED(width, 16)) { |
5423 | 19 | I422ToRGBARow = I422ToRGBARow_AVX2; |
5424 | 19 | } |
5425 | 133 | } |
5426 | 133 | #endif |
5427 | | #if defined(HAS_I422TORGBAROW_NEON) |
5428 | | if (TestCpuFlag(kCpuHasNEON)) { |
5429 | | I422ToRGBARow = I422ToRGBARow_Any_NEON; |
5430 | | if (IS_ALIGNED(width, 8)) { |
5431 | | I422ToRGBARow = I422ToRGBARow_NEON; |
5432 | | } |
5433 | | } |
5434 | | #endif |
5435 | | #if defined(HAS_I422TORGBAROW_SVE2) |
5436 | | if (TestCpuFlag(kCpuHasSVE2)) { |
5437 | | I422ToRGBARow = I422ToRGBARow_SVE2; |
5438 | | } |
5439 | | #endif |
5440 | | #if defined(HAS_I422TORGBAROW_SME) |
5441 | | if (TestCpuFlag(kCpuHasSME)) { |
5442 | | I422ToRGBARow = I422ToRGBARow_SME; |
5443 | | } |
5444 | | #endif |
5445 | | #if defined(HAS_I422TORGBAROW_LSX) |
5446 | | if (TestCpuFlag(kCpuHasLSX)) { |
5447 | | I422ToRGBARow = I422ToRGBARow_Any_LSX; |
5448 | | if (IS_ALIGNED(width, 16)) { |
5449 | | I422ToRGBARow = I422ToRGBARow_LSX; |
5450 | | } |
5451 | | } |
5452 | | #endif |
5453 | | #if defined(HAS_I422TORGBAROW_LASX) |
5454 | | if (TestCpuFlag(kCpuHasLASX)) { |
5455 | | I422ToRGBARow = I422ToRGBARow_Any_LASX; |
5456 | | if (IS_ALIGNED(width, 32)) { |
5457 | | I422ToRGBARow = I422ToRGBARow_LASX; |
5458 | | } |
5459 | | } |
5460 | | #endif |
5461 | | #if defined(HAS_I422TORGBAROW_RVV) |
5462 | | if (TestCpuFlag(kCpuHasRVV)) { |
5463 | | I422ToRGBARow = I422ToRGBARow_RVV; |
5464 | | } |
5465 | | #endif |
5466 | | |
5467 | 3.00k | for (y = 0; y < height; ++y) { |
5468 | 2.86k | I422ToRGBARow(src_y, src_u, src_v, dst_rgba, yuvconstants, width); |
5469 | 2.86k | dst_rgba += dst_stride_rgba; |
5470 | 2.86k | src_y += src_stride_y; |
5471 | 2.86k | if (y & 1) { |
5472 | 1.41k | src_u += src_stride_u; |
5473 | 1.41k | src_v += src_stride_v; |
5474 | 1.41k | } |
5475 | 2.86k | } |
5476 | 133 | return 0; |
5477 | 133 | } |
5478 | | |
5479 | | // Convert I420 to RGBA. |
5480 | | LIBYUV_API |
5481 | | int I420ToRGBA(const uint8_t* src_y, |
5482 | | int src_stride_y, |
5483 | | const uint8_t* src_u, |
5484 | | int src_stride_u, |
5485 | | const uint8_t* src_v, |
5486 | | int src_stride_v, |
5487 | | uint8_t* dst_rgba, |
5488 | | int dst_stride_rgba, |
5489 | | int width, |
5490 | 0 | int height) { |
5491 | 0 | return I420ToRGBAMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
5492 | 0 | src_stride_v, dst_rgba, dst_stride_rgba, |
5493 | 0 | &kYuvI601Constants, width, height); |
5494 | 0 | } |
5495 | | |
5496 | | // Convert I420 to BGRA. |
5497 | | LIBYUV_API |
5498 | | int I420ToBGRA(const uint8_t* src_y, |
5499 | | int src_stride_y, |
5500 | | const uint8_t* src_u, |
5501 | | int src_stride_u, |
5502 | | const uint8_t* src_v, |
5503 | | int src_stride_v, |
5504 | | uint8_t* dst_bgra, |
5505 | | int dst_stride_bgra, |
5506 | | int width, |
5507 | 0 | int height) { |
5508 | 0 | return I420ToRGBAMatrix(src_y, src_stride_y, src_v, |
5509 | 0 | src_stride_v, // Swap U and V |
5510 | 0 | src_u, src_stride_u, dst_bgra, dst_stride_bgra, |
5511 | 0 | &kYvuI601Constants, // Use Yvu matrix |
5512 | 0 | width, height); |
5513 | 0 | } |
5514 | | |
5515 | | // Convert I420 to RGB24 with matrix. |
5516 | | LIBYUV_API |
5517 | | int I420ToRGB24Matrix(const uint8_t* src_y, |
5518 | | int src_stride_y, |
5519 | | const uint8_t* src_u, |
5520 | | int src_stride_u, |
5521 | | const uint8_t* src_v, |
5522 | | int src_stride_v, |
5523 | | uint8_t* dst_rgb24, |
5524 | | int dst_stride_rgb24, |
5525 | | const struct YuvConstants* yuvconstants, |
5526 | | int width, |
5527 | 144 | int height) { |
5528 | 144 | int y; |
5529 | 144 | void (*I422ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf, |
5530 | 144 | const uint8_t* v_buf, uint8_t* rgb_buf, |
5531 | 144 | const struct YuvConstants* yuvconstants, int width) = |
5532 | 144 | I422ToRGB24Row_C; |
5533 | 144 | assert(yuvconstants); |
5534 | 144 | if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || |
5535 | 144 | height == INT_MIN) { |
5536 | 0 | return -1; |
5537 | 0 | } |
5538 | | // Negative height means invert the image. |
5539 | 144 | if (height < 0) { |
5540 | 0 | height = -height; |
5541 | 0 | dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; |
5542 | 0 | dst_stride_rgb24 = -dst_stride_rgb24; |
5543 | 0 | } |
5544 | 144 | #if defined(HAS_I422TORGB24ROW_SSSE3) |
5545 | 144 | if (TestCpuFlag(kCpuHasSSSE3)) { |
5546 | 144 | I422ToRGB24Row = I422ToRGB24Row_Any_SSSE3; |
5547 | 144 | if (IS_ALIGNED(width, 16)) { |
5548 | 17 | I422ToRGB24Row = I422ToRGB24Row_SSSE3; |
5549 | 17 | } |
5550 | 144 | } |
5551 | 144 | #endif |
5552 | 144 | #if defined(HAS_I422TORGB24ROW_AVX2) |
5553 | 144 | if (TestCpuFlag(kCpuHasAVX2)) { |
5554 | 144 | I422ToRGB24Row = I422ToRGB24Row_Any_AVX2; |
5555 | 144 | if (IS_ALIGNED(width, 16)) { |
5556 | 17 | I422ToRGB24Row = I422ToRGB24Row_AVX2; |
5557 | 17 | } |
5558 | 144 | } |
5559 | 144 | #endif |
5560 | 144 | #if defined(HAS_I422TORGB24ROW_AVX512VBMI) |
5561 | 144 | if (TestCpuFlag(kCpuHasAVX512VBMI)) { |
5562 | 0 | I422ToRGB24Row = I422ToRGB24Row_Any_AVX512VBMI; |
5563 | 0 | if (IS_ALIGNED(width, 32)) { |
5564 | 0 | I422ToRGB24Row = I422ToRGB24Row_AVX512VBMI; |
5565 | 0 | } |
5566 | 0 | } |
5567 | 144 | #endif |
5568 | | #if defined(HAS_I422TORGB24ROW_NEON) |
5569 | | if (TestCpuFlag(kCpuHasNEON)) { |
5570 | | I422ToRGB24Row = I422ToRGB24Row_Any_NEON; |
5571 | | if (IS_ALIGNED(width, 8)) { |
5572 | | I422ToRGB24Row = I422ToRGB24Row_NEON; |
5573 | | } |
5574 | | } |
5575 | | #endif |
5576 | | #if defined(HAS_I422TORGB24ROW_SVE2) |
5577 | | if (TestCpuFlag(kCpuHasSVE2)) { |
5578 | | I422ToRGB24Row = I422ToRGB24Row_SVE2; |
5579 | | } |
5580 | | #endif |
5581 | | #if defined(HAS_I422TORGB24ROW_SME) |
5582 | | if (TestCpuFlag(kCpuHasSME)) { |
5583 | | I422ToRGB24Row = I422ToRGB24Row_SME; |
5584 | | } |
5585 | | #endif |
5586 | | #if defined(HAS_I422TORGB24ROW_LSX) |
5587 | | if (TestCpuFlag(kCpuHasLSX)) { |
5588 | | I422ToRGB24Row = I422ToRGB24Row_Any_LSX; |
5589 | | if (IS_ALIGNED(width, 16)) { |
5590 | | I422ToRGB24Row = I422ToRGB24Row_LSX; |
5591 | | } |
5592 | | } |
5593 | | #endif |
5594 | | #if defined(HAS_I422TORGB24ROW_LASX) |
5595 | | if (TestCpuFlag(kCpuHasLASX)) { |
5596 | | I422ToRGB24Row = I422ToRGB24Row_Any_LASX; |
5597 | | if (IS_ALIGNED(width, 32)) { |
5598 | | I422ToRGB24Row = I422ToRGB24Row_LASX; |
5599 | | } |
5600 | | } |
5601 | | #endif |
5602 | | #if defined(HAS_I422TORGB24ROW_RVV) |
5603 | | if (TestCpuFlag(kCpuHasRVV)) { |
5604 | | I422ToRGB24Row = I422ToRGB24Row_RVV; |
5605 | | } |
5606 | | #endif |
5607 | | |
5608 | 2.50k | for (y = 0; y < height; ++y) { |
5609 | 2.36k | I422ToRGB24Row(src_y, src_u, src_v, dst_rgb24, yuvconstants, width); |
5610 | 2.36k | dst_rgb24 += dst_stride_rgb24; |
5611 | 2.36k | src_y += src_stride_y; |
5612 | 2.36k | if (y & 1) { |
5613 | 1.16k | src_u += src_stride_u; |
5614 | 1.16k | src_v += src_stride_v; |
5615 | 1.16k | } |
5616 | 2.36k | } |
5617 | 144 | return 0; |
5618 | 144 | } |
5619 | | |
5620 | | // Convert I420 to RGB24. |
5621 | | LIBYUV_API |
5622 | | int I420ToRGB24(const uint8_t* src_y, |
5623 | | int src_stride_y, |
5624 | | const uint8_t* src_u, |
5625 | | int src_stride_u, |
5626 | | const uint8_t* src_v, |
5627 | | int src_stride_v, |
5628 | | uint8_t* dst_rgb24, |
5629 | | int dst_stride_rgb24, |
5630 | | int width, |
5631 | 0 | int height) { |
5632 | 0 | return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
5633 | 0 | src_stride_v, dst_rgb24, dst_stride_rgb24, |
5634 | 0 | &kYuvI601Constants, width, height); |
5635 | 0 | } |
5636 | | |
5637 | | // Convert I420 to RAW. |
5638 | | LIBYUV_API |
5639 | | int I420ToRAW(const uint8_t* src_y, |
5640 | | int src_stride_y, |
5641 | | const uint8_t* src_u, |
5642 | | int src_stride_u, |
5643 | | const uint8_t* src_v, |
5644 | | int src_stride_v, |
5645 | | uint8_t* dst_raw, |
5646 | | int dst_stride_raw, |
5647 | | int width, |
5648 | 0 | int height) { |
5649 | 0 | return I420ToRGB24Matrix(src_y, src_stride_y, src_v, |
5650 | 0 | src_stride_v, // Swap U and V |
5651 | 0 | src_u, src_stride_u, dst_raw, dst_stride_raw, |
5652 | 0 | &kYvuI601Constants, // Use Yvu matrix |
5653 | 0 | width, height); |
5654 | 0 | } |
5655 | | |
5656 | | // Convert J420 to RGB24. |
5657 | | LIBYUV_API |
5658 | | int J420ToRGB24(const uint8_t* src_y, |
5659 | | int src_stride_y, |
5660 | | const uint8_t* src_u, |
5661 | | int src_stride_u, |
5662 | | const uint8_t* src_v, |
5663 | | int src_stride_v, |
5664 | | uint8_t* dst_rgb24, |
5665 | | int dst_stride_rgb24, |
5666 | | int width, |
5667 | 0 | int height) { |
5668 | 0 | return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
5669 | 0 | src_stride_v, dst_rgb24, dst_stride_rgb24, |
5670 | 0 | &kYuvJPEGConstants, width, height); |
5671 | 0 | } |
5672 | | |
5673 | | // Convert J420 to RAW. |
5674 | | LIBYUV_API |
5675 | | int J420ToRAW(const uint8_t* src_y, |
5676 | | int src_stride_y, |
5677 | | const uint8_t* src_u, |
5678 | | int src_stride_u, |
5679 | | const uint8_t* src_v, |
5680 | | int src_stride_v, |
5681 | | uint8_t* dst_raw, |
5682 | | int dst_stride_raw, |
5683 | | int width, |
5684 | 0 | int height) { |
5685 | 0 | return I420ToRGB24Matrix(src_y, src_stride_y, src_v, |
5686 | 0 | src_stride_v, // Swap U and V |
5687 | 0 | src_u, src_stride_u, dst_raw, dst_stride_raw, |
5688 | 0 | &kYvuJPEGConstants, // Use Yvu matrix |
5689 | 0 | width, height); |
5690 | 0 | } |
5691 | | |
5692 | | // Convert H420 to RGB24. |
5693 | | LIBYUV_API |
5694 | | int H420ToRGB24(const uint8_t* src_y, |
5695 | | int src_stride_y, |
5696 | | const uint8_t* src_u, |
5697 | | int src_stride_u, |
5698 | | const uint8_t* src_v, |
5699 | | int src_stride_v, |
5700 | | uint8_t* dst_rgb24, |
5701 | | int dst_stride_rgb24, |
5702 | | int width, |
5703 | 0 | int height) { |
5704 | 0 | return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
5705 | 0 | src_stride_v, dst_rgb24, dst_stride_rgb24, |
5706 | 0 | &kYuvH709Constants, width, height); |
5707 | 0 | } |
5708 | | |
5709 | | // Convert H420 to RAW. |
5710 | | LIBYUV_API |
5711 | | int H420ToRAW(const uint8_t* src_y, |
5712 | | int src_stride_y, |
5713 | | const uint8_t* src_u, |
5714 | | int src_stride_u, |
5715 | | const uint8_t* src_v, |
5716 | | int src_stride_v, |
5717 | | uint8_t* dst_raw, |
5718 | | int dst_stride_raw, |
5719 | | int width, |
5720 | 0 | int height) { |
5721 | 0 | return I420ToRGB24Matrix(src_y, src_stride_y, src_v, |
5722 | 0 | src_stride_v, // Swap U and V |
5723 | 0 | src_u, src_stride_u, dst_raw, dst_stride_raw, |
5724 | 0 | &kYvuH709Constants, // Use Yvu matrix |
5725 | 0 | width, height); |
5726 | 0 | } |
5727 | | |
5728 | | // Convert I422 to RGB24 with matrix. |
5729 | | LIBYUV_API |
5730 | | int I422ToRGB24Matrix(const uint8_t* src_y, |
5731 | | int src_stride_y, |
5732 | | const uint8_t* src_u, |
5733 | | int src_stride_u, |
5734 | | const uint8_t* src_v, |
5735 | | int src_stride_v, |
5736 | | uint8_t* dst_rgb24, |
5737 | | int dst_stride_rgb24, |
5738 | | const struct YuvConstants* yuvconstants, |
5739 | | int width, |
5740 | 64 | int height) { |
5741 | 64 | int y; |
5742 | 64 | void (*I422ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf, |
5743 | 64 | const uint8_t* v_buf, uint8_t* rgb_buf, |
5744 | 64 | const struct YuvConstants* yuvconstants, int width) = |
5745 | 64 | I422ToRGB24Row_C; |
5746 | 64 | assert(yuvconstants); |
5747 | 64 | if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || |
5748 | 64 | height == INT_MIN) { |
5749 | 0 | return -1; |
5750 | 0 | } |
5751 | | // Negative height means invert the image. |
5752 | 64 | if (height < 0) { |
5753 | 0 | height = -height; |
5754 | 0 | dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; |
5755 | 0 | dst_stride_rgb24 = -dst_stride_rgb24; |
5756 | 0 | } |
5757 | 64 | #if defined(HAS_I422TORGB24ROW_SSSE3) |
5758 | 64 | if (TestCpuFlag(kCpuHasSSSE3)) { |
5759 | 64 | I422ToRGB24Row = I422ToRGB24Row_Any_SSSE3; |
5760 | 64 | if (IS_ALIGNED(width, 16)) { |
5761 | 17 | I422ToRGB24Row = I422ToRGB24Row_SSSE3; |
5762 | 17 | } |
5763 | 64 | } |
5764 | 64 | #endif |
5765 | 64 | #if defined(HAS_I422TORGB24ROW_AVX2) |
5766 | 64 | if (TestCpuFlag(kCpuHasAVX2)) { |
5767 | 64 | I422ToRGB24Row = I422ToRGB24Row_Any_AVX2; |
5768 | 64 | if (IS_ALIGNED(width, 16)) { |
5769 | 17 | I422ToRGB24Row = I422ToRGB24Row_AVX2; |
5770 | 17 | } |
5771 | 64 | } |
5772 | 64 | #endif |
5773 | 64 | #if defined(HAS_I422TORGB24ROW_AVX512VBMI) |
5774 | 64 | if (TestCpuFlag(kCpuHasAVX512VBMI)) { |
5775 | 0 | I422ToRGB24Row = I422ToRGB24Row_Any_AVX512VBMI; |
5776 | 0 | if (IS_ALIGNED(width, 32)) { |
5777 | 0 | I422ToRGB24Row = I422ToRGB24Row_AVX512VBMI; |
5778 | 0 | } |
5779 | 0 | } |
5780 | 64 | #endif |
5781 | | #if defined(HAS_I422TORGB24ROW_NEON) |
5782 | | if (TestCpuFlag(kCpuHasNEON)) { |
5783 | | I422ToRGB24Row = I422ToRGB24Row_Any_NEON; |
5784 | | if (IS_ALIGNED(width, 8)) { |
5785 | | I422ToRGB24Row = I422ToRGB24Row_NEON; |
5786 | | } |
5787 | | } |
5788 | | #endif |
5789 | | #if defined(HAS_I422TORGB24ROW_SVE2) |
5790 | | if (TestCpuFlag(kCpuHasSVE2)) { |
5791 | | I422ToRGB24Row = I422ToRGB24Row_SVE2; |
5792 | | } |
5793 | | #endif |
5794 | | #if defined(HAS_I422TORGB24ROW_SME) |
5795 | | if (TestCpuFlag(kCpuHasSME)) { |
5796 | | I422ToRGB24Row = I422ToRGB24Row_SME; |
5797 | | } |
5798 | | #endif |
5799 | | #if defined(HAS_I422TORGB24ROW_LSX) |
5800 | | if (TestCpuFlag(kCpuHasLSX)) { |
5801 | | I422ToRGB24Row = I422ToRGB24Row_Any_LSX; |
5802 | | if (IS_ALIGNED(width, 16)) { |
5803 | | I422ToRGB24Row = I422ToRGB24Row_LSX; |
5804 | | } |
5805 | | } |
5806 | | #endif |
5807 | | #if defined(HAS_I422TORGB24ROW_LASX) |
5808 | | if (TestCpuFlag(kCpuHasLASX)) { |
5809 | | I422ToRGB24Row = I422ToRGB24Row_Any_LASX; |
5810 | | if (IS_ALIGNED(width, 32)) { |
5811 | | I422ToRGB24Row = I422ToRGB24Row_LASX; |
5812 | | } |
5813 | | } |
5814 | | #endif |
5815 | | #if defined(HAS_I422TORGB24ROW_RVV) |
5816 | | if (TestCpuFlag(kCpuHasRVV)) { |
5817 | | I422ToRGB24Row = I422ToRGB24Row_RVV; |
5818 | | } |
5819 | | #endif |
5820 | | |
5821 | 1.41k | for (y = 0; y < height; ++y) { |
5822 | 1.34k | I422ToRGB24Row(src_y, src_u, src_v, dst_rgb24, yuvconstants, width); |
5823 | 1.34k | dst_rgb24 += dst_stride_rgb24; |
5824 | 1.34k | src_y += src_stride_y; |
5825 | 1.34k | src_u += src_stride_u; |
5826 | 1.34k | src_v += src_stride_v; |
5827 | 1.34k | } |
5828 | 64 | return 0; |
5829 | 64 | } |
5830 | | |
5831 | | // Convert I422 to RGB24. |
5832 | | LIBYUV_API |
5833 | | int I422ToRGB24(const uint8_t* src_y, |
5834 | | int src_stride_y, |
5835 | | const uint8_t* src_u, |
5836 | | int src_stride_u, |
5837 | | const uint8_t* src_v, |
5838 | | int src_stride_v, |
5839 | | uint8_t* dst_rgb24, |
5840 | | int dst_stride_rgb24, |
5841 | | int width, |
5842 | 0 | int height) { |
5843 | 0 | return I422ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
5844 | 0 | src_stride_v, dst_rgb24, dst_stride_rgb24, |
5845 | 0 | &kYuvI601Constants, width, height); |
5846 | 0 | } |
5847 | | |
5848 | | // Convert I422 to RAW. |
5849 | | LIBYUV_API |
5850 | | int I422ToRAW(const uint8_t* src_y, |
5851 | | int src_stride_y, |
5852 | | const uint8_t* src_u, |
5853 | | int src_stride_u, |
5854 | | const uint8_t* src_v, |
5855 | | int src_stride_v, |
5856 | | uint8_t* dst_raw, |
5857 | | int dst_stride_raw, |
5858 | | int width, |
5859 | 0 | int height) { |
5860 | 0 | return I422ToRGB24Matrix(src_y, src_stride_y, src_v, |
5861 | 0 | src_stride_v, // Swap U and V |
5862 | 0 | src_u, src_stride_u, dst_raw, dst_stride_raw, |
5863 | 0 | &kYvuI601Constants, // Use Yvu matrix |
5864 | 0 | width, height); |
5865 | 0 | } |
5866 | | |
5867 | | // Convert I420 to ARGB1555. |
5868 | | LIBYUV_API |
5869 | | int I420ToARGB1555(const uint8_t* src_y, |
5870 | | int src_stride_y, |
5871 | | const uint8_t* src_u, |
5872 | | int src_stride_u, |
5873 | | const uint8_t* src_v, |
5874 | | int src_stride_v, |
5875 | | uint8_t* dst_argb1555, |
5876 | | int dst_stride_argb1555, |
5877 | | int width, |
5878 | 0 | int height) { |
5879 | 0 | int y; |
5880 | 0 | void (*I422ToARGB1555Row)(const uint8_t* y_buf, const uint8_t* u_buf, |
5881 | 0 | const uint8_t* v_buf, uint8_t* rgb_buf, |
5882 | 0 | const struct YuvConstants* yuvconstants, |
5883 | 0 | int width) = I422ToARGB1555Row_C; |
5884 | 0 | if (!src_y || !src_u || !src_v || !dst_argb1555 || width <= 0 || |
5885 | 0 | height == 0 || height == INT_MIN) { |
5886 | 0 | return -1; |
5887 | 0 | } |
5888 | | // Negative height means invert the image. |
5889 | 0 | if (height < 0) { |
5890 | 0 | height = -height; |
5891 | 0 | dst_argb1555 = dst_argb1555 + (ptrdiff_t)(height - 1) * dst_stride_argb1555; |
5892 | 0 | dst_stride_argb1555 = -dst_stride_argb1555; |
5893 | 0 | } |
5894 | | #if defined(HAS_I422TOARGB1555ROW_SSSE3) |
5895 | | if (TestCpuFlag(kCpuHasSSSE3)) { |
5896 | | I422ToARGB1555Row = I422ToARGB1555Row_Any_SSSE3; |
5897 | | if (IS_ALIGNED(width, 8)) { |
5898 | | I422ToARGB1555Row = I422ToARGB1555Row_SSSE3; |
5899 | | } |
5900 | | } |
5901 | | #endif |
5902 | | #if defined(HAS_I422TOARGB1555ROW_AVX2) |
5903 | | if (TestCpuFlag(kCpuHasAVX2)) { |
5904 | | I422ToARGB1555Row = I422ToARGB1555Row_Any_AVX2; |
5905 | | if (IS_ALIGNED(width, 16)) { |
5906 | | I422ToARGB1555Row = I422ToARGB1555Row_AVX2; |
5907 | | } |
5908 | | } |
5909 | | #endif |
5910 | | #if defined(HAS_I422TOARGB1555ROW_NEON) |
5911 | | if (TestCpuFlag(kCpuHasNEON)) { |
5912 | | I422ToARGB1555Row = I422ToARGB1555Row_Any_NEON; |
5913 | | if (IS_ALIGNED(width, 8)) { |
5914 | | I422ToARGB1555Row = I422ToARGB1555Row_NEON; |
5915 | | } |
5916 | | } |
5917 | | #endif |
5918 | | #if defined(HAS_I422TOARGB1555ROW_SVE2) |
5919 | | if (TestCpuFlag(kCpuHasSVE2)) { |
5920 | | I422ToARGB1555Row = I422ToARGB1555Row_SVE2; |
5921 | | } |
5922 | | #endif |
5923 | | #if defined(HAS_I422TOARGB1555ROW_SME) |
5924 | | if (TestCpuFlag(kCpuHasSME)) { |
5925 | | I422ToARGB1555Row = I422ToARGB1555Row_SME; |
5926 | | } |
5927 | | #endif |
5928 | | #if defined(HAS_I422TOARGB1555ROW_LSX) |
5929 | | if (TestCpuFlag(kCpuHasLSX)) { |
5930 | | I422ToARGB1555Row = I422ToARGB1555Row_Any_LSX; |
5931 | | if (IS_ALIGNED(width, 16)) { |
5932 | | I422ToARGB1555Row = I422ToARGB1555Row_LSX; |
5933 | | } |
5934 | | } |
5935 | | #endif |
5936 | | #if defined(HAS_I422TOARGB1555ROW_LASX) |
5937 | | if (TestCpuFlag(kCpuHasLASX)) { |
5938 | | I422ToARGB1555Row = I422ToARGB1555Row_Any_LASX; |
5939 | | if (IS_ALIGNED(width, 8)) { |
5940 | | I422ToARGB1555Row = I422ToARGB1555Row_LASX; |
5941 | | } |
5942 | | } |
5943 | | #endif |
5944 | |
|
5945 | 0 | for (y = 0; y < height; ++y) { |
5946 | 0 | I422ToARGB1555Row(src_y, src_u, src_v, dst_argb1555, &kYuvI601Constants, |
5947 | 0 | width); |
5948 | 0 | dst_argb1555 += dst_stride_argb1555; |
5949 | 0 | src_y += src_stride_y; |
5950 | 0 | if (y & 1) { |
5951 | 0 | src_u += src_stride_u; |
5952 | 0 | src_v += src_stride_v; |
5953 | 0 | } |
5954 | 0 | } |
5955 | 0 | return 0; |
5956 | 0 | } |
5957 | | |
5958 | | // Convert I420 to ARGB4444. |
5959 | | LIBYUV_API |
5960 | | int I420ToARGB4444(const uint8_t* src_y, |
5961 | | int src_stride_y, |
5962 | | const uint8_t* src_u, |
5963 | | int src_stride_u, |
5964 | | const uint8_t* src_v, |
5965 | | int src_stride_v, |
5966 | | uint8_t* dst_argb4444, |
5967 | | int dst_stride_argb4444, |
5968 | | int width, |
5969 | 0 | int height) { |
5970 | 0 | int y; |
5971 | 0 | void (*I422ToARGB4444Row)(const uint8_t* y_buf, const uint8_t* u_buf, |
5972 | 0 | const uint8_t* v_buf, uint8_t* rgb_buf, |
5973 | 0 | const struct YuvConstants* yuvconstants, |
5974 | 0 | int width) = I422ToARGB4444Row_C; |
5975 | 0 | if (!src_y || !src_u || !src_v || !dst_argb4444 || width <= 0 || |
5976 | 0 | height == 0 || height == INT_MIN) { |
5977 | 0 | return -1; |
5978 | 0 | } |
5979 | | // Negative height means invert the image. |
5980 | 0 | if (height < 0) { |
5981 | 0 | height = -height; |
5982 | 0 | dst_argb4444 = dst_argb4444 + (ptrdiff_t)(height - 1) * dst_stride_argb4444; |
5983 | 0 | dst_stride_argb4444 = -dst_stride_argb4444; |
5984 | 0 | } |
5985 | | #if defined(HAS_I422TOARGB4444ROW_SSSE3) |
5986 | | if (TestCpuFlag(kCpuHasSSSE3)) { |
5987 | | I422ToARGB4444Row = I422ToARGB4444Row_Any_SSSE3; |
5988 | | if (IS_ALIGNED(width, 8)) { |
5989 | | I422ToARGB4444Row = I422ToARGB4444Row_SSSE3; |
5990 | | } |
5991 | | } |
5992 | | #endif |
5993 | | #if defined(HAS_I422TOARGB4444ROW_AVX2) |
5994 | | if (TestCpuFlag(kCpuHasAVX2)) { |
5995 | | I422ToARGB4444Row = I422ToARGB4444Row_Any_AVX2; |
5996 | | if (IS_ALIGNED(width, 16)) { |
5997 | | I422ToARGB4444Row = I422ToARGB4444Row_AVX2; |
5998 | | } |
5999 | | } |
6000 | | #endif |
6001 | | #if defined(HAS_I422TOARGB4444ROW_NEON) |
6002 | | if (TestCpuFlag(kCpuHasNEON)) { |
6003 | | I422ToARGB4444Row = I422ToARGB4444Row_Any_NEON; |
6004 | | if (IS_ALIGNED(width, 8)) { |
6005 | | I422ToARGB4444Row = I422ToARGB4444Row_NEON; |
6006 | | } |
6007 | | } |
6008 | | #endif |
6009 | | #if defined(HAS_I422TOARGB4444ROW_SVE2) |
6010 | | if (TestCpuFlag(kCpuHasSVE2)) { |
6011 | | I422ToARGB4444Row = I422ToARGB4444Row_SVE2; |
6012 | | } |
6013 | | #endif |
6014 | | #if defined(HAS_I422TOARGB4444ROW_SME) |
6015 | | if (TestCpuFlag(kCpuHasSME)) { |
6016 | | I422ToARGB4444Row = I422ToARGB4444Row_SME; |
6017 | | } |
6018 | | #endif |
6019 | | #if defined(HAS_I422TOARGB4444ROW_LSX) |
6020 | | if (TestCpuFlag(kCpuHasLSX)) { |
6021 | | I422ToARGB4444Row = I422ToARGB4444Row_Any_LSX; |
6022 | | if (IS_ALIGNED(width, 16)) { |
6023 | | I422ToARGB4444Row = I422ToARGB4444Row_LSX; |
6024 | | } |
6025 | | } |
6026 | | #endif |
6027 | | #if defined(HAS_I422TOARGB4444ROW_LASX) |
6028 | | if (TestCpuFlag(kCpuHasLASX)) { |
6029 | | I422ToARGB4444Row = I422ToARGB4444Row_Any_LASX; |
6030 | | if (IS_ALIGNED(width, 8)) { |
6031 | | I422ToARGB4444Row = I422ToARGB4444Row_LASX; |
6032 | | } |
6033 | | } |
6034 | | #endif |
6035 | |
|
6036 | 0 | for (y = 0; y < height; ++y) { |
6037 | 0 | I422ToARGB4444Row(src_y, src_u, src_v, dst_argb4444, &kYuvI601Constants, |
6038 | 0 | width); |
6039 | 0 | dst_argb4444 += dst_stride_argb4444; |
6040 | 0 | src_y += src_stride_y; |
6041 | 0 | if (y & 1) { |
6042 | 0 | src_u += src_stride_u; |
6043 | 0 | src_v += src_stride_v; |
6044 | 0 | } |
6045 | 0 | } |
6046 | 0 | return 0; |
6047 | 0 | } |
6048 | | |
6049 | | // Convert I420 to RGB565 with specified color matrix. |
6050 | | LIBYUV_API |
6051 | | int I420ToRGB565Matrix(const uint8_t* src_y, |
6052 | | int src_stride_y, |
6053 | | const uint8_t* src_u, |
6054 | | int src_stride_u, |
6055 | | const uint8_t* src_v, |
6056 | | int src_stride_v, |
6057 | | uint8_t* dst_rgb565, |
6058 | | int dst_stride_rgb565, |
6059 | | const struct YuvConstants* yuvconstants, |
6060 | | int width, |
6061 | 120 | int height) { |
6062 | 120 | int y; |
6063 | 120 | void (*I422ToRGB565Row)(const uint8_t* y_buf, const uint8_t* u_buf, |
6064 | 120 | const uint8_t* v_buf, uint8_t* rgb_buf, |
6065 | 120 | const struct YuvConstants* yuvconstants, int width) = |
6066 | 120 | I422ToRGB565Row_C; |
6067 | 120 | assert(yuvconstants); |
6068 | 120 | if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0 || |
6069 | 120 | height == INT_MIN) { |
6070 | 0 | return -1; |
6071 | 0 | } |
6072 | | // Negative height means invert the image. |
6073 | 120 | if (height < 0) { |
6074 | 0 | height = -height; |
6075 | 0 | dst_rgb565 = dst_rgb565 + (ptrdiff_t)(height - 1) * dst_stride_rgb565; |
6076 | 0 | dst_stride_rgb565 = -dst_stride_rgb565; |
6077 | 0 | } |
6078 | | #if defined(HAS_I422TORGB565ROW_SSSE3) |
6079 | | if (TestCpuFlag(kCpuHasSSSE3)) { |
6080 | | I422ToRGB565Row = I422ToRGB565Row_Any_SSSE3; |
6081 | | if (IS_ALIGNED(width, 8)) { |
6082 | | I422ToRGB565Row = I422ToRGB565Row_SSSE3; |
6083 | | } |
6084 | | } |
6085 | | #endif |
6086 | | #if defined(HAS_I422TORGB565ROW_AVX2) |
6087 | | if (TestCpuFlag(kCpuHasAVX2)) { |
6088 | | I422ToRGB565Row = I422ToRGB565Row_Any_AVX2; |
6089 | | if (IS_ALIGNED(width, 16)) { |
6090 | | I422ToRGB565Row = I422ToRGB565Row_AVX2; |
6091 | | } |
6092 | | } |
6093 | | #endif |
6094 | | #if defined(HAS_I422TORGB565ROW_NEON) |
6095 | | if (TestCpuFlag(kCpuHasNEON)) { |
6096 | | I422ToRGB565Row = I422ToRGB565Row_Any_NEON; |
6097 | | if (IS_ALIGNED(width, 8)) { |
6098 | | I422ToRGB565Row = I422ToRGB565Row_NEON; |
6099 | | } |
6100 | | } |
6101 | | #endif |
6102 | | #if defined(HAS_I422TORGB565ROW_SVE2) |
6103 | | if (TestCpuFlag(kCpuHasSVE2)) { |
6104 | | I422ToRGB565Row = I422ToRGB565Row_SVE2; |
6105 | | } |
6106 | | #endif |
6107 | | #if defined(HAS_I422TORGB565ROW_SME) |
6108 | | if (TestCpuFlag(kCpuHasSME)) { |
6109 | | I422ToRGB565Row = I422ToRGB565Row_SME; |
6110 | | } |
6111 | | #endif |
6112 | | #if defined(HAS_I422TORGB565ROW_LSX) |
6113 | | if (TestCpuFlag(kCpuHasLSX)) { |
6114 | | I422ToRGB565Row = I422ToRGB565Row_Any_LSX; |
6115 | | if (IS_ALIGNED(width, 16)) { |
6116 | | I422ToRGB565Row = I422ToRGB565Row_LSX; |
6117 | | } |
6118 | | } |
6119 | | #endif |
6120 | | #if defined(HAS_I422TORGB565ROW_LASX) |
6121 | | if (TestCpuFlag(kCpuHasLASX)) { |
6122 | | I422ToRGB565Row = I422ToRGB565Row_Any_LASX; |
6123 | | if (IS_ALIGNED(width, 32)) { |
6124 | | I422ToRGB565Row = I422ToRGB565Row_LASX; |
6125 | | } |
6126 | | } |
6127 | | #endif |
6128 | | |
6129 | 2.64k | for (y = 0; y < height; ++y) { |
6130 | 2.52k | I422ToRGB565Row(src_y, src_u, src_v, dst_rgb565, yuvconstants, width); |
6131 | 2.52k | dst_rgb565 += dst_stride_rgb565; |
6132 | 2.52k | src_y += src_stride_y; |
6133 | 2.52k | if (y & 1) { |
6134 | 1.25k | src_u += src_stride_u; |
6135 | 1.25k | src_v += src_stride_v; |
6136 | 1.25k | } |
6137 | 2.52k | } |
6138 | 120 | return 0; |
6139 | 120 | } |
6140 | | |
6141 | | // Convert I420 to RGB565. |
6142 | | LIBYUV_API |
6143 | | int I420ToRGB565(const uint8_t* src_y, |
6144 | | int src_stride_y, |
6145 | | const uint8_t* src_u, |
6146 | | int src_stride_u, |
6147 | | const uint8_t* src_v, |
6148 | | int src_stride_v, |
6149 | | uint8_t* dst_rgb565, |
6150 | | int dst_stride_rgb565, |
6151 | | int width, |
6152 | 0 | int height) { |
6153 | 0 | return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
6154 | 0 | src_stride_v, dst_rgb565, dst_stride_rgb565, |
6155 | 0 | &kYuvI601Constants, width, height); |
6156 | 0 | } |
6157 | | |
6158 | | // Convert J420 to RGB565. |
6159 | | LIBYUV_API |
6160 | | int J420ToRGB565(const uint8_t* src_y, |
6161 | | int src_stride_y, |
6162 | | const uint8_t* src_u, |
6163 | | int src_stride_u, |
6164 | | const uint8_t* src_v, |
6165 | | int src_stride_v, |
6166 | | uint8_t* dst_rgb565, |
6167 | | int dst_stride_rgb565, |
6168 | | int width, |
6169 | 0 | int height) { |
6170 | 0 | return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
6171 | 0 | src_stride_v, dst_rgb565, dst_stride_rgb565, |
6172 | 0 | &kYuvJPEGConstants, width, height); |
6173 | 0 | } |
6174 | | |
6175 | | // Convert H420 to RGB565. |
6176 | | LIBYUV_API |
6177 | | int H420ToRGB565(const uint8_t* src_y, |
6178 | | int src_stride_y, |
6179 | | const uint8_t* src_u, |
6180 | | int src_stride_u, |
6181 | | const uint8_t* src_v, |
6182 | | int src_stride_v, |
6183 | | uint8_t* dst_rgb565, |
6184 | | int dst_stride_rgb565, |
6185 | | int width, |
6186 | 0 | int height) { |
6187 | 0 | return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
6188 | 0 | src_stride_v, dst_rgb565, dst_stride_rgb565, |
6189 | 0 | &kYuvH709Constants, width, height); |
6190 | 0 | } |
6191 | | |
6192 | | // Convert I422 to RGB565 with specified color matrix. |
6193 | | LIBYUV_API |
6194 | | int I422ToRGB565Matrix(const uint8_t* src_y, |
6195 | | int src_stride_y, |
6196 | | const uint8_t* src_u, |
6197 | | int src_stride_u, |
6198 | | const uint8_t* src_v, |
6199 | | int src_stride_v, |
6200 | | uint8_t* dst_rgb565, |
6201 | | int dst_stride_rgb565, |
6202 | | const struct YuvConstants* yuvconstants, |
6203 | | int width, |
6204 | 51 | int height) { |
6205 | 51 | int y; |
6206 | 51 | void (*I422ToRGB565Row)(const uint8_t* y_buf, const uint8_t* u_buf, |
6207 | 51 | const uint8_t* v_buf, uint8_t* rgb_buf, |
6208 | 51 | const struct YuvConstants* yuvconstants, int width) = |
6209 | 51 | I422ToRGB565Row_C; |
6210 | 51 | assert(yuvconstants); |
6211 | 51 | if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0 || |
6212 | 51 | height == INT_MIN) { |
6213 | 0 | return -1; |
6214 | 0 | } |
6215 | | // Negative height means invert the image. |
6216 | 51 | if (height < 0) { |
6217 | 0 | height = -height; |
6218 | 0 | dst_rgb565 = dst_rgb565 + (ptrdiff_t)(height - 1) * dst_stride_rgb565; |
6219 | 0 | dst_stride_rgb565 = -dst_stride_rgb565; |
6220 | 0 | } |
6221 | | #if defined(HAS_I422TORGB565ROW_SSSE3) |
6222 | | if (TestCpuFlag(kCpuHasSSSE3)) { |
6223 | | I422ToRGB565Row = I422ToRGB565Row_Any_SSSE3; |
6224 | | if (IS_ALIGNED(width, 8)) { |
6225 | | I422ToRGB565Row = I422ToRGB565Row_SSSE3; |
6226 | | } |
6227 | | } |
6228 | | #endif |
6229 | | #if defined(HAS_I422TORGB565ROW_AVX2) |
6230 | | if (TestCpuFlag(kCpuHasAVX2)) { |
6231 | | I422ToRGB565Row = I422ToRGB565Row_Any_AVX2; |
6232 | | if (IS_ALIGNED(width, 16)) { |
6233 | | I422ToRGB565Row = I422ToRGB565Row_AVX2; |
6234 | | } |
6235 | | } |
6236 | | #endif |
6237 | | #if defined(HAS_I422TORGB565ROW_NEON) |
6238 | | if (TestCpuFlag(kCpuHasNEON)) { |
6239 | | I422ToRGB565Row = I422ToRGB565Row_Any_NEON; |
6240 | | if (IS_ALIGNED(width, 8)) { |
6241 | | I422ToRGB565Row = I422ToRGB565Row_NEON; |
6242 | | } |
6243 | | } |
6244 | | #endif |
6245 | | #if defined(HAS_I422TORGB565ROW_SVE2) |
6246 | | if (TestCpuFlag(kCpuHasSVE2)) { |
6247 | | I422ToRGB565Row = I422ToRGB565Row_SVE2; |
6248 | | } |
6249 | | #endif |
6250 | | #if defined(HAS_I422TORGB565ROW_SME) |
6251 | | if (TestCpuFlag(kCpuHasSME)) { |
6252 | | I422ToRGB565Row = I422ToRGB565Row_SME; |
6253 | | } |
6254 | | #endif |
6255 | | #if defined(HAS_I422TORGB565ROW_LSX) |
6256 | | if (TestCpuFlag(kCpuHasLSX)) { |
6257 | | I422ToRGB565Row = I422ToRGB565Row_Any_LSX; |
6258 | | if (IS_ALIGNED(width, 16)) { |
6259 | | I422ToRGB565Row = I422ToRGB565Row_LSX; |
6260 | | } |
6261 | | } |
6262 | | #endif |
6263 | | #if defined(HAS_I422TORGB565ROW_LASX) |
6264 | | if (TestCpuFlag(kCpuHasLASX)) { |
6265 | | I422ToRGB565Row = I422ToRGB565Row_Any_LASX; |
6266 | | if (IS_ALIGNED(width, 32)) { |
6267 | | I422ToRGB565Row = I422ToRGB565Row_LASX; |
6268 | | } |
6269 | | } |
6270 | | #endif |
6271 | | |
6272 | 1.68k | for (y = 0; y < height; ++y) { |
6273 | 1.63k | I422ToRGB565Row(src_y, src_u, src_v, dst_rgb565, yuvconstants, width); |
6274 | 1.63k | dst_rgb565 += dst_stride_rgb565; |
6275 | 1.63k | src_y += src_stride_y; |
6276 | 1.63k | src_u += src_stride_u; |
6277 | 1.63k | src_v += src_stride_v; |
6278 | 1.63k | } |
6279 | 51 | return 0; |
6280 | 51 | } |
6281 | | |
6282 | | // Convert I422 to RGB565. |
6283 | | LIBYUV_API |
6284 | | int I422ToRGB565(const uint8_t* src_y, |
6285 | | int src_stride_y, |
6286 | | const uint8_t* src_u, |
6287 | | int src_stride_u, |
6288 | | const uint8_t* src_v, |
6289 | | int src_stride_v, |
6290 | | uint8_t* dst_rgb565, |
6291 | | int dst_stride_rgb565, |
6292 | | int width, |
6293 | 0 | int height) { |
6294 | 0 | return I422ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
6295 | 0 | src_stride_v, dst_rgb565, dst_stride_rgb565, |
6296 | 0 | &kYuvI601Constants, width, height); |
6297 | 0 | } |
6298 | | |
6299 | | // Ordered 8x8 dither for 888 to 565. Values from 0 to 7. |
6300 | | static const uint8_t kDither565_4x4[16] = { |
6301 | | 0, 4, 1, 5, 6, 2, 7, 3, 1, 5, 0, 4, 7, 3, 6, 2, |
6302 | | }; |
6303 | | |
6304 | | // Convert I420 to RGB565 with dithering. |
6305 | | LIBYUV_API |
6306 | | int I420ToRGB565Dither(const uint8_t* src_y, |
6307 | | int src_stride_y, |
6308 | | const uint8_t* src_u, |
6309 | | int src_stride_u, |
6310 | | const uint8_t* src_v, |
6311 | | int src_stride_v, |
6312 | | uint8_t* dst_rgb565, |
6313 | | int dst_stride_rgb565, |
6314 | | const uint8_t* dither4x4, |
6315 | | int width, |
6316 | 0 | int height) { |
6317 | 0 | int y; |
6318 | 0 | uint32_t dither4[4]; |
6319 | 0 | void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, |
6320 | 0 | const uint8_t* v_buf, uint8_t* rgb_buf, |
6321 | 0 | const struct YuvConstants* yuvconstants, int width) = |
6322 | 0 | I422ToARGBRow_C; |
6323 | 0 | void (*ARGBToRGB565DitherRow)(const uint8_t* src_argb, uint8_t* dst_rgb, |
6324 | 0 | uint32_t dither4, int width) = |
6325 | 0 | ARGBToRGB565DitherRow_C; |
6326 | 0 | if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0 || |
6327 | 0 | height == INT_MIN) { |
6328 | 0 | return -1; |
6329 | 0 | } |
6330 | | // Negative height means invert the image. |
6331 | 0 | if (height < 0) { |
6332 | 0 | height = -height; |
6333 | 0 | dst_rgb565 = dst_rgb565 + (ptrdiff_t)(height - 1) * dst_stride_rgb565; |
6334 | 0 | dst_stride_rgb565 = -dst_stride_rgb565; |
6335 | 0 | } |
6336 | 0 | if (!dither4x4) { |
6337 | 0 | dither4x4 = kDither565_4x4; |
6338 | 0 | } |
6339 | 0 | memcpy(dither4, dither4x4, 16); |
6340 | 0 | #if defined(HAS_I422TOARGBROW_SSSE3) |
6341 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
6342 | 0 | I422ToARGBRow = I422ToARGBRow_Any_SSSE3; |
6343 | 0 | if (IS_ALIGNED(width, 8)) { |
6344 | 0 | I422ToARGBRow = I422ToARGBRow_SSSE3; |
6345 | 0 | } |
6346 | 0 | } |
6347 | 0 | #endif |
6348 | 0 | #if defined(HAS_I422TOARGBROW_AVX2) |
6349 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
6350 | 0 | I422ToARGBRow = I422ToARGBRow_Any_AVX2; |
6351 | 0 | if (IS_ALIGNED(width, 16)) { |
6352 | 0 | I422ToARGBRow = I422ToARGBRow_AVX2; |
6353 | 0 | } |
6354 | 0 | } |
6355 | 0 | #endif |
6356 | 0 | #if defined(HAS_I422TOARGBROW_AVX512BW) |
6357 | 0 | if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) == |
6358 | 0 | (kCpuHasAVX512BW | kCpuHasAVX512VL)) { |
6359 | 0 | I422ToARGBRow = I422ToARGBRow_Any_AVX512BW; |
6360 | 0 | if (IS_ALIGNED(width, 32)) { |
6361 | 0 | I422ToARGBRow = I422ToARGBRow_AVX512BW; |
6362 | 0 | } |
6363 | 0 | } |
6364 | 0 | #endif |
6365 | | #if defined(HAS_I422TOARGBROW_NEON) |
6366 | | if (TestCpuFlag(kCpuHasNEON)) { |
6367 | | I422ToARGBRow = I422ToARGBRow_Any_NEON; |
6368 | | if (IS_ALIGNED(width, 8)) { |
6369 | | I422ToARGBRow = I422ToARGBRow_NEON; |
6370 | | } |
6371 | | } |
6372 | | #endif |
6373 | | #if defined(HAS_I422TOARGBROW_SVE2) |
6374 | | if (TestCpuFlag(kCpuHasSVE2)) { |
6375 | | I422ToARGBRow = I422ToARGBRow_SVE2; |
6376 | | } |
6377 | | #endif |
6378 | | #if defined(HAS_I422TOARGBROW_SME) |
6379 | | if (TestCpuFlag(kCpuHasSME)) { |
6380 | | I422ToARGBRow = I422ToARGBRow_SME; |
6381 | | } |
6382 | | #endif |
6383 | | #if defined(HAS_I422TOARGBROW_LSX) |
6384 | | if (TestCpuFlag(kCpuHasLSX)) { |
6385 | | I422ToARGBRow = I422ToARGBRow_Any_LSX; |
6386 | | if (IS_ALIGNED(width, 16)) { |
6387 | | I422ToARGBRow = I422ToARGBRow_LSX; |
6388 | | } |
6389 | | } |
6390 | | #endif |
6391 | | #if defined(HAS_I422TOARGBROW_LASX) |
6392 | | if (TestCpuFlag(kCpuHasLASX)) { |
6393 | | I422ToARGBRow = I422ToARGBRow_Any_LASX; |
6394 | | if (IS_ALIGNED(width, 32)) { |
6395 | | I422ToARGBRow = I422ToARGBRow_LASX; |
6396 | | } |
6397 | | } |
6398 | | #endif |
6399 | | #if defined(HAS_I422TOARGBROW_RVV) |
6400 | | if (TestCpuFlag(kCpuHasRVV)) { |
6401 | | I422ToARGBRow = I422ToARGBRow_RVV; |
6402 | | } |
6403 | | #endif |
6404 | | #if defined(HAS_ARGBTORGB565DITHERROW_SSE2) |
6405 | | if (TestCpuFlag(kCpuHasSSE2)) { |
6406 | | ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_SSE2; |
6407 | | if (IS_ALIGNED(width, 4)) { |
6408 | | ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_SSE2; |
6409 | | } |
6410 | | } |
6411 | | #endif |
6412 | 0 | #if defined(HAS_ARGBTORGB565DITHERROW_AVX2) |
6413 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
6414 | 0 | ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_AVX2; |
6415 | 0 | if (IS_ALIGNED(width, 8)) { |
6416 | 0 | ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_AVX2; |
6417 | 0 | } |
6418 | 0 | } |
6419 | 0 | #endif |
6420 | | #if defined(HAS_ARGBTORGB565DITHERROW_NEON) |
6421 | | if (TestCpuFlag(kCpuHasNEON)) { |
6422 | | ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_NEON; |
6423 | | if (IS_ALIGNED(width, 8)) { |
6424 | | ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_NEON; |
6425 | | } |
6426 | | } |
6427 | | #endif |
6428 | | #if defined(HAS_ARGBTORGB565DITHERROW_SVE2) |
6429 | | if (TestCpuFlag(kCpuHasSVE2)) { |
6430 | | ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_SVE2; |
6431 | | } |
6432 | | #endif |
6433 | | #if defined(HAS_ARGBTORGB565DITHERROW_LSX) |
6434 | | if (TestCpuFlag(kCpuHasLSX)) { |
6435 | | ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_LSX; |
6436 | | if (IS_ALIGNED(width, 8)) { |
6437 | | ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_LSX; |
6438 | | } |
6439 | | } |
6440 | | #endif |
6441 | | #if defined(HAS_ARGBTORGB565DITHERROW_LASX) |
6442 | | if (TestCpuFlag(kCpuHasLASX)) { |
6443 | | ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_LASX; |
6444 | | if (IS_ALIGNED(width, 16)) { |
6445 | | ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_LASX; |
6446 | | } |
6447 | | } |
6448 | | #endif |
6449 | 0 | { |
6450 | | // Allocate a row of argb. |
6451 | 0 | align_buffer_64(row_argb, width * 4); |
6452 | 0 | if (!row_argb) |
6453 | 0 | return 1; |
6454 | 0 | for (y = 0; y < height; ++y) { |
6455 | 0 | I422ToARGBRow(src_y, src_u, src_v, row_argb, &kYuvI601Constants, width); |
6456 | 0 | ARGBToRGB565DitherRow(row_argb, dst_rgb565, dither4[y & 3], width); |
6457 | 0 | dst_rgb565 += dst_stride_rgb565; |
6458 | 0 | src_y += src_stride_y; |
6459 | 0 | if (y & 1) { |
6460 | 0 | src_u += src_stride_u; |
6461 | 0 | src_v += src_stride_v; |
6462 | 0 | } |
6463 | 0 | } |
6464 | 0 | free_aligned_buffer_64(row_argb); |
6465 | 0 | } |
6466 | 0 | return 0; |
6467 | 0 | } |
6468 | | |
6469 | | // Convert I420 to AR30 with matrix. |
6470 | | LIBYUV_API |
6471 | | int I420ToAR30Matrix(const uint8_t* src_y, |
6472 | | int src_stride_y, |
6473 | | const uint8_t* src_u, |
6474 | | int src_stride_u, |
6475 | | const uint8_t* src_v, |
6476 | | int src_stride_v, |
6477 | | uint8_t* dst_ar30, |
6478 | | int dst_stride_ar30, |
6479 | | const struct YuvConstants* yuvconstants, |
6480 | | int width, |
6481 | 0 | int height) { |
6482 | 0 | int y; |
6483 | 0 | void (*I422ToAR30Row)(const uint8_t* y_buf, const uint8_t* u_buf, |
6484 | 0 | const uint8_t* v_buf, uint8_t* rgb_buf, |
6485 | 0 | const struct YuvConstants* yuvconstants, int width) = |
6486 | 0 | I422ToAR30Row_C; |
6487 | |
|
6488 | 0 | assert(yuvconstants); |
6489 | 0 | if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || |
6490 | 0 | height == INT_MIN) { |
6491 | 0 | return -1; |
6492 | 0 | } |
6493 | | // Negative height means invert the image. |
6494 | 0 | if (height < 0) { |
6495 | 0 | height = -height; |
6496 | 0 | dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; |
6497 | 0 | dst_stride_ar30 = -dst_stride_ar30; |
6498 | 0 | } |
6499 | |
|
6500 | 0 | #if defined(HAS_I422TOAR30ROW_SSSE3) |
6501 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
6502 | 0 | I422ToAR30Row = I422ToAR30Row_Any_SSSE3; |
6503 | 0 | if (IS_ALIGNED(width, 8)) { |
6504 | 0 | I422ToAR30Row = I422ToAR30Row_SSSE3; |
6505 | 0 | } |
6506 | 0 | } |
6507 | 0 | #endif |
6508 | 0 | #if defined(HAS_I422TOAR30ROW_AVX2) |
6509 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
6510 | 0 | I422ToAR30Row = I422ToAR30Row_Any_AVX2; |
6511 | 0 | if (IS_ALIGNED(width, 16)) { |
6512 | 0 | I422ToAR30Row = I422ToAR30Row_AVX2; |
6513 | 0 | } |
6514 | 0 | } |
6515 | 0 | #endif |
6516 | 0 | #if defined(HAS_I422TOAR30ROW_AVX512BW) |
6517 | 0 | if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) == |
6518 | 0 | (kCpuHasAVX512BW | kCpuHasAVX512VL)) { |
6519 | 0 | I422ToAR30Row = I422ToAR30Row_Any_AVX512BW; |
6520 | 0 | if (IS_ALIGNED(width, 32)) { |
6521 | 0 | I422ToAR30Row = I422ToAR30Row_AVX512BW; |
6522 | 0 | } |
6523 | 0 | } |
6524 | 0 | #endif |
6525 | | #if defined(HAS_I422TOAR30ROW_NEON) |
6526 | | if (TestCpuFlag(kCpuHasNEON)) { |
6527 | | I422ToAR30Row = I422ToAR30Row_Any_NEON; |
6528 | | if (IS_ALIGNED(width, 8)) { |
6529 | | I422ToAR30Row = I422ToAR30Row_NEON; |
6530 | | } |
6531 | | } |
6532 | | #endif |
6533 | | #if defined(HAS_I422TOAR30ROW_SVE2) |
6534 | | if (TestCpuFlag(kCpuHasSVE2)) { |
6535 | | I422ToAR30Row = I422ToAR30Row_SVE2; |
6536 | | } |
6537 | | #endif |
6538 | | #if defined(HAS_I422TOAR30ROW_SME) |
6539 | | if (TestCpuFlag(kCpuHasSME)) { |
6540 | | I422ToAR30Row = I422ToAR30Row_SME; |
6541 | | } |
6542 | | #endif |
6543 | |
|
6544 | 0 | for (y = 0; y < height; ++y) { |
6545 | 0 | I422ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width); |
6546 | 0 | dst_ar30 += dst_stride_ar30; |
6547 | 0 | src_y += src_stride_y; |
6548 | 0 | if (y & 1) { |
6549 | 0 | src_u += src_stride_u; |
6550 | 0 | src_v += src_stride_v; |
6551 | 0 | } |
6552 | 0 | } |
6553 | 0 | return 0; |
6554 | 0 | } |
6555 | | |
6556 | | // Convert I420 to AR30. |
6557 | | LIBYUV_API |
6558 | | int I420ToAR30(const uint8_t* src_y, |
6559 | | int src_stride_y, |
6560 | | const uint8_t* src_u, |
6561 | | int src_stride_u, |
6562 | | const uint8_t* src_v, |
6563 | | int src_stride_v, |
6564 | | uint8_t* dst_ar30, |
6565 | | int dst_stride_ar30, |
6566 | | int width, |
6567 | 0 | int height) { |
6568 | 0 | return I420ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
6569 | 0 | src_stride_v, dst_ar30, dst_stride_ar30, |
6570 | 0 | &kYuvI601Constants, width, height); |
6571 | 0 | } |
6572 | | |
6573 | | // Convert H420 to AR30. |
6574 | | LIBYUV_API |
6575 | | int H420ToAR30(const uint8_t* src_y, |
6576 | | int src_stride_y, |
6577 | | const uint8_t* src_u, |
6578 | | int src_stride_u, |
6579 | | const uint8_t* src_v, |
6580 | | int src_stride_v, |
6581 | | uint8_t* dst_ar30, |
6582 | | int dst_stride_ar30, |
6583 | | int width, |
6584 | 0 | int height) { |
6585 | 0 | return I420ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
6586 | 0 | src_stride_v, dst_ar30, dst_stride_ar30, |
6587 | 0 | &kYvuH709Constants, width, height); |
6588 | 0 | } |
6589 | | |
6590 | | // Convert I420 to AB30. |
6591 | | LIBYUV_API |
6592 | | int I420ToAB30(const uint8_t* src_y, |
6593 | | int src_stride_y, |
6594 | | const uint8_t* src_u, |
6595 | | int src_stride_u, |
6596 | | const uint8_t* src_v, |
6597 | | int src_stride_v, |
6598 | | uint8_t* dst_ab30, |
6599 | | int dst_stride_ab30, |
6600 | | int width, |
6601 | 0 | int height) { |
6602 | 0 | return I420ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, |
6603 | 0 | src_stride_u, dst_ab30, dst_stride_ab30, |
6604 | 0 | &kYvuI601Constants, width, height); |
6605 | 0 | } |
6606 | | |
6607 | | // Convert H420 to AB30. |
6608 | | LIBYUV_API |
6609 | | int H420ToAB30(const uint8_t* src_y, |
6610 | | int src_stride_y, |
6611 | | const uint8_t* src_u, |
6612 | | int src_stride_u, |
6613 | | const uint8_t* src_v, |
6614 | | int src_stride_v, |
6615 | | uint8_t* dst_ab30, |
6616 | | int dst_stride_ab30, |
6617 | | int width, |
6618 | 0 | int height) { |
6619 | 0 | return I420ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, |
6620 | 0 | src_stride_u, dst_ab30, dst_stride_ab30, |
6621 | 0 | &kYvuH709Constants, width, height); |
6622 | 0 | } |
6623 | | |
6624 | | static int I420ToARGBMatrixBilinear(const uint8_t* src_y, |
6625 | | int src_stride_y, |
6626 | | const uint8_t* src_u, |
6627 | | int src_stride_u, |
6628 | | const uint8_t* src_v, |
6629 | | int src_stride_v, |
6630 | | uint8_t* dst_argb, |
6631 | | int dst_stride_argb, |
6632 | | const struct YuvConstants* yuvconstants, |
6633 | | int width, |
6634 | 146 | int height) { |
6635 | 146 | int y; |
6636 | 146 | void (*I444ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, |
6637 | 146 | const uint8_t* v_buf, uint8_t* rgb_buf, |
6638 | 146 | const struct YuvConstants* yuvconstants, int width) = |
6639 | 146 | I444ToARGBRow_C; |
6640 | 146 | void (*Scale2RowUp_Bilinear)(const uint8_t* src_ptr, ptrdiff_t src_stride, |
6641 | 146 | uint8_t* dst_ptr, ptrdiff_t dst_stride, |
6642 | 146 | int dst_width) = ScaleRowUp2_Bilinear_Any_C; |
6643 | 146 | void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, |
6644 | 146 | int dst_width) = ScaleRowUp2_Linear_Any_C; |
6645 | 146 | assert(yuvconstants); |
6646 | 146 | if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || |
6647 | 146 | height == INT_MIN) { |
6648 | 0 | return -1; |
6649 | 0 | } |
6650 | | // Negative height means invert the image. |
6651 | 146 | if (height < 0) { |
6652 | 0 | height = -height; |
6653 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
6654 | 0 | dst_stride_argb = -dst_stride_argb; |
6655 | 0 | } |
6656 | 146 | #if defined(HAS_I444TOARGBROW_SSSE3) |
6657 | 146 | if (TestCpuFlag(kCpuHasSSSE3)) { |
6658 | 146 | I444ToARGBRow = I444ToARGBRow_Any_SSSE3; |
6659 | 146 | if (IS_ALIGNED(width, 8)) { |
6660 | 7 | I444ToARGBRow = I444ToARGBRow_SSSE3; |
6661 | 7 | } |
6662 | 146 | } |
6663 | 146 | #endif |
6664 | 146 | #if defined(HAS_I444TOARGBROW_AVX2) |
6665 | 146 | if (TestCpuFlag(kCpuHasAVX2)) { |
6666 | 146 | I444ToARGBRow = I444ToARGBRow_Any_AVX2; |
6667 | 146 | if (IS_ALIGNED(width, 16)) { |
6668 | 4 | I444ToARGBRow = I444ToARGBRow_AVX2; |
6669 | 4 | } |
6670 | 146 | } |
6671 | 146 | #endif |
6672 | | #if defined(HAS_I444TOARGBROW_NEON) |
6673 | | if (TestCpuFlag(kCpuHasNEON)) { |
6674 | | I444ToARGBRow = I444ToARGBRow_Any_NEON; |
6675 | | if (IS_ALIGNED(width, 8)) { |
6676 | | I444ToARGBRow = I444ToARGBRow_NEON; |
6677 | | } |
6678 | | } |
6679 | | #endif |
6680 | | #if defined(HAS_I444TOARGBROW_SVE2) |
6681 | | if (TestCpuFlag(kCpuHasSVE2)) { |
6682 | | I444ToARGBRow = I444ToARGBRow_SVE2; |
6683 | | } |
6684 | | #endif |
6685 | | #if defined(HAS_I444TOARGBROW_SME) |
6686 | | if (TestCpuFlag(kCpuHasSME)) { |
6687 | | I444ToARGBRow = I444ToARGBRow_SME; |
6688 | | } |
6689 | | #endif |
6690 | | #if defined(HAS_I444TOARGBROW_LASX) |
6691 | | if (TestCpuFlag(kCpuHasLASX)) { |
6692 | | I444ToARGBRow = I444ToARGBRow_Any_LASX; |
6693 | | if (IS_ALIGNED(width, 32)) { |
6694 | | I444ToARGBRow = I444ToARGBRow_LASX; |
6695 | | } |
6696 | | } |
6697 | | #endif |
6698 | | #if defined(HAS_I444TOARGBROW_RVV) |
6699 | | if (TestCpuFlag(kCpuHasRVV)) { |
6700 | | I444ToARGBRow = I444ToARGBRow_RVV; |
6701 | | } |
6702 | | #endif |
6703 | | |
6704 | 146 | #if defined(HAS_SCALEROWUP2_BILINEAR_SSE2) |
6705 | 146 | if (TestCpuFlag(kCpuHasSSE2)) { |
6706 | 146 | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSE2; |
6707 | 146 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2; |
6708 | 146 | } |
6709 | 146 | #endif |
6710 | | |
6711 | 146 | #if defined(HAS_SCALEROWUP2_BILINEAR_SSSE3) |
6712 | 146 | if (TestCpuFlag(kCpuHasSSSE3)) { |
6713 | 146 | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSSE3; |
6714 | 146 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3; |
6715 | 146 | } |
6716 | 146 | #endif |
6717 | | |
6718 | 146 | #if defined(HAS_SCALEROWUP2_BILINEAR_AVX2) |
6719 | 146 | if (TestCpuFlag(kCpuHasAVX2)) { |
6720 | 146 | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_AVX2; |
6721 | 146 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2; |
6722 | 146 | } |
6723 | 146 | #endif |
6724 | | |
6725 | | #if defined(HAS_SCALEROWUP2_BILINEAR_NEON) |
6726 | | if (TestCpuFlag(kCpuHasNEON)) { |
6727 | | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_NEON; |
6728 | | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON; |
6729 | | } |
6730 | | #endif |
6731 | | #if defined(HAS_SCALEROWUP2_BILINEAR_RVV) |
6732 | | if (TestCpuFlag(kCpuHasRVV)) { |
6733 | | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_RVV; |
6734 | | ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV; |
6735 | | } |
6736 | | #endif |
6737 | | |
6738 | | // alloc 4 lines temp |
6739 | 146 | const int row_size = (width + 31) & ~31; |
6740 | 146 | align_buffer_64(row, row_size * 4); |
6741 | 146 | uint8_t* temp_u_1 = row; |
6742 | 146 | uint8_t* temp_u_2 = row + row_size; |
6743 | 146 | uint8_t* temp_v_1 = row + row_size * 2; |
6744 | 146 | uint8_t* temp_v_2 = row + row_size * 3; |
6745 | 146 | if (!row) |
6746 | 0 | return 1; |
6747 | | |
6748 | 146 | ScaleRowUp2_Linear(src_u, temp_u_1, width); |
6749 | 146 | ScaleRowUp2_Linear(src_v, temp_v_1, width); |
6750 | 146 | I444ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width); |
6751 | 146 | dst_argb += dst_stride_argb; |
6752 | 146 | src_y += src_stride_y; |
6753 | | |
6754 | 2.44k | for (y = 0; y < height - 2; y += 2) { |
6755 | 2.30k | Scale2RowUp_Bilinear(src_u, src_stride_u, temp_u_1, row_size, width); |
6756 | 2.30k | Scale2RowUp_Bilinear(src_v, src_stride_v, temp_v_1, row_size, width); |
6757 | 2.30k | I444ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width); |
6758 | 2.30k | dst_argb += dst_stride_argb; |
6759 | 2.30k | src_y += src_stride_y; |
6760 | 2.30k | I444ToARGBRow(src_y, temp_u_2, temp_v_2, dst_argb, yuvconstants, width); |
6761 | 2.30k | dst_argb += dst_stride_argb; |
6762 | 2.30k | src_y += src_stride_y; |
6763 | 2.30k | src_u += src_stride_u; |
6764 | 2.30k | src_v += src_stride_v; |
6765 | 2.30k | } |
6766 | | |
6767 | 146 | if (!(height & 1)) { |
6768 | 38 | ScaleRowUp2_Linear(src_u, temp_u_1, width); |
6769 | 38 | ScaleRowUp2_Linear(src_v, temp_v_1, width); |
6770 | 38 | I444ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width); |
6771 | 38 | } |
6772 | | |
6773 | 146 | free_aligned_buffer_64(row); |
6774 | 146 | return 0; |
6775 | 146 | } |
6776 | | |
6777 | | static int I422ToARGBMatrixLinear(const uint8_t* src_y, |
6778 | | int src_stride_y, |
6779 | | const uint8_t* src_u, |
6780 | | int src_stride_u, |
6781 | | const uint8_t* src_v, |
6782 | | int src_stride_v, |
6783 | | uint8_t* dst_argb, |
6784 | | int dst_stride_argb, |
6785 | | const struct YuvConstants* yuvconstants, |
6786 | | int width, |
6787 | 107 | int height) { |
6788 | 107 | int y; |
6789 | 107 | void (*I444ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, |
6790 | 107 | const uint8_t* v_buf, uint8_t* rgb_buf, |
6791 | 107 | const struct YuvConstants* yuvconstants, int width) = |
6792 | 107 | I444ToARGBRow_C; |
6793 | 107 | void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, |
6794 | 107 | int dst_width) = ScaleRowUp2_Linear_Any_C; |
6795 | 107 | assert(yuvconstants); |
6796 | 107 | if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || |
6797 | 107 | height == INT_MIN) { |
6798 | 0 | return -1; |
6799 | 0 | } |
6800 | | // Negative height means invert the image. |
6801 | 107 | if (height < 0) { |
6802 | 0 | height = -height; |
6803 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
6804 | 0 | dst_stride_argb = -dst_stride_argb; |
6805 | 0 | } |
6806 | 107 | #if defined(HAS_I444TOARGBROW_SSSE3) |
6807 | 107 | if (TestCpuFlag(kCpuHasSSSE3)) { |
6808 | 107 | I444ToARGBRow = I444ToARGBRow_Any_SSSE3; |
6809 | 107 | if (IS_ALIGNED(width, 8)) { |
6810 | 42 | I444ToARGBRow = I444ToARGBRow_SSSE3; |
6811 | 42 | } |
6812 | 107 | } |
6813 | 107 | #endif |
6814 | 107 | #if defined(HAS_I444TOARGBROW_AVX2) |
6815 | 107 | if (TestCpuFlag(kCpuHasAVX2)) { |
6816 | 107 | I444ToARGBRow = I444ToARGBRow_Any_AVX2; |
6817 | 107 | if (IS_ALIGNED(width, 16)) { |
6818 | 17 | I444ToARGBRow = I444ToARGBRow_AVX2; |
6819 | 17 | } |
6820 | 107 | } |
6821 | 107 | #endif |
6822 | | #if defined(HAS_I444TOARGBROW_NEON) |
6823 | | if (TestCpuFlag(kCpuHasNEON)) { |
6824 | | I444ToARGBRow = I444ToARGBRow_Any_NEON; |
6825 | | if (IS_ALIGNED(width, 8)) { |
6826 | | I444ToARGBRow = I444ToARGBRow_NEON; |
6827 | | } |
6828 | | } |
6829 | | #endif |
6830 | | #if defined(HAS_I444TOARGBROW_SVE2) |
6831 | | if (TestCpuFlag(kCpuHasSVE2)) { |
6832 | | I444ToARGBRow = I444ToARGBRow_SVE2; |
6833 | | } |
6834 | | #endif |
6835 | | #if defined(HAS_I444TOARGBROW_SME) |
6836 | | if (TestCpuFlag(kCpuHasSME)) { |
6837 | | I444ToARGBRow = I444ToARGBRow_SME; |
6838 | | } |
6839 | | #endif |
6840 | | #if defined(HAS_I444TOARGBROW_LASX) |
6841 | | if (TestCpuFlag(kCpuHasLASX)) { |
6842 | | I444ToARGBRow = I444ToARGBRow_Any_LASX; |
6843 | | if (IS_ALIGNED(width, 32)) { |
6844 | | I444ToARGBRow = I444ToARGBRow_LASX; |
6845 | | } |
6846 | | } |
6847 | | #endif |
6848 | | #if defined(HAS_I444TOARGBROW_RVV) |
6849 | | if (TestCpuFlag(kCpuHasRVV)) { |
6850 | | I444ToARGBRow = I444ToARGBRow_RVV; |
6851 | | } |
6852 | | #endif |
6853 | 107 | #if defined(HAS_SCALEROWUP2_LINEAR_SSE2) |
6854 | 107 | if (TestCpuFlag(kCpuHasSSE2)) { |
6855 | 107 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2; |
6856 | 107 | } |
6857 | 107 | #endif |
6858 | 107 | #if defined(HAS_SCALEROWUP2_LINEAR_SSSE3) |
6859 | 107 | if (TestCpuFlag(kCpuHasSSSE3)) { |
6860 | 107 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3; |
6861 | 107 | } |
6862 | 107 | #endif |
6863 | 107 | #if defined(HAS_SCALEROWUP2_LINEAR_AVX2) |
6864 | 107 | if (TestCpuFlag(kCpuHasAVX2)) { |
6865 | 107 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2; |
6866 | 107 | } |
6867 | 107 | #endif |
6868 | | #if defined(HAS_SCALEROWUP2_LINEAR_NEON) |
6869 | | if (TestCpuFlag(kCpuHasNEON)) { |
6870 | | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON; |
6871 | | } |
6872 | | #endif |
6873 | | #if defined(HAS_SCALEROWUP2_LINEAR_RVV) |
6874 | | if (TestCpuFlag(kCpuHasRVV)) { |
6875 | | ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV; |
6876 | | } |
6877 | | #endif |
6878 | | |
6879 | | // alloc 2 lines temp |
6880 | 107 | const int row_size = (width + 31) & ~31; |
6881 | 107 | align_buffer_64(row, row_size * 2); |
6882 | 107 | uint8_t* temp_u = row; |
6883 | 107 | uint8_t* temp_v = row + row_size; |
6884 | 107 | if (!row) |
6885 | 0 | return 1; |
6886 | | |
6887 | 4.76k | for (y = 0; y < height; ++y) { |
6888 | 4.66k | ScaleRowUp2_Linear(src_u, temp_u, width); |
6889 | 4.66k | ScaleRowUp2_Linear(src_v, temp_v, width); |
6890 | 4.66k | I444ToARGBRow(src_y, temp_u, temp_v, dst_argb, yuvconstants, width); |
6891 | 4.66k | dst_argb += dst_stride_argb; |
6892 | 4.66k | src_y += src_stride_y; |
6893 | 4.66k | src_u += src_stride_u; |
6894 | 4.66k | src_v += src_stride_v; |
6895 | 4.66k | } |
6896 | | |
6897 | 107 | free_aligned_buffer_64(row); |
6898 | 107 | return 0; |
6899 | 107 | } |
6900 | | |
6901 | | static int I420ToRGB24MatrixBilinear(const uint8_t* src_y, |
6902 | | int src_stride_y, |
6903 | | const uint8_t* src_u, |
6904 | | int src_stride_u, |
6905 | | const uint8_t* src_v, |
6906 | | int src_stride_v, |
6907 | | uint8_t* dst_rgb24, |
6908 | | int dst_stride_rgb24, |
6909 | | const struct YuvConstants* yuvconstants, |
6910 | | int width, |
6911 | 75 | int height) { |
6912 | 75 | int y; |
6913 | 75 | void (*I444ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf, |
6914 | 75 | const uint8_t* v_buf, uint8_t* rgb_buf, |
6915 | 75 | const struct YuvConstants* yuvconstants, int width) = |
6916 | 75 | I444ToRGB24Row_C; |
6917 | 75 | void (*Scale2RowUp_Bilinear)(const uint8_t* src_ptr, ptrdiff_t src_stride, |
6918 | 75 | uint8_t* dst_ptr, ptrdiff_t dst_stride, |
6919 | 75 | int dst_width) = ScaleRowUp2_Bilinear_Any_C; |
6920 | 75 | void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, |
6921 | 75 | int dst_width) = ScaleRowUp2_Linear_Any_C; |
6922 | 75 | assert(yuvconstants); |
6923 | 75 | if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || |
6924 | 75 | height == INT_MIN) { |
6925 | 0 | return -1; |
6926 | 0 | } |
6927 | | // Negative height means invert the image. |
6928 | 75 | if (height < 0) { |
6929 | 0 | height = -height; |
6930 | 0 | dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; |
6931 | 0 | dst_stride_rgb24 = -dst_stride_rgb24; |
6932 | 0 | } |
6933 | 75 | #if defined(HAS_I444TORGB24ROW_SSSE3) |
6934 | 75 | if (TestCpuFlag(kCpuHasSSSE3)) { |
6935 | 75 | I444ToRGB24Row = I444ToRGB24Row_Any_SSSE3; |
6936 | 75 | if (IS_ALIGNED(width, 16)) { |
6937 | 5 | I444ToRGB24Row = I444ToRGB24Row_SSSE3; |
6938 | 5 | } |
6939 | 75 | } |
6940 | 75 | #endif |
6941 | 75 | #if defined(HAS_I444TORGB24ROW_AVX2) |
6942 | 75 | if (TestCpuFlag(kCpuHasAVX2)) { |
6943 | 75 | I444ToRGB24Row = I444ToRGB24Row_Any_AVX2; |
6944 | 75 | if (IS_ALIGNED(width, 32)) { |
6945 | 4 | I444ToRGB24Row = I444ToRGB24Row_AVX2; |
6946 | 4 | } |
6947 | 75 | } |
6948 | 75 | #endif |
6949 | | #if defined(HAS_I444TORGB24ROW_NEON) |
6950 | | if (TestCpuFlag(kCpuHasNEON)) { |
6951 | | I444ToRGB24Row = I444ToRGB24Row_Any_NEON; |
6952 | | if (IS_ALIGNED(width, 8)) { |
6953 | | I444ToRGB24Row = I444ToRGB24Row_NEON; |
6954 | | } |
6955 | | } |
6956 | | #endif |
6957 | | #if defined(HAS_I444TORGB24ROW_SVE2) |
6958 | | if (TestCpuFlag(kCpuHasSVE2)) { |
6959 | | I444ToRGB24Row = I444ToRGB24Row_SVE2; |
6960 | | } |
6961 | | #endif |
6962 | | #if defined(HAS_I444TORGB24ROW_SME) |
6963 | | if (TestCpuFlag(kCpuHasSME)) { |
6964 | | I444ToRGB24Row = I444ToRGB24Row_SME; |
6965 | | } |
6966 | | #endif |
6967 | | #if defined(HAS_I444TORGB24ROW_LASX) |
6968 | | if (TestCpuFlag(kCpuHasLASX)) { |
6969 | | I444ToRGB24Row = I444ToRGB24Row_Any_LASX; |
6970 | | if (IS_ALIGNED(width, 32)) { |
6971 | | I444ToRGB24Row = I444ToRGB24Row_LASX; |
6972 | | } |
6973 | | } |
6974 | | #endif |
6975 | | #if defined(HAS_I444TORGB24ROW_RVV) |
6976 | | if (TestCpuFlag(kCpuHasRVV)) { |
6977 | | I444ToRGB24Row = I444ToRGB24Row_RVV; |
6978 | | } |
6979 | | #endif |
6980 | | |
6981 | 75 | #if defined(HAS_SCALEROWUP2_BILINEAR_SSE2) |
6982 | 75 | if (TestCpuFlag(kCpuHasSSE2)) { |
6983 | 75 | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSE2; |
6984 | 75 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2; |
6985 | 75 | } |
6986 | 75 | #endif |
6987 | | |
6988 | 75 | #if defined(HAS_SCALEROWUP2_BILINEAR_SSSE3) |
6989 | 75 | if (TestCpuFlag(kCpuHasSSSE3)) { |
6990 | 75 | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSSE3; |
6991 | 75 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3; |
6992 | 75 | } |
6993 | 75 | #endif |
6994 | | |
6995 | 75 | #if defined(HAS_SCALEROWUP2_BILINEAR_AVX2) |
6996 | 75 | if (TestCpuFlag(kCpuHasAVX2)) { |
6997 | 75 | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_AVX2; |
6998 | 75 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2; |
6999 | 75 | } |
7000 | 75 | #endif |
7001 | | |
7002 | | #if defined(HAS_SCALEROWUP2_BILINEAR_NEON) |
7003 | | if (TestCpuFlag(kCpuHasNEON)) { |
7004 | | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_NEON; |
7005 | | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON; |
7006 | | } |
7007 | | #endif |
7008 | | #if defined(HAS_SCALEROWUP2_BILINEAR_RVV) |
7009 | | if (TestCpuFlag(kCpuHasRVV)) { |
7010 | | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_RVV; |
7011 | | ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV; |
7012 | | } |
7013 | | #endif |
7014 | | |
7015 | | // alloc 4 lines temp |
7016 | 75 | const int row_size = (width + 31) & ~31; |
7017 | 75 | align_buffer_64(row, row_size * 4); |
7018 | 75 | uint8_t* temp_u_1 = row; |
7019 | 75 | uint8_t* temp_u_2 = row + row_size; |
7020 | 75 | uint8_t* temp_v_1 = row + row_size * 2; |
7021 | 75 | uint8_t* temp_v_2 = row + row_size * 3; |
7022 | 75 | if (!row) |
7023 | 0 | return 1; |
7024 | | |
7025 | 75 | ScaleRowUp2_Linear(src_u, temp_u_1, width); |
7026 | 75 | ScaleRowUp2_Linear(src_v, temp_v_1, width); |
7027 | 75 | I444ToRGB24Row(src_y, temp_u_1, temp_v_1, dst_rgb24, yuvconstants, width); |
7028 | 75 | dst_rgb24 += dst_stride_rgb24; |
7029 | 75 | src_y += src_stride_y; |
7030 | | |
7031 | 1.30k | for (y = 0; y < height - 2; y += 2) { |
7032 | 1.23k | Scale2RowUp_Bilinear(src_u, src_stride_u, temp_u_1, row_size, width); |
7033 | 1.23k | Scale2RowUp_Bilinear(src_v, src_stride_v, temp_v_1, row_size, width); |
7034 | 1.23k | I444ToRGB24Row(src_y, temp_u_1, temp_v_1, dst_rgb24, yuvconstants, width); |
7035 | 1.23k | dst_rgb24 += dst_stride_rgb24; |
7036 | 1.23k | src_y += src_stride_y; |
7037 | 1.23k | I444ToRGB24Row(src_y, temp_u_2, temp_v_2, dst_rgb24, yuvconstants, width); |
7038 | 1.23k | dst_rgb24 += dst_stride_rgb24; |
7039 | 1.23k | src_y += src_stride_y; |
7040 | 1.23k | src_u += src_stride_u; |
7041 | 1.23k | src_v += src_stride_v; |
7042 | 1.23k | } |
7043 | | |
7044 | 75 | if (!(height & 1)) { |
7045 | 22 | ScaleRowUp2_Linear(src_u, temp_u_1, width); |
7046 | 22 | ScaleRowUp2_Linear(src_v, temp_v_1, width); |
7047 | 22 | I444ToRGB24Row(src_y, temp_u_1, temp_v_1, dst_rgb24, yuvconstants, width); |
7048 | 22 | } |
7049 | | |
7050 | 75 | free_aligned_buffer_64(row); |
7051 | 75 | return 0; |
7052 | 75 | } |
7053 | | |
7054 | | static int I010ToAR30MatrixBilinear(const uint16_t* src_y, |
7055 | | int src_stride_y, |
7056 | | const uint16_t* src_u, |
7057 | | int src_stride_u, |
7058 | | const uint16_t* src_v, |
7059 | | int src_stride_v, |
7060 | | uint8_t* dst_ar30, |
7061 | | int dst_stride_ar30, |
7062 | | const struct YuvConstants* yuvconstants, |
7063 | | int width, |
7064 | 0 | int height) { |
7065 | 0 | int y; |
7066 | 0 | void (*I410ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf, |
7067 | 0 | const uint16_t* v_buf, uint8_t* rgb_buf, |
7068 | 0 | const struct YuvConstants* yuvconstants, int width) = |
7069 | 0 | I410ToAR30Row_C; |
7070 | 0 | void (*Scale2RowUp_Bilinear_12)( |
7071 | 0 | const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, |
7072 | 0 | ptrdiff_t dst_stride, int dst_width) = ScaleRowUp2_Bilinear_16_Any_C; |
7073 | 0 | void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, |
7074 | 0 | int dst_width) = ScaleRowUp2_Linear_16_Any_C; |
7075 | 0 | assert(yuvconstants); |
7076 | 0 | if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || |
7077 | 0 | height == INT_MIN) { |
7078 | 0 | return -1; |
7079 | 0 | } |
7080 | | // Negative height means invert the image. |
7081 | 0 | if (height < 0) { |
7082 | 0 | height = -height; |
7083 | 0 | dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; |
7084 | 0 | dst_stride_ar30 = -dst_stride_ar30; |
7085 | 0 | } |
7086 | | #if defined(HAS_I410TOAR30ROW_NEON) |
7087 | | if (TestCpuFlag(kCpuHasNEON)) { |
7088 | | I410ToAR30Row = I410ToAR30Row_Any_NEON; |
7089 | | if (IS_ALIGNED(width, 8)) { |
7090 | | I410ToAR30Row = I410ToAR30Row_NEON; |
7091 | | } |
7092 | | } |
7093 | | #endif |
7094 | | #if defined(HAS_I410TOAR30ROW_SVE2) |
7095 | | if (TestCpuFlag(kCpuHasSVE2)) { |
7096 | | I410ToAR30Row = I410ToAR30Row_SVE2; |
7097 | | } |
7098 | | #endif |
7099 | | #if defined(HAS_I410TOAR30ROW_SME) |
7100 | | if (TestCpuFlag(kCpuHasSME)) { |
7101 | | I410ToAR30Row = I410ToAR30Row_SME; |
7102 | | } |
7103 | | #endif |
7104 | 0 | #if defined(HAS_I410TOAR30ROW_SSSE3) |
7105 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7106 | 0 | I410ToAR30Row = I410ToAR30Row_Any_SSSE3; |
7107 | 0 | if (IS_ALIGNED(width, 8)) { |
7108 | 0 | I410ToAR30Row = I410ToAR30Row_SSSE3; |
7109 | 0 | } |
7110 | 0 | } |
7111 | 0 | #endif |
7112 | 0 | #if defined(HAS_I410TOAR30ROW_AVX2) |
7113 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
7114 | 0 | I410ToAR30Row = I410ToAR30Row_Any_AVX2; |
7115 | 0 | if (IS_ALIGNED(width, 16)) { |
7116 | 0 | I410ToAR30Row = I410ToAR30Row_AVX2; |
7117 | 0 | } |
7118 | 0 | } |
7119 | 0 | #endif |
7120 | |
|
7121 | 0 | #if defined(HAS_SCALEROWUP2_BILINEAR_12_SSSE3) |
7122 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7123 | 0 | Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_SSSE3; |
7124 | 0 | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3; |
7125 | 0 | } |
7126 | 0 | #endif |
7127 | |
|
7128 | 0 | #if defined(HAS_SCALEROWUP2_BILINEAR_12_AVX2) |
7129 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
7130 | 0 | Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_AVX2; |
7131 | 0 | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2; |
7132 | 0 | } |
7133 | 0 | #endif |
7134 | |
|
7135 | | #if defined(HAS_SCALEROWUP2_BILINEAR_12_NEON) |
7136 | | if (TestCpuFlag(kCpuHasNEON)) { |
7137 | | Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_NEON; |
7138 | | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON; |
7139 | | } |
7140 | | #endif |
7141 | | |
7142 | | // alloc 4 lines temp |
7143 | 0 | const int row_size = (width + 31) & ~31; |
7144 | 0 | align_buffer_64(row, row_size * 4 * sizeof(uint16_t)); |
7145 | 0 | uint16_t* temp_u_1 = (uint16_t*)(row); |
7146 | 0 | uint16_t* temp_u_2 = (uint16_t*)(row) + row_size; |
7147 | 0 | uint16_t* temp_v_1 = (uint16_t*)(row) + row_size * 2; |
7148 | 0 | uint16_t* temp_v_2 = (uint16_t*)(row) + row_size * 3; |
7149 | 0 | if (!row) |
7150 | 0 | return 1; |
7151 | | |
7152 | 0 | ScaleRowUp2_Linear_12(src_u, temp_u_1, width); |
7153 | 0 | ScaleRowUp2_Linear_12(src_v, temp_v_1, width); |
7154 | 0 | I410ToAR30Row(src_y, temp_u_1, temp_v_1, dst_ar30, yuvconstants, width); |
7155 | 0 | dst_ar30 += dst_stride_ar30; |
7156 | 0 | src_y += src_stride_y; |
7157 | |
|
7158 | 0 | for (y = 0; y < height - 2; y += 2) { |
7159 | 0 | Scale2RowUp_Bilinear_12(src_u, src_stride_u, temp_u_1, row_size, width); |
7160 | 0 | Scale2RowUp_Bilinear_12(src_v, src_stride_v, temp_v_1, row_size, width); |
7161 | 0 | I410ToAR30Row(src_y, temp_u_1, temp_v_1, dst_ar30, yuvconstants, width); |
7162 | 0 | dst_ar30 += dst_stride_ar30; |
7163 | 0 | src_y += src_stride_y; |
7164 | 0 | I410ToAR30Row(src_y, temp_u_2, temp_v_2, dst_ar30, yuvconstants, width); |
7165 | 0 | dst_ar30 += dst_stride_ar30; |
7166 | 0 | src_y += src_stride_y; |
7167 | 0 | src_u += src_stride_u; |
7168 | 0 | src_v += src_stride_v; |
7169 | 0 | } |
7170 | |
|
7171 | 0 | if (!(height & 1)) { |
7172 | 0 | ScaleRowUp2_Linear_12(src_u, temp_u_1, width); |
7173 | 0 | ScaleRowUp2_Linear_12(src_v, temp_v_1, width); |
7174 | 0 | I410ToAR30Row(src_y, temp_u_1, temp_v_1, dst_ar30, yuvconstants, width); |
7175 | 0 | } |
7176 | |
|
7177 | 0 | free_aligned_buffer_64(row); |
7178 | |
|
7179 | 0 | return 0; |
7180 | 0 | } |
7181 | | |
7182 | | static int I210ToAR30MatrixLinear(const uint16_t* src_y, |
7183 | | int src_stride_y, |
7184 | | const uint16_t* src_u, |
7185 | | int src_stride_u, |
7186 | | const uint16_t* src_v, |
7187 | | int src_stride_v, |
7188 | | uint8_t* dst_ar30, |
7189 | | int dst_stride_ar30, |
7190 | | const struct YuvConstants* yuvconstants, |
7191 | | int width, |
7192 | 0 | int height) { |
7193 | 0 | int y; |
7194 | 0 | void (*I410ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf, |
7195 | 0 | const uint16_t* v_buf, uint8_t* rgb_buf, |
7196 | 0 | const struct YuvConstants* yuvconstants, int width) = |
7197 | 0 | I410ToAR30Row_C; |
7198 | 0 | void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, |
7199 | 0 | int dst_width) = ScaleRowUp2_Linear_16_Any_C; |
7200 | 0 | assert(yuvconstants); |
7201 | 0 | if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || |
7202 | 0 | height == INT_MIN) { |
7203 | 0 | return -1; |
7204 | 0 | } |
7205 | | // Negative height means invert the image. |
7206 | 0 | if (height < 0) { |
7207 | 0 | height = -height; |
7208 | 0 | dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; |
7209 | 0 | dst_stride_ar30 = -dst_stride_ar30; |
7210 | 0 | } |
7211 | | #if defined(HAS_I410TOAR30ROW_NEON) |
7212 | | if (TestCpuFlag(kCpuHasNEON)) { |
7213 | | I410ToAR30Row = I410ToAR30Row_Any_NEON; |
7214 | | if (IS_ALIGNED(width, 8)) { |
7215 | | I410ToAR30Row = I410ToAR30Row_NEON; |
7216 | | } |
7217 | | } |
7218 | | #endif |
7219 | | #if defined(HAS_I410TOAR30ROW_SVE2) |
7220 | | if (TestCpuFlag(kCpuHasSVE2)) { |
7221 | | I410ToAR30Row = I410ToAR30Row_SVE2; |
7222 | | } |
7223 | | #endif |
7224 | | #if defined(HAS_I410TOAR30ROW_SME) |
7225 | | if (TestCpuFlag(kCpuHasSME)) { |
7226 | | I410ToAR30Row = I410ToAR30Row_SME; |
7227 | | } |
7228 | | #endif |
7229 | 0 | #if defined(HAS_I410TOAR30ROW_SSSE3) |
7230 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7231 | 0 | I410ToAR30Row = I410ToAR30Row_Any_SSSE3; |
7232 | 0 | if (IS_ALIGNED(width, 8)) { |
7233 | 0 | I410ToAR30Row = I410ToAR30Row_SSSE3; |
7234 | 0 | } |
7235 | 0 | } |
7236 | 0 | #endif |
7237 | 0 | #if defined(HAS_I410TOAR30ROW_AVX2) |
7238 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
7239 | 0 | I410ToAR30Row = I410ToAR30Row_Any_AVX2; |
7240 | 0 | if (IS_ALIGNED(width, 16)) { |
7241 | 0 | I410ToAR30Row = I410ToAR30Row_AVX2; |
7242 | 0 | } |
7243 | 0 | } |
7244 | 0 | #endif |
7245 | |
|
7246 | 0 | #if defined(HAS_SCALEROWUP2_LINEAR_12_SSSE3) |
7247 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7248 | 0 | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3; |
7249 | 0 | } |
7250 | 0 | #endif |
7251 | 0 | #if defined(HAS_SCALEROWUP2_LINEAR_12_AVX2) |
7252 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
7253 | 0 | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2; |
7254 | 0 | } |
7255 | 0 | #endif |
7256 | | #if defined(HAS_SCALEROWUP2_LINEAR_12_NEON) |
7257 | | if (TestCpuFlag(kCpuHasNEON)) { |
7258 | | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON; |
7259 | | } |
7260 | | #endif |
7261 | | |
7262 | | // alloc 2 lines temp |
7263 | 0 | const int row_size = (width + 31) & ~31; |
7264 | 0 | align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); |
7265 | 0 | uint16_t* temp_u = (uint16_t*)(row); |
7266 | 0 | uint16_t* temp_v = (uint16_t*)(row) + row_size; |
7267 | 0 | if (!row) |
7268 | 0 | return 1; |
7269 | | |
7270 | 0 | for (y = 0; y < height; ++y) { |
7271 | 0 | ScaleRowUp2_Linear_12(src_u, temp_u, width); |
7272 | 0 | ScaleRowUp2_Linear_12(src_v, temp_v, width); |
7273 | 0 | I410ToAR30Row(src_y, temp_u, temp_v, dst_ar30, yuvconstants, width); |
7274 | 0 | dst_ar30 += dst_stride_ar30; |
7275 | 0 | src_y += src_stride_y; |
7276 | 0 | src_u += src_stride_u; |
7277 | 0 | src_v += src_stride_v; |
7278 | 0 | } |
7279 | 0 | free_aligned_buffer_64(row); |
7280 | 0 | return 0; |
7281 | 0 | } |
7282 | | |
7283 | | static int I010ToARGBMatrixBilinear(const uint16_t* src_y, |
7284 | | int src_stride_y, |
7285 | | const uint16_t* src_u, |
7286 | | int src_stride_u, |
7287 | | const uint16_t* src_v, |
7288 | | int src_stride_v, |
7289 | | uint8_t* dst_argb, |
7290 | | int dst_stride_argb, |
7291 | | const struct YuvConstants* yuvconstants, |
7292 | | int width, |
7293 | 86 | int height) { |
7294 | 86 | int y; |
7295 | 86 | void (*I410ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, |
7296 | 86 | const uint16_t* v_buf, uint8_t* rgb_buf, |
7297 | 86 | const struct YuvConstants* yuvconstants, int width) = |
7298 | 86 | I410ToARGBRow_C; |
7299 | 86 | void (*Scale2RowUp_Bilinear_12)( |
7300 | 86 | const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, |
7301 | 86 | ptrdiff_t dst_stride, int dst_width) = ScaleRowUp2_Bilinear_16_Any_C; |
7302 | 86 | void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, |
7303 | 86 | int dst_width) = ScaleRowUp2_Linear_16_Any_C; |
7304 | 86 | assert(yuvconstants); |
7305 | 86 | if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || |
7306 | 86 | height == INT_MIN) { |
7307 | 0 | return -1; |
7308 | 0 | } |
7309 | | // Negative height means invert the image. |
7310 | 86 | if (height < 0) { |
7311 | 0 | height = -height; |
7312 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
7313 | 0 | dst_stride_argb = -dst_stride_argb; |
7314 | 0 | } |
7315 | 86 | #if defined(HAS_I410TOARGBROW_SSSE3) |
7316 | 86 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7317 | 86 | I410ToARGBRow = I410ToARGBRow_Any_SSSE3; |
7318 | 86 | if (IS_ALIGNED(width, 8)) { |
7319 | 5 | I410ToARGBRow = I410ToARGBRow_SSSE3; |
7320 | 5 | } |
7321 | 86 | } |
7322 | 86 | #endif |
7323 | | #if defined(HAS_I410TOARGBROW_NEON) |
7324 | | if (TestCpuFlag(kCpuHasNEON)) { |
7325 | | I410ToARGBRow = I410ToARGBRow_Any_NEON; |
7326 | | if (IS_ALIGNED(width, 8)) { |
7327 | | I410ToARGBRow = I410ToARGBRow_NEON; |
7328 | | } |
7329 | | } |
7330 | | #endif |
7331 | | #if defined(HAS_I410TOARGBROW_SVE2) |
7332 | | if (TestCpuFlag(kCpuHasSVE2)) { |
7333 | | I410ToARGBRow = I410ToARGBRow_SVE2; |
7334 | | } |
7335 | | #endif |
7336 | | #if defined(HAS_I410TOARGBROW_SME) |
7337 | | if (TestCpuFlag(kCpuHasSME)) { |
7338 | | I410ToARGBRow = I410ToARGBRow_SME; |
7339 | | } |
7340 | | #endif |
7341 | 86 | #if defined(HAS_I410TOARGBROW_AVX2) |
7342 | 86 | if (TestCpuFlag(kCpuHasAVX2)) { |
7343 | 86 | I410ToARGBRow = I410ToARGBRow_Any_AVX2; |
7344 | 86 | if (IS_ALIGNED(width, 16)) { |
7345 | 2 | I410ToARGBRow = I410ToARGBRow_AVX2; |
7346 | 2 | } |
7347 | 86 | } |
7348 | 86 | #endif |
7349 | | |
7350 | 86 | #if defined(HAS_SCALEROWUP2_BILINEAR_12_SSSE3) |
7351 | 86 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7352 | 86 | Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_SSSE3; |
7353 | 86 | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3; |
7354 | 86 | } |
7355 | 86 | #endif |
7356 | | |
7357 | 86 | #if defined(HAS_SCALEROWUP2_BILINEAR_12_AVX2) |
7358 | 86 | if (TestCpuFlag(kCpuHasAVX2)) { |
7359 | 86 | Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_AVX2; |
7360 | 86 | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2; |
7361 | 86 | } |
7362 | 86 | #endif |
7363 | | |
7364 | | #if defined(HAS_SCALEROWUP2_BILINEAR_12_NEON) |
7365 | | if (TestCpuFlag(kCpuHasNEON)) { |
7366 | | Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_NEON; |
7367 | | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON; |
7368 | | } |
7369 | | #endif |
7370 | | |
7371 | | // alloc 4 lines temp |
7372 | 86 | const int row_size = (width + 31) & ~31; |
7373 | 86 | align_buffer_64(row, row_size * 4 * sizeof(uint16_t)); |
7374 | 86 | uint16_t* temp_u_1 = (uint16_t*)(row); |
7375 | 86 | uint16_t* temp_u_2 = (uint16_t*)(row) + row_size; |
7376 | 86 | uint16_t* temp_v_1 = (uint16_t*)(row) + row_size * 2; |
7377 | 86 | uint16_t* temp_v_2 = (uint16_t*)(row) + row_size * 3; |
7378 | 86 | if (!row) |
7379 | 0 | return 1; |
7380 | | |
7381 | 86 | ScaleRowUp2_Linear_12(src_u, temp_u_1, width); |
7382 | 86 | ScaleRowUp2_Linear_12(src_v, temp_v_1, width); |
7383 | 86 | I410ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width); |
7384 | 86 | dst_argb += dst_stride_argb; |
7385 | 86 | src_y += src_stride_y; |
7386 | | |
7387 | 1.28k | for (y = 0; y < height - 2; y += 2) { |
7388 | 1.20k | Scale2RowUp_Bilinear_12(src_u, src_stride_u, temp_u_1, row_size, width); |
7389 | 1.20k | Scale2RowUp_Bilinear_12(src_v, src_stride_v, temp_v_1, row_size, width); |
7390 | 1.20k | I410ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width); |
7391 | 1.20k | dst_argb += dst_stride_argb; |
7392 | 1.20k | src_y += src_stride_y; |
7393 | 1.20k | I410ToARGBRow(src_y, temp_u_2, temp_v_2, dst_argb, yuvconstants, width); |
7394 | 1.20k | dst_argb += dst_stride_argb; |
7395 | 1.20k | src_y += src_stride_y; |
7396 | 1.20k | src_u += src_stride_u; |
7397 | 1.20k | src_v += src_stride_v; |
7398 | 1.20k | } |
7399 | | |
7400 | 86 | if (!(height & 1)) { |
7401 | 23 | ScaleRowUp2_Linear_12(src_u, temp_u_1, width); |
7402 | 23 | ScaleRowUp2_Linear_12(src_v, temp_v_1, width); |
7403 | 23 | I410ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width); |
7404 | 23 | } |
7405 | | |
7406 | 86 | free_aligned_buffer_64(row); |
7407 | 86 | return 0; |
7408 | 86 | } |
7409 | | |
7410 | | static int I210ToARGBMatrixLinear(const uint16_t* src_y, |
7411 | | int src_stride_y, |
7412 | | const uint16_t* src_u, |
7413 | | int src_stride_u, |
7414 | | const uint16_t* src_v, |
7415 | | int src_stride_v, |
7416 | | uint8_t* dst_argb, |
7417 | | int dst_stride_argb, |
7418 | | const struct YuvConstants* yuvconstants, |
7419 | | int width, |
7420 | 104 | int height) { |
7421 | 104 | int y; |
7422 | 104 | void (*I410ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, |
7423 | 104 | const uint16_t* v_buf, uint8_t* rgb_buf, |
7424 | 104 | const struct YuvConstants* yuvconstants, int width) = |
7425 | 104 | I410ToARGBRow_C; |
7426 | 104 | void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, |
7427 | 104 | int dst_width) = ScaleRowUp2_Linear_16_Any_C; |
7428 | 104 | assert(yuvconstants); |
7429 | 105 | if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || |
7430 | 105 | height == INT_MIN) { |
7431 | 0 | return -1; |
7432 | 0 | } |
7433 | | // Negative height means invert the image. |
7434 | 104 | if (height < 0) { |
7435 | 0 | height = -height; |
7436 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
7437 | 0 | dst_stride_argb = -dst_stride_argb; |
7438 | 0 | } |
7439 | 104 | #if defined(HAS_I410TOARGBROW_SSSE3) |
7440 | 105 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7441 | 105 | I410ToARGBRow = I410ToARGBRow_Any_SSSE3; |
7442 | 105 | if (IS_ALIGNED(width, 8)) { |
7443 | 34 | I410ToARGBRow = I410ToARGBRow_SSSE3; |
7444 | 34 | } |
7445 | 105 | } |
7446 | 104 | #endif |
7447 | | #if defined(HAS_I410TOARGBROW_NEON) |
7448 | | if (TestCpuFlag(kCpuHasNEON)) { |
7449 | | I410ToARGBRow = I410ToARGBRow_Any_NEON; |
7450 | | if (IS_ALIGNED(width, 8)) { |
7451 | | I410ToARGBRow = I410ToARGBRow_NEON; |
7452 | | } |
7453 | | } |
7454 | | #endif |
7455 | | #if defined(HAS_I410TOARGBROW_SVE2) |
7456 | | if (TestCpuFlag(kCpuHasSVE2)) { |
7457 | | I410ToARGBRow = I410ToARGBRow_SVE2; |
7458 | | } |
7459 | | #endif |
7460 | | #if defined(HAS_I410TOARGBROW_SME) |
7461 | | if (TestCpuFlag(kCpuHasSME)) { |
7462 | | I410ToARGBRow = I410ToARGBRow_SME; |
7463 | | } |
7464 | | #endif |
7465 | 104 | #if defined(HAS_I410TOARGBROW_AVX2) |
7466 | 105 | if (TestCpuFlag(kCpuHasAVX2)) { |
7467 | 105 | I410ToARGBRow = I410ToARGBRow_Any_AVX2; |
7468 | 105 | if (IS_ALIGNED(width, 16)) { |
7469 | 17 | I410ToARGBRow = I410ToARGBRow_AVX2; |
7470 | 17 | } |
7471 | 105 | } |
7472 | 104 | #endif |
7473 | | |
7474 | 104 | #if defined(HAS_SCALEROWUP2_LINEAR_12_SSSE3) |
7475 | 104 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7476 | 103 | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3; |
7477 | 103 | } |
7478 | 104 | #endif |
7479 | 104 | #if defined(HAS_SCALEROWUP2_LINEAR_12_AVX2) |
7480 | 104 | if (TestCpuFlag(kCpuHasAVX2)) { |
7481 | 103 | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2; |
7482 | 103 | } |
7483 | 104 | #endif |
7484 | | #if defined(HAS_SCALEROWUP2_LINEAR_12_NEON) |
7485 | | if (TestCpuFlag(kCpuHasNEON)) { |
7486 | | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON; |
7487 | | } |
7488 | | #endif |
7489 | | |
7490 | | // alloc 2 lines temp |
7491 | 104 | const int row_size = (width + 31) & ~31; |
7492 | 104 | align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); |
7493 | 104 | uint16_t* temp_u = (uint16_t*)(row); |
7494 | 104 | uint16_t* temp_v = (uint16_t*)(row) + row_size; |
7495 | 104 | if (!row) |
7496 | 0 | return 1; |
7497 | | |
7498 | 3.11k | for (y = 0; y < height; ++y) { |
7499 | 3.00k | ScaleRowUp2_Linear_12(src_u, temp_u, width); |
7500 | 3.00k | ScaleRowUp2_Linear_12(src_v, temp_v, width); |
7501 | 3.00k | I410ToARGBRow(src_y, temp_u, temp_v, dst_argb, yuvconstants, width); |
7502 | 3.00k | dst_argb += dst_stride_argb; |
7503 | 3.00k | src_y += src_stride_y; |
7504 | 3.00k | src_u += src_stride_u; |
7505 | 3.00k | src_v += src_stride_v; |
7506 | 3.00k | } |
7507 | | |
7508 | 104 | free_aligned_buffer_64(row); |
7509 | 104 | return 0; |
7510 | 104 | } |
7511 | | |
7512 | | static int I420AlphaToARGBMatrixBilinear( |
7513 | | const uint8_t* src_y, |
7514 | | int src_stride_y, |
7515 | | const uint8_t* src_u, |
7516 | | int src_stride_u, |
7517 | | const uint8_t* src_v, |
7518 | | int src_stride_v, |
7519 | | const uint8_t* src_a, |
7520 | | int src_stride_a, |
7521 | | uint8_t* dst_argb, |
7522 | | int dst_stride_argb, |
7523 | | const struct YuvConstants* yuvconstants, |
7524 | | int width, |
7525 | | int height, |
7526 | 53 | int attenuate) { |
7527 | 53 | int y; |
7528 | 53 | void (*I444AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, |
7529 | 53 | const uint8_t* v_buf, const uint8_t* a_buf, |
7530 | 53 | uint8_t* dst_argb, |
7531 | 53 | const struct YuvConstants* yuvconstants, |
7532 | 53 | int width) = I444AlphaToARGBRow_C; |
7533 | 53 | void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, |
7534 | 53 | int width) = ARGBAttenuateRow_C; |
7535 | 53 | void (*Scale2RowUp_Bilinear)(const uint8_t* src_ptr, ptrdiff_t src_stride, |
7536 | 53 | uint8_t* dst_ptr, ptrdiff_t dst_stride, |
7537 | 53 | int dst_width) = ScaleRowUp2_Bilinear_Any_C; |
7538 | 53 | void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, |
7539 | 53 | int dst_width) = ScaleRowUp2_Linear_Any_C; |
7540 | 53 | assert(yuvconstants); |
7541 | 53 | if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || |
7542 | 53 | height == 0 || height == INT_MIN) { |
7543 | 0 | return -1; |
7544 | 0 | } |
7545 | | // Negative height means invert the image. |
7546 | 53 | if (height < 0) { |
7547 | 0 | height = -height; |
7548 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
7549 | 0 | dst_stride_argb = -dst_stride_argb; |
7550 | 0 | } |
7551 | 53 | #if defined(HAS_I444ALPHATOARGBROW_SSSE3) |
7552 | 53 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7553 | 53 | I444AlphaToARGBRow = I444AlphaToARGBRow_Any_SSSE3; |
7554 | 53 | if (IS_ALIGNED(width, 8)) { |
7555 | 4 | I444AlphaToARGBRow = I444AlphaToARGBRow_SSSE3; |
7556 | 4 | } |
7557 | 53 | } |
7558 | 53 | #endif |
7559 | 53 | #if defined(HAS_I444ALPHATOARGBROW_AVX2) |
7560 | 53 | if (TestCpuFlag(kCpuHasAVX2)) { |
7561 | 53 | I444AlphaToARGBRow = I444AlphaToARGBRow_Any_AVX2; |
7562 | 53 | if (IS_ALIGNED(width, 16)) { |
7563 | 3 | I444AlphaToARGBRow = I444AlphaToARGBRow_AVX2; |
7564 | 3 | } |
7565 | 53 | } |
7566 | 53 | #endif |
7567 | | #if defined(HAS_I444ALPHATOARGBROW_NEON) |
7568 | | if (TestCpuFlag(kCpuHasNEON)) { |
7569 | | I444AlphaToARGBRow = I444AlphaToARGBRow_Any_NEON; |
7570 | | if (IS_ALIGNED(width, 8)) { |
7571 | | I444AlphaToARGBRow = I444AlphaToARGBRow_NEON; |
7572 | | } |
7573 | | } |
7574 | | #endif |
7575 | | #if defined(HAS_I444ALPHATOARGBROW_SVE2) |
7576 | | if (TestCpuFlag(kCpuHasSVE2)) { |
7577 | | I444AlphaToARGBRow = I444AlphaToARGBRow_SVE2; |
7578 | | } |
7579 | | #endif |
7580 | | #if defined(HAS_I444ALPHATOARGBROW_SME) |
7581 | | if (TestCpuFlag(kCpuHasSME)) { |
7582 | | I444AlphaToARGBRow = I444AlphaToARGBRow_SME; |
7583 | | } |
7584 | | #endif |
7585 | | #if defined(HAS_I444ALPHATOARGBROW_LASX) |
7586 | | if (TestCpuFlag(kCpuHasLASX)) { |
7587 | | I444AlphaToARGBRow = I444AlphaToARGBRow_Any_LASX; |
7588 | | if (IS_ALIGNED(width, 16)) { |
7589 | | I444AlphaToARGBRow = I444AlphaToARGBRow_LASX; |
7590 | | } |
7591 | | } |
7592 | | #endif |
7593 | | #if defined(HAS_I444ALPHATOARGBROW_RVV) |
7594 | | if (TestCpuFlag(kCpuHasRVV)) { |
7595 | | I444AlphaToARGBRow = I444AlphaToARGBRow_RVV; |
7596 | | } |
7597 | | #endif |
7598 | 53 | #if defined(HAS_ARGBATTENUATEROW_SSSE3) |
7599 | 53 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7600 | 53 | ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; |
7601 | 53 | if (IS_ALIGNED(width, 4)) { |
7602 | 6 | ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; |
7603 | 6 | } |
7604 | 53 | } |
7605 | 53 | #endif |
7606 | 53 | #if defined(HAS_ARGBATTENUATEROW_AVX2) |
7607 | 53 | if (TestCpuFlag(kCpuHasAVX2)) { |
7608 | 53 | ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; |
7609 | 53 | if (IS_ALIGNED(width, 8)) { |
7610 | 4 | ARGBAttenuateRow = ARGBAttenuateRow_AVX2; |
7611 | 4 | } |
7612 | 53 | } |
7613 | 53 | #endif |
7614 | | #if defined(HAS_ARGBATTENUATEROW_NEON) |
7615 | | if (TestCpuFlag(kCpuHasNEON)) { |
7616 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; |
7617 | | if (IS_ALIGNED(width, 8)) { |
7618 | | ARGBAttenuateRow = ARGBAttenuateRow_NEON; |
7619 | | } |
7620 | | } |
7621 | | #endif |
7622 | | #if defined(HAS_ARGBATTENUATEROW_RVV) |
7623 | | if (TestCpuFlag(kCpuHasRVV)) { |
7624 | | ARGBAttenuateRow = ARGBAttenuateRow_RVV; |
7625 | | } |
7626 | | #endif |
7627 | | #if defined(HAS_ARGBATTENUATEROW_LSX) |
7628 | | if (TestCpuFlag(kCpuHasLSX)) { |
7629 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; |
7630 | | if (IS_ALIGNED(width, 8)) { |
7631 | | ARGBAttenuateRow = ARGBAttenuateRow_LSX; |
7632 | | } |
7633 | | } |
7634 | | #endif |
7635 | | #if defined(HAS_ARGBATTENUATEROW_LASX) |
7636 | | if (TestCpuFlag(kCpuHasLASX)) { |
7637 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; |
7638 | | if (IS_ALIGNED(width, 16)) { |
7639 | | ARGBAttenuateRow = ARGBAttenuateRow_LASX; |
7640 | | } |
7641 | | } |
7642 | | #endif |
7643 | | |
7644 | 53 | #if defined(HAS_SCALEROWUP2_BILINEAR_SSE2) |
7645 | 53 | if (TestCpuFlag(kCpuHasSSE2)) { |
7646 | 53 | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSE2; |
7647 | 53 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2; |
7648 | 53 | } |
7649 | 53 | #endif |
7650 | | |
7651 | 53 | #if defined(HAS_SCALEROWUP2_BILINEAR_SSSE3) |
7652 | 53 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7653 | 53 | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSSE3; |
7654 | 53 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3; |
7655 | 53 | } |
7656 | 53 | #endif |
7657 | | |
7658 | 53 | #if defined(HAS_SCALEROWUP2_BILINEAR_AVX2) |
7659 | 53 | if (TestCpuFlag(kCpuHasAVX2)) { |
7660 | 53 | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_AVX2; |
7661 | 53 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2; |
7662 | 53 | } |
7663 | 53 | #endif |
7664 | | |
7665 | | #if defined(HAS_SCALEROWUP2_BILINEAR_NEON) |
7666 | | if (TestCpuFlag(kCpuHasNEON)) { |
7667 | | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_NEON; |
7668 | | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON; |
7669 | | } |
7670 | | #endif |
7671 | | #if defined(HAS_SCALEROWUP2_BILINEAR_RVV) |
7672 | | if (TestCpuFlag(kCpuHasRVV)) { |
7673 | | Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_RVV; |
7674 | | ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV; |
7675 | | } |
7676 | | #endif |
7677 | | |
7678 | | // alloc 4 lines temp |
7679 | 53 | const int row_size = (width + 31) & ~31; |
7680 | 53 | align_buffer_64(row, row_size * 4); |
7681 | 53 | uint8_t* temp_u_1 = row; |
7682 | 53 | uint8_t* temp_u_2 = row + row_size; |
7683 | 53 | uint8_t* temp_v_1 = row + row_size * 2; |
7684 | 53 | uint8_t* temp_v_2 = row + row_size * 3; |
7685 | 53 | if (!row) |
7686 | 0 | return 1; |
7687 | | |
7688 | 53 | ScaleRowUp2_Linear(src_u, temp_u_1, width); |
7689 | 53 | ScaleRowUp2_Linear(src_v, temp_v_1, width); |
7690 | 53 | I444AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants, |
7691 | 53 | width); |
7692 | 53 | if (attenuate) { |
7693 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
7694 | 0 | } |
7695 | 53 | dst_argb += dst_stride_argb; |
7696 | 53 | src_y += src_stride_y; |
7697 | 53 | src_a += src_stride_a; |
7698 | | |
7699 | 1.73k | for (y = 0; y < height - 2; y += 2) { |
7700 | 1.68k | Scale2RowUp_Bilinear(src_u, src_stride_u, temp_u_1, row_size, width); |
7701 | 1.68k | Scale2RowUp_Bilinear(src_v, src_stride_v, temp_v_1, row_size, width); |
7702 | 1.68k | I444AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants, |
7703 | 1.68k | width); |
7704 | 1.68k | if (attenuate) { |
7705 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
7706 | 0 | } |
7707 | 1.68k | dst_argb += dst_stride_argb; |
7708 | 1.68k | src_y += src_stride_y; |
7709 | 1.68k | src_a += src_stride_a; |
7710 | 1.68k | I444AlphaToARGBRow(src_y, temp_u_2, temp_v_2, src_a, dst_argb, yuvconstants, |
7711 | 1.68k | width); |
7712 | 1.68k | if (attenuate) { |
7713 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
7714 | 0 | } |
7715 | 1.68k | dst_argb += dst_stride_argb; |
7716 | 1.68k | src_y += src_stride_y; |
7717 | 1.68k | src_u += src_stride_u; |
7718 | 1.68k | src_v += src_stride_v; |
7719 | 1.68k | src_a += src_stride_a; |
7720 | 1.68k | } |
7721 | | |
7722 | 53 | if (!(height & 1)) { |
7723 | 20 | ScaleRowUp2_Linear(src_u, temp_u_1, width); |
7724 | 20 | ScaleRowUp2_Linear(src_v, temp_v_1, width); |
7725 | 20 | I444AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants, |
7726 | 20 | width); |
7727 | 20 | if (attenuate) { |
7728 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
7729 | 0 | } |
7730 | 20 | } |
7731 | | |
7732 | 53 | free_aligned_buffer_64(row); |
7733 | 53 | return 0; |
7734 | 53 | } |
7735 | | |
7736 | | static int I422AlphaToARGBMatrixLinear(const uint8_t* src_y, |
7737 | | int src_stride_y, |
7738 | | const uint8_t* src_u, |
7739 | | int src_stride_u, |
7740 | | const uint8_t* src_v, |
7741 | | int src_stride_v, |
7742 | | const uint8_t* src_a, |
7743 | | int src_stride_a, |
7744 | | uint8_t* dst_argb, |
7745 | | int dst_stride_argb, |
7746 | | const struct YuvConstants* yuvconstants, |
7747 | | int width, |
7748 | | int height, |
7749 | 142 | int attenuate) { |
7750 | 142 | int y; |
7751 | 142 | void (*I444AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, |
7752 | 142 | const uint8_t* v_buf, const uint8_t* a_buf, |
7753 | 142 | uint8_t* dst_argb, |
7754 | 142 | const struct YuvConstants* yuvconstants, |
7755 | 142 | int width) = I444AlphaToARGBRow_C; |
7756 | 142 | void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, |
7757 | 142 | int width) = ARGBAttenuateRow_C; |
7758 | 142 | void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, |
7759 | 142 | int dst_width) = ScaleRowUp2_Linear_Any_C; |
7760 | 142 | assert(yuvconstants); |
7761 | 142 | if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || |
7762 | 142 | height == 0 || height == INT_MIN) { |
7763 | 0 | return -1; |
7764 | 0 | } |
7765 | | // Negative height means invert the image. |
7766 | 142 | if (height < 0) { |
7767 | 0 | height = -height; |
7768 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
7769 | 0 | dst_stride_argb = -dst_stride_argb; |
7770 | 0 | } |
7771 | 142 | #if defined(HAS_I444ALPHATOARGBROW_SSSE3) |
7772 | 142 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7773 | 142 | I444AlphaToARGBRow = I444AlphaToARGBRow_Any_SSSE3; |
7774 | 142 | if (IS_ALIGNED(width, 8)) { |
7775 | 42 | I444AlphaToARGBRow = I444AlphaToARGBRow_SSSE3; |
7776 | 42 | } |
7777 | 142 | } |
7778 | 142 | #endif |
7779 | 142 | #if defined(HAS_I444ALPHATOARGBROW_AVX2) |
7780 | 142 | if (TestCpuFlag(kCpuHasAVX2)) { |
7781 | 142 | I444AlphaToARGBRow = I444AlphaToARGBRow_Any_AVX2; |
7782 | 142 | if (IS_ALIGNED(width, 16)) { |
7783 | 25 | I444AlphaToARGBRow = I444AlphaToARGBRow_AVX2; |
7784 | 25 | } |
7785 | 142 | } |
7786 | 142 | #endif |
7787 | | #if defined(HAS_I444ALPHATOARGBROW_NEON) |
7788 | | if (TestCpuFlag(kCpuHasNEON)) { |
7789 | | I444AlphaToARGBRow = I444AlphaToARGBRow_Any_NEON; |
7790 | | if (IS_ALIGNED(width, 8)) { |
7791 | | I444AlphaToARGBRow = I444AlphaToARGBRow_NEON; |
7792 | | } |
7793 | | } |
7794 | | #endif |
7795 | | #if defined(HAS_I444ALPHATOARGBROW_SVE2) |
7796 | | if (TestCpuFlag(kCpuHasSVE2)) { |
7797 | | I444AlphaToARGBRow = I444AlphaToARGBRow_SVE2; |
7798 | | } |
7799 | | #endif |
7800 | | #if defined(HAS_I444ALPHATOARGBROW_SME) |
7801 | | if (TestCpuFlag(kCpuHasSME)) { |
7802 | | I444AlphaToARGBRow = I444AlphaToARGBRow_SME; |
7803 | | } |
7804 | | #endif |
7805 | | #if defined(HAS_I444ALPHATOARGBROW_LASX) |
7806 | | if (TestCpuFlag(kCpuHasLASX)) { |
7807 | | I444AlphaToARGBRow = I444AlphaToARGBRow_Any_LASX; |
7808 | | if (IS_ALIGNED(width, 16)) { |
7809 | | I444AlphaToARGBRow = I444AlphaToARGBRow_LASX; |
7810 | | } |
7811 | | } |
7812 | | #endif |
7813 | | #if defined(HAS_I444ALPHATOARGBROW_RVV) |
7814 | | if (TestCpuFlag(kCpuHasRVV)) { |
7815 | | I444AlphaToARGBRow = I444AlphaToARGBRow_RVV; |
7816 | | } |
7817 | | #endif |
7818 | 142 | #if defined(HAS_ARGBATTENUATEROW_SSSE3) |
7819 | 142 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7820 | 142 | ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; |
7821 | 142 | if (IS_ALIGNED(width, 4)) { |
7822 | 59 | ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; |
7823 | 59 | } |
7824 | 142 | } |
7825 | 142 | #endif |
7826 | 142 | #if defined(HAS_ARGBATTENUATEROW_AVX2) |
7827 | 142 | if (TestCpuFlag(kCpuHasAVX2)) { |
7828 | 142 | ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; |
7829 | 142 | if (IS_ALIGNED(width, 8)) { |
7830 | 42 | ARGBAttenuateRow = ARGBAttenuateRow_AVX2; |
7831 | 42 | } |
7832 | 142 | } |
7833 | 142 | #endif |
7834 | | #if defined(HAS_ARGBATTENUATEROW_NEON) |
7835 | | if (TestCpuFlag(kCpuHasNEON)) { |
7836 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; |
7837 | | if (IS_ALIGNED(width, 8)) { |
7838 | | ARGBAttenuateRow = ARGBAttenuateRow_NEON; |
7839 | | } |
7840 | | } |
7841 | | #endif |
7842 | | #if defined(HAS_ARGBATTENUATEROW_RVV) |
7843 | | if (TestCpuFlag(kCpuHasRVV)) { |
7844 | | ARGBAttenuateRow = ARGBAttenuateRow_RVV; |
7845 | | } |
7846 | | #endif |
7847 | | #if defined(HAS_ARGBATTENUATEROW_LSX) |
7848 | | if (TestCpuFlag(kCpuHasLSX)) { |
7849 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; |
7850 | | if (IS_ALIGNED(width, 8)) { |
7851 | | ARGBAttenuateRow = ARGBAttenuateRow_LSX; |
7852 | | } |
7853 | | } |
7854 | | #endif |
7855 | | #if defined(HAS_ARGBATTENUATEROW_LASX) |
7856 | | if (TestCpuFlag(kCpuHasLASX)) { |
7857 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; |
7858 | | if (IS_ALIGNED(width, 16)) { |
7859 | | ARGBAttenuateRow = ARGBAttenuateRow_LASX; |
7860 | | } |
7861 | | } |
7862 | | #endif |
7863 | | |
7864 | 142 | #if defined(HAS_SCALEROWUP2_LINEAR_SSE2) |
7865 | 142 | if (TestCpuFlag(kCpuHasSSE2)) { |
7866 | 142 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2; |
7867 | 142 | } |
7868 | 142 | #endif |
7869 | 142 | #if defined(HAS_SCALEROWUP2_LINEAR_SSSE3) |
7870 | 142 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7871 | 142 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3; |
7872 | 142 | } |
7873 | 142 | #endif |
7874 | 142 | #if defined(HAS_SCALEROWUP2_LINEAR_AVX2) |
7875 | 142 | if (TestCpuFlag(kCpuHasAVX2)) { |
7876 | 142 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2; |
7877 | 142 | } |
7878 | 142 | #endif |
7879 | | #if defined(HAS_SCALEROWUP2_LINEAR_NEON) |
7880 | | if (TestCpuFlag(kCpuHasNEON)) { |
7881 | | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON; |
7882 | | } |
7883 | | #endif |
7884 | | #if defined(HAS_SCALEROWUP2_LINEAR_RVV) |
7885 | | if (TestCpuFlag(kCpuHasRVV)) { |
7886 | | ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV; |
7887 | | } |
7888 | | #endif |
7889 | | |
7890 | | // alloc 2 lines temp |
7891 | 142 | const int row_size = (width + 31) & ~31; |
7892 | 142 | align_buffer_64(row, row_size * 2); |
7893 | 142 | uint8_t* temp_u = row; |
7894 | 142 | uint8_t* temp_v = row + row_size; |
7895 | 142 | if (!row) |
7896 | 0 | return 1; |
7897 | | |
7898 | 2.69k | for (y = 0; y < height; ++y) { |
7899 | 2.55k | ScaleRowUp2_Linear(src_u, temp_u, width); |
7900 | 2.55k | ScaleRowUp2_Linear(src_v, temp_v, width); |
7901 | 2.55k | I444AlphaToARGBRow(src_y, temp_u, temp_v, src_a, dst_argb, yuvconstants, |
7902 | 2.55k | width); |
7903 | 2.55k | if (attenuate) { |
7904 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
7905 | 0 | } |
7906 | 2.55k | dst_argb += dst_stride_argb; |
7907 | 2.55k | src_a += src_stride_a; |
7908 | 2.55k | src_y += src_stride_y; |
7909 | 2.55k | src_u += src_stride_u; |
7910 | 2.55k | src_v += src_stride_v; |
7911 | 2.55k | } |
7912 | | |
7913 | 142 | free_aligned_buffer_64(row); |
7914 | 142 | return 0; |
7915 | 142 | } |
7916 | | |
7917 | | static int I010AlphaToARGBMatrixBilinear( |
7918 | | const uint16_t* src_y, |
7919 | | int src_stride_y, |
7920 | | const uint16_t* src_u, |
7921 | | int src_stride_u, |
7922 | | const uint16_t* src_v, |
7923 | | int src_stride_v, |
7924 | | const uint16_t* src_a, |
7925 | | int src_stride_a, |
7926 | | uint8_t* dst_argb, |
7927 | | int dst_stride_argb, |
7928 | | const struct YuvConstants* yuvconstants, |
7929 | | int width, |
7930 | | int height, |
7931 | 44 | int attenuate) { |
7932 | 44 | int y; |
7933 | 44 | void (*I410AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, |
7934 | 44 | const uint16_t* v_buf, const uint16_t* a_buf, |
7935 | 44 | uint8_t* dst_argb, |
7936 | 44 | const struct YuvConstants* yuvconstants, |
7937 | 44 | int width) = I410AlphaToARGBRow_C; |
7938 | 44 | void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, |
7939 | 44 | int width) = ARGBAttenuateRow_C; |
7940 | 44 | void (*Scale2RowUp_Bilinear_12)( |
7941 | 44 | const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, |
7942 | 44 | ptrdiff_t dst_stride, int dst_width) = ScaleRowUp2_Bilinear_16_Any_C; |
7943 | 44 | void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, |
7944 | 44 | int dst_width) = ScaleRowUp2_Linear_16_Any_C; |
7945 | 44 | assert(yuvconstants); |
7946 | 44 | if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || |
7947 | 44 | height == 0 || height == INT_MIN) { |
7948 | 0 | return -1; |
7949 | 0 | } |
7950 | | // Negative height means invert the image. |
7951 | 44 | if (height < 0) { |
7952 | 0 | height = -height; |
7953 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
7954 | 0 | dst_stride_argb = -dst_stride_argb; |
7955 | 0 | } |
7956 | | #if defined(HAS_I410ALPHATOARGBROW_NEON) |
7957 | | if (TestCpuFlag(kCpuHasNEON)) { |
7958 | | I410AlphaToARGBRow = I410AlphaToARGBRow_Any_NEON; |
7959 | | if (IS_ALIGNED(width, 8)) { |
7960 | | I410AlphaToARGBRow = I410AlphaToARGBRow_NEON; |
7961 | | } |
7962 | | } |
7963 | | #endif |
7964 | | #if defined(HAS_I410ALPHATOARGBROW_SVE2) |
7965 | | if (TestCpuFlag(kCpuHasSVE2)) { |
7966 | | I410AlphaToARGBRow = I410AlphaToARGBRow_SVE2; |
7967 | | } |
7968 | | #endif |
7969 | | #if defined(HAS_I410ALPHATOARGBROW_SME) |
7970 | | if (TestCpuFlag(kCpuHasSME)) { |
7971 | | I410AlphaToARGBRow = I410AlphaToARGBRow_SME; |
7972 | | } |
7973 | | #endif |
7974 | 44 | #if defined(HAS_I410ALPHATOARGBROW_SSSE3) |
7975 | 44 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7976 | 44 | I410AlphaToARGBRow = I410AlphaToARGBRow_Any_SSSE3; |
7977 | 44 | if (IS_ALIGNED(width, 8)) { |
7978 | 4 | I410AlphaToARGBRow = I410AlphaToARGBRow_SSSE3; |
7979 | 4 | } |
7980 | 44 | } |
7981 | 44 | #endif |
7982 | 44 | #if defined(HAS_I410ALPHATOARGBROW_AVX2) |
7983 | 44 | if (TestCpuFlag(kCpuHasAVX2)) { |
7984 | 44 | I410AlphaToARGBRow = I410AlphaToARGBRow_Any_AVX2; |
7985 | 44 | if (IS_ALIGNED(width, 16)) { |
7986 | 3 | I410AlphaToARGBRow = I410AlphaToARGBRow_AVX2; |
7987 | 3 | } |
7988 | 44 | } |
7989 | 44 | #endif |
7990 | 44 | #if defined(HAS_ARGBATTENUATEROW_SSSE3) |
7991 | 44 | if (TestCpuFlag(kCpuHasSSSE3)) { |
7992 | 44 | ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; |
7993 | 44 | if (IS_ALIGNED(width, 4)) { |
7994 | 5 | ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; |
7995 | 5 | } |
7996 | 44 | } |
7997 | 44 | #endif |
7998 | 44 | #if defined(HAS_ARGBATTENUATEROW_AVX2) |
7999 | 44 | if (TestCpuFlag(kCpuHasAVX2)) { |
8000 | 44 | ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; |
8001 | 44 | if (IS_ALIGNED(width, 8)) { |
8002 | 4 | ARGBAttenuateRow = ARGBAttenuateRow_AVX2; |
8003 | 4 | } |
8004 | 44 | } |
8005 | 44 | #endif |
8006 | | #if defined(HAS_ARGBATTENUATEROW_NEON) |
8007 | | if (TestCpuFlag(kCpuHasNEON)) { |
8008 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; |
8009 | | if (IS_ALIGNED(width, 8)) { |
8010 | | ARGBAttenuateRow = ARGBAttenuateRow_NEON; |
8011 | | } |
8012 | | } |
8013 | | #endif |
8014 | | #if defined(HAS_ARGBATTENUATEROW_RVV) |
8015 | | if (TestCpuFlag(kCpuHasRVV)) { |
8016 | | ARGBAttenuateRow = ARGBAttenuateRow_RVV; |
8017 | | } |
8018 | | #endif |
8019 | | #if defined(HAS_ARGBATTENUATEROW_LSX) |
8020 | | if (TestCpuFlag(kCpuHasLSX)) { |
8021 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; |
8022 | | if (IS_ALIGNED(width, 8)) { |
8023 | | ARGBAttenuateRow = ARGBAttenuateRow_LSX; |
8024 | | } |
8025 | | } |
8026 | | #endif |
8027 | | #if defined(HAS_ARGBATTENUATEROW_LASX) |
8028 | | if (TestCpuFlag(kCpuHasLASX)) { |
8029 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; |
8030 | | if (IS_ALIGNED(width, 16)) { |
8031 | | ARGBAttenuateRow = ARGBAttenuateRow_LASX; |
8032 | | } |
8033 | | } |
8034 | | #endif |
8035 | | |
8036 | 44 | #if defined(HAS_SCALEROWUP2_BILINEAR_12_SSSE3) |
8037 | 44 | if (TestCpuFlag(kCpuHasSSSE3)) { |
8038 | 44 | Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_SSSE3; |
8039 | 44 | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3; |
8040 | 44 | } |
8041 | 44 | #endif |
8042 | | |
8043 | 44 | #if defined(HAS_SCALEROWUP2_BILINEAR_12_AVX2) |
8044 | 44 | if (TestCpuFlag(kCpuHasAVX2)) { |
8045 | 44 | Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_AVX2; |
8046 | 44 | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2; |
8047 | 44 | } |
8048 | 44 | #endif |
8049 | | |
8050 | | #if defined(HAS_SCALEROWUP2_BILINEAR_12_NEON) |
8051 | | if (TestCpuFlag(kCpuHasNEON)) { |
8052 | | Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_NEON; |
8053 | | ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON; |
8054 | | } |
8055 | | #endif |
8056 | | |
8057 | | // alloc 4 lines temp |
8058 | 44 | const int row_size = (width + 31) & ~31; |
8059 | 44 | align_buffer_64(row, row_size * 4 * sizeof(uint16_t)); |
8060 | 44 | uint16_t* temp_u_1 = (uint16_t*)(row); |
8061 | 44 | uint16_t* temp_u_2 = (uint16_t*)(row) + row_size; |
8062 | 44 | uint16_t* temp_v_1 = (uint16_t*)(row) + row_size * 2; |
8063 | 44 | uint16_t* temp_v_2 = (uint16_t*)(row) + row_size * 3; |
8064 | 44 | if (!row) |
8065 | 0 | return 1; |
8066 | | |
8067 | 44 | ScaleRowUp2_Linear_12(src_u, temp_u_1, width); |
8068 | 44 | ScaleRowUp2_Linear_12(src_v, temp_v_1, width); |
8069 | 44 | I410AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants, |
8070 | 44 | width); |
8071 | 44 | if (attenuate) { |
8072 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
8073 | 0 | } |
8074 | 44 | dst_argb += dst_stride_argb; |
8075 | 44 | src_y += src_stride_y; |
8076 | 44 | src_a += src_stride_a; |
8077 | | |
8078 | 1.05k | for (y = 0; y < height - 2; y += 2) { |
8079 | 1.01k | Scale2RowUp_Bilinear_12(src_u, src_stride_u, temp_u_1, row_size, width); |
8080 | 1.01k | Scale2RowUp_Bilinear_12(src_v, src_stride_v, temp_v_1, row_size, width); |
8081 | 1.01k | I410AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants, |
8082 | 1.01k | width); |
8083 | 1.01k | if (attenuate) { |
8084 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
8085 | 0 | } |
8086 | 1.01k | dst_argb += dst_stride_argb; |
8087 | 1.01k | src_y += src_stride_y; |
8088 | 1.01k | src_a += src_stride_a; |
8089 | 1.01k | I410AlphaToARGBRow(src_y, temp_u_2, temp_v_2, src_a, dst_argb, yuvconstants, |
8090 | 1.01k | width); |
8091 | 1.01k | if (attenuate) { |
8092 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
8093 | 0 | } |
8094 | 1.01k | dst_argb += dst_stride_argb; |
8095 | 1.01k | src_y += src_stride_y; |
8096 | 1.01k | src_a += src_stride_a; |
8097 | 1.01k | src_u += src_stride_u; |
8098 | 1.01k | src_v += src_stride_v; |
8099 | 1.01k | } |
8100 | | |
8101 | 44 | if (!(height & 1)) { |
8102 | 15 | ScaleRowUp2_Linear_12(src_u, temp_u_1, width); |
8103 | 15 | ScaleRowUp2_Linear_12(src_v, temp_v_1, width); |
8104 | 15 | I410AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants, |
8105 | 15 | width); |
8106 | 15 | if (attenuate) { |
8107 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
8108 | 0 | } |
8109 | 15 | } |
8110 | | |
8111 | 44 | free_aligned_buffer_64(row); |
8112 | 44 | return 0; |
8113 | 44 | } |
8114 | | |
8115 | | static int I210AlphaToARGBMatrixLinear(const uint16_t* src_y, |
8116 | | int src_stride_y, |
8117 | | const uint16_t* src_u, |
8118 | | int src_stride_u, |
8119 | | const uint16_t* src_v, |
8120 | | int src_stride_v, |
8121 | | const uint16_t* src_a, |
8122 | | int src_stride_a, |
8123 | | uint8_t* dst_argb, |
8124 | | int dst_stride_argb, |
8125 | | const struct YuvConstants* yuvconstants, |
8126 | | int width, |
8127 | | int height, |
8128 | 133 | int attenuate) { |
8129 | 133 | int y; |
8130 | 133 | void (*I410AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, |
8131 | 133 | const uint16_t* v_buf, const uint16_t* a_buf, |
8132 | 133 | uint8_t* dst_argb, |
8133 | 133 | const struct YuvConstants* yuvconstants, |
8134 | 133 | int width) = I410AlphaToARGBRow_C; |
8135 | 133 | void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, |
8136 | 133 | int width) = ARGBAttenuateRow_C; |
8137 | 133 | void (*ScaleRowUp2_Linear)(const uint16_t* src_ptr, uint16_t* dst_ptr, |
8138 | 133 | int dst_width) = ScaleRowUp2_Linear_16_Any_C; |
8139 | 133 | assert(yuvconstants); |
8140 | 133 | if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || |
8141 | 133 | height == 0 || height == INT_MIN) { |
8142 | 0 | return -1; |
8143 | 0 | } |
8144 | | // Negative height means invert the image. |
8145 | 133 | if (height < 0) { |
8146 | 0 | height = -height; |
8147 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
8148 | 0 | dst_stride_argb = -dst_stride_argb; |
8149 | 0 | } |
8150 | | #if defined(HAS_I410ALPHATOARGBROW_NEON) |
8151 | | if (TestCpuFlag(kCpuHasNEON)) { |
8152 | | I410AlphaToARGBRow = I410AlphaToARGBRow_Any_NEON; |
8153 | | if (IS_ALIGNED(width, 8)) { |
8154 | | I410AlphaToARGBRow = I410AlphaToARGBRow_NEON; |
8155 | | } |
8156 | | } |
8157 | | #endif |
8158 | | #if defined(HAS_I410ALPHATOARGBROW_SVE2) |
8159 | | if (TestCpuFlag(kCpuHasSVE2)) { |
8160 | | I410AlphaToARGBRow = I410AlphaToARGBRow_SVE2; |
8161 | | } |
8162 | | #endif |
8163 | | #if defined(HAS_I410ALPHATOARGBROW_SME) |
8164 | | if (TestCpuFlag(kCpuHasSME)) { |
8165 | | I410AlphaToARGBRow = I410AlphaToARGBRow_SME; |
8166 | | } |
8167 | | #endif |
8168 | 133 | #if defined(HAS_I410ALPHATOARGBROW_SSSE3) |
8169 | 133 | if (TestCpuFlag(kCpuHasSSSE3)) { |
8170 | 133 | I410AlphaToARGBRow = I410AlphaToARGBRow_Any_SSSE3; |
8171 | 133 | if (IS_ALIGNED(width, 8)) { |
8172 | 58 | I410AlphaToARGBRow = I410AlphaToARGBRow_SSSE3; |
8173 | 58 | } |
8174 | 133 | } |
8175 | 133 | #endif |
8176 | 133 | #if defined(HAS_I410ALPHATOARGBROW_AVX2) |
8177 | 133 | if (TestCpuFlag(kCpuHasAVX2)) { |
8178 | 133 | I410AlphaToARGBRow = I410AlphaToARGBRow_Any_AVX2; |
8179 | 133 | if (IS_ALIGNED(width, 16)) { |
8180 | 17 | I410AlphaToARGBRow = I410AlphaToARGBRow_AVX2; |
8181 | 17 | } |
8182 | 133 | } |
8183 | 133 | #endif |
8184 | 133 | #if defined(HAS_ARGBATTENUATEROW_SSSE3) |
8185 | 133 | if (TestCpuFlag(kCpuHasSSSE3)) { |
8186 | 133 | ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; |
8187 | 133 | if (IS_ALIGNED(width, 4)) { |
8188 | 76 | ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; |
8189 | 76 | } |
8190 | 133 | } |
8191 | 133 | #endif |
8192 | 133 | #if defined(HAS_ARGBATTENUATEROW_AVX2) |
8193 | 133 | if (TestCpuFlag(kCpuHasAVX2)) { |
8194 | 133 | ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; |
8195 | 133 | if (IS_ALIGNED(width, 8)) { |
8196 | 58 | ARGBAttenuateRow = ARGBAttenuateRow_AVX2; |
8197 | 58 | } |
8198 | 133 | } |
8199 | 133 | #endif |
8200 | | #if defined(HAS_ARGBATTENUATEROW_NEON) |
8201 | | if (TestCpuFlag(kCpuHasNEON)) { |
8202 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; |
8203 | | if (IS_ALIGNED(width, 8)) { |
8204 | | ARGBAttenuateRow = ARGBAttenuateRow_NEON; |
8205 | | } |
8206 | | } |
8207 | | #endif |
8208 | | #if defined(HAS_ARGBATTENUATEROW_RVV) |
8209 | | if (TestCpuFlag(kCpuHasRVV)) { |
8210 | | ARGBAttenuateRow = ARGBAttenuateRow_RVV; |
8211 | | } |
8212 | | #endif |
8213 | | #if defined(HAS_ARGBATTENUATEROW_LSX) |
8214 | | if (TestCpuFlag(kCpuHasLSX)) { |
8215 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; |
8216 | | if (IS_ALIGNED(width, 8)) { |
8217 | | ARGBAttenuateRow = ARGBAttenuateRow_LSX; |
8218 | | } |
8219 | | } |
8220 | | #endif |
8221 | | #if defined(HAS_ARGBATTENUATEROW_LASX) |
8222 | | if (TestCpuFlag(kCpuHasLASX)) { |
8223 | | ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; |
8224 | | if (IS_ALIGNED(width, 16)) { |
8225 | | ARGBAttenuateRow = ARGBAttenuateRow_LASX; |
8226 | | } |
8227 | | } |
8228 | | #endif |
8229 | | |
8230 | 133 | #if defined(HAS_SCALEROWUP2_LINEAR_12_SSSE3) |
8231 | 133 | if (TestCpuFlag(kCpuHasSSSE3)) { |
8232 | 133 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_12_Any_SSSE3; |
8233 | 133 | } |
8234 | 133 | #endif |
8235 | 133 | #if defined(HAS_SCALEROWUP2_LINEAR_12_AVX2) |
8236 | 133 | if (TestCpuFlag(kCpuHasAVX2)) { |
8237 | 133 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_12_Any_AVX2; |
8238 | 133 | } |
8239 | 133 | #endif |
8240 | | #if defined(HAS_SCALEROWUP2_LINEAR_12_NEON) |
8241 | | if (TestCpuFlag(kCpuHasNEON)) { |
8242 | | ScaleRowUp2_Linear = ScaleRowUp2_Linear_12_Any_NEON; |
8243 | | } |
8244 | | #endif |
8245 | | |
8246 | | // alloc 2 lines temp |
8247 | 133 | const int row_size = (width + 31) & ~31; |
8248 | 133 | align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); |
8249 | 133 | uint16_t* temp_u = (uint16_t*)(row); |
8250 | 133 | uint16_t* temp_v = (uint16_t*)(row) + row_size; |
8251 | 133 | if (!row) |
8252 | 0 | return 1; |
8253 | | |
8254 | 2.88k | for (y = 0; y < height; ++y) { |
8255 | 2.75k | ScaleRowUp2_Linear(src_u, temp_u, width); |
8256 | 2.75k | ScaleRowUp2_Linear(src_v, temp_v, width); |
8257 | 2.75k | I410AlphaToARGBRow(src_y, temp_u, temp_v, src_a, dst_argb, yuvconstants, |
8258 | 2.75k | width); |
8259 | 2.75k | if (attenuate) { |
8260 | 0 | ARGBAttenuateRow(dst_argb, dst_argb, width); |
8261 | 0 | } |
8262 | 2.75k | dst_argb += dst_stride_argb; |
8263 | 2.75k | src_a += src_stride_a; |
8264 | 2.75k | src_y += src_stride_y; |
8265 | 2.75k | src_u += src_stride_u; |
8266 | 2.75k | src_v += src_stride_v; |
8267 | 2.75k | } |
8268 | 133 | free_aligned_buffer_64(row); |
8269 | 133 | return 0; |
8270 | 133 | } |
8271 | | |
8272 | | static int P010ToARGBMatrixBilinear(const uint16_t* src_y, |
8273 | | int src_stride_y, |
8274 | | const uint16_t* src_uv, |
8275 | | int src_stride_uv, |
8276 | | uint8_t* dst_argb, |
8277 | | int dst_stride_argb, |
8278 | | const struct YuvConstants* yuvconstants, |
8279 | | int width, |
8280 | 0 | int height) { |
8281 | 0 | int y; |
8282 | 0 | void (*P410ToARGBRow)( |
8283 | 0 | const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, |
8284 | 0 | const struct YuvConstants* yuvconstants, int width) = P410ToARGBRow_C; |
8285 | 0 | void (*Scale2RowUp_Bilinear_16)( |
8286 | 0 | const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, |
8287 | 0 | ptrdiff_t dst_stride, int dst_width) = ScaleUVRowUp2_Bilinear_16_Any_C; |
8288 | 0 | assert(yuvconstants); |
8289 | 0 | if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || |
8290 | 0 | height == INT_MIN) { |
8291 | 0 | return -1; |
8292 | 0 | } |
8293 | | // Negative height means invert the image. |
8294 | 0 | if (height < 0) { |
8295 | 0 | height = -height; |
8296 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
8297 | 0 | dst_stride_argb = -dst_stride_argb; |
8298 | 0 | } |
8299 | 0 | #if defined(HAS_P410TOARGBROW_SSSE3) |
8300 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
8301 | 0 | P410ToARGBRow = P410ToARGBRow_Any_SSSE3; |
8302 | 0 | if (IS_ALIGNED(width, 8)) { |
8303 | 0 | P410ToARGBRow = P410ToARGBRow_SSSE3; |
8304 | 0 | } |
8305 | 0 | } |
8306 | 0 | #endif |
8307 | 0 | #if defined(HAS_P410TOARGBROW_AVX2) |
8308 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
8309 | 0 | P410ToARGBRow = P410ToARGBRow_Any_AVX2; |
8310 | 0 | if (IS_ALIGNED(width, 16)) { |
8311 | 0 | P410ToARGBRow = P410ToARGBRow_AVX2; |
8312 | 0 | } |
8313 | 0 | } |
8314 | 0 | #endif |
8315 | | #if defined(HAS_P410TOARGBROW_NEON) |
8316 | | if (TestCpuFlag(kCpuHasNEON)) { |
8317 | | P410ToARGBRow = P410ToARGBRow_Any_NEON; |
8318 | | if (IS_ALIGNED(width, 8)) { |
8319 | | P410ToARGBRow = P410ToARGBRow_NEON; |
8320 | | } |
8321 | | } |
8322 | | #endif |
8323 | | #if defined(HAS_P410TOARGBROW_SVE2) |
8324 | | if (TestCpuFlag(kCpuHasSVE2)) { |
8325 | | P410ToARGBRow = P410ToARGBRow_SVE2; |
8326 | | } |
8327 | | #endif |
8328 | | #if defined(HAS_P410TOARGBROW_SME) |
8329 | | if (TestCpuFlag(kCpuHasSME)) { |
8330 | | P410ToARGBRow = P410ToARGBRow_SME; |
8331 | | } |
8332 | | #endif |
8333 | |
|
8334 | 0 | #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_SSE41 |
8335 | 0 | if (TestCpuFlag(kCpuHasSSE41)) { |
8336 | 0 | Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_SSE41; |
8337 | 0 | } |
8338 | 0 | #endif |
8339 | |
|
8340 | 0 | #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_AVX2 |
8341 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
8342 | 0 | Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_AVX2; |
8343 | 0 | } |
8344 | 0 | #endif |
8345 | |
|
8346 | | #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_NEON |
8347 | | if (TestCpuFlag(kCpuHasNEON)) { |
8348 | | Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_NEON; |
8349 | | } |
8350 | | #endif |
8351 | | |
8352 | | // alloc 2 lines temp |
8353 | 0 | const int row_size = (2 * width + 31) & ~31; |
8354 | 0 | align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); |
8355 | 0 | uint16_t* temp_uv_1 = (uint16_t*)(row); |
8356 | 0 | uint16_t* temp_uv_2 = (uint16_t*)(row) + row_size; |
8357 | 0 | if (!row) |
8358 | 0 | return 1; |
8359 | | |
8360 | 0 | Scale2RowUp_Bilinear_16(src_uv, 0, temp_uv_1, row_size, width); |
8361 | 0 | P410ToARGBRow(src_y, temp_uv_1, dst_argb, yuvconstants, width); |
8362 | 0 | dst_argb += dst_stride_argb; |
8363 | 0 | src_y += src_stride_y; |
8364 | |
|
8365 | 0 | for (y = 0; y < height - 2; y += 2) { |
8366 | 0 | Scale2RowUp_Bilinear_16(src_uv, src_stride_uv, temp_uv_1, row_size, width); |
8367 | 0 | P410ToARGBRow(src_y, temp_uv_1, dst_argb, yuvconstants, width); |
8368 | 0 | dst_argb += dst_stride_argb; |
8369 | 0 | src_y += src_stride_y; |
8370 | 0 | P410ToARGBRow(src_y, temp_uv_2, dst_argb, yuvconstants, width); |
8371 | 0 | dst_argb += dst_stride_argb; |
8372 | 0 | src_y += src_stride_y; |
8373 | 0 | src_uv += src_stride_uv; |
8374 | 0 | } |
8375 | |
|
8376 | 0 | if (!(height & 1)) { |
8377 | 0 | Scale2RowUp_Bilinear_16(src_uv, 0, temp_uv_1, row_size, width); |
8378 | 0 | P410ToARGBRow(src_y, temp_uv_1, dst_argb, yuvconstants, width); |
8379 | 0 | } |
8380 | |
|
8381 | 0 | free_aligned_buffer_64(row); |
8382 | 0 | return 0; |
8383 | 0 | } |
8384 | | |
8385 | | static int P210ToARGBMatrixLinear(const uint16_t* src_y, |
8386 | | int src_stride_y, |
8387 | | const uint16_t* src_uv, |
8388 | | int src_stride_uv, |
8389 | | uint8_t* dst_argb, |
8390 | | int dst_stride_argb, |
8391 | | const struct YuvConstants* yuvconstants, |
8392 | | int width, |
8393 | 0 | int height) { |
8394 | 0 | int y; |
8395 | 0 | void (*P410ToARGBRow)( |
8396 | 0 | const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, |
8397 | 0 | const struct YuvConstants* yuvconstants, int width) = P410ToARGBRow_C; |
8398 | 0 | void (*ScaleRowUp2_Linear)(const uint16_t* src_uv, uint16_t* dst_uv, |
8399 | 0 | int dst_width) = ScaleUVRowUp2_Linear_16_Any_C; |
8400 | 0 | assert(yuvconstants); |
8401 | 0 | if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || |
8402 | 0 | height == INT_MIN) { |
8403 | 0 | return -1; |
8404 | 0 | } |
8405 | | // Negative height means invert the image. |
8406 | 0 | if (height < 0) { |
8407 | 0 | height = -height; |
8408 | 0 | dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; |
8409 | 0 | dst_stride_argb = -dst_stride_argb; |
8410 | 0 | } |
8411 | 0 | #if defined(HAS_P410TOARGBROW_SSSE3) |
8412 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
8413 | 0 | P410ToARGBRow = P410ToARGBRow_Any_SSSE3; |
8414 | 0 | if (IS_ALIGNED(width, 8)) { |
8415 | 0 | P410ToARGBRow = P410ToARGBRow_SSSE3; |
8416 | 0 | } |
8417 | 0 | } |
8418 | 0 | #endif |
8419 | 0 | #if defined(HAS_P410TOARGBROW_AVX2) |
8420 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
8421 | 0 | P410ToARGBRow = P410ToARGBRow_Any_AVX2; |
8422 | 0 | if (IS_ALIGNED(width, 16)) { |
8423 | 0 | P410ToARGBRow = P410ToARGBRow_AVX2; |
8424 | 0 | } |
8425 | 0 | } |
8426 | 0 | #endif |
8427 | | #if defined(HAS_P410TOARGBROW_NEON) |
8428 | | if (TestCpuFlag(kCpuHasNEON)) { |
8429 | | P410ToARGBRow = P410ToARGBRow_Any_NEON; |
8430 | | if (IS_ALIGNED(width, 8)) { |
8431 | | P410ToARGBRow = P410ToARGBRow_NEON; |
8432 | | } |
8433 | | } |
8434 | | #endif |
8435 | | #if defined(HAS_P410TOARGBROW_SVE2) |
8436 | | if (TestCpuFlag(kCpuHasSVE2)) { |
8437 | | P410ToARGBRow = P410ToARGBRow_SVE2; |
8438 | | } |
8439 | | #endif |
8440 | | #if defined(HAS_P410TOARGBROW_SME) |
8441 | | if (TestCpuFlag(kCpuHasSME)) { |
8442 | | P410ToARGBRow = P410ToARGBRow_SME; |
8443 | | } |
8444 | | #endif |
8445 | |
|
8446 | 0 | #ifdef HAS_SCALEUVROWUP2_LINEAR_16_SSE41 |
8447 | 0 | if (TestCpuFlag(kCpuHasSSE41)) { |
8448 | 0 | ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_SSE41; |
8449 | 0 | } |
8450 | 0 | #endif |
8451 | |
|
8452 | 0 | #ifdef HAS_SCALEUVROWUP2_LINEAR_16_AVX2 |
8453 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
8454 | 0 | ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_AVX2; |
8455 | 0 | } |
8456 | 0 | #endif |
8457 | |
|
8458 | | #ifdef HAS_SCALEUVROWUP2_LINEAR_16_NEON |
8459 | | if (TestCpuFlag(kCpuHasNEON)) { |
8460 | | ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_NEON; |
8461 | | } |
8462 | | #endif |
8463 | |
|
8464 | 0 | const int row_size = (2 * width + 31) & ~31; |
8465 | 0 | align_buffer_64(row, row_size * sizeof(uint16_t)); |
8466 | 0 | uint16_t* temp_uv = (uint16_t*)(row); |
8467 | 0 | if (!row) |
8468 | 0 | return 1; |
8469 | | |
8470 | 0 | for (y = 0; y < height; ++y) { |
8471 | 0 | ScaleRowUp2_Linear(src_uv, temp_uv, width); |
8472 | 0 | P410ToARGBRow(src_y, temp_uv, dst_argb, yuvconstants, width); |
8473 | 0 | dst_argb += dst_stride_argb; |
8474 | 0 | src_y += src_stride_y; |
8475 | 0 | src_uv += src_stride_uv; |
8476 | 0 | } |
8477 | |
|
8478 | 0 | free_aligned_buffer_64(row); |
8479 | 0 | return 0; |
8480 | 0 | } |
8481 | | |
8482 | | static int P010ToAR30MatrixBilinear(const uint16_t* src_y, |
8483 | | int src_stride_y, |
8484 | | const uint16_t* src_uv, |
8485 | | int src_stride_uv, |
8486 | | uint8_t* dst_ar30, |
8487 | | int dst_stride_ar30, |
8488 | | const struct YuvConstants* yuvconstants, |
8489 | | int width, |
8490 | 0 | int height) { |
8491 | 0 | int y; |
8492 | 0 | void (*P410ToAR30Row)( |
8493 | 0 | const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, |
8494 | 0 | const struct YuvConstants* yuvconstants, int width) = P410ToAR30Row_C; |
8495 | 0 | void (*Scale2RowUp_Bilinear_16)( |
8496 | 0 | const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, |
8497 | 0 | ptrdiff_t dst_stride, int dst_width) = ScaleUVRowUp2_Bilinear_16_Any_C; |
8498 | 0 | assert(yuvconstants); |
8499 | 0 | if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0 || |
8500 | 0 | height == INT_MIN) { |
8501 | 0 | return -1; |
8502 | 0 | } |
8503 | | // Negative height means invert the image. |
8504 | 0 | if (height < 0) { |
8505 | 0 | height = -height; |
8506 | 0 | dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; |
8507 | 0 | dst_stride_ar30 = -dst_stride_ar30; |
8508 | 0 | } |
8509 | 0 | #if defined(HAS_P410TOAR30ROW_SSSE3) |
8510 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
8511 | 0 | P410ToAR30Row = P410ToAR30Row_Any_SSSE3; |
8512 | 0 | if (IS_ALIGNED(width, 8)) { |
8513 | 0 | P410ToAR30Row = P410ToAR30Row_SSSE3; |
8514 | 0 | } |
8515 | 0 | } |
8516 | 0 | #endif |
8517 | 0 | #if defined(HAS_P410TOAR30ROW_AVX2) |
8518 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
8519 | 0 | P410ToAR30Row = P410ToAR30Row_Any_AVX2; |
8520 | 0 | if (IS_ALIGNED(width, 16)) { |
8521 | 0 | P410ToAR30Row = P410ToAR30Row_AVX2; |
8522 | 0 | } |
8523 | 0 | } |
8524 | 0 | #endif |
8525 | | #if defined(HAS_P410TOAR30ROW_NEON) |
8526 | | if (TestCpuFlag(kCpuHasNEON)) { |
8527 | | P410ToAR30Row = P410ToAR30Row_Any_NEON; |
8528 | | if (IS_ALIGNED(width, 8)) { |
8529 | | P410ToAR30Row = P410ToAR30Row_NEON; |
8530 | | } |
8531 | | } |
8532 | | #endif |
8533 | | #if defined(HAS_P410TOAR30ROW_SVE2) |
8534 | | if (TestCpuFlag(kCpuHasSVE2)) { |
8535 | | P410ToAR30Row = P410ToAR30Row_SVE2; |
8536 | | } |
8537 | | #endif |
8538 | | #if defined(HAS_P410TOAR30ROW_SME) |
8539 | | if (TestCpuFlag(kCpuHasSME)) { |
8540 | | P410ToAR30Row = P410ToAR30Row_SME; |
8541 | | } |
8542 | | #endif |
8543 | |
|
8544 | 0 | #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_SSE41 |
8545 | 0 | if (TestCpuFlag(kCpuHasSSE41)) { |
8546 | 0 | Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_SSE41; |
8547 | 0 | } |
8548 | 0 | #endif |
8549 | |
|
8550 | 0 | #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_AVX2 |
8551 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
8552 | 0 | Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_AVX2; |
8553 | 0 | } |
8554 | 0 | #endif |
8555 | |
|
8556 | | #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_NEON |
8557 | | if (TestCpuFlag(kCpuHasNEON)) { |
8558 | | Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_NEON; |
8559 | | } |
8560 | | #endif |
8561 | | |
8562 | | // alloc 2 lines temp |
8563 | 0 | const int row_size = (2 * width + 31) & ~31; |
8564 | 0 | align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); |
8565 | 0 | uint16_t* temp_uv_1 = (uint16_t*)(row); |
8566 | 0 | uint16_t* temp_uv_2 = (uint16_t*)(row) + row_size; |
8567 | 0 | if (!row) |
8568 | 0 | return 1; |
8569 | | |
8570 | 0 | Scale2RowUp_Bilinear_16(src_uv, 0, temp_uv_1, row_size, width); |
8571 | 0 | P410ToAR30Row(src_y, temp_uv_1, dst_ar30, yuvconstants, width); |
8572 | 0 | dst_ar30 += dst_stride_ar30; |
8573 | 0 | src_y += src_stride_y; |
8574 | |
|
8575 | 0 | for (y = 0; y < height - 2; y += 2) { |
8576 | 0 | Scale2RowUp_Bilinear_16(src_uv, src_stride_uv, temp_uv_1, row_size, width); |
8577 | 0 | P410ToAR30Row(src_y, temp_uv_1, dst_ar30, yuvconstants, width); |
8578 | 0 | dst_ar30 += dst_stride_ar30; |
8579 | 0 | src_y += src_stride_y; |
8580 | 0 | P410ToAR30Row(src_y, temp_uv_2, dst_ar30, yuvconstants, width); |
8581 | 0 | dst_ar30 += dst_stride_ar30; |
8582 | 0 | src_y += src_stride_y; |
8583 | 0 | src_uv += src_stride_uv; |
8584 | 0 | } |
8585 | |
|
8586 | 0 | if (!(height & 1)) { |
8587 | 0 | Scale2RowUp_Bilinear_16(src_uv, 0, temp_uv_1, row_size, width); |
8588 | 0 | P410ToAR30Row(src_y, temp_uv_1, dst_ar30, yuvconstants, width); |
8589 | 0 | } |
8590 | |
|
8591 | 0 | free_aligned_buffer_64(row); |
8592 | 0 | return 0; |
8593 | 0 | } |
8594 | | |
8595 | | static int P210ToAR30MatrixLinear(const uint16_t* src_y, |
8596 | | int src_stride_y, |
8597 | | const uint16_t* src_uv, |
8598 | | int src_stride_uv, |
8599 | | uint8_t* dst_ar30, |
8600 | | int dst_stride_ar30, |
8601 | | const struct YuvConstants* yuvconstants, |
8602 | | int width, |
8603 | 0 | int height) { |
8604 | 0 | int y; |
8605 | 0 | void (*P410ToAR30Row)( |
8606 | 0 | const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, |
8607 | 0 | const struct YuvConstants* yuvconstants, int width) = P410ToAR30Row_C; |
8608 | 0 | void (*ScaleRowUp2_Linear)(const uint16_t* src_uv, uint16_t* dst_uv, |
8609 | 0 | int dst_width) = ScaleUVRowUp2_Linear_16_Any_C; |
8610 | 0 | assert(yuvconstants); |
8611 | 0 | if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0 || |
8612 | 0 | height == INT_MIN) { |
8613 | 0 | return -1; |
8614 | 0 | } |
8615 | | // Negative height means invert the image. |
8616 | 0 | if (height < 0) { |
8617 | 0 | height = -height; |
8618 | 0 | dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; |
8619 | 0 | dst_stride_ar30 = -dst_stride_ar30; |
8620 | 0 | } |
8621 | 0 | #if defined(HAS_P410TOAR30ROW_SSSE3) |
8622 | 0 | if (TestCpuFlag(kCpuHasSSSE3)) { |
8623 | 0 | P410ToAR30Row = P410ToAR30Row_Any_SSSE3; |
8624 | 0 | if (IS_ALIGNED(width, 8)) { |
8625 | 0 | P410ToAR30Row = P410ToAR30Row_SSSE3; |
8626 | 0 | } |
8627 | 0 | } |
8628 | 0 | #endif |
8629 | 0 | #if defined(HAS_P410TOAR30ROW_AVX2) |
8630 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
8631 | 0 | P410ToAR30Row = P410ToAR30Row_Any_AVX2; |
8632 | 0 | if (IS_ALIGNED(width, 16)) { |
8633 | 0 | P410ToAR30Row = P410ToAR30Row_AVX2; |
8634 | 0 | } |
8635 | 0 | } |
8636 | 0 | #endif |
8637 | | #if defined(HAS_P410TOAR30ROW_NEON) |
8638 | | if (TestCpuFlag(kCpuHasNEON)) { |
8639 | | P410ToAR30Row = P410ToAR30Row_Any_NEON; |
8640 | | if (IS_ALIGNED(width, 8)) { |
8641 | | P410ToAR30Row = P410ToAR30Row_NEON; |
8642 | | } |
8643 | | } |
8644 | | #endif |
8645 | | #if defined(HAS_P410TOAR30ROW_SVE2) |
8646 | | if (TestCpuFlag(kCpuHasSVE2)) { |
8647 | | P410ToAR30Row = P410ToAR30Row_SVE2; |
8648 | | } |
8649 | | #endif |
8650 | | #if defined(HAS_P410TOAR30ROW_SME) |
8651 | | if (TestCpuFlag(kCpuHasSME)) { |
8652 | | P410ToAR30Row = P410ToAR30Row_SME; |
8653 | | } |
8654 | | #endif |
8655 | |
|
8656 | 0 | #ifdef HAS_SCALEUVROWUP2_LINEAR_16_SSE41 |
8657 | 0 | if (TestCpuFlag(kCpuHasSSE41)) { |
8658 | 0 | ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_SSE41; |
8659 | 0 | } |
8660 | 0 | #endif |
8661 | |
|
8662 | 0 | #ifdef HAS_SCALEUVROWUP2_LINEAR_16_AVX2 |
8663 | 0 | if (TestCpuFlag(kCpuHasAVX2)) { |
8664 | 0 | ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_AVX2; |
8665 | 0 | } |
8666 | 0 | #endif |
8667 | |
|
8668 | | #ifdef HAS_SCALEUVROWUP2_LINEAR_16_NEON |
8669 | | if (TestCpuFlag(kCpuHasNEON)) { |
8670 | | ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_NEON; |
8671 | | } |
8672 | | #endif |
8673 | |
|
8674 | 0 | const int row_size = (2 * width + 31) & ~31; |
8675 | 0 | align_buffer_64(row, row_size * sizeof(uint16_t)); |
8676 | 0 | uint16_t* temp_uv = (uint16_t*)(row); |
8677 | 0 | if (!row) |
8678 | 0 | return 1; |
8679 | | |
8680 | 0 | for (y = 0; y < height; ++y) { |
8681 | 0 | ScaleRowUp2_Linear(src_uv, temp_uv, width); |
8682 | 0 | P410ToAR30Row(src_y, temp_uv, dst_ar30, yuvconstants, width); |
8683 | 0 | dst_ar30 += dst_stride_ar30; |
8684 | 0 | src_y += src_stride_y; |
8685 | 0 | src_uv += src_stride_uv; |
8686 | 0 | } |
8687 | |
|
8688 | 0 | free_aligned_buffer_64(row); |
8689 | 0 | return 0; |
8690 | 0 | } |
8691 | | |
8692 | | static int I422ToRGB24MatrixLinear(const uint8_t* src_y, |
8693 | | int src_stride_y, |
8694 | | const uint8_t* src_u, |
8695 | | int src_stride_u, |
8696 | | const uint8_t* src_v, |
8697 | | int src_stride_v, |
8698 | | uint8_t* dst_rgb24, |
8699 | | int dst_stride_rgb24, |
8700 | | const struct YuvConstants* yuvconstants, |
8701 | | int width, |
8702 | 164 | int height) { |
8703 | 164 | int y; |
8704 | 164 | void (*I444ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf, |
8705 | 164 | const uint8_t* v_buf, uint8_t* rgb_buf, |
8706 | 164 | const struct YuvConstants* yuvconstants, int width) = |
8707 | 164 | I444ToRGB24Row_C; |
8708 | 164 | void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, |
8709 | 164 | int dst_width) = ScaleRowUp2_Linear_Any_C; |
8710 | 164 | assert(yuvconstants); |
8711 | 164 | if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || |
8712 | 164 | height == INT_MIN) { |
8713 | 0 | return -1; |
8714 | 0 | } |
8715 | | // Negative height means invert the image. |
8716 | 164 | if (height < 0) { |
8717 | 0 | height = -height; |
8718 | 0 | dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; |
8719 | 0 | dst_stride_rgb24 = -dst_stride_rgb24; |
8720 | 0 | } |
8721 | 164 | #if defined(HAS_I444TORGB24ROW_SSSE3) |
8722 | 164 | if (TestCpuFlag(kCpuHasSSSE3)) { |
8723 | 164 | I444ToRGB24Row = I444ToRGB24Row_Any_SSSE3; |
8724 | 164 | if (IS_ALIGNED(width, 16)) { |
8725 | 42 | I444ToRGB24Row = I444ToRGB24Row_SSSE3; |
8726 | 42 | } |
8727 | 164 | } |
8728 | 164 | #endif |
8729 | 164 | #if defined(HAS_I444TORGB24ROW_AVX2) |
8730 | 164 | if (TestCpuFlag(kCpuHasAVX2)) { |
8731 | 164 | I444ToRGB24Row = I444ToRGB24Row_Any_AVX2; |
8732 | 164 | if (IS_ALIGNED(width, 32)) { |
8733 | 25 | I444ToRGB24Row = I444ToRGB24Row_AVX2; |
8734 | 25 | } |
8735 | 164 | } |
8736 | 164 | #endif |
8737 | | #if defined(HAS_I444TORGB24ROW_NEON) |
8738 | | if (TestCpuFlag(kCpuHasNEON)) { |
8739 | | I444ToRGB24Row = I444ToRGB24Row_Any_NEON; |
8740 | | if (IS_ALIGNED(width, 8)) { |
8741 | | I444ToRGB24Row = I444ToRGB24Row_NEON; |
8742 | | } |
8743 | | } |
8744 | | #endif |
8745 | | #if defined(HAS_I444TORGB24ROW_SVE2) |
8746 | | if (TestCpuFlag(kCpuHasSVE2)) { |
8747 | | I444ToRGB24Row = I444ToRGB24Row_SVE2; |
8748 | | } |
8749 | | #endif |
8750 | | #if defined(HAS_I444TORGB24ROW_SME) |
8751 | | if (TestCpuFlag(kCpuHasSME)) { |
8752 | | I444ToRGB24Row = I444ToRGB24Row_SME; |
8753 | | } |
8754 | | #endif |
8755 | | #if defined(HAS_I444TORGB24ROW_RVV) |
8756 | | if (TestCpuFlag(kCpuHasRVV)) { |
8757 | | I444ToRGB24Row = I444ToRGB24Row_RVV; |
8758 | | } |
8759 | | #endif |
8760 | 164 | #if defined(HAS_SCALEROWUP2_LINEAR_SSE2) |
8761 | 164 | if (TestCpuFlag(kCpuHasSSE2)) { |
8762 | 164 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2; |
8763 | 164 | } |
8764 | 164 | #endif |
8765 | 164 | #if defined(HAS_SCALEROWUP2_LINEAR_SSSE3) |
8766 | 164 | if (TestCpuFlag(kCpuHasSSSE3)) { |
8767 | 164 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3; |
8768 | 164 | } |
8769 | 164 | #endif |
8770 | 164 | #if defined(HAS_SCALEROWUP2_LINEAR_AVX2) |
8771 | 164 | if (TestCpuFlag(kCpuHasAVX2)) { |
8772 | 164 | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2; |
8773 | 164 | } |
8774 | 164 | #endif |
8775 | | #if defined(HAS_SCALEROWUP2_LINEAR_NEON) |
8776 | | if (TestCpuFlag(kCpuHasNEON)) { |
8777 | | ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON; |
8778 | | } |
8779 | | #endif |
8780 | | #if defined(HAS_SCALEROWUP2_LINEAR_RVV) |
8781 | | if (TestCpuFlag(kCpuHasRVV)) { |
8782 | | ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV; |
8783 | | } |
8784 | | #endif |
8785 | | |
8786 | | // alloc 2 lines temp |
8787 | 164 | const int row_size = (width + 31) & ~31; |
8788 | 164 | align_buffer_64(row, row_size * 2); |
8789 | 164 | uint8_t* temp_u = row; |
8790 | 164 | uint8_t* temp_v = row + row_size; |
8791 | 164 | if (!row) |
8792 | 0 | return 1; |
8793 | | |
8794 | 3.03k | for (y = 0; y < height; ++y) { |
8795 | 2.87k | ScaleRowUp2_Linear(src_u, temp_u, width); |
8796 | 2.87k | ScaleRowUp2_Linear(src_v, temp_v, width); |
8797 | 2.87k | I444ToRGB24Row(src_y, temp_u, temp_v, dst_rgb24, yuvconstants, width); |
8798 | 2.87k | dst_rgb24 += dst_stride_rgb24; |
8799 | 2.87k | src_y += src_stride_y; |
8800 | 2.87k | src_u += src_stride_u; |
8801 | 2.87k | src_v += src_stride_v; |
8802 | 2.87k | } |
8803 | | |
8804 | 164 | free_aligned_buffer_64(row); |
8805 | 164 | return 0; |
8806 | 164 | } |
8807 | | |
8808 | | LIBYUV_API |
8809 | | int I422ToRGB24MatrixFilter(const uint8_t* src_y, |
8810 | | int src_stride_y, |
8811 | | const uint8_t* src_u, |
8812 | | int src_stride_u, |
8813 | | const uint8_t* src_v, |
8814 | | int src_stride_v, |
8815 | | uint8_t* dst_rgb24, |
8816 | | int dst_stride_rgb24, |
8817 | | const struct YuvConstants* yuvconstants, |
8818 | | int width, |
8819 | | int height, |
8820 | 228 | enum FilterMode filter) { |
8821 | 228 | switch (filter) { |
8822 | 64 | case kFilterNone: |
8823 | 64 | return I422ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
8824 | 64 | src_stride_v, dst_rgb24, dst_stride_rgb24, |
8825 | 64 | yuvconstants, width, height); |
8826 | 164 | case kFilterBilinear: |
8827 | 164 | case kFilterBox: |
8828 | 164 | case kFilterLinear: |
8829 | 164 | return I422ToRGB24MatrixLinear( |
8830 | 164 | src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, |
8831 | 164 | dst_rgb24, dst_stride_rgb24, yuvconstants, width, height); |
8832 | 228 | } |
8833 | | |
8834 | 0 | return -1; |
8835 | 228 | } |
8836 | | |
8837 | | LIBYUV_API |
8838 | | int I420ToARGBMatrixFilter(const uint8_t* src_y, |
8839 | | int src_stride_y, |
8840 | | const uint8_t* src_u, |
8841 | | int src_stride_u, |
8842 | | const uint8_t* src_v, |
8843 | | int src_stride_v, |
8844 | | uint8_t* dst_argb, |
8845 | | int dst_stride_argb, |
8846 | | const struct YuvConstants* yuvconstants, |
8847 | | int width, |
8848 | | int height, |
8849 | 324 | enum FilterMode filter) { |
8850 | 324 | switch (filter) { |
8851 | 178 | case kFilterNone: |
8852 | 178 | return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
8853 | 178 | src_stride_v, dst_argb, dst_stride_argb, |
8854 | 178 | yuvconstants, width, height); |
8855 | 146 | case kFilterBilinear: |
8856 | 146 | case kFilterBox: |
8857 | 146 | return I420ToARGBMatrixBilinear( |
8858 | 146 | src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, |
8859 | 146 | dst_argb, dst_stride_argb, yuvconstants, width, height); |
8860 | 0 | case kFilterLinear: |
8861 | | // Actually we can do this, but probably there's no usage. |
8862 | 0 | return -1; |
8863 | 324 | } |
8864 | | |
8865 | 0 | return -1; |
8866 | 324 | } |
8867 | | |
8868 | | LIBYUV_API |
8869 | | int I422ToARGBMatrixFilter(const uint8_t* src_y, |
8870 | | int src_stride_y, |
8871 | | const uint8_t* src_u, |
8872 | | int src_stride_u, |
8873 | | const uint8_t* src_v, |
8874 | | int src_stride_v, |
8875 | | uint8_t* dst_argb, |
8876 | | int dst_stride_argb, |
8877 | | const struct YuvConstants* yuvconstants, |
8878 | | int width, |
8879 | | int height, |
8880 | 227 | enum FilterMode filter) { |
8881 | 227 | switch (filter) { |
8882 | 120 | case kFilterNone: |
8883 | 120 | return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
8884 | 120 | src_stride_v, dst_argb, dst_stride_argb, |
8885 | 120 | yuvconstants, width, height); |
8886 | 107 | case kFilterBilinear: |
8887 | 107 | case kFilterBox: |
8888 | 107 | case kFilterLinear: |
8889 | 107 | return I422ToARGBMatrixLinear( |
8890 | 107 | src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, |
8891 | 107 | dst_argb, dst_stride_argb, yuvconstants, width, height); |
8892 | 227 | } |
8893 | | |
8894 | 0 | return -1; |
8895 | 227 | } |
8896 | | |
8897 | | LIBYUV_API |
8898 | | int I420ToRGB24MatrixFilter(const uint8_t* src_y, |
8899 | | int src_stride_y, |
8900 | | const uint8_t* src_u, |
8901 | | int src_stride_u, |
8902 | | const uint8_t* src_v, |
8903 | | int src_stride_v, |
8904 | | uint8_t* dst_rgb24, |
8905 | | int dst_stride_rgb24, |
8906 | | const struct YuvConstants* yuvconstants, |
8907 | | int width, |
8908 | | int height, |
8909 | 219 | enum FilterMode filter) { |
8910 | 219 | switch (filter) { |
8911 | 144 | case kFilterNone: |
8912 | 144 | return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
8913 | 144 | src_stride_v, dst_rgb24, dst_stride_rgb24, |
8914 | 144 | yuvconstants, width, height); |
8915 | 0 | case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 |
8916 | 75 | case kFilterBilinear: |
8917 | 75 | case kFilterBox: |
8918 | 75 | return I420ToRGB24MatrixBilinear( |
8919 | 75 | src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, |
8920 | 75 | dst_rgb24, dst_stride_rgb24, yuvconstants, width, height); |
8921 | 219 | } |
8922 | | |
8923 | 0 | return -1; |
8924 | 219 | } |
8925 | | |
8926 | | LIBYUV_API |
8927 | | int I010ToAR30MatrixFilter(const uint16_t* src_y, |
8928 | | int src_stride_y, |
8929 | | const uint16_t* src_u, |
8930 | | int src_stride_u, |
8931 | | const uint16_t* src_v, |
8932 | | int src_stride_v, |
8933 | | uint8_t* dst_ar30, |
8934 | | int dst_stride_ar30, |
8935 | | const struct YuvConstants* yuvconstants, |
8936 | | int width, |
8937 | | int height, |
8938 | 0 | enum FilterMode filter) { |
8939 | 0 | switch (filter) { |
8940 | 0 | case kFilterNone: |
8941 | 0 | return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
8942 | 0 | src_stride_v, dst_ar30, dst_stride_ar30, |
8943 | 0 | yuvconstants, width, height); |
8944 | 0 | case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 |
8945 | 0 | case kFilterBilinear: |
8946 | 0 | case kFilterBox: |
8947 | 0 | return I010ToAR30MatrixBilinear( |
8948 | 0 | src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, |
8949 | 0 | dst_ar30, dst_stride_ar30, yuvconstants, width, height); |
8950 | 0 | } |
8951 | | |
8952 | 0 | return -1; |
8953 | 0 | } |
8954 | | |
8955 | | LIBYUV_API |
8956 | | int I210ToAR30MatrixFilter(const uint16_t* src_y, |
8957 | | int src_stride_y, |
8958 | | const uint16_t* src_u, |
8959 | | int src_stride_u, |
8960 | | const uint16_t* src_v, |
8961 | | int src_stride_v, |
8962 | | uint8_t* dst_ar30, |
8963 | | int dst_stride_ar30, |
8964 | | const struct YuvConstants* yuvconstants, |
8965 | | int width, |
8966 | | int height, |
8967 | 0 | enum FilterMode filter) { |
8968 | 0 | switch (filter) { |
8969 | 0 | case kFilterNone: |
8970 | 0 | return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
8971 | 0 | src_stride_v, dst_ar30, dst_stride_ar30, |
8972 | 0 | yuvconstants, width, height); |
8973 | 0 | case kFilterBilinear: |
8974 | 0 | case kFilterBox: |
8975 | 0 | case kFilterLinear: |
8976 | 0 | return I210ToAR30MatrixLinear( |
8977 | 0 | src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, |
8978 | 0 | dst_ar30, dst_stride_ar30, yuvconstants, width, height); |
8979 | 0 | } |
8980 | | |
8981 | 0 | return -1; |
8982 | 0 | } |
8983 | | |
8984 | | LIBYUV_API |
8985 | | int I010ToARGBMatrixFilter(const uint16_t* src_y, |
8986 | | int src_stride_y, |
8987 | | const uint16_t* src_u, |
8988 | | int src_stride_u, |
8989 | | const uint16_t* src_v, |
8990 | | int src_stride_v, |
8991 | | uint8_t* dst_argb, |
8992 | | int dst_stride_argb, |
8993 | | const struct YuvConstants* yuvconstants, |
8994 | | int width, |
8995 | | int height, |
8996 | 196 | enum FilterMode filter) { |
8997 | 196 | switch (filter) { |
8998 | 110 | case kFilterNone: |
8999 | 110 | return I010ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
9000 | 110 | src_stride_v, dst_argb, dst_stride_argb, |
9001 | 110 | yuvconstants, width, height); |
9002 | 0 | case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 |
9003 | 86 | case kFilterBilinear: |
9004 | 86 | case kFilterBox: |
9005 | 86 | return I010ToARGBMatrixBilinear( |
9006 | 86 | src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, |
9007 | 86 | dst_argb, dst_stride_argb, yuvconstants, width, height); |
9008 | 196 | } |
9009 | | |
9010 | 0 | return -1; |
9011 | 196 | } |
9012 | | |
9013 | | LIBYUV_API |
9014 | | int I210ToARGBMatrixFilter(const uint16_t* src_y, |
9015 | | int src_stride_y, |
9016 | | const uint16_t* src_u, |
9017 | | int src_stride_u, |
9018 | | const uint16_t* src_v, |
9019 | | int src_stride_v, |
9020 | | uint8_t* dst_argb, |
9021 | | int dst_stride_argb, |
9022 | | const struct YuvConstants* yuvconstants, |
9023 | | int width, |
9024 | | int height, |
9025 | 177 | enum FilterMode filter) { |
9026 | 177 | switch (filter) { |
9027 | 72 | case kFilterNone: |
9028 | 72 | return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, |
9029 | 72 | src_stride_v, dst_argb, dst_stride_argb, |
9030 | 72 | yuvconstants, width, height); |
9031 | 104 | case kFilterBilinear: |
9032 | 104 | case kFilterBox: |
9033 | 104 | case kFilterLinear: |
9034 | 104 | return I210ToARGBMatrixLinear( |
9035 | 104 | src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, |
9036 | 104 | dst_argb, dst_stride_argb, yuvconstants, width, height); |
9037 | 177 | } |
9038 | | |
9039 | 0 | return -1; |
9040 | 177 | } |
9041 | | |
9042 | | LIBYUV_API |
9043 | | int I420AlphaToARGBMatrixFilter(const uint8_t* src_y, |
9044 | | int src_stride_y, |
9045 | | const uint8_t* src_u, |
9046 | | int src_stride_u, |
9047 | | const uint8_t* src_v, |
9048 | | int src_stride_v, |
9049 | | const uint8_t* src_a, |
9050 | | int src_stride_a, |
9051 | | uint8_t* dst_argb, |
9052 | | int dst_stride_argb, |
9053 | | const struct YuvConstants* yuvconstants, |
9054 | | int width, |
9055 | | int height, |
9056 | | int attenuate, |
9057 | 185 | enum FilterMode filter) { |
9058 | 185 | switch (filter) { |
9059 | 132 | case kFilterNone: |
9060 | 132 | return I420AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, |
9061 | 132 | src_v, src_stride_v, src_a, src_stride_a, |
9062 | 132 | dst_argb, dst_stride_argb, yuvconstants, |
9063 | 132 | width, height, attenuate); |
9064 | 0 | case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 |
9065 | 53 | case kFilterBilinear: |
9066 | 53 | case kFilterBox: |
9067 | 53 | return I420AlphaToARGBMatrixBilinear( |
9068 | 53 | src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, src_a, |
9069 | 53 | src_stride_a, dst_argb, dst_stride_argb, yuvconstants, width, height, |
9070 | 53 | attenuate); |
9071 | 185 | } |
9072 | | |
9073 | 0 | return -1; |
9074 | 185 | } |
9075 | | |
9076 | | LIBYUV_API |
9077 | | int I422AlphaToARGBMatrixFilter(const uint8_t* src_y, |
9078 | | int src_stride_y, |
9079 | | const uint8_t* src_u, |
9080 | | int src_stride_u, |
9081 | | const uint8_t* src_v, |
9082 | | int src_stride_v, |
9083 | | const uint8_t* src_a, |
9084 | | int src_stride_a, |
9085 | | uint8_t* dst_argb, |
9086 | | int dst_stride_argb, |
9087 | | const struct YuvConstants* yuvconstants, |
9088 | | int width, |
9089 | | int height, |
9090 | | int attenuate, |
9091 | 230 | enum FilterMode filter) { |
9092 | 230 | switch (filter) { |
9093 | 88 | case kFilterNone: |
9094 | 88 | return I422AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, |
9095 | 88 | src_v, src_stride_v, src_a, src_stride_a, |
9096 | 88 | dst_argb, dst_stride_argb, yuvconstants, |
9097 | 88 | width, height, attenuate); |
9098 | 142 | case kFilterBilinear: |
9099 | 142 | case kFilterBox: |
9100 | 142 | case kFilterLinear: |
9101 | 142 | return I422AlphaToARGBMatrixLinear( |
9102 | 142 | src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, src_a, |
9103 | 142 | src_stride_a, dst_argb, dst_stride_argb, yuvconstants, width, height, |
9104 | 142 | attenuate); |
9105 | 230 | } |
9106 | | |
9107 | 0 | return -1; |
9108 | 230 | } |
9109 | | |
9110 | | LIBYUV_API |
9111 | | int I010AlphaToARGBMatrixFilter(const uint16_t* src_y, |
9112 | | int src_stride_y, |
9113 | | const uint16_t* src_u, |
9114 | | int src_stride_u, |
9115 | | const uint16_t* src_v, |
9116 | | int src_stride_v, |
9117 | | const uint16_t* src_a, |
9118 | | int src_stride_a, |
9119 | | uint8_t* dst_argb, |
9120 | | int dst_stride_argb, |
9121 | | const struct YuvConstants* yuvconstants, |
9122 | | int width, |
9123 | | int height, |
9124 | | int attenuate, |
9125 | 168 | enum FilterMode filter) { |
9126 | 168 | switch (filter) { |
9127 | 124 | case kFilterNone: |
9128 | 124 | return I010AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, |
9129 | 124 | src_v, src_stride_v, src_a, src_stride_a, |
9130 | 124 | dst_argb, dst_stride_argb, yuvconstants, |
9131 | 124 | width, height, attenuate); |
9132 | 0 | case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 |
9133 | 44 | case kFilterBilinear: |
9134 | 44 | case kFilterBox: |
9135 | 44 | return I010AlphaToARGBMatrixBilinear( |
9136 | 44 | src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, src_a, |
9137 | 44 | src_stride_a, dst_argb, dst_stride_argb, yuvconstants, width, height, |
9138 | 44 | attenuate); |
9139 | 168 | } |
9140 | | |
9141 | 0 | return -1; |
9142 | 168 | } |
9143 | | |
9144 | | LIBYUV_API |
9145 | | int I210AlphaToARGBMatrixFilter(const uint16_t* src_y, |
9146 | | int src_stride_y, |
9147 | | const uint16_t* src_u, |
9148 | | int src_stride_u, |
9149 | | const uint16_t* src_v, |
9150 | | int src_stride_v, |
9151 | | const uint16_t* src_a, |
9152 | | int src_stride_a, |
9153 | | uint8_t* dst_argb, |
9154 | | int dst_stride_argb, |
9155 | | const struct YuvConstants* yuvconstants, |
9156 | | int width, |
9157 | | int height, |
9158 | | int attenuate, |
9159 | 214 | enum FilterMode filter) { |
9160 | 214 | switch (filter) { |
9161 | 81 | case kFilterNone: |
9162 | 81 | return I210AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, |
9163 | 81 | src_v, src_stride_v, src_a, src_stride_a, |
9164 | 81 | dst_argb, dst_stride_argb, yuvconstants, |
9165 | 81 | width, height, attenuate); |
9166 | 133 | case kFilterBilinear: |
9167 | 133 | case kFilterBox: |
9168 | 133 | case kFilterLinear: |
9169 | 133 | return I210AlphaToARGBMatrixLinear( |
9170 | 133 | src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, src_a, |
9171 | 133 | src_stride_a, dst_argb, dst_stride_argb, yuvconstants, width, height, |
9172 | 133 | attenuate); |
9173 | 214 | } |
9174 | | |
9175 | 0 | return -1; |
9176 | 214 | } |
9177 | | |
9178 | | // TODO(fb): Verify this function works correctly. P010 is like NV12 but 10 bit |
9179 | | // UV is biplanar. |
9180 | | LIBYUV_API |
9181 | | int P010ToARGBMatrixFilter(const uint16_t* src_y, |
9182 | | int src_stride_y, |
9183 | | const uint16_t* src_uv, |
9184 | | int src_stride_uv, |
9185 | | uint8_t* dst_argb, |
9186 | | int dst_stride_argb, |
9187 | | const struct YuvConstants* yuvconstants, |
9188 | | int width, |
9189 | | int height, |
9190 | 0 | enum FilterMode filter) { |
9191 | 0 | switch (filter) { |
9192 | 0 | case kFilterNone: |
9193 | 0 | return P010ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv, |
9194 | 0 | dst_argb, dst_stride_argb, yuvconstants, width, |
9195 | 0 | height); |
9196 | 0 | case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 |
9197 | 0 | case kFilterBilinear: |
9198 | 0 | case kFilterBox: |
9199 | 0 | return P010ToARGBMatrixBilinear(src_y, src_stride_y, src_uv, |
9200 | 0 | src_stride_uv, dst_argb, dst_stride_argb, |
9201 | 0 | yuvconstants, width, height); |
9202 | 0 | } |
9203 | | |
9204 | 0 | return -1; |
9205 | 0 | } |
9206 | | |
9207 | | LIBYUV_API |
9208 | | int P210ToARGBMatrixFilter(const uint16_t* src_y, |
9209 | | int src_stride_y, |
9210 | | const uint16_t* src_uv, |
9211 | | int src_stride_uv, |
9212 | | uint8_t* dst_argb, |
9213 | | int dst_stride_argb, |
9214 | | const struct YuvConstants* yuvconstants, |
9215 | | int width, |
9216 | | int height, |
9217 | 0 | enum FilterMode filter) { |
9218 | 0 | switch (filter) { |
9219 | 0 | case kFilterNone: |
9220 | 0 | return P210ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv, |
9221 | 0 | dst_argb, dst_stride_argb, yuvconstants, width, |
9222 | 0 | height); |
9223 | 0 | case kFilterBilinear: |
9224 | 0 | case kFilterBox: |
9225 | 0 | case kFilterLinear: |
9226 | 0 | return P210ToARGBMatrixLinear(src_y, src_stride_y, src_uv, src_stride_uv, |
9227 | 0 | dst_argb, dst_stride_argb, yuvconstants, |
9228 | 0 | width, height); |
9229 | 0 | } |
9230 | | |
9231 | 0 | return -1; |
9232 | 0 | } |
9233 | | |
9234 | | LIBYUV_API |
9235 | | int P010ToAR30MatrixFilter(const uint16_t* src_y, |
9236 | | int src_stride_y, |
9237 | | const uint16_t* src_uv, |
9238 | | int src_stride_uv, |
9239 | | uint8_t* dst_ar30, |
9240 | | int dst_stride_ar30, |
9241 | | const struct YuvConstants* yuvconstants, |
9242 | | int width, |
9243 | | int height, |
9244 | 0 | enum FilterMode filter) { |
9245 | 0 | switch (filter) { |
9246 | 0 | case kFilterNone: |
9247 | 0 | return P010ToAR30Matrix(src_y, src_stride_y, src_uv, src_stride_uv, |
9248 | 0 | dst_ar30, dst_stride_ar30, yuvconstants, width, |
9249 | 0 | height); |
9250 | 0 | case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 |
9251 | 0 | case kFilterBilinear: |
9252 | 0 | case kFilterBox: |
9253 | 0 | return P010ToAR30MatrixBilinear(src_y, src_stride_y, src_uv, |
9254 | 0 | src_stride_uv, dst_ar30, dst_stride_ar30, |
9255 | 0 | yuvconstants, width, height); |
9256 | 0 | } |
9257 | | |
9258 | 0 | return -1; |
9259 | 0 | } |
9260 | | |
9261 | | LIBYUV_API |
9262 | | int P210ToAR30MatrixFilter(const uint16_t* src_y, |
9263 | | int src_stride_y, |
9264 | | const uint16_t* src_uv, |
9265 | | int src_stride_uv, |
9266 | | uint8_t* dst_ar30, |
9267 | | int dst_stride_ar30, |
9268 | | const struct YuvConstants* yuvconstants, |
9269 | | int width, |
9270 | | int height, |
9271 | 0 | enum FilterMode filter) { |
9272 | 0 | switch (filter) { |
9273 | 0 | case kFilterNone: |
9274 | 0 | return P210ToAR30Matrix(src_y, src_stride_y, src_uv, src_stride_uv, |
9275 | 0 | dst_ar30, dst_stride_ar30, yuvconstants, width, |
9276 | 0 | height); |
9277 | 0 | case kFilterBilinear: |
9278 | 0 | case kFilterBox: |
9279 | 0 | case kFilterLinear: |
9280 | 0 | return P210ToAR30MatrixLinear(src_y, src_stride_y, src_uv, src_stride_uv, |
9281 | 0 | dst_ar30, dst_stride_ar30, yuvconstants, |
9282 | 0 | width, height); |
9283 | 0 | } |
9284 | | |
9285 | 0 | return -1; |
9286 | 0 | } |
9287 | | |
9288 | | #ifdef __cplusplus |
9289 | | } // extern "C" |
9290 | | } // namespace libyuv |
9291 | | #endif |