mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-09-24 20:20:37 +00:00
fix: prevent clip_preprocess center crop from exceeding the resized image (#1995)
This commit is contained in:
parent
9982c9caae
commit
d32b4e893b
@ -755,6 +755,13 @@ sd::Tensor<float> clip_preprocess(const sd::Tensor<float>& image, int target_wid
|
|||||||
int64_t resized_width = static_cast<int64_t>(scale * static_cast<float>(image.shape()[0]));
|
int64_t resized_width = static_cast<int64_t>(scale * static_cast<float>(image.shape()[0]));
|
||||||
int64_t resized_height = static_cast<int64_t>(scale * static_cast<float>(image.shape()[1]));
|
int64_t resized_height = static_cast<int64_t>(scale * static_cast<float>(image.shape()[1]));
|
||||||
|
|
||||||
|
// The resized image must cover the crop window. Floating-point rounding can
|
||||||
|
// leave a side one pixel short of the crop target (e.g. 730 -> 735.999...
|
||||||
|
// -> 735 after truncation), so clamp to keep the center crop in bounds.
|
||||||
|
// Truncation is otherwise preserved to avoid changing existing results.
|
||||||
|
resized_width = std::max<int64_t>(resized_width, target_width);
|
||||||
|
resized_height = std::max<int64_t>(resized_height, target_height);
|
||||||
|
|
||||||
sd::Tensor<float> resized = sd::ops::interpolate(
|
sd::Tensor<float> resized = sd::ops::interpolate(
|
||||||
image,
|
image,
|
||||||
{resized_width, resized_height, image.shape()[2], image.shape()[3]});
|
{resized_width, resized_height, image.shape()[2], image.shape()[3]});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user