diff --git a/examples/cli/main.cpp b/examples/cli/main.cpp index cf8f5b13..970f0aef 100644 --- a/examples/cli/main.cpp +++ b/examples/cli/main.cpp @@ -22,6 +22,8 @@ #define STB_IMAGE_RESIZE_STATIC #include "stb_image_resize.h" +#include "util.h" + const char* rng_type_to_str[] = { "std_default", "cuda", @@ -825,7 +827,6 @@ int main(int argc, const char* argv[]) { bool vae_decode_only = true; uint8_t* input_image_buffer = NULL; uint8_t* control_image_buffer = NULL; - uint8_t* mask_image_buffer = NULL; if (params.mode == IMG2IMG || params.mode == IMG2VID) { vae_decode_only = false; @@ -931,18 +932,6 @@ int main(int argc, const char* argv[]) { } } - if (params.mask_path != "") { - int c = 0; - mask_image_buffer = stbi_load(params.mask_path.c_str(), ¶ms.width, ¶ms.height, &c, 1); - } else { - std::vector<uint8_t> arr(params.width * params.height, 255); - mask_image_buffer = arr.data(); - } - sd_image_t mask_image = {(uint32_t)params.width, - (uint32_t)params.height, - 1, - mask_image_buffer}; - sd_image_t* results; if (params.mode == TXT2IMG) { results = txt2img(sd_ctx, @@ -1011,6 +1000,22 @@ int main(int argc, const char* argv[]) { free_sd_ctx(sd_ctx); return 0; } else { + uint8_t* mask_image_buffer = NULL; + if (params.mask_path != "") { + int c = 0; + mask_image_buffer = stbi_load(params.mask_path.c_str(), ¶ms.width, ¶ms.height, &c, 1); + } else { + std::vector<uint8_t> arr(params.width * params.height, 255); + // do not remove this LOG_DEBUG line, or -O3 may destroy arr[] + // before assigning to mask_image_buffer + LOG_DEBUG("img2img: created array with 0x%x fill", arr[0]); + mask_image_buffer = arr.data(); + } + const sd_image_t mask_image = {(uint32_t)params.width, + (uint32_t)params.height, + 1, + mask_image_buffer}; + LOG_DEBUG("img2img: created mask with 0x%x fill", *mask_image.data); results = img2img(sd_ctx, input_image, mask_image,