> ## Documentation Index
> Fetch the complete documentation index at: https://docs.facebetter.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Implementar belleza

> Integra Facebetter SDK 2.0 en Linux con la API C++

<Note>
  SDK **2.0.0**. Misma API C++ que Windows (namespace `facebetter`). Enumeraciones: [Enumeraciones de parámetros](/es/intro/makeup). Autenticación: [Autenticación y licencia](/es/intro/license).
</Note>

En Linux, Facebetter es `libfacebetter.so` más `facebetter/*.h`. Esta guía sigue el [demo de escritorio C++](https://github.com/pixpark/facebetter-sdk) (`demo/cpp`). Para compilar el propio SDK, usa `./scripts/build_linux.sh` o CMake en `build/linux`.

## Incluir headers

```cpp theme={null}
#include <facebetter/beauty_effect_engine.h>
#include <facebetter/beauty_params.h>
#include <facebetter/image_frame.h>
#include <facebetter/type_defines.h>

using namespace facebetter;
using namespace facebetter::beauty_params;
```

## Enlace CMake

```cmake theme={null}
target_include_directories(your_target PRIVATE /path/to/sdk/include)
target_link_libraries(your_target PRIVATE
    /path/to/sdk/lib/libfacebetter.so
    GL
)
```

En runtime, configura `LD_LIBRARY_PATH`, copia `libfacebetter.so` junto al binario o instálalo con `ldconfig`.

## Flujo de integración

```
SetLogConfig → Create(EngineConfig) → set effects → ProcessImage → render
```

No hay un paso de activar tipos. Intensidad `0` desactiva un efecto.

***

## 1. Configurar logging (opcional)

Llama **antes** de `Create`.

```cpp theme={null}
LogConfig log_cfg;
log_cfg.console_enabled = true;
log_cfg.file_enabled = false;
log_cfg.level = LogLevel::Info;
BeautyEffectEngine::SetLogConfig(log_cfg);
```

***

## 2. Crear el motor

En escritorio **debes** configurar `resource_path` al **archivo** `resource.fbd`.

**Prioridad de autenticación:** un `license_token` no vacío (token / JSON `{token}` / `.lic`) gana; si no, `app_id` + `app_key` v2 en línea.

```cpp theme={null}
EngineConfig cfg;
cfg.app_id = "your_app_id";
cfg.app_key = "your_app_key";
cfg.resource_path = "resource/resource.fbd";  // path to the .fbd file
cfg.external_context = false;

// cfg.license_token = "/* license token, {token} JSON, or .lic contents */";

auto engine = BeautyEffectEngine::Create(cfg);
if (!engine) {
    return -1;
}
```

<Warning>
  `resource_path` debe ser el archivo `resource.fbd`, no una carpeta. En producción prefiera una ruta absoluta.
</Warning>

***

## 3. Configurar parámetros de belleza

Piel / maquillaje `[0.0, 1.0]`. Remodelado **`[-1.0, 1.0]`**. Enumeraciones completas: [Enumeraciones de parámetros](/es/intro/makeup).

```cpp theme={null}
engine->SetSmoothing(0.5f);
engine->SetSmoothingStyle(SmoothingStyle::Natural);
engine->SetWhitening(0.3f);
engine->SetWhiteningStyle(WhiteningStyle::ColdWhite);
engine->SetSharpening(0.2f);
engine->SetRosiness(0.2f);
engine->SetBeautySkinOnly(true);

engine->SetReshape(Reshape::FaceThin, 0.4f);
engine->SetReshape(Reshape::EyeSize, 0.3f);

engine->AddResourcePack("resource/resource_body.fbd");  // or place resource_body.fbd next to resource.fbd
engine->SetBodyReshape(BodyReshape::WaistSlim, 0.4f);
engine->SetBodyReshape(BodyReshape::LegStretch, 0.3f);
engine->SetBodyReshape(BodyReshape::TorsoLong, 0.3f);

engine->SetLipstick(0.6f);
engine->SetLipstickColor(LipstickColor::Rouge);
engine->SetBlush(0.4f);
engine->SetBlushStyle(BlushStyle::SunKissed);
engine->SetBlushColor(BlushColor::CoralPink);
engine->SetContour(0.5f);
engine->SetContourStyle(ContourStyle::Natural);
```

El mismo patrón para sombra de ojos, delineador, cejas, pestañas y pupila.

***

## 4. Filtros, stickers y fondo virtual

Pasa una **ruta** o **bytes**.

```cpp theme={null}
engine->SetFilter("assets/filters/natural.fbd");
engine->SetFilterIntensity(0.8f);
engine->ClearFilter();

engine->SetSticker("assets/stickers/face/black_glass.fbd");
engine->ClearSticker();

engine->AddResourcePack("resource/resource_3d.fbd");  // or place it next to resource.fbd
engine->Set3DSticker("assets/stickers/3d/oculos.fbd");
engine->Clear3DSticker();

engine->SetVirtualBackgroundBlur(0.6f);
engine->SetVirtualBackground("assets/background.jpg");
engine->ClearVirtualBackground();

engine->SetChromaKey(ChromaKeyColor::Green);
engine->SetChromaKeySimilarity(0.4f);
engine->ClearChromaKey();
```

***

## 5. Callbacks y estadísticas

```cpp theme={null}
EngineCallbacks cbs;
cbs.on_engine_event = [](int code, const std::string& message) {
    // 0 license OK, 1 failed, 100 init complete, 101 init failed
    printf("[event] %d %s\n", code, message.c_str());
};
cbs.on_face_landmarks = [](const std::vector<FaceDetectionResult>& faces) {
    printf("faces=%zu\n", faces.size());
};
engine->SetCallbacks(cbs);

EngineStats stats = engine->GetStats();
```

***

## 6. Procesar fotogramas

Configura `ImageFrame::type`.

```cpp theme={null}
auto input = ImageFrame::CreateWithRGBA(rgba_data, width, height, stride);
input->type = FrameType::Video;
auto output = engine->ProcessImage(input);
```

Foto:

```cpp theme={null}
auto input = ImageFrame::CreateWithFile("input.jpg");
input->type = FrameType::Image;
auto output = engine->ProcessImage(input);
output->ToFile("output.jpg", 95);
```

<Tip>
  El formato de salida sigue el de entrada cuando es posible. Convierte con `output->Convert(Format::BGRA)`.
</Tip>

### Vista previa OpenGL

```cpp theme={null}
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
             output->Width(), output->Height(),
             0, GL_RGBA, GL_UNSIGNED_BYTE, output->Data());
```

Si tu app ya tiene un contexto GL actual, configura `cfg.external_context = true` y llama a `ProcessImage` en ese hilo.

***

## 7. Bucle mínimo

```cpp theme={null}
LogConfig log_cfg;
log_cfg.console_enabled = true;
log_cfg.level = LogLevel::Info;
BeautyEffectEngine::SetLogConfig(log_cfg);

EngineConfig cfg;
cfg.app_id = "your_app_id";
cfg.app_key = "your_app_key";
cfg.resource_path = "resource/resource.fbd";
auto engine = BeautyEffectEngine::Create(cfg);
if (!engine) return -1;

engine->SetSmoothing(0.5f);
engine->SetReshape(Reshape::FaceThin, 0.3f);
engine->SetLipstick(0.5f);

auto input = ImageFrame::CreateWithRGBA(rgba, width, height, stride);
input->type = FrameType::Video;
auto output = engine->ProcessImage(input);
```

Libera con `engine.reset()`. El motor **no** es un singleton.

Para TRTC / Agora / LiveKit: [Integración con terceros](/es/linux/third-party-integration).

## Relacionado

<CardGroup cols={2}>
  <Card title="Integración con terceros" href="/es/linux/third-party-integration">TRTC / Agora / LiveKit</Card>
  <Card title="Referencia de la API" href="/es/linux/api-reference">Métodos C++ y notas de Linux</Card>
  <Card title="Manejo de errores" href="/es/linux/error-handling">Códigos de retorno y problemas de .so / DISPLAY</Card>
  <Card title="Prácticas recomendadas" href="/es/linux/best-practices">Rendimiento y rpath</Card>
</CardGroup>
