|
31 | 31 | #include <cmath> |
32 | 32 | #if TARGET_RT_BIG_ENDIAN |
33 | 33 | #define FourCC2Str(fourcc) \ |
34 | | - (const char[]) { \ |
35 | | - *((char *)&fourcc), *(((char *)&fourcc) + 1), *(((char *)&fourcc) + 2), \ |
36 | | - *(((char *)&fourcc) + 3), 0 \ |
37 | | - } |
| 34 | + (const char[]){*((char *)&fourcc), *(((char *)&fourcc) + 1), \ |
| 35 | + *(((char *)&fourcc) + 2), *(((char *)&fourcc) + 3), 0} |
38 | 36 | #else |
39 | 37 | #define FourCC2Str(fourcc) \ |
40 | | - (const char[]) { \ |
41 | | - *(((char *)&fourcc) + 3), *(((char *)&fourcc) + 2), \ |
42 | | - *(((char *)&fourcc) + 1), *(((char *)&fourcc) + 0), 0 \ |
43 | | - } |
| 38 | + (const char[]){*(((char *)&fourcc) + 3), *(((char *)&fourcc) + 2), \ |
| 39 | + *(((char *)&fourcc) + 1), *(((char *)&fourcc) + 0), 0} |
44 | 40 | #endif |
45 | 41 |
|
46 | 42 | // pragma MARK: TextureHolder |
|
270 | 266 |
|
271 | 267 | // pragma MARK: YUV getColorspace() |
272 | 268 |
|
273 | | -SkYUVColorSpace SkiaCVPixelBufferUtils::YUV::getColorspace( |
274 | | - CVPixelBufferRef pixelBuffer) { |
| 269 | +SkYUVColorSpace |
| 270 | +SkiaCVPixelBufferUtils::YUV::getColorspace(CVPixelBufferRef pixelBuffer) { |
275 | 271 | const OSType pixelFormat = CVPixelBufferGetPixelFormatType(pixelBuffer); |
276 | 272 |
|
277 | | - CFTypeRef matrixAttachment = |
278 | | - CVBufferCopyAttachment(pixelBuffer, kCVImageBufferYCbCrMatrixKey, nullptr); |
| 273 | + CFTypeRef matrixAttachment = CVBufferCopyAttachment( |
| 274 | + pixelBuffer, kCVImageBufferYCbCrMatrixKey, nullptr); |
279 | 275 | CFStringRef matrix = nullptr; |
280 | 276 | if (matrixAttachment != nullptr && |
281 | 277 | CFGetTypeID(matrixAttachment) == CFStringGetTypeID()) { |
282 | 278 | matrix = reinterpret_cast<CFStringRef>(matrixAttachment); |
283 | 279 | } |
284 | 280 |
|
285 | | - SkYUVColorSpace colorspace = getSkYUVColorSpaceFromMatrix(matrix, pixelFormat); |
| 281 | + SkYUVColorSpace colorspace = |
| 282 | + getSkYUVColorSpaceFromMatrix(matrix, pixelFormat); |
286 | 283 | if (matrixAttachment != nullptr) { |
287 | 284 | CFRelease(matrixAttachment); |
288 | 285 | } |
|
320 | 317 | } |
321 | 318 | } |
322 | 319 |
|
323 | | -SkYUVColorSpace SkiaCVPixelBufferUtils::YUV::getSkYUVColorSpaceFromMatrix( |
324 | | - CFStringRef matrix, OSType pixelFormat) { |
| 320 | +SkYUVColorSpace |
| 321 | +SkiaCVPixelBufferUtils::YUV::getSkYUVColorSpaceFromMatrix(CFStringRef matrix, |
| 322 | + OSType pixelFormat) { |
325 | 323 | const bool isFullRange = isFullRangeYUVFormat(pixelFormat); |
326 | 324 | const bool isTenBit = isTenBitYUVFormat(pixelFormat); |
327 | 325 |
|
|
381 | 379 | "Requested out-of-bounds plane index " + std::to_string(planeIndex) + |
382 | 380 | " for pixel buffer with " + std::to_string(planesCount) + " planes."); |
383 | 381 | } |
384 | | - size_t width = planesCount > 0 ? CVPixelBufferGetWidthOfPlane(pixelBuffer, planeIndex) |
385 | | - : CVPixelBufferGetWidth(pixelBuffer); |
386 | | - size_t height = |
387 | | - planesCount > 0 ? CVPixelBufferGetHeightOfPlane(pixelBuffer, planeIndex) |
| 382 | + size_t width = planesCount > 0 |
| 383 | + ? CVPixelBufferGetWidthOfPlane(pixelBuffer, planeIndex) |
| 384 | + : CVPixelBufferGetWidth(pixelBuffer); |
| 385 | + size_t height = planesCount > 0 |
| 386 | + ? CVPixelBufferGetHeightOfPlane(pixelBuffer, planeIndex) |
388 | 387 | : CVPixelBufferGetHeight(pixelBuffer); |
389 | 388 | MTLPixelFormat pixelFormat = |
390 | 389 | getMTLPixelFormatForCVPixelBufferPlane(pixelBuffer, planeIndex); |
|
424 | 423 | MTLPixelFormat SkiaCVPixelBufferUtils::getMTLPixelFormatForCVPixelBufferPlane( |
425 | 424 | CVPixelBufferRef pixelBuffer, size_t planeIndex) { |
426 | 425 | const OSType format = CVPixelBufferGetPixelFormatType(pixelBuffer); |
427 | | - auto throwInvalidPlaneIndexForFormat = [&](size_t expectedPlanes) |
428 | | - -> MTLPixelFormat { |
| 426 | + auto throwInvalidPlaneIndexForFormat = |
| 427 | + [&](size_t expectedPlanes) -> MTLPixelFormat { |
429 | 428 | throw std::runtime_error( |
430 | 429 | "Invalid plane index " + std::to_string(planeIndex) + |
431 | | - " for pixel format " + std::string(FourCC2Str(format)) + " (expected 0.." + |
432 | | - std::to_string(expectedPlanes - 1) + ")."); |
| 430 | + " for pixel format " + std::string(FourCC2Str(format)) + |
| 431 | + " (expected 0.." + std::to_string(expectedPlanes - 1) + ")."); |
433 | 432 | }; |
434 | 433 |
|
435 | 434 | switch (format) { |
|
495 | 494 | planesCount > 0 ? CVPixelBufferGetWidthOfPlane(pixelBuffer, planeIndex) |
496 | 495 | : CVPixelBufferGetWidth(pixelBuffer); |
497 | 496 | const size_t bytesPerRow = |
498 | | - planesCount > 0 ? CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, planeIndex) |
499 | | - : CVPixelBufferGetBytesPerRow(pixelBuffer); |
| 497 | + planesCount > 0 |
| 498 | + ? CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, planeIndex) |
| 499 | + : CVPixelBufferGetBytesPerRow(pixelBuffer); |
500 | 500 | if (width == 0) [[unlikely]] { |
501 | 501 | throw std::runtime_error("Invalid plane width for pixel format " + |
502 | 502 | std::string(FourCC2Str(format)) + "!"); |
503 | 503 | } |
504 | 504 | if (bytesPerRow % width != 0) [[unlikely]] { |
505 | | - throw std::runtime_error( |
506 | | - "Invalid bytes per row! Bytes per row must be evenly divisible by width " |
507 | | - "for pixel format " + |
508 | | - std::string(FourCC2Str(format)) + "!"); |
| 505 | + throw std::runtime_error("Invalid bytes per row! Bytes per row must be " |
| 506 | + "evenly divisible by width " |
| 507 | + "for pixel format " + |
| 508 | + std::string(FourCC2Str(format)) + "!"); |
509 | 509 | } |
510 | 510 | const size_t bytesPerPixel = bytesPerRow / width; |
511 | 511 | if (bytesPerPixel == 1) { |
|
519 | 519 | } |
520 | 520 |
|
521 | 521 | [[unlikely]] throw std::runtime_error( |
522 | | - "Invalid bytes per row! Expected 1 (R), 2 (RG) or 4 (RGBA), but received " + |
| 522 | + "Invalid bytes per row! Expected 1 (R), 2 (RG) or 4 (RGBA), but " |
| 523 | + "received " + |
523 | 524 | std::to_string(bytesPerPixel)); |
524 | 525 | } |
0 commit comments