CMSC23700 Common Code Library
Support code for CS23700 programming projects
cs237-image.hxx
Go to the documentation of this file.
1 
8 /*
9  * COPYRIGHT (c) 2015 John Reppy (http://cs.uchicago.edu/~jhr)
10  * All rights reserved.
11  */
12 
13 #ifndef _CS237_IMAGE_HXX_
14 #define _CS237_IMAGE_HXX_
15 
16 #ifndef _CS237_HXX_
17 #error "c237-image.hxx should not be included directly"
18 #endif
19 
20 #include <fstream>
21 
22 namespace cs237 {
23 
24  namespace __detail {
25 
26  class image_base {
27  public:
29  unsigned int nDims () const { return this->_nDims; }
33  unsigned int format () const { return this->_format; }
43  unsigned int type () const { return this->_type; }
45  void *data () const { return this->_data; }
47  size_t nBytes () const { return this->_nBytes; }
48 
50  unsigned int nChannels () const;
51 
52  protected:
53  uint32_t _nDims;
54  GLenum _format;
55  GLenum _type;
58  size_t _nBytes;
61  void *_data;
62 
63  explicit image_base ()
64  : _nDims(0), _format(0), _type(0), _nBytes(0), _data(nullptr)
65  { }
66  explicit image_base (uint32_t nd)
67  : _nDims(nd), _format(0), _type(0), _nBytes(0), _data(nullptr)
68  { }
69  explicit image_base (uint32_t nd, GLenum fmt, GLenum ty, size_t nPixels);
70 
71  virtual ~image_base ();
72 
73  };
74 
75  } /* namespace __detail */
76 
77  /* 1D images */
78  class image1d : public __detail::image_base {
79  public:
92  image1d (uint32_t wid, GLenum fmt, GLenum ty);
93 
96  image1d (std::string const &file);
97 
99  GLsizei width () const { return this->_wid; }
100 
103  void texImage (GLuint texId);
104 
108  bool write (const char *file);
109 
110  private:
111  GLsizei _wid;
112  };
113 
114  /* 2D images */
115  class image2d : public __detail::image_base {
116  public:
130  image2d (uint32_t wid, uint32_t ht, GLenum fmt, GLenum ty);
131 
136  image2d (std::string const &file, bool flip = true);
137 
142  image2d (std::ifstream &inS, bool flip = true);
143 
145  GLsizei width () const { return this->_wid; }
146 
148  GLsizei height () const { return this->_ht; }
149 
153  void texImage (GLenum target, GLuint texId);
154 
163  bool write (const char *file, bool flip = true);
164 
173  bool write (std::ofstream &outS, bool flip = true);
174 
175  private:
176  GLsizei _wid;
177  GLsizei _ht;
178  };
179 
180 } /* namespace cs237 */
181 
182 #endif /* !_CS237_IMAGE_HXX_ */
uint32_t _nDims
the number of dimensions (1 or 2)
Definition: cs237-image.hxx:53
image1d(uint32_t wid, GLenum fmt, GLenum ty)
bool write(const char *file, bool flip=true)
unsigned int nChannels() const
the number of channels (1, 2, 3, or 4)
size_t _nBytes
size in bytes of image data
Definition: cs237-image.hxx:60
image2d(uint32_t wid, uint32_t ht, GLenum fmt, GLenum ty)
unsigned int format() const
Definition: cs237-image.hxx:33
GLenum _format
Definition: cs237-image.hxx:54
Definition: cs237-image.hxx:26
void texImage(GLenum target, GLuint texId)
GLenum _type
Definition: cs237-image.hxx:57
size_t nBytes() const
the total number of bytes of image data
Definition: cs237-image.hxx:47
Definition: cs237-image.hxx:78
image_base(uint32_t nd)
Definition: cs237-image.hxx:66
unsigned int nDims() const
the number of dimensions (1, 2, or 3)
Definition: cs237-image.hxx:29
void texImage(GLuint texId)
GLsizei height() const
return the height of the image
Definition: cs237-image.hxx:148
GLsizei width() const
return the width of the image
Definition: cs237-image.hxx:145
Definition: cs237-aabb.hxx:18
void * _data
the raw image data
Definition: cs237-image.hxx:61
GLsizei width() const
return the width of the image
Definition: cs237-image.hxx:99
image_base()
Definition: cs237-image.hxx:63
void * data() const
the data pointer
Definition: cs237-image.hxx:45
bool write(const char *file)
unsigned int type() const
Definition: cs237-image.hxx:43
Definition: cs237-image.hxx:115