openvrml::image Class Reference

Pixmap data. More...

#include <openvrml/basetypes.h>

Public Member Functions

 image () throw ()
 Construct.
 image (std::size_t x, std::size_t y, std::size_t comp) throw ( std::bad_alloc )
 Construct.
 image (std::size_t x, std::size_t y, std::size_t comp, const std::vector< unsigned char > &array) throw ( std::bad_alloc )
 Construct.
template<typename InputIterator >
 image (std::size_t x, std::size_t y, std::size_t comp, InputIterator array_begin, InputIterator array_end) throw ( std::bad_alloc )
 Construct.
void swap (image &img) throw ()
 Swap.
std::size_t x () const throw ()
 Pixels in the x-dimension.
void x (std::size_t value) throw ( std::bad_alloc )
 Set the pixels in the x-dimension.
std::size_t y () const throw ()
 Pixels in the y-dimension.
void y (std::size_t value) throw ( std::bad_alloc )
 Set the pixels in the y-dimension.
void resize (std::size_t x, std::size_t y) throw ( std::bad_alloc )
 Resize the x- and y-dimensions.
std::size_t comp () const throw ()
 Number of components.
void comp (std::size_t value) throw ( std::bad_alloc )
 Set the number of components.
const std::vector< unsigned
char > & 
array () const throw ()
 Pixel value array.
void array (const std::vector< unsigned char > &value) throw ()
 Set the pixel value array.
template<typename InputIterator >
void array (InputIterator begin, InputIterator end) throw ()
 Set the pixel value array.
int32 pixel (std::size_t index) const throw ()
 Pixel value.
void pixel (std::size_t index, int32 value) throw ()
 Set a pixel value.
int32 pixel (std::size_t x, std::size_t y) const throw ()
 Pixel value.
void pixel (std::size_t x, std::size_t y, int32 value) throw ()
 Set a pixel value.

Related Functions

(Note that these are not member functions.)

bool operator== (const image &lhs, const image &rhs) throw()
 Compare for equality.
bool operator!= (const image &lhs, const image &rhs) throw()
 Compare for inequality.
std::istream & operator>> (std::istream &in, image &img)
 Stream input.
std::ostream & operator<< (std::ostream &out, const image &img)
 Stream output.
template<> void swap (openvrml::image &a, openvrml::image &b)
 Swap the values of and b.

Detailed Description

Pixmap data.

The first pixel in the array is the lower left pixel and the last is the upper right pixel. Pixel values are limited to 256 levels of intensity. The elements of array are bytes, with one byte per pixel component. Thus the number of elements in the array is x * y * comp.

A one-component image specifies one-byte greyscale values. A two-component image specifies the intensity in the first byte and the alpha opacity in the second byte. A three-component image specifies the red component in the first byte, followed by the green and blue components. Four-component images specify the alpha opacity byte after red/green/blue.

Constructor & Destructor Documentation

openvrml::image::image ( ) throw ()
inline

Construct.

openvrml::image::image ( std::size_t  x,
std::size_t  y,
std::size_t  comp 
) throw ( std::bad_alloc )
inline

Construct.

Parameters
[in]xpixels in the x-direction.
[in]ypixels in the y-direction.
[in]compnumber of components.
openvrml::image::image ( std::size_t  x,
std::size_t  y,
std::size_t  comp,
const std::vector< unsigned char > &  array 
) throw ( std::bad_alloc )

Construct.

Precondition
array.size() <= x * y * comp.
Parameters
[in]xpixels in the x-direction.
[in]ypixels in the y-direction.
[in]compnumber of components.
[in]arraypixel data.
template<typename InputIterator >
openvrml::image::image ( std::size_t  x,
std::size_t  y,
std::size_t  comp,
InputIterator  array_begin,
InputIterator  array_end 
) throw ( std::bad_alloc )

Construct.

Precondition
std::distance(array_begin, array_end) <= x * y * comp.
Template Parameters
InputIteratoran Input Iterator.
Parameters
[in]xpixels in the x-direction.
[in]ypixels in the y-direction.
[in]compnumber of components.
[in]array_beginpixel data begin iterator.
[in]array_endpixel data end iterator.
Exceptions
std::bad_allocif memory allocation fails.

Member Function Documentation

void openvrml::image::swap ( image img) throw ()
inline

Swap.

Parameters
[in,out]imgan image.
std::size_t openvrml::image::x ( ) const throw ()
inline

Pixels in the x-dimension.

Returns
the number of pixels in the x-dimension.
void openvrml::image::x ( std::size_t  value) throw ( std::bad_alloc )

Set the pixels in the x-dimension.

Parameters
[in]valuenew value for the x-dimension.
Exceptions
std::bad_allocif memory allocation fails.
std::size_t openvrml::image::y ( ) const throw ()
inline

Pixels in the y-dimension.

Returns
the number of pixels in the y-dimension.
void openvrml::image::y ( std::size_t  value) throw ( std::bad_alloc )

Set the pixels in the y-dimension.

Parameters
[in]valuenew value for the x-dimension.
Exceptions
std::bad_allocif memory allocation fails.
void openvrml::image::resize ( std::size_t  x,
std::size_t  y 
) throw ( std::bad_alloc )

Resize the x- and y-dimensions.

Parameters
[in]xx-dimension.
[in]yy-dimension.
Exceptions
std::bad_allocif memory allocation fails.
std::size_t openvrml::image::comp ( ) const throw ()
inline

Number of components.

Returns
the number of components.
void openvrml::image::comp ( std::size_t  value) throw ( std::bad_alloc )

Set the number of components.

Precondition
value <= 4
Parameters
[in]valuenumber of components.
const std::vector< unsigned char > & openvrml::image::array ( ) const throw ()
inline

Pixel value array.

Returns
the array of pixel values.
void openvrml::image::array ( const std::vector< unsigned char > &  value) throw ()
inline

Set the pixel value array.

Precondition
value.size() <= (x() * y() * comp())
Parameters
[in]valuepixel value array.
template<typename InputIterator >
void openvrml::image::array ( InputIterator  begin,
InputIterator  end 
) throw ()

Set the pixel value array.

Precondition
std::distance(begin, end) <= (x() * y() * comp())
Template Parameters
InputIteratoran Input Iterator.
Parameters
[in]begininput iterator to the beginning of a sequence.
[in]endinput iterator to the end of the sequence (one past the last element).
int32 openvrml::image::pixel ( std::size_t  index) const throw ()
inline

Pixel value.

Precondition
index < x() * y()
Parameters
[in]indexpixel value index.
Returns
the pixel value at index.
void openvrml::image::pixel ( std::size_t  index,
int32  value 
) throw ()
inline

Set a pixel value.

Precondition
index < x() * y()
Parameters
[in]indexpixel value index.
[in]valuepixel value.
int32 openvrml::image::pixel ( std::size_t  x,
std::size_t  y 
) const throw ()
inline

Pixel value.

Precondition
x < x(), y < y()
Parameters
[in]xpixel value x- (column) index.
[in]ypixel value y- (row) index.
Returns
the pixel value at (x, y).
void openvrml::image::pixel ( std::size_t  x,
std::size_t  y,
int32  value 
) throw ()
inline

Set a pixel value.

Precondition
x < x(), y < y()
Parameters
[in]xpixel value x- (column) index.
[in]ypixel value y- (row) index.
[in]valuepixel value.

Friends And Related Function Documentation

bool operator== ( const image lhs,
const image rhs 
) throw()
related

Compare for equality.

Parameters
[in]lhsleft-hand operand.
[in]rhsright-hand operand.
Returns
true if lhs and rhs are equal; false otherwise.
bool operator!= ( const image lhs,
const image rhs 
) throw()
related

Compare for inequality.

Parameters
[in]lhsleft-hand operand.
[in]rhsright-hand operand.
Returns
true if lhs and rhs are not equal; false otherwise.
std::istream & operator>> ( std::istream &  in,
image img 
)
related

Stream input.

Consistent with the VRML97 convention, commas (“,”) in the input are treated as whitespace.

Parameters
[in,out]ininput stream.
[out]imgan image.
Returns
in.
std::ostream & operator<< ( std::ostream &  out,
const image img 
)
related

Stream output.

Parameters
[in,out]outoutput stream.
[in]imgan image.
template<> void swap ( openvrml::image a,
openvrml::image b 
)
related

Swap the values of and b.

Does not throw.

Parameters
[in,out]a
[in,out]b