00001 // This is core/vil/vil_image_resource.h 00002 #ifndef vil_image_resource_h_ 00003 #define vil_image_resource_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief Representation of a generic image source or destination. 00010 // 00011 // \author Ian Scott 00012 // \date 20 Sep 2002 00013 00014 #include <vil/vil_image_view_base.h> 00015 #include <vcl_cassert.h> 00016 #include <vil/vil_smart_ptr.h> 00017 #include <vil/vil_pixel_format.h> 00018 00019 #include <vil/vil_image_resource_sptr.h> 00020 00021 //: 00022 // Abstract representation of an image source or image destination. 00023 // Most references to vil_image_resource objects should usually be done 00024 // through smart pointers - vil_image_resource_sptr; 00025 // 00026 // All image data is presumed to be in planes, not components. This 00027 // does not say whether the data is stored on disk or in memory 00028 // as RGBRGBRGB.. or RRR..GGG..BBB.., just that the interface will 00029 // always tell you that it has a multi-plane single-component view. 00030 class vil_image_resource 00031 { 00032 public: 00033 vil_image_resource(); 00034 virtual ~vil_image_resource(); 00035 00036 //: Dimensions: Planes x ni x nj. 00037 // This concept is treated as a synonym to components. 00038 virtual unsigned nplanes() const = 0; 00039 //: Dimensions: Planes x ni x nj. 00040 // The number of pixels in each row. 00041 virtual unsigned ni() const = 0; 00042 //: Dimensions: Planes x ni x nj. 00043 // The number of pixels in each column. 00044 virtual unsigned nj() const = 0; 00045 00046 //: Pixel Format. 00047 // A standard RGB RGB RGB of chars image has 00048 // pixel_format() == VIL_PIXEL_FORMAT_BYTE 00049 virtual enum vil_pixel_format pixel_format() const = 0; 00050 00051 //: Create a read/write view of the data. 00052 // Modifying this view might modify the actual data. 00053 // If you want to modify this data in place, call put_view after you done, and 00054 // it should work efficiently. This function will always return a 00055 // multi-plane scalar-pixel view of the data. 00056 // \return 0 if unable to get view of correct size, or if resource is write-only. 00057 // 00058 // If you want to fill an existing view (e.g. a window onto some other image), 00059 // then use 00060 // \verbatim 00061 // vil_reformat(data->get_view(..), window); 00062 //\endverbatim 00063 virtual vil_image_view_base_sptr get_view(unsigned i0, unsigned n_i, 00064 unsigned j0, unsigned n_j) const 00065 { return get_copy_view (i0, n_i, j0, n_j); } 00066 00067 //: Create a read/write view of all the data. 00068 vil_image_view_base_sptr get_view() const 00069 { return get_view (0, ni(), 0, nj()); } 00070 00071 //: Create a read/write view of a copy of this data. 00072 // This function will always return a 00073 // multi-plane scalar-pixel view of the data. 00074 // \return 0 if unable to get view of correct size, or if resource is write-only. 00075 virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned n_i, 00076 unsigned j0, unsigned n_j) const = 0; 00077 00078 //: Create a read/write view of a copy of all the data. 00079 vil_image_view_base_sptr get_copy_view() const 00080 { return get_copy_view (0, ni(), 0, nj()); } 00081 00082 //: Put the data in this view back into the image source. 00083 // The view must be of scalar components. Assign your 00084 // view to a scalar-component view if this is not the case. 00085 // \return false if failed, because e.g. resource is read-only, 00086 // format of view is not correct (if it is a compound pixel type, try 00087 // assigning it to a multi-plane scalar pixel view.) 00088 virtual bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0) = 0; 00089 00090 //: Put the data in this view back into the image source at the origin 00091 bool put_view(const vil_image_view_base& im) 00092 { return put_view(im, 0, 0); } 00093 00094 //: Check that a view will fit into the data at the given offset. 00095 // This includes checking that the pixel type is scalar. 00096 virtual bool view_fits(const vil_image_view_base& im, unsigned i0, unsigned j0); 00097 00098 //: Return a string describing the file format. 00099 // Only file images have a format, others return 0 00100 virtual char const* file_format() const { return 0; } 00101 00102 //: Extra property information 00103 virtual bool get_property(char const* tag, void* property_value = 0) const =0; 00104 00105 protected: 00106 // You probably should not use a vil_image_resource in a vbl_smart_ptr, so the 00107 // ref functions are private 00108 friend class vil_smart_ptr<vil_image_resource>; 00109 void ref() { ++reference_count_; } 00110 void unref() { 00111 assert(reference_count_>0); 00112 if (--reference_count_<=0) delete this;} 00113 int reference_count_; 00114 }; 00115 00116 #endif // vil_image_resource_h_
1.4.4