| 110 | } |
| 111 | |
| 112 | static bool load_file_to_bytes(const char* path, unsigned char** bytesOut, long *sizeOut) { |
| 113 | auto file = fopen(path, "rb"); |
| 114 | if (file == NULL) { |
| 115 | fprintf(stderr, "%s: can't read file %s\n", __func__, path); |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | fseek(file, 0, SEEK_END); |
| 120 | auto fileSize = ftell(file); |
| 121 | fseek(file, 0, SEEK_SET); |
| 122 | |
| 123 | auto buffer = (unsigned char *)malloc(fileSize); // Allocate memory to hold the file data |
| 124 | if (buffer == NULL) { |
| 125 | fprintf(stderr, "%s: failed to alloc %ld bytes for file %s\n", __func__, fileSize, path); |
| 126 | perror("Memory allocation error"); |
| 127 | fclose(file); |
| 128 | return false; |
| 129 | } |
| 130 | fread(buffer, 1, fileSize, file); // Read the file into the buffer |
| 131 | fclose(file); // Close the file |
| 132 | |
| 133 | *bytesOut = buffer; |
| 134 | *sizeOut = fileSize; |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | LLAVA_API struct llava_image_embed * llava_image_embed_make_with_filename(struct clip_ctx * ctx_clip, int n_threads, const char * image_path) { |
| 139 | unsigned char* image_bytes; |
no test coverage detected