CVPixelFormat+Extensions.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /******************************************************************************
  2. Copyright (C) 2024 by Patrick Heyer <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. import CoreVideo
  15. import Metal
  16. extension OSType {
  17. /// Conversion of CoreVideo pixel formats into corresponding Metal pixel formats
  18. var mtlFormat: MTLPixelFormat? {
  19. switch self {
  20. case kCVPixelFormatType_OneComponent8:
  21. return .r8Unorm
  22. case kCVPixelFormatType_OneComponent16Half:
  23. return .r16Float
  24. case kCVPixelFormatType_OneComponent32Float:
  25. return .r32Float
  26. case kCVPixelFormatType_TwoComponent8:
  27. return .rg8Unorm
  28. case kCVPixelFormatType_TwoComponent16Half:
  29. return .rg16Float
  30. case kCVPixelFormatType_TwoComponent32Float:
  31. return .rg32Float
  32. case kCVPixelFormatType_32BGRA:
  33. return .bgra8Unorm
  34. case kCVPixelFormatType_32RGBA:
  35. return .rgba8Unorm
  36. case kCVPixelFormatType_64RGBAHalf:
  37. return .rgba16Float
  38. case kCVPixelFormatType_128RGBAFloat:
  39. return .rgba32Float
  40. case kCVPixelFormatType_ARGB2101010LEPacked:
  41. return .bgr10a2Unorm
  42. default:
  43. return nil
  44. }
  45. }
  46. }