00001
00002 #ifndef vil1_image_h_
00003 #define vil1_image_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012 #include <vcl_iosfwd.h>
00013 #include <vil1/vil1_image_impl.h>
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class vil1_image
00029 {
00030 VCL_SAFE_BOOL_DEFINE;
00031 public:
00032
00033 #define vil1_image_delegate(m, args, default) { return ptr ? ptr->m args : default; }
00034
00035
00036 int planes() const { vil1_image_delegate(planes, (), 0); }
00037
00038
00039 int width() const { vil1_image_delegate(width, (), 0); }
00040
00041
00042 int height() const { vil1_image_delegate(height, (), 0); }
00043
00044
00045 int components() const { vil1_image_delegate(components, (), 0); }
00046
00047
00048 int bits_per_component() const { vil1_image_delegate(bits_per_component, (), 0); }
00049
00050
00051 enum vil1_component_format component_format() const
00052 { vil1_image_delegate(component_format, (), VIL1_COMPONENT_FORMAT_UNKNOWN); }
00053
00054
00055 vil1_image get_plane(unsigned int p) const { vil1_image_delegate(get_plane, (p), vil1_image()); }
00056
00057
00058 bool get_section(void *buf, int x0, int y0, int wd, int ht) const
00059 { vil1_image_delegate(get_section, (buf, x0, y0, wd, ht), false); }
00060
00061
00062 bool put_section(void const *buf, int x0, int y0, int wd, int ht)
00063 { vil1_image_delegate(put_section, (buf, x0, y0, wd, ht), false); }
00064
00065
00066 bool get_property(char const *tag, void *property_value = 0) const
00067 { vil1_image_delegate(get_property, (tag, property_value), false); }
00068
00069
00070 bool set_property(char const *tag, void const *property_value = 0)
00071 { vil1_image_delegate(set_property, (tag, property_value), false); }
00072
00073
00074
00075 char const *file_format() const { vil1_image_delegate(file_format, (), "(null)"); }
00076
00077 #undef vil1_image_delegate
00078
00079
00080
00081 int rows() const { return height(); }
00082
00083 int cols() const { return width(); }
00084
00085
00086 int get_size_bytes() const;
00087
00088
00089 vcl_ostream& print(vcl_ostream&) const;
00090
00091
00092
00093 vil1_image(vil1_image_impl *p = 0) : ptr(p)
00094 {
00095 if (ptr)
00096 ptr->up_ref();
00097 }
00098
00099 vil1_image(vil1_image const& that) : ptr(that.ptr) {
00100 if (ptr)
00101 ptr->up_ref();
00102 }
00103
00104
00105 ~vil1_image() {
00106 if (ptr)
00107 ptr->down_ref();
00108 ptr = 0;
00109 }
00110
00111 vil1_image& operator=(vil1_image const &that) {
00112 if (ptr != that.ptr) {
00113 if (that.ptr)
00114 that.ptr->up_ref();
00115 if (ptr)
00116 ptr->down_ref();
00117 ptr = that.ptr;
00118 }
00119 return *this;
00120 }
00121
00122 vil1_image& operator=(vil1_image_impl *p) {
00123 if (ptr)
00124 ptr->down_ref();
00125 ptr = p;
00126 if (ptr)
00127 ptr->up_ref();
00128 return *this;
00129 }
00130
00131
00132 bool operator==(vil1_image const &that) const {
00133 return ptr == that.ptr;
00134 }
00135
00136
00137 bool operator< (vil1_image const &that) const {
00138 return ptr < that.ptr;
00139 }
00140
00141
00142 operator safe_bool () const
00143 { return (ptr != 0)? VCL_SAFE_BOOL_TRUE : 0; }
00144
00145
00146 bool operator!() const
00147 { return (ptr != 0)? false : true; }
00148
00149
00150 vil1_image_impl *impl() const {
00151 return ptr;
00152 }
00153
00154 protected:
00155 vil1_image_impl *ptr;
00156 };
00157
00158
00159 inline vcl_ostream& operator<<(vcl_ostream& s, vil1_image const& i)
00160 {
00161 return i.print(s);
00162 }
00163
00164 #endif // vil1_image_h_