Skip to content

fix: preserve reference image dimensions in server requests - #2007

Open
mikemikimike wants to merge 4 commits into
leejet:masterfrom
mikemikimike:fix/pid-ref-image-size-2004
Open

mikemikimike wants to merge 4 commits into
leejet:masterfrom
mikemikimike:fix/pid-ref-image-size-2004

Conversation

@mikemikimike

@mikemikimike mikemikimike commented Sep 20, 2026

Copy link
Copy Markdown

Summary

  • Preserve the source dimensions of ref_images, sdapi extra_images, and OpenAI edit uploads during decoding.
  • Keep output-size decoding for init and mask images unchanged.

Issue: #2004
Fixes #2004

Testing

  • cmake -S . -B build -DSD_BUILD_EXAMPLES=ON -DSD_SERVER_BUILD_FRONTEND=OFF -DSD_WEBP=OFF -DSD_WEBM=OFF -DCMAKE_BUILD_TYPE=Release
  • cmake --build build --parallel 4
  • sd-cli --help
  • sd-server --help

@leejet leejet left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not commit any test-related files.

@mikemikimike

Copy link
Copy Markdown
Author

@leejet The current head is 1a6d542b6df1d4f3b70eedb27ee574e3b52ecff9. gh pr diff --name-only contains only examples/common/common.cpp, examples/server/routes_openai.cpp, and examples/server/routes_sdapi.cpp; the previously added test files are no longer present. No code changes were made in this pass. Please re-review.

static_cast<int>(bytes.size()),
img_w, img_h,
width, height, 3);
0, 0, 3);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first reference image is also copied into init_image below. With this change, that copy retains the original dimensions and is later stretched to the output size by sd_image_to_tensor(), while the mask still goes through center-cropping and resizing during decoding.

When the uploaded image and mask have a different aspect ratio from the requested output, they therefore become misaligned, causing inpainting to affect the wrong region. I reproduced this with a 128×64 image/mask pair and a 64×64 output: they align before this change but not afterward.

Please keep the reference at its original size while separately applying the existing output-size crop/resize preprocessing to init_image, so it stays aligned with the mask.

@mikemikimike
mikemikimike force-pushed the fix/pid-ref-image-size-2004 branch from a4356f5 to c0d53d9 Compare September 21, 2026 19:11
@mikemikimike
mikemikimike force-pushed the fix/pid-ref-image-size-2004 branch from c0d53d9 to 1aabbdc Compare September 21, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants