OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimOpjCommon.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: Place for common code used by both encoders and decoders
8 // using the openjpeg library.
9 //
10 // This code is namespaced with "ossim".
11 //
12 //----------------------------------------------------------------------------
13 // $Id$
14 
15 #include <ossimOpjCommon.h>
16 #include <ossimOpjColor.h>
17 #include <ossim/base/ossimCommon.h>
19 #include <ossim/base/ossimIrect.h>
20 #include <ossim/base/ossimNotify.h>
21 #include <ossim/base/ossimString.h>
22 #include <ossim/base/ossimTrace.h>
24 
25 #include <openjpeg.h>
26 
27 #include <cstring>
28 #include <istream>
29 #include <iostream>
30 #include <iomanip>
31 
32 static ossimTrace traceDebug(ossimString("ossimOpjCommon:degug"));
33 
36 {
37 public:
39  ~opj_user_istream(){ m_str = 0; } // We don't own stream.
41  std::streamoff m_offset;
42  std::streamsize m_length;
43 };
44 
46 void ossim::opj_error_callback(const char* msg, void* /* client_data */)
47 {
48  ossimNotify(ossimNotifyLevel_WARN) << msg << std::endl;
49 }
50 
52 void ossim::opj_warning_callback(const char* msg, void* /* client_data */ )
53 {
54  ossimNotify(ossimNotifyLevel_WARN) << msg << std::endl;
55 }
56 
58 void ossim::opj_info_callback(const char* /* msg */ , void* /* client_data */)
59 {
60  //ossimNotify(ossimNotifyLevel_NOTICE) << msg << std::endl;
61 }
62 
64 static OPJ_SIZE_T ossim_opj_istream_read( void * p_buffer,
65  OPJ_SIZE_T p_nb_bytes,
66  void * p_user_data )
67 {
68  OPJ_SIZE_T count = 0;
69  opj_user_istream* usrStr = static_cast<opj_user_istream*>(p_user_data);
70  if ( usrStr )
71  {
72  if ( usrStr->m_str )
73  {
74  std::streamsize bytesToRead = ossim::min<std::streamsize>(
75  (std::streamsize)p_nb_bytes,
76  (std::streamsize)(usrStr->m_length - usrStr->m_str->tellg() ) );
77  // std::streamsize left = usrStr->m_str->tellg();
78  usrStr->m_str->read( (char*) p_buffer, bytesToRead );
79  count = usrStr->m_str->gcount();
80 
81  if ( usrStr->m_str->eof() )
82  {
83  // Set back to front:
84  usrStr->m_str->clear();
85  usrStr->m_str->seekg(usrStr->m_offset, std::ios_base::beg);
86  }
87  else if ( !usrStr->m_str->good() )
88  {
89  usrStr->m_str->clear();
90  usrStr->m_str->seekg(usrStr->m_offset, std::ios_base::beg);
91  count = -1;
92  }
93  }
94  }
95  return count;
96 }
97 
99 static OPJ_OFF_T ossim_opj_istream_skip(OPJ_OFF_T p_nb_bytes, void * p_user_data)
100 {
101  OPJ_OFF_T skipped = p_nb_bytes;
102  opj_user_istream* usrStr = static_cast<opj_user_istream*>(p_user_data);
103  if ( usrStr )
104  {
105  if ( usrStr->m_str )
106  {
107  std::streampos p1 = usrStr->m_str->tellg();
108  usrStr->m_str->seekg( p_nb_bytes, std::ios_base::cur );
109  std::streampos p2 = usrStr->m_str->tellg();
110  if ( ( p2 - p1 ) != p_nb_bytes )
111  {
112  skipped = -1;
113  }
114  }
115  }
116  return skipped;
117 }
118 
120 static OPJ_BOOL ossim_opj_istream_seek(OPJ_OFF_T p_nb_bytes, void * p_user_data)
121 {
122  opj_user_istream* usrStr = static_cast<opj_user_istream*>(p_user_data);
123  if ( usrStr )
124  {
125  if ( usrStr->m_str )
126  {
127  usrStr->m_str->seekg( p_nb_bytes, std::ios_base::cur );
128  }
129  }
130  return OPJ_TRUE;
131 }
132 
133 static void ossim_opj_free_user_istream_data( void * p_user_data )
134 {
135  opj_user_istream* usrStr = static_cast<opj_user_istream*>(p_user_data);
136  if ( usrStr )
137  {
138  delete usrStr;
139  }
140  usrStr = 0;
141 }
142 
144  const ossimIrect& rect,
145  ossim_uint32 resLevel,
146  ossim_int32 format, // OPJ_CODEC_FORMAT
147  std::streamoff fileOffset,
148  ossimImageData* tile)
149 {
150  static const char MODULE[] = "ossimOpjDecoder::decode";
151 
152  bool status = false;
153 
154  if ( traceDebug() )
155  {
157  << MODULE << "entered...\nrect: " << rect
158  << "\nresLevel: " << resLevel << std::endl;
159  }
160 
161  // Need to check for NAN in rect
162  if ( in && tile && !rect.hasNans())
163  {
164  in->seekg( fileOffset, std::ios_base::beg );
165 
166  opj_dparameters_t param;
167  opj_codec_t* codec = 0;
168  opj_image_t* image = 0;;
169  opj_stream_t* stream = 0;
170 
171  opj_user_istream* userStream = new opj_user_istream();
172  userStream->m_str = in;
173  userStream->m_offset = fileOffset;
174 
175  /* Set the length to avoid an assert */
176  in->seekg(0, std::ios_base::end);
177 
178  // Fix: length must be passed in for nift blocks.
179  userStream->m_length = in->tellg();
180 
181  // Set back to front:
182  in->clear();
183  in->seekg(fileOffset, std::ios_base::beg);
184 
185  stream = opj_stream_default_create(OPJ_TRUE);
186  if (!stream)
187  {
188  opj_stream_destroy(stream);
189  std::string errMsg = MODULE;
190  errMsg += " ERROR: opj_setup_decoder failed!";
191  throw ossimException(errMsg);
192  }
193 
194  opj_stream_set_read_function(stream, ossim_opj_istream_read);
195  opj_stream_set_skip_function(stream, ossim_opj_istream_skip);
196  opj_stream_set_seek_function(stream, ossim_opj_istream_seek);
197 
198  // Fix: length must be passed in for nift blocks.
199  opj_stream_set_user_data_length(stream, userStream->m_length);
200 
201  opj_stream_set_user_data(stream, userStream,
202  ossim_opj_free_user_istream_data);
203 
204  opj_stream_set_user_data_length(stream, userStream->m_length);
205 
206 
207  /* Set the default decoding parameters */
208  opj_set_default_decoder_parameters(&param);
209 
210  param.decod_format = format;
211 
213  /* do not use layer decoding limitations */
214  param.cp_layer = 0;
215 
216  /* do not use resolutions reductions */
217  param.cp_reduce = resLevel;
218 
219  codec = opj_create_decompress( (CODEC_FORMAT)format );
220 
221  // catch events using our callbacks and give a local context
222  //opj_set_info_handler (codec, ossim::opj_info_callback, 00);
223  opj_set_info_handler (codec, NULL, 00);
224  opj_set_warning_handler(codec, ossim::opj_warning_callback,00);
225  opj_set_error_handler (codec, ossim::opj_error_callback, 00);
226 
227  // Setup the decoder decoding parameters using user parameters
228  if ( opj_setup_decoder(codec, &param) == false )
229  {
230  opj_stream_destroy(stream);
231  opj_destroy_codec(codec);
232  std::string errMsg = MODULE;
233  errMsg += " ERROR: opj_setup_decoder failed!";
234  throw ossimException(errMsg);
235  }
236 
237  // Read the main header of the codestream and if necessary the JP2 boxes.
238  if ( opj_read_header(stream, codec, &image) == false )
239  {
240  opj_stream_destroy(stream);
241  opj_destroy_codec(codec);
242  opj_image_destroy(image);
243  std::string errMsg = MODULE;
244  errMsg += " ERROR: opj_read_header failed!";
245  throw ossimException(errMsg);
246  }
247 
248  // tmp drb:
249  // opj_stream_destroy(stream);
250  // return;
251 
252  if ( opj_set_decoded_resolution_factor(codec, resLevel) == false)
253  {
254  opj_stream_destroy(stream);
255  opj_destroy_codec(codec);
256  opj_image_destroy(image);
257  std::string errMsg = MODULE;
258  errMsg += " ERROR: opj_set_decoded_resolution_factor failed!";
259  throw ossimException(errMsg);
260  }
261 
262  //ossim_float32 res = resLevel;
263  ossimIrect resRect = rect * (1 << resLevel);
264 
265  //std::cout << "resRect.ul(): " << resRect.ul()
266  // << "\nresRect.lr(): " << resRect.lr()
267  // << std::endl;
268 
269 // if ( opj_set_decode_area(codec, image, rect.ul().x, rect.ul().y,
270 // rect.lr().x+1, rect.lr().y+1) == false )
271  if ( opj_set_decode_area(codec, image, resRect.ul().x, resRect.ul().y,
272  resRect.lr().x+1, resRect.lr().y+1) == false )
273  {
274  opj_stream_destroy(stream);
275  opj_destroy_codec(codec);
276  opj_image_destroy(image);
277  std::string errMsg = MODULE;
278  errMsg += " ERROR: opj_set_decode_area failed!";
279  throw ossimException(errMsg);
280  }
281 
282  // Get the decoded image:
283  if ( opj_decode(codec, stream, image) == false )
284  {
285  opj_stream_destroy(stream);
286  opj_destroy_codec(codec);
287  opj_image_destroy(image);
288  std::string errMsg = MODULE;
289  errMsg += " ERROR: opj_decode failed!";
290  throw ossimException(errMsg);
291  }
292 
293  // ossim::print(std::cout, *image);
294  if(image->icc_profile_buf) {
295 #if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
296  color_apply_icc_profile(image); /* FIXME */
297 #endif
298  free(image->icc_profile_buf);
299  image->icc_profile_buf = NULL; image->icc_profile_len = 0;
300  }
301 
302  status = ossim::copyOpjImage(image, tile);
303 
304 #if 0
305  ossim_uint32 tile_index = 0;
306  ossim_uint32 data_size = 0;
307  ossim_int32 current_tile_x0 = 0;
308  ossim_int32 current_tile_y0 = 0;
309  ossim_int32 current_tile_x1 = 0;
310  ossim_int32 current_tile_y1 = 0;
311  ossim_uint32 nb_comps = 0;
312  OPJ_BOOL go_on = 1;
313 
314  if ( opj_read_tile_header( codec,
315  stream,
316  &tile_index,
317  &data_size,
318  &current_tile_x0,
319  &current_tile_y0,
320  &current_tile_x1,
321  &current_tile_y1,
322  &nb_comps,
323  &go_on) == false )
324  {
325  opj_stream_destroy(stream);
326  opj_destroy_codec(codec);
327  opj_image_destroy(image);
328  std::string errMsg = MODULE;
329  errMsg += " ERROR: opj_read_tile_header failed!";
330  throw ossimException(errMsg);
331  }
332 #endif
333 
334 #if 0
335  std::cout << "tile_index: " << tile_index
336  << "\ndata_size: " << data_size
337  << "\ncurrent_tile_x0: " << current_tile_x0
338  << "\ncurrent_tile_y0: " << current_tile_y0
339  << "\ncurrent_tile_x1: " << current_tile_x1
340  << "\ncurrent_tile_y1: " << current_tile_y1
341  << "\nnb_comps: " << nb_comps
342  << std::endl;
343 #endif
344 
345 #if 0
346  if ( opj_decode_tile_data(codec, tile_index,l_data,l_data_size,l_stream) == false)
347  {
348  opj_stream_destroy(l_stream);
349  opj_destroy_codec(l_codec);
350  opj_image_destroy(l_image);
351  std::string errMsg = MODULE;
352  errMsg += " ERROR: opj_read_tile_header failed!";
353  throw ossimException(errMsg);
354  }
355 #endif
356 
357 #if 0
358 
359  if (opj_end_decompress(codec,stream) == false )
360  {
361  opj_stream_destroy(stream);
362  opj_destroy_codec(codec);
363  opj_image_destroy(image);
364  std::string errMsg = MODULE;
365  errMsg += " ERROR: opj_end_decompress failed!";
366  throw ossimException(errMsg);
367  }
368 
369 #endif
370 
371  /* Free memory */
372  opj_stream_destroy(stream);
373  opj_destroy_codec(codec);
374  opj_image_destroy(image);
375 
376  // Tmp drb:
377  if ( in->eof() )
378  {
379  in->clear();
380  }
381  in->seekg(fileOffset, std::ios_base::beg );
382 
383  } // Matches: if ( in && tile )
384 
385  return status;
386 
387 } // End: ossim::opj_decode( ... )
388 
389 bool ossim::copyOpjImage( opj_image* image, ossimImageData* tile )
390 {
391  bool status = false;
392 
393  if ( image && tile )
394  {
395  if ( image->color_space == OPJ_CLRSPC_SRGB )
396  {
397  const ossimScalarType SCALAR = tile->getScalarType();
398  if ( SCALAR == OSSIM_UINT8 )
399  {
400  status = ossim::copyOpjSrgbImage( ossim_uint8(0), image, tile );
401  }
402  else
403  {
405  << "ossim::copyOpjImage WARNING!\nUnhandle scalar: "
406  << SCALAR << "\n";
407  }
408  }
409  else
410  {
412  << "ossim::copyOpjImage WARNING!\nUnhandle color space: "
413  << image->color_space << "\n";
414  }
415  }
416 
417  return status;
418 }
419 
420 template <class T> bool ossim::copyOpjSrgbImage( T /* dummy */,
421  opj_image* image,
422  ossimImageData* tile )
423 {
424  bool status = false;
425 
426  const ossim_uint32 BANDS = tile->getNumberOfBands();
427 
428  if ( image->numcomps == BANDS )
429  {
430  for ( ossim_uint32 band = 0; band < BANDS; ++band )
431  {
432  T* buf = (T*)tile->getBuf(band);
433  const ossim_uint32 LINES = tile->getHeight();
434 
435  if ( image->comps[band].h == LINES )
436  {
437  ossim_uint32 offset = 0;
438  for ( ossim_uint32 line = 0; line < LINES; ++line )
439  {
440  const ossim_uint32 SAMPS = tile->getWidth();
441  if ( image->comps[band].w == SAMPS )
442  {
443  for ( ossim_uint32 samp = 0; samp < SAMPS; ++samp )
444  {
445  buf[offset] = (T)(image->comps[band].data[offset]);
446  ++offset;
447  }
448 
449  //---
450  // If we get here all the dimensions match and things sould
451  // be good.
452  //---
453  status = true;
454  }
455  else
456  {
458  << "ossim::copyOpjSrgbImage WARNING: sample mismatch!\n";
459  }
460  }
461  }
462  else
463  {
465  << "ossim::copyOpjSrgbImage WARNING: line mismatch!\n";
466  }
467  }
468  }
469  else
470  {
472  << "ossim::copyOpjSrgbImage WARNING: band mismatch!\n";
473  }
474 
475  return status;
476 
477 } // End: ossim::copyOpjSrgbImage( ... )
478 
480 {
481  ossim_int32 result = OPJ_CODEC_UNKNOWN; // -1
482 
483  if ( str )
484  {
485  if ( str->good() )
486  {
487  const ossim_uint8 JP2_RFC3745_MAGIC[12] =
488  { 0x00,0x00,0x00,0x0c,0x6a,0x50,0x20,0x20,0x0d,0x0a,0x87,0x0a };
489  const ossim_uint8 JP2_MAGIC[4] = { 0x0d,0x0a,0x87,0x0a };
490  const ossim_uint8 J2K_CODESTREAM_MAGIC[4] = { 0xff,0x4f,0xff,0x51 };
491 
492  ossim_uint8 buf[12];
493 
494  // Read in the box.
495  str->read((char*)buf, 12);
496 
497  if ( ( std::memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 ) ||
498  ( std::memcmp(buf, JP2_MAGIC, 4) == 0 ) )
499  {
500  result = OPJ_CODEC_JP2;
501  }
502  else if ( std::memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0 )
503  {
504  result = OPJ_CODEC_J2K;
505  }
506  }
507  }
508 
509  return result;
510 }
511 
512 std::ostream& ossim::print(std::ostream& out, const opj_codestream_info& info)
513 {
514  // Capture stream flags since we are going to mess with them.
515  std::ios_base::fmtflags f = out.flags();
516 
517  const int W = 20;
518 
519  out << std::setiosflags(std::ios_base::right) << std::setfill(' ')
520  << "opj_codestream_info:\n\n"
521  << std::setw(W) << "D_max: "
522  << info.D_max << "\n"
523  << std::setw(W) << "packno: "
524  << info.packno << "\n"
525  << std::setw(W) << "index_write: "
526  <<info.index_write << "\n"
527  << std::setw(W) << "image_w: "
528  << info.image_w << "\n"
529  << std::setw(W) << "image_h: "
530  << info.image_h << "\n"
531  << std::setw(W) << "proj: "
532  << info.prog << "\n"
533  << std::setw(W) << "tile_x: "
534  << info.tile_x << "\n"
535  << std::setw(W) << "tile_y: "
536  << info.tile_y << "\n"
537  << std::setw(W) << "tile_Ox: "
538  << info.tile_Ox << "\n"
539  << std::setw(W) << "tile_Oy: "
540  << info.tile_Oy << "\n"
541  << std::setw(W) << "tw: "
542  << info.tw << "\n"
543  << std::setw(W) << "th: "
544  << info.th << "\n"
545  << std::setw(W) << "numcomps: "
546  << info.numcomps << "\n"
547  << std::setw(W) << "numlayers: "
548  << info.numlayers << "\n";
549 
550  for (int i = 0; i < info.numcomps; ++i)
551  {
552  std::string s = "numdecompos[";
553  s += ossimString::toString(i).string();
554  s += "]: ";
555  out << std::setw(W) << s << info.numdecompos[i] << "\n";
556  }
557 
558  out << std::setw(W) << "marknum: "
559  << info.marknum << "\n"
560  // << std::setw(W) << "marker: " << info.marker << "\n"
561  << std::setw(W) << "maxmarknum: "
562  << info.maxmarknum << "\n"
563  << std::setw(W) << "main_head_start: "
564  << info.main_head_start << "\n"
565  << std::setw(W) << "main_head_end: "
566  << info.main_head_end << "\n"
567  << std::setw(W) << "codestream_size: "
568  << info.codestream_size << "\n"
569  // << "tile: " << info.tile
570  << std::endl;
571 
572  // Set the flags back.
573  out.flags(f);
574 
575  return out;
576 }
577 
578 std::ostream& ossim::print(std::ostream& out, const opj_cparameters& param)
579 {
580  // Capture stream flags since we are going to mess with them.
581  std::ios_base::fmtflags f = out.flags();
582 
583  const int W = 24;
584  int i;
585 
586  out << std::setiosflags(std::ios_base::left) << std::setfill(' ')
587  << "opj_cparameters:\n\n"
588 
589  << std::setw(W) << "tile_size_on:"
590  << param.tile_size_on << "\n"
591 
592  << std::setw(W) << "cp_tx0: "
593  << param.cp_tx0 << "\n"
594 
595  << std::setw(W) << "cp_ty0: "
596  << param.cp_ty0 << "\n"
597 
598  << std::setw(W) << "cp_tdx: "
599  << param.cp_tdx << "\n"
600 
601  << std::setw(W) << "cp_tdy: "
602  << param.cp_tdy << "\n"
603 
604  << std::setw(W) << "cp_disto_alloc: "
605  << param.cp_disto_alloc << "\n"
606 
607  << std::setw(W) << "cp_fixed_alloc: "
608  << param.cp_fixed_alloc << "\n"
609 
610  << std::setw(W) << "cp_fixed_quality: "
611  << param.cp_fixed_quality << "\n"
612 
613  << "cp_matrice:\n"
614 
615  << "cp_comment:\n"
616 
617  << std::setw(W) << "csty:"
618  << param.csty << "\n"
619 
620  << std::setw(W) << "prog_order: "
621  << getProgressionOrderString( (ossim_int32)param.prog_order ) << "\n"
622 
623  << "POC:\n"
624 
625  << std::setw(W) << "numpocs:"
626  << param.numpocs << "\n"
627 
628  << std::setw(W) << "tcp_numlayers:"
629  << param.tcp_numlayers << "\n";
630 
631  for ( i = 0; i < param.tcp_numlayers; ++i )
632  {
633  out << "tcp_rate[" << i << std::setw(14)<< "]: "<< std::setw(4) << param.tcp_rates[i] << "\n"
634  << "tcp_distoratio[" << i << std::setw(8) << "]: " << std::setw(4) << param.tcp_distoratio[i] << "\n";
635  }
636 
637  out << std::setw(W) << "numresolution:"
638  << param.numresolution << "\n"
639 
640  << std::setw(W) << "cblockw_init:"
641  << param.cblockw_init << "\n"
642 
643  << std::setw(W) << "cblockh_init:"
644  << param.cblockh_init << "\n"
645 
646  << std::setw(W) << "mode:"
647  << param.mode << "\n"
648 
649  << std::setw(W) << "irreversible:"
650  << param.irreversible << "\n"
651 
652  << std::setw(W) << "roi_compn:"
653  << param.roi_compno << "\n"
654 
655  << std::setw(W) << "roi_shift:"
656  << param.roi_shift << "\n"
657 
658  << std::setw(W) << "res_spec:"
659  << param.res_spec << "\n"
660 
661  << "prcw_init:\n"
662  // << param.prcw_init << "\n"
663 
664  << "prch_init:\n"
665  // << param.prcw_init << "\n"
666 
667  // << std::setw(W) << "infile:"
668  // << param.infile << "\n"
669 
670  << std::setw(W) << "outfile:"
671  << param.outfile << "\n"
672 
673  // << std::setw(W) << "index_on:"
674  // << param.index_on << "\n"
675 
676  // << std::setw(W) << "index:"
677  // << param.index << "\n"
678 
679  << std::setw(W) << "image_offset_x0:"
680  << param.image_offset_x0 << "\n"
681 
682  << std::setw(W) << "image_offset_y0:"
683  << param.image_offset_y0 << "\n"
684 
685  << std::setw(W) << "subsampling_dx:"
686  << param.subsampling_dx << "\n"
687 
688  << std::setw(W) << "image_offset_dy:"
689  << param.subsampling_dy << "\n"
690 
691  << std::setw(W) << "decod_format:"
692  << param.decod_format << "\n"
693 
694  << std::setw(W) << "cod_format:"
695  << param.cod_format << "\n"
696 
697  << std::setw(W) << "jpwl_epc_on:"
698  << param.jpwl_epc_on << "\n"
699 
700  << std::setw(W) << "jpwl_hprot_MH:"
701  << param.jpwl_hprot_MH << "\n"
702 
703  << "jpwl_hprot_TPH_tileno:\n"
704 
705  << "jpwl_pprot_TPH:\n"
706 
707  << "jpwl_pprot_tileno:\n"
708 
709  << "jpwl_pprot_packno:\n"
710 
711  << "jpwl_pprot:\n"
712 
713  << std::setw(W) << "jpwl_sens_size:"
714  << param.jpwl_sens_size << "\n"
715 
716  << std::setw(W) << "jpwl_sens_addr:"
717  << param.jpwl_sens_addr << "\n"
718 
719  << std::setw(W) << "jpwl_sens_range:"
720  << param.jpwl_sens_range << "\n"
721 
722  << std::setw(W) << "jpwl_sens_MH:"
723  << param.jpwl_sens_MH << "\n"
724 
725  << "jpwl_sens_TPH_tileno:\n"
726 
727  << "jpwl_sens_TPH:\n"
728 
729  << "cp_cinema:\n"
730 
731  << std::setw(W) << "max_comp_size:"
732  << param.max_comp_size << "\n"
733 
734  << std::setw(W) << "cp_rsiz:"
735  << param.cp_rsiz << "\n"
736 
737  << std::setw(W) << "tp_on:"
738  << param.tp_on << "\n"
739 
740  << std::setw(W) << "tp_flag:"
741  << param.tp_flag << "\n"
742 
743  << std::setw(W) << "tcp_mct:"
744  << int(param.tcp_mct) << "\n"
745 
746  << std::setw(W) << "jpip_on:"
747  << param.jpip_on << "\n"
748 
749  << "mct_data:\n"
750 
751  << std::setw(W) << "max_cs_size:"
752  << param.max_cs_size << "\n"
753 
754  << std::setw(W) << "rsiz:"
755  << param.rsiz << "\n"
756 
757  << std::endl;
758 
759  // Set the flags back.
760  out.flags(f);
761 
762  return out;
763 }
764 
765 std::ostream& ossim::print(std::ostream& out, const opj_dparameters& param)
766 {
767  // Capture stream flags since we are going to mess with them.
768  std::ios_base::fmtflags f = out.flags();
769 
770  const int W = 20;
771 
772  out << std::setiosflags(std::ios_base::right) << std::setfill(' ')
773  << "opj_dparameters:\n\n"
774  << std::setw(W) << "cp_reduce: "
775  << param.cp_reduce << "\n"
776  << std::setw(W) << "cp_layer: "
777  << param.cp_layer << "\n"
778  << std::setw(W) << "infile: "
779  << param.infile << "\n"
780  << std::setw(W) << "outfile: "
781  << param.outfile << "\n"
782  << std::setw(W) << "decod_format: "
783  << param.decod_format << "\n"
784  << std::setw(W) << "cod_format: "
785  << param.cod_format << "\n"
786  << std::setw(W) << "jpwl_correct: "
787  << param.jpwl_correct << "\n"
788  << std::setw(W) << "jpwl_exp_comps: "
789  << param.jpwl_exp_comps << "\n"
790  << std::setw(W) << "jpwl_max_tiles: "
791  << param.jpwl_max_tiles << "\n"
792  << std::setw(W) << "cp_limit_decoding: "
793  // << param.cp_limit_decoding fix (drb)
794  << std::endl;
795  // Set the flags back.
796  out.flags(f);
797 
798  return out;
799 }
800 
801 std::ostream& ossim::print(std::ostream& out, const opj_image& image)
802 {
803  // Capture stream flags since we are going to mess with them.
804  std::ios_base::fmtflags f = out.flags();
805 
806  const int W = 20;
807 
808  out << std::setiosflags(std::ios_base::right) << std::setfill(' ')
809  << "opj_image:\n\n"
810  << std::setw(W) << "x0: "
811  << image.x0 << "\n"
812  << std::setw(W) << "y0: "
813  << image.y0 << "\n"
814  << std::setw(W) << "x1: "
815  << image.x1 << "\n"
816  << std::setw(W) << "y1: "
817  << image.y1 << "\n"
818  << std::setw(W) << "numcomps: "
819  << image.numcomps << "\n"
820  << std::setw(W) << "color_space: ";
821  if ( image.color_space == OPJ_CLRSPC_UNKNOWN ) out << "UNKNOWN\n";
822  else if ( image.color_space == OPJ_CLRSPC_UNSPECIFIED) out << "UNSPECIFIED\n";
823  else if ( image.color_space == OPJ_CLRSPC_SRGB) out << "SRGB\n";
824  else if ( image.color_space == OPJ_CLRSPC_GRAY) out << "GRAY\n";
825  else if ( image.color_space == OPJ_CLRSPC_SYCC) out << "SYCC\n";
826  else if ( image.color_space == OPJ_CLRSPC_EYCC) out << "EYCC\n";
827  else if ( image.color_space == OPJ_CLRSPC_CMYK) out << "CMYK\n";
828 
829  for (ossim_uint32 i = 0; i < image.numcomps; ++i)
830  {
831  std::string s = "comps[";
832  s += ossimString::toString(i).string();
833  s += "]: ";
834  out << s << std::endl;
835 
836  print(out, (image.comps[i]));
837  }
838 
839  out << std::endl;
840 
841  // Set the flags back.
842  out.flags(f);
843 
844  return out;
845 }
846 
847 std::ostream& ossim::print(std::ostream& out, const opj_image_comp& comp)
848 {
849  // Capture stream flags since we are going to mess with them.
850  std::ios_base::fmtflags f = out.flags();
851 
852  const int W = 20;
853 
854  out << std::setiosflags(std::ios_base::right) << std::setfill(' ')
855  << "opj_image_comp:\n\n"
856  << std::setw(W) << "dx: "
857  << comp.dx << "\n"
858  << std::setw(W) << "dy: "
859  << comp.dy << "\n"
860  << std::setw(W) << "w: "
861  << comp.w << "\n"
862  << std::setw(W) << "h: "
863  << comp.h << "\n"
864  << std::setw(W) << "x0: "
865  << comp.x0 << "\n"
866  << std::setw(W) << "y0: "
867  << comp.y0 << "\n"
868  << std::setw(W) << "prec: "
869  << comp.prec << "\n"
870  << std::setw(W) << "bpp: "
871  << comp.bpp << "\n"
872  << std::setw(W) << "sgnd: "
873  << comp.sgnd << "\n"
874  << std::setw(W) << "resno_decoded: "
875  << comp.resno_decoded << "\n"
876  << std::setw(W) << "factor: "
877  << comp.factor
878  << std::endl;
879 
880  // Set the flags back.
881  out.flags(f);
882 
883  return out;
884 }
885 
886 std::string ossim::getProgressionOrderString( int prog_order )
887 {
888  std::string result = "";
889  switch (prog_order)
890  {
891  case OPJ_LRCP:
892  {
893  result = "LRCP";
894  break;
895  }
896  case OPJ_RLCP:
897  {
898  result = "RLCP";
899  break;
900  }
901  case OPJ_RPCL:
902  {
903  result = "RPCL";
904  break;
905  }
906  case OPJ_PCRL:
907  {
908  result = "PCRL";
909  break;
910  }
911  case OPJ_CPRL:
912  {
913  result = "CPRL";
914  break;
915  }
916  default:
917  {
918  result = "UNKOWN";
919  break;
920  }
921  }
922 
923  return result;
924 }
925 
virtual ossim_uint32 getWidth() const
virtual ossim_uint32 getNumberOfBands() const
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
static ossimString toString(bool aValue)
Numeric to string methods.
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual ossim_uint32 getHeight() const
std::streamsize m_length
std::ostream & print(H5::H5File *file, std::ostream &out)
Print method.
Definition: ossimH5Util.cpp:41
void opj_warning_callback(const char *msg, void *)
Callback method for warnings.
void color_apply_icc_profile(opj_image *image)
std::ostream & print(std::ostream &out, kdu_core::kdu_codestream &cs)
Convenience print method for kdu_codestream.
unsigned int ossim_uint32
std::streamoff m_offset
void opj_info_callback(const char *msg, void *)
Callback method for info.
bool copyOpjSrgbImage(T dummy, opj_image *image, ossimImageData *tile)
const ossimIpt & lr() const
Definition: ossimIrect.h:276
bool opj_decode(std::ifstream *in, const ossimIrect &rect, ossim_uint32 resLevel, ossim_int32 format, std::streamoff fileOffset, ossimImageData *tile)
ossimScalarType
std::string getProgressionOrderString(ossim_int32 prog_order)
return status
virtual ossimScalarType getScalarType() const
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
ossim_int32 y
Definition: ossimIpt.h:142
To hold stream and offset.
virtual const void * getBuf() const
void opj_error_callback(const char *msg, void *)
Callback method for errors.
bool hasNans() const
Definition: ossimIrect.h:337
ossim_int32 x
Definition: ossimIpt.h:141
8 bit unsigned integer
ossim_int32 getCodecFormat(std::istream *str)
Gets codec format from magic number.
bool copyOpjImage(opj_image *image, ossimImageData *tile)
std::istream * m_str
unsigned char ossim_uint8
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
int ossim_int32
const std::string & string() const
Definition: ossimString.h:414