fix bug in bicubic resize when need resize iamge smaller

This commit is contained in:
caitianchi 2024-05-30 16:39:42 +08:00
parent c38d152d7d
commit 88f5e6ab36

View File

@ -125,10 +125,6 @@ static std::pair<int, int> uhd_find_best_resize(std::pair<int, int> original_siz
return std::make_pair(best_width, best_height); return std::make_pair(best_width, best_height);
} }
inline float clip(float x, float lower, float upper) {
return std::max(lower, std::min(x, upper));
}
static std::pair<int, int> uhd_get_refine_size(std::pair<int, int> original_size, std::pair<int, int> grid, int scale_resolution, int patch_size, bool allow_upscale = false) { static std::pair<int, int> uhd_get_refine_size(std::pair<int, int> original_size, std::pair<int, int> grid, int scale_resolution, int patch_size, bool allow_upscale = false) {
int width, height; int width, height;
std::tie(width, height) = original_size; std::tie(width, height) = original_size;
@ -151,6 +147,10 @@ static std::pair<int, int> uhd_get_refine_size(std::pair<int, int> original_size
return refine_size; return refine_size;
} }
inline int clip(int x, int lower, int upper) {
return std::max(lower, std::min(x, upper));
}
static bool bicubic_resize(const clip_image_u8 &img, clip_image_u8 &dst, int target_width, int target_height) { static bool bicubic_resize(const clip_image_u8 &img, clip_image_u8 &dst, int target_width, int target_height) {
const int nx = img.nx; const int nx = img.nx;
const int ny = img.ny; const int ny = img.ny;
@ -251,6 +251,7 @@ static std::vector<std::vector<clip_image_u8 *>> uhd_slice_image(const clip_imag
clip_image_u8 *source_image = clip_image_u8_init(); clip_image_u8 *source_image = clip_image_u8_init();
bicubic_resize(*img, *source_image, best_size.first, best_size.second); bicubic_resize(*img, *source_image, best_size.first, best_size.second);
// source_image = image.copy().resize(best_resize, Image.Resampling.BICUBIC) // source_image = image.copy().resize(best_resize, Image.Resampling.BICUBIC)
LOG_TEE("%s: image_size: %d %d; source_image size: %d %d\n", __func__, img->nx, img->ny, best_size.first, best_size.second);
images[images.size()-1].push_back(source_image); images[images.size()-1].push_back(source_image);
std::vector<std::pair<int, int>> candidate_grids; std::vector<std::pair<int, int>> candidate_grids;
@ -281,7 +282,7 @@ static std::vector<std::vector<clip_image_u8 *>> uhd_slice_image(const clip_imag
clip_image_u8 *refine_image = clip_image_u8_init(); clip_image_u8 *refine_image = clip_image_u8_init();
bicubic_resize(*img, *refine_image, refine_size.first, refine_size.second); bicubic_resize(*img, *refine_image, refine_size.first, refine_size.second);
LOG_TEE("%s: refine_image_size: %d %d; best_grid: %d %d\n", __func__, refine_image->nx, refine_image->ny, best_grid.first, best_grid.second); LOG_TEE("%s: refine_image_size: %d %d; refine_size: %d %d\n", __func__, refine_image->nx, refine_image->ny, refine_size.first, refine_size.second);
// split_to_patches // split_to_patches
int width = refine_image->nx; int width = refine_image->nx;