36 typedef T ComputeType;
38 static ScalarType scalar(
const T& v) {
return v;}
45 typedef float ComputeType;
46 typedef uchar ScalarType;
47 static ScalarType scalar(
const uchar& v) {
return v;}
54 typedef float ComputeType;
55 typedef ushort ScalarType;
56 static ScalarType scalar(
const ushort& v) {
return v;}
64 typedef float ScalarType;
65 static ScalarType scalar(
const ByteRGBA& v) {
return (static_cast<float>(v.
r)+static_cast<float>(v.g)+static_cast<float>(v.b))/3.0f;}
79 typedef typename PixelTraits<T>::ComputeType ComputeType;
80 typedef typename PixelTraits<T>::ScalarType ScalarType;
84 Raster(uint w,uint h,uint p,T* d)
89 ,_row_end(row_range(h),p)
90 ,_const_row_end(row_range(h),p)
111 bool contiguous()
const
113 return (_width==_pitch);
116 uint contiguous_size()
const
118 assert(contiguous());
119 return _width*_height;
122 T* contiguous_begin()
124 assert(contiguous());
128 const T* contiguous_begin()
const
130 assert(contiguous());
136 assert(contiguous());
137 return _data+contiguous_size();
140 const T* contiguous_end()
const
142 assert(contiguous());
143 return _data+contiguous_size();
148 return _data+r*_pitch;
151 const T* row(uint r)
const
153 return _data+r*_pitch;
156 boost::iterator_range<T*> row_range(uint r)
159 return boost::iterator_range<T*>(it,it+_width);
162 boost::iterator_range<const T*> row_range(uint r)
const
164 const T*
const it=row(r);
165 return boost::iterator_range<const T*>(it,it+_width);
168 class RowIterator :
public std::iterator<std::forward_iterator_tag, boost::iterator_range<T*> >
172 RowIterator(
const boost::iterator_range<T*>& row, uint p)
183 assert(_pitch==it._pitch);
189 return _row.begin()==it._row.begin();
194 return _row.begin()!=it._row.begin();
199 _row=boost::iterator_range<T*>
210 _row=boost::iterator_range<T*>
218 boost::iterator_range<T*>& operator*()
223 boost::iterator_range<T*>* operator->()
230 boost::iterator_range<T*> _row;
240 RowIterator row_end()
245 class ConstRowIterator :
public std::iterator<std::forward_iterator_tag, boost::iterator_range<const T*> >
260 assert(_pitch==it._pitch);
266 return _row.begin()==it._row.begin();
271 return _row.begin()!=it._row.begin();
276 _row=boost::iterator_range<const T*>
287 _row=boost::iterator_range<const T*>
295 boost::iterator_range<const T*>& operator*()
300 boost::iterator_range<const T*>* operator->()
307 boost::iterator_range<const T*> _row;
317 ConstRowIterator row_end()
const
319 return _const_row_end;
323 void fill(
const T& v);
325 const ScalarType maximum_scalar_pixel_value()
const;
328 void scan(uint y,
float x0,
const ComputeType& v0,
float x1,
const ComputeType& v1);
331 template <
typename V>
void scan(uint y,
float x0,
const V& v0,
float x1,
const V& v1,
const boost::function<ComputeType (
const V&)>& fn);
333 bool write_ppmfile(
const std::string&,
Progress*)
const;
334 bool write_pgmfile(
const std::string&,
Progress*)
const;
346 const RowIterator _row_end;
348 const ConstRowIterator _const_row_end;
355 template <
typename T>
inline void Raster<T>::scan(uint y,
float x0,
const ComputeType& v0,
float x1,
const ComputeType& v1)
359 if (x1<0.5f || width()-0.5f<x0)
return;
361 const int ix_min=
static_cast<int>(std::max(0.0f ,ceilf(x0-0.5f)));
362 const int ix_max=
static_cast<int>(std::min(width()-0.5f,floorf(x1-0.5f)));
364 const ComputeType kv((v1-v0)/(x1-x0));
366 T*
const row_ptr=row(y);
367 for (
int ix=ix_min;ix<=ix_max;ix++)
369 const ComputeType v(v0+kv*(ix+0.5f-x0));
370 row_ptr[ix]=
static_cast<T
>(v);
374 template <
typename T>
template <
typename V>
inline void Raster<T>::scan(uint y,
float x0,
const V& v0,
float x1,
const V& v1,
const boost::function<ComputeType (
const V&)>& fn)
378 if (x1<0.5f || width()-0.5f<x0)
return;
380 const int ix_min=
static_cast<int>(std::max(0.0f ,ceilf(x0-0.5f)));
381 const int ix_max=
static_cast<int>(std::min(width()-0.5f,floorf(x1-0.5f)));
383 const V kv((v1-v0)/(x1-x0));
385 T*
const row_ptr=row(y);
386 for (
int ix=ix_min;ix<=ix_max;ix++)
388 const ComputeType v(fn(v0+kv*(ix+0.5f-x0)));
389 row_ptr[ix]=
static_cast<T
>(v);
402 boost::scoped_array<T> _storage;
T r
Colour component.
Definition: rgb.h:39
Class to represent red-green-blue-alpha colours stored with 8-bit resolution.
Definition: rgb.h:136
void fill(const T &v)
Clear the image to a constant value.
Definition: image.cpp:50
Class to support specialisation for particular pixel formats.
Definition: image.h:32
Class for 2D raster images of a specified type.
Definition: image.h:75
Interface for class ByteRGBA and class FloatRGBA.
Mix-in class for call-backs from long operations.
Definition: progress.h:30
Class to represent red-green-blue-alpha colours stored to floating point accuracy.
Definition: rgb.h:173
void scan(uint y, float x0, const ComputeType &v0, float x1, const ComputeType &v1)
Fill a line segment on the given half-open range [x0,x1), interpolating between the two given values...
Definition: image.h:355