@@ -116,7 +116,7 @@ static int sddebugmode = 0;
116116static std::string recent_data = " " ;
117117static uint8_t * input_image_buffer = NULL ;
118118static uint8_t * input_mask_buffer = NULL ;
119- static uint8_t * input_photomaker_buffer = NULL ;
119+ static uint8_t * input_extraimage_buffer = NULL ;
120120
121121static std::string sdplatformenv, sddeviceenv, sdvulkandeviceenv;
122122static int cfg_tiled_vae_threshold = 0 ;
@@ -434,14 +434,9 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
434434 std::string cleannegprompt = clean_input_prompt (inputs.negative_prompt );
435435 std::string img2img_data = std::string (inputs.init_images );
436436 std::string img2img_mask = std::string (inputs.mask );
437- std::string photomaker_image_data = std::string (inputs.photomaker_image );
437+ std::string extra_image_data = std::string (inputs.extra_image );
438438 std::string sampler = inputs.sample_method ;
439439
440- if (!photomaker_enabled)
441- {
442- photomaker_image_data = " " ;
443- }
444-
445440 sd_params->prompt = cleanprompt;
446441 sd_params->negative_prompt = cleannegprompt;
447442 sd_params->cfg_scale = inputs.cfg_scale ;
@@ -508,17 +503,17 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
508503
509504 // for img2img
510505 sd_image_t input_image = {0 ,0 ,0 ,nullptr };
511- sd_image_t photomaker_reference = {0 ,0 ,0 ,nullptr };
506+ sd_image_t extraimage_reference = {0 ,0 ,0 ,nullptr };
512507 std::vector<uint8_t > image_buffer;
513508 std::vector<uint8_t > image_mask_buffer;
514- std::vector<uint8_t > photomaker_buffer ;
509+ std::vector<uint8_t > extraimage_buffer ;
515510 int nx, ny, nc;
516511 int img2imgW = sd_params->width ; // for img2img input
517512 int img2imgH = sd_params->height ;
518513 int img2imgC = 3 ; // Assuming RGB image
519514 std::vector<uint8_t > resized_image_buf (img2imgW * img2imgH * img2imgC);
520515 std::vector<uint8_t > resized_mask_buf (img2imgW * img2imgH * img2imgC);
521- std::vector<uint8_t > resized_photomaker_buf (img2imgW * img2imgH * img2imgC);
516+ std::vector<uint8_t > resized_extraimage_buf (img2imgW * img2imgH * img2imgC);
522517
523518 std::string ts = get_timestamp_str ();
524519 if (!sd_is_quiet)
@@ -563,35 +558,38 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
563558 sd_params->sample_method = sample_method_t ::EULER_A;
564559 }
565560
566- if (photomaker_image_data !=" " )
561+ if (extra_image_data !=" " )
567562 {
568- if (input_photomaker_buffer !=nullptr ) // just in time free old buffer
563+ if (input_extraimage_buffer !=nullptr ) // just in time free old buffer
569564 {
570- stbi_image_free (input_photomaker_buffer );
571- input_photomaker_buffer = nullptr ;
565+ stbi_image_free (input_extraimage_buffer );
566+ input_extraimage_buffer = nullptr ;
572567 }
573568 int nx2, ny2, nc2;
574- photomaker_buffer = kcpp_base64_decode (photomaker_image_data );
575- input_photomaker_buffer = stbi_load_from_memory (photomaker_buffer .data (), photomaker_buffer .size (), &nx2, &ny2, &nc2, 1 );
569+ extraimage_buffer = kcpp_base64_decode (extra_image_data );
570+ input_extraimage_buffer = stbi_load_from_memory (extraimage_buffer .data (), extraimage_buffer .size (), &nx2, &ny2, &nc2, 1 );
576571 // Resize the image
577- int resok = stbir_resize_uint8 (input_photomaker_buffer , nx2, ny2, 0 , resized_photomaker_buf .data (), img2imgW, img2imgH, 0 , 1 );
572+ int resok = stbir_resize_uint8 (input_extraimage_buffer , nx2, ny2, 0 , resized_extraimage_buf .data (), img2imgW, img2imgH, 0 , 1 );
578573 if (!resok) {
579- printf (" \n KCPP SD: resize photomaker image failed!\n " );
574+ printf (" \n KCPP SD: resize extra image failed!\n " );
580575 output.data = " " ;
581576 output.status = 0 ;
582577 return output;
583578 }
584- photomaker_reference .width = img2imgW;
585- photomaker_reference .height = img2imgH;
586- photomaker_reference .channel = img2imgC;
587- photomaker_reference .data = resized_photomaker_buf .data ();
579+ extraimage_reference .width = img2imgW;
580+ extraimage_reference .height = img2imgH;
581+ extraimage_reference .channel = img2imgC;
582+ extraimage_reference .data = resized_extraimage_buf .data ();
588583
589584 // ensure prompt has img keyword, otherwise append it
590- if (sd_params->prompt .find (" img" ) == std::string::npos) {
591- sd_params->prompt += " img" ;
592- } else if (sd_params->prompt .rfind (" img" , 0 ) == 0 ) {
593- // "img" found at the start of the string (position 0), which is not allowed. Add some text before it
594- sd_params->prompt = " person " + sd_params->prompt ;
585+ if (photomaker_enabled)
586+ {
587+ if (sd_params->prompt .find (" img" ) == std::string::npos) {
588+ sd_params->prompt += " img" ;
589+ } else if (sd_params->prompt .rfind (" img" , 0 ) == 0 ) {
590+ // "img" found at the start of the string (position 0), which is not allowed. Add some text before it
591+ sd_params->prompt = " person " + sd_params->prompt ;
592+ }
595593 }
596594 }
597595
@@ -638,7 +636,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
638636 sd_params->slg_scale ,
639637 sd_params->skip_layer_start ,
640638 sd_params->skip_layer_end ,
641- (photomaker_image_data !=" " ?(&photomaker_reference ):nullptr ));
639+ (photomaker_enabled && extra_image_data !=" " ?(&extraimage_reference ):nullptr ));
642640 } else {
643641
644642 if (sd_params->width <= 0 || sd_params->width % 64 != 0 || sd_params->height <= 0 || sd_params->height % 64 != 0 ) {
@@ -762,7 +760,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
762760 sd_params->slg_scale ,
763761 sd_params->skip_layer_start ,
764762 sd_params->skip_layer_end ,
765- (photomaker_image_data !=" " ?(&photomaker_reference ):nullptr ));
763+ (photomaker_enabled && extra_image_data !=" " ?(&extraimage_reference ):nullptr ));
766764 }
767765
768766 if (results == NULL ) {
0 commit comments