Skip to content

Commit 01e4080

Browse files
committed
Add an indication of whether the PNG/JPG image saving was successful or not,
see issue #528. Unfortunately the library used does not give any detailed information about possible errors. In fact stb_image_write.h (line 77) tells: "Each function returns 0 on failure and non-0 on success."
1 parent 48e0a28 commit 01e4080

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

examples/cli/main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,15 +1830,16 @@ int main(int argc, const char* argv[]) {
18301830
if (results[i].data == nullptr) {
18311831
continue;
18321832
}
1833+
int write_ok;
18331834
std::string final_image_path = i > 0 ? base_path + "_" + std::to_string(i + 1) + file_ext : base_path + file_ext;
18341835
if (is_jpg) {
1835-
stbi_write_jpg(final_image_path.c_str(), results[i].width, results[i].height, results[i].channel,
1836+
write_ok = stbi_write_jpg(final_image_path.c_str(), results[i].width, results[i].height, results[i].channel,
18361837
results[i].data, 90, get_image_params(params, params.seed + i).c_str());
1837-
printf("save result JPEG image to '%s'\n", final_image_path.c_str());
1838+
printf("save result JPEG image to '%s' (%s)\n", final_image_path.c_str(), write_ok==0 ? "failure":"success");
18381839
} else {
1839-
stbi_write_png(final_image_path.c_str(), results[i].width, results[i].height, results[i].channel,
1840+
write_ok = stbi_write_png(final_image_path.c_str(), results[i].width, results[i].height, results[i].channel,
18401841
results[i].data, 0, get_image_params(params, params.seed + i).c_str());
1841-
printf("save result PNG image to '%s'\n", final_image_path.c_str());
1842+
printf("save result PNG image to '%s' (%s)\n", final_image_path.c_str(), write_ok==0 ? "failure":"success");
18421843
}
18431844
}
18441845
}

0 commit comments

Comments
 (0)