@@ -68,19 +68,6 @@ void mtmd_free(mtmd_context * ctx) {
6868 }
6969}
7070
71- int32_t mtmd_bitmap_init_from_file (const char * fname, mtmd_bitmap & output) {
72- clip_image_u8_ptr img_u8 (clip_image_u8_init ());
73- bool ok = clip_image_load_from_file (fname, img_u8.get ());
74- if (!ok) {
75- LOG_ERR (" Unable to load image %s\n " , fname);
76- return 1 ;
77- }
78- unsigned char * data = clip_image_u8_get_data (img_u8.get (), &output.nx , &output.ny );
79- output.data .resize (output.nx * output.ny * 3 );
80- std::memcpy (output.data .data (), data, output.nx * output.ny * 3 );
81- return 0 ;
82- }
83-
8471// copied from common_tokenize
8572static std::vector<llama_token> mtmd_tokenize_text_internal (
8673 const struct llama_vocab * vocab,
@@ -326,3 +313,29 @@ int32_t mtmd_helper_eval(mtmd_context * ctx,
326313 llama_batch_free (text_batch);
327314 return 0 ;
328315}
316+
317+ int32_t mtmd_helper_bitmap_init_from_buf (const unsigned char * buf, size_t len, mtmd_bitmap & output) {
318+ clip_image_u8_ptr img_u8 (clip_image_u8_init ());
319+ bool ok = clip_image_load_from_bytes (buf, len, img_u8.get ());
320+ if (!ok) {
321+ LOG_ERR (" Unable to load image from buffer\n " );
322+ return 1 ;
323+ }
324+ unsigned char * data = clip_image_u8_get_data (img_u8.get (), &output.nx , &output.ny );
325+ output.data .resize (output.nx * output.ny * 3 );
326+ std::memcpy (output.data .data (), data, output.nx * output.ny * 3 );
327+ return 0 ;
328+ }
329+
330+ int32_t mtmd_helper_bitmap_init_from_file (const char * fname, mtmd_bitmap & output) {
331+ clip_image_u8_ptr img_u8 (clip_image_u8_init ());
332+ bool ok = clip_image_load_from_file (fname, img_u8.get ());
333+ if (!ok) {
334+ LOG_ERR (" Unable to load image %s\n " , fname);
335+ return 1 ;
336+ }
337+ unsigned char * data = clip_image_u8_get_data (img_u8.get (), &output.nx , &output.ny );
338+ output.data .resize (output.nx * output.ny * 3 );
339+ std::memcpy (output.data .data (), data, output.nx * output.ny * 3 );
340+ return 0 ;
341+ }
0 commit comments