diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2015-05-23 23:42:26 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2015-05-23 23:42:26 +0000 |
| commit | 0539009c671a2ffc2478a50a11f48769c5c54b27 (patch) | |
| tree | 94d297d32a43d7b71a2740c053de0518df7f23d5 /src/Fl_PNG_Image.cxx | |
| parent | 03f69c0dd5244c50e430b430ee3a2e952b5a00fe (diff) | |
STR #2873: new function Fl_Image::fail() that returns 0, ERR_NO_IMAGE, ERR_FORMAT, or ERR_FILE_ACCESS to make life easier when loading images.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10732 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_PNG_Image.cxx')
| -rw-r--r-- | src/Fl_PNG_Image.cxx | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/Fl_PNG_Image.cxx b/src/Fl_PNG_Image.cxx index 3f5164fee..74d32da7d 100644 --- a/src/Fl_PNG_Image.cxx +++ b/src/Fl_PNG_Image.cxx @@ -71,18 +71,24 @@ extern "C" { /** - The constructor loads the named PNG image from the given png filename. + The constructor loads the named PNG image from the given png filename. - The destructor frees all memory and server resources that are used by - the image. + The destructor frees all memory and server resources that are used by + the image. - \param[in] filename Name of PNG file to read -*/ + Use Fl_Image::fail() to check if Fl_BMP_Image failed to load. fail() returns + ERR_FILE_ACCESS if the file could not bo opened or read, ERR_FORMAT if the + PNG format could not be decoded, and ERR_NO_IMAGE if the image could not + be loaded for another reason. + + \param[in] filename Name of PNG file to read + */ Fl_PNG_Image::Fl_PNG_Image (const char *filename): Fl_RGB_Image(0,0,0) { load_png_(filename, NULL, 0); } + /** \brief Constructor that reads a PNG image from memory. @@ -101,6 +107,7 @@ Fl_PNG_Image::Fl_PNG_Image ( load_png_(name_png, buffer, maxsize); } + void Fl_PNG_Image::load_png_(const char *name_png, const unsigned char *buffer_png, int maxsize) { #if defined(HAVE_LIBPNG) && defined(HAVE_LIBZ) @@ -114,7 +121,10 @@ void Fl_PNG_Image::load_png_(const char *name_png, const unsigned char *buffer_p int from_memory = (buffer_png != NULL); // true if reading image from memory if (!from_memory) { - if ((fp = fl_fopen(name_png, "rb")) == NULL) return; + if ((fp = fl_fopen(name_png, "rb")) == NULL) { + ld(ERR_FILE_ACCESS); + return; + } } const char *display_name = (name_png ? name_png : "In-memory PNG data"); @@ -125,6 +135,7 @@ void Fl_PNG_Image::load_png_(const char *name_png, const unsigned char *buffer_p if (pp) png_destroy_read_struct(&pp, NULL, NULL); if (!from_memory) fclose(fp); Fl::warning("Cannot allocate memory to read PNG file or data \"%s\".\n", display_name); + w(0); h(0); d(0); ld(ERR_FORMAT); return; } @@ -133,6 +144,7 @@ void Fl_PNG_Image::load_png_(const char *name_png, const unsigned char *buffer_p png_destroy_read_struct(&pp, &info, NULL); if (!from_memory) fclose(fp); Fl::warning("PNG file or data \"%s\" is too large or contains errors!\n", display_name); + w(0); h(0); d(0); ld(ERR_FORMAT); return; } |
