CMSC23700 Common Code Library
Support code for CS23700 programming projects
cs237::image2d Class Reference

#include <cs237-image.hxx>

Inherits cs237::__detail::image_base.

Public Member Functions

 image2d (uint32_t wid, uint32_t ht, GLenum fmt, GLenum ty)
 
 image2d (std::string const &file, bool flip=true)
 
 image2d (std::ifstream &inS, bool flip=true)
 
GLsizei width () const
 return the width of the image More...
 
GLsizei height () const
 return the height of the image More...
 
void texImage (GLenum target, GLuint texId)
 
bool write (const char *file, bool flip=true)
 
bool write (std::ofstream &outS, bool flip=true)
 
- Public Member Functions inherited from cs237::__detail::image_base
unsigned int nDims () const
 the number of dimensions (1, 2, or 3) More...
 
unsigned int format () const
 
unsigned int type () const
 
void * data () const
 the data pointer More...
 
size_t nBytes () const
 the total number of bytes of image data More...
 
unsigned int nChannels () const
 the number of channels (1, 2, 3, or 4) More...
 

Additional Inherited Members

- Protected Member Functions inherited from cs237::__detail::image_base
 image_base ()
 
 image_base (uint32_t nd)
 
 image_base (uint32_t nd, GLenum fmt, GLenum ty, size_t nPixels)
 
virtual ~image_base ()
 
- Protected Attributes inherited from cs237::__detail::image_base
uint32_t _nDims
 the number of dimensions (1 or 2) More...
 
GLenum _format
 
GLenum _type
 
size_t _nBytes
 size in bytes of image data More...
 
void * _data
 the raw image data More...
 

Constructor & Destructor Documentation

cs237::image2d::image2d ( uint32_t  wid,
uint32_t  ht,
GLenum  fmt,
GLenum  ty 
)

create and allocate space for an uninitialized image

Parameters
widthe width of the image
htthe height of the image
fmtthe image format, which should be one of GL_RED, GL_RG, GL_RGB, GL_BGR GL_RGBA, or GL_BGRA.
tythe type of the elements, which should be one of GL_UNSIGNED_BYTE GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, or GL_UNSIGNED_INT_2_10_10_10_REV
cs237::image2d::image2d ( std::string const &  file,
bool  flip = true 
)

create and initialize an image from a PNG file.

Parameters
filethe name of the PNG file
flipset to true if the image should be flipped vertically to match OpenGL texture coordinates (default true)
cs237::image2d::image2d ( std::ifstream &  inS,
bool  flip = true 
)

create and initialize an image from a PNG-format input stream

Parameters
inSthe input stream
flipset to true if the image should be flipped vertically to match OpenGL texture coordinates (default true)

Member Function Documentation

GLsizei cs237::image2d::height ( ) const
inline

return the height of the image

void cs237::image2d::texImage ( GLenum  target,
GLuint  texId 
)

Load the image into a 2D GL texture; this function also binds the current texture to texId

Parameters
[in]targetspecifies the target texture. Must be GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE
[in]texIdthe GL texture ID for this image
GLsizei cs237::image2d::width ( ) const
inline

return the width of the image

bool cs237::image2d::write ( const char *  file,
bool  flip = true 
)

write the texture to a file in PNG format

Parameters
filethe name of the PNG file
flipset to true if the image should be flipped vertically to match standard image-file coordinates (default true)
Returns
true if successful, false otherwise

Note that the type of the image must be either GL_UNSIGNED_BYTE, or GL_UNSIGNED_SHORT to write it as a PNG file.

bool cs237::image2d::write ( std::ofstream &  outS,
bool  flip = true 
)

write the texture to an output stream in PNG format

Parameters
outSthe output stream to write the PNG image to
flipset to true if the image should be flipped vertically to match standard image-file coordinates (default true)
Returns
true if successful, false otherwise

Note that the type of the image must be either GL_UNSIGNED_BYTE, or GL_UNSIGNED_SHORT to write it to an output stream.


The documentation for this class was generated from the following file: