From 3bda0bf1020d61442616a4db27770ae00a31690f Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Sun, 22 Mar 2026 23:09:08 +0800 Subject: [PATCH] passthrough mode without any gens --- otherarch/sdcpp/sdtype_adapter.cpp | 174 ++++++++++++++++------------- 1 file changed, 97 insertions(+), 77 deletions(-) diff --git a/otherarch/sdcpp/sdtype_adapter.cpp b/otherarch/sdcpp/sdtype_adapter.cpp index 94d3ef1a8..5cf2f7a36 100644 --- a/otherarch/sdcpp/sdtype_adapter.cpp +++ b/otherarch/sdcpp/sdtype_adapter.cpp @@ -956,7 +956,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs) output.status = 0; return output; } - sd_image_t * results; + sd_image_t * results = nullptr; //sanitize prompts, remove quotes and limit lengths std::string cleanprompt = clean_input_prompt(inputs.prompt); @@ -1264,6 +1264,9 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs) int generated_num_results = 1; remove_limits = inputs.remove_limits; + //special case, is img2img and denoise strength is 0 and steps is 1, do a passthru + bool is_passthrough = (sd_params->sample_steps<=1 && sd_params->strength<=0 && is_img2img && vid_req_frames<=1 && extra_image_data.size()==0); + if(is_vid_model) { std::vector control_frames; //empty for now @@ -1398,11 +1401,14 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs) fflush(stdout); - results = generate_image(sd_ctx, ¶ms); - + if (is_passthrough) { + printf("No generation triggered, passthrough mode.\n"); + } else { + results = generate_image(sd_ctx, ¶ms); + } } - if (results == NULL) { + if (!is_passthrough && results == NULL) { printf("\nKCPP SD generate failed!\n"); output.data = ""; output.data_extra = ""; @@ -1415,94 +1421,108 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs) sd_image_t upscaled_image; upscaled_image.data = nullptr; - for (int i = 0; i < params.batch_count; i++) { - if (results[i].data == NULL) { - continue; - } - - //if multiframe, make a video - if(vid_req_frames>1 && generated_num_results>1 && is_vid_model) + if (is_passthrough) + { + //either return original image or upscale if needed + int out_data_len; + unsigned char * png = nullptr; + if(inputs.upscale && upscaler_ctx != nullptr) { - if(!sd_is_quiet && sddebugmode==1) - { - printf("\nSaving video buffer, VIDEO_OUTPUT_TYPE=%d...",video_output_type); - } - uint8_t * out_data = nullptr; - uint8_t * out_data2 = nullptr; - size_t out_len = 0; - size_t out_len2 = 0; - int status = 0; - int status2 = 0; - wasanim = true; - - if(video_output_type==0 || video_output_type==2) - { - status = create_gif_buf_from_sd_images_msf(results, generated_num_results, 16, &out_data,&out_len); - } - if(video_output_type==1 || video_output_type==2) - { - status2 = create_mjpg_avi_membuf_from_sd_images(results, generated_num_results, 16, 40, &out_data2,&out_len2); - } - - if(!sd_is_quiet && sddebugmode==1) - { - printf("Video Output Sizes: GIF=%zu AVI=%zu\n",out_len,out_len2); - if(status==0 && status2==0) - { - printf("Video(s) Saved (Len %zu)!\n",out_len); - } else { - printf("Save Failed!\n"); - } - } - recent_data = ""; + printf("Upscaling original image (passthrough)...\n"); + upscaled_image = upscale(upscaler_ctx, input_image, 2); + png = stbi_write_png_to_mem(upscaled_image.data, 0, upscaled_image.width, upscaled_image.height, upscaled_image.channel, &out_data_len, get_image_params(params, lora_meta).c_str()); + } else { + png = stbi_write_png_to_mem(input_image.data, 0, input_image.width, input_image.height, input_image.channel, &out_data_len, get_image_params(params, lora_meta).c_str()); + } + if (png != NULL) + { + recent_data = kcpp_base64_encode(png,out_data_len); recent_data2 = ""; - if(status==0 && out_len>0) - { - recent_data = kcpp_base64_encode(out_data, out_len); - free(out_data); - } - if (status2 == 0 && out_len2 > 0) { - if (recent_data == "") { - recent_data = kcpp_base64_encode(out_data2, out_len2); - } else { - recent_data2 = kcpp_base64_encode(out_data2, out_len2); - } - free(out_data2); - } + free(png); } - else + } + else + { + for (int i = 0; i < params.batch_count; i++) { - int out_data_len; - unsigned char * png = nullptr; - if(inputs.upscale && upscaler_ctx != nullptr) + if (results[i].data == NULL) { + continue; + } + + //if multiframe, make a video + if(vid_req_frames>1 && generated_num_results>1 && is_vid_model) { - //special case, is img2img and denoise strength is 0 and steps is 1, do a passthru - if(sd_params->sample_steps<=1 && sd_params->strength<=0 && is_img2img && extra_image_data.size()==0) + if(!sd_is_quiet && sddebugmode==1) { - printf("Upscaling input image (passthrough mode)...\n"); - upscaled_image = upscale(upscaler_ctx, input_image, 2); + printf("\nSaving video buffer, VIDEO_OUTPUT_TYPE=%d...",video_output_type); } - else + uint8_t * out_data = nullptr; + uint8_t * out_data2 = nullptr; + size_t out_len = 0; + size_t out_len2 = 0; + int status = 0; + int status2 = 0; + wasanim = true; + + if(video_output_type==0 || video_output_type==2) + { + status = create_gif_buf_from_sd_images_msf(results, generated_num_results, 16, &out_data,&out_len); + } + if(video_output_type==1 || video_output_type==2) + { + status2 = create_mjpg_avi_membuf_from_sd_images(results, generated_num_results, 16, 40, &out_data2,&out_len2); + } + + if(!sd_is_quiet && sddebugmode==1) + { + printf("Video Output Sizes: GIF=%zu AVI=%zu\n",out_len,out_len2); + if(status==0 && status2==0) + { + printf("Video(s) Saved (Len %zu)!\n",out_len); + } else { + printf("Save Failed!\n"); + } + } + recent_data = ""; + recent_data2 = ""; + if(status==0 && out_len>0) + { + recent_data = kcpp_base64_encode(out_data, out_len); + free(out_data); + } + if (status2 == 0 && out_len2 > 0) { + if (recent_data == "") { + recent_data = kcpp_base64_encode(out_data2, out_len2); + } else { + recent_data2 = kcpp_base64_encode(out_data2, out_len2); + } + free(out_data2); + } + } + else + { + int out_data_len; + unsigned char * png = nullptr; + if(inputs.upscale && upscaler_ctx != nullptr) { printf("Upscaling output image...\n"); upscaled_image = upscale(upscaler_ctx, results[i], 2); + png = stbi_write_png_to_mem(upscaled_image.data, 0, upscaled_image.width, upscaled_image.height, upscaled_image.channel, &out_data_len, nullptr); + } else { + png = stbi_write_png_to_mem(results[i].data, 0, results[i].width, results[i].height, results[i].channel, &out_data_len, nullptr); } - png = stbi_write_png_to_mem(upscaled_image.data, 0, upscaled_image.width, upscaled_image.height, upscaled_image.channel, &out_data_len, get_image_params(params, lora_meta).c_str()); - } else { - png = stbi_write_png_to_mem(results[i].data, 0, results[i].width, results[i].height, results[i].channel, &out_data_len, get_image_params(params, lora_meta).c_str()); + if (png != NULL) + { + recent_data = kcpp_base64_encode(png,out_data_len); + recent_data2 = ""; + free(png); + } } - if (png != NULL) - { - recent_data = kcpp_base64_encode(png,out_data_len); - recent_data2 = ""; - free(png); - } + free(results[i].data); + results[i].data = NULL; } - - free(results[i].data); - results[i].data = NULL; } if(upscaled_image.data)