Go to the documentation of this file.00001
00002 #ifndef vidl_frame_h_
00003 #define vidl_frame_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "vidl_pixel_format.h"
00021 #include <vil/vil_memory_chunk.h>
00022 #include <vil/vil_image_view_base.h>
00023
00024
00025
00026 class vidl_frame
00027 {
00028 public:
00029
00030 virtual ~vidl_frame() {}
00031
00032
00033 virtual void invalidate() { ni_=0; nj_=0; format_=VIDL_PIXEL_FORMAT_UNKNOWN; }
00034
00035
00036 virtual void * data() = 0;
00037 virtual const void * data() const = 0;
00038
00039
00040 virtual unsigned long size() const = 0;
00041
00042
00043 unsigned ni() const { return ni_; }
00044
00045
00046 unsigned nj() const { return nj_; }
00047
00048
00049 vidl_pixel_format pixel_format() const { return format_; }
00050
00051 protected:
00052
00053 vidl_frame():
00054 ni_(0), nj_(0), format_(VIDL_PIXEL_FORMAT_UNKNOWN), ref_count_(0) {}
00055
00056
00057 vidl_frame(unsigned ni, unsigned nj, vidl_pixel_format fmt):
00058 ni_(ni), nj_(nj), format_(fmt), ref_count_(0) {}
00059
00060
00061 unsigned ni_;
00062
00063 unsigned nj_;
00064
00065 vidl_pixel_format format_;
00066
00067
00068
00069 public:
00070
00071
00072 void ref() { ref_count_++; }
00073
00074
00075 void unref();
00076
00077
00078 int ref_count() const { return ref_count_; }
00079
00080 private:
00081 int ref_count_;
00082 };
00083
00084
00085
00086 class vidl_shared_frame : public vidl_frame
00087 {
00088 public:
00089
00090 vidl_shared_frame():
00091 vidl_frame(), buffer_(NULL) {}
00092
00093
00094 vidl_shared_frame(void * buffer, unsigned ni, unsigned nj, vidl_pixel_format fmt):
00095 vidl_frame(ni,nj,fmt), buffer_(buffer) {}
00096
00097
00098 virtual ~vidl_shared_frame() {}
00099
00100
00101 virtual void invalidate() { buffer_ = 0; vidl_frame::invalidate(); }
00102
00103
00104 virtual void * data() { return buffer_; }
00105 virtual const void * data() const { return buffer_; }
00106
00107
00108 virtual unsigned long size() const { return vidl_pixel_format_buffer_size(ni_,nj_,format_); }
00109
00110 private:
00111 void * buffer_;
00112 };
00113
00114
00115
00116
00117 class vidl_memory_chunk_frame : public vidl_frame
00118 {
00119 public:
00120
00121 vidl_memory_chunk_frame() : memory_(NULL) {}
00122
00123
00124 vidl_memory_chunk_frame(unsigned ni, unsigned nj, vidl_pixel_format fmt,
00125 const vil_memory_chunk_sptr& memory):
00126 vidl_frame(ni,nj,fmt), memory_(memory) {}
00127
00128
00129
00130
00131 vidl_memory_chunk_frame(const vil_image_view_base& image,
00132 vidl_pixel_format fmt = VIDL_PIXEL_FORMAT_UNKNOWN);
00133
00134
00135
00136 inline const vil_memory_chunk_sptr& memory_chunk() const { return memory_; }
00137
00138
00139 virtual ~vidl_memory_chunk_frame() {}
00140
00141
00142 virtual void invalidate() { memory_ = NULL; vidl_frame::invalidate(); }
00143
00144
00145 virtual void * data () { return memory_?memory_->data():NULL; }
00146 virtual const void * data () const { return memory_?memory_->data():NULL; }
00147
00148
00149 virtual unsigned long size() const { return (unsigned long)(memory_?memory_->size():0L); }
00150
00151 private:
00152 vil_memory_chunk_sptr memory_;
00153 };
00154
00155
00156 #endif // vidl_frame_h_