From 01e408004bbdd7dc8195469ee2727492d59dec9d Mon Sep 17 00:00:00 2001 From: akleine Date: Thu, 23 Oct 2025 14:33:40 +0200 Subject: [PATCH] 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." --- examples/cli/main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/cli/main.cpp b/examples/cli/main.cpp index 8f938c9b4..34a4a7966 100644 --- a/examples/cli/main.cpp +++ b/examples/cli/main.cpp @@ -1830,15 +1830,16 @@ int main(int argc, const char* argv[]) { if (results[i].data == nullptr) { continue; } + int write_ok; std::string final_image_path = i > 0 ? base_path + "_" + std::to_string(i + 1) + file_ext : base_path + file_ext; if (is_jpg) { - stbi_write_jpg(final_image_path.c_str(), results[i].width, results[i].height, results[i].channel, + write_ok = stbi_write_jpg(final_image_path.c_str(), results[i].width, results[i].height, results[i].channel, results[i].data, 90, get_image_params(params, params.seed + i).c_str()); - printf("save result JPEG image to '%s'\n", final_image_path.c_str()); + printf("save result JPEG image to '%s' (%s)\n", final_image_path.c_str(), write_ok==0 ? "failure":"success"); } else { - stbi_write_png(final_image_path.c_str(), results[i].width, results[i].height, results[i].channel, + write_ok = stbi_write_png(final_image_path.c_str(), results[i].width, results[i].height, results[i].channel, results[i].data, 0, get_image_params(params, params.seed + i).c_str()); - printf("save result PNG image to '%s'\n", final_image_path.c_str()); + printf("save result PNG image to '%s' (%s)\n", final_image_path.c_str(), write_ok==0 ? "failure":"success"); } } }