Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 CopyRow(src, dst, width); | 219 CopyRow(src, dst, width); |
| 220 CopyRow(src + src_stride_0, dst + dst_stride, width); | 220 CopyRow(src + src_stride_0, dst + dst_stride, width); |
| 221 src += src_stride_0 + src_stride_1; | 221 src += src_stride_0 + src_stride_1; |
| 222 dst += dst_stride * 2; | 222 dst += dst_stride * 2; |
| 223 } | 223 } |
| 224 if (height & 1) { | 224 if (height & 1) { |
| 225 CopyRow(src, dst, width); | 225 CopyRow(src, dst, width); |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 | 228 |
| 229 // Support function for NV12 etc UV channels. | 229 LIBYUV_API |
| 230 // Width and height are plane sizes (typically half pixel width). | 230 int SplitUVPlanes(const uint8* src_uv, int src_stride_uv, |
|
fbarchard1
2016/08/24 17:42:23
suggest keeping the comments.
| |
| 231 static void SplitPlane(const uint8* src_uv, int src_stride_uv, | 231 uint8* dst_u, int dst_stride_u, |
| 232 uint8* dst_u, int dst_stride_u, | 232 uint8* dst_v, int dst_stride_v, |
| 233 uint8* dst_v, int dst_stride_v, | 233 int width, int height) { |
| 234 int width, int height) { | 234 if (!src_uv || !dst_u || !dst_v || width <= 0 || height == 0) { |
| 235 int y; | 235 return -1; |
| 236 void (*SplitUVRow)(const uint8* src_uv, uint8* dst_u, uint8* dst_v, | 236 } |
| 237 int width) = SplitUVRow_C; | |
| 238 // Negative height means invert the image. | 237 // Negative height means invert the image. |
| 239 if (height < 0) { | 238 if (height < 0) { |
| 240 height = -height; | 239 height = -height; |
| 241 dst_u = dst_u + (height - 1) * dst_stride_u; | 240 dst_u = dst_u + (height - 1) * dst_stride_u; |
| 242 dst_v = dst_v + (height - 1) * dst_stride_v; | 241 dst_v = dst_v + (height - 1) * dst_stride_v; |
| 243 dst_stride_u = -dst_stride_u; | 242 dst_stride_u = -dst_stride_u; |
| 244 dst_stride_v = -dst_stride_v; | 243 dst_stride_v = -dst_stride_v; |
| 245 } | 244 } |
| 246 // Coalesce rows. | 245 // Coalesce rows. |
| 247 if (src_stride_uv == width * 2 && | 246 if (src_stride_uv == width * 2 && |
| 248 dst_stride_u == width && | 247 dst_stride_u == width && |
| 249 dst_stride_v == width) { | 248 dst_stride_v == width) { |
| 250 width *= height; | 249 width *= height; |
| 251 height = 1; | 250 height = 1; |
| 252 src_stride_uv = dst_stride_u = dst_stride_v = 0; | 251 src_stride_uv = dst_stride_u = dst_stride_v = 0; |
| 253 } | 252 } |
| 254 #if defined(HAS_SPLITUVROW_SSE2) | 253 SplitUVRowFunction SplitUVRow = GetOptimizedSplitUVRowFunction( |
|
fbarchard1
2016/08/24 17:42:23
prefer not use getter function.
| |
| 255 if (TestCpuFlag(kCpuHasSSE2)) { | 254 src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, dst_stride_v, width); |
| 256 SplitUVRow = SplitUVRow_Any_SSE2; | |
| 257 if (IS_ALIGNED(width, 16)) { | |
| 258 SplitUVRow = SplitUVRow_SSE2; | |
| 259 } | |
| 260 } | |
| 261 #endif | |
| 262 #if defined(HAS_SPLITUVROW_AVX2) | |
| 263 if (TestCpuFlag(kCpuHasAVX2)) { | |
| 264 SplitUVRow = SplitUVRow_Any_AVX2; | |
| 265 if (IS_ALIGNED(width, 32)) { | |
| 266 SplitUVRow = SplitUVRow_AVX2; | |
| 267 } | |
| 268 } | |
| 269 #endif | |
| 270 #if defined(HAS_SPLITUVROW_NEON) | |
| 271 if (TestCpuFlag(kCpuHasNEON)) { | |
| 272 SplitUVRow = SplitUVRow_Any_NEON; | |
| 273 if (IS_ALIGNED(width, 16)) { | |
| 274 SplitUVRow = SplitUVRow_NEON; | |
| 275 } | |
| 276 } | |
| 277 #endif | |
| 278 #if defined(HAS_SPLITUVROW_DSPR2) | |
| 279 if (TestCpuFlag(kCpuHasDSPR2) && | |
| 280 IS_ALIGNED(dst_u, 4) && IS_ALIGNED(dst_stride_u, 4) && | |
| 281 IS_ALIGNED(dst_v, 4) && IS_ALIGNED(dst_stride_v, 4)) { | |
| 282 SplitUVRow = SplitUVRow_Any_DSPR2; | |
| 283 if (IS_ALIGNED(width, 16)) { | |
| 284 SplitUVRow = SplitUVRow_DSPR2; | |
| 285 } | |
| 286 } | |
| 287 #endif | |
| 288 | 255 |
| 289 for (y = 0; y < height; ++y) { | 256 for (int y = 0; y < height; ++y) { |
|
fbarchard1
2016/08/24 17:42:23
declare y at top for c89 compatibility.
| |
| 290 // Copy a row of UV. | 257 // Copy a row of UV. |
| 291 SplitUVRow(src_uv, dst_u, dst_v, width); | 258 SplitUVRow(src_uv, dst_u, dst_v, width); |
| 292 dst_u += dst_stride_u; | 259 dst_u += dst_stride_u; |
| 293 dst_v += dst_stride_v; | 260 dst_v += dst_stride_v; |
| 294 src_uv += src_stride_uv; | 261 src_uv += src_stride_uv; |
| 295 } | 262 } |
| 263 return 0; | |
| 296 } | 264 } |
| 297 | 265 |
| 298 // Support converting from FOURCC_M420 | 266 // Support converting from FOURCC_M420 |
| 299 // Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for | 267 // Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for |
| 300 // easy conversion to I420. | 268 // easy conversion to I420. |
| 301 // M420 format description: | 269 // M420 format description: |
| 302 // M420 is row biplanar 420: 2 rows of Y and 1 row of UV. | 270 // M420 is row biplanar 420: 2 rows of Y and 1 row of UV. |
| 303 // Chroma is half width / half height. (420) | 271 // Chroma is half width / half height. (420) |
| 304 // src_stride_m420 is row planar. Normally this will be the width in pixels. | 272 // src_stride_m420 is row planar. Normally this will be the width in pixels. |
| 305 // The UV plane is half width, but 2 values, so src_stride_m420 applies to | 273 // The UV plane is half width, but 2 values, so src_stride_m420 applies to |
| 306 // this as well as the two Y planes. | 274 // this as well as the two Y planes. |
| 307 static int X420ToI420(const uint8* src_y, | 275 static int X420ToI420(const uint8* src_y, |
| 308 int src_stride_y0, int src_stride_y1, | 276 int src_stride_y0, int src_stride_y1, |
| 309 const uint8* src_uv, int src_stride_uv, | 277 const uint8* src_uv, int src_stride_uv, |
| 310 uint8* dst_y, int dst_stride_y, | 278 uint8* dst_y, int dst_stride_y, |
| 311 uint8* dst_u, int dst_stride_u, | 279 uint8* dst_u, int dst_stride_u, |
| 312 uint8* dst_v, int dst_stride_v, | 280 uint8* dst_v, int dst_stride_v, |
| 313 int width, int height) { | 281 int width, int height) { |
| 314 int y; | 282 int y; |
| 315 int halfwidth = (width + 1) >> 1; | 283 int halfwidth = (width + 1) >> 1; |
| 316 int halfheight = (height + 1) >> 1; | 284 int halfheight = (height + 1) >> 1; |
| 317 void (*SplitUVRow)(const uint8* src_uv, uint8* dst_u, uint8* dst_v, | |
| 318 int width) = SplitUVRow_C; | |
| 319 if (!src_y || !src_uv || | 285 if (!src_y || !src_uv || |
| 320 !dst_y || !dst_u || !dst_v || | 286 !dst_y || !dst_u || !dst_v || |
| 321 width <= 0 || height == 0) { | 287 width <= 0 || height == 0) { |
| 322 return -1; | 288 return -1; |
| 323 } | 289 } |
| 324 // Negative height means invert the image. | 290 // Negative height means invert the image. |
| 325 if (height < 0) { | 291 if (height < 0) { |
| 326 height = -height; | 292 height = -height; |
| 327 halfheight = (height + 1) >> 1; | 293 halfheight = (height + 1) >> 1; |
| 328 dst_y = dst_y + (height - 1) * dst_stride_y; | 294 dst_y = dst_y + (height - 1) * dst_stride_y; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 341 src_stride_y0 = src_stride_y1 = dst_stride_y = 0; | 307 src_stride_y0 = src_stride_y1 = dst_stride_y = 0; |
| 342 } | 308 } |
| 343 // Coalesce rows. | 309 // Coalesce rows. |
| 344 if (src_stride_uv == halfwidth * 2 && | 310 if (src_stride_uv == halfwidth * 2 && |
| 345 dst_stride_u == halfwidth && | 311 dst_stride_u == halfwidth && |
| 346 dst_stride_v == halfwidth) { | 312 dst_stride_v == halfwidth) { |
| 347 halfwidth *= halfheight; | 313 halfwidth *= halfheight; |
| 348 halfheight = 1; | 314 halfheight = 1; |
| 349 src_stride_uv = dst_stride_u = dst_stride_v = 0; | 315 src_stride_uv = dst_stride_u = dst_stride_v = 0; |
| 350 } | 316 } |
| 351 #if defined(HAS_SPLITUVROW_SSE2) | 317 SplitUVRowFunction SplitUVRow = GetOptimizedSplitUVRowFunction( |
| 352 if (TestCpuFlag(kCpuHasSSE2)) { | 318 src_uv, src_stride_uv, |
| 353 SplitUVRow = SplitUVRow_Any_SSE2; | 319 dst_u, dst_stride_u, |
| 354 if (IS_ALIGNED(halfwidth, 16)) { | 320 dst_v, dst_stride_v, |
| 355 SplitUVRow = SplitUVRow_SSE2; | 321 halfwidth); |
| 356 } | |
| 357 } | |
| 358 #endif | |
| 359 #if defined(HAS_SPLITUVROW_AVX2) | |
| 360 if (TestCpuFlag(kCpuHasAVX2)) { | |
| 361 SplitUVRow = SplitUVRow_Any_AVX2; | |
| 362 if (IS_ALIGNED(halfwidth, 32)) { | |
| 363 SplitUVRow = SplitUVRow_AVX2; | |
| 364 } | |
| 365 } | |
| 366 #endif | |
| 367 #if defined(HAS_SPLITUVROW_NEON) | |
| 368 if (TestCpuFlag(kCpuHasNEON)) { | |
| 369 SplitUVRow = SplitUVRow_Any_NEON; | |
| 370 if (IS_ALIGNED(halfwidth, 16)) { | |
| 371 SplitUVRow = SplitUVRow_NEON; | |
| 372 } | |
| 373 } | |
| 374 #endif | |
| 375 #if defined(HAS_SPLITUVROW_DSPR2) | |
| 376 if (TestCpuFlag(kCpuHasDSPR2) && | |
| 377 IS_ALIGNED(src_uv, 4) && IS_ALIGNED(src_stride_uv, 4) && | |
| 378 IS_ALIGNED(dst_u, 4) && IS_ALIGNED(dst_stride_u, 4) && | |
| 379 IS_ALIGNED(dst_v, 4) && IS_ALIGNED(dst_stride_v, 4)) { | |
| 380 SplitUVRow = SplitUVRow_Any_DSPR2; | |
| 381 if (IS_ALIGNED(halfwidth, 16)) { | |
| 382 SplitUVRow = SplitUVRow_DSPR2; | |
| 383 } | |
| 384 } | |
| 385 #endif | |
| 386 | 322 |
| 387 if (dst_y) { | 323 if (dst_y) { |
| 388 if (src_stride_y0 == src_stride_y1) { | 324 if (src_stride_y0 == src_stride_y1) { |
| 389 CopyPlane(src_y, src_stride_y0, dst_y, dst_stride_y, width, height); | 325 CopyPlane(src_y, src_stride_y0, dst_y, dst_stride_y, width, height); |
| 390 } else { | 326 } else { |
| 391 CopyPlane2(src_y, src_stride_y0, src_stride_y1, dst_y, dst_stride_y, | 327 CopyPlane2(src_y, src_stride_y0, src_stride_y1, dst_y, dst_stride_y, |
| 392 width, height); | 328 width, height); |
| 393 } | 329 } |
| 394 } | 330 } |
| 395 | 331 |
| (...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1498 } | 1434 } |
| 1499 | 1435 |
| 1500 // Copy UV planes as is - I420 | 1436 // Copy UV planes as is - I420 |
| 1501 if (src_pixel_stride_uv == 1) { | 1437 if (src_pixel_stride_uv == 1) { |
| 1502 CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, halfheight); | 1438 CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, halfheight); |
| 1503 CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, halfheight); | 1439 CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, halfheight); |
| 1504 return 0; | 1440 return 0; |
| 1505 // Split UV planes - NV21 | 1441 // Split UV planes - NV21 |
| 1506 } else if (src_pixel_stride_uv == 2 && vu_off == -1 && | 1442 } else if (src_pixel_stride_uv == 2 && vu_off == -1 && |
| 1507 src_stride_u == src_stride_v) { | 1443 src_stride_u == src_stride_v) { |
| 1508 SplitPlane(src_v, src_stride_v, dst_v, dst_stride_v, dst_u, dst_stride_u, | 1444 SplitUVPlanes(src_v, src_stride_v, dst_v, dst_stride_v, dst_u, dst_stride_u, |
| 1509 halfwidth, halfheight); | 1445 halfwidth, halfheight); |
| 1510 return 0; | 1446 return 0; |
| 1511 // Split UV planes - NV12 | 1447 // Split UV planes - NV12 |
| 1512 } else if (src_pixel_stride_uv == 2 && vu_off == 1 && | 1448 } else if (src_pixel_stride_uv == 2 && vu_off == 1 && |
| 1513 src_stride_u == src_stride_v) { | 1449 src_stride_u == src_stride_v) { |
| 1514 SplitPlane(src_u, src_stride_u, dst_u, dst_stride_u, dst_v, dst_stride_v, | 1450 SplitUVPlanes(src_u, src_stride_u, dst_u, dst_stride_u, dst_v, dst_stride_v, |
| 1515 halfwidth, halfheight); | 1451 halfwidth, halfheight); |
| 1516 return 0; | 1452 return 0; |
| 1517 } | 1453 } |
| 1518 | 1454 |
| 1519 for (y = 0; y < halfheight; ++y) { | 1455 for (y = 0; y < halfheight; ++y) { |
| 1520 SplitPixels(src_u, src_pixel_stride_uv, dst_u, halfwidth); | 1456 SplitPixels(src_u, src_pixel_stride_uv, dst_u, halfwidth); |
| 1521 SplitPixels(src_v, src_pixel_stride_uv, dst_v, halfwidth); | 1457 SplitPixels(src_v, src_pixel_stride_uv, dst_v, halfwidth); |
| 1522 src_u += src_stride_u; | 1458 src_u += src_stride_u; |
| 1523 src_v += src_stride_v; | 1459 src_v += src_stride_v; |
| 1524 dst_u += dst_stride_u; | 1460 dst_u += dst_stride_u; |
| 1525 dst_v += dst_stride_v; | 1461 dst_v += dst_stride_v; |
| 1526 } | 1462 } |
| 1527 return 0; | 1463 return 0; |
| 1528 } | 1464 } |
| 1529 | 1465 |
| 1530 #ifdef __cplusplus | 1466 #ifdef __cplusplus |
| 1531 } // extern "C" | 1467 } // extern "C" |
| 1532 } // namespace libyuv | 1468 } // namespace libyuv |
| 1533 #endif | 1469 #endif |
| OLD | NEW |