| 86 | } |
| 87 | |
| 88 | LLAVA_API struct llava_image_embed * llava_image_embed_make_with_bytes(struct clip_ctx * ctx_clip, int n_threads, const unsigned char * image_bytes, int image_bytes_length) { |
| 89 | clip_image_u8 * img = make_clip_image_u8(); |
| 90 | if (!clip_image_load_from_bytes(image_bytes, image_bytes_length, img)) { |
| 91 | clip_image_u8_free(img); |
| 92 | fprintf(stderr, "%s: can't load image from bytes, is it a valid image?", __func__); |
| 93 | return NULL; |
| 94 | } |
| 95 | |
| 96 | float* image_embed = NULL; |
| 97 | int n_image_pos = 0; |
| 98 | bool image_embed_result = llava_image_embed_make_with_clip_img(ctx_clip, n_threads, img, &image_embed, &n_image_pos); |
| 99 | if (!image_embed_result) { |
| 100 | clip_image_u8_free(img); |
| 101 | fprintf(stderr, "%s: coulnd't embed the image\n", __func__); |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | clip_image_u8_free(img); |
| 106 | auto result = (llava_image_embed*)malloc(sizeof(llava_image_embed)); |
| 107 | result->embed = image_embed; |
| 108 | result->n_image_pos = n_image_pos; |
| 109 | return result; |
| 110 | } |
| 111 | |
| 112 | static bool load_file_to_bytes(const char* path, unsigned char** bytesOut, long *sizeOut) { |
| 113 | auto file = fopen(path, "rb"); |
no test coverage detected