macOS API 参考
日志相关
日志级别
日志级别枚举,用于控制日志输出级别。
objc
typedef NS_ENUM(NSInteger, FBLogLevel) {
FBLogLevel_Trace = 0,
FBLogLevel_Debug,
FBLogLevel_Info,
FBLogLevel_Warn,
FBLogLevel_Error,
FBLogLevel_Critical,
};日志配置类
日志配置类,用于配置日志输出方式和级别。
字段说明:
consoleEnabled: 是否启用控制台输出fileEnabled: 是否启用文件输出level: 日志级别fileName: 日志文件路径(仅在fileEnabled为YES时有效)
objc
FB_OBJC_API @interface FBLogConfig : NSObject
@property(nonatomic, assign) BOOL consoleEnabled;
@property(nonatomic, assign) BOOL fileEnabled;
@property(nonatomic, assign) FBLogLevel level;
@property(nonatomic, copy, nullable) NSString* fileName;
- (instancetype)init;
@end引擎相关
处理模式
图像处理模式枚举。
FBProcessModeImage: 图像模式,适合单张图片处理FBProcessModeVideo: 视频模式,适合视频流和直播场景,性能更优
objc
typedef NS_ENUM(NSInteger, FBProcessMode) {
FBProcessModeImage = 0, // 图像模式
FBProcessModeVideo = 1 // 视频模式
};引擎配置
引擎配置类,用于初始化美颜引擎。
字段说明:
appId: 应用 IDappKey: 应用密钥
objc
FB_OBJC_API @interface FBEngineConfig : NSObject
@property(nonatomic, copy) NSString* appId;
@property(nonatomic, copy) NSString* appKey;
- (instancetype)init;
@end引擎接口
美颜效果引擎主类,提供美颜功能的入口。
静态方法:
setLogConfig:: 设置日志配置
实例方法:
美颜类型控制
setBeautyTypeEnabled:enabled:: 启用或禁用美颜类型isBeautyTypeEnabled:: 检查美颜类型是否已启用disableAllBeautyTypes: 禁用所有美颜类型
参数设置
setBasicParam:floatValue:: 设置基础美颜参数(范围 0.0 - 1.0)setReshapeParam:floatValue:: 设置面部重塑参数(范围 0.0 - 1.0)setMakeupParam:floatValue:: 设置美妆参数(范围 0.0 - 1.0)setVirtualBackground:: 设置虚拟背景- 参数:
FBVirtualBackgroundOptions对象,包含背景模式和背景图片
- 参数:
图像处理
processImage:processMode:: 处理图像帧
返回值说明:
- 方法返回
int类型:0表示成功,其他值表示错误码 processImage:processMode:返回FBImageFrame:处理后的图像帧,失败时返回nil
objc
FB_OBJC_API @interface FBBeautyEffectEngine : NSObject
+ (int)setLogConfig:(FBLogConfig*)config;
+ (instancetype)createEngineWithConfig:(FBEngineConfig*)config;
- (int)setBeautyTypeEnabled:(FBBeautyType)type enabled:(BOOL)enabled;
- (BOOL)isBeautyTypeEnabled:(FBBeautyType)type;
- (int)disableAllBeautyTypes;
- (int)setBasicParam:(FBBasicParam)param floatValue:(float)value;
- (int)setReshapeParam:(FBReshapeParam)param floatValue:(float)value;
- (int)setMakeupParam:(FBMakeupParam)param floatValue:(float)value;
- (int)setVirtualBackground:(FBVirtualBackgroundOptions*)options;
- (FBImageFrame* _Nullable)processImage:(FBImageFrame*)imageFrame
processMode:(FBProcessMode)processMode;
@end美颜参数
美颜参数枚举类,包含所有美颜相关的参数类型定义。
美颜类型
定义可用的美颜功能类型。
objc
typedef NS_ENUM(NSInteger, FBBeautyType) {
FBBeautyType_Basic = 0, // 基础美颜
FBBeautyType_Reshape, // 面部重塑
FBBeautyType_Makeup, // 美妆效果
FBBeautyType_VirtualBackground, // 虚拟背景
};基础美颜参数
基础美颜效果的参数类型,所有参数值范围均为 0.0 - 1.0。
objc
typedef NS_ENUM(NSInteger, FBBasicParam) {
FBBasicParam_Smoothing = 0, // 磨皮
FBBasicParam_Sharpening, // 锐化
FBBasicParam_Whitening, // 美白
FBBasicParam_Rosiness, // 红润
};面部重塑参数
面部重塑效果的参数类型,所有参数值范围均为 0.0 - 1.0。
objc
typedef NS_ENUM(NSInteger, FBReshapeParam) {
FBReshapeParam_FaceThin = 0, // 瘦脸
FBReshapeParam_FaceVShape, // V脸
FBReshapeParam_FaceNarrow, // 窄脸
FBReshapeParam_FaceShort, // 短脸
FBReshapeParam_Cheekbone, // 颧骨
FBReshapeParam_Jawbone, // 下颌骨
FBReshapeParam_Chin, // 下巴
FBReshapeParam_NoseSlim, // 瘦鼻梁
FBReshapeParam_EyeSize, // 大眼
FBReshapeParam_EyeDistance, // 眼距
};美妆参数
美妆效果的参数类型,所有参数值范围均为 0.0 - 1.0。
objc
typedef NS_ENUM(NSInteger, FBMakeupParam) {
FBMakeupParam_Lipstick = 0, // 口红
FBMakeupParam_Blush, // 腮红
};虚拟背景选项
虚拟背景效果的配置选项。
objc
FB_OBJC_API @interface FBVirtualBackgroundOptions : NSObject
@property(nonatomic, assign) FBBackgroundMode mode;
@property(nonatomic, strong, nullable) FBImageFrame *backgroundImage;
- (instancetype)init;
- (instancetype)initWithMode:(FBBackgroundMode)mode;
@end;;图像相关
FBImageFrame
图像帧类,用于封装图像数据和处理。
创建方法:
createWithFile:: 从文件创建(支持 PNG、JPG)createWithRGBA:width:height:stride:: 从 RGBA 数据创建createWithBGRA:width:height:stride:: 从 BGRA 数据创建createWithI420:...: 从 I420 YUV 数据创建createWithNV12:...: 从 NV12 YUV 数据创建createWithNV21:...: 从 NV21 YUV 数据创建
图像操作:
rotate:: 旋转图像(返回 0 表示成功)
格式转换:
toRGBA,toBGRA,toRGB,toBGR: 转换为 RGB 格式toI420,toNV12,toNV21: 转换为 YUV 格式
objc
FB_OBJC_API @interface FBImageFrame : NSObject
+ (FBImageFrame *_Nullable)createWithFile:(NSString *)filePath;
+ (FBImageFrame *_Nullable)createWithRGBA:(const uint8_t *)data
width:(int)width
height:(int)height
stride:(int)stride;
+ (FBImageFrame *_Nullable)createWithBGRA:(const uint8_t *)data
width:(int)width
height:(int)height
stride:(int)stride;
+ (FBImageFrame *_Nullable)createWithI420:(int)width
height:(int)height
dataY:(const uint8_t *)dataY
strideY:(int)strideY
dataU:(const uint8_t *)dataU
strideU:(int)strideU
dataV:(const uint8_t *)dataV
strideV:(int)strideV;
+ (FBImageFrame *_Nullable)createWithNV12:(int)width
height:(int)height
dataY:(const uint8_t *)dataY
strideY:(int)strideY
dataUV:(const uint8_t *)dataUV
strideUV:(int)strideUV;
+ (FBImageFrame *_Nullable)createWithNV21:(int)width
height:(int)height
dataY:(const uint8_t *)dataY
strideY:(int)strideY
dataUV:(const uint8_t *)dataUV
strideUV:(int)strideUV;
- (int)rotate:(FBImageRotation)rotation;
- (FBImageBuffer *_Nullable)toRGBA;
- (FBImageBuffer *_Nullable)toBGRA;
- (FBImageBuffer *_Nullable)toRGB;
- (FBImageBuffer *_Nullable)toBGR;
- (FBImageBuffer *_Nullable)toI420;
- (FBImageBuffer *_Nullable)toNV12;
- (FBImageBuffer *_Nullable)toNV21;
@endFBImageBuffer
图像缓冲区类,用于访问图像数据。
支持的图像格式:
FBImageFormatI420: YUV 4:2:0(3 平面,Y、U、V)FBImageFormatNV12: YUV 4:2:0(2 平面,Y + UV)FBImageFormatNV21: YUV 4:2:0(2 平面,Y + VU)FBImageFormatRGBA,FBImageFormatBGRA: 32 位 RGBA/BGRAFBImageFormatRGB,FBImageFormatBGR: 24 位 RGB/BGRFBImageFormatTexture: 纹理格式
图像旋转角度:
FBImageRotation0: 0 度FBImageRotation90: 顺时针旋转 90 度FBImageRotation180: 顺时针旋转 180 度FBImageRotation270: 顺时针旋转 270 度
属性访问:
width,height: 获取图像宽高size: 获取图像数据大小(字节数)stride: 获取图像步长
数据访问:
data: 获取图像原始数据指针- YUV 格式专用:
dataY,dataU,dataV,dataUV - YUV 格式步长:
strideY,strideU,strideV,strideUV
objc
typedef NS_ENUM(NSInteger, FBImageFormat) {
FBImageFormatI420,
FBImageFormatNV12,
FBImageFormatNV21,
FBImageFormatBGRA,
FBImageFormatRGBA,
FBImageFormatBGR,
FBImageFormatRGB,
FBImageFormatTexture,
};
typedef NS_ENUM(NSInteger, FBImageRotation) {
FBImageRotation0, // 0度
FBImageRotation90, // 顺时针旋转90度
FBImageRotation180, // 顺时针旋转180度
FBImageRotation270, // 顺时针旋转270度
};
FB_OBJC_API @interface FBImageBuffer : NSObject
@property(nonatomic, assign, readonly) int32_t width;
@property(nonatomic, assign, readonly) int32_t height;
@property(nonatomic, assign, readonly) int32_t size;
@property(nonatomic, assign, readonly) int32_t stride;
- (const uint8_t *_Nullable)data;
- (const uint8_t *_Nullable)dataY;
- (const uint8_t *_Nullable)dataU;
- (const uint8_t *_Nullable)dataV;
- (const uint8_t *_Nullable)dataUV;
- (int32_t)strideY;
- (int32_t)strideU;
- (int32_t)strideV;
- (int32_t)strideUV;
@end