summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorLode <lvandeve@gmail.com>2015-12-09 00:20:41 +0100
committerLode <lvandeve@gmail.com>2015-12-09 00:20:41 +0100
commitc965e8a1f340675bc8a10638470f818e3f743724 (patch)
treed5834e8948339ee50eadd277230efd03dd1ceb0a /examples
parent942c151c7b92dc727fc2d0a00211e9fa83ef6e83 (diff)
Made load_file function return error if file can't be opened
Diffstat (limited to 'examples')
-rw-r--r--examples/example_decode.c14
-rw-r--r--examples/example_decode.cpp8
2 files changed, 11 insertions, 11 deletions
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;