mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-09-24 20:20:37 +00:00
fix: honor reference image resize settings in OpenAI edits (#2025)
This commit is contained in:
parent
e112ab5a50
commit
ac45422a05
@ -148,6 +148,19 @@ Native extension fields:
|
||||
|
||||
- any `sdcpp API` fields embedded through `sd_cpp_extra_args` inside `prompt`
|
||||
|
||||
Reference image sizing follows `auto_resize_ref_image`, as in the native and SDAPI APIs.
|
||||
The server default is `true`; `--disable-auto-resize-ref-image` sets it to `false`.
|
||||
When enabled, uploaded references are center-cropped and resized to the request dimensions.
|
||||
If `size` is omitted, the first decoded image establishes those dimensions.
|
||||
When disabled, each reference retains its original dimensions.
|
||||
The init image and mask still use the request dimensions, independently of this option.
|
||||
|
||||
To override the server default for one request, include this in `prompt`:
|
||||
|
||||
```text
|
||||
edit this image <sd_cpp_extra_args>{"auto_resize_ref_image":false}</sd_cpp_extra_args>
|
||||
```
|
||||
|
||||
Response fields:
|
||||
|
||||
| Field | Type | Notes |
|
||||
|
||||
@ -157,6 +157,19 @@ static bool build_openai_edit_request(const httplib::Request& req,
|
||||
request.gen_params.height = height;
|
||||
request.gen_params.batch_count = n;
|
||||
|
||||
std::string sd_cpp_extra_args_str = extract_and_remove_sd_cpp_extra_args(request.gen_params.prompt);
|
||||
if (!sd_cpp_extra_args_str.empty()) {
|
||||
const json extra_args = json::parse(sd_cpp_extra_args_str, nullptr, false);
|
||||
if (extra_args.is_discarded()) {
|
||||
error_message = "invalid sd_cpp_extra_args";
|
||||
return false;
|
||||
}
|
||||
// Resolve resizing before decoding while keeping embedded image overrides last.
|
||||
if (extra_args.contains("auto_resize_ref_image") && extra_args["auto_resize_ref_image"].is_boolean()) {
|
||||
request.gen_params.auto_resize_ref_image = extra_args["auto_resize_ref_image"].get<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& bytes : images_bytes) {
|
||||
int img_w = 0;
|
||||
int img_h = 0;
|
||||
@ -165,7 +178,13 @@ static bool build_openai_edit_request(const httplib::Request& req,
|
||||
reinterpret_cast<const char*>(bytes.data()),
|
||||
static_cast<int>(bytes.size()),
|
||||
img_w, img_h, resolved_channel,
|
||||
0, 0, 0);
|
||||
request.gen_params.auto_resize_ref_image && request.gen_params.width_and_height_are_set()
|
||||
? request.gen_params.width
|
||||
: 0,
|
||||
request.gen_params.auto_resize_ref_image && request.gen_params.width_and_height_are_set()
|
||||
? request.gen_params.height
|
||||
: 0,
|
||||
0);
|
||||
if (raw_pixels == nullptr) {
|
||||
continue;
|
||||
}
|
||||
@ -226,7 +245,6 @@ static bool build_openai_edit_request(const httplib::Request& req,
|
||||
});
|
||||
}
|
||||
|
||||
std::string sd_cpp_extra_args_str = extract_and_remove_sd_cpp_extra_args(request.gen_params.prompt);
|
||||
if (!sd_cpp_extra_args_str.empty() && !request.gen_params.from_json_str(sd_cpp_extra_args_str)) {
|
||||
error_message = "invalid sd_cpp_extra_args";
|
||||
return false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user