### Setup vcpkg Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Clone and bootstrap vcpkg, then set the VCPKG_ROOT environment variable. Commands differ for Linux/macOS and Windows. ```bash # Clone vcpkg git clone https://github.com/microsoft/vcpkg.git cd vcpkg # Bootstrap ./bootstrap-vcpkg.sh # Linux/macOS .\bootstrap-vcpkg.bat # Windows # Set environment variable export VCPKG_ROOT="$HOME/vcpkg" # Linux/macOS (add to .bashrc) $env:VCPKG_ROOT = "C:\vcpkg" # Windows PowerShell ``` -------------------------------- ### Install gwt-integrations Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Clone and run the installer for the gwt-integrations package, which provides AI agent integration for GeminiWatermarkTool. Requires GeminiWatermarkTool to be on PATH. ```bash git clone https://github.com/allenk/gwt-integrations.git cd gwt-integrations python install.py ``` -------------------------------- ### Usage examples for path formatter Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/path-formatter.md Shows how to use the formatter and helpers: logging a path with spdlog, displaying with ImGui, and converting a UTF-8 string from a drop event back to a path. ```cpp #include "utils/path_formatter.hpp" #include #include std::filesystem::path p = u8"照片/合影.png"; spdlog::info("File: {}", p); // fmt formatter -> UTF-8 ImGui::Text("File: %s", gwt::to_utf8(p).c_str()); // Reverse direction: a UTF-8 string from anywhere -> path std::filesystem::path from_drop = gwt::path_from_utf8(dropped_utf8_string); ``` -------------------------------- ### Example AI agent commands Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Example natural-language commands that AI agents can use to process watermarks after installation. ```text "Remove the Gemini watermark from screenshot.png using AI denoise" "Batch process all images in ./photos/ with fallback snap detection" ``` -------------------------------- ### CLI Basic Usage Examples Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Shows simple mode, output file specification, and batch processing. Simple mode overwrites the original file permanently; always back up important images. ```bash # Simple mode - just provide a filename GeminiWatermarkTool watermarked.jpg ``` ```bash # Specify output file (preserves original) GeminiWatermarkTool -i watermarked.jpg -o clean.jpg ``` ```bash # Batch processing - entire directory GeminiWatermarkTool -i ./input_folder/ -o ./output_folder/ ``` -------------------------------- ### CLI Advanced Usage Examples Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Shows various advanced options including denoise, fallback region, snap search, and force processing. When no --denoise is specified, behavior matches previous versions. ```bash # Standard removal with AI denoise cleanup GeminiWatermarkTool -i input.jpg -o clean.jpg --denoise ai ``` ```bash # Batch with AI denoise (all files) GeminiWatermarkTool -i ./photos/ -o ./clean/ --denoise ai ``` ```bash # Fallback for images that fail detection: search bottom-right area with snap GeminiWatermarkTool -i ./photos/ -o ./clean/ \ --fallback-region br:auto --snap --denoise ai ``` ```bash # Resized watermarks: expand snap search to 320px GeminiWatermarkTool -i ./photos/ -o ./clean/ \ --fallback-region br:80,80,200,200 --snap --snap-max-size 320 --denoise ai ``` ```bash # Gemini preview images (small ~28px watermark): use lower snap-threshold GeminiWatermarkTool -i preview.jpg -o clean.jpg \ --fallback-region br:auto --snap --snap-threshold 0.30 --denoise ai --sigma 13 --strength 175 ``` ```bash # Force process at explicit region (all images have watermark at same spot) GeminiWatermarkTool -i ./photos/ -o ./clean/ \ --force --region 500,800,160,160 --snap --denoise ai --sigma 75 ``` -------------------------------- ### Usage example for encode_png and write_png Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/image-io.md Shows how to include the header, encode an image in memory, and write a PNG with Unicode-safe path handling. The write_png call uses a CJK filename and checks the return value to handle failures. ```cpp #include "utils/image_io.hpp" // Encode in memory (e.g. to ship elsewhere or hash) cv::Mat img = cv::imread("input.png", cv::IMREAD_COLOR); std::vector bytes = gwt::encode_png(img, 6); // Write with Unicode-safe path handling (works for CJK/spaced filenames) const bool ok = gwt::write_png(u8"导出/结果.png", img, 6); if (!ok) { // encode or filesystem failure -- report, do not continue return false; } ``` -------------------------------- ### Usage example: load, process, and save image with AppController Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/app-controller.md Shows how to use AppController to load an image, set legacy mode and size mode, process it, and save the result. After processing, check the state for errors; error_message holds the failure reason. ```cpp #include "gui/app/app_controller.hpp" gwt::gui::AppController controller(*backend); if (controller.load_image(u8"输入/照片.png")) { controller.set_legacy_mode(false); // V2 profile controller.set_size_mode(gwt::gui::WatermarkSizeMode::Auto); controller.process_current(); // detect+remove+inpaint controller.save_image(u8"输出/结果.png"); } const auto& st = controller.state(); if (st.state == gwt::gui::ProcessState::Error) { // controller.state().error_message has the failure reason } ``` -------------------------------- ### Usage example with fallback Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/watermark-detector.md Shows how to call detect_watermark_region and fall back to the geometric region when detection fails or has low confidence. Includes the necessary include directives and uses cv::imread to load an image. ```cpp #include "core/watermark_detector.hpp" #include cv::Mat img = cv::imread("photo.png", cv::IMREAD_COLOR); auto result = gwt::detect_watermark_region(img); if (result && result->detected) { // 3-stage detection matched the watermark; use its region cv::Rect r = result->region; std::cout << "Detected at (" << r.x << "," << r.y << ") " << r.width << "x" << r.height << " conf=" << result->confidence * 100.0f << "%\n"; } else { // Fall back to the geometric bottom-right position cv::Rect fallback = gwt::get_fallback_watermark_region(img.cols, img.rows); } ``` -------------------------------- ### Simple removal, output to new file, batch processing, and scripted retry Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/cli.md Shows common CLI invocations: in-place removal, output to a new file with legacy profile pinning, batch directory processing with AI denoise and snap, and a scripted retry using exit codes. The retry example checks for exit code 1 and retries with --force when the safety gate skips the image. ```bash # Simple removal (in-place) GeminiWatermarkTool photo.png # Output to a new file with legacy profile pinning GeminiWatermarkTool -i photo.png -o clean.png --legacy # Batch directory with AI denoise + snap in the bottom-right corner GeminiWatermarkTool -i ./photos/ -o ./clean/ \ --fallback-region br:auto --snap --denoise ai # Scripted retry using exit codes GeminiWatermarkTool -i image.png -o clean.png if [ $? -eq 1 ]; then # skipped on both V2 and V1 -- retry without the safety gate GeminiWatermarkTool -i image.png -o clean.png --force fi ``` -------------------------------- ### Usage example: add watermark with custom brightness Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/blend-modes.md Shows adding a watermark back with a custom logo brightness and converting to BGR if needed. All inputs must be BGR 3-channel; assert failures terminate the process. ```cpp // Adding a watermark back with a custom logo brightness gwt::add_watermark_alpha_blend(img, alpha, cv::Point(10, 10), 240.0f); // All inputs must be BGR 3-channel; assert failures terminate the process if (img.channels() != 3) { cv::cvtColor(img, img, cv::COLOR_BGRA2BGR); } ``` -------------------------------- ### Initialize backend and create texture (OpenGL) Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Shows how to initialize SDL, create a window, and create an OpenGL backend. Checks for initialization errors and uploads a preview texture. Requires SDL3 and the render backend header. ```cpp #include "gui/backend/render_backend.hpp" #include SDL_Init(SDL_INIT_VIDEO); SDL_Window* window = SDL_CreateWindow("app", 1600, 1250, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL); auto backend = gwt::gui::create_backend(gwt::gui::BackendType::OpenGL); if (!backend || !backend->init(window)) { // check backend->last_error(): InitFailed / WindowCreationFailed / ... std::cerr << gwt::gui::to_string(backend->last_error()) << '\n'; return 1; } backend->imgui_init(); // Upload a preview texture gwt::gui::TextureDesc desc; desc.width = 1920; desc.height = 1080; desc.format = gwt::gui::TextureFormat::BGR8; auto tex = backend->create_texture(desc, bgr_pixels); if (!tex.valid()) { /* TextureCreationFailed */ } // ImGui::Image(backend->get_imgui_texture_id(tex), ...); ``` -------------------------------- ### Linux: Make executable and run Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Linux does not quarantine downloaded binaries. Ensure the file is executable and run it. ```bash chmod +x GeminiWatermarkTool ./GeminiWatermarkTool ``` -------------------------------- ### Guided detection and custom removal with error handling Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/watermark-engine.md Performs guided detection in a hand-drawn region, then removes the watermark using the matched rectangle and applies residual inpainting with GAUSSIAN method. If no template match is found, processing is bypassed; exceptions from empty images or decode failures are caught and printed. ```cpp // Guided detection in a hand-drawn region + error handling gwt::GuidedDetectionResult snap = engine.guided_detect( img, cv::Rect(400, 800, 300, 300), nullptr, 16, 320); if (!snap.found) { // No template match: bypass processing, keep the original image return; } try { engine.remove_watermark_custom(img, snap.match_rect, gwt::WatermarkVariant::V2); engine.inpaint_residual(img, snap.match_rect, 0.85f, gwt::InpaintMethod::GAUSSIAN); } catch (const std::exception& e) { // Empty image or decode failure surfaced here std::cerr << e.what() << '\n'; } ``` -------------------------------- ### IRenderBackend::imgui_init Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Initializes ImGui integration for the backend. ```APIDOC ## IRenderBackend::imgui_init ### Description Initializes ImGui integration for the backend. ### Method Virtual method ### Signature ```cpp virtual void imgui_init() = 0; ``` ``` -------------------------------- ### guided_detect Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/watermark-engine.md Performs guided detection of a watermark in a specified region with error handling. ```APIDOC ## `guided_detect` ### Description Performs guided detection of a watermark in a specified region with error handling. ### Method C++ member function ### Signature ```cpp gwt::GuidedDetectionResult guided_detect( const cv::Mat& image, const cv::Rect& region, void* user_data = nullptr, int something = 16, int another = 320 ) const; ``` ### Parameters - `image` (const cv::Mat&) - Required - Input image - `region` (const cv::Rect&) - Required - Region to search for watermark - `user_data` (void*) - Optional - User data (default nullptr) - `something` (int) - Optional - Some parameter (default 16) - `another` (int) - Optional - Another parameter (default 320) ### Returns - `gwt::GuidedDetectionResult` - Contains `found` (bool) and `match_rect` (cv::Rect) ### Usage Example ```cpp #include "core/watermark_engine.hpp" #include "embedded_assets.hpp" #include // Guided detection in a hand-drawn region + error handling gwt::GuidedDetectionResult snap = engine.guided_detect( img, cv::Rect(400, 800, 300, 300), nullptr, 16, 320); if (!snap.found) { // No template match: bypass processing, keep the original image return; } try { engine.remove_watermark_custom(img, snap.match_rect, gwt::WatermarkVariant::V2); engine.inpaint_residual(img, snap.match_rect, 0.85f, gwt::InpaintMethod::GAUSSIAN); } catch (const std::exception& e) { // Empty image or decode failure surfaced here std::cerr << e.what() << '\n'; } ``` ``` -------------------------------- ### Backend::init Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Initializes the backend with a given SDL window. Returns a boolean indicating success or failure. ```APIDOC ## Backend::init ### Description Initializes the backend with a given SDL window. Returns a boolean indicating success or failure. ### Method Member function call ### Signature `bool init(SDL_Window* window)` ### Parameters - `window` (SDL_Window*) - Required - The SDL window to initialize the backend with. ### Return Value - `bool` - `true` on success, `false` on failure. Check `last_error()` for error details. ### Example ```cpp if (!backend || !backend->init(window)) { // handle error } ``` ``` -------------------------------- ### Build gwt-mini (minimal CLI) Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Build the minimal CLI variant with GUI off, AI denoise on, and no video pipeline. Optionally strip and compress with UPX. ```bash # Linux cmake -B build-mini -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_GUI=OFF \ -DENABLE_AI_DENOISE=ON \ -DENABLE_VIDEO=OFF \ -DVCPKG_MANIFEST_FEATURES="ai-denoise" \ -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake cmake --build build-mini strip build-mini/GeminiWatermarkTool # Optional: shrink further with UPX upx --best --lzma build-mini/GeminiWatermarkTool ``` -------------------------------- ### Custom detection threshold Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Set a custom confidence threshold for watermark detection. The default threshold is 25% (0.25). This example uses 0.40. ```bash # Custom detection threshold (default: 25%) GeminiWatermarkTool --threshold 0.40 image.jpg ``` -------------------------------- ### Backend::imgui_init Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Initializes ImGui for the backend. Must be called after successful initialization. ```APIDOC ## Backend::imgui_init ### Description Initializes ImGui for the backend. Must be called after successful initialization. ### Method Member function call ### Signature `void imgui_init()` ### Parameters None ### Return Value None ### Example ```cpp backend->imgui_init(); ``` ``` -------------------------------- ### Manual build without presets Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Configure and build manually using Ninja and vcpkg toolchain. ```bash cmake -B build -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake \ -DVCPKG_TARGET_TRIPLET=x64-linux cmake --build build ``` -------------------------------- ### Usage example: remove watermark Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/blend-modes.md Shows how to compute an alpha map from a background capture and remove a watermark from an image, then save the result. Requires OpenCV imgcodecs. ```cpp #include "core/blend_modes.hpp" #include cv::Mat bg = cv::imread("gemini_bg_96.png", cv::IMREAD_COLOR); // watermark on flat bg cv::Mat alpha = gwt::calculate_alpha_map(bg); // CV_32FC1 [0,1] cv::Mat img = cv::imread("watermarked.jpg", cv::IMREAD_COLOR); gwt::remove_watermark_alpha_blend(img, alpha, cv::Point(1856, 960), 255.0f); cv::imwrite("restored.jpg", img); ``` -------------------------------- ### IRenderBackend::init Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Initializes the render backend with the given SDL window. Returns true on success, false on failure. ```APIDOC ## IRenderBackend::init ### Description Initializes the render backend with the given SDL window. Returns true on success, false on failure. ### Method Virtual method ### Signature ```cpp [[nodiscard]] virtual bool init(SDL_Window* window) = 0; ``` ### Parameters - `window` (SDL_Window*) - Required - The SDL window to initialize the backend with. ### Returns `bool` - `true` on success, `false` on failure. ``` -------------------------------- ### Auto-select backend and verify Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Creates a backend with automatic selection and logs the backend name and compute support. Useful for debugging or verifying the chosen backend. ```cpp // Auto selection, then verify what was picked auto b = gwt::gui::create_backend(); // BackendType::Auto if (b) { spdlog::info("backend={} compute={}", b->name(), b->supports_compute() ? "yes" : "no"); } ``` -------------------------------- ### Build on Linux Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Configure and build the project on Linux using the linux-x64-Release preset. ```bash cmake --preset linux-x64-Release cmake --build --preset linux-x64-Release ``` -------------------------------- ### create_backend function Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Creates a render backend instance. Returns nullptr if unavailable. Auto selects best for platform: Windows D3D11 > OpenGL; Linux/macOS OpenGL (Vulkan if enabled). ```cpp [[nodiscard]] std::unique_ptr create_backend(BackendType type = BackendType::Auto); ``` -------------------------------- ### gwt::GuidedDetectionResult struct definition Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/types.md Defines the result of a guided watermark detection search. Contains match confidence, raw NCC score, match rectangle, detected size, cancellation flag, and search progress stats. Returned by WatermarkEngine::guided_detect(). ```cpp struct GuidedDetectionResult { bool found{false}; // Whether a match was found float confidence{0.0f}; // Size-adjusted score (for decision making) float raw_ncc{0.0f}; // Raw NCC score (before size adjustment) cv::Rect match_rect; // Best match position and size (image coords) int detected_size{0}; // Detected watermark size in pixels bool was_cancelled{false}; // Search was cancelled by user // Search stats int scales_searched{0}; // Number of scales tested int total_scales{0}; // Total scales planned }; ``` -------------------------------- ### Build on Windows Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Configure and build the project on Windows using the windows-x64-Release preset. ```powershell cmake --preset windows-x64-Release cmake --build --preset windows-x64-Release ``` -------------------------------- ### gwt::gui::run Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Entry point for the GUI application. Initializes SDL, parses backend selection, creates the window, and runs the main UI loop. ```APIDOC ## [FUNCTION] gwt::gui::run ### Description Entry point for the GUI application. Initializes SDL, parses backend selection, creates the window, and runs the main UI loop. ### Signature ```cpp int run(int argc, char** argv); ``` ### Parameters - **argc** (int) - Required - Argument count - **argv** (char**) - Required - Argument values; only `--backend=` is read ### Returns - **int** - `0` on clean exit, `1` on startup failure (SDL init, backend creation, or window creation) ### Behavior - Sets up the `gwt-gui` logger - Initializes SDL video (`SDL_INIT_VIDEO`) - Enables the screen saver - Parses `--backend=opengl|d3d11|vulkan` (values unavailable in the build are ignored; default `Auto`) - Creates the backend through `create_backend()` - Creates a resizable `1600×1250` (min `1030×888`) SDL3 window - Hands control to the main UI loop (`MainWindow` + `AppController`) ``` -------------------------------- ### Run GeminiWatermarkTool with backend selection Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Launch the tool with automatic backend selection (D3D11 on Windows, OpenGL elsewhere) or force a specific render backend using the --backend flag. ```bash # Auto-select (D3D11 on Windows, OpenGL elsewhere) GeminiWatermarkTool # Force specific backend GeminiWatermarkTool --backend=d3d11 GeminiWatermarkTool --backend=opengl ``` -------------------------------- ### IRenderBackend::on_resize Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Handles window resize events. ```APIDOC ## IRenderBackend::on_resize ### Description Handles window resize events. ### Method Virtual method ### Signature ```cpp virtual void on_resize(int width, int height) = 0; ``` ### Parameters - `width` (int) - Required - New width of the window. - `height` (int) - Required - New height of the window. ``` -------------------------------- ### create_backend Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Creates a render backend instance of the specified type. Returns a unique pointer to the backend or nullptr if unavailable. ```APIDOC ## create_backend ### Description Creates a render backend instance of the specified type. Returns a unique pointer to the backend or nullptr if unavailable. ### Method Function ### Signature ```cpp [[nodiscard]] std::unique_ptr create_backend(BackendType type = BackendType::Auto); ``` ### Parameters - `type` (BackendType) - Optional - Default: `BackendType::Auto` - Requested backend type. ### Returns `std::unique_ptr` - The created backend instance, or `nullptr` if unavailable. ### Remarks `Auto` selects the best for the platform: Windows `D3D11 > OpenGL`; Linux/macOS `OpenGL` (Vulkan if enabled). ``` -------------------------------- ### IRenderBackend::begin_frame Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Begins a new frame for rendering. ```APIDOC ## IRenderBackend::begin_frame ### Description Begins a new frame for rendering. ### Method Virtual method ### Signature ```cpp virtual void begin_frame() = 0; ``` ``` -------------------------------- ### create_backend Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Creates a GUI backend instance for rendering. Supports auto-selection or explicit backend type, and returns a pointer to the backend object. ```APIDOC ## create_backend ### Description Creates a GUI backend instance for rendering. Supports auto-selection or explicit backend type, and returns a pointer to the backend object. ### Method Function call ### Signature `gwt::gui::create_backend(gwt::gui::BackendType type = gwt::gui::BackendType::Auto)` ### Parameters - `type` (BackendType) - Optional - The backend type to create. Defaults to `BackendType::Auto`. ### Return Value - `std::unique_ptr` - A pointer to the created backend, or `nullptr` on failure. ### Example ```cpp auto backend = gwt::gui::create_backend(gwt::gui::BackendType::OpenGL); ``` ``` -------------------------------- ### IRenderBackend::imgui_new_frame Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Begins a new ImGui frame. ```APIDOC ## IRenderBackend::imgui_new_frame ### Description Begins a new ImGui frame. ### Method Virtual method ### Signature ```cpp virtual void imgui_new_frame() = 0; ``` ``` -------------------------------- ### Build for Android Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Set ANDROID_NDK_HOME and build using the android-arm64-Release preset. ```bash export ANDROID_NDK_HOME="/path/to/android-ndk" cmake --preset android-arm64-Release cmake --build --preset android-arm64-Release ``` -------------------------------- ### IRenderBackend::imgui_render Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Renders the ImGui frame. ```APIDOC ## IRenderBackend::imgui_render ### Description Renders the ImGui frame. ### Method Virtual method ### Signature ```cpp virtual void imgui_render() = 0; ``` ``` -------------------------------- ### Clone with submodules and list presets Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Clone the repository with submodules (NCNN source) and list available CMake presets. ```bash # Clone with submodules (NCNN source) git clone --recursive https://github.com/allenk/GeminiWatermarkTool.git # Or if already cloned: git submodule update --init --recursive # List available presets cmake --list-presets ``` -------------------------------- ### IRenderBackend::create_texture Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Creates a texture with the given description and optional initial data. Returns a texture handle. ```APIDOC ## IRenderBackend::create_texture ### Description Creates a texture with the given description and optional initial data. Returns a texture handle. ### Method Virtual method ### Signature ```cpp [[nodiscard]] virtual TextureHandle create_texture(const TextureDesc& desc, std::span data = {}) = 0; ``` ### Parameters - `desc` (const TextureDesc&) - Required - Texture description (width, height, format, mip generation). - `data` (std::span) - Optional - Initial pixel data. ### Returns `TextureHandle` - Handle to the created texture. ``` -------------------------------- ### gwt::gui::apply_style Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Applies the custom dark ImGui style. ```APIDOC ## gwt::gui::apply_style ### Description Applies the custom dark ImGui style. ### Method Function call ### Signature `void apply_style()` ### Parameters None ### Return Value None ### Example ```cpp gwt::gui::apply_style(); ``` ``` -------------------------------- ### IRenderBackend::name Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Returns the name of the backend. ```APIDOC ## IRenderBackend::name ### Description Returns the name of the backend. ### Method Virtual method ### Signature ```cpp [[nodiscard]] virtual std::string_view name() const noexcept = 0; ``` ### Returns `std::string_view` - The backend name. ``` -------------------------------- ### Build macOS Universal Binary Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Build for x64 and arm64 separately, then combine them into a universal binary using lipo. ```bash # Build x64 cmake -B build-x64 -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake \ -DVCPKG_TARGET_TRIPLET=x64-osx \ -DCMAKE_OSX_ARCHITECTURES=x86_64 cmake --build build-x64 # Build arm64 cmake -B build-arm64 -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake \ -DVCPKG_TARGET_TRIPLET=arm64-osx \ -DCMAKE_OSX_ARCHITECTURES=arm64 cmake --build build-arm64 # Create Universal Binary lipo -create build-x64/GeminiWatermarkTool build-arm64/GeminiWatermarkTool \ -output GeminiWatermarkTool ``` -------------------------------- ### Backend::name Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Returns the name of the backend as a string. ```APIDOC ## Backend::name ### Description Returns the name of the backend as a string. ### Method Member function call ### Signature `const char* name() const` ### Parameters None ### Return Value - `const char*` - The backend name. ### Example ```cpp spdlog::info("backend={}", b->name()); ``` ``` -------------------------------- ### IRenderBackend::present Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Presents the rendered frame to the screen. ```APIDOC ## IRenderBackend::present ### Description Presents the rendered frame to the screen. ### Method Virtual method ### Signature ```cpp virtual void present() = 0; ``` ``` -------------------------------- ### IRenderBackend::type Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Returns the backend type. ```APIDOC ## IRenderBackend::type ### Description Returns the backend type. ### Method Virtual method ### Signature ```cpp [[nodiscard]] virtual BackendType type() const noexcept = 0; ``` ### Returns `BackendType` - The backend type. ``` -------------------------------- ### Backend::create_texture Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Creates a texture from pixel data. Returns a texture handle that can be used with ImGui. ```APIDOC ## Backend::create_texture ### Description Creates a texture from pixel data. Returns a texture handle that can be used with ImGui. ### Method Member function call ### Signature `TextureHandle create_texture(const TextureDesc& desc, const void* pixels)` ### Parameters - `desc` (TextureDesc) - Required - Description of the texture (width, height, format). - `pixels` (const void*) - Required - Pointer to the pixel data. ### Return Value - `TextureHandle` - A handle to the created texture. Check `valid()` to verify success. ### Example ```cpp gwt::gui::TextureDesc desc; desc.width = 1920; desc.height = 1080; desc.format = gwt::gui::TextureFormat::BGR8; auto tex = backend->create_texture(desc, bgr_pixels); if (!tex.valid()) { /* TextureCreationFailed */ } ``` ``` -------------------------------- ### is_backend_available function Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Checks whether a backend can be created. Returns bool. ```cpp [[nodiscard]] bool is_backend_available(BackendType type) noexcept; ``` -------------------------------- ### gwt::gui::run function signature Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Entry point for the GUI application. Returns 0 on clean exit, 1 on startup failure. Reads only the --backend= argument. ```cpp int run(int argc, char** argv); ``` -------------------------------- ### Guarding against empty input and low confidence Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/watermark-detector.md Shows how to interpret a nullopt result as an empty input, not 'nothing found', and how to skip processing when confidence is below the safety gate of 0.25f. ```cpp // Guarding: a nullopt means an empty input, NOT "nothing found" if (!result) { // empty image -- bail out return 1; } if (result->confidence < 0.25f) { // below the safety gate: skip, do not modify the image return 1; } ``` -------------------------------- ### IRenderBackend::supports_compute Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Indicates whether the backend supports compute shaders. ```APIDOC ## IRenderBackend::supports_compute ### Description Indicates whether the backend supports compute shaders. ### Method Virtual method ### Signature ```cpp [[nodiscard]] virtual bool supports_compute() const noexcept = 0; ``` ### Returns `bool` - `true` if compute is supported, `false` otherwise. ``` -------------------------------- ### WatermarkEngine constructor (file paths) Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/watermark-engine.md Constructs a V1-only WatermarkEngine by loading background captures from file paths. Throws std::runtime_error if either capture fails to load. ```APIDOC ## Constructor ### Description Constructs a V1-only WatermarkEngine by loading background captures from file paths. Throws std::runtime_error if either capture fails to load. ### Signature ```cpp WatermarkEngine( const std::filesystem::path& bg_small, const std::filesystem::path& bg_large, float logo_value = 255.0f ); ``` ### Parameters - `bg_small` (const std::filesystem::path&) - Required - Path to 48×48 background capture (V1) - `bg_large` (const std::filesystem::path&) - Required - Path to 96×96 background capture (V1) - `logo_value` (float) - Optional - Logo brightness (255 = white) ### Throws - `std::runtime_error` if either capture fails to load. ``` -------------------------------- ### gwt::cli::run_simple_mode Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/cli.md Handles drag-and-drop / in-place edit mode. Processes each positional argument as a file in place, rejecting directories and supporting simple-mode flags. ```APIDOC ## gwt::cli::run_simple_mode ### Description Handles drag-and-drop / in-place edit mode. Processes each positional argument as a file in place, rejecting directories and supporting simple-mode flags. ### Signature ```cpp int run_simple_mode(int argc, char** argv); ``` ### Parameters - **argc** (int) - Required - Argument count - **argv** (char**) - Required - File paths + optional `--banner`/`--no-banner`/`--legacy`/`--no-legacy` ### Returns - **int** - Process exit code (0 processed; 1 for a single-file invocation where the file was skipped; 2 for failures or `--legacy`+`--no-legacy` conflict). ### Behavior - Every positional argument is a file processed **in place** (`input == output`). - Directory arguments are rejected ("Directory not supported in simple mode"). - Defaults: detection enabled with threshold `0.25`, V2 profile first with automatic V1 fallback on skip. ``` -------------------------------- ### C++ exception handling with try-catch Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/errors.md Wrap engine construction and watermark removal in a try-catch block to handle exceptions thrown by the library. Log the error using spdlog and return a non-zero exit code. ```cpp #include "core/watermark_engine.hpp" #include try { gwt::WatermarkEngine engine(v1_small, v1_small_size, /*...*/); // may throw engine.remove_watermark(img); // may throw } catch (const std::exception& e) { spdlog::error("watermark processing failed: {}", e.what()); return 1; } ``` -------------------------------- ### IRenderBackend::imgui_shutdown Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Shuts down ImGui integration for the backend. ```APIDOC ## IRenderBackend::imgui_shutdown ### Description Shuts down ImGui integration for the backend. ### Method Virtual method ### Signature ```cpp virtual void imgui_shutdown() = 0; ``` ``` -------------------------------- ### IRenderBackend abstract class Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Abstract graphics backend interface with lifecycle, ImGui integration, frame management, texture operations, and backend info. Concrete implementations: D3D11Backend (GWT_HAS_D3D11), OpenGLBackend, VulkanBackend (GWT_HAS_VULKAN). ```cpp class IRenderBackend { public: virtual ~IRenderBackend() = default; IRenderBackend(const IRenderBackend&) = delete; IRenderBackend& operator=(const IRenderBackend&) = delete; // Lifecycle [[nodiscard]] virtual bool init(SDL_Window* window) = 0; virtual void shutdown() = 0; // ImGui integration virtual void imgui_init() = 0; virtual void imgui_shutdown() = 0; virtual void imgui_new_frame() = 0; virtual void imgui_render() = 0; // Frame management virtual void begin_frame() = 0; virtual void end_frame() = 0; virtual void present() = 0; virtual void on_resize(int width, int height) = 0; // Texture operations [[nodiscard]] virtual TextureHandle create_texture(const TextureDesc& desc, std::span data = {}) = 0; virtual void update_texture(TextureHandle handle, std::span data) = 0; virtual void destroy_texture(TextureHandle handle) = 0; [[nodiscard]] virtual void* get_imgui_texture_id(TextureHandle handle) const = 0; // Backend info [[nodiscard]] virtual std::string_view name() const noexcept = 0; [[nodiscard]] virtual BackendType type() const noexcept = 0; [[nodiscard]] virtual bool supports_compute() const noexcept = 0; [[nodiscard]] BackendError last_error() const noexcept { return m_last_error; } protected: IRenderBackend() = default; void set_error(BackendError error) noexcept { m_last_error = error; } void clear_error() noexcept { m_last_error = BackendError::None; } BackendError m_last_error{BackendError::None}; }; ``` -------------------------------- ### gwt::cli::run Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/cli.md Main entry point for the CLI. Parses arguments and dispatches to simple mode or full CLI11 parsing, handling conflicts and returning process exit codes. ```APIDOC ## gwt::cli::run ### Description Main entry point for the CLI. Parses arguments and dispatches to simple mode or full CLI11 parsing, handling conflicts and returning process exit codes. ### Signature ```cpp int run(int argc, char** argv); ``` ### Parameters - **argc** (int) - Required - Argument count - **argv** (char**) - Required - Argument values (CLI11-parsed options + positional paths) ### Returns - **int** - Process exit code: - `0` — file processed, or batch directory completed with no errors. - `1` — single-file run skipped (no watermark detected on any tried profile). - `2` — real failure (bad/conflicting arguments, missing input, IO/write error). ### Behavior - If arguments match simple mode (see `is_simple_mode`), forwards to `run_simple_mode`. - Detects `--legacy`/`--no-legacy` conflicts (exit 2). - Detects `--force-small` + `--force-large` conflicts (exit 2). - Standalone builds always operate in remove mode (`remove_mode = true`). ``` -------------------------------- ### Process multiple files in simple mode Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Process multiple image files at once in simple mode. Watermark detection is enabled by default; images without a detectable watermark are automatically skipped. ```bash # Process multiple files at once (new!) GeminiWatermarkTool img1.jpg img2.png img3.webp ``` -------------------------------- ### Backend::supports_compute Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Checks whether the backend supports compute operations. ```APIDOC ## Backend::supports_compute ### Description Checks whether the backend supports compute operations. ### Method Member function call ### Signature `bool supports_compute() const` ### Parameters None ### Return Value - `bool` - `true` if compute is supported, `false` otherwise. ### Example ```cpp spdlog::info("compute={}", b->supports_compute() ? "yes" : "no"); ``` ``` -------------------------------- ### macOS: Remove quarantine and make executable Source: https://github.com/allenk/geminiwatermarktool/blob/main/README.md Use when macOS shows 'Apple cannot check it for malicious software'. Removes the quarantine attribute and sets execute permission. Run from the directory containing the binary. ```bash xattr -dr com.apple.quarantine GeminiWatermarkTool chmod +x GeminiWatermarkTool ``` -------------------------------- ### is_backend_available Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Checks whether a backend of the given type can be created. Returns a boolean indicating availability. ```APIDOC ## is_backend_available ### Description Checks whether a backend of the given type can be created. Returns a boolean indicating availability. ### Method Function ### Signature ```cpp [[nodiscard]] bool is_backend_available(BackendType type) noexcept; ``` ### Parameters - `type` (BackendType) - Required - The backend type to check. ### Returns `bool` - `true` if a backend can be created, `false` otherwise. ``` -------------------------------- ### Windows configuration with icon resource and MSVC settings Source: https://github.com/allenk/geminiwatermarktool/blob/main/CMakeLists.txt Configures Windows-specific settings: generates a resource file from app.rc.in if app.ico exists, sets MSVC static runtime and compiler flags, and defines release optimizations. The GUI subsystem block is commented out. ```cmake if(WIN32) set(APP_ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/resources/app.ico") if(EXISTS "${APP_ICON_PATH}") # Generate .rc from template configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/resources/app.rc.in" "${CMAKE_CURRENT_BINARY_DIR}/resources/app.rc" @ONLY ) set(WIN_RESOURCE_FILE "${CMAKE_CURRENT_BINARY_DIR}/resources/app.rc") message(STATUS "Windows resource file configured with icon: ${APP_ICON_PATH}") else() message(STATUS "No icon found at ${APP_ICON_PATH}, skipping resource file") set(WIN_RESOURCE_FILE "") endif() # MSVC specific settings if(MSVC) # Use static runtime library (/MT instead of /MD) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") # Compiler flags add_compile_options(/W4 /utf-8) # Release optimizations set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /GL /Gy") set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG /OPT:REF /OPT:ICF") endif() # GUI: Use WIN32 subsystem (no console window) #if(BUILD_GUI) # set(WIN32_EXECUTABLE WIN32) #endif() endif() ``` -------------------------------- ### WatermarkEngine constructor (two-pair convenience) Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/watermark-engine.md Convenience constructor for V1 only, retained for callers without V2 assets. Throws std::runtime_error on decode failure. ```APIDOC ## Constructor ### Description Convenience constructor for V1 only, retained for callers without V2 assets. Throws std::runtime_error on decode failure. ### Signature ```cpp WatermarkEngine( const unsigned char* png_data_small, size_t png_size_small, const unsigned char* png_data_large, size_t png_size_large, float logo_value = 255.0f ); ``` ### Parameters - `png_data_small`, `png_size_small` (const unsigned char*, size_t) - Required - V1 small BG capture PNG bytes - `png_data_large`, `png_size_large` (const unsigned char*, size_t) - Required - V1 large BG capture PNG bytes - `logo_value` (float) - Optional - Logo brightness ### Throws - `std::runtime_error` on decode failure. ``` -------------------------------- ### Set include directories for src and assets Source: https://github.com/allenk/geminiwatermarktool/blob/main/CMakeLists.txt Adds the src and assets directories to the include path for the project target. ```cmake target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/assets ) ``` -------------------------------- ### IRenderBackend::end_frame Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/gui-app.md Ends the current frame. ```APIDOC ## IRenderBackend::end_frame ### Description Ends the current frame. ### Method Virtual method ### Signature ```cpp virtual void end_frame() = 0; ``` ``` -------------------------------- ### Define compile-time feature macros Source: https://github.com/allenk/geminiwatermarktool/blob/main/CMakeLists.txt Sets APP_VERSION, APP_NAME, and feature macros (GWT_HAS_GUI, GWT_HAS_D3D11, GWT_HAS_VULKAN, GWT_HAS_AI_DENOISE) based on build options. ```cmake target_compile_definitions(${PROJECT_NAME} PRIVATE APP_VERSION="${PROJECT_VERSION}" APP_NAME="${PROJECT_NAME}" $<$:GWT_HAS_GUI=1> $<$:GWT_HAS_D3D11=1> $<$:GWT_HAS_VULKAN=1> $<$:GWT_HAS_AI_DENOISE=1> ) ``` -------------------------------- ### Define main executable with add_executable Source: https://github.com/allenk/geminiwatermarktool/blob/main/CMakeLists.txt Creates the project executable, including main, core, CLI, utility sources, and optional Windows resource file. The WIN32_EXECUTABLE flag is used for GUI applications on Windows. ```cmake add_executable(${PROJECT_NAME} ${WIN32_EXECUTABLE} ${MAIN_SOURCE} ${CORE_SOURCES} ${CORE_HEADERS} ${CLI_SOURCES} ${CLI_HEADERS} ${UTILS_HEADERS} ${WIN_RESOURCE_FILE} ) ``` -------------------------------- ### CPU-only environment check Source: https://github.com/allenk/geminiwatermarktool/blob/main/_autodocs/api-reference/ai-denoise.md Shows that initialize() still returns true on CPU-only systems, using all available cores; device_name() reports "CPU (N threads)". Warns that no Vulkan GPU means slower but functional. ```cpp // CPU-only environment: initialize() still returns true, inference uses // all available cores; device_name() reports "CPU (N threads)". gwt::NcnnDenoiser d; const bool ok = d.initialize(); if (ok && !d.is_gpu_enabled()) { // warn: no Vulkan GPU -- slower but functional } ```