summaryrefslogtreecommitdiff
path: root/src/Fl_Image_Reader.h
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2021-09-25 19:33:22 +0200
committerAlbrecht Schlosser <albrechts.fltk@online.de>2021-09-25 19:33:22 +0200
commitbc0d18c1bb6ce205f034161ea7816638b5d7f5b7 (patch)
treede949877cd3e56856da658f88cf445457c60a257 /src/Fl_Image_Reader.h
parent0f12e96d138af1ea1fa371b858ee2094401621b7 (diff)
Enable error and EOF check in class Fl_Image_Reader (#271)
This is part 1 and a prerequisite for the fix of issue #271. It enables the user of this internal class (Fl_{BMP|GIF}_Image) to test for read errors and EOF (end of file) while reading. The method used to read data from memory got an optional third argument 'const long datasize = -1)' to limit the size of the memory block of data provided to the image reader. Default is -1 which means "unlimited" (backwards compatibility). Using only two arguments (w/o size limit) is deprecated and should only be done if the data size is not available.
Diffstat (limited to 'src/Fl_Image_Reader.h')
-rw-r--r--src/Fl_Image_Reader.h23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/Fl_Image_Reader.h b/src/Fl_Image_Reader.h
index 93f5edc0d..7d176acc1 100644
--- a/src/Fl_Image_Reader.h
+++ b/src/Fl_Image_Reader.h
@@ -1,7 +1,7 @@
//
// Internal (Image) Reader class for the Fast Light Tool Kit (FLTK).
//
-// Copyright 2020 by Bill Spitzak and others.
+// Copyright 2020-2021 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -37,7 +37,9 @@ public:
pIsFile(0), pIsData(0),
pFile(0L), pData(0L),
pStart(0L),
- pName(0L)
+ pEnd((const unsigned char *)(-1L)),
+ pName(0L),
+ pError(0)
{}
// Initialize the reader to access the file system, filename is copied
@@ -45,7 +47,7 @@ public:
int open(const char *filename);
// Initialize the reader for memory access, name is copied and stored
- int open(const char *imagename, const unsigned char *data);
+ int open(const char *imagename, const unsigned char *data, const long datasize = -1);
// Close and destroy the reader
~Fl_Image_Reader();
@@ -68,6 +70,15 @@ public:
// of the file or the original start address in memory
void seek(unsigned int n);
+ // Get the current file or memory offset from the beginning
+ // of the file or the original start address in memory
+ long tell() const;
+
+ // Get the current EOF or error status of the file or data block
+ int error() const {
+ return pError;
+ }
+
// return the name or filename for this reader
const char *name() { return pName; }
@@ -83,8 +94,14 @@ private:
const unsigned char *pData;
// a pointer to the start of the image data
const unsigned char *pStart;
+ // a pointer to the end of image data if reading from memory, otherwise undefined
+ // note: currently (const unsigned char *)(-1L) if end of memory is not available
+ // ... which means "unlimited"
+ const unsigned char *pEnd;
// a copy of the name associated with this reader
char *pName;
+ // a flag to store EOF or error status
+ int pError;
};
#endif // FL_IMAGE_READER_H