Changeset 5633 for pjproject/trunk/third_party/yuv/source/rotate.cc
- Timestamp:
- Jul 28, 2017 2:51:44 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/third_party/yuv/source/rotate.cc
r5358 r5633 11 11 #include "libyuv/rotate.h" 12 12 13 #include "libyuv/convert.h" 13 14 #include "libyuv/cpu_id.h" 14 #include "libyuv/convert.h"15 15 #include "libyuv/planar_functions.h" 16 16 #include "libyuv/rotate_row.h" … … 23 23 24 24 LIBYUV_API 25 void TransposePlane(const uint8* src, int src_stride, 26 uint8* dst, int dst_stride, 27 int width, int height) { 25 void TransposePlane(const uint8* src, 26 int src_stride, 27 uint8* dst, 28 int dst_stride, 29 int width, 30 int height) { 28 31 int i = height; 29 void (*TransposeWx8)(const uint8* src, int src_stride, 30 uint8* dst, int dst_stride, int width) = TransposeWx8_C; 32 #if defined(HAS_TRANSPOSEWX16_MSA) 33 void (*TransposeWx16)(const uint8* src, int src_stride, uint8* dst, 34 int dst_stride, int width) = TransposeWx16_C; 35 #else 36 void (*TransposeWx8)(const uint8* src, int src_stride, uint8* dst, 37 int dst_stride, int width) = TransposeWx8_C; 38 #endif 31 39 #if defined(HAS_TRANSPOSEWX8_NEON) 32 40 if (TestCpuFlag(kCpuHasNEON)) { … … 52 60 #if defined(HAS_TRANSPOSEWX8_DSPR2) 53 61 if (TestCpuFlag(kCpuHasDSPR2)) { 54 if (IS_ALIGNED(width, 4) && 55 IS_ALIGNED(src , 4) && IS_ALIGNED(src_stride, 4)) {62 if (IS_ALIGNED(width, 4) && IS_ALIGNED(src, 4) && 63 IS_ALIGNED(src_stride, 4)) { 56 64 TransposeWx8 = TransposeWx8_Fast_DSPR2; 57 65 } else { … … 60 68 } 61 69 #endif 62 70 #if defined(HAS_TRANSPOSEWX16_MSA) 71 if (TestCpuFlag(kCpuHasMSA)) { 72 TransposeWx16 = TransposeWx16_Any_MSA; 73 if (IS_ALIGNED(width, 16)) { 74 TransposeWx16 = TransposeWx16_MSA; 75 } 76 } 77 #endif 78 79 #if defined(HAS_TRANSPOSEWX16_MSA) 80 // Work across the source in 16x16 tiles 81 while (i >= 16) { 82 TransposeWx16(src, src_stride, dst, dst_stride, width); 83 src += 16 * src_stride; // Go down 16 rows. 84 dst += 16; // Move over 16 columns. 85 i -= 16; 86 } 87 #else 63 88 // Work across the source in 8x8 tiles 64 89 while (i >= 8) { 65 90 TransposeWx8(src, src_stride, dst, dst_stride, width); 66 src += 8 * src_stride; 67 dst += 8; 91 src += 8 * src_stride; // Go down 8 rows. 92 dst += 8; // Move over 8 columns. 68 93 i -= 8; 69 94 } 95 #endif 70 96 71 97 if (i > 0) { … … 75 101 76 102 LIBYUV_API 77 void RotatePlane90(const uint8* src, int src_stride, 78 uint8* dst, int dst_stride, 79 int width, int height) { 103 void RotatePlane90(const uint8* src, 104 int src_stride, 105 uint8* dst, 106 int dst_stride, 107 int width, 108 int height) { 80 109 // Rotate by 90 is a transpose with the source read 81 110 // from bottom to top. So set the source pointer to the end … … 87 116 88 117 LIBYUV_API 89 void RotatePlane270(const uint8* src, int src_stride, 90 uint8* dst, int dst_stride, 91 int width, int height) { 118 void RotatePlane270(const uint8* src, 119 int src_stride, 120 uint8* dst, 121 int dst_stride, 122 int width, 123 int height) { 92 124 // Rotate by 270 is a transpose with the destination written 93 125 // from bottom to top. So set the destination pointer to the end … … 99 131 100 132 LIBYUV_API 101 void RotatePlane180(const uint8* src, int src_stride, 102 uint8* dst, int dst_stride, 103 int width, int height) { 133 void RotatePlane180(const uint8* src, 134 int src_stride, 135 uint8* dst, 136 int dst_stride, 137 int width, 138 int height) { 104 139 // Swap first and last row and mirror the content. Uses a temporary row. 105 140 align_buffer_64(row, width); … … 136 171 // TODO(fbarchard): Mirror on mips handle unaligned memory. 137 172 #if defined(HAS_MIRRORROW_DSPR2) 138 if (TestCpuFlag(kCpuHasDSPR2) && 139 IS_ALIGNED(src , 4) && IS_ALIGNED(src_stride, 4) &&140 IS_ALIGNED(dst , 4) && IS_ALIGNED(dst_stride, 4)) {173 if (TestCpuFlag(kCpuHasDSPR2) && IS_ALIGNED(src, 4) && 174 IS_ALIGNED(src_stride, 4) && IS_ALIGNED(dst, 4) && 175 IS_ALIGNED(dst_stride, 4)) { 141 176 MirrorRow = MirrorRow_DSPR2; 177 } 178 #endif 179 #if defined(HAS_MIRRORROW_MSA) 180 if (TestCpuFlag(kCpuHasMSA)) { 181 MirrorRow = MirrorRow_Any_MSA; 182 if (IS_ALIGNED(width, 64)) { 183 MirrorRow = MirrorRow_MSA; 184 } 142 185 } 143 186 #endif … … 182 225 183 226 LIBYUV_API 184 void TransposeUV(const uint8* src, int src_stride, 185 uint8* dst_a, int dst_stride_a, 186 uint8* dst_b, int dst_stride_b, 187 int width, int height) { 227 void TransposeUV(const uint8* src, 228 int src_stride, 229 uint8* dst_a, 230 int dst_stride_a, 231 uint8* dst_b, 232 int dst_stride_b, 233 int width, 234 int height) { 188 235 int i = height; 189 void (*TransposeUVWx8)(const uint8* src, int src_stride, 190 uint8* dst_a, int dst_stride_a, 191 uint8* dst_b, int dst_stride_b, 236 #if defined(HAS_TRANSPOSEUVWX16_MSA) 237 void (*TransposeUVWx16)(const uint8* src, int src_stride, uint8* dst_a, 238 int dst_stride_a, uint8* dst_b, int dst_stride_b, 239 int width) = TransposeUVWx16_C; 240 #else 241 void (*TransposeUVWx8)(const uint8* src, int src_stride, uint8* dst_a, 242 int dst_stride_a, uint8* dst_b, int dst_stride_b, 192 243 int width) = TransposeUVWx8_C; 244 #endif 193 245 #if defined(HAS_TRANSPOSEUVWX8_NEON) 194 246 if (TestCpuFlag(kCpuHasNEON)) { … … 205 257 #endif 206 258 #if defined(HAS_TRANSPOSEUVWX8_DSPR2) 207 if (TestCpuFlag(kCpuHasDSPR2) && IS_ALIGNED(width, 2) && 208 IS_ALIGNED(src , 4) && IS_ALIGNED(src_stride, 4)) {259 if (TestCpuFlag(kCpuHasDSPR2) && IS_ALIGNED(width, 2) && IS_ALIGNED(src, 4) && 260 IS_ALIGNED(src_stride, 4)) { 209 261 TransposeUVWx8 = TransposeUVWx8_DSPR2; 210 262 } 211 263 #endif 212 264 #if defined(HAS_TRANSPOSEUVWX16_MSA) 265 if (TestCpuFlag(kCpuHasMSA)) { 266 TransposeUVWx16 = TransposeUVWx16_Any_MSA; 267 if (IS_ALIGNED(width, 8)) { 268 TransposeUVWx16 = TransposeUVWx16_MSA; 269 } 270 } 271 #endif 272 273 #if defined(HAS_TRANSPOSEUVWX16_MSA) 274 // Work through the source in 8x8 tiles. 275 while (i >= 16) { 276 TransposeUVWx16(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, 277 width); 278 src += 16 * src_stride; // Go down 16 rows. 279 dst_a += 16; // Move over 8 columns. 280 dst_b += 16; // Move over 8 columns. 281 i -= 16; 282 } 283 #else 213 284 // Work through the source in 8x8 tiles. 214 285 while (i >= 8) { 215 TransposeUVWx8(src, src_stride, 216 dst_a, dst_stride_a, 217 dst_b, dst_stride_b, 286 TransposeUVWx8(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, 218 287 width); 219 src += 8 * src_stride; 220 dst_a += 8; 221 dst_b += 8; 288 src += 8 * src_stride; // Go down 8 rows. 289 dst_a += 8; // Move over 8 columns. 290 dst_b += 8; // Move over 8 columns. 222 291 i -= 8; 223 292 } 293 #endif 224 294 225 295 if (i > 0) { 226 TransposeUVWxH_C(src, src_stride, 227 dst_a, dst_stride_a, 228 dst_b, dst_stride_b, 296 TransposeUVWxH_C(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, 229 297 width, i); 230 298 } … … 232 300 233 301 LIBYUV_API 234 void RotateUV90(const uint8* src, int src_stride, 235 uint8* dst_a, int dst_stride_a, 236 uint8* dst_b, int dst_stride_b, 237 int width, int height) { 302 void RotateUV90(const uint8* src, 303 int src_stride, 304 uint8* dst_a, 305 int dst_stride_a, 306 uint8* dst_b, 307 int dst_stride_b, 308 int width, 309 int height) { 238 310 src += src_stride * (height - 1); 239 311 src_stride = -src_stride; 240 312 241 TransposeUV(src, src_stride, 242 dst_a, dst_stride_a, 243 dst_b, dst_stride_b, 244 width, height); 245 } 246 247 LIBYUV_API 248 void RotateUV270(const uint8* src, int src_stride, 249 uint8* dst_a, int dst_stride_a, 250 uint8* dst_b, int dst_stride_b, 251 int width, int height) { 313 TransposeUV(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, width, 314 height); 315 } 316 317 LIBYUV_API 318 void RotateUV270(const uint8* src, 319 int src_stride, 320 uint8* dst_a, 321 int dst_stride_a, 322 uint8* dst_b, 323 int dst_stride_b, 324 int width, 325 int height) { 252 326 dst_a += dst_stride_a * (width - 1); 253 327 dst_b += dst_stride_b * (width - 1); … … 255 329 dst_stride_b = -dst_stride_b; 256 330 257 TransposeUV(src, src_stride, 258 dst_a, dst_stride_a, 259 dst_b, dst_stride_b, 260 width, height); 331 TransposeUV(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, width, 332 height); 261 333 } 262 334 263 335 // Rotate 180 is a horizontal and vertical flip. 264 336 LIBYUV_API 265 void RotateUV180(const uint8* src, int src_stride, 266 uint8* dst_a, int dst_stride_a, 267 uint8* dst_b, int dst_stride_b, 268 int width, int height) { 337 void RotateUV180(const uint8* src, 338 int src_stride, 339 uint8* dst_a, 340 int dst_stride_a, 341 uint8* dst_b, 342 int dst_stride_b, 343 int width, 344 int height) { 269 345 int i; 270 346 void (*MirrorUVRow)(const uint8* src, uint8* dst_u, uint8* dst_v, int width) = … … 281 357 #endif 282 358 #if defined(HAS_MIRRORUVROW_DSPR2) 283 if (TestCpuFlag(kCpuHasDSPR2) && 284 IS_ALIGNED(src , 4) && IS_ALIGNED(src_stride, 4)) {359 if (TestCpuFlag(kCpuHasDSPR2) && IS_ALIGNED(src, 4) && 360 IS_ALIGNED(src_stride, 4)) { 285 361 MirrorUVRow = MirrorUVRow_DSPR2; 286 362 } … … 299 375 300 376 LIBYUV_API 301 int RotatePlane(const uint8* src, int src_stride, 302 uint8* dst, int dst_stride, 303 int width, int height, 377 int RotatePlane(const uint8* src, 378 int src_stride, 379 uint8* dst, 380 int dst_stride, 381 int width, 382 int height, 304 383 enum RotationMode mode) { 305 384 if (!src || width <= 0 || height == 0 || !dst) { … … 317 396 case kRotate0: 318 397 // copy frame 319 CopyPlane(src, src_stride, 320 dst, dst_stride, 321 width, height); 398 CopyPlane(src, src_stride, dst, dst_stride, width, height); 322 399 return 0; 323 400 case kRotate90: 324 RotatePlane90(src, src_stride, 325 dst, dst_stride, 326 width, height); 401 RotatePlane90(src, src_stride, dst, dst_stride, width, height); 327 402 return 0; 328 403 case kRotate270: 329 RotatePlane270(src, src_stride, 330 dst, dst_stride, 331 width, height); 404 RotatePlane270(src, src_stride, dst, dst_stride, width, height); 332 405 return 0; 333 406 case kRotate180: 334 RotatePlane180(src, src_stride, 335 dst, dst_stride, 336 width, height); 407 RotatePlane180(src, src_stride, dst, dst_stride, width, height); 337 408 return 0; 338 409 default: … … 343 414 344 415 LIBYUV_API 345 int I420Rotate(const uint8* src_y, int src_stride_y, 346 const uint8* src_u, int src_stride_u, 347 const uint8* src_v, int src_stride_v, 348 uint8* dst_y, int dst_stride_y, 349 uint8* dst_u, int dst_stride_u, 350 uint8* dst_v, int dst_stride_v, 351 int width, int height, 416 int I420Rotate(const uint8* src_y, 417 int src_stride_y, 418 const uint8* src_u, 419 int src_stride_u, 420 const uint8* src_v, 421 int src_stride_v, 422 uint8* dst_y, 423 int dst_stride_y, 424 uint8* dst_u, 425 int dst_stride_u, 426 uint8* dst_v, 427 int dst_stride_v, 428 int width, 429 int height, 352 430 enum RotationMode mode) { 353 431 int halfwidth = (width + 1) >> 1; 354 432 int halfheight = (height + 1) >> 1; 355 if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || 356 !dst_ y || !dst_u || !dst_v) {433 if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || !dst_y || 434 !dst_u || !dst_v) { 357 435 return -1; 358 436 } … … 373 451 case kRotate0: 374 452 // copy frame 375 return I420Copy(src_y, src_stride_y, 376 src_u, src_stride_u, 377 src_v, src_stride_v, 378 dst_y, dst_stride_y, 379 dst_u, dst_stride_u, 380 dst_v, dst_stride_v, 381 width, height); 453 return I420Copy(src_y, src_stride_y, src_u, src_stride_u, src_v, 454 src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, 455 dst_v, dst_stride_v, width, height); 382 456 case kRotate90: 383 RotatePlane90(src_y, src_stride_y, 384 dst_y, dst_stride_y, 385 width, height); 386 RotatePlane90(src_u, src_stride_u, 387 dst_u, dst_stride_u, 388 halfwidth, halfheight); 389 RotatePlane90(src_v, src_stride_v, 390 dst_v, dst_stride_v, 391 halfwidth, halfheight); 457 RotatePlane90(src_y, src_stride_y, dst_y, dst_stride_y, width, height); 458 RotatePlane90(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, 459 halfheight); 460 RotatePlane90(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, 461 halfheight); 392 462 return 0; 393 463 case kRotate270: 394 RotatePlane270(src_y, src_stride_y, 395 dst_y, dst_stride_y, 396 width, height); 397 RotatePlane270(src_u, src_stride_u, 398 dst_u, dst_stride_u, 399 halfwidth, halfheight); 400 RotatePlane270(src_v, src_stride_v, 401 dst_v, dst_stride_v, 402 halfwidth, halfheight); 464 RotatePlane270(src_y, src_stride_y, dst_y, dst_stride_y, width, height); 465 RotatePlane270(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, 466 halfheight); 467 RotatePlane270(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, 468 halfheight); 403 469 return 0; 404 470 case kRotate180: 405 RotatePlane180(src_y, src_stride_y, 406 dst_y, dst_stride_y, 407 width, height); 408 RotatePlane180(src_u, src_stride_u, 409 dst_u, dst_stride_u, 410 halfwidth, halfheight); 411 RotatePlane180(src_v, src_stride_v, 412 dst_v, dst_stride_v, 413 halfwidth, halfheight); 471 RotatePlane180(src_y, src_stride_y, dst_y, dst_stride_y, width, height); 472 RotatePlane180(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, 473 halfheight); 474 RotatePlane180(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, 475 halfheight); 414 476 return 0; 415 477 default: … … 420 482 421 483 LIBYUV_API 422 int NV12ToI420Rotate(const uint8* src_y, int src_stride_y, 423 const uint8* src_uv, int src_stride_uv, 424 uint8* dst_y, int dst_stride_y, 425 uint8* dst_u, int dst_stride_u, 426 uint8* dst_v, int dst_stride_v, 427 int width, int height, 484 int NV12ToI420Rotate(const uint8* src_y, 485 int src_stride_y, 486 const uint8* src_uv, 487 int src_stride_uv, 488 uint8* dst_y, 489 int dst_stride_y, 490 uint8* dst_u, 491 int dst_stride_u, 492 uint8* dst_v, 493 int dst_stride_v, 494 int width, 495 int height, 428 496 enum RotationMode mode) { 429 497 int halfwidth = (width + 1) >> 1; 430 498 int halfheight = (height + 1) >> 1; 431 if (!src_y || !src_uv || width <= 0 || height == 0 || 432 !dst_ y || !dst_u || !dst_v) {499 if (!src_y || !src_uv || width <= 0 || height == 0 || !dst_y || !dst_u || 500 !dst_v) { 433 501 return -1; 434 502 } … … 447 515 case kRotate0: 448 516 // copy frame 449 return NV12ToI420(src_y, src_stride_y, 450 src_uv, src_stride_uv, 451 dst_y, dst_stride_y, 452 dst_u, dst_stride_u, 453 dst_v, dst_stride_v, 517 return NV12ToI420(src_y, src_stride_y, src_uv, src_stride_uv, dst_y, 518 dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, 454 519 width, height); 455 520 case kRotate90: 456 RotatePlane90(src_y, src_stride_y, 457 dst_y, dst_stride_y, 458 width, height); 459 RotateUV90(src_uv, src_stride_uv, 460 dst_u, dst_stride_u, 461 dst_v, dst_stride_v, 462 halfwidth, halfheight); 521 RotatePlane90(src_y, src_stride_y, dst_y, dst_stride_y, width, height); 522 RotateUV90(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, 523 dst_stride_v, halfwidth, halfheight); 463 524 return 0; 464 525 case kRotate270: 465 RotatePlane270(src_y, src_stride_y, 466 dst_y, dst_stride_y, 467 width, height); 468 RotateUV270(src_uv, src_stride_uv, 469 dst_u, dst_stride_u, 470 dst_v, dst_stride_v, 471 halfwidth, halfheight); 526 RotatePlane270(src_y, src_stride_y, dst_y, dst_stride_y, width, height); 527 RotateUV270(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, 528 dst_stride_v, halfwidth, halfheight); 472 529 return 0; 473 530 case kRotate180: 474 RotatePlane180(src_y, src_stride_y, 475 dst_y, dst_stride_y, 476 width, height); 477 RotateUV180(src_uv, src_stride_uv, 478 dst_u, dst_stride_u, 479 dst_v, dst_stride_v, 480 halfwidth, halfheight); 531 RotatePlane180(src_y, src_stride_y, dst_y, dst_stride_y, width, height); 532 RotateUV180(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, 533 dst_stride_v, halfwidth, halfheight); 481 534 return 0; 482 535 default:
Note: See TracChangeset
for help on using the changeset viewer.