OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimNitfJ2klraTag.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // File: ossimNitfJ2klraTag.cpp
4 //
5 // License: LGPL
6 //
7 // See LICENSE.txt file in the top level directory for more details.
8 //
9 // Author: David Burken
10 //
11 // Description: NITF J2KLRA tag.
12 //
13 // See: ISO/IEC BIIF Profile BPJ2K01.00 Table 9-3.
14 //
15 //----------------------------------------------------------------------------
16 // $Id$
17 
18 
21 #include <ossim/base/ossimString.h>
22 
23 #include <cstring> /* for memcpy */
24 #include <iomanip>
25 #include <istream>
26 #include <ostream>
27 
29 
31  : ossimNitfRegisteredTag(std::string("J2KLRA"), 0),
32  m_layer(1)
33 {
34  clearFields();
35 }
36 
38 {
39  clearFields();
40 
41  in.read(m_orig, ORIG_SIZE);
42  in.read(m_levels_o, NLEVELS_O_SIZE);
43  in.read(m_bands_o, NBANDS_O_SIZE);
44  in.read(m_layers_o, NLAYERS_O_SIZE);
45 
47  if ( layers && (layers < 1000) ) // 999 max
48  {
49  m_layer.resize(layers);
50  for ( ossim_uint32 i = 0; i < layers; ++i )
51  {
52  in.read(m_layer[i].m_layer_id, LAYER_ID_SIZE);
53  in.read(m_layer[i].m_bitrate, BITRATE_SIZE);
54  m_layer[i].m_layer_id[LAYER_ID_SIZE] = '\0';
55  m_layer[i].m_bitrate[BITRATE_SIZE] = '\0';
56  }
57  }
58  else
59  {
60  m_layer.clear();
61  }
62 
63  // Conditional:
64  if ( isParsed() )
65  {
66  in.read(m_nlevels_i, NLEVELS_I_SIZE);
67  in.read(m_nbands_i, NBANDS_I_SIZE);
68  in.read(m_nlayers_i, NLAYERS_I_SIZE);
69  }
70 
71  // Set the base tag length.
73 }
74 
76 {
77  out.write(m_orig, ORIG_SIZE);
78  out.write(m_levels_o, NLEVELS_O_SIZE);
79  out.write(m_bands_o, NBANDS_O_SIZE);
80  out.write(m_layers_o, NLAYERS_O_SIZE);
81 
82  ossim_uint32 size = m_layer.size();
83  for ( ossim_uint32 i = 0; i < size; ++i )
84  {
85  out.write(m_layer[i].m_layer_id, LAYER_ID_SIZE);
86  out.write(m_layer[i].m_bitrate, BITRATE_SIZE);
87  }
88 
89  // Conditional:
90  if ( isParsed() )
91  {
92  out.write(m_nlevels_i, NLEVELS_I_SIZE);
93  out.write(m_nbands_i, NBANDS_I_SIZE);
94  out.write(m_nlayers_i, NLAYERS_I_SIZE);
95  }
96 }
97 
99 {
100  ossim_uint32 result = 11 + (m_layer.size() * 12);
101 
102  // Conditional:
103  ossim_uint32 orig = getOriginNumber();
104  if ( orig )
105  {
106  if ( orig % 2 ) // Odd origins are "parsed".
107  {
108  result += 10;
109  }
110  }
111  return result;
112 }
113 
115 {
116  memset(m_orig, 0, ORIG_SIZE);
117 
118  memset(m_levels_o, 0, NLEVELS_O_SIZE);
119  memset(m_bands_o, 0, NBANDS_O_SIZE);
120  memset(m_layers_o, 0, NLAYERS_O_SIZE);
121 
122  m_layer.clear();
123 
124  memset(m_nlevels_i, 0, NLEVELS_I_SIZE);
125  memset(m_nbands_i, 0, NBANDS_I_SIZE);
126  memset(m_nlayers_i, 0, NLAYERS_I_SIZE);
127 
128  m_orig[ORIG_SIZE]= '\0';
129 
130  m_levels_o[NLEVELS_O_SIZE]= '\0';
131  m_bands_o[NBANDS_O_SIZE]= '\0';
132  m_layers_o[NLAYERS_O_SIZE]= '\0';
133 
135  m_nbands_i[NBANDS_I_SIZE] = '\0';
136  m_nlayers_i[NLAYERS_I_SIZE] = '\0';
137 
138  // Set the base tag length.
139  setTagLength( 0 );
140 }
141 
143  const std::string& prefix) const
144 {
145  std::string pfx = prefix;
146  pfx += getTagName();
147  pfx += ".";
148 
149  out << setiosflags(ios::left)
150  << pfx << std::setw(24) << "CETAG:" << getTagName() << "\n"
151  << pfx << std::setw(24) << "CEL:" << getTagLength() << "\n"
152  << pfx << std::setw(24) << "ORIG:" << m_orig << "\n"
153  << pfx << std::setw(24) << "NLEVELS_O:" << m_levels_o << "\n"
154  << pfx << std::setw(24) << "NBANDS_O:" << m_bands_o << "\n"
155  << pfx << std::setw(24) << "NLAYERS_O:" << m_layers_o << "\n";
156 
157  ossim_uint32 size = m_layer.size();
158  for ( ossim_uint32 i = 0; i < size; ++i )
159  {
160  out << pfx << "LAYER_ID[" << i << std::setw(14) << "]:" << m_layer[i].m_layer_id << "\n"
161  << pfx << "BITRATE[" << i << std::setw(15) << "]:" << m_layer[i].m_bitrate << "\n";
162  }
163 
164  // Conditional:
165  if ( isParsed() )
166  {
167  out << pfx << std::setw(24) << "NLEVELS_I:" << m_nlevels_i << "\n"
168  << pfx << std::setw(24) << "NBANDS_I_SIZE:" << m_nbands_i << "\n"
169  << pfx << std::setw(24) << "NLAYERS_I:" << m_nlayers_i << "\n";
170  }
171 
172  return out;
173 }
174 
176 {
177  return ossimString(m_orig).toUInt32();
178 }
179 
181 {
182  return ossimString(m_layers_o).toUInt32();
183 }
184 
186 {
187  bool result = true;
188  if ( origin <= 9 )
189  {
190  // Ascii 0 to 9
191  m_orig[0] = 0x30 + origin;
192  }
193  else
194  {
195  result = false;
196  }
197  return result;
198 }
199 
201 {
202  bool result = false;
203  if ( levels <= 32 )
204  {
206  if ( os.size() == NLEVELS_O_SIZE )
207  {
208  strncpy( m_levels_o, os.string().c_str(), NLEVELS_O_SIZE );
209  result = true;
210  }
211  }
212  return result;
213 }
214 
216 {
217  bool result = false;
218  if ( ( bands >= 1 ) && ( bands <= 16384 ) )
219  {
221  if ( os.size() == NBANDS_O_SIZE )
222  {
223  strncpy( m_bands_o, os.string().c_str(), NBANDS_O_SIZE );
224  result = true;
225  }
226  }
227  return result;
228 }
229 
231 {
232  bool result = false;
233  if ( ( layers >= 1 ) && ( layers <= 999 ) )
234  {
236  if ( os.size() == NLAYERS_O_SIZE )
237  {
238  strncpy( m_layers_o, os.string().c_str(), NLAYERS_O_SIZE );
239 
240  // Conditional repeating field:
241  m_layer.resize( layers );
242 
243  result = true;
244  }
245  }
246  return result;
247 }
248 
250 {
251  bool result = false;
252  if ( levels <= 32 )
253  {
255  if ( os.size() == NLEVELS_I_SIZE )
256  {
257  strncpy( m_nlevels_i, os.string().c_str(), NLEVELS_I_SIZE );
258  result = true;
259  }
260  }
261  return result;
262 }
263 
265 {
266  bool result = false;
267  if ( ( bands >= 1 ) && ( bands <= 16384 ) )
268  {
270  if ( os.size() == NBANDS_I_SIZE )
271  {
272  strncpy( m_nbands_i, os.string().c_str(), NBANDS_I_SIZE );
273  result = true;
274  }
275  }
276  return result;
277 }
278 
280 {
281  bool result = false;
282  if ( ( layers >= 1 ) && ( layers <= 999 ) )
283  {
285  if ( os.size() == NLAYERS_I_SIZE )
286  {
287  strncpy( m_nlayers_i, os.string().c_str(), NLAYERS_I_SIZE );
288  result = true;
289  }
290  }
291  return result;
292 }
293 
295 {
296  bool result = false;
297  if ( index < m_layer.size() && ( id <= 998 ) )
298  {
300  if ( os.size() == LAYER_ID_SIZE)
301  {
302  strncpy( m_layer[index].m_layer_id, os.string().c_str(), LAYER_ID_SIZE );
303  result = true;
304  }
305  }
306  return result;
307 }
308 
310 {
311  bool result = false;
312  if ( index < m_layer.size() && ( bitRate >= 0.0 ) && ( bitRate <= 37.0 ) )
313  {
314  // 00.000000 – 37.000000
316  if ( os.size() == BITRATE_SIZE)
317  {
318  strncpy( m_layer[index].m_bitrate, os.string().c_str(), BITRATE_SIZE);
319  result = true;
320  }
321  }
322  return result;
323 }
324 
326 {
327  bool result = false;
328  ossim_uint32 orig = getOriginNumber();
329  if ( orig )
330  {
331  /*
332  * 0 - Original NPJE
333  * 1 – Parsed NPJE
334  * 2 – Original EPJE
335  * 3 – Parsed EPJE*
336  * 4 - Original TPJE
337  * 5 - Parsed TPJE
338  * 6 - Original LPJE
339  * 7 - Parsed LPJE
340  * 8 – Original other
341  * 9 – Parsed other
342  */
343  if ( orig % 2 ) // Odd origins are "parsed".
344  {
345  result = true;
346  }
347  }
348  return result;
349 }
char m_levels_o[NLEVELS_O_SIZE+1]
FIELD: NLEVELS_O required 2 bytes 00 - 32 Number of wavelet levels in original image.
virtual const std::string & getTagName() const
This will return the name of the registered tag for this user defined header.
RTTI_DEF1(ossimNitfJ2klraTag, "ossimNitfJ2klraTag", ossimNitfRegisteredTag)
char m_orig[ORIG_SIZE+1]
FIELD: ORIG.
virtual void clearFields()
Clears all string fields within the record to some default nothingness.
virtual void writeStream(std::ostream &out)
Write method.
bool setOrigin(ossim_uint32 origin)
Sets origin:
virtual ossim_uint32 getSizeInBytes() const
bool setBandsI(ossim_uint32 bands)
Sets the number of bands in this image.
std::vector< ossimJ2klraLayer > m_layer
repeating fields
ossim_uint32 toUInt32() const
ossim_uint32 getOriginNumber() const
virtual void setTagLength(ossim_uint32 length)
Set the tag length.
char m_nbands_i[NBANDS_I_SIZE+1]
FIELD: NBANDS_I Conditional 5 bytes if ORIG=1, 3,or 9.
double ossim_float64
virtual ossim_uint32 getTagLength() const
Returns the length in bytes of the tag from the CEL or REL field.
static ossimString convertToDoubleString(const ossim_float64 &aValue, ossim_uint32 precision, ossim_uint32 size)
This method takes a value and converts to a string of size with requested precision with a &#39;0&#39; fill...
bool setBandsO(ossim_uint32 bands)
Sets the number of bands in the original image.
virtual void parseStream(std::istream &in)
Parse method.
yy_size_t size
std::string::size_type size() const
Definition: ossimString.h:405
char m_bands_o[NBANDS_O_SIZE+1]
FIELD: NBANDS_O required 5 bytes 00000 - 16384 Number of bands in original image. ...
unsigned int ossim_uint32
bool setLayerBitRate(ossim_uint32 index, ossim_float64 bitRate)
Sets the bitrate from index.
bool setLevelsO(ossim_uint32 levels)
Sets the number of wavelet levels in the original image.
static ossimString convertToUIntString(ossim_uint32 aValue, ossim_uint32 size)
This method takes a value and converts to a string of size with with a &#39;0&#39; fill.
char m_layers_o[NLAYERS_O_SIZE+1]
FIELD: NLAYERS_O required 3 bytes 000 - 999 Number of layers in original image.
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
bool setLevelsI(ossim_uint32 levels)
Sets the number of wavelet levels in this image.
ossim_uint32 getNumberOfLayersOriginal() const
char m_nlayers_i[NLAYERS_I_SIZE+1]
FIELD: NLAYERS_I Conditional 3 bytes if ORIG=1, 3, or 9.
bool setLayersI(ossim_uint32 layers)
Sets the number of layers in this image.
virtual std::ostream & print(std::ostream &out, const std::string &prefix) const
Print method that outputs a key/value type format adding prefix to keys.
bool setLayersO(ossim_uint32 layers)
Sets the number of layers in the original image.
ossimNitfJ2klraTag()
default constructor
char m_nlevels_i[NLEVELS_I_SIZE+1]
FIELD: NLEVELS_I Conditional 2 bytes if ORIG=1, 3, or 9.
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
const std::string & string() const
Definition: ossimString.h:414
bool setLayerId(ossim_uint32 index, ossim_uint32 id)
Sets the layer id for index.