core/vidl/vidl_istream_image_resource.h
Go to the documentation of this file.
00001 // This is core/vidl/vidl_istream_image_resource.h
00002 #ifndef vidl_istream_image_resource_h_
00003 #define vidl_istream_image_resource_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Wraps an input stream and frame number as a vil_image_resource
00010 // \author Matt Leotta (mleotta@lems.brown.edu)
00011 // \date Mar 23, 2007
00012 //
00013 //\verbatim
00014 //  Modifications
00015 //\endverbatim
00016 
00017 #include <vil/vil_image_resource.h>
00018 #include <vil/vil_pixel_format.h>
00019 #include <vidl/vidl_istream_sptr.h>
00020 
00021 
00022 //: A vil_image_resource to a frame of a vidl_istream
00023 // With this class you can create image resources to several frames
00024 // of an open vidl istream.  When get_view is called the stream is
00025 // seeked to the relevant frame number and the frame is decoded and
00026 // converted to an image view.  The stream must be seekable unless
00027 // views are requested in sequential order.  The stream is closed
00028 // when all image resources using it are destroyed.
00029 class vidl_istream_image_resource : public vil_image_resource
00030 {
00031   vidl_istream_sptr istream_;
00032   int frame_number_;
00033   unsigned int ni_;
00034   unsigned int nj_;
00035   unsigned int np_;
00036   vil_pixel_format format_;
00037 
00038  public:
00039 
00040   vidl_istream_image_resource(const vidl_istream_sptr& stream, int frame,
00041                               unsigned int ni, unsigned int nj, unsigned int np,
00042                               vil_pixel_format format);
00043   vidl_istream_image_resource(const vidl_istream_sptr& stream, int frame);
00044   vidl_istream_image_resource(const vidl_istream_sptr& stream);
00045   ~vidl_istream_image_resource();
00046 
00047   //: Dimensions
00048   virtual unsigned nplanes() const;
00049   virtual unsigned ni() const;
00050   virtual unsigned nj() const;
00051 
00052   virtual enum vil_pixel_format pixel_format() const;
00053 
00054   //: Create a read/write view of a copy of this data.
00055   // \return 0 if unable to get view of correct size.
00056   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00057                                                  unsigned j0, unsigned nj) const;
00058 
00059   //: Put the data in this view back into the image source.
00060   virtual bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0);
00061 
00062   bool get_property(char const *tag, void *prop = 0) const;
00063 
00064  private:
00065   //: try to find the image format and size from the current frame
00066   bool find_image_properties();
00067 
00068   //: create an empty image of the appropriate type and size
00069   vil_image_view_base_sptr create_empty_view() const;
00070 };
00071 
00072 #endif // vidl_istream_image_resource_h_