claw::graphic::image Class Reference

A class to deal with images. More...

#include <image.hpp>

Inheritance diagram for claw::graphic::image:
claw::graphic::bitmap claw::graphic::jpeg claw::graphic::pcx claw::graphic::png claw::graphic::targa claw::graphic::xbm

List of all members.

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.
scanlineoperator[] (unsigned int i)
 Gets a line of the image.
const scanlineoperator[] (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< scanlinem_data
 Data of the picture.

Detailed Description

A class to deal with images.

Author:
Julien Jorge

Definition at line 48 of file image.hpp.


Member Typedef Documentation

Definition at line 171 of file image.hpp.

Definition at line 170 of file image.hpp.

Definition at line 51 of file image.hpp.


Constructor & Destructor Documentation

claw::graphic::image::image (  ) 

Constructor. Creates an image without datas.

Postcondition:
width() == height() == 0

Definition at line 105 of file image.cpp.

00106 {
00107 
00108 } // image::image() [default constructor]

claw::graphic::image::image ( unsigned int  w,
unsigned int  h 
)

Constructor. Creates an empty image.

Parameters:
w Image's width.
h Image's height.
Precondition:
w > 0 and h > 0

Definition at line 117 of file image.cpp.

References set_size().

00118 {
00119   set_size(w, h);
00120 } // image::image() [constructor]

claw::graphic::image::image ( std::istream &  f  ) 

Constructor. Reads an image from an input stream.

Parameters:
f The stream to read from.

Definition at line 127 of file image.cpp.

References load().

00128 {
00129   load(f);
00130 } // image::image() [constructor]

claw::graphic::image::~image (  )  [virtual]

Destructor.

Definition at line 136 of file image.cpp.

00137 {
00138   // nothing to do
00139 } // image::~image()


Member Function Documentation

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.

00185 {
00186   return const_iterator(*this);
00187 } // image::begin()

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().

00167 {
00168   return iterator(*this);
00169 } // image::begin()

claw::graphic::image::const_iterator claw::graphic::image::end (  )  const

Get an iterator pointing just past the last pixel.

Definition at line 193 of file image.cpp.

References height(), and width().

00194 {
00195   return const_iterator(*this, width(), height());
00196 } // image::end()

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().

00176 {
00177   return iterator(*this, width(), height()-1);
00178 } // image::end()

void claw::graphic::image::flip (  ) 

Set the image upside down.

Definition at line 234 of file image.cpp.

References height(), and m_data.

00235 {
00236   for (unsigned int y=0; y!=height()/2; ++y)
00237     std::swap( m_data[y], m_data[height()-y-1] );
00238 } // image::flip()

unsigned int claw::graphic::image::height (  )  const
void claw::graphic::image::load ( std::istream &  f  ) 

Read the image from a stream.

Parameters:
f The stream to read from.

Definition at line 265 of file image.cpp.

Referenced by image().

00266 {
00267   bool ok = false;
00268 
00269 #ifdef CLAW_JPEG_SUPPORT
00270   if (!ok)
00271     try { jpeg::reader( *this, f ); ok = true; }
00272     catch( ... ) { }
00273 #endif // CLAW_JPEG_SUPPORT
00274 
00275 #ifdef CLAW_PNG_SUPPORT
00276   if (!ok)
00277     try { png::reader( *this, f ); ok = true; }
00278     catch( ... ) { }
00279 #endif // CLAW_PNG_SUPPORT
00280 
00281   if (!ok)
00282     try { bitmap::reader( *this, f ); ok = true; }
00283     catch( ... ) { }
00284 
00285   if (!ok)
00286     try { targa::reader( *this, f ); ok = true; }
00287     catch( ... ) { }
00288 
00289   if (!ok)
00290     try { pcx::reader( *this, f ); ok = true; }
00291     catch( ... ) { }
00292 
00293   if (!ok)
00294     try { xbm::reader( *this, f ); ok = true; }
00295     catch( ... ) { }
00296 
00297   if (!ok)
00298     throw claw::bad_format( "image::load: file format isn't supported." );
00299 } // image::load()

const claw::graphic::image::scanline & claw::graphic::image::operator[] ( unsigned int  i  )  const [inline]

Gets a line of the image.

Definition at line 439 of file image.ipp.

References m_data.

00440 {
00441   return m_data[i];
00442 } // image::operator[]() [const]

claw::graphic::image::scanline & claw::graphic::image::operator[] ( unsigned int  i  )  [inline]

Gets a line of the image.

Definition at line 429 of file image.ipp.

References m_data.

00430 {
00431   return m_data[i];
00432 } // image::operator[]()

void claw::graphic::image::partial_copy ( const image that,
const claw::math::coordinate_2d< int > &  pos 
)

Copy an image on the current image.

Parameters:
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.

00206 {
00207   claw::math::rectangle<int> my_box(0, 0, width(), height());
00208   claw::math::rectangle<int> his_box(pos.x, pos.y, that.width(), that.height());
00209 
00210   if ( my_box.intersects( his_box ) )
00211     {
00212       claw::math::rectangle<int> intersection;
00213       unsigned int that_y = pos.y < 0 ? -pos.y : 0;
00214       unsigned int that_x = pos.x < 0 ? -pos.x : 0;
00215 
00216       intersection = my_box.intersection( his_box );
00217 
00218       for (int y=0; y!=intersection.height; ++y)
00219         {
00220           scanline::const_iterator first = that[y + that_y].begin() + that_x;
00221           scanline::const_iterator last = first + intersection.width;
00222           scanline::iterator dest = (*this)[y + intersection.position.y].begin()
00223             + intersection.position.x;
00224 
00225           std::copy( first, last, dest );
00226         }
00227     }
00228 } // image::partial_copy()

void claw::graphic::image::set_size ( unsigned int  w,
unsigned int  h 
)

Set a new size to the image.

Remarks:
Image's data won't be lost. If a dimension is set larger than its current value, extra pixels won't be initialized.
Precondition:
(w!=0) && (h!=0)

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().

00248 {
00249   if (w == 0)
00250     m_data.clear();
00251   else
00252     {
00253       m_data.resize(h);
00254   
00255       for (unsigned int y=0; y!=height(); ++y)
00256         m_data[y].resize(w);
00257     }
00258 } // image::set_size()

unsigned int claw::graphic::image::width (  )  const

Member Data Documentation

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().


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

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1