1+ #include < cstdint>
12#define GGML_MAX_NAME 128
23
34#include < stdio.h>
@@ -226,7 +227,7 @@ int load_model(char *model, char *model_path, char* options[], int threads, int
226227 return 0 ;
227228}
228229
229- int gen_image (char *text, char *negativeText, int width, int height, int steps, int seed , char *dst, float cfg_scale, char *src_image, float strength, char *mask_image, char **ref_images, int ref_images_count) {
230+ int gen_image (char *text, char *negativeText, int width, int height, int steps, int64_t seed, char *dst, float cfg_scale, char *src_image, float strength, char *mask_image, char **ref_images, int ref_images_count) {
230231
231232 sd_image_t * results;
232233
@@ -252,14 +253,14 @@ int gen_image(char *text, char *negativeText, int width, int height, int steps,
252253 // Handle input image for img2img
253254 bool has_input_image = (src_image != NULL && strlen (src_image) > 0 );
254255 bool has_mask_image = (mask_image != NULL && strlen (mask_image) > 0 );
255-
256+
256257 uint8_t * input_image_buffer = NULL ;
257258 uint8_t * mask_image_buffer = NULL ;
258259 std::vector<uint8_t > default_mask_image_vec;
259-
260+
260261 if (has_input_image) {
261262 fprintf (stderr, " Loading input image: %s\n " , src_image);
262-
263+
263264 int c = 0 ;
264265 int img_width = 0 ;
265266 int img_height = 0 ;
@@ -273,29 +274,29 @@ int gen_image(char *text, char *negativeText, int width, int height, int steps,
273274 free (input_image_buffer);
274275 return 1 ;
275276 }
276-
277+
277278 // Resize input image if dimensions don't match
278279 if (img_width != width || img_height != height) {
279280 fprintf (stderr, " Resizing input image from %dx%d to %dx%d\n " , img_width, img_height, width, height);
280-
281+
281282 uint8_t * resized_image_buffer = (uint8_t *)malloc (height * width * 3 );
282283 if (resized_image_buffer == NULL ) {
283284 fprintf (stderr, " Failed to allocate memory for resized image\n " );
284285 free (input_image_buffer);
285286 return 1 ;
286287 }
287-
288+
288289 stbir_resize (input_image_buffer, img_width, img_height, 0 ,
289290 resized_image_buffer, width, height, 0 , STBIR_TYPE_UINT8,
290291 3 , STBIR_ALPHA_CHANNEL_NONE, 0 ,
291292 STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP,
292293 STBIR_FILTER_BOX, STBIR_FILTER_BOX,
293294 STBIR_COLORSPACE_SRGB, nullptr );
294-
295+
295296 free (input_image_buffer);
296297 input_image_buffer = resized_image_buffer;
297298 }
298-
299+
299300 p.init_image = {(uint32_t )width, (uint32_t )height, 3 , input_image_buffer};
300301 p.strength = strength;
301302 fprintf (stderr, " Using img2img with strength: %.2f\n " , strength);
@@ -304,11 +305,11 @@ int gen_image(char *text, char *negativeText, int width, int height, int steps,
304305 p.init_image = {(uint32_t )width, (uint32_t )height, 3 , NULL };
305306 p.strength = 0 .0f ;
306307 }
307-
308+
308309 // Handle mask image for inpainting
309310 if (has_mask_image) {
310311 fprintf (stderr, " Loading mask image: %s\n " , mask_image);
311-
312+
312313 int c = 0 ;
313314 int mask_width = 0 ;
314315 int mask_height = 0 ;
@@ -318,30 +319,30 @@ int gen_image(char *text, char *negativeText, int width, int height, int steps,
318319 if (input_image_buffer) free (input_image_buffer);
319320 return 1 ;
320321 }
321-
322+
322323 // Resize mask if dimensions don't match
323324 if (mask_width != width || mask_height != height) {
324325 fprintf (stderr, " Resizing mask image from %dx%d to %dx%d\n " , mask_width, mask_height, width, height);
325-
326+
326327 uint8_t * resized_mask_buffer = (uint8_t *)malloc (height * width);
327328 if (resized_mask_buffer == NULL ) {
328329 fprintf (stderr, " Failed to allocate memory for resized mask\n " );
329330 free (mask_image_buffer);
330331 if (input_image_buffer) free (input_image_buffer);
331332 return 1 ;
332333 }
333-
334+
334335 stbir_resize (mask_image_buffer, mask_width, mask_height, 0 ,
335336 resized_mask_buffer, width, height, 0 , STBIR_TYPE_UINT8,
336337 1 , STBIR_ALPHA_CHANNEL_NONE, 0 ,
337338 STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP,
338339 STBIR_FILTER_BOX, STBIR_FILTER_BOX,
339340 STBIR_COLORSPACE_SRGB, nullptr );
340-
341+
341342 free (mask_image_buffer);
342343 mask_image_buffer = resized_mask_buffer;
343344 }
344-
345+
345346 p.mask_image = {(uint32_t )width, (uint32_t )height, 1 , mask_image_buffer};
346347 fprintf (stderr, " Using inpainting with mask\n " );
347348 } else {
@@ -353,17 +354,17 @@ int gen_image(char *text, char *negativeText, int width, int height, int steps,
353354 // Handle reference images
354355 std::vector<sd_image_t > ref_images_vec;
355356 std::vector<uint8_t *> ref_image_buffers;
356-
357+
357358 if (ref_images_count > 0 && ref_images != NULL ) {
358359 fprintf (stderr, " Loading %d reference images\n " , ref_images_count);
359-
360+
360361 for (int i = 0 ; i < ref_images_count; i++) {
361362 if (ref_images[i] == NULL || strlen (ref_images[i]) == 0 ) {
362363 continue ;
363364 }
364-
365+
365366 fprintf (stderr, " Loading reference image %d: %s\n " , i + 1 , ref_images[i]);
366-
367+
367368 int c = 0 ;
368369 int ref_width = 0 ;
369370 int ref_height = 0 ;
@@ -377,33 +378,33 @@ int gen_image(char *text, char *negativeText, int width, int height, int steps,
377378 free (ref_image_buffer);
378379 continue ;
379380 }
380-
381+
381382 // Resize reference image if dimensions don't match
382383 if (ref_width != width || ref_height != height) {
383384 fprintf (stderr, " Resizing reference image from %dx%d to %dx%d\n " , ref_width, ref_height, width, height);
384-
385+
385386 uint8_t * resized_ref_buffer = (uint8_t *)malloc (height * width * 3 );
386387 if (resized_ref_buffer == NULL ) {
387388 fprintf (stderr, " Failed to allocate memory for resized reference image\n " );
388389 free (ref_image_buffer);
389390 continue ;
390391 }
391-
392+
392393 stbir_resize (ref_image_buffer, ref_width, ref_height, 0 ,
393394 resized_ref_buffer, width, height, 0 , STBIR_TYPE_UINT8,
394395 3 , STBIR_ALPHA_CHANNEL_NONE, 0 ,
395396 STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP,
396397 STBIR_FILTER_BOX, STBIR_FILTER_BOX,
397398 STBIR_COLORSPACE_SRGB, nullptr );
398-
399+
399400 free (ref_image_buffer);
400401 ref_image_buffer = resized_ref_buffer;
401402 }
402-
403+
403404 ref_image_buffers.push_back (ref_image_buffer);
404405 ref_images_vec.push_back ({(uint32_t )width, (uint32_t )height, 3 , ref_image_buffer});
405406 }
406-
407+
407408 if (!ref_images_vec.empty ()) {
408409 p.ref_images = ref_images_vec.data ();
409410 p.ref_images_count = ref_images_vec.size ();
0 commit comments