summaryrefslogtreecommitdiff
path: root/src/Fl_BMP_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_BMP_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_BMP_Image.cxx')
-rw-r--r--src/Fl_BMP_Image.cxx26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/Fl_BMP_Image.cxx b/src/Fl_BMP_Image.cxx
index 8542763be..be291b616 100644
--- a/src/Fl_BMP_Image.cxx
+++ b/src/Fl_BMP_Image.cxx
@@ -52,13 +52,19 @@
static int read_long(FILE *fp);
static unsigned short read_word(FILE *fp);
static unsigned int read_dword(FILE *fp);
+
+
/**
- The constructor loads the named BMP image from the given bmp filename.
- <P>The inherited destructor free all memory and server resources that are used by
- the image.
- <P>The destructor free all memory and server resources that are used by
- the image
-*/
+ The constructor loads the named BMP image from the given bmp filename.
+
+ The inherited destructor frees 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
+ BMP format could not be decoded, and ERR_NO_IMAGE if the image could not
+ be loaded for another reason.
+ */
Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
: Fl_RGB_Image(0,0,0) {
FILE *fp; // File pointer
@@ -86,13 +92,17 @@ Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
// Open the file...
- if ((fp = fl_fopen(bmp, "rb")) == NULL) return;
+ if ((fp = fl_fopen(bmp, "rb")) == NULL) {
+ ld(ERR_FILE_ACCESS);
+ return;
+ }
// Get the header...
byte = (uchar)getc(fp); // Check "BM" sync chars
bit = (uchar)getc(fp);
if (byte != 'B' || bit != 'M') {
fclose(fp);
+ ld(ERR_FORMAT);
return;
}
@@ -161,6 +171,7 @@ Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
// Check header data...
if (!w() || !h() || !depth) {
fclose(fp);
+ w(0); h(0); d(0); ld(ERR_FORMAT);
return;
}
@@ -191,6 +202,7 @@ Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
if (((size_t)w()) * h() * d() > max_size() ) {
Fl::warning("BMP file \"%s\" is too large!\n", bmp);
fclose(fp);
+ w(0); h(0); d(0); ld(ERR_FORMAT);
return;
}
array = new uchar[w() * h() * d()];