| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | #include "libyuv/convert.h" |
| 12 |
| 13 | #include "libyuv/basic_types.h" |
| 14 | #include "libyuv/cpu_id.h" |
| 15 | #include "libyuv/planar_functions.h" |
| 16 | #include "libyuv/rotate.h" |
| 17 | #include "libyuv/row.h" |
| 18 | #include "libyuv/scale.h" // For ScalePlane() |
| 19 | #include "libyuv/scale_row.h" // For FixedDiv |
| 20 | #include "libyuv/scale_uv.h" // For UVScale() |
| 21 |
| 22 | #ifdef __cplusplus |
| 23 | namespace libyuv { |
| 24 | extern "C" { |
| 25 | #endif |
| 26 |
| 27 | // Subsample amount uses a shift. |
| 28 | // v is value |
| 29 | // a is amount to add to round up |
| 30 | // s is shift to subsample down |
| 31 | #define SUBSAMPLE(v, a, s) (v < 0) ? (-((-v + a) >> s)) : ((v + a) >> s) |
| 32 | static __inline int Abs(int v) { |
| 33 | return v >= 0 ? v : -v; |
| 34 | } |
| 35 |
| 36 | // Any I4xx To I420 format with mirroring. |
| 37 | static int I4xxToI420(const uint8_t* src_y, |
| 38 | int src_stride_y, |
| 39 | const uint8_t* src_u, |
| 40 | int src_stride_u, |
| 41 | const uint8_t* src_v, |
| 42 | int src_stride_v, |
| 43 | uint8_t* dst_y, |
| 44 | int dst_stride_y, |
| 45 | uint8_t* dst_u, |
| 46 | int dst_stride_u, |
| 47 | uint8_t* dst_v, |
| 48 | int dst_stride_v, |
| 49 | int src_y_width, |
| 50 | int src_y_height, |
| 51 | int src_uv_width, |
| 52 | int src_uv_height) { |
| 53 | const int dst_y_width = Abs(src_y_width); |
| 54 | const int dst_y_height = Abs(src_y_height); |
| 55 | const int dst_uv_width = SUBSAMPLE(dst_y_width, 1, 1); |
| 56 | const int dst_uv_height = SUBSAMPLE(dst_y_height, 1, 1); |
| 57 | if (src_uv_width <= 0 || src_uv_height == 0) { |
| 58 | return -1; |
| 59 | } |
| 60 | if (dst_y) { |
| 61 | ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, dst_y, |
| 62 | dst_stride_y, dst_y_width, dst_y_height, kFilterBilinear); |
| 63 | } |
| 64 | ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, dst_u, |
| 65 | dst_stride_u, dst_uv_width, dst_uv_height, kFilterBilinear); |
| 66 | ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, dst_v, |
| 67 | dst_stride_v, dst_uv_width, dst_uv_height, kFilterBilinear); |
| 68 | return 0; |
| 69 | } |
| 70 |
| 71 | // Copy I420 with optional flipping. |
| 72 | // TODO(fbarchard): Use Scale plane which supports mirroring, but ensure |
| 73 | // is does row coalescing. |
| 74 | LIBYUV_API |
| 75 | int I420Copy(const uint8_t* src_y, |
| 76 | int src_stride_y, |
| 77 | const uint8_t* src_u, |
| 78 | int src_stride_u, |
| 79 | const uint8_t* src_v, |
| 80 | int src_stride_v, |
| 81 | uint8_t* dst_y, |
| 82 | int dst_stride_y, |
| 83 | uint8_t* dst_u, |
| 84 | int dst_stride_u, |
| 85 | uint8_t* dst_v, |
| 86 | int dst_stride_v, |
| 87 | int width, |
| 88 | int height) { |
| 89 | int halfwidth = (width + 1) >> 1; |
| 90 | int halfheight = (height + 1) >> 1; |
| 91 | if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || |
| 92 | height == 0) { |
| 93 | return -1; |
| 94 | } |
| 95 | // Negative height means invert the image. |
| 96 | if (height < 0) { |
| 97 | height = -height; |
| 98 | halfheight = (height + 1) >> 1; |
| 99 | src_y = src_y + (height - 1) * src_stride_y; |
| 100 | src_u = src_u + (halfheight - 1) * src_stride_u; |
| 101 | src_v = src_v + (halfheight - 1) * src_stride_v; |
| 102 | src_stride_y = -src_stride_y; |
| 103 | src_stride_u = -src_stride_u; |
| 104 | src_stride_v = -src_stride_v; |
| 105 | } |
| 106 |
| 107 | if (dst_y) { |
| 108 | CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); |
| 109 | } |
| 110 | // Copy UV planes. |
| 111 | CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, halfheight); |
| 112 | CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, halfheight); |
| 113 | return 0; |
| 114 | } |
| 115 |
| 116 | // Copy I010 with optional flipping. |
| 117 | LIBYUV_API |
| 118 | int I010Copy(const uint16_t* src_y, |
| 119 | int src_stride_y, |
| 120 | const uint16_t* src_u, |
| 121 | int src_stride_u, |
| 122 | const uint16_t* src_v, |
| 123 | int src_stride_v, |
| 124 | uint16_t* dst_y, |
| 125 | int dst_stride_y, |
| 126 | uint16_t* dst_u, |
| 127 | int dst_stride_u, |
| 128 | uint16_t* dst_v, |
| 129 | int dst_stride_v, |
| 130 | int width, |
| 131 | int height) { |
| 132 | int halfwidth = (width + 1) >> 1; |
| 133 | int halfheight = (height + 1) >> 1; |
| 134 | if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || |
| 135 | height == 0) { |
| 136 | return -1; |
| 137 | } |
| 138 | // Negative height means invert the image. |
| 139 | if (height < 0) { |
| 140 | height = -height; |
| 141 | halfheight = (height + 1) >> 1; |
| 142 | src_y = src_y + (height - 1) * src_stride_y; |
| 143 | src_u = src_u + (halfheight - 1) * src_stride_u; |
| 144 | src_v = src_v + (halfheight - 1) * src_stride_v; |
| 145 | src_stride_y = -src_stride_y; |
| 146 | src_stride_u = -src_stride_u; |
| 147 | src_stride_v = -src_stride_v; |
| 148 | } |
| 149 |
| 150 | if (dst_y) { |
| 151 | CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height); |
| 152 | } |
| 153 | // Copy UV planes. |
| 154 | CopyPlane_16(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, halfheight); |
| 155 | CopyPlane_16(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, halfheight); |
| 156 | return 0; |
| 157 | } |
| 158 |
| 159 | static int Planar16bitTo8bit(const uint16_t* src_y, |
| 160 | int src_stride_y, |
| 161 | const uint16_t* src_u, |
| 162 | int src_stride_u, |
| 163 | const uint16_t* src_v, |
| 164 | int src_stride_v, |
| 165 | uint8_t* dst_y, |
| 166 | int dst_stride_y, |
| 167 | uint8_t* dst_u, |
| 168 | int dst_stride_u, |
| 169 | uint8_t* dst_v, |
| 170 | int dst_stride_v, |
| 171 | int width, |
| 172 | int height, |
| 173 | int subsample_x, |
| 174 | int subsample_y, |
| 175 | int depth) { |
| 176 | int uv_width = SUBSAMPLE(width, subsample_x, subsample_x); |
| 177 | int uv_height = SUBSAMPLE(height, subsample_y, subsample_y); |
| 178 | int scale = 1 << (24 - depth); |
| 179 | if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || |
| 180 | height == 0) { |
| 181 | return -1; |
| 182 | } |
| 183 | // Negative height means invert the image. |
| 184 | if (height < 0) { |
| 185 | height = -height; |
| 186 | uv_height = -uv_height; |
| 187 | src_y = src_y + (height - 1) * src_stride_y; |
| 188 | src_u = src_u + (uv_height - 1) * src_stride_u; |
| 189 | src_v = src_v + (uv_height - 1) * src_stride_v; |
| 190 | src_stride_y = -src_stride_y; |
| 191 | src_stride_u = -src_stride_u; |
| 192 | src_stride_v = -src_stride_v; |
| 193 | } |
| 194 |
| 195 | // Convert Y plane. |
| 196 | Convert16To8Plane(src_y, src_stride_y, dst_y, dst_stride_y, scale, width, |
| 197 | height); |
| 198 | // Convert UV planes. |
| 199 | Convert16To8Plane(src_u, src_stride_u, dst_u, dst_stride_u, scale, uv_width, |
| 200 | uv_height); |
| 201 | Convert16To8Plane(src_v, src_stride_v, dst_v, dst_stride_v, scale, uv_width, |
| 202 | uv_height); |
| 203 | return 0; |
| 204 | } |
| 205 |
| 206 | // Convert 10 bit YUV to 8 bit. |
| 207 | LIBYUV_API |
| 208 | int I010ToI420(const uint16_t* src_y, |
| 209 | int src_stride_y, |
| 210 | const uint16_t* src_u, |
| 211 | int src_stride_u, |
| 212 | const uint16_t* src_v, |
| 213 | int src_stride_v, |
| 214 | uint8_t* dst_y, |
| 215 | int dst_stride_y, |
| 216 | uint8_t* dst_u, |
| 217 | int dst_stride_u, |
| 218 | uint8_t* dst_v, |
| 219 | int dst_stride_v, |
| 220 | int width, |
| 221 | int height) { |
| 222 | return Planar16bitTo8bit(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 223 | src_stride_v, dst_y, dst_stride_y, dst_u, |
| 224 | dst_stride_u, dst_v, dst_stride_v, width, height, 1, |
| 225 | 1, 10); |
| 226 | } |
| 227 |
| 228 | LIBYUV_API |
| 229 | int I210ToI420(const uint16_t* src_y, |
| 230 | int src_stride_y, |
| 231 | const uint16_t* src_u, |
| 232 | int src_stride_u, |
| 233 | const uint16_t* src_v, |
| 234 | int src_stride_v, |
| 235 | uint8_t* dst_y, |
| 236 | int dst_stride_y, |
| 237 | uint8_t* dst_u, |
| 238 | int dst_stride_u, |
| 239 | uint8_t* dst_v, |
| 240 | int dst_stride_v, |
| 241 | int width, |
| 242 | int height) { |
| 243 | const int depth = 10; |
| 244 | const int scale = 1 << (24 - depth); |
| 245 |
| 246 | if (width <= 0 || height == 0) { |
| 247 | return -1; |
| 248 | } |
| 249 | // Negative height means invert the image. |
| 250 | if (height < 0) { |
| 251 | height = -height; |
| 252 | src_y = src_y + (height - 1) * src_stride_y; |
| 253 | src_u = src_u + (height - 1) * src_stride_u; |
| 254 | src_v = src_v + (height - 1) * src_stride_v; |
| 255 | src_stride_y = -src_stride_y; |
| 256 | src_stride_u = -src_stride_u; |
| 257 | src_stride_v = -src_stride_v; |
| 258 | } |
| 259 |
| 260 | { |
| 261 | const int uv_width = SUBSAMPLE(width, 1, 1); |
| 262 | const int uv_height = SUBSAMPLE(height, 1, 1); |
| 263 | const int dy = FixedDiv(height, uv_height); |
| 264 |
| 265 | Convert16To8Plane(src_y, src_stride_y, dst_y, dst_stride_y, scale, width, |
| 266 | height); |
| 267 | ScalePlaneVertical_16To8(height, uv_width, uv_height, src_stride_u, |
| 268 | dst_stride_u, src_u, dst_u, 0, 32768, dy, |
| 269 | /*bpp=*/1, scale, kFilterBilinear); |
| 270 | ScalePlaneVertical_16To8(height, uv_width, uv_height, src_stride_v, |
| 271 | dst_stride_v, src_v, dst_v, 0, 32768, dy, |
| 272 | /*bpp=*/1, scale, kFilterBilinear); |
| 273 | } |
| 274 | return 0; |
| 275 | } |
| 276 |
| 277 | LIBYUV_API |
| 278 | int I210ToI422(const uint16_t* src_y, |
| 279 | int src_stride_y, |
| 280 | const uint16_t* src_u, |
| 281 | int src_stride_u, |
| 282 | const uint16_t* src_v, |
| 283 | int src_stride_v, |
| 284 | uint8_t* dst_y, |
| 285 | int dst_stride_y, |
| 286 | uint8_t* dst_u, |
| 287 | int dst_stride_u, |
| 288 | uint8_t* dst_v, |
| 289 | int dst_stride_v, |
| 290 | int width, |
| 291 | int height) { |
| 292 | return Planar16bitTo8bit(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 293 | src_stride_v, dst_y, dst_stride_y, dst_u, |
| 294 | dst_stride_u, dst_v, dst_stride_v, width, height, 1, |
| 295 | 0, 10); |
| 296 | } |
| 297 |
| 298 | LIBYUV_API |
| 299 | int I410ToI420(const uint16_t* src_y, |
| 300 | int src_stride_y, |
| 301 | const uint16_t* src_u, |
| 302 | int src_stride_u, |
| 303 | const uint16_t* src_v, |
| 304 | int src_stride_v, |
| 305 | uint8_t* dst_y, |
| 306 | int dst_stride_y, |
| 307 | uint8_t* dst_u, |
| 308 | int dst_stride_u, |
| 309 | uint8_t* dst_v, |
| 310 | int dst_stride_v, |
| 311 | int width, |
| 312 | int height) { |
| 313 | const int depth = 10; |
| 314 | const int scale = 1 << (24 - depth); |
| 315 |
| 316 | if (width <= 0 || height == 0) { |
| 317 | return -1; |
| 318 | } |
| 319 | // Negative height means invert the image. |
| 320 | if (height < 0) { |
| 321 | height = -height; |
| 322 | src_y = src_y + (height - 1) * src_stride_y; |
| 323 | src_u = src_u + (height - 1) * src_stride_u; |
| 324 | src_v = src_v + (height - 1) * src_stride_v; |
| 325 | src_stride_y = -src_stride_y; |
| 326 | src_stride_u = -src_stride_u; |
| 327 | src_stride_v = -src_stride_v; |
| 328 | } |
| 329 |
| 330 | { |
| 331 | const int uv_width = SUBSAMPLE(width, 1, 1); |
| 332 | const int uv_height = SUBSAMPLE(height, 1, 1); |
| 333 |
| 334 | Convert16To8Plane(src_y, src_stride_y, dst_y, dst_stride_y, scale, width, |
| 335 | height); |
| 336 | ScalePlaneDown2_16To8(width, height, uv_width, uv_height, src_stride_u, |
| 337 | dst_stride_u, src_u, dst_u, scale, kFilterBilinear); |
| 338 | ScalePlaneDown2_16To8(width, height, uv_width, uv_height, src_stride_v, |
| 339 | dst_stride_v, src_v, dst_v, scale, kFilterBilinear); |
| 340 | } |
| 341 | return 0; |
| 342 | } |
| 343 |
| 344 | LIBYUV_API |
| 345 | int I410ToI444(const uint16_t* src_y, |
| 346 | int src_stride_y, |
| 347 | const uint16_t* src_u, |
| 348 | int src_stride_u, |
| 349 | const uint16_t* src_v, |
| 350 | int src_stride_v, |
| 351 | uint8_t* dst_y, |
| 352 | int dst_stride_y, |
| 353 | uint8_t* dst_u, |
| 354 | int dst_stride_u, |
| 355 | uint8_t* dst_v, |
| 356 | int dst_stride_v, |
| 357 | int width, |
| 358 | int height) { |
| 359 | return Planar16bitTo8bit(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 360 | src_stride_v, dst_y, dst_stride_y, dst_u, |
| 361 | dst_stride_u, dst_v, dst_stride_v, width, height, 0, |
| 362 | 0, 10); |
| 363 | } |
| 364 |
| 365 | LIBYUV_API |
| 366 | int I012ToI420(const uint16_t* src_y, |
| 367 | int src_stride_y, |
| 368 | const uint16_t* src_u, |
| 369 | int src_stride_u, |
| 370 | const uint16_t* src_v, |
| 371 | int src_stride_v, |
| 372 | uint8_t* dst_y, |
| 373 | int dst_stride_y, |
| 374 | uint8_t* dst_u, |
| 375 | int dst_stride_u, |
| 376 | uint8_t* dst_v, |
| 377 | int dst_stride_v, |
| 378 | int width, |
| 379 | int height) { |
| 380 | return Planar16bitTo8bit(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 381 | src_stride_v, dst_y, dst_stride_y, dst_u, |
| 382 | dst_stride_u, dst_v, dst_stride_v, width, height, 1, |
| 383 | 1, 12); |
| 384 | } |
| 385 |
| 386 | LIBYUV_API |
| 387 | int I212ToI422(const uint16_t* src_y, |
| 388 | int src_stride_y, |
| 389 | const uint16_t* src_u, |
| 390 | int src_stride_u, |
| 391 | const uint16_t* src_v, |
| 392 | int src_stride_v, |
| 393 | uint8_t* dst_y, |
| 394 | int dst_stride_y, |
| 395 | uint8_t* dst_u, |
| 396 | int dst_stride_u, |
| 397 | uint8_t* dst_v, |
| 398 | int dst_stride_v, |
| 399 | int width, |
| 400 | int height) { |
| 401 | return Planar16bitTo8bit(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 402 | src_stride_v, dst_y, dst_stride_y, dst_u, |
| 403 | dst_stride_u, dst_v, dst_stride_v, width, height, 1, |
| 404 | 0, 12); |
| 405 | } |
| 406 |
| 407 | LIBYUV_API |
| 408 | int I412ToI444(const uint16_t* src_y, |
| 409 | int src_stride_y, |
| 410 | const uint16_t* src_u, |
| 411 | int src_stride_u, |
| 412 | const uint16_t* src_v, |
| 413 | int src_stride_v, |
| 414 | uint8_t* dst_y, |
| 415 | int dst_stride_y, |
| 416 | uint8_t* dst_u, |
| 417 | int dst_stride_u, |
| 418 | uint8_t* dst_v, |
| 419 | int dst_stride_v, |
| 420 | int width, |
| 421 | int height) { |
| 422 | return Planar16bitTo8bit(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 423 | src_stride_v, dst_y, dst_stride_y, dst_u, |
| 424 | dst_stride_u, dst_v, dst_stride_v, width, height, 0, |
| 425 | 0, 12); |
| 426 | } |
| 427 |
| 428 | // Any Ix10 To I010 format with mirroring. |
| 429 | static int Ix10ToI010(const uint16_t* src_y, |
| 430 | int src_stride_y, |
| 431 | const uint16_t* src_u, |
| 432 | int src_stride_u, |
| 433 | const uint16_t* src_v, |
| 434 | int src_stride_v, |
| 435 | uint16_t* dst_y, |
| 436 | int dst_stride_y, |
| 437 | uint16_t* dst_u, |
| 438 | int dst_stride_u, |
| 439 | uint16_t* dst_v, |
| 440 | int dst_stride_v, |
| 441 | int width, |
| 442 | int height, |
| 443 | int subsample_x, |
| 444 | int subsample_y) { |
| 445 | const int dst_y_width = Abs(width); |
| 446 | const int dst_y_height = Abs(height); |
| 447 | const int src_uv_width = SUBSAMPLE(width, subsample_x, subsample_x); |
| 448 | const int src_uv_height = SUBSAMPLE(height, subsample_y, subsample_y); |
| 449 | const int dst_uv_width = SUBSAMPLE(dst_y_width, 1, 1); |
| 450 | const int dst_uv_height = SUBSAMPLE(dst_y_height, 1, 1); |
| 451 | if (width <= 0 || height == 0) { |
| 452 | return -1; |
| 453 | } |
| 454 | if (dst_y) { |
| 455 | ScalePlane_12(src_y, src_stride_y, width, height, dst_y, dst_stride_y, |
| 456 | dst_y_width, dst_y_height, kFilterBilinear); |
| 457 | } |
| 458 | ScalePlane_12(src_u, src_stride_u, src_uv_width, src_uv_height, dst_u, |
| 459 | dst_stride_u, dst_uv_width, dst_uv_height, kFilterBilinear); |
| 460 | ScalePlane_12(src_v, src_stride_v, src_uv_width, src_uv_height, dst_v, |
| 461 | dst_stride_v, dst_uv_width, dst_uv_height, kFilterBilinear); |
| 462 | return 0; |
| 463 | } |
| 464 |
| 465 | LIBYUV_API |
| 466 | int I410ToI010(const uint16_t* src_y, |
| 467 | int src_stride_y, |
| 468 | const uint16_t* src_u, |
| 469 | int src_stride_u, |
| 470 | const uint16_t* src_v, |
| 471 | int src_stride_v, |
| 472 | uint16_t* dst_y, |
| 473 | int dst_stride_y, |
| 474 | uint16_t* dst_u, |
| 475 | int dst_stride_u, |
| 476 | uint16_t* dst_v, |
| 477 | int dst_stride_v, |
| 478 | int width, |
| 479 | int height) { |
| 480 | return Ix10ToI010(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 481 | src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, |
| 482 | dst_v, dst_stride_v, width, height, 0, 0); |
| 483 | } |
| 484 |
| 485 | LIBYUV_API |
| 486 | int I210ToI010(const uint16_t* src_y, |
| 487 | int src_stride_y, |
| 488 | const uint16_t* src_u, |
| 489 | int src_stride_u, |
| 490 | const uint16_t* src_v, |
| 491 | int src_stride_v, |
| 492 | uint16_t* dst_y, |
| 493 | int dst_stride_y, |
| 494 | uint16_t* dst_u, |
| 495 | int dst_stride_u, |
| 496 | uint16_t* dst_v, |
| 497 | int dst_stride_v, |
| 498 | int width, |
| 499 | int height) { |
| 500 | return Ix10ToI010(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 501 | src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, |
| 502 | dst_v, dst_stride_v, width, height, 1, 0); |
| 503 | } |
| 504 |
| 505 | // Any I[420]1[02] to P[420]1[02] format with mirroring. |
| 506 | static int IxxxToPxxx(const uint16_t* src_y, |
| 507 | int src_stride_y, |
| 508 | const uint16_t* src_u, |
| 509 | int src_stride_u, |
| 510 | const uint16_t* src_v, |
| 511 | int src_stride_v, |
| 512 | uint16_t* dst_y, |
| 513 | int dst_stride_y, |
| 514 | uint16_t* dst_uv, |
| 515 | int dst_stride_uv, |
| 516 | int width, |
| 517 | int height, |
| 518 | int subsample_x, |
| 519 | int subsample_y, |
| 520 | int depth) { |
| 521 | const int uv_width = SUBSAMPLE(width, subsample_x, subsample_x); |
| 522 | const int uv_height = SUBSAMPLE(height, subsample_y, subsample_y); |
| 523 | if (width <= 0 || height == 0) { |
| 524 | return -1; |
| 525 | } |
| 526 |
| 527 | ConvertToMSBPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height, |
| 528 | depth); |
| 529 | MergeUVPlane_16(src_u, src_stride_u, src_v, src_stride_v, dst_uv, |
| 530 | dst_stride_uv, uv_width, uv_height, depth); |
| 531 | return 0; |
| 532 | } |
| 533 |
| 534 | LIBYUV_API |
| 535 | int I010ToP010(const uint16_t* src_y, |
| 536 | int src_stride_y, |
| 537 | const uint16_t* src_u, |
| 538 | int src_stride_u, |
| 539 | const uint16_t* src_v, |
| 540 | int src_stride_v, |
| 541 | uint16_t* dst_y, |
| 542 | int dst_stride_y, |
| 543 | uint16_t* dst_uv, |
| 544 | int dst_stride_uv, |
| 545 | int width, |
| 546 | int height) { |
| 547 | return IxxxToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 548 | src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, |
| 549 | width, height, 1, 1, 10); |
| 550 | } |
| 551 |
| 552 | LIBYUV_API |
| 553 | int I210ToP210(const uint16_t* src_y, |
| 554 | int src_stride_y, |
| 555 | const uint16_t* src_u, |
| 556 | int src_stride_u, |
| 557 | const uint16_t* src_v, |
| 558 | int src_stride_v, |
| 559 | uint16_t* dst_y, |
| 560 | int dst_stride_y, |
| 561 | uint16_t* dst_uv, |
| 562 | int dst_stride_uv, |
| 563 | int width, |
| 564 | int height) { |
| 565 | return IxxxToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 566 | src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, |
| 567 | width, height, 1, 0, 10); |
| 568 | } |
| 569 |
| 570 | LIBYUV_API |
| 571 | int I012ToP012(const uint16_t* src_y, |
| 572 | int src_stride_y, |
| 573 | const uint16_t* src_u, |
| 574 | int src_stride_u, |
| 575 | const uint16_t* src_v, |
| 576 | int src_stride_v, |
| 577 | uint16_t* dst_y, |
| 578 | int dst_stride_y, |
| 579 | uint16_t* dst_uv, |
| 580 | int dst_stride_uv, |
| 581 | int width, |
| 582 | int height) { |
| 583 | return IxxxToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 584 | src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, |
| 585 | width, height, 1, 1, 12); |
| 586 | } |
| 587 |
| 588 | LIBYUV_API |
| 589 | int I212ToP212(const uint16_t* src_y, |
| 590 | int src_stride_y, |
| 591 | const uint16_t* src_u, |
| 592 | int src_stride_u, |
| 593 | const uint16_t* src_v, |
| 594 | int src_stride_v, |
| 595 | uint16_t* dst_y, |
| 596 | int dst_stride_y, |
| 597 | uint16_t* dst_uv, |
| 598 | int dst_stride_uv, |
| 599 | int width, |
| 600 | int height) { |
| 601 | return IxxxToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 602 | src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, |
| 603 | width, height, 1, 0, 12); |
| 604 | } |
| 605 |
| 606 | // 422 chroma is 1/2 width, 1x height |
| 607 | // 420 chroma is 1/2 width, 1/2 height |
| 608 | LIBYUV_API |
| 609 | int I422ToI420(const uint8_t* src_y, |
| 610 | int src_stride_y, |
| 611 | const uint8_t* src_u, |
| 612 | int src_stride_u, |
| 613 | const uint8_t* src_v, |
| 614 | int src_stride_v, |
| 615 | uint8_t* dst_y, |
| 616 | int dst_stride_y, |
| 617 | uint8_t* dst_u, |
| 618 | int dst_stride_u, |
| 619 | uint8_t* dst_v, |
| 620 | int dst_stride_v, |
| 621 | int width, |
| 622 | int height) { |
| 623 | const int src_uv_width = SUBSAMPLE(width, 1, 1); |
| 624 | return I4xxToI420(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 625 | src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, |
| 626 | dst_v, dst_stride_v, width, height, src_uv_width, height); |
| 627 | } |
| 628 |
| 629 | LIBYUV_API |
| 630 | int I422ToI210(const uint8_t* src_y, |
| 631 | int src_stride_y, |
| 632 | const uint8_t* src_u, |
| 633 | int src_stride_u, |
| 634 | const uint8_t* src_v, |
| 635 | int src_stride_v, |
| 636 | uint16_t* dst_y, |
| 637 | int dst_stride_y, |
| 638 | uint16_t* dst_u, |
| 639 | int dst_stride_u, |
| 640 | uint16_t* dst_v, |
| 641 | int dst_stride_v, |
| 642 | int width, |
| 643 | int height) { |
| 644 | int halfwidth = (width + 1) >> 1; |
| 645 | if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || |
| 646 | height == 0) { |
| 647 | return -1; |
| 648 | } |
| 649 | // Negative height means invert the image. |
| 650 | if (height < 0) { |
| 651 | height = -height; |
| 652 | src_y = src_y + (height - 1) * src_stride_y; |
| 653 | src_u = src_u + (height - 1) * src_stride_u; |
| 654 | src_v = src_v + (height - 1) * src_stride_v; |
| 655 | src_stride_y = -src_stride_y; |
| 656 | src_stride_u = -src_stride_u; |
| 657 | src_stride_v = -src_stride_v; |
| 658 | } |
| 659 |
| 660 | // Convert Y plane. |
| 661 | Convert8To16Plane(src_y, src_stride_y, dst_y, dst_stride_y, 1024, width, |
| 662 | height); |
| 663 | // Convert UV planes. |
| 664 | Convert8To16Plane(src_u, src_stride_u, dst_u, dst_stride_u, 1024, halfwidth, |
| 665 | height); |
| 666 | Convert8To16Plane(src_v, src_stride_v, dst_v, dst_stride_v, 1024, halfwidth, |
| 667 | height); |
| 668 | return 0; |
| 669 | } |
| 670 |
| 671 | // TODO(fbarchard): Implement row conversion. |
| 672 | LIBYUV_API |
| 673 | int I422ToNV21(const uint8_t* src_y, |
| 674 | int src_stride_y, |
| 675 | const uint8_t* src_u, |
| 676 | int src_stride_u, |
| 677 | const uint8_t* src_v, |
| 678 | int src_stride_v, |
| 679 | uint8_t* dst_y, |
| 680 | int dst_stride_y, |
| 681 | uint8_t* dst_vu, |
| 682 | int dst_stride_vu, |
| 683 | int width, |
| 684 | int height) { |
| 685 | int halfwidth = (width + 1) >> 1; |
| 686 | int halfheight = (height + 1) >> 1; |
| 687 | // Negative height means invert the image. |
| 688 | if (height < 0) { |
| 689 | height = -height; |
| 690 | halfheight = (height + 1) >> 1; |
| 691 | src_y = src_y + (height - 1) * src_stride_y; |
| 692 | src_u = src_u + (height - 1) * src_stride_u; |
| 693 | src_v = src_v + (height - 1) * src_stride_v; |
| 694 | src_stride_y = -src_stride_y; |
| 695 | src_stride_u = -src_stride_u; |
| 696 | src_stride_v = -src_stride_v; |
| 697 | } |
| 698 |
| 699 | // Allocate u and v buffers |
| 700 | align_buffer_64(plane_u, halfwidth * halfheight * 2); |
| 701 | uint8_t* plane_v = plane_u + halfwidth * halfheight; |
| 702 |
| 703 | I422ToI420(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, |
| 704 | dst_y, dst_stride_y, plane_u, halfwidth, plane_v, halfwidth, width, |
| 705 | height); |
| 706 | MergeUVPlane(plane_v, halfwidth, plane_u, halfwidth, dst_vu, dst_stride_vu, |
| 707 | halfwidth, halfheight); |
| 708 | free_aligned_buffer_64(plane_u); |
| 709 | return 0; |
| 710 | } |
| 711 |
| 712 | LIBYUV_API |
| 713 | int MM21ToNV12(const uint8_t* src_y, |
| 714 | int src_stride_y, |
| 715 | const uint8_t* src_uv, |
| 716 | int src_stride_uv, |
| 717 | uint8_t* dst_y, |
| 718 | int dst_stride_y, |
| 719 | uint8_t* dst_uv, |
| 720 | int dst_stride_uv, |
| 721 | int width, |
| 722 | int height) { |
| 723 | if (!src_uv || !dst_uv || width <= 0) { |
| 724 | return -1; |
| 725 | } |
| 726 |
| 727 | int sign = height < 0 ? -1 : 1; |
| 728 |
| 729 | if (dst_y) { |
| 730 | DetilePlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height, 32); |
| 731 | } |
| 732 | DetilePlane(src_uv, src_stride_uv, dst_uv, dst_stride_uv, (width + 1) & ~1, |
| 733 | (height + sign) / 2, 16); |
| 734 |
| 735 | return 0; |
| 736 | } |
| 737 |
| 738 | LIBYUV_API |
| 739 | int MM21ToI420(const uint8_t* src_y, |
| 740 | int src_stride_y, |
| 741 | const uint8_t* src_uv, |
| 742 | int src_stride_uv, |
| 743 | uint8_t* dst_y, |
| 744 | int dst_stride_y, |
| 745 | uint8_t* dst_u, |
| 746 | int dst_stride_u, |
| 747 | uint8_t* dst_v, |
| 748 | int dst_stride_v, |
| 749 | int width, |
| 750 | int height) { |
| 751 | int sign = height < 0 ? -1 : 1; |
| 752 |
| 753 | if (!src_uv || !dst_u || !dst_v || width <= 0) { |
| 754 | return -1; |
| 755 | } |
| 756 |
| 757 | if (dst_y) { |
| 758 | DetilePlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height, 32); |
| 759 | } |
| 760 | DetileSplitUVPlane(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, |
| 761 | dst_stride_v, (width + 1) & ~1, (height + sign) / 2, 16); |
| 762 |
| 763 | return 0; |
| 764 | } |
| 765 |
| 766 | LIBYUV_API |
| 767 | int MM21ToYUY2(const uint8_t* src_y, |
| 768 | int src_stride_y, |
| 769 | const uint8_t* src_uv, |
| 770 | int src_stride_uv, |
| 771 | uint8_t* dst_yuy2, |
| 772 | int dst_stride_yuy2, |
| 773 | int width, |
| 774 | int height) { |
| 775 | if (!src_y || !src_uv || !dst_yuy2 || width <= 0) { |
| 776 | return -1; |
| 777 | } |
| 778 |
| 779 | DetileToYUY2(src_y, src_stride_y, src_uv, src_stride_uv, dst_yuy2, |
| 780 | dst_stride_yuy2, width, height, 32); |
| 781 |
| 782 | return 0; |
| 783 | } |
| 784 |
| 785 | // Convert MT2T into P010. See tinyurl.com/mtk-10bit-video-format for format |
| 786 | // documentation. |
| 787 | // TODO(greenjustin): Add an MT2T to I420 conversion. |
| 788 | LIBYUV_API |
| 789 | int MT2TToP010(const uint8_t* src_y, |
| 790 | int src_stride_y, |
| 791 | const uint8_t* src_uv, |
| 792 | int src_stride_uv, |
| 793 | uint16_t* dst_y, |
| 794 | int dst_stride_y, |
| 795 | uint16_t* dst_uv, |
| 796 | int dst_stride_uv, |
| 797 | int width, |
| 798 | int height) { |
| 799 | if (width <= 0 || !height || !src_uv || !dst_uv) { |
| 800 | return -1; |
| 801 | } |
| 802 |
| 803 | { |
| 804 | int u_width = (width + 1) / 2; |
| 805 | int uv_width = 2 * u_width; |
| 806 | int y = 0; |
| 807 | int uv_height = uv_height = (height + 1) / 2; |
| 808 | const int tile_width = 16; |
| 809 | const int y_tile_height = 32; |
| 810 | const int uv_tile_height = 16; |
| 811 | int padded_width = (width + tile_width - 1) & ~(tile_width - 1); |
| 812 | int y_tile_row_size = padded_width * y_tile_height * 10 / 8; |
| 813 | int uv_tile_row_size = padded_width * uv_tile_height * 10 / 8; |
| 814 | size_t row_buf_size = padded_width * y_tile_height * sizeof(uint16_t); |
| 815 | void (*UnpackMT2T)(const uint8_t* src, uint16_t* dst, size_t size) = |
| 816 | UnpackMT2T_C; |
| 817 | align_buffer_64(row_buf, row_buf_size); |
| 818 |
| 819 | #if defined(HAS_UNPACKMT2T_NEON) |
| 820 | if (TestCpuFlag(kCpuHasNEON)) { |
| 821 | UnpackMT2T = UnpackMT2T_NEON; |
| 822 | } |
| 823 | #endif |
| 824 | // Negative height means invert the image. |
| 825 | if (height < 0) { |
| 826 | height = -height; |
| 827 | uv_height = (height + 1) / 2; |
| 828 | if (dst_y) { |
| 829 | dst_y = dst_y + (height - 1) * dst_stride_y; |
| 830 | dst_stride_y = -dst_stride_y; |
| 831 | } |
| 832 | dst_uv = dst_uv + (uv_height - 1) * dst_stride_uv; |
| 833 | dst_stride_uv = -dst_stride_uv; |
| 834 | } |
| 835 |
| 836 | // Unpack and detile Y in rows of tiles |
| 837 | if (src_y && dst_y) { |
| 838 | for (y = 0; y < (height & ~(y_tile_height - 1)); y += y_tile_height) { |
| 839 | UnpackMT2T(src_y, (uint16_t*)row_buf, y_tile_row_size); |
| 840 | DetilePlane_16((uint16_t*)row_buf, padded_width, dst_y, dst_stride_y, |
| 841 | width, y_tile_height, y_tile_height); |
| 842 | src_y += src_stride_y * y_tile_height; |
| 843 | dst_y += dst_stride_y * y_tile_height; |
| 844 | } |
| 845 | if (height & (y_tile_height - 1)) { |
| 846 | UnpackMT2T(src_y, (uint16_t*)row_buf, y_tile_row_size); |
| 847 | DetilePlane_16((uint16_t*)row_buf, padded_width, dst_y, dst_stride_y, |
| 848 | width, height & (y_tile_height - 1), y_tile_height); |
| 849 | } |
| 850 | } |
| 851 |
| 852 | // Unpack and detile UV plane |
| 853 | for (y = 0; y < (uv_height & ~(uv_tile_height - 1)); y += uv_tile_height) { |
| 854 | UnpackMT2T(src_uv, (uint16_t*)row_buf, uv_tile_row_size); |
| 855 | DetilePlane_16((uint16_t*)row_buf, padded_width, dst_uv, dst_stride_uv, |
| 856 | uv_width, uv_tile_height, uv_tile_height); |
| 857 | src_uv += src_stride_uv * uv_tile_height; |
| 858 | dst_uv += dst_stride_uv * uv_tile_height; |
| 859 | } |
| 860 | if (uv_height & (uv_tile_height - 1)) { |
| 861 | UnpackMT2T(src_uv, (uint16_t*)row_buf, uv_tile_row_size); |
| 862 | DetilePlane_16((uint16_t*)row_buf, padded_width, dst_uv, dst_stride_uv, |
| 863 | uv_width, uv_height & (uv_tile_height - 1), |
| 864 | uv_tile_height); |
| 865 | } |
| 866 | free_aligned_buffer_64(row_buf); |
| 867 | } |
| 868 | return 0; |
| 869 | } |
| 870 |
| 871 | #ifdef I422TONV21_ROW_VERSION |
| 872 | // Unittest fails for this version. |
| 873 | // 422 chroma is 1/2 width, 1x height |
| 874 | // 420 chroma is 1/2 width, 1/2 height |
| 875 | // Swap src_u and src_v to implement I422ToNV12 |
| 876 | LIBYUV_API |
| 877 | int I422ToNV21(const uint8_t* src_y, |
| 878 | int src_stride_y, |
| 879 | const uint8_t* src_u, |
| 880 | int src_stride_u, |
| 881 | const uint8_t* src_v, |
| 882 | int src_stride_v, |
| 883 | uint8_t* dst_y, |
| 884 | int dst_stride_y, |
| 885 | uint8_t* dst_vu, |
| 886 | int dst_stride_vu, |
| 887 | int width, |
| 888 | int height) { |
| 889 | int y; |
| 890 | void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, |
| 891 | uint8_t* dst_uv, int width) = MergeUVRow_C; |
| 892 | void (*InterpolateRow)(uint8_t* dst_ptr, const uint8_t* src_ptr, |
| 893 | ptrdiff_t src_stride, int dst_width, |
| 894 | int source_y_fraction) = InterpolateRow_C; |
| 895 | int halfwidth = (width + 1) >> 1; |
| 896 | int halfheight = (height + 1) >> 1; |
| 897 | if (!src_u || !src_v || !dst_vu || width <= 0 || height == 0) { |
| 898 | return -1; |
| 899 | } |
| 900 | // Negative height means invert the image. |
| 901 | if (height < 0) { |
| 902 | height = -height; |
| 903 | halfheight = (height + 1) >> 1; |
| 904 | src_y = src_y + (height - 1) * src_stride_y; |
| 905 | src_u = src_u + (halfheight - 1) * src_stride_u; |
| 906 | src_v = src_v + (halfheight - 1) * src_stride_v; |
| 907 | src_stride_y = -src_stride_y; |
| 908 | src_stride_u = -src_stride_u; |
| 909 | src_stride_v = -src_stride_v; |
| 910 | } |
| 911 | #if defined(HAS_MERGEUVROW_SSE2) |
| 912 | if (TestCpuFlag(kCpuHasSSE2)) { |
| 913 | MergeUVRow = MergeUVRow_Any_SSE2; |
| 914 | if (IS_ALIGNED(halfwidth, 16)) { |
| 915 | MergeUVRow = MergeUVRow_SSE2; |
| 916 | } |
| 917 | } |
| 918 | #endif |
| 919 | #if defined(HAS_MERGEUVROW_AVX2) |
| 920 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 921 | MergeUVRow = MergeUVRow_Any_AVX2; |
| 922 | if (IS_ALIGNED(halfwidth, 32)) { |
| 923 | MergeUVRow = MergeUVRow_AVX2; |
| 924 | } |
| 925 | } |
| 926 | #endif |
| 927 | #if defined(HAS_MERGEUVROW_NEON) |
| 928 | if (TestCpuFlag(kCpuHasNEON)) { |
| 929 | MergeUVRow = MergeUVRow_Any_NEON; |
| 930 | if (IS_ALIGNED(halfwidth, 16)) { |
| 931 | MergeUVRow = MergeUVRow_NEON; |
| 932 | } |
| 933 | } |
| 934 | #endif |
| 935 | #if defined(HAS_MERGEUVROW_MSA) |
| 936 | if (TestCpuFlag(kCpuHasMSA)) { |
| 937 | MergeUVRow = MergeUVRow_Any_MSA; |
| 938 | if (IS_ALIGNED(halfwidth, 16)) { |
| 939 | MergeUVRow = MergeUVRow_MSA; |
| 940 | } |
| 941 | } |
| 942 | #endif |
| 943 | #if defined(HAS_MERGEUVROW_LSX) |
| 944 | if (TestCpuFlag(kCpuHasLSX)) { |
| 945 | MergeUVRow = MergeUVRow_Any_LSX; |
| 946 | if (IS_ALIGNED(halfwidth, 16)) { |
| 947 | MergeUVRow = MergeUVRow_LSX; |
| 948 | } |
| 949 | } |
| 950 | #endif |
| 951 | #if defined(HAS_INTERPOLATEROW_SSSE3) |
| 952 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 953 | InterpolateRow = InterpolateRow_Any_SSSE3; |
| 954 | if (IS_ALIGNED(width, 16)) { |
| 955 | InterpolateRow = InterpolateRow_SSSE3; |
| 956 | } |
| 957 | } |
| 958 | #endif |
| 959 | #if defined(HAS_INTERPOLATEROW_AVX2) |
| 960 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 961 | InterpolateRow = InterpolateRow_Any_AVX2; |
| 962 | if (IS_ALIGNED(width, 32)) { |
| 963 | InterpolateRow = InterpolateRow_AVX2; |
| 964 | } |
| 965 | } |
| 966 | #endif |
| 967 | #if defined(HAS_INTERPOLATEROW_NEON) |
| 968 | if (TestCpuFlag(kCpuHasNEON)) { |
| 969 | InterpolateRow = InterpolateRow_Any_NEON; |
| 970 | if (IS_ALIGNED(width, 16)) { |
| 971 | InterpolateRow = InterpolateRow_NEON; |
| 972 | } |
| 973 | } |
| 974 | #endif |
| 975 | #if defined(HAS_INTERPOLATEROW_MSA) |
| 976 | if (TestCpuFlag(kCpuHasMSA)) { |
| 977 | InterpolateRow = InterpolateRow_Any_MSA; |
| 978 | if (IS_ALIGNED(width, 32)) { |
| 979 | InterpolateRow = InterpolateRow_MSA; |
| 980 | } |
| 981 | } |
| 982 | #endif |
| 983 | #if defined(HAS_INTERPOLATEROW_LSX) |
| 984 | if (TestCpuFlag(kCpuHasLSX)) { |
| 985 | InterpolateRow = InterpolateRow_Any_LSX; |
| 986 | if (IS_ALIGNED(width, 32)) { |
| 987 | InterpolateRow = InterpolateRow_LSX; |
| 988 | } |
| 989 | } |
| 990 | #endif |
| 991 |
| 992 | if (dst_y) { |
| 993 | CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, halfwidth, height); |
| 994 | } |
| 995 | { |
| 996 | // Allocate 2 rows of vu. |
| 997 | int awidth = halfwidth * 2; |
| 998 | align_buffer_64(row_vu_0, awidth * 2); |
| 999 | uint8_t* row_vu_1 = row_vu_0 + awidth; |
| 1000 |
| 1001 | for (y = 0; y < height - 1; y += 2) { |
| 1002 | MergeUVRow(src_v, src_u, row_vu_0, halfwidth); |
| 1003 | MergeUVRow(src_v + src_stride_v, src_u + src_stride_u, row_vu_1, |
| 1004 | halfwidth); |
| 1005 | InterpolateRow(dst_vu, row_vu_0, awidth, awidth, 128); |
| 1006 | src_u += src_stride_u * 2; |
| 1007 | src_v += src_stride_v * 2; |
| 1008 | dst_vu += dst_stride_vu; |
| 1009 | } |
| 1010 | if (height & 1) { |
| 1011 | MergeUVRow(src_v, src_u, dst_vu, halfwidth); |
| 1012 | } |
| 1013 | free_aligned_buffer_64(row_vu_0); |
| 1014 | } |
| 1015 | return 0; |
| 1016 | } |
| 1017 | #endif // I422TONV21_ROW_VERSION |
| 1018 |
| 1019 | // 444 chroma is 1x width, 1x height |
| 1020 | // 420 chroma is 1/2 width, 1/2 height |
| 1021 | LIBYUV_API |
| 1022 | int I444ToI420(const uint8_t* src_y, |
| 1023 | int src_stride_y, |
| 1024 | const uint8_t* src_u, |
| 1025 | int src_stride_u, |
| 1026 | const uint8_t* src_v, |
| 1027 | int src_stride_v, |
| 1028 | uint8_t* dst_y, |
| 1029 | int dst_stride_y, |
| 1030 | uint8_t* dst_u, |
| 1031 | int dst_stride_u, |
| 1032 | uint8_t* dst_v, |
| 1033 | int dst_stride_v, |
| 1034 | int width, |
| 1035 | int height) { |
| 1036 | return I4xxToI420(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 1037 | src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, |
| 1038 | dst_v, dst_stride_v, width, height, width, height); |
| 1039 | } |
| 1040 |
| 1041 | LIBYUV_API |
| 1042 | int I444ToNV12(const uint8_t* src_y, |
| 1043 | int src_stride_y, |
| 1044 | const uint8_t* src_u, |
| 1045 | int src_stride_u, |
| 1046 | const uint8_t* src_v, |
| 1047 | int src_stride_v, |
| 1048 | uint8_t* dst_y, |
| 1049 | int dst_stride_y, |
| 1050 | uint8_t* dst_uv, |
| 1051 | int dst_stride_uv, |
| 1052 | int width, |
| 1053 | int height) { |
| 1054 | if (!src_y || !src_u || !src_v || !dst_uv || width <= 0 || height == 0) { |
| 1055 | return -1; |
| 1056 | } |
| 1057 | // Negative height means invert the image. |
| 1058 | if (height < 0) { |
| 1059 | height = -height; |
| 1060 | src_y = src_y + (height - 1) * src_stride_y; |
| 1061 | src_u = src_u + (height - 1) * src_stride_u; |
| 1062 | src_v = src_v + (height - 1) * src_stride_v; |
| 1063 | src_stride_y = -src_stride_y; |
| 1064 | src_stride_u = -src_stride_u; |
| 1065 | src_stride_v = -src_stride_v; |
| 1066 | } |
| 1067 | if (dst_y) { |
| 1068 | CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); |
| 1069 | } |
| 1070 | HalfMergeUVPlane(src_u, src_stride_u, src_v, src_stride_v, dst_uv, |
| 1071 | dst_stride_uv, width, height); |
| 1072 | return 0; |
| 1073 | } |
| 1074 |
| 1075 | LIBYUV_API |
| 1076 | int I444ToNV21(const uint8_t* src_y, |
| 1077 | int src_stride_y, |
| 1078 | const uint8_t* src_u, |
| 1079 | int src_stride_u, |
| 1080 | const uint8_t* src_v, |
| 1081 | int src_stride_v, |
| 1082 | uint8_t* dst_y, |
| 1083 | int dst_stride_y, |
| 1084 | uint8_t* dst_vu, |
| 1085 | int dst_stride_vu, |
| 1086 | int width, |
| 1087 | int height) { |
| 1088 | return I444ToNV12(src_y, src_stride_y, src_v, src_stride_v, src_u, |
| 1089 | src_stride_u, dst_y, dst_stride_y, dst_vu, dst_stride_vu, |
| 1090 | width, height); |
| 1091 | } |
| 1092 |
| 1093 | // I400 is greyscale typically used in MJPG |
| 1094 | LIBYUV_API |
| 1095 | int I400ToI420(const uint8_t* src_y, |
| 1096 | int src_stride_y, |
| 1097 | uint8_t* dst_y, |
| 1098 | int dst_stride_y, |
| 1099 | uint8_t* dst_u, |
| 1100 | int dst_stride_u, |
| 1101 | uint8_t* dst_v, |
| 1102 | int dst_stride_v, |
| 1103 | int width, |
| 1104 | int height) { |
| 1105 | int halfwidth = (width + 1) >> 1; |
| 1106 | int halfheight = (height + 1) >> 1; |
| 1107 | if (!dst_u || !dst_v || width <= 0 || height == 0) { |
| 1108 | return -1; |
| 1109 | } |
| 1110 | // Negative height means invert the image. |
| 1111 | if (height < 0) { |
| 1112 | height = -height; |
| 1113 | halfheight = (height + 1) >> 1; |
| 1114 | src_y = src_y + (height - 1) * src_stride_y; |
| 1115 | src_stride_y = -src_stride_y; |
| 1116 | } |
| 1117 | if (dst_y) { |
| 1118 | CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); |
| 1119 | } |
| 1120 | SetPlane(dst_u, dst_stride_u, halfwidth, halfheight, 128); |
| 1121 | SetPlane(dst_v, dst_stride_v, halfwidth, halfheight, 128); |
| 1122 | return 0; |
| 1123 | } |
| 1124 |
| 1125 | // I400 is greyscale typically used in MJPG |
| 1126 | LIBYUV_API |
| 1127 | int I400ToNV21(const uint8_t* src_y, |
| 1128 | int src_stride_y, |
| 1129 | uint8_t* dst_y, |
| 1130 | int dst_stride_y, |
| 1131 | uint8_t* dst_vu, |
| 1132 | int dst_stride_vu, |
| 1133 | int width, |
| 1134 | int height) { |
| 1135 | int halfwidth = (width + 1) >> 1; |
| 1136 | int halfheight = (height + 1) >> 1; |
| 1137 | if (!dst_vu || width <= 0 || height == 0) { |
| 1138 | return -1; |
| 1139 | } |
| 1140 | // Negative height means invert the image. |
| 1141 | if (height < 0) { |
| 1142 | height = -height; |
| 1143 | halfheight = (height + 1) >> 1; |
| 1144 | src_y = src_y + (height - 1) * src_stride_y; |
| 1145 | src_stride_y = -src_stride_y; |
| 1146 | } |
| 1147 | if (dst_y) { |
| 1148 | CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); |
| 1149 | } |
| 1150 | SetPlane(dst_vu, dst_stride_vu, halfwidth * 2, halfheight, 128); |
| 1151 | return 0; |
| 1152 | } |
| 1153 |
| 1154 | // Convert NV12 to I420. |
| 1155 | // TODO(fbarchard): Consider inverting destination. Faster on ARM with prfm. |
| 1156 | LIBYUV_API |
| 1157 | int NV12ToI420(const uint8_t* src_y, |
| 1158 | int src_stride_y, |
| 1159 | const uint8_t* src_uv, |
| 1160 | int src_stride_uv, |
| 1161 | uint8_t* dst_y, |
| 1162 | int dst_stride_y, |
| 1163 | uint8_t* dst_u, |
| 1164 | int dst_stride_u, |
| 1165 | uint8_t* dst_v, |
| 1166 | int dst_stride_v, |
| 1167 | int width, |
| 1168 | int height) { |
| 1169 | int halfwidth = (width + 1) >> 1; |
| 1170 | int halfheight = (height + 1) >> 1; |
| 1171 | if (!src_uv || !dst_u || !dst_v || width <= 0 || height == 0) { |
| 1172 | return -1; |
| 1173 | } |
| 1174 | // Negative height means invert the image. |
| 1175 | if (height < 0) { |
| 1176 | height = -height; |
| 1177 | halfheight = (height + 1) >> 1; |
| 1178 | src_y = src_y + (height - 1) * src_stride_y; |
| 1179 | src_uv = src_uv + (halfheight - 1) * src_stride_uv; |
| 1180 | src_stride_y = -src_stride_y; |
| 1181 | src_stride_uv = -src_stride_uv; |
| 1182 | } |
| 1183 | // Coalesce rows. |
| 1184 | if (src_stride_y == width && dst_stride_y == width) { |
| 1185 | width *= height; |
| 1186 | height = 1; |
| 1187 | src_stride_y = dst_stride_y = 0; |
| 1188 | } |
| 1189 | // Coalesce rows. |
| 1190 | if (src_stride_uv == halfwidth * 2 && dst_stride_u == halfwidth && |
| 1191 | dst_stride_v == halfwidth) { |
| 1192 | halfwidth *= halfheight; |
| 1193 | halfheight = 1; |
| 1194 | src_stride_uv = dst_stride_u = dst_stride_v = 0; |
| 1195 | } |
| 1196 |
| 1197 | if (dst_y) { |
| 1198 | CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); |
| 1199 | } |
| 1200 |
| 1201 | // Split UV plane - NV12 / NV21 |
| 1202 | SplitUVPlane(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, dst_stride_v, |
| 1203 | halfwidth, halfheight); |
| 1204 |
| 1205 | return 0; |
| 1206 | } |
| 1207 |
| 1208 | // Convert NV21 to I420. Same as NV12 but u and v pointers swapped. |
| 1209 | LIBYUV_API |
| 1210 | int NV21ToI420(const uint8_t* src_y, |
| 1211 | int src_stride_y, |
| 1212 | const uint8_t* src_vu, |
| 1213 | int src_stride_vu, |
| 1214 | uint8_t* dst_y, |
| 1215 | int dst_stride_y, |
| 1216 | uint8_t* dst_u, |
| 1217 | int dst_stride_u, |
| 1218 | uint8_t* dst_v, |
| 1219 | int dst_stride_v, |
| 1220 | int width, |
| 1221 | int height) { |
| 1222 | return NV12ToI420(src_y, src_stride_y, src_vu, src_stride_vu, dst_y, |
| 1223 | dst_stride_y, dst_v, dst_stride_v, dst_u, dst_stride_u, |
| 1224 | width, height); |
| 1225 | } |
| 1226 |
| 1227 | LIBYUV_API |
| 1228 | int NV12ToNV24(const uint8_t* src_y, |
| 1229 | int src_stride_y, |
| 1230 | const uint8_t* src_uv, |
| 1231 | int src_stride_uv, |
| 1232 | uint8_t* dst_y, |
| 1233 | int dst_stride_y, |
| 1234 | uint8_t* dst_uv, |
| 1235 | int dst_stride_uv, |
| 1236 | int width, |
| 1237 | int height) { |
| 1238 | if (width <= 0 || height == 0) { |
| 1239 | return -1; |
| 1240 | } |
| 1241 |
| 1242 | if (dst_y) { |
| 1243 | ScalePlane(src_y, src_stride_y, width, height, dst_y, dst_stride_y, |
| 1244 | Abs(width), Abs(height), kFilterBilinear); |
| 1245 | } |
| 1246 | UVScale(src_uv, src_stride_uv, SUBSAMPLE(width, 1, 1), |
| 1247 | SUBSAMPLE(height, 1, 1), dst_uv, dst_stride_uv, Abs(width), |
| 1248 | Abs(height), kFilterBilinear); |
| 1249 | return 0; |
| 1250 | } |
| 1251 |
| 1252 | LIBYUV_API |
| 1253 | int NV16ToNV24(const uint8_t* src_y, |
| 1254 | int src_stride_y, |
| 1255 | const uint8_t* src_uv, |
| 1256 | int src_stride_uv, |
| 1257 | uint8_t* dst_y, |
| 1258 | int dst_stride_y, |
| 1259 | uint8_t* dst_uv, |
| 1260 | int dst_stride_uv, |
| 1261 | int width, |
| 1262 | int height) { |
| 1263 | if (width <= 0 || height == 0) { |
| 1264 | return -1; |
| 1265 | } |
| 1266 |
| 1267 | if (dst_y) { |
| 1268 | ScalePlane(src_y, src_stride_y, width, height, dst_y, dst_stride_y, |
| 1269 | Abs(width), Abs(height), kFilterBilinear); |
| 1270 | } |
| 1271 | UVScale(src_uv, src_stride_uv, SUBSAMPLE(width, 1, 1), height, dst_uv, |
| 1272 | dst_stride_uv, Abs(width), Abs(height), kFilterBilinear); |
| 1273 | return 0; |
| 1274 | } |
| 1275 |
| 1276 | // Any P[420]1[02] to I[420]1[02] format with mirroring. |
| 1277 | static int PxxxToIxxx(const uint16_t* src_y, |
| 1278 | int src_stride_y, |
| 1279 | const uint16_t* src_uv, |
| 1280 | int src_stride_uv, |
| 1281 | uint16_t* dst_y, |
| 1282 | int dst_stride_y, |
| 1283 | uint16_t* dst_u, |
| 1284 | int dst_stride_u, |
| 1285 | uint16_t* dst_v, |
| 1286 | int dst_stride_v, |
| 1287 | int width, |
| 1288 | int height, |
| 1289 | int subsample_x, |
| 1290 | int subsample_y, |
| 1291 | int depth) { |
| 1292 | const int uv_width = SUBSAMPLE(width, subsample_x, subsample_x); |
| 1293 | const int uv_height = SUBSAMPLE(height, subsample_y, subsample_y); |
| 1294 | if (width <= 0 || height == 0) { |
| 1295 | return -1; |
| 1296 | } |
| 1297 | ConvertToLSBPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height, |
| 1298 | depth); |
| 1299 | SplitUVPlane_16(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, |
| 1300 | dst_stride_v, uv_width, uv_height, depth); |
| 1301 | return 0; |
| 1302 | } |
| 1303 |
| 1304 | LIBYUV_API |
| 1305 | int P010ToI010(const uint16_t* src_y, |
| 1306 | int src_stride_y, |
| 1307 | const uint16_t* src_uv, |
| 1308 | int src_stride_uv, |
| 1309 | uint16_t* dst_y, |
| 1310 | int dst_stride_y, |
| 1311 | uint16_t* dst_u, |
| 1312 | int dst_stride_u, |
| 1313 | uint16_t* dst_v, |
| 1314 | int dst_stride_v, |
| 1315 | int width, |
| 1316 | int height) { |
| 1317 | return PxxxToIxxx(src_y, src_stride_y, src_uv, src_stride_uv, dst_y, |
| 1318 | dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, |
| 1319 | width, height, 1, 1, 10); |
| 1320 | } |
| 1321 |
| 1322 | LIBYUV_API |
| 1323 | int P012ToI012(const uint16_t* src_y, |
| 1324 | int src_stride_y, |
| 1325 | const uint16_t* src_uv, |
| 1326 | int src_stride_uv, |
| 1327 | uint16_t* dst_y, |
| 1328 | int dst_stride_y, |
| 1329 | uint16_t* dst_u, |
| 1330 | int dst_stride_u, |
| 1331 | uint16_t* dst_v, |
| 1332 | int dst_stride_v, |
| 1333 | int width, |
| 1334 | int height) { |
| 1335 | return PxxxToIxxx(src_y, src_stride_y, src_uv, src_stride_uv, dst_y, |
| 1336 | dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, |
| 1337 | width, height, 1, 1, 12); |
| 1338 | } |
| 1339 |
| 1340 | LIBYUV_API |
| 1341 | int P010ToP410(const uint16_t* src_y, |
| 1342 | int src_stride_y, |
| 1343 | const uint16_t* src_uv, |
| 1344 | int src_stride_uv, |
| 1345 | uint16_t* dst_y, |
| 1346 | int dst_stride_y, |
| 1347 | uint16_t* dst_uv, |
| 1348 | int dst_stride_uv, |
| 1349 | int width, |
| 1350 | int height) { |
| 1351 | if (width <= 0 || height == 0) { |
| 1352 | return -1; |
| 1353 | } |
| 1354 |
| 1355 | if (dst_y) { |
| 1356 | ScalePlane_16(src_y, src_stride_y, width, height, dst_y, dst_stride_y, |
| 1357 | Abs(width), Abs(height), kFilterBilinear); |
| 1358 | } |
| 1359 | UVScale_16(src_uv, src_stride_uv, SUBSAMPLE(width, 1, 1), |
| 1360 | SUBSAMPLE(height, 1, 1), dst_uv, dst_stride_uv, Abs(width), |
| 1361 | Abs(height), kFilterBilinear); |
| 1362 | return 0; |
| 1363 | } |
| 1364 |
| 1365 | LIBYUV_API |
| 1366 | int P210ToP410(const uint16_t* src_y, |
| 1367 | int src_stride_y, |
| 1368 | const uint16_t* src_uv, |
| 1369 | int src_stride_uv, |
| 1370 | uint16_t* dst_y, |
| 1371 | int dst_stride_y, |
| 1372 | uint16_t* dst_uv, |
| 1373 | int dst_stride_uv, |
| 1374 | int width, |
| 1375 | int height) { |
| 1376 | if (width <= 0 || height == 0) { |
| 1377 | return -1; |
| 1378 | } |
| 1379 |
| 1380 | if (dst_y) { |
| 1381 | ScalePlane_16(src_y, src_stride_y, width, height, dst_y, dst_stride_y, |
| 1382 | Abs(width), Abs(height), kFilterBilinear); |
| 1383 | } |
| 1384 | UVScale_16(src_uv, src_stride_uv, SUBSAMPLE(width, 1, 1), height, dst_uv, |
| 1385 | dst_stride_uv, Abs(width), Abs(height), kFilterBilinear); |
| 1386 | return 0; |
| 1387 | } |
| 1388 |
| 1389 | // Convert YUY2 to I420. |
| 1390 | LIBYUV_API |
| 1391 | int YUY2ToI420(const uint8_t* src_yuy2, |
| 1392 | int src_stride_yuy2, |
| 1393 | uint8_t* dst_y, |
| 1394 | int dst_stride_y, |
| 1395 | uint8_t* dst_u, |
| 1396 | int dst_stride_u, |
| 1397 | uint8_t* dst_v, |
| 1398 | int dst_stride_v, |
| 1399 | int width, |
| 1400 | int height) { |
| 1401 | int y; |
| 1402 | void (*YUY2ToUVRow)(const uint8_t* src_yuy2, int src_stride_yuy2, |
| 1403 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 1404 | YUY2ToUVRow_C; |
| 1405 | void (*YUY2ToYRow)(const uint8_t* src_yuy2, uint8_t* dst_y, int width) = |
| 1406 | YUY2ToYRow_C; |
| 1407 | // Negative height means invert the image. |
| 1408 | if (height < 0) { |
| 1409 | height = -height; |
| 1410 | src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; |
| 1411 | src_stride_yuy2 = -src_stride_yuy2; |
| 1412 | } |
| 1413 | #if defined(HAS_YUY2TOYROW_SSE2) |
| 1414 | if (TestCpuFlag(kCpuHasSSE2)) { |
| 1415 | YUY2ToUVRow = YUY2ToUVRow_Any_SSE2; |
| 1416 | YUY2ToYRow = YUY2ToYRow_Any_SSE2; |
| 1417 | if (IS_ALIGNED(width, 16)) { |
| 1418 | YUY2ToUVRow = YUY2ToUVRow_SSE2; |
| 1419 | YUY2ToYRow = YUY2ToYRow_SSE2; |
| 1420 | } |
| 1421 | } |
| 1422 | #endif |
| 1423 | #if defined(HAS_YUY2TOYROW_AVX2) |
| 1424 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 1425 | YUY2ToUVRow = YUY2ToUVRow_Any_AVX2; |
| 1426 | YUY2ToYRow = YUY2ToYRow_Any_AVX2; |
| 1427 | if (IS_ALIGNED(width, 32)) { |
| 1428 | YUY2ToUVRow = YUY2ToUVRow_AVX2; |
| 1429 | YUY2ToYRow = YUY2ToYRow_AVX2; |
| 1430 | } |
| 1431 | } |
| 1432 | #endif |
| 1433 | #if defined(HAS_YUY2TOYROW_NEON) |
| 1434 | if (TestCpuFlag(kCpuHasNEON)) { |
| 1435 | YUY2ToYRow = YUY2ToYRow_Any_NEON; |
| 1436 | YUY2ToUVRow = YUY2ToUVRow_Any_NEON; |
| 1437 | if (IS_ALIGNED(width, 16)) { |
| 1438 | YUY2ToYRow = YUY2ToYRow_NEON; |
| 1439 | YUY2ToUVRow = YUY2ToUVRow_NEON; |
| 1440 | } |
| 1441 | } |
| 1442 | #endif |
| 1443 | #if defined(HAS_YUY2TOYROW_MSA) && defined(HAS_YUY2TOUVROW_MSA) |
| 1444 | if (TestCpuFlag(kCpuHasMSA)) { |
| 1445 | YUY2ToYRow = YUY2ToYRow_Any_MSA; |
| 1446 | YUY2ToUVRow = YUY2ToUVRow_Any_MSA; |
| 1447 | if (IS_ALIGNED(width, 32)) { |
| 1448 | YUY2ToYRow = YUY2ToYRow_MSA; |
| 1449 | YUY2ToUVRow = YUY2ToUVRow_MSA; |
| 1450 | } |
| 1451 | } |
| 1452 | #endif |
| 1453 | #if defined(HAS_YUY2TOYROW_LASX) && defined(HAS_YUY2TOUVROW_LASX) |
| 1454 | if (TestCpuFlag(kCpuHasLASX)) { |
| 1455 | YUY2ToYRow = YUY2ToYRow_Any_LASX; |
| 1456 | YUY2ToUVRow = YUY2ToUVRow_Any_LASX; |
| 1457 | if (IS_ALIGNED(width, 32)) { |
| 1458 | YUY2ToYRow = YUY2ToYRow_LASX; |
| 1459 | YUY2ToUVRow = YUY2ToUVRow_LASX; |
| 1460 | } |
| 1461 | } |
| 1462 | #endif |
| 1463 |
| 1464 | for (y = 0; y < height - 1; y += 2) { |
| 1465 | YUY2ToUVRow(src_yuy2, src_stride_yuy2, dst_u, dst_v, width); |
| 1466 | YUY2ToYRow(src_yuy2, dst_y, width); |
| 1467 | YUY2ToYRow(src_yuy2 + src_stride_yuy2, dst_y + dst_stride_y, width); |
| 1468 | src_yuy2 += src_stride_yuy2 * 2; |
| 1469 | dst_y += dst_stride_y * 2; |
| 1470 | dst_u += dst_stride_u; |
| 1471 | dst_v += dst_stride_v; |
| 1472 | } |
| 1473 | if (height & 1) { |
| 1474 | YUY2ToUVRow(src_yuy2, 0, dst_u, dst_v, width); |
| 1475 | YUY2ToYRow(src_yuy2, dst_y, width); |
| 1476 | } |
| 1477 | return 0; |
| 1478 | } |
| 1479 |
| 1480 | // Convert UYVY to I420. |
| 1481 | LIBYUV_API |
| 1482 | int UYVYToI420(const uint8_t* src_uyvy, |
| 1483 | int src_stride_uyvy, |
| 1484 | uint8_t* dst_y, |
| 1485 | int dst_stride_y, |
| 1486 | uint8_t* dst_u, |
| 1487 | int dst_stride_u, |
| 1488 | uint8_t* dst_v, |
| 1489 | int dst_stride_v, |
| 1490 | int width, |
| 1491 | int height) { |
| 1492 | int y; |
| 1493 | void (*UYVYToUVRow)(const uint8_t* src_uyvy, int src_stride_uyvy, |
| 1494 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 1495 | UYVYToUVRow_C; |
| 1496 | void (*UYVYToYRow)(const uint8_t* src_uyvy, uint8_t* dst_y, int width) = |
| 1497 | UYVYToYRow_C; |
| 1498 | // Negative height means invert the image. |
| 1499 | if (height < 0) { |
| 1500 | height = -height; |
| 1501 | src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; |
| 1502 | src_stride_uyvy = -src_stride_uyvy; |
| 1503 | } |
| 1504 | #if defined(HAS_UYVYTOYROW_SSE2) |
| 1505 | if (TestCpuFlag(kCpuHasSSE2)) { |
| 1506 | UYVYToUVRow = UYVYToUVRow_Any_SSE2; |
| 1507 | UYVYToYRow = UYVYToYRow_Any_SSE2; |
| 1508 | if (IS_ALIGNED(width, 16)) { |
| 1509 | UYVYToUVRow = UYVYToUVRow_SSE2; |
| 1510 | UYVYToYRow = UYVYToYRow_SSE2; |
| 1511 | } |
| 1512 | } |
| 1513 | #endif |
| 1514 | #if defined(HAS_UYVYTOYROW_AVX2) |
| 1515 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 1516 | UYVYToUVRow = UYVYToUVRow_Any_AVX2; |
| 1517 | UYVYToYRow = UYVYToYRow_Any_AVX2; |
| 1518 | if (IS_ALIGNED(width, 32)) { |
| 1519 | UYVYToUVRow = UYVYToUVRow_AVX2; |
| 1520 | UYVYToYRow = UYVYToYRow_AVX2; |
| 1521 | } |
| 1522 | } |
| 1523 | #endif |
| 1524 | #if defined(HAS_UYVYTOYROW_NEON) |
| 1525 | if (TestCpuFlag(kCpuHasNEON)) { |
| 1526 | UYVYToYRow = UYVYToYRow_Any_NEON; |
| 1527 | UYVYToUVRow = UYVYToUVRow_Any_NEON; |
| 1528 | if (IS_ALIGNED(width, 16)) { |
| 1529 | UYVYToYRow = UYVYToYRow_NEON; |
| 1530 | UYVYToUVRow = UYVYToUVRow_NEON; |
| 1531 | } |
| 1532 | } |
| 1533 | #endif |
| 1534 | #if defined(HAS_UYVYTOYROW_MSA) |
| 1535 | if (TestCpuFlag(kCpuHasMSA)) { |
| 1536 | UYVYToYRow = UYVYToYRow_Any_MSA; |
| 1537 | UYVYToUVRow = UYVYToUVRow_Any_MSA; |
| 1538 | if (IS_ALIGNED(width, 32)) { |
| 1539 | UYVYToYRow = UYVYToYRow_MSA; |
| 1540 | UYVYToUVRow = UYVYToUVRow_MSA; |
| 1541 | } |
| 1542 | } |
| 1543 | #endif |
| 1544 | #if defined(HAS_UYVYTOYROW_LASX) |
| 1545 | if (TestCpuFlag(kCpuHasLASX)) { |
| 1546 | UYVYToYRow = UYVYToYRow_Any_LASX; |
| 1547 | UYVYToUVRow = UYVYToUVRow_Any_LASX; |
| 1548 | if (IS_ALIGNED(width, 32)) { |
| 1549 | UYVYToYRow = UYVYToYRow_LASX; |
| 1550 | UYVYToUVRow = UYVYToUVRow_LASX; |
| 1551 | } |
| 1552 | } |
| 1553 | #endif |
| 1554 |
| 1555 | for (y = 0; y < height - 1; y += 2) { |
| 1556 | UYVYToUVRow(src_uyvy, src_stride_uyvy, dst_u, dst_v, width); |
| 1557 | UYVYToYRow(src_uyvy, dst_y, width); |
| 1558 | UYVYToYRow(src_uyvy + src_stride_uyvy, dst_y + dst_stride_y, width); |
| 1559 | src_uyvy += src_stride_uyvy * 2; |
| 1560 | dst_y += dst_stride_y * 2; |
| 1561 | dst_u += dst_stride_u; |
| 1562 | dst_v += dst_stride_v; |
| 1563 | } |
| 1564 | if (height & 1) { |
| 1565 | UYVYToUVRow(src_uyvy, 0, dst_u, dst_v, width); |
| 1566 | UYVYToYRow(src_uyvy, dst_y, width); |
| 1567 | } |
| 1568 | return 0; |
| 1569 | } |
| 1570 |
| 1571 | // Convert AYUV to NV12. |
| 1572 | LIBYUV_API |
| 1573 | int AYUVToNV12(const uint8_t* src_ayuv, |
| 1574 | int src_stride_ayuv, |
| 1575 | uint8_t* dst_y, |
| 1576 | int dst_stride_y, |
| 1577 | uint8_t* dst_uv, |
| 1578 | int dst_stride_uv, |
| 1579 | int width, |
| 1580 | int height) { |
| 1581 | int y; |
| 1582 | void (*AYUVToUVRow)(const uint8_t* src_ayuv, int src_stride_ayuv, |
| 1583 | uint8_t* dst_uv, int width) = AYUVToUVRow_C; |
| 1584 | void (*AYUVToYRow)(const uint8_t* src_ayuv, uint8_t* dst_y, int width) = |
| 1585 | AYUVToYRow_C; |
| 1586 | // Negative height means invert the image. |
| 1587 | if (height < 0) { |
| 1588 | height = -height; |
| 1589 | src_ayuv = src_ayuv + (height - 1) * src_stride_ayuv; |
| 1590 | src_stride_ayuv = -src_stride_ayuv; |
| 1591 | } |
| 1592 | // place holders for future intel code |
| 1593 | #if defined(HAS_AYUVTOYROW_SSE2) |
| 1594 | if (TestCpuFlag(kCpuHasSSE2)) { |
| 1595 | AYUVToUVRow = AYUVToUVRow_Any_SSE2; |
| 1596 | AYUVToYRow = AYUVToYRow_Any_SSE2; |
| 1597 | if (IS_ALIGNED(width, 16)) { |
| 1598 | AYUVToUVRow = AYUVToUVRow_SSE2; |
| 1599 | AYUVToYRow = AYUVToYRow_SSE2; |
| 1600 | } |
| 1601 | } |
| 1602 | #endif |
| 1603 | #if defined(HAS_AYUVTOYROW_AVX2) |
| 1604 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 1605 | AYUVToUVRow = AYUVToUVRow_Any_AVX2; |
| 1606 | AYUVToYRow = AYUVToYRow_Any_AVX2; |
| 1607 | if (IS_ALIGNED(width, 32)) { |
| 1608 | AYUVToUVRow = AYUVToUVRow_AVX2; |
| 1609 | AYUVToYRow = AYUVToYRow_AVX2; |
| 1610 | } |
| 1611 | } |
| 1612 | #endif |
| 1613 |
| 1614 | #if defined(HAS_AYUVTOYROW_NEON) |
| 1615 | if (TestCpuFlag(kCpuHasNEON)) { |
| 1616 | AYUVToYRow = AYUVToYRow_Any_NEON; |
| 1617 | AYUVToUVRow = AYUVToUVRow_Any_NEON; |
| 1618 | if (IS_ALIGNED(width, 16)) { |
| 1619 | AYUVToYRow = AYUVToYRow_NEON; |
| 1620 | AYUVToUVRow = AYUVToUVRow_NEON; |
| 1621 | } |
| 1622 | } |
| 1623 | #endif |
| 1624 |
| 1625 | for (y = 0; y < height - 1; y += 2) { |
| 1626 | AYUVToUVRow(src_ayuv, src_stride_ayuv, dst_uv, width); |
| 1627 | AYUVToYRow(src_ayuv, dst_y, width); |
| 1628 | AYUVToYRow(src_ayuv + src_stride_ayuv, dst_y + dst_stride_y, width); |
| 1629 | src_ayuv += src_stride_ayuv * 2; |
| 1630 | dst_y += dst_stride_y * 2; |
| 1631 | dst_uv += dst_stride_uv; |
| 1632 | } |
| 1633 | if (height & 1) { |
| 1634 | AYUVToUVRow(src_ayuv, 0, dst_uv, width); |
| 1635 | AYUVToYRow(src_ayuv, dst_y, width); |
| 1636 | } |
| 1637 | return 0; |
| 1638 | } |
| 1639 |
| 1640 | // Convert AYUV to NV21. |
| 1641 | LIBYUV_API |
| 1642 | int AYUVToNV21(const uint8_t* src_ayuv, |
| 1643 | int src_stride_ayuv, |
| 1644 | uint8_t* dst_y, |
| 1645 | int dst_stride_y, |
| 1646 | uint8_t* dst_vu, |
| 1647 | int dst_stride_vu, |
| 1648 | int width, |
| 1649 | int height) { |
| 1650 | int y; |
| 1651 | void (*AYUVToVURow)(const uint8_t* src_ayuv, int src_stride_ayuv, |
| 1652 | uint8_t* dst_vu, int width) = AYUVToVURow_C; |
| 1653 | void (*AYUVToYRow)(const uint8_t* src_ayuv, uint8_t* dst_y, int width) = |
| 1654 | AYUVToYRow_C; |
| 1655 | // Negative height means invert the image. |
| 1656 | if (height < 0) { |
| 1657 | height = -height; |
| 1658 | src_ayuv = src_ayuv + (height - 1) * src_stride_ayuv; |
| 1659 | src_stride_ayuv = -src_stride_ayuv; |
| 1660 | } |
| 1661 | // place holders for future intel code |
| 1662 | #if defined(HAS_AYUVTOYROW_SSE2) |
| 1663 | if (TestCpuFlag(kCpuHasSSE2)) { |
| 1664 | AYUVToVURow = AYUVToVURow_Any_SSE2; |
| 1665 | AYUVToYRow = AYUVToYRow_Any_SSE2; |
| 1666 | if (IS_ALIGNED(width, 16)) { |
| 1667 | AYUVToVURow = AYUVToVURow_SSE2; |
| 1668 | AYUVToYRow = AYUVToYRow_SSE2; |
| 1669 | } |
| 1670 | } |
| 1671 | #endif |
| 1672 | #if defined(HAS_AYUVTOYROW_AVX2) |
| 1673 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 1674 | AYUVToVURow = AYUVToVURow_Any_AVX2; |
| 1675 | AYUVToYRow = AYUVToYRow_Any_AVX2; |
| 1676 | if (IS_ALIGNED(width, 32)) { |
| 1677 | AYUVToVURow = AYUVToVURow_AVX2; |
| 1678 | AYUVToYRow = AYUVToYRow_AVX2; |
| 1679 | } |
| 1680 | } |
| 1681 | #endif |
| 1682 |
| 1683 | #if defined(HAS_AYUVTOYROW_NEON) |
| 1684 | if (TestCpuFlag(kCpuHasNEON)) { |
| 1685 | AYUVToYRow = AYUVToYRow_Any_NEON; |
| 1686 | AYUVToVURow = AYUVToVURow_Any_NEON; |
| 1687 | if (IS_ALIGNED(width, 16)) { |
| 1688 | AYUVToYRow = AYUVToYRow_NEON; |
| 1689 | AYUVToVURow = AYUVToVURow_NEON; |
| 1690 | } |
| 1691 | } |
| 1692 | #endif |
| 1693 |
| 1694 | for (y = 0; y < height - 1; y += 2) { |
| 1695 | AYUVToVURow(src_ayuv, src_stride_ayuv, dst_vu, width); |
| 1696 | AYUVToYRow(src_ayuv, dst_y, width); |
| 1697 | AYUVToYRow(src_ayuv + src_stride_ayuv, dst_y + dst_stride_y, width); |
| 1698 | src_ayuv += src_stride_ayuv * 2; |
| 1699 | dst_y += dst_stride_y * 2; |
| 1700 | dst_vu += dst_stride_vu; |
| 1701 | } |
| 1702 | if (height & 1) { |
| 1703 | AYUVToVURow(src_ayuv, 0, dst_vu, width); |
| 1704 | AYUVToYRow(src_ayuv, dst_y, width); |
| 1705 | } |
| 1706 | return 0; |
| 1707 | } |
| 1708 |
| 1709 | // Convert ARGB to I420. |
| 1710 | LIBYUV_API |
| 1711 | int ARGBToI420(const uint8_t* src_argb, |
| 1712 | int src_stride_argb, |
| 1713 | uint8_t* dst_y, |
| 1714 | int dst_stride_y, |
| 1715 | uint8_t* dst_u, |
| 1716 | int dst_stride_u, |
| 1717 | uint8_t* dst_v, |
| 1718 | int dst_stride_v, |
| 1719 | int width, |
| 1720 | int height) { |
| 1721 | int y; |
| 1722 | void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, |
| 1723 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 1724 | ARGBToUVRow_C; |
| 1725 | void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = |
| 1726 | ARGBToYRow_C; |
| 1727 | if (!src_argb || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { |
| 1728 | return -1; |
| 1729 | } |
| 1730 | // Negative height means invert the image. |
| 1731 | if (height < 0) { |
| 1732 | height = -height; |
| 1733 | src_argb = src_argb + (height - 1) * src_stride_argb; |
| 1734 | src_stride_argb = -src_stride_argb; |
| 1735 | } |
| 1736 | #if defined(HAS_ARGBTOYROW_NEON) |
| 1737 | if (TestCpuFlag(kCpuHasNEON)) { |
| 1738 | ARGBToYRow = ARGBToYRow_Any_NEON; |
| 1739 | if (IS_ALIGNED(width, 16)) { |
| 1740 | ARGBToYRow = ARGBToYRow_NEON; |
| 1741 | } |
| 1742 | } |
| 1743 | #endif |
| 1744 | #if defined(HAS_ARGBTOUVROW_NEON) |
| 1745 | if (TestCpuFlag(kCpuHasNEON)) { |
| 1746 | ARGBToUVRow = ARGBToUVRow_Any_NEON; |
| 1747 | if (IS_ALIGNED(width, 16)) { |
| 1748 | ARGBToUVRow = ARGBToUVRow_NEON; |
| 1749 | } |
| 1750 | } |
| 1751 | #endif |
| 1752 | #if defined(HAS_ARGBTOYROW_SSSE3) |
| 1753 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 1754 | ARGBToYRow = ARGBToYRow_Any_SSSE3; |
| 1755 | if (IS_ALIGNED(width, 16)) { |
| 1756 | ARGBToYRow = ARGBToYRow_SSSE3; |
| 1757 | } |
| 1758 | } |
| 1759 | #endif |
| 1760 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 1761 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 1762 | ARGBToUVRow = ARGBToUVRow_Any_SSSE3; |
| 1763 | if (IS_ALIGNED(width, 16)) { |
| 1764 | ARGBToUVRow = ARGBToUVRow_SSSE3; |
| 1765 | } |
| 1766 | } |
| 1767 | #endif |
| 1768 | #if defined(HAS_ARGBTOYROW_AVX2) |
| 1769 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 1770 | ARGBToYRow = ARGBToYRow_Any_AVX2; |
| 1771 | if (IS_ALIGNED(width, 32)) { |
| 1772 | ARGBToYRow = ARGBToYRow_AVX2; |
| 1773 | } |
| 1774 | } |
| 1775 | #endif |
| 1776 | #if defined(HAS_ARGBTOUVROW_AVX2) |
| 1777 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 1778 | ARGBToUVRow = ARGBToUVRow_Any_AVX2; |
| 1779 | if (IS_ALIGNED(width, 32)) { |
| 1780 | ARGBToUVRow = ARGBToUVRow_AVX2; |
| 1781 | } |
| 1782 | } |
| 1783 | #endif |
| 1784 | #if defined(HAS_ARGBTOYROW_MSA) && defined(HAS_ARGBTOUVROW_MSA) |
| 1785 | if (TestCpuFlag(kCpuHasMSA)) { |
| 1786 | ARGBToYRow = ARGBToYRow_Any_MSA; |
| 1787 | ARGBToUVRow = ARGBToUVRow_Any_MSA; |
| 1788 | if (IS_ALIGNED(width, 16)) { |
| 1789 | ARGBToYRow = ARGBToYRow_MSA; |
| 1790 | } |
| 1791 | if (IS_ALIGNED(width, 32)) { |
| 1792 | ARGBToUVRow = ARGBToUVRow_MSA; |
| 1793 | } |
| 1794 | } |
| 1795 | #endif |
| 1796 | #if defined(HAS_ARGBTOYROW_LSX) |
| 1797 | if (TestCpuFlag(kCpuHasLSX)) { |
| 1798 | ARGBToYRow = ARGBToYRow_Any_LSX; |
| 1799 | if (IS_ALIGNED(width, 16)) { |
| 1800 | ARGBToYRow = ARGBToYRow_LSX; |
| 1801 | } |
| 1802 | } |
| 1803 | #endif |
| 1804 | #if defined(HAS_ARGBTOYROW_LASX) && defined(HAS_ARGBTOUVROW_LASX) |
| 1805 | if (TestCpuFlag(kCpuHasLASX)) { |
| 1806 | ARGBToYRow = ARGBToYRow_Any_LASX; |
| 1807 | ARGBToUVRow = ARGBToUVRow_Any_LASX; |
| 1808 | if (IS_ALIGNED(width, 32)) { |
| 1809 | ARGBToYRow = ARGBToYRow_LASX; |
| 1810 | ARGBToUVRow = ARGBToUVRow_LASX; |
| 1811 | } |
| 1812 | } |
| 1813 | #endif |
| 1814 |
| 1815 | for (y = 0; y < height - 1; y += 2) { |
| 1816 | ARGBToUVRow(src_argb, src_stride_argb, dst_u, dst_v, width); |
| 1817 | ARGBToYRow(src_argb, dst_y, width); |
| 1818 | ARGBToYRow(src_argb + src_stride_argb, dst_y + dst_stride_y, width); |
| 1819 | src_argb += src_stride_argb * 2; |
| 1820 | dst_y += dst_stride_y * 2; |
| 1821 | dst_u += dst_stride_u; |
| 1822 | dst_v += dst_stride_v; |
| 1823 | } |
| 1824 | if (height & 1) { |
| 1825 | ARGBToUVRow(src_argb, 0, dst_u, dst_v, width); |
| 1826 | ARGBToYRow(src_argb, dst_y, width); |
| 1827 | } |
| 1828 | return 0; |
| 1829 | } |
| 1830 |
| 1831 | // Convert BGRA to I420. |
| 1832 | LIBYUV_API |
| 1833 | int BGRAToI420(const uint8_t* src_bgra, |
| 1834 | int src_stride_bgra, |
| 1835 | uint8_t* dst_y, |
| 1836 | int dst_stride_y, |
| 1837 | uint8_t* dst_u, |
| 1838 | int dst_stride_u, |
| 1839 | uint8_t* dst_v, |
| 1840 | int dst_stride_v, |
| 1841 | int width, |
| 1842 | int height) { |
| 1843 | int y; |
| 1844 | void (*BGRAToUVRow)(const uint8_t* src_bgra0, int src_stride_bgra, |
| 1845 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 1846 | BGRAToUVRow_C; |
| 1847 | void (*BGRAToYRow)(const uint8_t* src_bgra, uint8_t* dst_y, int width) = |
| 1848 | BGRAToYRow_C; |
| 1849 | if (!src_bgra || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { |
| 1850 | return -1; |
| 1851 | } |
| 1852 | // Negative height means invert the image. |
| 1853 | if (height < 0) { |
| 1854 | height = -height; |
| 1855 | src_bgra = src_bgra + (height - 1) * src_stride_bgra; |
| 1856 | src_stride_bgra = -src_stride_bgra; |
| 1857 | } |
| 1858 | #if defined(HAS_BGRATOYROW_NEON) |
| 1859 | if (TestCpuFlag(kCpuHasNEON)) { |
| 1860 | BGRAToYRow = BGRAToYRow_Any_NEON; |
| 1861 | if (IS_ALIGNED(width, 16)) { |
| 1862 | BGRAToYRow = BGRAToYRow_NEON; |
| 1863 | } |
| 1864 | } |
| 1865 | #endif |
| 1866 | #if defined(HAS_BGRATOUVROW_NEON) |
| 1867 | if (TestCpuFlag(kCpuHasNEON)) { |
| 1868 | BGRAToUVRow = BGRAToUVRow_Any_NEON; |
| 1869 | if (IS_ALIGNED(width, 16)) { |
| 1870 | BGRAToUVRow = BGRAToUVRow_NEON; |
| 1871 | } |
| 1872 | } |
| 1873 | #endif |
| 1874 | #if defined(HAS_BGRATOYROW_SSSE3) |
| 1875 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 1876 | BGRAToYRow = BGRAToYRow_Any_SSSE3; |
| 1877 | if (IS_ALIGNED(width, 16)) { |
| 1878 | BGRAToYRow = BGRAToYRow_SSSE3; |
| 1879 | } |
| 1880 | } |
| 1881 | #endif |
| 1882 | #if defined(HAS_BGRATOUVROW_SSSE3) |
| 1883 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 1884 | BGRAToUVRow = BGRAToUVRow_Any_SSSE3; |
| 1885 | if (IS_ALIGNED(width, 16)) { |
| 1886 | BGRAToUVRow = BGRAToUVRow_SSSE3; |
| 1887 | } |
| 1888 | } |
| 1889 | #endif |
| 1890 | #if defined(HAS_BGRATOYROW_AVX2) |
| 1891 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 1892 | BGRAToYRow = BGRAToYRow_Any_AVX2; |
| 1893 | if (IS_ALIGNED(width, 32)) { |
| 1894 | BGRAToYRow = BGRAToYRow_AVX2; |
| 1895 | } |
| 1896 | } |
| 1897 | #endif |
| 1898 | #if defined(HAS_BGRATOUVROW_AVX2) |
| 1899 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 1900 | BGRAToUVRow = BGRAToUVRow_Any_AVX2; |
| 1901 | if (IS_ALIGNED(width, 32)) { |
| 1902 | BGRAToUVRow = BGRAToUVRow_AVX2; |
| 1903 | } |
| 1904 | } |
| 1905 | #endif |
| 1906 | #if defined(HAS_BGRATOYROW_MSA) && defined(HAS_BGRATOUVROW_MSA) |
| 1907 | if (TestCpuFlag(kCpuHasMSA)) { |
| 1908 | BGRAToYRow = BGRAToYRow_Any_MSA; |
| 1909 | BGRAToUVRow = BGRAToUVRow_Any_MSA; |
| 1910 | if (IS_ALIGNED(width, 16)) { |
| 1911 | BGRAToYRow = BGRAToYRow_MSA; |
| 1912 | } |
| 1913 | if (IS_ALIGNED(width, 32)) { |
| 1914 | BGRAToUVRow = BGRAToUVRow_MSA; |
| 1915 | } |
| 1916 | } |
| 1917 | #endif |
| 1918 | #if defined(HAS_BGRATOYROW_LSX) && defined(HAS_BGRATOUVROW_LSX) |
| 1919 | if (TestCpuFlag(kCpuHasLSX)) { |
| 1920 | BGRAToYRow = BGRAToYRow_Any_LSX; |
| 1921 | BGRAToUVRow = BGRAToUVRow_Any_LSX; |
| 1922 | if (IS_ALIGNED(width, 16)) { |
| 1923 | BGRAToYRow = BGRAToYRow_LSX; |
| 1924 | BGRAToUVRow = BGRAToUVRow_LSX; |
| 1925 | } |
| 1926 | } |
| 1927 | #endif |
| 1928 | #if defined(HAS_BGRATOYROW_LASX) |
| 1929 | if (TestCpuFlag(kCpuHasLASX)) { |
| 1930 | BGRAToYRow = BGRAToYRow_Any_LASX; |
| 1931 | if (IS_ALIGNED(width, 32)) { |
| 1932 | BGRAToYRow = BGRAToYRow_LASX; |
| 1933 | } |
| 1934 | } |
| 1935 | #endif |
| 1936 |
| 1937 | for (y = 0; y < height - 1; y += 2) { |
| 1938 | BGRAToUVRow(src_bgra, src_stride_bgra, dst_u, dst_v, width); |
| 1939 | BGRAToYRow(src_bgra, dst_y, width); |
| 1940 | BGRAToYRow(src_bgra + src_stride_bgra, dst_y + dst_stride_y, width); |
| 1941 | src_bgra += src_stride_bgra * 2; |
| 1942 | dst_y += dst_stride_y * 2; |
| 1943 | dst_u += dst_stride_u; |
| 1944 | dst_v += dst_stride_v; |
| 1945 | } |
| 1946 | if (height & 1) { |
| 1947 | BGRAToUVRow(src_bgra, 0, dst_u, dst_v, width); |
| 1948 | BGRAToYRow(src_bgra, dst_y, width); |
| 1949 | } |
| 1950 | return 0; |
| 1951 | } |
| 1952 |
| 1953 | // Convert ABGR to I420. |
| 1954 | LIBYUV_API |
| 1955 | int ABGRToI420(const uint8_t* src_abgr, |
| 1956 | int src_stride_abgr, |
| 1957 | uint8_t* dst_y, |
| 1958 | int dst_stride_y, |
| 1959 | uint8_t* dst_u, |
| 1960 | int dst_stride_u, |
| 1961 | uint8_t* dst_v, |
| 1962 | int dst_stride_v, |
| 1963 | int width, |
| 1964 | int height) { |
| 1965 | int y; |
| 1966 | void (*ABGRToUVRow)(const uint8_t* src_abgr0, int src_stride_abgr, |
| 1967 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 1968 | ABGRToUVRow_C; |
| 1969 | void (*ABGRToYRow)(const uint8_t* src_abgr, uint8_t* dst_y, int width) = |
| 1970 | ABGRToYRow_C; |
| 1971 | if (!src_abgr || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { |
| 1972 | return -1; |
| 1973 | } |
| 1974 | // Negative height means invert the image. |
| 1975 | if (height < 0) { |
| 1976 | height = -height; |
| 1977 | src_abgr = src_abgr + (height - 1) * src_stride_abgr; |
| 1978 | src_stride_abgr = -src_stride_abgr; |
| 1979 | } |
| 1980 | #if defined(HAS_ABGRTOYROW_SSSE3) |
| 1981 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 1982 | ABGRToYRow = ABGRToYRow_Any_SSSE3; |
| 1983 | if (IS_ALIGNED(width, 16)) { |
| 1984 | ABGRToYRow = ABGRToYRow_SSSE3; |
| 1985 | } |
| 1986 | } |
| 1987 | #endif |
| 1988 | #if defined(HAS_ABGRTOUVROW_SSSE3) |
| 1989 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 1990 | ABGRToUVRow = ABGRToUVRow_Any_SSSE3; |
| 1991 | if (IS_ALIGNED(width, 16)) { |
| 1992 | ABGRToUVRow = ABGRToUVRow_SSSE3; |
| 1993 | } |
| 1994 | } |
| 1995 | #endif |
| 1996 | #if defined(HAS_ABGRTOYROW_AVX2) |
| 1997 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 1998 | ABGRToYRow = ABGRToYRow_Any_AVX2; |
| 1999 | if (IS_ALIGNED(width, 32)) { |
| 2000 | ABGRToYRow = ABGRToYRow_AVX2; |
| 2001 | } |
| 2002 | } |
| 2003 | #endif |
| 2004 | #if defined(HAS_ABGRTOUVROW_AVX2) |
| 2005 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 2006 | ABGRToUVRow = ABGRToUVRow_Any_AVX2; |
| 2007 | if (IS_ALIGNED(width, 32)) { |
| 2008 | ABGRToUVRow = ABGRToUVRow_AVX2; |
| 2009 | } |
| 2010 | } |
| 2011 | #endif |
| 2012 | #if defined(HAS_ABGRTOYROW_NEON) |
| 2013 | if (TestCpuFlag(kCpuHasNEON)) { |
| 2014 | ABGRToYRow = ABGRToYRow_Any_NEON; |
| 2015 | if (IS_ALIGNED(width, 16)) { |
| 2016 | ABGRToYRow = ABGRToYRow_NEON; |
| 2017 | } |
| 2018 | } |
| 2019 | #endif |
| 2020 | #if defined(HAS_ABGRTOUVROW_NEON) |
| 2021 | if (TestCpuFlag(kCpuHasNEON)) { |
| 2022 | ABGRToUVRow = ABGRToUVRow_Any_NEON; |
| 2023 | if (IS_ALIGNED(width, 16)) { |
| 2024 | ABGRToUVRow = ABGRToUVRow_NEON; |
| 2025 | } |
| 2026 | } |
| 2027 | #endif |
| 2028 | #if defined(HAS_ABGRTOYROW_MSA) && defined(HAS_ABGRTOUVROW_MSA) |
| 2029 | if (TestCpuFlag(kCpuHasMSA)) { |
| 2030 | ABGRToYRow = ABGRToYRow_Any_MSA; |
| 2031 | ABGRToUVRow = ABGRToUVRow_Any_MSA; |
| 2032 | if (IS_ALIGNED(width, 16)) { |
| 2033 | ABGRToYRow = ABGRToYRow_MSA; |
| 2034 | ABGRToUVRow = ABGRToUVRow_MSA; |
| 2035 | } |
| 2036 | } |
| 2037 | #endif |
| 2038 | #if defined(HAS_ABGRTOYROW_LSX) && defined(HAS_ABGRTOUVROW_LSX) |
| 2039 | if (TestCpuFlag(kCpuHasLSX)) { |
| 2040 | ABGRToYRow = ABGRToYRow_Any_LSX; |
| 2041 | ABGRToUVRow = ABGRToUVRow_Any_LSX; |
| 2042 | if (IS_ALIGNED(width, 16)) { |
| 2043 | ABGRToYRow = ABGRToYRow_LSX; |
| 2044 | ABGRToUVRow = ABGRToUVRow_LSX; |
| 2045 | } |
| 2046 | } |
| 2047 | #endif |
| 2048 | #if defined(HAS_ABGRTOYROW_LASX) |
| 2049 | if (TestCpuFlag(kCpuHasLASX)) { |
| 2050 | ABGRToYRow = ABGRToYRow_Any_LASX; |
| 2051 | if (IS_ALIGNED(width, 32)) { |
| 2052 | ABGRToYRow = ABGRToYRow_LASX; |
| 2053 | } |
| 2054 | } |
| 2055 | #endif |
| 2056 |
| 2057 | for (y = 0; y < height - 1; y += 2) { |
| 2058 | ABGRToUVRow(src_abgr, src_stride_abgr, dst_u, dst_v, width); |
| 2059 | ABGRToYRow(src_abgr, dst_y, width); |
| 2060 | ABGRToYRow(src_abgr + src_stride_abgr, dst_y + dst_stride_y, width); |
| 2061 | src_abgr += src_stride_abgr * 2; |
| 2062 | dst_y += dst_stride_y * 2; |
| 2063 | dst_u += dst_stride_u; |
| 2064 | dst_v += dst_stride_v; |
| 2065 | } |
| 2066 | if (height & 1) { |
| 2067 | ABGRToUVRow(src_abgr, 0, dst_u, dst_v, width); |
| 2068 | ABGRToYRow(src_abgr, dst_y, width); |
| 2069 | } |
| 2070 | return 0; |
| 2071 | } |
| 2072 |
| 2073 | // Convert RGBA to I420. |
| 2074 | LIBYUV_API |
| 2075 | int RGBAToI420(const uint8_t* src_rgba, |
| 2076 | int src_stride_rgba, |
| 2077 | uint8_t* dst_y, |
| 2078 | int dst_stride_y, |
| 2079 | uint8_t* dst_u, |
| 2080 | int dst_stride_u, |
| 2081 | uint8_t* dst_v, |
| 2082 | int dst_stride_v, |
| 2083 | int width, |
| 2084 | int height) { |
| 2085 | int y; |
| 2086 | void (*RGBAToUVRow)(const uint8_t* src_rgba0, int src_stride_rgba, |
| 2087 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 2088 | RGBAToUVRow_C; |
| 2089 | void (*RGBAToYRow)(const uint8_t* src_rgba, uint8_t* dst_y, int width) = |
| 2090 | RGBAToYRow_C; |
| 2091 | if (!src_rgba || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { |
| 2092 | return -1; |
| 2093 | } |
| 2094 | // Negative height means invert the image. |
| 2095 | if (height < 0) { |
| 2096 | height = -height; |
| 2097 | src_rgba = src_rgba + (height - 1) * src_stride_rgba; |
| 2098 | src_stride_rgba = -src_stride_rgba; |
| 2099 | } |
| 2100 | #if defined(HAS_RGBATOYROW_SSSE3) |
| 2101 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2102 | RGBAToYRow = RGBAToYRow_Any_SSSE3; |
| 2103 | if (IS_ALIGNED(width, 16)) { |
| 2104 | RGBAToYRow = RGBAToYRow_SSSE3; |
| 2105 | } |
| 2106 | } |
| 2107 | #endif |
| 2108 | #if defined(HAS_RGBATOUVROW_SSSE3) |
| 2109 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2110 | RGBAToUVRow = RGBAToUVRow_Any_SSSE3; |
| 2111 | if (IS_ALIGNED(width, 16)) { |
| 2112 | RGBAToUVRow = RGBAToUVRow_SSSE3; |
| 2113 | } |
| 2114 | } |
| 2115 | #endif |
| 2116 | #if defined(HAS_RGBATOYROW_NEON) |
| 2117 | if (TestCpuFlag(kCpuHasNEON)) { |
| 2118 | RGBAToYRow = RGBAToYRow_Any_NEON; |
| 2119 | if (IS_ALIGNED(width, 16)) { |
| 2120 | RGBAToYRow = RGBAToYRow_NEON; |
| 2121 | } |
| 2122 | } |
| 2123 | #endif |
| 2124 | #if defined(HAS_RGBATOUVROW_NEON) |
| 2125 | if (TestCpuFlag(kCpuHasNEON)) { |
| 2126 | RGBAToUVRow = RGBAToUVRow_Any_NEON; |
| 2127 | if (IS_ALIGNED(width, 16)) { |
| 2128 | RGBAToUVRow = RGBAToUVRow_NEON; |
| 2129 | } |
| 2130 | } |
| 2131 | #endif |
| 2132 | #if defined(HAS_RGBATOYROW_MSA) && defined(HAS_RGBATOUVROW_MSA) |
| 2133 | if (TestCpuFlag(kCpuHasMSA)) { |
| 2134 | RGBAToYRow = RGBAToYRow_Any_MSA; |
| 2135 | RGBAToUVRow = RGBAToUVRow_Any_MSA; |
| 2136 | if (IS_ALIGNED(width, 16)) { |
| 2137 | RGBAToYRow = RGBAToYRow_MSA; |
| 2138 | RGBAToUVRow = RGBAToUVRow_MSA; |
| 2139 | } |
| 2140 | } |
| 2141 | #endif |
| 2142 | #if defined(HAS_RGBATOYROW_LSX) && defined(HAS_RGBATOUVROW_LSX) |
| 2143 | if (TestCpuFlag(kCpuHasLSX)) { |
| 2144 | RGBAToYRow = RGBAToYRow_Any_LSX; |
| 2145 | RGBAToUVRow = RGBAToUVRow_Any_LSX; |
| 2146 | if (IS_ALIGNED(width, 16)) { |
| 2147 | RGBAToYRow = RGBAToYRow_LSX; |
| 2148 | RGBAToUVRow = RGBAToUVRow_LSX; |
| 2149 | } |
| 2150 | } |
| 2151 | #endif |
| 2152 | #if defined(HAS_RGBATOYROW_LASX) |
| 2153 | if (TestCpuFlag(kCpuHasNEON)) { |
| 2154 | RGBAToYRow = RGBAToYRow_Any_LASX; |
| 2155 | if (IS_ALIGNED(width, 32)) { |
| 2156 | RGBAToYRow = RGBAToYRow_LASX; |
| 2157 | } |
| 2158 | } |
| 2159 | #endif |
| 2160 |
| 2161 | for (y = 0; y < height - 1; y += 2) { |
| 2162 | RGBAToUVRow(src_rgba, src_stride_rgba, dst_u, dst_v, width); |
| 2163 | RGBAToYRow(src_rgba, dst_y, width); |
| 2164 | RGBAToYRow(src_rgba + src_stride_rgba, dst_y + dst_stride_y, width); |
| 2165 | src_rgba += src_stride_rgba * 2; |
| 2166 | dst_y += dst_stride_y * 2; |
| 2167 | dst_u += dst_stride_u; |
| 2168 | dst_v += dst_stride_v; |
| 2169 | } |
| 2170 | if (height & 1) { |
| 2171 | RGBAToUVRow(src_rgba, 0, dst_u, dst_v, width); |
| 2172 | RGBAToYRow(src_rgba, dst_y, width); |
| 2173 | } |
| 2174 | return 0; |
| 2175 | } |
| 2176 |
| 2177 | // Enabled if 1 pass is available |
| 2178 | #if (defined(HAS_RGB24TOYROW_NEON) || defined(HAS_RGB24TOYROW_MSA) || \ |
| 2179 | defined(HAS_RGB24TOYROW_LSX)) |
| 2180 | #define HAS_RGB24TOYROW |
| 2181 | #endif |
| 2182 |
| 2183 | // Convert RGB24 to I420. |
| 2184 | LIBYUV_API |
| 2185 | int RGB24ToI420(const uint8_t* src_rgb24, |
| 2186 | int src_stride_rgb24, |
| 2187 | uint8_t* dst_y, |
| 2188 | int dst_stride_y, |
| 2189 | uint8_t* dst_u, |
| 2190 | int dst_stride_u, |
| 2191 | uint8_t* dst_v, |
| 2192 | int dst_stride_v, |
| 2193 | int width, |
| 2194 | int height) { |
| 2195 | int y; |
| 2196 | #if defined(HAS_RGB24TOYROW) |
| 2197 | void (*RGB24ToUVRow)(const uint8_t* src_rgb24, int src_stride_rgb24, |
| 2198 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 2199 | RGB24ToUVRow_C; |
| 2200 | void (*RGB24ToYRow)(const uint8_t* src_rgb24, uint8_t* dst_y, int width) = |
| 2201 | RGB24ToYRow_C; |
| 2202 | #else |
| 2203 | void (*RGB24ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = |
| 2204 | RGB24ToARGBRow_C; |
| 2205 | void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, |
| 2206 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 2207 | ARGBToUVRow_C; |
| 2208 | void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = |
| 2209 | ARGBToYRow_C; |
| 2210 | #endif |
| 2211 | if (!src_rgb24 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { |
| 2212 | return -1; |
| 2213 | } |
| 2214 | // Negative height means invert the image. |
| 2215 | if (height < 0) { |
| 2216 | height = -height; |
| 2217 | src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; |
| 2218 | src_stride_rgb24 = -src_stride_rgb24; |
| 2219 | } |
| 2220 |
| 2221 | #if defined(HAS_RGB24TOYROW) |
| 2222 |
| 2223 | // Neon version does direct RGB24 to YUV. |
| 2224 | #if defined(HAS_RGB24TOYROW_NEON) && defined(HAS_RGB24TOUVROW_NEON) |
| 2225 | if (TestCpuFlag(kCpuHasNEON)) { |
| 2226 | RGB24ToUVRow = RGB24ToUVRow_Any_NEON; |
| 2227 | RGB24ToYRow = RGB24ToYRow_Any_NEON; |
| 2228 | if (IS_ALIGNED(width, 16)) { |
| 2229 | RGB24ToYRow = RGB24ToYRow_NEON; |
| 2230 | RGB24ToUVRow = RGB24ToUVRow_NEON; |
| 2231 | } |
| 2232 | } |
| 2233 | #endif |
| 2234 | #if defined(HAS_RGB24TOYROW_MSA) && defined(HAS_RGB24TOUVROW_MSA) |
| 2235 | if (TestCpuFlag(kCpuHasMSA)) { |
| 2236 | RGB24ToUVRow = RGB24ToUVRow_Any_MSA; |
| 2237 | RGB24ToYRow = RGB24ToYRow_Any_MSA; |
| 2238 | if (IS_ALIGNED(width, 16)) { |
| 2239 | RGB24ToYRow = RGB24ToYRow_MSA; |
| 2240 | RGB24ToUVRow = RGB24ToUVRow_MSA; |
| 2241 | } |
| 2242 | } |
| 2243 | #endif |
| 2244 | #if defined(HAS_RGB24TOYROW_LSX) && defined(HAS_RGB24TOUVROW_LSX) |
| 2245 | if (TestCpuFlag(kCpuHasLSX)) { |
| 2246 | RGB24ToUVRow = RGB24ToUVRow_Any_LSX; |
| 2247 | RGB24ToYRow = RGB24ToYRow_Any_LSX; |
| 2248 | if (IS_ALIGNED(width, 16)) { |
| 2249 | RGB24ToYRow = RGB24ToYRow_LSX; |
| 2250 | RGB24ToUVRow = RGB24ToUVRow_LSX; |
| 2251 | } |
| 2252 | } |
| 2253 | #endif |
| 2254 | #if defined(HAS_RGB24TOYROW_LASX) && defined(HAS_RGB24TOUVROW_LASX) |
| 2255 | if (TestCpuFlag(kCpuHasLASX)) { |
| 2256 | RGB24ToUVRow = RGB24ToUVRow_Any_LASX; |
| 2257 | RGB24ToYRow = RGB24ToYRow_Any_LASX; |
| 2258 | if (IS_ALIGNED(width, 32)) { |
| 2259 | RGB24ToYRow = RGB24ToYRow_LASX; |
| 2260 | RGB24ToUVRow = RGB24ToUVRow_LASX; |
| 2261 | } |
| 2262 | } |
| 2263 | #endif |
| 2264 |
| 2265 | // Other platforms do intermediate conversion from RGB24 to ARGB. |
| 2266 | #else // HAS_RGB24TOYROW |
| 2267 |
| 2268 | #if defined(HAS_RGB24TOARGBROW_SSSE3) |
| 2269 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2270 | RGB24ToARGBRow = RGB24ToARGBRow_Any_SSSE3; |
| 2271 | if (IS_ALIGNED(width, 16)) { |
| 2272 | RGB24ToARGBRow = RGB24ToARGBRow_SSSE3; |
| 2273 | } |
| 2274 | } |
| 2275 | #endif |
| 2276 | #if defined(HAS_ARGBTOYROW_SSSE3) |
| 2277 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2278 | ARGBToYRow = ARGBToYRow_Any_SSSE3; |
| 2279 | if (IS_ALIGNED(width, 16)) { |
| 2280 | ARGBToYRow = ARGBToYRow_SSSE3; |
| 2281 | } |
| 2282 | } |
| 2283 | #endif |
| 2284 | #if defined(HAS_ARGBTOYROW_AVX2) |
| 2285 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 2286 | ARGBToYRow = ARGBToYRow_Any_AVX2; |
| 2287 | if (IS_ALIGNED(width, 32)) { |
| 2288 | ARGBToYRow = ARGBToYRow_AVX2; |
| 2289 | } |
| 2290 | } |
| 2291 | #endif |
| 2292 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 2293 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2294 | ARGBToUVRow = ARGBToUVRow_Any_SSSE3; |
| 2295 | if (IS_ALIGNED(width, 16)) { |
| 2296 | ARGBToUVRow = ARGBToUVRow_SSSE3; |
| 2297 | } |
| 2298 | } |
| 2299 | #endif |
| 2300 | #if defined(HAS_ARGBTOUVROW_AVX2) |
| 2301 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 2302 | ARGBToUVRow = ARGBToUVRow_Any_AVX2; |
| 2303 | if (IS_ALIGNED(width, 32)) { |
| 2304 | ARGBToUVRow = ARGBToUVRow_AVX2; |
| 2305 | } |
| 2306 | } |
| 2307 | #endif |
| 2308 | #endif // HAS_RGB24TOYROW |
| 2309 |
| 2310 | { |
| 2311 | #if !defined(HAS_RGB24TOYROW) |
| 2312 | // Allocate 2 rows of ARGB. |
| 2313 | const int row_size = (width * 4 + 31) & ~31; |
| 2314 | align_buffer_64(row, row_size * 2); |
| 2315 | #endif |
| 2316 |
| 2317 | for (y = 0; y < height - 1; y += 2) { |
| 2318 | #if defined(HAS_RGB24TOYROW) |
| 2319 | RGB24ToUVRow(src_rgb24, src_stride_rgb24, dst_u, dst_v, width); |
| 2320 | RGB24ToYRow(src_rgb24, dst_y, width); |
| 2321 | RGB24ToYRow(src_rgb24 + src_stride_rgb24, dst_y + dst_stride_y, width); |
| 2322 | #else |
| 2323 | RGB24ToARGBRow(src_rgb24, row, width); |
| 2324 | RGB24ToARGBRow(src_rgb24 + src_stride_rgb24, row + row_size, width); |
| 2325 | ARGBToUVRow(row, row_size, dst_u, dst_v, width); |
| 2326 | ARGBToYRow(row, dst_y, width); |
| 2327 | ARGBToYRow(row + row_size, dst_y + dst_stride_y, width); |
| 2328 | #endif |
| 2329 | src_rgb24 += src_stride_rgb24 * 2; |
| 2330 | dst_y += dst_stride_y * 2; |
| 2331 | dst_u += dst_stride_u; |
| 2332 | dst_v += dst_stride_v; |
| 2333 | } |
| 2334 | if (height & 1) { |
| 2335 | #if defined(HAS_RGB24TOYROW) |
| 2336 | RGB24ToUVRow(src_rgb24, 0, dst_u, dst_v, width); |
| 2337 | RGB24ToYRow(src_rgb24, dst_y, width); |
| 2338 | #else |
| 2339 | RGB24ToARGBRow(src_rgb24, row, width); |
| 2340 | ARGBToUVRow(row, 0, dst_u, dst_v, width); |
| 2341 | ARGBToYRow(row, dst_y, width); |
| 2342 | #endif |
| 2343 | } |
| 2344 | #if !defined(HAS_RGB24TOYROW) |
| 2345 | free_aligned_buffer_64(row); |
| 2346 | #endif |
| 2347 | } |
| 2348 | return 0; |
| 2349 | } |
| 2350 | #undef HAS_RGB24TOYROW |
| 2351 |
| 2352 | // Enabled if 1 pass is available |
| 2353 | #if defined(HAS_RGB24TOYJROW_NEON) || defined(HAS_RGB24TOYJROW_MSA) |
| 2354 | #define HAS_RGB24TOYJROW |
| 2355 | #endif |
| 2356 |
| 2357 | // Convert RGB24 to J420. |
| 2358 | LIBYUV_API |
| 2359 | int RGB24ToJ420(const uint8_t* src_rgb24, |
| 2360 | int src_stride_rgb24, |
| 2361 | uint8_t* dst_y, |
| 2362 | int dst_stride_y, |
| 2363 | uint8_t* dst_u, |
| 2364 | int dst_stride_u, |
| 2365 | uint8_t* dst_v, |
| 2366 | int dst_stride_v, |
| 2367 | int width, |
| 2368 | int height) { |
| 2369 | int y; |
| 2370 | #if defined(HAS_RGB24TOYJROW) |
| 2371 | void (*RGB24ToUVJRow)(const uint8_t* src_rgb24, int src_stride_rgb24, |
| 2372 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 2373 | RGB24ToUVJRow_C; |
| 2374 | void (*RGB24ToYJRow)(const uint8_t* src_rgb24, uint8_t* dst_y, int width) = |
| 2375 | RGB24ToYJRow_C; |
| 2376 | #else |
| 2377 | void (*RGB24ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = |
| 2378 | RGB24ToARGBRow_C; |
| 2379 | void (*ARGBToUVJRow)(const uint8_t* src_argb0, int src_stride_argb, |
| 2380 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 2381 | ARGBToUVJRow_C; |
| 2382 | void (*ARGBToYJRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = |
| 2383 | ARGBToYJRow_C; |
| 2384 | #endif |
| 2385 | if (!src_rgb24 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { |
| 2386 | return -1; |
| 2387 | } |
| 2388 | // Negative height means invert the image. |
| 2389 | if (height < 0) { |
| 2390 | height = -height; |
| 2391 | src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; |
| 2392 | src_stride_rgb24 = -src_stride_rgb24; |
| 2393 | } |
| 2394 |
| 2395 | #if defined(HAS_RGB24TOYJROW) |
| 2396 |
| 2397 | // Neon version does direct RGB24 to YUV. |
| 2398 | #if defined(HAS_RGB24TOYJROW_NEON) && defined(HAS_RGB24TOUVJROW_NEON) |
| 2399 | if (TestCpuFlag(kCpuHasNEON)) { |
| 2400 | RGB24ToUVJRow = RGB24ToUVJRow_Any_NEON; |
| 2401 | RGB24ToYJRow = RGB24ToYJRow_Any_NEON; |
| 2402 | if (IS_ALIGNED(width, 16)) { |
| 2403 | RGB24ToYJRow = RGB24ToYJRow_NEON; |
| 2404 | RGB24ToUVJRow = RGB24ToUVJRow_NEON; |
| 2405 | } |
| 2406 | } |
| 2407 | #endif |
| 2408 | #if defined(HAS_RGB24TOYJROW_MSA) && defined(HAS_RGB24TOUVJROW_MSA) |
| 2409 | if (TestCpuFlag(kCpuHasMSA)) { |
| 2410 | RGB24ToUVJRow = RGB24ToUVJRow_Any_MSA; |
| 2411 | RGB24ToYJRow = RGB24ToYJRow_Any_MSA; |
| 2412 | if (IS_ALIGNED(width, 16)) { |
| 2413 | RGB24ToYJRow = RGB24ToYJRow_MSA; |
| 2414 | RGB24ToUVJRow = RGB24ToUVJRow_MSA; |
| 2415 | } |
| 2416 | } |
| 2417 | #endif |
| 2418 | #if defined(HAS_RGB24TOYJROW_LSX) |
| 2419 | if (TestCpuFlag(kCpuHasLSX)) { |
| 2420 | RGB24ToYJRow = RGB24ToYJRow_Any_LSX; |
| 2421 | if (IS_ALIGNED(width, 16)) { |
| 2422 | RGB24ToYJRow = RGB24ToYJRow_LSX; |
| 2423 | } |
| 2424 | } |
| 2425 | #endif |
| 2426 | #if defined(HAS_RGB24TOYJROW_LASX) |
| 2427 | if (TestCpuFlag(kCpuHasLASX)) { |
| 2428 | RGB24ToYJRow = RGB24ToYJRow_Any_LASX; |
| 2429 | if (IS_ALIGNED(width, 32)) { |
| 2430 | RGB24ToYJRow = RGB24ToYJRow_LASX; |
| 2431 | } |
| 2432 | } |
| 2433 | #endif |
| 2434 |
| 2435 | // Other platforms do intermediate conversion from RGB24 to ARGB. |
| 2436 | #else // HAS_RGB24TOYJROW |
| 2437 |
| 2438 | #if defined(HAS_RGB24TOARGBROW_SSSE3) |
| 2439 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2440 | RGB24ToARGBRow = RGB24ToARGBRow_Any_SSSE3; |
| 2441 | if (IS_ALIGNED(width, 16)) { |
| 2442 | RGB24ToARGBRow = RGB24ToARGBRow_SSSE3; |
| 2443 | } |
| 2444 | } |
| 2445 | #endif |
| 2446 | #if defined(HAS_ARGBTOYJROW_SSSE3) |
| 2447 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2448 | ARGBToYJRow = ARGBToYJRow_Any_SSSE3; |
| 2449 | if (IS_ALIGNED(width, 16)) { |
| 2450 | ARGBToYJRow = ARGBToYJRow_SSSE3; |
| 2451 | } |
| 2452 | } |
| 2453 | #endif |
| 2454 | #if defined(HAS_ARGBTOYJROW_AVX2) |
| 2455 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 2456 | ARGBToYJRow = ARGBToYJRow_Any_AVX2; |
| 2457 | if (IS_ALIGNED(width, 32)) { |
| 2458 | ARGBToYJRow = ARGBToYJRow_AVX2; |
| 2459 | } |
| 2460 | } |
| 2461 | #endif |
| 2462 | #if defined(HAS_ARGBTOUVJROW_SSSE3) |
| 2463 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2464 | ARGBToUVJRow = ARGBToUVJRow_Any_SSSE3; |
| 2465 | if (IS_ALIGNED(width, 16)) { |
| 2466 | ARGBToUVJRow = ARGBToUVJRow_SSSE3; |
| 2467 | } |
| 2468 | } |
| 2469 | #endif |
| 2470 | #if defined(HAS_ARGBTOUVJROW_AVX2) |
| 2471 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 2472 | ARGBToUVJRow = ARGBToUVJRow_Any_AVX2; |
| 2473 | if (IS_ALIGNED(width, 32)) { |
| 2474 | ARGBToUVJRow = ARGBToUVJRow_AVX2; |
| 2475 | } |
| 2476 | } |
| 2477 | #endif |
| 2478 | #endif // HAS_RGB24TOYJROW |
| 2479 |
| 2480 | { |
| 2481 | #if !defined(HAS_RGB24TOYJROW) |
| 2482 | // Allocate 2 rows of ARGB. |
| 2483 | const int row_size = (width * 4 + 31) & ~31; |
| 2484 | align_buffer_64(row, row_size * 2); |
| 2485 | #endif |
| 2486 |
| 2487 | for (y = 0; y < height - 1; y += 2) { |
| 2488 | #if defined(HAS_RGB24TOYJROW) |
| 2489 | RGB24ToUVJRow(src_rgb24, src_stride_rgb24, dst_u, dst_v, width); |
| 2490 | RGB24ToYJRow(src_rgb24, dst_y, width); |
| 2491 | RGB24ToYJRow(src_rgb24 + src_stride_rgb24, dst_y + dst_stride_y, width); |
| 2492 | #else |
| 2493 | RGB24ToARGBRow(src_rgb24, row, width); |
| 2494 | RGB24ToARGBRow(src_rgb24 + src_stride_rgb24, row + row_size, width); |
| 2495 | ARGBToUVJRow(row, row_size, dst_u, dst_v, width); |
| 2496 | ARGBToYJRow(row, dst_y, width); |
| 2497 | ARGBToYJRow(row + row_size, dst_y + dst_stride_y, width); |
| 2498 | #endif |
| 2499 | src_rgb24 += src_stride_rgb24 * 2; |
| 2500 | dst_y += dst_stride_y * 2; |
| 2501 | dst_u += dst_stride_u; |
| 2502 | dst_v += dst_stride_v; |
| 2503 | } |
| 2504 | if (height & 1) { |
| 2505 | #if defined(HAS_RGB24TOYJROW) |
| 2506 | RGB24ToUVJRow(src_rgb24, 0, dst_u, dst_v, width); |
| 2507 | RGB24ToYJRow(src_rgb24, dst_y, width); |
| 2508 | #else |
| 2509 | RGB24ToARGBRow(src_rgb24, row, width); |
| 2510 | ARGBToUVJRow(row, 0, dst_u, dst_v, width); |
| 2511 | ARGBToYJRow(row, dst_y, width); |
| 2512 | #endif |
| 2513 | } |
| 2514 | #if !defined(HAS_RGB24TOYJROW) |
| 2515 | free_aligned_buffer_64(row); |
| 2516 | #endif |
| 2517 | } |
| 2518 | return 0; |
| 2519 | } |
| 2520 | #undef HAS_RGB24TOYJROW |
| 2521 |
| 2522 | // Enabled if 1 pass is available |
| 2523 | #if (defined(HAS_RAWTOYROW_NEON) || defined(HAS_RAWTOYROW_MSA) || \ |
| 2524 | defined(HAS_RAWTOYROW_LSX)) |
| 2525 | #define HAS_RAWTOYROW |
| 2526 | #endif |
| 2527 |
| 2528 | // Convert RAW to I420. |
| 2529 | LIBYUV_API |
| 2530 | int RAWToI420(const uint8_t* src_raw, |
| 2531 | int src_stride_raw, |
| 2532 | uint8_t* dst_y, |
| 2533 | int dst_stride_y, |
| 2534 | uint8_t* dst_u, |
| 2535 | int dst_stride_u, |
| 2536 | uint8_t* dst_v, |
| 2537 | int dst_stride_v, |
| 2538 | int width, |
| 2539 | int height) { |
| 2540 | int y; |
| 2541 | #if defined(HAS_RAWTOYROW) |
| 2542 | void (*RAWToUVRow)(const uint8_t* src_raw, int src_stride_raw, uint8_t* dst_u, |
| 2543 | uint8_t* dst_v, int width) = RAWToUVRow_C; |
| 2544 | void (*RAWToYRow)(const uint8_t* src_raw, uint8_t* dst_y, int width) = |
| 2545 | RAWToYRow_C; |
| 2546 | #else |
| 2547 | void (*RAWToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = |
| 2548 | RAWToARGBRow_C; |
| 2549 | void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, |
| 2550 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 2551 | ARGBToUVRow_C; |
| 2552 | void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = |
| 2553 | ARGBToYRow_C; |
| 2554 | #endif |
| 2555 | if (!src_raw || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { |
| 2556 | return -1; |
| 2557 | } |
| 2558 | // Negative height means invert the image. |
| 2559 | if (height < 0) { |
| 2560 | height = -height; |
| 2561 | src_raw = src_raw + (height - 1) * src_stride_raw; |
| 2562 | src_stride_raw = -src_stride_raw; |
| 2563 | } |
| 2564 |
| 2565 | #if defined(HAS_RAWTOYROW) |
| 2566 |
| 2567 | // Neon version does direct RAW to YUV. |
| 2568 | #if defined(HAS_RAWTOYROW_NEON) && defined(HAS_RAWTOUVROW_NEON) |
| 2569 | if (TestCpuFlag(kCpuHasNEON)) { |
| 2570 | RAWToUVRow = RAWToUVRow_Any_NEON; |
| 2571 | RAWToYRow = RAWToYRow_Any_NEON; |
| 2572 | if (IS_ALIGNED(width, 16)) { |
| 2573 | RAWToYRow = RAWToYRow_NEON; |
| 2574 | RAWToUVRow = RAWToUVRow_NEON; |
| 2575 | } |
| 2576 | } |
| 2577 | #endif |
| 2578 | #if defined(HAS_RAWTOYROW_MSA) && defined(HAS_RAWTOUVROW_MSA) |
| 2579 | if (TestCpuFlag(kCpuHasMSA)) { |
| 2580 | RAWToUVRow = RAWToUVRow_Any_MSA; |
| 2581 | RAWToYRow = RAWToYRow_Any_MSA; |
| 2582 | if (IS_ALIGNED(width, 16)) { |
| 2583 | RAWToYRow = RAWToYRow_MSA; |
| 2584 | RAWToUVRow = RAWToUVRow_MSA; |
| 2585 | } |
| 2586 | } |
| 2587 | #endif |
| 2588 | #if defined(HAS_RAWTOYROW_LSX) && defined(HAS_RAWTOUVROW_LSX) |
| 2589 | if (TestCpuFlag(kCpuHasLSX)) { |
| 2590 | RAWToUVRow = RAWToUVRow_Any_LSX; |
| 2591 | RAWToYRow = RAWToYRow_Any_LSX; |
| 2592 | if (IS_ALIGNED(width, 16)) { |
| 2593 | RAWToYRow = RAWToYRow_LSX; |
| 2594 | RAWToUVRow = RAWToUVRow_LSX; |
| 2595 | } |
| 2596 | } |
| 2597 | #endif |
| 2598 | #if defined(HAS_RAWTOYROW_LASX) && defined(HAS_RAWTOUVROW_LASX) |
| 2599 | if (TestCpuFlag(kCpuHasLASX)) { |
| 2600 | RAWToUVRow = RAWToUVRow_Any_LASX; |
| 2601 | RAWToYRow = RAWToYRow_Any_LASX; |
| 2602 | if (IS_ALIGNED(width, 32)) { |
| 2603 | RAWToYRow = RAWToYRow_LASX; |
| 2604 | RAWToUVRow = RAWToUVRow_LASX; |
| 2605 | } |
| 2606 | } |
| 2607 | #endif |
| 2608 |
| 2609 | // Other platforms do intermediate conversion from RAW to ARGB. |
| 2610 | #else // HAS_RAWTOYROW |
| 2611 |
| 2612 | #if defined(HAS_RAWTOARGBROW_SSSE3) |
| 2613 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2614 | RAWToARGBRow = RAWToARGBRow_Any_SSSE3; |
| 2615 | if (IS_ALIGNED(width, 16)) { |
| 2616 | RAWToARGBRow = RAWToARGBRow_SSSE3; |
| 2617 | } |
| 2618 | } |
| 2619 | #endif |
| 2620 | #if defined(HAS_ARGBTOYROW_SSSE3) |
| 2621 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2622 | ARGBToYRow = ARGBToYRow_Any_SSSE3; |
| 2623 | if (IS_ALIGNED(width, 16)) { |
| 2624 | ARGBToYRow = ARGBToYRow_SSSE3; |
| 2625 | } |
| 2626 | } |
| 2627 | #endif |
| 2628 | #if defined(HAS_ARGBTOYROW_AVX2) |
| 2629 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 2630 | ARGBToYRow = ARGBToYRow_Any_AVX2; |
| 2631 | if (IS_ALIGNED(width, 32)) { |
| 2632 | ARGBToYRow = ARGBToYRow_AVX2; |
| 2633 | } |
| 2634 | } |
| 2635 | #endif |
| 2636 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 2637 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2638 | ARGBToUVRow = ARGBToUVRow_Any_SSSE3; |
| 2639 | if (IS_ALIGNED(width, 16)) { |
| 2640 | ARGBToUVRow = ARGBToUVRow_SSSE3; |
| 2641 | } |
| 2642 | } |
| 2643 | #endif |
| 2644 | #if defined(HAS_ARGBTOUVROW_AVX2) |
| 2645 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 2646 | ARGBToUVRow = ARGBToUVRow_Any_AVX2; |
| 2647 | if (IS_ALIGNED(width, 32)) { |
| 2648 | ARGBToUVRow = ARGBToUVRow_AVX2; |
| 2649 | } |
| 2650 | } |
| 2651 | #endif |
| 2652 | #endif // HAS_RAWTOYROW |
| 2653 |
| 2654 | { |
| 2655 | #if !defined(HAS_RAWTOYROW) |
| 2656 | // Allocate 2 rows of ARGB. |
| 2657 | const int row_size = (width * 4 + 31) & ~31; |
| 2658 | align_buffer_64(row, row_size * 2); |
| 2659 | #endif |
| 2660 |
| 2661 | for (y = 0; y < height - 1; y += 2) { |
| 2662 | #if defined(HAS_RAWTOYROW) |
| 2663 | RAWToUVRow(src_raw, src_stride_raw, dst_u, dst_v, width); |
| 2664 | RAWToYRow(src_raw, dst_y, width); |
| 2665 | RAWToYRow(src_raw + src_stride_raw, dst_y + dst_stride_y, width); |
| 2666 | #else |
| 2667 | RAWToARGBRow(src_raw, row, width); |
| 2668 | RAWToARGBRow(src_raw + src_stride_raw, row + row_size, width); |
| 2669 | ARGBToUVRow(row, row_size, dst_u, dst_v, width); |
| 2670 | ARGBToYRow(row, dst_y, width); |
| 2671 | ARGBToYRow(row + row_size, dst_y + dst_stride_y, width); |
| 2672 | #endif |
| 2673 | src_raw += src_stride_raw * 2; |
| 2674 | dst_y += dst_stride_y * 2; |
| 2675 | dst_u += dst_stride_u; |
| 2676 | dst_v += dst_stride_v; |
| 2677 | } |
| 2678 | if (height & 1) { |
| 2679 | #if defined(HAS_RAWTOYROW) |
| 2680 | RAWToUVRow(src_raw, 0, dst_u, dst_v, width); |
| 2681 | RAWToYRow(src_raw, dst_y, width); |
| 2682 | #else |
| 2683 | RAWToARGBRow(src_raw, row, width); |
| 2684 | ARGBToUVRow(row, 0, dst_u, dst_v, width); |
| 2685 | ARGBToYRow(row, dst_y, width); |
| 2686 | #endif |
| 2687 | } |
| 2688 | #if !defined(HAS_RAWTOYROW) |
| 2689 | free_aligned_buffer_64(row); |
| 2690 | #endif |
| 2691 | } |
| 2692 | return 0; |
| 2693 | } |
| 2694 | #undef HAS_RAWTOYROW |
| 2695 |
| 2696 | // Enabled if 1 pass is available |
| 2697 | #if defined(HAS_RAWTOYJROW_NEON) || defined(HAS_RAWTOYJROW_MSA) |
| 2698 | #define HAS_RAWTOYJROW |
| 2699 | #endif |
| 2700 |
| 2701 | // Convert RAW to J420. |
| 2702 | LIBYUV_API |
| 2703 | int RAWToJ420(const uint8_t* src_raw, |
| 2704 | int src_stride_raw, |
| 2705 | uint8_t* dst_y, |
| 2706 | int dst_stride_y, |
| 2707 | uint8_t* dst_u, |
| 2708 | int dst_stride_u, |
| 2709 | uint8_t* dst_v, |
| 2710 | int dst_stride_v, |
| 2711 | int width, |
| 2712 | int height) { |
| 2713 | int y; |
| 2714 | #if defined(HAS_RAWTOYJROW) |
| 2715 | void (*RAWToUVJRow)(const uint8_t* src_raw, int src_stride_raw, |
| 2716 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 2717 | RAWToUVJRow_C; |
| 2718 | void (*RAWToYJRow)(const uint8_t* src_raw, uint8_t* dst_y, int width) = |
| 2719 | RAWToYJRow_C; |
| 2720 | #else |
| 2721 | void (*RAWToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = |
| 2722 | RAWToARGBRow_C; |
| 2723 | void (*ARGBToUVJRow)(const uint8_t* src_argb0, int src_stride_argb, |
| 2724 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 2725 | ARGBToUVJRow_C; |
| 2726 | void (*ARGBToYJRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = |
| 2727 | ARGBToYJRow_C; |
| 2728 | #endif |
| 2729 | if (!src_raw || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { |
| 2730 | return -1; |
| 2731 | } |
| 2732 | // Negative height means invert the image. |
| 2733 | if (height < 0) { |
| 2734 | height = -height; |
| 2735 | src_raw = src_raw + (height - 1) * src_stride_raw; |
| 2736 | src_stride_raw = -src_stride_raw; |
| 2737 | } |
| 2738 |
| 2739 | #if defined(HAS_RAWTOYJROW) |
| 2740 |
| 2741 | // Neon version does direct RAW to YUV. |
| 2742 | #if defined(HAS_RAWTOYJROW_NEON) && defined(HAS_RAWTOUVJROW_NEON) |
| 2743 | if (TestCpuFlag(kCpuHasNEON)) { |
| 2744 | RAWToUVJRow = RAWToUVJRow_Any_NEON; |
| 2745 | RAWToYJRow = RAWToYJRow_Any_NEON; |
| 2746 | if (IS_ALIGNED(width, 16)) { |
| 2747 | RAWToYJRow = RAWToYJRow_NEON; |
| 2748 | RAWToUVJRow = RAWToUVJRow_NEON; |
| 2749 | } |
| 2750 | } |
| 2751 | #endif |
| 2752 | #if defined(HAS_RAWTOYJROW_MSA) && defined(HAS_RAWTOUVJROW_MSA) |
| 2753 | if (TestCpuFlag(kCpuHasMSA)) { |
| 2754 | RAWToUVJRow = RAWToUVJRow_Any_MSA; |
| 2755 | RAWToYJRow = RAWToYJRow_Any_MSA; |
| 2756 | if (IS_ALIGNED(width, 16)) { |
| 2757 | RAWToYJRow = RAWToYJRow_MSA; |
| 2758 | RAWToUVJRow = RAWToUVJRow_MSA; |
| 2759 | } |
| 2760 | } |
| 2761 | #endif |
| 2762 | #if defined(HAS_RAWTOYJROW_LSX) |
| 2763 | if (TestCpuFlag(kCpuHasLSX)) { |
| 2764 | RAWToYJRow = RAWToYJRow_Any_LSX; |
| 2765 | if (IS_ALIGNED(width, 16)) { |
| 2766 | RAWToYJRow = RAWToYJRow_LSX; |
| 2767 | } |
| 2768 | } |
| 2769 | #endif |
| 2770 | #if defined(HAS_RAWTOYJROW_LASX) |
| 2771 | if (TestCpuFlag(kCpuHasLASX)) { |
| 2772 | RAWToYJRow = RAWToYJRow_Any_LASX; |
| 2773 | if (IS_ALIGNED(width, 32)) { |
| 2774 | RAWToYJRow = RAWToYJRow_LASX; |
| 2775 | } |
| 2776 | } |
| 2777 | #endif |
| 2778 |
| 2779 | // Other platforms do intermediate conversion from RAW to ARGB. |
| 2780 | #else // HAS_RAWTOYJROW |
| 2781 |
| 2782 | #if defined(HAS_RAWTOARGBROW_SSSE3) |
| 2783 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2784 | RAWToARGBRow = RAWToARGBRow_Any_SSSE3; |
| 2785 | if (IS_ALIGNED(width, 16)) { |
| 2786 | RAWToARGBRow = RAWToARGBRow_SSSE3; |
| 2787 | } |
| 2788 | } |
| 2789 | #endif |
| 2790 | #if defined(HAS_ARGBTOYJROW_SSSE3) |
| 2791 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2792 | ARGBToYJRow = ARGBToYJRow_Any_SSSE3; |
| 2793 | if (IS_ALIGNED(width, 16)) { |
| 2794 | ARGBToYJRow = ARGBToYJRow_SSSE3; |
| 2795 | } |
| 2796 | } |
| 2797 | #endif |
| 2798 | #if defined(HAS_ARGBTOYJROW_AVX2) |
| 2799 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 2800 | ARGBToYJRow = ARGBToYJRow_Any_AVX2; |
| 2801 | if (IS_ALIGNED(width, 32)) { |
| 2802 | ARGBToYJRow = ARGBToYJRow_AVX2; |
| 2803 | } |
| 2804 | } |
| 2805 | #endif |
| 2806 | #if defined(HAS_ARGBTOUVJROW_SSSE3) |
| 2807 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2808 | ARGBToUVJRow = ARGBToUVJRow_Any_SSSE3; |
| 2809 | if (IS_ALIGNED(width, 16)) { |
| 2810 | ARGBToUVJRow = ARGBToUVJRow_SSSE3; |
| 2811 | } |
| 2812 | } |
| 2813 | #endif |
| 2814 | #if defined(HAS_ARGBTOUVJROW_AVX2) |
| 2815 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 2816 | ARGBToUVJRow = ARGBToUVJRow_Any_AVX2; |
| 2817 | if (IS_ALIGNED(width, 32)) { |
| 2818 | ARGBToUVJRow = ARGBToUVJRow_AVX2; |
| 2819 | } |
| 2820 | } |
| 2821 | #endif |
| 2822 | #endif // HAS_RAWTOYJROW |
| 2823 |
| 2824 | { |
| 2825 | #if !defined(HAS_RAWTOYJROW) |
| 2826 | // Allocate 2 rows of ARGB. |
| 2827 | const int row_size = (width * 4 + 31) & ~31; |
| 2828 | align_buffer_64(row, row_size * 2); |
| 2829 | #endif |
| 2830 |
| 2831 | for (y = 0; y < height - 1; y += 2) { |
| 2832 | #if defined(HAS_RAWTOYJROW) |
| 2833 | RAWToUVJRow(src_raw, src_stride_raw, dst_u, dst_v, width); |
| 2834 | RAWToYJRow(src_raw, dst_y, width); |
| 2835 | RAWToYJRow(src_raw + src_stride_raw, dst_y + dst_stride_y, width); |
| 2836 | #else |
| 2837 | RAWToARGBRow(src_raw, row, width); |
| 2838 | RAWToARGBRow(src_raw + src_stride_raw, row + row_size, width); |
| 2839 | ARGBToUVJRow(row, row_size, dst_u, dst_v, width); |
| 2840 | ARGBToYJRow(row, dst_y, width); |
| 2841 | ARGBToYJRow(row + row_size, dst_y + dst_stride_y, width); |
| 2842 | #endif |
| 2843 | src_raw += src_stride_raw * 2; |
| 2844 | dst_y += dst_stride_y * 2; |
| 2845 | dst_u += dst_stride_u; |
| 2846 | dst_v += dst_stride_v; |
| 2847 | } |
| 2848 | if (height & 1) { |
| 2849 | #if defined(HAS_RAWTOYJROW) |
| 2850 | RAWToUVJRow(src_raw, 0, dst_u, dst_v, width); |
| 2851 | RAWToYJRow(src_raw, dst_y, width); |
| 2852 | #else |
| 2853 | RAWToARGBRow(src_raw, row, width); |
| 2854 | ARGBToUVJRow(row, 0, dst_u, dst_v, width); |
| 2855 | ARGBToYJRow(row, dst_y, width); |
| 2856 | #endif |
| 2857 | } |
| 2858 | #if !defined(HAS_RAWTOYJROW) |
| 2859 | free_aligned_buffer_64(row); |
| 2860 | #endif |
| 2861 | } |
| 2862 | return 0; |
| 2863 | } |
| 2864 | #undef HAS_RAWTOYJROW |
| 2865 |
| 2866 | // Convert RGB565 to I420. |
| 2867 | LIBYUV_API |
| 2868 | int RGB565ToI420(const uint8_t* src_rgb565, |
| 2869 | int src_stride_rgb565, |
| 2870 | uint8_t* dst_y, |
| 2871 | int dst_stride_y, |
| 2872 | uint8_t* dst_u, |
| 2873 | int dst_stride_u, |
| 2874 | uint8_t* dst_v, |
| 2875 | int dst_stride_v, |
| 2876 | int width, |
| 2877 | int height) { |
| 2878 | int y; |
| 2879 | #if (defined(HAS_RGB565TOYROW_NEON) || defined(HAS_RGB565TOYROW_MSA) || \ |
| 2880 | defined(HAS_RGB565TOYROW_LSX) || defined(HAS_RGB565TOYROW_LASX)) |
| 2881 | void (*RGB565ToUVRow)(const uint8_t* src_rgb565, int src_stride_rgb565, |
| 2882 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 2883 | RGB565ToUVRow_C; |
| 2884 | void (*RGB565ToYRow)(const uint8_t* src_rgb565, uint8_t* dst_y, int width) = |
| 2885 | RGB565ToYRow_C; |
| 2886 | #else |
| 2887 | void (*RGB565ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, |
| 2888 | int width) = RGB565ToARGBRow_C; |
| 2889 | void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, |
| 2890 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 2891 | ARGBToUVRow_C; |
| 2892 | void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = |
| 2893 | ARGBToYRow_C; |
| 2894 | #endif |
| 2895 | if (!src_rgb565 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { |
| 2896 | return -1; |
| 2897 | } |
| 2898 | // Negative height means invert the image. |
| 2899 | if (height < 0) { |
| 2900 | height = -height; |
| 2901 | src_rgb565 = src_rgb565 + (height - 1) * src_stride_rgb565; |
| 2902 | src_stride_rgb565 = -src_stride_rgb565; |
| 2903 | } |
| 2904 |
| 2905 | // Neon version does direct RGB565 to YUV. |
| 2906 | #if defined(HAS_RGB565TOYROW_NEON) |
| 2907 | if (TestCpuFlag(kCpuHasNEON)) { |
| 2908 | RGB565ToUVRow = RGB565ToUVRow_Any_NEON; |
| 2909 | RGB565ToYRow = RGB565ToYRow_Any_NEON; |
| 2910 | if (IS_ALIGNED(width, 8)) { |
| 2911 | RGB565ToYRow = RGB565ToYRow_NEON; |
| 2912 | if (IS_ALIGNED(width, 16)) { |
| 2913 | RGB565ToUVRow = RGB565ToUVRow_NEON; |
| 2914 | } |
| 2915 | } |
| 2916 | } |
| 2917 | // MSA version does direct RGB565 to YUV. |
| 2918 | #elif (defined(HAS_RGB565TOYROW_MSA) || defined(HAS_RGB565TOYROW_LSX) || \ |
| 2919 | defined(HAS_RGB565TOYROW_LASX)) |
| 2920 | #if defined(HAS_RGB565TOYROW_MSA) && defined(HAS_RGB565TOUVROW_MSA) |
| 2921 | if (TestCpuFlag(kCpuHasMSA)) { |
| 2922 | RGB565ToUVRow = RGB565ToUVRow_Any_MSA; |
| 2923 | RGB565ToYRow = RGB565ToYRow_Any_MSA; |
| 2924 | if (IS_ALIGNED(width, 16)) { |
| 2925 | RGB565ToYRow = RGB565ToYRow_MSA; |
| 2926 | RGB565ToUVRow = RGB565ToUVRow_MSA; |
| 2927 | } |
| 2928 | } |
| 2929 | #endif |
| 2930 | #if defined(HAS_RGB565TOYROW_LSX) && defined(HAS_RGB565TOUVROW_LSX) |
| 2931 | if (TestCpuFlag(kCpuHasLSX)) { |
| 2932 | RGB565ToUVRow = RGB565ToUVRow_Any_LSX; |
| 2933 | RGB565ToYRow = RGB565ToYRow_Any_LSX; |
| 2934 | if (IS_ALIGNED(width, 16)) { |
| 2935 | RGB565ToYRow = RGB565ToYRow_LSX; |
| 2936 | RGB565ToUVRow = RGB565ToUVRow_LSX; |
| 2937 | } |
| 2938 | } |
| 2939 | #endif |
| 2940 | #if defined(HAS_RGB565TOYROW_LASX) && defined(HAS_RGB565TOUVROW_LASX) |
| 2941 | if (TestCpuFlag(kCpuHasLASX)) { |
| 2942 | RGB565ToUVRow = RGB565ToUVRow_Any_LASX; |
| 2943 | RGB565ToYRow = RGB565ToYRow_Any_LASX; |
| 2944 | if (IS_ALIGNED(width, 32)) { |
| 2945 | RGB565ToYRow = RGB565ToYRow_LASX; |
| 2946 | RGB565ToUVRow = RGB565ToUVRow_LASX; |
| 2947 | } |
| 2948 | } |
| 2949 | #endif |
| 2950 | // Other platforms do intermediate conversion from RGB565 to ARGB. |
| 2951 | #else |
| 2952 | #if defined(HAS_RGB565TOARGBROW_SSE2) |
| 2953 | if (TestCpuFlag(kCpuHasSSE2)) { |
| 2954 | RGB565ToARGBRow = RGB565ToARGBRow_Any_SSE2; |
| 2955 | if (IS_ALIGNED(width, 8)) { |
| 2956 | RGB565ToARGBRow = RGB565ToARGBRow_SSE2; |
| 2957 | } |
| 2958 | } |
| 2959 | #endif |
| 2960 | #if defined(HAS_RGB565TOARGBROW_AVX2) |
| 2961 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 2962 | RGB565ToARGBRow = RGB565ToARGBRow_Any_AVX2; |
| 2963 | if (IS_ALIGNED(width, 16)) { |
| 2964 | RGB565ToARGBRow = RGB565ToARGBRow_AVX2; |
| 2965 | } |
| 2966 | } |
| 2967 | #endif |
| 2968 | #if defined(HAS_ARGBTOYROW_SSSE3) |
| 2969 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2970 | ARGBToYRow = ARGBToYRow_Any_SSSE3; |
| 2971 | if (IS_ALIGNED(width, 16)) { |
| 2972 | ARGBToYRow = ARGBToYRow_SSSE3; |
| 2973 | } |
| 2974 | } |
| 2975 | #endif |
| 2976 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 2977 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 2978 | ARGBToUVRow = ARGBToUVRow_Any_SSSE3; |
| 2979 | if (IS_ALIGNED(width, 16)) { |
| 2980 | ARGBToUVRow = ARGBToUVRow_SSSE3; |
| 2981 | } |
| 2982 | } |
| 2983 | #endif |
| 2984 | #if defined(HAS_ARGBTOYROW_AVX2) |
| 2985 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 2986 | ARGBToYRow = ARGBToYRow_Any_AVX2; |
| 2987 | if (IS_ALIGNED(width, 32)) { |
| 2988 | ARGBToYRow = ARGBToYRow_AVX2; |
| 2989 | } |
| 2990 | } |
| 2991 | #endif |
| 2992 | #if defined(HAS_ARGBTOUVROW_AVX2) |
| 2993 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 2994 | ARGBToUVRow = ARGBToUVRow_Any_AVX2; |
| 2995 | if (IS_ALIGNED(width, 32)) { |
| 2996 | ARGBToUVRow = ARGBToUVRow_AVX2; |
| 2997 | } |
| 2998 | } |
| 2999 | #endif |
| 3000 | #endif |
| 3001 | { |
| 3002 | #if !(defined(HAS_RGB565TOYROW_NEON) || defined(HAS_RGB565TOYROW_MSA) || \ |
| 3003 | defined(HAS_RGB565TOYROW_LSX) || defined(HAS_RGB565TOYROW_LASX)) |
| 3004 | // Allocate 2 rows of ARGB. |
| 3005 | const int row_size = (width * 4 + 31) & ~31; |
| 3006 | align_buffer_64(row, row_size * 2); |
| 3007 | #endif |
| 3008 | for (y = 0; y < height - 1; y += 2) { |
| 3009 | #if (defined(HAS_RGB565TOYROW_NEON) || defined(HAS_RGB565TOYROW_MSA) || \ |
| 3010 | defined(HAS_RGB565TOYROW_LSX) || defined(HAS_RGB565TOYROW_LASX)) |
| 3011 | RGB565ToUVRow(src_rgb565, src_stride_rgb565, dst_u, dst_v, width); |
| 3012 | RGB565ToYRow(src_rgb565, dst_y, width); |
| 3013 | RGB565ToYRow(src_rgb565 + src_stride_rgb565, dst_y + dst_stride_y, width); |
| 3014 | #else |
| 3015 | RGB565ToARGBRow(src_rgb565, row, width); |
| 3016 | RGB565ToARGBRow(src_rgb565 + src_stride_rgb565, row + row_size, width); |
| 3017 | ARGBToUVRow(row, row_size, dst_u, dst_v, width); |
| 3018 | ARGBToYRow(row, dst_y, width); |
| 3019 | ARGBToYRow(row + row_size, dst_y + dst_stride_y, width); |
| 3020 | #endif |
| 3021 | src_rgb565 += src_stride_rgb565 * 2; |
| 3022 | dst_y += dst_stride_y * 2; |
| 3023 | dst_u += dst_stride_u; |
| 3024 | dst_v += dst_stride_v; |
| 3025 | } |
| 3026 | if (height & 1) { |
| 3027 | #if (defined(HAS_RGB565TOYROW_NEON) || defined(HAS_RGB565TOYROW_MSA) || \ |
| 3028 | defined(HAS_RGB565TOYROW_LSX) || defined(HAS_RGB565TOYROW_LASX)) |
| 3029 | RGB565ToUVRow(src_rgb565, 0, dst_u, dst_v, width); |
| 3030 | RGB565ToYRow(src_rgb565, dst_y, width); |
| 3031 | #else |
| 3032 | RGB565ToARGBRow(src_rgb565, row, width); |
| 3033 | ARGBToUVRow(row, 0, dst_u, dst_v, width); |
| 3034 | ARGBToYRow(row, dst_y, width); |
| 3035 | #endif |
| 3036 | } |
| 3037 | #if !(defined(HAS_RGB565TOYROW_NEON) || defined(HAS_RGB565TOYROW_MSA) || \ |
| 3038 | defined(HAS_RGB565TOYROW_LSX) || defined(HAS_RGB565TOYROW_LASX)) |
| 3039 | free_aligned_buffer_64(row); |
| 3040 | #endif |
| 3041 | } |
| 3042 | return 0; |
| 3043 | } |
| 3044 |
| 3045 | // Convert ARGB1555 to I420. |
| 3046 | LIBYUV_API |
| 3047 | int ARGB1555ToI420(const uint8_t* src_argb1555, |
| 3048 | int src_stride_argb1555, |
| 3049 | uint8_t* dst_y, |
| 3050 | int dst_stride_y, |
| 3051 | uint8_t* dst_u, |
| 3052 | int dst_stride_u, |
| 3053 | uint8_t* dst_v, |
| 3054 | int dst_stride_v, |
| 3055 | int width, |
| 3056 | int height) { |
| 3057 | int y; |
| 3058 | #if (defined(HAS_ARGB1555TOYROW_NEON) || defined(HAS_ARGB1555TOYROW_MSA) || \ |
| 3059 | defined(HAS_ARGB1555TOYROW_LSX) || defined(HAS_ARGB1555TOYROW_LASX)) |
| 3060 | void (*ARGB1555ToUVRow)(const uint8_t* src_argb1555, int src_stride_argb1555, |
| 3061 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 3062 | ARGB1555ToUVRow_C; |
| 3063 | void (*ARGB1555ToYRow)(const uint8_t* src_argb1555, uint8_t* dst_y, |
| 3064 | int width) = ARGB1555ToYRow_C; |
| 3065 | #else |
| 3066 | void (*ARGB1555ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, |
| 3067 | int width) = ARGB1555ToARGBRow_C; |
| 3068 | void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, |
| 3069 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 3070 | ARGBToUVRow_C; |
| 3071 | void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = |
| 3072 | ARGBToYRow_C; |
| 3073 | #endif |
| 3074 | if (!src_argb1555 || !dst_y || !dst_u || !dst_v || width <= 0 || |
| 3075 | height == 0) { |
| 3076 | return -1; |
| 3077 | } |
| 3078 | // Negative height means invert the image. |
| 3079 | if (height < 0) { |
| 3080 | height = -height; |
| 3081 | src_argb1555 = src_argb1555 + (height - 1) * src_stride_argb1555; |
| 3082 | src_stride_argb1555 = -src_stride_argb1555; |
| 3083 | } |
| 3084 |
| 3085 | // Neon version does direct ARGB1555 to YUV. |
| 3086 | #if defined(HAS_ARGB1555TOYROW_NEON) |
| 3087 | if (TestCpuFlag(kCpuHasNEON)) { |
| 3088 | ARGB1555ToUVRow = ARGB1555ToUVRow_Any_NEON; |
| 3089 | ARGB1555ToYRow = ARGB1555ToYRow_Any_NEON; |
| 3090 | if (IS_ALIGNED(width, 8)) { |
| 3091 | ARGB1555ToYRow = ARGB1555ToYRow_NEON; |
| 3092 | if (IS_ALIGNED(width, 16)) { |
| 3093 | ARGB1555ToUVRow = ARGB1555ToUVRow_NEON; |
| 3094 | } |
| 3095 | } |
| 3096 | } |
| 3097 | // MSA version does direct ARGB1555 to YUV. |
| 3098 | #elif (defined(HAS_ARGB1555TOYROW_MSA) || defined(HAS_ARGB1555TOYROW_LSX) || \ |
| 3099 | defined(HAS_ARGB1555TOYROW_LASX)) |
| 3100 | #if defined(HAS_ARGB1555TOYROW_MSA) && defined(HAS_ARGB1555TOUVROW_MSA) |
| 3101 | if (TestCpuFlag(kCpuHasMSA)) { |
| 3102 | ARGB1555ToUVRow = ARGB1555ToUVRow_Any_MSA; |
| 3103 | ARGB1555ToYRow = ARGB1555ToYRow_Any_MSA; |
| 3104 | if (IS_ALIGNED(width, 16)) { |
| 3105 | ARGB1555ToYRow = ARGB1555ToYRow_MSA; |
| 3106 | ARGB1555ToUVRow = ARGB1555ToUVRow_MSA; |
| 3107 | } |
| 3108 | } |
| 3109 | #endif |
| 3110 | #if defined(HAS_ARGB1555TOYROW_LSX) && defined(HAS_ARGB1555TOUVROW_LSX) |
| 3111 | if (TestCpuFlag(kCpuHasLSX)) { |
| 3112 | ARGB1555ToUVRow = ARGB1555ToUVRow_Any_LSX; |
| 3113 | ARGB1555ToYRow = ARGB1555ToYRow_Any_LSX; |
| 3114 | if (IS_ALIGNED(width, 16)) { |
| 3115 | ARGB1555ToYRow = ARGB1555ToYRow_LSX; |
| 3116 | ARGB1555ToUVRow = ARGB1555ToUVRow_LSX; |
| 3117 | } |
| 3118 | } |
| 3119 | #endif |
| 3120 | #if defined(HAS_ARGB1555TOYROW_LASX) && defined(HAS_ARGB1555TOUVROW_LASX) |
| 3121 | if (TestCpuFlag(kCpuHasLASX)) { |
| 3122 | ARGB1555ToUVRow = ARGB1555ToUVRow_Any_LASX; |
| 3123 | ARGB1555ToYRow = ARGB1555ToYRow_Any_LASX; |
| 3124 | if (IS_ALIGNED(width, 32)) { |
| 3125 | ARGB1555ToYRow = ARGB1555ToYRow_LASX; |
| 3126 | ARGB1555ToUVRow = ARGB1555ToUVRow_LASX; |
| 3127 | } |
| 3128 | } |
| 3129 | #endif |
| 3130 | // Other platforms do intermediate conversion from ARGB1555 to ARGB. |
| 3131 | #else |
| 3132 | #if defined(HAS_ARGB1555TOARGBROW_SSE2) |
| 3133 | if (TestCpuFlag(kCpuHasSSE2)) { |
| 3134 | ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_SSE2; |
| 3135 | if (IS_ALIGNED(width, 8)) { |
| 3136 | ARGB1555ToARGBRow = ARGB1555ToARGBRow_SSE2; |
| 3137 | } |
| 3138 | } |
| 3139 | #endif |
| 3140 | #if defined(HAS_ARGB1555TOARGBROW_AVX2) |
| 3141 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 3142 | ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_AVX2; |
| 3143 | if (IS_ALIGNED(width, 16)) { |
| 3144 | ARGB1555ToARGBRow = ARGB1555ToARGBRow_AVX2; |
| 3145 | } |
| 3146 | } |
| 3147 | #endif |
| 3148 | #if defined(HAS_ARGBTOYROW_SSSE3) |
| 3149 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 3150 | ARGBToYRow = ARGBToYRow_Any_SSSE3; |
| 3151 | if (IS_ALIGNED(width, 16)) { |
| 3152 | ARGBToYRow = ARGBToYRow_SSSE3; |
| 3153 | } |
| 3154 | } |
| 3155 | #endif |
| 3156 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 3157 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 3158 | ARGBToUVRow = ARGBToUVRow_Any_SSSE3; |
| 3159 | if (IS_ALIGNED(width, 16)) { |
| 3160 | ARGBToUVRow = ARGBToUVRow_SSSE3; |
| 3161 | } |
| 3162 | } |
| 3163 | #endif |
| 3164 | #if defined(HAS_ARGBTOYROW_AVX2) |
| 3165 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 3166 | ARGBToYRow = ARGBToYRow_Any_AVX2; |
| 3167 | if (IS_ALIGNED(width, 32)) { |
| 3168 | ARGBToYRow = ARGBToYRow_AVX2; |
| 3169 | } |
| 3170 | } |
| 3171 | #endif |
| 3172 | #if defined(HAS_ARGBTOUVROW_AVX2) |
| 3173 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 3174 | ARGBToUVRow = ARGBToUVRow_Any_AVX2; |
| 3175 | if (IS_ALIGNED(width, 32)) { |
| 3176 | ARGBToUVRow = ARGBToUVRow_AVX2; |
| 3177 | } |
| 3178 | } |
| 3179 | #endif |
| 3180 | #endif |
| 3181 | { |
| 3182 | #if !(defined(HAS_ARGB1555TOYROW_NEON) || defined(HAS_ARGB1555TOYROW_MSA) || \ |
| 3183 | defined(HAS_ARGB1555TOYROW_LSX) || defined(HAS_ARGB1555TOYROW_LASX)) |
| 3184 | // Allocate 2 rows of ARGB. |
| 3185 | const int row_size = (width * 4 + 31) & ~31; |
| 3186 | align_buffer_64(row, row_size * 2); |
| 3187 | #endif |
| 3188 |
| 3189 | for (y = 0; y < height - 1; y += 2) { |
| 3190 | #if (defined(HAS_ARGB1555TOYROW_NEON) || defined(HAS_ARGB1555TOYROW_MSA) || \ |
| 3191 | defined(HAS_ARGB1555TOYROW_LSX) || defined(HAS_ARGB1555TOYROW_LASX)) |
| 3192 | ARGB1555ToUVRow(src_argb1555, src_stride_argb1555, dst_u, dst_v, width); |
| 3193 | ARGB1555ToYRow(src_argb1555, dst_y, width); |
| 3194 | ARGB1555ToYRow(src_argb1555 + src_stride_argb1555, dst_y + dst_stride_y, |
| 3195 | width); |
| 3196 | #else |
| 3197 | ARGB1555ToARGBRow(src_argb1555, row, width); |
| 3198 | ARGB1555ToARGBRow(src_argb1555 + src_stride_argb1555, row + row_size, |
| 3199 | width); |
| 3200 | ARGBToUVRow(row, row_size, dst_u, dst_v, width); |
| 3201 | ARGBToYRow(row, dst_y, width); |
| 3202 | ARGBToYRow(row + row_size, dst_y + dst_stride_y, width); |
| 3203 | #endif |
| 3204 | src_argb1555 += src_stride_argb1555 * 2; |
| 3205 | dst_y += dst_stride_y * 2; |
| 3206 | dst_u += dst_stride_u; |
| 3207 | dst_v += dst_stride_v; |
| 3208 | } |
| 3209 | if (height & 1) { |
| 3210 | #if (defined(HAS_ARGB1555TOYROW_NEON) || defined(HAS_ARGB1555TOYROW_MSA) || \ |
| 3211 | defined(HAS_ARGB1555TOYROW_LSX) || defined(HAS_ARGB1555TOYROW_LASX)) |
| 3212 | ARGB1555ToUVRow(src_argb1555, 0, dst_u, dst_v, width); |
| 3213 | ARGB1555ToYRow(src_argb1555, dst_y, width); |
| 3214 | #else |
| 3215 | ARGB1555ToARGBRow(src_argb1555, row, width); |
| 3216 | ARGBToUVRow(row, 0, dst_u, dst_v, width); |
| 3217 | ARGBToYRow(row, dst_y, width); |
| 3218 | #endif |
| 3219 | } |
| 3220 | #if !(defined(HAS_ARGB1555TOYROW_NEON) || defined(HAS_ARGB1555TOYROW_MSA) || \ |
| 3221 | defined(HAS_ARGB1555TOYROW_LSX) || defined(HAS_ARGB1555TOYROW_LASX)) |
| 3222 | free_aligned_buffer_64(row); |
| 3223 | #endif |
| 3224 | } |
| 3225 | return 0; |
| 3226 | } |
| 3227 |
| 3228 | // Convert ARGB4444 to I420. |
| 3229 | LIBYUV_API |
| 3230 | int ARGB4444ToI420(const uint8_t* src_argb4444, |
| 3231 | int src_stride_argb4444, |
| 3232 | uint8_t* dst_y, |
| 3233 | int dst_stride_y, |
| 3234 | uint8_t* dst_u, |
| 3235 | int dst_stride_u, |
| 3236 | uint8_t* dst_v, |
| 3237 | int dst_stride_v, |
| 3238 | int width, |
| 3239 | int height) { |
| 3240 | int y; |
| 3241 | #if defined(HAS_ARGB4444TOYROW_NEON) |
| 3242 | void (*ARGB4444ToUVRow)(const uint8_t* src_argb4444, int src_stride_argb4444, |
| 3243 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 3244 | ARGB4444ToUVRow_C; |
| 3245 | void (*ARGB4444ToYRow)(const uint8_t* src_argb4444, uint8_t* dst_y, |
| 3246 | int width) = ARGB4444ToYRow_C; |
| 3247 | #else |
| 3248 | void (*ARGB4444ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, |
| 3249 | int width) = ARGB4444ToARGBRow_C; |
| 3250 | void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, |
| 3251 | uint8_t* dst_u, uint8_t* dst_v, int width) = |
| 3252 | ARGBToUVRow_C; |
| 3253 | void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = |
| 3254 | ARGBToYRow_C; |
| 3255 | #endif |
| 3256 | if (!src_argb4444 || !dst_y || !dst_u || !dst_v || width <= 0 || |
| 3257 | height == 0) { |
| 3258 | return -1; |
| 3259 | } |
| 3260 | // Negative height means invert the image. |
| 3261 | if (height < 0) { |
| 3262 | height = -height; |
| 3263 | src_argb4444 = src_argb4444 + (height - 1) * src_stride_argb4444; |
| 3264 | src_stride_argb4444 = -src_stride_argb4444; |
| 3265 | } |
| 3266 |
| 3267 | // Neon version does direct ARGB4444 to YUV. |
| 3268 | #if defined(HAS_ARGB4444TOYROW_NEON) |
| 3269 | if (TestCpuFlag(kCpuHasNEON)) { |
| 3270 | ARGB4444ToUVRow = ARGB4444ToUVRow_Any_NEON; |
| 3271 | ARGB4444ToYRow = ARGB4444ToYRow_Any_NEON; |
| 3272 | if (IS_ALIGNED(width, 8)) { |
| 3273 | ARGB4444ToYRow = ARGB4444ToYRow_NEON; |
| 3274 | if (IS_ALIGNED(width, 16)) { |
| 3275 | ARGB4444ToUVRow = ARGB4444ToUVRow_NEON; |
| 3276 | } |
| 3277 | } |
| 3278 | } |
| 3279 | // Other platforms do intermediate conversion from ARGB4444 to ARGB. |
| 3280 | #else |
| 3281 | #if defined(HAS_ARGB4444TOARGBROW_SSE2) |
| 3282 | if (TestCpuFlag(kCpuHasSSE2)) { |
| 3283 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_SSE2; |
| 3284 | if (IS_ALIGNED(width, 8)) { |
| 3285 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_SSE2; |
| 3286 | } |
| 3287 | } |
| 3288 | #endif |
| 3289 | #if defined(HAS_ARGB4444TOARGBROW_AVX2) |
| 3290 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 3291 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_AVX2; |
| 3292 | if (IS_ALIGNED(width, 16)) { |
| 3293 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_AVX2; |
| 3294 | } |
| 3295 | } |
| 3296 | #endif |
| 3297 | #if defined(HAS_ARGB4444TOARGBROW_MSA) |
| 3298 | if (TestCpuFlag(kCpuHasMSA)) { |
| 3299 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_MSA; |
| 3300 | if (IS_ALIGNED(width, 16)) { |
| 3301 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_MSA; |
| 3302 | } |
| 3303 | } |
| 3304 | #endif |
| 3305 | #if defined(HAS_ARGB4444TOARGBROW_LSX) |
| 3306 | if (TestCpuFlag(kCpuHasLSX)) { |
| 3307 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_LSX; |
| 3308 | if (IS_ALIGNED(width, 16)) { |
| 3309 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_LSX; |
| 3310 | } |
| 3311 | } |
| 3312 | #endif |
| 3313 | #if defined(HAS_ARGB4444TOARGBROW_LASX) |
| 3314 | if (TestCpuFlag(kCpuHasLASX)) { |
| 3315 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_LASX; |
| 3316 | if (IS_ALIGNED(width, 32)) { |
| 3317 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_LASX; |
| 3318 | } |
| 3319 | } |
| 3320 | #endif |
| 3321 | #if defined(HAS_ARGBTOYROW_SSSE3) |
| 3322 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 3323 | ARGBToYRow = ARGBToYRow_Any_SSSE3; |
| 3324 | if (IS_ALIGNED(width, 16)) { |
| 3325 | ARGBToYRow = ARGBToYRow_SSSE3; |
| 3326 | } |
| 3327 | } |
| 3328 | #endif |
| 3329 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 3330 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 3331 | ARGBToUVRow = ARGBToUVRow_Any_SSSE3; |
| 3332 | if (IS_ALIGNED(width, 16)) { |
| 3333 | ARGBToUVRow = ARGBToUVRow_SSSE3; |
| 3334 | } |
| 3335 | } |
| 3336 | #endif |
| 3337 | #if defined(HAS_ARGBTOYROW_AVX2) |
| 3338 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 3339 | ARGBToYRow = ARGBToYRow_Any_AVX2; |
| 3340 | if (IS_ALIGNED(width, 32)) { |
| 3341 | ARGBToYRow = ARGBToYRow_AVX2; |
| 3342 | } |
| 3343 | } |
| 3344 | #endif |
| 3345 | #if defined(HAS_ARGBTOUVROW_AVX2) |
| 3346 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 3347 | ARGBToUVRow = ARGBToUVRow_Any_AVX2; |
| 3348 | if (IS_ALIGNED(width, 32)) { |
| 3349 | ARGBToUVRow = ARGBToUVRow_AVX2; |
| 3350 | } |
| 3351 | } |
| 3352 | #endif |
| 3353 | #if defined(HAS_ARGBTOYROW_MSA) && defined(HAS_ARGBTOUVROW_MSA) |
| 3354 | if (TestCpuFlag(kCpuHasMSA)) { |
| 3355 | ARGBToUVRow = ARGBToUVRow_Any_MSA; |
| 3356 | ARGBToYRow = ARGBToYRow_Any_MSA; |
| 3357 | if (IS_ALIGNED(width, 16)) { |
| 3358 | ARGBToYRow = ARGBToYRow_MSA; |
| 3359 | if (IS_ALIGNED(width, 32)) { |
| 3360 | ARGBToUVRow = ARGBToUVRow_MSA; |
| 3361 | } |
| 3362 | } |
| 3363 | } |
| 3364 | #endif |
| 3365 | #if defined(HAS_ARGBTOYROW_LSX) |
| 3366 | if (TestCpuFlag(kCpuHasLSX)) { |
| 3367 | ARGBToYRow = ARGBToYRow_Any_LSX; |
| 3368 | if (IS_ALIGNED(width, 16)) { |
| 3369 | ARGBToYRow = ARGBToYRow_LSX; |
| 3370 | } |
| 3371 | } |
| 3372 | #endif |
| 3373 | #if defined(HAS_ARGBTOYROW_LASX) && defined(HAS_ARGBTOUVROW_LASX) |
| 3374 | if (TestCpuFlag(kCpuHasLASX)) { |
| 3375 | ARGBToYRow = ARGBToYRow_Any_LASX; |
| 3376 | ARGBToUVRow = ARGBToUVRow_Any_LASX; |
| 3377 | if (IS_ALIGNED(width, 32)) { |
| 3378 | ARGBToYRow = ARGBToYRow_LASX; |
| 3379 | ARGBToUVRow = ARGBToUVRow_LASX; |
| 3380 | } |
| 3381 | } |
| 3382 | #endif |
| 3383 | #endif |
| 3384 |
| 3385 | { |
| 3386 | #if !(defined(HAS_ARGB4444TOYROW_NEON)) |
| 3387 | // Allocate 2 rows of ARGB. |
| 3388 | const int row_size = (width * 4 + 31) & ~31; |
| 3389 | align_buffer_64(row, row_size * 2); |
| 3390 | #endif |
| 3391 |
| 3392 | for (y = 0; y < height - 1; y += 2) { |
| 3393 | #if defined(HAS_ARGB4444TOYROW_NEON) |
| 3394 | ARGB4444ToUVRow(src_argb4444, src_stride_argb4444, dst_u, dst_v, width); |
| 3395 | ARGB4444ToYRow(src_argb4444, dst_y, width); |
| 3396 | ARGB4444ToYRow(src_argb4444 + src_stride_argb4444, dst_y + dst_stride_y, |
| 3397 | width); |
| 3398 | #else |
| 3399 | ARGB4444ToARGBRow(src_argb4444, row, width); |
| 3400 | ARGB4444ToARGBRow(src_argb4444 + src_stride_argb4444, row + row_size, |
| 3401 | width); |
| 3402 | ARGBToUVRow(row, row_size, dst_u, dst_v, width); |
| 3403 | ARGBToYRow(row, dst_y, width); |
| 3404 | ARGBToYRow(row + row_size, dst_y + dst_stride_y, width); |
| 3405 | #endif |
| 3406 | src_argb4444 += src_stride_argb4444 * 2; |
| 3407 | dst_y += dst_stride_y * 2; |
| 3408 | dst_u += dst_stride_u; |
| 3409 | dst_v += dst_stride_v; |
| 3410 | } |
| 3411 | if (height & 1) { |
| 3412 | #if defined(HAS_ARGB4444TOYROW_NEON) |
| 3413 | ARGB4444ToUVRow(src_argb4444, 0, dst_u, dst_v, width); |
| 3414 | ARGB4444ToYRow(src_argb4444, dst_y, width); |
| 3415 | #else |
| 3416 | ARGB4444ToARGBRow(src_argb4444, row, width); |
| 3417 | ARGBToUVRow(row, 0, dst_u, dst_v, width); |
| 3418 | ARGBToYRow(row, dst_y, width); |
| 3419 | #endif |
| 3420 | } |
| 3421 | #if !(defined(HAS_ARGB4444TOYROW_NEON)) |
| 3422 | free_aligned_buffer_64(row); |
| 3423 | #endif |
| 3424 | } |
| 3425 | return 0; |
| 3426 | } |
| 3427 |
| 3428 | // Convert RGB24 to J400. |
| 3429 | LIBYUV_API |
| 3430 | int RGB24ToJ400(const uint8_t* src_rgb24, |
| 3431 | int src_stride_rgb24, |
| 3432 | uint8_t* dst_yj, |
| 3433 | int dst_stride_yj, |
| 3434 | int width, |
| 3435 | int height) { |
| 3436 | int y; |
| 3437 | void (*RGB24ToYJRow)(const uint8_t* src_rgb24, uint8_t* dst_yj, int width) = |
| 3438 | RGB24ToYJRow_C; |
| 3439 | if (!src_rgb24 || !dst_yj || width <= 0 || height == 0) { |
| 3440 | return -1; |
| 3441 | } |
| 3442 | if (height < 0) { |
| 3443 | height = -height; |
| 3444 | src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; |
| 3445 | src_stride_rgb24 = -src_stride_rgb24; |
| 3446 | } |
| 3447 | // Coalesce rows. |
| 3448 | if (src_stride_rgb24 == width * 3 && dst_stride_yj == width) { |
| 3449 | width *= height; |
| 3450 | height = 1; |
| 3451 | src_stride_rgb24 = dst_stride_yj = 0; |
| 3452 | } |
| 3453 | #if defined(HAS_RGB24TOYJROW_SSSE3) |
| 3454 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 3455 | RGB24ToYJRow = RGB24ToYJRow_Any_SSSE3; |
| 3456 | if (IS_ALIGNED(width, 16)) { |
| 3457 | RGB24ToYJRow = RGB24ToYJRow_SSSE3; |
| 3458 | } |
| 3459 | } |
| 3460 | #endif |
| 3461 | #if defined(HAS_RGB24TOYJROW_AVX2) |
| 3462 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 3463 | RGB24ToYJRow = RGB24ToYJRow_Any_AVX2; |
| 3464 | if (IS_ALIGNED(width, 32)) { |
| 3465 | RGB24ToYJRow = RGB24ToYJRow_AVX2; |
| 3466 | } |
| 3467 | } |
| 3468 | #endif |
| 3469 | #if defined(HAS_RGB24TOYJROW_NEON) |
| 3470 | if (TestCpuFlag(kCpuHasNEON)) { |
| 3471 | RGB24ToYJRow = RGB24ToYJRow_Any_NEON; |
| 3472 | if (IS_ALIGNED(width, 16)) { |
| 3473 | RGB24ToYJRow = RGB24ToYJRow_NEON; |
| 3474 | } |
| 3475 | } |
| 3476 | #endif |
| 3477 | #if defined(HAS_RGB24TOYJROW_MSA) |
| 3478 | if (TestCpuFlag(kCpuHasMSA)) { |
| 3479 | RGB24ToYJRow = RGB24ToYJRow_Any_MSA; |
| 3480 | if (IS_ALIGNED(width, 16)) { |
| 3481 | RGB24ToYJRow = RGB24ToYJRow_MSA; |
| 3482 | } |
| 3483 | } |
| 3484 | #endif |
| 3485 | #if defined(HAS_RGB24TOYJROW_LSX) |
| 3486 | if (TestCpuFlag(kCpuHasLSX)) { |
| 3487 | RGB24ToYJRow = RGB24ToYJRow_Any_LSX; |
| 3488 | if (IS_ALIGNED(width, 16)) { |
| 3489 | RGB24ToYJRow = RGB24ToYJRow_LSX; |
| 3490 | } |
| 3491 | } |
| 3492 | #endif |
| 3493 | #if defined(HAS_RGB24TOYJROW_LASX) |
| 3494 | if (TestCpuFlag(kCpuHasLASX)) { |
| 3495 | RGB24ToYJRow = RGB24ToYJRow_Any_LASX; |
| 3496 | if (IS_ALIGNED(width, 32)) { |
| 3497 | RGB24ToYJRow = RGB24ToYJRow_LASX; |
| 3498 | } |
| 3499 | } |
| 3500 | #endif |
| 3501 |
| 3502 | for (y = 0; y < height; ++y) { |
| 3503 | RGB24ToYJRow(src_rgb24, dst_yj, width); |
| 3504 | src_rgb24 += src_stride_rgb24; |
| 3505 | dst_yj += dst_stride_yj; |
| 3506 | } |
| 3507 | return 0; |
| 3508 | } |
| 3509 |
| 3510 | // Convert RAW to J400. |
| 3511 | LIBYUV_API |
| 3512 | int RAWToJ400(const uint8_t* src_raw, |
| 3513 | int src_stride_raw, |
| 3514 | uint8_t* dst_yj, |
| 3515 | int dst_stride_yj, |
| 3516 | int width, |
| 3517 | int height) { |
| 3518 | int y; |
| 3519 | void (*RAWToYJRow)(const uint8_t* src_raw, uint8_t* dst_yj, int width) = |
| 3520 | RAWToYJRow_C; |
| 3521 | if (!src_raw || !dst_yj || width <= 0 || height == 0) { |
| 3522 | return -1; |
| 3523 | } |
| 3524 |
| 3525 | if (height < 0) { |
| 3526 | height = -height; |
| 3527 | src_raw = src_raw + (height - 1) * src_stride_raw; |
| 3528 | src_stride_raw = -src_stride_raw; |
| 3529 | } |
| 3530 | // Coalesce rows. |
| 3531 | if (src_stride_raw == width * 3 && dst_stride_yj == width) { |
| 3532 | width *= height; |
| 3533 | height = 1; |
| 3534 | src_stride_raw = dst_stride_yj = 0; |
| 3535 | } |
| 3536 |
| 3537 | #if defined(HAS_RAWTOYJROW_SSSE3) |
| 3538 | if (TestCpuFlag(kCpuHasSSSE3)) { |
| 3539 | RAWToYJRow = RAWToYJRow_Any_SSSE3; |
| 3540 | if (IS_ALIGNED(width, 16)) { |
| 3541 | RAWToYJRow = RAWToYJRow_SSSE3; |
| 3542 | } |
| 3543 | } |
| 3544 | #endif |
| 3545 | #if defined(HAS_RAWTOYJROW_AVX2) |
| 3546 | if (TestCpuFlag(kCpuHasAVX2)) { |
| 3547 | RAWToYJRow = RAWToYJRow_Any_AVX2; |
| 3548 | if (IS_ALIGNED(width, 32)) { |
| 3549 | RAWToYJRow = RAWToYJRow_AVX2; |
| 3550 | } |
| 3551 | } |
| 3552 | #endif |
| 3553 | #if defined(HAS_RAWTOYJROW_NEON) |
| 3554 | if (TestCpuFlag(kCpuHasNEON)) { |
| 3555 | RAWToYJRow = RAWToYJRow_Any_NEON; |
| 3556 | if (IS_ALIGNED(width, 16)) { |
| 3557 | RAWToYJRow = RAWToYJRow_NEON; |
| 3558 | } |
| 3559 | } |
| 3560 | #endif |
| 3561 | #if defined(HAS_RAWTOYJROW_MSA) |
| 3562 | if (TestCpuFlag(kCpuHasMSA)) { |
| 3563 | RAWToYJRow = RAWToYJRow_Any_MSA; |
| 3564 | if (IS_ALIGNED(width, 16)) { |
| 3565 | RAWToYJRow = RAWToYJRow_MSA; |
| 3566 | } |
| 3567 | } |
| 3568 | #endif |
| 3569 | #if defined(HAS_RAWTOYJROW_LSX) |
| 3570 | if (TestCpuFlag(kCpuHasLSX)) { |
| 3571 | RAWToYJRow = RAWToYJRow_Any_LSX; |
| 3572 | if (IS_ALIGNED(width, 16)) { |
| 3573 | RAWToYJRow = RAWToYJRow_LSX; |
| 3574 | } |
| 3575 | } |
| 3576 | #endif |
| 3577 | #if defined(HAS_RAWTOYJROW_LASX) |
| 3578 | if (TestCpuFlag(kCpuHasLASX)) { |
| 3579 | RAWToYJRow = RAWToYJRow_Any_LASX; |
| 3580 | if (IS_ALIGNED(width, 32)) { |
| 3581 | RAWToYJRow = RAWToYJRow_LASX; |
| 3582 | } |
| 3583 | } |
| 3584 | #endif |
| 3585 |
| 3586 | for (y = 0; y < height; ++y) { |
| 3587 | RAWToYJRow(src_raw, dst_yj, width); |
| 3588 | src_raw += src_stride_raw; |
| 3589 | dst_yj += dst_stride_yj; |
| 3590 | } |
| 3591 | return 0; |
| 3592 | } |
| 3593 |
| 3594 | // Convert Android420 to I420. |
| 3595 | LIBYUV_API |
| 3596 | int Android420ToI420(const uint8_t* src_y, |
| 3597 | int src_stride_y, |
| 3598 | const uint8_t* src_u, |
| 3599 | int src_stride_u, |
| 3600 | const uint8_t* src_v, |
| 3601 | int src_stride_v, |
| 3602 | int src_pixel_stride_uv, |
| 3603 | uint8_t* dst_y, |
| 3604 | int dst_stride_y, |
| 3605 | uint8_t* dst_u, |
| 3606 | int dst_stride_u, |
| 3607 | uint8_t* dst_v, |
| 3608 | int dst_stride_v, |
| 3609 | int width, |
| 3610 | int height) { |
| 3611 | return Android420ToI420Rotate(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 3612 | src_stride_v, src_pixel_stride_uv, dst_y, |
| 3613 | dst_stride_y, dst_u, dst_stride_u, dst_v, |
| 3614 | dst_stride_v, width, height, kRotate0); |
| 3615 | } |
| 3616 |
| 3617 | #ifdef __cplusplus |
| 3618 | } // extern "C" |
| 3619 | } // namespace libyuv |
| 3620 | #endif |
| 3621 |