Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Img2img mask can be filled with zeroes #610

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions examples/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(), &params.width, &params.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,
Expand Down Expand Up @@ -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(), &params.width, &params.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,
Expand Down
Loading