LPBeautySetVC.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. //
  2. // LPBeautySetVC.m
  3. // zhimi
  4. //
  5. // Created by 张灿 on 2019/1/17.
  6. // Copyright © 2019年 caiPro. All rights reserved.
  7. //
  8. #import "LPBeautySetVC.h"
  9. #import "FUCamera.h"
  10. #import <PixelFree/SMPixelFree.h>
  11. #import "PFAPIDemoBar.h"
  12. #import "PFDateHandle.h"
  13. #import "FUOpenGLView.h"
  14. @interface LPBeautySetVC()<FUCameraDelegate,FUCameraDataSource,PFAPIDemoBarDelegate>
  15. {
  16. dispatch_semaphore_t signal;
  17. dispatch_semaphore_t semaphore;
  18. UIView *localCameraVideoView;
  19. }
  20. @property (nonatomic, strong) FUCamera *mCamera ;
  21. @property (nonatomic,assign) BOOL needSave; //是否需要保存
  22. @property (nonatomic,strong) UIView* botView;
  23. @property (nonatomic,strong) UIButton* btnSwitch;
  24. @property (nonatomic,assign) BOOL beautyOpen;//美颜是否开启
  25. @property (strong, nonatomic) FUOpenGLView *renderView;
  26. @property(nonatomic, strong) PFAPIDemoBar *beautyEditView;
  27. @property (nonatomic, strong) NSUserDefaults *def;
  28. @property (nonatomic,strong) SMPixelFree *mPixelFree;
  29. @property (nonatomic,assign)BOOL clickCompare;
  30. @property (nonatomic,strong) UILabel *titleLabel;
  31. @end
  32. @implementation LPBeautySetVC
  33. - (BOOL)prefersStatusBarHidden
  34. {
  35. return YES;
  36. }
  37. -(FUCamera *)mCamera {
  38. if (!_mCamera) {
  39. _mCamera = [[FUCamera alloc] init];
  40. _mCamera.delegate = self ;
  41. // _mCamera.dataSource = self;
  42. }
  43. return _mCamera ;
  44. }
  45. -(FUOpenGLView *)renderView {
  46. if (!_renderView) {
  47. _renderView = [[FUOpenGLView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
  48. }
  49. return _renderView ;
  50. }
  51. - (void)viewWillAppear:(BOOL)animated{
  52. [super viewWillAppear:animated];
  53. [UIApplication sharedApplication].idleTimerDisabled = YES;
  54. [self.mCamera startCapture];
  55. }
  56. - (void)viewWillDisappear:(BOOL)animated{
  57. [super viewWillDisappear:animated];
  58. [UIApplication sharedApplication].idleTimerDisabled = YES;
  59. [self.mCamera resetFocusAndExposureModes];
  60. [self.mCamera stopCapture];
  61. }
  62. -(void)viewDidLayoutSubviews {
  63. [super viewDidLayoutSubviews];
  64. // 适配 iPhone X
  65. }
  66. -(void)dealloc{
  67. NSLog(@"dealloc---");
  68. }
  69. -(void)viewDidDisappear:(BOOL)animated {
  70. [super viewDidDisappear:animated];
  71. }
  72. - (void)viewDidLoad {
  73. [super viewDidLoad];
  74. self.view.backgroundColor = [UIColor blackColor];
  75. [self.view addSubview:self.renderView];
  76. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchScreenAction:)];
  77. [self.renderView addGestureRecognizer:tap];
  78. self.def = [NSUserDefaults standardUserDefaults];
  79. [self initPixelFree];
  80. [self setDefaultParam];
  81. [self.mCamera setExposureValue:0];
  82. [self.mCamera startCapture];
  83. signal = dispatch_semaphore_create(1);
  84. [self addObserver];
  85. [self setupUI];
  86. //v1.1.2 增加相机权限判断
  87. [UCAuthorityManager cameraAuthority:^{
  88. } denied:^{
  89. UIAlertController *systemAlert = [UIAlertController alertControllerWithTitle:@"请在iphone的“设置-隐私-相机”选项中,允许APP访问您的相机。" message:nil preferredStyle:UIAlertControllerStyleAlert];
  90. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"现在去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  91. if ([[UIDevice currentDevice].systemVersion floatValue] < 10.0)
  92. {
  93. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  94. }
  95. else
  96. {
  97. // 去系统设置页面
  98. if (@available(iOS 10.0, *)) {
  99. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  100. } else {
  101. // Fallback on earlier versions
  102. }
  103. }
  104. }];
  105. UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
  106. [systemAlert addAction:cancelAction];
  107. [systemAlert addAction:action];
  108. dispatch_async(dispatch_get_main_queue(), ^{
  109. [self presentViewController: systemAlert animated: YES completion: nil];
  110. });
  111. }];
  112. }
  113. - (void)touchScreenAction:(UITapGestureRecognizer *)tap {
  114. if (tap.view == self.renderView) {
  115. self.botView.hidden = NO;
  116. self.beautyEditView.hidden = YES;
  117. }
  118. }
  119. - (void)setupUI{
  120. self.beautyOpen = YES;
  121. self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, StatusBarHeight + 12.0f, KScreenWidth, 20)];
  122. self.titleLabel.textAlignment = NSTextAlignmentCenter ;
  123. self.titleLabel.textColor = [UIColor whiteColor];
  124. self.titleLabel.text = @"澜极美颜设置";
  125. self.titleLabel.font = [UIFont boldSystemFontOfSize:20];
  126. [self.view addSubview:self.titleLabel];
  127. UIButton* backAction = [[UIButton alloc]initWithFrame:CGRectMake(14, StatusBarHeight + 10.0f, 24, 24)];
  128. [backAction setImage:[UIImage imageNamed:@"vqu_images_return_white"] forState:(UIControlStateNormal)];
  129. [backAction setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  130. backAction.adjustsImageWhenHighlighted = NO;
  131. [backAction addTarget:self action:@selector(backClick) forControlEvents:(UIControlEventTouchUpInside)];
  132. [self.view addSubview:backAction];
  133. UIButton* beautSwiBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth-62-14, StatusBarHeight + 12.0f, 62, 20)];
  134. if (Is_iPhoneX) {
  135. // backAction.frame = CGRectMake(KScreenWidth-68-15, 45, 68, 32);
  136. }
  137. [beautSwiBtn setImage:[UIImage imageNamed:@"vqu_images_beauty_open"] forState:(UIControlStateSelected)];
  138. [beautSwiBtn setImage:[UIImage imageNamed:@"vqu_images_beauty_off"] forState:(UIControlStateNormal)];
  139. beautSwiBtn.adjustsImageWhenHighlighted = NO;
  140. [beautSwiBtn addTarget:self action:@selector(beautSwiClick:) forControlEvents:(UIControlEventTouchUpInside)];
  141. beautSwiBtn.selected = self.beautyOpen;
  142. self.btnSwitch = beautSwiBtn;
  143. [self.view addSubview:beautSwiBtn];
  144. UIView* botView = [[UIView alloc]initWithFrame:CGRectMake(0, KScreenHeight-120, KScreenWidth, 70)];
  145. self.botView = botView;
  146. [self.view addSubview:botView];
  147. UIButton* beautSaveBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth/2-35, 0, 70, 70)];
  148. [beautSaveBtn setImage:[UIImage imageNamed:@"vqu_images_beauty_save"] forState:(UIControlStateNormal)];
  149. beautSaveBtn.adjustsImageWhenHighlighted = NO;
  150. [beautSaveBtn addTarget:self action:@selector(beautSave) forControlEvents:(UIControlEventTouchUpInside)];
  151. [self.botView addSubview:beautSaveBtn];
  152. UIButton* beautSetBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth/4-45, 8, 54, 54)];
  153. [beautSetBtn setImage:[UIImage imageNamed:@"vqu_images_beauty_be"] forState:(UIControlStateNormal)];
  154. beautSetBtn.adjustsImageWhenHighlighted = NO;
  155. [beautSetBtn addTarget:self action:@selector(beautSetClick) forControlEvents:(UIControlEventTouchUpInside)];
  156. [self.botView addSubview:beautSetBtn];
  157. UIButton* beautChangeBtn= [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth*3/4-10, 8, 54, 54)];
  158. [beautChangeBtn setImage:[UIImage imageNamed:@"vqu_images_beauty_switch"] forState:(UIControlStateNormal)];
  159. beautChangeBtn.adjustsImageWhenHighlighted = NO;
  160. [beautChangeBtn addTarget:self action:@selector(changeCamera:) forControlEvents:(UIControlEventTouchUpInside)];
  161. [self.botView addSubview:beautChangeBtn];
  162. }
  163. - (void)beautSetClick{
  164. self.botView.hidden = YES;
  165. self.beautyEditView.hidden = NO;
  166. }
  167. - (void)beautSwiClick:(UIButton *)sender {
  168. sender.selected = !sender.selected;
  169. self.beautyOpen = sender.selected;
  170. if (sender.selected) {
  171. self.needSave = YES;
  172. }else{
  173. self.needSave = YES;
  174. }
  175. }
  176. - (void)changeCamera:(UIButton *)sender {
  177. sender.userInteractionEnabled = NO ;
  178. dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC);
  179. dispatch_after(delayTime, dispatch_get_main_queue(), ^(void){
  180. sender.userInteractionEnabled = YES ;
  181. });
  182. [self.mCamera changeCameraInputDeviceisFront:sender.selected];
  183. sender.selected = !sender.selected ;
  184. }
  185. - (void)beautSave{
  186. // 归档
  187. NSData *shapeParamsData = [NSKeyedArchiver archivedDataWithRootObject:_beautyEditView.shapeParams];
  188. NSData *skinParamsData = [NSKeyedArchiver archivedDataWithRootObject:_beautyEditView.skinParams];
  189. NSUserDefaults*userDefaults = [NSUserDefaults standardUserDefaults];
  190. [userDefaults setInteger:_beautyEditView.oneKeyType forKey:@"oneKeyType"];
  191. [userDefaults setInteger:_beautyEditView.filterIndex forKey:@"filtersUseIndex"];;
  192. [userDefaults synchronize];
  193. // 写本地
  194. [self writeData:shapeParamsData fileName:@"shapeParamsData"];
  195. [self writeData:skinParamsData fileName:@"skinParamsData"];
  196. [ZCHUDHelper showTitle:@"保存成功"];
  197. [self back];
  198. }
  199. - (void)backClick{
  200. if (self.needSave) {
  201. //弹窗保存美颜设置
  202. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"保存设置" message:@"保存当前美颜设置,视频中直接使用" preferredStyle:UIAlertControllerStyleAlert];
  203. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  204. [self back];
  205. }];
  206. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"保存" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  207. [self.navigationController popToRootViewControllerAnimated:NO];
  208. [self beautSave];
  209. }];
  210. [alertController addAction:cancelAction];
  211. [alertController addAction:okAction];
  212. [self presentViewController:alertController animated:YES completion:nil];
  213. }else{
  214. [self back];
  215. }
  216. }
  217. - (void)back{
  218. dispatch_semaphore_wait(signal, DISPATCH_TIME_FOREVER);
  219. [self.mCamera stopCapture];
  220. UIViewController *presenting = self.presentingViewController;
  221. if(presenting){
  222. [self dismissViewControllerAnimated:YES completion:nil];
  223. }else{
  224. [self.navigationController popViewControllerAnimated:YES];
  225. }
  226. dispatch_semaphore_signal(signal);
  227. }
  228. #pragma mark --- FUCameraDelegate
  229. -(void)didOutputVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer {
  230. CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) ;
  231. if (self.beautyOpen) {
  232. [_mPixelFree processWithBuffer:pixelBuffer rotationMode:PFRotationMode0];
  233. }
  234. [self.renderView displayPixelBuffer:pixelBuffer withLandmarks:NULL count:0 MAX:YES];
  235. }
  236. -(void)demoBarDidShowTopView:(BOOL)shown {
  237. //是否显示上半部分
  238. }
  239. #pragma mark --- Observer
  240. - (void)addObserver{
  241. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willResignActive) name:UIApplicationWillResignActiveNotification object:nil];
  242. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
  243. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
  244. }
  245. - (void)willResignActive
  246. {
  247. if (self.navigationController.visibleViewController == self) {
  248. [_mCamera stopCapture];
  249. }
  250. }
  251. - (void)willEnterForeground
  252. {
  253. if (self.navigationController.visibleViewController == self) {
  254. [_mCamera startCapture];
  255. }
  256. }
  257. - (void)didBecomeActive
  258. {
  259. if (self.navigationController.visibleViewController == self) {
  260. [_mCamera startCapture];
  261. }
  262. }
  263. - (void)didReceiveMemoryWarning {
  264. [super didReceiveMemoryWarning];
  265. }
  266. #pragma mark 澜极美颜--start
  267. -(PFAPIDemoBar *)beautyEditView {
  268. if (!_beautyEditView) {
  269. _beautyEditView = [[PFAPIDemoBar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 280, self.view.frame.size.width, 280)];
  270. _beautyEditView.mDelegate = self;
  271. }
  272. return _beautyEditView ;
  273. }
  274. -(void)comparisonButtonDidClick:(BOOL)state{
  275. self.clickCompare = state;
  276. }
  277. -(void)writeData:(NSData *)data fileName:(NSString *)fileName{
  278. NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  279. NSString *documentDirectory = [documentDirectories objectAtIndex:0];
  280. // 获取目标文件的完整路径
  281. NSString *filePath = [documentDirectory stringByAppendingPathComponent:fileName];
  282. // [[NSFileManager defaultManager] fileExistsAtPath:filePath];
  283. // 创建文件并覆盖写入数据
  284. BOOL success = [[NSFileManager defaultManager] createFileAtPath:filePath
  285. contents:data
  286. attributes:nil];
  287. if (success) {
  288. NSLog(@"数据写入成功");
  289. } else {
  290. NSLog(@"数据写入失败");
  291. }
  292. }
  293. -(NSData *)readDatafileName:(NSString *)fileName{
  294. NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  295. NSString *documentDirectory = [documentDirectories objectAtIndex:0];
  296. // 获取目标文件的完整路径
  297. NSString *filePath = [documentDirectory stringByAppendingPathComponent:fileName];
  298. NSData *data = [NSData dataWithContentsOfFile:filePath];
  299. return data;
  300. }
  301. -(void)initPixelFree{
  302. NSString *face_FiltePath = [[NSBundle mainBundle] pathForResource:@"filter_model.bundle" ofType:nil];
  303. NSString *authFile = [[NSBundle mainBundle] pathForResource:@"pixelfreeAuth.lic" ofType:nil];
  304. self.mPixelFree = [[SMPixelFree alloc] initWithProcessContext:nil srcFilterPath:face_FiltePath authFile:authFile];
  305. [self.view addSubview:self.beautyEditView];
  306. self.beautyEditView.hidden = YES;
  307. }
  308. -(void)setDefaultParam{
  309. NSArray<PFBeautyParam *>* defaultData = [PFDateHandle setupShapData];
  310. NSArray<PFBeautyParam *>* defaultSkinData = [PFDateHandle setupSkinData];
  311. NSArray<PFBeautyParam *>* defaultfiltersData = [PFDateHandle setupFilterData];
  312. NSArray<PFBeautyParam *>* defaultfaceData = [PFDateHandle setupFaceType];
  313. // 读本地缓存
  314. NSData *data = [self readDatafileName:@"shapeParamsData"];
  315. if (data) {
  316. defaultData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  317. }
  318. data = [self readDatafileName:@"skinParamsData"];
  319. if (data) {
  320. defaultSkinData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  321. }
  322. data = [self readDatafileName:@"filtersParamsData"];
  323. if (data) {
  324. defaultfiltersData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  325. }
  326. data = [self readDatafileName:@"oneKeyParamsData"];
  327. if (data) {
  328. defaultfaceData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  329. }
  330. // 更新 UI
  331. self.beautyEditView.shapeParams = defaultData;
  332. self.beautyEditView.skinParams = defaultSkinData;
  333. self.beautyEditView.filtersParams = defaultfiltersData;
  334. self.beautyEditView.faceTypeParams = defaultfaceData;
  335. NSUserDefaults*userDefaults = [NSUserDefaults standardUserDefaults];
  336. int oneKeyType = (int)[userDefaults integerForKey:@"oneKeyType"];
  337. int filtersIndex = (int)[userDefaults integerForKey:@"filtersUseIndex"];
  338. self.beautyEditView.oneKeyType = oneKeyType;
  339. self.beautyEditView.filterIndex = filtersIndex;
  340. [self.beautyEditView updateDemoBar];
  341. // 更新 SDK 设置
  342. for (PFBeautyParam *param in defaultData) {
  343. [self filterValueChange:param];
  344. }
  345. for (PFBeautyParam *param in defaultSkinData) {
  346. [self filterValueChange:param];
  347. }
  348. PFBeautyParam *param = defaultfaceData[oneKeyType];
  349. [self filterValueChange:param];
  350. param = defaultfiltersData[filtersIndex];
  351. [self filterValueChange:param];
  352. }
  353. -(void)filterValueChange:(PFBeautyParam *)param{
  354. CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
  355. float value = param.mValue;
  356. if(param.type == FUDataTypeBeautify){
  357. if ([param.mParam isEqualToString:@"face_EyeStrength"]) {
  358. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_EyeStrength value:&value];
  359. }
  360. if ([param.mParam isEqualToString:@"face_thinning"]) {
  361. float aa = param.mValue;
  362. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_thinning value:&value];
  363. }
  364. if ([param.mParam isEqualToString:@"face_narrow"]) {
  365. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_narrow value:&value];
  366. }
  367. if ([param.mParam isEqualToString:@"face_chin"]) {
  368. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_chin value:&value];
  369. }
  370. if ([param.mParam isEqualToString:@"face_V"]) {
  371. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_V value:&value];
  372. }
  373. if ([param.mParam isEqualToString:@"face_small"]) {
  374. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_small value:&value];
  375. }
  376. if ([param.mParam isEqualToString:@"face_nose"]) {
  377. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_nose value:&value];
  378. }
  379. if ([param.mParam isEqualToString:@"face_forehead"]) {
  380. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_forehead value:&value];
  381. }
  382. if ([param.mParam isEqualToString:@"face_mouth"]) {
  383. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_mouth value:&value];
  384. }
  385. if ([param.mParam isEqualToString:@"face_philtrum"]) {
  386. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_philtrum value:&value];
  387. }
  388. if ([param.mParam isEqualToString:@"face_long_nose"]) {
  389. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_long_nose value:&value];
  390. }
  391. if ([param.mParam isEqualToString:@"face_eye_space"]) {
  392. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_eye_space value:&value];
  393. }
  394. if ([param.mParam isEqualToString:@"face_smile"]) {
  395. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_smile value:&value];
  396. }
  397. if ([param.mParam isEqualToString:@"face_eye_rotate"]) {
  398. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_eye_rotate value:&value];
  399. }
  400. if ([param.mParam isEqualToString:@"face_canthus"]) {
  401. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_canthus value:&value];
  402. }
  403. if ([param.mParam isEqualToString:@"runddy"]) {
  404. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceRuddyStrength value:&value];
  405. }
  406. if ([param.mParam isEqualToString:@"writen"]) {
  407. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceWhitenStrength value:&value];
  408. }
  409. if ([param.mParam isEqualToString:@"blur"]) {
  410. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceBlurStrength value:&value];
  411. }
  412. if ([param.mParam isEqualToString:@"sharpen"]) {
  413. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceSharpenStrength value:&value];
  414. }
  415. if ([param.mParam isEqualToString:@"newWhitenStrength"]) {
  416. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceM_newWhitenStrength value:&value];
  417. }
  418. if ([param.mParam isEqualToString:@"qualityStrength"]) {
  419. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceH_qualityStrength value:&value];
  420. }
  421. }
  422. if (param.type == FUDataTypeFilter) {
  423. const char *aaa = [param.mParam UTF8String];
  424. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterName value:(void *)aaa];
  425. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterStrength value:&value];
  426. }
  427. if (param.type == FUDataTypeStickers) {
  428. if([param.mParam isEqualToString:@"origin"]){
  429. [self.mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterSticker2DFilter value:NULL];
  430. } else{
  431. // NSString *path = [[NSBundle mainBundle] pathForResource:@"Stickers" ofType:nil];
  432. // NSString *currentFolder = [path stringByAppendingPathComponent:param.mParam];
  433. // const char *aaa = [currentFolder UTF8String];
  434. // [self.mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterSticker2DFilter value:(void *)aaa];
  435. NSString *name = [NSString stringWithFormat:@"%@.bundle",param.mParam];
  436. NSString *paths = [[NSBundle mainBundle] pathForResource:name ofType:nil];
  437. [self.mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterSticker2DFilter value:(void *)[paths UTF8String]];
  438. }
  439. }
  440. if (param.type == FUDataTypeOneKey) {
  441. if ([param.mTitle isEqualToString:@"origin"]) {
  442. int value = PFBeautyTypeOneKeyNormal;
  443. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  444. }
  445. if ([param.mTitle isEqualToString:@"自然"]) {
  446. int value = PFBeautyTypeOneKeyNatural;
  447. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  448. }
  449. if ([param.mTitle isEqualToString:@"可爱"]) {
  450. int value = PFBeautyTypeOneKeyCute;
  451. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  452. }
  453. if ([param.mTitle isEqualToString:@"女神"]) {
  454. int value = PFBeautyTypeOneKeyGoddess;
  455. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  456. }
  457. if ([param.mTitle isEqualToString:@"白净"]) {
  458. int value = PFBeautyTypeOneKeyFair;
  459. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  460. }
  461. }
  462. }
  463. -(void)bottomDidChange:(int)index{
  464. if (index != 0 && _beautyEditView.oneKeyType != PFBeautyTypeOneKeyNormal) {
  465. int value = PFBeautyTypeOneKeyNormal;
  466. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  467. [self showDelayedAlert];
  468. _beautyEditView.oneKeyType = PFBeautyTypeOneKeyNormal;
  469. }
  470. }
  471. - (void)showDelayedAlert {
  472. // 创建 UIAlertController
  473. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"一键美颜已关闭" preferredStyle:UIAlertControllerStyleAlert];
  474. dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC));
  475. dispatch_after(delay, dispatch_get_main_queue(), ^{
  476. [alertController dismissViewControllerAnimated:YES completion:nil];
  477. });
  478. [self presentViewController:alertController animated:YES completion:nil];
  479. }
  480. #pragma mark 澜极美颜--end
  481. @end