core/vil/file_formats/NCSJPCVilIOStream.h
Go to the documentation of this file.
00001 // vil_j2k: Written by Rob Radtke (rob@) and Harry Voorhees (hlv@) of
00002 // Stellar Science Ltd. Co. (stellarscience.com) for 
00003 // Air Force Research Laboratory, 2005.
00004 // Do not remove the following notice
00005 // Modifications approved for public release, distribution unlimited 
00006 // DISTAR Case 14074
00007 //
00008 #ifndef NCSJPCVILIOSTREAM_H
00009 #define NCSJPCVILIOSTREAM_H
00010 
00011 #include <NCSJPCIOStream.h>
00012 
00013 #include <vil/vil_stream.h>
00014 
00015 /**
00016   * Wrapper class that allows you to effectively "convert" a vil_stream
00017   * to a CNCSJPCIOStream.  This class is used by vil_j2k_image to read JPEG 2000
00018   * imagery.  A couple of notes:
00019   * 1) This stream's home position (ie. the place it goes when you call Seek(0,START),
00020   * is the current position of the stream that is passed to Open() at the time of that call.
00021   * \sa Open() for more info.
00022   *
00023   * Known Issues:
00024   * 1) As of 2/24/05, the writing capability of this class has not been tested.  In
00025   * theory it should work just fine though.
00026   *
00027   * 2) It is necessary to provide a unique string name to an open CNCSJPCIO
00028   *  stream. The original code always used the same name "VIL". The result is
00029   * that all resources access the same J2K data, since the ecw library 
00030   * accesses streams by name. Only one stream with the same name can exist, 
00031   * which is the first one opened with that name. The fix is to provide a 
00032   * unique name, based on a static unsigned short integer that is maintained 
00033   * and appended to the stream name prefix. JLM April 13, 2009
00034   */
00035 class CNCSJPCVilIOStream : public CNCSJPCIOStream
00036 {
00037 public:
00038   CNCSJPCVilIOStream();
00039   ~CNCSJPCVilIOStream();
00040 
00041   /**
00042     * Pass me the stream you want me to wrap.  stream->tell() at the time
00043     * of this function call will become my home position.  see \sa mHomePos for
00044     * more details on what that means.
00045     */
00046   virtual CNCSError Open( vil_stream* stream, bool bWrite = false );
00047 
00048   virtual CNCSError Close();
00049 
00050   virtual bool NCS_FASTCALL Seek ();
00051 
00052   virtual bool NCS_FASTCALL Seek (INT64 offset, Origin origin = CURRENT);
00053 
00054   virtual INT64 NCS_FASTCALL Tell(); 
00055 
00056   virtual INT64 NCS_FASTCALL Size();
00057 
00058   virtual bool NCS_FASTCALL Read (void* buffer, UINT32 count);
00059 
00060   virtual bool NCS_FASTCALL Write (void* buffer, UINT32 count);
00061 
00062 protected:
00063   /**
00064     * The stream I get all my data from (and write too)
00065     */
00066   vil_stream* mVilStream;
00067   /**
00068     * This position is my home position (ie. mVilStream->tell() when it was
00069     * passed into me).  All Seek()'s with an origin of START will be relative 
00070     * to me.  Tell() is the position relative to this position etc.
00071     */
00072   vil_streampos mHomePos;
00073   
00074   static unsigned short mId; /*unique id */
00075 };
00076 
00077 #endif //NCSJPCVILIOSTREAM_H