100 #ifndef _CV_WIMAGE_H_
101 #define _CV_WIMAGE_H_
109 template <
typename T>
class WImage;
110 template <
typename T>
class WImageBuffer;
111 template <
typename T>
class WImageView;
113 template<
typename T,
int C>
class WImageC;
114 template<
typename T,
int C>
class WImageBufferC;
115 template<
typename T,
int C>
class WImageViewC;
118 typedef WImage<uchar> WImage_b;
119 typedef WImageView<uchar> WImageView_b;
120 typedef WImageBuffer<uchar> WImageBuffer_b;
122 typedef WImageC<uchar, 1> WImage1_b;
123 typedef WImageViewC<uchar, 1> WImageView1_b;
124 typedef WImageBufferC<uchar, 1> WImageBuffer1_b;
126 typedef WImageC<uchar, 3> WImage3_b;
127 typedef WImageViewC<uchar, 3> WImageView3_b;
128 typedef WImageBufferC<uchar, 3> WImageBuffer3_b;
130 typedef WImage<float> WImage_f;
131 typedef WImageView<float> WImageView_f;
132 typedef WImageBuffer<float> WImageBuffer_f;
134 typedef WImageC<float, 1> WImage1_f;
135 typedef WImageViewC<float, 1> WImageView1_f;
136 typedef WImageBufferC<float, 1> WImageBuffer1_f;
138 typedef WImageC<float, 3> WImage3_f;
139 typedef WImageViewC<float, 3> WImageView3_f;
140 typedef WImageBufferC<float, 3> WImageBuffer3_f;
144 typedef WImage<short> WImage_16s;
145 typedef WImageView<short> WImageView_16s;
146 typedef WImageBuffer<short> WImageBuffer_16s;
148 typedef WImageC<short, 1> WImage1_16s;
149 typedef WImageViewC<short, 1> WImageView1_16s;
150 typedef WImageBufferC<short, 1> WImageBuffer1_16s;
152 typedef WImageC<short, 3> WImage3_16s;
153 typedef WImageViewC<short, 3> WImageView3_16s;
154 typedef WImageBufferC<short, 3> WImageBuffer3_16s;
156 typedef WImage<ushort> WImage_16u;
157 typedef WImageView<ushort> WImageView_16u;
158 typedef WImageBuffer<ushort> WImageBuffer_16u;
160 typedef WImageC<ushort, 1> WImage1_16u;
161 typedef WImageViewC<ushort, 1> WImageView1_16u;
162 typedef WImageBufferC<ushort, 1> WImageBuffer1_16u;
164 typedef WImageC<ushort, 3> WImage3_16u;
165 typedef WImageViewC<ushort, 3> WImageView3_16u;
166 typedef WImageBufferC<ushort, 3> WImageBuffer3_16u;
182 virtual ~WImage() = 0;
186 const IplImage* Ipl()
const {
return image_; }
187 T* ImageData() {
return reinterpret_cast<T*
>(image_->imageData); }
188 const T* ImageData()
const {
189 return reinterpret_cast<const T*
>(image_->imageData);
192 int Width()
const {
return image_->width; }
193 int Height()
const {
return image_->height; }
196 int WidthStep()
const {
return image_->widthStep; }
198 int Channels()
const {
return image_->nChannels; }
199 int ChannelSize()
const {
return sizeof(
T); }
202 int PixelSize()
const {
return Channels() * ChannelSize(); }
209 inline const T* Row(
int r)
const {
210 return reinterpret_cast<T*
>(image_->imageData + r*image_->widthStep);
213 inline T* Row(
int r) {
214 return reinterpret_cast<T*
>(image_->imageData + r*image_->widthStep);
218 inline T* operator() (
int c,
int r) {
219 return reinterpret_cast<T*
>(image_->imageData + r*image_->widthStep) +
223 inline const T* operator() (
int c,
int r)
const {
224 return reinterpret_cast<T*
>(image_->imageData + r*image_->widthStep) +
229 void CopyFrom(
const WImage<T>&
src) {
cvCopy(src.Ipl(), image_); }
235 WImageView<T> View(
int c,
int r,
int width,
int height);
239 WImage(
const WImage&);
240 void operator=(
const WImage&);
259 template<
typename T,
int C>
260 class WImageC :
public WImage<T>
263 typedef typename WImage<T>::BaseType BaseType;
264 enum { kChannels = C };
266 explicit WImageC(
IplImage* img) : WImage<
T>(img) {
271 WImageViewC<T, C> View(
int c,
int r,
int width,
int height);
274 void CopyFrom(
const WImageC<T, C>& src) {
275 cvCopy(src.Ipl(), WImage<T>::image_);
280 virtual ~WImageC() = 0;
282 int Channels()
const {
return C; }
286 WImageC(
const WImageC&);
287 void operator=(
const WImageC&);
290 assert(!image || image->
depth == WImage<T>::Depth());
291 WImage<T>::SetIpl(image);
302 class WImageBuffer :
public WImage<T>
305 typedef typename WImage<T>::BaseType BaseType;
308 WImageBuffer() : WImage<
T>(0) {}
310 WImageBuffer(
int width,
int height,
int nchannels) : WImage<
T>(0) {
311 Allocate(width, height, nchannels);
316 explicit WImageBuffer(
IplImage* img) : WImage<
T>(img) {}
320 void Allocate(
int width,
int height,
int nchannels);
325 WImage<T>::SetIpl(img);
329 void CloneFrom(
const WImage<T>& src) {
330 Allocate(src.Width(), src.Height());
339 void ReleaseImage() {
340 if (WImage<T>::image_) {
343 WImage<T>::SetIpl(0);
347 bool IsNull()
const {
return WImage<T>::image_ == NULL; }
351 WImageBuffer(
const WImageBuffer&);
352 void operator=(
const WImageBuffer&);
357 template<
typename T,
int C>
358 class WImageBufferC :
public WImageC<T, C>
361 typedef typename WImage<T>::BaseType BaseType;
362 enum { kChannels = C };
365 WImageBufferC() : WImageC<
T, C>(0) {}
367 WImageBufferC(
int width,
int height) : WImageC<
T, C>(0) {
368 Allocate(width, height);
373 explicit WImageBufferC(
IplImage* img) : WImageC<
T, C>(img) {}
382 WImageC<T, C>::SetIpl(img);
386 void CloneFrom(
const WImageC<T, C>& src) {
387 Allocate(src.Width(), src.Height());
396 void ReleaseImage() {
397 if (WImage<T>::image_) {
400 WImageC<T, C>::SetIpl(0);
404 bool IsNull()
const {
return WImage<T>::image_ == NULL; }
408 WImageBufferC(
const WImageBufferC&);
409 void operator=(
const WImageBufferC&);
419 class WImageView :
public WImage<T>
422 typedef typename WImage<T>::BaseType BaseType;
426 WImageView(WImage<T>* img,
int c,
int r,
int width,
int height);
434 WImageView(
IplImage* img) : WImage<
T>(img) {}
437 WImageView(
const WImage<T>& img) : WImage<
T>(0) {
438 header_ = *(img.Ipl());
439 WImage<T>::SetIpl(&header_);
442 WImageView& operator=(
const WImage<T>& img) {
443 header_ = *(img.Ipl());
444 WImage<T>::SetIpl(&header_);
453 template<
typename T,
int C>
454 class WImageViewC :
public WImageC<T, C>
457 typedef typename WImage<T>::BaseType BaseType;
458 enum { kChannels = C };
463 virtual ~WImageViewC() {}
467 WImageViewC(WImageC<T, C>* img,
475 WImageViewC(
IplImage* img) : WImageC<
T, C>(img) {}
480 WImageViewC(
const WImageC<T, C>& img) : WImageC<
T, C>(0) {
481 header_ = *(img.Ipl());
482 WImageC<T, C>::SetIpl(&header_);
484 WImageViewC(
const WImageViewC<T, C>& img) : WImageC<
T, C>(0) {
485 header_ = *(img.Ipl());
486 WImageC<T, C>::SetIpl(&header_);
489 WImageViewC& operator=(
const WImageC<T, C>& img) {
490 header_ = *(img.Ipl());
491 WImageC<T, C>::SetIpl(&header_);
494 WImageViewC& operator=(
const WImageViewC<T, C>& img) {
495 header_ = *(img.Ipl());
496 WImageC<T, C>::SetIpl(&header_);
507 inline int WImage<uchar>::Depth()
const {
return IPL_DEPTH_8U; }
509 inline int WImage<schar>::Depth()
const {
return IPL_DEPTH_8S; }
511 inline int WImage<short>::Depth()
const {
return IPL_DEPTH_16S; }
513 inline int WImage<ushort>::Depth()
const {
return IPL_DEPTH_16U; }
515 inline int WImage<int>::Depth()
const {
return IPL_DEPTH_32S; }
517 inline int WImage<float>::Depth()
const {
return IPL_DEPTH_32F; }
519 inline int WImage<double>::Depth()
const {
return IPL_DEPTH_64F; }
524 template<
typename T>
inline WImage<T>::~WImage() {}
525 template<
typename T,
int C>
inline WImageC<T, C>::~WImageC() {}
531 inline void WImageBuffer<T>::Allocate(
int width,
int height,
int nchannels)
533 if (IsNull() || WImage<T>::Width() != width ||
534 WImage<T>::Height() != height || WImage<T>::Channels() != nchannels) {
537 WImage<T>::Depth(), nchannels);
541 template<
typename T,
int C>
542 inline void WImageBufferC<T, C>::Allocate(
int width,
int height)
544 if (IsNull() || WImage<T>::Width() != width || WImage<T>::Height() != height) {
554 WImageView<T>::WImageView(WImage<T>* img,
int c,
int r,
int width,
int height)
557 header_ = *(img->Ipl());
558 header_.imageData =
reinterpret_cast<char*
>((*img)(
c,
r));
559 header_.width =
width;
561 WImage<T>::SetIpl(&header_);
565 WImageView<T>::WImageView(
T*
data,
int width,
int height,
int nchannels,
int width_step)
569 header_.imageData =
reinterpret_cast<char*
>(
data);
570 if (width_step > 0) {
571 header_.widthStep = width_step;
573 WImage<T>::SetIpl(&header_);
576 template<
typename T,
int C>
577 WImageViewC<T, C>::WImageViewC(WImageC<T, C>* img,
int c,
int r,
int width,
int height)
580 header_ = *(img->Ipl());
581 header_.imageData =
reinterpret_cast<char*
>((*img)(
c,
r));
582 header_.width =
width;
584 WImageC<T, C>::SetIpl(&header_);
587 template<
typename T,
int C>
588 WImageViewC<T, C>::WImageViewC() : WImageC<
T, C>(0) {
590 header_.imageData =
reinterpret_cast<char*
>(0);
591 WImageC<T, C>::SetIpl(&header_);
594 template<
typename T,
int C>
595 WImageViewC<T, C>::WImageViewC(
T* data,
int width,
int height,
int width_step)
599 header_.imageData =
reinterpret_cast<char*
>(
data);
600 if (width_step > 0) {
601 header_.widthStep = width_step;
603 WImageC<T, C>::SetIpl(&header_);
608 WImageView<T> WImage<T>::View(
int c,
int r,
int width,
int height) {
612 template<
typename T,
int C>
613 WImageViewC<T, C> WImageC<T, C>::View(
int c,
int r,
int width,
int height) {
619 #endif // __cplusplus
621 #endif // _CV_WIMAGE_H_