@@ -72,10 +72,8 @@ BOOL CDlgBeautyEx2::OnInitDialog()
7272
7373 InitCtrlText ();
7474
75- // 暂时隐藏脸部塑形相关的UI控件
7675 HideFaceShapeControls ();
7776
78- // 如果引擎已经初始化,创建美颜资源
7977 if (m_initialize && *m_initialize && m_rtcEngine && *m_rtcEngine) {
8078 InitializeBeautyResources ();
8179 }
@@ -96,12 +94,10 @@ void CDlgBeautyEx2::InitializeBeautyResources()
9694 return ;
9795 }
9896
99- // 如果已经创建过,直接返回
10097 if (m_videoEffectObjectRef) {
10198 return ;
10299 }
103100
104- // 1. 启用扩展
105101 int ret = (*m_rtcEngine)->enableExtension (" agora_video_filters_clear_vision" , " clear_vision" , true );
106102 if (ret != 0 ) {
107103 CString strMsg;
@@ -110,22 +106,18 @@ void CDlgBeautyEx2::InitializeBeautyResources()
110106 return ;
111107 }
112108
113- // 2. 设置参数优化
114109 (*m_rtcEngine)->setParameters (" {\" rtc.video.yuvconverter_enable_hardware_buffer\" :true}" );
115110
116- // 3. 获取美颜资源路径
117111 CString strExePath = GetExePath ();
118112 CString strModelPath = strExePath + _T (" \\ beauty_agora\\ beauty_material.bundle\\ beauty_material_v2.0.0" );
119113
120- // 检查路径是否存在
121114 if (!PathFileExists (strModelPath)) {
122115 CString strMsg;
123116 strMsg.Format (_T (" Beauty resource path not exist: %s" ), strModelPath);
124117 AfxMessageBox (strMsg);
125118 return ;
126119 }
127120
128- // 4. 创建VideoEffectObject - 使用智能指针
129121 std::string modelPath = cs2utf8 (strModelPath);
130122 m_videoEffectObjectRef = (*m_rtcEngine)->createVideoEffectObject (
131123 modelPath.c_str (),
@@ -147,28 +139,25 @@ CString CDlgBeautyEx2::GetExePath()
147139 GetModuleFileName (NULL , szPath, MAX_PATH);
148140 CString strExePath = szPath;
149141 int nPos = strExePath.ReverseFind (' \\ ' );
150- return strExePath.Left (nPos); // 去掉exe文件名,得到目录路径
142+ return strExePath.Left (nPos);
151143}
152144
153145void CDlgBeautyEx2::CleanupBeautyResources ()
154146{
155147 if (m_videoEffectObjectRef && m_rtcEngine && *m_rtcEngine) {
156- // 禁用扩展
157148 (*m_rtcEngine)->enableExtension (
158149 " agora_video_filters_clear_vision" ,
159150 " clear_vision" ,
160151 false ,
161152 agora::media::PRIMARY_CAMERA_SOURCE
162153 );
163154
164- // 智能指针自动管理生命周期
165155 m_videoEffectObjectRef = nullptr ;
166156 }
167157}
168158
169159void CDlgBeautyEx2::OnClose ()
170160{
171- // 清理资源
172161 CleanupBeautyResources ();
173162
174163 if (m_beautyDlg) {
@@ -224,43 +213,42 @@ void CDlgBeautyEx2::InitCtrlData()
224213// set control text from config.
225214void CDlgBeautyEx2::InitCtrlText ()
226215{
227- // make up - 根据实际资源文件映射
228216 mDdBrowStyle .ResetContent ();
229- mDdBrowStyle .InsertString (0 , TEXT (" CLOSE" )); // 0 - 关闭
230- mDdBrowStyle .InsertString (1 , TEXT (" eyebrow001" )); // 1 - eyebrow001.txt
231- mDdBrowStyle .InsertString (2 , TEXT (" eyebrow002" )); // 2 - eyebrow002.txt
232- mDdBrowStyle .InsertString (3 , TEXT (" eyebrow003" )); // 3 - eyebrow003.txt
217+ mDdBrowStyle .InsertString (0 , TEXT (" CLOSE" ));
218+ mDdBrowStyle .InsertString (1 , TEXT (" eyebrow001" ));
219+ mDdBrowStyle .InsertString (2 , TEXT (" eyebrow002" ));
220+ mDdBrowStyle .InsertString (3 , TEXT (" eyebrow003" ));
233221
234222 mDdBrowColor .ResetContent ();
235223 mDdBrowColor .InsertString (0 , TEXT (" Brown" ));
236224 mDdBrowColor .InsertString (1 , TEXT (" Gray Brown" ));
237225 mDdBrowColor .InsertString (2 , TEXT (" Dark Brown" ));
238226
239227 mDdLashStyle .ResetContent ();
240- mDdLashStyle .InsertString (0 , TEXT (" CLOSE" )); // 0 - 关闭
241- mDdLashStyle .InsertString (1 , TEXT (" eyelash003" )); // 映射到3
242- mDdLashStyle .InsertString (2 , TEXT (" eyelash005" )); // 映射到5
228+ mDdLashStyle .InsertString (0 , TEXT (" CLOSE" ));
229+ mDdLashStyle .InsertString (1 , TEXT (" eyelash003" ));
230+ mDdLashStyle .InsertString (2 , TEXT (" eyelash005" ));
243231
244232 mDdLashColor .ResetContent ();
245233 mDdLashColor .InsertString (0 , TEXT (" Black" ));
246234 mDdLashColor .InsertString (1 , TEXT (" Brown" ));
247235 mDdLashColor .InsertString (2 , TEXT (" Blue" ));
248236
249237 mDdShadowStyle .ResetContent ();
250- mDdShadowStyle .InsertString (0 , TEXT (" CLOSE" )); // 0 - 关闭
251- mDdShadowStyle .InsertString (1 , TEXT (" eyeshadow001" )); // 映射到1
252- mDdShadowStyle .InsertString (2 , TEXT (" eyeshadow006" )); // 映射到6
238+ mDdShadowStyle .InsertString (0 , TEXT (" CLOSE" ));
239+ mDdShadowStyle .InsertString (1 , TEXT (" eyeshadow001" ));
240+ mDdShadowStyle .InsertString (2 , TEXT (" eyeshadow006" ));
253241
254242 mDdPupilStyle .ResetContent ();
255- mDdPupilStyle .InsertString (0 , TEXT (" CLOSE" )); // 0 - 关闭
256- mDdPupilStyle .InsertString (1 , TEXT (" facial002" )); // 映射到2
243+ mDdPupilStyle .InsertString (0 , TEXT (" CLOSE" ));
244+ mDdPupilStyle .InsertString (1 , TEXT (" facial002" ));
257245
258246 mDdBlushStyle .ResetContent ();
259- mDdBlushStyle .InsertString (0 , TEXT (" CLOSE" )); // 0 - 关闭
260- mDdBlushStyle .InsertString (1 , TEXT (" blush001" )); // 映射到1
261- mDdBlushStyle .InsertString (2 , TEXT (" blush002" )); // 映射到2
262- mDdBlushStyle .InsertString (3 , TEXT (" blush004" )); // 映射到4
263- mDdBlushStyle .InsertString (4 , TEXT (" blush009" )); // 映射到9
247+ mDdBlushStyle .InsertString (0 , TEXT (" CLOSE" ));
248+ mDdBlushStyle .InsertString (1 , TEXT (" blush001" ));
249+ mDdBlushStyle .InsertString (2 , TEXT (" blush002" ));
250+ mDdBlushStyle .InsertString (3 , TEXT (" blush004" ));
251+ mDdBlushStyle .InsertString (4 , TEXT (" blush009" ));
264252
265253 mDdBlushColor .ResetContent ();
266254 mDdBlushColor .InsertString (0 , TEXT (" Pink" ));
@@ -307,59 +295,45 @@ void CDlgBeautyEx2::InitCtrlText()
307295}
308296
309297void CDlgBeautyEx2::HideFaceShapeControls ()
310- {
311- // 隐藏脸部塑形相关的控件 - 使用实际存在的控件ID
312-
313- // 隐藏美颜塑形复选框
298+ {
314299 CWnd* pShapeCheckbox = GetDlgItem (IDC_CHECK_BEAUTY_SHAPE);
315300 if (pShapeCheckbox) {
316301 pShapeCheckbox->ShowWindow (SW_HIDE);
317302 }
318303
319- // 隐藏脸部塑形区域下拉框
320304 CWnd* pShapeAreaCombo = GetDlgItem (IDC_COMBO_FACE_SHAPE_AREA);
321305 if (pShapeAreaCombo) {
322306 pShapeAreaCombo->ShowWindow (SW_HIDE);
323307 }
324308
325- // 隐藏脸部塑形风格下拉框
326309 CWnd* pShapeStyleCombo = GetDlgItem (IDC_COMBO_FACE_SHAPE_STYLE);
327310 if (pShapeStyleCombo) {
328311 pShapeStyleCombo->ShowWindow (SW_HIDE);
329312 }
330313
331- // 隐藏塑形区域强度滑块
332314 CWnd* pShapeAreaIntensitySlider = GetDlgItem (IDC_SLIDER__SHAPE_AREA_INTENSITY);
333315 if (pShapeAreaIntensitySlider) {
334316 pShapeAreaIntensitySlider->ShowWindow (SW_HIDE);
335317 }
336318
337- // 隐藏塑形风格强度滑块
338319 CWnd* pShapeStyleIntensitySlider = GetDlgItem (IDC_SLIDER__SHAPE_STYLE_INTENSITY);
339320 if (pShapeStyleIntensitySlider) {
340321 pShapeStyleIntensitySlider->ShowWindow (SW_HIDE);
341322 }
342-
343- // 隐藏相关的静态文本标签(需要根据实际资源文件中的ID调整)
344- // 这些ID需要根据您的.rc资源文件中的实际定义来确定
345323}
346324
347325void CDlgBeautyEx2::SetBeauty ()
348326{
349- // 如果还没有创建VideoEffectObject,先创建
350327 if (!m_videoEffectObjectRef) {
351328 InitializeBeautyResources ();
352329 }
353330
354- // 检查是否创建成功
355331 if (!m_videoEffectObjectRef) {
356332 AfxMessageBox (_T (" VideoEffectObject not created successfully" ));
357333 return ;
358334 }
359335
360- // 只应用化妆效果,暂时不应用脸部塑形
361336 ApplyMakeupEffect ();
362- // ApplyFaceShapeEffect(); // 暂时注释掉
363337}
364338
365339void CDlgBeautyEx2::ApplyMakeupEffect ()
@@ -369,7 +343,6 @@ void CDlgBeautyEx2::ApplyMakeupEffect()
369343 }
370344
371345 try {
372- // 添加或更新化妆节点
373346 int ret = m_videoEffectObjectRef->addOrUpdateVideoEffect (
374347 static_cast <uint32_t >(agora::rtc::IVideoEffectObject::VIDEO_EFFECT_NODE_ID::STYLE_MAKEUP),
375348 " "
@@ -382,51 +355,43 @@ void CDlgBeautyEx2::ApplyMakeupEffect()
382355 return ;
383356 }
384357
385- // 启用化妆功能
386358 m_videoEffectObjectRef->setVideoEffectBoolParam (" makeup_options" , " enable_mu" , m_makeupOptions.enable_mu );
387359
388360 if (m_makeupOptions.enable_mu ) {
389- // // 打印下m_makeupOptions的所有参数
390- // CString strParams;
391- // strParams.Format(_T("browStyle: %d, browColor: %d, browStrength: %f, lashStyle: %d, lashColor: %d, lashStrength: %f, shadowStyle: %d, shadowStrength: %f, pupilStyle: %d, pupilStrength: %f, blushStyle: %d, blushColor: %d, blushStrength: %f, lipStyle: %d, lipColor: %d, lipStrength: %f"),
392- // m_makeupOptions.browStyle, m_makeupOptions.browColor, m_makeupOptions.browStrength,
393- // m_makeupOptions.lashStyle, m_makeupOptions.lashColor, m_makeupOptions.lashStrength,
394- // m_makeupOptions.shadowStyle, m_makeupOptions.shadowStrength,
395- // m_makeupOptions.pupilStyle, m_makeupOptions.pupilStrength,
396- // m_makeupOptions.blushStyle, m_makeupOptions.blushColor, m_makeupOptions.blushStrength,
397- // m_makeupOptions.lipStyle, m_makeupOptions.lipColor, m_makeupOptions.lipStrength
398- // );
399- // AfxMessageBox(strParams);
361+ CString strParams;
362+ strParams.Format (_T (" browStyle: %d, browColor: %d, browStrength: %f, lashStyle: %d, lashColor: %d, lashStrength: %f, shadowStyle: %d, shadowStrength: %f, pupilStyle: %d, pupilStrength: %f, blushStyle: %d, blushColor: %d, blushStrength: %f, lipStyle: %d, lipColor: %d, lipStrength: %f\n " ),
363+ m_makeupOptions.browStyle , m_makeupOptions.browColor , m_makeupOptions.browStrength ,
364+ m_makeupOptions.lashStyle , m_makeupOptions.lashColor , m_makeupOptions.lashStrength ,
365+ m_makeupOptions.shadowStyle , m_makeupOptions.shadowStrength ,
366+ m_makeupOptions.pupilStyle , m_makeupOptions.pupilStrength ,
367+ m_makeupOptions.blushStyle , m_makeupOptions.blushColor , m_makeupOptions.blushStrength ,
368+ m_makeupOptions.lipStyle , m_makeupOptions.lipColor , m_makeupOptions.lipStrength
369+ );
370+ OutputDebugString (strParams);
400371
401- // 眉毛参数 - 使用映射后的值
402372 int browStyleId = MapUIToResourceId (_T (" eyebrow" ), m_makeupOptions.browStyle );
403373 m_videoEffectObjectRef->setVideoEffectIntParam (" makeup_options" , " browStyle" , browStyleId);
404374 m_videoEffectObjectRef->setVideoEffectIntParam (" makeup_options" , " browColor" , m_makeupOptions.browColor );
405375 m_videoEffectObjectRef->setVideoEffectFloatParam (" makeup_options" , " browStrength" , m_makeupOptions.browStrength );
406376
407- // 睫毛参数 - 使用映射后的值
408377 int lashStyleId = MapUIToResourceId (_T (" eyelash" ), m_makeupOptions.lashStyle );
409378 m_videoEffectObjectRef->setVideoEffectIntParam (" makeup_options" , " lashStyle" , lashStyleId);
410379 m_videoEffectObjectRef->setVideoEffectIntParam (" makeup_options" , " lashColor" , m_makeupOptions.lashColor );
411380 m_videoEffectObjectRef->setVideoEffectFloatParam (" makeup_options" , " lashStrength" , m_makeupOptions.lashStrength );
412381
413- // 眼影参数 - 使用映射后的值
414382 int shadowStyleId = MapUIToResourceId (_T (" eyeshadow" ), m_makeupOptions.shadowStyle );
415383 m_videoEffectObjectRef->setVideoEffectIntParam (" makeup_options" , " shadowStyle" , shadowStyleId);
416384 m_videoEffectObjectRef->setVideoEffectFloatParam (" makeup_options" , " shadowStrength" , m_makeupOptions.shadowStrength );
417385
418- // 美瞳参数 - 使用映射后的值
419386 int pupilStyleId = MapUIToResourceId (_T (" pupil" ), m_makeupOptions.pupilStyle );
420387 m_videoEffectObjectRef->setVideoEffectIntParam (" makeup_options" , " pupilStyle" , pupilStyleId);
421388 m_videoEffectObjectRef->setVideoEffectFloatParam (" makeup_options" , " pupilStrength" , m_makeupOptions.pupilStrength );
422389
423- // 腮红参数 - 使用映射后的值
424390 int blushStyleId = MapUIToResourceId (_T (" blush" ), m_makeupOptions.blushStyle );
425391 m_videoEffectObjectRef->setVideoEffectIntParam (" makeup_options" , " blushStyle" , blushStyleId);
426392 m_videoEffectObjectRef->setVideoEffectIntParam (" makeup_options" , " blushColor" , m_makeupOptions.blushColor );
427393 m_videoEffectObjectRef->setVideoEffectFloatParam (" makeup_options" , " blushStrength" , m_makeupOptions.blushStrength );
428394
429- // 口红参数 - 直接使用UI值
430395 m_videoEffectObjectRef->setVideoEffectIntParam (" makeup_options" , " lipStyle" , m_makeupOptions.lipStyle );
431396 m_videoEffectObjectRef->setVideoEffectIntParam (" makeup_options" , " lipColor" , m_makeupOptions.lipColor );
432397 m_videoEffectObjectRef->setVideoEffectFloatParam (" makeup_options" , " lipStrength" , m_makeupOptions.lipStrength );
@@ -443,7 +408,6 @@ void CDlgBeautyEx2::ApplyFaceShapeEffect()
443408 }
444409
445410 try {
446- // 添加或更新脸部塑形节点 - 应该使用BEAUTY节点而非FACE_SHAPE
447411 int ret = m_videoEffectObjectRef->addOrUpdateVideoEffect (
448412 static_cast <uint32_t >(agora::rtc::IVideoEffectObject::VIDEO_EFFECT_NODE_ID::BEAUTY),
449413 " "
@@ -453,14 +417,11 @@ void CDlgBeautyEx2::ApplyFaceShapeEffect()
453417 return ;
454418 }
455419
456- // 应用脸部塑形参数 - 根据文档修正选项组名称
457420 if (m_faceShapeAreaOptions.shapeArea != FaceShapeAreaOptions::FACE_SHAPE_AREA_NONE) {
458421 std::string paramName = GetFaceShapeAreaParamName (m_faceShapeAreaOptions.shapeArea );
459- // 注意:这里使用具体的参数名而不是face_shape选项组
460422 m_videoEffectObjectRef->setVideoEffectFloatParam (" face_buffing_option" , paramName.c_str (), m_faceShapeAreaOptions.shapeIntensity / 100 .0f );
461423 }
462424
463- // 应用整体脸型风格 - 根据文档使用face_shape_beauty_option
464425 if (m_faceShapeBeautyOptions.shapeStyle != FaceShapeBeautyOptions::FACE_SHAPE_BEAUTY_STYLE_FEMALE) {
465426 m_videoEffectObjectRef->setVideoEffectBoolParam (" face_shape_beauty_option" , " enable" , true );
466427 m_videoEffectObjectRef->setVideoEffectIntParam (" face_shape_beauty_option" , " intensity" , static_cast <int >(m_faceShapeBeautyOptions.styleIntensity ));
@@ -470,7 +431,6 @@ void CDlgBeautyEx2::ApplyFaceShapeEffect()
470431 }
471432}
472433
473- // 辅助方法:将脸部区域枚举转换为参数名称
474434std::string CDlgBeautyEx2::GetFaceShapeAreaParamName (FaceShapeAreaOptions::FACE_SHAPE_AREA area)
475435{
476436 switch (area) {
@@ -653,33 +613,27 @@ void CDlgBeautyEx2::OnCbnSelchangeComboFaceShapeStyle()
653613 SetBeauty ();
654614}
655615
656- // 添加映射函数
657616int CDlgBeautyEx2::MapUIToResourceId (const CString& resourceType, int uiIndex)
658617{
659618 if (resourceType == _T (" eyebrow" )) {
660- // 眉毛: 0->0, 1->1, 2->2, 3->3
661619 return uiIndex;
662620 }
663621 else if (resourceType == _T (" eyelash" )) {
664- // 睫毛: 0->0, 1->3, 2->5
665622 int lashMapping[] = {0 , 3 , 5 };
666623 return (uiIndex < 3 ) ? lashMapping[uiIndex] : 0 ;
667624 }
668625 else if (resourceType == _T (" eyeshadow" )) {
669- // 眼影: 0->0, 1->1, 2->6
670626 int shadowMapping[] = {0 , 1 , 6 };
671627 return (uiIndex < 3 ) ? shadowMapping[uiIndex] : 0 ;
672628 }
673629 else if (resourceType == _T (" blush" )) {
674- // 腮红: 0->0, 1->1, 2->2, 3->4, 4->9
675630 int blushMapping[] = {0 , 1 , 2 , 4 , 9 };
676631 return (uiIndex < 5 ) ? blushMapping[uiIndex] : 0 ;
677632 }
678633 else if (resourceType == _T (" pupil" )) {
679- // 美瞳: 0->0, 1->2 (假设使用facial002)
680634 int pupilMapping[] = {0 , 2 };
681635 return (uiIndex < 2 ) ? pupilMapping[uiIndex] : 0 ;
682636 }
683637
684- return uiIndex; // 默认直接映射
638+ return uiIndex;
685639}
0 commit comments