core/vil/file_formats/vil_j2k_image.h

Go to the documentation of this file.
00001 //:
00002 // \file
00003 // vil_j2k: Written by Rob Radtke (rob@) and Harry Voorhees (hlv@) of
00004 // Stellar Science Ltd. Co. (stellarscience.com) for
00005 // Air Force Research Laboratory, 2005.
00006 
00007 #ifndef VIL_J2K_H
00008 #define VIL_J2K_H
00009 
00010 #include <vil/vil_image_resource.h>
00011 #include <vil/vil_file_format.h>
00012 
00013 class CNCSFile;
00014 class vil_stream;
00015 
00016 class vil_j2k_file_format : public vil_file_format
00017 {
00018  public:
00019   virtual char const *tag() const;
00020   virtual vil_image_resource_sptr make_input_image(vil_stream *vs);
00021   virtual vil_image_resource_sptr make_output_image(vil_stream* vs,
00022                                                     unsigned nx,
00023                                                     unsigned ny,
00024                                                     unsigned nplanes,
00025                                                     enum vil_pixel_format);
00026 };
00027 
00028 //:
00029 //  Class capable of reading JPEG2000 Part I files and ECW (ER Mapper's proprietary format)
00030 //  image files.  They can either be local or hosted on an Image Web Server.  Either way, you
00031 //  just pass in the file path or url (eg. "ecwp://www.earthetc.com/images/australia/Sydney.ecw")
00032 //  to the ctor.  The call get_copy_view() to get the image data that you want.  The class efficiently
00033 //  handles reading large images (Terrabytes) -- and can read image portions without loading the whole file
00034 //  into memory.
00035 // 
00036 //  Because the source image can be really big, it is possible (through the get_copy_view() API) to
00037 //  ask for more data than you can handle in memory -- or more than you download for the remote case.
00038 //  That is why the setMaxImageDimension() guard is in place.  You can set a max image dimension
00039 //  for both remote and local files (different values for each).  Then if you call get_copy_view()
00040 //  asking for an image that is too big, get_copy_view() will scale down the image to the max dimension
00041 //  you specified.  It does this silently -- perhaps we could/should change this?
00042 // 
00043 //  Writing not currently supported.
00044 // 
00045 //  Note that, in order to use this class, you need to use cmake to cofigure VXL to link against
00046 //  Er Mapper's freely available ECW JPEG 2000 SDK (http://ermapper.com/downloads/sdks.aspx#16).
00047 class vil_j2k_image : public vil_image_resource
00048 {
00049  public:
00050   //:
00051   //  \param filelOrUrl: can either be a local file (eg. /home/beavis/file1.jp2) or
00052   //  it can be a url to a file hosted on an Image Web Server (eg.
00053   //  ecwp://www.earthetc.com/images/australia/Sydney.ecw or
00054   //  ecwp://www.earthetc.com/images/usa/1metercalif.ecw
00055   vil_j2k_image( const vcl_string& fileOrUrl );
00056   //:
00057   //  Read a jpeg 2000 image from a stream containing either a raw j2k codestream
00058   //  or a jp2 file stream.  is' current position needs to be pointing at the beginning of
00059   //  one of these two things.  In other words, the beginning of the stream must contain one
00060   //  of the two signatures:
00061   //  - Hex( FF 4F )                                -- (codestream)
00062   //  - Hex( 00 00 00 0C 6A 50 20 20 0D 0A 87 0A )  -- jp2 file
00063   // 
00064   //  Note that some references state that jp2 files start with ( 00 00 00 0C 6A 50 1A 1A 0D 0A 87 0A )
00065   //  [note the 1A 1A difference].  I believe this was changed between the last draft and the final version
00066   //  of ISO/IEC 155444-1 (JPEG standard).  I have never seen a real jp2 file with this old signature (including
00067   //  the official jpeg conformance test files)
00068   // 
00069   //  also note: Don't use is while I'm trying to use it... it'll screw us both up.
00070   vil_j2k_image( vil_stream* is );
00071 
00072   ~vil_j2k_image();
00073   //: Dimensions:  planes x width x height x components
00074   virtual unsigned nplanes() const;
00075   virtual unsigned ni() const;
00076   virtual unsigned nj() const;
00077   virtual enum vil_pixel_format pixel_format() const;
00078 
00079   virtual bool get_property(char const* /* tag */, void* /* property_value */ = 0) const
00080   { return false; }
00081   virtual bool put_view(const vil_image_view_base& /* im */, unsigned /* i0 */,
00082                         unsigned /* j0 */ )
00083   { return false; }
00084   //: Create a read/write view of a copy of this data.
00085   // \return 0 if unable to get view of correct size.
00086   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00087                                                  unsigned j0, unsigned nj) const;
00088 
00089   virtual vil_image_view_base_sptr get_copy_view_decimated(unsigned i0, unsigned ni,
00090                                                            unsigned j0, unsigned nj,
00091                                                            double i_factor, double j_factor) const;
00092   virtual vil_image_view_base_sptr 
00093   get_copy_view_decimated_by_size(unsigned i0, unsigned ni,
00094                                   unsigned j0, unsigned nj,
00095                                   unsigned int output_width, 
00096                                   unsigned int output_height) const;
00097 
00098 
00099   vil_image_view_base_sptr  get_copy_view () const
00100   { return get_copy_view( 0, ni(), 0, nj() ); }
00101 
00102   //:
00103   //  Call this after construction to see if you can get valid data from me.
00104   //  If this returns false, then this image is of no use to you
00105   bool is_valid() const { return mFileResource != 0; }
00106 
00107   //:
00108   //  When calling get_copy_view(), the function will scale down the output image_view
00109   //  so that neither dimension (x or y) is greater than widthOrHeight.  This feature
00110   //  is here to protect you in the case that your code asks for an excessively large
00111   //  image that will crash your program.  You can turn this checking off with \sa unsetMaxImageDimension()
00112   //  By default, this value is set to 5000.
00113   void setMaxImageDimension( unsigned int widthOrHeight, bool remote = false );
00114   //:
00115   //  Call this if you don't want get_copy_view() to do size checking.
00116   //  Be warned that jpeg 2000 codestreams can be really big, so you could
00117   //  cause a program crash.
00118   void unsetMaxImageDimension( bool remote = false );
00119 
00120   //:
00121   //  Static function that can be used to decode a JPEG2000 codestream
00122   //  or file (jp2 file).  The stream must start at vs' current position.
00123   static vil_image_view_base_sptr s_decode_jpeg_2000( vil_stream* vs,
00124                                                       unsigned i0, unsigned ni,
00125                                                       unsigned j0, unsigned nj,
00126                                                       double i_factor, double j_factor );
00127   static vil_image_view_base_sptr 
00128   s_decode_jpeg_2000_by_size( vil_stream* vs,
00129                               unsigned i0, unsigned ni,
00130                               unsigned j0, unsigned nj,
00131                               unsigned int output_width, 
00132                               unsigned int output_height );
00133 
00134  protected:
00135   CNCSFile* mFileResource;
00136   //:
00137   //  \sa setMaxImageDimension and \sa unsetMaxImageDimension
00138   // 
00139   //  if this equals vcl_numeric_limits<unsigned int>::max(), then this feature is turned off
00140   //  Of course I'm ignored if mRemoteFile is true
00141   unsigned int mMaxLocalDimension;
00142   //:
00143   //  Same as \sa mMaxLocalDimension but applies to remote files.
00144   //  This is typically a smaller number because of the speed concerns of downloading
00145   //  a very largeimage
00146   unsigned int mMaxRemoteDimension;
00147   ///file is remote
00148   bool mRemoteFile;
00149 };
00150 
00151 #endif // VIL_J2K_H

Generated on Sat Nov 22 05:07:51 2008 for core/vil by  doxygen 1.5.1