Skip to content

Commit fed0ed4

Browse files
authored
Move mask creation closer to img2img
Or else it can be filled with zeroes instead of 0xFF, with -O3 optimization.
1 parent 19d876e commit fed0ed4

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

examples/cli/main.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -931,18 +931,6 @@ int main(int argc, const char* argv[]) {
931931
}
932932
}
933933

934-
if (params.mask_path != "") {
935-
int c = 0;
936-
mask_image_buffer = stbi_load(params.mask_path.c_str(), &params.width, &params.height, &c, 1);
937-
} else {
938-
std::vector<uint8_t> arr(params.width * params.height, 255);
939-
mask_image_buffer = arr.data();
940-
}
941-
sd_image_t mask_image = {(uint32_t)params.width,
942-
(uint32_t)params.height,
943-
1,
944-
mask_image_buffer};
945-
946934
sd_image_t* results;
947935
if (params.mode == TXT2IMG) {
948936
results = txt2img(sd_ctx,
@@ -1011,6 +999,19 @@ int main(int argc, const char* argv[]) {
1011999
free_sd_ctx(sd_ctx);
10121000
return 0;
10131001
} else {
1002+
if (params.mask_path != "") {
1003+
int c = 0;
1004+
mask_image_buffer = stbi_load(params.mask_path.c_str(), &params.width, &params.height, &c, 1);
1005+
} else {
1006+
std::vector<uint8_t> arr(params.width * params.height, 255);
1007+
for (uint8_t dummy_arr : arr) if (dummy_arr) break; // dummy cycle to avoid -O3 optimization
1008+
mask_image_buffer = arr.data();
1009+
}
1010+
sd_image_t mask_image = {(uint32_t)params.width,
1011+
(uint32_t)params.height,
1012+
1,
1013+
mask_image_buffer};
1014+
LOG_DEBUG("img2img: created mask with 0x%x fill", *mask_image.data);
10141015
results = img2img(sd_ctx,
10151016
input_image,
10161017
mask_image,

0 commit comments

Comments
 (0)