37 #include <kdu_sample_processing.h> 38 #include <kdu_region_decompressor.h> 45 #ifdef OSSIM_ID_ENABLED 46 static const char OSSIM_ID[] =
"$Id";
53 "ossimKakaduNitfReader",
58 m_startOfCodestreamOffset(0),
64 m_openTileThreadQueue(0),
65 m_sourcePrecisionBits(0),
72 kdu_customize_warnings(&pretty_cout);
73 kdu_customize_errors(&pretty_cerr);
120 catch ( kdu_core::kdu_exception exc )
128 e <<
"ossimKakaduNitfReader::~ossimKakaduNitfReader\n" 129 <<
"Caught exception from kdu_region_decompressor: " << exc <<
"\n";
132 catch ( std::bad_alloc& )
136 m_threadEnv->handle_exception(KDU_MEMORY_EXCEPTION);
139 "Caught exception from kdu_region_decompressor: std::bad_alloc";
145 "Caught unhandled exception from kdu_region_decompressor";
385 cout <<
"ovr get tile res level: " << resLevel
387 <<
"\nlevel: " << level
400 static_cast<int>(level),
408 static_cast<int>(level),
417 << __FILE__ <<
":" << __LINE__ <<
" caught exception\n" 418 << e.
what() << std::endl;
434 << __FILE__ <<
" " << __LINE__
435 <<
"Range error." << std::endl;
474 << __FILE__ <<
":" << __LINE__
475 <<
"\nossimKakaduNitfReader::loadBlock failed!" 490 static const char MODULE[] =
"ossimKakaduNitfReader::parseFile";
522 << MODULE <<
" exit status = " << (result?
"true\n":
"false\n");
530 static const char MODULE[] =
"ossimKakaduNitfReader::allocate";
629 if ( colour.exists() )
632 <<
"jp2 color space: " << colour.get_space() << endl;
669 std::vector<ossimIrect> tileDims;
675 << __FILE__ <<
" " << __LINE__ <<
" " << MODULE
676 <<
"Could not ascertain dimensions!" << std::endl;
680 kdu_dims region_of_interest;
681 region_of_interest.pos.x = 0;
682 region_of_interest.pos.y = 0;
683 region_of_interest.size.x =
m_imageDims[0].width();
684 region_of_interest.size.y =
m_imageDims[0].height();
692 KDU_WANT_OUTPUT_COMPONENTS);
700 <<
"m_codestream.get_num_components(false): " 702 <<
"\nm_codestream.get_num_components(true): " 704 <<
"\nm_codestream.get_bit_depth(0, true): " 706 <<
"\nm_codestream.get_signed(0, true): " 708 <<
"\nm_codestream.get_min_dwt_levels(): " 710 <<
"\ntheNumberOfInputBands: " 712 <<
"\ntheNumberOfOutputBands: " 714 <<
"\nthreads: " << threads
716 for ( std::vector<ossimIrect>::size_type i = 0; i <
m_imageDims.size(); ++i )
719 <<
"m_imageDims[" << i <<
"]: " <<
m_imageDims[i] <<
"\n";
735 << MODULE <<
" Caught exception: " << e.
what() << std::endl;
744 << MODULE <<
" Caught unknown exception!" << std::endl;
755 << MODULE <<
" exit status = " << (result?
"true":
"false\n")
884 if ( (markerField[0] == 0xff) && (markerField[1] == 0x4f) )
902 if (static_cast<ossim_uint8>(c) == 0xff)
906 if (static_cast<ossim_uint8>(c) == 0x4f)
918 if ( (result ==
true) && traceDump() )
982 theFileStr->seekg(startOfDataPos, ios_base::beg);
986 {0x00,0x00,0x00,0x0c,0x6a,0x50,0x20,0x20,0x0d,0x0a,0x87,0x0a};
995 if (box[i] != J2K_SIGNATURE_BOX[i])
1004 theFileStr->seekg(startOfDataPos, ios_base::beg);
1012 bool result =
false;
1064 std::streampos currentPos =
theFileStr->tellg();
1079 bool foundSot =
false;
1080 if ( (markerField[0] == 0xff) && (markerField[1] == 0x4f) )
1084 if ( (markerField[0] == 0xff) && (markerField[1] == 0x51) )
1095 if (static_cast<ossim_uint8>(c) == 0xff)
1099 out <<
"marker: 0xff" << hex << (
ossim_uint16)c << dec << endl;
1101 if (static_cast<ossim_uint8>(c) == 0x52)
1103 out <<
"\nFound COD...\n\n" << endl;
1109 else if (static_cast<ossim_uint8>(c) == 0x55)
1111 out <<
"\nFound TLM...\n\n" << endl;
1116 else if (static_cast<ossim_uint8>(c) == 0x90)
1133 out <<
"sot pos: " << pos << endl;
1137 sotRecord.
print(out);
virtual bool scanForJpegBlockOffsets()
This method simply checks for Start of Codestream (SOC) marker as the Kakadu library handles finding ...
virtual ossim_uint32 getNumberOfDecimationLevels() const
Returns the number of decimation levels.
ossim_float64 m_maxSampleValue
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.
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
virtual void setNullPixelValue(ossim_uint32 band, const ossim_float64 &pix)
convenience method to set null pixel value.
virtual ossim_uint32 getNumberOfBands() const
virtual void setMaxPixelValue(ossim_uint32 band, const ossim_float64 &pix)
convenience method to set max pixel value.
virtual void setImageRectangle(const ossimIrect &rect)
ossim_uint32 theNumberOfInputBands
void parseStream(ossim::istream &in)
Parse method.
virtual void initializeReadMode()
Initializes the data member "theReadMode" from the current entry.
virtual ~ossimKakaduNitfReader()
virtural destructor
std::shared_ptr< ossim::istream > theFileStr
virtual ossimString getShortName() const
Returns short name.
std::ostream & print(std::ostream &out, const std::string &prefix=std::string()) const
print method that outputs a key/value type format adding prefix to keys.
virtual ossim_uint32 getNumberOfLines(ossim_uint32 resLevel=0) const =0
Pure virtual, derived classes must implement.
double nan()
Method to return ieee floating point double precision NAN.
std::streamoff m_startOfCodestreamOffset
This code was derived from https://gist.github.com/mshockwave.
void parseStream(std::istream &in)
Parse method.
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.
ossim_uint32 toUInt32() const
unsigned short ossim_uint16
virtual ossim_uint32 getNumberOfSamples(ossim_uint32 resLevel=0) const
Returns the number of samples in the image.
ossimInterleaveType theCacheTileInterLeaveType
virtual ossim_float64 getNullPixelValue(ossim_uint32 band=0) const
IMODE = B, IC = C3 "JPEG compressed blocks".
virtual bool canUncompress(const ossimNitfImageHeader *hdr) const
void configureChannelMapping()
Initializes m_channels to be used with copyRegionToTile if it makes sense.
static ossimAppFixedTileCache * instance(ossim_uint32 maxSize=0)
virtual ossim_uint32 getNumberOfLines(ossim_uint32 resLevel=0) const
Gets number of lines for res level.
std::ostream & dumpTiles(std::ostream &out)
Method to print out tile info.
virtual bool allocate()
Allocates everything for current entry.
virtual ossim_uint32 getNumberOfDecimationLevels() const
This returns the total number of decimation levels.
virtual bool isValidRLevel(ossim_uint32 resLevel) const
Determines if the passed in reslution level is valid.
virtual double getMinPixelValue(ossim_uint32 band=0) const
Retuns the min pixel value.
kdu_supp::jp2_source * m_jp2Source
ossim_float64 m_minSampleValue
min/max/null These are class attributes so that when behaving as an overview the owner or base image ...
virtual void setNullPix(ossim_float64 null_pix)
virtual bool getOverviewTile(ossim_uint32 resLevel, ossimImageData *result)
Method to get an overview tile.
ossim_uint32 theNumberOfImages
ossim_float64 m_nullSampleValue
const char * findPreference(const char *key) const
kdu_supp::kdu_channel_mapping * m_channels
virtual const char * what() const
Returns the error message.
void parseStream(ossim::istream &in)
Parse method.
virtual ossim_float64 getMaxPixelValue(ossim_uint32 band=0) const
unsigned int ossim_uint32
virtual bool allocateBuffers()
Allocates buffers for current entry.
virtual const ossim_float64 * getNullPix() const
virtual void close()
Closes file and destroys all memory allocated.
ossim_uint32 thePsot
The length in bytes of this record including the SOT marker.
std::ostream & print(std::ostream &out, const std::string &prefix=std::string()) const
print method that outputs a key/value type format adding prefix to keys.
virtual void initializeSwapBytesFlag()
Sets the "theSwapBytesFlag" from the current entry.
ossimRefPtr< ossimImageData > theCacheTile
virtual ossimIrect getImageRectangle() const
virtual bool parseFile()
Parses "theImageFile" and initializes all nitf headers.
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
virtual bool loadBlock(ossim_uint32 x, ossim_uint32 y)
Loads a block of data to theCacheTile.
const ossimNitfImageHeader * getCurrentImageHeader() const
ossim_uint32 m_sourcePrecisionBits
std::ostream & print(std::ostream &out, const std::string &prefix=std::string()) const
print method that outputs a key/value type format adding prefix to keys.
ossimAppFixedTileCache::ossimAppFixedCacheId theCacheId
ossimKakaduNitfReader()
default construtor
static ossimPreferences * instance()
virtual ossim_uint32 getNumberOfSamples(ossim_uint32 resLevel=0) const
Gets the number of samples for res level.
virtual bool getOverviewTile(ossim_uint32 resLevel, ossimImageData *result)
Gets an overview tile.
kdu_supp::jp2_family_src * m_jp2FamilySrc
virtual void makeBlank()
Initializes data to null pixel values.
ossimRefPtr< ossimImageData > theTile
void setStartingResLevel(ossim_uint32 level)
bool isEntryJ2k() const
Checks current entry image header to see if it is j2k.
ossimRefPtr< ossimImageHandler > theOverview
bool copyRegionToTile(kdu_supp::kdu_channel_mapping *channelMapping, kdu_core::kdu_codestream &codestream, int discard_levels, kdu_core::kdu_thread_env *threadEnv, kdu_core::kdu_thread_queue *threadQueue, ossimImageData *destTile)
Copies region from codestream to tile at a given rlevel.
virtual void setMaxPix(ossim_float64 max_pix)
kdu_core::kdu_thread_env * m_threadEnv
virtual ossimString getLongName() const
Returns long name.
ossim_uint32 m_minDwtLevels
std::ostream & print(std::ostream &out, const std::string &prefix=std::string()) const
print method that outputs a key/value type format adding prefix to keys.
virtual bool canUncompress(const ossimNitfImageHeader *hdr) const
Checks header to see is we can decompress entry.
virtual bool allocate()
Allocates everything for current entry.
virtual void setDataObjectStatus(ossimDataObjectStatus status) const
Full list found in ossimConstants.h.
virtual ossim_uint32 getNumberOfOutputBands() const
virtual ossim_uint32 getNumberOfSamples(ossim_uint32 resLevel=0) const =0
Pure virtual, derived classes must implement.
bool checkJp2Signature()
Checks for jp2 signature block.
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
virtual void setNullPixelValue(ossim_uint32 band, const ossim_float64 &pix)
convenience method to set null pixel value.
virtual ossim_float64 getMinPixelValue(ossim_uint32 band=0) const
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.
RTTI_DEF1_INST(ossimKakaduNitfReader, "ossimKakaduNitfReader", ossimNitfTileSource) ossimKakaduNitfReader
virtual bool loadBlock(ossim_uint32 x, ossim_uint32 y)
Loads a block of data to theCacheTile.
virtual void setMinPix(ossim_float64 min_pix)
virtual bool allocateBuffers()
Allocates buffers for current entry.
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
virtual void setMinPixelValue(ossim_uint32 band, const ossim_float64 &pix)
convenience method to set min pixel value.
bool getCodestreamDimensions(kdu_core::kdu_codestream &codestream, std::vector< ossimIrect > &imageDims, std::vector< ossimIrect > &tileDims)
Gets image and tile dimensions from codestream for each resolution level (rlevel).
unsigned char ossim_uint8
virtual void initializeCacheTileInterLeaveType()
Initializes the data member "theCacheTileInterLeaveType".
ossimRefPtr< ossimImageData > addTile(ossimAppFixedCacheId cacheId, ossimRefPtr< ossimImageData > data, bool duplicateData=true)
std::vector< ossimRefPtr< ossimNitfImageHeader > > theNitfImageHeader
std::vector< ossimIrect > m_imageDims
Image dimensions for each level.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
ossim_uint32 theStartingResLevel
theStartingResLevel If set to something other than zero(default) this is indicative that the reader i...
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
void parseStream(ossim::istream &in)
Parse method.
ossim_uint32 theNumberOfOutputBands
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.