Skip to content

Instantly share code, notes, and snippets.

@danielpi
Created March 27, 2017 13:29
Show Gist options
  • Save danielpi/df478fcf4df2d6b42e1e8da717523769 to your computer and use it in GitHub Desktop.
Save danielpi/df478fcf4df2d6b42e1e8da717523769 to your computer and use it in GitHub Desktop.
Extension to AVCaptureVideoDataOutput and an enum to represent OSType CVPixelFormatType data
extension AVCaptureVideoDataOutput {
var availableVideoCVPixelFormatTypedEnums: [OSTypedEnum] {
let availablePixelFormatDescriptions: Array<OSType> = self.availableVideoCVPixelFormatTypes as! Array<OSType>
let availablePixelFormats: Array<OSTypedEnum> = availablePixelFormatDescriptions.map { OSTypedEnum(rawValue: $0)! }
return availablePixelFormats
}
}
enum OSTypedEnum: OSType {
case monochrome1 = 1
case indexed2 = 2
case indexed4 = 4
case indexed8 = 8
case indexedGray_WhiteIsZero1 = 33
case indexedGray_WhiteIsZero2 = 34
case indexedGray_WhiteIsZero4 = 36
case indexedGray_WhiteIsZero8 = 40
case BE16BE555 = 16
case LE16LE555 = 1278555445
case LE16LE5551 = 892679473
case BE16BE565 = 1110783541
case LE16LE565 = 1278555701
case RGB24 = 24
case BGR24 = 842285639
case ARGB32 = 32
case BGRA32 = 1111970369
case ABGR32 = 1094862674
case RGBA32 = 1380401729
case ARGB64 = 1647719521
case RGB48 = 1647589490
case alphaGray32 = 1647522401
case gray16 = 1647392359
case RGB30 = 1378955371
case YpCbCr8_422 = 846624121
case YpCbCrA8_4444 = 1983131704
case YpCbCrA8R_4444 = 1916022840
case AYpCbCr8_4444 = 2033463352
case AYpCbCr16_4444 = 2033463606
case YpCbCr8_444 = 1983066168
case YpCbCr16_422 = 1983000886
case YpCbCr10_422 = 1983000880
case YpCbCr10_444 = 1983131952
case YpCbCr8Planar_420 = 2033463856
case YpCbCr8PlanarFullRange_420 = 1714696752
case YpCbCr_4A_8BiPlanar_422 = 1630697081
case YpCbCr8BiPlanarVideoRange_420 = 875704438
case YpCbCr8BiPlanarFullRange_420 = 875704422
case YpCbCr8_yuvs_422 = 2037741171
case YpCbCr8FullRange_422 = 2037741158
case oneComponent8 = 1278226488
case twoComponent8 = 843264056
case RGBLEPackedWideGamut30 = 1999843442
case oneComponent16Half = 1278226536
case oneComponent32Float = 1278226534
case twoComponent16Half = 843264104
case twoComponent32Float = 843264102
case RGBAHalf64 = 1380411457
case RGBAFloat128 = 1380410945
case bayer_GRBG14 = 1735549492
case bayer_RGGB14 = 1919379252
case bayer_BGGR14 = 1650943796
case bayer_GBRG14 = 1734505012
var typeKey: String {
switch self {
case .monochrome1:
return "kCVPixelFormatType_1Monochrome"
case .indexed2:
return "kCVPixelFormatType_2Indexed"
case .indexed4:
return "kCVPixelFormatType_4Indexed"
case .indexed8:
return "kCVPixelFormatType_8Indexed"
case .indexedGray_WhiteIsZero1:
return "kCVPixelFormatType_1IndexedGray_WhiteIsZero"
case .indexedGray_WhiteIsZero2:
return "kCVPixelFormatType_2IndexedGray_WhiteIsZero"
case .indexedGray_WhiteIsZero4:
return "kCVPixelFormatType_4IndexedGray_WhiteIsZero"
case .indexedGray_WhiteIsZero8:
return "kCVPixelFormatType_8IndexedGray_WhiteIsZero"
case .BE16BE555:
return "kCVPixelFormatType_16BE555"
case .LE16LE555:
return "kCVPixelFormatType_16LE555"
case .LE16LE5551:
return "kCVPixelFormatType_16LE5551"
case .BE16BE565:
return "kCVPixelFormatType_16BE565"
case .LE16LE565:
return "kCVPixelFormatType_16LE565"
case .RGB24:
return "kCVPixelFormatType_24RGB"
case .BGR24:
return "kCVPixelFormatType_24BGR"
case .ARGB32:
return "kCVPixelFormatType_32ARGB"
case .BGRA32:
return "kCVPixelFormatType_32BGRA"
case .ABGR32:
return "kCVPixelFormatType_32ABGR"
case .RGBA32:
return "kCVPixelFormatType_32RGBA"
case .ARGB64:
return "kCVPixelFormatType_64ARGB"
case .RGB48:
return "kCVPixelFormatType_48RGB"
case .alphaGray32:
return "kCVPixelFormatType_32AlphaGray"
case .gray16:
return "kCVPixelFormatType_16Gray"
case .RGB30:
return "kCVPixelFormatType_30RGB"
case .YpCbCr8_422:
return "kCVPixelFormatType_422YpCbCr8"
case .YpCbCrA8_4444:
return "kCVPixelFormatType_4444YpCbCrA8"
case .YpCbCrA8R_4444:
return "kCVPixelFormatType_4444YpCbCrA8R"
case .AYpCbCr8_4444:
return "kCVPixelFormatType_4444AYpCbCr8"
case .AYpCbCr16_4444:
return "kCVPixelFormatType_4444AYpCbCr16"
case .YpCbCr8_444:
return "kCVPixelFormatType_444YpCbCr8"
case .YpCbCr16_422:
return "kCVPixelFormatType_422YpCbCr16"
case .YpCbCr10_422:
return "kCVPixelFormatType_422YpCbCr10"
case .YpCbCr10_444:
return "kCVPixelFormatType_444YpCbCr10"
case .YpCbCr8Planar_420:
return "kCVPixelFormatType_420YpCbCr8Planar"
case .YpCbCr8PlanarFullRange_420:
return "kCVPixelFormatType_420YpCbCr8PlanarFullRange"
case .YpCbCr_4A_8BiPlanar_422:
return "kCVPixelFormatType_422YpCbCr_4A_8BiPlanar"
case .YpCbCr8BiPlanarVideoRange_420:
return "kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange"
case .YpCbCr8BiPlanarFullRange_420:
return "kCVPixelFormatType_420YpCbCr8BiPlanarFullRange"
case .YpCbCr8_yuvs_422:
return "kCVPixelFormatType_422YpCbCr8_yuvs"
case .YpCbCr8FullRange_422:
return "kCVPixelFormatType_422YpCbCr8FullRange"
case .oneComponent8:
return "kCVPixelFormatType_OneComponent8"
case .twoComponent8:
return "kCVPixelFormatType_TwoComponent8"
case .RGBLEPackedWideGamut30:
return "kCVPixelFormatType_30RGBLEPackedWideGamut"
case .oneComponent16Half:
return "kCVPixelFormatType_OneComponent16Half"
case .oneComponent32Float:
return "kCVPixelFormatType_OneComponent32Float"
case .twoComponent16Half:
return "kCVPixelFormatType_TwoComponent16Half"
case .twoComponent32Float:
return "kCVPixelFormatType_TwoComponent32Float"
case .RGBAHalf64:
return "kCVPixelFormatType_64RGBAHalf"
case .RGBAFloat128:
return "kCVPixelFormatType_128RGBAFloat"
case .bayer_GRBG14:
return "kCVPixelFormatType_14Bayer_GRBG"
case .bayer_RGGB14:
return "kCVPixelFormatType_14Bayer_RGGB"
case .bayer_BGGR14:
return "kCVPixelFormatType_14Bayer_BGGR"
case .bayer_GBRG14:
return "kCVPixelFormatType_14Bayer_GBRG"
}
}
var description: String {
switch self {
case .monochrome1:
return "1 bit indexed"
case .indexed2:
return "2 bit indexed"
case .indexed4:
return "4 bit indexed"
case .indexed8:
return "8 bit indexed"
case .indexedGray_WhiteIsZero1:
return "1 bit indexed gray, white is zero"
case .indexedGray_WhiteIsZero2:
return "2 bit indexed gray, white is zero"
case .indexedGray_WhiteIsZero4:
return "4 bit indexed gray, white is zero"
case .indexedGray_WhiteIsZero8:
return "8 bit indexed gray, white is zero"
case .BE16BE555:
return "16 bit BE RGB 555"
case .LE16LE555:
return "16 bit LE RGB 555"
case .LE16LE5551:
return "16 bit LE RGB 5551"
case .BE16BE565:
return "16 bit BE RGB 565"
case .LE16LE565:
return "16 bit LE RGB 565"
case .RGB24:
return "24 bit RGB"
case .BGR24:
return "24 bit BGR"
case .ARGB32:
return "32 bit ARGB"
case .BGRA32:
return "32 bit BGRA"
case .ABGR32:
return "32 bit ABGR"
case .RGBA32:
return "32 bit RGBA"
case .ARGB64:
return "64 bit ARGB, 16-bit big-endian samples"
case .RGB48:
return "48 bit RGB, 16-bit big-endian samples"
case .alphaGray32:
return "32 bit AlphaGray, 16-bit big-endian samples, black is zero"
case .gray16:
return "16 bit Grayscale, 16-bit big-endian samples, black is zero"
case .RGB30:
return "30 bit RGB, 10-bit big-endian samples, 2 unused padding bits (at least significant end)."
case .YpCbCr8_422:
return "Component Y'CbCr 8-bit 4:2:2, ordered Cb Y'0 Cr Y'1"
case .YpCbCrA8_4444:
return "Component Y'CbCrA 8-bit 4:4:4:4, ordered Cb Y' Cr A"
case .YpCbCrA8R_4444:
return "Component Y'CbCrA 8-bit 4:4:4:4, rendering format. full range alpha, zero biased YUV, ordered A Y' Cb Cr"
case .AYpCbCr8_4444:
return "Component Y'CbCrA 8-bit 4:4:4:4, ordered A Y' Cb Cr, full range alpha, video range Y'CbCr."
case .AYpCbCr16_4444:
return "Component Y'CbCrA 16-bit 4:4:4:4, ordered A Y' Cb Cr, full range alpha, video range Y'CbCr, 16-bit little-endian samples."
case .YpCbCr8_444:
return "Component Y'CbCr 8-bit 4:4:4"
case .YpCbCr16_422:
return "Component Y'CbCr 10,12,14,16-bit 4:2:2"
case .YpCbCr10_422:
return "Component Y'CbCr 10-bit 4:2:2"
case .YpCbCr10_444:
return "Component Y'CbCr 10-bit 4:4:4"
case .YpCbCr8Planar_420:
return "Planar Component Y'CbCr 8-bit 4:2:0. baseAddr points to a big-endian CVPlanarPixelBufferInfo_YCbCrPlanar struct"
case .YpCbCr8PlanarFullRange_420:
return "Planar Component Y'CbCr 8-bit 4:2:0, full range. baseAddr points to a big-endian CVPlanarPixelBufferInfo_YCbCrPlanar struct"
case .YpCbCr_4A_8BiPlanar_422:
return "First plane: Video-range Component Y'CbCr 8-bit 4:2:2, ordered Cb Y'0 Cr Y'1; second plane: alpha 8-bit 0-255"
case .YpCbCr8BiPlanarVideoRange_420:
return "Bi-Planar Component Y'CbCr 8-bit 4:2:0, video-range (luma=[16,235] chroma=[16,240]). baseAddr points to a big-endian CVPlanarPixelBufferInfo_YCbCrBiPlanar struct"
case .YpCbCr8BiPlanarFullRange_420:
return "Bi-Planar Component Y'CbCr 8-bit 4:2:0, full-range (luma=[0,255] chroma=[1,255]). baseAddr points to a big-endian CVPlanarPixelBufferInfo_YCbCrBiPlanar struct"
case .YpCbCr8_yuvs_422:
return "Component Y'CbCr 8-bit 4:2:2, ordered Y'0 Cb Y'1 Cr"
case .YpCbCr8FullRange_422:
return "Component Y'CbCr 8-bit 4:2:2, full range, ordered Y'0 Cb Y'1 Cr"
case .oneComponent8:
return "8 bit one component, black is zero"
case .twoComponent8:
return "8 bit two component, black is zero"
case .RGBLEPackedWideGamut30:
return "little-endian RGB101010, 2 MSB are zero, wide-gamut (384-895)"
case .oneComponent16Half:
return "16 bit one component IEEE half-precision float, 16-bit little-endian samples"
case .oneComponent32Float:
return "32 bit one component IEEE float, 32-bit little-endian samples"
case .twoComponent16Half:
return "16 bit two component IEEE half-precision float, 16-bit little-endian samples"
case .twoComponent32Float:
return "32 bit two component IEEE float, 32-bit little-endian samples"
case .RGBAHalf64:
return "64 bit RGBA IEEE half-precision float, 16-bit little-endian samples"
case .RGBAFloat128:
return "128 bit RGBA IEEE float, 32-bit little-endian samples"
case .bayer_GRBG14:
return "Bayer 14-bit Little-Endian, packed in 16-bits, ordered G R G R... alternating with B G B G..."
case .bayer_RGGB14:
return "Bayer 14-bit Little-Endian, packed in 16-bits, ordered R G R G... alternating with G B G B..."
case .bayer_BGGR14:
return "Bayer 14-bit Little-Endian, packed in 16-bits, ordered B G B G... alternating with G R G R..."
case .bayer_GBRG14:
return "Bayer 14-bit Little-Endian, packed in 16-bits, ordered G B G B... alternating with R G R G..."
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment