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