From c965e8a1f340675bc8a10638470f818e3f743724 Mon Sep 17 00:00:00 2001 From: Lode Date: Wed, 9 Dec 2015 00:20:41 +0100 Subject: Made load_file function return error if file can't be opened --- examples/example_decode.c | 14 +++++++------- examples/example_decode.cpp | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/example_decode.c b/examples/example_decode.c index 1ecec3d..8f6ce39 100644 --- a/examples/example_decode.c +++ b/examples/example_decode.c @@ -59,11 +59,11 @@ void decodeTwoSteps(const char* filename) unsigned error; unsigned char* image; unsigned width, height; - unsigned char* png; + unsigned char* png = 0; size_t pngsize; - lodepng_load_file(&png, &pngsize, filename); - error = lodepng_decode32(&image, &width, &height, png, pngsize); + error = lodepng_load_file(&png, &pngsize, filename); + if(!error) error = lodepng_decode32(&image, &width, &height, png, pngsize); if(error) printf("error %u: %s\n", error, lodepng_error_text(error)); free(png); @@ -82,15 +82,15 @@ void decodeWithState(const char* filename) unsigned error; unsigned char* image; unsigned width, height; - unsigned char* png; + unsigned char* png = 0; size_t pngsize; LodePNGState state; lodepng_state_init(&state); /*optionally customize the state*/ - lodepng_load_file(&png, &pngsize, filename); - error = lodepng_decode(&image, &width, &height, &state, png, pngsize); + error = lodepng_load_file(&png, &pngsize, filename); + if(!error) error = lodepng_decode(&image, &width, &height, &state, png, pngsize); if(error) printf("error %u: %s\n", error, lodepng_error_text(error)); free(png); @@ -107,7 +107,7 @@ int main(int argc, char *argv[]) const char* filename = argc > 1 ? argv[1] : "test.png"; decodeOneStep(filename); - + return 0; } diff --git a/examples/example_decode.cpp b/examples/example_decode.cpp index 4eee6b8..76cda6e 100644 --- a/examples/example_decode.cpp +++ b/examples/example_decode.cpp @@ -58,8 +58,8 @@ void decodeTwoSteps(const char* filename) unsigned width, height; //load and decode - lodepng::load_file(png, filename); - unsigned error = lodepng::decode(image, width, height, png); + unsigned error = lodepng::load_file(png, filename); + if(!error) error = lodepng::decode(image, width, height, png); //if there's an error, display it if(error) std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; @@ -76,8 +76,8 @@ void decodeWithState(const char* filename) unsigned width, height; lodepng::State state; //optionally customize this one - lodepng::load_file(png, filename); //load the image file with given filename - unsigned error = lodepng::decode(image, width, height, state, png); + unsigned error = lodepng::load_file(png, filename); //load the image file with given filename + if(!error) error = lodepng::decode(image, width, height, state, png); //if there's an error, display it if(error) std::cout << "decoder error " << error << ": "<< lodepng_error_text(error) << std::endl; -- cgit v1.2.3