このページは現在英語版のみで提供されており、日本語版も近日中に提供される予定です。ご利用いただきありがとうございます。

iOS

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. Download and unzip TEBeautyKit.
2. Copy the TEBeautyKit folder into your project and make it the same level as the podfile directory.
3. Edit the podfile, adding the following code:
pod 'TEBeautyKit',:path => 'TEBeautyKit/TEBeautyKit.podspec'

User Guide

1. Effect Authentication
After the app is launched, effect authentication needs to be performed once to use the effect feature normally.
API:
TEBeautyKit.h
+ (void)setTELicense:(NSString *)url key:(NSString *)key completion:(callback _Nullable )completion;
Example:
[TEBeautyKit setTELicense:@"your license" key:@"your key" completion:^(NSInteger authresult, NSString * _Nullable errorMsg) {
NSLog(@"----------result: %zd %@",authresult,errorMsg);
}];
2. Set the Effect Material Path
The effect data on the effect panel are all parsed from the json file in the material path set here.
API:
#import "TEUIConfig.h"
/// Configure the beauty panel settings according to the beauty package options.
/// - Parameter panelLevel: Beauty Package
/// Beauty Package Types: A1_00,A1_01,A1_02,A1_03,A1_04,A1_05,A1_06,S1_00,S1_01,S1_02,S1_03,S1_04,S1_05,S1_06,S1_07
-(void)setPanelLevel:(TEPanelLevel)panelLevel;
Example:
[[TEUIConfig shareInstance] setPanelLevel:S1_07];
3. Initialize and add TEPanelView
-(TEPanelView *)tePanelView{
if (!_tePanelView) {
_tePanelView = [[TEPanelView alloc] init:nil comboType:nil];
_tePanelView.delegate = self;
}
return _tePanelView;
}
[self.view addSubview:self.tePanelView];
[self.tePanelView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.view);
make.centerX.mas_equalTo(self.view);
make.height.mas_equalTo(250);
make.bottom.mas_equalTo(self.view.mas_bottom);
}];
4. Create an effect object
API:
//Create a TEBeautyKit object with effectMode options: EFFECT_MODE_NORMAL (High-Performance Mode) and EFFECT_MODE_PRO (Default Mode).
+ (void)createXMagic:(EffectMode)effectMode onInitListener:(OnInitListener _Nullable )onInitListener;
//Create the TEBeautyKit object, do not enable the High Performance Mode
+ (void)create:(OnInitListener _Nullable )onInitListener;
Example:
- (void)initXMagic {
__weak __typeof(self)weakSelf = self;
[TEBeautyKit createXMagic:EFFECT_MODE_PRO onInitListener:^(TEBeautyKit * _Nullable api) {
__strong typeof(self) strongSelf = weakSelf;
strongSelf.teBeautyKit = api;
strongSelf.tePanelView.teBeautyKit = strongSelf.teBeautyKit;
[strongSelf.tePanelView setDefaultBeauty];
[strongSelf.teBeautyKit setLogLevel:YT_SDK_ERROR_LEVEL];
// [strongSelf.teBeautyKit registerSDKEventListener:strongSelf];
}];
}
5. Processing video data
API:
/**
textureId: Texture ID
textureWidth: Texture width
textureHeight: Texture height
origin: Enumeration value (YtLightImageOriginTopLeft, YtLightImageOriginBottomLeft). When setting to YtLightImageOriginBottomLeft, the image is flipped vertically
orientation: Enumeration value for image rotation angle
*/
- (YTProcessOutput *)processTexture:(int)textureId
textureWidth:(int)textureWidth
textureHeight:(int)textureHeight
withOrigin:(YtLightImageOrigin)origin
withOrientation:(YtLightDeviceCameraOrientation)orientation

Example:
#pragma mark - TRTCVideoFrameDelegate
- (uint32_t)onProcessVideoFrame:(TRTCVideoFrame *_Nonnull)srcFrame dstFrame:(TRTCVideoFrame *_Nonnull)dstFrame {
if(!_teBeautyKit){
[self initXMagic];
}
YTProcessOutput *output = [self.teBeautyKit processTexture:srcFrame.textureId
textureWidth:srcFrame.width textureHeight:srcFrame.height
withOrigin:YtLightImageOriginTopLeft withOrientation:YtLightCameraRotation0];
dstFrame.textureId = output.textureData.texture;
return 0;
}
6. Destroy effect
- (void)destroyXMagic{
[self.teBeautyKit onDestroy];
self.teBeautyKit=nil;
}

Appendix

Panel JSON File Description

Beauty, Body Shaping.

Field
Description
displayName
Chinese Name
displayNameEn
English Name
icon
Image address, supports setting local images and network images. Local images support assets resources and SD resources. Assets images are as shown in the image above. For SD card images, set the full path of the image. For network images, set the corresponding HTTP link.
sdkParam
The effect SDK requires four properties. Refer to the Effect Parameters table
effectName
Effect attribute key, refer to the Effect Parameters table
effectValue
Setting the attribute intensity, refer to the Effect Parameters table
resourcePath
Setting the resource path, refer to the Effect Parameters table
extraInfo
Setting other information, refer to the Effect Parameters table
Filters, Animated Stickers and Segmentation.

Since the configuration of Filters, Animated Stickers and Segmentation is primarily identical, the JSON for filters is used here for illustration. The fields downloadPath and resourceUri are added here.
Field
Description
downloadPath
If your filter material is downloaded from the network, then the configuration here is the location of your material stored locally after download, which is a relative path, and the full path is set in TEDownloader.h using basicPath+the path set here
resourceUri
If your material needs to be downloaded via network, configure the network address here, as in the third red box in the image above. However, if your filter material is local, configure the corresponding local address according to the figure above.
Makeup

In the Makeup, the makeupLutStrength field is added under extraInfo. This field is used to adjust the strength of the filter in the makeup material (if this makeup material supports adjusting the filter strength, configure it accordingly). This field can be referenced in the Effect Parameters table.

TEBeautyKit Method Descriptions

//Create a TEBeautyKit object with effectMode options: EFFECT_MODE_NORMAL (High-Performance Mode) and EFFECT_MODE_PRO (Default Mode).
+ (void)createXMagic:(EffectMode)effectMode onInitListener:(OnInitListener _Nullable )onInitListener;
//Create TEBeautyKit object, do not enable the High Performance Mode
+ (void)create:(OnInitListener _Nullable )onInitListener;
/**
Create TEBeautyKit object
isEnableHighPerformance: Whether to enable the High Performance Mode
When the High Performance Mode is enabled, the effect feature consumes fewer system CPU/GPU resources, reducing heating and lagging of the phone, making it more suitable for prolonged use on low-end devices.
Note: After enabling the High Performance Mode, the following effect options will be unavailable:
1. Eyes: Eye width, eye height, eye bag removal
2. Eyebrows: Angle, distance, height, length, thickness, eyebrow peak
3. Lips: Smile lip
4. Face: Slim face (natural, woman, man), chin tuck, wrinkle removal, smile lines removal. It is recommended to use "Face Shape" for comprehensive big eyes and slim face effect
*/
+ (void)create:(BOOL)isEnableHighPerformance onInitListener:(OnInitListener _Nullable )onInitListener;
// Effect Authentication
+ (void)setTELicense:(NSString *)url key:(NSString *)key completion:(callback _Nullable )completion;
// Setting effect object
- (void)setXMagicApi:(XMagic *_Nullable)xmagicApi;
// Mute Effect
- (void)setMute:(BOOL)isMute;
/** * Set the toggle of a certain feature * * @param featureName Values see XmagicConstant.FeatureName * @param enable true indicates enable, false indicates disable */
- (void)setFeatureEnableDisable:(NSString *_Nullable)featureName enable:(BOOL)enable;
/// Configure Frame Synchronization Mode
/// @isSync Indicates whether synchronization is enabled
/// @syncFrameCount The number of frames to synchronize. A value of -1 denotes no limit. If isSync is set to false, this parameter is irrelevant.
- (void)setSyncMode:(BOOL)isSync syncFrameCount:(int)syncFrameCount;
// Processing image beautification
- (UIImage *_Nullable)processUIImage:(UIImage *_Nullable)inputImage
imageWidth:(int)imageWidth
imageHeight:(int)imageHeight
needReset:(bool)needReset;
// Processing texture
- (YTProcessOutput *_Nullable)processTexture:(int)textureId
textureWidth:(int)textureWidth
textureHeight:(int)textureHeight
withOrigin:(YtLightImageOrigin)origin
withOrientation:(YtLightDeviceCameraOrientation)orientation;
// Processing CVPixelBufferRef
- (YTProcessOutput * _Nullable)processPixelData:(CVPixelBufferRef _Nullable )pixelData
pixelDataWidth:(int)pixelDataWidth
pixelDataHeight:(int)pixelDataHeight
withOrigin:(YtLightImageOrigin)origin
withOrientation:(YtLightDeviceCameraOrientation)orientation;
// Set effect
- (void)setEffect:(TESDKParam *_Nullable)sdkParam;
// Setting effect list
- (void)setEffectList:(NSArray<TESDKParam *>*_Nullable)sdkParamList;
//Is the Beauty Enhancement Mode Enabled
- (BOOL)isEnableEnhancedMode;
// Whether to enable the Enhanced Mode
- (void)enableEnhancedMode:(BOOL)enable;
// Access the current effect parameters
- (NSString *_Nullable)exportInUseSDKParam;
// Access saved effect parameters. Upon re-entering the Effect mode, calling setEffectList will restore the same effects.
- (NSMutableArray<TESDKParam *> *_Nonnull)getInUseSDKParamList;
// Restore the effect
- (void)onResume;
// Pause the effect
- (void)onPause;
// Destroy the effect
- (void)onDestroy;
// Access current texture image
- (void)exportCurrentTexture:(void (^_Nullable)(UIImage * _Nullable image))callback;
// Set the log
- (void)setLogLevel:(YtSDKLoggerLevel)level;
// Set AIDataListener
- (void)setAIDataListener:(id<TEBeautyKitAIDataListener> _Nullable)listener;
// Set TipsListener
- (void)setTipsListener:(id<TEBeautyKitTipsListener> _Nullable)listener;
// Save the effect parameters
- (void)saveEffectParam:(TESDKParam *_Nonnull)sdkParam;
// Delete a saved effect data
- (void)deleteEffectParam:(TESDKParam *_Nonnull)sdkParam;
// Clear saved effect parameters
- (void)clearEffectParam;

TEUIConfig Descriptions.

// Color of the following properties can be modified externally
// Background color of the effect panel
@property(nonatomic,strong)UIColor *panelBackgroundColor;
// Dividing 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;

/// Configure the beauty panel settings according to the beauty package options.
/// - Parameter panelLevel: Beauty Package
/// Beauty Package Types: A1_00,A1_01,A1_02,A1_03,A1_04,A1_05,A1_06,S1_00,S1_01,S1_02,S1_03,S1_04,S1_05,S1_06,S1_07
-(void)setPanelLevel:(TEPanelLevel)panelLevel;

/**
configure the effect parameters
beauty: Effect json path
beautyBody: Body shaping json path
lut: Filter json path
motion: Animated effects json path
makeup: Makeup json path
segmentation: Background segmentation json path
lightMakeup: The Path to Light and Elegant Makeup
*/
-(void)setTEPanelViewRes:(NSString *)beauty
beautyBody:(NSString *)beautyBody
lut:(NSString *)lut
motion:(NSString *)motion
makeup:(NSString *)makeup
segmentation:(NSString *)segmentation
lightMakeup:(NSString *)lightMakeup;

TEPanelView Description.

// Initialize the effect panel, fill in nil for abilityType and comboType.
- (instancetype)init:(NSString *)abilityType comboType:(NSString *)comboType;

@protocol TEPanelViewDelegate <NSObject>
// Callback after setting the effect
- (void)setEffect;
@end