Skip to content

feat(server): add image upscale endpoints#3

Open
mihard wants to merge 1 commit into
masterfrom
feat/server-upscale-api
Open

feat(server): add image upscale endpoints#3
mihard wants to merge 1 commit into
masterfrom
feat/server-upscale-api

Conversation

@mihard

@mihard mihard commented May 31, 2026

Copy link
Copy Markdown
Owner

What changed and why

Adds standalone image upscaling to the server, exposed on both API surfaces:

  • POST /sdapi/v1/extra-single-image — synchronous, A1111-compatible. Accepts a
    base64 image plus upscaler_1, upscaler_2, upscaling_resize / target dims and
    returns {"image": "<base64-png>", "html_info": ""}.
  • POST /sdcpp/v1/upscale — async job variant, polled via the existing
    GET /sdcpp/v1/jobs/{id} endpoint.

The shared perform_upscale() function handles:

  • Built-in resamplers: None (passthrough copy), Lanczos (CatmullRom filter),
    Nearest (Box filter) via a new resize_sd_image() helper in media_io.
  • Model-backed ESRGAN upscalers resolved from hires_upscalers_dir.
  • Optional two-upscaler pixel blending (upscaler_2_visibility), guarded so it only
    runs when both outputs share identical dimensions.
  • Post-upscale resize to exact target size when a model's native scale differs.

A new AsyncJobKind::Upscale variant and UpscaleJobRequest struct extend the
existing async job system without touching unrelated code paths.

Verification

Build with server examples enabled:

cmake -B build -DSD_BUILD_EXAMPLES=ON
cmake --build build --target sd-server

Smoke test — synchronous Lanczos upscale (2×):

IMG=$(base64 -w0 input.png)
curl -s -X POST http://localhost:8080/sdapi/v1/extra-single-image \
  -H 'Content-Type: application/json' \
  -d "{\"image\":\"$IMG\",\"upscaler_1\":\"Lanczos\",\"upscaling_resize\":2}" \
  | jq -r .image | base64 -d > output.png

Async upscale:

curl -s -X POST http://localhost:8080/sdcpp/v1/upscale \
  -H 'Content-Type: application/json' \
  -d "{\"image\":\"$IMG\",\"upscaler\":\"Lanczos\",\"scale\":2}" \
  | jq .poll_url
# then poll: GET /sdcpp/v1/jobs/{id}

Checklist

@mihard mihard changed the title Add image upscaling support with async job queue feat(server): add image upscale endpoints May 31, 2026
@mihard
mihard changed the base branch from claude/clever-hawking-6tNeg to master May 31, 2026 13:50
@mihard
mihard force-pushed the feat/server-upscale-api branch from 587d196 to 06070cb Compare May 31, 2026 21:33
@mihard
mihard force-pushed the feat/server-upscale-api branch from 06070cb to c93ae95 Compare June 5, 2026 15:50
Add standalone image upscaling to both server API surfaces:

- POST /sdapi/v1/extra-single-image (synchronous, A1111-compatible).
  Accepts image + upscaler_1/upscaler_2 + upscaling_resize/target dims
  and returns {"image": "<base64-png>", "html_info": ""}.
- POST /sdcpp/v1/upscale (async job, polled via /sdcpp/v1/jobs/{id}).

Shared perform_upscale() supports built-in resamplers (None passthrough,
Lanczos via CatmullRom, Nearest via Box through the new resize_sd_image()
helper in media_io), model-backed ESRGAN upscalers resolved from the hires
upscalers dir, optional two-upscaler blending, and exact target-size
resizing when a model's native scale differs from the requested size.

The blend path only runs when both upscaler outputs share identical
dimensions to avoid reading past the smaller buffer.
@mihard
mihard force-pushed the feat/server-upscale-api branch from c93ae95 to 7f49366 Compare June 5, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant