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::scanline
One line in the image.
Definition: image.hpp:59
claw::graphic::image::scanline::const_reference
super::const_reference const_reference
Const reference to a pixel.
Definition: image.hpp:75
claw::graphic::image::base_iterator::iterator_category
std::random_access_iterator_tag iterator_category
The type of this category.
Definition: image.hpp:135
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::base_iterator::difference_type
ptrdiff_t difference_type
The type of the distance between two iterators.
Definition: image.hpp:132
claw::graphic::image::scanline::const_iterator
super::const_iterator const_iterator
Const iterator in the line.
Definition: image.hpp:81
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::scanline::operator[]
reference operator[](unsigned int i)
Get a pixel from the line.
Definition: image.ipp:38
claw::graphic::image::scanline::value_type
super::value_type value_type
The type of the pixels.
Definition: image.hpp:69
std
Definition: gif.hpp:461
claw::graphic::image::scanline::size
size_type size() const
Get the length of the line.
Definition: image.cpp:93
claw::graphic::image::height
unsigned int height() const
Gets image&#39;s height.
Definition: image.cpp:159
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::rgba_pixel
RGBA pixel.
Definition: pixel.hpp:79
claw::math::coordinate_2d< unsigned int >
claw::graphic::image::scanline::size_type
super::size_type size_type
An unsigned integral type.
Definition: image.hpp:84
claw::graphic::image::flip
void flip()
Set the image upside down.
Definition: image.cpp:301
claw::graphic::image::swap
void swap(image &that)
Swap the content of two images.
Definition: image.cpp:138
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::base_iterator
Base class for iterators on an image.
Definition: image.hpp:106
claw::graphic::image::scanline::end
iterator end()
Get en iterator past the last pixel.
Definition: image.cpp:63
claw::graphic::image::load
void load(std::istream &f)
Read the image from a stream.
Definition: image.cpp:381
math.hpp
Some mathematical structures and functions.
claw::math::rectangle
A class representing a rectangle by his x,y coordinates, width and height.
Definition: box_2d.hpp:39
claw::graphic::image::base_iterator::pointer
pixel_type * pointer
The type of the pointers to the values accesssed by the iterator.
Definition: image.hpp:129
claw::graphic::image::scanline::iterator
super::iterator iterator
Iterator in the line.
Definition: image.hpp:78
claw::graphic::image::width
unsigned int width() const
Gets image&#39;s width.
Definition: image.cpp:147
claw::graphic::image::base_iterator::reference
pixel_type & reference
The type of the references to the values accesssed by the iterator.
Definition: image.hpp:125
claw::graphic::image::scanline::super
std::vector< pixel_type > super
The type of the parent class.
Definition: image.hpp:66
claw::graphic::image::merge
void merge(const image &that)
Merge an image on the current image.
Definition: image.cpp:205
claw::graphic::image::base_iterator::value_type
pixel_type value_type
The type of the values accessed by the iterator.
Definition: image.hpp:121
claw::graphic::image::scanline::begin
iterator begin()
Get an iterator on the first pixel.
Definition: image.cpp:54
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::scanline::reference
super::reference reference
Reference to a pixel..
Definition: image.hpp:72
pixel.hpp
Representation of a pixel in image processing.
claw::graphic::image
A class to deal with images.
Definition: image.hpp:49
claw
This is the main namespace.
Definition: algorithm.hpp:33
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
operator+
claw::graphic::image::base_iterator< ImageT, PixelT >::self_type operator+(int n, const typename claw::graphic::image::base_iterator< ImageT, PixelT >::self_type &self)
Get an iterator at a specific distance of the current iterator.
Definition: image.ipp:261
image.ipp
Inline methods for the claw::graphic::image class.