CMSC23700 Common Code Library
Support code for CS23700 programming projects
Loading...
Searching...
No Matches
cs237::Image2D Class Reference

#include <cs237-image.hpp>

Inheritance diagram for cs237::Image2D:
Collaboration diagram for cs237::Image2D:

Public Member Functions

 Image2D (uint32_t wid, uint32_t ht, Channels chans, ChannelTy ty)
 
 Image2D (std::string const &file, bool flip=true)
 
 Image2D (std::ifstream &inS, bool flip=true)
 
size_t width () const
 return the width of the image
 
size_t height () const
 return the height of the image
 
bool write (const char *file, bool flip=true)
 
bool write (std::ofstream &outS, bool flip=true)
 
void bitblt (Image2D const &src, uint32_t row, uint32_t col)
 
- Public Member Functions inherited from cs237::__detail::ImageBase
uint32_t nDims () const
 the number of dimensions (1, 2, or 3)
 
Channels channels () const
 return the format of the pixels.
 
ChannelTy type () const
 returns the type of the channels
 
vk::Format format () const
 return the vulkan format of the image data
 
voiddata () const
 the data pointer
 
size_t nBytes () const
 the total number of bytes of image data
 
unsigned int nChannels () const
 the number of channels (1, 2, 3, or 4)
 
size_t nBytesPerPixel () const
 the number of bytes per pixel
 
void addAlphaChannel ()
 

Protected Attributes

uint32_t _wid
 the width of the image in pixels
 
uint32_t _ht
 the height of the image in pixels
 
- Protected Attributes inherited from cs237::__detail::ImageBase
uint32_t _nDims
 the number of dimensions (1 or 2)
 
Channels _chans
 the texture format
 
ChannelTy _type
 the representation type of the data
 
bool _sRGB
 should the image be interpreted as an sRGB encoded image?
 
size_t _nBytes
 size in bytes of image data
 
void_data
 the raw image data
 

Additional Inherited Members

- Protected Member Functions inherited from cs237::__detail::ImageBase
 ImageBase ()
 
 ImageBase (uint32_t nd)
 
 ImageBase (uint32_t nd, Channels chans, ChannelTy ty, size_t nPixels)
 
virtual ~ImageBase ()
 

Detailed Description

A 2D Image; by default, it is assumed to store color data, which means that RGB data will be interpreted as being sRGB encoded. Use the DataImage2D class to represent unencoded image data.

Constructor & Destructor Documentation

◆ Image2D() [1/3]

cs237::Image2D::Image2D ( uint32_t  wid,
uint32_t  ht,
Channels  chans,
ChannelTy  ty 
)

create and allocate space for an uninitialized image

Parameters
widthe width of the image
htthe height of the image
chansthe image format
tythe type of the elements

◆ Image2D() [2/3]

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)

◆ Image2D() [3/3]

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

◆ bitblt()

void cs237::Image2D::bitblt ( Image2D const &  src,
uint32_t  row,
uint32_t  col 
)

copy the contents of another image into this image

Parameters
srcthe image to blt into this image
rowthe row of this image where the first row of src is copied
colthe column of this image where the leftmost column of src is copied

Note that this function requires that the two images have the same format and sample type.

◆ height()

size_t cs237::Image2D::height ( ) const
inline

return the height of the image

◆ width()

size_t cs237::Image2D::width ( ) const
inline

return the width of the image

◆ write() [1/2]

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.

◆ write() [2/2]

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.

Member Data Documentation

◆ _ht

uint32_t cs237::Image2D::_ht
protected

the height of the image in pixels

◆ _wid

uint32_t cs237::Image2D::_wid
protected

the width of the image in pixels


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