core/vil1/vil1_image_impl.h

Go to the documentation of this file.
00001 // This is core/vil1/vil1_image_impl.h
00002 #ifndef vil1_image_impl_h_
00003 #define vil1_image_impl_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Representation of a generic image
00010 //
00011 // A vil1_image_impl is reference counted (see below).
00012 // For a smart-pointer version, use class vil1_image.
00013 //
00014 // \author AWF
00015 // \date 17 Feb 2000
00016 //
00017 // \verbatim
00018 //  Modifications
00019 //   000216 AWF Initial version.
00020 // \endverbatim
00021 
00022 #include <vcl_cassert.h>
00023 #include <vcl_string.h>
00024 
00025 class vil1_image;
00026 
00027 //: Describes the interpretation of component bits.
00028 // These make no statement about the number of
00029 // bits in the representation.
00030 enum vil1_component_format
00031 {
00032   VIL1_COMPONENT_FORMAT_UNKNOWN,
00033   VIL1_COMPONENT_FORMAT_UNSIGNED_INT,
00034   VIL1_COMPONENT_FORMAT_SIGNED_INT,
00035   VIL1_COMPONENT_FORMAT_IEEE_FLOAT,
00036   VIL1_COMPONENT_FORMAT_COMPLEX
00037 };
00038 
00039 inline
00040 const char* vil1_print(vil1_component_format f)
00041 {
00042   switch (f)
00043   {
00044     case VIL1_COMPONENT_FORMAT_UNKNOWN: return "VIL1_COMPONENT_FORMAT=UNKNOWN";
00045     case VIL1_COMPONENT_FORMAT_UNSIGNED_INT: return "VIL1_COMPONENT_FORMAT=unsigned int";
00046     case VIL1_COMPONENT_FORMAT_SIGNED_INT: return "VIL1_COMPONENT_FORMAT=signed int";
00047     case VIL1_COMPONENT_FORMAT_IEEE_FLOAT: return "VIL1_COMPONENT_FORMAT=IEEE float";
00048     case VIL1_COMPONENT_FORMAT_COMPLEX: return "VIL1_COMPONENT_FORMAT=complex";
00049     default: return "VIL1_COMPONENT_FORMAT_INVALID";
00050   }
00051 }
00052 
00053 //:
00054 // Representation of a generic image.
00055 //
00056 // \verbatim
00057 //                        Component   Cell     Pixel      get_section(plane=0,
00058 //                        example     example  example      x0=0,y0=0,w=1,h=1)
00059 //
00060 //  3 x W x H x 1
00061 //     +------+           r           r        r,g,b      r
00062 //     |r     |           g           g
00063 //   +-|      |           b           b
00064 //   |g|      |
00065 // +-| +------+
00066 // |b|      |
00067 // | +------+
00068 // |      |
00069 // +------+
00070 //
00071 // 1 x W x H x 3
00072 // +------------+         r           rgb       rgb       rgb
00073 // |rgb|rgb|    |
00074 // +---+---+    |
00075 // |            |
00076 // |            |
00077 // |            |
00078 // +------------+
00079 // \endverbatim
00080 //
00081 // document relationship between :
00082 // - Component: r, r
00083 // - Cell: r, rgb
00084 // - Pixel : spatial location,
00085 // - Plane
00086 
00087 class vil1_image_impl
00088 {
00089  public:
00090   //:
00091   // the reference count starts at 0.
00092   vil1_image_impl() : reference_count(0) {}
00093   virtual ~vil1_image_impl() {}
00094 
00095   //: Dimensions:  Planes x W x H x Components
00096   virtual int planes() const = 0;
00097   //: Dimensions:  Planes x W x H x Components
00098   virtual int width() const = 0;
00099   //: Dimensions:  Planes x W x H x Components
00100   virtual int height() const = 0;
00101   //: Dimensions:  Planes x W x H x Components
00102   virtual int components() const = 0;
00103 
00104   //: Number of bits per component.
00105   // Size (in bits) for the smallest entity of the image.
00106   virtual int bits_per_component() const = 0;
00107 
00108   //: Format.
00109   //  A standard RGB RGB RGB image has
00110   // - components() == 3
00111   // - bits_per_component() == 8
00112   // - component_format() == VIL1_COMPONENT_FORMAT_UNSIGNED_INT
00113   // Use vil1_print(fmt) to return a string description of the format fmt.
00114   virtual enum vil1_component_format component_format() const = 0;
00115 
00116   //: return the ith plane.
00117   virtual vil1_image get_plane(unsigned int p) const;
00118 
00119   //: Copy buffer of this to BUF.
00120   // The buffer is stored like this for each pixel:
00121   // component0(plane0,plane1,plane2,...),component1(plane0,plane1,plane2,...),...\n
00122   //   total size of BUF in bytes should be (bits_per_component * components + 7) / 8
00123   //   i.e. rounding to the next multiple of 8 bits (only correct if 1 byte = 8 bits)
00124   virtual bool get_section(void* buf, int x0, int y0, int width, int height) const = 0;
00125 
00126   //: Copy plane PLANE of BUF to this.
00127   // The buffer should look like this for each pixel:
00128   // component0(plane0,plane1,plane2,...),component1(plane0,plane1,plane2,...),...\n
00129   // total size of BUF in bytes should be (bits_per_component * components + 7) / 8
00130   // i.e. rounding to the next multiple of 8 bits (only correct if 1 byte = 8 bits)
00131   virtual bool put_section(void const* buf, int x0, int y0, int width, int height) = 0;
00132 
00133   //: Return a string describing the file format.
00134   // Only file images have a format, others return 0
00135   virtual char const* file_format() const { return 0; }
00136 
00137   //: Extra property information
00138   virtual bool get_property(char const* tag, void* property_value = 0) const;
00139   virtual bool set_property(char const* tag, void const* property_value = 0) const;
00140 
00141   //: Return the name of the class;
00142   virtual vcl_string is_a() const { return "vil1_image_impl"; }
00143 
00144   //: Return true if the name of the class matches the argument
00145   virtual bool is_class(vcl_string const& s) const { return s==is_a(); }
00146 
00147  private:
00148   friend class vil1_image;
00149   // You probably should not use a vil1_image_impl in a vbl_smart_ptr, so the
00150   // ref counting methods are called by the unusual up_ref() and down_ref().
00151   void up_ref() { ++reference_count; }
00152   void down_ref()
00153   {
00154     assert(reference_count>0);
00155     if (--reference_count<=0) delete this;
00156   }
00157   int reference_count;
00158 };
00159 
00160 #define VIL1_DISPATCH_AUX(VTYPE, uchar, Template, Args) \
00161 case VTYPE: Template<uchar > Args; break;
00162 
00163 #define VIL1_DISPATCH_IMAGE_OP(f, Template, Args) \
00164 switch (f) {\
00165  VIL1_DISPATCH_AUX(VIL1_UNSIGNED_8, vil1_unsigned_8);\
00166  VIL1_DISPATCH_AUX(VIL1_SIGNED_8, vil1_signed_8); \
00167  VIL1_DISPATCH_AUX(VIL1_FLOAT_32, vil1_float_32); \
00168 }
00169 
00170 #endif // vil1_image_impl_h_

Generated on Mon Mar 8 05:09:32 2010 for core/vil1 by  doxygen 1.5.1