| 686 | } |
| 687 | |
| 688 | std::vector<clip_image_u8_ptr> mtmd_image_preprocessor_llava_uhd::slice_image(const clip_image_u8 & img, const mtmd_image_preprocessor_llava_uhd::slice_instructions & inst, bool overview_first) { |
| 689 | std::vector<clip_image_u8_ptr> output; |
| 690 | |
| 691 | // resize to overview size |
| 692 | clip_image_u8_ptr resized_img(clip_image_u8_init()); |
| 693 | img_tool::resize(img, *resized_img, inst.overview_size, hparams.image_resize_algo_ov, |
| 694 | hparams.image_pad_ov, hparams.image_pad_color_ov); |
| 695 | if (overview_first) { |
| 696 | output.push_back(std::move(resized_img)); |
| 697 | } |
| 698 | |
| 699 | if (inst.slices.empty()) { |
| 700 | // no slices, just return the resized image |
| 701 | if (!overview_first) { |
| 702 | output.push_back(std::move(resized_img)); |
| 703 | } |
| 704 | return output; |
| 705 | } |
| 706 | |
| 707 | // resize to refined size |
| 708 | clip_image_u8_ptr refined_img(clip_image_u8_init()); |
| 709 | img_tool::resize(img, *refined_img, inst.refined_size, hparams.image_resize_algo_rf, |
| 710 | hparams.image_pad_rf, hparams.image_pad_color_rf); |
| 711 | |
| 712 | // create slices |
| 713 | for (const auto & slice : inst.slices) { |
| 714 | int x = slice.x; |
| 715 | int y = slice.y; |
| 716 | int w = slice.size.width; |
| 717 | int h = slice.size.height; |
| 718 | |
| 719 | clip_image_u8_ptr img_slice(clip_image_u8_init()); |
| 720 | img_tool::crop(*refined_img, *img_slice, x, y, w, h); |
| 721 | output.push_back(std::move(img_slice)); |
| 722 | } |
| 723 | |
| 724 | if (!overview_first) { |
| 725 | output.push_back(std::move(resized_img)); |
| 726 | } |
| 727 | |
| 728 | return output; |
| 729 | } |
| 730 | |
| 731 | clip_image_size mtmd_image_preprocessor_llava_uhd::get_best_resize(const clip_image_size & original_size, int scale_resolution, int patch_size, bool allow_upscale) { |
| 732 | int width = original_size.width; |
nothing calls this directly
no test coverage detected