MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / slice_image

Method slice_image

subprojects/llama.cpp/tools/mtmd/clip.cpp:2652–2684  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2650 }
2651
2652 static std::vector<clip_image_u8_ptr> slice_image(const clip_image_u8 * img, const slice_instructions & inst) {
2653 std::vector<clip_image_u8_ptr> output;
2654
2655 // resize to overview size
2656 clip_image_u8_ptr resized_img(clip_image_u8_init());
2657 img_tool::resize(*img, *resized_img, inst.overview_size, inst.interpolation_overview,
2658 inst.padding_overview, inst.pad_color_overview);
2659 output.push_back(std::move(resized_img));
2660
2661 if (inst.slices.empty()) {
2662 // no slices, just return the resized image
2663 return output;
2664 }
2665
2666 // resize to refined size
2667 clip_image_u8_ptr refined_img(clip_image_u8_init());
2668 img_tool::resize(*img, *refined_img, inst.refined_size, inst.interpolation_refined,
2669 inst.padding_refined, inst.pad_color_refined);
2670
2671 // create slices
2672 for (const auto & slice : inst.slices) {
2673 int x = slice.x;
2674 int y = slice.y;
2675 int w = slice.size.width;
2676 int h = slice.size.height;
2677
2678 clip_image_u8_ptr img_slice(clip_image_u8_init());
2679 img_tool::crop(*refined_img, *img_slice, x, y, w, h);
2680 output.push_back(std::move(img_slice));
2681 }
2682
2683 return output;
2684 }
2685
2686private:
2687 static clip_image_size get_best_resize(const clip_image_size & original_size, int scale_resolution, int patch_size, bool allow_upscale = false) {

Callers

nothing calls this directly

Calls 3

clip_image_u8_initFunction · 0.85
emptyMethod · 0.65
push_backMethod · 0.45

Tested by

no test coverage detected