core/vil/file_formats/vil_openjpeg.h
Go to the documentation of this file.
00001 //==========
00002 // Kitware (c) 2010
00003 //
00004 // Restrictions applicable to use by the US Government:
00005 //
00006 // UNLIMITED RIGHTS
00007 //
00008 // Restrictions applicable for all other users:
00009 //
00010 // This software and all information and expression are the property of Kitware, Inc. All Rights Reserved.
00011 //==========
00012 //:
00013 // \file
00014 // \brief Image I/O for JPEG2000 imagery using OpenJPEG
00015 // \author Chuck Atkins
00016 
00017 #ifndef vil_openjpeg_h_
00018 #define vil_openjpeg_h_
00019 
00020 #include <vil/vil_fwd.h>
00021 #include <vil/vil_file_format.h>
00022 #include <vil/vil_image_resource.h>
00023 
00024 //: OpenJPEG Codec
00025 enum vil_openjpeg_format
00026 {
00027   VIL_OPENJPEG_JP2 = 1,
00028   VIL_OPENJPEG_JPT = 2,
00029   VIL_OPENJPEG_J2K = 3
00030 };
00031 
00032 
00033 //: Derived class for JPEG2000 imagery using OpenJPEG
00034 class vil_openjpeg_file_format
00035 {
00036  public:
00037   vil_image_resource_sptr make_input_image(vil_stream* vs,
00038                                            vil_openjpeg_format opjfmt);
00039   vil_image_resource_sptr make_output_image(vil_stream* vs,
00040                                             unsigned int ni,
00041                                             unsigned int nj,
00042                                             unsigned int nplanes,
00043                                             vil_pixel_format format,
00044                                             vil_openjpeg_format opjfmt);
00045 };
00046 
00047 class vil_openjpeg_jp2_file_format : public vil_file_format,
00048                                      public vil_openjpeg_file_format
00049 {
00050  public:
00051   virtual const char * tag() const { return "jp2"; }
00052 
00053   virtual vil_image_resource_sptr make_input_image(vil_stream* vs)
00054   {
00055     return static_cast<vil_openjpeg_file_format*>(this)->
00056            make_input_image(vs, VIL_OPENJPEG_JP2);
00057   }
00058 
00059   virtual vil_image_resource_sptr make_output_image(vil_stream* vs,
00060                                                     unsigned int ni,
00061                                                     unsigned int nj,
00062                                                     unsigned int nplanes,
00063                                                     vil_pixel_format format)
00064   {
00065     return static_cast<vil_openjpeg_file_format*>(this)->
00066            make_output_image(vs, ni, nj, nplanes, format, VIL_OPENJPEG_JP2);
00067   }
00068 };
00069 
00070 #if 0
00071 class vil_openjpeg_jpt_file_format : public vil_file_format,
00072                                      public vil_openjpeg_file_format
00073 {
00074  public:
00075   virtual const char * tag() const { return "jpt"; }
00076 
00077   virtual vil_image_resource_sptr make_input_image(vil_stream* vs)
00078   {
00079     return static_cast<vil_openjpeg_file_format*>(this)->
00080            make_input_image(vs, VIL_OPENJPEG_JPT);
00081   }
00082 
00083   virtual vil_image_resource_sptr make_output_image(vil_stream* vs,
00084                                                     unsigned int ni,
00085                                                     unsigned int nj,
00086                                                     unsigned int nplanes,
00087                                                     vil_pixel_format format)
00088   {
00089     return static_cast<vil_openjpeg_file_format*>(this)->
00090            make_output_image(vs, ni, nj, nplanes, format, VIL_OPENJPEG_JPT);
00091   }
00092 };
00093 #endif // 0
00094 
00095 class vil_openjpeg_j2k_file_format : public vil_file_format,
00096                                      public vil_openjpeg_file_format
00097 {
00098  public:
00099   virtual const char * tag() const { return "j2k"; }
00100 
00101   virtual vil_image_resource_sptr make_input_image(vil_stream* vs)
00102   {
00103     return static_cast<vil_openjpeg_file_format*>(this)->
00104            make_input_image(vs, VIL_OPENJPEG_J2K);
00105   }
00106 
00107   virtual vil_image_resource_sptr make_output_image(vil_stream* vs,
00108                                                     unsigned int ni,
00109                                                     unsigned int nj,
00110                                                     unsigned int nplanes,
00111                                                     vil_pixel_format format)
00112   {
00113     return static_cast<vil_openjpeg_file_format*>(this)->
00114            make_output_image(vs, ni, nj, nplanes, format, VIL_OPENJPEG_J2K);
00115   }
00116 };
00117 
00118 struct vil_openjpeg_image_impl;
00119 
00120 //: Derived image resource for JPEG2000 imagery using OpenJPEG
00121 class vil_openjpeg_image : public vil_image_resource
00122 {
00123  public:
00124   vil_openjpeg_image (vil_stream* is,
00125                       unsigned int ni, unsigned int nj, unsigned int nplanes,
00126                       vil_pixel_format format, vil_openjpeg_format opjfmt);
00127   vil_openjpeg_image(vil_stream* is, vil_openjpeg_format opjfmt);
00128   ~vil_openjpeg_image(void);
00129 
00130   bool is_valid(void) const;
00131 
00132   // Inherit the documentation from vil_image_resource
00133 
00134   virtual unsigned int nplanes() const;
00135   virtual unsigned int ni() const;
00136   virtual unsigned int nj() const;
00137   virtual enum vil_pixel_format pixel_format() const;
00138   virtual const char * file_format();
00139 
00140   //: Reductions.
00141   // An image may supply lower resolutions.
00142   // This will return the number of reductions available.
00143   // 0 means only the full size image is available.
00144   virtual unsigned int nreductions() const;
00145 
00146   virtual vil_image_view_base_sptr get_copy_view(
00147     unsigned int i0, unsigned int ni, unsigned int j0, unsigned int nj) const;
00148 
00149   //: Create a read/write view of a copy of this data.
00150   // This is similar to get_copy_view, except that a reduction level may
00151   // be specified. On success, the returned data is reduced by 2^reduction.
00152   // Coordinates should be specified relative to the full-sized image.
00153   // \return 0 if the reduction is not available, or for any reason that
00154   // get_copy_view would return 0.
00155   virtual vil_image_view_base_sptr get_copy_view_reduced(
00156     unsigned i0, unsigned ni, unsigned j0, unsigned nj,
00157     unsigned reduction) const;
00158 
00159   virtual bool put_view(const vil_image_view_base& im,
00160                         unsigned int i0, unsigned int j0);
00161 
00162   virtual bool get_property(char const* tag, void* property_value = 0) const;
00163 
00164  private:
00165   bool validate_format();
00166 
00167   int maxbpp(void) const;
00168 
00169   template<typename PIXEL_TYPE>
00170   vil_image_view_base_sptr opj2vil(
00171     void *opj_view,
00172     unsigned int i0, unsigned int ni, unsigned int j0, unsigned int nji) const;
00173 //    vil_memory_chunk_sptr image_mem_ptr);
00174 
00175   vil_openjpeg_image_impl *impl_;
00176 };
00177 
00178 #endif