OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimKakaduJpipInfo.cpp
Go to the documentation of this file.
1 #include "ossimKakaduJpipInfo.h"
3 #include <ossim/base/ossimUrl.h>
8 
9 //---
10 // Kakadu code has defines that have (kdu_uint32) which should be
11 // (kdu_core::kdu_uint32)
12 //---
13 using namespace kdu_core;
14 
16 {
17 
18 }
19 
21 {
22 
23 }
24 
26 {
27  m_handler = new ossimKakaduJpipHandler();
28  ossimImageHandler* handler = m_handler.get();
29  bool result = false;
30  ossimUrl url(file.c_str());
31  ossimString protocol = url.getProtocol().downcase();
32  if((protocol == "jpip")||
33  (protocol == "jpips"))
34  {
35  result = handler->open(file);
36 
37  }
38  else
39  {
40  url = ossimUrl();
41  if(file.ext() == "jpip")
42  {
43  ossimKeywordlist kwl;
44 
45  if(kwl.addFile(file.c_str()))
46  {
47  result = handler->loadState(kwl);
48  }
49  }
50  }
51  if(!result) m_handler = 0;
52 
53  return result;
54 }
55 
57 {
58  if(m_handler.valid())
59  {
60  ossimKeywordlist kwl;
61  ossimString xml;
63  m_handler->extractBoxes(boxes);
64 
65  ossim_uint32 idx = 0;
66  for(idx = 0; idx < boxes.size(); ++idx)
67  {
68  if(boxes[idx].m_type == jp2_xml_4cc)
69  {
71  //std::istringstream in(ossimString((char*)&boxes[idx].m_buffer.front(),
72  // (char*)&boxes[idx].m_buffer.front() + boxes[idx].m_buffer.size()));
73  ossimByteStreamBuffer byteStreamBuf((char*)&boxes[idx].m_buffer.front(), boxes[idx].m_buffer.size());
74  std::iostream in(&byteStreamBuf);
75 
76  // std::cout << "________________________________________________" << std::endl;
77  // std::cout << ossimString((char*)&boxes[idx].m_buffer.front(),
78  // (char*)&boxes[idx].m_buffer.front() + boxes[idx].m_buffer.size()) << std::endl;
79  // std::cout << "________________________________________________" << std::endl;
80  if(ossimString((char*)&boxes[idx].m_buffer.front(), (char*)&boxes[idx].m_buffer.front()+4) ==
81  "<?xm")
82  {
83  xmlDoc->read(in);
84  }
85  else
86  {
88  if(node->read(in))
89  {
90  xmlDoc->initRoot(node);
91  }
92  }
93  if(xmlDoc->getRoot().valid())
94  {
96  node->setTag("jpip.image0");
97  node->addChildNode(xmlDoc->getRoot().get());
98  xmlDoc->initRoot(node.get());
99  xmlDoc->toKwl(kwl);
100  out << kwl;
101  }
102  }
103  else if(boxes[idx].m_type == jp2_uuid_4cc)
104  {
105  kdu_byte geojp2_uuid[16] = {0xB1,0x4B,0xF8,0xBD,0x08,0x3D,0x4B,0x43,
106  0xA5,0xAE,0x8C,0xD7,0xD5,0xA6,0xCE,0x03};
107 
108  if(memcmp(&boxes[idx].m_buffer.front(),geojp2_uuid, 16)==0)
109  {
110  ossimTiffInfo info;
111 
112  //---
113  // Have geotiff boxes with badly terminated geotiffs. So to keep
114  // the tag parser from walking past the first image file directory
115  // (IFD) into garbage we will set the process overview flag to false.
116  //
117  // Note if we ever get multiple entries we will need to take this out.
118  //---
119  info.setProcessOverviewFlag(false);
120  //ossimByteStreamBuffer buf((char*)&boxList[idx].m_buffer.front()+16,
121  // boxList[idx].m_buffer.size()-16);
122  //std::istream str(&buf);
123  std::ofstream outStr("/tmp/dump.bin", std::ios::out|std::ios::binary);
124  outStr.write((char*)&boxes[idx].m_buffer.front(),
125  boxes[idx].m_buffer.size());
126  outStr.close();
127  std::istringstream str(ossimString((char*)&boxes[idx].m_buffer.front()+16,
128  (char*)&boxes[idx].m_buffer.front() + boxes[idx].m_buffer.size()));
129  ossim_uint32 entry = 0;
130  ossimKeywordlist kwl; // Used to capture geometry data.
131  // std::cout << ossimString((char*)&boxList[idx].m_buffer.front() + 16,
132  // (char*)&boxList[idx].m_buffer.front() + boxList[idx].m_buffer.size()) << std::endl;
133  if ( info.getImageGeometry(str, kwl, entry) )
134  {
135  kwl.stripPrefixFromAll("image0.");
136  kwl.addPrefixToAll("jpip.image0.geojp2.");
137  out << kwl << std::endl;
138  // ossimRefPtr<ossimProjection> proj = ossimProjectionFactoryRegistry::instance()->createProjection(kwl, "image0.");
139  //if(proj.valid())
140  // {
141  // ossimKeywordlist projKwl;
142  // proj->saveState(projKwl,"jpip.image0.geojp2.");
143  // out << projKwl << std::endl;
144  // }
145  }
146  }
147  else
148  {
149  }
150  }
151  }
152  }
153  return out;
154 }
155 
157 {
158  m_handler = handler;
159 }
160 
virtual bool open()=0
Pure virtual open.
void setTag(const ossimString &tag)
void stripPrefixFromAll(const ossimString &regularExpression)
void setProcessOverviewFlag(bool flag)
Sets the overview flag.
virtual ~ossimKakaduJpipInfo()
virtual destructor
ossimKakaduJpipInfo()
default constructor
Represents serializable keyword/value map.
bool addFile(const char *file)
bool valid() const
Definition: ossimRefPtr.h:75
bool read(std::istream &in)
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 setHandler(ossimKakaduJpipHandler *handler)
virtual bool open(const ossimFilename &file)
open method.
bool getImageGeometry(ossimKeywordlist &geomKwl, ossim_uint32 entryIndex) const
Extracts geometry info to keyword list.
virtual std::ostream & print(std::ostream &out) const
Print method.
TIFF info class.
Definition: ossimTiffInfo.h:36
unsigned int ossim_uint32
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
void addPrefixToAll(const ossimString &prefix)
This class defines an abstract Handler which all image handlers(loaders) should derive from...
void toKwl(ossimKeywordlist &kwl, const ossimString &prefix="") const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool read(std::istream &in)
ossimString ext() const
std::basic_iostream< char > iostream
Base class for char mixed input and output streams.
Definition: ossimIosFwd.h:26
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
ossimRefPtr< ossimXmlNode > getRoot()
void initRoot(ossimRefPtr< ossimXmlNode > node)
void addChildNode(ossimRefPtr< ossimXmlNode > node)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23