OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimKakaduReaderFactory.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: See top level LICENSE.txt file
4 //
5 // Author: David Burken
6 //
7 // Description: Factory for OSSIM JPEG 2000 (J2k) reader using kakadu library.
8 //----------------------------------------------------------------------------
9 // $Id: ossimKakaduReaderFactory.cpp 22884 2014-09-12 13:14:35Z dburken $
10 
12 #include "ossimKakaduJp2Reader.h"
13 #include "ossimKakaduJ2kReader.h"
14 #include "ossimKakaduNitfReader.h"
17 #include <ossim/base/ossimRefPtr.h>
18 #include <ossim/base/ossimString.h>
19 #include <ossim/base/ossimTrace.h>
21 
22 static const ossimTrace traceDebug( ossimString("ossimKakaduReaderFactory:debug") );
23 
24 class ossimImageHandler;
25 
27  "ossimKakaduReaderFactory",
29 
31 {
32 }
33 
35 {
36  static ossimKakaduReaderFactory inst;
37  return &inst;
38 }
39 
41  bool openOverview)const
42 {
43  static const char* M = "ossimKakaduReaderFactory::open(filename) -- ";
44  if(traceDebug())
45  ossimNotify(ossimNotifyLevel_DEBUG)<<M<<"Entered with filename <"<<fileName<<">" ;
46 
48  while (true)
49  {
50  if (hasExcludedExtension(fileName)) break;
51 
52  if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<<M<< "Trying ossimKakaduNitfReader...";
53  reader = new ossimKakaduNitfReader;
55  if(reader->open(fileName)) break;
56 
57  if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<<M<< "Trying ossimKakaduJp2Reader...";
58  reader = new ossimKakaduJp2Reader;
60  if(reader->open(fileName)) break;
61 
62  if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<<M<< "Trying ossimKakaduJ2kReader...";
63  reader = new ossimKakaduJ2kReader;
65  if(reader->open(fileName)) break;
66 
67  reader = 0;
68  break;
69  }
70 
71  if (traceDebug())
72  {
73  if (reader.valid())
74  ossimNotify(ossimNotifyLevel_DEBUG)<<M<< " SUCCESS" << std::endl;
75  else
76  ossimNotify(ossimNotifyLevel_DEBUG)<<M<< " Open FAILED" << std::endl;
77  }
78 
79  return reader.release();
80 }
81 
83  const char* prefix)const
84 {
85  if(traceDebug())
86  {
88  << "ossimKakaduReaderFactory::open(kwl, prefix) DEBUG: entered..."
89  << std::endl;
90  }
91 
93 
94  // To save time check the file name first.
95  const char* lookup = kwl.find(prefix, ossimKeywordNames::FILENAME_KW);
96  if (!lookup)
97  {
98  // Deprecated...
99  lookup = kwl.find(prefix, ossimKeywordNames::IMAGE_FILE_KW);
100  }
101 
102  if (lookup)
103  {
104  ossimFilename f = lookup;
105  if ( hasExcludedExtension(f) == false )
106  {
107  reader = new ossimKakaduNitfReader;
108  if(reader->loadState(kwl, prefix) == false)
109  {
110  reader = 0;
111  }
112 
113  if (!reader)
114  {
115  reader = new ossimKakaduJp2Reader;
116  if(reader->loadState(kwl, prefix) == false)
117  {
118  reader = 0;
119  }
120  }
121 
122  if (!reader)
123  {
124  reader = new ossimKakaduJ2kReader;
125  if(reader->loadState(kwl, prefix) == false)
126  {
127  reader = 0;
128  }
129  }
130  }
131  }
132 
133  if(traceDebug())
134  {
136  << "ossimKakaduReaderFactory::open(kwl, prefix) DEBUG: leaving..."
137  << std::endl;
138  }
139 
140  return reader.release();
141 }
142 
144  std::shared_ptr<ossim::istream>& str,
145  const std::string& connectionString,
146  bool openOverview ) const
147 {
149 
150  // J2K NITF:
153  if ( ih->open( str, connectionString ) )
154  {
155  result = ih.get();
156  }
157  else
158  {
159  // Reset the stream for downstream code.
160  str->seekg(0, std::ios_base::beg);
161  str->clear();
162  }
163 
164  return result;
165 }
166 
167 
169  const ossimFilename& file ) const
170 {
172  if ( file.size() )
173  {
174  result = new ossimKakaduNitfReader;
175 
176  result->setOpenOverviewFlag( false ); // Always false...
177 
178  if( result->open( file ) == false )
179  {
180  result = 0;
181  }
182  }
183  return result;
184 }
185 
187  std::shared_ptr<ossim::istream>& str, const ossimString& connectionString ) const
188 {
190 
191  // J2K NITF:
193  ih->setOpenOverviewFlag(false);
194  if ( ih->open( str, connectionString ) )
195  {
196  result = ih.get();
197  }
198  else
199  {
200  // Reset the stream for downstream code.
201  str->seekg(0, std::ios_base::beg);
202  str->clear();
203  }
204 
205  return result;
206 }
207 
209 {
210  ossimRefPtr<ossimObject> result = 0;
211  if(typeName == "ossimKakaduNitfReader")
212  {
213  result = new ossimKakaduNitfReader;
214  }
215  else if(typeName == "ossimKakaduJp2Reader")
216  {
217  result = new ossimKakaduJp2Reader;
218  }
219  else if(typeName == "ossimKakaduJ2kReader")
220  {
221  result = new ossimKakaduJ2kReader;
222  }
223  return result.release();
224 }
225 
227  const ossimKeywordlist& kwl,
228  const char* prefix)const
229 {
230  return this->open(kwl, prefix);
231 }
232 
234  std::vector<ossimString>& typeList)const
235 {
236  typeList.push_back(ossimString("ossimKakaduNitfReader"));
237  typeList.push_back(ossimString("ossimKakaduJp2Reader"));
238  typeList.push_back(ossimString("ossimKakaduJ2kReader"));
239 }
240 
243 {
244  extensionList.push_back(ossimString("j2k"));
245  extensionList.push_back(ossimString("jp2"));
246 }
247 
249  const ossimFilename& file) const
250 {
251  bool result = false;
252  ossimString ext = file.ext().downcase();
253  if ( (ext == "tif") ||
254  (ext == "tiff") ||
255  (ext == "jpg") ||
256  (ext == "jpeg") ||
257  (ext == "png") )
258  {
259  result = true;
260  }
261  return result;
262 }
269  const ossimString& ext)const
270 {
271  ossimString testExt = ext.downcase();
272  if(testExt == "jp2")
273  {
274  result.push_back(new ossimKakaduJp2Reader);
275  }
276  else if(testExt == "ntf")
277  {
278  result.push_back(new ossimKakaduNitfReader);
279  }
280  else if(testExt == "nitf")
281  {
282  result.push_back(new ossimKakaduNitfReader);
283  }
284 }
291  const ossimString& mimeType)const
292 {
293  ossimString test(mimeType.begin(), mimeType.begin()+6);
294  if(test == "image/")
295  {
296  ossimString mimeTypeTest(mimeType.begin() + 6, mimeType.end());
297  if(mimeTypeTest == "jp2")
298  {
299  result.push_back(new ossimKakaduJp2Reader);
300  }
301  else if(mimeTypeTest == "nitf")
302  {
303  result.push_back(new ossimKakaduNitfReader);
304  }
305  }
306 }
307 
308 
310 
312 
virtual bool open()=0
Pure virtual open.
void setOpenOverviewFlag(bool flag)
Sets theOpenOverviewFlag.
virtual void getImageHandlersByMimeType(ossimImageHandlerFactoryBase::ImageHandlerList &result, const ossimString &mimeType) const
Will add to the result list and handler that supports the passed in mime type.
ossimKakaduJp2Reader class for reading images with JPEG2000 (J2K) compressed blocks using kakadu libr...
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual void getImageHandlersBySuffix(ossimImageHandlerFactoryBase::ImageHandlerList &result, const ossimString &ext) const
Will add to the result list any handler that supports the passed in extensions.
ossimKakaduReaderFactory()
hidden from use default constructor
ossimKakaduJ2kReader class for reading images with JPEG2000 (J2K) compressed blocks using kakadu libr...
virtual ossimRefPtr< ossimImageHandler > openOverview(const ossimFilename &file) const
Open overview that takes a file name.
void operator=(const ossimKakaduReaderFactory &)
hidden from use copy constructor
std::string::iterator end()
Definition: ossimString.h:423
virtual bool openOverview()
Searches for an overview.
void push_back(char c)
Equivalent to insert(end(), c).
Definition: ossimString.h:905
std::string::size_type size() const
Definition: ossimString.h:405
Factory for J2K image reader.
std::string::iterator begin()
Definition: ossimString.h:420
virtual void getSupportedExtensions(ossimImageHandlerFactoryBase::UniqueStringList &extensionList) const
Method to add supported extension to the list, like "jp2".
T * release()
Definition: ossimRefPtr.h:93
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
virtual ossimObject * createObject(const ossimString &typeName) const
createObject that takes a class name (ossimKakaduReader)
This class defines an abstract Handler which all image handlers(loaders) should derive from...
virtual bool open()
Returns true if the image_file can be opened and is a valid nitf file.
bool hasExcludedExtension(const ossimFilename &file) const
Method to weed out extensions that this plugin knows it does not support.
virtual ossimImageHandler * open(const ossimFilename &fileName, bool openOverview=true) const
open that takes a file name.
RTTI_DEF1(ossimKakaduReaderFactory, "ossimKakaduReaderFactory", ossimImageHandlerFactoryBase)
ossimString ext() const
virtual void getTypeNameList(std::vector< ossimString > &typeList) const
Adds ossimKakaduWriter to the typeList.
std::vector< ossimRefPtr< ossimImageHandler > > ImageHandlerList
ossimKakaduNitfReader class for reading NITF images with JPEG2000 (J2K) compressed blocks using kakad...
static const char * IMAGE_FILE_KW
static const char * FILENAME_KW
virtual ~ossimKakaduReaderFactory()
virtual destructor
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
static ossimKakaduReaderFactory * instance()
static method to return instance (the only one) of this class.