| 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/scale.h" // For ScalePlane() |
| 18 | #include "libyuv/row.h" |
| 19 |
| 20 | #ifdef __cplusplus |
| 21 | namespace libyuv { |
| 22 | extern "C" { |
| 23 | #endif |
| 24 |
| 25 | #define SUBSAMPLE(v, a, s) (v < 0) ? (-((-v + a) >> s)) : ((v + a) >> s) |
| 26 | static __inline int Abs(int v) { |
| 27 | return v >= 0 ? v : -v; |
| 28 | } |
| 29 |
| 30 | // Any I4xx To I420 format with mirroring. |
| 31 | static int I4xxToI420(const uint8* src_y, int src_stride_y, |
| 32 | const uint8* src_u, int src_stride_u, |
| 33 | const uint8* src_v, int src_stride_v, |
| 34 | uint8* dst_y, int dst_stride_y, |
| 35 | uint8* dst_u, int dst_stride_u, |
| 36 | uint8* dst_v, int dst_stride_v, |
| 37 | int src_y_width, int src_y_height, |
| 38 | int src_uv_width, int src_uv_height) { |
| 39 | const int dst_y_width = Abs(src_y_width); |
| 40 | const int dst_y_height = Abs(src_y_height); |
| 41 | const int dst_uv_width = SUBSAMPLE(dst_y_width, 1, 1); |
| 42 | const int dst_uv_height = SUBSAMPLE(dst_y_height, 1, 1); |
| 43 | if (src_y_width == 0 || src_y_height == 0 || |
| 44 | src_uv_width == 0 || src_uv_height == 0) { |
| 45 | return -1; |
| 46 | } |
| 47 | ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, |
| 48 | dst_y, dst_stride_y, dst_y_width, dst_y_height, |
| 49 | kFilterBilinear); |
| 50 | ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, |
| 51 | dst_u, dst_stride_u, dst_uv_width, dst_uv_height, |
| 52 | kFilterBilinear); |
| 53 | ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, |
| 54 | dst_v, dst_stride_v, dst_uv_width, dst_uv_height, |
| 55 | kFilterBilinear); |
| 56 | return 0; |
| 57 | } |
| 58 |
| 59 | // Copy I420 with optional flipping |
| 60 | // TODO(fbarchard): Use Scale plane which supports mirroring, but ensure |
| 61 | // is does row coalescing. |
| 62 | LIBYUV_API |
| 63 | int I420Copy(const uint8* src_y, int src_stride_y, |
| 64 | const uint8* src_u, int src_stride_u, |
| 65 | const uint8* src_v, int src_stride_v, |
| 66 | uint8* dst_y, int dst_stride_y, |
| 67 | uint8* dst_u, int dst_stride_u, |
| 68 | uint8* dst_v, int dst_stride_v, |
| 69 | int width, int height) { |
| 70 | int halfwidth = (width + 1) >> 1; |
| 71 | int halfheight = (height + 1) >> 1; |
| 72 | if (!src_y || !src_u || !src_v || |
| 73 | !dst_y || !dst_u || !dst_v || |
| 74 | width <= 0 || height == 0) { |
| 75 | return -1; |
| 76 | } |
| 77 | // Negative height means invert the image. |
| 78 | if (height < 0) { |
| 79 | height = -height; |
| 80 | halfheight = (height + 1) >> 1; |
| 81 | src_y = src_y + (height - 1) * src_stride_y; |
| 82 | src_u = src_u + (halfheight - 1) * src_stride_u; |
| 83 | src_v = src_v + (halfheight - 1) * src_stride_v; |
| 84 | src_stride_y = -src_stride_y; |
| 85 | src_stride_u = -src_stride_u; |
| 86 | src_stride_v = -src_stride_v; |
| 87 | } |
| 88 |
| 89 | if (dst_y) { |
| 90 | CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); |
| 91 | } |
| 92 | // Copy UV planes. |
| 93 | CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, halfheight); |
| 94 | CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, halfheight); |
| 95 | return 0; |
| 96 | } |
| 97 |
| 98 | // 422 chroma is 1/2 width, 1x height |
| 99 | // 420 chroma is 1/2 width, 1/2 height |
| 100 | LIBYUV_API |
| 101 | int I422ToI420(const uint8* src_y, int src_stride_y, |
| 102 | const uint8* src_u, int src_stride_u, |
| 103 | const uint8* src_v, int src_stride_v, |
| 104 | uint8* dst_y, int dst_stride_y, |
| 105 | uint8* dst_u, int dst_stride_u, |
| 106 | uint8* dst_v, int dst_stride_v, |
| 107 | int width, int height) { |
| 108 | const int src_uv_width = SUBSAMPLE(width, 1, 1); |
| 109 | return I4xxToI420(src_y, src_stride_y, |
| 110 | src_u, src_stride_u, |
| 111 | src_v, src_stride_v, |
| 112 | dst_y, dst_stride_y, |
| 113 | dst_u, dst_stride_u, |
| 114 | dst_v, dst_stride_v, |
| 115 | width, height, |
| 116 | src_uv_width, height); |
| 117 | } |
| 118 |
| 119 | // 444 chroma is 1x width, 1x height |
| 120 | // 420 chroma is 1/2 width, 1/2 height |
| 121 | LIBYUV_API |
| 122 | int I444ToI420(const uint8* src_y, int src_stride_y, |
| 123 | const uint8* src_u, int src_stride_u, |
| 124 | const uint8* src_v, int src_stride_v, |
| 125 | uint8* dst_y, int dst_stride_y, |
| 126 | uint8* dst_u, int dst_stride_u, |
| 127 | uint8* dst_v, int dst_stride_v, |
| 128 | int width, int height) { |
| 129 | return I4xxToI420(src_y, src_stride_y, |
| 130 | src_u, src_stride_u, |
| 131 | src_v, src_stride_v, |
| 132 | dst_y, dst_stride_y, |
| 133 | dst_u, dst_stride_u, |
| 134 | dst_v, dst_stride_v, |
| 135 | width, height, |
| 136 | width, height); |
| 137 | } |
| 138 |
| 139 | // 411 chroma is 1/4 width, 1x height |
| 140 | // 420 chroma is 1/2 width, 1/2 height |
| 141 | LIBYUV_API |
| 142 | int I411ToI420(const uint8* src_y, int src_stride_y, |
| 143 | const uint8* src_u, int src_stride_u, |
| 144 | const uint8* src_v, int src_stride_v, |
| 145 | uint8* dst_y, int dst_stride_y, |
| 146 | uint8* dst_u, int dst_stride_u, |
| 147 | uint8* dst_v, int dst_stride_v, |
| 148 | int width, int height) { |
| 149 | const int src_uv_width = SUBSAMPLE(width, 3, 2); |
| 150 | return I4xxToI420(src_y, src_stride_y, |
| 151 | src_u, src_stride_u, |
| 152 | src_v, src_stride_v, |
| 153 | dst_y, dst_stride_y, |
| 154 | dst_u, dst_stride_u, |
| 155 | dst_v, dst_stride_v, |
| 156 | width, height, |
| 157 | src_uv_width, height); |
| 158 | } |
| 159 |
| 160 | // I400 is greyscale typically used in MJPG |
| 161 | LIBYUV_API |
| 162 | int I400ToI420(const uint8* src_y, int src_stride_y, |
| 163 | uint8* dst_y, int dst_stride_y, |
| 164 | uint8* dst_u, int dst_stride_u, |
| 165 | uint8* dst_v, int dst_stride_v, |
| 166 | int width, int height) { |
| 167 | int halfwidth = (width + 1) >> 1; |
| 168 | int halfheight = (height + 1) >> 1; |
| 169 | if (!src_y || !dst_y || !dst_u || !dst_v || |
| 170 | width <= 0 || height == 0) { |
| 171 | return -1; |
| 172 | } |
| 173 | // Negative height means invert the image. |
| 174 | if (height < 0) { |
| 175 | height = -height; |
| 176 | halfheight = (height + 1) >> 1; |
| 177 | src_y = src_y + (height - 1) * src_stride_y; |
| 178 | src_stride_y = -src_stride_y; |
| 179 | } |
| 180 | CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); |
| 181 | SetPlane(dst_u, dst_stride_u, halfwidth, halfheight, 128); |
| 182 | SetPlane(dst_v, dst_stride_v, halfwidth, halfheight, 128); |
| 183 | return 0; |
| 184 | } |
| 185 |
| 186 | static void CopyPlane2(const uint8* src, int src_stride_0, int src_stride_1, |
| 187 | uint8* dst, int dst_stride, |
| 188 | int width, int height) { |
| 189 | int y; |
| 190 | void (*CopyRow)(const uint8* src, uint8* dst, int width) = CopyRow_C; |
| 191 | #if defined(HAS_COPYROW_X86) |
| 192 | if (TestCpuFlag(kCpuHasX86) && IS_ALIGNED(width, 4)) { |
| 193 | CopyRow = CopyRow_X86; |
| 194 | } |
| 195 | #endif |
| 196 | #if defined(HAS_COPYROW_SSE2) |
| 197 | if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(width, 32) && |
| 198 | IS_ALIGNED(src, 16) && |
| 199 | IS_ALIGNED(src_stride_0, 16) && IS_ALIGNED(src_stride_1, 16) && |
| 200 | IS_ALIGNED(dst, 16) && IS_ALIGNED(dst_stride, 16)) { |
| 201 | CopyRow = CopyRow_SSE2; |
| 202 | } |
| 203 | #endif |
| 204 | #if defined(HAS_COPYROW_ERMS) |
| 205 | if (TestCpuFlag(kCpuHasERMS)) { |
| 206 | CopyRow = CopyRow_ERMS; |
| 207 | } |
| 208 | #endif |
| 209 | #if defined(HAS_COPYROW_NEON) |
| 210 | if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 32)) { |
| 211 | CopyRow = CopyRow_NEON; |
| 212 | } |
| 213 | #endif |
| 214 | #if defined(HAS_COPYROW_MIPS) |
| 215 | if (TestCpuFlag(kCpuHasMIPS)) { |
| 216 | CopyRow = CopyRow_MIPS; |
| 217 | } |
| 218 | #endif |
| 219 |
| 220 | // Copy plane |
| 221 | for (y = 0; y < height - 1; y += 2) { |
| 222 | CopyRow(src, dst, width); |
| 223 | CopyRow(src + src_stride_0, dst + dst_stride, width); |
| 224 | src += src_stride_0 + src_stride_1; |
| 225 | dst += dst_stride * 2; |
| 226 | } |
| 227 | if (height & 1) { |
| 228 | CopyRow(src, dst, width); |
| 229 | } |
| 230 | } |
| 231 |
| 232 | // Support converting from FOURCC_M420 |
| 233 | // Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for |
| 234 | // easy conversion to I420. |
| 235 | // M420 format description: |
| 236 | // M420 is row biplanar 420: 2 rows of Y and 1 row of UV. |
| 237 | // Chroma is half width / half height. (420) |
| 238 | // src_stride_m420 is row planar. Normally this will be the width in pixels. |
| 239 | // The UV plane is half width, but 2 values, so src_stride_m420 applies to |
| 240 | // this as well as the two Y planes. |
| 241 | static int X420ToI420(const uint8* src_y, |
| 242 | int src_stride_y0, int src_stride_y1, |
| 243 | const uint8* src_uv, int src_stride_uv, |
| 244 | uint8* dst_y, int dst_stride_y, |
| 245 | uint8* dst_u, int dst_stride_u, |
| 246 | uint8* dst_v, int dst_stride_v, |
| 247 | int width, int height) { |
| 248 | int y; |
| 249 | int halfwidth = (width + 1) >> 1; |
| 250 | int halfheight = (height + 1) >> 1; |
| 251 | void (*SplitUVRow)(const uint8* src_uv, uint8* dst_u, uint8* dst_v, int pix) = |
| 252 | SplitUVRow_C; |
| 253 | if (!src_y || !src_uv || |
| 254 | !dst_y || !dst_u || !dst_v || |
| 255 | width <= 0 || height == 0) { |
| 256 | return -1; |
| 257 | } |
| 258 | // Negative height means invert the image. |
| 259 | if (height < 0) { |
| 260 | height = -height; |
| 261 | halfheight = (height + 1) >> 1; |
| 262 | dst_y = dst_y + (height - 1) * dst_stride_y; |
| 263 | dst_u = dst_u + (halfheight - 1) * dst_stride_u; |
| 264 | dst_v = dst_v + (halfheight - 1) * dst_stride_v; |
| 265 | dst_stride_y = -dst_stride_y; |
| 266 | dst_stride_u = -dst_stride_u; |
| 267 | dst_stride_v = -dst_stride_v; |
| 268 | } |
| 269 | // Coalesce rows. |
| 270 | if (src_stride_y0 == width && |
| 271 | src_stride_y1 == width && |
| 272 | dst_stride_y == width) { |
| 273 | width *= height; |
| 274 | height = 1; |
| 275 | src_stride_y0 = src_stride_y1 = dst_stride_y = 0; |
| 276 | } |
| 277 | // Coalesce rows. |
| 278 | if (src_stride_uv == halfwidth * 2 && |
| 279 | dst_stride_u == halfwidth && |
| 280 | dst_stride_v == halfwidth) { |
| 281 | halfwidth *= halfheight; |
| 282 | halfheight = 1; |
| 283 | src_stride_uv = dst_stride_u = dst_stride_v = 0; |
| 284 | } |
| 285 | #if defined(HAS_SPLITUVROW_SSE2) |
| 286 | if (TestCpuFlag(kCpuHasSSE2) && halfwidth >= 16) { |
| 287 | SplitUVRow = SplitUVRow_Any_SSE2; |
| 288 | if (IS_ALIGNED(halfwidth, 16)) { |
| 289 | SplitUVRow = SplitUVRow_Unaligned_SSE2; |
| 290 | if (IS_ALIGNED(src_uv, 16) && IS_ALIGNED(src_stride_uv, 16) && |
| 291 | IS_ALIGNED(dst_u, 16) && IS_ALIGNED(dst_stride_u, 16) && |
| 292 | IS_ALIGNED(dst_v, 16) && IS_ALIGNED(dst_stride_v, 16)) { |
| 293 | SplitUVRow = SplitUVRow_SSE2; |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | #endif |
| 298 | #if defined(HAS_SPLITUVROW_AVX2) |
| 299 | if (TestCpuFlag(kCpuHasAVX2) && halfwidth >= 32) { |
| 300 | SplitUVRow = SplitUVRow_Any_AVX2; |
| 301 | if (IS_ALIGNED(halfwidth, 32)) { |
| 302 | SplitUVRow = SplitUVRow_AVX2; |
| 303 | } |
| 304 | } |
| 305 | #endif |
| 306 | #if defined(HAS_SPLITUVROW_NEON) |
| 307 | if (TestCpuFlag(kCpuHasNEON) && halfwidth >= 16) { |
| 308 | SplitUVRow = SplitUVRow_Any_NEON; |
| 309 | if (IS_ALIGNED(halfwidth, 16)) { |
| 310 | SplitUVRow = SplitUVRow_NEON; |
| 311 | } |
| 312 | } |
| 313 | #endif |
| 314 | #if defined(HAS_SPLITUVROW_MIPS_DSPR2) |
| 315 | if (TestCpuFlag(kCpuHasMIPS_DSPR2) && halfwidth >= 16) { |
| 316 | SplitUVRow = SplitUVRow_Any_MIPS_DSPR2; |
| 317 | if (IS_ALIGNED(halfwidth, 16)) { |
| 318 | SplitUVRow = SplitUVRow_Unaligned_MIPS_DSPR2; |
| 319 | if (IS_ALIGNED(src_uv, 4) && IS_ALIGNED(src_stride_uv, 4) && |
| 320 | IS_ALIGNED(dst_u, 4) && IS_ALIGNED(dst_stride_u, 4) && |
| 321 | IS_ALIGNED(dst_v, 4) && IS_ALIGNED(dst_stride_v, 4)) { |
| 322 | SplitUVRow = SplitUVRow_MIPS_DSPR2; |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | #endif |
| 327 |
| 328 | if (dst_y) { |
| 329 | if (src_stride_y0 == src_stride_y1) { |
| 330 | CopyPlane(src_y, src_stride_y0, dst_y, dst_stride_y, width, height); |
| 331 | } else { |
| 332 | CopyPlane2(src_y, src_stride_y0, src_stride_y1, dst_y, dst_stride_y, |
| 333 | width, height); |
| 334 | } |
| 335 | } |
| 336 |
| 337 | for (y = 0; y < halfheight; ++y) { |
| 338 | // Copy a row of UV. |
| 339 | SplitUVRow(src_uv, dst_u, dst_v, halfwidth); |
| 340 | dst_u += dst_stride_u; |
| 341 | dst_v += dst_stride_v; |
| 342 | src_uv += src_stride_uv; |
| 343 | } |
| 344 | return 0; |
| 345 | } |
| 346 |
| 347 | // Convert NV12 to I420. |
| 348 | LIBYUV_API |
| 349 | int NV12ToI420(const uint8* src_y, int src_stride_y, |
| 350 | const uint8* src_uv, int src_stride_uv, |
| 351 | uint8* dst_y, int dst_stride_y, |
| 352 | uint8* dst_u, int dst_stride_u, |
| 353 | uint8* dst_v, int dst_stride_v, |
| 354 | int width, int height) { |
| 355 | return X420ToI420(src_y, src_stride_y, src_stride_y, |
| 356 | src_uv, src_stride_uv, |
| 357 | dst_y, dst_stride_y, |
| 358 | dst_u, dst_stride_u, |
| 359 | dst_v, dst_stride_v, |
| 360 | width, height); |
| 361 | } |
| 362 |
| 363 | // Convert NV21 to I420. Same as NV12 but u and v pointers swapped. |
| 364 | LIBYUV_API |
| 365 | int NV21ToI420(const uint8* src_y, int src_stride_y, |
| 366 | const uint8* src_vu, int src_stride_vu, |
| 367 | uint8* dst_y, int dst_stride_y, |
| 368 | uint8* dst_u, int dst_stride_u, |
| 369 | uint8* dst_v, int dst_stride_v, |
| 370 | int width, int height) { |
| 371 | return X420ToI420(src_y, src_stride_y, src_stride_y, |
| 372 | src_vu, src_stride_vu, |
| 373 | dst_y, dst_stride_y, |
| 374 | dst_v, dst_stride_v, |
| 375 | dst_u, dst_stride_u, |
| 376 | width, height); |
| 377 | } |
| 378 |
| 379 | // Convert M420 to I420. |
| 380 | LIBYUV_API |
| 381 | int M420ToI420(const uint8* src_m420, int src_stride_m420, |
| 382 | uint8* dst_y, int dst_stride_y, |
| 383 | uint8* dst_u, int dst_stride_u, |
| 384 | uint8* dst_v, int dst_stride_v, |
| 385 | int width, int height) { |
| 386 | return X420ToI420(src_m420, src_stride_m420, src_stride_m420 * 2, |
| 387 | src_m420 + src_stride_m420 * 2, src_stride_m420 * 3, |
| 388 | dst_y, dst_stride_y, |
| 389 | dst_u, dst_stride_u, |
| 390 | dst_v, dst_stride_v, |
| 391 | width, height); |
| 392 | } |
| 393 |
| 394 | // Convert Q420 to I420. |
| 395 | // Format is rows of YY/YUYV |
| 396 | LIBYUV_API |
| 397 | int Q420ToI420(const uint8* src_y, int src_stride_y, |
| 398 | const uint8* src_yuy2, int src_stride_yuy2, |
| 399 | uint8* dst_y, int dst_stride_y, |
| 400 | uint8* dst_u, int dst_stride_u, |
| 401 | uint8* dst_v, int dst_stride_v, |
| 402 | int width, int height) { |
| 403 | int y; |
| 404 | int halfheight; |
| 405 | void (*CopyRow)(const uint8* src, uint8* dst, int width) = CopyRow_C; |
| 406 | void (*YUY2ToUV422Row)(const uint8* src_yuy2, uint8* dst_u, uint8* dst_v, |
| 407 | int pix) = YUY2ToUV422Row_C; |
| 408 | void (*YUY2ToYRow)(const uint8* src_yuy2, uint8* dst_y, int pix) = |
| 409 | YUY2ToYRow_C; |
| 410 | if (!src_y || !src_yuy2 || |
| 411 | !dst_y || !dst_u || !dst_v || |
| 412 | width <= 0 || height == 0) { |
| 413 | return -1; |
| 414 | } |
| 415 | // Negative height means invert the image. |
| 416 | if (height < 0) { |
| 417 | height = -height; |
| 418 | halfheight = (height + 1) >> 1; |
| 419 | dst_y = dst_y + (height - 1) * dst_stride_y; |
| 420 | dst_u = dst_u + (halfheight - 1) * dst_stride_u; |
| 421 | dst_v = dst_v + (halfheight - 1) * dst_stride_v; |
| 422 | dst_stride_y = -dst_stride_y; |
| 423 | dst_stride_u = -dst_stride_u; |
| 424 | dst_stride_v = -dst_stride_v; |
| 425 | } |
| 426 | // CopyRow for rows of just Y in Q420 copied to Y plane of I420. |
| 427 | #if defined(HAS_COPYROW_NEON) |
| 428 | if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 32)) { |
| 429 | CopyRow = CopyRow_NEON; |
| 430 | } |
| 431 | #endif |
| 432 | #if defined(HAS_COPYROW_X86) |
| 433 | if (IS_ALIGNED(width, 4)) { |
| 434 | CopyRow = CopyRow_X86; |
| 435 | } |
| 436 | #endif |
| 437 | #if defined(HAS_COPYROW_SSE2) |
| 438 | if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(width, 32) && |
| 439 | IS_ALIGNED(src_y, 16) && IS_ALIGNED(src_stride_y, 16) && |
| 440 | IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { |
| 441 | CopyRow = CopyRow_SSE2; |
| 442 | } |
| 443 | #endif |
| 444 | #if defined(HAS_COPYROW_ERMS) |
| 445 | if (TestCpuFlag(kCpuHasERMS)) { |
| 446 | CopyRow = CopyRow_ERMS; |
| 447 | } |
| 448 | #endif |
| 449 | #if defined(HAS_COPYROW_MIPS) |
| 450 | if (TestCpuFlag(kCpuHasMIPS)) { |
| 451 | CopyRow = CopyRow_MIPS; |
| 452 | } |
| 453 | #endif |
| 454 |
| 455 | #if defined(HAS_YUY2TOYROW_SSE2) |
| 456 | if (TestCpuFlag(kCpuHasSSE2) && width >= 16) { |
| 457 | YUY2ToUV422Row = YUY2ToUV422Row_Any_SSE2; |
| 458 | YUY2ToYRow = YUY2ToYRow_Any_SSE2; |
| 459 | if (IS_ALIGNED(width, 16)) { |
| 460 | YUY2ToUV422Row = YUY2ToUV422Row_Unaligned_SSE2; |
| 461 | YUY2ToYRow = YUY2ToYRow_Unaligned_SSE2; |
| 462 | if (IS_ALIGNED(src_yuy2, 16) && IS_ALIGNED(src_stride_yuy2, 16)) { |
| 463 | YUY2ToUV422Row = YUY2ToUV422Row_SSE2; |
| 464 | if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { |
| 465 | YUY2ToYRow = YUY2ToYRow_SSE2; |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | #endif |
| 471 | #if defined(HAS_YUY2TOYROW_AVX2) |
| 472 | if (TestCpuFlag(kCpuHasAVX2) && width >= 32) { |
| 473 | YUY2ToUV422Row = YUY2ToUV422Row_Any_AVX2; |
| 474 | YUY2ToYRow = YUY2ToYRow_Any_AVX2; |
| 475 | if (IS_ALIGNED(width, 32)) { |
| 476 | YUY2ToUV422Row = YUY2ToUV422Row_AVX2; |
| 477 | YUY2ToYRow = YUY2ToYRow_AVX2; |
| 478 | } |
| 479 | } |
| 480 | #endif |
| 481 | #if defined(HAS_YUY2TOYROW_NEON) |
| 482 | if (TestCpuFlag(kCpuHasNEON) && width >= 8) { |
| 483 | YUY2ToYRow = YUY2ToYRow_Any_NEON; |
| 484 | if (width >= 16) { |
| 485 | YUY2ToUV422Row = YUY2ToUV422Row_Any_NEON; |
| 486 | } |
| 487 | if (IS_ALIGNED(width, 16)) { |
| 488 | YUY2ToYRow = YUY2ToYRow_NEON; |
| 489 | YUY2ToUV422Row = YUY2ToUV422Row_NEON; |
| 490 | } |
| 491 | } |
| 492 | #endif |
| 493 |
| 494 | for (y = 0; y < height - 1; y += 2) { |
| 495 | CopyRow(src_y, dst_y, width); |
| 496 | src_y += src_stride_y; |
| 497 | dst_y += dst_stride_y; |
| 498 |
| 499 | YUY2ToUV422Row(src_yuy2, dst_u, dst_v, width); |
| 500 | YUY2ToYRow(src_yuy2, dst_y, width); |
| 501 | src_yuy2 += src_stride_yuy2; |
| 502 | dst_y += dst_stride_y; |
| 503 | dst_u += dst_stride_u; |
| 504 | dst_v += dst_stride_v; |
| 505 | } |
| 506 | if (height & 1) { |
| 507 | CopyRow(src_y, dst_y, width); |
| 508 | YUY2ToUV422Row(src_yuy2, dst_u, dst_v, width); |
| 509 | } |
| 510 | return 0; |
| 511 | } |
| 512 |
| 513 | // Convert YUY2 to I420. |
| 514 | LIBYUV_API |
| 515 | int YUY2ToI420(const uint8* src_yuy2, int src_stride_yuy2, |
| 516 | uint8* dst_y, int dst_stride_y, |
| 517 | uint8* dst_u, int dst_stride_u, |
| 518 | uint8* dst_v, int dst_stride_v, |
| 519 | int width, int height) { |
| 520 | int y; |
| 521 | void (*YUY2ToUVRow)(const uint8* src_yuy2, int src_stride_yuy2, |
| 522 | uint8* dst_u, uint8* dst_v, int pix) = YUY2ToUVRow_C; |
| 523 | void (*YUY2ToYRow)(const uint8* src_yuy2, |
| 524 | uint8* dst_y, int pix) = YUY2ToYRow_C; |
| 525 | // Negative height means invert the image. |
| 526 | if (height < 0) { |
| 527 | height = -height; |
| 528 | src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; |
| 529 | src_stride_yuy2 = -src_stride_yuy2; |
| 530 | } |
| 531 | #if defined(HAS_YUY2TOYROW_SSE2) |
| 532 | if (TestCpuFlag(kCpuHasSSE2) && width >= 16) { |
| 533 | YUY2ToUVRow = YUY2ToUVRow_Any_SSE2; |
| 534 | YUY2ToYRow = YUY2ToYRow_Any_SSE2; |
| 535 | if (IS_ALIGNED(width, 16)) { |
| 536 | YUY2ToUVRow = YUY2ToUVRow_Unaligned_SSE2; |
| 537 | YUY2ToYRow = YUY2ToYRow_Unaligned_SSE2; |
| 538 | if (IS_ALIGNED(src_yuy2, 16) && IS_ALIGNED(src_stride_yuy2, 16)) { |
| 539 | YUY2ToUVRow = YUY2ToUVRow_SSE2; |
| 540 | if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { |
| 541 | YUY2ToYRow = YUY2ToYRow_SSE2; |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | #endif |
| 547 | #if defined(HAS_YUY2TOYROW_AVX2) |
| 548 | if (TestCpuFlag(kCpuHasAVX2) && width >= 32) { |
| 549 | YUY2ToUVRow = YUY2ToUVRow_Any_AVX2; |
| 550 | YUY2ToYRow = YUY2ToYRow_Any_AVX2; |
| 551 | if (IS_ALIGNED(width, 32)) { |
| 552 | YUY2ToUVRow = YUY2ToUVRow_AVX2; |
| 553 | YUY2ToYRow = YUY2ToYRow_AVX2; |
| 554 | } |
| 555 | } |
| 556 | #endif |
| 557 | #if defined(HAS_YUY2TOYROW_NEON) |
| 558 | if (TestCpuFlag(kCpuHasNEON) && width >= 8) { |
| 559 | YUY2ToYRow = YUY2ToYRow_Any_NEON; |
| 560 | if (width >= 16) { |
| 561 | YUY2ToUVRow = YUY2ToUVRow_Any_NEON; |
| 562 | } |
| 563 | if (IS_ALIGNED(width, 16)) { |
| 564 | YUY2ToYRow = YUY2ToYRow_NEON; |
| 565 | YUY2ToUVRow = YUY2ToUVRow_NEON; |
| 566 | } |
| 567 | } |
| 568 | #endif |
| 569 |
| 570 | for (y = 0; y < height - 1; y += 2) { |
| 571 | YUY2ToUVRow(src_yuy2, src_stride_yuy2, dst_u, dst_v, width); |
| 572 | YUY2ToYRow(src_yuy2, dst_y, width); |
| 573 | YUY2ToYRow(src_yuy2 + src_stride_yuy2, dst_y + dst_stride_y, width); |
| 574 | src_yuy2 += src_stride_yuy2 * 2; |
| 575 | dst_y += dst_stride_y * 2; |
| 576 | dst_u += dst_stride_u; |
| 577 | dst_v += dst_stride_v; |
| 578 | } |
| 579 | if (height & 1) { |
| 580 | YUY2ToUVRow(src_yuy2, 0, dst_u, dst_v, width); |
| 581 | YUY2ToYRow(src_yuy2, dst_y, width); |
| 582 | } |
| 583 | return 0; |
| 584 | } |
| 585 |
| 586 | // Convert UYVY to I420. |
| 587 | LIBYUV_API |
| 588 | int UYVYToI420(const uint8* src_uyvy, int src_stride_uyvy, |
| 589 | uint8* dst_y, int dst_stride_y, |
| 590 | uint8* dst_u, int dst_stride_u, |
| 591 | uint8* dst_v, int dst_stride_v, |
| 592 | int width, int height) { |
| 593 | int y; |
| 594 | void (*UYVYToUVRow)(const uint8* src_uyvy, int src_stride_uyvy, |
| 595 | uint8* dst_u, uint8* dst_v, int pix) = UYVYToUVRow_C; |
| 596 | void (*UYVYToYRow)(const uint8* src_uyvy, |
| 597 | uint8* dst_y, int pix) = UYVYToYRow_C; |
| 598 | // Negative height means invert the image. |
| 599 | if (height < 0) { |
| 600 | height = -height; |
| 601 | src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; |
| 602 | src_stride_uyvy = -src_stride_uyvy; |
| 603 | } |
| 604 | #if defined(HAS_UYVYTOYROW_SSE2) |
| 605 | if (TestCpuFlag(kCpuHasSSE2) && width >= 16) { |
| 606 | UYVYToUVRow = UYVYToUVRow_Any_SSE2; |
| 607 | UYVYToYRow = UYVYToYRow_Any_SSE2; |
| 608 | if (IS_ALIGNED(width, 16)) { |
| 609 | UYVYToUVRow = UYVYToUVRow_Unaligned_SSE2; |
| 610 | UYVYToYRow = UYVYToYRow_Unaligned_SSE2; |
| 611 | if (IS_ALIGNED(src_uyvy, 16) && IS_ALIGNED(src_stride_uyvy, 16)) { |
| 612 | UYVYToUVRow = UYVYToUVRow_SSE2; |
| 613 | if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { |
| 614 | UYVYToYRow = UYVYToYRow_SSE2; |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | #endif |
| 620 | #if defined(HAS_UYVYTOYROW_AVX2) |
| 621 | if (TestCpuFlag(kCpuHasAVX2) && width >= 32) { |
| 622 | UYVYToUVRow = UYVYToUVRow_Any_AVX2; |
| 623 | UYVYToYRow = UYVYToYRow_Any_AVX2; |
| 624 | if (IS_ALIGNED(width, 32)) { |
| 625 | UYVYToUVRow = UYVYToUVRow_AVX2; |
| 626 | UYVYToYRow = UYVYToYRow_AVX2; |
| 627 | } |
| 628 | } |
| 629 | #endif |
| 630 | #if defined(HAS_UYVYTOYROW_NEON) |
| 631 | if (TestCpuFlag(kCpuHasNEON) && width >= 8) { |
| 632 | UYVYToYRow = UYVYToYRow_Any_NEON; |
| 633 | if (width >= 16) { |
| 634 | UYVYToUVRow = UYVYToUVRow_Any_NEON; |
| 635 | } |
| 636 | if (IS_ALIGNED(width, 16)) { |
| 637 | UYVYToYRow = UYVYToYRow_NEON; |
| 638 | UYVYToUVRow = UYVYToUVRow_NEON; |
| 639 | } |
| 640 | } |
| 641 | #endif |
| 642 |
| 643 | for (y = 0; y < height - 1; y += 2) { |
| 644 | UYVYToUVRow(src_uyvy, src_stride_uyvy, dst_u, dst_v, width); |
| 645 | UYVYToYRow(src_uyvy, dst_y, width); |
| 646 | UYVYToYRow(src_uyvy + src_stride_uyvy, dst_y + dst_stride_y, width); |
| 647 | src_uyvy += src_stride_uyvy * 2; |
| 648 | dst_y += dst_stride_y * 2; |
| 649 | dst_u += dst_stride_u; |
| 650 | dst_v += dst_stride_v; |
| 651 | } |
| 652 | if (height & 1) { |
| 653 | UYVYToUVRow(src_uyvy, 0, dst_u, dst_v, width); |
| 654 | UYVYToYRow(src_uyvy, dst_y, width); |
| 655 | } |
| 656 | return 0; |
| 657 | } |
| 658 |
| 659 | // Convert ARGB to I420. |
| 660 | LIBYUV_API |
| 661 | int ARGBToI420(const uint8* src_argb, int src_stride_argb, |
| 662 | uint8* dst_y, int dst_stride_y, |
| 663 | uint8* dst_u, int dst_stride_u, |
| 664 | uint8* dst_v, int dst_stride_v, |
| 665 | int width, int height) { |
| 666 | int y; |
| 667 | void (*ARGBToUVRow)(const uint8* src_argb0, int src_stride_argb, |
| 668 | uint8* dst_u, uint8* dst_v, int width) = ARGBToUVRow_C; |
| 669 | void (*ARGBToYRow)(const uint8* src_argb, uint8* dst_y, int pix) = |
| 670 | ARGBToYRow_C; |
| 671 | if (!src_argb || |
| 672 | !dst_y || !dst_u || !dst_v || |
| 673 | width <= 0 || height == 0) { |
| 674 | return -1; |
| 675 | } |
| 676 | // Negative height means invert the image. |
| 677 | if (height < 0) { |
| 678 | height = -height; |
| 679 | src_argb = src_argb + (height - 1) * src_stride_argb; |
| 680 | src_stride_argb = -src_stride_argb; |
| 681 | } |
| 682 | #if defined(HAS_ARGBTOYROW_SSSE3) && defined(HAS_ARGBTOUVROW_SSSE3) |
| 683 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 684 | ARGBToUVRow = ARGBToUVRow_Any_SSSE3; |
| 685 | ARGBToYRow = ARGBToYRow_Any_SSSE3; |
| 686 | if (IS_ALIGNED(width, 16)) { |
| 687 | ARGBToUVRow = ARGBToUVRow_Unaligned_SSSE3; |
| 688 | ARGBToYRow = ARGBToYRow_Unaligned_SSSE3; |
| 689 | if (IS_ALIGNED(src_argb, 16) && IS_ALIGNED(src_stride_argb, 16)) { |
| 690 | ARGBToUVRow = ARGBToUVRow_SSSE3; |
| 691 | if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { |
| 692 | ARGBToYRow = ARGBToYRow_SSSE3; |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | #endif |
| 698 | #if defined(HAS_ARGBTOYROW_AVX2) && defined(HAS_ARGBTOUVROW_AVX2) |
| 699 | if (TestCpuFlag(kCpuHasAVX2) && width >= 32) { |
| 700 | ARGBToUVRow = ARGBToUVRow_Any_AVX2; |
| 701 | ARGBToYRow = ARGBToYRow_Any_AVX2; |
| 702 | if (IS_ALIGNED(width, 32)) { |
| 703 | ARGBToUVRow = ARGBToUVRow_AVX2; |
| 704 | ARGBToYRow = ARGBToYRow_AVX2; |
| 705 | } |
| 706 | } |
| 707 | #endif |
| 708 | #if defined(HAS_ARGBTOYROW_NEON) |
| 709 | if (TestCpuFlag(kCpuHasNEON) && width >= 8) { |
| 710 | ARGBToYRow = ARGBToYRow_Any_NEON; |
| 711 | if (IS_ALIGNED(width, 8)) { |
| 712 | ARGBToYRow = ARGBToYRow_NEON; |
| 713 | } |
| 714 | } |
| 715 | #endif |
| 716 | #if defined(HAS_ARGBTOUVROW_NEON) |
| 717 | if (TestCpuFlag(kCpuHasNEON) && width >= 16) { |
| 718 | ARGBToUVRow = ARGBToUVRow_Any_NEON; |
| 719 | if (IS_ALIGNED(width, 16)) { |
| 720 | ARGBToUVRow = ARGBToUVRow_NEON; |
| 721 | } |
| 722 | } |
| 723 | #endif |
| 724 |
| 725 | for (y = 0; y < height - 1; y += 2) { |
| 726 | ARGBToUVRow(src_argb, src_stride_argb, dst_u, dst_v, width); |
| 727 | ARGBToYRow(src_argb, dst_y, width); |
| 728 | ARGBToYRow(src_argb + src_stride_argb, dst_y + dst_stride_y, width); |
| 729 | src_argb += src_stride_argb * 2; |
| 730 | dst_y += dst_stride_y * 2; |
| 731 | dst_u += dst_stride_u; |
| 732 | dst_v += dst_stride_v; |
| 733 | } |
| 734 | if (height & 1) { |
| 735 | ARGBToUVRow(src_argb, 0, dst_u, dst_v, width); |
| 736 | ARGBToYRow(src_argb, dst_y, width); |
| 737 | } |
| 738 | return 0; |
| 739 | } |
| 740 |
| 741 | // Convert BGRA to I420. |
| 742 | LIBYUV_API |
| 743 | int BGRAToI420(const uint8* src_bgra, int src_stride_bgra, |
| 744 | uint8* dst_y, int dst_stride_y, |
| 745 | uint8* dst_u, int dst_stride_u, |
| 746 | uint8* dst_v, int dst_stride_v, |
| 747 | int width, int height) { |
| 748 | int y; |
| 749 | void (*BGRAToUVRow)(const uint8* src_bgra0, int src_stride_bgra, |
| 750 | uint8* dst_u, uint8* dst_v, int width) = BGRAToUVRow_C; |
| 751 | void (*BGRAToYRow)(const uint8* src_bgra, uint8* dst_y, int pix) = |
| 752 | BGRAToYRow_C; |
| 753 | if (!src_bgra || |
| 754 | !dst_y || !dst_u || !dst_v || |
| 755 | width <= 0 || height == 0) { |
| 756 | return -1; |
| 757 | } |
| 758 | // Negative height means invert the image. |
| 759 | if (height < 0) { |
| 760 | height = -height; |
| 761 | src_bgra = src_bgra + (height - 1) * src_stride_bgra; |
| 762 | src_stride_bgra = -src_stride_bgra; |
| 763 | } |
| 764 | #if defined(HAS_BGRATOYROW_SSSE3) |
| 765 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 766 | BGRAToUVRow = BGRAToUVRow_Any_SSSE3; |
| 767 | BGRAToYRow = BGRAToYRow_Any_SSSE3; |
| 768 | if (IS_ALIGNED(width, 16)) { |
| 769 | BGRAToUVRow = BGRAToUVRow_Unaligned_SSSE3; |
| 770 | BGRAToYRow = BGRAToYRow_Unaligned_SSSE3; |
| 771 | if (IS_ALIGNED(src_bgra, 16) && IS_ALIGNED(src_stride_bgra, 16)) { |
| 772 | BGRAToUVRow = BGRAToUVRow_SSSE3; |
| 773 | if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { |
| 774 | BGRAToYRow = BGRAToYRow_SSSE3; |
| 775 | } |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | #elif defined(HAS_BGRATOYROW_NEON) |
| 780 | if (TestCpuFlag(kCpuHasNEON) && width >= 8) { |
| 781 | BGRAToYRow = BGRAToYRow_Any_NEON; |
| 782 | if (IS_ALIGNED(width, 8)) { |
| 783 | BGRAToYRow = BGRAToYRow_NEON; |
| 784 | } |
| 785 | } |
| 786 | #endif |
| 787 | #if defined(HAS_BGRATOUVROW_NEON) |
| 788 | if (TestCpuFlag(kCpuHasNEON) && width >= 16) { |
| 789 | BGRAToUVRow = BGRAToUVRow_Any_NEON; |
| 790 | if (IS_ALIGNED(width, 16)) { |
| 791 | BGRAToUVRow = BGRAToUVRow_NEON; |
| 792 | } |
| 793 | } |
| 794 | #endif |
| 795 |
| 796 | for (y = 0; y < height - 1; y += 2) { |
| 797 | BGRAToUVRow(src_bgra, src_stride_bgra, dst_u, dst_v, width); |
| 798 | BGRAToYRow(src_bgra, dst_y, width); |
| 799 | BGRAToYRow(src_bgra + src_stride_bgra, dst_y + dst_stride_y, width); |
| 800 | src_bgra += src_stride_bgra * 2; |
| 801 | dst_y += dst_stride_y * 2; |
| 802 | dst_u += dst_stride_u; |
| 803 | dst_v += dst_stride_v; |
| 804 | } |
| 805 | if (height & 1) { |
| 806 | BGRAToUVRow(src_bgra, 0, dst_u, dst_v, width); |
| 807 | BGRAToYRow(src_bgra, dst_y, width); |
| 808 | } |
| 809 | return 0; |
| 810 | } |
| 811 |
| 812 | // Convert ABGR to I420. |
| 813 | LIBYUV_API |
| 814 | int ABGRToI420(const uint8* src_abgr, int src_stride_abgr, |
| 815 | uint8* dst_y, int dst_stride_y, |
| 816 | uint8* dst_u, int dst_stride_u, |
| 817 | uint8* dst_v, int dst_stride_v, |
| 818 | int width, int height) { |
| 819 | int y; |
| 820 | void (*ABGRToUVRow)(const uint8* src_abgr0, int src_stride_abgr, |
| 821 | uint8* dst_u, uint8* dst_v, int width) = ABGRToUVRow_C; |
| 822 | void (*ABGRToYRow)(const uint8* src_abgr, uint8* dst_y, int pix) = |
| 823 | ABGRToYRow_C; |
| 824 | if (!src_abgr || |
| 825 | !dst_y || !dst_u || !dst_v || |
| 826 | width <= 0 || height == 0) { |
| 827 | return -1; |
| 828 | } |
| 829 | // Negative height means invert the image. |
| 830 | if (height < 0) { |
| 831 | height = -height; |
| 832 | src_abgr = src_abgr + (height - 1) * src_stride_abgr; |
| 833 | src_stride_abgr = -src_stride_abgr; |
| 834 | } |
| 835 | #if defined(HAS_ABGRTOYROW_SSSE3) |
| 836 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 837 | ABGRToUVRow = ABGRToUVRow_Any_SSSE3; |
| 838 | ABGRToYRow = ABGRToYRow_Any_SSSE3; |
| 839 | if (IS_ALIGNED(width, 16)) { |
| 840 | ABGRToUVRow = ABGRToUVRow_Unaligned_SSSE3; |
| 841 | ABGRToYRow = ABGRToYRow_Unaligned_SSSE3; |
| 842 | if (IS_ALIGNED(src_abgr, 16) && IS_ALIGNED(src_stride_abgr, 16)) { |
| 843 | ABGRToUVRow = ABGRToUVRow_SSSE3; |
| 844 | if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { |
| 845 | ABGRToYRow = ABGRToYRow_SSSE3; |
| 846 | } |
| 847 | } |
| 848 | } |
| 849 | } |
| 850 | #elif defined(HAS_ABGRTOYROW_NEON) |
| 851 | if (TestCpuFlag(kCpuHasNEON) && width >= 8) { |
| 852 | ABGRToYRow = ABGRToYRow_Any_NEON; |
| 853 | if (IS_ALIGNED(width, 8)) { |
| 854 | ABGRToYRow = ABGRToYRow_NEON; |
| 855 | } |
| 856 | } |
| 857 | #endif |
| 858 | #if defined(HAS_ABGRTOUVROW_NEON) |
| 859 | if (TestCpuFlag(kCpuHasNEON) && width >= 16) { |
| 860 | ABGRToUVRow = ABGRToUVRow_Any_NEON; |
| 861 | if (IS_ALIGNED(width, 16)) { |
| 862 | ABGRToUVRow = ABGRToUVRow_NEON; |
| 863 | } |
| 864 | } |
| 865 | #endif |
| 866 |
| 867 | for (y = 0; y < height - 1; y += 2) { |
| 868 | ABGRToUVRow(src_abgr, src_stride_abgr, dst_u, dst_v, width); |
| 869 | ABGRToYRow(src_abgr, dst_y, width); |
| 870 | ABGRToYRow(src_abgr + src_stride_abgr, dst_y + dst_stride_y, width); |
| 871 | src_abgr += src_stride_abgr * 2; |
| 872 | dst_y += dst_stride_y * 2; |
| 873 | dst_u += dst_stride_u; |
| 874 | dst_v += dst_stride_v; |
| 875 | } |
| 876 | if (height & 1) { |
| 877 | ABGRToUVRow(src_abgr, 0, dst_u, dst_v, width); |
| 878 | ABGRToYRow(src_abgr, dst_y, width); |
| 879 | } |
| 880 | return 0; |
| 881 | } |
| 882 |
| 883 | // Convert RGBA to I420. |
| 884 | LIBYUV_API |
| 885 | int RGBAToI420(const uint8* src_rgba, int src_stride_rgba, |
| 886 | uint8* dst_y, int dst_stride_y, |
| 887 | uint8* dst_u, int dst_stride_u, |
| 888 | uint8* dst_v, int dst_stride_v, |
| 889 | int width, int height) { |
| 890 | int y; |
| 891 | void (*RGBAToUVRow)(const uint8* src_rgba0, int src_stride_rgba, |
| 892 | uint8* dst_u, uint8* dst_v, int width) = RGBAToUVRow_C; |
| 893 | void (*RGBAToYRow)(const uint8* src_rgba, uint8* dst_y, int pix) = |
| 894 | RGBAToYRow_C; |
| 895 | if (!src_rgba || |
| 896 | !dst_y || !dst_u || !dst_v || |
| 897 | width <= 0 || height == 0) { |
| 898 | return -1; |
| 899 | } |
| 900 | // Negative height means invert the image. |
| 901 | if (height < 0) { |
| 902 | height = -height; |
| 903 | src_rgba = src_rgba + (height - 1) * src_stride_rgba; |
| 904 | src_stride_rgba = -src_stride_rgba; |
| 905 | } |
| 906 | #if defined(HAS_RGBATOYROW_SSSE3) |
| 907 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 908 | RGBAToUVRow = RGBAToUVRow_Any_SSSE3; |
| 909 | RGBAToYRow = RGBAToYRow_Any_SSSE3; |
| 910 | if (IS_ALIGNED(width, 16)) { |
| 911 | RGBAToUVRow = RGBAToUVRow_Unaligned_SSSE3; |
| 912 | RGBAToYRow = RGBAToYRow_Unaligned_SSSE3; |
| 913 | if (IS_ALIGNED(src_rgba, 16) && IS_ALIGNED(src_stride_rgba, 16)) { |
| 914 | RGBAToUVRow = RGBAToUVRow_SSSE3; |
| 915 | if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { |
| 916 | RGBAToYRow = RGBAToYRow_SSSE3; |
| 917 | } |
| 918 | } |
| 919 | } |
| 920 | } |
| 921 | #elif defined(HAS_RGBATOYROW_NEON) |
| 922 | if (TestCpuFlag(kCpuHasNEON) && width >= 8) { |
| 923 | RGBAToYRow = RGBAToYRow_Any_NEON; |
| 924 | if (IS_ALIGNED(width, 8)) { |
| 925 | RGBAToYRow = RGBAToYRow_NEON; |
| 926 | } |
| 927 | } |
| 928 | #endif |
| 929 | #if defined(HAS_RGBATOUVROW_NEON) |
| 930 | if (TestCpuFlag(kCpuHasNEON) && width >= 16) { |
| 931 | RGBAToUVRow = RGBAToUVRow_Any_NEON; |
| 932 | if (IS_ALIGNED(width, 16)) { |
| 933 | RGBAToUVRow = RGBAToUVRow_NEON; |
| 934 | } |
| 935 | } |
| 936 | #endif |
| 937 |
| 938 | for (y = 0; y < height - 1; y += 2) { |
| 939 | RGBAToUVRow(src_rgba, src_stride_rgba, dst_u, dst_v, width); |
| 940 | RGBAToYRow(src_rgba, dst_y, width); |
| 941 | RGBAToYRow(src_rgba + src_stride_rgba, dst_y + dst_stride_y, width); |
| 942 | src_rgba += src_stride_rgba * 2; |
| 943 | dst_y += dst_stride_y * 2; |
| 944 | dst_u += dst_stride_u; |
| 945 | dst_v += dst_stride_v; |
| 946 | } |
| 947 | if (height & 1) { |
| 948 | RGBAToUVRow(src_rgba, 0, dst_u, dst_v, width); |
| 949 | RGBAToYRow(src_rgba, dst_y, width); |
| 950 | } |
| 951 | return 0; |
| 952 | } |
| 953 |
| 954 | // Convert RGB24 to I420. |
| 955 | LIBYUV_API |
| 956 | int RGB24ToI420(const uint8* src_rgb24, int src_stride_rgb24, |
| 957 | uint8* dst_y, int dst_stride_y, |
| 958 | uint8* dst_u, int dst_stride_u, |
| 959 | uint8* dst_v, int dst_stride_v, |
| 960 | int width, int height) { |
| 961 | int y; |
| 962 | #if defined(HAS_RGB24TOYROW_NEON) |
| 963 | void (*RGB24ToUVRow)(const uint8* src_rgb24, int src_stride_rgb24, |
| 964 | uint8* dst_u, uint8* dst_v, int width) = RGB24ToUVRow_C; |
| 965 | void (*RGB24ToYRow)(const uint8* src_rgb24, uint8* dst_y, int pix) = |
| 966 | RGB24ToYRow_C; |
| 967 | #else |
| 968 | void (*RGB24ToARGBRow)(const uint8* src_rgb, uint8* dst_argb, int pix) = |
| 969 | RGB24ToARGBRow_C; |
| 970 | void (*ARGBToUVRow)(const uint8* src_argb0, int src_stride_argb, |
| 971 | uint8* dst_u, uint8* dst_v, int width) = ARGBToUVRow_C; |
| 972 | void (*ARGBToYRow)(const uint8* src_argb, uint8* dst_y, int pix) = |
| 973 | ARGBToYRow_C; |
| 974 | #endif |
| 975 | if (!src_rgb24 || !dst_y || !dst_u || !dst_v || |
| 976 | width <= 0 || height == 0) { |
| 977 | return -1; |
| 978 | } |
| 979 | // Negative height means invert the image. |
| 980 | if (height < 0) { |
| 981 | height = -height; |
| 982 | src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; |
| 983 | src_stride_rgb24 = -src_stride_rgb24; |
| 984 | } |
| 985 |
| 986 | #if defined(HAS_RGB24TOYROW_NEON) |
| 987 | if (TestCpuFlag(kCpuHasNEON) && width >= 8) { |
| 988 | RGB24ToYRow = RGB24ToYRow_Any_NEON; |
| 989 | if (IS_ALIGNED(width, 8)) { |
| 990 | RGB24ToYRow = RGB24ToYRow_NEON; |
| 991 | } |
| 992 | } |
| 993 | #endif |
| 994 | #if defined(HAS_RGB24TOUVROW_NEON) |
| 995 | if (TestCpuFlag(kCpuHasNEON) && width >= 16) { |
| 996 | RGB24ToUVRow = RGB24ToUVRow_Any_NEON; |
| 997 | if (IS_ALIGNED(width, 16)) { |
| 998 | RGB24ToUVRow = RGB24ToUVRow_NEON; |
| 999 | } |
| 1000 | } |
| 1001 | #endif |
| 1002 | #if defined(HAS_RGB24TOARGBROW_SSSE3) |
| 1003 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 1004 | RGB24ToARGBRow = RGB24ToARGBRow_Any_SSSE3; |
| 1005 | if (IS_ALIGNED(width, 16)) { |
| 1006 | RGB24ToARGBRow = RGB24ToARGBRow_SSSE3; |
| 1007 | } |
| 1008 | } |
| 1009 | #endif |
| 1010 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 1011 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 1012 | ARGBToUVRow = ARGBToUVRow_Any_SSSE3; |
| 1013 | if (IS_ALIGNED(width, 16)) { |
| 1014 | ARGBToUVRow = ARGBToUVRow_SSSE3; |
| 1015 | } |
| 1016 | } |
| 1017 | #endif |
| 1018 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 1019 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 1020 | ARGBToYRow = ARGBToYRow_Any_SSSE3; |
| 1021 | if (IS_ALIGNED(width, 16)) { |
| 1022 | ARGBToYRow = ARGBToYRow_Unaligned_SSSE3; |
| 1023 | if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { |
| 1024 | ARGBToYRow = ARGBToYRow_SSSE3; |
| 1025 | } |
| 1026 | } |
| 1027 | } |
| 1028 | #endif // HAS_ARGBTOUVROW_SSSE3 |
| 1029 |
| 1030 | { |
| 1031 | #if !defined(HAS_RGB24TOYROW_NEON) |
| 1032 | // Allocate 2 rows of ARGB. |
| 1033 | const int kRowSize = (width * 4 + 15) & ~15; |
| 1034 | align_buffer_64(row, kRowSize * 2); |
| 1035 | #endif |
| 1036 |
| 1037 | for (y = 0; y < height - 1; y += 2) { |
| 1038 | #if defined(HAS_RGB24TOYROW_NEON) |
| 1039 | RGB24ToUVRow(src_rgb24, src_stride_rgb24, dst_u, dst_v, width); |
| 1040 | RGB24ToYRow(src_rgb24, dst_y, width); |
| 1041 | RGB24ToYRow(src_rgb24 + src_stride_rgb24, dst_y + dst_stride_y, width); |
| 1042 | #else |
| 1043 | RGB24ToARGBRow(src_rgb24, row, width); |
| 1044 | RGB24ToARGBRow(src_rgb24 + src_stride_rgb24, row + kRowSize, width); |
| 1045 | ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); |
| 1046 | ARGBToYRow(row, dst_y, width); |
| 1047 | ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); |
| 1048 | #endif |
| 1049 | src_rgb24 += src_stride_rgb24 * 2; |
| 1050 | dst_y += dst_stride_y * 2; |
| 1051 | dst_u += dst_stride_u; |
| 1052 | dst_v += dst_stride_v; |
| 1053 | } |
| 1054 | if (height & 1) { |
| 1055 | #if defined(HAS_RGB24TOYROW_NEON) |
| 1056 | RGB24ToUVRow(src_rgb24, 0, dst_u, dst_v, width); |
| 1057 | RGB24ToYRow(src_rgb24, dst_y, width); |
| 1058 | #else |
| 1059 | RGB24ToARGBRow(src_rgb24, row, width); |
| 1060 | ARGBToUVRow(row, 0, dst_u, dst_v, width); |
| 1061 | ARGBToYRow(row, dst_y, width); |
| 1062 | #endif |
| 1063 | } |
| 1064 | #if !defined(HAS_RGB24TOYROW_NEON) |
| 1065 | free_aligned_buffer_64(row); |
| 1066 | #endif |
| 1067 | } |
| 1068 | return 0; |
| 1069 | } |
| 1070 |
| 1071 | // Convert RAW to I420. |
| 1072 | LIBYUV_API |
| 1073 | int RAWToI420(const uint8* src_raw, int src_stride_raw, |
| 1074 | uint8* dst_y, int dst_stride_y, |
| 1075 | uint8* dst_u, int dst_stride_u, |
| 1076 | uint8* dst_v, int dst_stride_v, |
| 1077 | int width, int height) { |
| 1078 | int y; |
| 1079 | #if defined(HAS_RAWTOYROW_NEON) |
| 1080 | void (*RAWToUVRow)(const uint8* src_raw, int src_stride_raw, |
| 1081 | uint8* dst_u, uint8* dst_v, int width) = RAWToUVRow_C; |
| 1082 | void (*RAWToYRow)(const uint8* src_raw, uint8* dst_y, int pix) = |
| 1083 | RAWToYRow_C; |
| 1084 | #else |
| 1085 | void (*RAWToARGBRow)(const uint8* src_rgb, uint8* dst_argb, int pix) = |
| 1086 | RAWToARGBRow_C; |
| 1087 | void (*ARGBToUVRow)(const uint8* src_argb0, int src_stride_argb, |
| 1088 | uint8* dst_u, uint8* dst_v, int width) = ARGBToUVRow_C; |
| 1089 | void (*ARGBToYRow)(const uint8* src_argb, uint8* dst_y, int pix) = |
| 1090 | ARGBToYRow_C; |
| 1091 | #endif |
| 1092 | if (!src_raw || !dst_y || !dst_u || !dst_v || |
| 1093 | width <= 0 || height == 0) { |
| 1094 | return -1; |
| 1095 | } |
| 1096 | // Negative height means invert the image. |
| 1097 | if (height < 0) { |
| 1098 | height = -height; |
| 1099 | src_raw = src_raw + (height - 1) * src_stride_raw; |
| 1100 | src_stride_raw = -src_stride_raw; |
| 1101 | } |
| 1102 |
| 1103 | #if defined(HAS_RAWTOYROW_NEON) |
| 1104 | if (TestCpuFlag(kCpuHasNEON) && width >= 8) { |
| 1105 | RAWToYRow = RAWToYRow_Any_NEON; |
| 1106 | if (IS_ALIGNED(width, 8)) { |
| 1107 | RAWToYRow = RAWToYRow_NEON; |
| 1108 | } |
| 1109 | } |
| 1110 | #endif |
| 1111 | #if defined(HAS_RAWTOUVROW_NEON) |
| 1112 | if (TestCpuFlag(kCpuHasNEON) && width >= 16) { |
| 1113 | RAWToUVRow = RAWToUVRow_Any_NEON; |
| 1114 | if (IS_ALIGNED(width, 16)) { |
| 1115 | RAWToUVRow = RAWToUVRow_NEON; |
| 1116 | } |
| 1117 | } |
| 1118 | #endif |
| 1119 | #if defined(HAS_RAWTOARGBROW_SSSE3) |
| 1120 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 1121 | RAWToARGBRow = RAWToARGBRow_Any_SSSE3; |
| 1122 | if (IS_ALIGNED(width, 16)) { |
| 1123 | RAWToARGBRow = RAWToARGBRow_SSSE3; |
| 1124 | } |
| 1125 | } |
| 1126 | #endif |
| 1127 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 1128 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 1129 | ARGBToUVRow = ARGBToUVRow_Any_SSSE3; |
| 1130 | if (IS_ALIGNED(width, 16)) { |
| 1131 | ARGBToUVRow = ARGBToUVRow_SSSE3; |
| 1132 | } |
| 1133 | } |
| 1134 | #endif |
| 1135 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 1136 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 1137 | ARGBToYRow = ARGBToYRow_Any_SSSE3; |
| 1138 | if (IS_ALIGNED(width, 16)) { |
| 1139 | ARGBToYRow = ARGBToYRow_Unaligned_SSSE3; |
| 1140 | if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { |
| 1141 | ARGBToYRow = ARGBToYRow_SSSE3; |
| 1142 | } |
| 1143 | } |
| 1144 | } |
| 1145 | #endif // HAS_ARGBTOUVROW_SSSE3 |
| 1146 |
| 1147 | { |
| 1148 | // Allocate 2 rows of ARGB. |
| 1149 | const int kRowSize = (width * 4 + 15) & ~15; |
| 1150 | align_buffer_64(row, kRowSize * 2); |
| 1151 |
| 1152 | for (y = 0; y < height - 1; y += 2) { |
| 1153 | #if defined(HAS_RAWTOYROW_NEON) |
| 1154 | RAWToUVRow(src_raw, src_stride_raw, dst_u, dst_v, width); |
| 1155 | RAWToYRow(src_raw, dst_y, width); |
| 1156 | RAWToYRow(src_raw + src_stride_raw, dst_y + dst_stride_y, width); |
| 1157 | #else |
| 1158 | RAWToARGBRow(src_raw, row, width); |
| 1159 | RAWToARGBRow(src_raw + src_stride_raw, row + kRowSize, width); |
| 1160 | ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); |
| 1161 | ARGBToYRow(row, dst_y, width); |
| 1162 | ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); |
| 1163 | #endif |
| 1164 | src_raw += src_stride_raw * 2; |
| 1165 | dst_y += dst_stride_y * 2; |
| 1166 | dst_u += dst_stride_u; |
| 1167 | dst_v += dst_stride_v; |
| 1168 | } |
| 1169 | if (height & 1) { |
| 1170 | #if defined(HAS_RAWTOYROW_NEON) |
| 1171 | RAWToUVRow(src_raw, 0, dst_u, dst_v, width); |
| 1172 | RAWToYRow(src_raw, dst_y, width); |
| 1173 | #else |
| 1174 | RAWToARGBRow(src_raw, row, width); |
| 1175 | ARGBToUVRow(row, 0, dst_u, dst_v, width); |
| 1176 | ARGBToYRow(row, dst_y, width); |
| 1177 | #endif |
| 1178 | } |
| 1179 | #if !defined(HAS_RAWTOYROW_NEON) |
| 1180 | free_aligned_buffer_64(row); |
| 1181 | #endif |
| 1182 | } |
| 1183 | return 0; |
| 1184 | } |
| 1185 |
| 1186 | // Convert RGB565 to I420. |
| 1187 | LIBYUV_API |
| 1188 | int RGB565ToI420(const uint8* src_rgb565, int src_stride_rgb565, |
| 1189 | uint8* dst_y, int dst_stride_y, |
| 1190 | uint8* dst_u, int dst_stride_u, |
| 1191 | uint8* dst_v, int dst_stride_v, |
| 1192 | int width, int height) { |
| 1193 | int y; |
| 1194 | #if defined(HAS_RGB565TOYROW_NEON) |
| 1195 | void (*RGB565ToUVRow)(const uint8* src_rgb565, int src_stride_rgb565, |
| 1196 | uint8* dst_u, uint8* dst_v, int width) = RGB565ToUVRow_C; |
| 1197 | void (*RGB565ToYRow)(const uint8* src_rgb565, uint8* dst_y, int pix) = |
| 1198 | RGB565ToYRow_C; |
| 1199 | #else |
| 1200 | void (*RGB565ToARGBRow)(const uint8* src_rgb, uint8* dst_argb, int pix) = |
| 1201 | RGB565ToARGBRow_C; |
| 1202 | void (*ARGBToUVRow)(const uint8* src_argb0, int src_stride_argb, |
| 1203 | uint8* dst_u, uint8* dst_v, int width) = ARGBToUVRow_C; |
| 1204 | void (*ARGBToYRow)(const uint8* src_argb, uint8* dst_y, int pix) = |
| 1205 | ARGBToYRow_C; |
| 1206 | #endif |
| 1207 | if (!src_rgb565 || !dst_y || !dst_u || !dst_v || |
| 1208 | width <= 0 || height == 0) { |
| 1209 | return -1; |
| 1210 | } |
| 1211 | // Negative height means invert the image. |
| 1212 | if (height < 0) { |
| 1213 | height = -height; |
| 1214 | src_rgb565 = src_rgb565 + (height - 1) * src_stride_rgb565; |
| 1215 | src_stride_rgb565 = -src_stride_rgb565; |
| 1216 | } |
| 1217 |
| 1218 | #if defined(HAS_RGB565TOYROW_NEON) |
| 1219 | if (TestCpuFlag(kCpuHasNEON) && width >= 8) { |
| 1220 | RGB565ToYRow = RGB565ToYRow_Any_NEON; |
| 1221 | if (IS_ALIGNED(width, 8)) { |
| 1222 | RGB565ToYRow = RGB565ToYRow_NEON; |
| 1223 | } |
| 1224 | if (width >= 16) { |
| 1225 | RGB565ToUVRow = RGB565ToUVRow_Any_NEON; |
| 1226 | if (IS_ALIGNED(width, 16)) { |
| 1227 | RGB565ToUVRow = RGB565ToUVRow_NEON; |
| 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | #else // HAS_RGB565TOYROW_NEON |
| 1232 |
| 1233 | #if defined(HAS_RGB565TOARGBROW_SSE2) |
| 1234 | if (TestCpuFlag(kCpuHasSSE2) && width >= 8) { |
| 1235 | RGB565ToARGBRow = RGB565ToARGBRow_Any_SSE2; |
| 1236 | if (IS_ALIGNED(width, 8)) { |
| 1237 | RGB565ToARGBRow = RGB565ToARGBRow_SSE2; |
| 1238 | } |
| 1239 | } |
| 1240 | #endif |
| 1241 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 1242 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 1243 | ARGBToUVRow = ARGBToUVRow_Any_SSSE3; |
| 1244 | if (IS_ALIGNED(width, 16)) { |
| 1245 | ARGBToUVRow = ARGBToUVRow_SSSE3; |
| 1246 | } |
| 1247 | } |
| 1248 | #endif |
| 1249 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 1250 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 1251 | ARGBToYRow = ARGBToYRow_Any_SSSE3; |
| 1252 | if (IS_ALIGNED(width, 16)) { |
| 1253 | ARGBToYRow = ARGBToYRow_Unaligned_SSSE3; |
| 1254 | if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { |
| 1255 | ARGBToYRow = ARGBToYRow_SSSE3; |
| 1256 | } |
| 1257 | } |
| 1258 | } |
| 1259 | #endif // HAS_ARGBTOUVROW_SSSE3 |
| 1260 | #endif // HAS_RGB565TOYROW_NEON |
| 1261 |
| 1262 | { |
| 1263 | #if !defined(HAS_RGB565TOYROW_NEON) |
| 1264 | // Allocate 2 rows of ARGB. |
| 1265 | const int kRowSize = (width * 4 + 15) & ~15; |
| 1266 | align_buffer_64(row, kRowSize * 2); |
| 1267 | #endif |
| 1268 |
| 1269 | for (y = 0; y < height - 1; y += 2) { |
| 1270 | #if defined(HAS_RGB565TOYROW_NEON) |
| 1271 | RGB565ToUVRow(src_rgb565, src_stride_rgb565, dst_u, dst_v, width); |
| 1272 | RGB565ToYRow(src_rgb565, dst_y, width); |
| 1273 | RGB565ToYRow(src_rgb565 + src_stride_rgb565, dst_y + dst_stride_y, width); |
| 1274 | #else |
| 1275 | RGB565ToARGBRow(src_rgb565, row, width); |
| 1276 | RGB565ToARGBRow(src_rgb565 + src_stride_rgb565, row + kRowSize, width); |
| 1277 | ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); |
| 1278 | ARGBToYRow(row, dst_y, width); |
| 1279 | ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); |
| 1280 | #endif |
| 1281 | src_rgb565 += src_stride_rgb565 * 2; |
| 1282 | dst_y += dst_stride_y * 2; |
| 1283 | dst_u += dst_stride_u; |
| 1284 | dst_v += dst_stride_v; |
| 1285 | } |
| 1286 | if (height & 1) { |
| 1287 | #if defined(HAS_RGB565TOYROW_NEON) |
| 1288 | RGB565ToUVRow(src_rgb565, 0, dst_u, dst_v, width); |
| 1289 | RGB565ToYRow(src_rgb565, dst_y, width); |
| 1290 | #else |
| 1291 | RGB565ToARGBRow(src_rgb565, row, width); |
| 1292 | ARGBToUVRow(row, 0, dst_u, dst_v, width); |
| 1293 | ARGBToYRow(row, dst_y, width); |
| 1294 | #endif |
| 1295 | } |
| 1296 | #if !defined(HAS_RGB565TOYROW_NEON) |
| 1297 | free_aligned_buffer_64(row); |
| 1298 | #endif |
| 1299 | } |
| 1300 | return 0; |
| 1301 | } |
| 1302 |
| 1303 | // Convert ARGB1555 to I420. |
| 1304 | LIBYUV_API |
| 1305 | int ARGB1555ToI420(const uint8* src_argb1555, int src_stride_argb1555, |
| 1306 | uint8* dst_y, int dst_stride_y, |
| 1307 | uint8* dst_u, int dst_stride_u, |
| 1308 | uint8* dst_v, int dst_stride_v, |
| 1309 | int width, int height) { |
| 1310 | int y; |
| 1311 | #if defined(HAS_ARGB1555TOYROW_NEON) |
| 1312 | void (*ARGB1555ToUVRow)(const uint8* src_argb1555, int src_stride_argb1555, |
| 1313 | uint8* dst_u, uint8* dst_v, int width) = ARGB1555ToUVRow_C; |
| 1314 | void (*ARGB1555ToYRow)(const uint8* src_argb1555, uint8* dst_y, int pix) = |
| 1315 | ARGB1555ToYRow_C; |
| 1316 | #else |
| 1317 | void (*ARGB1555ToARGBRow)(const uint8* src_rgb, uint8* dst_argb, int pix) = |
| 1318 | ARGB1555ToARGBRow_C; |
| 1319 | void (*ARGBToUVRow)(const uint8* src_argb0, int src_stride_argb, |
| 1320 | uint8* dst_u, uint8* dst_v, int width) = ARGBToUVRow_C; |
| 1321 | void (*ARGBToYRow)(const uint8* src_argb, uint8* dst_y, int pix) = |
| 1322 | ARGBToYRow_C; |
| 1323 | #endif |
| 1324 | if (!src_argb1555 || !dst_y || !dst_u || !dst_v || |
| 1325 | width <= 0 || height == 0) { |
| 1326 | return -1; |
| 1327 | } |
| 1328 | // Negative height means invert the image. |
| 1329 | if (height < 0) { |
| 1330 | height = -height; |
| 1331 | src_argb1555 = src_argb1555 + (height - 1) * src_stride_argb1555; |
| 1332 | src_stride_argb1555 = -src_stride_argb1555; |
| 1333 | } |
| 1334 |
| 1335 | #if defined(HAS_ARGB1555TOYROW_NEON) |
| 1336 | if (TestCpuFlag(kCpuHasNEON) && width >= 8) { |
| 1337 | ARGB1555ToYRow = ARGB1555ToYRow_Any_NEON; |
| 1338 | if (IS_ALIGNED(width, 8)) { |
| 1339 | ARGB1555ToYRow = ARGB1555ToYRow_NEON; |
| 1340 | } |
| 1341 | if (width >= 16) { |
| 1342 | ARGB1555ToUVRow = ARGB1555ToUVRow_Any_NEON; |
| 1343 | if (IS_ALIGNED(width, 16)) { |
| 1344 | ARGB1555ToUVRow = ARGB1555ToUVRow_NEON; |
| 1345 | } |
| 1346 | } |
| 1347 | } |
| 1348 | #else // HAS_ARGB1555TOYROW_NEON |
| 1349 |
| 1350 | #if defined(HAS_ARGB1555TOARGBROW_SSE2) |
| 1351 | if (TestCpuFlag(kCpuHasSSE2) && width >= 8) { |
| 1352 | ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_SSE2; |
| 1353 | if (IS_ALIGNED(width, 8)) { |
| 1354 | ARGB1555ToARGBRow = ARGB1555ToARGBRow_SSE2; |
| 1355 | } |
| 1356 | } |
| 1357 | #endif |
| 1358 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 1359 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 1360 | ARGBToUVRow = ARGBToUVRow_Any_SSSE3; |
| 1361 | if (IS_ALIGNED(width, 16)) { |
| 1362 | ARGBToUVRow = ARGBToUVRow_SSSE3; |
| 1363 | } |
| 1364 | } |
| 1365 | #endif |
| 1366 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 1367 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 1368 | ARGBToYRow = ARGBToYRow_Any_SSSE3; |
| 1369 | if (IS_ALIGNED(width, 16)) { |
| 1370 | ARGBToYRow = ARGBToYRow_Unaligned_SSSE3; |
| 1371 | if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { |
| 1372 | ARGBToYRow = ARGBToYRow_SSSE3; |
| 1373 | } |
| 1374 | } |
| 1375 | } |
| 1376 | #endif // HAS_ARGBTOUVROW_SSSE3 |
| 1377 | #endif // HAS_ARGB1555TOYROW_NEON |
| 1378 |
| 1379 | { |
| 1380 | #if !defined(HAS_ARGB1555TOYROW_NEON) |
| 1381 | // Allocate 2 rows of ARGB. |
| 1382 | const int kRowSize = (width * 4 + 15) & ~15; |
| 1383 | align_buffer_64(row, kRowSize * 2); |
| 1384 | #endif |
| 1385 | for (y = 0; y < height - 1; y += 2) { |
| 1386 | #if defined(HAS_ARGB1555TOYROW_NEON) |
| 1387 | ARGB1555ToUVRow(src_argb1555, src_stride_argb1555, dst_u, dst_v, width); |
| 1388 | ARGB1555ToYRow(src_argb1555, dst_y, width); |
| 1389 | ARGB1555ToYRow(src_argb1555 + src_stride_argb1555, dst_y + dst_stride_y, |
| 1390 | width); |
| 1391 | #else |
| 1392 | ARGB1555ToARGBRow(src_argb1555, row, width); |
| 1393 | ARGB1555ToARGBRow(src_argb1555 + src_stride_argb1555, row + kRowSize, |
| 1394 | width); |
| 1395 | ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); |
| 1396 | ARGBToYRow(row, dst_y, width); |
| 1397 | ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); |
| 1398 | #endif |
| 1399 | src_argb1555 += src_stride_argb1555 * 2; |
| 1400 | dst_y += dst_stride_y * 2; |
| 1401 | dst_u += dst_stride_u; |
| 1402 | dst_v += dst_stride_v; |
| 1403 | } |
| 1404 | if (height & 1) { |
| 1405 | #if defined(HAS_ARGB1555TOYROW_NEON) |
| 1406 | ARGB1555ToUVRow(src_argb1555, 0, dst_u, dst_v, width); |
| 1407 | ARGB1555ToYRow(src_argb1555, dst_y, width); |
| 1408 | #else |
| 1409 | ARGB1555ToARGBRow(src_argb1555, row, width); |
| 1410 | ARGBToUVRow(row, 0, dst_u, dst_v, width); |
| 1411 | ARGBToYRow(row, dst_y, width); |
| 1412 | #endif |
| 1413 | } |
| 1414 | #if !defined(HAS_ARGB1555TOYROW_NEON) |
| 1415 | free_aligned_buffer_64(row); |
| 1416 | #endif |
| 1417 | } |
| 1418 | return 0; |
| 1419 | } |
| 1420 |
| 1421 | // Convert ARGB4444 to I420. |
| 1422 | LIBYUV_API |
| 1423 | int ARGB4444ToI420(const uint8* src_argb4444, int src_stride_argb4444, |
| 1424 | uint8* dst_y, int dst_stride_y, |
| 1425 | uint8* dst_u, int dst_stride_u, |
| 1426 | uint8* dst_v, int dst_stride_v, |
| 1427 | int width, int height) { |
| 1428 | int y; |
| 1429 | #if defined(HAS_ARGB4444TOYROW_NEON) |
| 1430 | void (*ARGB4444ToUVRow)(const uint8* src_argb4444, int src_stride_argb4444, |
| 1431 | uint8* dst_u, uint8* dst_v, int width) = ARGB4444ToUVRow_C; |
| 1432 | void (*ARGB4444ToYRow)(const uint8* src_argb4444, uint8* dst_y, int pix) = |
| 1433 | ARGB4444ToYRow_C; |
| 1434 | #else |
| 1435 | void (*ARGB4444ToARGBRow)(const uint8* src_rgb, uint8* dst_argb, int pix) = |
| 1436 | ARGB4444ToARGBRow_C; |
| 1437 | void (*ARGBToUVRow)(const uint8* src_argb0, int src_stride_argb, |
| 1438 | uint8* dst_u, uint8* dst_v, int width) = ARGBToUVRow_C; |
| 1439 | void (*ARGBToYRow)(const uint8* src_argb, uint8* dst_y, int pix) = |
| 1440 | ARGBToYRow_C; |
| 1441 | #endif |
| 1442 | if (!src_argb4444 || !dst_y || !dst_u || !dst_v || |
| 1443 | width <= 0 || height == 0) { |
| 1444 | return -1; |
| 1445 | } |
| 1446 | // Negative height means invert the image. |
| 1447 | if (height < 0) { |
| 1448 | height = -height; |
| 1449 | src_argb4444 = src_argb4444 + (height - 1) * src_stride_argb4444; |
| 1450 | src_stride_argb4444 = -src_stride_argb4444; |
| 1451 | } |
| 1452 |
| 1453 | #if defined(HAS_ARGB4444TOYROW_NEON) |
| 1454 | if (TestCpuFlag(kCpuHasNEON) && width >= 8) { |
| 1455 | ARGB4444ToYRow = ARGB4444ToYRow_Any_NEON; |
| 1456 | if (IS_ALIGNED(width, 8)) { |
| 1457 | ARGB4444ToYRow = ARGB4444ToYRow_NEON; |
| 1458 | } |
| 1459 | if (width >= 16) { |
| 1460 | ARGB4444ToUVRow = ARGB4444ToUVRow_Any_NEON; |
| 1461 | if (IS_ALIGNED(width, 16)) { |
| 1462 | ARGB4444ToUVRow = ARGB4444ToUVRow_NEON; |
| 1463 | } |
| 1464 | } |
| 1465 | } |
| 1466 | #else // HAS_ARGB4444TOYROW_NEON |
| 1467 |
| 1468 | #if defined(HAS_ARGB4444TOARGBROW_SSE2) |
| 1469 | if (TestCpuFlag(kCpuHasSSE2) && width >= 8) { |
| 1470 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_SSE2; |
| 1471 | if (IS_ALIGNED(width, 8)) { |
| 1472 | ARGB4444ToARGBRow = ARGB4444ToARGBRow_SSE2; |
| 1473 | } |
| 1474 | } |
| 1475 | #endif |
| 1476 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 1477 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 1478 | ARGBToUVRow = ARGBToUVRow_Any_SSSE3; |
| 1479 | if (IS_ALIGNED(width, 16)) { |
| 1480 | ARGBToUVRow = ARGBToUVRow_SSSE3; |
| 1481 | } |
| 1482 | } |
| 1483 | #endif |
| 1484 | #if defined(HAS_ARGBTOUVROW_SSSE3) |
| 1485 | if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { |
| 1486 | ARGBToYRow = ARGBToYRow_Any_SSSE3; |
| 1487 | if (IS_ALIGNED(width, 16)) { |
| 1488 | ARGBToYRow = ARGBToYRow_Unaligned_SSSE3; |
| 1489 | if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { |
| 1490 | ARGBToYRow = ARGBToYRow_SSSE3; |
| 1491 | } |
| 1492 | } |
| 1493 | } |
| 1494 | #endif // HAS_ARGBTOUVROW_SSSE3 |
| 1495 | #endif // HAS_ARGB4444TOYROW_NEON |
| 1496 |
| 1497 | { |
| 1498 | #if !defined(HAS_ARGB4444TOYROW_NEON) |
| 1499 | // Allocate 2 rows of ARGB. |
| 1500 | const int kRowSize = (width * 4 + 15) & ~15; |
| 1501 | align_buffer_64(row, kRowSize * 2); |
| 1502 | #endif |
| 1503 |
| 1504 | for (y = 0; y < height - 1; y += 2) { |
| 1505 | #if defined(HAS_ARGB4444TOYROW_NEON) |
| 1506 | ARGB4444ToUVRow(src_argb4444, src_stride_argb4444, dst_u, dst_v, width); |
| 1507 | ARGB4444ToYRow(src_argb4444, dst_y, width); |
| 1508 | ARGB4444ToYRow(src_argb4444 + src_stride_argb4444, dst_y + dst_stride_y, |
| 1509 | width); |
| 1510 | #else |
| 1511 | ARGB4444ToARGBRow(src_argb4444, row, width); |
| 1512 | ARGB4444ToARGBRow(src_argb4444 + src_stride_argb4444, row + kRowSize, |
| 1513 | width); |
| 1514 | ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); |
| 1515 | ARGBToYRow(row, dst_y, width); |
| 1516 | ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); |
| 1517 | #endif |
| 1518 | src_argb4444 += src_stride_argb4444 * 2; |
| 1519 | dst_y += dst_stride_y * 2; |
| 1520 | dst_u += dst_stride_u; |
| 1521 | dst_v += dst_stride_v; |
| 1522 | } |
| 1523 | if (height & 1) { |
| 1524 | #if defined(HAS_ARGB4444TOYROW_NEON) |
| 1525 | ARGB4444ToUVRow(src_argb4444, 0, dst_u, dst_v, width); |
| 1526 | ARGB4444ToYRow(src_argb4444, dst_y, width); |
| 1527 | #else |
| 1528 | ARGB4444ToARGBRow(src_argb4444, row, width); |
| 1529 | ARGBToUVRow(row, 0, dst_u, dst_v, width); |
| 1530 | ARGBToYRow(row, dst_y, width); |
| 1531 | #endif |
| 1532 | } |
| 1533 | #if !defined(HAS_ARGB4444TOYROW_NEON) |
| 1534 | free_aligned_buffer_64(row); |
| 1535 | #endif |
| 1536 | } |
| 1537 | return 0; |
| 1538 | } |
| 1539 |
| 1540 | #ifdef __cplusplus |
| 1541 | } // extern "C" |
| 1542 | } // namespace libyuv |
| 1543 | #endif |
| 1544 |