Image Utilities (IU)
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Groups Pages
image_cpu.h
1 #pragma once
2 #include <thrust/memory.h>
3 #include "image.h"
4 #include "image_allocator_cpu.h"
5 
6 //#include "ndarray/ndarray_ref.host.h"
7 template<typename type, int dims> class ndarray_ref;
8 
9 namespace boost
10 {
11  namespace python
12  {
13  namespace api
14  {
15  class object;
16  }
17  }
18 }
19 
20 
21 namespace iu {
22 
23 template<typename PixelType, class Allocator>
27 class ImageCpu : public Image
28 {
29 public:
31  typedef PixelType pixel_type;
32 
35  Image(),
36  data_(0), pitch_(0), ext_data_pointer_(false)
37  {
38  }
39 
41  virtual ~ImageCpu()
42  {
44  {
45  // do not delete externally handeled data pointers.
46  Allocator::free(data_);
47  data_ = 0;
48  }
49  pitch_ = 0;
50  }
51 
56  ImageCpu(unsigned int _width, unsigned int _height) :
57  Image(_width, _height), data_(0), pitch_(0),
58  ext_data_pointer_(false)
59  {
60  data_ = Allocator::alloc(_width, _height, &pitch_);
61  }
62 
67  Image(size.width, size.height), data_(0), pitch_(0),
68  ext_data_pointer_(false)
69  {
70  data_ = Allocator::alloc(size.width, size.height, &pitch_);
71  }
72 
80  ImageCpu(PixelType* _data, unsigned int _width, unsigned int _height,
81  size_t _pitch, bool ext_data_pointer = false) :
82  Image(_width, _height), data_(0), pitch_(0),
83  ext_data_pointer_(ext_data_pointer)
84  {
86  {
87  data_ = _data;
88  pitch_ = _pitch;
89  }
90  else
91  {
92  data_ = Allocator::alloc(width(), height(), &pitch_);
93  Allocator::copy(_data, _pitch, data_, pitch_, this->size());
94  }
95  }
96 
103  PixelType* data(int ox = 0, int oy = 0)
104  {
105  return &data_[oy * stride() + ox];
106  }
107 
114  const PixelType* data(int ox = 0, int oy = 0) const
115  {
116  return reinterpret_cast<const PixelType*>(
117  &data_[oy * stride() + ox]);
118  }
119 
121  PixelType getPixel(unsigned int x, unsigned int y)
122  {
123  return *data(x, y);
124  }
125 
130  PixelType* operator[](unsigned int row)
131  {
132  return data_+row*stride();
133  }
134 
136  virtual size_t bytes() const
137  {
138  return height()*pitch_;
139  }
140 
142  virtual size_t pitch() const
143  {
144  return pitch_;
145  }
146 
148  virtual size_t stride() const
149  {
150  return pitch_/sizeof(PixelType);
151  }
152 
154  virtual unsigned int bitDepth() const
155  {
156  return 8*sizeof(PixelType);
157  }
158 
162  thrust::pointer<PixelType, thrust::host_system_tag> begin(void)
163  {
164  return thrust::pointer<PixelType, thrust::host_system_tag>(data());
165  }
166 
170  thrust::pointer<PixelType, thrust::host_system_tag> end(void)
171  {
172  return thrust::pointer<PixelType, thrust::host_system_tag>(data()+stride()*height());
173  }
174 
176  virtual bool onDevice() const
177  {
178  return false;
179  }
180 
183 
186 
197  ImageCpu(boost::python::api::object& py_arr);
198 
199 protected:
201  PixelType* data_;
203  size_t pitch_;
206 
207 private:
209  ImageCpu(const ImageCpu&);
211  ImageCpu& operator=(const ImageCpu&);
212 };
213 
214 } // namespace iu
215 
216 
ImageCpu(unsigned int _width, unsigned int _height)
Definition: image_cpu.h:56
iu::Size< 2 > size() const
Definition: image.h:64
ndarray_ref< PixelType, 2 > ref() const
ImageCpu(const iu::Size< 2 > &size)
Definition: image_cpu.h:66
Base class for 2D images (pitched memory).
Definition: image.h:30
IUCORE_DLLAPI void copy(const LinearHostMemory_8u_C1 *src, LinearHostMemory_8u_C1 *dst)
thrust::pointer< PixelType, thrust::host_system_tag > end(void)
Definition: image_cpu.h:170
unsigned int & height
Definition: vector.h:531
virtual bool onDevice() const
Definition: image_cpu.h:176
size_t pitch_
Definition: image_cpu.h:203
PixelType * operator[](unsigned int row)
Definition: image_cpu.h:130
unsigned int & width
Definition: vector.h:529
PixelType getPixel(unsigned int x, unsigned int y)
Definition: image_cpu.h:121
virtual unsigned int bitDepth() const
Definition: image_cpu.h:154
Definition: image_cpu.h:7
PixelType * data_
Definition: image_cpu.h:201
virtual size_t pitch() const
Definition: image_cpu.h:142
ImageCpu()
Definition: image_cpu.h:34
virtual size_t bytes() const
Definition: image_cpu.h:136
virtual size_t stride() const
Definition: image_cpu.h:148
PixelType pixel_type
Definition: image_cpu.h:31
Template specialization for 2-d unsigned int vectors (size vectors).
Definition: vector.h:525
thrust::pointer< PixelType, thrust::host_system_tag > begin(void)
Definition: image_cpu.h:162
unsigned int width() const
Definition: image.h:72
bool ext_data_pointer_
Definition: image_cpu.h:205
const PixelType * data(int ox=0, int oy=0) const
Definition: image_cpu.h:114
ImageCpu(PixelType *_data, unsigned int _width, unsigned int _height, size_t _pitch, bool ext_data_pointer=false)
Definition: image_cpu.h:80
PixelType * data(int ox=0, int oy=0)
Definition: image_cpu.h:103
virtual ~ImageCpu()
Definition: image_cpu.h:41
Host 2D image class (pitched memory).
Definition: image_cpu.h:27
unsigned int height() const
Definition: image.h:80