FLTK
Fl_Image_Reader.h
1 //
2 // Internal (Image) Reader class for the Fast Light Tool Kit (FLTK).
3 //
4 // Copyright 2020 by Bill Spitzak and others.
5 //
6 // This library is free software. Distribution and use rights are outlined in
7 // the file "COPYING" which should have been included with this file. If this
8 // file is missing or damaged, see the license at:
9 //
10 // https://www.fltk.org/COPYING.php
11 //
12 // Please see the following page on how to report bugs and issues:
13 //
14 // https://www.fltk.org/bugs.php
15 //
16 
17 /*
18  This internal (undocumented) class reads data chunks from a file or from
19  memory in LSB-first byte order.
20 
21  This class is used in Fl_GIF_Image and Fl_BMP_Image to avoid code
22  duplication and may be extended to be used in similar cases. Future
23  options might be to read data in MSB-first byte order or to add more
24  methods.
25 */
26 
27 #ifndef FL_IMAGE_READER_H
28 #define FL_IMAGE_READER_H
29 
30 #include <stdio.h>
31 
33 {
34 public:
35  // Create the reader.
36  Fl_Image_Reader() :
37  pIsFile(0), pIsData(0),
38  pFile(0L), pData(0L),
39  pStart(0L),
40  pName(0L)
41  {}
42 
43  // Initialize the reader to access the file system, filename is copied
44  // and stored.
45  int open(const char *filename);
46 
47  // Initialize the reader for memory access, name is copied and stored
48  int open(const char *imagename, const unsigned char *data);
49 
50  // Close and destroy the reader
51  ~Fl_Image_Reader();
52 
53  // Read a single byte from memory or a file
54  unsigned char read_byte();
55 
56  // Read a 16-bit unsigned integer, LSB-first
57  unsigned short read_word();
58 
59  // Read a 32-bit unsigned integer, LSB-first
60  unsigned int read_dword();
61 
62  // Read a 32-bit signed integer, LSB-first
63  int read_long() {
64  return (int)read_dword();
65  };
66 
67  // Move the current read position to a byte offset from the beginning
68  // of the file or the original start address in memory
69  void seek(unsigned int n);
70 
71  // return the name or filename for this reader
72  const char *name() { return pName; }
73 
74 private:
75 
76  // open() sets this if we read from a file
77  char pIsFile;
78  // open() sets this if we read from memory
79  char pIsData;
80  // a pointer to the opened file
81  FILE *pFile;
82  // a pointer to the current byte in memory
83  const unsigned char *pData;
84  // a pointer to the start of the image data
85  const unsigned char *pStart;
86  // a copy of the name associated with this reader
87  char *pName;
88 };
89 
90 #endif // FL_IMAGE_READER_H
Definition: Fl_Image_Reader.h:32