### Setup Linux Environment for GPUPixel Source: https://gpupixel.pixpark.net/zh/guide/build Run this script to install necessary dependencies for compiling GPUPixel on Debian or Ubuntu systems. ```bash ./script/setup_env_linux.sh ``` -------------------------------- ### Compile GPUPixel for Windows Source: https://gpupixel.pixpark.net/zh/guide/build This batch file compiles the GPUPixel library for Windows. Ensure Visual Studio 2017+ and CMake 3.10+ are installed. Only supports x86_64 Release builds. ```bash .\script\build_windows.bat ``` -------------------------------- ### Adjust Beauty Face Filter Parameters Source: https://gpupixel.pixpark.net/zh/call/beauty_effects Provides examples for adjusting the skin smoothing and whitening intensity of the BeautyFaceFilter. Values are typically normalized between 0.0 and 1.0. ```cpp // 设置磨皮程度 (0.0-1.0) beauty_face_filter_->SetBlurAlpha(value/10); // 设置美白程度 (0.0-1.0) beauty_face_filter_->SetWhite(value/20); ``` -------------------------------- ### Build GPUPixel for Windows and Linux Source: https://gpupixel.pixpark.net/zh/guide/demo Run the platform-specific build scripts from the project root directory to compile the demo. ```bash .\script\build_windows.bat ``` ```bash ./script/build_linux.sh ``` -------------------------------- ### Initialize Custom Input Source Source: https://gpupixel.pixpark.net/zh/custom/custom_input Implement the static `Create` method and constructor for your custom input source. Ensure proper initialization by calling `Init()` and returning a valid shared pointer. ```cpp std::shared_ptr YourCustomInput::Create() { auto input = std::shared_ptr(new YourCustomInput()); if (input->Init()) { return input; } return nullptr; } ``` -------------------------------- ### Integrate Custom Input Source Source: https://gpupixel.pixpark.net/zh/custom/custom_input Create an instance of your custom input source using `YourCustomInput::Create()`. Add sinks (filters) to the input source and set up further processing or output. ```cpp auto input = YourCustomInput::Create(); if (input) { auto filter = BeautyFaceFilter::Create(); input->AddSink(filter); // Set more filters or output } ``` -------------------------------- ### Compile GPUPixel for macOS Source: https://gpupixel.pixpark.net/zh/guide/build Run this script from the project root to compile the GPUPixel library for macOS. The compiled output will be in the 'output' directory. ```bash ./script/build_macos.sh ``` -------------------------------- ### Compile GPUPixel for iOS Source: https://gpupixel.pixpark.net/zh/guide/build Execute this script from the project root to compile the GPUPixel library for iOS. Output is located in the 'output' directory. ```bash ./script/build_ios.sh ``` -------------------------------- ### 创建并链接 GPUPixel 滤镜链 Source: https://gpupixel.pixpark.net/zh/call/basic_filters 通过实例化源、滤镜和目标组件,并使用 AddSink 方法将它们串联起来以构建处理链路。 ```cpp // 声明组件 std::shared_ptr source_raw_input_; std::shared_ptr beauty_face_filter_; std::shared_ptr target_raw_output_; // 初始化并链接组件 // 创建源 source_raw_input_ = SourceRawData::Create(); // 创建滤镜 beauty_face_filter_ = BeautyFaceFilter::Create(); // 创建目标 target_raw_output_ = SinkRawData::Create(); // 链接滤镜链 source_raw_input_->AddSink(beauty_face_filter_) ->AddSink(target_raw_output_); ``` -------------------------------- ### Compile GPUPixel for Linux Source: https://gpupixel.pixpark.net/zh/guide/build Execute this script from the project root to compile the GPUPixel library on Linux (Debian/Ubuntu). Output is located in the 'output' directory. ```bash ./script/build_linux.sh ``` -------------------------------- ### Create and Chain Face Beauty Filters Source: https://gpupixel.pixpark.net/zh/call/beauty_effects Demonstrates how to create and link multiple beauty filters in a chain for complex effects. Ensure face detection is enabled if using face-specific filters. ```cpp // 创建源 gpuPixelRawInput = SourceRawData::Create(); // 创建目标 target_raw_output_ = SinkRawData::Create(); // 创建滤镜 lipstick_filter_ = LipstickFilter::Create(); blusher_filter_ = BlusherFilter::Create(); face_reshape_filter_ = FaceReshapeFilter::Create(); beauty_face_filter_ = BeautyFaceFilter::Create(); // 创建人脸检测器(需启用 GPUPIXEL_ENABLE_FACE_DETECTOR) face_detector_ = FaceDetector::Create(); // 链接滤镜链 gpuPixelRawInput->AddSink(lipstick_filter_) ->AddSink(blusher_filter_) ->AddSink(face_reshape_filter_) ->AddSink(beauty_face_filter_) ->AddSink(target_raw_output_); ``` -------------------------------- ### Add GPUPixel Framework to Xcode Project Source: https://gpupixel.pixpark.net/zh/guide/integrated Steps to add the gpupixel.framework to your iOS or MacOS project's build phases and search paths. ```bash ├── gpupixel.framework ``` ```bash ├── gpupixel.framework ``` -------------------------------- ### Initialize Custom Filter with Shader and Parameters in C++ Source: https://gpupixel.pixpark.net/zh/custom/custom_filter The Init() method initializes the filter with a fragment shader string and registers custom properties. Ensure the shader initialization is successful and parameters are registered with their setters. ```cpp bool CustomFilter::Init() { // 使用着色器字符串初始化 if (!InitWithFragmentShaderString(kCustomFragmentShader)) { return false; } // 注册参数 _parameter = 1.0f; RegisterProperty( "parameter", _parameter, "参数描述", [this](float& value) { setParameter(value); }); return true; } ``` -------------------------------- ### Define Custom Input Source Class Source: https://gpupixel.pixpark.net/zh/custom/custom_input Inherit from the `Source` class to create a custom input source. Implement a static `Create` method and private members as needed. ```cpp class YourCustomInput : public Source { public: static std::shared_ptr Create(); // Your custom methods private: // Your private members }; ``` -------------------------------- ### Compile GPUPixel for Android Source: https://gpupixel.pixpark.net/zh/guide/build Use this script from the project root to compile the GPUPixel library for Android. The output AAR file is located in 'src/android/java/gpupixel/build/outputs/aar'. ```bash ./script/build_android.sh ``` -------------------------------- ### Process Frame with Face Detection and Filter Chain Source: https://gpupixel.pixpark.net/zh/call/beauty_effects Shows how to detect face landmarks using a detector and pass them to relevant filters before processing the frame. This is crucial for real-time facial adjustments. ```cpp // 获取当前帧图像数据(宽、高、stride 等) const uint8_t* buffer = ...; // 例如从相机或其它输入获取 int width = ..., height = ..., stride = ...; std::vector landmarks = face_detector_->Detect( buffer, width, height, stride, GPUPIXEL_MODE_FMT_PICTURE, GPUPIXEL_FRAME_TYPE_RGBA); if (!landmarks.empty()) { lipstick_filter_->SetFaceLandmarks(landmarks); blusher_filter_->SetFaceLandmarks(landmarks); face_reshape_filter_->SetFaceLandmarks(landmarks); } // 再执行滤镜链:使用 SourceRawData 时调用 ProcessData 送入本帧并触发渲染; // 若使用 SourceImage,则改为先取 buffer = source->GetRgbaImageBuffer() 再 source->Render() gpuPixelRawInput->ProcessData(buffer, width, height, stride, GPUPIXEL_FRAME_TYPE_RGBA); ``` -------------------------------- ### Implement Custom Filter Factory Method in C++ Source: https://gpupixel.pixpark.net/zh/custom/custom_filter Implement a static factory method to create and initialize a custom filter instance. It ensures proper initialization within the GPUPixel context. ```cpp std::shared_ptr CustomFilter::Create() { auto ret = std::shared_ptr(new CustomFilter()); gpupixel::GPUPixelContext::GetInstance()->SyncRunWithContext([&] { if (ret && !ret->Init()) { ret.reset(); } }); return ret; } ``` -------------------------------- ### Import GPUPixel Header in Objective-C Source: https://gpupixel.pixpark.net/zh/guide/integrated Import the main GPUPixel header file in your Objective-C source files. Ensure your Objective-C files have a .mm extension to enable C++ interoperability. ```objective-c #import ``` -------------------------------- ### Manage Frame Buffer Source: https://gpupixel.pixpark.net/zh/custom/custom_input Create and manage the frame buffer for your input source. Ensure the frame buffer dimensions match the input width and height, and set the output rotation. ```cpp if (!framebuffer_ || (framebuffer_->GetWidth() != width || framebuffer_->GetHeight() != height)) { framebuffer_ = GPUPixelContext::GetInstance()->GetFramebufferFactory()->CreateFramebuffer( width, height); } this->SetFramebuffer(framebuffer_, outputRotation); ``` -------------------------------- ### 自定义 Sink 实现示例 Source: https://gpupixel.pixpark.net/zh/custom/custom_target 展示了继承 Sink 类并实现自定义渲染逻辑的最小化代码结构。 ```cpp class MyCustomTarget : public Sink { public: MyCustomTarget() : Sink(1) { // 初始化着色器和其他资源 initShaders(); } ~MyCustomTarget() { // 清理资源 cleanup(); } void Render() override { if (!IsReady()) return; // 设置渲染状态 setupRenderState(); // 执行自定义渲染逻辑 Render(); // 处理输出 processOutput(); } private: // 自定义实现细节 }; ``` -------------------------------- ### Adjust Makeup Filter Parameters Source: https://gpupixel.pixpark.net/zh/call/beauty_effects Shows how to adjust the intensity of lipstick and blusher effects using their respective filters. The blend level controls the concentration of the makeup effect. ```cpp // 设置口红浓度 (0.0-1.0) lipstick_filter_->SetBlendLevel(value/10); // 设置腮红浓度 (0.0-1.0) blusher_filter_->SetBlendLevel(value/10); ``` -------------------------------- ### SinkRawData 原始数据输出实现 Source: https://gpupixel.pixpark.net/zh/custom/custom_target SinkRawData 类支持将渲染结果输出为 RGBA 或 I420 格式的原始数据,并利用 PBO 优化性能。 ```cpp class SinkRawData : public Sink { public: static std::shared_ptr Create(); void Render() override; // 获取输出尺寸与缓冲区(拉取方式,非回调) const uint8_t* GetRgbaBuffer(); const uint8_t* GetI420Buffer(); int GetWidth() const; int GetHeight() const; }; ``` -------------------------------- ### Sink 基类接口定义 Source: https://gpupixel.pixpark.net/zh/custom/custom_target Sink 类是所有输出目标的基类,定义了管理输入帧缓冲区、处理旋转模式和更新机制的核心接口。 ```cpp class Sink { public: // 构造函数,指定输入数量 Sink(int inputNumber = 1); // 设置输入帧缓冲区 virtual void SetInputFramebuffer(std::shared_ptr framebuffer, RotationMode rotation_mode = NoRotation, int texIdx = 0); // 更新处理 virtual void Render(){}; }; ``` -------------------------------- ### Implement Custom Filter Rendering Logic in C++ Source: https://gpupixel.pixpark.net/zh/custom/custom_filter The DoRender() method updates shader uniform variables with current filter parameters and then calls the base class implementation to perform the rendering. ```cpp bool CustomFilter::DoRender(bool updateSinks) { // 更新着色器 uniform 变量 filter_program_->SetUniformValue("parameter", _parameter); // 调用基类实现 return Filter::DoRender(updateSinks); } ``` -------------------------------- ### 清理 GPUPixel 资源 Source: https://gpupixel.pixpark.net/zh/call/basic_filters 在完成处理后,通过重置智能指针来释放滤镜链组件占用的资源。 ```cpp // 清理 GPUPixel 资源 // 释放你的滤镜引用 source_raw_input_.reset(); beauty_face_filter_.reset(); target_raw_output_.reset(); // 其他滤镜... ``` -------------------------------- ### Process Raw Data Input Source: https://gpupixel.pixpark.net/zh/call/input_output Use ProcessData to feed pixel data into the filter chain. Note that only RGBA/BGRA formats are supported; YUV data must be converted first. ```cpp // 对于 RGBA 数据(需指定 GPUPIXEL_FRAME_TYPE_RGBA 或 GPUPIXEL_FRAME_TYPE_BGRA) source_raw_input_->ProcessData(pixels, width, height, stride, GPUPIXEL_FRAME_TYPE_RGBA); ``` ```cpp gpuPixelRawInput->ProcessData(pixels, width, height, stride, GPUPIXEL_FRAME_TYPE_RGBA); ``` -------------------------------- ### SinkRender 渲染到屏幕实现 Source: https://gpupixel.pixpark.net/zh/custom/custom_target SinkRender 类用于将图像渲染到屏幕,支持多种填充模式、镜像显示及旋转处理。 ```cpp class SinkRender : public Sink { public: // 初始化着色器程序和属性位置 void Init() { } // 实现更新方法,执行实际的渲染 void Render() override { // do render } }; ``` -------------------------------- ### Adjust Face Reshape Filter Parameters Source: https://gpupixel.pixpark.net/zh/call/beauty_effects Illustrates how to control the face slimming and eye enlargement effects using the FaceReshapeFilter. Parameter values are typically between 0.0 and 1.0. ```cpp // 设置瘦脸程度 (0.0-1.0) face_reshape_filter_->SetFaceSlimLevel(value/100); // 设置大眼程度 (0.0-1.0) face_reshape_filter_->SetEyeZoomLevel(value/50); ``` -------------------------------- ### Define Custom Filter Structure in C++ Source: https://gpupixel.pixpark.net/zh/custom/custom_filter This is the basic structure for a custom filter class inheriting from GPUPixel's Filter. It includes methods for creation, initialization, rendering, and parameter setting. ```cpp class CustomFilter : public Filter { public: static std::shared_ptr Create(); bool Init(); virtual bool DoRender(bool updateSinks = true) override; // 自定义参数设置器 void setParameter(float value); protected: CustomFilter(){}; // 滤镜参数 float _parameter; }; ``` -------------------------------- ### Process Raw Pixel Data Source: https://gpupixel.pixpark.net/zh/custom/custom_input Implement `setFrameData` to handle raw pixel data. This involves updating the OpenGL texture with new pixel data, width, height, and stride. ```cpp void YourCustomInput::setFrameData(const uint8_t* pixels, int width, int height, int stride) { // Update texture glBindTexture(GL_TEXTURE_2D, this->GetFramebuffer()->GetTexture()); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); } ``` -------------------------------- ### Add GPUPixel AAR to Android Project Source: https://gpupixel.pixpark.net/zh/guide/integrated Include the gpupixel-release.aar file in your Android project's libs directory and add it as a dependency in your Gradle build file. ```gradle dependencies { implementation files('libs/gpupixel-release.aar') } ``` -------------------------------- ### Control Data Stream Rendering Source: https://gpupixel.pixpark.net/zh/custom/custom_input Call `DoRender(true, timestamp)` to process the frame through the filter chain. This method is essential for controlling the data flow and applying filters. ```cpp Source::DoRender(true, timestamp); ``` -------------------------------- ### Define HueFilter Structure in C++ Source: https://gpupixel.pixpark.net/zh/custom/custom_filter This C++ code defines the structure for a HueFilter, inheriting from the base Filter class. It includes methods for creation, initialization, rendering, and a specific setter for hue adjustment. ```cpp class HueFilter : public Filter { public: static std::shared_ptr Create(); bool Init(); virtual bool DoRender(bool updateSinks = true) override; void setHueAdjustment(float hueAdjustment); protected: HueFilter(){}; float _hueAdjustment; }; ``` -------------------------------- ### Retrieve Processed Output Data Source: https://gpupixel.pixpark.net/zh/call/input_output Extract processed results from the pipeline using SinkRawData after rendering is complete. ```cpp // 获取 RGBA 结果 const uint8_t* rgba_data = target_raw_output_->GetRgbaBuffer(); int width = target_raw_output_->GetWidth(); int height = target_raw_output_->GetHeight(); size_t rgba_size = width * height * 4; // 使用 rgba_data 进行处理或显示 // 获取 I420 结果 const uint8_t* i420_data = target_raw_output_->GetI420Buffer(); size_t y_size = width * height; const uint8_t* uData = i420_data + y_size; const uint8_t* vData = i420_data + y_size + y_size / 4; ``` -------------------------------- ### Define Custom Fragment Shader in GLSL Source: https://gpupixel.pixpark.net/zh/custom/custom_filter This GLSL code defines the fragment shader for a custom filter. It includes uniform variables for input texture and custom parameters, and the main function where the image processing logic resides. ```glsl const std::string kCustomFragmentShader = R"( precision highp float; uniform sampler2D inputImageTexture; uniform float parameter; varying highp vec2 textureCoordinate; void main() { // 在此实现滤镜效果 vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); gl_FragColor = textureColor; })" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.