degate  0.1.2
Public Types | Public Member Functions | Private Member Functions | Private Attributes
degate::StoragePolicy_Tile< PixelPolicy > Class Template Reference

Storage policy for image objects that consists of tiles. More...

#include <TileImage.h>

Inheritance diagram for degate::StoragePolicy_Tile< PixelPolicy >:
Inheritance graph
[legend]

List of all members.

Public Types

typedef std::shared_ptr
< MemoryMap< typename
PixelPolicy::pixel_type > > 
MemoryMap_shptr

Public Member Functions

 StoragePolicy_Tile (unsigned int _width, unsigned int _height, std::string const &_directory, bool _persistent=false, unsigned int _tile_width_exp=10)
 The constructor for a tile based image.
virtual ~StoragePolicy_Tile ()
 The destructor.
unsigned int get_tile_size () const
 Get the width / height of a single tile.
std::string get_directory () const
 Get the directory, where images are stored.
bool is_persistent () const
 Check if the image is persistent.
PixelPolicy::pixel_type get_pixel (unsigned int x, unsigned int y) const
 Get pixel for "native" pixel types.
void set_pixel (unsigned int x, unsigned int y, typename PixelPolicy::pixel_type new_val)
 Set "native" pixel.
void raw_copy (void *dst_buf, unsigned int src_x, unsigned int src_y) const
 Copy the raw data from an image tile that has its upper left corner at x,y into a buffer.

Private Member Functions

unsigned int calc_real_size (unsigned int requested_size, unsigned int tile_width_exp) const
 Get the minimum width or height of an tile based image, that it at least requested_size pixel width / height.

Private Attributes

const bool persistent
const unsigned int tile_width_exp
const unsigned int offset_bitmask
const std::string directory
TileCache< PixelPolicy > tile_cache

Detailed Description

template<class PixelPolicy>
class degate::StoragePolicy_Tile< PixelPolicy >

Storage policy for image objects that consists of tiles.

This implementation uses a TileCache.

Definition at line 40 of file TileImage.h.


Member Typedef Documentation

template<class PixelPolicy >
typedef std::shared_ptr<MemoryMap<typename PixelPolicy::pixel_type> > degate::StoragePolicy_Tile< PixelPolicy >::MemoryMap_shptr

Definition at line 44 of file TileImage.h.


Constructor & Destructor Documentation

template<class PixelPolicy >
degate::StoragePolicy_Tile< PixelPolicy >::StoragePolicy_Tile ( unsigned int  _width,
unsigned int  _height,
std::string const &  _directory,
bool  _persistent = false,
unsigned int  _tile_width_exp = 10 
) [inline]

The constructor for a tile based image.

The constructed image has at least the size specified via the width and height parameter. Because the image is splitted into equisized tiles the constructed image might be larger than the requested size.

Parameters:
_widthThe minimum width of the image.
_heightThe minimum height of the image.
_directoryA tile based image is stored in multiple files. This directory specifies the place where the files are stored. If the directory doen't exits, it is created.
_persistentThis boolean value indicates whether the image files are removed on object destruction.
_tile_width_expThe width (and height) for image tiles. This value is specified as an exponent to the base 2. This means for example that if you want to use a width of 1024 pixel, you have to give a value of 10, because 2^10 is 1024.

Definition at line 102 of file TileImage.h.

References degate::create_directory(), and degate::file_exists().

                                                          :
      persistent(_persistent),
      tile_width_exp(_tile_width_exp),
      offset_bitmask((1 << _tile_width_exp) - 1),
      directory(_directory),
      tile_cache(_directory, _tile_width_exp, _persistent) {

      if(!file_exists(_directory)) create_directory(_directory);

    }

Here is the call graph for this function:

template<class PixelPolicy >
virtual degate::StoragePolicy_Tile< PixelPolicy >::~StoragePolicy_Tile ( ) [inline, virtual]

The destructor.

Definition at line 119 of file TileImage.h.

References degate::StoragePolicy_Tile< PixelPolicy >::directory, degate::StoragePolicy_Tile< PixelPolicy >::persistent, and degate::remove_directory().

Here is the call graph for this function:


Member Function Documentation

template<class PixelPolicy >
unsigned int degate::StoragePolicy_Tile< PixelPolicy >::calc_real_size ( unsigned int  requested_size,
unsigned int  tile_width_exp 
) const [inline, private]

Get the minimum width or height of an tile based image, that it at least requested_size pixel width / height.

Parameters:
requested_sizeThe minimum size.
tile_width_expThe exponent (to base 2) that gives th
Returns:

Definition at line 71 of file TileImage.h.

References degate::StoragePolicy_Tile< PixelPolicy >::tile_width_exp.

                                                                   {

      // we can't use the get_tile_size() method here, because we use
      // this method during the base class constructor call.
      unsigned int tile_size = (1 << tile_width_exp);
      unsigned int remainder = requested_size % tile_size;
      if(remainder == 0) return requested_size;
      else return requested_size - remainder + tile_size;
    }
template<class PixelPolicy >
std::string degate::StoragePolicy_Tile< PixelPolicy >::get_directory ( ) const [inline]

Get the directory, where images are stored.

Definition at line 136 of file TileImage.h.

References degate::StoragePolicy_Tile< PixelPolicy >::directory.

{ return directory; }
template<class PixelPolicy >
PixelPolicy::pixel_type degate::StoragePolicy_Tile< PixelPolicy >::get_pixel ( unsigned int  x,
unsigned int  y 
) const [inline, virtual]

Get pixel for "native" pixel types.

This method is abstract. If you derive from this class, you should implement it for a concrete StoragePolicy.

Implements degate::StoragePolicy_Base< PixelPolicy >.

Definition at line 161 of file TileImage.h.

                                                                   {
    MemoryMap_shptr mem = tile_cache.get_tile(x, y);
    return mem->get(x & offset_bitmask, y & offset_bitmask);
  }
template<class PixelPolicy >
unsigned int degate::StoragePolicy_Tile< PixelPolicy >::get_tile_size ( ) const [inline]

Get the width / height of a single tile.

The size is a power of two.

Definition at line 128 of file TileImage.h.

References degate::StoragePolicy_Tile< PixelPolicy >::tile_width_exp.

                                              {
      return (1 << tile_width_exp);
    }
template<class PixelPolicy >
bool degate::StoragePolicy_Tile< PixelPolicy >::is_persistent ( ) const [inline]

Check if the image is persistent.

Definition at line 141 of file TileImage.h.

References degate::StoragePolicy_Tile< PixelPolicy >::persistent.

{ return persistent; }
template<class PixelPolicy >
void degate::StoragePolicy_Tile< PixelPolicy >::raw_copy ( void *  dst_buf,
unsigned int  src_x,
unsigned int  src_y 
) const [inline]

Copy the raw data from an image tile that has its upper left corner at x,y into a buffer.

Definition at line 151 of file TileImage.h.

References degate::StoragePolicy_Tile< PixelPolicy >::tile_cache.

                                                                                {
      MemoryMap_shptr mem = tile_cache.get_tile(src_x, src_y);
      mem->raw_copy(dst_buf);
    }
template<class PixelPolicy >
void degate::StoragePolicy_Tile< PixelPolicy >::set_pixel ( unsigned int  x,
unsigned int  y,
typename PixelPolicy::pixel_type  new_val 
) [inline, virtual]

Set "native" pixel.

This method is abstract. If you derive from this class, you should implement it for a concrete StoragePolicy.

Implements degate::StoragePolicy_Base< PixelPolicy >.

Definition at line 169 of file TileImage.h.

                                                                                     {

    MemoryMap_shptr mem = tile_cache.get_tile(x, y);
    mem->set(x & offset_bitmask, y & offset_bitmask, new_val);
  }

Member Data Documentation

template<class PixelPolicy >
const std::string degate::StoragePolicy_Tile< PixelPolicy >::directory [private]
template<class PixelPolicy >
const unsigned int degate::StoragePolicy_Tile< PixelPolicy >::offset_bitmask [private]

Definition at line 53 of file TileImage.h.

template<class PixelPolicy >
const bool degate::StoragePolicy_Tile< PixelPolicy >::persistent [private]
template<class PixelPolicy >
TileCache<PixelPolicy> degate::StoragePolicy_Tile< PixelPolicy >::tile_cache [mutable, private]

Definition at line 59 of file TileImage.h.

Referenced by degate::StoragePolicy_Tile< PixelPolicy >::raw_copy().

template<class PixelPolicy >
const unsigned int degate::StoragePolicy_Tile< PixelPolicy >::tile_width_exp [private]

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