【CoreGraphics】CGColorSpace - 色彩空间

简单来说:表示需要使用的色彩标准(为创建CGColor做准备)
例如RBG:CGColorSpaceCreateDeviceRGB
注:简单了解,深入需要更多色彩相关知识;

创建

  • 通用标准创建
    // 灰度 色彩
    CGColorSpaceRef graySpaceRef = CGColorSpaceCreateDeviceGray();
    
    // RGBA 色彩 (显示3色)
    CGColorSpaceRef rgbSapceRef = CGColorSpaceCreateDeviceRGB();
    
    // CMYK 色彩 (印刷4色)
    CGColorSpaceRef cmykSpaceRef = CGColorSpaceCreateDeviceCMYK();

    
  • 色彩矫正
    // 灰度 色彩矫正
//    CGFloat whitePoint[] = {0, 100, 200};// CIE XYZ 值
//    CGFloat blackPoint[] = {200, 100, 0};
//    CGFloat calibratedGrayComponents[] = {0.6, 0.6};
//    CGColorSpaceRef calibratedGraySpaceRef = CGColorSpaceCreateCalibratedGray(whitePoint, blackPoint, 0.5);
//    CGColorRef calibratedGrayColorRef = CGColorCreate(calibratedGraySpaceRef, calibratedGrayComponents);

    
    // RGB 色彩矫正 (数据不太对,见谅,水好深)
//    CGFloat whitePoint[] = {0, 100, 200};// CIE XYZ 值
//    CGFloat blackPoint[] = {200, 100, 0};
//    CGFloat gamma[] = {0, 0, 0};
//    CGFloat matrix[] = {0, 100, 200, 0, 100, 200, 0, 100, 200};
//    CGFloat calibratedRGBComponents[] = {1, 0, 0, 1};
//    CGColorSpaceRef calibratedRGBSpaceRef = CGColorSpaceCreateCalibratedRGB(whitePoint, blackPoint, gamma, matrix);
//    CGColorRef calibratedRGBColorRef = CGColorCreate(calibratedRGBSpaceRef, calibratedRGBComponents);

  • 根据名称创建
    注:__IPHONE_9_0
    CGColorSpaceRef nameSpaceColor = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);

// 有点多
CG_EXTERN const CFStringRef kCGColorSpaceGenericGray
  CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_9_0);

CG_EXTERN const CFStringRef kCGColorSpaceGenericRGB
  CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_9_0);

CG_EXTERN const CFStringRef kCGColorSpaceGenericCMYK
  CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_9_0);
  
CG_EXTERN const CFStringRef kCGColorSpaceDisplayP3
  CG_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_9_0);

CG_EXTERN const CFStringRef kCGColorSpaceGenericRGBLinear
  CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_9_0);

CG_EXTERN const CFStringRef kCGColorSpaceAdobeRGB1998
  CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_9_0);

CG_EXTERN const CFStringRef kCGColorSpaceSRGB
  CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_9_0);

CG_EXTERN const CFStringRef kCGColorSpaceGenericGrayGamma2_2
  CG_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_9_0);

CG_EXTERN const CFStringRef kCGColorSpaceGenericXYZ
  CG_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0);

CG_EXTERN const CFStringRef kCGColorSpaceACESCGLinear
CG_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0);

CG_EXTERN const CFStringRef kCGColorSpaceITUR_709
CG_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0);

CG_EXTERN const CFStringRef kCGColorSpaceITUR_2020
CG_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0);

CG_EXTERN const CFStringRef kCGColorSpaceROMMRGB
CG_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0);

CG_EXTERN const CFStringRef kCGColorSpaceDCIP3
CG_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0);

  • 更多
    水太深,HOLD 不住啊。

CG_EXTERN CGColorSpaceRef __nullable CGColorSpaceCreateLab(const CGFloat whitePoint[3],
  const CGFloat blackPoint[3], const CGFloat range[4])
  CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

CG_EXTERN CGColorSpaceRef __nullable CGColorSpaceCreateWithICCProfile(CFDataRef __nullable data)
  CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);

CG_EXTERN CGColorSpaceRef __nullable CGColorSpaceCreateICCBased(size_t nComponents,
  const CGFloat * __nullable range, CGDataProviderRef __nullable profile,
  CGColorSpaceRef __nullable alternate)
  CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

CG_EXTERN CGColorSpaceRef __nullable CGColorSpaceCreateIndexed(CGColorSpaceRef __nullable baseSpace,
  size_t lastIndex, const unsigned char * __nullable colorTable)
  CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

CG_EXTERN CGColorSpaceRef __nullable CGColorSpaceCreatePattern(CGColorSpaceRef __nullable baseSpace)
  CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

CG_EXTERN CGColorSpaceRef __nullable
  CGColorSpaceCreateWithPlatformColorSpace(const void * __nullable ref)
  CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_9_0);

操作

 // retain
    CGColorSpaceRef retain = CGColorSpaceRetain(nameSpaceColorRef);
 // release
    CGColorSpaceRelease(nameSpaceColorRef);

获取信息

CG_EXTERN CFTypeID CGColorSpaceGetTypeID(void)
  CG_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0);

CG_EXTERN size_t CGColorSpaceGetNumberOfComponents(CGColorSpaceRef __nullable space)
  CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

CG_EXTERN CGColorSpaceModel CGColorSpaceGetModel(CGColorSpaceRef __nullable space)
  CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);

CG_EXTERN CGColorSpaceRef __nullable CGColorSpaceGetBaseColorSpace(CGColorSpaceRef __nullable space)
  CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);

CG_EXTERN size_t CGColorSpaceGetColorTableCount(CGColorSpaceRef __nullable space)
  CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);

CG_EXTERN void CGColorSpaceGetColorTable(CGColorSpaceRef __nullable space,
  uint8_t * __nullable table) CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);

CG_EXTERN CFDataRef __nullable CGColorSpaceCopyICCProfile(CGColorSpaceRef __nullable space)
  CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_6_0);

1

你可能感兴趣的:(【CoreGraphics】CGColorSpace - 色彩空间)