OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimJ2kSizRecord.cpp
Go to the documentation of this file.
1 //---
2 //
3 // License: MIT
4 //
5 // Author: David Burken
6 //
7 // Description: Container class for J2K Image and tile size (SIZ) record.
8 //
9 // See document BPJ2K01.00 Table 7-6 Image and tile size (15444-1 Annex A5.1)
10 //
11 //---
12 // $Id$
13 
16 #include <ossim/base/ossimCommon.h>
17 #include <ossim/base/ossimEndian.h>
19 #include <iostream>
20 #include <iomanip>
21 
22 
24  :
25  m_marker(0xff51),
26  m_Lsiz(0),
27  m_Rsiz(0),
28  m_Xsiz(0),
29  m_Ysiz(0),
30  m_XOsiz(0),
31  m_YOsiz(0),
32  m_XTsiz(0),
33  m_YTsiz(0),
34  m_XTOsiz(0),
35  m_YTOsiz(0),
36  m_Csiz(0),
37  m_Ssiz(0),
38  m_XRsiz(0),
39  m_YRsiz(0)
40 {
41 }
42 
44 {
45 }
46 
48 {
49  // Note: Marker is not read.
50  in.read((char*)&m_Lsiz, 2);
51  in.read((char*)&m_Rsiz, 2);
52  in.read((char*)&m_Xsiz, 4);
53  in.read((char*)&m_Ysiz, 4);
54  in.read((char*)&m_XOsiz, 4);
55  in.read((char*)&m_YOsiz, 4);
56  in.read((char*)&m_XTsiz, 4);
57  in.read((char*)&m_YTsiz, 4);
58  in.read((char*)&m_XTOsiz, 4);
59  in.read((char*)&m_YTOsiz, 4);
60  in.read((char*)&m_Csiz, 2);
61 
63  {
64  // Stored in file big endian, must swap.
65  ossimEndian s;
66  s.swap(m_Lsiz);
67  s.swap(m_Rsiz);
68  s.swap(m_Xsiz);
69  s.swap(m_Ysiz);
70  s.swap(m_XOsiz);
71  s.swap(m_YOsiz);
72  s.swap(m_XTsiz);
73  s.swap(m_YTsiz);
74  s.swap(m_XTOsiz);
75  s.swap(m_YTOsiz);
76  s.swap(m_Csiz);
77  }
78 
79  m_Ssiz.resize( m_Csiz );
80  in.read((char*)&m_Ssiz.front(), m_Csiz);
81 
82  m_XRsiz.resize( m_Csiz );
83  in.read((char*)&m_XRsiz.front(), m_Csiz);
84 
85  m_YRsiz.resize( m_Csiz );
86  in.read((char*)&m_YRsiz.front(), m_Csiz);
87 }
88 
90 {
91  // Length of this marker segment(marker not included):
92  m_Lsiz = 38 + 3*m_Csiz;
93 
94  // Grab component count before swapping:
95  ossim_uint16 components = m_Csiz;
96 
97  ossimEndian* s = 0;
98 
100  {
101  // Stored in file big endian, must swap.
102  s = new ossimEndian();
103  s->swap(m_Lsiz);
104  s->swap(m_Rsiz);
105  s->swap(m_Xsiz);
106  s->swap(m_Ysiz);
107  s->swap(m_XOsiz);
108  s->swap(m_YOsiz);
109  s->swap(m_XTsiz);
110  s->swap(m_YTsiz);
111  s->swap(m_XTOsiz);
112  s->swap(m_YTOsiz);
113  s->swap(m_Csiz);
114  }
115 
116  out.put( 0xff );
117  out.put( 0x51 );
118  // out.write( (char*)&m_marker, 2 );
119 
120  out.write((char*)&m_Lsiz, 2);
121  out.write((char*)&m_Rsiz, 2);
122  out.write((char*)&m_Xsiz, 4);
123  out.write((char*)&m_Ysiz, 4);
124  out.write((char*)&m_XOsiz, 4);
125  out.write((char*)&m_YOsiz, 4);
126  out.write((char*)&m_XTsiz, 4);
127  out.write((char*)&m_YTsiz, 4);
128  out.write((char*)&m_XTOsiz, 4);
129  out.write((char*)&m_YTOsiz, 4);
130  out.write((char*)&m_Csiz, 2);
131 
132  out.write((char*)&m_Ssiz.front(), components);
133  out.write((char*)&m_XRsiz.front(), components);
134  out.write((char*)&m_YRsiz.front(), components);
135 
136  if ( s )
137  {
138  // Swap it back to native.
139  s->swap(m_Lsiz);
140  s->swap(m_Rsiz);
141  s->swap(m_Xsiz);
142  s->swap(m_Ysiz);
143  s->swap(m_XOsiz);
144  s->swap(m_YOsiz);
145  s->swap(m_XTsiz);
146  s->swap(m_YTsiz);
147  s->swap(m_XTOsiz);
148  s->swap(m_YTOsiz);
149  s->swap(m_Csiz);
150 
151  // Cleanup:
152  delete s;
153  s = 0;
154  }
155 }
156 
158 {
159  // Currently assumes all components the same scalar type.
160 
162 
163  if ( m_Ssiz.size() )
164  {
165  // Bits per pixel first seven bits plus one.
166  ossim_uint8 bpp = ( m_Ssiz[0] & 0x3f ) + 1;
167 
168  // Signed bit is msb.
169  bool isSigned = ( m_Ssiz[0] & 0x80 ) ? true : false;
170 
171  if ( bpp <= 8 )
172  {
173  if ( isSigned == 0 )
174  {
175  result = OSSIM_UINT8;
176  }
177  else if (isSigned == 1)
178  {
179  result = OSSIM_SINT8;
180  }
181  }
182  else if ( bpp == 11 )
183  {
184  if ( isSigned == 0 )
185  {
186  result = OSSIM_USHORT11;
187  }
188  else
189  {
190  result = OSSIM_SINT16;
191  }
192  }
193  else if ( bpp == 12 )
194  {
195  if ( isSigned == 0 )
196  {
197  result = OSSIM_USHORT12;
198  }
199  else
200  {
201  result = OSSIM_SINT16;
202  }
203  }
204  else if ( bpp == 13 )
205  {
206  if ( isSigned == 0 )
207  {
208  result = OSSIM_USHORT13;
209  }
210  else
211  {
212  result = OSSIM_SINT16;
213  }
214  }
215  else if ( bpp == 14 )
216  {
217  if ( isSigned == 0 )
218  {
219  result = OSSIM_USHORT14;
220  }
221  else
222  {
223  result = OSSIM_SINT16;
224  }
225  }
226  else if ( bpp == 15 )
227  {
228  if ( isSigned == 0 )
229  {
230  result = OSSIM_USHORT15;
231  }
232  else
233  {
234  result = OSSIM_SINT16;
235  }
236  }
237  else if( bpp <= 16 )
238  {
239  if( isSigned == 0 )
240  {
241  result = OSSIM_UINT16;
242  }
243  else if( isSigned == 1 )
244  {
245  result = OSSIM_SINT16;
246  }
247  }
248  }
249  return result;
250 }
251 
253  const std::string& prefix) const
254 {
255  // Capture the original flags.
256  std::ios_base::fmtflags f = out.flags();
257 
258  std::string pfx = prefix;
259  pfx += "siz.";
260 
261  out.setf(std::ios_base::hex, std::ios_base::basefield);
262  out << pfx << "marker: 0x" << m_marker << "\n";
263  out.setf(std::ios_base::fmtflags(0), std::ios_base::basefield);
264 
265  out << pfx << "Lsiz: " << m_Lsiz << "\n"
266  << pfx << "Rsiz: " << m_Rsiz << "\n"
267  << pfx << "Xsiz: " << m_Xsiz << "\n"
268  << pfx << "Yziz: " << m_Ysiz << "\n"
269  << pfx << "XOsiz: " << m_XOsiz << "\n"
270  << pfx << "YOsiz: " << m_YOsiz << "\n"
271  << pfx << "XTsiz: " << m_XTsiz << "\n"
272  << pfx << "YTsiz: " << m_YTsiz << "\n"
273  << pfx << "XTOsiz: " << m_XTOsiz << "\n"
274  << pfx << "YTOsiz: " << m_YTOsiz << "\n"
275  << pfx << "Csiz: " << m_Csiz << "\n";
276 
277  for ( ossim_uint16 i = 0; i < m_Csiz; ++i )
278  {
279  out << pfx << "Ssiz[" << i << "]: " << int(m_Ssiz[i]) << "\n"
280  << pfx << "XRsiz[" << i << "]: " << int(m_XRsiz[i]) << "\n"
281  << pfx << "YRsiz[" << i << "]: " << int(m_YRsiz[i]) << "\n";
282  }
283 
284  out.flush();
285 
286  // Reset flags.
287  out.setf(f);
288 
289  return out;
290 }
291 
293 {
294  return obj.print(out);
295 }
16 bit unsigned integer (15 bits used)
8 bit signed integer
ossim_uint32 m_XTOsiz
Horizontal offset from the orgin of reference grid to the left edge of first tile.
ossim_uint32 m_YTOsiz
Vertical offset from the orgin of reference grid to the top edge of first tile.
16 bit unsigned integer
ossim_uint32 m_Xsiz
width of reference grid
16 bit signed integer
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
16 bit unsigned integer (14 bits used)
16 bit unsigned integer (13 bits used)
unsigned short ossim_uint16
std::vector< ossim_uint8 > m_XRsiz
One for each component:
ossim_uint32 m_YTsiz
height of one reference tile
ossim_uint16 m_Csiz
number of component in the image
OSSIM_DLL bool isSigned(ossimScalarType scalarType)
ossim_uint16 m_Rsiz
profile
ossim_uint32 m_XOsiz
Horizontal offset from the orgin of reference grid to the left side of image.
std::vector< ossim_uint8 > m_Ssiz
One for each component:
~ossimJ2kSizRecord()
destructor
std::ostream & operator<<(std::ostream &out, const ossimJ2kSizRecord &obj)
ossim_uint32 m_XTsiz
width of one reference tile
void writeStream(std::ostream &out)
Write method.
std::ostream & print(std::ostream &out, const std::string &prefix=std::string()) const
print method that outputs a key/value type format adding prefix to keys.
ossimJ2kSizRecord()
default constructor
ossimScalarType
16 bit unsigned integer (11 bits used)
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
ossim_uint16 m_Lsiz
length of segment minus marker
ossim_uint16 m_marker
segmet marker 0xff51 (big endian)
8 bit unsigned integer
std::vector< ossim_uint8 > m_YRsiz
One for each component:
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
unsigned char ossim_uint8
ossimScalarType getScalarType() const
Gets the scalar type.
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
ossim_uint32 m_YOsiz
Vertical offset from the orgin of reference grid to the top of image.
ossim_uint32 m_Ysiz
height of reference grid
void parseStream(ossim::istream &in)
Parse method.
16 bit unsigned integer (12 bits used)