OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimNitfVqCompressionHeader.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2004 Garrett Potts
3 //
4 // LICENSE: LGPL see top level LICENSE.txt for more details
5 //
6 // Author: Garrett Potts
7 // Description: Nitf support class
8 //
9 //********************************************************************
10 // $Id: ossimNitfVqCompressionHeader.cpp 19682 2011-05-31 14:21:20Z dburken $
11 
12 #include <iostream>
13 #include <sstream>
14 #include <iomanip>
15 
17 #include <ossim/base/ossimEndian.h>
18 #include <ossim/base/ossimString.h>
20 
21 RTTI_DEF1(ossimNitfVqCompressionHeader, "ossimNitfVqCompressionHeader", ossimNitfCompressionHeader);
22 
23 #if 0
26 {
27  out << "theTableId: " << data.theTableId << std::endl
28  << "theNumberOfCompressionLookupRecords: " << data.theNumberOfCompressionLookupRecords << std::endl
29  << "theNumberOfValuesPerCompressionLookup: " << data.theNumberOfValuesPerCompressionLookup << std::endl
30  << "theCompressionLookupValueBitLength: " << data.theCompressionLookupValueBitLength<< std::endl
31  << "theCompressionLookupTableOffset: " << data.theCompressionLookupTableOffset;
32 
33  return out;
34 }
35 #endif
36 
37 
39  :theData(NULL)
40 {
41  clearFields();
42 }
43 
45  :theTableId(rhs.theTableId),
46  theNumberOfCompressionLookupRecords(rhs.theNumberOfCompressionLookupRecords),
47  theNumberOfValuesPerCompressionLookup(rhs.theNumberOfValuesPerCompressionLookup),
48  theCompressionLookupValueBitLength(rhs.theCompressionLookupValueBitLength),
49  theCompressionLookupTableOffset(rhs.theCompressionLookupTableOffset),
50  theData(NULL)
51 
52 {
56  if(size > 0)
57  {
58  theData = new unsigned char[size];
59  if(rhs.theData)
60  {
61  memcpy(theData, rhs.theData, size);
62  }
63  }
64 }
65 
67 {
68  if(theData)
69  {
70  delete [] theData;
71  theData = NULL;
72  }
73 }
74 
76 {
77  if(this != &rhs)
78  {
79  if(theData)
80  {
81  delete [] theData;
82  theData = NULL;
83  }
84 
85  theTableId = rhs.theTableId;
90 
91  if(rhs.theData)
92  {
96  if(size > 0)
97  {
98  theData = new unsigned char[size];
99  memcpy(theData, rhs.theData, size);
100  }
101  }
102  }
103 
104  return *this;
105 
106 }
108 {
112 }
113 
115 {
116  ossimEndian endian;
117  in.read((char*)(&theTableId), 2);
118  in.read((char*)(&theNumberOfCompressionLookupRecords),4);
119  in.read((char*)(&theNumberOfValuesPerCompressionLookup), 2);
120  in.read((char*)(&theCompressionLookupValueBitLength),2);
121  in.read((char*)(&theCompressionLookupTableOffset), 4);
122 
124  {
125  endian.swap(theTableId);
130  }
131 }
132 
134 {
135  theTableId = 0;
140 
141  if(theData)
142  {
143  delete [] theData;
144  theData = NULL;
145  }
146 }
147 
149 {
150  clearFields();
151 }
152 
154 {
155  ossimEndian endian;
156 
157  in.read((char*)(&theNumberOfImageRows), 4);
158  in.read((char*)(&theNumberOfImageCodesPerRow), 4);
159  in.read((char*)(&theImageCodeBitLength), 1);
160  in.read((char*)(&theCompressionAlgorithmId), 2);
161 
162  in.read((char*)(&theNumberOfCompressionLookupOffsetRecords), 2);
163  in.read((char*)(&theNumberOfCompressionParameterOffsetRecords), 2);
164  in.read((char*)(&theCompressionLookupOffsetTableOffset), 4);
165  in.read((char*)(&theCompressionLookupTableOffsetRecordLength), 2);
166 
168  {
169  endian.swap(theNumberOfImageRows);
176  }
177 
180  {
181  theTable.clear();
183 
184  ossim_uint32 idx = 0;
185 
186  for(idx = 0; idx < theNumberOfCompressionLookupOffsetRecords; ++idx)
187  {
188  theTable[idx].parseStream(in);
189  }
190  for(idx = 0; idx < theTable.size(); ++idx)
191  {
192  if(theTable[idx].theData)
193  {
194  delete [] theTable[idx].theData;
195  theTable[idx].theData = 0;
196  }
197  if(theTable[idx].getDataLengthInBytes()>0)
198  {
199  theTable[idx].theData = new ossim_uint8[theTable[idx].getDataLengthInBytes()];
200  in.read((char*)(theTable[idx].theData), theTable[idx].getDataLengthInBytes());
201  }
202  }
203  }
204 }
205 
207 {
208  return this->print(out, std::string(""));
209 }
210 
212  std::ostream& out, const std::string& prefix ) const
213 {
214  std::string pfx = prefix;
215  pfx += "vq_header.";
216 
217  out << std::setiosflags(std::ios::left)
218  << pfx << std::setw(24) << "image_rows:"
219  << theNumberOfImageRows << "\n"
220  << pfx << std::setw(24) << "codes_per_row:"
221  << theNumberOfImageCodesPerRow << "\n"
222  << pfx << std::setw(24) << "codebit_length:"
224  << pfx << std::setw(24) << "algorithm_id:"
225  << theCompressionAlgorithmId << "\n"
226  << pfx << std::setw(24)
227  << "offset_records:"
229  << pfx << std::setw(24)
230  << "offset_record_length:"
232 
233  if(theTable.size() > 0)
234  {
235  for(ossim_uint32 idx = 0; idx < theTable.size()-1; ++idx)
236  {
237  std::string tblPfx = pfx;
238  tblPfx += "table";
239  tblPfx += ossimString::toString(idx).string();
240  tblPfx += ".";
241 
242  out << tblPfx << std::setw(24) << "id:"
243  << theTable[idx].theTableId << "\n"
244  << tblPfx << std::setw(24) << "lookup_records:"
245  << theTable[idx].theNumberOfCompressionLookupRecords << "\n"
246  << tblPfx << std::setw(24) << "values_per_lookup:"
247  << theTable[idx].theNumberOfValuesPerCompressionLookup << "\n"
248  << tblPfx << std::setw(24) << "lookup_bit_length:"
249  << theTable[idx].theCompressionLookupValueBitLength << "\n"
250  << tblPfx << std::setw(24) << "lookup_table_offset:"
251  << theTable[idx].theCompressionLookupTableOffset << "\n";
252  }
253 
254  }
255 
256  return out;
257 }
258 
260 {
261  bool result = ossimNitfCompressionHeader::saveState(kwl, prefix);
262 
263  if(result)
264  {
265  std::ostringstream out;
266 
267  out << std::setiosflags(std::ios::left)
268  << "image_rows:" << theNumberOfImageRows << "\n"
269  << "codes_per_row:" << theNumberOfImageCodesPerRow << "\n"
270  << "codebit_length:" << (ossim_uint32)theImageCodeBitLength << "\n"
271  << "algorithm_id:" << theCompressionAlgorithmId << "\n"
272  << "offset_records:" << theNumberOfCompressionLookupOffsetRecords << "\n"
273  << "offset_record_length:" << theCompressionLookupTableOffsetRecordLength << "\n";
274 
275  if(theTable.size() > 0)
276  {
277  for(ossim_uint32 idx = 0; idx < theTable.size()-1; ++idx)
278  {
279  std::string tblPfx = "table";
280  tblPfx += ossimString::toString(idx).string();
281  tblPfx += ".";
282 
283  out << tblPfx<< "id:"
284  << theTable[idx].theTableId << "\n"
285  << tblPfx << "lookup_records:"<< theTable[idx].theNumberOfCompressionLookupRecords << "\n"
286  << tblPfx <<"values_per_lookup:"<< theTable[idx].theNumberOfValuesPerCompressionLookup << "\n"
287  << tblPfx << "lookup_bit_length:"<< theTable[idx].theCompressionLookupValueBitLength << "\n"
288  << tblPfx << "lookup_table_offset:"<< theTable[idx].theCompressionLookupTableOffset << "\n";
289  }
290  }
291  ossimKeywordlist kwlTemp;
292 
293  std::istringstream in(out.str());
294  if(kwlTemp.parseStream(in))
295  {
296  kwl.add(prefix, kwlTemp);
297  }
298  }
299 
300  return result;
301 }
302 
304 {
305  return (getNumberOfImageRows()*
308 }
309 
311 {
312  return theNumberOfImageRows;
313 }
314 
316 {
318 }
319 
321 {
323 }
324 
326 {
327  return theImageCodeBitLength;
328 }
329 
331 {
332  return (ossim_uint32)theTable.size();
333 }
334 
335 const std::vector<ossimNitfVqCompressionOffsetTableData>& ossimNitfVqCompressionHeader::getTable()const
336 {
337  return theTable;
338 }
339 
341 {
348 }
349 
virtual ossim_uint32 getBlockSizeInBytes() const
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
virtual ossim_uint32 getNumberOfImageRows() const
Represents serializable keyword/value map.
static ossimString toString(bool aValue)
Numeric to string methods.
virtual bool saveState(ossimKeywordlist &kwl, const ossimString &prefix="") const
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ostream & operator<<(ostream &out, const ossimAxes &axes)
Definition: ossimAxes.h:88
virtual ossim_uint32 getNumberOfImageCodesPerRow() const
virtual std::ostream & print(std::ostream &out) const
Generic print method.
yy_size_t size
virtual ossim_uint32 getImageCodeBitLength() const
const std::vector< ossimNitfVqCompressionOffsetTableData > & getTable() const
unsigned int ossim_uint32
virtual ossim_uint32 getCompressionAlgorithmId() const
virtual void parseStream(std::istream &in)
ossimByteOrder getSystemEndianType() const
Definition: ossimEndian.h:78
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
virtual bool saveState(ossimKeywordlist &kwl, const ossimString &prefix="") const
virtual bool parseStream(ossim::istream &is, bool ignoreBinaryChars)
deprecated method
virtual ossim_uint32 getNumberOfTables() const
std::vector< ossimNitfVqCompressionOffsetTableData > theTable
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
const ossimNitfVqCompressionOffsetTableData & operator=(const ossimNitfVqCompressionOffsetTableData &rhs)
RTTI_DEF1(ossimNitfVqCompressionHeader, "ossimNitfVqCompressionHeader", ossimNitfCompressionHeader)
unsigned char ossim_uint8
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
const std::string & string() const
Definition: ossimString.h:414