Skip to content

Commit 0bd648f

Browse files
committed
photomaker renamed to extra image to handle future extension
1 parent 815d205 commit 0bd648f

File tree

4 files changed

+41
-43
lines changed

4 files changed

+41
-43
lines changed

expose.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ struct sd_generation_inputs
181181
const char * negative_prompt = nullptr;
182182
const char * init_images = "";
183183
const char * mask = "";
184-
const char * photomaker_image = "";
184+
const char * extra_image = "";
185185
const bool flip_mask = false;
186186
const float denoising_strength = 0.0f;
187187
const float cfg_scale = 0.0f;

kcpp_sdui.embd

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

koboldcpp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class sd_generation_inputs(ctypes.Structure):
291291
("negative_prompt", ctypes.c_char_p),
292292
("init_images", ctypes.c_char_p),
293293
("mask", ctypes.c_char_p),
294-
("photomaker_image", ctypes.c_char_p),
294+
("extra_image", ctypes.c_char_p),
295295
("flip_mask", ctypes.c_bool),
296296
("denoising_strength", ctypes.c_float),
297297
("cfg_scale", ctypes.c_float),
@@ -1714,7 +1714,7 @@ def sd_generate(genparams):
17141714
seed = random.randint(100000, 999999)
17151715
sample_method = genparams.get("sampler_name", "k_euler_a")
17161716
clip_skip = tryparseint(genparams.get("clip_skip", -1),-1)
1717-
photomaker_image = strip_base64_prefix(genparams.get("photomaker_image", ""))
1717+
extra_image = strip_base64_prefix(genparams.get("extra_image", ""))
17181718

17191719
#clean vars
17201720
cfg_scale = (1 if cfg_scale < 1 else (25 if cfg_scale > 25 else cfg_scale))
@@ -1728,7 +1728,7 @@ def sd_generate(genparams):
17281728
inputs.negative_prompt = negative_prompt.encode("UTF-8")
17291729
inputs.init_images = init_images.encode("UTF-8")
17301730
inputs.mask = "".encode("UTF-8") if not mask else mask.encode("UTF-8")
1731-
inputs.photomaker_image = "".encode("UTF-8") if not photomaker_image else photomaker_image.encode("UTF-8")
1731+
inputs.extra_image = "".encode("UTF-8") if not extra_image else extra_image.encode("UTF-8")
17321732
inputs.flip_mask = flip_mask
17331733
inputs.cfg_scale = cfg_scale
17341734
inputs.denoising_strength = denoising_strength

otherarch/sdcpp/sdtype_adapter.cpp

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int sddebugmode = 0;
116116
static std::string recent_data = "";
117117
static uint8_t * input_image_buffer = NULL;
118118
static uint8_t * input_mask_buffer = NULL;
119-
static uint8_t * input_photomaker_buffer = NULL;
119+
static uint8_t * input_extraimage_buffer = NULL;
120120

121121
static std::string sdplatformenv, sddeviceenv, sdvulkandeviceenv;
122122
static 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("\nKCPP SD: resize photomaker image failed!\n");
574+
printf("\nKCPP 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

Comments
 (0)