png++ 0.2.10

Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
png::image< pixel, pixel_buffer_type > Class Template Reference

Class template to represent PNG image. More...

`#include <image.hpp>`

## Classes
struct | transform_identity
| The default io transformation: does nothing. More...
class | streaming_impl
| A common base class template for pixel_consumer and pixel_generator classes. More...
class | pixel_consumer
| The pixel buffer adapter for reading pixel data. More...
class | pixel_generator
| The pixel buffer adapter for writing pixel data. More...

## Public Types
typedef pixel_traits< pixel > | traits
| The pixel traits type for `pixel`.
typedef pixel_buffer_type | pixbuf
| The pixel buffer type for `pixel`.
typedef pixbuf::row_type | row_type
| Represents a row of image pixel data.
typedef pixbuf::row_access | row_access
typedef pixbuf::row_const_access | row_const_access
typedef convert_color_space< pixel > | transform_convert
| A transformation functor to convert any image to appropriate color space.

## Public Member Functions
| image ()
| Constructs an empty image.
| image (uint_32 width, uint_32 height)
| Constructs an empty image of specified width and height.
| image (std::string const &filename)
| Constructs an image reading data from specified file using default converting transform.
template<class transformation>
| image (std::string const &filename, transformation const &transform)
| Constructs an image reading data from specified file using custom transformaton.
| image (char const *filename)
| Constructs an image reading data from specified file using default converting transform.
template<class transformation>
| image (char const *filename, transformation const &transform)
| Constructs an image reading data from specified file using custom transformaton.
| image (std::istream &stream)
| Constructs an image reading data from a stream using default converting transform.
template<class transformation>
| image (std::istream &stream, transformation const &transform)
| Constructs an image reading data from a stream using custom transformation.
void | read (std::string const &filename)
| Reads an image from specified file using default converting transform.
template<class transformation>
void | read (std::string const &filename, transformation const &transform)
| Reads an image from specified file using custom transformaton.
void | read (char const *filename)
| Reads an image from specified file using default converting transform.
template<class transformation>
void | read (char const *filename, transformation const &transform)
| Reads an image from specified file using custom transformaton.
void | read (std::istream &stream)
| Reads an image from a stream using default converting transform.
template<class transformation>
void | read (std::istream &stream, transformation const &transform)
| Reads an image from a stream using custom transformation.
template<class istream>
void | read_stream (istream &stream)
| Reads an image from a stream using default converting transform.
template<class istream, class transformation>
void | read_stream (istream &stream, transformation const &transform)
| Reads an image from a stream using custom transformation.
void | write (std::string const &filename)
| Writes an image to specified file.
void | write (char const *filename)
| Writes an image to specified file.
template<class ostream>
void | write_stream (ostream &stream)
| Writes an image to a stream.
pixbuf & | get_pixbuf ()
| Returns a reference to image pixel buffer.
pixbuf const & | get_pixbuf () const
| Returns a const reference to image pixel buffer.
void | set_pixbuf (pixbuf const &buffer)
| Replaces the image pixel buffer.
uint_32 | get_width () const
uint_32 | get_height () const
void | resize (uint_32 width, uint_32 height)
| Resizes the image pixel buffer.
row_access | get_row (size_t index)
| Returns a reference to the row of image data at specified index.
row_const_access | get_row (size_t index) const
| Returns a const reference to the row of image data at specified index.
row_access | operator[] (size_t index)
| The non-checking version of get_row() method.
row_const_access | operator[] (size_t index) const
| The non-checking version of get_row() method.
pixel | get_pixel (size_t x, size_t y) const
| Returns a pixel at (x,y) position.
void | set_pixel (size_t x, size_t y, pixel p)
| Replaces a pixel at (x,y) position.
interlace_type | get_interlace_type () const
void | set_interlace_type (interlace_type interlace)
compression_type | get_compression_type () const
void | set_compression_type (compression_type compression)
filter_type | get_filter_type () const
void | set_filter_type (filter_type filter)
palette & | get_palette ()
| Returns a reference to the image palette.
palette const & | get_palette () const
| Returns a const reference to the image palette.
void | set_palette (palette const &plte)
| Replaces the image palette.
tRNS const & | get_tRNS () const
tRNS & | get_tRNS ()
void | set_tRNS (tRNS const &trns)
double | get_gamma () const
void | set_gamma (double gamma)

## Protected Attributes
image_info | m_info
pixbuf | m_pixbuf

## Detailed Description

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>
class png::image< pixel, pixel_buffer_type >

Class template to represent PNG image.

The image consists of pixel data as well as additional image info like interlace type, compression method, palette (for colormap-based images) etc. Provides methods to read and write images from/to a generic stream and to manipulate image pixels.

The default pixel_buffer stores pixels in a vector of vectors, which is good for openning, editing or converting an image to any pixel type. But for simple and fast image unpacking to one memory chunk this approch is unacceptable, because it leads to multiple memory allocations, the unpacked image is spread across the memory and client code needs to gather it manualy. solid_pixel_buffer solves this problem, but with restriction: pixels with fractional number of bytes per channel are not allowed (see solid_pixel_buffer.hpp for details).

## Member Typedef Documentation

## ◆ traits

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

typedef pixel_traits< pixel > png::image< pixel, pixel_buffer_type >::traits

The pixel traits type for `pixel`.

## ◆ pixbuf

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

typedef pixel_buffer_type png::image< pixel, pixel_buffer_type >::pixbuf

The pixel buffer type for `pixel`.

## ◆ row_type

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

typedef pixbuf::row_type png::image< pixel, pixel_buffer_type >::row_type

Represents a row of image pixel data.

## ◆ row_access

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

typedef pixbuf::row_access png::image< pixel, pixel_buffer_type >::row_access

## ◆ row_const_access

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

typedef pixbuf::row_const_access png::image< pixel, pixel_buffer_type >::row_const_access

## ◆ transform_convert

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

typedef convert_color_space< pixel > png::image< pixel, pixel_buffer_type >::transform_convert

A transformation functor to convert any image to appropriate color space.

## Constructor & Destructor Documentation

## ◆ image() [1/8]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

png::image< pixel, pixel_buffer_type >::image | ( |  | ) |
| inline

Constructs an empty image.

References m_info, and png::make_image_info().

## ◆ image() [2/8]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

png::image< pixel, pixel_buffer_type >::image | ( | uint_32 | width,
|  | uint_32 | height )
| inline

Constructs an empty image of specified width and height.

References m_info, png::make_image_info(), and resize().

## ◆ image() [3/8]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

png::image< pixel, pixel_buffer_type >::image | ( | std::string const & | filename | ) |
| inline explicit

Constructs an image reading data from specified file using default converting transform.

References read().

## ◆ image() [4/8]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>
template<class transformation>

png::image< pixel, pixel_buffer_type >::image | ( | std::string const & | filename,
|  | transformation const & | transform )
| inline

Constructs an image reading data from specified file using custom transformaton.

References read().

## ◆ image() [5/8]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

png::image< pixel, pixel_buffer_type >::image | ( | char const * | filename | ) |
| inline explicit

Constructs an image reading data from specified file using default converting transform.

References read().

## ◆ image() [6/8]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>
template<class transformation>

png::image< pixel, pixel_buffer_type >::image | ( | char const * | filename,
|  | transformation const & | transform )
| inline

Constructs an image reading data from specified file using custom transformaton.

References read().

## ◆ image() [7/8]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

png::image< pixel, pixel_buffer_type >::image | ( | std::istream & | stream | ) |
| inline explicit

Constructs an image reading data from a stream using default converting transform.

References read_stream().

## ◆ image() [8/8]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>
template<class transformation>

png::image< pixel, pixel_buffer_type >::image | ( | std::istream & | stream,
|  | transformation const & | transform )
| inline

Constructs an image reading data from a stream using custom transformation.

References read_stream().

## Member Function Documentation

## ◆ read() [1/6]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::read | ( | std::string const & | filename | ) |
| inline

Reads an image from specified file using default converting transform.

References read().

Referenced by image(), image(), image(), image(), read(), read(), and read().

## ◆ read() [2/6]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>
template<class transformation>

void png::image< pixel, pixel_buffer_type >::read | ( | std::string const & | filename,
|  | transformation const & | transform )
| inline

Reads an image from specified file using custom transformaton.

References read().

## ◆ read() [3/6]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::read | ( | char const * | filename | ) |
| inline

Reads an image from specified file using default converting transform.

References read().

## ◆ read() [4/6]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>
template<class transformation>

void png::image< pixel, pixel_buffer_type >::read | ( | char const * | filename,
|  | transformation const & | transform )
| inline

Reads an image from specified file using custom transformaton.

References read_stream().

## ◆ read() [5/6]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::read | ( | std::istream & | stream | ) |
| inline

Reads an image from a stream using default converting transform.

References read_stream().

## ◆ read() [6/6]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>
template<class transformation>

void png::image< pixel, pixel_buffer_type >::read | ( | std::istream & | stream,
|  | transformation const & | transform )
| inline

Reads an image from a stream using custom transformation.

References read_stream().

## ◆ read_stream() [1/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>
template<class istream>

void png::image< pixel, pixel_buffer_type >::read_stream | ( | istream & | stream | ) |
| inline

Reads an image from a stream using default converting transform.

References read_stream().

Referenced by image(), image(), read(), read(), read(), and read_stream().

## ◆ read_stream() [2/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>
template<class istream, class transformation>

void png::image< pixel, pixel_buffer_type >::read_stream | ( | istream & | stream,
|  | transformation const & | transform )
| inline

Reads an image from a stream using custom transformation.

References m_info, m_pixbuf, and png::consumer< pixel, pixcon, info_holder, interlacing_supported >::read().

## ◆ write() [1/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::write | ( | std::string const & | filename | ) |
| inline

Writes an image to specified file.

References write().

Referenced by write().

## ◆ write() [2/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::write | ( | char const * | filename | ) |
| inline

Writes an image to specified file.

References write_stream().

## ◆ write_stream()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>
template<class ostream>

void png::image< pixel, pixel_buffer_type >::write_stream | ( | ostream & | stream | ) |
| inline

Writes an image to a stream.

References m_info, m_pixbuf, and png::generator< pixel, pixgen, info_holder, interlacing_supported >::write().

Referenced by write().

## ◆ get_pixbuf() [1/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

pixbuf & png::image< pixel, pixel_buffer_type >::get_pixbuf | ( |  | ) |
| inline

Returns a reference to image pixel buffer.

References m_pixbuf.

## ◆ get_pixbuf() [2/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

pixbuf const & png::image< pixel, pixel_buffer_type >::get_pixbuf | ( |  | ) | const
| inline

Returns a const reference to image pixel buffer.

References m_pixbuf.

## ◆ set_pixbuf()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::set_pixbuf | ( | pixbuf const & | buffer | ) |
| inline

Replaces the image pixel buffer.

Parameters

  buffer | a pixel buffer object to take a copy from

References m_pixbuf.

## ◆ get_width()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

uint_32 png::image< pixel, pixel_buffer_type >::get_width | ( |  | ) | const
| inline

References m_pixbuf.

Referenced by png::image< pixel, pixel_buffer_type >::pixel_consumer::reset().

## ◆ get_height()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

uint_32 png::image< pixel, pixel_buffer_type >::get_height | ( |  | ) | const
| inline

References m_pixbuf.

Referenced by png::image< pixel, pixel_buffer_type >::pixel_consumer::reset().

## ◆ resize()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::resize | ( | uint_32 | width,
|  | uint_32 | height )
| inline

Resizes the image pixel buffer.

References m_info, and m_pixbuf.

Referenced by image().

## ◆ get_row() [1/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

row_access png::image< pixel, pixel_buffer_type >::get_row | ( | size_t | index | ) |
| inline

Returns a reference to the row of image data at specified index.

See also
  pixel_buffer::get_row()

References m_pixbuf.

## ◆ get_row() [2/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

row_const_access png::image< pixel, pixel_buffer_type >::get_row | ( | size_t | index | ) | const
| inline

Returns a const reference to the row of image data at specified index.

See also
  pixel_buffer::get_row()

References m_pixbuf.

## ◆ operator[]() [1/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

row_access png::image< pixel, pixel_buffer_type >::operator[] | ( | size_t | index | ) |
| inline

The non-checking version of get_row() method.

References m_pixbuf.

## ◆ operator[]() [2/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

row_const_access png::image< pixel, pixel_buffer_type >::operator[] | ( | size_t | index | ) | const
| inline

The non-checking version of get_row() method.

References m_pixbuf.

## ◆ get_pixel()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

pixel png::image< pixel, pixel_buffer_type >::get_pixel | ( | size_t | x,
|  | size_t | y ) const
| inline

Returns a pixel at (x,y) position.

References m_pixbuf.

## ◆ set_pixel()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::set_pixel | ( | size_t | x,
|  | size_t | y,
|  | pixel | p )
| inline

Replaces a pixel at (x,y) position.

References m_pixbuf.

## ◆ get_interlace_type()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

interlace_type png::image< pixel, pixel_buffer_type >::get_interlace_type | ( |  | ) | const
| inline

References m_info.

## ◆ set_interlace_type()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::set_interlace_type | ( | interlace_type | interlace | ) |
| inline

References m_info.

## ◆ get_compression_type()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

compression_type png::image< pixel, pixel_buffer_type >::get_compression_type | ( |  | ) | const
| inline

References m_info.

## ◆ set_compression_type()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::set_compression_type | ( | compression_type | compression | ) |
| inline

References m_info.

## ◆ get_filter_type()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

filter_type png::image< pixel, pixel_buffer_type >::get_filter_type | ( |  | ) | const
| inline

References m_info.

## ◆ set_filter_type()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::set_filter_type | ( | filter_type | filter | ) |
| inline

References m_info.

## ◆ get_palette() [1/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

palette & png::image< pixel, pixel_buffer_type >::get_palette | ( |  | ) |
| inline

Returns a reference to the image palette.

References m_info.

## ◆ get_palette() [2/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

palette const & png::image< pixel, pixel_buffer_type >::get_palette | ( |  | ) | const
| inline

Returns a const reference to the image palette.

References m_info.

## ◆ set_palette()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::set_palette | ( | palette const & | plte | ) |
| inline

Replaces the image palette.

References m_info.

## ◆ get_tRNS() [1/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

tRNS const & png::image< pixel, pixel_buffer_type >::get_tRNS | ( |  | ) | const
| inline

References m_info.

## ◆ get_tRNS() [2/2]

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

tRNS & png::image< pixel, pixel_buffer_type >::get_tRNS | ( |  | ) |
| inline

References m_info.

## ◆ set_tRNS()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::set_tRNS | ( | tRNS const & | trns | ) |
| inline

References m_info.

## ◆ get_gamma()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

double png::image< pixel, pixel_buffer_type >::get_gamma | ( |  | ) | const
| inline

References m_info.

## ◆ set_gamma()

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

void png::image< pixel, pixel_buffer_type >::set_gamma | ( | double | gamma | ) |
| inline

References m_info.

## Member Data Documentation

## ◆ m_info

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

image_info png::image< pixel, pixel_buffer_type >::m_info
| protected

Referenced by get_compression_type(), get_filter_type(), get_gamma(), get_interlace_type(), get_palette(), get_palette(), get_tRNS(), get_tRNS(), image(), image(), read_stream(), resize(), set_compression_type(), set_filter_type(), set_gamma(), set_interlace_type(), set_palette(), set_tRNS(), and write_stream().

## ◆ m_pixbuf

template<typename pixel, typename pixel_buffer_type = pixel_buffer< pixel >>

pixbuf png::image< pixel, pixel_buffer_type >::m_pixbuf
| protected

Referenced by get_height(), get_pixbuf(), get_pixbuf(), get_pixel(), get_row(), get_row(), get_width(), operator[](), operator[](), read_stream(), resize(), set_pixbuf(), set_pixel(), and write_stream().

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

- image.hpp