Use with TEBeautyKit

Features

TEBeautyKit is the UI panel library for the Tencent Effect module, used for quick and convenient usage and management of the effect features. The effect is as shown in the figure below:


Integration Steps

1. Integration TEBeautyKit,Edit the Podfile and append the following code snippet and execution pod install.
# Replace S1-07 with the package you purchased,Note that TEBeautyKit and TencentEffect must use the same package
pod 'TEBeautyKit/S1-07', :podspec => 'https://mediacloud-76607.gzc.vod.tencent-cloud.com/TencentEffect/iOS/TEBeautyKit/latest/TEBeautyKit.podspec'
pod 'TencentEffect_S1-07', :podspec => 'https://mediacloud-76607.gzc.vod.tencent-cloud.com/TencentEffect/iOS/podspec/latest/TencentEffect_S1-07.podspec'
2. Integration Panel Resources, download the resource package and incorporate it into your main project. The contents can be found in the appendix.
3. Integration Effect Resources.

Usage Guide

Step 1. Authenticate

After the application is launched, a beauty filter authentication must be performed to enable the normal use of beauty features. See the authentication error code
[TEBeautyKit setTELicense:@"your license" key:@"your key" completion:^(NSInteger authresult, NSString * _Nullable errorMsg) {
NSLog(@"----------result: %zd %@",authresult,errorMsg);
}];

Step 2. Configuration Panel Resource Path

The beauty data and icon assets on the beauty panel are available in beauty_panel.zip. As per the API documentation, you may pass the corresponding JSON file path and customize the settings according to your specific requirements.
4.4.0 and later versions
Versions before 4.4.0
/// 4.4.0 adds new configuration methods and is compatible with old version configuration methods.
- (void)configPanel {
NSString *indexPath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"json"];
// Configure the package and index path. Here we take the S1_07 package as an example.
[[TEUIConfig shareInstance] setPanelViewRes:indexPath effectPlanName:TEEffectPlan_S1_07];
}
- (void)configPanel {
NSBundle *bundle = [NSBundle mainBundle];
NSString *beautyJsonPath = [bundle pathForResource:@"beauty" ofType:@"json"]; //beauty
NSString *lutJsonPath = [bundle pathForResource:@"lut" ofType:@"json"]; //lut
NSString *motion2dJsonPath = [bundle pathForResource:@"motion_2d" ofType:@"json"]; //2d Sticker
NSMutableArray *resArray = [[NSMutableArray alloc] init];
[resArray addObject:@{TEUI_BEAUTY : beautyJsonPath}];
[resArray addObject:@{TEUI_LUT : lutJsonPath}];
[resArray addObject:@{TEUI_MOTION_2D : motion2dJsonPath}];
/// Set up resources
[[TEUIConfig shareInstance] setTEPanelViewResources:resArray];
}

Step 3. Initialize and incorporate TEPanelView

TEPanelView is a custom panel view used to display the data configured in Step 2.
- (void)addPanelView {
TEPanelView *tePanelView = [[TEPanelView alloc] init];
tePanelView.delegate = self;
[self.view addSubview:tePanelView];
[tePanelView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.bottom.mas_equalTo(self.view);
make.left.right.mas_equalTo(self.view);
make.height.mas_equalTo(230 + self.view.safeAreaInsets.bottom);
}];
}

Step 4. Initialize the beauty filter object

1. Initialization
- (void)initXMagic {
__weak typeof(self)weakSelf = self;
[TEBeautyKit createXMagic:EFFECT_MODE_PRO onInitListener:^(TEBeautyKit * _Nullable beautyKit) {
__strong typeof(weakSelf)strongSelf = weakSelf;
strongSelf.teBeautyKit = beautyKit;
strongSelf.tePanelView.teBeautyKit = strongSelf.teBeautyKit;
[strongSelf.tePanelView setDefaultBeauty];
}];
}
2. Processing video data
#pragma mark AVCaptureVideoDataOutputSampleBufferDelegate
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
if (captureOutput == self.videoDataOutput) {
[self mycaptureOutput:captureOutput didOutputSampleBuffer:sampleBuffer fromConnection:connection originImageProcess:YES];
}
}

- (void)mycaptureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)inputSampleBuffer fromConnection:(AVCaptureConnection *)connection originImageProcess:(BOOL)originImageProcess {
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(inputSampleBuffer);
YTProcessOutput *output = [self.teBeautyKit processPixelData:pixelBuffer
pixelDataWidth:(int)CVPixelBufferGetWidth(pixelBuffer)
pixelDataHeight:(int)CVPixelBufferGetHeight(pixelBuffer)
withOrigin:YtLightImageOriginTopLeft
withOrientation:YtLightCameraRotation0];
if (output.pixelData.data != nil) {
/// Output video data, render or other processing
}
if (output != nil) {
output.pixelData = nil;
output = nil;
}
}
3. Destroy Beauty Filter
- (void)destroyXMagic {
[self.teBeautyKit onDestroy];
self.teBeautyKit = nil;
}

Step 5: Export beauty parameters

Supports real-time export of beauty parameters during use; must be called before destruction.
/// export
- (void)exportEffectData {
self.exportBeautyString = [self.teBeautyKit exportInUseSDKParam];
NSLog(@"%@",self.exportBeautyString);
[[NSUserDefaults standardUserDefaults] setObject:self.exportBeautyString forKey:kExportEffectData];
}
/// set
- (void)setExportEffectData {
self.exportBeautyString = [[NSUserDefaults standardUserDefaults] objectForKey:kExportEffectData];
if (self.exportBeautyString) {
[self.tePanelView setExportParamList:self.exportBeautyString];
}
}

Appendix

Panel JSON File Description

beauty_panel/
├── index.json ← Define which tabs the panel contains
├── panel_json/ ← Define the function items in each Tab
│ ├── beauty_template.json
│ ├── beauty.json
│ ├── beauty_image.json
│ ├── shape.json → beauty_base_shape.json / beauty_general_shape.json / beauty_shape.json
│ ├── beauty_body.json
│ ├── lut.json
│ ├── beauty_makeup.json
│ └── motions.json
└── panel_icon/ ← All icon resources required for the panel
For details, please download the panel resources and refer to the README.md document.

TEBeautyKit Method Descriptions

/// Creates a TEBeautyKit object
/// - Parameters:
/// - effectMode: EFFECT_MODE_NORMAL (High-performance mode) or EFFECT_MODE_PRO (Default mode)
/// When high-performance mode is enabled, the beauty features consume fewer system CPU/GPU resources, reducing phone overheating and lag; this mode is better suited for prolonged use on low-end devices.
/// Note: When high-performance mode is enabled, the following beauty features will be unavailable:
/// 1. Eyes: Eye width, eye height, eye bag removal
/// 2. Eyebrows: Angle, spacing, height, length, thickness, arch
/// 3. Mouth: Smile lips
/// 4. Face: Face slimming (Natural, Goddess, Handsome), jawline slimming, wrinkle removal, nasolabial fold removal. It is recommended to use the "Face Shape" feature to achieve comprehensive eye-enlarging and face-slimming effects.
/// - onInitListener: Callback
+ (void)createXMagic:(EffectMode)effectMode onInitListener:(OnInitListener _Nullable)onInitListener;

/// Beauty feature authorization
+ (void)setTELicense:(NSString *_Nullable)url key:(NSString *_Nullable)key completion:(callback _Nullable)completion;

/// Sets the beauty object
- (void)setXMagicApi:(XMagic *_Nullable)xmagicApi;

/// Sets the render size
- (void)setRenderSize:(CGSize)size;

/// Sets the image orientation
- (void)setImageOrientation:(YtLightDeviceCameraOrientation)orientation;

/// Gets the current GL context interface
- (nullable EAGLContext*)getCurrentGlContext;

/// Mutes audio
- (void)setMute:(BOOL)isMute;

/// Enables or disables a feature
- (void)setFeatureEnableDisable:(NSString *_Nullable)featureName enable:(BOOL)enable;

/// Sets the frame synchronization mode
/// isSync Whether synchronization is enabled
/// syncFrameCount The number of synchronized frames. -1 indicates no limit. If `isSync` is `false`, this parameter is ignored.
- (void)setSyncMode:(BOOL)isSync syncFrameCount:(int)syncFrameCount;

/// Gets the device level.
+ (DeviceLevel)getDeviceLevel;

/// Applies beauty effects to a UIImage.
- (UIImage *_Nullable)processUIImage:(UIImage *_Nullable)inputImage
imageWidth:(int)imageWidth
imageHeight:(int)imageHeight
needReset:(bool)needReset;

/// Processes a texture.
/// - Parameters:
/// - textureId: Texture ID.
/// - textureWidth: Texture width.
/// - textureHeight: Texture height.
/// - origin: Enum value; setting this to `YtLightImageOriginBottomLeft` flips the image vertically.
/// - orientation: Enum value; image rotation angle.
- (YTProcessOutput *_Nullable)processTexture:(unsigned int)textureId
textureWidth:(int)textureWidth
textureHeight:(int)textureHeight
withOrigin:(YtLightImageOrigin)origin
withOrientation:(YtLightDeviceCameraOrientation)orientation;

/// Processes a CVPixelBufferRef.
/// - Parameters:
/// - pixelData: Image data.
/// - pixelDataWidth: Image width.
/// - pixelDataHeight: Image height.
/// - origin: Enum value; setting this to `YtLightImageOriginBottomLeft` flips the image vertically.
/// - orientation: Enum value; image rotation angle.
- (YTProcessOutput * _Nullable)processPixelData:(CVPixelBufferRef _Nullable )pixelData
pixelDataWidth:(int)pixelDataWidth
pixelDataHeight:(int)pixelDataHeight
withOrigin:(YtLightImageOrigin)origin
withOrientation:(YtLightDeviceCameraOrientation)orientation;

/// Sets beauty effects.
- (void)setEffect:(TESDKParam *_Nullable)sdkParam;

/// Sets beauty effects.
- (void)setEffectList:(NSArray<TESDKParam *>*_Nullable)sdkParamList;

/// Checks if enhanced beauty mode is enabled.
- (BOOL)isEnableEnhancedMode;

/// Enables or disables enhanced beauty mode.
- (void)enableEnhancedMode:(BOOL)enable;

/// Resumes.
- (void)onResume;

/// Pause
- (void)onPause;

/// Destroy
- (void)onDestroy;

// Get the image from the current texture
- (void)exportCurrentTexture:(void (^_Nullable)(UIImage * _Nullable image))callback;

/// Set log listener
- (void)registerSDKLogListener:(id<YTSDKLogListener> _Nullable)listener level:(YtSDKLoggerLevel)level;

/// Register SDK event listener
- (void)registerSDKEventListener:(id<YTSDKEventListener> _Nullable)listener;

/// Save configured beauty parameters
- (void)saveEffectParam:(TESDKParam *_Nonnull)sdkParam;

/// Delete specific saved beauty parameters
- (void)deleteEffectParam:(TESDKParam *_Nonnull)sdkParam;

/// Clear all saved beauty parameters
- (void)clearEffectParam;

/// Set the center-crop ratio for the output texture
- (void)setOutputTextureKeepRatio:(float)ratio;

/// Get the list of beauty parameters currently in use
- (NSMutableArray<TESDKParam *> *_Nonnull)getInUseSDKParamList;

/// Export beauty parameters currently in use
/// Returns a JSON string
- (NSString *_Nullable)exportInUseSDKParam;

/// Set beauty parameters
/// - Parameter params: JSON string
/// To update the panel UI simultaneously, simply call setExportParamList on TEPanelView
- (void)setExportedSDKParam:(NSString *_Nonnull)params;

/// Enable or disable beauty effects
- (void)enableBeauty:(BOOL)enable;

/// Clear registered listeners
- (void)clearListeners;

TEUIConfig Descriptions

/// Colors for the following properties can be modified externally
/// Beauty panel background color
@property (nonatomic, strong) UIColor *panelBackgroundColor;
/// Divider line color
@property (nonatomic, strong) UIColor *panelDividerColor;
/// Selected item color
@property (nonatomic, strong) UIColor *panelItemCheckedColor;
/// Text color
@property (nonatomic, strong) UIColor *textColor;
/// Selected text color
@property (nonatomic, strong) UIColor *textCheckedColor;
/// Progress bar color
@property (nonatomic, strong) UIColor *seekBarProgressColor;
/// Sets the language for displaying names; default is YES (display displayName field), NO (display displayNameEn field)
@property (nonatomic, assign) BOOL useDisplayName;
/// Panel layout direction, default NO: LTR (left to right), set YES: RTL (right to left, Arabic, etc.)
@property (nonatomic, assign) BOOL isLayoutRtl;
/// Matching key for the name field of the panel copy (such as zh/en/ja, customers can extend other keys), defaultLanguage is used when not set
@property (nonatomic, copy, nullable) NSString *displayNameKey;
/// The default language of the panel (defaultLanguage field of index.json, automatically written when the SDK parses, customers do not need to set it), and provide details when key matching fails.
@property (nonatomic, copy, nullable) NSString *defaultLanguage;
/// Panel index.json file path (set via setPanelViewRes:effectPlanName:)
@property (nonatomic, copy, readonly, nullable) NSString *indexFilePath;
/// Current plan (set via setPanelViewRes:effectPlanName:)
@property (nonatomic, assign, readonly) TEEffectPlan effectPlan;
/// Singleton instance
+ (instancetype)shareInstance;
/// Set the panel index.json path and package
/// - Parameters:
/// - indexFilePath: index.json file path
/// - effectPlan: plan type
- (void)setPanelViewRes:(NSString *)indexFilePath effectPlanName:(TEEffectPlan)effectPlan;
/// Sets the panel resource paths
/// - Parameter resources: List of resource paths
/// e.g. @[@{TEUI_BEAUTY : @"json file path"}]
- (void)setTEPanelViewResources:(NSArray<NSDictionary *> *)resources;
/// Gets the panel resource paths
- (NSArray<NSDictionary *> *)getTEPanelViewResources;
/// Sets the LightCore.bundle path
- (void)setLightCoreBundlePath:(NSString *)corePath;
/// Gets the LightCore.bundle path
- (NSString *)getLightCoreBundlePath;
/// Sets the Resources bundle path
- (void)setResourcesBundlePath:(NSString *)resPath;
/// Gets the Resources bundle path
- (NSString *)getResourcesBundlePath;

TEPanelView Description

/// Beauty SDK object
@property (nonatomic, weak) XMagic *beautyKitApi;
/// beautyKit object
@property (nonatomic, strong) TEBeautyKit *teBeautyKit;
/// Delegate
@property (nonatomic, weak) id<TEPanelViewDelegate> delegate;
/// Set exported beauty parameters
- (void)setExportParamList:(NSString *)lastParamList;
/// Set default beauty settings
- (void)setDefaultBeauty;
/// Reset all effects
- (void)performFullReset;
/// Enhanced mode
- (void)setEnhancedMode:(BOOL)enhancedMode;
/// Show comparison button
- (void)isShowCompareBtn:(BOOL)isShow;

Configuring Multilingual Support

Panel language settings consist of two parts: system text and panel item names.
1. System Text
System text is located in the Localizable.strings file under Assets.
Default supported languages: Simplified Chinese, English.
To add other languages:
Create a Localizable.strings file in your project (or simply add the new language if the file already exists).
Add the new language under "Localizations" in the PROJECT list.
Translate the text content within TEBeautyKit.
2. Panel Item Names
4.4.0 and later versions
Versions before 4.4.0
1. Add the corresponding language text under the name node in the panel json file.
2. Set the key to display the corresponding language in the code, for example, to display English: [[TEUIConfig shareInstance] setDisplayNameKey:@"en"];
Panel item names are defined in a JSON configuration file and controlled by the following two fields:
Field
Default Language
displayName
Simplified Chinese
displayNameEn
English
Switching between Chinese and English:
// Display Chinese (uses the displayName field)
[[TEUIConfig shareInstance] setUseDisplayName:YES];
// Display English (uses the displayNameEnField)
[[TEUIConfig shareInstance] setUseDisplayName:NO];
Adding other languages:
Copy the original JSON file and create a version for the target language (e.g., panel_zh_hant.json for Traditional Chinese).
Translate the value of the displayName field into the target language.
Detect the current system language in your code and load the corresponding JSON file.
Call [[TEUIConfig shareInstance] setUseDisplayName:YES].