OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimKakaduNitfReader.h
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: MIT
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Description:
8 //
9 // Class declaration for reader of NITF images with JPEG2000 (J2K) compressed
10 // blocks using kakadu library for decompression.
11 //
12 //----------------------------------------------------------------------------
13 // $Id$
14 
15 #ifndef ossimKakaduNitfReader_HEADER
16 #define ossimKakaduNitfReader_HEADER 1
17 
20 #include <kdu_compressed.h>
21 #include <iosfwd>
22 #include <fstream>
23 
24 // Forward declarations:
25 
26 namespace kdu_core
27 {
28  class kdu_thread_queue;
29 }
30 
31 namespace kdu_supp
32 {
33  class jp2_family_src;
34  class jp2_source;
35  struct kdu_channel_mapping;
36 }
37 
38 
39 
45  public ossimNitfTileSource, public kdu_core::kdu_compressed_source
46 {
47 public:
48 
50  enum
51  {
52  SIGNATURE_BOX_SIZE = 12
53  };
54 
57 
59  virtual ~ossimKakaduNitfReader();
60 
65  virtual ossimString getShortName() const;
66 
71  virtual ossimString getLongName() const;
72 
83 
94  virtual ossim_uint32 getNumberOfLines(ossim_uint32 resLevel = 0) const;
95 
106  virtual ossim_uint32 getNumberOfSamples(ossim_uint32 resLevel = 0) const;
107 
118  virtual void setMinPixelValue(ossim_uint32 band, const ossim_float64& pix);
119 
130  virtual void setMaxPixelValue(ossim_uint32 band, const ossim_float64& pix);
131 
142  virtual void setNullPixelValue(ossim_uint32 band, const ossim_float64& pix);
143 
145  virtual ossim_float64 getMinPixelValue(ossim_uint32 band=0)const;
146 
148  virtual ossim_float64 getMaxPixelValue(ossim_uint32 band=0)const;
149 
151  virtual ossim_float64 getNullPixelValue(ossim_uint32 band=0)const;
152 
153 protected:
154 
173  virtual bool getOverviewTile(ossim_uint32 resLevel,
174  ossimImageData* result);
175 
176 
189  virtual bool loadBlock(ossim_uint32 x, ossim_uint32 y);
190 
198  virtual bool parseFile();
199 
214  virtual bool allocate();
215 
225  virtual bool allocateBuffers();
226 
239  virtual bool canUncompress(const ossimNitfImageHeader* hdr) const;
240 
246  virtual void initializeReadMode();
247 
256  virtual bool scanForJpegBlockOffsets();
257 
263  virtual void initializeSwapBytesFlag();
264 
270  virtual void initializeCacheTileInterLeaveType();
271 
279  virtual ossim_int32 get_capabilities();
280 
291  virtual ossim_int32 read(kdu_core::kdu_byte *buf, ossim_int32 num_bytes);
292 
302  virtual bool seek(kdu_core::kdu_long offset);
303 
311  virtual kdu_core::kdu_long get_pos();
312 
313 private:
314 
319  bool isEntryJ2k() const;
320 
329  bool checkJp2Signature();
330 
334  void configureChannelMapping();
335 
336 
337 
339  std::ostream& dumpTiles(std::ostream& out);
340 
342 
343  kdu_supp::jp2_family_src* m_jp2FamilySrc;
344  kdu_supp::jp2_source* m_jp2Source;
345  kdu_supp::kdu_channel_mapping* m_channels;
346  kdu_core::kdu_codestream m_codestream;
347  kdu_core::kdu_thread_env* m_threadEnv;
348  kdu_core::kdu_thread_queue* m_openTileThreadQueue;
349 
352 
354  std::vector<ossimIrect> m_imageDims;
355 
365 
366 TYPE_DATA
367 };
368 
370 {
371  return ( KDU_SOURCE_CAP_SEEKABLE | KDU_SOURCE_CAP_SEQUENTIAL );
372 }
373 
374 inline ossim_int32 ossimKakaduNitfReader::read(kdu_core::kdu_byte *buf, ossim_int32 num_bytes)
375 {
376  theFileStr->read((char*)buf, num_bytes);
377  return theFileStr->gcount();
378 }
379 
380 inline bool ossimKakaduNitfReader::seek(kdu_core::kdu_long offset)
381 {
382  // If the last byte is read, the eofbit must be reset.
383  if ( theFileStr->eof() )
384  {
385  theFileStr->clear();
386  }
387 
388  //---
389  // All seeks are relative to the start of code stream.
390  //---
391  theFileStr->seekg(offset+m_startOfCodestreamOffset, ios_base::beg);
392  return theFileStr->good();
393 }
394 
395 inline kdu_core::kdu_long ossimKakaduNitfReader::get_pos()
396 {
397  //---
398  // Must subtract the SOC(start of code stream) from the real file position
399  // since positions are relative to SOC.
400  //---
401  return static_cast<kdu_core::kdu_long>(theFileStr->tellg() - m_startOfCodestreamOffset );
402 }
403 
404 #endif /* #ifndef ossimKakaduNitfReader_HEADER */
ossim_uint32 x
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
kdu_core::kdu_codestream m_codestream
virtual void initializeCacheTileInterLeaveType()
Initializes the data member "theCacheTileInterLeaveType".
virtual void setMaxPixelValue(ossim_uint32 band, const ossim_float64 &pix)
convenience method to set max pixel value.
virtual ossim_int32 read(kdu_core::kdu_byte *buf, ossim_int32 num_bytes)
Read method.
ossim_uint32 y
std::shared_ptr< ossim::istream > theFileStr
std::streamoff m_startOfCodestreamOffset
virtual ossim_uint32 getNumberOfLines(ossim_uint32 resLevel=0) const
Returns the number of lines in the image.
virtual void initializeSwapBytesFlag()
Initializes the data member "theSwapBytesFlag" from the current entry.
virtual ossim_uint32 getNumberOfSamples(ossim_uint32 resLevel=0) const
Returns the number of samples in the image.
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
virtual bool canUncompress(const ossimNitfImageHeader *hdr) const
virtual bool allocate()
Allocates everything for current entry.
virtual ossim_uint32 getNumberOfDecimationLevels() const
This returns the total number of decimation levels.
kdu_supp::jp2_source * m_jp2Source
double ossim_float64
ossim_float64 m_minSampleValue
min/max/null These are class attributes so that when behaving as an overview the owner or base image ...
virtual bool getOverviewTile(ossim_uint32 resLevel, ossimImageData *result)
Method to get an overview tile.
kdu_supp::kdu_channel_mapping * m_channels
#define TYPE_DATA
Definition: ossimRtti.h:339
unsigned int ossim_uint32
virtual ossimString getLongName() const
virtual void setMinPixelValue(ossim_uint32 band, const ossim_float64 &pix)
convenience method to set min pixel value.
virtual bool parseFile()
Parses "theImageFile" and initializes all nitf headers.
kdu_core::kdu_thread_queue * m_openTileThreadQueue
#define OSSIM_PLUGINS_DLL
kdu_supp::jp2_family_src * m_jp2FamilySrc
kdu_core::kdu_thread_env * m_threadEnv
virtual bool scanForJpegBlockOffsets()
scans the file storing in offsets in "theNitfBlockOffset" and block sizes in "theNitfBlockSize".
virtual bool seek(kdu_core::kdu_long offset)
Seek method.
virtual void setNullPixelValue(ossim_uint32 band, const ossim_float64 &pix)
convenience method to set null pixel value.
virtual double getMinPixelValue(ossim_uint32 band=0) const
Retuns the min pixel value.
ossimKakaduNitfReader class for reading NITF images with JPEG2000 (J2K) compressed blocks using kakad...
virtual void initializeReadMode()
Initializes the data member "theReadMode" from the current entry.
virtual ossim_int32 get_capabilities()
Gets kdu source capability.
virtual bool loadBlock(ossim_uint32 x, ossim_uint32 y)
Loads a block of data to theCacheTile.
virtual ossimString getShortName() const
virtual bool allocateBuffers()
Allocates buffers for current entry.
virtual kdu_core::kdu_long get_pos()
Get file position relative to the start of code stream offset.
std::vector< ossimIrect > m_imageDims
Image dimensions for each level.
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
int ossim_int32