Skip to content

Instantly share code, notes, and snippets.

@nh7a
Created January 31, 2019 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nh7a/53ff440dfe3d226483f943f1443a9fb7 to your computer and use it in GitHub Desktop.
Save nh7a/53ff440dfe3d226483f943f1443a9fb7 to your computer and use it in GitHub Desktop.
import CoreVideo
enum CVPixelFormatType: RawRepresentable, CaseIterable {
typealias RawValue = OSType
case _1Monochrome
case _2Indexed
case _4Indexed
case _8Indexed
case _1IndexedGray_WhiteIsZero
case _2IndexedGray_WhiteIsZero
case _4IndexedGray_WhiteIsZero
case _8IndexedGray_WhiteIsZero
case _16BE555
case _16LE555
case _16LE5551
case _16BE565
case _16LE565
case _24RGB
case _24BGR
case _32ARGB
case _32BGRA
case _32ABGR
case _32RGBA
case _64ARGB
case _48RGB
case _32AlphaGray
case _16Gray
case _30RGB
case _422YpCbCr8
case _4444YpCbCrA8
case _4444YpCbCrA8R
case _4444AYpCbCr8
case _4444AYpCbCr16
case _444YpCbCr8
case _422YpCbCr16
case _422YpCbCr10
case _444YpCbCr10
case _420YpCbCr8Planar
case _420YpCbCr8PlanarFullRange
case _422YpCbCr_4A_8BiPlanar
case _420YpCbCr8BiPlanarVideoRange
case _420YpCbCr8BiPlanarFullRange
case _422YpCbCr8_yuvs
case _422YpCbCr8FullRange
case _OneComponent8
case _TwoComponent8
case _30RGBLEPackedWideGamut
case _ARGB2101010LEPacked
case _OneComponent16Half
case _OneComponent32Float
case _TwoComponent16Half
case _TwoComponent32Float
case _64RGBAHalf
case _128RGBAFloat
case _14Bayer_GRBG
case _14Bayer_RGGB
case _14Bayer_BGGR
case _14Bayer_GBRG
case _DisparityFloat16
case _DisparityFloat32
case _DepthFloat16
case _DepthFloat32
case _420YpCbCr10BiPlanarVideoRange
case _422YpCbCr10BiPlanarVideoRange
case _444YpCbCr10BiPlanarVideoRange
case _420YpCbCr10BiPlanarFullRange
case _422YpCbCr10BiPlanarFullRange
case _444YpCbCr10BiPlanarFullRange
init?(rawValue: RawValue) {
switch rawValue {
case kCVPixelFormatType_1Monochrome: self = ._1Monochrome
case kCVPixelFormatType_2Indexed: self = ._2Indexed
case kCVPixelFormatType_4Indexed: self = ._4Indexed
case kCVPixelFormatType_8Indexed: self = ._8Indexed
case kCVPixelFormatType_1IndexedGray_WhiteIsZero: self = ._1IndexedGray_WhiteIsZero
case kCVPixelFormatType_2IndexedGray_WhiteIsZero: self = ._2IndexedGray_WhiteIsZero
case kCVPixelFormatType_4IndexedGray_WhiteIsZero: self = ._4IndexedGray_WhiteIsZero
case kCVPixelFormatType_8IndexedGray_WhiteIsZero: self = ._8IndexedGray_WhiteIsZero
case kCVPixelFormatType_16BE555: self = ._16BE555
case kCVPixelFormatType_16LE555: self = ._16LE555
case kCVPixelFormatType_16LE5551: self = ._16LE5551
case kCVPixelFormatType_16BE565: self = ._16BE565
case kCVPixelFormatType_16LE565: self = ._16LE565
case kCVPixelFormatType_24RGB: self = ._24RGB
case kCVPixelFormatType_24BGR: self = ._24BGR
case kCVPixelFormatType_32ARGB: self = ._32ARGB
case kCVPixelFormatType_32BGRA: self = ._32BGRA
case kCVPixelFormatType_32ABGR: self = ._32ABGR
case kCVPixelFormatType_32RGBA: self = ._32RGBA
case kCVPixelFormatType_64ARGB: self = ._64ARGB
case kCVPixelFormatType_48RGB: self = ._48RGB
case kCVPixelFormatType_32AlphaGray: self = ._32AlphaGray
case kCVPixelFormatType_16Gray: self = ._16Gray
case kCVPixelFormatType_30RGB: self = ._30RGB
case kCVPixelFormatType_422YpCbCr8: self = ._422YpCbCr8
case kCVPixelFormatType_4444YpCbCrA8: self = ._4444YpCbCrA8
case kCVPixelFormatType_4444YpCbCrA8R: self = ._4444YpCbCrA8R
case kCVPixelFormatType_4444AYpCbCr8: self = ._4444AYpCbCr8
case kCVPixelFormatType_4444AYpCbCr16: self = ._4444AYpCbCr16
case kCVPixelFormatType_444YpCbCr8: self = ._444YpCbCr8
case kCVPixelFormatType_422YpCbCr16: self = ._422YpCbCr16
case kCVPixelFormatType_422YpCbCr10: self = ._422YpCbCr10
case kCVPixelFormatType_444YpCbCr10: self = ._444YpCbCr10
case kCVPixelFormatType_420YpCbCr8Planar: self = ._420YpCbCr8Planar
case kCVPixelFormatType_420YpCbCr8PlanarFullRange: self = ._420YpCbCr8PlanarFullRange
case kCVPixelFormatType_422YpCbCr_4A_8BiPlanar: self = ._422YpCbCr_4A_8BiPlanar
case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange: self = ._420YpCbCr8BiPlanarVideoRange
case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange: self = ._420YpCbCr8BiPlanarFullRange
case kCVPixelFormatType_422YpCbCr8_yuvs: self = ._422YpCbCr8_yuvs
case kCVPixelFormatType_422YpCbCr8FullRange: self = ._422YpCbCr8FullRange
case kCVPixelFormatType_OneComponent8: self = ._OneComponent8
case kCVPixelFormatType_TwoComponent8: self = ._TwoComponent8
case kCVPixelFormatType_30RGBLEPackedWideGamut: self = ._30RGBLEPackedWideGamut
case kCVPixelFormatType_ARGB2101010LEPacked: self = ._ARGB2101010LEPacked
case kCVPixelFormatType_OneComponent16Half: self = ._OneComponent16Half
case kCVPixelFormatType_OneComponent32Float: self = ._OneComponent32Float
case kCVPixelFormatType_TwoComponent16Half: self = ._TwoComponent16Half
case kCVPixelFormatType_TwoComponent32Float: self = ._TwoComponent32Float
case kCVPixelFormatType_64RGBAHalf: self = ._64RGBAHalf
case kCVPixelFormatType_128RGBAFloat: self = ._128RGBAFloat
case kCVPixelFormatType_14Bayer_GRBG: self = ._14Bayer_GRBG
case kCVPixelFormatType_14Bayer_RGGB: self = ._14Bayer_RGGB
case kCVPixelFormatType_14Bayer_BGGR: self = ._14Bayer_BGGR
case kCVPixelFormatType_14Bayer_GBRG: self = ._14Bayer_GBRG
case kCVPixelFormatType_DisparityFloat16: self = ._DisparityFloat16
case kCVPixelFormatType_DisparityFloat32: self = ._DisparityFloat32
case kCVPixelFormatType_DepthFloat16: self = ._DepthFloat16
case kCVPixelFormatType_DepthFloat32: self = ._DepthFloat32
case kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange: self = ._420YpCbCr10BiPlanarVideoRange
case kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange: self = ._422YpCbCr10BiPlanarVideoRange
case kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange: self = ._444YpCbCr10BiPlanarVideoRange
case kCVPixelFormatType_420YpCbCr10BiPlanarFullRange: self = ._420YpCbCr10BiPlanarFullRange
case kCVPixelFormatType_422YpCbCr10BiPlanarFullRange: self = ._422YpCbCr10BiPlanarFullRange
case kCVPixelFormatType_444YpCbCr10BiPlanarFullRange: self = ._444YpCbCr10BiPlanarFullRange
default: return nil
}
}
var rawValue: RawValue {
switch self {
case ._1Monochrome: return kCVPixelFormatType_1Monochrome
case ._2Indexed: return kCVPixelFormatType_2Indexed
case ._4Indexed: return kCVPixelFormatType_4Indexed
case ._8Indexed: return kCVPixelFormatType_8Indexed
case ._1IndexedGray_WhiteIsZero: return kCVPixelFormatType_1IndexedGray_WhiteIsZero
case ._2IndexedGray_WhiteIsZero: return kCVPixelFormatType_2IndexedGray_WhiteIsZero
case ._4IndexedGray_WhiteIsZero: return kCVPixelFormatType_4IndexedGray_WhiteIsZero
case ._8IndexedGray_WhiteIsZero: return kCVPixelFormatType_8IndexedGray_WhiteIsZero
case ._16BE555: return kCVPixelFormatType_16BE555
case ._16LE555: return kCVPixelFormatType_16LE555
case ._16LE5551: return kCVPixelFormatType_16LE5551
case ._16BE565: return kCVPixelFormatType_16BE565
case ._16LE565: return kCVPixelFormatType_16LE565
case ._24RGB: return kCVPixelFormatType_24RGB
case ._24BGR: return kCVPixelFormatType_24BGR
case ._32ARGB: return kCVPixelFormatType_32ARGB
case ._32BGRA: return kCVPixelFormatType_32BGRA
case ._32ABGR: return kCVPixelFormatType_32ABGR
case ._32RGBA: return kCVPixelFormatType_32RGBA
case ._64ARGB: return kCVPixelFormatType_64ARGB
case ._48RGB: return kCVPixelFormatType_48RGB
case ._32AlphaGray: return kCVPixelFormatType_32AlphaGray
case ._16Gray: return kCVPixelFormatType_16Gray
case ._30RGB: return kCVPixelFormatType_30RGB
case ._422YpCbCr8: return kCVPixelFormatType_422YpCbCr8
case ._4444YpCbCrA8: return kCVPixelFormatType_4444YpCbCrA8
case ._4444YpCbCrA8R: return kCVPixelFormatType_4444YpCbCrA8R
case ._4444AYpCbCr8: return kCVPixelFormatType_4444AYpCbCr8
case ._4444AYpCbCr16: return kCVPixelFormatType_4444AYpCbCr16
case ._444YpCbCr8: return kCVPixelFormatType_444YpCbCr8
case ._422YpCbCr16: return kCVPixelFormatType_422YpCbCr16
case ._422YpCbCr10: return kCVPixelFormatType_422YpCbCr10
case ._444YpCbCr10: return kCVPixelFormatType_444YpCbCr10
case ._420YpCbCr8Planar: return kCVPixelFormatType_420YpCbCr8Planar
case ._420YpCbCr8PlanarFullRange: return kCVPixelFormatType_420YpCbCr8PlanarFullRange
case ._422YpCbCr_4A_8BiPlanar: return kCVPixelFormatType_422YpCbCr_4A_8BiPlanar
case ._420YpCbCr8BiPlanarVideoRange: return kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
case ._420YpCbCr8BiPlanarFullRange: return kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
case ._422YpCbCr8_yuvs: return kCVPixelFormatType_422YpCbCr8_yuvs
case ._422YpCbCr8FullRange: return kCVPixelFormatType_422YpCbCr8FullRange
case ._OneComponent8: return kCVPixelFormatType_OneComponent8
case ._TwoComponent8: return kCVPixelFormatType_TwoComponent8
case ._30RGBLEPackedWideGamut: return kCVPixelFormatType_30RGBLEPackedWideGamut
case ._ARGB2101010LEPacked: return kCVPixelFormatType_ARGB2101010LEPacked
case ._OneComponent16Half: return kCVPixelFormatType_OneComponent16Half
case ._OneComponent32Float: return kCVPixelFormatType_OneComponent32Float
case ._TwoComponent16Half: return kCVPixelFormatType_TwoComponent16Half
case ._TwoComponent32Float: return kCVPixelFormatType_TwoComponent32Float
case ._64RGBAHalf: return kCVPixelFormatType_64RGBAHalf
case ._128RGBAFloat: return kCVPixelFormatType_128RGBAFloat
case ._14Bayer_GRBG: return kCVPixelFormatType_14Bayer_GRBG
case ._14Bayer_RGGB: return kCVPixelFormatType_14Bayer_RGGB
case ._14Bayer_BGGR: return kCVPixelFormatType_14Bayer_BGGR
case ._14Bayer_GBRG: return kCVPixelFormatType_14Bayer_GBRG
case ._DisparityFloat16: return kCVPixelFormatType_DisparityFloat16
case ._DisparityFloat32: return kCVPixelFormatType_DisparityFloat32
case ._DepthFloat16: return kCVPixelFormatType_DepthFloat16
case ._DepthFloat32: return kCVPixelFormatType_DepthFloat32
case ._420YpCbCr10BiPlanarVideoRange: return kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange
case ._422YpCbCr10BiPlanarVideoRange: return kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange
case ._444YpCbCr10BiPlanarVideoRange: return kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange
case ._420YpCbCr10BiPlanarFullRange: return kCVPixelFormatType_420YpCbCr10BiPlanarFullRange
case ._422YpCbCr10BiPlanarFullRange: return kCVPixelFormatType_422YpCbCr10BiPlanarFullRange
case ._444YpCbCr10BiPlanarFullRange: return kCVPixelFormatType_444YpCbCr10BiPlanarFullRange
}
}
}
CVPixelFormatType.allCases.forEach {
assert(CVPixelFormatType(rawValue: $0.rawValue)?.rawValue == $0.rawValue)
}
print("\(CVPixelFormatType(rawValue: 875704438)!)") // _420YpCbCr8BiPlanarVideoRange
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment