mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-10-30 08:42:00 +00:00 
			
		
		
		
	llava: build clip image from pixels (#11999)
* llava: export function `clip_build_img_from_pixels` to build image from pixels decoded by other libraries instead of stb_image.h for better performance * Apply suggestions from code review --------- Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com>
This commit is contained in:
		| @@ -1729,11 +1729,11 @@ void clip_image_f32_batch_free(struct clip_image_f32_batch  * batch) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| static void build_clip_img_from_data(const stbi_uc * data, int nx, int ny, clip_image_u8 * img) { | void clip_build_img_from_pixels(const unsigned char * rgb_pixels, int nx, int ny, clip_image_u8 * img) { | ||||||
|     img->nx = nx; |     img->nx = nx; | ||||||
|     img->ny = ny; |     img->ny = ny; | ||||||
|     img->buf.resize(3 * nx * ny); |     img->buf.resize(3 * nx * ny); | ||||||
|     memcpy(img->buf.data(), data, img->buf.size()); |     memcpy(img->buf.data(), rgb_pixels, img->buf.size()); | ||||||
| } | } | ||||||
|  |  | ||||||
| bool clip_image_load_from_file(const char * fname, clip_image_u8 * img) { | bool clip_image_load_from_file(const char * fname, clip_image_u8 * img) { | ||||||
| @@ -1743,7 +1743,7 @@ bool clip_image_load_from_file(const char * fname, clip_image_u8 * img) { | |||||||
|         LOG_ERR("%s: failed to load image '%s'\n", __func__, fname); |         LOG_ERR("%s: failed to load image '%s'\n", __func__, fname); | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|     build_clip_img_from_data(data, nx, ny, img); |     clip_build_img_from_pixels(data, nx, ny, img); | ||||||
|     stbi_image_free(data); |     stbi_image_free(data); | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| @@ -1755,7 +1755,7 @@ bool clip_image_load_from_bytes(const unsigned char * bytes, size_t bytes_length | |||||||
|         LOG_ERR("%s: failed to decode image bytes\n", __func__); |         LOG_ERR("%s: failed to decode image bytes\n", __func__); | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|     build_clip_img_from_data(data, nx, ny, img); |     clip_build_img_from_pixels(data, nx, ny, img); | ||||||
|     stbi_image_free(data); |     stbi_image_free(data); | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -73,6 +73,9 @@ CLIP_API void clip_image_f32_free(struct clip_image_f32 * img); | |||||||
| CLIP_API void clip_image_u8_batch_free (struct clip_image_u8_batch  * batch); | CLIP_API void clip_image_u8_batch_free (struct clip_image_u8_batch  * batch); | ||||||
| CLIP_API void clip_image_f32_batch_free(struct clip_image_f32_batch * batch); | CLIP_API void clip_image_f32_batch_free(struct clip_image_f32_batch * batch); | ||||||
|  |  | ||||||
|  | /** build image from pixels decoded by other libraries instead of stb_image.h for better performance. The memory layout is RGBRGBRGB..., input buffer length must be 3*nx*ny bytes */ | ||||||
|  | CLIP_API void clip_build_img_from_pixels(const unsigned char * rgb_pixels, int nx, int ny, clip_image_u8 * img); | ||||||
|  |  | ||||||
| CLIP_API bool clip_image_load_from_file(const char * fname, struct clip_image_u8 * img); | CLIP_API bool clip_image_load_from_file(const char * fname, struct clip_image_u8 * img); | ||||||
|  |  | ||||||
| /** interpret bytes as an image file with length bytes_length, and use the result to populate img */ | /** interpret bytes as an image file with length bytes_length, and use the result to populate img */ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Ting Lou
					Ting Lou