A class to deal with images. More...
#include <image.hpp>
Classes | |
class | base_iterator |
Base class for iterators on an image. More... | |
class | scanline |
One line in the image. More... | |
Public Types | |
typedef rgba_pixel | pixel_type |
typedef base_iterator< image, pixel_type > | iterator |
typedef base_iterator< const image, const pixel_type > | const_iterator |
Public Member Functions | |
image () | |
Constructor. Creates an image without datas. | |
image (unsigned int w, unsigned int h) | |
Constructor. Creates an empty image. | |
image (std::istream &f) | |
Constructor. Reads an image from an input stream. | |
virtual | ~image () |
Destructor. | |
unsigned int | width () const |
Gets image's width. | |
unsigned int | height () const |
Gets image's height. | |
scanline & | operator[] (unsigned int i) |
Gets a line of the image. | |
const scanline & | operator[] (unsigned int i) const |
Gets a line of the image. | |
iterator | begin () |
Get an iterator pointing on the first pixel. | |
iterator | end () |
Get an iterator pointing just past the last pixel. | |
const_iterator | begin () const |
Get an iterator pointing on the first pixel. | |
const_iterator | end () const |
Get an iterator pointing just past the last pixel. | |
void | partial_copy (const image &that, const claw::math::coordinate_2d< int > &pos) |
Copy an image on the current image. | |
void | flip () |
Set the image upside down. | |
void | set_size (unsigned int w, unsigned int h) |
Set a new size to the image. | |
void | load (std::istream &f) |
Read the image from a stream. | |
Private Attributes | |
std::vector< scanline > | m_data |
Data of the picture. |
A class to deal with images.
Definition at line 48 of file image.hpp.
typedef base_iterator<const image, const pixel_type> claw::graphic::image::const_iterator |
claw::graphic::image::image | ( | ) |
claw::graphic::image::image | ( | unsigned int | w, | |
unsigned int | h | |||
) |
Constructor. Creates an empty image.
w | Image's width. | |
h | Image's height. |
Definition at line 117 of file image.cpp.
References set_size().
{ set_size(w, h); } // image::image() [constructor]
claw::graphic::image::image | ( | std::istream & | f | ) |
claw::graphic::image::~image | ( | ) | [virtual] |
claw::graphic::image::iterator claw::graphic::image::begin | ( | ) |
Get an iterator pointing on the first pixel.
Definition at line 166 of file image.cpp.
Referenced by partial_copy(), claw::graphic::xbm::reader::read_name(), claw::graphic::targa::writer::save_rle_true_color(), and claw::graphic::targa::writer::save_true_color().
{ return iterator(*this); } // image::begin()
claw::graphic::image::const_iterator claw::graphic::image::begin | ( | ) | const |
Get an iterator pointing on the first pixel.
Definition at line 184 of file image.cpp.
{ return const_iterator(*this); } // image::begin()
claw::graphic::image::const_iterator claw::graphic::image::end | ( | ) | const |
claw::graphic::image::iterator claw::graphic::image::end | ( | ) |
Get an iterator pointing just past the last pixel.
Definition at line 175 of file image.cpp.
References height(), and width().
Referenced by claw::graphic::xbm::reader::read_name(), claw::graphic::xbm::reader::remove_comments(), claw::graphic::targa::writer::save_rle_true_color(), and claw::graphic::targa::writer::save_true_color().
void claw::graphic::image::flip | ( | ) |
unsigned int claw::graphic::image::height | ( | ) | const |
Gets image's height.
Definition at line 157 of file image.cpp.
References m_data.
Referenced by claw::graphic::targa::reader::rle_targa_output_buffer< InputBuffer >::completed(), claw::graphic::png::reader::copy_pixel_line(), end(), flip(), claw::graphic::bitmap::writer::init_header(), claw::graphic::targa::reader::load_color_mapped_raw(), claw::graphic::targa::reader::load_true_color_raw(), partial_copy(), claw::graphic::targa::reader::rle_targa_output_buffer< InputBuffer >::rle_targa_output_buffer(), claw::graphic::xbm::writer::save(), claw::graphic::targa::writer::save(), claw::graphic::xbm::writer::save_bits(), claw::graphic::bitmap::writer::save_data(), claw::graphic::targa::writer::save_rle_true_color(), and set_size().
{ return m_data.size(); } // image::height()
void claw::graphic::image::load | ( | std::istream & | f | ) |
Read the image from a stream.
f | The stream to read from. |
Definition at line 265 of file image.cpp.
Referenced by image().
{ bool ok = false; #ifdef CLAW_JPEG_SUPPORT if (!ok) try { jpeg::reader( *this, f ); ok = true; } catch( ... ) { } #endif // CLAW_JPEG_SUPPORT #ifdef CLAW_PNG_SUPPORT if (!ok) try { png::reader( *this, f ); ok = true; } catch( ... ) { } #endif // CLAW_PNG_SUPPORT if (!ok) try { bitmap::reader( *this, f ); ok = true; } catch( ... ) { } if (!ok) try { targa::reader( *this, f ); ok = true; } catch( ... ) { } if (!ok) try { pcx::reader( *this, f ); ok = true; } catch( ... ) { } if (!ok) try { xbm::reader( *this, f ); ok = true; } catch( ... ) { } if (!ok) throw claw::bad_format( "image::load: file format isn't supported." ); } // image::load()
const claw::graphic::image::scanline & claw::graphic::image::operator[] | ( | unsigned int | i | ) | const [inline] |
claw::graphic::image::scanline & claw::graphic::image::operator[] | ( | unsigned int | i | ) | [inline] |
void claw::graphic::image::partial_copy | ( | const image & | that, | |
const claw::math::coordinate_2d< int > & | pos | |||
) |
Copy an image on the current image.
that | The image to copy. | |
pos | The position of the top left corner. |
Definition at line 205 of file image.cpp.
References begin(), claw::math::rectangle< T >::height, height(), claw::math::rectangle< T >::intersection(), claw::math::rectangle< T >::intersects(), claw::math::rectangle< T >::position, claw::math::rectangle< T >::width, width(), claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.
{ claw::math::rectangle<int> my_box(0, 0, width(), height()); claw::math::rectangle<int> his_box(pos.x, pos.y, that.width(), that.height()); if ( my_box.intersects( his_box ) ) { claw::math::rectangle<int> intersection; unsigned int that_y = pos.y < 0 ? -pos.y : 0; unsigned int that_x = pos.x < 0 ? -pos.x : 0; intersection = my_box.intersection( his_box ); for (int y=0; y!=intersection.height; ++y) { scanline::const_iterator first = that[y + that_y].begin() + that_x; scanline::const_iterator last = first + intersection.width; scanline::iterator dest = (*this)[y + intersection.position.y].begin() + intersection.position.x; std::copy( first, last, dest ); } } } // image::partial_copy()
void claw::graphic::image::set_size | ( | unsigned int | w, | |
unsigned int | h | |||
) |
Set a new size to the image.
Definition at line 247 of file image.cpp.
References height(), and m_data.
Referenced by image(), claw::graphic::targa::reader::load(), claw::graphic::pcx::reader::load(), claw::graphic::bitmap::reader::load(), and claw::graphic::xbm::reader::read_size().
unsigned int claw::graphic::image::width | ( | ) | const |
Gets image's width.
Definition at line 145 of file image.cpp.
References m_data.
Referenced by claw::graphic::targa::reader::rle_targa_output_buffer< InputBuffer >::adjust_position(), claw::graphic::targa::reader::rle_targa_output_buffer< InputBuffer >::copy(), claw::graphic::png::reader::copy_pixel_line(), end(), claw::graphic::targa::reader::rle_targa_output_buffer< InputBuffer >::fill(), claw::graphic::bitmap::writer::init_header(), claw::graphic::bitmap::reader::load_1bpp(), claw::graphic::bitmap::reader::load_24bpp(), claw::graphic::targa::reader::load_color_mapped_raw(), claw::graphic::targa::reader::load_true_color_raw(), partial_copy(), claw::graphic::targa::reader::rle_targa_output_buffer< InputBuffer >::rle_targa_output_buffer(), claw::graphic::xbm::writer::save(), claw::graphic::targa::writer::save(), claw::graphic::pcx::writer::save(), claw::graphic::xbm::writer::save_bits(), claw::graphic::bitmap::writer::save_data(), and claw::graphic::jpeg::writer::save_image().
std::vector<scanline> claw::graphic::image::m_data [private] |
Data of the picture.
Definition at line 201 of file image.hpp.
Referenced by flip(), height(), operator[](), set_size(), and width().