summaryrefslogtreecommitdiff
path: root/src/Fl_PNM_Image.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2015-05-23 23:42:26 +0000
committerMatthias Melcher <fltk@matthiasm.com>2015-05-23 23:42:26 +0000
commit0539009c671a2ffc2478a50a11f48769c5c54b27 (patch)
tree94d297d32a43d7b71a2740c053de0518df7f23d5 /src/Fl_PNM_Image.cxx
parent03f69c0dd5244c50e430b430ee3a2e952b5a00fe (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_PNM_Image.cxx')
-rw-r--r--src/Fl_PNM_Image.cxx22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/Fl_PNM_Image.cxx b/src/Fl_PNM_Image.cxx
index c4a65076f..40073b26a 100644
--- a/src/Fl_PNM_Image.cxx
+++ b/src/Fl_PNM_Image.cxx
@@ -37,11 +37,18 @@
// 'Fl_PNM_Image::Fl_PNM_Image()' - Load a PNM image...
//
-/**
- The constructor loads the named PNM image.
- <P>The inherited destructor free all memory and server resources that are used by the image.
-*/
+/**
+ The constructor loads the named PNM image.
+
+ The inherited destructor free all memory and server resources that are used by
+ the image.
+
+ 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
+ PNM format could not be decoded, and ERR_NO_IMAGE if the image could not
+ be loaded for another reason.
+ */
Fl_PNM_Image::Fl_PNM_Image(const char *name) // I - File to read
: Fl_RGB_Image(0,0,0) {
FILE *fp; // File pointer
@@ -56,7 +63,10 @@ Fl_PNM_Image::Fl_PNM_Image(const char *name) // I - File to read
maxval; // Maximum pixel value
- if ((fp = fl_fopen(name, "rb")) == NULL) return;
+ if ((fp = fl_fopen(name, "rb")) == NULL) {
+ ld(ERR_FILE_ACCESS);
+ return;
+ }
//
// Read the file header in the format:
@@ -75,6 +85,7 @@ Fl_PNM_Image::Fl_PNM_Image(const char *name) // I - File to read
if (!lineptr) {
fclose(fp);
Fl::error("Early end-of-file in PNM file \"%s\"!", name);
+ ld(ERR_FILE_ACCESS);
return;
}
@@ -122,6 +133,7 @@ Fl_PNM_Image::Fl_PNM_Image(const char *name) // I - File to read
if (((size_t)w()) * h() * d() > max_size() ) {
Fl::warning("PNM file \"%s\" is too large!\n", name);
fclose(fp);
+ w(0); h(0); d(0); ld(ERR_FORMAT);
return;
}
array = new uchar[w() * h() * d()];