Skip to content

Commit a966110

Browse files
committed
refactor: Use image_manipulation util
Branch: GraniteDocling Signed-off-by: Gabe Goodhart <[email protected]>
1 parent 899b48a commit a966110

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

tools/mtmd/clip.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3562,14 +3562,8 @@ bool clip_image_preprocess(struct clip_ctx * ctx, const clip_image_u8 * img, str
35623562
// multiples of image_size (always rounding up)
35633563
//
35643564
// CITE: https://github.com/huggingface/transformers/blob/main/src/transformers/models/idefics3/image_processing_idefics3.py#L737
3565-
const float scale = std::min(
3566-
static_cast<float>(params.preproc_image_size) / original_size.width,
3567-
static_cast<float>(params.preproc_image_size) / original_size.height);
3568-
int refined_w = static_cast<int>(original_size.width * scale);
3569-
int refined_h = static_cast<int>(original_size.height * scale);
3570-
refined_w = static_cast<int>(params.image_size * std::ceil(static_cast<float>(refined_w) / params.image_size));
3571-
refined_h = static_cast<int>(params.image_size * std::ceil(static_cast<float>(refined_h) / params.image_size));
3572-
const clip_image_size refined_size{refined_w, refined_h};
3565+
const clip_image_size refined_size = image_manipulation::calc_size_preserved_ratio(
3566+
original_size, params.image_size, params.preproc_image_size);
35733567

35743568
llava_uhd::slice_instructions instructions;
35753569
instructions.overview_size = clip_image_size{params.image_size, params.image_size};

0 commit comments

Comments
 (0)