From bc0d18c1bb6ce205f034161ea7816638b5d7f5b7 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Sat, 25 Sep 2021 19:33:22 +0200 Subject: 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. --- src/Fl_Image_Reader.h | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/Fl_Image_Reader.h') 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 -- cgit v1.2.3