Changeset 5633 for pjproject/trunk/third_party/yuv/source/convert_from.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/convert_from.cc
r5358 r5633 16 16 #include "libyuv/planar_functions.h" 17 17 #include "libyuv/rotate.h" 18 #include "libyuv/row.h" 18 19 #include "libyuv/scale.h" // For ScalePlane() 19 20 #include "libyuv/video_common.h" 20 #include "libyuv/row.h"21 21 22 22 #ifdef __cplusplus … … 31 31 32 32 // I420 To any I4xx YUV format with mirroring. 33 static int I420ToI4xx(const uint8* src_y, int src_stride_y, 34 const uint8* src_u, int src_stride_u, 35 const uint8* src_v, int src_stride_v, 36 uint8* dst_y, int dst_stride_y, 37 uint8* dst_u, int dst_stride_u, 38 uint8* dst_v, int dst_stride_v, 39 int src_y_width, int src_y_height, 40 int dst_uv_width, int dst_uv_height) { 33 static int I420ToI4xx(const uint8* src_y, 34 int src_stride_y, 35 const uint8* src_u, 36 int src_stride_u, 37 const uint8* src_v, 38 int src_stride_v, 39 uint8* dst_y, 40 int dst_stride_y, 41 uint8* dst_u, 42 int dst_stride_u, 43 uint8* dst_v, 44 int dst_stride_v, 45 int src_y_width, 46 int src_y_height, 47 int dst_uv_width, 48 int dst_uv_height) { 41 49 const int dst_y_width = Abs(src_y_width); 42 50 const int dst_y_height = Abs(src_y_height); 43 51 const int src_uv_width = SUBSAMPLE(src_y_width, 1, 1); 44 52 const int src_uv_height = SUBSAMPLE(src_y_height, 1, 1); 45 if (src_y_width == 0 || src_y_height == 0 || 46 dst_uv_width <= 0 || dst_uv_height <= 0) { 47 return -1; 48 } 49 ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, 50 dst_y, dst_stride_y, dst_y_width, dst_y_height, 51 kFilterBilinear); 52 ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, 53 dst_u, dst_stride_u, dst_uv_width, dst_uv_height, 54 kFilterBilinear); 55 ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, 56 dst_v, dst_stride_v, dst_uv_width, dst_uv_height, 57 kFilterBilinear); 53 if (src_y_width == 0 || src_y_height == 0 || dst_uv_width <= 0 || 54 dst_uv_height <= 0) { 55 return -1; 56 } 57 if (dst_y) { 58 ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, dst_y, 59 dst_stride_y, dst_y_width, dst_y_height, kFilterBilinear); 60 } 61 ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, dst_u, 62 dst_stride_u, dst_uv_width, dst_uv_height, kFilterBilinear); 63 ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, dst_v, 64 dst_stride_v, dst_uv_width, dst_uv_height, kFilterBilinear); 58 65 return 0; 59 66 } … … 62 69 // 422 chroma is 1/2 width, 1x height 63 70 LIBYUV_API 64 int I420ToI422(const uint8* src_y, int src_stride_y, 65 const uint8* src_u, int src_stride_u, 66 const uint8* src_v, int src_stride_v, 67 uint8* dst_y, int dst_stride_y, 68 uint8* dst_u, int dst_stride_u, 69 uint8* dst_v, int dst_stride_v, 70 int width, int height) { 71 int I420ToI422(const uint8* src_y, 72 int src_stride_y, 73 const uint8* src_u, 74 int src_stride_u, 75 const uint8* src_v, 76 int src_stride_v, 77 uint8* dst_y, 78 int dst_stride_y, 79 uint8* dst_u, 80 int dst_stride_u, 81 uint8* dst_v, 82 int dst_stride_v, 83 int width, 84 int height) { 71 85 const int dst_uv_width = (Abs(width) + 1) >> 1; 72 86 const int dst_uv_height = Abs(height); 73 return I420ToI4xx(src_y, src_stride_y, 74 src_u, src_stride_u, 75 src_v, src_stride_v, 76 dst_y, dst_stride_y, 77 dst_u, dst_stride_u, 78 dst_v, dst_stride_v, 79 width, height, 80 dst_uv_width, dst_uv_height); 87 return I420ToI4xx(src_y, src_stride_y, src_u, src_stride_u, src_v, 88 src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, 89 dst_v, dst_stride_v, width, height, dst_uv_width, 90 dst_uv_height); 81 91 } 82 92 … … 84 94 // 444 chroma is 1x width, 1x height 85 95 LIBYUV_API 86 int I420ToI444(const uint8* src_y, int src_stride_y, 87 const uint8* src_u, int src_stride_u, 88 const uint8* src_v, int src_stride_v, 89 uint8* dst_y, int dst_stride_y, 90 uint8* dst_u, int dst_stride_u, 91 uint8* dst_v, int dst_stride_v, 92 int width, int height) { 96 int I420ToI444(const uint8* src_y, 97 int src_stride_y, 98 const uint8* src_u, 99 int src_stride_u, 100 const uint8* src_v, 101 int src_stride_v, 102 uint8* dst_y, 103 int dst_stride_y, 104 uint8* dst_u, 105 int dst_stride_u, 106 uint8* dst_v, 107 int dst_stride_v, 108 int width, 109 int height) { 93 110 const int dst_uv_width = Abs(width); 94 111 const int dst_uv_height = Abs(height); 95 return I420ToI4xx(src_y, src_stride_y, 96 src_u, src_stride_u, 97 src_v, src_stride_v, 98 dst_y, dst_stride_y, 99 dst_u, dst_stride_u, 100 dst_v, dst_stride_v, 101 width, height, 102 dst_uv_width, dst_uv_height); 103 } 104 105 // 420 chroma is 1/2 width, 1/2 height 106 // 411 chroma is 1/4 width, 1x height 107 LIBYUV_API 108 int I420ToI411(const uint8* src_y, int src_stride_y, 109 const uint8* src_u, int src_stride_u, 110 const uint8* src_v, int src_stride_v, 111 uint8* dst_y, int dst_stride_y, 112 uint8* dst_u, int dst_stride_u, 113 uint8* dst_v, int dst_stride_v, 114 int width, int height) { 115 const int dst_uv_width = (Abs(width) + 3) >> 2; 116 const int dst_uv_height = Abs(height); 117 return I420ToI4xx(src_y, src_stride_y, 118 src_u, src_stride_u, 119 src_v, src_stride_v, 120 dst_y, dst_stride_y, 121 dst_u, dst_stride_u, 122 dst_v, dst_stride_v, 123 width, height, 124 dst_uv_width, dst_uv_height); 112 return I420ToI4xx(src_y, src_stride_y, src_u, src_stride_u, src_v, 113 src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, 114 dst_v, dst_stride_v, width, height, dst_uv_width, 115 dst_uv_height); 125 116 } 126 117 127 118 // Copy to I400. Source can be I420,422,444,400,NV12,NV21 128 119 LIBYUV_API 129 int I400Copy(const uint8* src_y, int src_stride_y, 130 uint8* dst_y, int dst_stride_y, 131 int width, int height) { 132 if (!src_y || !dst_y || 133 width <= 0 || height == 0) { 120 int I400Copy(const uint8* src_y, 121 int src_stride_y, 122 uint8* dst_y, 123 int dst_stride_y, 124 int width, 125 int height) { 126 if (!src_y || !dst_y || width <= 0 || height == 0) { 134 127 return -1; 135 128 } … … 145 138 146 139 LIBYUV_API 147 int I422ToYUY2(const uint8* src_y, int src_stride_y, 148 const uint8* src_u, int src_stride_u, 149 const uint8* src_v, int src_stride_v, 150 uint8* dst_yuy2, int dst_stride_yuy2, 151 int width, int height) { 140 int I422ToYUY2(const uint8* src_y, 141 int src_stride_y, 142 const uint8* src_u, 143 int src_stride_u, 144 const uint8* src_v, 145 int src_stride_v, 146 uint8* dst_yuy2, 147 int dst_stride_yuy2, 148 int width, 149 int height) { 152 150 int y; 153 151 void (*I422ToYUY2Row)(const uint8* src_y, const uint8* src_u, 154 152 const uint8* src_v, uint8* dst_yuy2, int width) = 155 153 I422ToYUY2Row_C; 156 if (!src_y || !src_u || !src_v || !dst_yuy2 || 157 width <= 0 || height == 0) { 154 if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) { 158 155 return -1; 159 156 } … … 165 162 } 166 163 // Coalesce rows. 167 if (src_stride_y == width && 168 src_stride_u * 2 == width && 169 src_stride_v * 2 == width && 170 dst_stride_yuy2 == width * 2) { 164 if (src_stride_y == width && src_stride_u * 2 == width && 165 src_stride_v * 2 == width && dst_stride_yuy2 == width * 2) { 171 166 width *= height; 172 167 height = 1; … … 201 196 202 197 LIBYUV_API 203 int I420ToYUY2(const uint8* src_y, int src_stride_y, 204 const uint8* src_u, int src_stride_u, 205 const uint8* src_v, int src_stride_v, 206 uint8* dst_yuy2, int dst_stride_yuy2, 207 int width, int height) { 198 int I420ToYUY2(const uint8* src_y, 199 int src_stride_y, 200 const uint8* src_u, 201 int src_stride_u, 202 const uint8* src_v, 203 int src_stride_v, 204 uint8* dst_yuy2, 205 int dst_stride_yuy2, 206 int width, 207 int height) { 208 208 int y; 209 209 void (*I422ToYUY2Row)(const uint8* src_y, const uint8* src_u, 210 210 const uint8* src_v, uint8* dst_yuy2, int width) = 211 211 I422ToYUY2Row_C; 212 if (!src_y || !src_u || !src_v || !dst_yuy2 || 213 width <= 0 || height == 0) { 212 if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) { 214 213 return -1; 215 214 } … … 233 232 if (IS_ALIGNED(width, 16)) { 234 233 I422ToYUY2Row = I422ToYUY2Row_NEON; 234 } 235 } 236 #endif 237 #if defined(HAS_I422TOYUY2ROW_MSA) 238 if (TestCpuFlag(kCpuHasMSA)) { 239 I422ToYUY2Row = I422ToYUY2Row_Any_MSA; 240 if (IS_ALIGNED(width, 32)) { 241 I422ToYUY2Row = I422ToYUY2Row_MSA; 235 242 } 236 243 } … … 253 260 254 261 LIBYUV_API 255 int I422ToUYVY(const uint8* src_y, int src_stride_y, 256 const uint8* src_u, int src_stride_u, 257 const uint8* src_v, int src_stride_v, 258 uint8* dst_uyvy, int dst_stride_uyvy, 259 int width, int height) { 262 int I422ToUYVY(const uint8* src_y, 263 int src_stride_y, 264 const uint8* src_u, 265 int src_stride_u, 266 const uint8* src_v, 267 int src_stride_v, 268 uint8* dst_uyvy, 269 int dst_stride_uyvy, 270 int width, 271 int height) { 260 272 int y; 261 273 void (*I422ToUYVYRow)(const uint8* src_y, const uint8* src_u, 262 274 const uint8* src_v, uint8* dst_uyvy, int width) = 263 275 I422ToUYVYRow_C; 264 if (!src_y || !src_u || !src_v || !dst_uyvy || 265 width <= 0 || height == 0) { 276 if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) { 266 277 return -1; 267 278 } … … 273 284 } 274 285 // Coalesce rows. 275 if (src_stride_y == width && 276 src_stride_u * 2 == width && 277 src_stride_v * 2 == width && 278 dst_stride_uyvy == width * 2) { 286 if (src_stride_y == width && src_stride_u * 2 == width && 287 src_stride_v * 2 == width && dst_stride_uyvy == width * 2) { 279 288 width *= height; 280 289 height = 1; … … 294 303 if (IS_ALIGNED(width, 16)) { 295 304 I422ToUYVYRow = I422ToUYVYRow_NEON; 305 } 306 } 307 #endif 308 #if defined(HAS_I422TOUYVYROW_MSA) 309 if (TestCpuFlag(kCpuHasMSA)) { 310 I422ToUYVYRow = I422ToUYVYRow_Any_MSA; 311 if (IS_ALIGNED(width, 32)) { 312 I422ToUYVYRow = I422ToUYVYRow_MSA; 296 313 } 297 314 } … … 309 326 310 327 LIBYUV_API 311 int I420ToUYVY(const uint8* src_y, int src_stride_y, 312 const uint8* src_u, int src_stride_u, 313 const uint8* src_v, int src_stride_v, 314 uint8* dst_uyvy, int dst_stride_uyvy, 315 int width, int height) { 328 int I420ToUYVY(const uint8* src_y, 329 int src_stride_y, 330 const uint8* src_u, 331 int src_stride_u, 332 const uint8* src_v, 333 int src_stride_v, 334 uint8* dst_uyvy, 335 int dst_stride_uyvy, 336 int width, 337 int height) { 316 338 int y; 317 339 void (*I422ToUYVYRow)(const uint8* src_y, const uint8* src_u, 318 340 const uint8* src_v, uint8* dst_uyvy, int width) = 319 341 I422ToUYVYRow_C; 320 if (!src_y || !src_u || !src_v || !dst_uyvy || 321 width <= 0 || height == 0) { 342 if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) { 322 343 return -1; 323 344 } … … 341 362 if (IS_ALIGNED(width, 16)) { 342 363 I422ToUYVYRow = I422ToUYVYRow_NEON; 364 } 365 } 366 #endif 367 #if defined(HAS_I422TOUYVYROW_MSA) 368 if (TestCpuFlag(kCpuHasMSA)) { 369 I422ToUYVYRow = I422ToUYVYRow_Any_MSA; 370 if (IS_ALIGNED(width, 32)) { 371 I422ToUYVYRow = I422ToUYVYRow_MSA; 343 372 } 344 373 } … … 360 389 } 361 390 362 LIBYUV_API 363 int I420ToNV12(const uint8* src_y, int src_stride_y, 364 const uint8* src_u, int src_stride_u, 365 const uint8* src_v, int src_stride_v, 366 uint8* dst_y, int dst_stride_y, 367 uint8* dst_uv, int dst_stride_uv, 368 int width, int height) { 391 // TODO(fbarchard): test negative height for invert. 392 LIBYUV_API 393 int I420ToNV12(const uint8* src_y, 394 int src_stride_y, 395 const uint8* src_u, 396 int src_stride_u, 397 const uint8* src_v, 398 int src_stride_v, 399 uint8* dst_y, 400 int dst_stride_y, 401 uint8* dst_uv, 402 int dst_stride_uv, 403 int width, 404 int height) { 405 if (!src_y || !src_u || !src_v || !dst_y || !dst_uv || width <= 0 || 406 height == 0) { 407 return -1; 408 } 409 int halfwidth = (width + 1) / 2; 410 int halfheight = height > 0 ? (height + 1) / 2 : (height - 1) / 2; 411 if (dst_y) { 412 CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); 413 } 414 MergeUVPlane(src_u, src_stride_u, src_v, src_stride_v, dst_uv, dst_stride_uv, 415 halfwidth, halfheight); 416 return 0; 417 } 418 419 LIBYUV_API 420 int I420ToNV21(const uint8* src_y, 421 int src_stride_y, 422 const uint8* src_u, 423 int src_stride_u, 424 const uint8* src_v, 425 int src_stride_v, 426 uint8* dst_y, 427 int dst_stride_y, 428 uint8* dst_vu, 429 int dst_stride_vu, 430 int width, 431 int height) { 432 return I420ToNV12(src_y, src_stride_y, src_v, src_stride_v, src_u, 433 src_stride_u, dst_y, dst_stride_y, dst_vu, dst_stride_vu, 434 width, height); 435 } 436 437 // Convert I422 to RGBA with matrix 438 static int I420ToRGBAMatrix(const uint8* src_y, 439 int src_stride_y, 440 const uint8* src_u, 441 int src_stride_u, 442 const uint8* src_v, 443 int src_stride_v, 444 uint8* dst_rgba, 445 int dst_stride_rgba, 446 const struct YuvConstants* yuvconstants, 447 int width, 448 int height) { 369 449 int y; 370 void (*MergeUVRow_)(const uint8* src_u, const uint8* src_v, uint8* dst_uv, 371 int width) = MergeUVRow_C; 372 // Coalesce rows. 373 int halfwidth = (width + 1) >> 1; 374 int halfheight = (height + 1) >> 1; 375 if (!src_y || !src_u || !src_v || !dst_y || !dst_uv || 376 width <= 0 || height == 0) { 377 return -1; 378 } 379 // Negative height means invert the image. 380 if (height < 0) { 381 height = -height; 382 halfheight = (height + 1) >> 1; 383 dst_y = dst_y + (height - 1) * dst_stride_y; 384 dst_uv = dst_uv + (halfheight - 1) * dst_stride_uv; 385 dst_stride_y = -dst_stride_y; 386 dst_stride_uv = -dst_stride_uv; 387 } 388 if (src_stride_y == width && 389 dst_stride_y == width) { 390 width *= height; 391 height = 1; 392 src_stride_y = dst_stride_y = 0; 393 } 394 // Coalesce rows. 395 if (src_stride_u == halfwidth && 396 src_stride_v == halfwidth && 397 dst_stride_uv == halfwidth * 2) { 398 halfwidth *= halfheight; 399 halfheight = 1; 400 src_stride_u = src_stride_v = dst_stride_uv = 0; 401 } 402 #if defined(HAS_MERGEUVROW_SSE2) 403 if (TestCpuFlag(kCpuHasSSE2)) { 404 MergeUVRow_ = MergeUVRow_Any_SSE2; 405 if (IS_ALIGNED(halfwidth, 16)) { 406 MergeUVRow_ = MergeUVRow_SSE2; 407 } 408 } 409 #endif 410 #if defined(HAS_MERGEUVROW_AVX2) 411 if (TestCpuFlag(kCpuHasAVX2)) { 412 MergeUVRow_ = MergeUVRow_Any_AVX2; 413 if (IS_ALIGNED(halfwidth, 32)) { 414 MergeUVRow_ = MergeUVRow_AVX2; 415 } 416 } 417 #endif 418 #if defined(HAS_MERGEUVROW_NEON) 419 if (TestCpuFlag(kCpuHasNEON)) { 420 MergeUVRow_ = MergeUVRow_Any_NEON; 421 if (IS_ALIGNED(halfwidth, 16)) { 422 MergeUVRow_ = MergeUVRow_NEON; 423 } 424 } 425 #endif 426 427 CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); 428 for (y = 0; y < halfheight; ++y) { 429 // Merge a row of U and V into a row of UV. 430 MergeUVRow_(src_u, src_v, dst_uv, halfwidth); 431 src_u += src_stride_u; 432 src_v += src_stride_v; 433 dst_uv += dst_stride_uv; 434 } 435 return 0; 436 } 437 438 LIBYUV_API 439 int I420ToNV21(const uint8* src_y, int src_stride_y, 440 const uint8* src_u, int src_stride_u, 441 const uint8* src_v, int src_stride_v, 442 uint8* dst_y, int dst_stride_y, 443 uint8* dst_vu, int dst_stride_vu, 444 int width, int height) { 445 return I420ToNV12(src_y, src_stride_y, 446 src_v, src_stride_v, 447 src_u, src_stride_u, 448 dst_y, dst_stride_y, 449 dst_vu, dst_stride_vu, 450 width, height); 451 } 452 453 // Convert I422 to RGBA with matrix 454 static int I420ToRGBAMatrix(const uint8* src_y, int src_stride_y, 455 const uint8* src_u, int src_stride_u, 456 const uint8* src_v, int src_stride_v, 457 uint8* dst_rgba, int dst_stride_rgba, 458 const struct YuvConstants* yuvconstants, 459 int width, int height) { 460 int y; 461 void (*I422ToRGBARow)(const uint8* y_buf, 462 const uint8* u_buf, 463 const uint8* v_buf, 464 uint8* rgb_buf, 465 const struct YuvConstants* yuvconstants, 466 int width) = I422ToRGBARow_C; 467 if (!src_y || !src_u || !src_v || !dst_rgba || 468 width <= 0 || height == 0) { 450 void (*I422ToRGBARow)(const uint8* y_buf, const uint8* u_buf, 451 const uint8* v_buf, uint8* rgb_buf, 452 const struct YuvConstants* yuvconstants, int width) = 453 I422ToRGBARow_C; 454 if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0) { 469 455 return -1; 470 456 } … … 508 494 } 509 495 #endif 496 #if defined(HAS_I422TORGBAROW_MSA) 497 if (TestCpuFlag(kCpuHasMSA)) { 498 I422ToRGBARow = I422ToRGBARow_Any_MSA; 499 if (IS_ALIGNED(width, 8)) { 500 I422ToRGBARow = I422ToRGBARow_MSA; 501 } 502 } 503 #endif 510 504 511 505 for (y = 0; y < height; ++y) { … … 523 517 // Convert I420 to RGBA. 524 518 LIBYUV_API 525 int I420ToRGBA(const uint8* src_y, int src_stride_y, 526 const uint8* src_u, int src_stride_u, 527 const uint8* src_v, int src_stride_v, 528 uint8* dst_rgba, int dst_stride_rgba, 529 int width, int height) { 530 return I420ToRGBAMatrix(src_y, src_stride_y, 531 src_u, src_stride_u, 532 src_v, src_stride_v, 533 dst_rgba, dst_stride_rgba, 534 &kYuvI601Constants, 535 width, height); 519 int I420ToRGBA(const uint8* src_y, 520 int src_stride_y, 521 const uint8* src_u, 522 int src_stride_u, 523 const uint8* src_v, 524 int src_stride_v, 525 uint8* dst_rgba, 526 int dst_stride_rgba, 527 int width, 528 int height) { 529 return I420ToRGBAMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, 530 src_stride_v, dst_rgba, dst_stride_rgba, 531 &kYuvI601Constants, width, height); 536 532 } 537 533 538 534 // Convert I420 to BGRA. 539 535 LIBYUV_API 540 int I420ToBGRA(const uint8* src_y, int src_stride_y, 541 const uint8* src_u, int src_stride_u, 542 const uint8* src_v, int src_stride_v, 543 uint8* dst_bgra, int dst_stride_bgra, 544 int width, int height) { 545 return I420ToRGBAMatrix(src_y, src_stride_y, 546 src_v, src_stride_v, // Swap U and V 547 src_u, src_stride_u, 548 dst_bgra, dst_stride_bgra, 536 int I420ToBGRA(const uint8* src_y, 537 int src_stride_y, 538 const uint8* src_u, 539 int src_stride_u, 540 const uint8* src_v, 541 int src_stride_v, 542 uint8* dst_bgra, 543 int dst_stride_bgra, 544 int width, 545 int height) { 546 return I420ToRGBAMatrix(src_y, src_stride_y, src_v, 547 src_stride_v, // Swap U and V 548 src_u, src_stride_u, dst_bgra, dst_stride_bgra, 549 549 &kYvuI601Constants, // Use Yvu matrix 550 550 width, height); … … 552 552 553 553 // Convert I420 to RGB24 with matrix 554 static int I420ToRGB24Matrix(const uint8* src_y, int src_stride_y, 555 const uint8* src_u, int src_stride_u, 556 const uint8* src_v, int src_stride_v, 557 uint8* dst_rgb24, int dst_stride_rgb24, 554 static int I420ToRGB24Matrix(const uint8* src_y, 555 int src_stride_y, 556 const uint8* src_u, 557 int src_stride_u, 558 const uint8* src_v, 559 int src_stride_v, 560 uint8* dst_rgb24, 561 int dst_stride_rgb24, 558 562 const struct YuvConstants* yuvconstants, 559 int width, int height) { 563 int width, 564 int height) { 560 565 int y; 561 void (*I422ToRGB24Row)(const uint8* y_buf, 562 const uint8* u_buf, 563 const uint8* v_buf, 564 uint8* rgb_buf, 565 const struct YuvConstants* yuvconstants, 566 int width) = I422ToRGB24Row_C; 567 if (!src_y || !src_u || !src_v || !dst_rgb24 || 568 width <= 0 || height == 0) { 566 void (*I422ToRGB24Row)(const uint8* y_buf, const uint8* u_buf, 567 const uint8* v_buf, uint8* rgb_buf, 568 const struct YuvConstants* yuvconstants, int width) = 569 I422ToRGB24Row_C; 570 if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0) { 569 571 return -1; 570 572 } … … 596 598 if (IS_ALIGNED(width, 8)) { 597 599 I422ToRGB24Row = I422ToRGB24Row_NEON; 600 } 601 } 602 #endif 603 #if defined(HAS_I422TORGB24ROW_MSA) 604 if (TestCpuFlag(kCpuHasMSA)) { 605 I422ToRGB24Row = I422ToRGB24Row_Any_MSA; 606 if (IS_ALIGNED(width, 16)) { 607 I422ToRGB24Row = I422ToRGB24Row_MSA; 598 608 } 599 609 } … … 614 624 // Convert I420 to RGB24. 615 625 LIBYUV_API 616 int I420ToRGB24(const uint8* src_y, int src_stride_y, 617 const uint8* src_u, int src_stride_u, 618 const uint8* src_v, int src_stride_v, 619 uint8* dst_rgb24, int dst_stride_rgb24, 620 int width, int height) { 621 return I420ToRGB24Matrix(src_y, src_stride_y, 622 src_u, src_stride_u, 623 src_v, src_stride_v, 624 dst_rgb24, dst_stride_rgb24, 625 &kYuvI601Constants, 626 width, height); 626 int I420ToRGB24(const uint8* src_y, 627 int src_stride_y, 628 const uint8* src_u, 629 int src_stride_u, 630 const uint8* src_v, 631 int src_stride_v, 632 uint8* dst_rgb24, 633 int dst_stride_rgb24, 634 int width, 635 int height) { 636 return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, 637 src_stride_v, dst_rgb24, dst_stride_rgb24, 638 &kYuvI601Constants, width, height); 627 639 } 628 640 629 641 // Convert I420 to RAW. 630 642 LIBYUV_API 631 int I420ToRAW(const uint8* src_y, int src_stride_y, 632 const uint8* src_u, int src_stride_u, 633 const uint8* src_v, int src_stride_v, 634 uint8* dst_raw, int dst_stride_raw, 635 int width, int height) { 636 return I420ToRGB24Matrix(src_y, src_stride_y, 637 src_v, src_stride_v, // Swap U and V 638 src_u, src_stride_u, 639 dst_raw, dst_stride_raw, 643 int I420ToRAW(const uint8* src_y, 644 int src_stride_y, 645 const uint8* src_u, 646 int src_stride_u, 647 const uint8* src_v, 648 int src_stride_v, 649 uint8* dst_raw, 650 int dst_stride_raw, 651 int width, 652 int height) { 653 return I420ToRGB24Matrix(src_y, src_stride_y, src_v, 654 src_stride_v, // Swap U and V 655 src_u, src_stride_u, dst_raw, dst_stride_raw, 640 656 &kYvuI601Constants, // Use Yvu matrix 641 657 width, height); … … 644 660 // Convert I420 to ARGB1555. 645 661 LIBYUV_API 646 int I420ToARGB1555(const uint8* src_y, int src_stride_y, 647 const uint8* src_u, int src_stride_u, 648 const uint8* src_v, int src_stride_v, 649 uint8* dst_argb1555, int dst_stride_argb1555, 650 int width, int height) { 662 int I420ToARGB1555(const uint8* src_y, 663 int src_stride_y, 664 const uint8* src_u, 665 int src_stride_u, 666 const uint8* src_v, 667 int src_stride_v, 668 uint8* dst_argb1555, 669 int dst_stride_argb1555, 670 int width, 671 int height) { 651 672 int y; 652 void (*I422ToARGB1555Row)(const uint8* y_buf, 653 const uint8* u_buf, 654 const uint8* v_buf, 655 uint8* rgb_buf, 673 void (*I422ToARGB1555Row)(const uint8* y_buf, const uint8* u_buf, 674 const uint8* v_buf, uint8* rgb_buf, 656 675 const struct YuvConstants* yuvconstants, 657 676 int width) = I422ToARGB1555Row_C; 658 if (!src_y || !src_u || !src_v || !dst_argb1555 || 659 width <= 0 ||height == 0) {677 if (!src_y || !src_u || !src_v || !dst_argb1555 || width <= 0 || 678 height == 0) { 660 679 return -1; 661 680 } … … 687 706 if (IS_ALIGNED(width, 8)) { 688 707 I422ToARGB1555Row = I422ToARGB1555Row_NEON; 708 } 709 } 710 #endif 711 #if defined(HAS_I422TOARGB1555ROW_DSPR2) 712 if (TestCpuFlag(kCpuHasDSPR2)) { 713 I422ToARGB1555Row = I422ToARGB1555Row_Any_DSPR2; 714 if (IS_ALIGNED(width, 4)) { 715 I422ToARGB1555Row = I422ToARGB1555Row_DSPR2; 716 } 717 } 718 #endif 719 #if defined(HAS_I422TOARGB1555ROW_MSA) 720 if (TestCpuFlag(kCpuHasMSA)) { 721 I422ToARGB1555Row = I422ToARGB1555Row_Any_MSA; 722 if (IS_ALIGNED(width, 8)) { 723 I422ToARGB1555Row = I422ToARGB1555Row_MSA; 689 724 } 690 725 } … … 704 739 } 705 740 706 707 741 // Convert I420 to ARGB4444. 708 742 LIBYUV_API 709 int I420ToARGB4444(const uint8* src_y, int src_stride_y, 710 const uint8* src_u, int src_stride_u, 711 const uint8* src_v, int src_stride_v, 712 uint8* dst_argb4444, int dst_stride_argb4444, 713 int width, int height) { 743 int I420ToARGB4444(const uint8* src_y, 744 int src_stride_y, 745 const uint8* src_u, 746 int src_stride_u, 747 const uint8* src_v, 748 int src_stride_v, 749 uint8* dst_argb4444, 750 int dst_stride_argb4444, 751 int width, 752 int height) { 714 753 int y; 715 void (*I422ToARGB4444Row)(const uint8* y_buf, 716 const uint8* u_buf, 717 const uint8* v_buf, 718 uint8* rgb_buf, 754 void (*I422ToARGB4444Row)(const uint8* y_buf, const uint8* u_buf, 755 const uint8* v_buf, uint8* rgb_buf, 719 756 const struct YuvConstants* yuvconstants, 720 757 int width) = I422ToARGB4444Row_C; 721 if (!src_y || !src_u || !src_v || !dst_argb4444 || 722 width <= 0 ||height == 0) {758 if (!src_y || !src_u || !src_v || !dst_argb4444 || width <= 0 || 759 height == 0) { 723 760 return -1; 724 761 } … … 750 787 if (IS_ALIGNED(width, 8)) { 751 788 I422ToARGB4444Row = I422ToARGB4444Row_NEON; 789 } 790 } 791 #endif 792 #if defined(HAS_I422TOARGB4444ROW_DSPR2) 793 if (TestCpuFlag(kCpuHasDSPR2)) { 794 I422ToARGB4444Row = I422ToARGB4444Row_Any_DSPR2; 795 if (IS_ALIGNED(width, 4)) { 796 I422ToARGB4444Row = I422ToARGB4444Row_DSPR2; 797 } 798 } 799 #endif 800 #if defined(HAS_I422TOARGB4444ROW_MSA) 801 if (TestCpuFlag(kCpuHasMSA)) { 802 I422ToARGB4444Row = I422ToARGB4444Row_Any_MSA; 803 if (IS_ALIGNED(width, 8)) { 804 I422ToARGB4444Row = I422ToARGB4444Row_MSA; 752 805 } 753 806 } … … 769 822 // Convert I420 to RGB565. 770 823 LIBYUV_API 771 int I420ToRGB565(const uint8* src_y, int src_stride_y, 772 const uint8* src_u, int src_stride_u, 773 const uint8* src_v, int src_stride_v, 774 uint8* dst_rgb565, int dst_stride_rgb565, 775 int width, int height) { 824 int I420ToRGB565(const uint8* src_y, 825 int src_stride_y, 826 const uint8* src_u, 827 int src_stride_u, 828 const uint8* src_v, 829 int src_stride_v, 830 uint8* dst_rgb565, 831 int dst_stride_rgb565, 832 int width, 833 int height) { 776 834 int y; 777 void (*I422ToRGB565Row)(const uint8* y_buf, 778 const uint8* u_buf, 779 const uint8* v_buf, 780 uint8* rgb_buf, 781 const struct YuvConstants* yuvconstants, 782 int width) = I422ToRGB565Row_C; 783 if (!src_y || !src_u || !src_v || !dst_rgb565 || 784 width <= 0 || height == 0) { 835 void (*I422ToRGB565Row)(const uint8* y_buf, const uint8* u_buf, 836 const uint8* v_buf, uint8* rgb_buf, 837 const struct YuvConstants* yuvconstants, int width) = 838 I422ToRGB565Row_C; 839 if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) { 785 840 return -1; 786 841 } … … 812 867 if (IS_ALIGNED(width, 8)) { 813 868 I422ToRGB565Row = I422ToRGB565Row_NEON; 869 } 870 } 871 #endif 872 #if defined(HAS_I422TORGB565ROW_MSA) 873 if (TestCpuFlag(kCpuHasMSA)) { 874 I422ToRGB565Row = I422ToRGB565Row_Any_MSA; 875 if (IS_ALIGNED(width, 8)) { 876 I422ToRGB565Row = I422ToRGB565Row_MSA; 814 877 } 815 878 } … … 828 891 } 829 892 893 // Convert I422 to RGB565. 894 LIBYUV_API 895 int I422ToRGB565(const uint8* src_y, 896 int src_stride_y, 897 const uint8* src_u, 898 int src_stride_u, 899 const uint8* src_v, 900 int src_stride_v, 901 uint8* dst_rgb565, 902 int dst_stride_rgb565, 903 int width, 904 int height) { 905 int y; 906 void (*I422ToRGB565Row)(const uint8* y_buf, const uint8* u_buf, 907 const uint8* v_buf, uint8* rgb_buf, 908 const struct YuvConstants* yuvconstants, int width) = 909 I422ToRGB565Row_C; 910 if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) { 911 return -1; 912 } 913 // Negative height means invert the image. 914 if (height < 0) { 915 height = -height; 916 dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565; 917 dst_stride_rgb565 = -dst_stride_rgb565; 918 } 919 #if defined(HAS_I422TORGB565ROW_SSSE3) 920 if (TestCpuFlag(kCpuHasSSSE3)) { 921 I422ToRGB565Row = I422ToRGB565Row_Any_SSSE3; 922 if (IS_ALIGNED(width, 8)) { 923 I422ToRGB565Row = I422ToRGB565Row_SSSE3; 924 } 925 } 926 #endif 927 #if defined(HAS_I422TORGB565ROW_AVX2) 928 if (TestCpuFlag(kCpuHasAVX2)) { 929 I422ToRGB565Row = I422ToRGB565Row_Any_AVX2; 930 if (IS_ALIGNED(width, 16)) { 931 I422ToRGB565Row = I422ToRGB565Row_AVX2; 932 } 933 } 934 #endif 935 #if defined(HAS_I422TORGB565ROW_NEON) 936 if (TestCpuFlag(kCpuHasNEON)) { 937 I422ToRGB565Row = I422ToRGB565Row_Any_NEON; 938 if (IS_ALIGNED(width, 8)) { 939 I422ToRGB565Row = I422ToRGB565Row_NEON; 940 } 941 } 942 #endif 943 #if defined(HAS_I422TORGB565ROW_MSA) 944 if (TestCpuFlag(kCpuHasMSA)) { 945 I422ToRGB565Row = I422ToRGB565Row_Any_MSA; 946 if (IS_ALIGNED(width, 8)) { 947 I422ToRGB565Row = I422ToRGB565Row_MSA; 948 } 949 } 950 #endif 951 952 for (y = 0; y < height; ++y) { 953 I422ToRGB565Row(src_y, src_u, src_v, dst_rgb565, &kYuvI601Constants, width); 954 dst_rgb565 += dst_stride_rgb565; 955 src_y += src_stride_y; 956 src_u += src_stride_u; 957 src_v += src_stride_v; 958 } 959 return 0; 960 } 961 830 962 // Ordered 8x8 dither for 888 to 565. Values from 0 to 7. 831 963 static const uint8 kDither565_4x4[16] = { 832 0, 4, 1, 5, 833 6, 2, 7, 3, 834 1, 5, 0, 4, 835 7, 3, 6, 2, 964 0, 4, 1, 5, 6, 2, 7, 3, 1, 5, 0, 4, 7, 3, 6, 2, 836 965 }; 837 966 838 967 // Convert I420 to RGB565 with dithering. 839 968 LIBYUV_API 840 int I420ToRGB565Dither(const uint8* src_y, int src_stride_y, 841 const uint8* src_u, int src_stride_u, 842 const uint8* src_v, int src_stride_v, 843 uint8* dst_rgb565, int dst_stride_rgb565, 844 const uint8* dither4x4, int width, int height) { 969 int I420ToRGB565Dither(const uint8* src_y, 970 int src_stride_y, 971 const uint8* src_u, 972 int src_stride_u, 973 const uint8* src_v, 974 int src_stride_v, 975 uint8* dst_rgb565, 976 int dst_stride_rgb565, 977 const uint8* dither4x4, 978 int width, 979 int height) { 845 980 int y; 846 void (*I422ToARGBRow)(const uint8* y_buf, 847 const uint8* u_buf, 848 const uint8* v_buf, 849 uint8* rgb_buf, 850 const struct YuvConstants* yuvconstants, 851 int width) = I422ToARGBRow_C; 981 void (*I422ToARGBRow)(const uint8* y_buf, const uint8* u_buf, 982 const uint8* v_buf, uint8* rgb_buf, 983 const struct YuvConstants* yuvconstants, int width) = 984 I422ToARGBRow_C; 852 985 void (*ARGBToRGB565DitherRow)(const uint8* src_argb, uint8* dst_rgb, 853 const uint32 dither4, int width) = ARGBToRGB565DitherRow_C;854 if (!src_y || !src_u || !src_v || !dst_rgb565 ||855 986 const uint32 dither4, int width) = 987 ARGBToRGB565DitherRow_C; 988 if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) { 856 989 return -1; 857 990 } … … 897 1030 } 898 1031 #endif 1032 #if defined(HAS_I422TOARGBROW_MSA) 1033 if (TestCpuFlag(kCpuHasMSA)) { 1034 I422ToARGBRow = I422ToARGBRow_Any_MSA; 1035 if (IS_ALIGNED(width, 8)) { 1036 I422ToARGBRow = I422ToARGBRow_MSA; 1037 } 1038 } 1039 #endif 899 1040 #if defined(HAS_ARGBTORGB565DITHERROW_SSE2) 900 1041 if (TestCpuFlag(kCpuHasSSE2)) { … … 918 1059 if (IS_ALIGNED(width, 8)) { 919 1060 ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_NEON; 1061 } 1062 } 1063 #endif 1064 #if defined(HAS_ARGBTORGB565DITHERROW_MSA) 1065 if (TestCpuFlag(kCpuHasMSA)) { 1066 ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_MSA; 1067 if (IS_ALIGNED(width, 8)) { 1068 ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_MSA; 920 1069 } 921 1070 } … … 927 1076 I422ToARGBRow(src_y, src_u, src_v, row_argb, &kYuvI601Constants, width); 928 1077 ARGBToRGB565DitherRow(row_argb, dst_rgb565, 929 *(uint32*)(dither4x4 + ((y & 3) << 2)), width); 1078 *(uint32*)(dither4x4 + ((y & 3) << 2)), 1079 width); // NOLINT 930 1080 dst_rgb565 += dst_stride_rgb565; 931 1081 src_y += src_stride_y; … … 942 1092 // Convert I420 to specified format 943 1093 LIBYUV_API 944 int ConvertFromI420(const uint8* y, int y_stride, 945 const uint8* u, int u_stride, 946 const uint8* v, int v_stride, 947 uint8* dst_sample, int dst_sample_stride, 948 int width, int height, 1094 int ConvertFromI420(const uint8* y, 1095 int y_stride, 1096 const uint8* u, 1097 int u_stride, 1098 const uint8* v, 1099 int v_stride, 1100 uint8* dst_sample, 1101 int dst_sample_stride, 1102 int width, 1103 int height, 949 1104 uint32 fourcc) { 950 1105 uint32 format = CanonicalFourCC(fourcc); 951 1106 int r = 0; 952 if (!y || !u|| !v || !dst_sample || 953 width <= 0 || height == 0) { 1107 if (!y || !u || !v || !dst_sample || width <= 0 || height == 0) { 954 1108 return -1; 955 1109 } … … 957 1111 // Single plane formats 958 1112 case FOURCC_YUY2: 959 r = I420ToYUY2(y, y_stride, 960 u, u_stride, 961 v, v_stride, 962 dst_sample, 963 dst_sample_stride ? dst_sample_stride : width * 2, 964 width, height); 1113 r = I420ToYUY2(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1114 dst_sample_stride ? dst_sample_stride : width * 2, width, 1115 height); 965 1116 break; 966 1117 case FOURCC_UYVY: 967 r = I420ToUYVY(y, y_stride, 968 u, u_stride, 969 v, v_stride, 970 dst_sample, 971 dst_sample_stride ? dst_sample_stride : width * 2, 972 width, height); 1118 r = I420ToUYVY(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1119 dst_sample_stride ? dst_sample_stride : width * 2, width, 1120 height); 973 1121 break; 974 1122 case FOURCC_RGBP: 975 r = I420ToRGB565(y, y_stride, 976 u, u_stride, 977 v, v_stride, 978 dst_sample, 979 dst_sample_stride ? dst_sample_stride : width * 2, 980 width, height); 1123 r = I420ToRGB565(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1124 dst_sample_stride ? dst_sample_stride : width * 2, width, 1125 height); 981 1126 break; 982 1127 case FOURCC_RGBO: 983 r = I420ToARGB1555(y, y_stride, 984 u, u_stride, 985 v, v_stride, 986 dst_sample, 1128 r = I420ToARGB1555(y, y_stride, u, u_stride, v, v_stride, dst_sample, 987 1129 dst_sample_stride ? dst_sample_stride : width * 2, 988 1130 width, height); 989 1131 break; 990 1132 case FOURCC_R444: 991 r = I420ToARGB4444(y, y_stride, 992 u, u_stride, 993 v, v_stride, 994 dst_sample, 1133 r = I420ToARGB4444(y, y_stride, u, u_stride, v, v_stride, dst_sample, 995 1134 dst_sample_stride ? dst_sample_stride : width * 2, 996 1135 width, height); 997 1136 break; 998 1137 case FOURCC_24BG: 999 r = I420ToRGB24(y, y_stride, 1000 u, u_stride, 1001 v, v_stride, 1002 dst_sample, 1003 dst_sample_stride ? dst_sample_stride : width * 3, 1004 width, height); 1138 r = I420ToRGB24(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1139 dst_sample_stride ? dst_sample_stride : width * 3, width, 1140 height); 1005 1141 break; 1006 1142 case FOURCC_RAW: 1007 r = I420ToRAW(y, y_stride, 1008 u, u_stride, 1009 v, v_stride, 1010 dst_sample, 1011 dst_sample_stride ? dst_sample_stride : width * 3, 1012 width, height); 1143 r = I420ToRAW(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1144 dst_sample_stride ? dst_sample_stride : width * 3, width, 1145 height); 1013 1146 break; 1014 1147 case FOURCC_ARGB: 1015 r = I420ToARGB(y, y_stride, 1016 u, u_stride, 1017 v, v_stride, 1018 dst_sample, 1019 dst_sample_stride ? dst_sample_stride : width * 4, 1020 width, height); 1148 r = I420ToARGB(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1149 dst_sample_stride ? dst_sample_stride : width * 4, width, 1150 height); 1021 1151 break; 1022 1152 case FOURCC_BGRA: 1023 r = I420ToBGRA(y, y_stride, 1024 u, u_stride, 1025 v, v_stride, 1026 dst_sample, 1027 dst_sample_stride ? dst_sample_stride : width * 4, 1028 width, height); 1153 r = I420ToBGRA(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1154 dst_sample_stride ? dst_sample_stride : width * 4, width, 1155 height); 1029 1156 break; 1030 1157 case FOURCC_ABGR: 1031 r = I420ToABGR(y, y_stride, 1032 u, u_stride, 1033 v, v_stride, 1034 dst_sample, 1035 dst_sample_stride ? dst_sample_stride : width * 4, 1036 width, height); 1158 r = I420ToABGR(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1159 dst_sample_stride ? dst_sample_stride : width * 4, width, 1160 height); 1037 1161 break; 1038 1162 case FOURCC_RGBA: 1039 r = I420ToRGBA(y, y_stride, 1040 u, u_stride, 1041 v, v_stride, 1042 dst_sample, 1043 dst_sample_stride ? dst_sample_stride : width * 4, 1044 width, height); 1163 r = I420ToRGBA(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1164 dst_sample_stride ? dst_sample_stride : width * 4, width, 1165 height); 1045 1166 break; 1046 1167 case FOURCC_I400: 1047 r = I400Copy(y, y_stride, 1048 dst_sample, 1049 dst_sample_stride ? dst_sample_stride : width, 1050 width, height); 1168 r = I400Copy(y, y_stride, dst_sample, 1169 dst_sample_stride ? dst_sample_stride : width, width, 1170 height); 1051 1171 break; 1052 1172 case FOURCC_NV12: { 1053 1173 uint8* dst_uv = dst_sample + width * height; 1054 r = I420ToNV12(y, y_stride, 1055 u, u_stride, 1056 v, v_stride, 1057 dst_sample, 1058 dst_sample_stride ? dst_sample_stride : width, 1059 dst_uv, 1060 dst_sample_stride ? dst_sample_stride : width, 1061 width, height); 1174 r = I420ToNV12(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1175 dst_sample_stride ? dst_sample_stride : width, dst_uv, 1176 dst_sample_stride ? dst_sample_stride : width, width, 1177 height); 1062 1178 break; 1063 1179 } 1064 1180 case FOURCC_NV21: { 1065 1181 uint8* dst_vu = dst_sample + width * height; 1066 r = I420ToNV21(y, y_stride, 1067 u, u_stride, 1068 v, v_stride, 1069 dst_sample, 1070 dst_sample_stride ? dst_sample_stride : width, 1071 dst_vu, 1072 dst_sample_stride ? dst_sample_stride : width, 1073 width, height); 1182 r = I420ToNV21(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1183 dst_sample_stride ? dst_sample_stride : width, dst_vu, 1184 dst_sample_stride ? dst_sample_stride : width, width, 1185 height); 1074 1186 break; 1075 1187 } 1076 1188 // TODO(fbarchard): Add M420. 1077 1189 // Triplanar formats 1078 // TODO(fbarchard): halfstride instead of halfwidth1079 1190 case FOURCC_I420: 1080 1191 case FOURCC_YV12: { 1081 int halfwidth = (width + 1) / 2; 1192 dst_sample_stride = dst_sample_stride ? dst_sample_stride : width; 1193 int halfstride = (dst_sample_stride + 1) / 2; 1082 1194 int halfheight = (height + 1) / 2; 1083 1195 uint8* dst_u; 1084 1196 uint8* dst_v; 1085 1197 if (format == FOURCC_YV12) { 1086 dst_v = dst_sample + width* height;1087 dst_u = dst_v + half width* halfheight;1198 dst_v = dst_sample + dst_sample_stride * height; 1199 dst_u = dst_v + halfstride * halfheight; 1088 1200 } else { 1089 dst_u = dst_sample + width* height;1090 dst_v = dst_u + half width* halfheight;1201 dst_u = dst_sample + dst_sample_stride * height; 1202 dst_v = dst_u + halfstride * halfheight; 1091 1203 } 1092 r = I420Copy(y, y_stride, 1093 u, u_stride, 1094 v, v_stride, 1095 dst_sample, width, 1096 dst_u, halfwidth, 1097 dst_v, halfwidth, 1204 r = I420Copy(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1205 dst_sample_stride, dst_u, halfstride, dst_v, halfstride, 1098 1206 width, height); 1099 1207 break; … … 1101 1209 case FOURCC_I422: 1102 1210 case FOURCC_YV16: { 1103 int halfwidth = (width + 1) / 2; 1211 dst_sample_stride = dst_sample_stride ? dst_sample_stride : width; 1212 int halfstride = (dst_sample_stride + 1) / 2; 1104 1213 uint8* dst_u; 1105 1214 uint8* dst_v; 1106 1215 if (format == FOURCC_YV16) { 1107 dst_v = dst_sample + width* height;1108 dst_u = dst_v + half width* height;1216 dst_v = dst_sample + dst_sample_stride * height; 1217 dst_u = dst_v + halfstride * height; 1109 1218 } else { 1110 dst_u = dst_sample + width* height;1111 dst_v = dst_u + half width* height;1219 dst_u = dst_sample + dst_sample_stride * height; 1220 dst_v = dst_u + halfstride * height; 1112 1221 } 1113 r = I420ToI422(y, y_stride, 1114 u, u_stride, 1115 v, v_stride, 1116 dst_sample, width, 1117 dst_u, halfwidth, 1118 dst_v, halfwidth, 1222 r = I420ToI422(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1223 dst_sample_stride, dst_u, halfstride, dst_v, halfstride, 1119 1224 width, height); 1120 1225 break; … … 1122 1227 case FOURCC_I444: 1123 1228 case FOURCC_YV24: { 1229 dst_sample_stride = dst_sample_stride ? dst_sample_stride : width; 1124 1230 uint8* dst_u; 1125 1231 uint8* dst_v; 1126 1232 if (format == FOURCC_YV24) { 1127 dst_v = dst_sample + width* height;1128 dst_u = dst_v + width* height;1233 dst_v = dst_sample + dst_sample_stride * height; 1234 dst_u = dst_v + dst_sample_stride * height; 1129 1235 } else { 1130 dst_u = dst_sample + width* height;1131 dst_v = dst_u + width* height;1236 dst_u = dst_sample + dst_sample_stride * height; 1237 dst_v = dst_u + dst_sample_stride * height; 1132 1238 } 1133 r = I420ToI444(y, y_stride, 1134 u, u_stride, 1135 v, v_stride, 1136 dst_sample, width, 1137 dst_u, width, 1138 dst_v, width, 1139 width, height); 1140 break; 1141 } 1142 case FOURCC_I411: { 1143 int quarterwidth = (width + 3) / 4; 1144 uint8* dst_u = dst_sample + width * height; 1145 uint8* dst_v = dst_u + quarterwidth * height; 1146 r = I420ToI411(y, y_stride, 1147 u, u_stride, 1148 v, v_stride, 1149 dst_sample, width, 1150 dst_u, quarterwidth, 1151 dst_v, quarterwidth, 1152 width, height); 1153 break; 1154 } 1155 1239 r = I420ToI444(y, y_stride, u, u_stride, v, v_stride, dst_sample, 1240 dst_sample_stride, dst_u, dst_sample_stride, dst_v, 1241 dst_sample_stride, width, height); 1242 break; 1243 } 1156 1244 // Formats not supported - MJPG, biplanar, some rgb formats. 1157 1245 default:
Note: See TracChangeset
for help on using the changeset viewer.