OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimOpjReaderFactory.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 J2k image readers OpenJPEG library.
8 //----------------------------------------------------------------------------
9 // $Id: ossimOpjReaderFactory.cpp 11046 2007-05-25 18:03:03Z gpotts $
10 
11 #include <ossimOpjReaderFactory.h>
12 #include <ossimOpjJp2Reader.h>
13 #include <ossimOpjNitfReader.h>
15 #include <ossim/base/ossimString.h>
17 #include <ossim/base/ossimTrace.h>
19 
20 static const ossimTrace traceDebug("ossimOpjReaderFactory:debug");
21 
23  "ossimOpjReaderFactory",
25 
27 
29 {
30  theInstance = 0;
31 }
32 
34 {
35  if(!theInstance)
36  {
38  }
39  return theInstance;
40 }
41 
43  const ossimFilename& fileName, bool openOverview) const
44 {
45  static const char* M = "ossimOpjReaderFactory::open(filename)";
46 
47  if(traceDebug())
48  {
50  << M << " Entered with filename:" << fileName
51  << "\n";
52  }
53 
55  while (true)
56  {
57  if (hasExcludedExtension(fileName)) break;
58 
59  if (traceDebug())
60  {
61  ossimNotify(ossimNotifyLevel_DEBUG) << M << " Trying ossimOpjJp2Reader...";
62  }
63  reader = new ossimOpjJp2Reader();
65  if( reader->open(fileName) ) break;
66 
67  if (traceDebug())
68  {
69  ossimNotify(ossimNotifyLevel_DEBUG) << M << " Trying ossimOpjNitfReader...";
70  }
71  reader = new ossimOpjNitfReader();
72  if( reader->open(fileName) ) break;
73 
74  reader = 0;
75  break;
76  }
77 
78  if(traceDebug())
79  {
80  ossimNotify(ossimNotifyLevel_DEBUG) << M << " DEBUG: leaving..." << std::endl;
81  }
82 
83  return reader.release();
84 }
85 
87  const ossimKeywordlist& kwl, const char* prefix)const
88 {
89  if(traceDebug())
90  {
92  << "ossimOpjReaderFactory::open(kwl, prefix) DEBUG: entered..."
93  << "Trying ossimOpjReader"
94  << std::endl;
95  }
96 
98 
99  // To save time check the file name first.
100  const char* lookup = kwl.find(prefix, ossimKeywordNames::FILENAME_KW);
101  if (!lookup)
102  {
103  // Deprecated...
104  lookup = kwl.find(prefix, ossimKeywordNames::IMAGE_FILE_KW);
105  }
106 
107  if (lookup)
108  {
109  ossimFilename f = lookup;
110  if ( hasExcludedExtension(f) == false )
111  {
112  reader = new ossimOpjNitfReader;
113  if(reader->loadState(kwl, prefix) == false)
114  {
115  reader = 0;
116  }
117 
118  if (!reader)
119  {
120  reader = new ossimOpjJp2Reader;
121  if(reader->loadState(kwl, prefix) == false)
122  {
123  reader = 0;
124  }
125  }
126  }
127  }
128 
129  if(traceDebug())
130  {
132  << "ossimOpjReaderFactory::open(kwl, prefix) DEBUG: leaving..."
133  << std::endl;
134  }
135 
136  return reader.release();
137 }
138 
140  const ossimFilename& file ) const
141 {
143  if ( file.size() )
144  {
145  result = new ossimOpjNitfReader();
146 
147  result->setOpenOverviewFlag( false ); // Always false...
148 
149  if( result->open( file ) == false )
150  {
151  result = 0;
152  }
153  }
154  return result;
155 }
156 
158  const ossimString& typeName)const
159 {
160  if(typeName == "ossimOpjJp2Reader")
161  {
162  return new ossimOpjJp2Reader;
163  }
164  else if(typeName == "ossimOpjNitfReader")
165  {
166  return new ossimOpjNitfReader;
167  }
168  return 0;
169 }
170 
172  const ossimKeywordlist& kwl,
173  const char* prefix)const
174 {
175  return this->open(kwl, prefix);
176 }
177 
179  std::vector<ossimString>& typeList)const
180 {
181  typeList.push_back(ossimString("ossimOpjJp2Reader"));
182  typeList.push_back(ossimString("ossimOpjNitfReader"));
183 }
184 
187 {
188  extensionList.push_back(ossimString("jp2"));
189 }
190 
193  const ossimString& ext)const
194 {
195  ossimString testExt = ext.downcase();
196  if ( (testExt == "jp2") || (testExt == "j2k") )
197  {
198  result.push_back( new ossimOpjJp2Reader() );
199  }
200  else if( (testExt == "ntf") || (testExt == "nitf") )
201  {
202  result.push_back(new ossimOpjNitfReader() );
203  }
204 }
205 
208  const ossimString& mimeType) const
209 {
210  ossimString test(mimeType.begin(), mimeType.begin()+6);
211  if(test == "image/")
212  {
213  ossimString mimeTypeTest(mimeType.begin() + 6, mimeType.end());
214  if( (mimeTypeTest == "jp2") || (mimeTypeTest == "j2k") )
215  {
216  result.push_back(new ossimOpjJp2Reader);
217  }
218  else if(mimeTypeTest == "nitf")
219  {
220  result.push_back(new ossimOpjNitfReader);
221  }
222  }
223 }
224 
226 {
227  bool result = false;
228  ossimString ext = file.ext().downcase();
229  if ( (ext == "tif") ||
230  (ext == "tiff") ||
231  (ext == "jpg") ||
232  (ext == "jpeg") ||
233  (ext == "png") )
234  {
235  result = true;
236  }
237  return result;
238 }
239 
241 
243 
virtual bool open()=0
Pure virtual open.
void setOpenOverviewFlag(bool flag)
Sets theOpenOverviewFlag.
Factory for PNG image reader.
ossimOpjReaderFactory()
hidden from use default constructor
Represents serializable keyword/value map.
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.
static ossimOpjReaderFactory * theInstance
static instance of this class
virtual void getImageHandlersBySuffix(ossimImageHandlerFactoryBase::ImageHandlerList &result, const ossimString &ext) const
Will add to the result list any handler that supports the passed in extensions.
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.
virtual ossimRefPtr< ossimImageHandler > openOverview(const ossimFilename &file) const
Open overview that takes a file name.
std::string::iterator end()
Definition: ossimString.h:423
virtual ossimImageHandler * open(const ossimFilename &fileName, bool openOverview=true) const
open that takes a file name.
void push_back(char c)
Equivalent to insert(end(), c).
Definition: ossimString.h:905
RTTI_DEF1(ossimOpjReaderFactory, "ossimOpjReaderFactory", ossimImageHandlerFactoryBase)
std::string::size_type size() const
Definition: ossimString.h:405
std::string::iterator begin()
Definition: ossimString.h:420
virtual void getTypeNameList(std::vector< ossimString > &typeList) const
Adds ossimOpjWriter to the typeList.
void operator=(const ossimOpjReaderFactory &)
hidden from use copy constructor
T * release()
Definition: ossimRefPtr.h:93
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
bool hasExcludedExtension(const ossimFilename &file) const
Method to weed out extensions that this plugin knows it does not support.
This class defines an abstract Handler which all image handlers(loaders) should derive from...
virtual ossimObject * createObject(const ossimString &typeName) const
createObject that takes a class name (ossimOpjReader)
ossimString ext() const
std::vector< ossimRefPtr< ossimImageHandler > > ImageHandlerList
virtual void getSupportedExtensions(ossimImageHandlerFactoryBase::UniqueStringList &extensionList) const
Method to add supported extension to the list, like "png".
static const char * IMAGE_FILE_KW
static const char * FILENAME_KW
virtual ~ossimOpjReaderFactory()
virtual destructor
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
static ossimOpjReaderFactory * instance()
static method to return instance (the only one) of this class.