image.hpp
Go to the documentation of this file.
/*
CLAW - a C++ Library Absolutely Wonderful
CLAW is a free library without any particular aim but being useful to
anyone.
Copyright (C) 2005-2011 Julien Jorge
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
contact: julien.jorge@gamned.org
*/
#ifndef __CLAW_IMAGE_HPP__
#define __CLAW_IMAGE_HPP__
#include <claw/pixel.hpp>
#include <claw/math.hpp>
#include <vector>
#include <iterator>
#include <iostream>
#include <cstddef>
namespace claw
{
namespace graphic
{
class image
{
public:
typedef rgba_pixel pixel_type;
class scanline:
private std::vector<pixel_type>
{
friend class image;
public:
typedef std::vector<pixel_type> super;
typedef super::value_type value_type;
typedef super::reference reference;
typedef super::const_reference const_reference;
typedef super::iterator iterator;
typedef super::const_iterator const_iterator;
typedef super::size_type size_type;
public:
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
inline reference operator[](unsigned int i);
inline const_reference operator[](unsigned int i) const;
size_type size() const;
}; // class scanline
public:
template<typename Image, typename Pixel>
class base_iterator:
public std::iterator<std::random_access_iterator_tag, Pixel>
{
private:
typedef Image image_type;
typedef Pixel pixel_type;
typedef base_iterator<image_type, pixel_type> self_type;
public:
typedef pixel_type value_type;
typedef pixel_type& reference;
typedef pixel_type* pointer;
typedef ptrdiff_t difference_type;
typedef std::random_access_iterator_tag iterator_category;
public:
inline base_iterator();
inline base_iterator( image_type& owner, unsigned int x=0,
unsigned int y = 0 );
inline bool operator==( const self_type& that ) const;
inline bool operator!=( const self_type& that ) const;
inline bool operator<( const self_type& that ) const;
inline bool operator>( const self_type& that ) const;
inline bool operator<=( const self_type& that ) const;
inline bool operator>=( const self_type& that ) const;
inline self_type& operator+=( int n );
inline self_type& operator-=( int n );
inline self_type operator+( int n ) const;
inline self_type operator-( int n ) const;
template<typename ImageT, typename PixelT>
friend inline self_type operator+( int n, const self_type& self );
inline difference_type operator-( const self_type& that ) const;
inline self_type& operator++();
inline self_type operator++(int);
inline self_type& operator--();
inline self_type operator--(int);
inline reference operator*() const;
inline pointer operator->() const;
inline reference operator[]( int n ) const;
private:
bool is_final() const;
private:
image_type* m_owner;
math::coordinate_2d<unsigned int> m_pos;
}; // class base_iterator
public:
typedef base_iterator<image, pixel_type> iterator;
typedef base_iterator<const image, const pixel_type> const_iterator;
public:
image();
image( unsigned int w, unsigned int h );
image( std::istream& f );
void swap( image& that );
unsigned int width() const;
unsigned int height() const;
inline scanline& operator[](unsigned int i);
inline const scanline& operator[](unsigned int i) const;
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
void merge( const image& that );
void merge
( const image& that, const math::coordinate_2d<int>& pos );
void partial_copy
( const image& that, const math::coordinate_2d<int>& pos );
void flip();
void fill( const math::rectangle<int> r, const pixel_type& c );
void set_size( unsigned int w, unsigned int h );
void load( std::istream& f );
private:
std::vector<scanline> m_data;
}; // class image
} // namespace graphic
} // namespace claw
namespace std
{
void swap( claw::graphic::image& a, claw::graphic::image& b );
} // namespace std
// Inline methods
#include <claw/impl/image.ipp>
#endif // __CLAW_IMAGE_HPP__
claw::graphic::image::base_iterator
Base class for iterators on an image.
Definition image.hpp:108
claw::graphic::image::base_iterator::operator+=
self_type & operator+=(int n)
Move the iterator.
Definition image.ipp:178
claw::graphic::image::base_iterator::operator<=
bool operator<=(const self_type &that) const
Tell if the current iterator is before an other, or on the same address.
Definition image.ipp:152
claw::graphic::image::base_iterator::operator+
self_type operator+(int n) const
Get an iterator at a specific distance of the current iterator.
Definition image.ipp:231
claw::graphic::image::base_iterator< image_type, pixel_type >::pointer
pixel_type * pointer
Definition image.hpp:129
claw::graphic::image::base_iterator::operator>
bool operator>(const self_type &that) const
Tell if the current iterator is after an other.
Definition image.ipp:138
claw::graphic::image::base_iterator::operator++
self_type operator++(int)
Postincrement.
Definition image.ipp:323
claw::graphic::image::base_iterator::operator-=
self_type & operator-=(int n)
Move the iterator.
Definition image.ipp:203
claw::graphic::image::base_iterator< image_type, pixel_type >::iterator_category
std::random_access_iterator_tag iterator_category
Definition image.hpp:135
claw::graphic::image::base_iterator::operator++
self_type & operator++()
Preincrement.
Definition image.ipp:302
claw::graphic::image::base_iterator::operator->
pointer operator->() const
Get a pointer on the pointed pixel.
Definition image.ipp:384
claw::graphic::image::base_iterator::base_iterator
base_iterator(image_type &owner, unsigned int x=0, unsigned int y=0)
Constructor, from an image.
Definition image.ipp:77
claw::graphic::image::base_iterator::operator-
self_type operator-(int n) const
Get an iterator at a specific distance of the current iterator.
Definition image.ipp:245
claw::graphic::image::base_iterator::operator==
bool operator==(const self_type &that) const
Tell if two iterator point to the same address.
Definition image.ipp:91
claw::graphic::image::base_iterator< image_type, pixel_type >::reference
pixel_type & reference
Definition image.hpp:125
claw::graphic::image::base_iterator::operator*
reference operator*() const
Get a reference on the pointed pixel.
Definition image.ipp:371
claw::graphic::image::base_iterator< image_type, pixel_type >::value_type
pixel_type value_type
Definition image.hpp:121
claw::graphic::image::base_iterator::operator--
self_type operator--(int)
Postdecrement.
Definition image.ipp:358
claw::graphic::image::base_iterator::operator<
bool operator<(const self_type &that) const
Tell if the current iterator is before an other.
Definition image.ipp:122
claw::graphic::image::base_iterator< image_type, pixel_type >::difference_type
ptrdiff_t difference_type
Definition image.hpp:132
claw::graphic::image::base_iterator::operator!=
bool operator!=(const self_type &that) const
Tell if two iterator points to different addresses.
Definition image.ipp:109
claw::graphic::image::base_iterator::operator+
friend self_type operator+(int n, const self_type &self)
Get an iterator at a specific distance of the current iterator.
claw::graphic::image::base_iterator::operator[]
reference operator[](int n) const
Get a pixel, using the iterator like an array.
Definition image.ipp:398
claw::graphic::image::base_iterator::operator--
self_type & operator--()
Predecrement.
Definition image.ipp:336
claw::graphic::image::base_iterator::operator-
difference_type operator-(const self_type &that) const
Get the distance between two iterators.
Definition image.ipp:277
claw::graphic::image::base_iterator::operator>=
bool operator>=(const self_type &that) const
Tell if the current iterator is after an other, or on the same address.
Definition image.ipp:166
claw::graphic::image::base_iterator::base_iterator
base_iterator()
Constructor.
Definition image.ipp:62
claw::graphic::image::scanline
One line in the image.
Definition image.hpp:61
claw::graphic::image::scanline::value_type
super::value_type value_type
The type of the pixels.
Definition image.hpp:69
claw::graphic::image::scanline::size_type
super::size_type size_type
An unsigned integral type.
Definition image.hpp:84
claw::graphic::image::scanline::begin
iterator begin()
Get an iterator on the first pixel.
Definition image.cpp:54
claw::graphic::image::scanline::end
iterator end()
Get en iterator past the last pixel.
Definition image.cpp:63
claw::graphic::image::scanline::reference
super::reference reference
Reference to a pixel..
Definition image.hpp:72
claw::graphic::image::scanline::operator[]
reference operator[](unsigned int i)
Get a pixel from the line.
Definition image.ipp:38
claw::graphic::image::scanline::const_reference
super::const_reference const_reference
Const reference to a pixel.
Definition image.hpp:75
claw::graphic::image::scanline::iterator
super::iterator iterator
Iterator in the line.
Definition image.hpp:78
claw::graphic::image::scanline::super
std::vector< pixel_type > super
The type of the parent class.
Definition image.hpp:66
claw::graphic::image::scanline::const_iterator
super::const_iterator const_iterator
Const iterator in the line.
Definition image.hpp:81
claw::graphic::image::scanline::size
size_type size() const
Get the length of the line.
Definition image.cpp:93
claw::graphic::image
A class to deal with images.
Definition image.hpp:50
claw::graphic::image::flip
void flip()
Set the image upside down.
Definition image.cpp:301
claw::graphic::image::partial_copy
void partial_copy(const image &that, const math::coordinate_2d< int > &pos)
Copy an image on the current image.
Definition image.cpp:272
claw::graphic::image::height
unsigned int height() const
Gets image's height.
Definition image.cpp:159
claw::graphic::image::pixel_type
rgba_pixel pixel_type
The type representing the colors of the pixels in the image.
Definition image.hpp:53
claw::graphic::image::operator[]
scanline & operator[](unsigned int i)
Gets a line of the image.
Definition image.ipp:429
claw::graphic::image::set_size
void set_size(unsigned int w, unsigned int h)
Set a new size to the image.
Definition image.cpp:363
claw::graphic::image::width
unsigned int width() const
Gets image's width.
Definition image.cpp:147
claw::graphic::image::merge
void merge(const image &that)
Merge an image on the current image.
Definition image.cpp:205
claw::graphic::image::fill
void fill(const math::rectangle< int > r, const pixel_type &c)
Fill an area of the image with a given color.
Definition image.cpp:314
claw::graphic::image::end
iterator end()
Get an iterator pointing just past the last pixel.
Definition image.cpp:177
claw::graphic::image::swap
void swap(image &that)
Swap the content of two images.
Definition image.cpp:138
claw::graphic::image::image
image()
Constructor. Creates an image without datas.
Definition image.cpp:106
claw::graphic::image::load
void load(std::istream &f)
Read the image from a stream.
Definition image.cpp:381
claw::graphic::image::const_iterator
base_iterator< const image, const pixel_type > const_iterator
The type of the iterator to access constant pixels.
Definition image.hpp:203
claw::graphic::image::iterator
base_iterator< image, pixel_type > iterator
The type of the iterator on the pixels of the image.
Definition image.hpp:195
claw::graphic::image::begin
iterator begin()
Get an iterator pointing on the first pixel.
Definition image.cpp:168
claw::math::coordinate_2d
Coordinates in a two dimensional space.
Definition coordinate_2d.hpp:43
claw::math::rectangle
A class representing a rectangle by his x,y coordinates, width and height.
Definition rectangle.hpp:52
image.ipp
Inline methods for the claw::graphic::image class.
math.hpp
Some mathematical structures and functions.
claw::graphic
Everything about image structures and processing.
Definition bitmap.hpp:43
claw
This is the main namespace.
Definition algorithm.hpp:34
pixel.hpp
Representation of a pixel in image processing.
claw::graphic::rgba_pixel
RGBA pixel.
Definition pixel.hpp:80